Mercurial > audlegacy
annotate src/audacious/flow.c @ 3688:8ab4cd5c6462
multifile plugins :(
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Tue, 02 Oct 2007 21:47:17 -0500 |
parents | cc888ce7b6fb |
children | 6f4068a0f291 |
rev | line source |
---|---|
3551 | 1 /* |
2 * Audacious | |
3 * Copyright (c) 2007 William Pitcock | |
4 * | |
5 * flow.c: flow management API. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; under version 3 of the License. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
18 * | |
19 * The Audacious team does not consider modular code linking to | |
20 * Audacious or using our public API to be a derived work. | |
21 */ | |
22 | |
23 #include "flow.h" | |
24 | |
25 mowgli_object_class_t flow_klass; | |
26 | |
27 static void | |
28 flow_destructor(Flow *flow) | |
29 { | |
30 FlowElement *element, *element2; | |
31 | |
32 g_return_if_fail(flow != NULL); | |
33 | |
34 MOWGLI_ITER_FOREACH_SAFE(element, element2, flow->head) | |
35 g_slice_free(FlowElement, element); | |
36 | |
37 g_slice_free(Flow, flow); | |
38 } | |
39 | |
3558
5aec9950c47a
Add time to flow_execute() and friends.
William Pitcock <nenolod@atheme.org>
parents:
3551
diff
changeset
|
40 void flow_execute(Flow *flow, gint time, gpointer data, gsize len, AFormat fmt, |
3551 | 41 gint srate, gint channels) |
42 { | |
43 FlowElement *element; | |
44 FlowContext context = {}; | |
45 | |
46 g_return_if_fail(flow != NULL); | |
47 g_return_if_fail(data != NULL); | |
48 | |
3558
5aec9950c47a
Add time to flow_execute() and friends.
William Pitcock <nenolod@atheme.org>
parents:
3551
diff
changeset
|
49 context.time = time; |
3551 | 50 context.data = data; |
51 context.len = len; | |
52 context.fmt = fmt; | |
53 context.srate = srate; | |
54 context.channels = channels; | |
55 context.error = FALSE; | |
56 | |
57 MOWGLI_ITER_FOREACH(element, flow->head) | |
58 { | |
59 element->func(&context); | |
60 | |
61 if (context.error) | |
62 break; | |
63 } | |
64 } | |
65 | |
66 Flow * | |
67 flow_new(void) | |
68 { | |
69 static int init = 0; | |
70 Flow *out; | |
71 | |
72 if (!init) | |
73 { | |
74 mowgli_object_class_init(&flow_klass, "audacious.flow", | |
75 (mowgli_destructor_t) flow_destructor, FALSE); | |
76 ++init; | |
77 } | |
78 | |
79 out = g_slice_new0(Flow); | |
80 mowgli_object_init(mowgli_object(out), NULL, &flow_klass, NULL); | |
81 | |
82 return out; | |
83 } | |
84 | |
85 void | |
86 flow_link_element(Flow *flow, FlowFunction func) | |
87 { | |
88 FlowElement *element; | |
89 | |
90 g_return_if_fail(flow != NULL); | |
91 g_return_if_fail(func != NULL); | |
92 | |
93 element = g_slice_new0(FlowElement); | |
94 element->func = func; | |
95 element->prev = flow->tail; | |
96 | |
97 if (flow->tail) | |
98 flow->tail->next = element; | |
99 | |
100 flow->tail = element; | |
3563 | 101 |
102 if (!flow->head) | |
103 flow->head = element; | |
3551 | 104 } |
105 | |
106 /* TBD: unlink all elements of func, or just the first --nenolod */ | |
107 void | |
108 flow_unlink_element(Flow *flow, FlowFunction func) | |
109 { | |
110 FlowElement *iter, *iter2; | |
111 | |
112 g_return_if_fail(flow != NULL); | |
113 g_return_if_fail(func != NULL); | |
114 | |
115 MOWGLI_ITER_FOREACH_SAFE(iter, iter2, flow->head) | |
116 if (iter->func == func) | |
117 { | |
118 if (iter->next) | |
119 iter->next->prev = iter->prev; | |
120 | |
121 iter->prev->next = iter->next; | |
122 | |
3563 | 123 if (flow->tail == iter) |
124 flow->tail = iter->prev; | |
125 | |
126 if (flow->head == iter) | |
127 flow->head = iter->next; | |
128 | |
3551 | 129 g_slice_free(FlowElement, iter); |
130 } | |
131 } |