2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
26 #include "pbd/failed_constructor.h"
27 #include "pbd/xml++.h"
28 #include "pbd/convert.h"
30 #include "ardour/audio_buffer.h"
31 #include "ardour/automation_list.h"
32 #include "ardour/buffer_set.h"
33 #include "ardour/debug.h"
34 #include "ardour/event_type_map.h"
35 #include "ardour/ladspa_plugin.h"
36 #include "ardour/luaproc.h"
37 #include "ardour/plugin.h"
38 #include "ardour/plugin_insert.h"
39 #include "ardour/port.h"
42 #include "ardour/lv2_plugin.h"
45 #ifdef WINDOWS_VST_SUPPORT
46 #include "ardour/windows_vst_plugin.h"
50 #include "ardour/lxvst_plugin.h"
53 #ifdef AUDIOUNIT_SUPPORT
54 #include "ardour/audio_unit.h"
57 #include "ardour/session.h"
58 #include "ardour/types.h"
63 using namespace ARDOUR;
66 const string PluginInsert::port_automation_node_name = "PortAutomation";
68 PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug)
69 : Processor (s, (plug ? plug->name() : string ("toBeRenamed")))
70 , _sc_playback_latency (0)
71 , _sc_capture_latency (0)
72 , _signal_analysis_collected_nframes(0)
73 , _signal_analysis_collect_nframes_max(0)
78 , _maps_from_state (false)
80 /* the first is the master */
84 create_automatable_parameters ();
85 const ChanCount& sc (sidechain_input_pins ());
86 if (sc.n_audio () > 0) {
87 add_sidechain (sc.n_audio ());
92 PluginInsert::~PluginInsert ()
97 PluginInsert::set_strict_io (bool b)
99 bool changed = _strict_io != b;
102 PluginConfigChanged (); /* EMIT SIGNAL */
107 PluginInsert::set_count (uint32_t num)
109 bool require_state = !_plugins.empty();
111 if (require_state && num > 1 && plugin (0)->get_info ()->type == ARDOUR::AudioUnit) {
112 // we don't allow to replicate AUs
116 /* this is a bad idea.... we shouldn't do this while active.
117 * only a route holding their redirect_lock should be calling this
122 } else if (num > _plugins.size()) {
123 uint32_t diff = num - _plugins.size();
125 for (uint32_t n = 0; n < diff; ++n) {
126 boost::shared_ptr<Plugin> p = plugin_factory (_plugins[0]);
130 XMLNode& state = _plugins[0]->get_state ();
131 p->set_state (state, Stateful::loading_state_version);
138 PluginConfigChanged (); /* EMIT SIGNAL */
140 } else if (num < _plugins.size()) {
141 uint32_t diff = _plugins.size() - num;
142 for (uint32_t n= 0; n < diff; ++n) {
145 PluginConfigChanged (); /* EMIT SIGNAL */
153 PluginInsert::set_sinks (const ChanCount& c)
156 /* no signal, change will only be visible after re-config */
160 PluginInsert::set_outputs (const ChanCount& c)
162 bool changed = (_custom_out != c) && _custom_cfg;
165 PluginConfigChanged (); /* EMIT SIGNAL */
170 PluginInsert::set_custom_cfg (bool b)
172 bool changed = _custom_cfg != b;
175 PluginConfigChanged (); /* EMIT SIGNAL */
180 PluginInsert::set_preset_out (const ChanCount& c)
182 bool changed = _preset_out != c;
184 if (changed && !_custom_cfg) {
185 PluginConfigChanged (); /* EMIT SIGNAL */
191 PluginInsert::add_sidechain (uint32_t n_audio)
193 // caller must hold process lock
197 std::ostringstream n;
199 n << "Sidechain " << Session::next_name_id ();
201 n << "TO BE RESET FROM XML";
203 SideChain *sc = new SideChain (_session, n.str ());
204 _sidechain = boost::shared_ptr<SideChain> (sc);
205 _sidechain->activate ();
206 for (uint32_t n = 0; n < n_audio; ++n) {
207 _sidechain->input()->add_port ("", owner()); // add a port, don't connect.
209 PluginConfigChanged (); /* EMIT SIGNAL */
214 PluginInsert::del_sidechain ()
220 _sc_playback_latency = 0;
221 _sc_capture_latency = 0;
222 PluginConfigChanged (); /* EMIT SIGNAL */
227 PluginInsert::set_sidechain_latency (uint32_t capture, uint32_t playback)
230 (_sc_playback_latency != playback || _sc_capture_latency != capture)) {
231 _sc_capture_latency = capture;
232 _sc_playback_latency = playback;
233 LatencyRange pl; pl.min = pl.max = playback;
234 LatencyRange cl; cl.min = cl.max = capture;
235 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: capture %2 playback; %3\n", _sidechain->name (), capture, playback));
236 PortSet& ps (_sidechain->input ()->ports ());
237 for (PortSet::iterator p = ps.begin(); p != ps.end(); ++p) {
238 p->set_private_latency_range (pl, true);
239 p->set_private_latency_range (cl, false);
245 PluginInsert::control_list_automation_state_changed (Evoral::Parameter which, AutoState s)
247 if (which.type() != PluginAutomation)
250 boost::shared_ptr<AutomationControl> c
251 = boost::dynamic_pointer_cast<AutomationControl>(control (which));
254 _plugins[0]->set_parameter (which.id(), c->list()->eval (_session.transport_frame()));
259 PluginInsert::output_streams() const
261 assert (_configured);
262 return _configured_out;
266 PluginInsert::input_streams() const
268 assert (_configured);
269 return _configured_in;
273 PluginInsert::internal_streams() const
275 assert (_configured);
276 return _configured_internal;
280 PluginInsert::internal_output_streams() const
282 assert (!_plugins.empty());
284 PluginInfoPtr info = _plugins.front()->get_info();
286 if (info->reconfigurable_io()) {
287 ChanCount out = _plugins.front()->output_streams ();
288 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, reconfigur(able) output streams = %1\n", out));
291 ChanCount out = info->n_outputs;
292 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, static output streams = %1 for %2 plugins\n", out, _plugins.size()));
293 out.set_audio (out.n_audio() * _plugins.size());
294 out.set_midi (out.n_midi() * _plugins.size());
300 PluginInsert::internal_input_streams() const
302 assert (!_plugins.empty());
306 PluginInfoPtr info = _plugins.front()->get_info();
308 if (info->reconfigurable_io()) {
309 in = _plugins.front()->input_streams();
314 DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, input streams = %1, match using %2\n", in, _match.method));
316 if (_match.method == Split) {
318 /* we are splitting 1 processor input to multiple plugin inputs,
319 so we have a maximum of 1 stream of each type.
321 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
322 if (in.get (*t) > 1) {
328 } else if (_match.method == Hide) {
330 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
331 in.set (*t, in.get (*t) - _match.hide.get (*t));
337 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
338 in.set (*t, in.get (*t) * _plugins.size ());
346 PluginInsert::natural_output_streams() const
349 if (is_channelstrip ()) {
350 return ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2));
353 return _plugins[0]->get_info()->n_outputs;
357 PluginInsert::natural_input_streams() const
360 if (is_channelstrip ()) {
361 return ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2));
364 return _plugins[0]->get_info()->n_inputs;
368 PluginInsert::sidechain_input_pins() const
370 return _cached_sidechain_pins;
374 PluginInsert::has_no_inputs() const
376 return _plugins[0]->get_info()->n_inputs == ChanCount::ZERO;
380 PluginInsert::has_no_audio_inputs() const
382 return _plugins[0]->get_info()->n_inputs.n_audio() == 0;
386 PluginInsert::plugin_latency () const {
387 return _plugins.front()->signal_latency ();
391 PluginInsert::needs_midi_input() const
393 PluginInfoPtr pip = _plugins[0]->get_info();
394 if (pip->needs_midi_input ()) {
397 return pip->n_inputs.n_midi() != 0 && pip->n_outputs.n_audio() != 0;
401 PluginInsert::has_output_presets (ChanCount in, ChanCount out)
403 if (!_configured && _plugins[0]->get_info ()->reconfigurable_io ()) {
404 // collect possible configurations, prefer given in/out
405 _plugins[0]->can_support_io_configuration (in, out);
408 PluginOutputConfiguration ppc (_plugins[0]->possible_output ());
410 if (ppc.size () == 0) {
413 if (!strict_io () && ppc.size () == 1) {
417 if (strict_io () && ppc.size () == 1) {
418 // "stereo" is currently preferred default for instruments
419 if (ppc.find (2) != ppc.end ()) {
423 if (!needs_midi_input ()) {
430 PluginInsert::create_automatable_parameters ()
432 assert (!_plugins.empty());
434 boost::shared_ptr<Plugin> plugin = _plugins.front();
435 set<Evoral::Parameter> a = _plugins.front()->automatable ();
437 for (uint32_t i = 0; i < plugin->parameter_count(); ++i) {
438 if (!plugin->parameter_is_control (i) || !plugin->parameter_is_input (i)) {
441 Evoral::Parameter param (PluginAutomation, 0, i);
443 ParameterDescriptor desc;
444 plugin->get_parameter_descriptor(i, desc);
446 const bool automatable = a.find(param) != a.end();
449 can_automate (param);
451 boost::shared_ptr<AutomationList> list(new AutomationList(param, desc));
452 boost::shared_ptr<AutomationControl> c (new PluginControl(this, param, desc, list));
454 c->set_flags (Controllable::Flag ((int)c->flags() | Controllable::NotAutomatable));
457 plugin->set_automation_control (i, c);
460 const Plugin::PropertyDescriptors& pdl (plugin->get_supported_properties ());
461 for (Plugin::PropertyDescriptors::const_iterator p = pdl.begin(); p != pdl.end(); ++p) {
462 Evoral::Parameter param (PluginPropertyAutomation, 0, p->first);
463 const ParameterDescriptor& desc = plugin->get_property_descriptor(param.id());
464 if (desc.datatype != Variant::NOTHING) {
465 boost::shared_ptr<AutomationList> list;
466 if (Variant::type_is_numeric(desc.datatype)) {
467 list = boost::shared_ptr<AutomationList>(new AutomationList(param, desc));
469 add_control (boost::shared_ptr<AutomationControl> (new PluginPropertyControl(this, param, desc, list)));
473 /** Called when something outside of this host has modified a plugin
474 * parameter. Responsible for propagating the change to two places:
476 * 1) anything listening to the Control itself
477 * 2) any replicated plugins that make up this PluginInsert.
479 * The PluginInsert is connected to the ParameterChangedExternally signal for
480 * the first (primary) plugin, and here broadcasts that change to any others.
482 * XXX We should probably drop this whole replication idea (Paul, October 2015)
483 * since it isn't used by sensible plugin APIs (AU, LV2).
486 PluginInsert::parameter_changed_externally (uint32_t which, float val)
488 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, which));
490 /* First propagation: alter the underlying value of the control,
491 * without telling the plugin(s) that own/use it to set it.
498 boost::shared_ptr<PluginControl> pc = boost::dynamic_pointer_cast<PluginControl> (ac);
501 pc->catch_up_with_external_value (val);
504 /* Second propagation: tell all plugins except the first to
505 update the value of this parameter. For sane plugin APIs,
506 there are no other plugins, so this is a no-op in those
510 Plugins::iterator i = _plugins.begin();
512 /* don't set the first plugin, just all the slaves */
514 if (i != _plugins.end()) {
516 for (; i != _plugins.end(); ++i) {
517 (*i)->set_parameter (which, val);
523 PluginInsert::set_block_size (pframes_t nframes)
526 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
527 if ((*i)->set_block_size (nframes) != 0) {
535 PluginInsert::activate ()
537 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
541 Processor::activate ();
545 PluginInsert::deactivate ()
547 Processor::deactivate ();
549 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
555 PluginInsert::flush ()
557 for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
563 PluginInsert::inplace_silence_unconnected (BufferSet& bufs, const PinMappings& out_map, framecnt_t nframes, framecnt_t offset) const
565 // TODO optimize: store "unconnected" in a fixed set.
566 // it only changes on reconfiguration.
567 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
568 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
570 if (*t == DataType::MIDI && out == 0 && has_midi_bypass ()) {
571 mapped = true; // in-place Midi bypass
573 for (uint32_t pc = 0; pc < get_count() && !mapped; ++pc) {
574 PinMappings::const_iterator i = out_map.find (pc);
575 if (i == out_map.end ()) {
578 const ChanMapping& outmap (i->second);
579 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
581 uint32_t idx = outmap.get (*t, o, &valid);
582 if (valid && idx == out) {
589 bufs.get (*t, out).silence (nframes, offset);
596 PluginInsert::connect_and_run (BufferSet& bufs, framepos_t start, framepos_t end, double speed, pframes_t nframes, framecnt_t offset, bool with_auto)
598 // TODO: atomically copy maps & _no_inplace
599 PinMappings in_map (_in_map);
600 PinMappings out_map (_out_map);
601 ChanMapping thru_map (_thru_map);
602 if (_mapping_changed) { // ToDo use a counters, increment until match.
603 _no_inplace = check_inplace ();
604 _mapping_changed = false;
607 if (_latency_changed) {
608 /* delaylines are configured with the max possible latency (as reported by the plugin)
609 * so this won't allocate memory (unless the plugin lied about its max latency)
610 * It may still 'click' though, since the fixed delaylines are not de-clicked.
611 * Then again plugin-latency changes are not click-free to begin with.
613 * This is also worst case, there is currently no concept of per-stream latency.
615 * e.g. Two identical latent plugins:
616 * 1st plugin: process left (latent), bypass right.
617 * 2nd plugin: bypass left, process right (latent).
618 * -> currently this yields 2 times latency of the plugin,
620 _latency_changed = false;
621 _delaybuffers.set (ChanCount::max(bufs.count(), _configured_out), plugin_latency ());
624 if (_match.method == Split && !_no_inplace) {
625 // TODO: also use this optimization if one source-buffer
626 // feeds _all_ *connected* inputs.
627 // currently this is *first* buffer to all only --
628 // see PluginInsert::check_inplace
629 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
630 if (_configured_internal.get (*t) == 0) {
634 uint32_t first_idx = in_map[0].get (*t, 0, &valid);
635 assert (valid && first_idx == 0); // check_inplace ensures this
636 /* copy the first stream's buffer contents to the others */
637 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
638 uint32_t idx = in_map[0].get (*t, i, &valid);
641 bufs.get (*t, i).read_from (bufs.get (*t, first_idx), nframes, offset, offset);
645 /* the copy operation produces a linear monotonic input map */
646 in_map[0] = ChanMapping (natural_input_streams ());
649 bufs.set_count(ChanCount::max(bufs.count(), _configured_internal));
650 bufs.set_count(ChanCount::max(bufs.count(), _configured_out));
656 for (Controls::iterator li = controls().begin(); li != controls().end(); ++li, ++n) {
658 boost::shared_ptr<AutomationControl> c
659 = boost::dynamic_pointer_cast<AutomationControl>(li->second);
661 if (c->list() && c->automation_playback()) {
664 const float val = c->list()->rt_safe_eval (start, valid);
667 /* This is the ONLY place where we are
669 * AutomationControl::set_value_unchecked(). We
670 * know that the control is in
671 * automation playback mode, so no
672 * check on writable() is required
673 * (which must be done in AutomationControl::set_value()
676 c->set_value_unchecked(val);
683 /* Calculate if, and how many frames we need to collect for analysis */
684 framecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max -
685 _signal_analysis_collected_nframes);
686 if (nframes < collect_signal_nframes) { // we might not get all frames now
687 collect_signal_nframes = nframes;
690 if (collect_signal_nframes > 0) {
692 //std::cerr << "collect input, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
693 //std::cerr << " streams " << internal_input_streams().n_audio() << std::endl;
694 //std::cerr << "filling buffer with " << collect_signal_nframes << " frames at " << _signal_analysis_collected_nframes << std::endl;
696 _signal_analysis_inputs.set_count(input_streams());
698 for (uint32_t i = 0; i < input_streams().n_audio(); ++i) {
699 _signal_analysis_inputs.get_audio(i).read_from (
701 collect_signal_nframes,
702 _signal_analysis_collected_nframes); // offset is for target buffer
707 if (is_channelstrip ()) {
708 if (_configured_in.n_audio() > 0) {
709 ChanMapping mb_in_map (ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2)));
710 ChanMapping mb_out_map (ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2)));
712 _plugins.front()->connect_and_run (bufs, start, end, speed, mb_in_map, mb_out_map, nframes, offset);
714 for (uint32_t out = _configured_in.n_audio (); out < bufs.count().get (DataType::AUDIO); ++out) {
715 bufs.get (DataType::AUDIO, out).silence (nframes, offset);
721 // TODO optimize -- build maps once.
723 BufferSet& inplace_bufs = _session.get_noinplace_buffers();
724 ARDOUR::ChanMapping used_outputs;
726 assert (inplace_bufs.count () >= natural_input_streams () + _configured_out);
728 /* build used-output map */
729 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
730 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
731 for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) {
733 uint32_t out_idx = out_map[pc].get (*t, out, &valid);
735 used_outputs.set (*t, out_idx, 1); // mark as used
740 /* copy thru data to outputs before processing in-place */
741 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
742 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
744 uint32_t in_idx = thru_map.get (*t, out, &valid);
745 uint32_t m = out + natural_input_streams ().get (*t);
747 _delaybuffers.delay (*t, out, inplace_bufs.get (*t, m), bufs.get (*t, in_idx), nframes, offset, offset);
748 used_outputs.set (*t, out, 1); // mark as used
750 used_outputs.get (*t, out, &valid);
752 /* the plugin is expected to write here, but may not :(
753 * (e.g. drumgizmo w/o kit loaded)
755 inplace_bufs.get (*t, m).silence (nframes);
762 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
764 ARDOUR::ChanMapping i_in_map (natural_input_streams());
765 ARDOUR::ChanMapping i_out_map (out_map[pc]);
766 ARDOUR::ChanCount mapped;
768 /* map inputs sequentially */
769 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
770 for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) {
772 uint32_t in_idx = in_map[pc].get (*t, in, &valid);
773 uint32_t m = mapped.get (*t);
775 inplace_bufs.get (*t, m).read_from (bufs.get (*t, in_idx), nframes, offset, offset);
777 inplace_bufs.get (*t, m).silence (nframes, offset);
779 mapped.set (*t, m + 1);
783 /* outputs are mapped to inplace_bufs after the inputs */
784 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
785 i_out_map.offset_to (*t, natural_input_streams ().get (*t));
788 if ((*i)->connect_and_run (inplace_bufs, start, end, speed, i_in_map, i_out_map, nframes, offset)) {
793 /* all instances have completed, now copy data that was written
794 * and zero unconnected buffers */
795 ARDOUR::ChanMapping nonzero_out (used_outputs);
796 if (has_midi_bypass ()) {
797 nonzero_out.set (DataType::MIDI, 0, 1); // Midi bypass.
799 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
800 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
802 used_outputs.get (*t, out, &valid);
804 nonzero_out.get (*t, out, &valid);
806 bufs.get (*t, out).silence (nframes, offset);
809 uint32_t m = out + natural_input_streams ().get (*t);
810 bufs.get (*t, out).read_from (inplace_bufs.get (*t, m), nframes, offset, offset);
815 /* in-place processing */
817 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
818 if ((*i)->connect_and_run(bufs, start, end, speed, in_map[pc], out_map[pc], nframes, offset)) {
822 // now silence unconnected outputs
823 inplace_silence_unconnected (bufs, _out_map, nframes, offset);
826 if (collect_signal_nframes > 0) {
828 //std::cerr << " output, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
829 //std::cerr << " streams " << internal_output_streams().n_audio() << std::endl;
831 _signal_analysis_outputs.set_count(output_streams());
833 for (uint32_t i = 0; i < output_streams().n_audio(); ++i) {
834 _signal_analysis_outputs.get_audio(i).read_from(
836 collect_signal_nframes,
837 _signal_analysis_collected_nframes); // offset is for target buffer
840 _signal_analysis_collected_nframes += collect_signal_nframes;
841 assert(_signal_analysis_collected_nframes <= _signal_analysis_collect_nframes_max);
843 if (_signal_analysis_collected_nframes == _signal_analysis_collect_nframes_max) {
844 _signal_analysis_collect_nframes_max = 0;
845 _signal_analysis_collected_nframes = 0;
847 AnalysisDataGathered(&_signal_analysis_inputs,
848 &_signal_analysis_outputs);
854 PluginInsert::bypass (BufferSet& bufs, pframes_t nframes)
856 /* bypass the plugin(s) not the whole processor.
857 * -> use mappings just like connect_and_run
860 // TODO: atomically copy maps & _no_inplace
861 const ChanMapping in_map (no_sc_input_map ());
862 const ChanMapping out_map (output_map ());
863 if (_mapping_changed) {
864 _no_inplace = check_inplace ();
865 _mapping_changed = false;
868 bufs.set_count(ChanCount::max(bufs.count(), _configured_internal));
869 bufs.set_count(ChanCount::max(bufs.count(), _configured_out));
872 ChanMapping thru_map (_thru_map);
874 BufferSet& inplace_bufs = _session.get_noinplace_buffers();
876 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
877 for (uint32_t in = 0; in < _configured_internal.get (*t); ++in) {
878 inplace_bufs.get (*t, in).read_from (bufs.get (*t, in), nframes, 0, 0);
881 ARDOUR::ChanMapping used_outputs;
883 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
884 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
886 uint32_t in_idx = thru_map.get (*t, out, &valid);
888 bufs.get (*t, out).read_from (inplace_bufs.get (*t, in_idx), nframes, 0, 0);
889 used_outputs.set (*t, out, 1); // mark as used
893 // plugin no-op: assume every plugin has an internal identity map
894 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
895 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
897 uint32_t src_idx = out_map.get_src (*t, out, &valid);
901 uint32_t in_idx = in_map.get (*t, src_idx, &valid);
905 bufs.get (*t, out).read_from (inplace_bufs.get (*t, in_idx), nframes, 0, 0);
906 used_outputs.set (*t, out, 1); // mark as used
909 // now silence all unused outputs
910 if (has_midi_bypass ()) {
911 used_outputs.set (DataType::MIDI, 0, 1); // Midi bypass.
913 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
914 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
916 used_outputs.get (*t, out, &valid);
918 bufs.get (*t, out).silence (nframes, 0);
923 if (_match.method == Split) {
924 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
925 if (_configured_internal.get (*t) == 0) {
928 // copy/feeds _all_ *connected* inputs, copy the first buffer
930 uint32_t first_idx = in_map.get (*t, 0, &valid);
931 assert (valid && first_idx == 0); // check_inplace ensures this
932 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
933 uint32_t idx = in_map.get (*t, i, &valid);
936 bufs.get (*t, i).read_from (bufs.get (*t, first_idx), nframes, 0, 0);
942 // apply output map and/or monotonic but not identity i/o mappings
943 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
944 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
946 uint32_t src_idx = out_map.get_src (*t, out, &valid);
948 bufs.get (*t, out).silence (nframes, 0);
951 uint32_t in_idx = in_map.get (*t, src_idx, &valid);
953 bufs.get (*t, out).silence (nframes, 0);
956 if (in_idx != src_idx) {
957 bufs.get (*t, out).read_from (bufs.get (*t, in_idx), nframes, 0, 0);
965 PluginInsert::silence (framecnt_t nframes, framepos_t start_frame)
971 _delaybuffers.flush ();
973 ChanMapping in_map (natural_input_streams ());
974 ChanMapping out_map (natural_output_streams ());
975 ChanCount maxbuf = ChanCount::max (natural_input_streams (), natural_output_streams());
977 if (is_channelstrip ()) {
978 if (_configured_in.n_audio() > 0) {
979 _plugins.front()->connect_and_run (_session.get_scratch_buffers (maxbuf, true), start_frame, start_frame + nframes, 1.0, in_map, out_map, nframes, 0);
983 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
984 (*i)->connect_and_run (_session.get_scratch_buffers (maxbuf, true), start_frame, start_frame + nframes, 1.0, in_map, out_map, nframes, 0);
989 PluginInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, double speed, pframes_t nframes, bool)
992 // collect sidechain input for complete cycle (!)
993 // TODO we need delaylines here for latency compensation
994 _sidechain->run (bufs, start_frame, end_frame, speed, nframes, true);
997 if (_pending_active) {
998 /* run as normal if we are active or moving from inactive to active */
1000 if (_session.transport_rolling() || _session.bounce_processing()) {
1001 automation_run (bufs, start_frame, end_frame, speed, nframes);
1003 connect_and_run (bufs, start_frame, end_frame, speed, nframes, 0, false);
1007 bypass (bufs, nframes);
1008 _delaybuffers.flush ();
1011 _active = _pending_active;
1013 /* we have no idea whether the plugin generated silence or not, so mark
1014 * all buffers appropriately.
1019 PluginInsert::automation_run (BufferSet& bufs, framepos_t start, framepos_t end, double speed, pframes_t nframes)
1021 Evoral::ControlEvent next_event (0, 0.0f);
1022 framecnt_t offset = 0;
1024 Glib::Threads::Mutex::Lock lm (control_lock(), Glib::Threads::TRY_LOCK);
1027 connect_and_run (bufs, start, end, speed, nframes, offset, false);
1031 if (!find_next_event (start, end, next_event) || _plugins.front()->requires_fixed_sized_buffers()) {
1033 /* no events have a time within the relevant range */
1035 connect_and_run (bufs, start, end, speed, nframes, offset, true);
1041 framecnt_t cnt = min (((framecnt_t) ceil (next_event.when) - start), (framecnt_t) nframes);
1043 connect_and_run (bufs, start, start + cnt, speed, cnt, offset, true); // XXX (start + cnt) * speed
1049 if (!find_next_event (start, end, next_event)) {
1054 /* cleanup anything that is left to do */
1057 connect_and_run (bufs, start, start + nframes, speed, nframes, offset, true);
1062 PluginInsert::default_parameter_value (const Evoral::Parameter& param)
1064 if (param.type() != PluginAutomation)
1067 if (_plugins.empty()) {
1068 fatal << _("programming error: ") << X_("PluginInsert::default_parameter_value() called with no plugin")
1070 abort(); /*NOTREACHED*/
1073 return _plugins[0]->default_value (param.id());
1078 PluginInsert::can_reset_all_parameters ()
1081 uint32_t params = 0;
1082 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
1084 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
1086 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
1090 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
1096 if (ac->automation_state() & Play) {
1101 return all && (params > 0);
1105 PluginInsert::reset_parameters_to_default ()
1109 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
1111 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
1113 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
1117 const float dflt = _plugins[0]->default_value (cid);
1118 const float curr = _plugins[0]->get_parameter (cid);
1124 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
1129 if (ac->automation_state() & Play) {
1134 ac->set_value (dflt, Controllable::NoGroup);
1139 boost::shared_ptr<Plugin>
1140 PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
1142 boost::shared_ptr<LadspaPlugin> lp;
1143 boost::shared_ptr<LuaProc> lua;
1145 boost::shared_ptr<LV2Plugin> lv2p;
1147 #ifdef WINDOWS_VST_SUPPORT
1148 boost::shared_ptr<WindowsVSTPlugin> vp;
1150 #ifdef LXVST_SUPPORT
1151 boost::shared_ptr<LXVSTPlugin> lxvp;
1153 #ifdef AUDIOUNIT_SUPPORT
1154 boost::shared_ptr<AUPlugin> ap;
1157 if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
1158 return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
1159 } else if ((lua = boost::dynamic_pointer_cast<LuaProc> (other)) != 0) {
1160 return boost::shared_ptr<Plugin> (new LuaProc (*lua));
1162 } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
1163 return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
1165 #ifdef WINDOWS_VST_SUPPORT
1166 } else if ((vp = boost::dynamic_pointer_cast<WindowsVSTPlugin> (other)) != 0) {
1167 return boost::shared_ptr<Plugin> (new WindowsVSTPlugin (*vp));
1169 #ifdef LXVST_SUPPORT
1170 } else if ((lxvp = boost::dynamic_pointer_cast<LXVSTPlugin> (other)) != 0) {
1171 return boost::shared_ptr<Plugin> (new LXVSTPlugin (*lxvp));
1173 #ifdef AUDIOUNIT_SUPPORT
1174 } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
1175 return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
1179 fatal << string_compose (_("programming error: %1"),
1180 X_("unknown plugin type in PluginInsert::plugin_factory"))
1182 abort(); /*NOTREACHED*/
1183 return boost::shared_ptr<Plugin> ((Plugin*) 0);
1187 PluginInsert::set_input_map (uint32_t num, ChanMapping m) {
1188 if (num < _in_map.size()) {
1189 bool changed = _in_map[num] != m;
1191 changed |= sanitize_maps ();
1193 PluginMapChanged (); /* EMIT SIGNAL */
1194 _mapping_changed = true;
1195 _session.set_dirty();
1201 PluginInsert::set_output_map (uint32_t num, ChanMapping m) {
1202 if (num < _out_map.size()) {
1203 bool changed = _out_map[num] != m;
1205 changed |= sanitize_maps ();
1207 PluginMapChanged (); /* EMIT SIGNAL */
1208 _mapping_changed = true;
1209 _session.set_dirty();
1215 PluginInsert::set_thru_map (ChanMapping m) {
1216 bool changed = _thru_map != m;
1218 changed |= sanitize_maps ();
1220 PluginMapChanged (); /* EMIT SIGNAL */
1221 _mapping_changed = true;
1222 _session.set_dirty();
1227 PluginInsert::pre_seed (const ChanCount& in, const ChanCount& out,
1228 const ChanMapping& im, const ChanMapping& om, const ChanMapping& tm)
1230 if (_configured) { return false; }
1231 _configured_in = in;
1232 _configured_out = out;
1236 _maps_from_state = in.n_total () > 0 && out.n_total () > 0;
1241 PluginInsert::input_map () const
1245 for (PinMappings::const_iterator i = _in_map.begin (); i != _in_map.end (); ++i, ++pc) {
1246 ChanMapping m (i->second);
1247 const ChanMapping::Mappings& mp ((*i).second.mappings());
1248 for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
1249 for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
1250 rv.set (tm->first, i->first + pc * natural_input_streams().get(tm->first), i->second);
1259 PluginInsert::no_sc_input_map () const
1263 for (PinMappings::const_iterator i = _in_map.begin (); i != _in_map.end (); ++i, ++pc) {
1264 ChanMapping m (i->second);
1265 const ChanMapping::Mappings& mp ((*i).second.mappings());
1266 for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
1267 for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
1268 rv.set (tm->first, i->first + pc * (natural_input_streams().get(tm->first) - _cached_sidechain_pins.get(tm->first)), i->second);
1276 PluginInsert::output_map () const
1280 for (PinMappings::const_iterator i = _out_map.begin (); i != _out_map.end (); ++i, ++pc) {
1281 ChanMapping m (i->second);
1282 const ChanMapping::Mappings& mp ((*i).second.mappings());
1283 for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
1284 for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
1285 rv.set (tm->first, i->first + pc * natural_output_streams().get(tm->first), i->second);
1289 if (has_midi_bypass ()) {
1290 rv.set (DataType::MIDI, 0, 0);
1297 PluginInsert::has_midi_bypass () const
1299 if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
1300 && natural_output_streams ().n_midi () == 0) {
1307 PluginInsert::has_midi_thru () const
1309 if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
1310 && natural_input_streams ().n_midi () == 0 && natural_output_streams ().n_midi () == 0) {
1318 PluginInsert::is_channelstrip () const {
1319 return _plugins.front()->is_channelstrip();
1324 PluginInsert::check_inplace ()
1326 bool inplace_ok = !_plugins.front()->inplace_broken ();
1328 if (_thru_map.n_total () > 0) {
1329 // TODO once midi-bypass is part of the mapping, ignore it
1333 if (_match.method == Split && inplace_ok) {
1334 assert (get_count() == 1);
1335 assert (_in_map.size () == 1);
1336 if (!_out_map[0].is_monotonic ()) {
1339 if (_configured_internal != _configured_in) {
1340 /* no sidechain -- TODO we could allow this with
1341 * some more logic in PluginInsert::connect_and_run().
1343 * PluginInsert::reset_map() already maps it.
1348 for (DataType::iterator t = DataType::begin(); t != DataType::end() && inplace_ok; ++t) {
1349 if (_configured_internal.get (*t) == 0) {
1353 uint32_t first_idx = _in_map[0].get (*t, 0, &valid);
1354 if (!valid || first_idx != 0) {
1355 // so far only allow to copy the *first* stream's buffer to others
1358 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
1359 uint32_t idx = _in_map[0].get (*t, i, &valid);
1360 if (valid && idx != first_idx) {
1369 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: In Place Split Map\n", name()));
1374 for (uint32_t pc = 0; pc < get_count() && inplace_ok ; ++pc) {
1375 if (!_in_map[pc].is_monotonic ()) {
1378 if (!_out_map[pc].is_monotonic ()) {
1384 /* check if every output is fed by the corresponding input
1386 * this prevents in-port 1 -> sink-pin 2 || source-pin 1 -> out port 1, source-pin 2 -> out port 2
1387 * (with in-place, source-pin 1 -> out port 1 overwrites in-port 1)
1389 * but allows in-port 1 -> sink-pin 2 || source-pin 2 -> out port 1
1391 ChanMapping in_map (input_map ());
1392 const ChanMapping::Mappings out_m (output_map ().mappings ());
1393 for (ChanMapping::Mappings::const_iterator t = out_m.begin (); t != out_m.end () && inplace_ok; ++t) {
1394 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
1395 /* src-pin: c->first, out-port: c->second */
1397 uint32_t in_port = in_map.get (t->first, c->first, &valid);
1398 if (valid && in_port != c->second) {
1406 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: %2\n", name(), inplace_ok ? "In-Place" : "No Inplace Processing"));
1407 return !inplace_ok; // no-inplace
1411 PluginInsert::sanitize_maps ()
1413 bool changed = false;
1414 /* strip dead wood */
1415 PinMappings new_ins;
1416 PinMappings new_outs;
1417 ChanMapping new_thru;
1419 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1421 ChanMapping new_out;
1422 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1423 for (uint32_t i = 0; i < natural_input_streams().get (*t); ++i) {
1425 uint32_t idx = _in_map[pc].get (*t, i, &valid);
1426 if (valid && idx < _configured_internal.get (*t)) {
1427 new_in.set (*t, i, idx);
1430 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
1432 uint32_t idx = _out_map[pc].get (*t, o, &valid);
1433 if (valid && idx < _configured_out.get (*t)) {
1434 new_out.set (*t, o, idx);
1438 if (_in_map[pc] != new_in || _out_map[pc] != new_out) {
1441 new_ins[pc] = new_in;
1442 new_outs[pc] = new_out;
1445 /* prevent dup output assignments */
1446 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1447 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1448 bool mapped = false;
1449 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1451 uint32_t idx = new_outs[pc].get_src (*t, o, &valid);
1452 if (valid && mapped) {
1453 new_outs[pc].unset (*t, idx);
1461 /* remove excess thru */
1462 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1463 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1465 uint32_t idx = _thru_map.get (*t, o, &valid);
1466 if (valid && idx < _configured_internal.get (*t)) {
1467 new_thru.set (*t, o, idx);
1472 /* prevent out + thru, existing plugin outputs override thru */
1473 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1474 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1475 bool mapped = false;
1477 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1478 new_outs[pc].get_src (*t, o, &mapped);
1479 if (mapped) { break; }
1481 if (!mapped) { continue; }
1482 uint32_t idx = new_thru.get (*t, o, &valid);
1484 new_thru.unset (*t, idx);
1489 if (has_midi_bypass ()) {
1490 // TODO: include midi-bypass in the thru set,
1491 // remove dedicated handling.
1492 new_thru.unset (DataType::MIDI, 0);
1495 if (_in_map != new_ins || _out_map != new_outs || _thru_map != new_thru) {
1499 _out_map = new_outs;
1500 _thru_map = new_thru;
1506 PluginInsert::reset_map (bool emit)
1508 const PinMappings old_in (_in_map);
1509 const PinMappings old_out (_out_map);
1513 _thru_map = ChanMapping ();
1515 /* build input map */
1516 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1517 uint32_t sc = 0; // side-chain round-robin (all instances)
1519 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1520 const uint32_t nis = natural_input_streams ().get(*t);
1521 const uint32_t stride = nis - sidechain_input_pins().get (*t);
1523 /* SC inputs are last in the plugin-insert.. */
1524 const uint32_t sc_start = _configured_in.get (*t);
1525 const uint32_t sc_len = _configured_internal.get (*t) - sc_start;
1526 /* ...but may not be at the end of the plugin ports.
1527 * in case the side-chain is not the last port, shift connections back.
1528 * and connect to side-chain
1531 uint32_t ic = 0; // split inputs
1532 const uint32_t cend = _configured_in.get (*t);
1534 for (uint32_t in = 0; in < nis; ++in) {
1535 const Plugin::IOPortDescription& iod (_plugins[pc]->describe_io_port (*t, true, in));
1536 if (iod.is_sidechain) {
1537 /* connect sidechain sinks to sidechain inputs in round-robin fashion */
1538 if (sc_len > 0) {// side-chain may be hidden
1539 _in_map[pc].set (*t, in, sc_start + sc);
1540 sc = (sc + 1) % sc_len;
1544 if (_match.method == Split) {
1545 if (cend == 0) { continue; }
1546 if (_strict_io && ic + stride * pc >= cend) {
1549 /* connect *no* sidechain sinks in round-robin fashion */
1550 _in_map[pc].set (*t, in, ic + stride * pc);
1551 if (_strict_io && (ic + 1) == cend) {
1554 ic = (ic + 1) % cend;
1556 uint32_t s = in - shift;
1557 if (stride * pc + s < cend) {
1558 _in_map[pc].set (*t, in, s + stride * pc);
1566 /* build output map */
1568 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1569 _out_map[pc] = ChanMapping (ChanCount::min (natural_output_streams(), _configured_out));
1570 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1571 _out_map[pc].offset_to(*t, pc * natural_output_streams().get(*t));
1576 if (old_in == _in_map && old_out == _out_map) {
1580 PluginMapChanged (); /* EMIT SIGNAL */
1581 _mapping_changed = true;
1582 _session.set_dirty();
1588 PluginInsert::configure_io (ChanCount in, ChanCount out)
1590 Match old_match = _match;
1592 ChanCount old_internal;
1596 old_pins = natural_input_streams();
1597 old_in = _configured_in;
1598 old_out = _configured_out;
1599 old_internal = _configured_internal;
1601 _configured_in = in;
1602 _configured_internal = in;
1603 _configured_out = out;
1606 /* TODO hide midi-bypass, and custom outs. Best /fake/ "out" here.
1607 * (currently _sidechain->configure_io always succeeds
1608 * since Processor::configure_io() succeeds)
1610 if (!_sidechain->configure_io (in, out)) {
1611 DEBUG_TRACE (DEBUG::ChanMapping, "Sidechain configuration failed\n");
1614 _configured_internal += _sidechain->input()->n_ports();
1616 // include (static_cast<Route*>owner())->name() ??
1617 _sidechain->input ()-> set_pretty_name (string_compose (_("SC %1"), name ()));
1620 /* get plugin configuration */
1621 _match = private_can_support_io_configuration (in, out);
1623 if (DEBUG_ENABLED(DEBUG::ChanMapping)) {
1625 DEBUG_STR_APPEND(a, string_compose ("%1: ", name()));
1626 DEBUG_STR_APPEND(a, _match);
1627 DEBUG_TRACE (DEBUG::ChanMapping, DEBUG_STR(a).str());
1631 /* set the matching method and number of plugins that we will use to meet this configuration */
1632 if (set_count (_match.plugins) == false) {
1633 PluginIoReConfigure (); /* EMIT SIGNAL */
1634 _configured = false;
1638 /* configure plugins */
1639 switch (_match.method) {
1642 if (_plugins.front()->configure_io (natural_input_streams(), out) == false) {
1643 PluginIoReConfigure (); /* EMIT SIGNAL */
1644 _configured = false;
1650 ChanCount din (_configured_internal);
1651 ChanCount dout (din); // hint
1653 if (_custom_sinks.n_total () > 0) {
1654 din = _custom_sinks;
1657 } else if (_preset_out.n_audio () > 0) {
1658 dout.set (DataType::AUDIO, _preset_out.n_audio ());
1659 } else if (dout.n_midi () > 0 && dout.n_audio () == 0) {
1660 dout.set (DataType::AUDIO, 2);
1662 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1664 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: Delegate lookup : %2 %3\n", name(), din, dout));
1665 bool const r = _plugins.front()->can_support_io_configuration (din, dout, &useins);
1667 if (useins.n_audio() == 0) {
1670 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: Delegate configuration: %2 %3\n", name(), useins, dout));
1672 if (_plugins.front()->configure_io (useins, dout) == false) {
1673 PluginIoReConfigure (); /* EMIT SIGNAL */
1674 _configured = false;
1678 _custom_sinks = din;
1683 if (_plugins.front()->configure_io (in, out) == false) {
1684 PluginIoReConfigure (); /* EMIT SIGNAL */
1685 _configured = false;
1691 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: cfg:%2 state:%3 chn-in:%4 chn-out:%5 inpin:%6 match:%7 cust:%8 size-in:%9 size-out:%10\n",
1693 _configured ? "Y" : "N",
1694 _maps_from_state ? "Y" : "N",
1695 old_in == in ? "==" : "!=",
1696 old_out == out ? "==" : "!=",
1697 old_pins == natural_input_streams () ? "==" : "!=",
1698 old_match.method == _match.method ? "==" : "!=",
1699 old_match.custom_cfg == _match.custom_cfg ? "==" : "!=",
1700 _in_map.size() == get_count () ? "==" : "!=",
1701 _out_map.size() == get_count () ? "==" : "!="
1704 bool mapping_changed = false;
1705 if (old_in == in && old_out == out
1707 && old_pins == natural_input_streams ()
1708 && old_match.method == _match.method
1709 && old_match.custom_cfg == _match.custom_cfg
1710 && _in_map.size() == _out_map.size()
1711 && _in_map.size() == get_count ()
1713 assert (_maps_from_state == false);
1714 /* If the configuration has not changed, keep the mapping */
1715 mapping_changed = sanitize_maps ();
1716 } else if (_match.custom_cfg && _configured) {
1717 assert (_maps_from_state == false);
1718 /* don't touch the map in manual mode */
1719 mapping_changed = sanitize_maps ();
1722 if (is_channelstrip ()) {
1723 /* fake channel map - for wire display */
1726 _thru_map = ChanMapping ();
1727 _in_map[0] = ChanMapping (ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2)));
1728 _out_map[0] = ChanMapping (ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2)));
1729 /* set "thru" map for in-place forward of audio */
1730 for (uint32_t i = 2; i < _configured_in.n_audio(); ++i) {
1731 _thru_map.set (DataType::AUDIO, i, i);
1733 /* and midi (after implicit 1st channel bypass) */
1734 for (uint32_t i = 1; i < _configured_in.n_midi(); ++i) {
1735 _thru_map.set (DataType::MIDI, i, i);
1739 if (_maps_from_state && old_in == in && old_out == out) {
1740 mapping_changed = true;
1743 /* generate a new mapping */
1744 mapping_changed = reset_map (false);
1746 _maps_from_state = false;
1749 if (mapping_changed) {
1750 PluginMapChanged (); /* EMIT SIGNAL */
1753 if (DEBUG_ENABLED(DEBUG::ChanMapping)) {
1756 DEBUG_STR_APPEND(a, "\n--------<<--------\n");
1757 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1759 DEBUG_STR_APPEND(a, "----><----\n");
1761 DEBUG_STR_APPEND(a, string_compose ("Channel Map for %1 plugin %2\n", name(), pc));
1762 DEBUG_STR_APPEND(a, " * Inputs:\n");
1763 DEBUG_STR_APPEND(a, _in_map[pc]);
1764 DEBUG_STR_APPEND(a, " * Outputs:\n");
1765 DEBUG_STR_APPEND(a, _out_map[pc]);
1767 DEBUG_STR_APPEND(a, " * Thru:\n");
1768 DEBUG_STR_APPEND(a, _thru_map);
1769 DEBUG_STR_APPEND(a, "-------->>--------\n");
1770 DEBUG_TRACE (DEBUG::ChanMapping, DEBUG_STR(a).str());
1775 _no_inplace = check_inplace ();
1776 _mapping_changed = false;
1778 /* only the "noinplace_buffers" thread buffers need to be this large,
1779 * this can be optimized. other buffers are fine with
1780 * ChanCount::max (natural_input_streams (), natural_output_streams())
1781 * and route.cc's max (configured_in, configured_out)
1783 * no-inplace copies "thru" outputs (to emulate in-place) for
1784 * all outputs (to prevent overwrite) into a temporary space
1785 * which also holds input buffers (in case the plugin does process
1786 * in-place and overwrites those).
1788 * this buffers need to be at least as
1789 * natural_input_streams () + possible outputs.
1791 * sidechain inputs add a constraint on the input:
1792 * configured input + sidechain (=_configured_internal)
1794 * NB. this also satisfies
1795 * max (natural_input_streams(), natural_output_streams())
1796 * which is needed for silence runs
1798 _required_buffers = ChanCount::max (_configured_internal,
1799 natural_input_streams () + ChanCount::max (_configured_out, natural_output_streams () * get_count ()));
1801 if (old_in != in || old_out != out || old_internal != _configured_internal
1802 || old_pins != natural_input_streams ()
1803 || (old_match.method != _match.method && (old_match.method == Split || _match.method == Split))
1805 PluginIoReConfigure (); /* EMIT SIGNAL */
1808 _delaybuffers.configure (_configured_out, _plugins.front ()->max_latency ());
1809 _latency_changed = true;
1811 // we don't know the analysis window size, so we must work with the
1812 // current buffer size here. each request for data fills in these
1813 // buffers and the analyser makes sure it gets enough data for the
1815 session().ensure_buffer_set (_signal_analysis_inputs, in);
1816 _signal_analysis_inputs.set_count (in);
1818 session().ensure_buffer_set (_signal_analysis_outputs, out);
1819 _signal_analysis_outputs.set_count (out);
1821 // std::cerr << "set counts to i" << in.n_audio() << "/o" << out.n_audio() << std::endl;
1824 return Processor::configure_io (in, out);
1827 /** Decide whether this PluginInsert can support a given IO configuration.
1828 * To do this, we run through a set of possible solutions in rough order of
1831 * @param in Required input channel count.
1832 * @param out Filled in with the output channel count if we return true.
1833 * @return true if the given IO configuration can be supported.
1836 PluginInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out)
1839 _sidechain->can_support_io_configuration (in, out); // never fails, sets "out"
1841 return private_can_support_io_configuration (in, out).method != Impossible;
1845 PluginInsert::private_can_support_io_configuration (ChanCount const& in, ChanCount& out) const
1847 if (!_custom_cfg && _preset_out.n_audio () > 0) {
1848 // preseed hint (for variable i/o)
1849 out.set (DataType::AUDIO, _preset_out.n_audio ());
1852 Match rv = internal_can_support_io_configuration (in, out);
1854 if (!_custom_cfg && _preset_out.n_audio () > 0) {
1855 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: using output preset: %2\n", name(), _preset_out));
1856 out.set (DataType::AUDIO, _preset_out.n_audio ());
1861 /** A private version of can_support_io_configuration which returns the method
1862 * by which the configuration can be matched, rather than just whether or not
1866 PluginInsert::internal_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
1868 if (_plugins.empty()) {
1873 if (is_channelstrip ()) {
1875 return Match (ExactMatch, 1);
1879 /* if a user specified a custom cfg, so be it. */
1881 PluginInfoPtr info = _plugins.front()->get_info();
1883 if (info->reconfigurable_io()) {
1884 return Match (Delegate, 1, _strict_io, true);
1886 return Match (ExactMatch, get_count(), _strict_io, true);
1890 /* try automatic configuration */
1891 Match m = PluginInsert::automatic_can_support_io_configuration (inx, out);
1893 PluginInfoPtr info = _plugins.front()->get_info();
1894 ChanCount inputs = info->n_inputs;
1895 ChanCount outputs = info->n_outputs;
1897 /* handle case strict-i/o */
1898 if (_strict_io && m.method != Impossible) {
1901 /* special case MIDI instruments */
1902 if (needs_midi_input ()) {
1903 // output = midi-bypass + at most master-out channels.
1904 ChanCount max_out (DataType::AUDIO, 2); // TODO use master-out
1905 max_out.set (DataType::MIDI, out.get(DataType::MIDI));
1906 out = ChanCount::min (out, max_out);
1907 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: special case strict-i/o instrument\n", name()));
1913 if (inx.n_audio () != out.n_audio ()) { // ignore midi bypass
1914 /* replicate processor to match output count (generators and such)
1915 * at least enough to feed every output port. */
1916 uint32_t f = 1; // at least one. e.g. control data filters, no in, no out.
1917 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1918 uint32_t nout = outputs.get (*t);
1919 if (nout == 0 || inx.get(*t) == 0) { continue; }
1920 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nout));
1923 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: special case strict-i/o for generator\n", name()));
1924 return Match (Replicate, f, _strict_io);
1935 if (m.method != Impossible) {
1939 ChanCount ns_inputs = inputs - sidechain_input_pins ();
1941 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: resolving 'Impossible' match...\n", name()));
1943 if (info->reconfigurable_io()) {
1946 if (out.n_midi () > 0 && out.n_audio () == 0) { out.set (DataType::AUDIO, 2); }
1947 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1948 bool const r = _plugins.front()->can_support_io_configuration (inx + sidechain_input_pins (), out, &useins);
1950 // houston, we have a problem.
1951 return Match (Impossible, 0);
1954 if (inx.n_midi () > 0 && out.n_midi () == 0) { out.set (DataType::MIDI, 1); }
1955 return Match (Delegate, 1, _strict_io);
1958 ChanCount midi_bypass;
1959 if (inx.get(DataType::MIDI) == 1 && outputs.get(DataType::MIDI) == 0) {
1960 midi_bypass.set (DataType::MIDI, 1);
1963 // add at least as many plugins so that output count matches input count (w/o sidechain pins)
1965 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1966 uint32_t nin = ns_inputs.get (*t);
1967 uint32_t nout = outputs.get (*t);
1968 if (nin == 0 || inx.get(*t) == 0) { continue; }
1969 // prefer floor() so the count won't overly increase IFF (nin < nout)
1970 f = max (f, (uint32_t) floor (inx.get(*t) / (float)nout));
1972 if (f > 0 && outputs * f >= _configured_out) {
1973 out = outputs * f + midi_bypass;
1974 return Match (Replicate, f, _strict_io);
1977 // add at least as many plugins needed to connect all inputs (w/o sidechain pins)
1979 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1980 uint32_t nin = ns_inputs.get (*t);
1981 if (nin == 0 || inx.get(*t) == 0) { continue; }
1982 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1985 out = outputs * f + midi_bypass;
1986 return Match (Replicate, f, _strict_io);
1989 // add at least as many plugins needed to connect all inputs
1991 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1992 uint32_t nin = inputs.get (*t);
1993 if (nin == 0 || inx.get(*t) == 0) { continue; }
1994 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1996 out = outputs * f + midi_bypass;
1997 return Match (Replicate, f, _strict_io);
2000 /* this is the original Ardour 3/4 behavior, mainly for backwards compatibility */
2002 PluginInsert::automatic_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
2004 if (_plugins.empty()) {
2008 PluginInfoPtr info = _plugins.front()->get_info();
2009 ChanCount in; in += inx;
2010 ChanCount midi_bypass;
2012 if (info->reconfigurable_io()) {
2013 /* Plugin has flexible I/O, so delegate to it
2014 * pre-seed outputs, plugin tries closest match
2017 if (out.n_midi () > 0 && out.n_audio () == 0) { out.set (DataType::AUDIO, 2); }
2018 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
2019 bool const r = _plugins.front()->can_support_io_configuration (in + sidechain_input_pins (), out);
2021 return Match (Impossible, 0);
2024 if (in.n_midi () > 0 && out.n_midi () == 0) { out.set (DataType::MIDI, 1); }
2025 return Match (Delegate, 1);
2028 ChanCount inputs = info->n_inputs;
2029 ChanCount outputs = info->n_outputs;
2030 ChanCount ns_inputs = inputs - sidechain_input_pins ();
2032 if (in.get(DataType::MIDI) == 1 && outputs.get(DataType::MIDI) == 0) {
2033 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: bypassing midi-data\n", name()));
2034 midi_bypass.set (DataType::MIDI, 1);
2036 if (in.get(DataType::MIDI) == 1 && inputs.get(DataType::MIDI) == 0) {
2037 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: hiding midi-port from plugin\n", name()));
2038 in.set(DataType::MIDI, 0);
2041 // add internally provided sidechain ports
2042 ChanCount insc = in + sidechain_input_ports ();
2044 bool no_inputs = true;
2045 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2046 if (inputs.get (*t) != 0) {
2053 /* no inputs so we can take any input configuration since we throw it away */
2054 out = outputs + midi_bypass;
2055 return Match (NoInputs, 1);
2058 /* Plugin inputs match requested inputs + side-chain-ports exactly */
2059 if (inputs == insc) {
2060 out = outputs + midi_bypass;
2061 return Match (ExactMatch, 1);
2064 /* Plugin inputs matches without side-chain-pins */
2065 if (ns_inputs == in) {
2066 out = outputs + midi_bypass;
2067 return Match (ExactMatch, 1);
2070 /* We may be able to run more than one copy of the plugin within this insert
2071 to cope with the insert having more inputs than the plugin.
2072 We allow replication only for plugins with either zero or 1 inputs and outputs
2073 for every valid data type.
2077 bool can_replicate = true;
2078 for (DataType::iterator t = DataType::begin(); t != DataType::end() && can_replicate; ++t) {
2080 // ignore side-chains
2081 uint32_t nin = ns_inputs.get (*t);
2083 // No inputs of this type
2084 if (nin == 0 && in.get(*t) == 0) {
2088 if (nin != 1 || outputs.get (*t) != 1) {
2089 can_replicate = false;
2093 // Potential factor not set yet
2095 f = in.get(*t) / nin;
2098 // Factor for this type does not match another type, can not replicate
2099 if (f != (in.get(*t) / nin)) {
2100 can_replicate = false;
2105 if (can_replicate && f > 0) {
2106 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2107 out.set (*t, outputs.get(*t) * f);
2110 return Match (Replicate, f);
2113 /* If the processor has exactly one input of a given type, and
2114 the plugin has more, we can feed the single processor input
2115 to some or all of the plugin inputs. This is rather
2116 special-case-y, but the 1-to-many case is by far the
2117 simplest. How do I split thy 2 processor inputs to 3
2118 plugin inputs? Let me count the ways ...
2121 bool can_split = true;
2122 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2124 bool const can_split_type = (in.get (*t) == 1 && ns_inputs.get (*t) > 1);
2125 bool const nothing_to_do_for_type = (in.get (*t) == 0 && inputs.get (*t) == 0);
2127 if (!can_split_type && !nothing_to_do_for_type) {
2133 out = outputs + midi_bypass;
2134 return Match (Split, 1);
2137 /* If the plugin has more inputs than we want, we can `hide' some of them
2138 by feeding them silence.
2141 bool could_hide = false;
2142 bool cannot_hide = false;
2143 ChanCount hide_channels;
2145 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2146 if (inputs.get(*t) > in.get(*t)) {
2147 /* there is potential to hide, since the plugin has more inputs of type t than the insert */
2148 hide_channels.set (*t, inputs.get(*t) - in.get(*t));
2150 } else if (inputs.get(*t) < in.get(*t)) {
2151 /* we definitely cannot hide, since the plugin has fewer inputs of type t than the insert */
2156 if (could_hide && !cannot_hide) {
2157 out = outputs + midi_bypass;
2158 return Match (Hide, 1, false, false, hide_channels);
2161 return Match (Impossible, 0);
2166 PluginInsert::get_state ()
2168 return state (true);
2172 PluginInsert::state (bool full)
2174 XMLNode& node = Processor::state (full);
2176 node.add_property("type", _plugins[0]->state_node_name());
2177 node.add_property("unique-id", _plugins[0]->unique_id());
2178 node.add_property("count", string_compose("%1", _plugins.size()));
2180 /* remember actual i/o configuration (for later placeholder
2181 * in case the plugin goes missing) */
2182 node.add_child_nocopy (* _configured_in.state (X_("ConfiguredInput")));
2183 node.add_child_nocopy (* _custom_sinks.state (X_("CustomSinks")));
2184 node.add_child_nocopy (* _configured_out.state (X_("ConfiguredOutput")));
2185 node.add_child_nocopy (* _preset_out.state (X_("PresetOutput")));
2187 /* save custom i/o config */
2188 node.add_property("custom", _custom_cfg ? "yes" : "no");
2189 for (uint32_t pc = 0; pc < get_count(); ++pc) {
2191 snprintf (tmp, sizeof(tmp), "InputMap-%d", pc);
2192 node.add_child_nocopy (* _in_map[pc].state (tmp));
2193 snprintf (tmp, sizeof(tmp), "OutputMap-%d", pc);
2194 node.add_child_nocopy (* _out_map[pc].state (tmp));
2196 node.add_child_nocopy (* _thru_map.state ("ThruMap"));
2199 node.add_child_nocopy (_sidechain->state (full));
2202 _plugins[0]->set_insert_id(this->id());
2203 node.add_child_nocopy (_plugins[0]->get_state());
2205 for (Controls::iterator c = controls().begin(); c != controls().end(); ++c) {
2206 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> ((*c).second);
2208 node.add_child_nocopy (ac->get_state());
2216 PluginInsert::set_control_ids (const XMLNode& node, int version)
2218 const XMLNodeList& nlist = node.children();
2219 XMLNodeConstIterator iter;
2220 set<Evoral::Parameter>::const_iterator p;
2222 for (iter = nlist.begin(); iter != nlist.end(); ++iter) {
2223 if ((*iter)->name() == Controllable::xml_node_name) {
2224 XMLProperty const * prop;
2226 uint32_t p = (uint32_t)-1;
2228 if ((prop = (*iter)->property (X_("symbol"))) != 0) {
2229 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugins[0]);
2231 p = lv2plugin->port_index(prop->value().c_str());
2235 if (p == (uint32_t)-1 && (prop = (*iter)->property (X_("parameter"))) != 0) {
2236 p = atoi (prop->value());
2239 if (p != (uint32_t)-1) {
2241 /* this may create the new controllable */
2243 boost::shared_ptr<Evoral::Control> c = control (Evoral::Parameter (PluginAutomation, 0, p));
2245 #ifndef NO_PLUGIN_STATE
2249 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (c);
2251 ac->set_state (**iter, version);
2260 PluginInsert::set_state(const XMLNode& node, int version)
2262 XMLNodeList nlist = node.children();
2263 XMLNodeIterator niter;
2264 XMLPropertyList plist;
2265 XMLProperty const * prop;
2266 ARDOUR::PluginType type;
2268 if ((prop = node.property ("type")) == 0) {
2269 error << _("XML node describing plugin is missing the `type' field") << endmsg;
2273 if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */
2274 type = ARDOUR::LADSPA;
2275 } else if (prop->value() == X_("lv2")) {
2277 } else if (prop->value() == X_("windows-vst")) {
2278 type = ARDOUR::Windows_VST;
2279 } else if (prop->value() == X_("lxvst")) {
2280 type = ARDOUR::LXVST;
2281 } else if (prop->value() == X_("audiounit")) {
2282 type = ARDOUR::AudioUnit;
2283 } else if (prop->value() == X_("luaproc")) {
2286 error << string_compose (_("unknown plugin type %1 in plugin insert state"),
2292 prop = node.property ("unique-id");
2295 #ifdef WINDOWS_VST_SUPPORT
2296 /* older sessions contain VST plugins with only an "id" field.
2299 if (type == ARDOUR::Windows_VST) {
2300 prop = node.property ("id");
2304 #ifdef LXVST_SUPPORT
2305 /*There shouldn't be any older sessions with linuxVST support.. but anyway..*/
2307 if (type == ARDOUR::LXVST) {
2308 prop = node.property ("id");
2314 error << _("Plugin has no unique ID field") << endmsg;
2319 boost::shared_ptr<Plugin> plugin = find_plugin (_session, prop->value(), type);
2321 /* treat linux and windows VST plugins equivalent if they have the same uniqueID
2322 * allow to move sessions windows <> linux */
2323 #ifdef LXVST_SUPPORT
2324 if (plugin == 0 && type == ARDOUR::Windows_VST) {
2325 type = ARDOUR::LXVST;
2326 plugin = find_plugin (_session, prop->value(), type);
2330 #ifdef WINDOWS_VST_SUPPORT
2331 if (plugin == 0 && type == ARDOUR::LXVST) {
2332 type = ARDOUR::Windows_VST;
2333 plugin = find_plugin (_session, prop->value(), type);
2337 if (plugin == 0 && type == ARDOUR::Lua) {
2338 /* unique ID (sha1 of script) was not found,
2339 * load the plugin from the serialized version in the
2340 * session-file instead.
2342 boost::shared_ptr<LuaProc> lp (new LuaProc (_session.engine(), _session, ""));
2343 XMLNode *ls = node.child (lp->state_node_name().c_str());
2345 lp->set_script_from_state (*ls);
2351 error << string_compose(
2352 _("Found a reference to a plugin (\"%1\") that is unknown.\n"
2353 "Perhaps it was removed or moved since it was last used."),
2359 // The name of the PluginInsert comes from the plugin, nothing else
2360 _name = plugin->get_info()->name;
2364 // Processor::set_state() will set this, but too late
2365 // for it to be available when setting up plugin
2366 // state. We can't call Processor::set_state() until
2367 // the plugins themselves are created and added.
2371 if (_plugins.empty()) {
2372 /* if we are adding the first plugin, we will need to set
2373 up automatable controls.
2375 add_plugin (plugin);
2376 create_automatable_parameters ();
2377 set_control_ids (node, version);
2380 if ((prop = node.property ("count")) != 0) {
2381 sscanf (prop->value().c_str(), "%u", &count);
2384 if (_plugins.size() != count) {
2385 for (uint32_t n = 1; n < count; ++n) {
2386 add_plugin (plugin_factory (plugin));
2390 Processor::set_state (node, version);
2392 PBD::ID new_id = this->id();
2393 PBD::ID old_id = this->id();
2395 if ((prop = node.property ("id")) != 0) {
2396 old_id = prop->value ();
2399 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2401 /* find the node with the type-specific node name ("lv2", "ladspa", etc)
2402 and set all plugins to the same state.
2405 if ((*niter)->name() == plugin->state_node_name()) {
2407 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2408 /* Plugin state can include external files which are named after the ID.
2410 * If regenerate_xml_or_string_ids() is set, the ID will already have
2411 * been changed, so we need to use the old ID from the XML to load the
2412 * state and then update the ID.
2414 * When copying a plugin-state, route_ui takes care of of updating the ID,
2415 * but we need to call set_insert_id() to clear the cached plugin-state
2416 * and force a change.
2418 if (!regenerate_xml_or_string_ids ()) {
2419 (*i)->set_insert_id (new_id);
2421 (*i)->set_insert_id (old_id);
2424 (*i)->set_state (**niter, version);
2426 if (regenerate_xml_or_string_ids ()) {
2427 (*i)->set_insert_id (new_id);
2435 if (version < 3000) {
2437 /* Only 2.X sessions need a call to set_parameter_state() - in 3.X and above
2438 this is all handled by Automatable
2441 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2442 if ((*niter)->name() == "Redirect") {
2443 /* XXX do we need to tackle placement? i think not (pd; oct 16 2009) */
2444 Processor::set_state (**niter, version);
2449 set_parameter_state_2X (node, version);
2452 if ((prop = node.property (X_("custom"))) != 0) {
2453 _custom_cfg = string_is_affirmative (prop->value());
2456 uint32_t in_maps = 0;
2457 uint32_t out_maps = 0;
2458 XMLNodeList kids = node.children ();
2459 for (XMLNodeIterator i = kids.begin(); i != kids.end(); ++i) {
2460 if ((*i)->name() == X_("ConfiguredInput")) {
2461 _configured_in = ChanCount(**i);
2463 if ((*i)->name() == X_("CustomSinks")) {
2464 _custom_sinks = ChanCount(**i);
2466 if ((*i)->name() == X_("ConfiguredOutput")) {
2467 _custom_out = ChanCount(**i);
2468 _configured_out = ChanCount(**i);
2470 if ((*i)->name() == X_("PresetOutput")) {
2471 _preset_out = ChanCount(**i);
2473 if (strncmp ((*i)->name ().c_str(), X_("InputMap-"), 9) == 0) {
2474 long pc = atol (&((*i)->name().c_str()[9]));
2475 if (pc >= 0 && pc <= (long) get_count()) {
2476 _in_map[pc] = ChanMapping (**i);
2480 if (strncmp ((*i)->name ().c_str(), X_("OutputMap-"), 10) == 0) {
2481 long pc = atol (&((*i)->name().c_str()[10]));
2482 if (pc >= 0 && pc <= (long) get_count()) {
2483 _out_map[pc] = ChanMapping (**i);
2487 if ((*i)->name () == "ThruMap") {
2488 _thru_map = ChanMapping (**i);
2491 // sidechain is a Processor (IO)
2492 if ((*i)->name () == Processor::state_node_name) {
2496 _sidechain->set_state (**i, version);
2500 if (in_maps == out_maps && out_maps >0 && out_maps == get_count()) {
2501 _maps_from_state = true;
2504 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2508 (*i)->deactivate ();
2512 PluginConfigChanged (); /* EMIT SIGNAL */
2517 PluginInsert::update_id (PBD::ID id)
2520 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2521 (*i)->set_insert_id (id);
2526 PluginInsert::set_state_dir (const std::string& d)
2528 // state() only saves the state of the first plugin
2529 _plugins[0]->set_state_dir (d);
2533 PluginInsert::set_parameter_state_2X (const XMLNode& node, int version)
2535 XMLNodeList nlist = node.children();
2536 XMLNodeIterator niter;
2538 /* look for port automation node */
2540 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2542 if ((*niter)->name() != port_automation_node_name) {
2547 XMLProperty const * cprop;
2548 XMLNodeConstIterator iter;
2553 cnodes = (*niter)->children ("port");
2555 for (iter = cnodes.begin(); iter != cnodes.end(); ++iter){
2559 if ((cprop = child->property("number")) != 0) {
2560 port = cprop->value().c_str();
2562 warning << _("PluginInsert: Auto: no ladspa port number") << endmsg;
2566 sscanf (port, "%" PRIu32, &port_id);
2568 if (port_id >= _plugins[0]->parameter_count()) {
2569 warning << _("PluginInsert: Auto: port id out of range") << endmsg;
2573 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(
2574 control(Evoral::Parameter(PluginAutomation, 0, port_id), true));
2576 if (c && c->alist()) {
2577 if (!child->children().empty()) {
2578 c->alist()->set_state (*child->children().front(), version);
2580 /* In some cases 2.X saves lists with min_yval and max_yval
2581 being FLT_MIN and FLT_MAX respectively. This causes problems
2582 in A3 because these min/max values are used to compute
2583 where GUI control points should be drawn. If we see such
2584 values, `correct' them to the min/max of the appropriate
2588 float min_y = c->alist()->get_min_y ();
2589 float max_y = c->alist()->get_max_y ();
2591 ParameterDescriptor desc;
2592 _plugins.front()->get_parameter_descriptor (port_id, desc);
2594 if (min_y == FLT_MIN) {
2598 if (max_y == FLT_MAX) {
2602 c->alist()->set_yrange (min_y, max_y);
2605 error << string_compose (_("PluginInsert: automatable control %1 not found - ignored"), port_id) << endmsg;
2617 PluginInsert::describe_parameter (Evoral::Parameter param)
2619 if (param.type() == PluginAutomation) {
2620 return _plugins[0]->describe_parameter (param);
2621 } else if (param.type() == PluginPropertyAutomation) {
2622 boost::shared_ptr<AutomationControl> c(automation_control(param));
2623 if (c && !c->desc().label.empty()) {
2624 return c->desc().label;
2627 return Automatable::describe_parameter(param);
2631 PluginInsert::signal_latency() const
2633 if (_user_latency) {
2634 return _user_latency;
2637 return _plugins[0]->signal_latency ();
2641 PluginInsert::type ()
2643 return plugin()->get_info()->type;
2646 PluginInsert::PluginControl::PluginControl (PluginInsert* p,
2647 const Evoral::Parameter& param,
2648 const ParameterDescriptor& desc,
2649 boost::shared_ptr<AutomationList> list)
2650 : AutomationControl (p->session(), param, desc, list, p->describe_parameter(param))
2654 alist()->reset_default (desc.normal);
2656 list->set_interpolation(Evoral::ControlList::Discrete);
2661 /** @param val `user' value */
2664 PluginInsert::PluginControl::actually_set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override)
2666 /* FIXME: probably should be taking out some lock here.. */
2668 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
2669 (*i)->set_parameter (_list->parameter().id(), user_val);
2672 boost::shared_ptr<Plugin> iasp = _plugin->_impulseAnalysisPlugin.lock();
2674 iasp->set_parameter (_list->parameter().id(), user_val);
2677 AutomationControl::actually_set_value (user_val, group_override);
2681 PluginInsert::PluginControl::catch_up_with_external_value (double user_val)
2683 AutomationControl::actually_set_value (user_val, Controllable::NoGroup);
2687 PluginInsert::PluginControl::get_state ()
2691 XMLNode& node (AutomationControl::get_state());
2692 ss << parameter().id();
2693 node.add_property (X_("parameter"), ss.str());
2695 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugin->_plugins[0]);
2697 node.add_property (X_("symbol"), lv2plugin->port_symbol (parameter().id()));
2704 /** @return `user' val */
2706 PluginInsert::PluginControl::get_value () const
2708 boost::shared_ptr<Plugin> plugin = _plugin->plugin (0);
2714 return plugin->get_parameter (_list->parameter().id());
2717 PluginInsert::PluginPropertyControl::PluginPropertyControl (PluginInsert* p,
2718 const Evoral::Parameter& param,
2719 const ParameterDescriptor& desc,
2720 boost::shared_ptr<AutomationList> list)
2721 : AutomationControl (p->session(), param, desc, list)
2725 alist()->set_yrange (desc.lower, desc.upper);
2726 alist()->reset_default (desc.normal);
2731 PluginInsert::PluginPropertyControl::actually_set_value (double user_val, Controllable::GroupControlDisposition gcd)
2733 /* Old numeric set_value(), coerce to appropriate datatype if possible.
2734 This is lossy, but better than nothing until Ardour's automation system
2735 can handle various datatypes all the way down. */
2736 const Variant value(_desc.datatype, user_val);
2737 if (value.type() == Variant::NOTHING) {
2738 error << "set_value(double) called for non-numeric property" << endmsg;
2742 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
2743 (*i)->set_property(_list->parameter().id(), value);
2748 AutomationControl::actually_set_value (user_val, gcd);
2752 PluginInsert::PluginPropertyControl::get_state ()
2756 XMLNode& node (AutomationControl::get_state());
2757 ss << parameter().id();
2758 node.add_property (X_("property"), ss.str());
2759 node.remove_property (X_("value"));
2765 PluginInsert::PluginPropertyControl::get_value () const
2767 return _value.to_double();
2770 boost::shared_ptr<Plugin>
2771 PluginInsert::get_impulse_analysis_plugin()
2773 boost::shared_ptr<Plugin> ret;
2774 if (_impulseAnalysisPlugin.expired()) {
2775 // LV2 in particular uses various _session params
2776 // during init() -- most notably block_size..
2778 ret = plugin_factory(_plugins[0]);
2779 ret->configure_io (internal_input_streams (), internal_output_streams ());
2780 _impulseAnalysisPlugin = ret;
2782 ret = _impulseAnalysisPlugin.lock();
2789 PluginInsert::collect_signal_for_analysis (framecnt_t nframes)
2791 // called from outside the audio thread, so this should be safe
2792 // only do audio as analysis is (currently) only for audio plugins
2793 _signal_analysis_inputs.ensure_buffers (DataType::AUDIO, input_streams().n_audio(), nframes);
2794 _signal_analysis_outputs.ensure_buffers (DataType::AUDIO, output_streams().n_audio(), nframes);
2796 _signal_analysis_collected_nframes = 0;
2797 _signal_analysis_collect_nframes_max = nframes;
2800 /** Add a plugin to our list */
2802 PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
2804 plugin->set_insert_id (this->id());
2806 if (_plugins.empty()) {
2807 /* first (and probably only) plugin instance - connect to relevant signals */
2809 plugin->ParameterChangedExternally.connect_same_thread (*this, boost::bind (&PluginInsert::parameter_changed_externally, this, _1, _2));
2810 plugin->StartTouch.connect_same_thread (*this, boost::bind (&PluginInsert::start_touch, this, _1));
2811 plugin->EndTouch.connect_same_thread (*this, boost::bind (&PluginInsert::end_touch, this, _1));
2812 plugin->LatencyChanged.connect_same_thread (*this, boost::bind (&PluginInsert::latency_changed, this, _1, _2));
2813 _custom_sinks = plugin->get_info()->n_inputs;
2814 // cache sidechain port count
2815 _cached_sidechain_pins.reset ();
2816 const ChanCount& nis (plugin->get_info()->n_inputs);
2817 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2818 for (uint32_t in = 0; in < nis.get (*t); ++in) {
2819 const Plugin::IOPortDescription& iod (plugin->describe_io_port (*t, true, in));
2820 if (iod.is_sidechain) {
2821 _cached_sidechain_pins.set (*t, 1 + _cached_sidechain_pins.n(*t));
2826 #if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
2827 boost::shared_ptr<VSTPlugin> vst = boost::dynamic_pointer_cast<VSTPlugin> (plugin);
2829 vst->set_insert (this, _plugins.size ());
2832 _plugins.push_back (plugin);
2836 PluginInsert::load_preset (ARDOUR::Plugin::PresetRecord pr)
2839 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2840 if (! (*i)->load_preset (pr)) {
2848 PluginInsert::realtime_handle_transport_stopped ()
2850 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2851 (*i)->realtime_handle_transport_stopped ();
2856 PluginInsert::realtime_locate ()
2858 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2859 (*i)->realtime_locate ();
2864 PluginInsert::monitoring_changed ()
2866 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2867 (*i)->monitoring_changed ();
2872 PluginInsert::latency_changed (framecnt_t, framecnt_t)
2874 // this is called in RT context, LatencyChanged is emitted after run()
2875 _latency_changed = true;
2879 PluginInsert::start_touch (uint32_t param_id)
2881 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
2883 ac->start_touch (session().audible_frame());
2888 PluginInsert::end_touch (uint32_t param_id)
2890 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
2892 ac->stop_touch (true, session().audible_frame());
2896 std::ostream& operator<<(std::ostream& o, const ARDOUR::PluginInsert::Match& m)
2899 case PluginInsert::Impossible: o << "Impossible"; break;
2900 case PluginInsert::Delegate: o << "Delegate"; break;
2901 case PluginInsert::NoInputs: o << "NoInputs"; break;
2902 case PluginInsert::ExactMatch: o << "ExactMatch"; break;
2903 case PluginInsert::Replicate: o << "Replicate"; break;
2904 case PluginInsert::Split: o << "Split"; break;
2905 case PluginInsert::Hide: o << "Hide"; break;
2907 o << " cnt: " << m.plugins
2908 << (m.strict_io ? " strict-io" : "")
2909 << (m.custom_cfg ? " custom-cfg" : "");
2910 if (m.method == PluginInsert::Hide) {
2911 o << " hide: " << m.hide;