From 1ca828c49d86c8a42aca8aad2ae6c76fa89035b2 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Wed, 9 Jun 2004 00:18:31 +0000 Subject: implemented song id's now we just need to implement id commands git-svn-id: https://svn.musicpd.org/mpd/trunk@1405 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/playlist.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/playlist.c b/src/playlist.c index 8d5ad150b..1f7c876ed 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -58,11 +58,15 @@ #define PLAYLIST_BUFFER_SIZE 2*MAXPATHLEN +#define PLAYLIST_HASH_MULT 4 + typedef struct _Playlist { Song ** songs; /* holds version a song was modified on */ mpd_uint32 * songMod; int * order; + int * numToId; + int * idToNum; int length; int current; int queued; @@ -123,6 +127,7 @@ static void incrPlaylistCurrent() { void initPlaylist() { char * test; + int i; playlist.length = 0; playlist.repeat = 0; @@ -156,6 +161,9 @@ void initPlaylist() { playlist.songs = malloc(sizeof(Song *)*playlist_max_length); playlist.songMod = malloc(sizeof(mpd_uint32)*playlist_max_length); playlist.order = malloc(sizeof(int)*playlist_max_length); + playlist.idToNum = malloc(sizeof(int)*playlist_max_length* + PLAYLIST_HASH_MULT); + playlist.numToId = malloc(sizeof(int)*playlist_max_length); memset(playlist.songs,0,sizeof(char *)*playlist_max_length); @@ -165,6 +173,22 @@ void initPlaylist() { playlist_stateFile = getConf()[CONF_STATE_FILE]; } + for(i=0; i= playlist_max_length*PLAYLIST_HASH_MULT) { + cur = 0; + } + } + + return cur; } void finishPlaylist() { @@ -183,6 +207,10 @@ void finishPlaylist() { playlist.songMod = NULL; free(playlist.order); playlist.order = NULL; + free(playlist.idToNum); + playlist.idToNum = NULL; + free(playlist.numToId); + playlist.numToId = NULL; } int clearPlaylist(FILE * fp) { @@ -194,6 +222,7 @@ int clearPlaylist(FILE * fp) { if(playlist.songs[i]->type == SONG_TYPE_URL) { freeJustSong(playlist.songs[i]); } + playlist.idToNum[playlist.numToId[i]] = -1; playlist.songs[i] = NULL; } playlist.length = 0; @@ -396,6 +425,7 @@ void printPlaylistSongInfo(FILE * fp, int song) { printMpdTag(fp, tag); } myfprintf(fp, "Num: %i\n", song); + myfprintf(fp, "Id: %i\n", playlist.numToId[song]); } int playlistChanges(FILE * fp, mpd_uint32 version) { @@ -434,13 +464,22 @@ int playlistInfo(FILE * fp, int song) { } void swapSongs(int song1, int song2) { - Song * temp; + Song * sTemp; + int iTemp; - temp = playlist.songs[song1]; + sTemp = playlist.songs[song1]; playlist.songs[song1] = playlist.songs[song2]; - playlist.songs[song2] = temp; + playlist.songs[song2] = sTemp; + playlist.songMod[song1] = playlist.version; playlist.songMod[song2] = playlist.version; + + playlist.idToNum[playlist.numToId[song1]] = song2; + playlist.idToNum[playlist.numToId[song2]] = song1; + + iTemp = playlist.numToId[song1]; + playlist.numToId[song1] = playlist.numToId[song2]; + playlist.numToId[song2] = iTemp; } void queueNextSongInPlaylist() { @@ -559,6 +598,8 @@ int addSongToPlaylist(FILE * fp, Song * song) { playlist.songs[playlist.length] = song; playlist.songMod[playlist.length] = playlist.version; playlist.order[playlist.length] = playlist.length; + playlist.numToId[playlist.length] = getNextId(); + playlist.idToNum[playlist.numToId[playlist.length]] = playlist.length; playlist.length++; if(playlist.random) { @@ -632,6 +673,13 @@ int swapSongsInPlaylist(FILE * fp, int song1, int song2) { return 0; } +#define moveSongFromTo(from, to) { \ + playlist.idToNum[playlist.numToId[from]] = to; \ + playlist.numToId[to] = playlist.numToId[from]; \ + playlist.songs[to] = playlist.songs[from]; \ + playlist.songMod[to] = playlist.version; \ +} + int deleteFromPlaylist(FILE * fp, int song) { int i; int songOrder; @@ -656,10 +704,11 @@ int deleteFromPlaylist(FILE * fp, int song) { freeJustSong(playlist.songs[song]); } + playlist.idToNum[playlist.numToId[song]] = -1; + /* delete song from songs array */ for(i=song;ito */ for(i=from;ifrom */ for(i=from;i>to;i--) { - playlist.songs[i] = playlist.songs[i-1]; - playlist.songMod[i] = playlist.version; + moveSongFromTo(i-1, i); } /* put song at _to_ */ + playlist.idToNum[playlist.numToId[tmpId]] = to; + playlist.numToId[to] = tmpId; playlist.songs[to] = tmpSong; playlist.songMod[to] = playlist.version; /* now deal with order */ -- cgit v1.2.3