Add xterm-white.theme
[cmus.git] / play_queue.c
blob05f4872cdf07bacc18304b3b4cf411669dc77d4f
1 /*
2 * Copyright 2005-2006 Timo Hirvonen
3 */
5 #include "play_queue.h"
6 #include "editable.h"
7 #include "track.h"
8 #include "xmalloc.h"
10 struct editable pq_editable;
12 static void pq_free_track(struct list_head *item)
14 struct simple_track *track = to_simple_track(item);
16 track_info_unref(track->info);
17 free(track);
20 void play_queue_init(void)
22 editable_init(&pq_editable, pq_free_track);
25 void play_queue_append(struct track_info *ti)
27 struct simple_track *t = simple_track_new(ti);
29 editable_add(&pq_editable, t);
32 void play_queue_prepend(struct track_info *ti)
34 struct simple_track *t = simple_track_new(ti);
36 list_add(&t->node, &pq_editable.head);
37 pq_editable.nr_tracks++;
38 if (t->info->duration != -1)
39 pq_editable.total_time += t->info->duration;
40 window_changed(pq_editable.win);
43 struct track_info *play_queue_remove(void)
45 struct list_head *item;
46 struct simple_track *t;
47 struct track_info *info;
48 struct iter iter;
50 item = pq_editable.head.next;
51 if (item == &pq_editable.head)
52 return NULL;
54 t = to_simple_track(item);
56 editable_track_to_iter(&pq_editable, t, &iter);
57 window_row_vanishes(pq_editable.win, &iter);
59 pq_editable.nr_marked -= t->marked;
60 pq_editable.nr_tracks--;
61 list_del(&t->node);
63 info = t->info;
64 free(t);
65 return info;