Index: apps/playlist.c
===================================================================
--- apps/playlist.c (revision 15068)
+++ apps/playlist.c (working copy)
@@ -572,6 +572,7 @@
if (playlist == NULL)
playlist = ¤t_playlist;
+ playlist->last_insert_pos = -1;
while (playlist->index > 0)
if ((result = remove_track_from_playlist(playlist, 0, true)) < 0)
return result;
@@ -602,6 +603,10 @@
* current playing track and end of playlist
* PLAYLIST_REPLACE - Erase current playlist, Cue the current track
* and inster this track at the end.
+ * PLAYLIST_REPLACE_SHUFFLED - should never be called with this: Menu option
+ * is not there for single files. For directories
+ * and playlists it is turned into
+ * PLAYLIST_INSERT_SHUFFLED before this is called.
*/
static int add_track_to_playlist(struct playlist_info* playlist,
const char *filename, int position,
@@ -625,18 +630,10 @@
position = insert_position = playlist->first_index;
break;
case PLAYLIST_INSERT:
- /* if there are already inserted tracks then add track to end of
- insertion list else add after current playing track */
- if (playlist->last_insert_pos >= 0 &&
- playlist->last_insert_pos < playlist->amount &&
- (playlist->indices[playlist->last_insert_pos]&
- PLAYLIST_INSERT_TYPE_MASK) == PLAYLIST_INSERT_TYPE_INSERT)
- position = insert_position = playlist->last_insert_pos+1;
- else if (playlist->amount > 0)
- position = insert_position = playlist->index + 1;
- else
- position = insert_position = 0;
-
+ if ( playlist_did_insert_ex(playlist) )
+ position = insert_position = playlist->last_insert_pos+1;
+ else
+ return -1; /* should only be called after an insertion has been done */
if (playlist->started)
playlist->last_insert_pos = position;
break;
@@ -682,8 +679,14 @@
if (remove_all_tracks(playlist) < 0)
return -1;
- position = insert_position = playlist->index + 1;
+ if (playlist->amount > 0)
+ position = insert_position = playlist->index + 1;
+ else
+ position = insert_position = 0;
break;
+ case PLAYLIST_REPLACE_SHUFFLED:
+ return -1;
+ break;
}
if (queue)
@@ -2902,12 +2905,12 @@
return -1;
}
- if (position == PLAYLIST_REPLACE)
+ if ((position == PLAYLIST_REPLACE) || (position == PLAYLIST_REPLACE_SHUFFLED))
{
- if (remove_all_tracks(playlist) == 0)
- position = PLAYLIST_INSERT_LAST;
- else
+ if (remove_all_tracks(playlist) != 0)
return -1;
+ position = (position == PLAYLIST_REPLACE) ? PLAYLIST_INSERT_LAST :
+ PLAYLIST_INSERT_SHUFFLED;
}
if (queue)
@@ -2991,11 +2994,12 @@
display_playlist_count(count, count_str, false);
- if (position == PLAYLIST_REPLACE)
+ if ((position == PLAYLIST_REPLACE) || (position == PLAYLIST_REPLACE_SHUFFLED))
{
- if (remove_all_tracks(playlist) == 0)
- position = PLAYLIST_INSERT_LAST;
- else return -1;
+ if (remove_all_tracks(playlist) != 0)
+ return -1;
+ position = (position == PLAYLIST_REPLACE) ? PLAYLIST_INSERT_LAST :
+ PLAYLIST_INSERT_SHUFFLED;
}
cpu_boost(true);
@@ -3274,6 +3278,22 @@
return playlist->amount;
}
+/* returns true if an insert has been done to this playlist */
+bool playlist_did_insert_ex(const struct playlist_info* playlist)
+{
+ if (!playlist)
+ playlist = ¤t_playlist;
+
+ if (playlist->last_insert_pos >= 0 &&
+ playlist->last_insert_pos < playlist->amount &&
+ (playlist->indices[playlist->last_insert_pos]&
+ PLAYLIST_INSERT_TYPE_MASK) == PLAYLIST_INSERT_TYPE_INSERT)
+ return true;
+ else
+ return false;
+
+}
+
/* returns full path of playlist (minus extension) */
char *playlist_name(const struct playlist_info* playlist, char *buf,
int buf_size)
Index: apps/playlist.h
===================================================================
--- apps/playlist.h (revision 15068)
+++ apps/playlist.h (working copy)
@@ -49,7 +49,8 @@
PLAYLIST_INSERT_LAST = -3,
PLAYLIST_INSERT_FIRST = -4,
PLAYLIST_INSERT_SHUFFLED = -5,
- PLAYLIST_REPLACE = -6
+ PLAYLIST_REPLACE = -6,
+ PLAYLIST_REPLACE_SHUFFLED = -7
};
enum {
@@ -154,6 +155,7 @@
int playlist_get_first_index(const struct playlist_info* playlist);
int playlist_get_seed(const struct playlist_info* playlist);
int playlist_amount_ex(const struct playlist_info* playlist);
+bool playlist_did_insert_ex(const struct playlist_info* playlist);
char *playlist_name(const struct playlist_info* playlist, char *buf,
int buf_size);
char *playlist_get_name(const struct playlist_info* playlist, char *buf,
Index: apps/lang/english.lang
===================================================================
--- apps/lang/english.lang (revision 15068)
+++ apps/lang/english.lang (working copy)
@@ -7069,13 +7069,13 @@
desc: in onplay menu. insert a track/playlist into dynamic playlist.
user:
- *: "Insert"
+ *: "Insert more"
- *: "Insert"
+ *: "Insert more"
- *: "Insert"
+ *: "Insert more"
@@ -7122,16 +7122,16 @@
id: LANG_QUEUE
- desc: The verb/action Queue
+ desc: in onplay menu. queue a track/playlist after previous queue
user:
- *: "Queue"
+ *: "Queue more"
- *: "Queue"
+ *: "Queue more"
- *: "Queue"
+ *: "Queue more"
@@ -7181,16 +7181,30 @@
desc: in onplay menu. Replace the current playlist with a new one.
user:
- *: "Play Next"
+ *: "Replace"
- *: "Play Next"
+ *: "Replace"
- *: "Play Next"
+ *: "Replace"
+ id: LANG_REPLACE_SHUFFLED
+ desc: in onplay menu. Replace the current playlist with a new one shuffled.
+ user:
+
+ *: "Replace shuffled"
+
+
+ *: "Replace shuffled"
+
+
+ *: "Replace shuffled"
+
+
+
id: LANG_PLAYLIST_INSERT_COUNT
desc: splash number of tracks inserted
user:
Index: apps/onplay.c
===================================================================
--- apps/onplay.c (revision 15068)
+++ apps/onplay.c (working copy)
@@ -158,7 +158,6 @@
static bool add_to_playlist(int position, bool queue)
{
- bool new_playlist = !(audio_status() & AUDIO_STATUS_PLAY);
char *lines[] = {
ID2P(LANG_RECURSE_DIRECTORY_QUESTION),
selected_file
@@ -166,12 +165,32 @@
struct text_message message={lines, 2};
gui_syncsplash(0, ID2P(LANG_WAIT));
-
- if (new_playlist)
+
+ bool have_list = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE);
+ if (!have_list && position != PLAYLIST_REPLACE &&
+ position != PLAYLIST_REPLACE_SHUFFLED)
+ {
+ if (global_status.resume_index != -1)
+ {
+ /* Try to restore the list from control file */
+ have_list = (playlist_resume() != -1);
+ }
+ if (!have_list && playlist_amount() > 0)
+ {
+ /*If dynamic playlist still exists, view it anyway even
+ if playback has reached the end of the playlist */
+ have_list = true;
+ }
+ }
+ if (!have_list)
+ {
playlist_create(NULL, NULL);
+ }
+
/* always set seed before inserting shuffled */
- if (position == PLAYLIST_INSERT_SHUFFLED)
+ if (position == PLAYLIST_INSERT_SHUFFLED||
+ position == PLAYLIST_REPLACE_SHUFFLED)
srand(current_tick);
#ifdef HAVE_TAGCACHE
@@ -203,17 +222,6 @@
playlist_insert_playlist(NULL, selected_file, position, queue);
}
- if (new_playlist && (playlist_amount() > 0))
- {
- /* nothing is currently playing so begin playing what we just
- inserted */
- if (global_settings.playlist_shuffle)
- playlist_shuffle(current_tick, -1);
- playlist_start(0,0);
- gui_syncstatusbar_draw(&statusbars, false);
- onplay_result = ONPLAY_START_PLAY;
- }
-
return false;
}
@@ -312,39 +320,20 @@
add_to_playlist((intptr_t)param, true);
return 0;
}
-static int treeplaylist_wplayback_callback(int action,
- const struct menu_item_ex*
- this_item)
-{
- (void)this_item;
- switch (action)
- {
- case ACTION_REQUEST_MENUITEM:
- if (audio_status() & AUDIO_STATUS_PLAY)
- return action;
- else
- return ACTION_EXIT_MENUITEM;
- break;
- }
- return action;
-}
static int treeplaylist_callback(int action,
const struct menu_item_ex *this_item);
/* insert items */
-MENUITEM_FUNCTION(i_pl_item_no_play, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT),
- playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_LAST,
- treeplaylist_callback, Icon_Playlist);
MENUITEM_FUNCTION(i_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT),
playlist_insert_func, (intptr_t*)PLAYLIST_INSERT,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
MENUITEM_FUNCTION(i_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_FIRST),
playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_FIRST,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
MENUITEM_FUNCTION(i_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_LAST),
playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_LAST,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
MENUITEM_FUNCTION(i_shuf_pl_item, MENU_FUNC_USEPARAM,
ID2P(LANG_INSERT_SHUFFLED), playlist_insert_func,
(intptr_t*)PLAYLIST_INSERT_SHUFFLED, treeplaylist_callback,
@@ -352,21 +341,24 @@
/* queue items */
MENUITEM_FUNCTION(q_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE),
playlist_queue_func, (intptr_t*)PLAYLIST_INSERT,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
MENUITEM_FUNCTION(q_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_FIRST),
playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_FIRST,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
MENUITEM_FUNCTION(q_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_LAST),
playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_LAST,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
MENUITEM_FUNCTION(q_shuf_pl_item, MENU_FUNC_USEPARAM,
ID2P(LANG_QUEUE_SHUFFLED), playlist_queue_func,
(intptr_t*)PLAYLIST_INSERT_SHUFFLED,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
/* replace playlist */
MENUITEM_FUNCTION(replace_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_REPLACE),
playlist_insert_func, (intptr_t*)PLAYLIST_REPLACE,
- treeplaylist_wplayback_callback, Icon_Playlist);
+ treeplaylist_callback, Icon_Playlist);
+MENUITEM_FUNCTION(replace_shuf_pl_item, MENU_FUNC_USEPARAM,ID2P(LANG_REPLACE_SHUFFLED),
+ playlist_insert_func, (intptr_t*)PLAYLIST_REPLACE_SHUFFLED,
+ treeplaylist_callback, Icon_Playlist);
/* others */
MENUITEM_FUNCTION(view_playlist_item, 0, ID2P(LANG_VIEW),
@@ -380,7 +372,7 @@
&view_playlist_item,
/* insert */
- &i_pl_item_no_play, &i_pl_item, &i_first_pl_item,
+ &i_pl_item, &i_first_pl_item,
&i_last_pl_item, &i_shuf_pl_item,
/* queue */
@@ -388,8 +380,9 @@
&q_shuf_pl_item,
/* replace */
- &replace_pl_item
+ &replace_pl_item, &replace_shuf_pl_item
);
+
static int treeplaylist_callback(int action,
const struct menu_item_ex *this_item)
{
@@ -417,31 +410,22 @@
else
return ACTION_EXIT_MENUITEM;
}
- else if (this_item == &i_pl_item_no_play)
- {
- if (!(audio_status() & AUDIO_STATUS_PLAY))
- {
- return action;
- }
- else
- return ACTION_EXIT_MENUITEM;
- }
- else if (this_item == &i_shuf_pl_item)
- {
-
- if (audio_status() & AUDIO_STATUS_PLAY)
- {
- return action;
- }
- else if ((this_item == &i_shuf_pl_item) &&
- ((selected_file_attr & ATTR_DIRECTORY) ||
- ((selected_file_attr & FILE_ATTR_MASK) ==
- FILE_ATTR_M3U)))
- {
- return action;
- }
- return ACTION_EXIT_MENUITEM;
- }
+ else if ((this_item == &i_pl_item) || (this_item == &q_pl_item))
+ { /* do not show this when it would do the same as insert/q next */
+ if ( playlist_did_insert_ex(NULL) == false )
+ return ACTION_EXIT_MENUITEM;
+ else
+ return action;
+ }
+ else if (this_item == &replace_shuf_pl_item)
+ { /* only show replace shuffled for dir and playlist */
+ if ((selected_file_attr & ATTR_DIRECTORY) ||
+ ((selected_file_attr & FILE_ATTR_MASK) ==
+ FILE_ATTR_M3U))
+ return action;
+ else
+ return ACTION_EXIT_MENUITEM;
+ }
break;
}
return action;