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 /* this is a bad idea.... we shouldn't do this while active.
110 only a route holding their redirect_lock should be calling this
115 } else if (num > _plugins.size()) {
116 uint32_t diff = num - _plugins.size();
118 for (uint32_t n = 0; n < diff; ++n) {
119 boost::shared_ptr<Plugin> p = plugin_factory (_plugins[0]);
123 XMLNode& state = _plugins[0]->get_state ();
124 p->set_state (state, Stateful::loading_state_version);
131 PluginConfigChanged (); /* EMIT SIGNAL */
133 } else if (num < _plugins.size()) {
134 uint32_t diff = _plugins.size() - num;
135 for (uint32_t n= 0; n < diff; ++n) {
138 PluginConfigChanged (); /* EMIT SIGNAL */
146 PluginInsert::set_outputs (const ChanCount& c)
148 bool changed = (_custom_out != c) && _custom_cfg;
151 PluginConfigChanged (); /* EMIT SIGNAL */
156 PluginInsert::set_custom_cfg (bool b)
158 bool changed = _custom_cfg != b;
161 PluginConfigChanged (); /* EMIT SIGNAL */
166 PluginInsert::set_preset_out (const ChanCount& c)
168 bool changed = _preset_out != c;
170 if (changed && !_custom_cfg) {
171 PluginConfigChanged (); /* EMIT SIGNAL */
177 PluginInsert::add_sidechain (uint32_t n_audio)
179 // caller must hold process lock
183 std::ostringstream n;
185 n << "Sidechain " << Session::next_name_id ();
187 n << "TO BE RESET FROM XML";
189 SideChain *sc = new SideChain (_session, n.str ());
190 _sidechain = boost::shared_ptr<SideChain> (sc);
191 _sidechain->activate ();
192 for (uint32_t n = 0; n < n_audio; ++n) {
193 _sidechain->input()->add_port ("", owner()); // add a port, don't connect.
195 PluginConfigChanged (); /* EMIT SIGNAL */
200 PluginInsert::del_sidechain ()
206 PluginConfigChanged (); /* EMIT SIGNAL */
211 PluginInsert::control_list_automation_state_changed (Evoral::Parameter which, AutoState s)
213 if (which.type() != PluginAutomation)
216 boost::shared_ptr<AutomationControl> c
217 = boost::dynamic_pointer_cast<AutomationControl>(control (which));
220 _plugins[0]->set_parameter (which.id(), c->list()->eval (_session.transport_frame()));
225 PluginInsert::output_streams() const
227 assert (_configured);
228 return _configured_out;
232 PluginInsert::input_streams() const
234 assert (_configured);
235 return _configured_in;
239 PluginInsert::internal_streams() const
241 assert (_configured);
242 return _configured_internal;
246 PluginInsert::internal_output_streams() const
248 assert (!_plugins.empty());
250 PluginInfoPtr info = _plugins.front()->get_info();
252 if (info->reconfigurable_io()) {
253 ChanCount out = _plugins.front()->output_streams ();
254 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, reconfigur(able) output streams = %1\n", out));
257 ChanCount out = info->n_outputs;
258 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, static output streams = %1 for %2 plugins\n", out, _plugins.size()));
259 out.set_audio (out.n_audio() * _plugins.size());
260 out.set_midi (out.n_midi() * _plugins.size());
266 PluginInsert::internal_input_streams() const
268 assert (!_plugins.empty());
272 PluginInfoPtr info = _plugins.front()->get_info();
274 if (info->reconfigurable_io()) {
275 in = _plugins.front()->input_streams();
280 DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, input streams = %1, match using %2\n", in, _match.method));
282 if (_match.method == Split) {
284 /* we are splitting 1 processor input to multiple plugin inputs,
285 so we have a maximum of 1 stream of each type.
287 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
288 if (in.get (*t) > 1) {
294 } else if (_match.method == Hide) {
296 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
297 in.set (*t, in.get (*t) - _match.hide.get (*t));
303 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
304 in.set (*t, in.get (*t) * _plugins.size ());
312 PluginInsert::natural_output_streams() const
315 if (is_channelstrip ()) {
316 return ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2));
319 return _plugins[0]->get_info()->n_outputs;
323 PluginInsert::natural_input_streams() const
326 if (is_channelstrip ()) {
327 return ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2));
330 return _plugins[0]->get_info()->n_inputs;
334 PluginInsert::sidechain_input_pins() const
336 return _cached_sidechain_pins;
340 PluginInsert::has_no_inputs() const
342 return _plugins[0]->get_info()->n_inputs == ChanCount::ZERO;
346 PluginInsert::has_no_audio_inputs() const
348 return _plugins[0]->get_info()->n_inputs.n_audio() == 0;
352 PluginInsert::plugin_latency () const {
353 return _plugins.front()->signal_latency ();
357 PluginInsert::needs_midi_input() const
359 PluginInfoPtr pip = _plugins[0]->get_info();
360 if (pip->needs_midi_input ()) {
363 return pip->n_inputs.n_midi() != 0 && pip->n_outputs.n_audio() != 0;
367 PluginInsert::create_automatable_parameters ()
369 assert (!_plugins.empty());
371 set<Evoral::Parameter> a = _plugins.front()->automatable ();
373 for (set<Evoral::Parameter>::iterator i = a.begin(); i != a.end(); ++i) {
374 if (i->type() == PluginAutomation) {
376 Evoral::Parameter param(*i);
378 ParameterDescriptor desc;
379 _plugins.front()->get_parameter_descriptor(i->id(), desc);
381 can_automate (param);
382 boost::shared_ptr<AutomationList> list(new AutomationList(param, desc));
383 boost::shared_ptr<AutomationControl> c (new PluginControl(this, param, desc, list));
385 _plugins.front()->set_automation_control (i->id(), c);
386 } else if (i->type() == PluginPropertyAutomation) {
387 Evoral::Parameter param(*i);
388 const ParameterDescriptor& desc = _plugins.front()->get_property_descriptor(param.id());
389 if (desc.datatype != Variant::NOTHING) {
390 boost::shared_ptr<AutomationList> list;
391 if (Variant::type_is_numeric(desc.datatype)) {
392 list = boost::shared_ptr<AutomationList>(new AutomationList(param, desc));
394 add_control (boost::shared_ptr<AutomationControl> (new PluginPropertyControl(this, param, desc, list)));
399 /** Called when something outside of this host has modified a plugin
400 * parameter. Responsible for propagating the change to two places:
402 * 1) anything listening to the Control itself
403 * 2) any replicated plugins that make up this PluginInsert.
405 * The PluginInsert is connected to the ParameterChangedExternally signal for
406 * the first (primary) plugin, and here broadcasts that change to any others.
408 * XXX We should probably drop this whole replication idea (Paul, October 2015)
409 * since it isn't used by sensible plugin APIs (AU, LV2).
412 PluginInsert::parameter_changed_externally (uint32_t which, float val)
414 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, which));
416 /* First propagation: alter the underlying value of the control,
417 * without telling the plugin(s) that own/use it to set it.
424 boost::shared_ptr<PluginControl> pc = boost::dynamic_pointer_cast<PluginControl> (ac);
427 pc->catch_up_with_external_value (val);
430 /* Second propagation: tell all plugins except the first to
431 update the value of this parameter. For sane plugin APIs,
432 there are no other plugins, so this is a no-op in those
436 Plugins::iterator i = _plugins.begin();
438 /* don't set the first plugin, just all the slaves */
440 if (i != _plugins.end()) {
442 for (; i != _plugins.end(); ++i) {
443 (*i)->set_parameter (which, val);
449 PluginInsert::set_block_size (pframes_t nframes)
452 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
453 if ((*i)->set_block_size (nframes) != 0) {
461 PluginInsert::activate ()
463 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
467 Processor::activate ();
471 PluginInsert::deactivate ()
473 Processor::deactivate ();
475 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
481 PluginInsert::flush ()
483 for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
489 PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t offset, bool with_auto, framepos_t now)
491 // TODO: atomically copy maps & _no_inplace
492 PinMappings in_map (_in_map);
493 PinMappings out_map (_out_map);
494 ChanMapping thru_map (_thru_map);
495 if (_mapping_changed) { // ToDo use a counters, increment until match.
496 _no_inplace = check_inplace ();
497 _mapping_changed = false;
500 if (_latency_changed) {
501 /* delaylines are configured with the max possible latency (as reported by the plugin)
502 * so this won't allocate memory (unless the plugin lied about its max latency)
503 * It may still 'click' though, since the fixed delaylines are not de-clicked.
504 * Then again plugin-latency changes are not click-free to begin with.
506 * This is also worst case, there is currently no concept of per-stream latency.
508 * e.g. Two identical latent plugins:
509 * 1st plugin: process left (latent), bypass right.
510 * 2nd plugin: bypass left, process right (latent).
511 * -> currently this yields 2 times latency of the plugin,
513 _latency_changed = false;
514 _delaybuffers.set (ChanCount::max(bufs.count(), _configured_out), plugin_latency ());
517 if (_match.method == Split && !_no_inplace) {
518 // TODO: also use this optimization if one source-buffer
519 // feeds _all_ *connected* inputs.
520 // currently this is *first* buffer to all only --
521 // see PluginInsert::check_inplace
522 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
523 if (_configured_internal.get (*t) == 0) {
527 uint32_t first_idx = in_map[0].get (*t, 0, &valid);
528 assert (valid && first_idx == 0); // check_inplace ensures this
529 /* copy the first stream's buffer contents to the others */
530 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
531 uint32_t idx = in_map[0].get (*t, i, &valid);
534 bufs.get (*t, i).read_from (bufs.get (*t, first_idx), nframes, offset, offset);
538 /* the copy operation produces a linear monotonic input map */
539 in_map[0] = ChanMapping (natural_input_streams ());
542 bufs.set_count(ChanCount::max(bufs.count(), _configured_internal));
543 bufs.set_count(ChanCount::max(bufs.count(), _configured_out));
549 for (Controls::iterator li = controls().begin(); li != controls().end(); ++li, ++n) {
551 boost::shared_ptr<AutomationControl> c
552 = boost::dynamic_pointer_cast<AutomationControl>(li->second);
554 if (c->list() && c->automation_playback()) {
557 const float val = c->list()->rt_safe_eval (now, valid);
560 /* This is the ONLY place where we are
562 * AutomationControl::set_value_unchecked(). We
563 * know that the control is in
564 * automation playback mode, so no
565 * check on writable() is required
566 * (which must be done in AutomationControl::set_value()
569 c->set_value_unchecked(val);
576 /* Calculate if, and how many frames we need to collect for analysis */
577 framecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max -
578 _signal_analysis_collected_nframes);
579 if (nframes < collect_signal_nframes) { // we might not get all frames now
580 collect_signal_nframes = nframes;
583 if (collect_signal_nframes > 0) {
585 //std::cerr << "collect input, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
586 //std::cerr << " streams " << internal_input_streams().n_audio() << std::endl;
587 //std::cerr << "filling buffer with " << collect_signal_nframes << " frames at " << _signal_analysis_collected_nframes << std::endl;
589 _signal_analysis_inputs.set_count(internal_input_streams());
591 for (uint32_t i = 0; i < internal_input_streams().n_audio(); ++i) {
592 _signal_analysis_inputs.get_audio(i).read_from(
594 collect_signal_nframes,
595 _signal_analysis_collected_nframes); // offset is for target buffer
600 if (is_channelstrip ()) {
601 if (_configured_in.n_audio() > 0) {
602 ChanMapping mb_in_map (ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2)));
603 ChanMapping mb_out_map (ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2)));
605 _plugins.front()->connect_and_run (bufs, mb_in_map, mb_out_map, nframes, offset);
607 for (uint32_t out = _configured_in.n_audio (); out < bufs.count().get (DataType::AUDIO); ++out) {
608 bufs.get (DataType::AUDIO, out).silence (nframes, offset);
614 // TODO optimize -- build maps once.
616 BufferSet& inplace_bufs = _session.get_noinplace_buffers();
617 ARDOUR::ChanMapping used_outputs;
619 assert (inplace_bufs.count () >= natural_input_streams () + _configured_out);
621 /* build used-output map */
622 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
623 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
624 for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) {
626 uint32_t out_idx = out_map[pc].get (*t, out, &valid);
628 used_outputs.set (*t, out_idx, 1); // mark as used
633 /* copy thru data to outputs before processing in-place */
634 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
635 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
637 uint32_t in_idx = thru_map.get (*t, out, &valid);
638 uint32_t m = out + natural_input_streams ().get (*t);
640 _delaybuffers.delay (*t, out, inplace_bufs.get (*t, m), bufs.get (*t, in_idx), nframes, offset, offset);
641 used_outputs.set (*t, out, 1); // mark as used
643 used_outputs.get (*t, out, &valid);
645 /* the plugin is expected to write here, but may not :(
646 * (e.g. drumgizmo w/o kit loaded)
648 inplace_bufs.get (*t, m).silence (nframes);
655 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
657 ARDOUR::ChanMapping i_in_map (natural_input_streams());
658 ARDOUR::ChanMapping i_out_map (out_map[pc]);
659 ARDOUR::ChanCount mapped;
661 /* map inputs sequentially */
662 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
663 for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) {
665 uint32_t in_idx = in_map[pc].get (*t, in, &valid);
666 uint32_t m = mapped.get (*t);
668 inplace_bufs.get (*t, m).read_from (bufs.get (*t, in_idx), nframes, offset, offset);
670 inplace_bufs.get (*t, m).silence (nframes, offset);
672 mapped.set (*t, m + 1);
676 /* outputs are mapped to inplace_bufs after the inputs */
677 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
678 i_out_map.offset_to (*t, natural_input_streams ().get (*t));
681 if ((*i)->connect_and_run (inplace_bufs, i_in_map, i_out_map, nframes, offset)) {
686 /* all instances have completed, now copy data that was written
687 * and zero unconnected buffers */
688 ARDOUR::ChanMapping nonzero_out (used_outputs);
689 if (has_midi_bypass ()) {
690 nonzero_out.set (DataType::MIDI, 0, 1); // Midi bypass.
692 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
693 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
695 used_outputs.get (*t, out, &valid);
697 nonzero_out.get (*t, out, &valid);
699 bufs.get (*t, out).silence (nframes, offset);
702 uint32_t m = out + natural_input_streams ().get (*t);
703 bufs.get (*t, out).read_from (inplace_bufs.get (*t, m), nframes, offset, offset);
708 /* in-place processing */
710 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
711 if ((*i)->connect_and_run(bufs, in_map[pc], out_map[pc], nframes, offset)) {
716 // TODO optimize: store "unconnected" in a fixed set.
717 // it only changes on reconfiguration.
718 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
719 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
721 if (*t == DataType::MIDI && out == 0 && has_midi_bypass ()) {
722 mapped = true; // in-place Midi bypass
724 for (uint32_t pc = 0; pc < get_count() && !mapped; ++pc) {
725 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
727 uint32_t idx = out_map[pc].get (*t, o, &valid);
728 if (valid && idx == out) {
735 bufs.get (*t, out).silence (nframes, offset);
741 if (collect_signal_nframes > 0) {
743 //std::cerr << " output, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
744 //std::cerr << " streams " << internal_output_streams().n_audio() << std::endl;
746 _signal_analysis_outputs.set_count(internal_output_streams());
748 for (uint32_t i = 0; i < internal_output_streams().n_audio(); ++i) {
749 _signal_analysis_outputs.get_audio(i).read_from(
751 collect_signal_nframes,
752 _signal_analysis_collected_nframes); // offset is for target buffer
755 _signal_analysis_collected_nframes += collect_signal_nframes;
756 assert(_signal_analysis_collected_nframes <= _signal_analysis_collect_nframes_max);
758 if (_signal_analysis_collected_nframes == _signal_analysis_collect_nframes_max) {
759 _signal_analysis_collect_nframes_max = 0;
760 _signal_analysis_collected_nframes = 0;
762 AnalysisDataGathered(&_signal_analysis_inputs,
763 &_signal_analysis_outputs);
769 PluginInsert::silence (framecnt_t nframes)
775 _delaybuffers.flush ();
777 ChanMapping in_map (natural_input_streams ());
778 ChanMapping out_map (natural_output_streams ());
779 ChanCount maxbuf = ChanCount::max (natural_input_streams (), natural_output_streams());
781 if (is_channelstrip ()) {
782 if (_configured_in.n_audio() > 0) {
783 _plugins.front()->connect_and_run (_session.get_scratch_buffers (maxbuf, true), in_map, out_map, nframes, 0);
787 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
788 (*i)->connect_and_run (_session.get_scratch_buffers (maxbuf, true), in_map, out_map, nframes, 0);
793 PluginInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool)
795 if (_pending_active) {
796 /* run as normal if we are active or moving from inactive to active */
799 // collect sidechain input for complete cycle (!)
800 // TODO we need delaylines here for latency compensation
801 _sidechain->run (bufs, start_frame, end_frame, nframes, true);
804 if (_session.transport_rolling() || _session.bounce_processing()) {
805 automation_run (bufs, start_frame, nframes);
807 connect_and_run (bufs, nframes, 0, false);
811 // TODO use mapping in bypassed mode ?!
812 // -> do we bypass the processor or the plugin
814 // TODO include sidechain??
816 uint32_t in = input_streams ().n_audio ();
817 uint32_t out = output_streams().n_audio ();
819 if (has_no_audio_inputs() || in == 0) {
821 /* silence all (audio) outputs. Should really declick
822 * at the transitions of "active"
825 for (uint32_t n = 0; n < out; ++n) {
826 bufs.get_audio (n).silence (nframes);
829 } else if (out > in) {
831 /* not active, but something has make up for any channel count increase
832 * for now , simply replicate last buffer
834 for (uint32_t n = in; n < out; ++n) {
835 bufs.get_audio(n).read_from(bufs.get_audio(in - 1), nframes);
839 bufs.count().set_audio (out);
842 _active = _pending_active;
844 /* we have no idea whether the plugin generated silence or not, so mark
845 * all buffers appropriately.
850 PluginInsert::automation_run (BufferSet& bufs, framepos_t start, pframes_t nframes)
852 Evoral::ControlEvent next_event (0, 0.0f);
853 framepos_t now = start;
854 framepos_t end = now + nframes;
855 framecnt_t offset = 0;
857 Glib::Threads::Mutex::Lock lm (control_lock(), Glib::Threads::TRY_LOCK);
860 connect_and_run (bufs, nframes, offset, false);
864 if (!find_next_event (now, end, next_event) || _plugins.front()->requires_fixed_sized_buffers()) {
866 /* no events have a time within the relevant range */
868 connect_and_run (bufs, nframes, offset, true, now);
874 framecnt_t cnt = min (((framecnt_t) ceil (next_event.when) - now), (framecnt_t) nframes);
876 connect_and_run (bufs, cnt, offset, true, now);
882 if (!find_next_event (now, end, next_event)) {
887 /* cleanup anything that is left to do */
890 connect_and_run (bufs, nframes, offset, true, now);
895 PluginInsert::default_parameter_value (const Evoral::Parameter& param)
897 if (param.type() != PluginAutomation)
900 if (_plugins.empty()) {
901 fatal << _("programming error: ") << X_("PluginInsert::default_parameter_value() called with no plugin")
903 abort(); /*NOTREACHED*/
906 return _plugins[0]->default_value (param.id());
911 PluginInsert::can_reset_all_parameters ()
915 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
917 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
919 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
923 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
929 if (ac->automation_state() & Play) {
934 return all && (params > 0);
938 PluginInsert::reset_parameters_to_default ()
942 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
944 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
946 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
950 const float dflt = _plugins[0]->default_value (cid);
951 const float curr = _plugins[0]->get_parameter (cid);
957 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
962 if (ac->automation_state() & Play) {
967 ac->set_value (dflt, Controllable::NoGroup);
972 boost::shared_ptr<Plugin>
973 PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
975 boost::shared_ptr<LadspaPlugin> lp;
976 boost::shared_ptr<LuaProc> lua;
978 boost::shared_ptr<LV2Plugin> lv2p;
980 #ifdef WINDOWS_VST_SUPPORT
981 boost::shared_ptr<WindowsVSTPlugin> vp;
984 boost::shared_ptr<LXVSTPlugin> lxvp;
986 #ifdef AUDIOUNIT_SUPPORT
987 boost::shared_ptr<AUPlugin> ap;
990 if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
991 return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
992 } else if ((lua = boost::dynamic_pointer_cast<LuaProc> (other)) != 0) {
993 return boost::shared_ptr<Plugin> (new LuaProc (*lua));
995 } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
996 return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
998 #ifdef WINDOWS_VST_SUPPORT
999 } else if ((vp = boost::dynamic_pointer_cast<WindowsVSTPlugin> (other)) != 0) {
1000 return boost::shared_ptr<Plugin> (new WindowsVSTPlugin (*vp));
1002 #ifdef LXVST_SUPPORT
1003 } else if ((lxvp = boost::dynamic_pointer_cast<LXVSTPlugin> (other)) != 0) {
1004 return boost::shared_ptr<Plugin> (new LXVSTPlugin (*lxvp));
1006 #ifdef AUDIOUNIT_SUPPORT
1007 } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
1008 return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
1012 fatal << string_compose (_("programming error: %1"),
1013 X_("unknown plugin type in PluginInsert::plugin_factory"))
1015 abort(); /*NOTREACHED*/
1016 return boost::shared_ptr<Plugin> ((Plugin*) 0);
1020 PluginInsert::set_input_map (uint32_t num, ChanMapping m) {
1021 if (num < _in_map.size()) {
1022 bool changed = _in_map[num] != m;
1024 changed |= sanitize_maps ();
1026 PluginMapChanged (); /* EMIT SIGNAL */
1027 _mapping_changed = true;
1028 _session.set_dirty();
1034 PluginInsert::set_output_map (uint32_t num, ChanMapping m) {
1035 if (num < _out_map.size()) {
1036 bool changed = _out_map[num] != m;
1038 changed |= sanitize_maps ();
1040 PluginMapChanged (); /* EMIT SIGNAL */
1041 _mapping_changed = true;
1042 _session.set_dirty();
1048 PluginInsert::set_thru_map (ChanMapping m) {
1049 bool changed = _thru_map != m;
1051 changed |= sanitize_maps ();
1053 PluginMapChanged (); /* EMIT SIGNAL */
1054 _mapping_changed = true;
1055 _session.set_dirty();
1060 PluginInsert::input_map () const
1064 for (PinMappings::const_iterator i = _in_map.begin (); i != _in_map.end (); ++i, ++pc) {
1065 ChanMapping m (i->second);
1066 const ChanMapping::Mappings& mp ((*i).second.mappings());
1067 for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
1068 for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
1069 rv.set (tm->first, i->first + pc * natural_input_streams().get(tm->first), i->second);
1077 PluginInsert::output_map () const
1081 for (PinMappings::const_iterator i = _out_map.begin (); i != _out_map.end (); ++i, ++pc) {
1082 ChanMapping m (i->second);
1083 const ChanMapping::Mappings& mp ((*i).second.mappings());
1084 for (ChanMapping::Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
1085 for (ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
1086 rv.set (tm->first, i->first + pc * natural_output_streams().get(tm->first), i->second);
1090 if (has_midi_bypass ()) {
1091 rv.set (DataType::MIDI, 0, 0);
1098 PluginInsert::has_midi_bypass () const
1100 if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
1101 && natural_output_streams ().n_midi () == 0) {
1108 PluginInsert::has_midi_thru () const
1110 if (_configured_in.n_midi () == 1 && _configured_out.n_midi () == 1
1111 && natural_input_streams ().n_midi () == 0 && natural_output_streams ().n_midi () == 0) {
1119 PluginInsert::is_channelstrip () const {
1120 return _plugins.front()->is_channelstrip();
1125 PluginInsert::check_inplace ()
1127 bool inplace_ok = !_plugins.front()->inplace_broken ();
1129 if (_thru_map.n_total () > 0) {
1130 // TODO once midi-bypass is part of the mapping, ignore it
1134 if (_match.method == Split && inplace_ok) {
1135 assert (get_count() == 1);
1136 assert (_in_map.size () == 1);
1137 if (!_out_map[0].is_monotonic ()) {
1140 if (_configured_internal != _configured_in) {
1141 /* no sidechain -- TODO we could allow this with
1142 * some more logic in PluginInsert::connect_and_run().
1144 * PluginInsert::reset_map() already maps it.
1149 for (DataType::iterator t = DataType::begin(); t != DataType::end() && inplace_ok; ++t) {
1150 if (_configured_internal.get (*t) == 0) {
1154 uint32_t first_idx = _in_map[0].get (*t, 0, &valid);
1155 if (!valid || first_idx != 0) {
1156 // so far only allow to copy the *first* stream's buffer to others
1159 for (uint32_t i = 1; i < natural_input_streams ().get (*t); ++i) {
1160 uint32_t idx = _in_map[0].get (*t, i, &valid);
1161 if (valid && idx != first_idx) {
1170 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: In Place Split Map\n", name()));
1175 for (uint32_t pc = 0; pc < get_count() && inplace_ok ; ++pc) {
1176 if (!_in_map[pc].is_monotonic ()) {
1179 if (!_out_map[pc].is_monotonic ()) {
1183 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("%1: %2\n", name(), inplace_ok ? "In-Place" : "No Inplace Processing"));
1184 return !inplace_ok; // no-inplace
1188 PluginInsert::sanitize_maps ()
1190 bool changed = false;
1191 /* strip dead wood */
1192 PinMappings new_ins;
1193 PinMappings new_outs;
1194 ChanMapping new_thru;
1196 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1198 ChanMapping new_out;
1199 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1200 for (uint32_t i = 0; i < natural_input_streams().get (*t); ++i) {
1202 uint32_t idx = _in_map[pc].get (*t, i, &valid);
1203 if (valid && idx < _configured_internal.get (*t)) {
1204 new_in.set (*t, i, idx);
1207 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
1209 uint32_t idx = _out_map[pc].get (*t, o, &valid);
1210 if (valid && idx < _configured_out.get (*t)) {
1211 new_out.set (*t, o, idx);
1215 if (_in_map[pc] != new_in || _out_map[pc] != new_out) {
1218 new_ins[pc] = new_in;
1219 new_outs[pc] = new_out;
1222 /* prevent dup output assignments */
1223 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1224 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1225 bool mapped = false;
1226 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1228 uint32_t idx = new_outs[pc].get_src (*t, o, &valid);
1229 if (valid && mapped) {
1230 new_outs[pc].unset (*t, idx);
1238 /* remove excess thru */
1239 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1240 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1242 uint32_t idx = _thru_map.get (*t, o, &valid);
1243 if (valid && idx < _configured_internal.get (*t)) {
1244 new_thru.set (*t, o, idx);
1249 /* prevent out + thru, existing plugin outputs override thru */
1250 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1251 for (uint32_t o = 0; o < _configured_out.get (*t); ++o) {
1252 bool mapped = false;
1254 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1255 new_outs[pc].get_src (*t, o, &mapped);
1256 if (mapped) { break; }
1258 if (!mapped) { continue; }
1259 uint32_t idx = new_thru.get (*t, o, &valid);
1261 new_thru.unset (*t, idx);
1266 if (has_midi_bypass ()) {
1267 // TODO: include midi-bypass in the thru set,
1268 // remove dedicated handling.
1269 new_thru.unset (DataType::MIDI, 0);
1272 if (_in_map != new_ins || _out_map != new_outs || _thru_map != new_thru) {
1276 _out_map = new_outs;
1277 _thru_map = new_thru;
1283 PluginInsert::reset_map (bool emit)
1285 const PinMappings old_in (_in_map);
1286 const PinMappings old_out (_out_map);
1290 _thru_map = ChanMapping ();
1292 /* build input map */
1293 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1294 uint32_t sc = 0; // side-chain round-robin (all instances)
1296 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1297 const uint32_t nis = natural_input_streams ().get(*t);
1298 const uint32_t stride = nis - sidechain_input_pins().get (*t);
1300 /* SC inputs are last in the plugin-insert.. */
1301 const uint32_t sc_start = _configured_in.get (*t);
1302 const uint32_t sc_len = _configured_internal.get (*t) - sc_start;
1303 /* ...but may not be at the end of the plugin ports.
1304 * in case the side-chain is not the last port, shift connections back.
1305 * and connect to side-chain
1308 uint32_t ic = 0; // split inputs
1309 const uint32_t cend = _configured_in.get (*t);
1311 for (uint32_t in = 0; in < nis; ++in) {
1312 const Plugin::IOPortDescription& iod (_plugins[pc]->describe_io_port (*t, true, in));
1313 if (iod.is_sidechain) {
1314 /* connect sidechain sinks to sidechain inputs in round-robin fashion */
1315 if (sc_len > 0) {// side-chain may be hidden
1316 _in_map[pc].set (*t, in, sc_start + sc);
1317 sc = (sc + 1) % sc_len;
1321 if (_match.method == Split) {
1322 if (cend == 0) { continue; }
1323 if (_strict_io && ic + stride * pc >= cend) {
1326 /* connect *no* sidechain sinks in round-robin fashion */
1327 _in_map[pc].set (*t, in, ic + stride * pc);
1328 if (_strict_io && (ic + 1) == cend) {
1331 ic = (ic + 1) % cend;
1333 uint32_t s = in - shift;
1334 if (stride * pc + s < cend) {
1335 _in_map[pc].set (*t, in, s + stride * pc);
1343 /* build output map */
1345 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1346 _out_map[pc] = ChanMapping (ChanCount::min (natural_output_streams(), _configured_out));
1347 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1348 _out_map[pc].offset_to(*t, pc * natural_output_streams().get(*t));
1353 if (old_in == _in_map && old_out == _out_map) {
1357 PluginMapChanged (); /* EMIT SIGNAL */
1358 _mapping_changed = true;
1359 _session.set_dirty();
1365 PluginInsert::configure_io (ChanCount in, ChanCount out)
1367 Match old_match = _match;
1369 ChanCount old_internal;
1373 old_in = _configured_in;
1374 old_internal = _configured_internal;
1375 old_out = _configured_out;
1378 _configured_in = in;
1379 _configured_internal = in;
1380 _configured_out = out;
1383 /* TODO hide midi-bypass, and custom outs. Best /fake/ "out" here.
1384 * (currently _sidechain->configure_io always succeeds
1385 * since Processor::configure_io() succeeds)
1387 if (!_sidechain->configure_io (in, out)) {
1388 DEBUG_TRACE (DEBUG::ChanMapping, "Sidechain configuration failed\n");
1391 _configured_internal += _sidechain->input()->n_ports();
1393 // include (static_cast<Route*>owner())->name() ??
1394 _sidechain->input ()-> set_pretty_name (string_compose (_("SC %1"), name ()));
1397 /* get plugin configuration */
1398 _match = private_can_support_io_configuration (in, out);
1400 if (DEBUG_ENABLED(DEBUG::ChanMapping)) {
1402 DEBUG_STR_APPEND(a, string_compose ("Match '%1': ", name()));
1403 DEBUG_STR_APPEND(a, _match);
1404 DEBUG_TRACE (DEBUG::ChanMapping, DEBUG_STR(a).str());
1408 /* set the matching method and number of plugins that we will use to meet this configuration */
1409 if (set_count (_match.plugins) == false) {
1410 PluginIoReConfigure (); /* EMIT SIGNAL */
1411 _configured = false;
1415 /* configure plugins */
1416 switch (_match.method) {
1419 if (_plugins.front()->configure_io (natural_input_streams(), out) == false) {
1420 PluginIoReConfigure (); /* EMIT SIGNAL */
1421 _configured = false;
1427 ChanCount dout (in); // hint
1430 } else if (_preset_out.n_audio () > 0) {
1431 dout.set (DataType::AUDIO, _preset_out.n_audio ());
1432 } else if (dout.n_midi () > 0 && dout.n_audio () == 0) {
1433 dout.set (DataType::AUDIO, 2);
1435 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1437 bool const r = _plugins.front()->can_support_io_configuration (in, dout, &useins);
1439 if (useins.n_audio() == 0) {
1442 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("Delegate configuration: %1 %2 %3\n", name(), useins, dout));
1444 if (_plugins.front()->configure_io (useins, dout) == false) {
1445 PluginIoReConfigure (); /* EMIT SIGNAL */
1446 _configured = false;
1452 if (_plugins.front()->configure_io (in, out) == false) {
1453 PluginIoReConfigure (); /* EMIT SIGNAL */
1454 _configured = false;
1460 bool mapping_changed = false;
1461 if (old_in == in && old_out == out
1463 && old_match.method == _match.method
1464 && _in_map.size() == _out_map.size()
1465 && _in_map.size() == get_count ()
1467 assert (_maps_from_state == false);
1468 /* If the configuration has not changed, keep the mapping */
1469 if (old_internal != _configured_internal) {
1470 mapping_changed = sanitize_maps ();
1472 } else if (_match.custom_cfg && _configured) {
1473 assert (_maps_from_state == false);
1474 mapping_changed = sanitize_maps ();
1477 if (is_channelstrip ()) {
1478 /* fake channel map - for wire display */
1479 _maps_from_state = false;
1482 _thru_map = ChanMapping ();
1483 _in_map[0] = ChanMapping (ChanCount::min (_configured_in, ChanCount (DataType::AUDIO, 2)));
1484 _out_map[0] = ChanMapping (ChanCount::min (_configured_out, ChanCount (DataType::AUDIO, 2)));
1485 /* set "thru" map for in-place forward of audio */
1486 for (uint32_t i = 2; i < _configured_in.n_audio(); ++i) {
1487 _thru_map.set (DataType::AUDIO, i, i);
1489 /* and midi (after implicit 1st channel bypass) */
1490 for (uint32_t i = 1; i < _configured_in.n_midi(); ++i) {
1491 _thru_map.set (DataType::MIDI, i, i);
1495 if (_maps_from_state) {
1496 _maps_from_state = false;
1497 mapping_changed = true;
1500 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("Reset Map for '%1': cfg:%2 chn-in:%3 chn-out:%4 match:%5 size-in:%6 size-out:%7\n",
1502 _configured ? "Y" : "N",
1503 old_in == in ? "==" : "!=",
1504 old_out == out ? "==" : "mismatch",
1505 old_match.method == _match.method ? "==" : "!=",
1506 _in_map.size() == get_count () ? "==" : "!=",
1507 _out_map.size() == get_count () ? "==" : "!="
1509 /* generate a new mapping */
1510 mapping_changed = reset_map (false);
1514 if (mapping_changed) {
1515 PluginMapChanged (); /* EMIT SIGNAL */
1518 if (DEBUG_ENABLED(DEBUG::ChanMapping)) {
1521 DEBUG_STR_APPEND(a, "\n--------<<--------\n");
1522 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1524 DEBUG_STR_APPEND(a, "----><----\n");
1526 DEBUG_STR_APPEND(a, string_compose ("Channel Map for %1 plugin %2\n", name(), pc));
1527 DEBUG_STR_APPEND(a, " * Inputs:\n");
1528 DEBUG_STR_APPEND(a, _in_map[pc]);
1529 DEBUG_STR_APPEND(a, " * Outputs:\n");
1530 DEBUG_STR_APPEND(a, _out_map[pc]);
1532 DEBUG_STR_APPEND(a, " * Thru:\n");
1533 DEBUG_STR_APPEND(a, _thru_map);
1534 DEBUG_STR_APPEND(a, "-------->>--------\n");
1535 DEBUG_TRACE (DEBUG::ChanMapping, DEBUG_STR(a).str());
1540 _no_inplace = check_inplace ();
1541 _mapping_changed = false;
1543 /* only the "noinplace_buffers" thread buffers need to be this large,
1544 * this can be optimized. other buffers are fine with
1545 * ChanCount::max (natural_input_streams (), natural_output_streams())
1546 * and route.cc's max (configured_in, configured_out)
1548 * no-inplace copies "thru" outputs (to emulate in-place) for
1549 * all outputs (to prevent overwrite) into a temporary space
1550 * which also holds input buffers (in case the plugin does process
1551 * in-place and overwrites those).
1553 * this buffers need to be at least as
1554 * natural_input_streams () + possible outputs.
1556 * sidechain inputs add a constraint on the input:
1557 * configured input + sidechain (=_configured_internal)
1559 * NB. this also satisfies
1560 * max (natural_input_streams(), natural_output_streams())
1561 * which is needed for silence runs
1563 _required_buffers = ChanCount::max (_configured_internal,
1564 natural_input_streams () + ChanCount::max (_configured_out, natural_output_streams () * get_count ()));
1566 if (old_in != in || old_out != out || old_internal != _configured_internal
1567 || (old_match.method != _match.method && (old_match.method == Split || _match.method == Split))
1569 PluginIoReConfigure (); /* EMIT SIGNAL */
1572 _delaybuffers.configure (_configured_out, _plugins.front ()->max_latency ());
1573 _latency_changed = true;
1575 // we don't know the analysis window size, so we must work with the
1576 // current buffer size here. each request for data fills in these
1577 // buffers and the analyser makes sure it gets enough data for the
1579 session().ensure_buffer_set (_signal_analysis_inputs, in);
1580 //_signal_analysis_inputs.set_count (in);
1582 session().ensure_buffer_set (_signal_analysis_outputs, out);
1583 //_signal_analysis_outputs.set_count (out);
1585 // std::cerr << "set counts to i" << in.n_audio() << "/o" << out.n_audio() << std::endl;
1588 return Processor::configure_io (in, out);
1591 /** Decide whether this PluginInsert can support a given IO configuration.
1592 * To do this, we run through a set of possible solutions in rough order of
1595 * @param in Required input channel count.
1596 * @param out Filled in with the output channel count if we return true.
1597 * @return true if the given IO configuration can be supported.
1600 PluginInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out)
1603 _sidechain->can_support_io_configuration (in, out); // never fails, sets "out"
1605 return private_can_support_io_configuration (in, out).method != Impossible;
1609 PluginInsert::private_can_support_io_configuration (ChanCount const& in, ChanCount& out) const
1611 if (!_custom_cfg && _preset_out.n_audio () > 0) {
1612 // preseed hint (for variable i/o)
1613 out.set (DataType::AUDIO, _preset_out.n_audio ());
1616 Match rv = internal_can_support_io_configuration (in, out);
1618 if (!_custom_cfg && _preset_out.n_audio () > 0) {
1619 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("using output preset: %1 %2\n", name(), _preset_out));
1620 out.set (DataType::AUDIO, _preset_out.n_audio ());
1625 /** A private version of can_support_io_configuration which returns the method
1626 * by which the configuration can be matched, rather than just whether or not
1630 PluginInsert::internal_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
1632 if (_plugins.empty()) {
1637 if (is_channelstrip ()) {
1639 return Match (ExactMatch, 1);
1643 /* if a user specified a custom cfg, so be it. */
1645 PluginInfoPtr info = _plugins.front()->get_info();
1647 if (info->reconfigurable_io()) {
1648 return Match (Delegate, get_count(), _strict_io, true);
1650 return Match (ExactMatch, get_count(), _strict_io, true);
1654 /* try automatic configuration */
1655 Match m = PluginInsert::automatic_can_support_io_configuration (inx, out);
1657 PluginInfoPtr info = _plugins.front()->get_info();
1658 ChanCount inputs = info->n_inputs;
1659 ChanCount outputs = info->n_outputs;
1661 /* handle case strict-i/o */
1662 if (_strict_io && m.method != Impossible) {
1665 /* special case MIDI instruments */
1666 if (needs_midi_input ()) {
1667 // output = midi-bypass + at most master-out channels.
1668 ChanCount max_out (DataType::AUDIO, 2); // TODO use master-out
1669 max_out.set (DataType::MIDI, out.get(DataType::MIDI));
1670 out = ChanCount::min (out, max_out);
1671 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("special case strict-i/o instrument: %1\n", name()));
1677 if (inx.n_audio () != out.n_audio ()) { // ignore midi bypass
1678 /* replicate processor to match output count (generators and such)
1679 * at least enough to feed every output port. */
1680 uint32_t f = 1; // at least one. e.g. control data filters, no in, no out.
1681 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1682 uint32_t nout = outputs.get (*t);
1683 if (nout == 0 || inx.get(*t) == 0) { continue; }
1684 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nout));
1687 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("special case strict-i/o generator: %1\n", name()));
1688 return Match (Replicate, f, _strict_io);
1699 if (m.method != Impossible) {
1703 ChanCount ns_inputs = inputs - sidechain_input_pins ();
1705 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("resolving 'Impossible' match for %1\n", name()));
1707 if (info->reconfigurable_io()) {
1710 if (out.n_midi () > 0 && out.n_audio () == 0) { out.set (DataType::AUDIO, 2); }
1711 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1712 bool const r = _plugins.front()->can_support_io_configuration (inx, out, &useins);
1714 // houston, we have a problem.
1715 return Match (Impossible, 0);
1717 return Match (Delegate, 1, _strict_io);
1720 ChanCount midi_bypass;
1721 if (inx.get(DataType::MIDI) == 1 && outputs.get(DataType::MIDI) == 0) {
1722 midi_bypass.set (DataType::MIDI, 1);
1725 // add at least as many plugins so that output count matches input count (w/o sidechain pins)
1727 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1728 uint32_t nin = ns_inputs.get (*t);
1729 uint32_t nout = outputs.get (*t);
1730 if (nin == 0 || inx.get(*t) == 0) { continue; }
1731 // prefer floor() so the count won't overly increase IFF (nin < nout)
1732 f = max (f, (uint32_t) floor (inx.get(*t) / (float)nout));
1734 if (f > 0 && outputs * f >= _configured_out) {
1735 out = outputs * f + midi_bypass;
1736 return Match (Replicate, f, _strict_io);
1739 // add at least as many plugins needed to connect all inputs (w/o sidechain pins)
1741 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1742 uint32_t nin = ns_inputs.get (*t);
1743 if (nin == 0 || inx.get(*t) == 0) { continue; }
1744 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1747 out = outputs * f + midi_bypass;
1748 return Match (Replicate, f, _strict_io);
1751 // add at least as many plugins needed to connect all inputs
1753 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1754 uint32_t nin = inputs.get (*t);
1755 if (nin == 0 || inx.get(*t) == 0) { continue; }
1756 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1758 out = outputs * f + midi_bypass;
1759 return Match (Replicate, f, _strict_io);
1762 /* this is the original Ardour 3/4 behavior, mainly for backwards compatibility */
1764 PluginInsert::automatic_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
1766 if (_plugins.empty()) {
1770 PluginInfoPtr info = _plugins.front()->get_info();
1771 ChanCount in; in += inx;
1772 ChanCount midi_bypass;
1774 if (info->reconfigurable_io()) {
1775 /* Plugin has flexible I/O, so delegate to it
1776 * pre-seed outputs, plugin tries closest match
1779 if (out.n_midi () > 0 && out.n_audio () == 0) { out.set (DataType::AUDIO, 2); }
1780 if (out.n_audio () == 0) { out.set (DataType::AUDIO, 1); }
1781 bool const r = _plugins.front()->can_support_io_configuration (in, out);
1783 return Match (Impossible, 0);
1785 return Match (Delegate, 1);
1788 ChanCount inputs = info->n_inputs;
1789 ChanCount outputs = info->n_outputs;
1790 ChanCount ns_inputs = inputs - sidechain_input_pins ();
1792 if (in.get(DataType::MIDI) == 1 && outputs.get(DataType::MIDI) == 0) {
1793 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("bypassing midi-data around %1\n", name()));
1794 midi_bypass.set (DataType::MIDI, 1);
1796 if (in.get(DataType::MIDI) == 1 && inputs.get(DataType::MIDI) == 0) {
1797 DEBUG_TRACE (DEBUG::ChanMapping, string_compose ("hiding midi-port from plugin %1\n", name()));
1798 in.set(DataType::MIDI, 0);
1801 // add internally provided sidechain ports
1802 ChanCount insc = in + sidechain_input_ports ();
1804 bool no_inputs = true;
1805 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1806 if (inputs.get (*t) != 0) {
1813 /* no inputs so we can take any input configuration since we throw it away */
1814 out = outputs + midi_bypass;
1815 return Match (NoInputs, 1);
1818 /* Plugin inputs match requested inputs + side-chain-ports exactly */
1819 if (inputs == insc) {
1820 out = outputs + midi_bypass;
1821 return Match (ExactMatch, 1);
1824 /* Plugin inputs matches without side-chain-pins */
1825 if (ns_inputs == in) {
1826 out = outputs + midi_bypass;
1827 return Match (ExactMatch, 1);
1830 /* We may be able to run more than one copy of the plugin within this insert
1831 to cope with the insert having more inputs than the plugin.
1832 We allow replication only for plugins with either zero or 1 inputs and outputs
1833 for every valid data type.
1837 bool can_replicate = true;
1838 for (DataType::iterator t = DataType::begin(); t != DataType::end() && can_replicate; ++t) {
1840 // ignore side-chains
1841 uint32_t nin = ns_inputs.get (*t);
1843 // No inputs of this type
1844 if (nin == 0 && in.get(*t) == 0) {
1848 if (nin != 1 || outputs.get (*t) != 1) {
1849 can_replicate = false;
1853 // Potential factor not set yet
1855 f = in.get(*t) / nin;
1858 // Factor for this type does not match another type, can not replicate
1859 if (f != (in.get(*t) / nin)) {
1860 can_replicate = false;
1865 if (can_replicate && f > 0) {
1866 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1867 out.set (*t, outputs.get(*t) * f);
1870 return Match (Replicate, f);
1873 /* If the processor has exactly one input of a given type, and
1874 the plugin has more, we can feed the single processor input
1875 to some or all of the plugin inputs. This is rather
1876 special-case-y, but the 1-to-many case is by far the
1877 simplest. How do I split thy 2 processor inputs to 3
1878 plugin inputs? Let me count the ways ...
1881 bool can_split = true;
1882 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1884 bool const can_split_type = (in.get (*t) == 1 && ns_inputs.get (*t) > 1);
1885 bool const nothing_to_do_for_type = (in.get (*t) == 0 && inputs.get (*t) == 0);
1887 if (!can_split_type && !nothing_to_do_for_type) {
1893 out = outputs + midi_bypass;
1894 return Match (Split, 1);
1897 /* If the plugin has more inputs than we want, we can `hide' some of them
1898 by feeding them silence.
1901 bool could_hide = false;
1902 bool cannot_hide = false;
1903 ChanCount hide_channels;
1905 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1906 if (inputs.get(*t) > in.get(*t)) {
1907 /* there is potential to hide, since the plugin has more inputs of type t than the insert */
1908 hide_channels.set (*t, inputs.get(*t) - in.get(*t));
1910 } else if (inputs.get(*t) < in.get(*t)) {
1911 /* we definitely cannot hide, since the plugin has fewer inputs of type t than the insert */
1916 if (could_hide && !cannot_hide) {
1917 out = outputs + midi_bypass;
1918 return Match (Hide, 1, false, false, hide_channels);
1921 return Match (Impossible, 0);
1926 PluginInsert::get_state ()
1928 return state (true);
1932 PluginInsert::state (bool full)
1934 XMLNode& node = Processor::state (full);
1936 node.add_property("type", _plugins[0]->state_node_name());
1937 node.add_property("unique-id", _plugins[0]->unique_id());
1938 node.add_property("count", string_compose("%1", _plugins.size()));
1940 /* remember actual i/o configuration (for later placeholder
1941 * in case the plugin goes missing) */
1942 node.add_child_nocopy (* _configured_in.state (X_("ConfiguredInput")));
1943 node.add_child_nocopy (* _configured_out.state (X_("ConfiguredOutput")));
1944 node.add_child_nocopy (* _preset_out.state (X_("PresetOutput")));
1946 /* save custom i/o config */
1947 node.add_property("custom", _custom_cfg ? "yes" : "no");
1948 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1950 snprintf (tmp, sizeof(tmp), "InputMap-%d", pc);
1951 node.add_child_nocopy (* _in_map[pc].state (tmp));
1952 snprintf (tmp, sizeof(tmp), "OutputMap-%d", pc);
1953 node.add_child_nocopy (* _out_map[pc].state (tmp));
1955 node.add_child_nocopy (* _thru_map.state ("ThruMap"));
1958 node.add_child_nocopy (_sidechain->state (full));
1961 _plugins[0]->set_insert_id(this->id());
1962 node.add_child_nocopy (_plugins[0]->get_state());
1964 for (Controls::iterator c = controls().begin(); c != controls().end(); ++c) {
1965 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> ((*c).second);
1967 node.add_child_nocopy (ac->get_state());
1975 PluginInsert::set_control_ids (const XMLNode& node, int version)
1977 const XMLNodeList& nlist = node.children();
1978 XMLNodeConstIterator iter;
1979 set<Evoral::Parameter>::const_iterator p;
1981 for (iter = nlist.begin(); iter != nlist.end(); ++iter) {
1982 if ((*iter)->name() == Controllable::xml_node_name) {
1983 const XMLProperty* prop;
1985 uint32_t p = (uint32_t)-1;
1987 if ((prop = (*iter)->property (X_("symbol"))) != 0) {
1988 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugins[0]);
1990 p = lv2plugin->port_index(prop->value().c_str());
1994 if (p == (uint32_t)-1 && (prop = (*iter)->property (X_("parameter"))) != 0) {
1995 p = atoi (prop->value());
1998 if (p != (uint32_t)-1) {
2000 /* this may create the new controllable */
2002 boost::shared_ptr<Evoral::Control> c = control (Evoral::Parameter (PluginAutomation, 0, p));
2004 #ifndef NO_PLUGIN_STATE
2008 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (c);
2010 ac->set_state (**iter, version);
2019 PluginInsert::set_state(const XMLNode& node, int version)
2021 XMLNodeList nlist = node.children();
2022 XMLNodeIterator niter;
2023 XMLPropertyList plist;
2024 const XMLProperty *prop;
2025 ARDOUR::PluginType type;
2027 if ((prop = node.property ("type")) == 0) {
2028 error << _("XML node describing plugin is missing the `type' field") << endmsg;
2032 if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */
2033 type = ARDOUR::LADSPA;
2034 } else if (prop->value() == X_("lv2")) {
2036 } else if (prop->value() == X_("windows-vst")) {
2037 type = ARDOUR::Windows_VST;
2038 } else if (prop->value() == X_("lxvst")) {
2039 type = ARDOUR::LXVST;
2040 } else if (prop->value() == X_("audiounit")) {
2041 type = ARDOUR::AudioUnit;
2042 } else if (prop->value() == X_("luaproc")) {
2045 error << string_compose (_("unknown plugin type %1 in plugin insert state"),
2051 prop = node.property ("unique-id");
2054 #ifdef WINDOWS_VST_SUPPORT
2055 /* older sessions contain VST plugins with only an "id" field.
2058 if (type == ARDOUR::Windows_VST) {
2059 prop = node.property ("id");
2063 #ifdef LXVST_SUPPORT
2064 /*There shouldn't be any older sessions with linuxVST support.. but anyway..*/
2066 if (type == ARDOUR::LXVST) {
2067 prop = node.property ("id");
2073 error << _("Plugin has no unique ID field") << endmsg;
2078 boost::shared_ptr<Plugin> plugin = find_plugin (_session, prop->value(), type);
2080 /* treat linux and windows VST plugins equivalent if they have the same uniqueID
2081 * allow to move sessions windows <> linux */
2082 #ifdef LXVST_SUPPORT
2083 if (plugin == 0 && type == ARDOUR::Windows_VST) {
2084 type = ARDOUR::LXVST;
2085 plugin = find_plugin (_session, prop->value(), type);
2089 #ifdef WINDOWS_VST_SUPPORT
2090 if (plugin == 0 && type == ARDOUR::LXVST) {
2091 type = ARDOUR::Windows_VST;
2092 plugin = find_plugin (_session, prop->value(), type);
2097 error << string_compose(
2098 _("Found a reference to a plugin (\"%1\") that is unknown.\n"
2099 "Perhaps it was removed or moved since it was last used."),
2105 if (type == ARDOUR::Lua) {
2106 XMLNode *ls = node.child (plugin->state_node_name().c_str());
2107 // we need to load the script to set the name and parameters.
2108 boost::shared_ptr<LuaProc> lp = boost::dynamic_pointer_cast<LuaProc>(plugin);
2110 lp->set_script_from_state (*ls);
2114 // The name of the PluginInsert comes from the plugin, nothing else
2115 _name = plugin->get_info()->name;
2119 // Processor::set_state() will set this, but too late
2120 // for it to be available when setting up plugin
2121 // state. We can't call Processor::set_state() until
2122 // the plugins themselves are created and added.
2126 if (_plugins.empty()) {
2127 /* if we are adding the first plugin, we will need to set
2128 up automatable controls.
2130 add_plugin (plugin);
2131 create_automatable_parameters ();
2132 set_control_ids (node, version);
2135 if ((prop = node.property ("count")) != 0) {
2136 sscanf (prop->value().c_str(), "%u", &count);
2139 if (_plugins.size() != count) {
2140 for (uint32_t n = 1; n < count; ++n) {
2141 add_plugin (plugin_factory (plugin));
2145 Processor::set_state (node, version);
2147 PBD::ID new_id = this->id();
2148 PBD::ID old_id = this->id();
2150 if ((prop = node.property ("id")) != 0) {
2151 old_id = prop->value ();
2154 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2156 /* find the node with the type-specific node name ("lv2", "ladspa", etc)
2157 and set all plugins to the same state.
2160 if ((*niter)->name() == plugin->state_node_name()) {
2162 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2163 /* Plugin state can include external files which are named after the ID.
2165 * If regenerate_xml_or_string_ids() is set, the ID will already have
2166 * been changed, so we need to use the old ID from the XML to load the
2167 * state and then update the ID.
2169 * When copying a plugin-state, route_ui takes care of of updating the ID,
2170 * but we need to call set_insert_id() to clear the cached plugin-state
2171 * and force a change.
2173 if (!regenerate_xml_or_string_ids ()) {
2174 (*i)->set_insert_id (new_id);
2176 (*i)->set_insert_id (old_id);
2179 (*i)->set_state (**niter, version);
2181 if (regenerate_xml_or_string_ids ()) {
2182 (*i)->set_insert_id (new_id);
2190 if (version < 3000) {
2192 /* Only 2.X sessions need a call to set_parameter_state() - in 3.X and above
2193 this is all handled by Automatable
2196 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2197 if ((*niter)->name() == "Redirect") {
2198 /* XXX do we need to tackle placement? i think not (pd; oct 16 2009) */
2199 Processor::set_state (**niter, version);
2204 set_parameter_state_2X (node, version);
2207 if ((prop = node.property (X_("custom"))) != 0) {
2208 _custom_cfg = string_is_affirmative (prop->value());
2211 uint32_t in_maps = 0;
2212 uint32_t out_maps = 0;
2213 XMLNodeList kids = node.children ();
2214 for (XMLNodeIterator i = kids.begin(); i != kids.end(); ++i) {
2215 if ((*i)->name() == X_("ConfiguredOutput")) {
2216 _custom_out = ChanCount(**i);
2218 if ((*i)->name() == X_("PresetOutput")) {
2219 _preset_out = ChanCount(**i);
2221 if (strncmp ((*i)->name ().c_str(), X_("InputMap-"), 9) == 0) {
2222 long pc = atol (&((*i)->name().c_str()[9]));
2223 if (pc >=0 && pc <= get_count()) {
2224 _in_map[pc] = ChanMapping (**i);
2228 if (strncmp ((*i)->name ().c_str(), X_("OutputMap-"), 10) == 0) {
2229 long pc = atol (&((*i)->name().c_str()[10]));
2230 if (pc >=0 && pc <= get_count()) {
2231 _out_map[pc] = ChanMapping (**i);
2235 if ((*i)->name () == "ThruMap") {
2236 _thru_map = ChanMapping (**i);
2239 // sidechain is a Processor (IO)
2240 if ((*i)->name () == Processor::state_node_name) {
2244 _sidechain->set_state (**i, version);
2248 if (in_maps == out_maps && out_maps >0 && out_maps == get_count()) {
2249 _maps_from_state = true;
2252 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2256 (*i)->deactivate ();
2260 PluginConfigChanged (); /* EMIT SIGNAL */
2265 PluginInsert::update_id (PBD::ID id)
2268 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2269 (*i)->set_insert_id (id);
2274 PluginInsert::set_state_dir (const std::string& d)
2276 // state() only saves the state of the first plugin
2277 _plugins[0]->set_state_dir (d);
2281 PluginInsert::set_parameter_state_2X (const XMLNode& node, int version)
2283 XMLNodeList nlist = node.children();
2284 XMLNodeIterator niter;
2286 /* look for port automation node */
2288 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2290 if ((*niter)->name() != port_automation_node_name) {
2296 XMLNodeConstIterator iter;
2301 cnodes = (*niter)->children ("port");
2303 for (iter = cnodes.begin(); iter != cnodes.end(); ++iter){
2307 if ((cprop = child->property("number")) != 0) {
2308 port = cprop->value().c_str();
2310 warning << _("PluginInsert: Auto: no ladspa port number") << endmsg;
2314 sscanf (port, "%" PRIu32, &port_id);
2316 if (port_id >= _plugins[0]->parameter_count()) {
2317 warning << _("PluginInsert: Auto: port id out of range") << endmsg;
2321 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(
2322 control(Evoral::Parameter(PluginAutomation, 0, port_id), true));
2324 if (c && c->alist()) {
2325 if (!child->children().empty()) {
2326 c->alist()->set_state (*child->children().front(), version);
2328 /* In some cases 2.X saves lists with min_yval and max_yval
2329 being FLT_MIN and FLT_MAX respectively. This causes problems
2330 in A3 because these min/max values are used to compute
2331 where GUI control points should be drawn. If we see such
2332 values, `correct' them to the min/max of the appropriate
2336 float min_y = c->alist()->get_min_y ();
2337 float max_y = c->alist()->get_max_y ();
2339 ParameterDescriptor desc;
2340 _plugins.front()->get_parameter_descriptor (port_id, desc);
2342 if (min_y == FLT_MIN) {
2346 if (max_y == FLT_MAX) {
2350 c->alist()->set_yrange (min_y, max_y);
2353 error << string_compose (_("PluginInsert: automatable control %1 not found - ignored"), port_id) << endmsg;
2365 PluginInsert::describe_parameter (Evoral::Parameter param)
2367 if (param.type() == PluginAutomation) {
2368 return _plugins[0]->describe_parameter (param);
2369 } else if (param.type() == PluginPropertyAutomation) {
2370 boost::shared_ptr<AutomationControl> c(automation_control(param));
2371 if (c && !c->desc().label.empty()) {
2372 return c->desc().label;
2375 return Automatable::describe_parameter(param);
2379 PluginInsert::signal_latency() const
2381 if (_user_latency) {
2382 return _user_latency;
2385 return _plugins[0]->signal_latency ();
2389 PluginInsert::type ()
2391 return plugin()->get_info()->type;
2394 PluginInsert::PluginControl::PluginControl (PluginInsert* p,
2395 const Evoral::Parameter& param,
2396 const ParameterDescriptor& desc,
2397 boost::shared_ptr<AutomationList> list)
2398 : AutomationControl (p->session(), param, desc, list, p->describe_parameter(param))
2402 alist()->reset_default (desc.normal);
2404 list->set_interpolation(Evoral::ControlList::Discrete);
2409 set_flags(Controllable::Toggle);
2413 /** @param val `user' value */
2415 PluginInsert::PluginControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override)
2418 _set_value (user_val, group_override);
2422 PluginInsert::PluginControl::set_value_unchecked (double user_val)
2424 /* used only by automation playback */
2425 _set_value (user_val, Controllable::NoGroup);
2429 PluginInsert::PluginControl::_set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override)
2431 /* FIXME: probably should be taking out some lock here.. */
2433 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
2434 (*i)->set_parameter (_list->parameter().id(), user_val);
2437 boost::shared_ptr<Plugin> iasp = _plugin->_impulseAnalysisPlugin.lock();
2439 iasp->set_parameter (_list->parameter().id(), user_val);
2442 AutomationControl::set_value (user_val, group_override);
2446 PluginInsert::PluginControl::catch_up_with_external_value (double user_val)
2448 AutomationControl::set_value (user_val, Controllable::NoGroup);
2452 PluginInsert::PluginControl::get_state ()
2456 XMLNode& node (AutomationControl::get_state());
2457 ss << parameter().id();
2458 node.add_property (X_("parameter"), ss.str());
2460 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugin->_plugins[0]);
2462 node.add_property (X_("symbol"), lv2plugin->port_symbol (parameter().id()));
2469 /** @return `user' val */
2471 PluginInsert::PluginControl::get_value () const
2473 boost::shared_ptr<Plugin> plugin = _plugin->plugin (0);
2479 return plugin->get_parameter (_list->parameter().id());
2482 PluginInsert::PluginPropertyControl::PluginPropertyControl (PluginInsert* p,
2483 const Evoral::Parameter& param,
2484 const ParameterDescriptor& desc,
2485 boost::shared_ptr<AutomationList> list)
2486 : AutomationControl (p->session(), param, desc, list)
2490 alist()->set_yrange (desc.lower, desc.upper);
2491 alist()->reset_default (desc.normal);
2495 set_flags(Controllable::Toggle);
2500 PluginInsert::PluginPropertyControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition /* group_override*/)
2503 set_value_unchecked (user_val);
2508 PluginInsert::PluginPropertyControl::set_value_unchecked (double user_val)
2510 /* Old numeric set_value(), coerce to appropriate datatype if possible.
2511 This is lossy, but better than nothing until Ardour's automation system
2512 can handle various datatypes all the way down. */
2513 const Variant value(_desc.datatype, user_val);
2514 if (value.type() == Variant::NOTHING) {
2515 error << "set_value(double) called for non-numeric property" << endmsg;
2519 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
2520 (*i)->set_property(_list->parameter().id(), value);
2524 AutomationControl::set_value (user_val, Controllable::NoGroup);
2528 PluginInsert::PluginPropertyControl::get_state ()
2532 XMLNode& node (AutomationControl::get_state());
2533 ss << parameter().id();
2534 node.add_property (X_("property"), ss.str());
2535 node.remove_property (X_("value"));
2541 PluginInsert::PluginPropertyControl::get_value () const
2543 return _value.to_double();
2546 boost::shared_ptr<Plugin>
2547 PluginInsert::get_impulse_analysis_plugin()
2549 boost::shared_ptr<Plugin> ret;
2550 if (_impulseAnalysisPlugin.expired()) {
2551 // LV2 in particular uses various _session params
2552 // during init() -- most notably block_size..
2554 ret = plugin_factory(_plugins[0]);
2555 ret->configure_io (internal_input_streams (), internal_output_streams ());
2556 _impulseAnalysisPlugin = ret;
2558 ret = _impulseAnalysisPlugin.lock();
2565 PluginInsert::collect_signal_for_analysis (framecnt_t nframes)
2567 // called from outside the audio thread, so this should be safe
2568 // only do audio as analysis is (currently) only for audio plugins
2569 _signal_analysis_inputs.ensure_buffers( DataType::AUDIO, internal_input_streams().n_audio(), nframes);
2570 _signal_analysis_outputs.ensure_buffers( DataType::AUDIO, internal_output_streams().n_audio(), nframes);
2572 _signal_analysis_collected_nframes = 0;
2573 _signal_analysis_collect_nframes_max = nframes;
2576 /** Add a plugin to our list */
2578 PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
2580 plugin->set_insert_id (this->id());
2582 if (_plugins.empty()) {
2583 /* first (and probably only) plugin instance - connect to relevant signals */
2585 plugin->ParameterChangedExternally.connect_same_thread (*this, boost::bind (&PluginInsert::parameter_changed_externally, this, _1, _2));
2586 plugin->StartTouch.connect_same_thread (*this, boost::bind (&PluginInsert::start_touch, this, _1));
2587 plugin->EndTouch.connect_same_thread (*this, boost::bind (&PluginInsert::end_touch, this, _1));
2588 plugin->LatencyChanged.connect_same_thread (*this, boost::bind (&PluginInsert::latency_changed, this, _1, _2));
2589 // cache sidechain port count
2590 _cached_sidechain_pins.reset ();
2591 const ChanCount& nis (plugin->get_info()->n_inputs);
2592 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
2593 for (uint32_t in = 0; in < nis.get (*t); ++in) {
2594 const Plugin::IOPortDescription& iod (plugin->describe_io_port (*t, true, in));
2595 if (iod.is_sidechain) {
2596 _cached_sidechain_pins.set (*t, 1 + _cached_sidechain_pins.n(*t));
2601 #if (defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT)
2602 boost::shared_ptr<VSTPlugin> vst = boost::dynamic_pointer_cast<VSTPlugin> (plugin);
2604 vst->set_insert (this, _plugins.size ());
2607 _plugins.push_back (plugin);
2611 PluginInsert::realtime_handle_transport_stopped ()
2613 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2614 (*i)->realtime_handle_transport_stopped ();
2619 PluginInsert::realtime_locate ()
2621 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2622 (*i)->realtime_locate ();
2627 PluginInsert::monitoring_changed ()
2629 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
2630 (*i)->monitoring_changed ();
2635 PluginInsert::latency_changed (framecnt_t, framecnt_t)
2637 // this is called in RT context, LatencyChanged is emitted after run()
2638 _latency_changed = true;
2642 PluginInsert::start_touch (uint32_t param_id)
2644 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
2646 ac->start_touch (session().audible_frame());
2651 PluginInsert::end_touch (uint32_t param_id)
2653 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
2655 ac->stop_touch (true, session().audible_frame());
2659 std::ostream& operator<<(std::ostream& o, const ARDOUR::PluginInsert::Match& m)
2662 case PluginInsert::Impossible: o << "Impossible"; break;
2663 case PluginInsert::Delegate: o << "Delegate"; break;
2664 case PluginInsert::NoInputs: o << "NoInputs"; break;
2665 case PluginInsert::ExactMatch: o << "ExactMatch"; break;
2666 case PluginInsert::Replicate: o << "Replicate"; break;
2667 case PluginInsert::Split: o << "Split"; break;
2668 case PluginInsert::Hide: o << "Hide"; break;
2670 o << " cnt: " << m.plugins
2671 << (m.strict_io ? " strict-io" : "")
2672 << (m.custom_cfg ? " custom-cfg" : "");
2673 if (m.method == PluginInsert::Hide) {
2674 o << " hide: " << m.hide;