comparison audacious/effect.c @ 0:cb178e5ad177 trunk

[svn] Import audacious source.
author nenolod
date Mon, 24 Oct 2005 03:06:47 -0700
parents
children f12d7e208b43
comparison
equal deleted inserted replaced
-1:000000000000 0:cb178e5ad177
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
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 #include "effect.h"
23
24 #include <glib.h>
25 #include <string.h>
26 #include "plugin.h"
27
28 EffectPluginData ep_data = {
29 NULL,
30 NULL,
31 FALSE,
32 FALSE
33 };
34
35 static gint
36 effect_do_mod_samples(gpointer * data, gint length,
37 AFormat fmt, gint srate, gint nch)
38 {
39 GList *l = ep_data.enabled_list;
40
41 while (l) {
42 if (l->data) {
43 EffectPlugin *ep = l->data;
44 if (ep->mod_samples)
45 length = ep->mod_samples(data, length, fmt, srate, nch);
46 }
47 l = g_list_next(l);
48 }
49
50 return length;
51 }
52
53 static void
54 effect_do_query_format(AFormat * fmt, gint * rate, gint * nch)
55 {
56 GList *l = ep_data.enabled_list;
57
58 while (l) {
59 if (l->data) {
60 EffectPlugin *ep = l->data;
61 if (ep->query_format)
62 ep->query_format(fmt, rate, nch);
63 }
64 l = g_list_next(l);
65 }
66 }
67
68 static EffectPlugin pseudo_effect_plugin = {
69 NULL,
70 NULL,
71 "XMMS Multiple Effects Support",
72 NULL,
73 NULL,
74 NULL,
75 NULL,
76 effect_do_mod_samples,
77 effect_do_query_format
78 };
79
80 /* get_current_effect_plugin() and effects_enabled() are still to be used by
81 * output plugins as they were when we only supported one effects plugin at
82 * a time. We now had a pseudo-effects-plugin that chains all the enabled
83 * plugins. -- Jakdaw */
84
85 EffectPlugin *
86 get_current_effect_plugin(void)
87 {
88 return &pseudo_effect_plugin;
89 }
90
91 gboolean
92 effects_enabled(void)
93 {
94 return TRUE;
95 }
96
97 GList *
98 get_effect_enabled_list(void)
99 {
100 return ep_data.enabled_list;
101 }
102
103 void
104 effect_about(int i)
105 {
106 EffectPlugin *effect;
107 GList *node = g_list_nth(ep_data.effect_list, i);
108 if (node) {
109 effect = node->data;
110 if (effect && effect->about)
111 effect->about();
112 }
113 }
114
115 void
116 effect_configure(int i)
117 {
118 GList *node = g_list_nth(ep_data.effect_list, i);
119 EffectPlugin *effect;
120 if (node) {
121 effect = node->data;
122 if (effect && effect->configure)
123 effect->configure();
124 }
125 }
126
127
128 void
129 enable_effect_plugin(int i, gboolean enable)
130 {
131 GList *node = g_list_nth(ep_data.effect_list, i);
132 EffectPlugin *ep;
133
134 if (!node || !(node->data))
135 return;
136 ep = node->data;
137
138 if (enable && !g_list_find(ep_data.enabled_list, ep)) {
139 ep_data.enabled_list = g_list_append(ep_data.enabled_list, ep);
140 if (ep->init)
141 ep->init();
142 }
143 else if (!enable && g_list_find(ep_data.enabled_list, ep)) {
144 ep_data.enabled_list = g_list_remove(ep_data.enabled_list, ep);
145 if (ep->cleanup)
146 ep->cleanup();
147 }
148 }
149
150 GList *
151 get_effect_list(void)
152 {
153 return ep_data.effect_list;
154 }
155
156 gboolean
157 effect_enabled(int i)
158 {
159 return (g_list_find
160 (ep_data.enabled_list,
161 (EffectPlugin *) g_list_nth(ep_data.effect_list,
162 i)->data) ? TRUE : FALSE);
163 }
164
165 gchar *
166 effect_stringify_enabled_list(void)
167 {
168 gchar *enalist = NULL, *temp, *temp2;
169 GList *node = ep_data.enabled_list;
170
171 if (g_list_length(node)) {
172 enalist =
173 g_strdup(g_basename(((EffectPlugin *) node->data)->filename));
174 node = node->next;
175 while (node) {
176 temp = enalist;
177 temp2 =
178 g_strdup(g_basename(((EffectPlugin *) node->data)->filename));
179 enalist = g_strconcat(temp, ",", temp2, NULL);
180 g_free(temp);
181 g_free(temp2);
182 node = node->next;
183 }
184 }
185 return enalist;
186 }
187
188 void
189 effect_enable_from_stringified_list(const gchar * list)
190 {
191 gchar **plugins, *base;
192 GList *node;
193 gint i;
194 EffectPlugin *ep;
195
196 if (!list || !strcmp(list, ""))
197 return;
198 plugins = g_strsplit(list, ",", 0);
199 for (i = 0; plugins[i]; i++) {
200 node = ep_data.effect_list;
201 while (node) {
202 base =
203 g_path_get_basename((char *) ((EffectPlugin *) node->
204 data)->filename);
205 if (!strcmp(plugins[i], base)) {
206 ep = node->data;
207 ep_data.enabled_list =
208 g_list_append(ep_data.enabled_list, ep);
209 if (ep->init)
210 ep->init();
211 }
212 g_free(base);
213 node = node->next;
214 }
215 }
216 g_strfreev(plugins);
217 }