From c2c34f78dd2b63d27bcbd6f21503bf052cad0655 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Sat, 5 Jun 2004 01:14:37 +0000 Subject: new command, plchanges, and also add Num: to songinfo of playlistinfo git-svn-id: https://svn.musicpd.org/mpd/trunk@1339 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/command.c | 80 +++++++++++++++++++++++++++------------------- src/command.h | 2 +- src/conf.c | 2 +- src/directory.c | 2 +- src/playlist.c | 93 +++++++++++++++++++++++++++++++++++++++++++----------- src/playlist.h | 5 ++- src/sig_handlers.c | 2 +- 7 files changed, 131 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/command.c b/src/command.c index 1252886d8..d87b7786c 100644 --- a/src/command.c +++ b/src/command.c @@ -37,43 +37,44 @@ #include #include -#define COMMAND_PLAY "play" -#define COMMAND_STOP "stop" -#define COMMAND_PAUSE "pause" -#define COMMAND_STATUS "status" -#define COMMAND_KILL "kill" -#define COMMAND_CLOSE "close" -#define COMMAND_ADD "add" -#define COMMAND_DELETE "delete" -#define COMMAND_PLAYLIST "playlist" -#define COMMAND_SHUFFLE "shuffle" -#define COMMAND_CLEAR "clear" -#define COMMAND_SAVE "save" -#define COMMAND_LOAD "load" -#define COMMAND_LSINFO "lsinfo" -#define COMMAND_RM "rm" -#define COMMAND_PLAYLISTINFO "playlistinfo" -#define COMMAND_FIND "find" -#define COMMAND_SEARCH "search" -#define COMMAND_UPDATE "update" -#define COMMAND_NEXT "next" -#define COMMAND_PREVIOUS "previous" -#define COMMAND_LISTALL "listall" -#define COMMAND_VOLUME "volume" -#define COMMAND_REPEAT "repeat" -#define COMMAND_RANDOM "random" -#define COMMAND_STATS "stats" -#define COMMAND_CLEAR_ERROR "clearerror" -#define COMMAND_LIST "list" -#define COMMAND_MOVE "move" -#define COMMAND_SWAP "swap" -#define COMMAND_SEEK "seek" +#define COMMAND_PLAY "play" +#define COMMAND_STOP "stop" +#define COMMAND_PAUSE "pause" +#define COMMAND_STATUS "status" +#define COMMAND_KILL "kill" +#define COMMAND_CLOSE "close" +#define COMMAND_ADD "add" +#define COMMAND_DELETE "delete" +#define COMMAND_PLAYLIST "playlist" +#define COMMAND_SHUFFLE "shuffle" +#define COMMAND_CLEAR "clear" +#define COMMAND_SAVE "save" +#define COMMAND_LOAD "load" +#define COMMAND_LSINFO "lsinfo" +#define COMMAND_RM "rm" +#define COMMAND_PLAYLISTINFO "playlistinfo" +#define COMMAND_FIND "find" +#define COMMAND_SEARCH "search" +#define COMMAND_UPDATE "update" +#define COMMAND_NEXT "next" +#define COMMAND_PREVIOUS "previous" +#define COMMAND_LISTALL "listall" +#define COMMAND_VOLUME "volume" +#define COMMAND_REPEAT "repeat" +#define COMMAND_RANDOM "random" +#define COMMAND_STATS "stats" +#define COMMAND_CLEAR_ERROR "clearerror" +#define COMMAND_LIST "list" +#define COMMAND_MOVE "move" +#define COMMAND_SWAP "swap" +#define COMMAND_SEEK "seek" #define COMMAND_LISTALLINFO "listallinfo" #define COMMAND_PING "ping" #define COMMAND_SETVOL "setvol" #define COMMAND_PASSWORD "password" #define COMMAND_CROSSFADE "crossfade" -#define COMMAND_URL_HANDLERS "urlhandlers" +#define COMMAND_URL_HANDLERS "urlhandlers" +#define COMMAND_PLCHANGES "plchanges" #define COMMAND_STATUS_VOLUME "volume" #define COMMAND_STATUS_STATE "state" @@ -322,6 +323,20 @@ int handleRm(FILE * fp, unsigned int * permission, int argArrayLength, return deletePlaylist(fp,argArray[1]); } +int handlePlaylistChanges(FILE * fp, unsigned int * permission, + int argArrayLength, char ** argArray) +{ + unsigned long version; + char * test; + + version = strtoul(argArray[1], &test, 10); + if(*test!='\0') { + commandError(fp, ACK_ERROR_ARG, "need a positive integer"); + return -1; + } + return playlistChanges(fp, version); +} + int handlePlaylistInfo(FILE * fp, unsigned int * permission, int argArrayLength, char ** argArray) { @@ -641,6 +656,7 @@ void initCommands() { addCommand(COMMAND_PASSWORD ,0, 1, 1,handlePassword,NULL); addCommand(COMMAND_CROSSFADE ,PERMISSION_CONTROL, 1, 1,handleCrossfade,NULL); addCommand(COMMAND_URL_HANDLERS,PERMISSION_READ, 0, 0,handleUrlHandlers,NULL); + addCommand(COMMAND_PLCHANGES ,PERMISSION_READ, 1, 1,handlePlaylistChanges,NULL); sortList(commandList); } diff --git a/src/command.h b/src/command.h index 85a3683a4..59f6e433f 100644 --- a/src/command.h +++ b/src/command.h @@ -54,7 +54,7 @@ void finishCommands(); current_command = NULL; \ } \ else { \ - myfprintf(fp, "ACK [%i@%i] " format "\n", \ + myfprintf(stderr, "ACK [%i@%i] " format "\n", \ (int)error, command_listNum, \ ##__VA_ARGS__); \ } \ diff --git a/src/conf.c b/src/conf.c index c9050b8b0..ff38030a5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -69,7 +69,7 @@ #endif #endif -char * conf_params[CONF_NUMBER_OF_PARAMS]; +static char * conf_params[CONF_NUMBER_OF_PARAMS]; void initConf() { int i; diff --git a/src/directory.c b/src/directory.c index 653cdb15f..959ade487 100644 --- a/src/directory.c +++ b/src/directory.c @@ -159,7 +159,7 @@ void readDirectoryDBIfUpdateIsFinished() { if(directory_reReadDB && 0==directory_updatePid) { DEBUG("readDirectoryDB since update finished successfully\n"); readDirectoryDB(); - incrPlaylistVersion(); + playlistVersionChange(); directory_reReadDB = 0; } } diff --git a/src/playlist.c b/src/playlist.c index c7da3fa38..dd261cfd2 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -36,8 +36,6 @@ #include #include -#define BITS_FOR_VERSION 31 - #define PLAYLIST_COMMENT '#' #define PLAYLIST_STATE_STOP 0 @@ -62,13 +60,15 @@ typedef struct _Playlist { Song ** songs; + /* holds version a song was modified on */ + mpd_uint32 * songMod; int * order; int length; int current; int queued; int repeat; int random; - unsigned long version; + mpd_uint32 version; } Playlist; static Playlist playlist; @@ -87,10 +87,28 @@ static void swapOrder(int a, int b); static int playPlaylistOrderNumber(FILE * fp, int orderNum); static void randomizeOrder(int start, int end); -void incrPlaylistVersion() { - static unsigned long max = ((unsigned long)1<=max) playlist.version = 0; + if(playlist.version>=max) { + int i; + + for(i=0; iutf8url); + if((tag = (playlist.songs[song])->tag)) { + printMpdTag(fp, tag); + } + myfprintf(fp, "Num: %i\n", song); +} + +int playlistChanges(FILE * fp, mpd_uint32 version) { + int i; + + for(i=0; i playlist.version || + playlist.songMod[i] >= version || + playlist.songMod[i] == 0) + { + printPlaylistSongInfo(fp, i); + } + } + + return 0; +} + +int playlistInfo(FILE * fp, int song) { int i; int begin = 0; int end = playlist.length; @@ -380,12 +428,7 @@ int playlistInfo(FILE * fp,int song) { return -1; } - for(i=begin;iutf8url); - if((tag = (playlist.songs[i])->tag)) { - printMpdTag(fp,tag); - } - } + for(i=begin; itype == SONG_TYPE_URL && 0 == strcmp(song->utf8url, songPlayer->utf8url) && @@ -759,6 +808,7 @@ void syncCurrentPlayerDecodeMetadata() { { if(song->tag) freeMpdTag(song->tag); song->tag = mpdTagDup(songPlayer->tag); + playlist.songMod[songNum] = playlist.version; incrPlaylistVersion(); } } @@ -891,11 +941,18 @@ int moveSongInPlaylist(FILE * fp, int from, int to) { tmpSong = playlist.songs[from]; /* move songs to one less in from->to */ - for(i=from;ifrom */ - for(i=from;i>to;i--) playlist.songs[i] = playlist.songs[i-1]; + for(i=from;i>to;i--) { + playlist.songs[i] = playlist.songs[i-1]; + playlist.songMod[i] = playlist.version; + } /* put song at _to_ */ playlist.songs[to] = tmpSong; + playlist.songMod[to] = playlist.version; /* now deal with order */ if(playlist.random) { for(i=0;i #include @@ -93,7 +94,9 @@ void playPlaylistIfPlayerStopped(); int seekSongInPlaylist(FILE * fp, int song, float time); -void incrPlaylistVersion(); +void playlistVersionChange(); + +int playlistChanges(FILE * fp, mpd_uint32 version); #endif /* vim:set shiftwidth=4 tabstop=8 expandtab: */ diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 33d3065ea..84243bf45 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -44,7 +44,7 @@ int handlePendingSignals() { signal_clear(SIGHUP); if(!isUpdatingDB()) { readDirectoryDB(); - incrPlaylistVersion(); + playlistVersionChange(); } if(myfprintfCloseAndOpenLogFile()<0) return COMMAND_RETURN_KILL; playerCycleLogFiles(); -- cgit v1.2.3