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"
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 for (node
= plugin
->children
; node
; node
= node
->next
)
170 if (xmlStrcmp (node
->name
, _x("id")) == 0)
172 content
= xmlNodeGetContent (node
);
173 num
= strtoul (_s(content
), NULL
, 10);
176 desc
= plugin_mgr_get_any_desc (jack_rack
->plugin_mgr
, num
);
179 fprintf (stderr
, _("The file '%s' contains an unknown plugin with ID '%ld'; skipping\n"), filename
, num
);
183 settings
= settings_new (desc
, saved_rack
->channels
, saved_rack
->sample_rate
);
185 else if (xmlStrcmp (node
->name
, _x("enabled")) == 0)
187 content
= xmlNodeGetContent (node
);
188 settings_set_enabled (settings
, xmlStrcmp (content
, _x("true")) == 0 ? TRUE
: FALSE
);
191 else if (xmlStrcmp (node
->name
, _x("wet_dry_enabled")) == 0)
193 content
= xmlNodeGetContent (node
);
194 settings_set_wet_dry_enabled (settings
, xmlStrcmp (content
, _x("true")) == 0 ? TRUE
: FALSE
);
197 else if (xmlStrcmp (node
->name
, _x("wet_dry_locked")) == 0)
199 content
= xmlNodeGetContent (node
);
200 settings_set_wet_dry_locked (settings
, xmlStrcmp (content
, _x("true")) == 0 ? TRUE
: FALSE
);
203 else if (xmlStrcmp (node
->name
, _x("wet_dry_values")) == 0)
205 unsigned long channel
= 0;
207 for (sub_node
= node
->children
; sub_node
; sub_node
= sub_node
->next
)
209 if (xmlStrcmp (sub_node
->name
, _x("value")) == 0)
211 content
= xmlNodeGetContent (sub_node
);
212 settings_set_wet_dry_value (settings
, channel
, strtod (_s(content
), NULL
));
219 else if (xmlStrcmp (node
->name
, _x("lockall")) == 0)
221 content
= xmlNodeGetContent (node
);
222 settings_set_lock_all (settings
, xmlStrcmp (content
, _x("true")) == 0 ? TRUE
: FALSE
);
225 else if (xmlStrcmp (node
->name
, _x("controlrow")) == 0)
229 for (sub_node
= node
->children
; sub_node
; sub_node
= sub_node
->next
)
231 if (xmlStrcmp (sub_node
->name
, _x("lock")) == 0)
233 content
= xmlNodeGetContent (sub_node
);
234 settings_set_lock (settings
, control
, xmlStrcmp (content
, _x("true")) == 0 ? TRUE
: FALSE
);
237 else if (xmlStrcmp (sub_node
->name
, _x("value")) == 0)
239 content
= xmlNodeGetContent (sub_node
);
240 settings_set_control_value (settings
, copy
, control
, strtod (_s(content
), NULL
));
251 saved_plugin
->settings
= settings
;
255 saved_rack_parse_jackrack (jack_rack_t
* jack_rack
, saved_rack_t
* saved_rack
, const char * filename
, xmlNodePtr jackrack
)
259 saved_plugin_t
* saved_plugin
;
261 for (node
= jackrack
->children
; node
; node
= node
->next
)
263 if (xmlStrcmp (node
->name
, _x("channels")) == 0)
265 content
= xmlNodeGetContent (node
);
266 saved_rack
->channels
= strtoul (_s(content
), NULL
, 10);
269 else if (xmlStrcmp (node
->name
, _x("samplerate")) == 0)
271 content
= xmlNodeGetContent (node
);
272 saved_rack
->sample_rate
= strtoul (_s(content
), NULL
, 10);
275 else if (xmlStrcmp (node
->name
, _x("plugin")) == 0)
277 saved_plugin
= g_malloc0 (sizeof (saved_plugin_t
));
278 saved_rack
->plugins
= g_slist_append (saved_rack
->plugins
, saved_plugin
);
279 saved_rack_parse_plugin (jack_rack
, saved_rack
, saved_plugin
, filename
, node
);
284 static saved_rack_t
*
285 saved_rack_new (jack_rack_t
* jack_rack
, const char * filename
, xmlDocPtr doc
)
288 saved_rack_t
*saved_rack
;
290 /* create the saved rack */
291 saved_rack
= g_malloc (sizeof (saved_rack_t
));
292 saved_rack
->plugins
= NULL
;
293 saved_rack
->sample_rate
= 48000;
294 saved_rack
->channels
= 2;
296 for (node
= doc
->children
; node
; node
= node
->next
)
298 if (xmlStrcmp (node
->name
, _x("jackrack")) == 0)
299 saved_rack_parse_jackrack (jack_rack
, saved_rack
, filename
, node
);
306 saved_rack_destroy (saved_rack_t
* saved_rack
)
310 for (list
= saved_rack
->plugins
; list
; list
= g_slist_next (list
))
311 settings_destroy (((saved_plugin_t
*) list
->data
)->settings
);
312 g_slist_free (saved_rack
->plugins
);
318 jack_rack_open_file (jack_rack_t
* jack_rack
, const char * filename
)
321 saved_rack_t
* saved_rack
;
323 saved_plugin_t
* saved_plugin
;
325 doc
= xmlParseFile (filename
);
328 fprintf (stderr
, _("Could not parse file '%s'\n"), filename
);
332 if (xmlStrcmp ( ((xmlDtdPtr
)doc
->children
)->name
, _x("jackrack")) != 0)
334 fprintf (stderr
, _("The file '%s' is not a JACK Rack settings file\n"), filename
);
338 saved_rack
= saved_rack_new (jack_rack
, filename
, doc
);
344 for (list
= saved_rack
->plugins
; list
; list
= g_slist_next (list
))
346 saved_plugin
= list
->data
;
348 settings_set_sample_rate (saved_plugin
->settings
, sample_rate
);
350 jack_rack_add_saved_plugin (jack_rack
, saved_plugin
);
353 saved_rack_destroy (saved_rack
);