Commit f1c53fe0 authored by Eric Wong's avatar Eric Wong Committed by Max Kellermann

song: stop storing song_type

We already know if a song is a URL or not based on whether it has parentDir defined or not. Hopefully one day in the future we can drop HTTP support from MPD entirely when an HTTP filesystem comes along and we can access streams via open(2).
parent 22e40b61
......@@ -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);
......
......@@ -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);
......
......@@ -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];
......
......@@ -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
......@@ -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) {
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment