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).
This commit is contained in:
Eric Wong 2008-10-06 18:52:13 +02:00 committed by Max Kellermann
parent 22e40b61cc
commit f1c53fe0ed
6 changed files with 22 additions and 27 deletions

View File

@ -617,7 +617,7 @@ addToDirectory(Directory * directory, const char *name)
Song *song; Song *song;
const char *shortname = mpd_basename(name); const char *shortname = mpd_basename(name);
if (!(song = newSong(shortname, SONG_TYPE_FILE, directory))) if (!(song = newSong(shortname, directory)))
return -1; return -1;
songvec_add(&directory->songs, song); songvec_add(&directory->songs, song);
LOG("added %s\n", name); LOG("added %s\n", name);

View File

@ -174,7 +174,7 @@ void finishPlaylist(void)
{ {
int i; int i;
for (i = 0; i < playlist.length; 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]); freeJustSong(playlist.songs[i]);
} }
} }
@ -200,7 +200,7 @@ void clearPlaylist(void)
stopPlaylist(); stopPlaylist();
for (i = 0; i < playlist.length; 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]); freeJustSong(playlist.songs[i]);
} }
playlist.idToPosition[playlist.positionToId[i]] = -1; playlist.idToPosition[playlist.positionToId[i]] = -1;
@ -560,7 +560,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id)
if ((song = getSongFromDB(url))) { if ((song = getSongFromDB(url))) {
} else if (!(isValidRemoteUtf8Url(url) && } else if (!(isValidRemoteUtf8Url(url) &&
(song = newSong(url, SONG_TYPE_URL, NULL)))) { (song = newSong(url, NULL)))) {
return PLAYLIST_RESULT_NO_SUCH_SONG; return PLAYLIST_RESULT_NO_SUCH_SONG;
} }
@ -580,7 +580,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file)
if (!isValidRemoteUtf8Url(url)) if (!isValidRemoteUtf8Url(url))
return ACK_ERROR_NO_EXIST; return ACK_ERROR_NO_EXIST;
song = newSong(url, SONG_TYPE_URL, NULL); song = newSong(url, NULL);
if (song) { if (song) {
int ret = appendSongToStoredPlaylistByPath(utf8file, song); int ret = appendSongToStoredPlaylistByPath(utf8file, song);
freeJustSong(song); freeJustSong(song);
@ -715,7 +715,7 @@ enum playlist_result deleteFromPlaylist(int song)
clearPlayerQueue(); clearPlayerQueue();
} }
if (playlist.songs[song]->type == SONG_TYPE_URL) { if (!song_is_file(playlist.songs[song])) {
freeJustSong(playlist.songs[song]); freeJustSong(playlist.songs[song]);
} }
@ -891,7 +891,7 @@ static void syncCurrentPlayerDecodeMetadata(void)
songNum = playlist.order[playlist.current]; songNum = playlist.order[playlist.current];
song = playlist.songs[songNum]; 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) && 0 == strcmp(get_song_url(path_max_tmp, song), songPlayer->url) &&
!tag_equal(song->tag, songPlayer->tag)) { !tag_equal(song->tag, songPlayer->tag)) {
if (song->tag) if (song->tag)
@ -1267,7 +1267,7 @@ enum playlist_result savePlaylist(const char *utf8file)
utf8_to_fs_charset(tmp, path_max_tmp); utf8_to_fs_charset(tmp, path_max_tmp);
if (playlist_saveAbsolutePaths && if (playlist_saveAbsolutePaths &&
playlist.songs[i]->type == SONG_TYPE_FILE) song_is_file(playlist.songs[i]))
fprintf(fp, "%s\n", rmp2amp_r(tmp, tmp)); fprintf(fp, "%s\n", rmp2amp_r(tmp, tmp));
else else
fprintf(fp, "%s\n", tmp); fprintf(fp, "%s\n", tmp);

View File

@ -29,20 +29,19 @@
#include "os_compat.h" #include "os_compat.h"
Song * 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); size_t urllen = strlen(url);
Song *song = xmalloc(sizeof(*song) - sizeof(song->url) + urllen + 1); Song *song = xmalloc(sizeof(*song) - sizeof(song->url) + urllen + 1);
song->tag = NULL; song->tag = NULL;
memcpy(song->url, url, urllen + 1); memcpy(song->url, url, urllen + 1);
song->type = type;
song->parentDir = parent; song->parentDir = parent;
return song; return song;
} }
Song *newSong(const char *url, enum song_type type, Directory * parentDir) Song *newSong(const char *url, Directory * parentDir)
{ {
Song *song; Song *song;
@ -51,11 +50,9 @@ Song *newSong(const char *url, enum song_type type, Directory * parentDir)
return NULL; return NULL;
} }
song = song_alloc(url, type, parentDir); song = song_alloc(url, parentDir);
assert(type == SONG_TYPE_URL || parentDir); if (song_is_file(song)) {
if (song->type == SONG_TYPE_FILE) {
struct decoder_plugin *plugin; struct decoder_plugin *plugin;
unsigned int next = 0; unsigned int next = 0;
char path_max_tmp[MPD_PATH_MAX]; char path_max_tmp[MPD_PATH_MAX];
@ -91,7 +88,7 @@ void freeJustSong(Song * song)
int updateSongInfo(Song * song) int updateSongInfo(Song * song)
{ {
if (song->type == SONG_TYPE_FILE) { if (song_is_file(song)) {
struct decoder_plugin *plugin; struct decoder_plugin *plugin;
unsigned int next = 0; unsigned int next = 0;
char path_max_tmp[MPD_PATH_MAX]; char path_max_tmp[MPD_PATH_MAX];

View File

@ -25,18 +25,12 @@
#define SONG_BEGIN "songList begin" #define SONG_BEGIN "songList begin"
#define SONG_END "songList end" #define SONG_END "songList end"
enum song_type {
SONG_TYPE_FILE = 1,
SONG_TYPE_URL = 2
};
#define SONG_FILE "file: " #define SONG_FILE "file: "
#define SONG_TIME "Time: " #define SONG_TIME "Time: "
struct client; struct client;
typedef struct _Song { typedef struct _Song {
enum song_type type;
struct tag *tag; struct tag *tag;
struct _Directory *parentDir; struct _Directory *parentDir;
time_t mtime; time_t mtime;
@ -44,10 +38,9 @@ typedef struct _Song {
} mpd_packed Song; } mpd_packed Song;
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, Song *newSong(const char *url, struct _Directory *parentDir);
struct _Directory *parentDir);
void freeSong(Song *); void freeSong(Song *);
@ -63,4 +56,9 @@ int updateSongInfo(Song * song);
*/ */
char *get_song_url(char *path_max_tmp, 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 #endif

View File

@ -112,7 +112,7 @@ void readSongInfoIntoList(FILE *fp, struct songvec *sv,
insertSongIntoList(sv, song); insertSongIntoList(sv, song);
song = song_alloc(buffer + strlen(SONG_KEY), song = song_alloc(buffer + strlen(SONG_KEY),
SONG_TYPE_FILE, parentDir); parentDir);
} else if (*buffer == 0) { } else if (*buffer == 0) {
/* ignore empty lines (starting with '\0') */ /* ignore empty lines (starting with '\0') */
} else if (song == NULL) { } else if (song == NULL) {

View File

@ -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)); 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); s = rmp2amp_r(path_max_tmp, s);
fprintf(file, "%s\n", s); fprintf(file, "%s\n", s);