From 79e8abb461fa848cce3717333ee5cfa55ee91c71 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 10:49:11 +0200 Subject: song: converted typedef Song to struct song Again, a data type which can be forward-declared. [ew: * used "struct mpd_song" instead to avoid token duplication (like I did with "struct mpd_tag") as there's no good abbreviation for "song" and identical tokens on the same line don't read well * rewritten using perl -i -p -e 's/\bSong\b/struct mpd_song/g' src/*.[ch] since it was too hard to merge * also, I don't care much for forward declarations ] --- src/playlist.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index 696636993..ea9f5719c 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -41,7 +41,7 @@ enum _playlist_state { static enum _playlist_state playlist_state; struct _playlist { - Song **songs; + struct mpd_song **songs; /* holds version a song was modified on */ uint32_t *songMod; int *order; @@ -157,7 +157,8 @@ void initPlaylist(void) playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS; - playlist.songs = xcalloc(playlist_max_length, sizeof(Song *)); + playlist.songs = xcalloc(playlist_max_length, + sizeof(struct mpd_song *)); playlist.songMod = xmalloc(sizeof(uint32_t) * playlist_max_length); playlist.order = xmalloc(sizeof(int) * playlist_max_length); playlist.idToPosition = xmalloc(sizeof(int) * playlist_max_length * @@ -440,7 +441,7 @@ enum playlist_result playlistId(int fd, int id) static void swapSongs(int song1, int song2) { - Song *sTemp; + struct mpd_song *sTemp; int iTemp; assert(song1 < playlist.length); @@ -463,7 +464,7 @@ static void swapSongs(int song1, int song2) playlist.positionToId[song2] = iTemp; } -static Song *song_at(int order_num) +static struct mpd_song *song_at(int order_num) { if (order_num >= 0 && order_num < playlist.length) { assert(playlist.songs[playlist.order[order_num]]); @@ -536,7 +537,7 @@ void playlist_queue_next(void) char *playlist_queued_url(char utf8url[MPD_PATH_MAX]) { - Song *song; + struct mpd_song *song; assert(pthread_equal(pthread_self(), dc.thread)); pthread_mutex_lock(&queue_lock); @@ -570,7 +571,7 @@ static int clear_queue(void) enum playlist_result addToPlaylist(const char *url, int *added_id) { - Song *song; + struct mpd_song *song; DEBUG("add to playlist: %s\n", url); @@ -585,7 +586,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id) int addToStoredPlaylist(const char *url, const char *utf8file) { - Song *song; + struct mpd_song *song; DEBUG("add to stored playlist: %s\n", url); @@ -604,7 +605,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file) return ACK_ERROR_NO_EXIST; } -enum playlist_result addSongToPlaylist(Song * song, int *added_id) +enum playlist_result addSongToPlaylist(struct mpd_song * song, int *added_id) { int id; @@ -798,7 +799,7 @@ enum playlist_result deleteFromPlaylistById(int id) return deleteFromPlaylist(playlist.idToPosition[id]); } -void deleteASongFromPlaylist(const Song * song) +void deleteASongFromPlaylist(const struct mpd_song * song) { int i; @@ -917,7 +918,7 @@ enum playlist_result playPlaylistById(int id, int stopOnError) /* This is used when we stream data out to shout while playing static files */ struct mpd_tag *playlist_current_tag(void) { - Song *song = song_at(playlist.current); + struct mpd_song *song = song_at(playlist.current); /* Non-file song tags can get swept out from under us */ return (song && song_is_file(song)) ? song->tag : NULL; @@ -926,7 +927,7 @@ struct mpd_tag *playlist_current_tag(void) /* This receives dynamic metadata updates from streams */ static void sync_metadata(void) { - Song *song; + struct mpd_song *song; struct mpd_tag *tag; if (!(tag = metadata_pipe_current())) @@ -998,7 +999,7 @@ void setPlaylistRepeatStatus(int status) enum playlist_result moveSongInPlaylist(int from, int to) { int i; - Song *tmpSong; + struct mpd_song *tmpSong; int tmpId; int currentSong; int queued_is_current = (playlist.queued == playlist.current); @@ -1361,7 +1362,7 @@ int PlaylistInfo(int fd, const char *utf8file, int detail) int wrote = 0; if (detail) { - Song *song = getSongFromDB(temp); + struct mpd_song *song = getSongFromDB(temp); if (song) { song_print_info(song, fd); wrote = 1; -- cgit v1.2.3 From 5f15ba96cf5fa641d34d4e98ae8e0972fa6fef0c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:05:02 +0200 Subject: playlist: simplified setPlaylistRandomStatus() Check the old status before assigning. This saves a temporary variable. --- src/playlist.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index ea9f5719c..02800c2ba 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -1146,11 +1146,7 @@ static void randomizeOrder(int start, int end) void setPlaylistRandomStatus(int status) { - int statusWas = playlist.random; - - playlist.random = status; - - if (status != statusWas) { + if (status != playlist.random) { if (playlist.random) randomizeOrder(0, playlist.length - 1); else -- cgit v1.2.3 From d24e17ebdd5eeb16c87b897a9ecb52a5704a52b3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:05:25 +0200 Subject: song: replaced all song constructors Provide separate constructors for creating a remote song, a local song, and one for loading data from a song file. This way, we can add more assertions. --- src/playlist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index 02800c2ba..22df8be5d 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -577,7 +577,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id) if ((song = getSongFromDB(url))) { } else if (!(isValidRemoteUtf8Url(url) && - (song = newSong(url, NULL)))) { + (song = song_remote_new(url)))) { return PLAYLIST_RESULT_NO_SUCH_SONG; } @@ -596,7 +596,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file) if (!isValidRemoteUtf8Url(url)) return ACK_ERROR_NO_EXIST; - if ((song = newSong(url, NULL))) { + if ((song = song_remote_new(url))) { int ret = appendSongToStoredPlaylistByPath(utf8file, song); freeJustSong(song); return ret; -- cgit v1.2.3 From e6f87010949c1d659b27c5db5707e23230d3eaf0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:05:34 +0200 Subject: song: removed CamelCase CamelCase is ugly... rename all functions. --- src/playlist.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index 22df8be5d..24f74b02d 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -189,7 +189,7 @@ void finishPlaylist(void) for (i = playlist.length; --i >= 0; ) { if (!song_is_file(playlist.songs[i])) - freeJustSong(playlist.songs[i]); + song_free(playlist.songs[i]); } playlist.length = 0; @@ -214,7 +214,7 @@ void clearPlaylist(void) for (i = playlist.length; --i >= 0 ; ) { if (!song_is_file(playlist.songs[i])) - freeJustSong(playlist.songs[i]); + song_free(playlist.songs[i]); playlist.idToPosition[playlist.positionToId[i]] = -1; playlist.songs[i] = NULL; } @@ -236,7 +236,7 @@ void showPlaylist(int fd) for (i = 0; i < playlist.length; i++) fdprintf(fd, "%i:%s\n", i, - get_song_url(path_max_tmp, playlist.songs[i])); + song_get_url(playlist.songs[i], path_max_tmp)); } void savePlaylistState(int fd) @@ -543,7 +543,7 @@ char *playlist_queued_url(char utf8url[MPD_PATH_MAX]) pthread_mutex_lock(&queue_lock); song = song_at(playlist.queued); - return song ? get_song_url(utf8url, song) : NULL; + return song ? song_get_url(song, utf8url) : NULL; } static void queue_song_locked(int order_num) @@ -598,7 +598,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file) if ((song = song_remote_new(url))) { int ret = appendSongToStoredPlaylistByPath(utf8file, song); - freeJustSong(song); + song_free(song); return ret; } @@ -741,7 +741,7 @@ enum playlist_result deleteFromPlaylist(int song) } if (!song_is_file(playlist.songs[song])) - freeJustSong(playlist.songs[song]); + song_free(playlist.songs[song]); playlist.idToPosition[playlist.positionToId[song]] = -1; @@ -842,7 +842,7 @@ static void play_order_num(int order_num, float seek_time) assert(song_at(order_num)); DEBUG("playlist: play %i:\"%s\"\n", order_num, - get_song_url(path, song_at(order_num))); + song_get_url(song_at(order_num), path)); dc_trigger_action(DC_ACTION_STOP, 0); queue_song_locked(order_num); @@ -1259,7 +1259,7 @@ enum playlist_result savePlaylist(const char *utf8file) for (i = 0; i < playlist.length; i++) { char tmp[MPD_PATH_MAX]; - get_song_url(path_max_tmp, playlist.songs[i]); + song_get_url(playlist.songs[i], path_max_tmp); utf8_to_fs_charset(tmp, path_max_tmp); if (playlist_saveAbsolutePaths && @@ -1326,7 +1326,7 @@ enum playlist_result seekSongInPlaylist(int song, float seek_time) */ } - DEBUG("playlist: seek %i:\"%s\"\n", i, get_song_url(path, song_at(i))); + DEBUG("playlist: seek %i:\"%s\"\n", i, song_get_url(song_at(i), path)); play_order_num(i, seek_time); return PLAYLIST_RESULT_SUCCESS; } -- cgit v1.2.3 From 729523ec80f35a683c982054628cd47d2161d3d4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:07:35 +0200 Subject: directory: moved code to database.c Taming the directory.c monster, part II: move the database management stuff to database. directory.c should only contain code which works on directory objects. --- src/playlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index 24f74b02d..118733543 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -22,7 +22,7 @@ #include "ls.h" #include "tag.h" #include "conf.h" -#include "directory.h" +#include "database.h" #include "log.h" #include "path.h" #include "utils.h" -- cgit v1.2.3 From 4629f646077109f7c6185aab92560da52c237412 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:07:55 +0200 Subject: database: renamed functions, "db_" prefix and no CamelCase Yet another CamelCase removal patch. --- src/playlist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/playlist.c') diff --git a/src/playlist.c b/src/playlist.c index 118733543..8a7b5cf7f 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -575,7 +575,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id) DEBUG("add to playlist: %s\n", url); - if ((song = getSongFromDB(url))) { + if ((song = db_get_song(url))) { } else if (!(isValidRemoteUtf8Url(url) && (song = song_remote_new(url)))) { return PLAYLIST_RESULT_NO_SUCH_SONG; @@ -590,7 +590,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file) DEBUG("add to stored playlist: %s\n", url); - if ((song = getSongFromDB(url))) + if ((song = db_get_song(url))) return appendSongToStoredPlaylistByPath(utf8file, song); if (!isValidRemoteUtf8Url(url)) @@ -1358,7 +1358,7 @@ int PlaylistInfo(int fd, const char *utf8file, int detail) int wrote = 0; if (detail) { - struct mpd_song *song = getSongFromDB(temp); + struct mpd_song *song = db_get_song(temp); if (song) { song_print_info(song, fd); wrote = 1; -- cgit v1.2.3