5 * Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
7 * Modification for MLT:
8 * Copyright (C) 2004 Ushodaya Enterprises Limited
9 * Author: Dan Dennedy <dan@dennedy.org>
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; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <libxml/tree.h>
35 #include "jack_rack.h"
36 #include "lock_free_fifo.h"
37 #include "plugin_settings.h"
42 #define _x (const xmlChar*)
43 #define _s (const char*)
46 jack_rack_new (const char * client_name, unsigned long channels)
50 rack = g_malloc (sizeof (jack_rack_t));
51 rack->saved_plugins = NULL;
52 rack->channels = channels;
53 rack->procinfo = process_info_new (client_name, channels, FALSE, FALSE);
54 if (!rack->procinfo) {
58 rack->plugin_mgr = plugin_mgr_new ();
59 plugin_mgr_set_plugins (rack->plugin_mgr, channels);
66 jack_rack_destroy (jack_rack_t * jack_rack)
68 process_quit (jack_rack->procinfo);
69 plugin_mgr_destroy (jack_rack->plugin_mgr);
70 process_info_destroy (jack_rack->procinfo);
71 g_slist_free (jack_rack->saved_plugins);
76 jack_rack_instantiate_plugin (jack_rack_t * jack_rack, plugin_desc_t * desc)
80 /* check whether or not the plugin is RT capable and confirm with the user if it isn't */
81 if (!LADSPA_IS_HARD_RT_CAPABLE(desc->properties)) {
82 fprintf (stderr, "Plugin not RT capable. The plugin '%s' does not describe itself as being capable of real-time operation. You may experience drop outs or jack may even kick us out if you use it.\n",
86 /* create the plugin */
87 plugin = plugin_new (desc, jack_rack);
90 fprintf (stderr, "Error loading file plugin '%s' from file '%s'\n",
91 desc->name, desc->object_file);
99 jack_rack_add_saved_plugin (jack_rack_t * jack_rack, saved_plugin_t * saved_plugin)
101 plugin_t * plugin = jack_rack_instantiate_plugin (jack_rack, saved_plugin->settings->desc);
104 jack_rack->saved_plugins = g_slist_append (jack_rack->saved_plugins, saved_plugin);
105 process_add_plugin (jack_rack->procinfo, plugin);
106 jack_rack_add_plugin (jack_rack, plugin);
111 jack_rack_add_plugin (jack_rack_t * jack_rack, plugin_t * plugin)
113 saved_plugin_t * saved_plugin = NULL;
115 unsigned long control, channel;
119 /* see if there's any saved settings that match the plugin id */
120 for (list = jack_rack->saved_plugins; list; list = g_slist_next (list))
122 saved_plugin = list->data;
124 if (saved_plugin->settings->desc->id == plugin->desc->id)
126 /* process the settings! */
127 jack_rack->saved_plugins = g_slist_remove (jack_rack->saved_plugins, saved_plugin);
133 /* initialize plugin parameters */
134 plugin->enabled = settings_get_enabled (saved_plugin->settings);
135 plugin->wet_dry_enabled = settings_get_wet_dry_enabled (saved_plugin->settings);
137 for (control = 0; control < saved_plugin->settings->desc->control_port_count; control++)
138 for (copy = 0; copy < plugin->copies; copy++)
140 value = settings_get_control_value (saved_plugin->settings, copy, control);
141 plugin->holders[copy].control_memory[control] = value;
142 //printf("setting control value %s (%d) = %f\n", saved_plugin->settings->desc->port_names[control], copy, value);
143 // lff_write (plugin->holders[copy].ui_control_fifos + control, &value);
145 if (plugin->wet_dry_enabled)
146 for (channel = 0; channel < jack_rack->channels; channel++)
148 value = settings_get_wet_dry_value (saved_plugin->settings, channel);
149 plugin->wet_dry_values[channel] = value;
150 //printf("setting wet/dry value %d = %f\n", channel, value);
151 // lff_write (plugin->wet_dry_fifos + channel, &value);
157 saved_rack_parse_plugin (jack_rack_t * jack_rack, saved_rack_t * saved_rack, saved_plugin_t * saved_plugin,
158 const char * filename, xmlNodePtr plugin)
160 plugin_desc_t * desc;
161 settings_t * settings = NULL;
166 unsigned long control = 0;
168 xmlFreeFunc xmlFree = NULL;
169 xmlMemGet( &xmlFree, NULL, NULL, NULL);
172 for (node = plugin->children; node; node = node->next)
174 if (xmlStrcmp (node->name, _x("id")) == 0)
176 content = xmlNodeGetContent (node);
177 num = strtoul (_s(content), NULL, 10);
180 desc = plugin_mgr_get_any_desc (jack_rack->plugin_mgr, num);
183 fprintf (stderr, _("The file '%s' contains an unknown plugin with ID '%ld'; skipping\n"), filename, num);
187 settings = settings_new (desc, saved_rack->channels, saved_rack->sample_rate);
189 else if (xmlStrcmp (node->name, _x("enabled")) == 0)
191 content = xmlNodeGetContent (node);
192 settings_set_enabled (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
195 else if (xmlStrcmp (node->name, _x("wet_dry_enabled")) == 0)
197 content = xmlNodeGetContent (node);
198 settings_set_wet_dry_enabled (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
201 else if (xmlStrcmp (node->name, _x("wet_dry_locked")) == 0)
203 content = xmlNodeGetContent (node);
204 settings_set_wet_dry_locked (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
207 else if (xmlStrcmp (node->name, _x("wet_dry_values")) == 0)
209 unsigned long channel = 0;
211 for (sub_node = node->children; sub_node; sub_node = sub_node->next)
213 if (xmlStrcmp (sub_node->name, _x("value")) == 0)
215 content = xmlNodeGetContent (sub_node);
216 settings_set_wet_dry_value (settings, channel, strtod (_s(content), NULL));
223 else if (xmlStrcmp (node->name, _x("lockall")) == 0)
225 content = xmlNodeGetContent (node);
226 settings_set_lock_all (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
229 else if (xmlStrcmp (node->name, _x("controlrow")) == 0)
233 for (sub_node = node->children; sub_node; sub_node = sub_node->next)
235 if (xmlStrcmp (sub_node->name, _x("lock")) == 0)
237 content = xmlNodeGetContent (sub_node);
238 settings_set_lock (settings, control, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
241 else if (xmlStrcmp (sub_node->name, _x("value")) == 0)
243 content = xmlNodeGetContent (sub_node);
244 settings_set_control_value (settings, copy, control, strtod (_s(content), NULL));
255 saved_plugin->settings = settings;
259 saved_rack_parse_jackrack (jack_rack_t * jack_rack, saved_rack_t * saved_rack, const char * filename, xmlNodePtr jackrack)
263 saved_plugin_t * saved_plugin;
265 xmlFreeFunc xmlFree = NULL;
266 xmlMemGet( &xmlFree, NULL, NULL, NULL);
269 for (node = jackrack->children; node; node = node->next)
271 if (xmlStrcmp (node->name, _x("channels")) == 0)
273 content = xmlNodeGetContent (node);
274 saved_rack->channels = strtoul (_s(content), NULL, 10);
277 else if (xmlStrcmp (node->name, _x("samplerate")) == 0)
279 content = xmlNodeGetContent (node);
280 saved_rack->sample_rate = strtoul (_s(content), NULL, 10);
283 else if (xmlStrcmp (node->name, _x("plugin")) == 0)
285 saved_plugin = g_malloc0 (sizeof (saved_plugin_t));
286 saved_rack->plugins = g_slist_append (saved_rack->plugins, saved_plugin);
287 saved_rack_parse_plugin (jack_rack, saved_rack, saved_plugin, filename, node);
292 static saved_rack_t *
293 saved_rack_new (jack_rack_t * jack_rack, const char * filename, xmlDocPtr doc)
296 saved_rack_t *saved_rack;
298 /* create the saved rack */
299 saved_rack = g_malloc (sizeof (saved_rack_t));
300 saved_rack->plugins = NULL;
301 saved_rack->sample_rate = 48000;
302 saved_rack->channels = 2;
304 for (node = doc->children; node; node = node->next)
306 if (xmlStrcmp (node->name, _x("jackrack")) == 0)
307 saved_rack_parse_jackrack (jack_rack, saved_rack, filename, node);
314 saved_rack_destroy (saved_rack_t * saved_rack)
318 for (list = saved_rack->plugins; list; list = g_slist_next (list))
319 settings_destroy (((saved_plugin_t *) list->data)->settings);
320 g_slist_free (saved_rack->plugins);
326 jack_rack_open_file (jack_rack_t * jack_rack, const char * filename)
329 saved_rack_t * saved_rack;
331 saved_plugin_t * saved_plugin;
333 doc = xmlParseFile (filename);
336 fprintf (stderr, _("Could not parse file '%s'\n"), filename);
340 if (xmlStrcmp ( ((xmlDtdPtr)doc->children)->name, _x("jackrack")) != 0)
342 fprintf (stderr, _("The file '%s' is not a JACK Rack settings file\n"), filename);
346 saved_rack = saved_rack_new (jack_rack, filename, doc);
352 for (list = saved_rack->plugins; list; list = g_slist_next (list))
354 saved_plugin = list->data;
356 settings_set_sample_rate (saved_plugin->settings, sample_rate);
358 jack_rack_add_saved_plugin (jack_rack, saved_plugin);
361 saved_rack_destroy (saved_rack);