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
This commit is contained in:
		
							
								
								
									
										17
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								TODO
									
									
									
									
									
								
							| @@ -1,20 +1,15 @@ | ||||
| 1) add song# to metadata when printing songs | ||||
| 1) Parse icymetadata | ||||
|  | ||||
| 2) add updated songs command, to output list of updated songs: | ||||
| 	updatesongs <since-playlist-version> | ||||
| 2) Put a new metadata entry for icyName for Song's | ||||
|  | ||||
| 3) Parse icymetadata | ||||
|  | ||||
| 4) Put a new metadata entry for icyName for Song's | ||||
|  | ||||
| 5) Add a list_OK options for command_lists, to get a list_OK after each | ||||
| 3) Add a list_OK options for command_lists, to get a list_OK after each | ||||
| 	command | ||||
|  | ||||
| 6) put some sort of error reporting for streaming/inputStream! | ||||
| 4) put some sort of error reporting for streaming/inputStream! | ||||
|  | ||||
| 7) Fix charset errors so they don't goto stderr/out | ||||
| 5) Fix charset errors so they don't goto stderr/out | ||||
|  | ||||
| 8) Add a timeout for streams (how long? 1 minutes?) | ||||
| 6) Add a timeout for streams (how long? 1 minutes?) | ||||
|  | ||||
|  | ||||
| Post-1.0 | ||||
|   | ||||
| @@ -37,43 +37,44 @@ | ||||
| #include <string.h> | ||||
| #include <unistd.h> | ||||
|  | ||||
| #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); | ||||
| } | ||||
|   | ||||
| @@ -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__); \ | ||||
| 		} \ | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -36,8 +36,6 @@ | ||||
| #include <unistd.h> | ||||
| #include <time.h> | ||||
|  | ||||
| #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<<BITS_FOR_VERSION)-1; | ||||
| static void incrPlaylistVersion() { | ||||
| 	static unsigned long max = ((mpd_uint32)1<<31)-1; | ||||
| 	playlist.version++; | ||||
| 	if(playlist.version>=max) playlist.version = 0; | ||||
| 	if(playlist.version>=max) { | ||||
| 		int i; | ||||
|  | ||||
| 		for(i=0; i<playlist.length; i++) { | ||||
| 			playlist.songMod[i] = 0; | ||||
| 		} | ||||
|  | ||||
| 		playlist.version = 1; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void playlistVersionChange() { | ||||
| 	int i = 0; | ||||
|  | ||||
| 	for(i=0; i<playlist.length; i++) { | ||||
| 		playlist.songMod[i] = playlist.version; | ||||
| 	} | ||||
|  | ||||
| 	incrPlaylistVersion(); | ||||
| } | ||||
|  | ||||
| static void incrPlaylistCurrent() { | ||||
| @@ -108,7 +126,7 @@ void initPlaylist() { | ||||
|  | ||||
| 	playlist.length = 0; | ||||
| 	playlist.repeat = 0; | ||||
| 	playlist.version = 0; | ||||
| 	playlist.version = 1; | ||||
| 	playlist.random = 0; | ||||
| 	playlist.queued = -1; | ||||
|         playlist.current = -1; | ||||
| @@ -136,7 +154,8 @@ void initPlaylist() { | ||||
| 	} | ||||
|  | ||||
| 	playlist.songs = malloc(sizeof(Song *)*playlist_max_length); | ||||
| 	playlist.order = malloc(sizeof(Song *)*playlist_max_length); | ||||
| 	playlist.songMod = malloc(sizeof(mpd_uint32)*playlist_max_length); | ||||
| 	playlist.order = malloc(sizeof(int)*playlist_max_length); | ||||
|  | ||||
| 	memset(playlist.songs,0,sizeof(char *)*playlist_max_length); | ||||
|  | ||||
| @@ -155,8 +174,13 @@ void finishPlaylist() { | ||||
| 			freeJustSong(playlist.songs[i]); | ||||
| 		} | ||||
|         } | ||||
|  | ||||
| 	playlist.length = 0; | ||||
|  | ||||
| 	free(playlist.songs); | ||||
| 	playlist.songs = NULL; | ||||
| 	free(playlist.songMod); | ||||
| 	playlist.songMod = NULL; | ||||
| 	free(playlist.order); | ||||
| 	playlist.order = NULL; | ||||
| } | ||||
| @@ -364,8 +388,32 @@ void readPlaylistState() { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int playlistInfo(FILE * fp,int song) { | ||||
| void printPlaylistSongInfo(FILE * fp, int song) { | ||||
| 	MpdTag * tag; | ||||
| 	 | ||||
| 	myfprintf(fp, "file: %s\n", (playlist.songs[song])->utf8url); | ||||
| 	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.length; i++) { | ||||
| 		if(version > 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;i<end;i++) { | ||||
| 		myfprintf(fp,"file: %s\n",(playlist.songs[i])->utf8url); | ||||
| 		if((tag = (playlist.songs[i])->tag)) { | ||||
| 			printMpdTag(fp,tag); | ||||
| 		} | ||||
| 	}  | ||||
| 	for(i=begin; i<end; i++) printPlaylistSongInfo(fp, i); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
| @@ -396,6 +439,8 @@ void swapSongs(int song1, int song2) { | ||||
| 	temp = playlist.songs[song1]; | ||||
| 	playlist.songs[song1] = playlist.songs[song2]; | ||||
| 	playlist.songs[song2] = temp; | ||||
| 	playlist.songMod[song1] = playlist.version; | ||||
| 	playlist.songMod[song2] = playlist.version; | ||||
| } | ||||
|  | ||||
| void queueNextSongInPlaylist() { | ||||
| @@ -512,6 +557,7 @@ int addSongToPlaylist(FILE * fp, Song * song) { | ||||
| 	} | ||||
|  | ||||
| 	playlist.songs[playlist.length] = song; | ||||
| 	playlist.songMod[playlist.length] = playlist.version; | ||||
| 	playlist.order[playlist.length] = playlist.length; | ||||
| 	playlist.length++; | ||||
|  | ||||
| @@ -613,6 +659,7 @@ int deleteFromPlaylist(FILE * fp, int song) { | ||||
| 	/* delete song from songs array */ | ||||
| 	for(i=song;i<playlist.length-1;i++) { | ||||
| 		playlist.songs[i] = playlist.songs[i+1]; | ||||
| 		playlist.songMod[i] = playlist.version; | ||||
| 	} | ||||
| 	/* now find it in the order array */ | ||||
| 	for(i=0;i<playlist.length-1;i++) { | ||||
| @@ -746,12 +793,14 @@ int playPlaylist(FILE * fp, int song, int stopOnError) { | ||||
| void syncCurrentPlayerDecodeMetadata() { | ||||
|         Song * songPlayer = playerCurrentDecodeSong(); | ||||
|         Song * song; | ||||
| 	int songNum; | ||||
|  | ||||
|         if(!songPlayer) return; | ||||
|  | ||||
| 	if(playlist_state!=PLAYLIST_STATE_PLAY) return; | ||||
|  | ||||
|         song = playlist.songs[playlist.order[playlist.current]]; | ||||
| 	songNum = playlist.order[playlist.current]; | ||||
|         song = playlist.songs[songNum]; | ||||
|  | ||||
|         if(song->type == 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;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; | ||||
| 	} | ||||
| 	/* move songs to one more in to->from */ | ||||
| 	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<playlist.length;i++) { | ||||
|   | ||||
| @@ -22,6 +22,7 @@ | ||||
| #include "../config.h" | ||||
|  | ||||
| #include "song.h" | ||||
| #include "mpd_types.h" | ||||
|  | ||||
| #include <stdio.h> | ||||
| #include <sys/param.h> | ||||
| @@ -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: */ | ||||
|   | ||||
| @@ -44,7 +44,7 @@ int handlePendingSignals() { | ||||
| 		signal_clear(SIGHUP); | ||||
| 		if(!isUpdatingDB()) { | ||||
|                         readDirectoryDB(); | ||||
| 		        incrPlaylistVersion(); | ||||
| 		        playlistVersionChange(); | ||||
|                 } | ||||
|                 if(myfprintfCloseAndOpenLogFile()<0) return COMMAND_RETURN_KILL; | ||||
|                 playerCycleLogFiles(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Warren Dukes
					Warren Dukes