diff options
-rw-r--r-- | src/directory.c | 2 | ||||
-rw-r--r-- | src/playlist.c | 16 | ||||
-rw-r--r-- | src/song.c | 17 | ||||
-rw-r--r-- | src/song.h | 14 | ||||
-rw-r--r-- | src/storedPlaylist.c | 2 |
5 files changed, 22 insertions, 29 deletions
diff --git a/src/directory.c b/src/directory.c index de4532e75..5dbab5018 100644 --- a/src/directory.c +++ b/src/directory.c @@ -604,7 +604,7 @@ static int addToDirectory(Directory * directory, const char *name) Song *song; const char *shortname = mpd_basename(name); - if (!(song = newSong(shortname, SONG_TYPE_FILE, directory))) + if (!(song = newSong(shortname, directory))) return -1; songvec_add(&directory->songs, song); LOG("added %s\n", name); diff --git a/src/playlist.c b/src/playlist.c index a91553140..6207ca985 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -187,7 +187,7 @@ void finishPlaylist(void) int i; for (i = playlist.length; --i >= 0; ) { - if (playlist.songs[i]->type == SONG_TYPE_URL) + if (!song_is_file(playlist.songs[i])) freeJustSong(playlist.songs[i]); } @@ -212,7 +212,7 @@ void clearPlaylist(void) stopPlaylist(); for (i = playlist.length; --i >= 0 ; ) { - if (playlist.songs[i]->type == SONG_TYPE_URL) + if (!song_is_file(playlist.songs[i])) freeJustSong(playlist.songs[i]); playlist.idToPosition[playlist.positionToId[i]] = -1; playlist.songs[i] = NULL; @@ -576,7 +576,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id) if ((song = getSongFromDB(url))) { } else if (!(isValidRemoteUtf8Url(url) && - (song = newSong(url, SONG_TYPE_URL, NULL)))) { + (song = newSong(url, NULL)))) { return PLAYLIST_RESULT_NO_SUCH_SONG; } @@ -595,7 +595,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file) if (!isValidRemoteUtf8Url(url)) return ACK_ERROR_NO_EXIST; - if ((song = newSong(url, SONG_TYPE_URL, NULL))) { + if ((song = newSong(url, NULL))) { int ret = appendSongToStoredPlaylistByPath(utf8file, song); freeJustSong(song); return ret; @@ -739,7 +739,7 @@ enum playlist_result deleteFromPlaylist(int song) } } - if (playlist.songs[song]->type == SONG_TYPE_URL) + if (!song_is_file(playlist.songs[song])) freeJustSong(playlist.songs[song]); playlist.idToPosition[playlist.positionToId[song]] = -1; @@ -920,7 +920,7 @@ struct mpd_tag *playlist_current_tag(void) Song *song = song_at(playlist.current); /* Non-file song tags can get swept out from under us */ - return (song && song->type == SONG_TYPE_FILE) ? song->tag : NULL; + return (song && song_is_file(song)) ? song->tag : NULL; } /* This receives dynamic metadata updates from streams */ @@ -932,7 +932,7 @@ static void sync_metadata(void) if (!(tag = metadata_pipe_current())) return; song = song_at(playlist.current); - if (!song || song->type != SONG_TYPE_URL || tag_equal(song->tag, tag)) { + if (!song || song_is_file(song) || tag_equal(song->tag, tag)) { tag_free(tag); return; } @@ -1266,7 +1266,7 @@ enum playlist_result savePlaylist(const char *utf8file) utf8_to_fs_charset(tmp, path_max_tmp); if (playlist_saveAbsolutePaths && - playlist.songs[i]->type == SONG_TYPE_FILE) + song_is_file(playlist.songs[i])) fprintf(fp, "%s\n", rmp2amp_r(tmp, tmp)); else fprintf(fp, "%s\n", tmp); diff --git a/src/song.c b/src/song.c index e1d8bb1b8..ab98963ad 100644 --- a/src/song.c +++ b/src/song.c @@ -29,21 +29,19 @@ #include "os_compat.h" -static Song * -song_alloc(const char *url, enum song_type type, Directory *parent) +static Song * song_alloc(const char *url, Directory *parent) { size_t urllen = strlen(url); Song *song = xmalloc(sizeof(Song) + urllen); song->tag = NULL; memcpy(song->url, url, urllen + 1); - song->type = type; song->parentDir = parent; return song; } -Song *newSong(const char *url, enum song_type type, Directory * parentDir) +Song *newSong(const char *url, Directory * parentDir) { Song *song; @@ -52,11 +50,9 @@ Song *newSong(const char *url, enum song_type type, Directory * parentDir) return NULL; } - song = song_alloc(url, type, parentDir); + song = song_alloc(url, parentDir); - assert(type == SONG_TYPE_URL || parentDir); - - if (song->type == SONG_TYPE_FILE) { + if (song_is_file(song)) { InputPlugin *plugin; unsigned int next = 0; char path_max_tmp[MPD_PATH_MAX]; @@ -166,8 +162,7 @@ void readSongInfoIntoList(FILE * fp, Directory * parentDir) if (!prefixcmp(buffer, SONG_KEY)) { if (song) insertSongIntoList(sv, song); - song = song_alloc(buffer + strlen(SONG_KEY), - SONG_TYPE_FILE, parentDir); + song = song_alloc(buffer + strlen(SONG_KEY), parentDir); } else if (*buffer == 0) { /* ignore empty lines (starting with '\0') */ } else if (song == NULL) { @@ -204,7 +199,7 @@ void readSongInfoIntoList(FILE * fp, Directory * parentDir) int updateSongInfo(Song * song) { - if (song->type == SONG_TYPE_FILE) { + if (song_is_file(song)) { InputPlugin *plugin; unsigned int next = 0; char path_max_tmp[MPD_PATH_MAX]; diff --git a/src/song.h b/src/song.h index aebc8f044..377a78814 100644 --- a/src/song.h +++ b/src/song.h @@ -30,11 +30,6 @@ #define SONG_BEGIN "songList begin" #define SONG_END "songList end" -enum song_type { - SONG_TYPE_FILE = 1, - SONG_TYPE_URL = 2 -}; - #define SONG_FILE "file: " #define SONG_TIME "Time: " @@ -42,12 +37,10 @@ typedef struct _Song { struct mpd_tag *tag; struct _Directory *parentDir; time_t mtime; - enum song_type type; char url[1]; } mpd_packed Song; -Song *newSong(const char *url, enum song_type type, - struct _Directory *parentDir); +Song *newSong(const char *url, struct _Directory *parentDir); void freeSong(Song *); @@ -69,4 +62,9 @@ void printSongUrl(int fd, Song * song); */ char *get_song_url(char *path_max_tmp, Song * song); +static inline int song_is_file(const Song *song) +{ + return !!song->parentDir; +} + #endif diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c index c1452ddb9..265301392 100644 --- a/src/storedPlaylist.c +++ b/src/storedPlaylist.c @@ -297,7 +297,7 @@ appendSongToStoredPlaylistByPath(const char *utf8path, Song *song) s = utf8_to_fs_charset(path_max_tmp2, get_song_url(path_max_tmp, song)); - if (playlist_saveAbsolutePaths && song->type == SONG_TYPE_FILE) + if (playlist_saveAbsolutePaths && song_is_file(song)) s = rmp2amp_r(path_max_tmp, s); fprintf(file, "%s\n", s); |