summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2006-12-26 13:31:04 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2006-12-26 13:31:04 +0000
commitbe3f29cc11a1d31a4bacee16a8ca2f1a9de2caed (patch)
treeb0f9cebfb3e4215df4d880a0befc6da7c4d04848 /apps/playlist.c
parent6ee5e3849480ac6a01545f4637052b58b11463d0 (diff)
downloadrockbox-be3f29cc11a1d31a4bacee16a8ca2f1a9de2caed.tar.gz
rockbox-be3f29cc11a1d31a4bacee16a8ca2f1a9de2caed.zip
Accept FS#6464 by Chris Taylor. Adds a "Play Next" playlist insertion
option which replaces the current playlist with the new selection but keeps the current track queued so playback doesnt stop. (minor fixes by me) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11842 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index e8f9d48ce0..27c8676b96 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -561,6 +561,33 @@ exit:
561} 561}
562 562
563/* 563/*
564 * Removes all tracks, from the playlist, leaving the presently playing
565 * track queued.
566 */
567int remove_all_tracks(struct playlist_info *playlist)
568{
569 int result;
570
571 if (playlist == NULL)
572 playlist = &current_playlist;
573
574 while (playlist->index > 0)
575 if ((result = remove_track_from_playlist(playlist, 0, true)) < 0)
576 return result;
577
578 while (playlist->amount > 1)
579 if ((result = remove_track_from_playlist(playlist, 1, true)) < 0)
580 return result;
581
582 if (playlist->amount == 1) {
583 playlist->indices[0] |= PLAYLIST_QUEUED;
584 }
585
586 return 0;
587}
588
589
590/*
564 * Add track to playlist at specified position. There are five special 591 * Add track to playlist at specified position. There are five special
565 * positions that can be specified: 592 * positions that can be specified:
566 * PLAYLIST_PREPEND - Add track at beginning of playlist 593 * PLAYLIST_PREPEND - Add track at beginning of playlist
@@ -572,6 +599,8 @@ exit:
572 * PLAYLIST_INSERT_LAST - Add track to end of playlist 599 * PLAYLIST_INSERT_LAST - Add track to end of playlist
573 * PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the 600 * PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the
574 * current playing track and end of playlist 601 * current playing track and end of playlist
602 * PLAYLIST_REPLACE - Erase current playlist, Cue the current track
603 * and inster this track at the end.
575 */ 604 */
576static int add_track_to_playlist(struct playlist_info* playlist, 605static int add_track_to_playlist(struct playlist_info* playlist,
577 const char *filename, int position, 606 const char *filename, int position,
@@ -648,6 +677,12 @@ static int add_track_to_playlist(struct playlist_info* playlist,
648 position = insert_position = (rand() % (playlist->amount+1)); 677 position = insert_position = (rand() % (playlist->amount+1));
649 break; 678 break;
650 } 679 }
680 case PLAYLIST_REPLACE:
681 if (remove_all_tracks(playlist) < 0)
682 return -1;
683
684 position = insert_position = playlist->index + 1;
685 break;
651 } 686 }
652 687
653 if (queue) 688 if (queue)
@@ -2860,6 +2895,14 @@ int playlist_insert_directory(struct playlist_info* playlist,
2860 return -1; 2895 return -1;
2861 } 2896 }
2862 2897
2898 if (position == PLAYLIST_REPLACE)
2899 {
2900 if (remove_all_tracks(playlist) == 0)
2901 position = PLAYLIST_INSERT_LAST;
2902 else
2903 return -1;
2904 }
2905
2863 if (queue) 2906 if (queue)
2864 count_str = str(LANG_PLAYLIST_QUEUE_COUNT); 2907 count_str = str(LANG_PLAYLIST_QUEUE_COUNT);
2865 else 2908 else
@@ -2871,7 +2914,7 @@ int playlist_insert_directory(struct playlist_info* playlist,
2871 context.position = position; 2914 context.position = position;
2872 context.queue = queue; 2915 context.queue = queue;
2873 context.count = 0; 2916 context.count = 0;
2874 2917
2875 cpu_boost(true); 2918 cpu_boost(true);
2876 2919
2877 result = playlist_directory_tracksearch(dirname, recurse, 2920 result = playlist_directory_tracksearch(dirname, recurse,
@@ -2941,6 +2984,13 @@ int playlist_insert_playlist(struct playlist_info* playlist, char *filename,
2941 2984
2942 display_playlist_count(count, count_str); 2985 display_playlist_count(count, count_str);
2943 2986
2987 if (position == PLAYLIST_REPLACE)
2988 {
2989 if (remove_all_tracks(playlist) == 0)
2990 position = PLAYLIST_INSERT_LAST;
2991 else return -1;
2992 }
2993
2944 cpu_boost(true); 2994 cpu_boost(true);
2945 2995
2946 while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0) 2996 while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0)