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 , _signal_analysis_collected_nframes(0)
71 , _signal_analysis_collect_nframes_max(0)
76 , _maps_from_state (false)
78 /* the first is the master */
82 create_automatable_parameters ();
83 const ChanCount& sc (sidechain_input_pins ());
84 if (sc.n_audio () > 0) {
85 add_sidechain (sc.n_audio ());
90 PluginInsert::~PluginInsert ()
95 PluginInsert::set_strict_io (bool b)
97 bool changed = _strict_io != b;
100 PluginConfigChanged (); /* EMIT SIGNAL */
105 PluginInsert::set_count (uint32_t num)
107 bool require_state = !_plugins.empty();
109 if (require_state && num > 1 && plugin (0)->get_info ()->type == ARDOUR::AudioUnit) {
110 // we don't allow to replicate AUs
114 /* this is a bad idea.... we shouldn't do this while active.
115 * only a route holding their redirect_lock should be calling this
120 } else if (num > _plugins.size()) {
121 uint32_t diff = num - _plugins.size();
123 for (uint32_t n = 0; n < diff; ++n) {
124 boost::shared_ptr<Plugin> p = plugin_factory (_plugins[0]);
128 XMLNode& state = _plugins[0]->get_state ();
129 p->set_state (state, Stateful::loading_state_version);
136 PluginConfigChanged (); /* EMIT SIGNAL */
138 } else if (num < _plugins.size()) {
139 uint32_t diff = _plugins.size() - num;
140 for (uint32_t n= 0; n < diff; ++n) {
143 PluginConfigChanged (); /* EMIT SIGNAL */
151 PluginInsert::set_sinks (const ChanCount& c)
154 /* no signal, change will only be visible after re-config */
158 PluginInsert::set_outputs (const ChanCount& c)
160 bool changed = (_custom_out != c) && _custom_cfg;
163 PluginConfigChanged (); /* EMIT SIGNAL */
168 PluginInsert::set_custom_cfg (bool b)
170 bool changed = _custom_cfg != b;
173 PluginConfigChanged (); /* EMIT SIGNAL */
178 PluginInsert::set_preset_out (const ChanCount& c)
180 bool changed = _preset_out != c;
182 if (changed && !_custom_cfg) {
183 PluginConfigChanged (); /* EMIT SIGNAL */
189 PluginInsert::add_sidechain (uint32_t n_audio)
191 // caller must hold process lock
195 std::ostringstream n;
197 n << "Sidechain " << Session::next_name_id ();
199 n << "TO BE RESET FROM XML";
201 SideChain *sc = new SideChain (_session, n.str ());
202 _sidechain = boost::shared_ptr<SideChain> (sc);
203 _sidechain->activate ();
204 for (uint32_t n = 0; n < n_audio; ++n) {
205 _sidechain->input()->add_port ("", owner()); // add a port, don't connect.
207 PluginConfigChanged (); /* EMIT SIGNAL */
212 PluginInsert::del_sidechain ()
218 PluginConfigChanged (); /* EMIT SIGNAL */
223 PluginInsert::control_list_automation_state_changed (Evoral::Parameter which, AutoState s)
225 if (which.type() != PluginAutomation)
228 boost::shared_ptr<AutomationControl> c
229 = boost::dynamic_pointer_cast<AutomationControl>(control (which));
232 _plugins[0]->set_parameter (which.id(), c->list()->eval (_session.transport_frame()));
237 PluginInsert::output_streams() const
239 assert (_configured);
240 return _configured_out;
244 PluginInsert::input_streams() const
246 assert (_configured);
247 return _configured_in;
251 PluginInsert::internal_streams() const
253 assert (_configured);
254 return _configured_internal;
258 PluginInsert::internal_output_streams() const
260 assert (!_plugins.empty());
262 PluginInfoPtr info = _plugins.front()->get_info();
264 if (info->reconfigurable_io()) {
265 ChanCount out = _plugins.front()->output_streams ();
266 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, reconfigur(able) output streams = %1\n", out));
269 ChanCount out = info->n_outputs;
270 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, static output streams = %1 for %2 plugins\n", out, _plugins.size()));
271 out.set_audio (out.n_audio() * _plugins.size());
272 out.set_midi (out.n_midi() * _plugins.size());
278 PluginInsert::internal_input_streams() const
280 assert (!_plugins.empty());
284 PluginInfoPtr info = _plugins.front()->get_info();
286 if (info->reconfigurable_io()) {
287 in = _plugins.front()->input_streams();
292 DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, input streams = %1, match using %2\n", in, _match.method));
294 if (_match.method == Split) {
296 /* we are splitting 1 processor input to multiple plugin inputs,
297 so we have a maximum of 1 stream of each type.
299 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
300 if (in.get (*t) > 1) {
306 } else if (_match.method == Hide) {
308 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
309 in.set (*t, in.get (*t) - _match.hide.get (*t));
315 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
316 in.set (*t, in.get (*t) * _plugins.size ());
324 PluginInsert::natural_output_streams() const
327 if (is_channelstrip ()) {
328 return ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2));
331 return _plugins[0]->get_info()->n_outputs;
335 PluginInsert::natural_input_streams() const
338 if (is_channelstrip ()) {
339 return ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2));
342 return _plugins[0]->get_info()->n_inputs;
346 PluginInsert::sidechain_input_pins() const
348 return _cached_sidechain_pins;
352 PluginInsert::has_no_inputs() const
354 return _plugins[0]->get_info()->n_inputs == ChanCount::ZERO;
358 PluginInsert::has_no_audio_inputs() const
360 return _plugins[0]->get_info()->n_inputs.n_audio() == 0;
364 PluginInsert::plugin_latency () const {
365 return _plugins.front()->signal_latency ();
369 PluginInsert::needs_midi_input() const
371 PluginInfoPtr pip = _plugins[0]->get_info();
372 if (pip->needs_midi_input ()) {
375 return pip->n_inputs.n_midi() != 0 && pip->n_outputs.n_audio() != 0;
379 PluginInsert::has_output_presets (ChanCount in, ChanCount out)
381 if (!_configured && _plugins[0]->get_info ()->reconfigurable_io ()) {
382 // collect possible configurations, prefer given in/out
383 _plugins[0]->can_support_io_configuration (in, out);
386 PluginOutputConfiguration ppc (_plugins[0]->possible_output ());
388 if (ppc.size () == 0) {
391 if (!strict_io () && ppc.size () == 1) {
395 if (strict_io () && ppc.size () == 1) {
396 // "stereo" is currently preferred default for instruments
397 if (ppc.find (2) != ppc.end ()) {
401 if (!needs_midi_input ()) {
408 PluginInsert::create_automatable_parameters ()
410 assert (!_plugins.empty());
412 set<Evoral::Parameter> a = _plugins.front()->automatable ();
414 for (set<Evoral::Parameter>::iterator i = a.begin(); i != a.end(); ++i) {
415 if (i->type() == PluginAutomation) {
417 Evoral::Parameter param(*i);
419 ParameterDescriptor desc;
420 _plugins.front()->get_parameter_descriptor(i->id(), desc);
422 can_automate (param);
423 boost::shared_ptr<AutomationList> list(new AutomationList(param, desc));
424 boost::shared_ptr<AutomationControl> c (new PluginControl(this, param, desc, list));
426 _plugins.front()->set_automation_control (i->id(), c);
427 } else if (i->type() == PluginPropertyAutomation) {
428 Evoral::Parameter param(*i);
429 const ParameterDescriptor& desc = _plugins.front()->get_property_descriptor(param.id());
430 if (desc.datatype != Variant::NOTHING) {
431 boost::shared_ptr<AutomationList> list;
432 if (Variant::type_is_numeric(desc.datatype)) {
433 list = boost::shared_ptr<AutomationList>(new AutomationList(param, desc));
435 add_control (boost::shared_ptr<AutomationControl> (new PluginPropertyControl(this, param, desc, list)));
440 /** Called when something outside of this host has modified a plugin
441 * parameter. Responsible for propagating the change to two places:
443 * 1) anything listening to the Control itself
444 * 2) any replicated plugins that make up this PluginInsert.
446 * The PluginInsert is connected to the ParameterChangedExternally signal for
447 * the first (primary) plugin, and here broadcasts that change to any others.
449 * XXX We should probably drop this whole replication idea (Paul, October 2015)
450 * since it isn't used by sensible plugin APIs (AU, LV2).
453 PluginInsert::parameter_changed_externally (uint32_t which, float val)
455 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, which));
457 /* First propagation: alter the underlying value of the control,
458 * without telling the plugin(s) that own/use it to set it.
465 boost::shared_ptr<PluginControl> pc = boost::dynamic_pointer_cast<PluginControl> (ac);
468 pc->catch_up_with_external_value (val);
471 /* Second propagation: tell all plugins except the first to
472 update the value of this parameter. For sane plugin APIs,
473 there are no other plugins, so this is a no-op in those
477 Plugins::iterator i = _plugins.begin();
479 /* don't set the first plugin, just all the slaves */
481 if (i != _plugins.end()) {
483 for (; i != _plugins.end(); ++i) {
484 (*i)->set_parameter (which, val);
490 PluginInsert::set_block_size (pframes_t nframes)
493 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
494 if ((*i)->set_block_size (nframes) != 0) {
502 PluginInsert::activate ()
504 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
508 Processor::activate ();
512 PluginInsert::deactivate ()
514 Processor::deactivate ();
516 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
522 PluginInsert::flush ()
524 for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
530 PluginInsert::inplace_silence_unconnected (BufferSet& bufs, const PinMappings& out_map, framecnt_t nframes, framecnt_t offset) const
532 // TODO optimize: store "unconnected" in a fixed set.
533 // it only changes on reconfiguration.
534 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
535 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
537 if (*t == DataType::MIDI && out == 0 && has_midi_bypass ()) {
538 mapped = true; // in-place Midi bypass
540 for (uint32_t pc = 0; pc < get_count() && !mapped; ++pc) {
541 PinMappings::const_iterator i = out_map.find (pc);
542 if (i == out_map.end ()) {
545 const ChanMapping& outmap (i->second);
546 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
548 uint32_t idx = outmap.get (*t, o, &valid);
549 if (valid && idx == out) {
556 bufs.get (*t, out).silence (nframes, offset);
563 PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t offset, bool with_auto, framepos_t now)
565 // TODO: atomically copy maps & _no_inplace
566 PinMappings in_map (_in_map);
567 PinMappings out_map (_out_map);
568 ChanMapping thru_map (_thru_map);
569 if (_mapping_changed) { // ToDo use a counters, increment until match.
570 _no_inplace = check_inplace ();
571 _mapping_changed = false;
574 if (_latency_changed) {
575 /* delaylines are configured with the max possible latency (as reported by the plugin)
576 * so this won't allocate memory (unless the plugin lied about its max latency)
577 * It may still 'click' though, since the fixed delaylines are not de-clicked.
578 * Then again plugin-latency changes are not click-free to begin with.
580 * This is also worst case, there is currently no concept of per-stream latency.
582 * e.g. Two identical latent plugins:
583 * 1st plugin: process left (latent), bypass right.
584 * 2nd plugin: bypass left, process right (latent).
585 * -> currently this yields 2 times latency of the plugin,
587 _latency_changed = false;
588 _delaybuffers.set (ChanCount::max(bufs.count(), _configured_out), plugin_latency ());
591 if (_match.method == Split && !_no_inplace) {
592 // TODO: also use this optimization if one source-buffer
593 // feeds _all_ *connected* inputs.
594 // currently this is *first* buffer to all only --
595 // see PluginInsert::check_inplace
596 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
597 if (_configured_internal.get (*t) == 0) {
601 uint32_t first_idx = in_map[0].get (*t, 0, &valid);
602 assert (valid && first_idx == 0); // check_inplace ensures this
603 /* copy the first stream's buffer contents to the others */
604 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
605 uint32_t idx = in_map[0].get (*t, i, &valid);
608 bufs.get (*t, i).read_from (bufs.get (*t, first_idx), nframes, offset, offset);
612 /* the copy operation produces a linear monotonic input map */
613 in_map[0] = ChanMapping (natural_input_streams ());
616 bufs.set_count(ChanCount::max(bufs.count(), _configured_internal));
617 bufs.set_count(ChanCount::max(bufs.count(), _configured_out));
623 for (Controls::iterator li = controls().begin(); li != controls().end(); ++li, ++n) {
625 boost::shared_ptr<AutomationControl> c
626 = boost::dynamic_pointer_cast<AutomationControl>(li->second);
628 if (c->list() && c->automation_playback()) {
631 const float val = c->list()->rt_safe_eval (now, valid);
634 /* This is the ONLY place where we are
636 * AutomationControl::set_value_unchecked(). We
637 * know that the control is in
638 * automation playback mode, so no
639 * check on writable() is required
640 * (which must be done in AutomationControl::set_value()
643 c->set_value_unchecked(val);
650 /* Calculate if, and how many frames we need to collect for analysis */
651 framecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max -
652 _signal_analysis_collected_nframes);
653 if (nframes < collect_signal_nframes) { // we might not get all frames now
654 collect_signal_nframes = nframes;
657 if (collect_signal_nframes > 0) {
659 //std::cerr << "collect input, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
660 //std::cerr << " streams " << internal_input_streams().n_audio() << std::endl;
661 //std::cerr << "filling buffer with " << collect_signal_nframes << " frames at " << _signal_analysis_collected_nframes << std::endl;
663 _signal_analysis_inputs.set_count(input_streams());
665 for (uint32_t i = 0; i < input_streams().n_audio(); ++i) {
666 _signal_analysis_inputs.get_audio(i).read_from (
668 collect_signal_nframes,
669 _signal_analysis_collected_nframes); // offset is for target buffer
674 if (is_channelstrip ()) {
675 if (_configured_in.n_audio() > 0) {
676 ChanMapping mb_in_map (ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2)));
677 ChanMapping mb_out_map (ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2)));
679 _plugins.front()->connect_and_run (bufs, mb_in_map, mb_out_map, nframes, offset);
681 for (uint32_t out = _configured_in.n_audio (); out < bufs.count().get (DataType::AUDIO); ++out) {
682 bufs.get (DataType::AUDIO, out).silence (nframes, offset);
688 // TODO optimize -- build maps once.
690 BufferSet& inplace_bufs = _session.get_noinplace_buffers();
691 ARDOUR::ChanMapping used_outputs;
693 assert (inplace_bufs.count () >= natural_input_streams () + _configured_out);
695 /* build used-output map */
696 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
697 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
698 for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) {
700 uint32_t out_idx = out_map[pc].get (*t, out, &valid);
702 used_outputs.set (*t, out_idx, 1); // mark as used
707 /* copy thru data to outputs before processing in-place */
708 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
709 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
711 uint32_t in_idx = thru_map.get (*t, out, &valid);
712 uint32_t m = out + natural_input_streams ().get (*t);
714 _delaybuffers.delay (*t, out, inplace_bufs.get (*t, m), bufs.get (*t, in_idx), nframes, offset, offset);
715 used_outputs.set (*t, out, 1); // mark as used
717 used_outputs.get (*t, out, &valid);
719 /* the plugin is expected to write here, but may not :(
720 * (e.g. drumgizmo w/o kit loaded)
722 inplace_bufs.get (*t, m).silence (nframes);
729 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
731 ARDOUR::ChanMapping i_in_map (natural_input_streams());
732 ARDOUR::ChanMapping i_out_map (out_map[pc]);
733 ARDOUR::ChanCount mapped;
735 /* map inputs sequentially */
736 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
737 for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) {
739 uint32_t in_idx = in_map[pc].get (*t, in, &valid);
740 uint32_t m = mapped.get (*t);
742 inplace_bufs.get (*t, m).read_from (bufs.get (*t, in_idx), nframes, offset, offset);
744 inplace_bufs.get (*t, m).silence (nframes, offset);
746 mapped.set (*t, m + 1);
750 /* outputs are mapped to inplace_bufs after the inputs */
751 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
752 i_out_map.offset_to (*t, natural_input_streams ().get (*t));
755 if ((*i)->connect_and_run (inplace_bufs, i_in_map, i_out_map, nframes, offset)) {
760 /* all instances have completed, now copy data that was written
761 * and zero unconnected buffers */
762 ARDOUR::ChanMapping nonzero_out (used_outputs);
763 if (has_midi_bypass ()) {
764 nonzero_out.set (DataType::MIDI, 0, 1); // Midi bypass.
766 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
767 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
769 used_outputs.get (*t, out, &valid);
771 nonzero_out.get (*t, out, &valid);
773 bufs.get (*t, out).silence (nframes, offset);
776 uint32_t m = out + natural_input_streams ().get (*t);
777 bufs.get (*t, out).read_from (inplace_bufs.get (*t, m), nframes, offset, offset);
782 /* in-place processing */
784 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
785 if ((*i)->connect_and_run(bufs, in_map[pc], out_map[pc], nframes, offset)) {
789 // now silence unconnected outputs
790 inplace_silence_unconnected (bufs, _out_map, nframes, offset);
793 if (collect_signal_nframes > 0) {
795 //std::cerr << " output, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
796 //std::cerr << " streams " << internal_output_streams().n_audio() << std::endl;
798 _signal_analysis_outputs.set_count(output_streams());
800 for (uint32_t i = 0; i < output_streams().n_audio(); ++i) {
801 _signal_analysis_outputs.get_audio(i).read_from(
803 collect_signal_nframes,
804 _signal_analysis_collected_nframes); // offset is for target buffer
807 _signal_analysis_collected_nframes += collect_signal_nframes;
808 assert(_signal_analysis_collected_nframes <= _signal_analysis_collect_nframes_max);
810 if (_signal_analysis_collected_nframes == _signal_analysis_collect_nframes_max) {
811 _signal_analysis_collect_nframes_max = 0;
812 _signal_analysis_collected_nframes = 0;
814 AnalysisDataGathered(&_signal_analysis_inputs,
815 &_signal_analysis_outputs);
821 PluginInsert::bypass (BufferSet& bufs, pframes_t nframes)
823 /* bypass the plugin(s) not the whole processor.
824 * -> use mappings just like connect_and_run
827 // TODO: atomically copy maps & _no_inplace
828 ChanMapping in_map (input_map ());
829 ChanMapping out_map (output_map ());
830 if (_mapping_changed) {
831 _no_inplace = check_inplace ();
832 _mapping_changed = false;
835 bufs.set_count(ChanCount::max(bufs.count(), _configured_internal));
836 bufs.set_count(ChanCount::max(bufs.count(), _configured_out));
839 ChanMapping thru_map (_thru_map);
841 BufferSet& inplace_bufs = _session.get_noinplace_buffers();
843 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
844 for (uint32_t in = 0; in < _configured_internal.get (*t); ++in) {
845 inplace_bufs.get (*t, in).read_from (bufs.get (*t, in), nframes, 0, 0);
848 ARDOUR::ChanMapping used_outputs;
850 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
851 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
853 uint32_t in_idx = thru_map.get (*t, out, &valid);
855 bufs.get (*t, out).read_from (inplace_bufs.get (*t, in_idx), nframes, 0, 0);
856 used_outputs.set (*t, out, 1); // mark as used
860 // plugin no-op: assume every plugin has an internal identity map
861 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
862 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
864 uint32_t src_idx = out_map.get_src (*t, out, &valid);
868 uint32_t in_idx = in_map.get (*t, src_idx, &valid);
872 bufs.get (*t, out).read_from (inplace_bufs.get (*t, in_idx), nframes, 0, 0);
873 used_outputs.set (*t, out, 1); // mark as used
876 // now silence all unused outputs
877 if (has_midi_bypass ()) {
878 used_outputs.set (DataType::MIDI, 0, 1); // Midi bypass.
880 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
881 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
883 used_outputs.get (*t, out, &valid);
885 bufs.get (*t, out).silence (nframes, 0);
890 if (_match.method == Split) {
891 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
892 if (_configured_internal.get (*t) == 0) {
895 // copy/feeds _all_ *connected* inputs, copy the first buffer
897 uint32_t first_idx = in_map.get (*t, 0, &valid);
898 assert (valid && first_idx == 0); // check_inplace ensures this
899 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
900 uint32_t idx = in_map.get (*t, i, &valid);
903 bufs.get (*t, i).read_from (bufs.get (*t, first_idx), nframes, 0, 0);
909 // apply output map and/or monotonic but not identity i/o mappings
910 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
911 for (uint32_t out = 0; out < _configured_out.get (*t); ++out) {
913 uint32_t src_idx = out_map.get_src (*t, out, &valid);
915 bufs.get (*t, out).silence (nframes, 0);
918 uint32_t in_idx = in_map.get (*t, src_idx, &valid);
920 bufs.get (*t, out).silence (nframes, 0);
923 if (in_idx != src_idx) {
924 bufs.get (*t, out).read_from (bufs.get (*t, in_idx), nframes, 0, 0);
932 PluginInsert::silence (framecnt_t nframes)
938 _delaybuffers.flush ();
940 ChanMapping in_map (natural_input_streams ());
941 ChanMapping out_map (natural_output_streams ());
942 ChanCount maxbuf = ChanCount::max (natural_input_streams (), natural_output_streams());
944 if (is_channelstrip ()) {
945 if (_configured_in.n_audio() > 0) {
946 _plugins.front()->connect_and_run (_session.get_scratch_buffers (maxbuf, true), in_map, out_map, nframes, 0);
950 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
951 (*i)->connect_and_run (_session.get_scratch_buffers (maxbuf, true), in_map, out_map, nframes, 0);
956 PluginInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool)
960 error << string_compose (_("Force bypassed unconfigured plugin: %1"), name ()) << endmsg;
964 if (_pending_active) {
965 /* run as normal if we are active or moving from inactive to active */
968 // collect sidechain input for complete cycle (!)
969 // TODO we need delaylines here for latency compensation
970 _sidechain->run (bufs, start_frame, end_frame, nframes, true);
973 if (_session.transport_rolling() || _session.bounce_processing()) {
974 automation_run (bufs, start_frame, nframes);
976 connect_and_run (bufs, nframes, 0, false);
980 bypass (bufs, nframes);
981 _delaybuffers.flush ();
984 _active = _pending_active;
986 /* we have no idea whether the plugin generated silence or not, so mark
987 * all buffers appropriately.
992 PluginInsert::automation_run (BufferSet& bufs, framepos_t start, pframes_t nframes)
994 Evoral::ControlEvent next_event (0, 0.0f);
995 framepos_t now = start;
996 framepos_t end = now + nframes;
997 framecnt_t offset = 0;
999 Glib::Threads::Mutex::Lock lm (control_lock(), Glib::Threads::TRY_LOCK);
1002 connect_and_run (bufs, nframes, offset, false);
1006 if (!find_next_event (now, end, next_event) || _plugins.front()->requires_fixed_sized_buffers()) {
1008 /* no events have a time within the relevant range */
1010 connect_and_run (bufs, nframes, offset, true, now);
1016 framecnt_t cnt = min (((framecnt_t) ceil (next_event.when) - now), (framecnt_t) nframes);
1018 connect_and_run (bufs, cnt, offset, true, now);
1024 if (!find_next_event (now, end, next_event)) {
1029 /* cleanup anything that is left to do */
1032 connect_and_run (bufs, nframes, offset, true, now);
1037 PluginInsert::default_parameter_value (const Evoral::Parameter& param)
1039 if (param.type() != PluginAutomation)
1042 if (_plugins.empty()) {
1043 fatal << _("programming error: ") << X_("PluginInsert::default_parameter_value() called with no plugin")
1045 abort(); /*NOTREACHED*/
1048 return _plugins[0]->default_value (param.id());
1053 PluginInsert::can_reset_all_parameters ()
1056 uint32_t params = 0;
1057 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
1059 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
1061 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
1065 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
1071 if (ac->automation_state() & Play) {
1076 return all && (params > 0);
1080 PluginInsert::reset_parameters_to_default ()
1084 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
1086 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
1088 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
1092 const float dflt = _plugins[0]->default_value (cid);
1093 const float curr = _plugins[0]->get_parameter (cid);
1099 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
1104 if (ac->automation_state() & Play) {
1109 ac->set_value (dflt, Controllable::NoGroup);
1114 boost::shared_ptr<Plugin>
1115 PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
1117 boost::shared_ptr<LadspaPlugin> lp;
1118 boost::shared_ptr<LuaProc> lua;
1120 boost::shared_ptr<LV2Plugin> lv2p;
1122 #ifdef WINDOWS_VST_SUPPORT
1123 boost::shared_ptr<WindowsVSTPlugin> vp;
1125 #ifdef LXVST_SUPPORT
1126 boost::shared_ptr<LXVSTPlugin> lxvp;
1128 #ifdef AUDIOUNIT_SUPPORT
1129 boost::shared_ptr<AUPlugin> ap;
1132 if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
1133 return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
1134 } else if ((lua = boost::dynamic_pointer_cast<LuaProc> (other)) != 0) {
1135 return boost::shared_ptr<Plugin> (new LuaProc (*lua));
1137 } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
1138 return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
1140 #ifdef WINDOWS_VST_SUPPORT
1141 } else if ((vp = boost::dynamic_pointer_cast<WindowsVSTPlugin> (other)) != 0) {
1142 return boost::shared_ptr<Plugin> (new WindowsVSTPlugin (*vp));
1144 #ifdef LXVST_SUPPORT
1145 } else if ((lxvp = boost::dynamic_pointer_cast<LXVSTPlugin> (other)) != 0) {
1146 return boost::shared_ptr<Plugin> (new LXVSTPlugin (*lxvp));
1148 #ifdef AUDIOUNIT_SUPPORT
1149 } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
1150 return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
1154 fatal << string_compose (_("programming error: %1"),
1155 X_("unknown plugin type in PluginInsert::plugin_factory"))
1157 abort(); /*NOTREACHED*/
1158 return boost::shared_ptr<Plugin> ((Plugin*) 0);
1162 PluginInsert::set_input_map (uint32_t num, ChanMapping m) {
1163 if (num < _in_map.size()) {
1164 bool changed = _in_map[num] != m;
1166 changed |= sanitize_maps ();
1168 PluginMapChanged (); /* EMIT SIGNAL */
1169 _mapping_changed = true;
1170 _session.set_dirty();
1176 PluginInsert::set_output_map (uint32_t num, ChanMapping m) {
1177 if (num < _out_map.size()) {
1178 bool changed = _out_map[num] != m;
1180 changed |= sanitize_maps ();
1182 PluginMapChanged (); /* EMIT SIGNAL */
1183 _mapping_changed = true;
1184 _session.set_dirty();
1190 PluginInsert::set_thru_map (ChanMapping m) {
1191 bool changed = _thru_map != m;
1193 changed |= sanitize_maps ();
1195 PluginMapChanged (); /* EMIT SIGNAL */
1196 _mapping_changed = true;
1197 _session.set_dirty();
1202 PluginInsert::pre_seed (const ChanCount& in, const ChanCount& out,
1203 const ChanMapping& im, const ChanMapping& om, const ChanMapping& tm)
1205 if (_configured) { return false; }
1206 _configured_in = in;
1207 _configured_out = out;
1211 _maps_from_state = in.n_total () > 0 && out.n_total () > 0;
1216 PluginInsert::input_map () const
1220 for (PinMappings::const_iterator i = _in_map.begin (); i != _in_map.end (); ++i, ++pc) {
1221 ChanMapping m (i->second);
1222 const ChanMapping::Mappings& mp ((*i).second.mappings());
1223 for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
1224 for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
1225 rv.set (tm->first, i->first + pc * natural_input_streams().get(tm->first), i->second);
1233 PluginInsert::output_map () const
1237 for (PinMappings::const_iterator i = _out_map.begin (); i != _out_map.end (); ++i, ++pc) {
1238 ChanMapping m (i->second);
1239 const ChanMapping::Mappings& mp ((*i).second.mappings());
1240 for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
1241 for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
1242 rv.set (tm->first, i->first + pc * natural_output_streams().get(tm->first), i->second);
1246 if (has_midi_bypass ()) {
1247 rv.set (DataType::MIDI, 0, 0);
1254 PluginInsert::has_midi_bypass () const
1256 if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
1257 && natural_output_streams ().n_midi () == 0) {
1264 PluginInsert::has_midi_thru () const
1266 if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
1267 && natural_input_streams ().n_midi () == 0 && natural_output_streams ().n_midi () == 0) {
1275 PluginInsert::is_channelstrip () const {
1276 return _plugins.front()->is_channelstrip();
1281 PluginInsert::check_inplace ()
1283 bool inplace_ok = !_plugins.front()->inplace_broken ();
1285 if (_thru_map.n_total () > 0) {
1286 // TODO once midi-bypass is part of the mapping, ignore it
1290 if (_match.method == Split && inplace_ok) {
1291 assert (get_count() == 1);
1292 assert (_in_map.size () == 1);
1293 if (!_out_map[0].is_monotonic ()) {
1296 if (_configured_internal != _configured_in) {
1297 /* no sidechain -- TODO we could allow this with
1298 * some more logic in PluginInsert::connect_and_run().
1300 * PluginInsert::reset_map() already maps it.
1305 for (DataType::iterator t = DataType::begin(); t != DataType::end() && inplace_ok; ++t) {
1306 if (_configured_internal.get (*t) == 0) {
1310 uint32_t first_idx = _in_map[0].get (*t, 0, &valid);
1311 if (!valid || first_idx != 0) {
1312 // so far only allow to copy the *first* stream's buffer to others
1315 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
1316 uint32_t idx = _in_map[0].get (*t, i, &valid);
1317 if (valid && idx != first_idx) {
1326 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: In Place Split Map\n", name()));
1331 for (uint32_t pc = 0; pc < get_count() && inplace_ok ; ++pc) {
1332 if (!_in_map[pc].is_monotonic ()) {
1335 if (!_out_map[pc].is_monotonic ()) {
1339 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: %2\n", name(), inplace_ok ? "In-Place" : "No Inplace Processing"));
1340 return !inplace_ok; // no-inplace
1344 PluginInsert::sanitize_maps ()
1346 bool changed = false;
1347 /* strip dead wood */
1348 PinMappings new_ins;
1349 PinMappings new_outs;
1350 ChanMapping new_thru;
1352 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1354 ChanMapping new_out;
1355 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1356 for (uint32_t i = 0; i < natural_input_streams().get (*t); ++i) {
1358 uint32_t idx = _in_map[pc].get (*t, i, &valid);
1359 if (valid && idx < _configured_internal.get (*t)) {
1360 new_in.set (*t, i, idx);
1363 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
1365 uint32_t idx = _out_map[pc].get (*t, o, &valid);
1366 if (valid && idx < _configured_out.get (*t)) {
1367 new_out.set (*t, o, idx);
1371 if (_in_map[pc] != new_in || _out_map[pc] != new_out) {
1374 new_ins[pc] = new_in;
1375 new_outs[pc] = new_out;
1378 /* prevent dup output assignments */
1379 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1380 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1381 bool mapped = false;
1382 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1384 uint32_t idx = new_outs[pc].get_src (*t, o, &valid);
1385 if (valid && mapped) {
1386 new_outs[pc].unset (*t, idx);
1394 /* remove excess thru */
1395 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1396 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1398 uint32_t idx = _thru_map.get (*t, o, &valid);
1399 if (valid && idx < _configured_internal.get (*t)) {
1400 new_thru.set (*t, o, idx);
1405 /* prevent out + thru, existing plugin outputs override thru */
1406 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1407 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1408 bool mapped = false;
1410 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1411 new_outs[pc].get_src (*t, o, &mapped);
1412 if (mapped) { break; }
1414 if (!mapped) { continue; }
1415 uint32_t idx = new_thru.get (*t, o, &valid);
1417 new_thru.unset (*t, idx);
1422 if (has_midi_bypass ()) {
1423 // TODO: include midi-bypass in the thru set,
1424 // remove dedicated handling.
1425 new_thru.unset (DataType::MIDI, 0);
1428 if (_in_map != new_ins || _out_map != new_outs || _thru_map != new_thru) {
1432 _out_map = new_outs;
1433 _thru_map = new_thru;
1439 PluginInsert::reset_map (bool emit)
1441 const PinMappings old_in (_in_map);
1442 const PinMappings old_out (_out_map);
1446 _thru_map = ChanMapping ();
1448 /* build input map */
1449 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1450 uint32_t sc = 0; // side-chain round-robin (all instances)
1452 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1453 const uint32_t nis = natural_input_streams ().get(*t);
1454 const uint32_t stride = nis - sidechain_input_pins().get (*t);
1456 /* SC inputs are last in the plugin-insert.. */
1457 const uint32_t sc_start = _configured_in.get (*t);
1458 const uint32_t sc_len = _configured_internal.get (*t) - sc_start;
1459 /* ...but may not be at the end of the plugin ports.
1460 * in case the side-chain is not the last port, shift connections back.
1461 * and connect to side-chain
1464 uint32_t ic = 0; // split inputs
1465 const uint32_t cend = _configured_in.get (*t);
1467 for (uint32_t in = 0; in < nis; ++in) {
1468 const Plugin::IOPortDescription& iod (_plugins[pc]->describe_io_port (*t, true, in));
1469 if (iod.is_sidechain) {
1470 /* connect sidechain sinks to sidechain inputs in round-robin fashion */
1471 if (sc_len > 0) {// side-chain may be hidden
1472 _in_map[pc].set (*t, in, sc_start + sc);
1473 sc = (sc + 1) % sc_len;
1477 if (_match.method == Split) {
1478 if (cend == 0) { continue; }
1479 if (_strict_io && ic + stride * pc >= cend) {
1482 /* connect *no* sidechain sinks in round-robin fashion */
1483 _in_map[pc].set (*t, in, ic + stride * pc);
1484 if (_strict_io && (ic + 1) == cend) {
1487 ic = (ic + 1) % cend;
1489 uint32_t s = in - shift;
1490 if (stride * pc + s < cend) {
1491 _in_map[pc].set (*t, in, s + stride * pc);
1499 /* build output map */
1501 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1502 _out_map[pc] = ChanMapping (ChanCount::min (natural_output_streams(), _configured_out));
1503 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1504 _out_map[pc].offset_to(*t, pc * natural_output_streams().get(*t));
1509 if (old_in == _in_map && old_out == _out_map) {
1513 PluginMapChanged (); /* EMIT SIGNAL */
1514 _mapping_changed = true;
1515 _session.set_dirty();
1521 PluginInsert::configure_io (ChanCount in, ChanCount out)
1523 Match old_match = _match;
1525 ChanCount old_internal;
1529 old_pins = natural_input_streams();
1530 old_in = _configured_in;
1531 old_out = _configured_out;
1532 old_internal = _configured_internal;
1534 _configured_in = in;
1535 _configured_internal = in;
1536 _configured_out = out;
1539 /* TODO hide midi-bypass, and custom outs. Best /fake/ "out" here.
1540 * (currently _sidechain->configure_io always succeeds
1541 * since Processor::configure_io() succeeds)
1543 if (!_sidechain->configure_io (in, out)) {
1544 DEBUG_TRACE (DEBUG::ChanMapping, "Sidechain configuration failed\n");
1547 _configured_internal += _sidechain->input()->n_ports();
1549 // include (static_cast<Route*>owner())->name() ??
1550 _sidechain->input ()-> set_pretty_name (string_compose (_("SC %1"), name ()));
1553 /* get plugin configuration */
1554 _match = private_can_support_io_configuration (in, out);
1556 if (DEBUG_ENABLED(DEBUG::ChanMapping)) {
1558 DEBUG_STR_APPEND(a, string_compose ("%1: ", name()));
1559 DEBUG_STR_APPEND(a, _match);
1560 DEBUG_TRACE (DEBUG::ChanMapping, DEBUG_STR(a).str());
1564 /* set the matching method and number of plugins that we will use to meet this configuration */
1565 if (set_count (_match.plugins) == false) {
1566 PluginIoReConfigure (); /* EMIT SIGNAL */
1567 _configured = false;
1571 /* configure plugins */
1572 switch (_match.method) {
1575 if (_plugins.front()->configure_io (natural_input_streams(), out) == false) {
1576 PluginIoReConfigure (); /* EMIT SIGNAL */
1577 _configured = false;
1583 ChanCount din (_configured_internal);
1584 ChanCount dout (din); // hint
1586 if (_custom_sinks.n_total () > 0) {
1587 din = _custom_sinks;
1590 } else if (_preset_out.n_audio () > 0) {
1591 dout.set (DataType::AUDIO, _preset_out.n_audio ());
1592 } else if (dout.n_midi () > 0 && dout.n_audio () == 0) {
1593 dout.set (DataType::AUDIO, 2);
1595 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1597 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: Delegate lookup : %2 %3\n", name(), din, dout));
1598 bool const r = _plugins.front()->can_support_io_configuration (din, dout, &useins);
1600 if (useins.n_audio() == 0) {
1603 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: Delegate configuration: %2 %3\n", name(), useins, dout));
1605 if (_plugins.front()->configure_io (useins, dout) == false) {
1606 PluginIoReConfigure (); /* EMIT SIGNAL */
1607 _configured = false;
1611 _custom_sinks = din;
1616 if (_plugins.front()->configure_io (in, out) == false) {
1617 PluginIoReConfigure (); /* EMIT SIGNAL */
1618 _configured = false;
1624 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",
1626 _configured ? "Y" : "N",
1627 _maps_from_state ? "Y" : "N",
1628 old_in == in ? "==" : "!=",
1629 old_out == out ? "==" : "!=",
1630 old_pins == natural_input_streams () ? "==" : "!=",
1631 old_match.method == _match.method ? "==" : "!=",
1632 old_match.custom_cfg == _match.custom_cfg ? "==" : "!=",
1633 _in_map.size() == get_count () ? "==" : "!=",
1634 _out_map.size() == get_count () ? "==" : "!="
1637 bool mapping_changed = false;
1638 if (old_in == in && old_out == out
1640 && old_pins == natural_input_streams ()
1641 && old_match.method == _match.method
1642 && old_match.custom_cfg == _match.custom_cfg
1643 && _in_map.size() == _out_map.size()
1644 && _in_map.size() == get_count ()
1646 assert (_maps_from_state == false);
1647 /* If the configuration has not changed, keep the mapping */
1648 mapping_changed = sanitize_maps ();
1649 } else if (_match.custom_cfg && _configured) {
1650 assert (_maps_from_state == false);
1651 /* don't touch the map in manual mode */
1652 mapping_changed = sanitize_maps ();
1655 if (is_channelstrip ()) {
1656 /* fake channel map - for wire display */
1659 _thru_map = ChanMapping ();
1660 _in_map[0] = ChanMapping (ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2)));
1661 _out_map[0] = ChanMapping (ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2)));
1662 /* set "thru" map for in-place forward of audio */
1663 for (uint32_t i = 2; i < _configured_in.n_audio(); ++i) {
1664 _thru_map.set (DataType::AUDIO, i, i);
1666 /* and midi (after implicit 1st channel bypass) */
1667 for (uint32_t i = 1; i < _configured_in.n_midi(); ++i) {
1668 _thru_map.set (DataType::MIDI, i, i);
1672 if (_maps_from_state && old_in == in && old_out == out) {
1673 mapping_changed = true;
1676 /* generate a new mapping */
1677 mapping_changed = reset_map (false);
1679 _maps_from_state = false;
1682 if (mapping_changed) {
1683 PluginMapChanged (); /* EMIT SIGNAL */
1686 if (DEBUG_ENABLED(DEBUG::ChanMapping)) {
1689 DEBUG_STR_APPEND(a, "\n--------<<--------\n");
1690 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1692 DEBUG_STR_APPEND(a, "----><----\n");
1694 DEBUG_STR_APPEND(a, string_compose ("Channel Map for %1 plugin %2\n", name(), pc));
1695 DEBUG_STR_APPEND(a, " * Inputs:\n");
1696 DEBUG_STR_APPEND(a, _in_map[pc]);
1697 DEBUG_STR_APPEND(a, " * Outputs:\n");
1698 DEBUG_STR_APPEND(a, _out_map[pc]);
1700 DEBUG_STR_APPEND(a, " * Thru:\n");
1701 DEBUG_STR_APPEND(a, _thru_map);
1702 DEBUG_STR_APPEND(a, "-------->>--------\n");
1703 DEBUG_TRACE (DEBUG::ChanMapping, DEBUG_STR(a).str());
1708 _no_inplace = check_inplace ();
1709 _mapping_changed = false;
1711 /* only the "noinplace_buffers" thread buffers need to be this large,
1712 * this can be optimized. other buffers are fine with
1713 * ChanCount::max (natural_input_streams (), natural_output_streams())
1714 * and route.cc's max (configured_in, configured_out)
1716 * no-inplace copies "thru" outputs (to emulate in-place) for
1717 * all outputs (to prevent overwrite) into a temporary space
1718 * which also holds input buffers (in case the plugin does process
1719 * in-place and overwrites those).
1721 * this buffers need to be at least as
1722 * natural_input_streams () + possible outputs.
1724 * sidechain inputs add a constraint on the input:
1725 * configured input + sidechain (=_configured_internal)
1727 * NB. this also satisfies
1728 * max (natural_input_streams(), natural_output_streams())
1729 * which is needed for silence runs
1731 _required_buffers = ChanCount::max (_configured_internal,
1732 natural_input_streams () + ChanCount::max (_configured_out, natural_output_streams () * get_count ()));
1734 if (old_in != in || old_out != out || old_internal != _configured_internal
1735 || old_pins != natural_input_streams ()
1736 || (old_match.method != _match.method && (old_match.method == Split || _match.method == Split))
1738 PluginIoReConfigure (); /* EMIT SIGNAL */
1741 _delaybuffers.configure (_configured_out, _plugins.front ()->max_latency ());
1742 _latency_changed = true;
1744 // we don't know the analysis window size, so we must work with the
1745 // current buffer size here. each request for data fills in these
1746 // buffers and the analyser makes sure it gets enough data for the
1748 session().ensure_buffer_set (_signal_analysis_inputs, in);
1749 _signal_analysis_inputs.set_count (in);
1751 session().ensure_buffer_set (_signal_analysis_outputs, out);
1752 _signal_analysis_outputs.set_count (out);
1754 // std::cerr << "set counts to i" << in.n_audio() << "/o" << out.n_audio() << std::endl;
1757 return Processor::configure_io (in, out);
1760 /** Decide whether this PluginInsert can support a given IO configuration.
1761 * To do this, we run through a set of possible solutions in rough order of
1764 * @param in Required input channel count.
1765 * @param out Filled in with the output channel count if we return true.
1766 * @return true if the given IO configuration can be supported.
1769 PluginInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out)
1772 _sidechain->can_support_io_configuration (in, out); // never fails, sets "out"
1774 return private_can_support_io_configuration (in, out).method != Impossible;
1778 PluginInsert::private_can_support_io_configuration (ChanCount const& in, ChanCount& out) const
1780 if (!_custom_cfg && _preset_out.n_audio () > 0) {
1781 // preseed hint (for variable i/o)
1782 out.set (DataType::AUDIO, _preset_out.n_audio ());
1785 Match rv = internal_can_support_io_configuration (in, out);
1787 if (!_custom_cfg && _preset_out.n_audio () > 0) {
1788 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: using output preset: %2\n", name(), _preset_out));
1789 out.set (DataType::AUDIO, _preset_out.n_audio ());
1794 /** A private version of can_support_io_configuration which returns the method
1795 * by which the configuration can be matched, rather than just whether or not
1799 PluginInsert::internal_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
1801 if (_plugins.empty()) {
1806 if (is_channelstrip ()) {
1808 return Match (ExactMatch, 1);
1812 /* if a user specified a custom cfg, so be it. */
1814 PluginInfoPtr info = _plugins.front()->get_info();
1816 if (info->reconfigurable_io()) {
1817 return Match (Delegate, 1, _strict_io, true);
1819 return Match (ExactMatch, get_count(), _strict_io, true);
1823 /* try automatic configuration */
1824 Match m = PluginInsert::automatic_can_support_io_configuration (inx, out);
1826 PluginInfoPtr info = _plugins.front()->get_info();
1827 ChanCount inputs = info->n_inputs;
1828 ChanCount outputs = info->n_outputs;
1830 /* handle case strict-i/o */
1831 if (_strict_io && m.method != Impossible) {
1834 /* special case MIDI instruments */
1835 if (needs_midi_input ()) {
1836 // output = midi-bypass + at most master-out channels.
1837 ChanCount max_out (DataType::AUDIO, 2); // TODO use master-out
1838 max_out.set (DataType::MIDI, out.get(DataType::MIDI));
1839 out = ChanCount::min (out, max_out);
1840 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: special case strict-i/o instrument\n", name()));
1846 if (inx.n_audio () != out.n_audio ()) { // ignore midi bypass
1847 /* replicate processor to match output count (generators and such)
1848 * at least enough to feed every output port. */
1849 uint32_t f = 1; // at least one. e.g. control data filters, no in, no out.
1850 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1851 uint32_t nout = outputs.get (*t);
1852 if (nout == 0 || inx.get(*t) == 0) { continue; }
1853 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nout));
1856 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: special case strict-i/o for generator\n", name()));
1857 return Match (Replicate, f, _strict_io);
1868 if (m.method != Impossible) {
1872 ChanCount ns_inputs = inputs - sidechain_input_pins ();
1874 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: resolving 'Impossible' match...\n", name()));
1876 if (info->reconfigurable_io()) {
1879 if (out.n_midi () > 0 && out.n_audio () == 0) { out.set (DataType::AUDIO, 2); }
1880 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1881 bool const r = _plugins.front()->can_support_io_configuration (inx + sidechain_input_pins (), out, &useins);
1883 // houston, we have a problem.
1884 return Match (Impossible, 0);
1887 if (inx.n_midi () > 0 && out.n_midi () == 0) { out.set (DataType::MIDI, 1); }
1888 return Match (Delegate, 1, _strict_io);
1891 ChanCount midi_bypass;
1892 if (inx.get(DataType::MIDI) == 1 && outputs.get(DataType::MIDI) == 0) {
1893 midi_bypass.set (DataType::MIDI, 1);
1896 // add at least as many plugins so that output count matches input count (w/o sidechain pins)
1898 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1899 uint32_t nin = ns_inputs.get (*t);
1900 uint32_t nout = outputs.get (*t);
1901 if (nin == 0 || inx.get(*t) == 0) { continue; }
1902 // prefer floor() so the count won't overly increase IFF (nin < nout)
1903 f = max (f, (uint32_t) floor (inx.get(*t) / (float)nout));
1905 if (f > 0 && outputs * f >= _configured_out) {
1906 out = outputs * f + midi_bypass;
1907 return Match (Replicate, f, _strict_io);
1910 // add at least as many plugins needed to connect all inputs (w/o sidechain pins)
1912 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1913 uint32_t nin = ns_inputs.get (*t);
1914 if (nin == 0 || inx.get(*t) == 0) { continue; }
1915 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1918 out = outputs * f + midi_bypass;
1919 return Match (Replicate, f, _strict_io);
1922 // add at least as many plugins needed to connect all inputs
1924 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1925 uint32_t nin = inputs.get (*t);
1926 if (nin == 0 || inx.get(*t) == 0) { continue; }
1927 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1929 out = outputs * f + midi_bypass;
1930 return Match (Replicate, f, _strict_io);
1933 /* this is the original Ardour 3/4 behavior, mainly for backwards compatibility */
1935 PluginInsert::automatic_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
1937 if (_plugins.empty()) {
1941 PluginInfoPtr info = _plugins.front()->get_info();
1942 ChanCount in; in += inx;
1943 ChanCount midi_bypass;
1945 if (info->reconfigurable_io()) {
1946 /* Plugin has flexible I/O, so delegate to it
1947 * pre-seed outputs, plugin tries closest match
1950 if (out.n_midi () > 0 && out.n_audio () == 0) { out.set (DataType::AUDIO, 2); }
1951 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1952 bool const r = _plugins.front()->can_support_io_configuration (in + sidechain_input_pins (), out);
1954 return Match (Impossible, 0);
1957 if (in.n_midi () > 0 && out.n_midi () == 0) { out.set (DataType::MIDI, 1); }
1958 return Match (Delegate, 1);
1961 ChanCount inputs = info->n_inputs;
1962 ChanCount outputs = info->n_outputs;
1963 ChanCount ns_inputs = inputs - sidechain_input_pins ();
1965 if (in.get(DataType::MIDI) == 1 && outputs.get(DataType::MIDI) == 0) {
1966 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: bypassing midi-data\n", name()));
1967 midi_bypass.set (DataType::MIDI, 1);
1969 if (in.get(DataType::MIDI) == 1 && inputs.get(DataType::MIDI) == 0) {
1970 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: hiding midi-port from plugin\n", name()));
1971 in.set(DataType::MIDI, 0);
1974 // add internally provided sidechain ports
1975 ChanCount insc = in + sidechain_input_ports ();
1977 bool no_inputs = true;
1978 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1979 if (inputs.get (*t) != 0) {
1986 /* no inputs so we can take any input configuration since we throw it away */
1987 out = outputs + midi_bypass;
1988 return Match (NoInputs, 1);
1991 /* Plugin inputs match requested inputs + side-chain-ports exactly */
1992 if (inputs == insc) {
1993 out = outputs + midi_bypass;
1994 return Match (ExactMatch, 1);
1997 /* Plugin inputs matches without side-chain-pins */
1998 if (ns_inputs == in) {
1999 out = outputs + midi_bypass;
2000 return Match (ExactMatch, 1);
2003 /* We may be able to run more than one copy of the plugin within this insert
2004 to cope with the insert having more inputs than the plugin.
2005 We allow replication only for plugins with either zero or 1 inputs and outputs
2006 for every valid data type.
2010 bool can_replicate = true;
2011 for (DataType::iterator t = DataType::begin(); t != DataType::end() && can_replicate; ++t) {
2013 // ignore side-chains
2014 uint32_t nin = ns_inputs.get (*t);
2016 // No inputs of this type
2017 if (nin == 0 && in.get(*t) == 0) {
2021 if (nin != 1 || outputs.get (*t) != 1) {
2022 can_replicate = false;
2026 // Potential factor not set yet
2028 f = in.get(*t) / nin;
2031 // Factor for this type does not match another type, can not replicate
2032 if (f != (in.get(*t) / nin)) {
2033 can_replicate = false;
2038 if (can_replicate && f > 0) {
2039 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2040 out.set (*t, outputs.get(*t) * f);
2043 return Match (Replicate, f);
2046 /* If the processor has exactly one input of a given type, and
2047 the plugin has more, we can feed the single processor input
2048 to some or all of the plugin inputs. This is rather
2049 special-case-y, but the 1-to-many case is by far the
2050 simplest. How do I split thy 2 processor inputs to 3
2051 plugin inputs? Let me count the ways ...
2054 bool can_split = true;
2055 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2057 bool const can_split_type = (in.get (*t) == 1 && ns_inputs.get (*t) > 1);
2058 bool const nothing_to_do_for_type = (in.get (*t) == 0 && inputs.get (*t) == 0);
2060 if (!can_split_type && !nothing_to_do_for_type) {
2066 out = outputs + midi_bypass;
2067 return Match (Split, 1);
2070 /* If the plugin has more inputs than we want, we can `hide' some of them
2071 by feeding them silence.
2074 bool could_hide = false;
2075 bool cannot_hide = false;
2076 ChanCount hide_channels;
2078 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2079 if (inputs.get(*t) > in.get(*t)) {
2080 /* there is potential to hide, since the plugin has more inputs of type t than the insert */
2081 hide_channels.set (*t, inputs.get(*t) - in.get(*t));
2083 } else if (inputs.get(*t) < in.get(*t)) {
2084 /* we definitely cannot hide, since the plugin has fewer inputs of type t than the insert */
2089 if (could_hide && !cannot_hide) {
2090 out = outputs + midi_bypass;
2091 return Match (Hide, 1, false, false, hide_channels);
2094 return Match (Impossible, 0);
2099 PluginInsert::get_state ()
2101 return state (true);
2105 PluginInsert::state (bool full)
2107 XMLNode& node = Processor::state (full);
2109 node.add_property("type", _plugins[0]->state_node_name());
2110 node.add_property("unique-id", _plugins[0]->unique_id());
2111 node.add_property("count", string_compose("%1", _plugins.size()));
2113 /* remember actual i/o configuration (for later placeholder
2114 * in case the plugin goes missing) */
2115 node.add_child_nocopy (* _configured_in.state (X_("ConfiguredInput")));
2116 node.add_child_nocopy (* _custom_sinks.state (X_("CustomSinks")));
2117 node.add_child_nocopy (* _configured_out.state (X_("ConfiguredOutput")));
2118 node.add_child_nocopy (* _preset_out.state (X_("PresetOutput")));
2120 /* save custom i/o config */
2121 node.add_property("custom", _custom_cfg ? "yes" : "no");
2122 for (uint32_t pc = 0; pc < get_count(); ++pc) {
2124 snprintf (tmp, sizeof(tmp), "InputMap-%d", pc);
2125 node.add_child_nocopy (* _in_map[pc].state (tmp));
2126 snprintf (tmp, sizeof(tmp), "OutputMap-%d", pc);
2127 node.add_child_nocopy (* _out_map[pc].state (tmp));
2129 node.add_child_nocopy (* _thru_map.state ("ThruMap"));
2132 node.add_child_nocopy (_sidechain->state (full));
2135 _plugins[0]->set_insert_id(this->id());
2136 node.add_child_nocopy (_plugins[0]->get_state());
2138 for (Controls::iterator c = controls().begin(); c != controls().end(); ++c) {
2139 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> ((*c).second);
2141 node.add_child_nocopy (ac->get_state());
2149 PluginInsert::set_control_ids (const XMLNode& node, int version)
2151 const XMLNodeList& nlist = node.children();
2152 XMLNodeConstIterator iter;
2153 set<Evoral::Parameter>::const_iterator p;
2155 for (iter = nlist.begin(); iter != nlist.end(); ++iter) {
2156 if ((*iter)->name() == Controllable::xml_node_name) {
2157 XMLProperty const * prop;
2159 uint32_t p = (uint32_t)-1;
2161 if ((prop = (*iter)->property (X_("symbol"))) != 0) {
2162 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugins[0]);
2164 p = lv2plugin->port_index(prop->value().c_str());
2168 if (p == (uint32_t)-1 && (prop = (*iter)->property (X_("parameter"))) != 0) {
2169 p = atoi (prop->value());
2172 if (p != (uint32_t)-1) {
2174 /* this may create the new controllable */
2176 boost::shared_ptr<Evoral::Control> c = control (Evoral::Parameter (PluginAutomation, 0, p));
2178 #ifndef NO_PLUGIN_STATE
2182 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (c);
2184 ac->set_state (**iter, version);
2193 PluginInsert::set_state(const XMLNode& node, int version)
2195 XMLNodeList nlist = node.children();
2196 XMLNodeIterator niter;
2197 XMLPropertyList plist;
2198 XMLProperty const * prop;
2199 ARDOUR::PluginType type;
2201 if ((prop = node.property ("type")) == 0) {
2202 error << _("XML node describing plugin is missing the `type' field") << endmsg;
2206 if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */
2207 type = ARDOUR::LADSPA;
2208 } else if (prop->value() == X_("lv2")) {
2210 } else if (prop->value() == X_("windows-vst")) {
2211 type = ARDOUR::Windows_VST;
2212 } else if (prop->value() == X_("lxvst")) {
2213 type = ARDOUR::LXVST;
2214 } else if (prop->value() == X_("audiounit")) {
2215 type = ARDOUR::AudioUnit;
2216 } else if (prop->value() == X_("luaproc")) {
2219 error << string_compose (_("unknown plugin type %1 in plugin insert state"),
2225 prop = node.property ("unique-id");
2228 #ifdef WINDOWS_VST_SUPPORT
2229 /* older sessions contain VST plugins with only an "id" field.
2232 if (type == ARDOUR::Windows_VST) {
2233 prop = node.property ("id");
2237 #ifdef LXVST_SUPPORT
2238 /*There shouldn't be any older sessions with linuxVST support.. but anyway..*/
2240 if (type == ARDOUR::LXVST) {
2241 prop = node.property ("id");
2247 error << _("Plugin has no unique ID field") << endmsg;
2252 boost::shared_ptr<Plugin> plugin = find_plugin (_session, prop->value(), type);
2254 /* treat linux and windows VST plugins equivalent if they have the same uniqueID
2255 * allow to move sessions windows <> linux */
2256 #ifdef LXVST_SUPPORT
2257 if (plugin == 0 && type == ARDOUR::Windows_VST) {
2258 type = ARDOUR::LXVST;
2259 plugin = find_plugin (_session, prop->value(), type);
2263 #ifdef WINDOWS_VST_SUPPORT
2264 if (plugin == 0 && type == ARDOUR::LXVST) {
2265 type = ARDOUR::Windows_VST;
2266 plugin = find_plugin (_session, prop->value(), type);
2270 if (plugin == 0 && type == ARDOUR::Lua) {
2271 /* unique ID (sha1 of script) was not found,
2272 * load the plugin from the serialized version in the
2273 * session-file instead.
2275 boost::shared_ptr<LuaProc> lp (new LuaProc (_session.engine(), _session, ""));
2276 XMLNode *ls = node.child (lp->state_node_name().c_str());
2278 lp->set_script_from_state (*ls);
2284 error << string_compose(
2285 _("Found a reference to a plugin (\"%1\") that is unknown.\n"
2286 "Perhaps it was removed or moved since it was last used."),
2292 // The name of the PluginInsert comes from the plugin, nothing else
2293 _name = plugin->get_info()->name;
2297 // Processor::set_state() will set this, but too late
2298 // for it to be available when setting up plugin
2299 // state. We can't call Processor::set_state() until
2300 // the plugins themselves are created and added.
2304 if (_plugins.empty()) {
2305 /* if we are adding the first plugin, we will need to set
2306 up automatable controls.
2308 add_plugin (plugin);
2309 create_automatable_parameters ();
2310 set_control_ids (node, version);
2313 if ((prop = node.property ("count")) != 0) {
2314 sscanf (prop->value().c_str(), "%u", &count);
2317 if (_plugins.size() != count) {
2318 for (uint32_t n = 1; n < count; ++n) {
2319 add_plugin (plugin_factory (plugin));
2323 Processor::set_state (node, version);
2325 PBD::ID new_id = this->id();
2326 PBD::ID old_id = this->id();
2328 if ((prop = node.property ("id")) != 0) {
2329 old_id = prop->value ();
2332 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2334 /* find the node with the type-specific node name ("lv2", "ladspa", etc)
2335 and set all plugins to the same state.
2338 if ((*niter)->name() == plugin->state_node_name()) {
2340 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2341 /* Plugin state can include external files which are named after the ID.
2343 * If regenerate_xml_or_string_ids() is set, the ID will already have
2344 * been changed, so we need to use the old ID from the XML to load the
2345 * state and then update the ID.
2347 * When copying a plugin-state, route_ui takes care of of updating the ID,
2348 * but we need to call set_insert_id() to clear the cached plugin-state
2349 * and force a change.
2351 if (!regenerate_xml_or_string_ids ()) {
2352 (*i)->set_insert_id (new_id);
2354 (*i)->set_insert_id (old_id);
2357 (*i)->set_state (**niter, version);
2359 if (regenerate_xml_or_string_ids ()) {
2360 (*i)->set_insert_id (new_id);
2368 if (version < 3000) {
2370 /* Only 2.X sessions need a call to set_parameter_state() - in 3.X and above
2371 this is all handled by Automatable
2374 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2375 if ((*niter)->name() == "Redirect") {
2376 /* XXX do we need to tackle placement? i think not (pd; oct 16 2009) */
2377 Processor::set_state (**niter, version);
2382 set_parameter_state_2X (node, version);
2385 if ((prop = node.property (X_("custom"))) != 0) {
2386 _custom_cfg = string_is_affirmative (prop->value());
2389 uint32_t in_maps = 0;
2390 uint32_t out_maps = 0;
2391 XMLNodeList kids = node.children ();
2392 for (XMLNodeIterator i = kids.begin(); i != kids.end(); ++i) {
2393 if ((*i)->name() == X_("ConfiguredInput")) {
2394 _configured_in = ChanCount(**i);
2396 if ((*i)->name() == X_("CustomSinks")) {
2397 _custom_sinks = ChanCount(**i);
2399 if ((*i)->name() == X_("ConfiguredOutput")) {
2400 _custom_out = ChanCount(**i);
2401 _configured_out = ChanCount(**i);
2403 if ((*i)->name() == X_("PresetOutput")) {
2404 _preset_out = ChanCount(**i);
2406 if (strncmp ((*i)->name ().c_str(), X_("InputMap-"), 9) == 0) {
2407 long pc = atol (&((*i)->name().c_str()[9]));
2408 if (pc >= 0 && pc <= (long) get_count()) {
2409 _in_map[pc] = ChanMapping (**i);
2413 if (strncmp ((*i)->name ().c_str(), X_("OutputMap-"), 10) == 0) {
2414 long pc = atol (&((*i)->name().c_str()[10]));
2415 if (pc >= 0 && pc <= (long) get_count()) {
2416 _out_map[pc] = ChanMapping (**i);
2420 if ((*i)->name () == "ThruMap") {
2421 _thru_map = ChanMapping (**i);
2424 // sidechain is a Processor (IO)
2425 if ((*i)->name () == Processor::state_node_name) {
2429 _sidechain->set_state (**i, version);
2433 if (in_maps == out_maps && out_maps >0 && out_maps == get_count()) {
2434 _maps_from_state = true;
2437 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2441 (*i)->deactivate ();
2445 PluginConfigChanged (); /* EMIT SIGNAL */
2450 PluginInsert::update_id (PBD::ID id)
2453 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2454 (*i)->set_insert_id (id);
2459 PluginInsert::set_state_dir (const std::string& d)
2461 // state() only saves the state of the first plugin
2462 _plugins[0]->set_state_dir (d);
2466 PluginInsert::set_parameter_state_2X (const XMLNode& node, int version)
2468 XMLNodeList nlist = node.children();
2469 XMLNodeIterator niter;
2471 /* look for port automation node */
2473 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2475 if ((*niter)->name() != port_automation_node_name) {
2480 XMLProperty const * cprop;
2481 XMLNodeConstIterator iter;
2486 cnodes = (*niter)->children ("port");
2488 for (iter = cnodes.begin(); iter != cnodes.end(); ++iter){
2492 if ((cprop = child->property("number")) != 0) {
2493 port = cprop->value().c_str();
2495 warning << _("PluginInsert: Auto: no ladspa port number") << endmsg;
2499 sscanf (port, "%" PRIu32, &port_id);
2501 if (port_id >= _plugins[0]->parameter_count()) {
2502 warning << _("PluginInsert: Auto: port id out of range") << endmsg;
2506 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(
2507 control(Evoral::Parameter(PluginAutomation, 0, port_id), true));
2509 if (c && c->alist()) {
2510 if (!child->children().empty()) {
2511 c->alist()->set_state (*child->children().front(), version);
2513 /* In some cases 2.X saves lists with min_yval and max_yval
2514 being FLT_MIN and FLT_MAX respectively. This causes problems
2515 in A3 because these min/max values are used to compute
2516 where GUI control points should be drawn. If we see such
2517 values, `correct' them to the min/max of the appropriate
2521 float min_y = c->alist()->get_min_y ();
2522 float max_y = c->alist()->get_max_y ();
2524 ParameterDescriptor desc;
2525 _plugins.front()->get_parameter_descriptor (port_id, desc);
2527 if (min_y == FLT_MIN) {
2531 if (max_y == FLT_MAX) {
2535 c->alist()->set_yrange (min_y, max_y);
2538 error << string_compose (_("PluginInsert: automatable control %1 not found - ignored"), port_id) << endmsg;
2550 PluginInsert::describe_parameter (Evoral::Parameter param)
2552 if (param.type() == PluginAutomation) {
2553 return _plugins[0]->describe_parameter (param);
2554 } else if (param.type() == PluginPropertyAutomation) {
2555 boost::shared_ptr<AutomationControl> c(automation_control(param));
2556 if (c && !c->desc().label.empty()) {
2557 return c->desc().label;
2560 return Automatable::describe_parameter(param);
2564 PluginInsert::signal_latency() const
2566 if (_user_latency) {
2567 return _user_latency;
2570 return _plugins[0]->signal_latency ();
2574 PluginInsert::type ()
2576 return plugin()->get_info()->type;
2579 PluginInsert::PluginControl::PluginControl (PluginInsert* p,
2580 const Evoral::Parameter& param,
2581 const ParameterDescriptor& desc,
2582 boost::shared_ptr<AutomationList> list)
2583 : AutomationControl (p->session(), param, desc, list, p->describe_parameter(param))
2587 alist()->reset_default (desc.normal);
2589 list->set_interpolation(Evoral::ControlList::Discrete);
2594 set_flags(Controllable::Toggle);
2598 /** @param val `user' value */
2600 PluginInsert::PluginControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override)
2603 _set_value (user_val, group_override);
2607 PluginInsert::PluginControl::set_value_unchecked (double user_val)
2609 /* used only by automation playback */
2610 _set_value (user_val, Controllable::NoGroup);
2614 PluginInsert::PluginControl::_set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override)
2616 /* FIXME: probably should be taking out some lock here.. */
2618 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
2619 (*i)->set_parameter (_list->parameter().id(), user_val);
2622 boost::shared_ptr<Plugin> iasp = _plugin->_impulseAnalysisPlugin.lock();
2624 iasp->set_parameter (_list->parameter().id(), user_val);
2627 AutomationControl::set_value (user_val, group_override);
2631 PluginInsert::PluginControl::catch_up_with_external_value (double user_val)
2633 AutomationControl::set_value (user_val, Controllable::NoGroup);
2637 PluginInsert::PluginControl::get_state ()
2641 XMLNode& node (AutomationControl::get_state());
2642 ss << parameter().id();
2643 node.add_property (X_("parameter"), ss.str());
2645 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugin->_plugins[0]);
2647 node.add_property (X_("symbol"), lv2plugin->port_symbol (parameter().id()));
2654 /** @return `user' val */
2656 PluginInsert::PluginControl::get_value () const
2658 boost::shared_ptr<Plugin> plugin = _plugin->plugin (0);
2664 return plugin->get_parameter (_list->parameter().id());
2667 PluginInsert::PluginPropertyControl::PluginPropertyControl (PluginInsert* p,
2668 const Evoral::Parameter& param,
2669 const ParameterDescriptor& desc,
2670 boost::shared_ptr<AutomationList> list)
2671 : AutomationControl (p->session(), param, desc, list)
2675 alist()->set_yrange (desc.lower, desc.upper);
2676 alist()->reset_default (desc.normal);
2680 set_flags(Controllable::Toggle);
2685 PluginInsert::PluginPropertyControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition /* group_override*/)
2688 set_value_unchecked (user_val);
2693 PluginInsert::PluginPropertyControl::set_value_unchecked (double user_val)
2695 /* Old numeric set_value(), coerce to appropriate datatype if possible.
2696 This is lossy, but better than nothing until Ardour's automation system
2697 can handle various datatypes all the way down. */
2698 const Variant value(_desc.datatype, user_val);
2699 if (value.type() == Variant::NOTHING) {
2700 error << "set_value(double) called for non-numeric property" << endmsg;
2704 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
2705 (*i)->set_property(_list->parameter().id(), value);
2709 AutomationControl::set_value (user_val, Controllable::NoGroup);
2713 PluginInsert::PluginPropertyControl::get_state ()
2717 XMLNode& node (AutomationControl::get_state());
2718 ss << parameter().id();
2719 node.add_property (X_("property"), ss.str());
2720 node.remove_property (X_("value"));
2726 PluginInsert::PluginPropertyControl::get_value () const
2728 return _value.to_double();
2731 boost::shared_ptr<Plugin>
2732 PluginInsert::get_impulse_analysis_plugin()
2734 boost::shared_ptr<Plugin> ret;
2735 if (_impulseAnalysisPlugin.expired()) {
2736 // LV2 in particular uses various _session params
2737 // during init() -- most notably block_size..
2739 ret = plugin_factory(_plugins[0]);
2740 ret->configure_io (internal_input_streams (), internal_output_streams ());
2741 _impulseAnalysisPlugin = ret;
2743 ret = _impulseAnalysisPlugin.lock();
2750 PluginInsert::collect_signal_for_analysis (framecnt_t nframes)
2752 // called from outside the audio thread, so this should be safe
2753 // only do audio as analysis is (currently) only for audio plugins
2754 _signal_analysis_inputs.ensure_buffers (DataType::AUDIO, input_streams().n_audio(), nframes);
2755 _signal_analysis_outputs.ensure_buffers (DataType::AUDIO, output_streams().n_audio(), nframes);
2757 _signal_analysis_collected_nframes = 0;
2758 _signal_analysis_collect_nframes_max = nframes;
2761 /** Add a plugin to our list */
2763 PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
2765 plugin->set_insert_id (this->id());
2767 if (_plugins.empty()) {
2768 /* first (and probably only) plugin instance - connect to relevant signals */
2770 plugin->ParameterChangedExternally.connect_same_thread (*this, boost::bind (&PluginInsert::parameter_changed_externally, this, _1, _2));
2771 plugin->StartTouch.connect_same_thread (*this, boost::bind (&PluginInsert::start_touch, this, _1));
2772 plugin->EndTouch.connect_same_thread (*this, boost::bind (&PluginInsert::end_touch, this, _1));
2773 plugin->LatencyChanged.connect_same_thread (*this, boost::bind (&PluginInsert::latency_changed, this, _1, _2));
2774 _custom_sinks = plugin->get_info()->n_inputs;
2775 // cache sidechain port count
2776 _cached_sidechain_pins.reset ();
2777 const ChanCount& nis (plugin->get_info()->n_inputs);
2778 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2779 for (uint32_t in = 0; in < nis.get (*t); ++in) {
2780 const Plugin::IOPortDescription& iod (plugin->describe_io_port (*t, true, in));
2781 if (iod.is_sidechain) {
2782 _cached_sidechain_pins.set (*t, 1 + _cached_sidechain_pins.n(*t));
2787 #if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
2788 boost::shared_ptr<VSTPlugin> vst = boost::dynamic_pointer_cast<VSTPlugin> (plugin);
2790 vst->set_insert (this, _plugins.size ());
2793 _plugins.push_back (plugin);
2797 PluginInsert::load_preset (ARDOUR::Plugin::PresetRecord pr)
2800 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2801 if (! (*i)->load_preset (pr)) {
2809 PluginInsert::realtime_handle_transport_stopped ()
2811 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2812 (*i)->realtime_handle_transport_stopped ();
2817 PluginInsert::realtime_locate ()
2819 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2820 (*i)->realtime_locate ();
2825 PluginInsert::monitoring_changed ()
2827 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2828 (*i)->monitoring_changed ();
2833 PluginInsert::latency_changed (framecnt_t, framecnt_t)
2835 // this is called in RT context, LatencyChanged is emitted after run()
2836 _latency_changed = true;
2840 PluginInsert::start_touch (uint32_t param_id)
2842 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
2844 ac->start_touch (session().audible_frame());
2849 PluginInsert::end_touch (uint32_t param_id)
2851 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
2853 ac->stop_touch (true, session().audible_frame());
2857 std::ostream& operator<<(std::ostream& o, const ARDOUR::PluginInsert::Match& m)
2860 case PluginInsert::Impossible: o << "Impossible"; break;
2861 case PluginInsert::Delegate: o << "Delegate"; break;
2862 case PluginInsert::NoInputs: o << "NoInputs"; break;
2863 case PluginInsert::ExactMatch: o << "ExactMatch"; break;
2864 case PluginInsert::Replicate: o << "Replicate"; break;
2865 case PluginInsert::Split: o << "Split"; break;
2866 case PluginInsert::Hide: o << "Hide"; break;
2868 o << " cnt: " << m.plugins
2869 << (m.strict_io ? " strict-io" : "")
2870 << (m.custom_cfg ? " custom-cfg" : "");
2871 if (m.method == PluginInsert::Hide) {
2872 o << " hide: " << m.hide;