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