diff options
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | playlist.c | 105 | ||||
-rw-r--r-- | playlist.h | 14 | ||||
-rw-r--r-- | streamer.c | 6 |
4 files changed, 118 insertions, 10 deletions
@@ -531,6 +531,8 @@ main (int argc, char *argv[]) { atexit (atexit_handler); // helps to save in simple cases, like xkill + plt_add (0, "Default"); + // execute server commands in local context int noloadpl = 0; if (argc > 1) { @@ -586,6 +588,7 @@ main (int argc, char *argv[]) { pl_free (); conf_free (); messagepump_free (); + plt_free (); sigterm_handled = 1; fprintf (stderr, "hej-hej!\n"); return 0; @@ -56,15 +56,114 @@ static float pl_totaltime = 0; static playItem_t *playqueue[100]; static int playqueue_count = 0; -static playlist_t dummy_playlist; -static playlist_t *playlist = &dummy_playlist; +static int playlists_count = 0; +static playlist_t *playlists_head = NULL; +static playlist_t *playlist = NULL; // current playlist -playlist_t * +int +plt_get_count (void) { + return playlists_count; +} + +void +plt_add (int before, const char *title) { + playlist_t *plt = malloc (sizeof (playlist_t)); + memset (plt, 0, sizeof (playlist_t)); + plt->title = strdup (title); + + playlist_t *p = NULL; + + if (before > 0) { + p = playlists_head; + int i; + for (i = 0; p && i < before; i++) { + p = p->next; + } + } + + if (!p) { + plt->next = playlists_head; + playlists_head = plt; + } + else { + playlist_t *next = p->next; + p->next = plt; + plt->next = next; + } + if (!playlist) { + playlist = plt; + } + playlists_count++; +} + +void +plt_remove (int plt) { + int i; + playlist_t *prev = NULL; + playlist_t *p = playlists_head; + for (i = 0; p && i < plt; i++) { + prev = p; + p = p->next; + } + if (i != plt) { + trace ("plt_remove %d failed\n", i); + } + if (p) { + if (!prev) { + playlists_head = p->next; + } + else { + prev->next = p->next; + } + } + if (p == playlist) { + playlist = NULL; + } + free (p->title); + free (p); + playlists_count--; +} + +void +plt_set_curr (int plt) { + int i; + playlist_t *p = playlists_head; + for (i = 0; p && i <= plt; i++) { + p = p->next; + } + if (i != plt) { + trace ("plt_set_curr %d failed\n", i); + return; + } + playlist = p; +} + +int plt_get_curr (void) { + int i; + playlist_t *p = playlists_head; + for (i = 0; p && i < playlists_count; i++) { + if (p == playlist) { + return i; + } + p = p->next; + } + return -1; +} + +playlist_t * +plt_get_curr_ptr (void) { return playlist; } void +plt_free (void) { + while (playlists_head) { + plt_remove (0); + } +} + +void pl_free (void) { while (playlist->head[PL_MAIN]) { pl_remove (playlist->head[PL_MAIN]); @@ -54,7 +54,7 @@ typedef struct playItem_s { } playItem_t; typedef struct playlist_s{ - char *fname; + char *title; playItem_t *head[PL_MAX_ITERATORS]; // head of linked list playItem_t *tail[PL_MAX_ITERATORS]; // tail of linked list int current_row[PL_MAX_ITERATORS]; // current row (cursor) @@ -66,17 +66,23 @@ int plt_get_count (void); void -plt_add (int before); +plt_add (int before, const char *title); void plt_remove (int plt); void -plt_set_curr (playlist_t *ptr); +plt_free (void); -playlist_t * +void +plt_set_curr (int plt); + +int plt_get_curr (void); +playlist_t * +plt_get_curr_ptr (void); + // playlist access functions int pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *user_data); @@ -928,7 +928,7 @@ streamer_configchanged (void) { void streamer_play_current_track (void) { - playlist_t *plt = plt_get_curr (); + playlist_t *plt = plt_get_curr_ptr (); if (p_ispaused ()) { // unpause currently paused track p_unpause (); @@ -959,7 +959,7 @@ streamer_play_current_track (void) { int streamer_move_prevsong (void) { - playlist_t *plt = plt_get_curr (); + playlist_t *plt = plt_get_curr_ptr (); pl_playqueue_clear (); if (!plt->head[PL_MAIN]) { streamer_set_nextsong (-2, 1); @@ -1032,7 +1032,7 @@ streamer_move_prevsong (void) { int streamer_move_nextsong (int reason) { - playlist_t *plt = plt_get_curr (); + playlist_t *plt = plt_get_curr_ptr (); playItem_t *it = pl_playqueue_getnext (); if (it) { pl_playqueue_pop (); |