f7b8a858260bb4fcc03761b4ba0f4a0c7016bba3
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 "plugin_settings.h"
39 jack_rack_new (const char * client_name
, unsigned long channels
)
43 rack
= g_malloc (sizeof (jack_rack_t
));
44 rack
->saved_plugins
= NULL
;
45 rack
->channels
= channels
;
46 rack
->procinfo
= process_info_new (client_name
, channels
, FALSE
, FALSE
);
47 if (!rack
->procinfo
) {
51 rack
->plugin_mgr
= plugin_mgr_new ();
52 plugin_mgr_set_plugins (rack
->plugin_mgr
, channels
);
59 jack_rack_destroy (jack_rack_t
* jack_rack
)
61 process_quit (jack_rack
->procinfo
);
62 plugin_mgr_destroy (jack_rack
->plugin_mgr
);
63 process_info_destroy (jack_rack
->procinfo
);
64 g_slist_free (jack_rack
->saved_plugins
);
69 jack_rack_instantiate_plugin (jack_rack_t
* jack_rack
, plugin_desc_t
* desc
)
73 /* check whether or not the plugin is RT capable and confirm with the user if it isn't */
74 if (!LADSPA_IS_HARD_RT_CAPABLE(desc
->properties
)) {
75 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",
79 /* create the plugin */
80 plugin
= plugin_new (desc
, jack_rack
);
83 fprintf (stderr
, "Error loading file plugin '%s' from file '%s'\n",
84 desc
->name
, desc
->object_file
);
92 jack_rack_add_saved_plugin (jack_rack_t
* jack_rack
, saved_plugin_t
* saved_plugin
)
94 plugin_t
* plugin
= jack_rack_instantiate_plugin (jack_rack
, saved_plugin
->settings
->desc
);
97 jack_rack
->saved_plugins
= g_slist_append (jack_rack
->saved_plugins
, saved_plugin
);
98 process_add_plugin (jack_rack
->procinfo
, plugin
);
99 jack_rack_add_plugin (jack_rack
, plugin
);
104 jack_rack_add_plugin (jack_rack_t
* jack_rack
, plugin_t
* plugin
)
106 saved_plugin_t
* saved_plugin
= NULL
;
108 unsigned long control
, channel
;
112 /* see if there's any saved settings that match the plugin id */
113 for (list
= jack_rack
->saved_plugins
; list
; list
= g_slist_next (list
))
115 saved_plugin
= list
->data
;
117 if (saved_plugin
->settings
->desc
->id
== plugin
->desc
->id
)
119 /* process the settings! */
120 jack_rack
->saved_plugins
= g_slist_remove (jack_rack
->saved_plugins
, saved_plugin
);
126 /* initialize plugin parameters */
127 plugin
->enabled
= settings_get_enabled (saved_plugin
->settings
);
128 plugin
->wet_dry_enabled
= settings_get_wet_dry_enabled (saved_plugin
->settings
);
130 for (control
= 0; control
< saved_plugin
->settings
->desc
->control_port_count
; control
++)
131 for (copy
= 0; copy
< plugin
->copies
; copy
++)
133 value
= settings_get_control_value (saved_plugin
->settings
, copy
, control
);
134 plugin
->holders
[copy
].control_memory
[control
] = value
;
135 //printf("setting control value %s (%d) = %f\n", saved_plugin->settings->desc->port_names[control], copy, value);
136 // lff_write (plugin->holders[copy].ui_control_fifos + control, &value);
138 if (plugin
->wet_dry_enabled
)
139 for (channel
= 0; channel
< jack_rack
->channels
; channel
++)
141 value
= settings_get_wet_dry_value (saved_plugin
->settings
, channel
);
142 plugin
->wet_dry_values
[channel
] = value
;
143 //printf("setting wet/dry value %d = %f\n", channel, value);
144 // lff_write (plugin->wet_dry_fifos + channel, &value);
150 saved_rack_parse_plugin (jack_rack_t
* jack_rack
, saved_rack_t
* saved_rack
, saved_plugin_t
* saved_plugin
,
151 const char * filename
, xmlNodePtr plugin
)
153 plugin_desc_t
* desc
;
154 settings_t
* settings
= NULL
;
159 unsigned long control
= 0;
161 for (node
= plugin
->children
; node
; node
= node
->next
)
163 if (strcmp (node
->name
, "id") == 0)
165 content
= xmlNodeGetContent (node
);
166 num
= strtoul (content
, NULL
, 10);
169 desc
= plugin_mgr_get_any_desc (jack_rack
->plugin_mgr
, num
);
172 fprintf (stderr
, _("The file '%s' contains an unknown plugin with ID '%ld'; skipping\n"), filename
, num
);
176 settings
= settings_new (desc
, saved_rack
->channels
, saved_rack
->sample_rate
);
178 else if (strcmp (node
->name
, "enabled") == 0)
180 content
= xmlNodeGetContent (node
);
181 settings_set_enabled (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
184 else if (strcmp (node
->name
, "wet_dry_enabled") == 0)
186 content
= xmlNodeGetContent (node
);
187 settings_set_wet_dry_enabled (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
190 else if (strcmp (node
->name
, "wet_dry_locked") == 0)
192 content
= xmlNodeGetContent (node
);
193 settings_set_wet_dry_locked (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
196 else if (strcmp (node
->name
, "wet_dry_values") == 0)
198 unsigned long channel
= 0;
200 for (sub_node
= node
->children
; sub_node
; sub_node
= sub_node
->next
)
202 if (strcmp (sub_node
->name
, "value") == 0)
204 content
= xmlNodeGetContent (sub_node
);
205 settings_set_wet_dry_value (settings
, channel
, strtod (content
, NULL
));
212 else if (strcmp (node
->name
, "lockall") == 0)
214 content
= xmlNodeGetContent (node
);
215 settings_set_lock_all (settings
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
218 else if (strcmp (node
->name
, "controlrow") == 0)
222 for (sub_node
= node
->children
; sub_node
; sub_node
= sub_node
->next
)
224 if (strcmp (sub_node
->name
, "lock") == 0)
226 content
= xmlNodeGetContent (sub_node
);
227 settings_set_lock (settings
, control
, strcmp (content
, "true") == 0 ? TRUE
: FALSE
);
230 else if (strcmp (sub_node
->name
, "value") == 0)
232 content
= xmlNodeGetContent (sub_node
);
233 settings_set_control_value (settings
, copy
, control
, strtod (content
, NULL
));
244 saved_plugin
->settings
= settings
;
248 saved_rack_parse_jackrack (jack_rack_t
* jack_rack
, saved_rack_t
* saved_rack
, const char * filename
, xmlNodePtr jackrack
)
252 saved_plugin_t
* saved_plugin
;
254 for (node
= jackrack
->children
; node
; node
= node
->next
)
256 if (strcmp (node
->name
, "channels") == 0)
258 content
= xmlNodeGetContent (node
);
259 saved_rack
->channels
= strtoul (content
, NULL
, 10);
262 else if (strcmp (node
->name
, "samplerate") == 0)
264 content
= xmlNodeGetContent (node
);
265 saved_rack
->sample_rate
= strtoul (content
, NULL
, 10);
268 else if (strcmp (node
->name
, "plugin") == 0)
270 saved_plugin
= g_malloc0 (sizeof (saved_plugin_t
));
271 saved_rack
->plugins
= g_slist_append (saved_rack
->plugins
, saved_plugin
);
272 saved_rack_parse_plugin (jack_rack
, saved_rack
, saved_plugin
, filename
, node
);
277 static saved_rack_t
*
278 saved_rack_new (jack_rack_t
* jack_rack
, const char * filename
, xmlDocPtr doc
)
281 saved_rack_t
*saved_rack
;
283 /* create the saved rack */
284 saved_rack
= g_malloc (sizeof (saved_rack_t
));
285 saved_rack
->plugins
= NULL
;
286 saved_rack
->sample_rate
= 48000;
287 saved_rack
->channels
= 2;
289 for (node
= doc
->children
; node
; node
= node
->next
)
291 if (strcmp (node
->name
, "jackrack") == 0)
292 saved_rack_parse_jackrack (jack_rack
, saved_rack
, filename
, node
);
299 saved_rack_destroy (saved_rack_t
* saved_rack
)
303 for (list
= saved_rack
->plugins
; list
; list
= g_slist_next (list
))
304 settings_destroy (((saved_plugin_t
*) list
->data
)->settings
);
305 g_slist_free (saved_rack
->plugins
);
311 jack_rack_open_file (jack_rack_t
* jack_rack
, const char * filename
)
314 saved_rack_t
* saved_rack
;
316 saved_plugin_t
* saved_plugin
;
318 doc
= xmlParseFile (filename
);
321 fprintf (stderr
, _("Could not parse file '%s'\n"), filename
);
325 if (strcmp ( ((xmlDtdPtr
)doc
->children
)->name
, "jackrack") != 0)
327 fprintf (stderr
, _("The file '%s' is not a JACK Rack settings file\n"), filename
);
331 saved_rack
= saved_rack_new (jack_rack
, filename
, doc
);
337 for (list
= saved_rack
->plugins
; list
; list
= g_slist_next (list
))
339 saved_plugin
= list
->data
;
341 settings_set_sample_rate (saved_plugin
->settings
, sample_rate
);
343 jack_rack_add_saved_plugin (jack_rack
, saved_plugin
);
346 saved_rack_destroy (saved_rack
);