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"
44 jack_rack_new (const char * client_name
, unsigned long channels
)
48 rack
= g_malloc (sizeof (jack_rack_t
));
49 rack
->saved_plugins
= NULL
;
50 rack
->channels
= channels
;
51 rack
->procinfo
= process_info_new (client_name
, channels
, FALSE
, FALSE
);
52 if (!rack
->procinfo
) {
56 rack
->plugin_mgr
= plugin_mgr_new ();
57 plugin_mgr_set_plugins (rack
->plugin_mgr
, channels
);
64 jack_rack_destroy (jack_rack_t
* jack_rack
)
66 process_quit (jack_rack
->procinfo
);
67 plugin_mgr_destroy (jack_rack
->plugin_mgr
);
68 process_info_destroy (jack_rack
->procinfo
);
69 g_slist_free (jack_rack
->saved_plugins
);
74 jack_rack_instantiate_plugin (jack_rack_t
* jack_rack
, plugin_desc_t
* desc
)
78 /* check whether or not the plugin is RT capable and confirm with the user if it isn't */
79 if (!LADSPA_IS_HARD_RT_CAPABLE(desc
->properties
)) {
80 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",
84 /* create the plugin */
85 plugin
= plugin_new (desc
, jack_rack
);
88 fprintf (stderr
, "Error loading file plugin '%s' from file '%s'\n",
89 desc
->name
, desc
->object_file
);
97 jack_rack_add_saved_plugin (jack_rack_t
* jack_rack
, saved_plugin_t
* saved_plugin
)
99 plugin_t
* plugin
= jack_rack_instantiate_plugin (jack_rack
, saved_plugin
->settings
->desc
);
102 jack_rack
->saved_plugins
= g_slist_append (jack_rack
->saved_plugins
, saved_plugin
);
103 process_add_plugin (jack_rack
->procinfo
, plugin
);
104 jack_rack_add_plugin (jack_rack
, plugin
);
109 jack_rack_add_plugin (jack_rack_t
* jack_rack
, plugin_t
* plugin
)
111 saved_plugin_t
* saved_plugin
= NULL
;
113 unsigned long control
, channel
;
117 /* see if there's any saved settings that match the plugin id */
118 for (list
= jack_rack
->saved_plugins
; list
; list
= g_slist_next (list
))
120 saved_plugin
= list
->data
;
122 if (saved_plugin
->settings
->desc
->id
== plugin
->desc
->id
)
124 /* process the settings! */
125 jack_rack
->saved_plugins
= g_slist_remove (jack_rack
->saved_plugins
, saved_plugin
);
131 /* initialize plugin parameters */
132 plugin
->enabled
= settings_get_enabled (saved_plugin
->settings
);
133 plugin
->wet_dry_enabled
= settings_get_wet_dry_enabled (saved_plugin
->settings
);
135 for (control
= 0; control
< saved_plugin
->settings
->desc
->control_port_count
; control
++)
136 for (copy
= 0; copy
< plugin
->copies
; copy
++)
138 value
= settings_get_control_value (saved_plugin
->settings
, copy
, control
);
139 plugin
->holders
[copy
].control_memory
[control
] = value
;
140 //printf("setting control value %s (%d) = %f\n", saved_plugin->settings->desc->port_names[control], copy, value);
141 // lff_write (plugin->holders[copy].ui_control_fifos + control, &value);
143 if (plugin
->wet_dry_enabled
)
144 for (channel
= 0; channel
< jack_rack
->channels
; channel
++)
146 value
= settings_get_wet_dry_value (saved_plugin
->settings
, channel
);
147 plugin
->wet_dry_values
[channel
] = value
;
148 //printf("setting wet/dry value %d = %f\n", channel, value);
149 // lff_write (plugin->wet_dry_fifos + channel, &value);
155 saved_rack_parse_plugin (jack_rack_t
* jack_rack
, saved_rack_t
* saved_rack
, saved_plugin_t
* saved_plugin
,
156 const char * filename
, xmlNodePtr plugin
)
158 plugin_desc_t
* desc
;
159 settings_t
* settings
= NULL
;
164 unsigned long control
= 0;
166 for (node
= plugin
->children
; node
; node
= node
->next
)
168 if (strcmp (node
->name
, "id") == 0)
170 content
= xmlNodeGetContent (node
);
171 num
= strtoul (content
, NULL
, 10);
174 desc
= plugin_mgr_get_any_desc (jack_rack
->plugin_mgr
, num
);
177 fprintf (stderr
, _("The file '%s' contains an unknown plugin with ID '%ld'; skipping\n"), filename
, num
);
181 settings
= settings_new (desc
, saved_rack
->channels
, saved_rack
->sample_rate
);
183 else if (strcmp (node
->name
, "enabled") == 0)
185 content
= xmlNodeGetContent (node
);
186 settings_set_enabled (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
189 else if (strcmp (node
->name
, "wet_dry_enabled") == 0)
191 content
= xmlNodeGetContent (node
);
192 settings_set_wet_dry_enabled (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
195 else if (strcmp (node
->name
, "wet_dry_locked") == 0)
197 content
= xmlNodeGetContent (node
);
198 settings_set_wet_dry_locked (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
201 else if (strcmp (node
->name
, "wet_dry_values") == 0)
203 unsigned long channel
= 0;
205 for (sub_node
= node
->children
; sub_node
; sub_node
= sub_node
->next
)
207 if (strcmp (sub_node
->name
, "value") == 0)
209 content
= xmlNodeGetContent (sub_node
);
210 settings_set_wet_dry_value (settings
, channel
, strtod (content
, NULL
));
217 else if (strcmp (node
->name
, "lockall") == 0)
219 content
= xmlNodeGetContent (node
);
220 settings_set_lock_all (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
223 else if (strcmp (node
->name
, "controlrow") == 0)
227 for (sub_node
= node
->children
; sub_node
; sub_node
= sub_node
->next
)
229 if (strcmp (sub_node
->name
, "lock") == 0)
231 content
= xmlNodeGetContent (sub_node
);
232 settings_set_lock (settings
, control
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
235 else if (strcmp (sub_node
->name
, "value") == 0)
237 content
= xmlNodeGetContent (sub_node
);
238 settings_set_control_value (settings
, copy
, control
, strtod (content
, NULL
));
249 saved_plugin
->settings
= settings
;
253 saved_rack_parse_jackrack (jack_rack_t
* jack_rack
, saved_rack_t
* saved_rack
, const char * filename
, xmlNodePtr jackrack
)
257 saved_plugin_t
* saved_plugin
;
259 for (node
= jackrack
->children
; node
; node
= node
->next
)
261 if (strcmp (node
->name
, "channels") == 0)
263 content
= xmlNodeGetContent (node
);
264 saved_rack
->channels
= strtoul (content
, NULL
, 10);
267 else if (strcmp (node
->name
, "samplerate") == 0)
269 content
= xmlNodeGetContent (node
);
270 saved_rack
->sample_rate
= strtoul (content
, NULL
, 10);
273 else if (strcmp (node
->name
, "plugin") == 0)
275 saved_plugin
= g_malloc0 (sizeof (saved_plugin_t
));
276 saved_rack
->plugins
= g_slist_append (saved_rack
->plugins
, saved_plugin
);
277 saved_rack_parse_plugin (jack_rack
, saved_rack
, saved_plugin
, filename
, node
);
282 static saved_rack_t
*
283 saved_rack_new (jack_rack_t
* jack_rack
, const char * filename
, xmlDocPtr doc
)
286 saved_rack_t
*saved_rack
;
288 /* create the saved rack */
289 saved_rack
= g_malloc (sizeof (saved_rack_t
));
290 saved_rack
->plugins
= NULL
;
291 saved_rack
->sample_rate
= 48000;
292 saved_rack
->channels
= 2;
294 for (node
= doc
->children
; node
; node
= node
->next
)
296 if (strcmp (node
->name
, "jackrack") == 0)
297 saved_rack_parse_jackrack (jack_rack
, saved_rack
, filename
, node
);
304 saved_rack_destroy (saved_rack_t
* saved_rack
)
308 for (list
= saved_rack
->plugins
; list
; list
= g_slist_next (list
))
309 settings_destroy (((saved_plugin_t
*) list
->data
)->settings
);
310 g_slist_free (saved_rack
->plugins
);
316 jack_rack_open_file (jack_rack_t
* jack_rack
, const char * filename
)
319 saved_rack_t
* saved_rack
;
321 saved_plugin_t
* saved_plugin
;
323 doc
= xmlParseFile (filename
);
326 fprintf (stderr
, _("Could not parse file '%s'\n"), filename
);
330 if (strcmp ( ((xmlDtdPtr
)doc
->children
)->name
, "jackrack") != 0)
332 fprintf (stderr
, _("The file '%s' is not a JACK Rack settings file\n"), filename
);
336 saved_rack
= saved_rack_new (jack_rack
, filename
, doc
);
342 for (list
= saved_rack
->plugins
; list
; list
= g_slist_next (list
))
344 saved_plugin
= list
->data
;
346 settings_set_sample_rate (saved_plugin
->settings
, sample_rate
);
348 jack_rack_add_saved_plugin (jack_rack
, saved_plugin
);
351 saved_rack_destroy (saved_rack
);