[SCM] calf/master: + Framework: move LADSPA-related classes to separate file, adjust dependencies
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:38:18 UTC 2013
The following commit has been merged in the master branch:
commit 19afd0c45461c1ef98c5f48091ebe8c7d1b8b69b
Author: Krzysztof Foltman <wdev at foltman.com>
Date: Tue Nov 4 17:38:06 2008 +0000
+ Framework: move LADSPA-related classes to separate file, adjust dependencies
diff --git a/src/calf/giface.h b/src/calf/giface.h
index db483ac..1078bd3 100644
--- a/src/calf/giface.h
+++ b/src/calf/giface.h
@@ -271,422 +271,6 @@ struct plugin_list_info_iface;
extern void get_all_plugins(std::vector<giface_plugin_info> &plugins);
extern void get_all_small_plugins(plugin_list_info_iface *plii);
-#if USE_LADSPA
-
-extern std::string generate_ladspa_rdf(const ladspa_plugin_info &info, parameter_properties *params, const char *param_names[], unsigned int count, unsigned int ctl_ofs);
-
-/// A template implementing plugin_ctl_iface for a given plugin
-template<class Module>
-struct ladspa_instance: public Module, public plugin_ctl_iface
-{
- bool activate_flag;
- ladspa_instance()
- {
- for (int i=0; i < Module::in_count; i++)
- Module::ins[i] = NULL;
- for (int i=0; i < Module::out_count; i++)
- Module::outs[i] = NULL;
- for (int i=0; i < Module::param_count; i++)
- Module::params[i] = NULL;
- activate_flag = true;
- }
- virtual parameter_properties *get_param_props(int param_no)
- {
- return &Module::param_props[param_no];
- }
- virtual float get_param_value(int param_no)
- {
- return *Module::params[param_no];
- }
- virtual void set_param_value(int param_no, float value)
- {
- *Module::params[param_no] = value;
- }
- virtual int get_param_count()
- {
- return Module::param_count;
- }
- virtual int get_param_port_offset()
- {
- return Module::in_count + Module::out_count;
- }
- virtual const char *get_gui_xml() {
- return Module::get_gui_xml();
- }
- virtual line_graph_iface *get_line_graph_iface()
- {
- return this;
- }
- virtual bool activate_preset(int bank, int program) {
- return false;
- }
- virtual const char *get_name()
- {
- return Module::get_name();
- }
- virtual const char *get_id()
- {
- return Module::get_id();
- }
- virtual const char *get_label()
- {
- return Module::get_label();
- }
- virtual char *configure(const char *key, const char *value)
- {
- if (!strcmp(key, "ExecCommand"))
- {
- if (*value)
- {
- execute(atoi(value));
- }
- return NULL;
- }
- return Module::configure(key, value);
- }
- virtual int get_input_count() { return Module::in_count; }
- virtual int get_output_count() { return Module::out_count; }
- virtual bool get_midi() { return Module::support_midi; }
- virtual float get_level(unsigned int port) { return 0.f; }
- virtual void execute(int cmd_no) {
- Module::execute(cmd_no);
- }
- virtual void send_configures(send_configure_iface *sci) {
- Module::send_configures(sci);
- }
- virtual void clear_preset() {
- for (int i=0; i < Module::param_count; i++)
- *Module::params[i] = Module::param_props[i].def_value;
- const char **p = Module::get_default_configure_vars();
- if (p)
- {
- for(; p[0]; p += 2)
- configure(p[0], p[1]);
- }
- }
-};
-
-/// A wrapper class for plugin class object (there is only one ladspa_wrapper for many instances of the same plugin)
-template<class Module>
-struct ladspa_wrapper
-{
- typedef ladspa_instance<Module> instance;
-
- static LADSPA_Descriptor descriptor;
-#if USE_DSSI
- static DSSI_Descriptor dssi_descriptor;
- static DSSI_Program_Descriptor dssi_default_program;
-
- static std::vector<plugin_preset> *presets;
- static std::vector<DSSI_Program_Descriptor> *preset_descs;
-#endif
-
- ladspa_wrapper()
- {
- int ins = Module::in_count;
- int outs = Module::out_count;
- int params = Module::param_count;
- ladspa_plugin_info &plugin_info = Module::plugin_info;
- descriptor.UniqueID = plugin_info.unique_id;
- descriptor.Label = plugin_info.label;
- descriptor.Name = plugin_info.name;
- descriptor.Maker = plugin_info.maker;
- descriptor.Copyright = plugin_info.copyright;
- descriptor.Properties = Module::rt_capable ? LADSPA_PROPERTY_HARD_RT_CAPABLE : 0;
- descriptor.PortCount = ins + outs + params;
- descriptor.PortNames = new char *[descriptor.PortCount];
- descriptor.PortDescriptors = new LADSPA_PortDescriptor[descriptor.PortCount];
- descriptor.PortRangeHints = new LADSPA_PortRangeHint[descriptor.PortCount];
- int i;
- for (i = 0; i < ins + outs; i++)
- {
- LADSPA_PortRangeHint &prh = ((LADSPA_PortRangeHint *)descriptor.PortRangeHints)[i];
- ((int *)descriptor.PortDescriptors)[i] = i < ins ? LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO
- : i < ins + outs ? LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO
- : LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
- prh.HintDescriptor = 0;
- ((const char **)descriptor.PortNames)[i] = Module::port_names[i];
- }
- for (; i < ins + outs + params; i++)
- {
- LADSPA_PortRangeHint &prh = ((LADSPA_PortRangeHint *)descriptor.PortRangeHints)[i];
- parameter_properties &pp = Module::param_props[i - ins - outs];
- ((int *)descriptor.PortDescriptors)[i] =
- LADSPA_PORT_CONTROL | (pp.flags & PF_PROP_OUTPUT ? LADSPA_PORT_OUTPUT : LADSPA_PORT_INPUT);
- prh.HintDescriptor = LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_BOUNDED_BELOW;
- ((const char **)descriptor.PortNames)[i] = pp.name;
- prh.LowerBound = pp.min;
- prh.UpperBound = pp.max;
- switch(pp.flags & PF_TYPEMASK) {
- case PF_BOOL:
- prh.HintDescriptor |= LADSPA_HINT_TOGGLED;
- break;
- case PF_INT:
- case PF_ENUM:
- prh.HintDescriptor |= LADSPA_HINT_INTEGER;
- break;
- }
- switch(pp.flags & PF_SCALEMASK) {
- case PF_SCALE_LOG:
- prh.HintDescriptor |= LADSPA_HINT_LOGARITHMIC;
- break;
- }
- }
- descriptor.ImplementationData = this;
- descriptor.instantiate = cb_instantiate;
- descriptor.connect_port = cb_connect;
- descriptor.activate = cb_activate;
- descriptor.run = cb_run;
- descriptor.run_adding = NULL;
- descriptor.set_run_adding_gain = NULL;
- descriptor.deactivate = cb_deactivate;
- descriptor.cleanup = cb_cleanup;
-#if USE_DSSI
- memset(&dssi_descriptor, 0, sizeof(dssi_descriptor));
- dssi_descriptor.DSSI_API_Version = 1;
- dssi_descriptor.LADSPA_Plugin = &descriptor;
- dssi_descriptor.configure = cb_configure;
- dssi_descriptor.get_program = cb_get_program;
- dssi_descriptor.select_program = cb_select_program;
- dssi_descriptor.run_synth = cb_run_synth;
-
- presets = new std::vector<plugin_preset>;
- preset_descs = new std::vector<DSSI_Program_Descriptor>;
-
- preset_list plist_tmp, plist;
- plist.load_defaults(true);
- plist_tmp.load_defaults(false);
- plist.presets.insert(plist.presets.end(), plist_tmp.presets.begin(), plist_tmp.presets.end());
-
- // XXXKF this assumes that plugin name in preset is case-insensitive equal to plugin label
- // if I forget about this, I'll be in a deep trouble
- dssi_default_program.Bank = 0;
- dssi_default_program.Program = 0;
- dssi_default_program.Name = "default";
-
- int pos = 1;
- for (unsigned int i = 0; i < plist.presets.size(); i++)
- {
- plugin_preset &pp = plist.presets[i];
- if (strcasecmp(pp.plugin.c_str(), descriptor.Label))
- continue;
- DSSI_Program_Descriptor pd;
- pd.Bank = pos >> 7;
- pd.Program = pos++;
- pd.Name = pp.name.c_str();
- preset_descs->push_back(pd);
- presets->push_back(pp);
- }
- // printf("presets = %p:%d name = %s\n", presets, presets->size(), descriptor.Label);
-
-#endif
- }
-
- ~ladspa_wrapper()
- {
- delete []descriptor.PortNames;
- delete []descriptor.PortDescriptors;
- delete []descriptor.PortRangeHints;
-#if USE_DSSI
- presets->clear();
- preset_descs->clear();
- delete presets;
- delete preset_descs;
-#endif
- }
-
- /// LADSPA instantiation function (create a plugin instance)
- static LADSPA_Handle cb_instantiate(const struct _LADSPA_Descriptor * Descriptor, unsigned long sample_rate)
- {
- instance *mod = new instance();
- mod->srate = sample_rate;
- return mod;
- }
-
-#if USE_DSSI
- /// DSSI get program descriptor function; for 0, it returns the default program (from parameter properties table), for others, it uses global or user preset
- static const DSSI_Program_Descriptor *cb_get_program(LADSPA_Handle Instance, unsigned long index) {
- if (index > presets->size())
- return NULL;
- if (index)
- return &(*preset_descs)[index - 1];
- return &dssi_default_program;
- }
-
- /// DSSI select program function; for 0, it sets the defaults, for others, it sets global or user preset
- static void cb_select_program(LADSPA_Handle Instance, unsigned long Bank, unsigned long Program) {
- instance *mod = (instance *)Instance;
- unsigned int no = (Bank << 7) + Program - 1;
- // printf("no = %d presets = %p:%d\n", no, presets, presets->size());
- if (no == -1U) {
- for (int i =0 ; i < Module::param_count; i++)
- *mod->params[i] = Module::param_props[i].def_value;
- return;
- }
- if (no >= presets->size())
- return;
- plugin_preset &p = (*presets)[no];
- // printf("activating preset %s\n", p.name.c_str());
- p.activate(mod);
- }
-
-#endif
-
- /// LADSPA port connection function
- static void cb_connect(LADSPA_Handle Instance, unsigned long port, LADSPA_Data *DataLocation) {
- unsigned long ins = Module::in_count;
- unsigned long outs = Module::out_count;
- unsigned long params = Module::param_count;
- instance *const mod = (instance *)Instance;
- if (port < ins)
- mod->ins[port] = DataLocation;
- else if (port < ins + outs)
- mod->outs[port - ins] = DataLocation;
- else if (port < ins + outs + params) {
- int i = port - ins - outs;
- mod->params[i] = DataLocation;
- *mod->params[i] = Module::param_props[i].def_value;
- }
- }
-
- /// LADSPA activate function (note that at this moment the ports are not set)
- static void cb_activate(LADSPA_Handle Instance) {
- instance *const mod = (instance *)Instance;
- mod->activate_flag = true;
- }
-
- /// utility function: zero port values if mask is 0
- static inline void zero_by_mask(Module *module, uint32_t mask, uint32_t offset, uint32_t nsamples)
- {
- for (int i=0; i<Module::out_count; i++) {
- if ((mask & (1 << i)) == 0) {
- dsp::zero(module->outs[i] + offset, nsamples);
- }
- }
- }
-
- /// LADSPA run function - does set sample rate / activate logic when it's run first time after activation
- static void cb_run(LADSPA_Handle Instance, unsigned long SampleCount) {
- instance *const mod = (instance *)Instance;
- if (mod->activate_flag)
- {
- mod->set_sample_rate(mod->srate);
- mod->activate();
- mod->activate_flag = false;
- }
- mod->params_changed();
- process_slice(mod, 0, SampleCount);
- }
-
- /// utility function: call process, and if it returned zeros in output masks, zero out the relevant output port buffers
- static inline void process_slice(Module *mod, uint32_t offset, uint32_t end)
- {
- while(offset < end)
- {
- uint32_t newend = std::min(offset + MAX_SAMPLE_RUN, end);
- uint32_t out_mask = mod->process(offset, newend - offset, -1, -1);
- zero_by_mask(mod, out_mask, offset, newend - offset);
- offset = newend;
- }
- }
-
-#if USE_DSSI
- /// DSSI "run synth" function, same as run() except it allows for event delivery
- static void cb_run_synth(LADSPA_Handle Instance, unsigned long SampleCount,
- snd_seq_event_t *Events, unsigned long EventCount) {
- instance *const mod = (instance *)Instance;
- if (mod->activate_flag)
- {
- mod->set_sample_rate(mod->srate);
- mod->activate();
- mod->activate_flag = false;
- }
- mod->params_changed();
-
- uint32_t offset = 0;
- for (uint32_t e = 0; e < EventCount; e++)
- {
- uint32_t timestamp = Events[e].time.tick;
- if (timestamp != offset)
- process_slice(mod, offset, timestamp);
- process_dssi_event(mod, Events[e]);
- offset = timestamp;
- }
- if (offset != SampleCount)
- process_slice(mod, offset, SampleCount);
- }
-
- /// DSSI configure function (named properties)
- static char *cb_configure(LADSPA_Handle Instance,
- const char *Key,
- const char *Value)
- {
- instance *const mod = (instance *)Instance;
- return mod->configure(Key, Value);
- }
-
- /// Utility function: handle MIDI event (only handles a subset in this version)
- static void process_dssi_event(Module *module, snd_seq_event_t &event)
- {
- switch(event.type) {
- case SND_SEQ_EVENT_NOTEON:
- module->note_on(event.data.note.note, event.data.note.velocity);
- break;
- case SND_SEQ_EVENT_NOTEOFF:
- module->note_off(event.data.note.note, event.data.note.velocity);
- break;
- case SND_SEQ_EVENT_PGMCHANGE:
- module->program_change(event.data.control.value);
- break;
- case SND_SEQ_EVENT_CONTROLLER:
- module->control_change(event.data.control.param, event.data.control.value);
- break;
- case SND_SEQ_EVENT_PITCHBEND:
- module->pitch_bend(event.data.control.value);
- break;
- }
- }
-#endif
-
- /// LADSPA deactivate function
- static void cb_deactivate(LADSPA_Handle Instance) {
- instance *const mod = (instance *)Instance;
- mod->deactivate();
- }
-
- /// LADSPA cleanup (delete instance) function
- static void cb_cleanup(LADSPA_Handle Instance) {
- instance *const mod = (instance *)Instance;
- delete mod;
- }
-
- /// Get a wrapper singleton - used to prevent initialization order problems which were present in older versions
- static ladspa_wrapper &get() {
- static ladspa_wrapper instance;
- return instance;
- }
-};
-
-template<class Module>
-LADSPA_Descriptor ladspa_wrapper<Module>::descriptor;
-
-#if USE_DSSI
-
-template<class Module>
-DSSI_Descriptor ladspa_wrapper<Module>::dssi_descriptor;
-
-template<class Module>
-DSSI_Program_Descriptor ladspa_wrapper<Module>::dssi_default_program;
-
-template<class Module>
-std::vector<plugin_preset> *ladspa_wrapper<Module>::presets;
-
-template<class Module>
-std::vector<DSSI_Program_Descriptor> *ladspa_wrapper<Module>::preset_descs;
-#endif
-
-
-#endif
struct audio_exception: public std::exception
{
diff --git a/src/calf/ladspa_wrap.h b/src/calf/ladspa_wrap.h
new file mode 100644
index 0000000..fda9d20
--- /dev/null
+++ b/src/calf/ladspa_wrap.h
@@ -0,0 +1,445 @@
+/* Calf DSP Library
+ * API wrappers for Linux audio standards (apart from JACK, which is
+ * a separate file now!)
+ *
+ * Copyright (C) 2007 Krzysztof Foltman
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __CALF_LADSPA_WRAP_H
+#define __CALF_LADSPA_WRAP_H
+
+#if USE_LADSPA
+
+#include "giface.h"
+
+namespace synth {
+
+/// A template implementing plugin_ctl_iface for a given plugin
+template<class Module>
+struct ladspa_instance: public Module, public plugin_ctl_iface
+{
+ bool activate_flag;
+ ladspa_instance()
+ {
+ for (int i=0; i < Module::in_count; i++)
+ Module::ins[i] = NULL;
+ for (int i=0; i < Module::out_count; i++)
+ Module::outs[i] = NULL;
+ for (int i=0; i < Module::param_count; i++)
+ Module::params[i] = NULL;
+ activate_flag = true;
+ }
+ virtual parameter_properties *get_param_props(int param_no)
+ {
+ return &Module::param_props[param_no];
+ }
+ virtual float get_param_value(int param_no)
+ {
+ return *Module::params[param_no];
+ }
+ virtual void set_param_value(int param_no, float value)
+ {
+ *Module::params[param_no] = value;
+ }
+ virtual int get_param_count()
+ {
+ return Module::param_count;
+ }
+ virtual int get_param_port_offset()
+ {
+ return Module::in_count + Module::out_count;
+ }
+ virtual const char *get_gui_xml() {
+ return Module::get_gui_xml();
+ }
+ virtual line_graph_iface *get_line_graph_iface()
+ {
+ return this;
+ }
+ virtual bool activate_preset(int bank, int program) {
+ return false;
+ }
+ virtual const char *get_name()
+ {
+ return Module::get_name();
+ }
+ virtual const char *get_id()
+ {
+ return Module::get_id();
+ }
+ virtual const char *get_label()
+ {
+ return Module::get_label();
+ }
+ virtual char *configure(const char *key, const char *value)
+ {
+ if (!strcmp(key, "ExecCommand"))
+ {
+ if (*value)
+ {
+ execute(atoi(value));
+ }
+ return NULL;
+ }
+ return Module::configure(key, value);
+ }
+ virtual int get_input_count() { return Module::in_count; }
+ virtual int get_output_count() { return Module::out_count; }
+ virtual bool get_midi() { return Module::support_midi; }
+ virtual float get_level(unsigned int port) { return 0.f; }
+ virtual void execute(int cmd_no) {
+ Module::execute(cmd_no);
+ }
+ virtual void send_configures(send_configure_iface *sci) {
+ Module::send_configures(sci);
+ }
+ virtual void clear_preset() {
+ for (int i=0; i < Module::param_count; i++)
+ *Module::params[i] = Module::param_props[i].def_value;
+ const char **p = Module::get_default_configure_vars();
+ if (p)
+ {
+ for(; p[0]; p += 2)
+ configure(p[0], p[1]);
+ }
+ }
+};
+
+/// A wrapper class for plugin class object (there is only one ladspa_wrapper for many instances of the same plugin)
+template<class Module>
+struct ladspa_wrapper
+{
+ typedef ladspa_instance<Module> instance;
+
+ static LADSPA_Descriptor descriptor;
+#if USE_DSSI
+ static DSSI_Descriptor dssi_descriptor;
+ static DSSI_Program_Descriptor dssi_default_program;
+
+ static std::vector<plugin_preset> *presets;
+ static std::vector<DSSI_Program_Descriptor> *preset_descs;
+#endif
+
+ ladspa_wrapper()
+ {
+ int ins = Module::in_count;
+ int outs = Module::out_count;
+ int params = Module::param_count;
+ ladspa_plugin_info &plugin_info = Module::plugin_info;
+ descriptor.UniqueID = plugin_info.unique_id;
+ descriptor.Label = plugin_info.label;
+ descriptor.Name = plugin_info.name;
+ descriptor.Maker = plugin_info.maker;
+ descriptor.Copyright = plugin_info.copyright;
+ descriptor.Properties = Module::rt_capable ? LADSPA_PROPERTY_HARD_RT_CAPABLE : 0;
+ descriptor.PortCount = ins + outs + params;
+ descriptor.PortNames = new char *[descriptor.PortCount];
+ descriptor.PortDescriptors = new LADSPA_PortDescriptor[descriptor.PortCount];
+ descriptor.PortRangeHints = new LADSPA_PortRangeHint[descriptor.PortCount];
+ int i;
+ for (i = 0; i < ins + outs; i++)
+ {
+ LADSPA_PortRangeHint &prh = ((LADSPA_PortRangeHint *)descriptor.PortRangeHints)[i];
+ ((int *)descriptor.PortDescriptors)[i] = i < ins ? LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO
+ : i < ins + outs ? LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO
+ : LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
+ prh.HintDescriptor = 0;
+ ((const char **)descriptor.PortNames)[i] = Module::port_names[i];
+ }
+ for (; i < ins + outs + params; i++)
+ {
+ LADSPA_PortRangeHint &prh = ((LADSPA_PortRangeHint *)descriptor.PortRangeHints)[i];
+ parameter_properties &pp = Module::param_props[i - ins - outs];
+ ((int *)descriptor.PortDescriptors)[i] =
+ LADSPA_PORT_CONTROL | (pp.flags & PF_PROP_OUTPUT ? LADSPA_PORT_OUTPUT : LADSPA_PORT_INPUT);
+ prh.HintDescriptor = LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_BOUNDED_BELOW;
+ ((const char **)descriptor.PortNames)[i] = pp.name;
+ prh.LowerBound = pp.min;
+ prh.UpperBound = pp.max;
+ switch(pp.flags & PF_TYPEMASK) {
+ case PF_BOOL:
+ prh.HintDescriptor |= LADSPA_HINT_TOGGLED;
+ break;
+ case PF_INT:
+ case PF_ENUM:
+ prh.HintDescriptor |= LADSPA_HINT_INTEGER;
+ break;
+ }
+ switch(pp.flags & PF_SCALEMASK) {
+ case PF_SCALE_LOG:
+ prh.HintDescriptor |= LADSPA_HINT_LOGARITHMIC;
+ break;
+ }
+ }
+ descriptor.ImplementationData = this;
+ descriptor.instantiate = cb_instantiate;
+ descriptor.connect_port = cb_connect;
+ descriptor.activate = cb_activate;
+ descriptor.run = cb_run;
+ descriptor.run_adding = NULL;
+ descriptor.set_run_adding_gain = NULL;
+ descriptor.deactivate = cb_deactivate;
+ descriptor.cleanup = cb_cleanup;
+#if USE_DSSI
+ memset(&dssi_descriptor, 0, sizeof(dssi_descriptor));
+ dssi_descriptor.DSSI_API_Version = 1;
+ dssi_descriptor.LADSPA_Plugin = &descriptor;
+ dssi_descriptor.configure = cb_configure;
+ dssi_descriptor.get_program = cb_get_program;
+ dssi_descriptor.select_program = cb_select_program;
+ dssi_descriptor.run_synth = cb_run_synth;
+
+ presets = new std::vector<plugin_preset>;
+ preset_descs = new std::vector<DSSI_Program_Descriptor>;
+
+ preset_list plist_tmp, plist;
+ plist.load_defaults(true);
+ plist_tmp.load_defaults(false);
+ plist.presets.insert(plist.presets.end(), plist_tmp.presets.begin(), plist_tmp.presets.end());
+
+ // XXXKF this assumes that plugin name in preset is case-insensitive equal to plugin label
+ // if I forget about this, I'll be in a deep trouble
+ dssi_default_program.Bank = 0;
+ dssi_default_program.Program = 0;
+ dssi_default_program.Name = "default";
+
+ int pos = 1;
+ for (unsigned int i = 0; i < plist.presets.size(); i++)
+ {
+ plugin_preset &pp = plist.presets[i];
+ if (strcasecmp(pp.plugin.c_str(), descriptor.Label))
+ continue;
+ DSSI_Program_Descriptor pd;
+ pd.Bank = pos >> 7;
+ pd.Program = pos++;
+ pd.Name = pp.name.c_str();
+ preset_descs->push_back(pd);
+ presets->push_back(pp);
+ }
+ // printf("presets = %p:%d name = %s\n", presets, presets->size(), descriptor.Label);
+
+#endif
+ }
+
+ ~ladspa_wrapper()
+ {
+ delete []descriptor.PortNames;
+ delete []descriptor.PortDescriptors;
+ delete []descriptor.PortRangeHints;
+#if USE_DSSI
+ presets->clear();
+ preset_descs->clear();
+ delete presets;
+ delete preset_descs;
+#endif
+ }
+
+ /// LADSPA instantiation function (create a plugin instance)
+ static LADSPA_Handle cb_instantiate(const struct _LADSPA_Descriptor * Descriptor, unsigned long sample_rate)
+ {
+ instance *mod = new instance();
+ mod->srate = sample_rate;
+ return mod;
+ }
+
+#if USE_DSSI
+ /// DSSI get program descriptor function; for 0, it returns the default program (from parameter properties table), for others, it uses global or user preset
+ static const DSSI_Program_Descriptor *cb_get_program(LADSPA_Handle Instance, unsigned long index) {
+ if (index > presets->size())
+ return NULL;
+ if (index)
+ return &(*preset_descs)[index - 1];
+ return &dssi_default_program;
+ }
+
+ /// DSSI select program function; for 0, it sets the defaults, for others, it sets global or user preset
+ static void cb_select_program(LADSPA_Handle Instance, unsigned long Bank, unsigned long Program) {
+ instance *mod = (instance *)Instance;
+ unsigned int no = (Bank << 7) + Program - 1;
+ // printf("no = %d presets = %p:%d\n", no, presets, presets->size());
+ if (no == -1U) {
+ for (int i =0 ; i < Module::param_count; i++)
+ *mod->params[i] = Module::param_props[i].def_value;
+ return;
+ }
+ if (no >= presets->size())
+ return;
+ plugin_preset &p = (*presets)[no];
+ // printf("activating preset %s\n", p.name.c_str());
+ p.activate(mod);
+ }
+
+#endif
+
+ /// LADSPA port connection function
+ static void cb_connect(LADSPA_Handle Instance, unsigned long port, LADSPA_Data *DataLocation) {
+ unsigned long ins = Module::in_count;
+ unsigned long outs = Module::out_count;
+ unsigned long params = Module::param_count;
+ instance *const mod = (instance *)Instance;
+ if (port < ins)
+ mod->ins[port] = DataLocation;
+ else if (port < ins + outs)
+ mod->outs[port - ins] = DataLocation;
+ else if (port < ins + outs + params) {
+ int i = port - ins - outs;
+ mod->params[i] = DataLocation;
+ *mod->params[i] = Module::param_props[i].def_value;
+ }
+ }
+
+ /// LADSPA activate function (note that at this moment the ports are not set)
+ static void cb_activate(LADSPA_Handle Instance) {
+ instance *const mod = (instance *)Instance;
+ mod->activate_flag = true;
+ }
+
+ /// utility function: zero port values if mask is 0
+ static inline void zero_by_mask(Module *module, uint32_t mask, uint32_t offset, uint32_t nsamples)
+ {
+ for (int i=0; i<Module::out_count; i++) {
+ if ((mask & (1 << i)) == 0) {
+ dsp::zero(module->outs[i] + offset, nsamples);
+ }
+ }
+ }
+
+ /// LADSPA run function - does set sample rate / activate logic when it's run first time after activation
+ static void cb_run(LADSPA_Handle Instance, unsigned long SampleCount) {
+ instance *const mod = (instance *)Instance;
+ if (mod->activate_flag)
+ {
+ mod->set_sample_rate(mod->srate);
+ mod->activate();
+ mod->activate_flag = false;
+ }
+ mod->params_changed();
+ process_slice(mod, 0, SampleCount);
+ }
+
+ /// utility function: call process, and if it returned zeros in output masks, zero out the relevant output port buffers
+ static inline void process_slice(Module *mod, uint32_t offset, uint32_t end)
+ {
+ while(offset < end)
+ {
+ uint32_t newend = std::min(offset + MAX_SAMPLE_RUN, end);
+ uint32_t out_mask = mod->process(offset, newend - offset, -1, -1);
+ zero_by_mask(mod, out_mask, offset, newend - offset);
+ offset = newend;
+ }
+ }
+
+#if USE_DSSI
+ /// DSSI "run synth" function, same as run() except it allows for event delivery
+ static void cb_run_synth(LADSPA_Handle Instance, unsigned long SampleCount,
+ snd_seq_event_t *Events, unsigned long EventCount) {
+ instance *const mod = (instance *)Instance;
+ if (mod->activate_flag)
+ {
+ mod->set_sample_rate(mod->srate);
+ mod->activate();
+ mod->activate_flag = false;
+ }
+ mod->params_changed();
+
+ uint32_t offset = 0;
+ for (uint32_t e = 0; e < EventCount; e++)
+ {
+ uint32_t timestamp = Events[e].time.tick;
+ if (timestamp != offset)
+ process_slice(mod, offset, timestamp);
+ process_dssi_event(mod, Events[e]);
+ offset = timestamp;
+ }
+ if (offset != SampleCount)
+ process_slice(mod, offset, SampleCount);
+ }
+
+ /// DSSI configure function (named properties)
+ static char *cb_configure(LADSPA_Handle Instance,
+ const char *Key,
+ const char *Value)
+ {
+ instance *const mod = (instance *)Instance;
+ return mod->configure(Key, Value);
+ }
+
+ /// Utility function: handle MIDI event (only handles a subset in this version)
+ static void process_dssi_event(Module *module, snd_seq_event_t &event)
+ {
+ switch(event.type) {
+ case SND_SEQ_EVENT_NOTEON:
+ module->note_on(event.data.note.note, event.data.note.velocity);
+ break;
+ case SND_SEQ_EVENT_NOTEOFF:
+ module->note_off(event.data.note.note, event.data.note.velocity);
+ break;
+ case SND_SEQ_EVENT_PGMCHANGE:
+ module->program_change(event.data.control.value);
+ break;
+ case SND_SEQ_EVENT_CONTROLLER:
+ module->control_change(event.data.control.param, event.data.control.value);
+ break;
+ case SND_SEQ_EVENT_PITCHBEND:
+ module->pitch_bend(event.data.control.value);
+ break;
+ }
+ }
+#endif
+
+ /// LADSPA deactivate function
+ static void cb_deactivate(LADSPA_Handle Instance) {
+ instance *const mod = (instance *)Instance;
+ mod->deactivate();
+ }
+
+ /// LADSPA cleanup (delete instance) function
+ static void cb_cleanup(LADSPA_Handle Instance) {
+ instance *const mod = (instance *)Instance;
+ delete mod;
+ }
+
+ /// Get a wrapper singleton - used to prevent initialization order problems which were present in older versions
+ static ladspa_wrapper &get() {
+ static ladspa_wrapper instance;
+ return instance;
+ }
+};
+
+template<class Module>
+LADSPA_Descriptor ladspa_wrapper<Module>::descriptor;
+
+#if USE_DSSI
+
+template<class Module>
+DSSI_Descriptor ladspa_wrapper<Module>::dssi_descriptor;
+
+template<class Module>
+DSSI_Program_Descriptor ladspa_wrapper<Module>::dssi_default_program;
+
+template<class Module>
+std::vector<plugin_preset> *ladspa_wrapper<Module>::presets;
+
+template<class Module>
+std::vector<DSSI_Program_Descriptor> *ladspa_wrapper<Module>::preset_descs;
+#endif
+
+};
+
+#endif
+
+#endif
diff --git a/src/calf/utils.h b/src/calf/utils.h
index 9babfa6..e791399 100644
--- a/src/calf/utils.h
+++ b/src/calf/utils.h
@@ -23,6 +23,7 @@
#include <pthread.h>
#include <map>
+#include <string>
namespace calf_utils
{
@@ -109,6 +110,22 @@ typedef std::map<std::string, std::string> dictionary;
extern std::string encodeMap(const dictionary &data);
extern void decodeMap(dictionary &data, const std::string &src);
+static inline std::string i2s(int value)
+{
+ char buf[32];
+ sprintf(buf, "%d", value);
+
+ return std::string(buf);
+}
+
+static inline std::string f2s(double value)
+{
+ // XXXKF might not work with some locale settings
+ char buf[64];
+ sprintf(buf, "%g", value);
+ return buf;
+}
+
};
#endif
diff --git a/src/giface.cpp b/src/giface.cpp
index 8ce4dd3..8ea3e77 100644
--- a/src/giface.cpp
+++ b/src/giface.cpp
@@ -27,22 +27,7 @@
using namespace synth;
using namespace std;
-
-static std::string i2s(int value)
-{
- char buf[32];
- sprintf(buf, "%d", value);
-
- return string(buf);
-}
-
-static string f2s(double value)
-{
- // XXXKF might not work with some locale settings
- char buf[64];
- sprintf(buf, "%g", value);
- return buf;
-}
+using namespace calf_utils;
float parameter_properties::from_01(double value01) const
{
@@ -215,77 +200,3 @@ std::string synth::xml_escape(const std::string &src)
return dest;
}
-#if USE_LADSPA
-
-static std::string unit_to_string(parameter_properties &props)
-{
- uint32_t flags = props.flags & PF_UNITMASK;
-
- switch(flags) {
- case PF_UNIT_DB:
- return "ladspa:hasUnit=\"&ladspa;dB\" ";
- case PF_UNIT_COEF:
- return "ladspa:hasUnit=\"&ladspa;coef\" ";
- case PF_UNIT_HZ:
- return "ladspa:hasUnit=\"&ladspa;Hz\" ";
- case PF_UNIT_SEC:
- return "ladspa:hasUnit=\"&ladspa;seconds\" ";
- case PF_UNIT_MSEC:
- return "ladspa:hasUnit=\"&ladspa;milliseconds\" ";
- default:
- return string();
- }
-}
-
-static std::string scale_to_string(parameter_properties &props)
-{
- if ((props.flags & PF_TYPEMASK) != PF_ENUM) {
- return "/";
- }
- string tmp = "><ladspa:hasScale><ladspa:Scale>\n";
- for (int i = (int)props.min; i <= (int)props.max; i++) {
- tmp += " <ladspa:hasPoint><ladspa:Point rdf:value=\""+i2s(i)+"\" ladspa:hasLabel=\""+props.choices[(int)(i - props.min)]+"\" /></ladspa:hasPoint>\n";
- }
- return tmp+" </ladspa:Scale></ladspa:hasScale></ladspa:InputControlPort";
-}
-
-std::string synth::generate_ladspa_rdf(const ladspa_plugin_info &info, parameter_properties *params, const char *param_names[], unsigned int count,
- unsigned int ctl_ofs)
-{
- string rdf;
- string plugin_id = "&ladspa;" + i2s(info.unique_id);
- string plugin_type = string(info.plugin_type);
-
- rdf += " <ladspa:" + plugin_type + " rdf:about=\"" + plugin_id + "\">\n";
- rdf += " <dc:creator>" + xml_escape(info.maker) + "</dc:creator>\n";
- rdf += " <dc:title>" + xml_escape(info.name) + "</dc:title>\n";
-
- for (unsigned int i = 0; i < count; i++) {
- rdf +=
- " <ladspa:hasPort>\n"
- " <ladspa:" + string(params[i].flags & PF_PROP_OUTPUT ? "Output" : "Input")
- + "ControlPort rdf:about=\"" + plugin_id + "."+i2s(ctl_ofs + i)+"\" "
- + unit_to_string(params[i]) +
- "ladspa:hasLabel=\"" + params[i].short_name + "\" "
- + scale_to_string(params[i]) +
- ">\n"
- " </ladspa:hasPort>\n";
- }
- rdf += " <ladspa:hasSetting>\n"
- " <ladspa:Default>\n";
- for (unsigned int i = 0; i < count; i++) {
- rdf +=
- " <ladspa:hasPortValue>\n"
- " <ladspa:PortValue rdf:value=\"" + f2s(params[i].def_value) + "\">\n"
- " <ladspa:forPort rdf:resource=\"" + plugin_id + "." + i2s(ctl_ofs + i) + "\"/>\n"
- " </ladspa:PortValue>\n"
- " </ladspa:hasPortValue>\n";
- }
- rdf += " </ladspa:Default>\n"
- " </ladspa:hasSetting>\n";
-
- rdf += " </ladspa:" + plugin_type + ">\n";
- return rdf;
-}
-
-#endif
diff --git a/src/makerdf.cpp b/src/makerdf.cpp
index a50294b..a0a9466 100644
--- a/src/makerdf.cpp
+++ b/src/makerdf.cpp
@@ -25,6 +25,7 @@
#include <calf/modules.h>
#include <calf/modules_dev.h>
#include <calf/plugininfo.h>
+#include <calf/utils.h>
#if USE_LV2
#include <calf/lv2_event.h>
#include <calf/lv2_uri_map.h>
@@ -32,6 +33,7 @@
using namespace std;
using namespace synth;
+using namespace calf_utils;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
@@ -41,6 +43,78 @@ static struct option long_options[] = {
};
#if USE_LADSPA
+
+static std::string unit_to_string(parameter_properties &props)
+{
+ uint32_t flags = props.flags & PF_UNITMASK;
+
+ switch(flags) {
+ case PF_UNIT_DB:
+ return "ladspa:hasUnit=\"&ladspa;dB\" ";
+ case PF_UNIT_COEF:
+ return "ladspa:hasUnit=\"&ladspa;coef\" ";
+ case PF_UNIT_HZ:
+ return "ladspa:hasUnit=\"&ladspa;Hz\" ";
+ case PF_UNIT_SEC:
+ return "ladspa:hasUnit=\"&ladspa;seconds\" ";
+ case PF_UNIT_MSEC:
+ return "ladspa:hasUnit=\"&ladspa;milliseconds\" ";
+ default:
+ return string();
+ }
+}
+
+static std::string scale_to_string(parameter_properties &props)
+{
+ if ((props.flags & PF_TYPEMASK) != PF_ENUM) {
+ return "/";
+ }
+ string tmp = "><ladspa:hasScale><ladspa:Scale>\n";
+ for (int i = (int)props.min; i <= (int)props.max; i++) {
+ tmp += " <ladspa:hasPoint><ladspa:Point rdf:value=\""+i2s(i)+"\" ladspa:hasLabel=\""+props.choices[(int)(i - props.min)]+"\" /></ladspa:hasPoint>\n";
+ }
+ return tmp+" </ladspa:Scale></ladspa:hasScale></ladspa:InputControlPort";
+}
+
+std::string generate_ladspa_rdf(const ladspa_plugin_info &info, parameter_properties *params, const char *param_names[], unsigned int count,
+ unsigned int ctl_ofs)
+{
+ string rdf;
+ string plugin_id = "&ladspa;" + i2s(info.unique_id);
+ string plugin_type = string(info.plugin_type);
+
+ rdf += " <ladspa:" + plugin_type + " rdf:about=\"" + plugin_id + "\">\n";
+ rdf += " <dc:creator>" + xml_escape(info.maker) + "</dc:creator>\n";
+ rdf += " <dc:title>" + xml_escape(info.name) + "</dc:title>\n";
+
+ for (unsigned int i = 0; i < count; i++) {
+ rdf +=
+ " <ladspa:hasPort>\n"
+ " <ladspa:" + string(params[i].flags & PF_PROP_OUTPUT ? "Output" : "Input")
+ + "ControlPort rdf:about=\"" + plugin_id + "."+i2s(ctl_ofs + i)+"\" "
+ + unit_to_string(params[i]) +
+ "ladspa:hasLabel=\"" + params[i].short_name + "\" "
+ + scale_to_string(params[i]) +
+ ">\n"
+ " </ladspa:hasPort>\n";
+ }
+ rdf += " <ladspa:hasSetting>\n"
+ " <ladspa:Default>\n";
+ for (unsigned int i = 0; i < count; i++) {
+ rdf +=
+ " <ladspa:hasPortValue>\n"
+ " <ladspa:PortValue rdf:value=\"" + f2s(params[i].def_value) + "\">\n"
+ " <ladspa:forPort rdf:resource=\"" + plugin_id + "." + i2s(ctl_ofs + i) + "\"/>\n"
+ " </ladspa:PortValue>\n"
+ " </ladspa:hasPortValue>\n";
+ }
+ rdf += " </ladspa:Default>\n"
+ " </ladspa:hasSetting>\n";
+
+ rdf += " </ladspa:" + plugin_type + ">\n";
+ return rdf;
+}
+
void make_rdf()
{
string rdf;
@@ -56,7 +130,7 @@ void make_rdf()
rdf += "<rdf:RDF xmlns:rdf=\"&rdf;\" xmlns:rdfs=\"&rdfs;\" xmlns:dc=\"&dc;\" xmlns:ladspa=\"&ladspa;\">\n";
#define RDF_EXPR(Module) \
- synth::generate_ladspa_rdf(Module::plugin_info, Module::param_props, Module::port_names, Module::param_count, Module::in_count + Module::out_count);
+ generate_ladspa_rdf(Module::plugin_info, Module::param_props, Module::port_names, Module::param_count, Module::in_count + Module::out_count);
#define PER_MODULE_ITEM(name, isSynth, jackname) if (!isSynth) rdf += RDF_EXPR(name##_audio_module)
#define PER_SMALL_MODULE_ITEM(...)
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 45d155b..7a881eb 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -19,6 +19,7 @@
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
+#include <calf/ladspa_wrap.h>
#include <calf/lv2wrap.h>
#include <calf/modules.h>
#include <calf/modules_dev.h>
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list