X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fplugin_insert.cc;h=b174ceb2fe57ce67d32b669765ae38ab5d03a177;hb=1503db4a28fe01650bb8619f5f38fccb312474ab;hp=98ff9ab4f0983040e1fc1eb0d49a42788dfab612;hpb=22b07e0233a29d9633ffa825a79503befaf2e16e;p=ardour.git diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index 98ff9ab4f0..b174ceb2fe 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -33,6 +33,7 @@ #include "ardour/debug.h" #include "ardour/event_type_map.h" #include "ardour/ladspa_plugin.h" +#include "ardour/luaproc.h" #include "ardour/plugin.h" #include "ardour/plugin_insert.h" @@ -67,6 +68,10 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr plug) : Processor (s, (plug ? plug->name() : string ("toBeRenamed"))) , _signal_analysis_collected_nframes(0) , _signal_analysis_collect_nframes_max(0) + , _no_inplace (false) + , _pending_no_inplace (false) + , _strict_io (false) + , _strict_io_configured (false) { /* the first is the master */ @@ -137,7 +142,10 @@ PluginInsert::output_streams() const PluginInfoPtr info = _plugins.front()->get_info(); - if (info->reconfigurable_io()) { + if (_strict_io_configured) { + return _configured_in; // XXX, check initial configuration + } + else if (info->reconfigurable_io()) { ChanCount out = _plugins.front()->output_streams (); // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, reconfigur(able) output streams = %1\n", out)); return out; @@ -250,7 +258,9 @@ PluginInsert::create_automatable_parameters () can_automate (param); boost::shared_ptr list(new AutomationList(param, desc)); - add_control (boost::shared_ptr (new PluginControl(this, param, desc, list))); + boost::shared_ptr c (new PluginControl(this, param, desc, list)); + add_control (c); + _plugins.front()->set_automation_control (i->id(), c); } else if (i->type() == PluginPropertyAutomation) { Evoral::Parameter param(*i); const ParameterDescriptor& desc = _plugins.front()->get_property_descriptor(param.id()); @@ -264,26 +274,53 @@ PluginInsert::create_automatable_parameters () } } } - +/** Called when something outside of this host has modified a plugin + * parameter. Responsible for propagating the change to two places: + * + * 1) anything listening to the Control itself + * 2) any replicated plugins that make up this PluginInsert. + * + * The PluginInsert is connected to the ParameterChangedExternally signal for + * the first (primary) plugin, and here broadcasts that change to any others. + * + * XXX We should probably drop this whole replication idea (Paul, October 2015) + * since it isn't used by sensible plugin APIs (AU, LV2). + */ void -PluginInsert::parameter_changed (uint32_t which, float val) +PluginInsert::parameter_changed_externally (uint32_t which, float val) { boost::shared_ptr ac = automation_control (Evoral::Parameter (PluginAutomation, 0, which)); - if (ac) { - ac->set_value (val); + /* First propagation: alter the underlying value of the control, + * without telling the plugin(s) that own/use it to set it. + */ + + if (!ac) { + return; + } + + boost::shared_ptr pc = boost::dynamic_pointer_cast (ac); - Plugins::iterator i = _plugins.begin(); + if (pc) { + pc->catch_up_with_external_value (val); + } + + /* Second propagation: tell all plugins except the first to + update the value of this parameter. For sane plugin APIs, + there are no other plugins, so this is a no-op in those + cases. + */ - /* don't set the first plugin, just all the slaves */ + Plugins::iterator i = _plugins.begin(); - if (i != _plugins.end()) { - ++i; - for (; i != _plugins.end(); ++i) { - (*i)->set_parameter (which, val); - } - } - } + /* don't set the first plugin, just all the slaves */ + + if (i != _plugins.end()) { + ++i; + for (; i != _plugins.end(); ++i) { + (*i)->set_parameter (which, val); + } + } } int @@ -329,6 +366,7 @@ PluginInsert::flush () void PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t offset, bool with_auto, framepos_t now) { + _no_inplace = _pending_no_inplace; // Calculate if, and how many frames we need to collect for analysis framecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max - _signal_analysis_collected_nframes); @@ -339,19 +377,17 @@ PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t of ChanCount const in_streams = input_streams (); ChanCount const out_streams = output_streams (); - ChanMapping in_map (in_streams); - ChanMapping out_map (out_streams); - bool valid; if (_match.method == Split) { + assert (_in_map.size () == 1); /* fix the input mapping so that we have maps for each of the plugin's inputs */ - in_map = ChanMapping (natural_input_streams ()); /* copy the first stream's buffer contents to the others */ /* XXX: audio only */ - uint32_t first_idx = in_map.get (DataType::AUDIO, 0, &valid); + bool valid; + uint32_t first_idx = _in_map[0].get (DataType::AUDIO, 0, &valid); if (valid) { for (uint32_t i = in_streams.n_audio(); i < natural_input_streams().n_audio(); ++i) { - bufs.get_audio(in_map.get (DataType::AUDIO, i, &valid)).read_from(bufs.get_audio(first_idx), nframes, offset, offset); + bufs.get_audio(_in_map[0].get (DataType::AUDIO, i, &valid)).read_from(bufs.get_audio(first_idx), nframes, offset, offset); } } } @@ -378,7 +414,16 @@ PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t of const float val = c->list()->rt_safe_eval (now, valid); if (valid) { - c->set_value(val); + /* This is the ONLY place where we are + * allowed to call + * AutomationControl::set_value_unchecked(). We + * know that the control is in + * automation playback mode, so no + * check on writable() is required + * (which must be done in AutomationControl::set_value() + * + */ + c->set_value_unchecked(val); } } @@ -402,11 +447,71 @@ PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t of } - for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { - (*i)->connect_and_run(bufs, in_map, out_map, nframes, offset); - for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { - in_map.offset_to(*t, natural_input_streams().get(*t)); - out_map.offset_to(*t, natural_output_streams().get(*t)); + if (_no_inplace) { + BufferSet& inplace_bufs = _session.get_noinplace_buffers(); + + uint32_t pc = 0; + for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) { + + ARDOUR::ChanMapping in_map (natural_input_streams()); + ARDOUR::ChanMapping out_map; + ARDOUR::ChanCount mapped; + ARDOUR::ChanCount backmap; + + // map inputs sequentially + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) { + bool valid; + uint32_t in_idx = _in_map[pc].get (*t, in, &valid); + uint32_t m = mapped.get (*t); + if (valid) { + inplace_bufs.get (*t, m).read_from (bufs.get (*t, in_idx), nframes, offset, offset); + } else { + inplace_bufs.get (*t, m).silence (nframes, offset); + } + mapped.set (*t, m + 1); + } + } + + backmap = mapped; + + // map outputs + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) { + uint32_t m = mapped.get (*t); + inplace_bufs.get (*t, m).silence (nframes, offset); + out_map.set (*t, out, m); + mapped.set (*t, m + 1); + } + } + + if ((*i)->connect_and_run(inplace_bufs, in_map, out_map, nframes, offset)) { + deactivate (); + } + + // clear output buffers + bufs.silence (nframes, offset); + + // copy back outputs + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) { + uint32_t m = backmap.get (*t); + bool valid; + uint32_t out_idx = _out_map[pc].get (*t, out, &valid); + if (valid) { + bufs.get (*t, out_idx).read_from (inplace_bufs.get (*t, m), nframes, offset, offset); + } + backmap.set (*t, m + 1); + } + } + } + + } else { + uint32_t pc = 0; + for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) { + if ((*i)->connect_and_run(bufs, _in_map[pc], _out_map[pc], nframes, offset)) { + deactivate (); + } } } @@ -445,13 +550,8 @@ PluginInsert::silence (framecnt_t nframes) return; } - ChanMapping in_map(input_streams()); - ChanMapping out_map(output_streams()); - - if (_match.method == Split) { - /* fix the input mapping so that we have maps for each of the plugin's inputs */ - in_map = ChanMapping (natural_input_streams ()); - } + ChanMapping in_map (natural_input_streams ()); + ChanMapping out_map (natural_output_streams ()); for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { (*i)->connect_and_run (_session.get_scratch_buffers ((*i)->get_info()->n_inputs, true), in_map, out_map, nframes, 0); @@ -506,41 +606,6 @@ PluginInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t /*end_fra } -void -PluginInsert::set_parameter (Evoral::Parameter param, float val) -{ - if (param.type() != PluginAutomation) { - return; - } - - /* the others will be set from the event triggered by this */ - - _plugins[0]->set_parameter (param.id(), val); - - boost::shared_ptr ac - = boost::dynamic_pointer_cast(control(param)); - - if (ac) { - ac->set_value(val); - } else { - warning << "set_parameter called for nonexistent parameter " - << EventTypeMap::instance().to_symbol(param) << endmsg; - } - - _session.set_dirty(); -} - -float -PluginInsert::get_parameter (Evoral::Parameter param) -{ - if (param.type() != PluginAutomation) { - return 0.0; - } else { - assert (!_plugins.empty ()); - return _plugins[0]->get_parameter (param.id()); - } -} - void PluginInsert::automation_run (BufferSet& bufs, framepos_t start, pframes_t nframes) { @@ -556,7 +621,7 @@ PluginInsert::automation_run (BufferSet& bufs, framepos_t start, pframes_t nfram return; } - if (!find_next_event (now, end, next_event) || requires_fixed_sized_buffers()) { + if (!find_next_event (now, end, next_event) || _plugins.front()->requires_fixed_sized_buffers()) { /* no events have a time within the relevant range */ @@ -659,7 +724,7 @@ PluginInsert::reset_parameters_to_default () continue; } - ac->set_value (dflt); + ac->set_value (dflt, Controllable::NoGroup); } return all; } @@ -668,6 +733,7 @@ boost::shared_ptr PluginInsert::plugin_factory (boost::shared_ptr other) { boost::shared_ptr lp; + boost::shared_ptr lua; #ifdef LV2_SUPPORT boost::shared_ptr lv2p; #endif @@ -683,6 +749,8 @@ PluginInsert::plugin_factory (boost::shared_ptr other) if ((lp = boost::dynamic_pointer_cast (other)) != 0) { return boost::shared_ptr (new LadspaPlugin (*lp)); + } else if ((lua = boost::dynamic_pointer_cast (other)) != 0) { + return boost::shared_ptr (new LuaProc (*lua)); #ifdef LV2_SUPPORT } else if ((lv2p = boost::dynamic_pointer_cast (other)) != 0) { return boost::shared_ptr (new LV2Plugin (*lv2p)); @@ -743,6 +811,24 @@ PluginInsert::configure_io (ChanCount in, ChanCount out) break; } + // TODO make configurable + uint32_t pc = 0; + for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) { + if (_match.method == Split) { + /* TODO see PluginInsert::connect_and_run, channel replication */ + _in_map[pc] = ChanMapping (natural_input_streams ()); + } else { + _in_map[pc] = ChanMapping (input_streams ()); + } + _out_map[pc] = ChanMapping (output_streams()); + + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + _in_map[pc].offset_to(*t, pc * natural_input_streams().get(*t)); + _out_map[pc].offset_to(*t, pc * natural_output_streams().get(*t)); + } + } + + if ( (old_match.method != _match.method && (old_match.method == Split || _match.method == Split)) || old_in != in || old_out != out @@ -787,6 +873,7 @@ PluginInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out) PluginInsert::Match PluginInsert::private_can_support_io_configuration (ChanCount const & inx, ChanCount& out) { + _strict_io_configured = false; if (_plugins.empty()) { return Match(); } @@ -802,6 +889,11 @@ PluginInsert::private_can_support_io_configuration (ChanCount const & inx, ChanC return Match (Impossible, 0); } + if (_strict_io && in.n_audio() < out.n_audio()) { + DEBUG_TRACE (DEBUG::Processors, string_compose ("hiding output ports of reconfigurable %1\n", name())); + out.set (DataType::AUDIO, in.get (DataType::AUDIO)); + } + return Match (Delegate, 1); } @@ -832,7 +924,7 @@ PluginInsert::private_can_support_io_configuration (ChanCount const & inx, ChanC } /* Plugin inputs match requested inputs exactly */ - if (inputs == in) { + if (inputs == in && (!_strict_io || outputs.n_audio() == inputs.n_audio())) { out = outputs + midi_bypass; return Match (ExactMatch, 1); } @@ -887,7 +979,7 @@ PluginInsert::private_can_support_io_configuration (ChanCount const & inx, ChanC plugin inputs? Let me count the ways ... */ - bool can_split = true; + bool can_split = !_strict_io; for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { bool const can_split_type = (in.get (*t) == 1 && inputs.get (*t) > 1); @@ -923,7 +1015,12 @@ PluginInsert::private_can_support_io_configuration (ChanCount const & inx, ChanC } if (could_hide && !cannot_hide) { - out = outputs + midi_bypass; + if (_strict_io && inputs.get (DataType::AUDIO) == outputs.get (DataType::AUDIO)) { + _strict_io_configured = true; + outputs = inputs; + } else { + out = outputs + midi_bypass; + } return Match (Hide, 1, hide_channels); } @@ -951,6 +1048,7 @@ PluginInsert::state (bool full) node.add_child_nocopy (* _configured_in.state (X_("ConfiguredInput"))); node.add_child_nocopy (* _configured_out.state (X_("ConfiguredOutput"))); + _plugins[0]->set_insert_id(this->id()); node.add_child_nocopy (_plugins[0]->get_state()); for (Controls::iterator c = controls().begin(); c != controls().end(); ++c) { @@ -974,8 +1072,20 @@ PluginInsert::set_control_ids (const XMLNode& node, int version) if ((*iter)->name() == Controllable::xml_node_name) { const XMLProperty* prop; - if ((prop = (*iter)->property (X_("parameter"))) != 0) { - uint32_t p = atoi (prop->value()); + uint32_t p = (uint32_t)-1; +#ifdef LV2_SUPPORT + if ((prop = (*iter)->property (X_("symbol"))) != 0) { + boost::shared_ptr lv2plugin = boost::dynamic_pointer_cast (_plugins[0]); + if (lv2plugin) { + p = lv2plugin->port_index(prop->value().c_str()); + } + } +#endif + if (p == (uint32_t)-1 && (prop = (*iter)->property (X_("parameter"))) != 0) { + p = atoi (prop->value()); + } + + if (p != (uint32_t)-1) { /* this may create the new controllable */ @@ -1019,6 +1129,8 @@ PluginInsert::set_state(const XMLNode& node, int version) type = ARDOUR::LXVST; } else if (prop->value() == X_("audiounit")) { type = ARDOUR::AudioUnit; + } else if (prop->value() == X_("luaproc")) { + type = ARDOUR::Lua; } else { error << string_compose (_("unknown plugin type %1 in plugin insert state"), prop->value()) @@ -1080,6 +1192,15 @@ PluginInsert::set_state(const XMLNode& node, int version) return -1; } + if (type == ARDOUR::Lua) { + XMLNode *ls = node.child (plugin->state_node_name().c_str()); + // we need to load the script to set the name and parameters. + boost::shared_ptr lp = boost::dynamic_pointer_cast(plugin); + if (ls && lp) { + lp->set_script_from_state (*ls); + } + } + // The name of the PluginInsert comes from the plugin, nothing else _name = plugin->get_info()->name; @@ -1113,6 +1234,13 @@ PluginInsert::set_state(const XMLNode& node, int version) Processor::set_state (node, version); + PBD::ID new_id = this->id(); + PBD::ID old_id = this->id(); + + if ((prop = node.property ("id")) != 0) { + old_id = prop->value (); + } + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { /* find the node with the type-specific node name ("lv2", "ladspa", etc) @@ -1122,7 +1250,27 @@ PluginInsert::set_state(const XMLNode& node, int version) if ((*niter)->name() == plugin->state_node_name()) { for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + /* Plugin state can include external files which are named after the ID. + * + * If regenerate_xml_or_string_ids() is set, the ID will already have + * been changed, so we need to use the old ID from the XML to load the + * state and then update the ID. + * + * When copying a plugin-state, route_ui takes care of of updating the ID, + * but we need to call set_insert_id() to clear the cached plugin-state + * and force a change. + */ + if (!regenerate_xml_or_string_ids ()) { + (*i)->set_insert_id (new_id); + } else { + (*i)->set_insert_id (old_id); + } + (*i)->set_state (**niter, version); + + if (regenerate_xml_or_string_ids ()) { + (*i)->set_insert_id (new_id); + } } break; @@ -1166,6 +1314,13 @@ PluginInsert::update_id (PBD::ID id) } } +void +PluginInsert::set_state_dir (const std::string& d) +{ + // state() only saves the state of the first plugin + _plugins[0]->set_state_dir (d); +} + void PluginInsert::set_parameter_state_2X (const XMLNode& node, int version) { @@ -1301,7 +1456,21 @@ PluginInsert::PluginControl::PluginControl (PluginInsert* p, /** @param val `user' value */ void -PluginInsert::PluginControl::set_value (double user_val) +PluginInsert::PluginControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override) +{ + if (writable()) { + _set_value (user_val, group_override); + } +} +void +PluginInsert::PluginControl::set_value_unchecked (double user_val) +{ + /* used only by automation playback */ + _set_value (user_val, Controllable::NoGroup); +} + +void +PluginInsert::PluginControl::_set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override) { /* FIXME: probably should be taking out some lock here.. */ @@ -1314,7 +1483,13 @@ PluginInsert::PluginControl::set_value (double user_val) iasp->set_parameter (_list->parameter().id(), user_val); } - AutomationControl::set_value (user_val); + AutomationControl::set_value (user_val, group_override); +} + +void +PluginInsert::PluginControl::catch_up_with_external_value (double user_val) +{ + AutomationControl::set_value (user_val, Controllable::NoGroup); } XMLNode& @@ -1325,6 +1500,12 @@ PluginInsert::PluginControl::get_state () XMLNode& node (AutomationControl::get_state()); ss << parameter().id(); node.add_property (X_("parameter"), ss.str()); +#ifdef LV2_SUPPORT + boost::shared_ptr lv2plugin = boost::dynamic_pointer_cast (_plugin->_plugins[0]); + if (lv2plugin) { + node.add_property (X_("symbol"), lv2plugin->port_symbol (parameter().id())); + } +#endif return node; } @@ -1333,8 +1514,13 @@ PluginInsert::PluginControl::get_state () double PluginInsert::PluginControl::get_value () const { - /* FIXME: probably should be taking out some lock here.. */ - return _plugin->get_parameter (_list->parameter()); + boost::shared_ptr plugin = _plugin->plugin (0); + + if (!plugin) { + return 0.0; + } + + return plugin->get_parameter (_list->parameter().id()); } PluginInsert::PluginPropertyControl::PluginPropertyControl (PluginInsert* p, @@ -1355,7 +1541,15 @@ PluginInsert::PluginPropertyControl::PluginPropertyControl (PluginInsert* } void -PluginInsert::PluginPropertyControl::set_value (double user_val) +PluginInsert::PluginPropertyControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition /* group_override*/) +{ + if (writable()) { + set_value_unchecked (user_val); + } +} + +void +PluginInsert::PluginPropertyControl::set_value_unchecked (double user_val) { /* Old numeric set_value(), coerce to appropriate datatype if possible. This is lossy, but better than nothing until Ardour's automation system @@ -1371,7 +1565,7 @@ PluginInsert::PluginPropertyControl::set_value (double user_val) } _value = value; - AutomationControl::set_value(user_val); + AutomationControl::set_value (user_val, Controllable::NoGroup); } XMLNode& @@ -1430,7 +1624,7 @@ PluginInsert::add_plugin (boost::shared_ptr plugin) /* first (and probably only) plugin instance - connect to relevant signals */ - plugin->ParameterChanged.connect_same_thread (*this, boost::bind (&PluginInsert::parameter_changed, this, _1, _2)); + plugin->ParameterChangedExternally.connect_same_thread (*this, boost::bind (&PluginInsert::parameter_changed_externally, this, _1, _2)); plugin->StartTouch.connect_same_thread (*this, boost::bind (&PluginInsert::start_touch, this, _1)); plugin->EndTouch.connect_same_thread (*this, boost::bind (&PluginInsert::end_touch, this, _1)); }