aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/directory.c2
-rw-r--r--src/playlist.c14
-rw-r--r--src/song.c13
-rw-r--r--src/song.h16
-rw-r--r--src/song_save.c2
-rw-r--r--src/storedPlaylist.c2
6 files changed, 22 insertions, 27 deletions
diff --git a/src/directory.c b/src/directory.c
index 0ce533966..8eb18d463 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -617,7 +617,7 @@ 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 e735d7731..b6329cfde 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -174,7 +174,7 @@ void finishPlaylist(void)
{
int i;
for (i = 0; i < playlist.length; i++) {
- if (playlist.songs[i]->type == SONG_TYPE_URL) {
+ if (!song_is_file(playlist.songs[i])) {
freeJustSong(playlist.songs[i]);
}
}
@@ -200,7 +200,7 @@ void clearPlaylist(void)
stopPlaylist();
for (i = 0; i < playlist.length; i++) {
- 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;
@@ -560,7 +560,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;
}
@@ -580,7 +580,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file)
if (!isValidRemoteUtf8Url(url))
return ACK_ERROR_NO_EXIST;
- song = newSong(url, SONG_TYPE_URL, NULL);
+ song = newSong(url, NULL);
if (song) {
int ret = appendSongToStoredPlaylistByPath(utf8file, song);
freeJustSong(song);
@@ -715,7 +715,7 @@ enum playlist_result deleteFromPlaylist(int song)
clearPlayerQueue();
}
- if (playlist.songs[song]->type == SONG_TYPE_URL) {
+ if (!song_is_file(playlist.songs[song])) {
freeJustSong(playlist.songs[song]);
}
@@ -891,7 +891,7 @@ static void syncCurrentPlayerDecodeMetadata(void)
songNum = playlist.order[playlist.current];
song = playlist.songs[songNum];
- if (song->type == SONG_TYPE_URL &&
+ if (!song_is_file(song) &&
0 == strcmp(get_song_url(path_max_tmp, song), songPlayer->url) &&
!tag_equal(song->tag, songPlayer->tag)) {
if (song->tag)
@@ -1267,7 +1267,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 6d689c5c8..54e9ea7e0 100644
--- a/src/song.c
+++ b/src/song.c
@@ -29,20 +29,19 @@
#include "os_compat.h"
Song *
-song_alloc(const char *url, enum song_type type, struct _Directory *parent)
+song_alloc(const char *url, struct _Directory *parent)
{
size_t urllen = strlen(url);
Song *song = xmalloc(sizeof(*song) - sizeof(song->url) + urllen + 1);
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;
@@ -51,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)) {
struct decoder_plugin *plugin;
unsigned int next = 0;
char path_max_tmp[MPD_PATH_MAX];
@@ -91,7 +88,7 @@ void freeJustSong(Song * song)
int updateSongInfo(Song * song)
{
- if (song->type == SONG_TYPE_FILE) {
+ if (song_is_file(song)) {
struct decoder_plugin *plugin;
unsigned int next = 0;
char path_max_tmp[MPD_PATH_MAX];
diff --git a/src/song.h b/src/song.h
index c20bae270..b5f316955 100644
--- a/src/song.h
+++ b/src/song.h
@@ -25,18 +25,12 @@
#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: "
struct client;
typedef struct _Song {
- enum song_type type;
struct tag *tag;
struct _Directory *parentDir;
time_t mtime;
@@ -44,10 +38,9 @@ typedef struct _Song {
} mpd_packed Song;
Song *
-song_alloc(const char *url, enum song_type type, struct _Directory *parent);
+song_alloc(const char *url, struct _Directory *parent);
-Song *newSong(const char *url, enum song_type type,
- struct _Directory *parentDir);
+Song *newSong(const char *url, struct _Directory *parentDir);
void freeSong(Song *);
@@ -63,4 +56,9 @@ int updateSongInfo(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/song_save.c b/src/song_save.c
index 1daf2fe32..4c40a262c 100644
--- a/src/song_save.c
+++ b/src/song_save.c
@@ -112,7 +112,7 @@ void readSongInfoIntoList(FILE *fp, struct songvec *sv,
insertSongIntoList(sv, song);
song = song_alloc(buffer + strlen(SONG_KEY),
- SONG_TYPE_FILE, parentDir);
+ parentDir);
} else if (*buffer == 0) {
/* ignore empty lines (starting with '\0') */
} else if (song == NULL) {
diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c
index 512a29b7c..0f10268d0 100644
--- a/src/storedPlaylist.c
+++ b/src/storedPlaylist.c
@@ -294,7 +294,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);