From 494fd9673dc9d1417e357810fe64f36e627cdc05 Mon Sep 17 00:00:00 2001 From: Dave Hooper Date: Wed, 28 Oct 2009 22:27:38 +0000 Subject: Committing FS#10717 by Tomasz Kowalyczyk: add PLAYLIST_INSERT_LAST_SHUFFLED (appends the inserted folder into shuffled order to end of playlist) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23385 a1c6a512-1295-4272-9138-f99709370657 --- apps/lang/english.lang | 28 ++++++++++++++++++++++++++++ apps/onplay.c | 25 ++++++++++++++++++++++++- apps/playlist.c | 40 +++++++++++++++++++++++++++------------- apps/playlist.h | 6 +++++- 4 files changed, 84 insertions(+), 15 deletions(-) (limited to 'apps') diff --git a/apps/lang/english.lang b/apps/lang/english.lang index d7dba2f3c0..e7e3acde0b 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -13182,3 +13182,31 @@ usb_hid: "USB Human Interface Device" + + id: LANG_INSERT_LAST_SHUFFLED + desc: in onplay menu. insert a playlist randomly at end of dynamic playlist + user: core + + *: "Insert Last Shuffled" + + + *: "Insert Last Shuffled" + + + *: "Insert Last Shuffled" + + + + id: LANG_QUEUE_LAST_SHUFFLED + desc: in onplay menu. queue a playlist randomly at and of dynamic playlist + user: core + + *: "Queue Last Shuffled" + + + *: "Queue Last Shuffled" + + + *: "Queue Last Shuffled" + + diff --git a/apps/onplay.c b/apps/onplay.c index 28bf7de8ae..7ad22d5d70 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -173,8 +173,12 @@ static bool add_to_playlist(int position, bool queue) playlist_create(NULL, NULL); /* always set seed before inserting shuffled */ - if (position == PLAYLIST_INSERT_SHUFFLED) + if (position == PLAYLIST_INSERT_SHUFFLED || position == PLAYLIST_INSERT_LAST_SHUFFLED) + { srand(current_tick); + if (position == PLAYLIST_INSERT_LAST_SHUFFLED) + playlist_set_last_shuffled_start(); + } #ifdef HAVE_TAGCACHE if (context == CONTEXT_ID3DB) @@ -355,6 +359,10 @@ MENUITEM_FUNCTION(i_shuf_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_SHUFFLED), playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_SHUFFLED, treeplaylist_callback, Icon_Playlist); +MENUITEM_FUNCTION(i_last_shuf_pl_item, MENU_FUNC_USEPARAM, + ID2P(LANG_INSERT_LAST_SHUFFLED), playlist_insert_func, + (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED, treeplaylist_callback, + Icon_Playlist); /* queue items */ MENUITEM_FUNCTION(q_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE), playlist_queue_func, (intptr_t*)PLAYLIST_INSERT, @@ -369,6 +377,10 @@ 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); +MENUITEM_FUNCTION(q_last_shuf_pl_item, MENU_FUNC_USEPARAM, + ID2P(LANG_QUEUE_LAST_SHUFFLED), playlist_queue_func, + (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED, + treeplaylist_callback, Icon_Playlist); /* replace playlist */ MENUITEM_FUNCTION(replace_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_REPLACE), playlist_insert_func, (intptr_t*)PLAYLIST_REPLACE, @@ -388,10 +400,12 @@ MAKE_ONPLAYMENU( tree_playlist_menu, ID2P(LANG_PLAYLIST), /* insert */ &i_pl_item, &i_first_pl_item, &i_last_pl_item, &i_shuf_pl_item, + &i_last_shuf_pl_item, /* queue */ &q_pl_item, &q_first_pl_item, &q_last_pl_item, &q_shuf_pl_item, + &q_last_shuf_pl_item, /* replace */ &replace_pl_item @@ -439,6 +453,15 @@ static int treeplaylist_callback(int action, } return ACTION_EXIT_MENUITEM; } + else if (this_item == &i_last_shuf_pl_item || this_item == &q_last_shuf_pl_item) + { + if ((playlist_amount() > 0) && (audio_status() & AUDIO_STATUS_PLAY) && (selected_file_attr & ATTR_DIRECTORY)) + { + return action; + } + else + return ACTION_EXIT_MENUITEM; + } break; } return action; diff --git a/apps/playlist.c b/apps/playlist.c index 1e96ebf46b..0c4fe9785b 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -664,19 +664,21 @@ int playlist_remove_all_tracks(struct playlist_info *playlist) /* - * Add track to playlist at specified position. There are five special + * Add track to playlist at specified position. There are seven special * positions that can be specified: - * PLAYLIST_PREPEND - Add track at beginning of playlist - * PLAYLIST_INSERT - Add track after current song. NOTE: If - * there are already inserted tracks then track - * is added to the end of the insertion list - * PLAYLIST_INSERT_FIRST - Add track immediately after current song, no - * matter what other tracks have been inserted - * PLAYLIST_INSERT_LAST - Add track to end of playlist - * PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the - * current playing track and end of playlist - * PLAYLIST_REPLACE - Erase current playlist, Cue the current track - * and inster this track at the end. + * PLAYLIST_PREPEND - Add track at beginning of playlist + * PLAYLIST_INSERT - Add track after current song. NOTE: If + * there are already inserted tracks then track + * is added to the end of the insertion list + * PLAYLIST_INSERT_FIRST - Add track immediately after current song, no + * matter what other tracks have been inserted + * PLAYLIST_INSERT_LAST - Add track to end of playlist + * PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the + * current playing track and end of playlist + * PLAYLIST_INSERT_LAST_SHUFFLED - Add tracks in random order to the end of + * the playlist. + * PLAYLIST_REPLACE - Erase current playlist, Cue the current track + * and inster this track at the end. */ static int add_track_to_playlist(struct playlist_info* playlist, const char *filename, int position, @@ -753,6 +755,12 @@ static int add_track_to_playlist(struct playlist_info* playlist, position = insert_position = (rand() % (playlist->amount+1)); break; } + case PLAYLIST_INSERT_LAST_SHUFFLED: + { + position = insert_position = playlist->last_shuffled_start + + rand() % (playlist->amount - playlist->last_shuffled_start + 1); + break; + } case PLAYLIST_REPLACE: if (playlist_remove_all_tracks(playlist) < 0) return -1; @@ -2639,7 +2647,13 @@ int playlist_amount(void) { return playlist_amount_ex(NULL); } - +/* set playlist->last_shuffle_start to playlist->amount for + PLAYLIST_INSERT_LAST_SHUFFLED command purposes*/ +void playlist_set_last_shuffled_start(void) +{ + struct playlist_info* playlist = ¤t_playlist; + playlist->last_shuffled_start = playlist->amount; +} /* * Create a new playlist If playlist is not NULL then we're loading a * playlist off disk for viewing/editing. The index_buffer is used to store diff --git a/apps/playlist.h b/apps/playlist.h index 4f7b9cff3a..fa234f6c12 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -53,7 +53,8 @@ enum { PLAYLIST_INSERT_LAST = -3, PLAYLIST_INSERT_FIRST = -4, PLAYLIST_INSERT_SHUFFLED = -5, - PLAYLIST_REPLACE = -6 + PLAYLIST_REPLACE = -6, + PLAYLIST_INSERT_LAST_SHUFFLED = -7 }; enum { @@ -105,6 +106,8 @@ struct playlist_info bool pending_control_sync; /* control file needs to be synced */ struct mutex control_mutex; /* mutex for control file access */ + int last_shuffled_start; /* number of tracks when insert last + shuffled command start */ }; struct playlist_track_info @@ -131,6 +134,7 @@ int playlist_get_resume_info(int *resume_index); int playlist_update_resume_info(const struct mp3entry* id3); int playlist_get_display_index(void); int playlist_amount(void); +void playlist_set_last_shuffled_start(void); /* Exported functions for all playlists. Pass NULL for playlist_info structure to work with current playlist. */ -- cgit v1.2.3