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 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "plugin_desc.h"
27 #define set_string_property(property, value) \
33 (property) = g_strdup (value); \
39 plugin_desc_set_ports (plugin_desc_t * pd,
40 unsigned long port_count,
41 const LADSPA_PortDescriptor * port_descriptors,
42 const LADSPA_PortRangeHint * port_range_hints,
43 const char * const * port_names);
48 plugin_desc_init (plugin_desc_t * pd)
50 pd->object_file = NULL;
56 pd->port_descriptors = NULL;
57 pd->port_range_hints = NULL;
58 pd->audio_input_port_indicies = NULL;
59 pd->audio_output_port_indicies = NULL;
60 pd->audio_aux_port_indicies = NULL;
61 pd->control_port_count = 0;
62 pd->control_port_indicies = NULL;
64 pd->aux_are_input = TRUE;
68 plugin_desc_free_ports (plugin_desc_t * pd)
72 g_free (pd->port_descriptors);
73 g_free (pd->port_range_hints);
74 pd->port_descriptors = NULL;
75 pd->port_range_hints = NULL;
81 plugin_desc_free (plugin_desc_t * pd)
83 plugin_desc_set_object_file (pd, NULL);
84 plugin_desc_set_name (pd, NULL);
85 plugin_desc_free_ports (pd);
92 pd = g_malloc (sizeof (plugin_desc_t));
93 plugin_desc_init (pd);
98 plugin_desc_new_with_descriptor (const char * object_file,
100 const LADSPA_Descriptor * descriptor)
103 pd = plugin_desc_new ();
105 plugin_desc_set_object_file (pd, object_file);
106 plugin_desc_set_index (pd, index);
107 plugin_desc_set_id (pd, descriptor->UniqueID);
108 plugin_desc_set_name (pd, descriptor->Name);
109 plugin_desc_set_properties (pd, descriptor->Properties);
110 plugin_desc_set_ports (pd,
111 descriptor->PortCount,
112 descriptor->PortDescriptors,
113 descriptor->PortRangeHints,
114 descriptor->PortNames);
116 pd->rt = LADSPA_IS_HARD_RT_CAPABLE(pd->properties) ? TRUE : FALSE;
122 plugin_desc_destroy (plugin_desc_t * pd)
124 plugin_desc_free (pd);
129 plugin_desc_set_object_file (plugin_desc_t * pd, const char * object_file)
131 set_string_property (pd->object_file, object_file);
135 plugin_desc_set_index (plugin_desc_t * pd, unsigned long index)
142 plugin_desc_set_id (plugin_desc_t * pd, unsigned long id)
148 plugin_desc_set_name (plugin_desc_t * pd, const char * name)
150 set_string_property (pd->name, name);
154 plugin_desc_set_properties (plugin_desc_t * pd, LADSPA_Properties properties)
156 pd->properties = properties;
160 plugin_desc_add_audio_port_index (unsigned long ** indicies,
161 unsigned long * current_port_count,
164 (*current_port_count)++;
166 if (*current_port_count == 0)
167 *indicies = g_malloc (sizeof (unsigned long) * *current_port_count);
169 *indicies = g_realloc (*indicies, sizeof (unsigned long) * *current_port_count);
171 (*indicies)[*current_port_count - 1] = index;
175 plugin_desc_set_port_counts (plugin_desc_t * pd)
178 unsigned long icount = 0;
179 unsigned long ocount = 0;
181 for (i = 0; i < pd->port_count; i++)
183 if (LADSPA_IS_PORT_AUDIO (pd->port_descriptors[i]))
185 if (LADSPA_IS_PORT_INPUT (pd->port_descriptors[i]))
186 plugin_desc_add_audio_port_index (&pd->audio_input_port_indicies, &icount, i);
188 plugin_desc_add_audio_port_index (&pd->audio_output_port_indicies, &ocount, i);
192 if (LADSPA_IS_PORT_OUTPUT (pd->port_descriptors[i]))
195 pd->control_port_count++;
196 if (pd->control_port_count == 0)
197 pd->control_port_indicies = g_malloc (sizeof (unsigned long) * pd->control_port_count);
199 pd->control_port_indicies = g_realloc (pd->control_port_indicies,
200 sizeof (unsigned long) * pd->control_port_count);
202 pd->control_port_indicies[pd->control_port_count - 1] = i;
206 if (icount == ocount)
207 pd->channels = icount;
209 { /* deal with auxilliary ports */
210 unsigned long ** port_indicies;
211 unsigned long port_count;
216 pd->channels = ocount;
217 pd->aux_channels = icount - ocount;
218 pd->aux_are_input = TRUE;
219 port_indicies = &pd->audio_input_port_indicies;
224 pd->channels = icount;
225 pd->aux_channels = ocount - icount;
226 pd->aux_are_input = FALSE;
227 port_indicies = &pd->audio_output_port_indicies;
231 /* allocate indicies */
232 pd->audio_aux_port_indicies = g_malloc (sizeof (unsigned long) * pd->aux_channels);
235 for (i = pd->channels, j = 0; i < port_count; i++, j++)
236 pd->audio_aux_port_indicies[j] = (*port_indicies)[i];
238 /* shrink the main indicies to only have channels indicies */
239 *port_indicies = g_realloc (*port_indicies, sizeof (unsigned long) * pd->channels);
244 plugin_desc_set_ports (plugin_desc_t * pd,
245 unsigned long port_count,
246 const LADSPA_PortDescriptor * port_descriptors,
247 const LADSPA_PortRangeHint * port_range_hints,
248 const char * const * port_names)
252 plugin_desc_free_ports (pd);
257 pd->port_count = port_count;
258 pd->port_descriptors = g_malloc (sizeof (LADSPA_PortDescriptor) * port_count);
259 pd->port_range_hints = g_malloc (sizeof (LADSPA_PortRangeHint) * port_count);
260 pd->port_names = g_malloc (sizeof (char *) * port_count);
262 memcpy (pd->port_descriptors, port_descriptors, sizeof (LADSPA_PortDescriptor) * port_count);
263 memcpy (pd->port_range_hints, port_range_hints, sizeof (LADSPA_PortRangeHint) * port_count);
265 for (i = 0; i < port_count; i++)
266 pd->port_names[i] = g_strdup (port_names[i]);
268 plugin_desc_set_port_counts (pd);
273 plugin_desc_get_default_control_value (plugin_desc_t * pd, unsigned long port_index, guint32 sample_rate)
275 LADSPA_Data upper, lower;
276 LADSPA_PortRangeHintDescriptor hint_descriptor;
278 hint_descriptor = pd->port_range_hints[port_index].HintDescriptor;
280 /* set upper and lower, possibly adjusted to the sample rate */
281 if (LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)) {
282 upper = pd->port_range_hints[port_index].UpperBound * (LADSPA_Data) sample_rate;
283 lower = pd->port_range_hints[port_index].LowerBound * (LADSPA_Data) sample_rate;
285 upper = pd->port_range_hints[port_index].UpperBound;
286 lower = pd->port_range_hints[port_index].LowerBound;
289 if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor))
291 if (lower < FLT_EPSILON)
296 if (LADSPA_IS_HINT_HAS_DEFAULT(hint_descriptor)) {
298 if (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint_descriptor)) {
302 } else if (LADSPA_IS_HINT_DEFAULT_LOW(hint_descriptor)) {
304 if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
305 return exp(log(lower) * 0.75 + log(upper) * 0.25);
307 return lower * 0.75 + upper * 0.25;
310 } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint_descriptor)) {
312 if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
313 return exp(log(lower) * 0.5 + log(upper) * 0.5);
315 return lower * 0.5 + upper * 0.5;
318 } else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint_descriptor)) {
320 if (LADSPA_IS_HINT_LOGARITHMIC(hint_descriptor)) {
321 return exp(log(lower) * 0.25 + log(upper) * 0.75);
323 return lower * 0.25 + upper * 0.75;
326 } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint_descriptor)) {
330 } else if (LADSPA_IS_HINT_DEFAULT_0(hint_descriptor)) {
334 } else if (LADSPA_IS_HINT_DEFAULT_1(hint_descriptor)) {
336 if (LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)) {
337 return (LADSPA_Data) sample_rate;
342 } else if (LADSPA_IS_HINT_DEFAULT_100(hint_descriptor)) {
344 if (LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)) {
345 return 100.0 * (LADSPA_Data) sample_rate;
350 } else if (LADSPA_IS_HINT_DEFAULT_440(hint_descriptor)) {
352 if (LADSPA_IS_HINT_SAMPLE_RATE(hint_descriptor)) {
353 return 440.0 * (LADSPA_Data) sample_rate;
360 } else { /* try and find a reasonable default */
362 if (LADSPA_IS_HINT_BOUNDED_BELOW(hint_descriptor)) {
364 } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint_descriptor)) {
373 plugin_desc_change_control_value (plugin_desc_t * pd,
374 unsigned long control_index,
376 guint32 old_sample_rate,
377 guint32 new_sample_rate)
380 if (LADSPA_IS_HINT_SAMPLE_RATE (pd->port_range_hints[control_index].HintDescriptor))
382 LADSPA_Data old_sr, new_sr;
384 old_sr = (LADSPA_Data) old_sample_rate;
385 new_sr = (LADSPA_Data) new_sample_rate;
395 plugin_desc_get_copies (plugin_desc_t * pd, unsigned long rack_channels)
399 if (pd->channels > rack_channels)
402 while (pd->channels * copies < rack_channels)
405 if (pd->channels * copies > rack_channels)