Mercurial > audlegacy
annotate audacious/effect.c @ 2184:7d40f0a290b9 trunk
[svn] - break out string-related functions from util.c
author | nenolod |
---|---|
date | Wed, 20 Dec 2006 06:45:56 -0800 |
parents | f18a5b617c34 |
children | 86f0443d0de2 |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
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 | |
2105
f18a5b617c34
[svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents:
1459
diff
changeset
|
9 * the Free Software Foundation; under version 2 of the License. |
0 | 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, write to the Free Software | |
1459 | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 19 */ |
20 | |
21 #include "effect.h" | |
22 | |
23 #include <glib.h> | |
24 #include <string.h> | |
25 #include "plugin.h" | |
26 | |
27 EffectPluginData ep_data = { | |
28 NULL, | |
29 NULL, | |
30 FALSE, | |
31 FALSE | |
32 }; | |
33 | |
34 static gint | |
35 effect_do_mod_samples(gpointer * data, gint length, | |
36 AFormat fmt, gint srate, gint nch) | |
37 { | |
38 GList *l = ep_data.enabled_list; | |
39 | |
40 while (l) { | |
41 if (l->data) { | |
42 EffectPlugin *ep = l->data; | |
43 if (ep->mod_samples) | |
44 length = ep->mod_samples(data, length, fmt, srate, nch); | |
45 } | |
46 l = g_list_next(l); | |
47 } | |
48 | |
49 return length; | |
50 } | |
51 | |
52 static void | |
53 effect_do_query_format(AFormat * fmt, gint * rate, gint * nch) | |
54 { | |
55 GList *l = ep_data.enabled_list; | |
56 | |
57 while (l) { | |
58 if (l->data) { | |
59 EffectPlugin *ep = l->data; | |
60 if (ep->query_format) | |
61 ep->query_format(fmt, rate, nch); | |
62 } | |
63 l = g_list_next(l); | |
64 } | |
65 } | |
66 | |
67 static EffectPlugin pseudo_effect_plugin = { | |
68 NULL, | |
69 NULL, | |
70 "XMMS Multiple Effects Support", | |
71 NULL, | |
72 NULL, | |
73 NULL, | |
74 NULL, | |
75 effect_do_mod_samples, | |
76 effect_do_query_format | |
77 }; | |
78 | |
79 /* get_current_effect_plugin() and effects_enabled() are still to be used by | |
80 * output plugins as they were when we only supported one effects plugin at | |
81 * a time. We now had a pseudo-effects-plugin that chains all the enabled | |
82 * plugins. -- Jakdaw */ | |
83 | |
84 EffectPlugin * | |
85 get_current_effect_plugin(void) | |
86 { | |
87 return &pseudo_effect_plugin; | |
88 } | |
89 | |
90 gboolean | |
91 effects_enabled(void) | |
92 { | |
93 return TRUE; | |
94 } | |
95 | |
96 GList * | |
97 get_effect_enabled_list(void) | |
98 { | |
99 return ep_data.enabled_list; | |
100 } | |
101 | |
102 void | |
103 effect_about(int i) | |
104 { | |
105 EffectPlugin *effect; | |
106 GList *node = g_list_nth(ep_data.effect_list, i); | |
107 if (node) { | |
108 effect = node->data; | |
109 if (effect && effect->about) | |
110 effect->about(); | |
111 } | |
112 } | |
113 | |
114 void | |
115 effect_configure(int i) | |
116 { | |
117 GList *node = g_list_nth(ep_data.effect_list, i); | |
118 EffectPlugin *effect; | |
119 if (node) { | |
120 effect = node->data; | |
121 if (effect && effect->configure) | |
122 effect->configure(); | |
123 } | |
124 } | |
125 | |
126 | |
127 void | |
128 enable_effect_plugin(int i, gboolean enable) | |
129 { | |
130 GList *node = g_list_nth(ep_data.effect_list, i); | |
131 EffectPlugin *ep; | |
132 | |
133 if (!node || !(node->data)) | |
134 return; | |
135 ep = node->data; | |
136 | |
137 if (enable && !g_list_find(ep_data.enabled_list, ep)) { | |
138 ep_data.enabled_list = g_list_append(ep_data.enabled_list, ep); | |
139 if (ep->init) | |
140 ep->init(); | |
141 } | |
142 else if (!enable && g_list_find(ep_data.enabled_list, ep)) { | |
143 ep_data.enabled_list = g_list_remove(ep_data.enabled_list, ep); | |
144 if (ep->cleanup) | |
145 ep->cleanup(); | |
146 } | |
147 } | |
148 | |
149 GList * | |
150 get_effect_list(void) | |
151 { | |
152 return ep_data.effect_list; | |
153 } | |
154 | |
155 gboolean | |
156 effect_enabled(int i) | |
157 { | |
158 return (g_list_find | |
159 (ep_data.enabled_list, | |
160 (EffectPlugin *) g_list_nth(ep_data.effect_list, | |
161 i)->data) ? TRUE : FALSE); | |
162 } | |
163 | |
164 gchar * | |
165 effect_stringify_enabled_list(void) | |
166 { | |
167 gchar *enalist = NULL, *temp, *temp2; | |
168 GList *node = ep_data.enabled_list; | |
169 | |
170 if (g_list_length(node)) { | |
171 enalist = | |
172 g_strdup(g_basename(((EffectPlugin *) node->data)->filename)); | |
173 node = node->next; | |
174 while (node) { | |
175 temp = enalist; | |
176 temp2 = | |
177 g_strdup(g_basename(((EffectPlugin *) node->data)->filename)); | |
178 enalist = g_strconcat(temp, ",", temp2, NULL); | |
179 g_free(temp); | |
180 g_free(temp2); | |
181 node = node->next; | |
182 } | |
183 } | |
184 return enalist; | |
185 } | |
186 | |
187 void | |
188 effect_enable_from_stringified_list(const gchar * list) | |
189 { | |
190 gchar **plugins, *base; | |
191 GList *node; | |
192 gint i; | |
193 EffectPlugin *ep; | |
194 | |
195 if (!list || !strcmp(list, "")) | |
196 return; | |
197 plugins = g_strsplit(list, ",", 0); | |
198 for (i = 0; plugins[i]; i++) { | |
199 node = ep_data.effect_list; | |
200 while (node) { | |
201 base = | |
202 g_path_get_basename((char *) ((EffectPlugin *) node-> | |
203 data)->filename); | |
204 if (!strcmp(plugins[i], base)) { | |
205 ep = node->data; | |
206 ep_data.enabled_list = | |
207 g_list_append(ep_data.enabled_list, ep); | |
208 if (ep->init) | |
209 ep->init(); | |
210 } | |
211 g_free(base); | |
212 node = node->next; | |
213 } | |
214 } | |
215 g_strfreev(plugins); | |
216 } |