From 4a541faf121bdad6951540c9c0c9d055d4b73ee6 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Sun, 23 May 2004 14:12:05 +0000 Subject: by popular demand: have stop remember the current song and play will start playing from the stopped song. git-svn-id: https://svn.musicpd.org/mpd/trunk@1139 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/playlist.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index 8d145c314..ee71d9d82 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -101,6 +101,7 @@ void initPlaylist() { playlist.version = 0; playlist.random = 0; playlist.queued = -1; + playlist.current = -1; playlist_max_length = strtol((getConf())[CONF_MAX_PLAYLIST_LENGTH],&test,10); if(*test!='\0') { @@ -501,8 +502,8 @@ int addSongToPlaylist(FILE * fp, Song * song) { if(playlist.random) { int swap; int start; - if(playlist_state==PLAYLIST_STATE_STOP) start = 0; - else if(playlist.queued>=0) start = playlist.queued+1; + /*if(playlist_state==PLAYLIST_STATE_STOP) start = 0; + else */if(playlist.queued>=0) start = playlist.queued+1; else start = playlist.current+1; swap = rand()%(playlist.length-start); swap+=start; @@ -621,12 +622,12 @@ int deleteFromPlaylist(FILE * fp, int song) { playerStop(stderr); playlist_noGoToNext = 1; } - else if(playlist_state!=PLAYLIST_STATE_STOP && + else if(/*playlist_state!=PLAYLIST_STATE_STOP &&*/ playlist.current>songOrder) { playlist.current--; } - if(playlist_state!=PLAYLIST_STATE_STOP && playlist.queued>songOrder) { + if(/*playlist_state!=PLAYLIST_STATE_STOP && */playlist.queued>songOrder) { playlist.queued--; } @@ -682,7 +683,15 @@ int playPlaylist(FILE * fp, int song, int stopOnError) { clearPlayerError(); - if(song==-1) i = 0; + if(song==-1) { + if(playlist.current >= 0 && playlist.current < playlist.length) + { + i = playlist.current; + } + else { + i = 0; + } + } else if(song<0) { myfprintf(fp,"%s need integer >= -1\n",COMMAND_RESPOND_ERROR); playlist_state = PLAYLIST_STATE_STOP; @@ -700,17 +709,17 @@ int playPlaylist(FILE * fp, int song, int stopOnError) { } if(playlist.random) { - /*if(song == -1 && playlist_state==PLAYLIST_STATE_PLAY) { + if(song == -1 && playlist_state==PLAYLIST_STATE_PLAY) { randomizeOrder(0,playlist.length-1); } - else {*/ + else { if(song>=0) for(i=0;song!=playlist.order[i];i++); if(playlist_state==PLAYLIST_STATE_STOP) { playlist.current = 0; } swapOrder(i,playlist.current); i = playlist.current; - /*}*/ + } } playlist_stopOnError = stopOnError; @@ -994,7 +1003,10 @@ int shufflePlaylist(FILE * fp) { else playlist.current = 0; i = 1; } - else i = 0; + else { + i = 0; + playlist.current = -1; + } /* shuffle the rest of the list */ for(;i= 0 && playlist.current < playlist.length) { + return playlist.order[playlist.current]; + } + + return -1; } unsigned long getPlaylistVersion() { -- cgit v1.2.3