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"
38 #include "framework/mlt_log.h"
43 #define _x (const xmlChar*)
44 #define _s (const char*)
47 jack_rack_new (const char * client_name, unsigned long channels)
51 rack = g_malloc (sizeof (jack_rack_t));
52 rack->saved_plugins = NULL;
53 rack->channels = channels;
54 rack->procinfo = process_info_new (client_name, channels, FALSE, FALSE);
55 if (!rack->procinfo) {
59 rack->plugin_mgr = plugin_mgr_new ();
60 plugin_mgr_set_plugins (rack->plugin_mgr, channels);
67 jack_rack_destroy (jack_rack_t * jack_rack)
69 process_quit (jack_rack->procinfo);
70 plugin_mgr_destroy (jack_rack->plugin_mgr);
71 process_info_destroy (jack_rack->procinfo);
72 g_slist_free (jack_rack->saved_plugins);
77 jack_rack_instantiate_plugin (jack_rack_t * jack_rack, plugin_desc_t * desc)
81 /* check whether or not the plugin is RT capable and confirm with the user if it isn't */
82 if (!LADSPA_IS_HARD_RT_CAPABLE(desc->properties)) {
83 mlt_log_info( NULL, "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",
87 /* create the plugin */
88 plugin = plugin_new (desc, jack_rack);
91 mlt_log_error( NULL, "Error loading file plugin '%s' from file '%s'\n",
92 desc->name, desc->object_file);
100 jack_rack_add_saved_plugin (jack_rack_t * jack_rack, saved_plugin_t * saved_plugin)
102 plugin_t * plugin = jack_rack_instantiate_plugin (jack_rack, saved_plugin->settings->desc);
105 jack_rack->saved_plugins = g_slist_append (jack_rack->saved_plugins, saved_plugin);
106 process_add_plugin (jack_rack->procinfo, plugin);
107 jack_rack_add_plugin (jack_rack, plugin);
112 jack_rack_add_plugin (jack_rack_t * jack_rack, plugin_t * plugin)
114 saved_plugin_t * saved_plugin = NULL;
116 unsigned long control, channel;
120 /* see if there's any saved settings that match the plugin id */
121 for (list = jack_rack->saved_plugins; list; list = g_slist_next (list))
123 saved_plugin = list->data;
125 if (saved_plugin->settings->desc->id == plugin->desc->id)
127 /* process the settings! */
128 jack_rack->saved_plugins = g_slist_remove (jack_rack->saved_plugins, saved_plugin);
134 /* initialize plugin parameters */
135 plugin->enabled = settings_get_enabled (saved_plugin->settings);
136 plugin->wet_dry_enabled = settings_get_wet_dry_enabled (saved_plugin->settings);
138 for (control = 0; control < saved_plugin->settings->desc->control_port_count; control++)
139 for (copy = 0; copy < plugin->copies; copy++)
141 value = settings_get_control_value (saved_plugin->settings, copy, control);
142 plugin->holders[copy].control_memory[control] = value;
143 //mlt_log_debug( NULL, "setting control value %s (%d) = %f\n", saved_plugin->settings->desc->port_names[control], copy, value);
144 // lff_write (plugin->holders[copy].ui_control_fifos + control, &value);
146 if (plugin->wet_dry_enabled)
147 for (channel = 0; channel < jack_rack->channels; channel++)
149 value = settings_get_wet_dry_value (saved_plugin->settings, channel);
150 plugin->wet_dry_values[channel] = value;
151 //mlt_log_debug( NULL, "setting wet/dry value %d = %f\n", channel, value);
152 // lff_write (plugin->wet_dry_fifos + channel, &value);
158 saved_rack_parse_plugin (jack_rack_t * jack_rack, saved_rack_t * saved_rack, saved_plugin_t * saved_plugin,
159 const char * filename, xmlNodePtr plugin)
161 plugin_desc_t * desc;
162 settings_t * settings = NULL;
167 unsigned long control = 0;
169 xmlFreeFunc xmlFree = NULL;
170 xmlMemGet( &xmlFree, NULL, NULL, NULL);
173 for (node = plugin->children; node; node = node->next)
175 if (xmlStrcmp (node->name, _x("id")) == 0)
177 content = xmlNodeGetContent (node);
178 num = strtoul (_s(content), NULL, 10);
181 desc = plugin_mgr_get_any_desc (jack_rack->plugin_mgr, num);
184 mlt_log_verbose( NULL, _("The file '%s' contains an unknown plugin with ID '%ld'; skipping\n"), filename, num);
188 settings = settings_new (desc, saved_rack->channels, saved_rack->sample_rate);
190 else if (xmlStrcmp (node->name, _x("enabled")) == 0)
192 content = xmlNodeGetContent (node);
193 settings_set_enabled (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
196 else if (xmlStrcmp (node->name, _x("wet_dry_enabled")) == 0)
198 content = xmlNodeGetContent (node);
199 settings_set_wet_dry_enabled (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
202 else if (xmlStrcmp (node->name, _x("wet_dry_locked")) == 0)
204 content = xmlNodeGetContent (node);
205 settings_set_wet_dry_locked (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
208 else if (xmlStrcmp (node->name, _x("wet_dry_values")) == 0)
210 unsigned long channel = 0;
212 for (sub_node = node->children; sub_node; sub_node = sub_node->next)
214 if (xmlStrcmp (sub_node->name, _x("value")) == 0)
216 content = xmlNodeGetContent (sub_node);
217 settings_set_wet_dry_value (settings, channel, strtod (_s(content), NULL));
224 else if (xmlStrcmp (node->name, _x("lockall")) == 0)
226 content = xmlNodeGetContent (node);
227 settings_set_lock_all (settings, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
230 else if (xmlStrcmp (node->name, _x("controlrow")) == 0)
234 for (sub_node = node->children; sub_node; sub_node = sub_node->next)
236 if (xmlStrcmp (sub_node->name, _x("lock")) == 0)
238 content = xmlNodeGetContent (sub_node);
239 settings_set_lock (settings, control, xmlStrcmp (content, _x("true")) == 0 ? TRUE : FALSE);
242 else if (xmlStrcmp (sub_node->name, _x("value")) == 0)
244 content = xmlNodeGetContent (sub_node);
245 settings_set_control_value (settings, copy, control, strtod (_s(content), NULL));
256 saved_plugin->settings = settings;
260 saved_rack_parse_jackrack (jack_rack_t * jack_rack, saved_rack_t * saved_rack, const char * filename, xmlNodePtr jackrack)
264 saved_plugin_t * saved_plugin;
266 xmlFreeFunc xmlFree = NULL;
267 xmlMemGet( &xmlFree, NULL, NULL, NULL);
270 for (node = jackrack->children; node; node = node->next)
272 if (xmlStrcmp (node->name, _x("channels")) == 0)
274 content = xmlNodeGetContent (node);
275 saved_rack->channels = strtoul (_s(content), NULL, 10);
278 else if (xmlStrcmp (node->name, _x("samplerate")) == 0)
280 content = xmlNodeGetContent (node);
281 saved_rack->sample_rate = strtoul (_s(content), NULL, 10);
284 else if (xmlStrcmp (node->name, _x("plugin")) == 0)
286 saved_plugin = g_malloc0 (sizeof (saved_plugin_t));
287 saved_rack->plugins = g_slist_append (saved_rack->plugins, saved_plugin);
288 saved_rack_parse_plugin (jack_rack, saved_rack, saved_plugin, filename, node);
293 static saved_rack_t *
294 saved_rack_new (jack_rack_t * jack_rack, const char * filename, xmlDocPtr doc)
297 saved_rack_t *saved_rack;
299 /* create the saved rack */
300 saved_rack = g_malloc (sizeof (saved_rack_t));
301 saved_rack->plugins = NULL;
302 saved_rack->sample_rate = 48000;
303 saved_rack->channels = 2;
305 for (node = doc->children; node; node = node->next)
307 if (xmlStrcmp (node->name, _x("jackrack")) == 0)
308 saved_rack_parse_jackrack (jack_rack, saved_rack, filename, node);
315 saved_rack_destroy (saved_rack_t * saved_rack)
319 for (list = saved_rack->plugins; list; list = g_slist_next (list))
320 settings_destroy (((saved_plugin_t *) list->data)->settings);
321 g_slist_free (saved_rack->plugins);
327 jack_rack_open_file (jack_rack_t * jack_rack, const char * filename)
330 saved_rack_t * saved_rack;
332 saved_plugin_t * saved_plugin;
334 doc = xmlParseFile (filename);
337 mlt_log_error( NULL, _("Could not parse file '%s'\n"), filename);
341 if (xmlStrcmp ( ((xmlDtdPtr)doc->children)->name, _x("jackrack")) != 0)
343 mlt_log_error( NULL, _("The file '%s' is not a JACK Rack settings file\n"), filename);
347 saved_rack = saved_rack_new (jack_rack, filename, doc);
353 for (list = saved_rack->plugins; list; list = g_slist_next (list))
355 saved_plugin = list->data;
357 settings_set_sample_rate (saved_plugin->settings, sample_rate);
359 jack_rack_add_saved_plugin (jack_rack, saved_plugin);
362 saved_rack_destroy (saved_rack);