4 * Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <libxml/tree.h>
30 #include "jack_rack.h"
31 #include "lock_free_fifo.h"
32 #include "control_message.h"
34 #include "plugin_settings.h"
41 jack_rack_new (ui_t
* ui
, unsigned long channels
)
45 rack
= g_malloc (sizeof (jack_rack_t
));
46 rack
->saved_plugins
= NULL
;
48 rack
->channels
= channels
;
55 jack_rack_destroy (jack_rack_t
* jack_rack
)
61 jack_rack_instantiate_plugin (jack_rack_t
* jack_rack
, plugin_desc_t
* desc
)
65 /* check whether or not the plugin is RT capable and confirm with the user if it isn't */
66 if (!LADSPA_IS_HARD_RT_CAPABLE(desc
->properties
)) {
67 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",
71 /* create the plugin */
72 plugin
= plugin_new (desc
, jack_rack
);
75 fprintf (stderr
, "Error loading file plugin '%s' from file '%s'\n",
76 desc
->name
, desc
->object_file
);
83 jack_rack_send_add_plugin (jack_rack_t
* jack_rack
, plugin_desc_t
* desc
)
88 plugin
= jack_rack_instantiate_plugin (jack_rack
, desc
);
93 /* send the chain link off to the process() callback */
94 ctrlmsg
.type
= CTRLMSG_ADD
;
95 ctrlmsg
.data
.add
.plugin
= plugin
;
96 lff_write (jack_rack
->ui
->ui_to_process
, &ctrlmsg
);
100 jack_rack_add_saved_plugin (jack_rack_t
* jack_rack
, saved_plugin_t
* saved_plugin
)
102 jack_rack
->saved_plugins
= g_slist_append (jack_rack
->saved_plugins
, saved_plugin
);
104 jack_rack_send_add_plugin (jack_rack
, saved_plugin
->settings
->desc
);
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 (saved_rack_t
* saved_rack
, saved_plugin_t
* saved_plugin
,
156 ui_t
* ui
, 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 (ui
->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 (saved_rack_t
* saved_rack
, ui_t
* ui
, 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 (saved_rack
, saved_plugin
, ui
, filename
, node
);
282 static saved_rack_t
*
283 saved_rack_new (ui_t
* ui
, 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 (saved_rack
, ui
, filename
, node
);
304 saved_rack_destroy (saved_rack_t
* saved_rack
)
308 /* for (list = saved_rack->settings; list; list = g_slist_next (list))
309 settings_destroy ((settings_t *) list->data); */
310 /* g_slist_free (saved_rack->settings); */
317 jack_rack_open_file (ui_t
* ui
, const char * filename
)
320 saved_rack_t
* saved_rack
;
322 saved_plugin_t
* saved_plugin
;
324 doc
= xmlParseFile (filename
);
327 fprintf (stderr
, _("Could not parse file '%s'\n"), filename
);
331 if (strcmp ( ((xmlDtdPtr
)doc
->children
)->name
, "jackrack") != 0)
333 fprintf (stderr
, _("The file '%s' is not a JACK Rack settings file\n"), filename
);
337 saved_rack
= saved_rack_new (ui
, filename
, doc
);
343 for (list
= saved_rack
->plugins
; list
; list
= g_slist_next (list
))
345 saved_plugin
= list
->data
;
347 settings_set_sample_rate (saved_plugin
->settings
, sample_rate
);
349 jack_rack_add_saved_plugin (ui
->jack_rack
, saved_plugin
);
352 g_slist_free (saved_rack
->plugins
);