playlist: renamed global "playlist" variable to "g_playlist"

Export the "g_playlist" variable, and pass it to all playlist
functions.  This way, we can split playlist.c easier into separate
parts.  The code which initializes the singleton variable is moved to
playlist_global.c.
This commit is contained in:
Max Kellermann 2009-02-04 18:56:41 +01:00
parent 1720c7090d
commit 8d3205871c
11 changed files with 503 additions and 400 deletions

View File

@ -182,6 +182,7 @@ mpd_SOURCES = \
player_thread.c \ player_thread.c \
player_control.c \ player_control.c \
playlist.c \ playlist.c \
playlist_global.c \
playlist_print.c \ playlist_print.c \
playlist_save.c \ playlist_save.c \
playlist_state.c \ playlist_state.c \

View File

@ -392,7 +392,7 @@ handle_play(struct client *client, int argc, char *argv[])
if (argc == 2 && !check_int(client, &song, argv[1], need_positive)) if (argc == 2 && !check_int(client, &song, argv[1], need_positive))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playPlaylist(song); result = playPlaylist(&g_playlist, song);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -405,7 +405,7 @@ handle_playid(struct client *client, int argc, char *argv[])
if (argc == 2 && !check_int(client, &id, argv[1], need_positive)) if (argc == 2 && !check_int(client, &id, argv[1], need_positive))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playPlaylistById(id); result = playPlaylistById(&g_playlist, id);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -413,7 +413,7 @@ static enum command_return
handle_stop(G_GNUC_UNUSED struct client *client, handle_stop(G_GNUC_UNUSED struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
stopPlaylist(); stopPlaylist(&g_playlist);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -421,8 +421,8 @@ static enum command_return
handle_currentsong(struct client *client, handle_currentsong(struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
int song = getPlaylistCurrentSong(); int song = getPlaylistCurrentSong(&g_playlist);
const struct queue *queue = playlist_get_queue(); const struct queue *queue = playlist_get_queue(&g_playlist);
if (song >= 0) if (song >= 0)
queue_print_info(client, queue, song, song + 1); queue_print_info(client, queue, song, song + 1);
@ -475,19 +475,19 @@ handle_status(struct client *client,
COMMAND_STATUS_CROSSFADE ": %i\n" COMMAND_STATUS_CROSSFADE ": %i\n"
COMMAND_STATUS_STATE ": %s\n", COMMAND_STATUS_STATE ": %s\n",
volume_level_get(), volume_level_get(),
getPlaylistRepeatStatus(), getPlaylistRepeatStatus(&g_playlist),
getPlaylistRandomStatus(), getPlaylistRandomStatus(&g_playlist),
getPlaylistVersion(), getPlaylistVersion(&g_playlist),
getPlaylistLength(), getPlaylistLength(&g_playlist),
(int)(getPlayerCrossFade() + 0.5), (int)(getPlayerCrossFade() + 0.5),
state); state);
song = getPlaylistCurrentSong(); song = getPlaylistCurrentSong(&g_playlist);
if (song >= 0) { if (song >= 0) {
client_printf(client, client_printf(client,
COMMAND_STATUS_SONG ": %i\n" COMMAND_STATUS_SONG ": %i\n"
COMMAND_STATUS_SONGID ": %u\n", COMMAND_STATUS_SONGID ": %u\n",
song, getPlaylistSongId(song)); song, getPlaylistSongId(&g_playlist, song));
} }
if (getPlayerState() != PLAYER_STATE_STOP) { if (getPlayerState() != PLAYER_STATE_STOP) {
@ -540,7 +540,8 @@ handle_add(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
#ifdef WIN32 #ifdef WIN32
result = PLAYLIST_RESULT_DENIED; result = PLAYLIST_RESULT_DENIED;
#else #else
result = playlist_append_file(uri + 7, client_get_uid(client), result = playlist_append_file(&g_playlist,
uri + 7, client_get_uid(client),
NULL); NULL);
#endif #endif
return print_playlist_result(client, result); return print_playlist_result(client, result);
@ -553,7 +554,7 @@ handle_add(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
return addToPlaylist(uri, NULL); return addToPlaylist(&g_playlist, uri, NULL);
} }
result = addAllIn(uri); result = addAllIn(uri);
@ -577,7 +578,7 @@ handle_addid(struct client *client, int argc, char *argv[])
#ifdef WIN32 #ifdef WIN32
result = PLAYLIST_RESULT_DENIED; result = PLAYLIST_RESULT_DENIED;
#else #else
result = playlist_append_file(uri + 7, result = playlist_append_file(&g_playlist, uri + 7,
client_get_uid(client), client_get_uid(client),
&added_id); &added_id);
#endif #endif
@ -588,7 +589,7 @@ handle_addid(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
result = addToPlaylist(uri, &added_id); result = addToPlaylist(&g_playlist, uri, &added_id);
} }
if (result != PLAYLIST_RESULT_SUCCESS) if (result != PLAYLIST_RESULT_SUCCESS)
@ -598,11 +599,11 @@ handle_addid(struct client *client, int argc, char *argv[])
int to; int to;
if (!check_int(client, &to, argv[2], check_integer, argv[2])) if (!check_int(client, &to, argv[2], check_integer, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = moveSongInPlaylistById(added_id, to); result = moveSongInPlaylistById(&g_playlist, added_id, to);
if (result != PLAYLIST_RESULT_SUCCESS) { if (result != PLAYLIST_RESULT_SUCCESS) {
enum command_return ret = enum command_return ret =
print_playlist_result(client, result); print_playlist_result(client, result);
deleteFromPlaylistById(added_id); deleteFromPlaylistById(&g_playlist, added_id);
return ret; return ret;
} }
} }
@ -620,7 +621,7 @@ handle_delete(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_int(client, &song, argv[1], need_positive)) if (!check_int(client, &song, argv[1], need_positive))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = deleteFromPlaylist(song); result = deleteFromPlaylist(&g_playlist, song);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -633,7 +634,7 @@ handle_deleteid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_int(client, &id, argv[1], need_positive)) if (!check_int(client, &id, argv[1], need_positive))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = deleteFromPlaylistById(id); result = deleteFromPlaylistById(&g_playlist, id);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -641,7 +642,7 @@ static enum command_return
handle_playlist(struct client *client, handle_playlist(struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
const struct queue *queue = playlist_get_queue(); const struct queue *queue = playlist_get_queue(&g_playlist);
queue_print_uris(client, queue, 0, queue_length(queue)); queue_print_uris(client, queue, 0, queue_length(queue));
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
@ -651,7 +652,7 @@ static enum command_return
handle_shuffle(G_GNUC_UNUSED struct client *client, handle_shuffle(G_GNUC_UNUSED struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
shufflePlaylist(); shufflePlaylist(&g_playlist);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -659,7 +660,7 @@ static enum command_return
handle_clear(G_GNUC_UNUSED struct client *client, handle_clear(G_GNUC_UNUSED struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
clearPlaylist(); clearPlaylist(&g_playlist);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -669,7 +670,7 @@ handle_save(struct client *client,
{ {
enum playlist_result result; enum playlist_result result;
result = spl_save_queue(argv[1], playlist_get_queue()); result = spl_save_queue(argv[1], playlist_get_queue(&g_playlist));
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -678,7 +679,7 @@ handle_load(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
{ {
enum playlist_result result; enum playlist_result result;
result = playlist_load_spl(argv[1]); result = playlist_load_spl(&g_playlist, argv[1]);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -761,7 +762,7 @@ static enum command_return
handle_plchanges(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) handle_plchanges(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
{ {
uint32_t version; uint32_t version;
const struct queue *queue = playlist_get_queue(); const struct queue *queue = playlist_get_queue(&g_playlist);
if (!check_uint32(client, &version, argv[1], need_positive)) if (!check_uint32(client, &version, argv[1], need_positive))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
@ -774,7 +775,7 @@ static enum command_return
handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[]) handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
{ {
uint32_t version; uint32_t version;
const struct queue *queue = playlist_get_queue(); const struct queue *queue = playlist_get_queue(&g_playlist);
if (!check_uint32(client, &version, argv[1], need_positive)) if (!check_uint32(client, &version, argv[1], need_positive))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
@ -787,7 +788,7 @@ static enum command_return
handle_playlistinfo(struct client *client, int argc, char *argv[]) handle_playlistinfo(struct client *client, int argc, char *argv[])
{ {
unsigned start = 0, end = UINT_MAX; unsigned start = 0, end = UINT_MAX;
const struct queue *queue = playlist_get_queue(); const struct queue *queue = playlist_get_queue(&g_playlist);
if (argc == 2 && !check_range(client, &start, &end, if (argc == 2 && !check_range(client, &start, &end,
argv[1], need_range)) argv[1], need_range))
@ -809,7 +810,7 @@ handle_playlistid(struct client *client, int argc, char *argv[])
{ {
int id = -1, start; int id = -1, start;
unsigned end; unsigned end;
const struct queue *queue = playlist_get_queue(); const struct queue *queue = playlist_get_queue(&g_playlist);
if (argc == 2 && !check_int(client, &id, argv[1], need_positive)) if (argc == 2 && !check_int(client, &id, argv[1], need_positive))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
@ -919,7 +920,7 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
queue_find(client, playlist_get_queue(), list); queue_find(client, playlist_get_queue(&g_playlist), list);
locate_item_list_free(list); locate_item_list_free(list);
@ -940,7 +941,7 @@ handle_playlistsearch(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
queue_search(client, playlist_get_queue(), list); queue_search(client, playlist_get_queue(&g_playlist), list);
locate_item_list_free(list); locate_item_list_free(list);
@ -1002,7 +1003,7 @@ static enum command_return
handle_next(G_GNUC_UNUSED struct client *client, handle_next(G_GNUC_UNUSED struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
nextSongInPlaylist(); nextSongInPlaylist(&g_playlist);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -1010,7 +1011,7 @@ static enum command_return
handle_previous(G_GNUC_UNUSED struct client *client, handle_previous(G_GNUC_UNUSED struct client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
previousSongInPlaylist(); previousSongInPlaylist(&g_playlist);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -1077,7 +1078,7 @@ handle_repeat(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
setPlaylistRepeatStatus(status); setPlaylistRepeatStatus(&g_playlist, status);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -1095,7 +1096,7 @@ handle_random(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
setPlaylistRandomStatus(status); setPlaylistRandomStatus(&g_playlist, status);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
@ -1177,7 +1178,7 @@ handle_move(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_int(client, &to, argv[2], check_integer, argv[2])) if (!check_int(client, &to, argv[2], check_integer, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = moveSongInPlaylist(from, to); result = moveSongInPlaylist(&g_playlist, from, to);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -1191,7 +1192,7 @@ handle_moveid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_int(client, &to, argv[2], check_integer, argv[2])) if (!check_int(client, &to, argv[2], check_integer, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = moveSongInPlaylistById(id, to); result = moveSongInPlaylistById(&g_playlist, id, to);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -1205,7 +1206,7 @@ handle_swap(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_int(client, &song2, argv[2], check_integer, argv[2])) if (!check_int(client, &song2, argv[2], check_integer, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = swapSongsInPlaylist(song1, song2); result = swapSongsInPlaylist(&g_playlist, song1, song2);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -1219,7 +1220,7 @@ handle_swapid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_int(client, &id2, argv[2], check_integer, argv[2])) if (!check_int(client, &id2, argv[2], check_integer, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = swapSongsInPlaylistById(id1, id2); result = swapSongsInPlaylistById(&g_playlist, id1, id2);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -1234,7 +1235,7 @@ handle_seek(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_int(client, &seek_time, argv[2], check_integer, argv[2])) if (!check_int(client, &seek_time, argv[2], check_integer, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = seekSongInPlaylist(song, seek_time); result = seekSongInPlaylist(&g_playlist, song, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
@ -1249,7 +1250,7 @@ handle_seekid(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_int(client, &seek_time, argv[2], check_integer, argv[2])) if (!check_int(client, &seek_time, argv[2], check_integer, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = seekSongInPlaylistById(id, seek_time); result = seekSongInPlaylistById(&g_playlist, id, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }

View File

@ -168,7 +168,7 @@ int printAllIn(struct client *client, const char *name)
static int static int
directoryAddSongToPlaylist(struct song *song, G_GNUC_UNUSED void *data) directoryAddSongToPlaylist(struct song *song, G_GNUC_UNUSED void *data)
{ {
return addSongToPlaylist(song, NULL); return addSongToPlaylist(&g_playlist, song, NULL);
} }
struct add_data { struct add_data {

View File

@ -235,7 +235,6 @@ int main(int argc, char *argv[])
event_pipe_init(); event_pipe_init();
event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted); event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted);
event_pipe_register(PIPE_EVENT_PLAYLIST, syncPlayerAndPlaylist);
path_global_init(); path_global_init();
mapper_init(); mapper_init();

File diff suppressed because it is too large Load Diff

View File

@ -83,21 +83,36 @@ struct playlist {
int queued; int queued;
}; };
/** the global playlist object */
extern struct playlist g_playlist;
void initPlaylist(void); void initPlaylist(void);
void finishPlaylist(void); void finishPlaylist(void);
void
playlist_init(struct playlist *playlist);
void
playlist_finish(struct playlist *playlist);
void
playlist_tag_changed(struct playlist *playlist);
/** /**
* Returns the "queue" object of the global playlist instance. * Returns the "queue" object of the global playlist instance.
*/ */
const struct queue * static inline const struct queue *
playlist_get_queue(void); playlist_get_queue(const struct playlist *playlist)
{
return &playlist->queue;
}
void readPlaylistState(FILE *); void readPlaylistState(FILE *);
void savePlaylistState(FILE *); void savePlaylistState(FILE *);
void clearPlaylist(void); void clearPlaylist(struct playlist *playlist);
#ifndef WIN32 #ifndef WIN32
/** /**
@ -105,66 +120,85 @@ void clearPlaylist(void);
* but only if the file's owner is equal to the specified uid. * but only if the file's owner is equal to the specified uid.
*/ */
enum playlist_result enum playlist_result
playlist_append_file(const char *path, int uid, unsigned *added_id); playlist_append_file(struct playlist *playlist, const char *path, int uid,
unsigned *added_id);
#endif #endif
enum playlist_result addToPlaylist(const char *file, unsigned *added_id); enum playlist_result
addToPlaylist(struct playlist *playlist, const char *file, unsigned *added_id);
enum playlist_result enum playlist_result
addSongToPlaylist(struct song *song, unsigned *added_id); addSongToPlaylist(struct playlist *playlist,
struct song *song, unsigned *added_id);
enum playlist_result deleteFromPlaylist(unsigned song); enum playlist_result
deleteFromPlaylist(struct playlist *playlist, unsigned song);
enum playlist_result deleteFromPlaylistById(unsigned song); enum playlist_result
deleteFromPlaylistById(struct playlist *playlist, unsigned song);
void stopPlaylist(void); void stopPlaylist(struct playlist *playlist);
enum playlist_result playPlaylist(int song); enum playlist_result
playPlaylist(struct playlist *playlist, int song);
enum playlist_result playPlaylistById(int song); enum playlist_result
playPlaylistById(struct playlist *playlist, int song);
void nextSongInPlaylist(void); void nextSongInPlaylist(struct playlist *playlist);
void syncPlayerAndPlaylist(void); void syncPlayerAndPlaylist(struct playlist *playlist);
void previousSongInPlaylist(void); void previousSongInPlaylist(struct playlist *playlist);
void shufflePlaylist(void); void shufflePlaylist(struct playlist *playlist);
enum playlist_result savePlaylist(const char *utf8file); enum playlist_result
savePlaylist(struct playlist *playlist, const char *utf8file);
void void
deleteASongFromPlaylist(const struct song *song); deleteASongFromPlaylist(struct playlist *playlist, const struct song *song);
enum playlist_result moveSongInPlaylist(unsigned from, int to); enum playlist_result
moveSongInPlaylist(struct playlist *playlist, unsigned from, int to);
enum playlist_result moveSongInPlaylistById(unsigned id, int to); enum playlist_result
moveSongInPlaylistById(struct playlist *playlist, unsigned id, int to);
enum playlist_result swapSongsInPlaylist(unsigned song1, unsigned song2); enum playlist_result
swapSongsInPlaylist(struct playlist *playlist, unsigned song1, unsigned song2);
enum playlist_result swapSongsInPlaylistById(unsigned id1, unsigned id2); enum playlist_result
swapSongsInPlaylistById(struct playlist *playlist, unsigned id1, unsigned id2);
bool getPlaylistRepeatStatus(void); bool
getPlaylistRepeatStatus(struct playlist *playlist);
void setPlaylistRepeatStatus(bool status); void setPlaylistRepeatStatus(struct playlist *playlist, bool status);
bool getPlaylistRandomStatus(void); bool
getPlaylistRandomStatus(struct playlist *playlist);
void setPlaylistRandomStatus(bool status); void setPlaylistRandomStatus(struct playlist *playlist, bool status);
int getPlaylistCurrentSong(void); int getPlaylistCurrentSong(struct playlist *playlist);
unsigned getPlaylistSongId(unsigned song); unsigned
getPlaylistSongId(struct playlist *playlist, unsigned song);
int getPlaylistLength(void); int getPlaylistLength(struct playlist *playlist);
unsigned long getPlaylistVersion(void); unsigned long
getPlaylistVersion(struct playlist *playlist);
enum playlist_result seekSongInPlaylist(unsigned song, float seek_time); enum playlist_result
seekSongInPlaylist(struct playlist *playlist, unsigned song, float seek_time);
enum playlist_result seekSongInPlaylistById(unsigned id, float seek_time); enum playlist_result
seekSongInPlaylistById(struct playlist *playlist,
unsigned id, float seek_time);
void playlistVersionChange(void); void playlistVersionChange(struct playlist *playlist);
int is_valid_playlist_name(const char *utf8path); int is_valid_playlist_name(const char *utf8path);

63
src/playlist_global.c Normal file
View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2003-2009 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* The manager of the global "struct playlist" instance (g_playlist).
*
*/
#include "playlist.h"
#include "playlist_state.h"
#include "event_pipe.h"
struct playlist g_playlist;
static void
playlist_tag_event(void)
{
playlist_tag_changed(&g_playlist);
}
static void
playlist_event(void)
{
syncPlayerAndPlaylist(&g_playlist);
}
void initPlaylist(void)
{
playlist_init(&g_playlist);
event_pipe_register(PIPE_EVENT_TAG, playlist_tag_event);
event_pipe_register(PIPE_EVENT_PLAYLIST, playlist_event);
}
void finishPlaylist(void)
{
playlist_finish(&g_playlist);
}
void savePlaylistState(FILE *fp)
{
playlist_state_save(fp, &g_playlist);
}
void readPlaylistState(FILE *fp)
{
playlist_state_restore(fp, &g_playlist);
}

View File

@ -98,7 +98,7 @@ spl_save_queue(const char *name_utf8, const struct queue *queue)
} }
enum playlist_result enum playlist_result
playlist_load_spl(const char *name_utf8) playlist_load_spl(struct playlist *playlist, const char *name_utf8)
{ {
GPtrArray *list; GPtrArray *list;
@ -108,7 +108,7 @@ playlist_load_spl(const char *name_utf8)
for (unsigned i = 0; i < list->len; ++i) { for (unsigned i = 0; i < list->len; ++i) {
const char *temp = g_ptr_array_index(list, i); const char *temp = g_ptr_array_index(list, i);
if ((addToPlaylist(temp, NULL)) != PLAYLIST_RESULT_SUCCESS) { if ((addToPlaylist(playlist, temp, NULL)) != PLAYLIST_RESULT_SUCCESS) {
/* for windows compatibility, convert slashes */ /* for windows compatibility, convert slashes */
char *temp2 = g_strdup(temp); char *temp2 = g_strdup(temp);
char *p = temp2; char *p = temp2;
@ -117,7 +117,7 @@ playlist_load_spl(const char *name_utf8)
*p = '/'; *p = '/';
p++; p++;
} }
if ((addToPlaylist(temp, NULL)) != PLAYLIST_RESULT_SUCCESS) { if ((addToPlaylist(playlist, temp, NULL)) != PLAYLIST_RESULT_SUCCESS) {
g_warning("can't add file \"%s\"", temp2); g_warning("can't add file \"%s\"", temp2);
} }
g_free(temp2); g_free(temp2);

View File

@ -42,6 +42,6 @@ spl_save_queue(const char *name_utf8, const struct queue *queue);
* playlist. * playlist.
*/ */
enum playlist_result enum playlist_result
playlist_load_spl(const char *name_utf8); playlist_load_spl(struct playlist *playlist, const char *name_utf8);
#endif #endif

View File

@ -95,13 +95,14 @@ playlist_state_load(FILE *fp, struct playlist *playlist,
song = queue_load_song(&playlist->queue, buffer); song = queue_load_song(&playlist->queue, buffer);
if (song >= 0 && song == current) { if (song >= 0 && song == current) {
if (state != PLAYER_STATE_STOP) { if (state != PLAYER_STATE_STOP) {
playPlaylist(queue_length(&playlist->queue) - 1); playPlaylist(playlist, queue_length(&playlist->queue) - 1);
} }
if (state == PLAYER_STATE_PAUSE) { if (state == PLAYER_STATE_PAUSE) {
playerPause(); playerPause();
} }
if (state != PLAYER_STATE_STOP) { if (state != PLAYER_STATE_STOP) {
seekSongInPlaylist(queue_length(&playlist->queue) - 1, seekSongInPlaylist(playlist,
queue_length(&playlist->queue) - 1,
seek_time); seek_time);
} }
} }
@ -145,9 +146,9 @@ playlist_state_restore(FILE *fp, struct playlist *playlist)
if (strcmp if (strcmp
(&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]), (&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
"1") == 0) { "1") == 0) {
setPlaylistRepeatStatus(true); setPlaylistRepeatStatus(playlist, true);
} else } else
setPlaylistRepeatStatus(false); setPlaylistRepeatStatus(playlist, false);
} else if (g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_CROSSFADE)) { } else if (g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_CROSSFADE)) {
setPlayerCrossFade(atoi setPlayerCrossFade(atoi
(& (&
@ -171,5 +172,5 @@ playlist_state_restore(FILE *fp, struct playlist *playlist)
} }
} }
setPlaylistRandomStatus(random_mode); setPlaylistRandomStatus(playlist, random_mode);
} }

View File

@ -725,7 +725,7 @@ static void song_delete_event(void)
sticker_song_delete(delete); sticker_song_delete(delete);
#endif #endif
deleteASongFromPlaylist(delete); deleteASongFromPlaylist(&g_playlist, delete);
delete = NULL; delete = NULL;
notify_signal(&update_notify); notify_signal(&update_notify);
@ -742,7 +742,7 @@ static void update_finished_event(void)
if (modified) { if (modified) {
/* send "idle" events */ /* send "idle" events */
playlistVersionChange(); playlistVersionChange(&g_playlist);
idle_add(IDLE_DATABASE); idle_add(IDLE_DATABASE);
} }