comparison Plugins/Effect/ladspa/ladspa.c @ 306:0e22e4ef781e trunk

[svn] Convert to configdb usage.
author chainsaw
date Sat, 17 Dec 2005 11:40:29 -0800
parents 08e4eb900f21
children d539e5c5f730
comparison
equal deleted inserted replaced
305:edc22c4569ad 306:0e22e4ef781e
26 #include <dirent.h> 26 #include <dirent.h>
27 #include <sys/types.h> 27 #include <sys/types.h>
28 #include <gtk/gtk.h> 28 #include <gtk/gtk.h>
29 29
30 #include <audacious/plugin.h> 30 #include <audacious/plugin.h>
31 #include <libaudacious/configfile.h> 31 #include <libaudacious/configdb.h>
32 32
33 #include "../../../config.h" 33 #include "../../../config.h"
34 #include "ladspa.h" 34 #include "ladspa.h"
35 35
36 #ifndef PATH_MAX 36 #ifndef PATH_MAX
140 state.running = TRUE; 140 state.running = TRUE;
141 } 141 }
142 142
143 static void restore (void) 143 static void restore (void)
144 { 144 {
145 ConfigFile *cfg; 145 ConfigDb *db;
146 gchar *filename;
147 gint k, plugins= 0; 146 gint k, plugins= 0;
148 147
149 filename= g_strdup_printf("%s/%s", g_get_home_dir(), "/.audacious/ladsparc"); 148 db = bmp_cfg_db_open();
150 cfg = xmms_cfg_open_file(filename); 149
151 if (cfg == NULL) { 150 bmp_cfg_db_get_int(db, "ladspa", "plugins", &plugins);
152 state.initialised = TRUE;
153 return;
154 }
155
156 xmms_cfg_read_int(cfg, "session", "plugins", &plugins);
157 for (k= 0; k < plugins; ++k) { 151 for (k= 0; k < plugins; ++k) {
158 gint id; 152 gint id;
159 int port, ports= 0; 153 int port, ports= 0;
160 plugin_instance *instance; 154 plugin_instance *instance;
161 gchar *section = g_strdup_printf("plugin%d", k); 155 gchar *section = g_strdup_printf("ladspa_plugin%d", k);
162 156
163 xmms_cfg_read_int(cfg, section, "id", &id); 157 bmp_cfg_db_get_int(db, section, "id", &id);
164 instance = add_plugin(get_plugin_by_id(id)); 158 instance = add_plugin(get_plugin_by_id(id));
165 if (!instance) continue; /* couldn't load this plugin */ 159 if (!instance) continue; /* couldn't load this plugin */
166 xmms_cfg_read_int(cfg, section, "ports", &ports); 160 bmp_cfg_db_get_int(db, section, "ports", &ports);
167 for (port= 0; port < ports && port < MAX_KNOBS; ++port) { 161 for (port= 0; port < ports && port < MAX_KNOBS; ++port) {
168 gchar *key = g_strdup_printf("port%d", port); 162 gchar *key = g_strdup_printf("port%d", port);
169 xmms_cfg_read_float(cfg, section, key, &(instance->knobs[port])); 163 bmp_cfg_db_get_float(db, section, key, &(instance->knobs[port]));
170 } 164 }
171 instance->restored = TRUE; 165 instance->restored = TRUE;
172 g_free(section); 166 g_free(section);
173 } 167 }
174 168
175 state.initialised = TRUE; 169 state.initialised = TRUE;
176 xmms_cfg_free(cfg); 170 bmp_cfg_db_close(db);
177 g_free(filename);
178 } 171 }
179 172
180 static ladspa_plugin *get_plugin_by_id(unsigned long id) 173 static ladspa_plugin *get_plugin_by_id(unsigned long id)
181 { 174 {
182 GSList *list; 175 GSList *list;
260 } 253 }
261 254
262 static void stop (void) 255 static void stop (void)
263 { 256 {
264 GSList *list; 257 GSList *list;
265 ConfigFile *cfg = xmms_cfg_new(); 258 ConfigDb *db;
266 gchar *filename;
267 gint plugins = 0; 259 gint plugins = 0;
268 260
269 if (state.running == FALSE) { 261 if (state.running == FALSE) {
270 return; 262 return;
271 } 263 }
272 state.running = FALSE; 264 state.running = FALSE;
265 db = bmp_cfg_db_open();
273 G_LOCK (running_plugins); 266 G_LOCK (running_plugins);
274 for (list= running_plugins; list != NULL; list = g_slist_next(list)) { 267 for (list= running_plugins; list != NULL; list = g_slist_next(list)) {
275 plugin_instance *instance = (plugin_instance *) list->data; 268 plugin_instance *instance = (plugin_instance *) list->data;
276 gchar *section = g_strdup_printf("plugin%d", plugins++); 269 gchar *section = g_strdup_printf("ladspa_plugin%d", plugins++);
277 int port, ports= 0; 270 int port, ports= 0;
278 271
279 xmms_cfg_write_int(cfg, section, "id", instance->descriptor->UniqueID); 272 bmp_cfg_db_set_int(db, section, "id", instance->descriptor->UniqueID);
280 xmms_cfg_write_string(cfg, section, "file", instance->filename); 273 bmp_cfg_db_set_string(db, section, "file", instance->filename);
281 xmms_cfg_write_string(cfg, section, "label", (gchar *) 274 bmp_cfg_db_set_string(db, section, "label", (gchar *)
282 instance->descriptor->Label); 275 instance->descriptor->Label);
283 276
284 ports = instance->descriptor->PortCount; 277 ports = instance->descriptor->PortCount;
285 if (ports > MAX_KNOBS) ports = MAX_KNOBS; 278 if (ports > MAX_KNOBS) ports = MAX_KNOBS;
286 for (port= 0; port < ports; ++port) { 279 for (port= 0; port < ports; ++port) {
287 gchar *key = g_strdup_printf("port%d", port); 280 gchar *key = g_strdup_printf("port%d", port);
288 xmms_cfg_write_float(cfg, section, key, instance->knobs[port]); 281 bmp_cfg_db_set_float(db, section, key, instance->knobs[port]);
289 g_free(key); 282 g_free(key);
290 } 283 }
291 xmms_cfg_write_int(cfg, section, "ports", ports); 284 bmp_cfg_db_set_int(db, section, "ports", ports);
292 g_free(section); 285 g_free(section);
293 shutdown (instance); 286 shutdown (instance);
294 } 287 }
295 G_UNLOCK (running_plugins); 288 G_UNLOCK (running_plugins);
296 289
297 xmms_cfg_write_int(cfg, "session", "plugins", plugins); 290 bmp_cfg_db_set_int(db, "ladspa", "plugins", plugins);
298 filename= g_strdup_printf("%s/%s", g_get_home_dir(), "/.audacious/ladsparc"); 291 bmp_cfg_db_close(db);
299 xmms_cfg_write_file(cfg, filename);
300 g_free(filename);
301 xmms_cfg_free(cfg);
302 } 292 }
303 293
304 static void shutdown (plugin_instance *instance) 294 static void shutdown (plugin_instance *instance)
305 { 295 {
306 const LADSPA_Descriptor * descriptor= instance->descriptor; 296 const LADSPA_Descriptor * descriptor= instance->descriptor;