annotate src/audacious/flow.c @ 4598:a2cbde1af409

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