X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fladspa_plugin.cc;h=cebff597710567f42361186b777faf4171d00544;hb=d7e39ee5c779ab5e118ecea60bb3f86e94fba069;hp=43fa8e43eea7698cbe0370265788ecb4d4e327d3;hpb=80c61db0cda63e565197abcbbc11b504c9a76c17;p=ardour.git diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index 43fa8e43ee..cebff59771 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -37,9 +37,7 @@ #include "midi++/manager.h" -#include "ardour/ardour.h" #include "ardour/session.h" -#include "ardour/audioengine.h" #include "ardour/ladspa_plugin.h" #include "ardour/buffer_set.h" #include "ardour/audio_buffer.h" @@ -178,32 +176,17 @@ LadspaPlugin::default_value (uint32_t port) } else if (LADSPA_IS_HINT_DEFAULT_LOW(prh[port].HintDescriptor)) { - if (LADSPA_IS_HINT_LOGARITHMIC(prh[port].HintDescriptor)) { - ret = exp(log(prh[port].LowerBound) * 0.75f + log(prh[port].UpperBound) * 0.25f); - } - else { - ret = prh[port].LowerBound * 0.75f + prh[port].UpperBound * 0.25f; - } + ret = prh[port].LowerBound * 0.75f + prh[port].UpperBound * 0.25f; bounds_given = true; sr_scaling = true; } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(prh[port].HintDescriptor)) { - if (LADSPA_IS_HINT_LOGARITHMIC(prh[port].HintDescriptor)) { - ret = exp(log(prh[port].LowerBound) * 0.5f + log(prh[port].UpperBound) * 0.5f); - } - else { - ret = prh[port].LowerBound * 0.5f + prh[port].UpperBound * 0.5f; - } + ret = prh[port].LowerBound * 0.5f + prh[port].UpperBound * 0.5f; bounds_given = true; sr_scaling = true; } else if (LADSPA_IS_HINT_DEFAULT_HIGH(prh[port].HintDescriptor)) { - if (LADSPA_IS_HINT_LOGARITHMIC(prh[port].HintDescriptor)) { - ret = exp(log(prh[port].LowerBound) * 0.25f + log(prh[port].UpperBound) * 0.75f); - } - else { - ret = prh[port].LowerBound * 0.25f + prh[port].UpperBound * 0.75f; - } + ret = prh[port].LowerBound * 0.25f + prh[port].UpperBound * 0.75f; bounds_given = true; sr_scaling = true; } @@ -296,23 +279,30 @@ void LadspaPlugin::set_parameter (uint32_t which, float val) { if (which < _descriptor->PortCount) { + + if (get_parameter (which) == val) { + return; + } + _shadow_data[which] = (LADSPA_Data) val; -#if 0 - ParameterChanged (Parameter(PluginAutomation, 0, which), val); /* EMIT SIGNAL */ +#if 0 if (which < parameter_count() && controls[which]) { controls[which]->Changed (); } #endif } else { - warning << string_compose (_("illegal parameter number used with plugin \"%1\". This may" - "indicate a change in the plugin design, and presets may be" + warning << string_compose (_("illegal parameter number used with plugin \"%1\". This may " + "indicate a change in the plugin design, and presets may be " "invalid"), name()) << endmsg; } + + Plugin::set_parameter (which, val); } +/** @return `plugin' value */ float LadspaPlugin::get_parameter (uint32_t which) const { @@ -341,10 +331,9 @@ LadspaPlugin::nth_parameter (uint32_t n, bool& ok) const return 0; } -XMLNode& -LadspaPlugin::get_state() +void +LadspaPlugin::add_state (XMLNode* root) const { - XMLNode *root = new XMLNode(state_node_name()); XMLNode *child; char buf[16]; LocaleGuard lg (X_("POSIX")); @@ -362,8 +351,6 @@ LadspaPlugin::get_state() root->add_child_nocopy (*child); } } - - return *root; } int @@ -372,7 +359,7 @@ LadspaPlugin::set_state (const XMLNode& node, int version) if (version < 3000) { return set_state_2X (node, version); } - + XMLNodeList nodes; XMLProperty *prop; XMLNodeConstIterator iter; @@ -389,7 +376,7 @@ LadspaPlugin::set_state (const XMLNode& node, int version) nodes = node.children ("Port"); - for(iter = nodes.begin(); iter != nodes.end(); ++iter){ + for (iter = nodes.begin(); iter != nodes.end(); ++iter) { child = *iter; @@ -412,7 +399,7 @@ LadspaPlugin::set_state (const XMLNode& node, int version) latency_compute_run (); - return 0; + return Plugin::set_state (node, version); } int @@ -560,20 +547,28 @@ LadspaPlugin::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t offset) { Plugin::connect_and_run (bufs, in_map, out_map, nframes, offset); - + cycles_t now; cycles_t then = get_cycles (); + BufferSet& silent_bufs = _session.get_silent_buffers(ChanCount(DataType::AUDIO, 1)); + BufferSet& scratch_bufs = _session.get_silent_buffers(ChanCount(DataType::AUDIO, 1)); + uint32_t audio_in_index = 0; uint32_t audio_out_index = 0; + bool valid; for (uint32_t port_index = 0; port_index < parameter_count(); ++port_index) { if (LADSPA_IS_PORT_AUDIO(port_descriptor(port_index))) { if (LADSPA_IS_PORT_INPUT(port_descriptor(port_index))) { - const uint32_t buf_index = in_map.get(DataType::AUDIO, audio_in_index++); - connect_port(port_index, bufs.get_audio(buf_index).data(offset)); + const uint32_t buf_index = in_map.get(DataType::AUDIO, audio_in_index++, &valid); + connect_port(port_index, + valid ? bufs.get_audio(buf_index).data(offset) + : silent_bufs.get_audio(0).data(offset)); } else if (LADSPA_IS_PORT_OUTPUT(port_descriptor(port_index))) { - const uint32_t buf_index = out_map.get(DataType::AUDIO, audio_out_index++); - connect_port(port_index, bufs.get_audio(buf_index).data(offset)); + const uint32_t buf_index = out_map.get(DataType::AUDIO, audio_out_index++, &valid); + connect_port(port_index, + valid ? bufs.get_audio(buf_index).data(offset) + : scratch_bufs.get_audio(0).data(offset)); } } } @@ -621,6 +616,28 @@ LadspaPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const } } +boost::shared_ptr +LadspaPlugin::get_scale_points(uint32_t port_index) const +{ + const uint32_t id = atol(unique_id().c_str()); + lrdf_defaults* points = lrdf_get_scale_values(id, port_index); + + boost::shared_ptr ret; + if (!points) { + return ret; + } + + ret = boost::shared_ptr(new ScalePoints()); + + for (uint32_t i = 0; i < points->count; ++i) { + ret->insert(make_pair(points->items[i].label, + points->items[i].value)); + } + + lrdf_free_setting_values(points); + return ret; +} + void LadspaPlugin::run_in_place (pframes_t nframes) { @@ -631,7 +648,7 @@ LadspaPlugin::run_in_place (pframes_t nframes) } assert (_was_activated); - + _descriptor->run (_handle, nframes); } @@ -709,15 +726,14 @@ LadspaPluginInfo::LadspaPluginInfo() } -vector -LadspaPlugin::get_presets () +void +LadspaPlugin::find_presets () { - vector result; uint32_t id; std::string unique (unique_id()); if (!isdigit (unique[0])) { - return result; + return; } id = atol (unique.c_str()); @@ -727,47 +743,43 @@ LadspaPlugin::get_presets () if (set_uris) { for (uint32_t i = 0; i < (uint32_t) set_uris->count; ++i) { if (char* label = lrdf_get_label(set_uris->items[i])) { - PresetRecord rec(set_uris->items[i], label); - result.push_back(rec); + PresetRecord rec (set_uris->items[i], label); _presets.insert (make_pair (set_uris->items[i], rec)); } } lrdf_free_uris(set_uris); } - - return result; } bool -LadspaPlugin::load_preset (const string& preset_uri) +LadspaPlugin::load_preset (PresetRecord r) { - lrdf_defaults* defs = lrdf_get_setting_values(preset_uri.c_str()); + lrdf_defaults* defs = lrdf_get_setting_values (r.uri.c_str()); if (defs) { for (uint32_t i = 0; i < (uint32_t) defs->count; ++i) { - // The defs->items[i].pid < defs->count check is to work around - // a bug in liblrdf that saves invalid values into the presets file. - if (((uint32_t) defs->items[i].pid < (uint32_t) defs->count) && parameter_is_input (defs->items[i].pid)) { + if (parameter_is_input (defs->items[i].pid)) { set_parameter(defs->items[i].pid, defs->items[i].value); } } lrdf_free_setting_values(defs); } + Plugin::load_preset (r); return true; } /* XXX: should be in liblrdf */ static void -lrdf_remove_preset (const char *source, const char *setting_uri) +lrdf_remove_preset (const char* /*source*/, const char *setting_uri) { lrdf_statement p; lrdf_statement *q; lrdf_statement *i; char setting_uri_copy[64]; char buf[64]; - + strncpy(setting_uri_copy, setting_uri, sizeof(setting_uri_copy)); p.subject = setting_uri_copy; @@ -810,7 +822,7 @@ LadspaPlugin::do_remove_preset (string name) if (!p) { return; } - + string const source = preset_source (envvar); lrdf_remove_preset (source.c_str(), p->uri.c_str ()); @@ -824,7 +836,7 @@ LadspaPlugin::preset_envvar () const if ((envvar = getenv ("HOME")) == 0) { return ""; } - + return envvar; } @@ -862,8 +874,14 @@ LadspaPlugin::write_preset_file (string envvar) string LadspaPlugin::do_save_preset (string name) { - lrdf_portvalue portvalues[parameter_count()]; - lrdf_defaults defaults; + /* make a vector of pids that are input parameters */ + vector input_parameter_pids; + for (uint32_t i = 0; i < parameter_count(); ++i) { + if (parameter_is_input (i)) { + input_parameter_pids.push_back (i); + } + } + std::string unique (unique_id()); if (!isdigit (unique[0])) { @@ -872,14 +890,14 @@ LadspaPlugin::do_save_preset (string name) uint32_t const id = atol (unique.c_str()); - defaults.count = parameter_count(); + lrdf_defaults defaults; + defaults.count = input_parameter_pids.size (); + lrdf_portvalue portvalues[input_parameter_pids.size()]; defaults.items = portvalues; - for (uint32_t i = 0; i < parameter_count(); ++i) { - if (parameter_is_input (i)) { - portvalues[i].pid = i; - portvalues[i].value = get_parameter(i); - } + for (vector::size_type i = 0; i < input_parameter_pids.size(); ++i) { + portvalues[i].pid = input_parameter_pids[i]; + portvalues[i].value = get_parameter (input_parameter_pids[i]); } string const envvar = preset_envvar (); @@ -901,3 +919,16 @@ LadspaPlugin::do_save_preset (string name) return uri; } +LADSPA_PortDescriptor +LadspaPlugin::port_descriptor (uint32_t i) const +{ + if (i < _descriptor->PortCount) { + return _descriptor->PortDescriptors[i]; + } + + warning << "LADSPA plugin port index " << i << " out of range." << endmsg; + return 0; +} + + +