File: play_queue.c

package info (click to toggle)
cmus 2.2.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,196 kB
  • ctags: 2,714
  • sloc: ansic: 24,078; sh: 1,024; makefile: 209; python: 26
file content (66 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2005-2006 Timo Hirvonen
 */

#include "play_queue.h"
#include "editable.h"
#include "track.h"
#include "xmalloc.h"

struct editable pq_editable;

static void pq_free_track(struct list_head *item)
{
	struct simple_track *track = to_simple_track(item);

	track_info_unref(track->info);
	free(track);
}

void play_queue_init(void)
{
	editable_init(&pq_editable, pq_free_track);
}

void play_queue_append(struct track_info *ti)
{
	struct simple_track *t = simple_track_new(ti);

	editable_add(&pq_editable, t);
}

void play_queue_prepend(struct track_info *ti)
{
	struct simple_track *t = simple_track_new(ti);

	list_add(&t->node, &pq_editable.head);
	pq_editable.nr_tracks++;
	if (t->info->duration != -1)
		pq_editable.total_time += t->info->duration;
	window_changed(pq_editable.win);
}

struct track_info *play_queue_remove(void)
{
	struct list_head *item;
	struct simple_track *t;
	struct track_info *info;
	struct iter iter;

	item = pq_editable.head.next;
	if (item == &pq_editable.head)
		return NULL;

	t = to_simple_track(item);

	editable_track_to_iter(&pq_editable, t, &iter);
	window_row_vanishes(pq_editable.win, &iter);

	pq_editable.nr_marked -= t->marked;
	pq_editable.nr_tracks--;
	list_del(&t->node);

	info = t->info;
	free(t);
	return info;
}