Mercurial > audlegacy
annotate src/audacious/effect.c @ 3369:676bfd7b6586 trunk
simplified the custom plugin menuentries system, expecially for ui files
author | Giacomo Lozito <james@develia.org> |
---|---|
date | Sun, 19 Aug 2007 13:57:53 +0200 |
parents | f1c756f39e6c |
children | 3092a8b3fe34 |
rev | line source |
---|---|
2313 | 1 /* |
2 * Audacious - Cross-platform multimedia player | |
3 * Copyright (C) 2005-2007 Audacious dvelopment team. | |
4 * | |
5 * Based on BMP: | |
6 * Copyright (C) 2003-2004 BMP development team. | |
7 * | |
8 * Based on XMMS: | |
9 * Copyright (C) 1998-2003 XMMS development team. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2365
diff
changeset
|
13 * the Free Software Foundation; under version 3 of the License. |
2313 | 14 * |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
2365
diff
changeset
|
21 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
22 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
23 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
24 * Audacious or using our public API to be a derived work. |
2313 | 25 */ |
26 | |
27 #include "effect.h" | |
28 | |
29 #include <glib.h> | |
30 #include <string.h> | |
31 #include "plugin.h" | |
32 | |
33 EffectPluginData ep_data = { | |
34 NULL, | |
2365 | 35 NULL |
2313 | 36 }; |
37 | |
38 static gint | |
39 effect_do_mod_samples(gpointer * data, gint length, | |
40 AFormat fmt, gint srate, gint nch) | |
41 { | |
42 GList *l = ep_data.enabled_list; | |
43 | |
44 while (l) { | |
45 if (l->data) { | |
46 EffectPlugin *ep = l->data; | |
47 if (ep->mod_samples) | |
48 length = ep->mod_samples(data, length, fmt, srate, nch); | |
49 } | |
50 l = g_list_next(l); | |
51 } | |
52 | |
53 return length; | |
54 } | |
55 | |
56 static void | |
57 effect_do_query_format(AFormat * fmt, gint * rate, gint * nch) | |
58 { | |
59 GList *l = ep_data.enabled_list; | |
60 | |
61 while (l) { | |
62 if (l->data) { | |
63 EffectPlugin *ep = l->data; | |
64 if (ep->query_format) | |
65 ep->query_format(fmt, rate, nch); | |
66 } | |
67 l = g_list_next(l); | |
68 } | |
69 } | |
70 | |
71 static EffectPlugin pseudo_effect_plugin = { | |
72 NULL, | |
73 NULL, | |
74 "XMMS Multiple Effects Support", | |
75 NULL, | |
76 NULL, | |
77 NULL, | |
78 NULL, | |
79 effect_do_mod_samples, | |
80 effect_do_query_format | |
81 }; | |
82 | |
83 /* get_current_effect_plugin() and effects_enabled() are still to be used by | |
84 * output plugins as they were when we only supported one effects plugin at | |
85 * a time. We now had a pseudo-effects-plugin that chains all the enabled | |
86 * plugins. -- Jakdaw */ | |
87 | |
88 EffectPlugin * | |
89 get_current_effect_plugin(void) | |
90 { | |
91 return &pseudo_effect_plugin; | |
92 } | |
93 | |
94 gboolean | |
95 effects_enabled(void) | |
96 { | |
97 return TRUE; | |
98 } | |
99 | |
100 GList * | |
101 get_effect_enabled_list(void) | |
102 { | |
103 return ep_data.enabled_list; | |
104 } | |
105 | |
106 void | |
107 effect_about(int i) | |
108 { | |
109 EffectPlugin *effect; | |
110 GList *node = g_list_nth(ep_data.effect_list, i); | |
111 if (node) { | |
112 effect = node->data; | |
113 if (effect && effect->about) | |
114 effect->about(); | |
115 } | |
116 } | |
117 | |
118 void | |
119 effect_configure(int i) | |
120 { | |
121 GList *node = g_list_nth(ep_data.effect_list, i); | |
122 EffectPlugin *effect; | |
123 if (node) { | |
124 effect = node->data; | |
125 if (effect && effect->configure) | |
126 effect->configure(); | |
127 } | |
128 } | |
129 | |
130 | |
131 void | |
132 enable_effect_plugin(int i, gboolean enable) | |
133 { | |
134 GList *node = g_list_nth(ep_data.effect_list, i); | |
135 EffectPlugin *ep; | |
136 | |
137 if (!node || !(node->data)) | |
138 return; | |
139 ep = node->data; | |
140 | |
141 if (enable && !g_list_find(ep_data.enabled_list, ep)) { | |
142 ep_data.enabled_list = g_list_append(ep_data.enabled_list, ep); | |
143 if (ep->init) | |
144 ep->init(); | |
145 } | |
146 else if (!enable && g_list_find(ep_data.enabled_list, ep)) { | |
147 ep_data.enabled_list = g_list_remove(ep_data.enabled_list, ep); | |
148 if (ep->cleanup) | |
149 ep->cleanup(); | |
150 } | |
151 } | |
152 | |
153 GList * | |
154 get_effect_list(void) | |
155 { | |
156 return ep_data.effect_list; | |
157 } | |
158 | |
159 gboolean | |
160 effect_enabled(int i) | |
161 { | |
162 return (g_list_find | |
163 (ep_data.enabled_list, | |
164 (EffectPlugin *) g_list_nth(ep_data.effect_list, | |
165 i)->data) ? TRUE : FALSE); | |
166 } | |
167 | |
168 gchar * | |
169 effect_stringify_enabled_list(void) | |
170 { | |
171 gchar *enalist = NULL, *temp, *temp2; | |
172 GList *node = ep_data.enabled_list; | |
173 | |
174 if (g_list_length(node)) { | |
175 enalist = | |
176 g_strdup(g_basename(((EffectPlugin *) node->data)->filename)); | |
177 node = node->next; | |
178 while (node) { | |
179 temp = enalist; | |
180 temp2 = | |
181 g_strdup(g_basename(((EffectPlugin *) node->data)->filename)); | |
182 enalist = g_strconcat(temp, ",", temp2, NULL); | |
183 g_free(temp); | |
184 g_free(temp2); | |
185 node = node->next; | |
186 } | |
187 } | |
188 return enalist; | |
189 } | |
190 | |
191 void | |
192 effect_enable_from_stringified_list(const gchar * list) | |
193 { | |
194 gchar **plugins, *base; | |
195 GList *node; | |
196 gint i; | |
197 EffectPlugin *ep; | |
198 | |
199 if (!list || !strcmp(list, "")) | |
200 return; | |
201 plugins = g_strsplit(list, ",", 0); | |
202 for (i = 0; plugins[i]; i++) { | |
203 node = ep_data.effect_list; | |
204 while (node) { | |
205 base = | |
206 g_path_get_basename((char *) ((EffectPlugin *) node-> | |
207 data)->filename); | |
208 if (!strcmp(plugins[i], base)) { | |
209 ep = node->data; | |
210 ep_data.enabled_list = | |
211 g_list_append(ep_data.enabled_list, ep); | |
212 if (ep->init) | |
213 ep->init(); | |
214 } | |
215 g_free(base); | |
216 node = node->next; | |
217 } | |
218 } | |
219 g_strfreev(plugins); | |
220 } |