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"
41 #include "ardour/lv2_plugin.h"
44 #ifdef WINDOWS_VST_SUPPORT
45 #include "ardour/windows_vst_plugin.h"
49 #include "ardour/lxvst_plugin.h"
52 #ifdef AUDIOUNIT_SUPPORT
53 #include "ardour/audio_unit.h"
56 #include "ardour/session.h"
57 #include "ardour/types.h"
62 using namespace ARDOUR;
65 const string PluginInsert::port_automation_node_name = "PortAutomation";
67 PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug)
68 : Processor (s, (plug ? plug->name() : string ("toBeRenamed")))
69 , _signal_analysis_collected_nframes(0)
70 , _signal_analysis_collect_nframes_max(0)
75 , _pending_no_inplace (false)
77 /* the first is the master */
81 create_automatable_parameters ();
85 PluginInsert::~PluginInsert ()
90 PluginInsert::set_count (uint32_t num)
92 bool require_state = !_plugins.empty();
94 /* this is a bad idea.... we shouldn't do this while active.
95 only a route holding their redirect_lock should be calling this
100 } else if (num > _plugins.size()) {
101 uint32_t diff = num - _plugins.size();
103 for (uint32_t n = 0; n < diff; ++n) {
104 boost::shared_ptr<Plugin> p = plugin_factory (_plugins[0]);
111 /* XXX do something */
115 } else if (num < _plugins.size()) {
116 uint32_t diff = _plugins.size() - num;
117 for (uint32_t n= 0; n < diff; ++n) {
127 PluginInsert::set_outputs (const ChanCount& c)
133 PluginInsert::control_list_automation_state_changed (Evoral::Parameter which, AutoState s)
135 if (which.type() != PluginAutomation)
138 boost::shared_ptr<AutomationControl> c
139 = boost::dynamic_pointer_cast<AutomationControl>(control (which));
142 _plugins[0]->set_parameter (which.id(), c->list()->eval (_session.transport_frame()));
147 PluginInsert::output_streams() const
149 assert (_configured);
150 return _configured_out;
154 PluginInsert::input_streams() const
156 assert (_configured);
157 return _configured_in;
161 PluginInsert::internal_output_streams() const
163 assert (!_plugins.empty());
165 PluginInfoPtr info = _plugins.front()->get_info();
167 if (info->reconfigurable_io()) {
168 ChanCount out = _plugins.front()->output_streams ();
169 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, reconfigur(able) output streams = %1\n", out));
172 ChanCount out = info->n_outputs;
173 // DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, static output streams = %1 for %2 plugins\n", out, _plugins.size()));
174 out.set_audio (out.n_audio() * _plugins.size());
175 out.set_midi (out.n_midi() * _plugins.size());
181 PluginInsert::internal_input_streams() const
183 assert (!_plugins.empty());
187 PluginInfoPtr info = _plugins.front()->get_info();
189 if (info->reconfigurable_io()) {
190 assert (_plugins.size() == 1);
191 in = _plugins.front()->input_streams();
196 DEBUG_TRACE (DEBUG::Processors, string_compose ("Plugin insert, input streams = %1, match using %2\n", in, _match.method));
198 if (_match.method == Split) {
200 /* we are splitting 1 processor input to multiple plugin inputs,
201 so we have a maximum of 1 stream of each type.
203 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
204 if (in.get (*t) > 1) {
210 } else if (_match.method == Hide) {
212 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
213 in.set (*t, in.get (*t) - _match.hide.get (*t));
219 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
220 in.set (*t, in.get (*t) * _plugins.size ());
228 PluginInsert::natural_output_streams() const
230 return _plugins[0]->get_info()->n_outputs;
234 PluginInsert::natural_input_streams() const
236 return _plugins[0]->get_info()->n_inputs;
240 PluginInsert::has_no_inputs() const
242 return _plugins[0]->get_info()->n_inputs == ChanCount::ZERO;
246 PluginInsert::has_no_audio_inputs() const
248 return _plugins[0]->get_info()->n_inputs.n_audio() == 0;
252 PluginInsert::is_midi_instrument() const
254 /* XXX more finesse is possible here. VST plugins have a
255 a specific "instrument" flag, for example.
257 PluginInfoPtr pi = _plugins[0]->get_info();
259 return pi->n_inputs.n_midi() != 0 &&
260 pi->n_outputs.n_audio() > 0;
264 PluginInsert::create_automatable_parameters ()
266 assert (!_plugins.empty());
268 set<Evoral::Parameter> a = _plugins.front()->automatable ();
270 for (set<Evoral::Parameter>::iterator i = a.begin(); i != a.end(); ++i) {
271 if (i->type() == PluginAutomation) {
273 Evoral::Parameter param(*i);
275 ParameterDescriptor desc;
276 _plugins.front()->get_parameter_descriptor(i->id(), desc);
278 can_automate (param);
279 boost::shared_ptr<AutomationList> list(new AutomationList(param, desc));
280 boost::shared_ptr<AutomationControl> c (new PluginControl(this, param, desc, list));
282 _plugins.front()->set_automation_control (i->id(), c);
283 } else if (i->type() == PluginPropertyAutomation) {
284 Evoral::Parameter param(*i);
285 const ParameterDescriptor& desc = _plugins.front()->get_property_descriptor(param.id());
286 if (desc.datatype != Variant::NOTHING) {
287 boost::shared_ptr<AutomationList> list;
288 if (Variant::type_is_numeric(desc.datatype)) {
289 list = boost::shared_ptr<AutomationList>(new AutomationList(param, desc));
291 add_control (boost::shared_ptr<AutomationControl> (new PluginPropertyControl(this, param, desc, list)));
296 /** Called when something outside of this host has modified a plugin
297 * parameter. Responsible for propagating the change to two places:
299 * 1) anything listening to the Control itself
300 * 2) any replicated plugins that make up this PluginInsert.
302 * The PluginInsert is connected to the ParameterChangedExternally signal for
303 * the first (primary) plugin, and here broadcasts that change to any others.
305 * XXX We should probably drop this whole replication idea (Paul, October 2015)
306 * since it isn't used by sensible plugin APIs (AU, LV2).
309 PluginInsert::parameter_changed_externally (uint32_t which, float val)
311 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, which));
313 /* First propagation: alter the underlying value of the control,
314 * without telling the plugin(s) that own/use it to set it.
321 boost::shared_ptr<PluginControl> pc = boost::dynamic_pointer_cast<PluginControl> (ac);
324 pc->catch_up_with_external_value (val);
327 /* Second propagation: tell all plugins except the first to
328 update the value of this parameter. For sane plugin APIs,
329 there are no other plugins, so this is a no-op in those
333 Plugins::iterator i = _plugins.begin();
335 /* don't set the first plugin, just all the slaves */
337 if (i != _plugins.end()) {
339 for (; i != _plugins.end(); ++i) {
340 (*i)->set_parameter (which, val);
346 PluginInsert::set_block_size (pframes_t nframes)
349 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
350 if ((*i)->set_block_size (nframes) != 0) {
358 PluginInsert::activate ()
360 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
364 Processor::activate ();
368 PluginInsert::deactivate ()
370 Processor::deactivate ();
372 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
378 PluginInsert::flush ()
380 for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
386 PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t offset, bool with_auto, framepos_t now)
388 PinMappings in_map (_in_map);
389 PinMappings out_map (_out_map);
392 // auto-detect if inplace processing is possible
393 // TODO: do this once. during configure_io and every time the
394 // plugin-count or mapping changes.
395 bool inplace_ok = true;
396 for (uint32_t pc = 0; pc < get_count() && inplace_ok ; ++pc) {
397 if (!in_map[pc].is_monotonic ()) {
400 if (!out_map[pc].is_monotonic ()) {
405 if (_pending_no_inplace != !inplace_ok) {
406 #ifndef NDEBUG // this 'cerr' needs to go ASAP.
407 cerr << name () << " automatically set : " << (inplace_ok ? "Use Inplace" : "No Inplace") << "\n"; // XXX
409 _pending_no_inplace = !inplace_ok;
413 _no_inplace = _pending_no_inplace || _plugins.front()->inplace_broken ();
417 // TODO optimize special case.
418 // Currently this never triggers because the in_map for "Split" triggeres no_inplace.
419 if (_match.method == Split && !_no_inplace) {
420 assert (in_map.size () == 1);
421 in_map[0] = ChanMapping (max (natural_input_streams (), _configured_in));
422 ChanCount const in_streams = internal_input_streams ();
423 /* copy the first stream's audio buffer contents to the others */
425 uint32_t first_idx = in_map[0].get (DataType::AUDIO, 0, &valid);
427 for (uint32_t i = in_streams.n_audio(); i < natural_input_streams().n_audio(); ++i) {
428 uint32_t idx = in_map[0].get (DataType::AUDIO, i, &valid);
430 bufs.get_audio(idx).read_from(bufs.get_audio(first_idx), nframes, offset, offset);
437 bufs.set_count(ChanCount::max(bufs.count(), _configured_in));
438 bufs.set_count(ChanCount::max(bufs.count(), _configured_out));
444 for (Controls::iterator li = controls().begin(); li != controls().end(); ++li, ++n) {
446 boost::shared_ptr<AutomationControl> c
447 = boost::dynamic_pointer_cast<AutomationControl>(li->second);
449 if (c->list() && c->automation_playback()) {
452 const float val = c->list()->rt_safe_eval (now, valid);
455 /* This is the ONLY place where we are
457 * AutomationControl::set_value_unchecked(). We
458 * know that the control is in
459 * automation playback mode, so no
460 * check on writable() is required
461 * (which must be done in AutomationControl::set_value()
464 c->set_value_unchecked(val);
471 /* Calculate if, and how many frames we need to collect for analysis */
472 framecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max -
473 _signal_analysis_collected_nframes);
474 if (nframes < collect_signal_nframes) { // we might not get all frames now
475 collect_signal_nframes = nframes;
478 if (collect_signal_nframes > 0) {
480 //std::cerr << "collect input, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
481 //std::cerr << " streams " << internal_input_streams().n_audio() << std::endl;
482 //std::cerr << "filling buffer with " << collect_signal_nframes << " frames at " << _signal_analysis_collected_nframes << std::endl;
484 _signal_analysis_inputs.set_count(internal_input_streams());
486 for (uint32_t i = 0; i < internal_input_streams().n_audio(); ++i) {
487 _signal_analysis_inputs.get_audio(i).read_from(
489 collect_signal_nframes,
490 _signal_analysis_collected_nframes); // offset is for target buffer
496 BufferSet& inplace_bufs = _session.get_noinplace_buffers();
497 ARDOUR::ChanMapping used_outputs;
500 // TODO optimize this flow. prepare during configure_io()
501 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
503 ARDOUR::ChanMapping i_in_map (natural_input_streams());
504 ARDOUR::ChanMapping i_out_map;
505 ARDOUR::ChanCount mapped;
506 ARDOUR::ChanCount backmap;
508 // map inputs sequentially
509 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
510 for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) {
512 uint32_t in_idx = in_map[pc].get (*t, in, &valid);
513 uint32_t m = mapped.get (*t);
515 inplace_bufs.get (*t, m).read_from (bufs.get (*t, in_idx), nframes, offset, offset);
517 inplace_bufs.get (*t, m).silence (nframes, offset);
519 mapped.set (*t, m + 1);
523 // TODO use map_offset_to() instead ??
527 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
528 for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) {
529 uint32_t m = mapped.get (*t);
530 inplace_bufs.get (*t, m).silence (nframes, offset);
531 i_out_map.set (*t, out, m);
532 mapped.set (*t, m + 1);
536 if ((*i)->connect_and_run(inplace_bufs, i_in_map, i_out_map, nframes, offset)) {
541 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
542 for (uint32_t out = 0; out < natural_output_streams().get (*t); ++out) {
543 uint32_t m = backmap.get (*t);
545 uint32_t out_idx = out_map[pc].get (*t, out, &valid);
547 bufs.get (*t, out_idx).read_from (inplace_bufs.get (*t, m), nframes, offset, offset);
548 used_outputs.set (*t, out_idx, 1); // mark as used
550 backmap.set (*t, m + 1);
554 /* all instances have completed, now clear outputs that have not been written to.
555 * (except midi bypass)
557 if (bufs.count().n_midi() == 1 && natural_output_streams().get(DataType::MIDI) == 0) {
558 used_outputs.set (DataType::MIDI, 0, 1); // Midi bypass.
560 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
561 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
563 used_outputs.get (*t, out, &valid);
564 if (valid) { continue; }
565 bufs.get (*t, out).silence (nframes, offset);
571 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
572 if ((*i)->connect_and_run(bufs, in_map[pc], out_map[pc], nframes, offset)) {
577 // TODO optimize: store "unconnected" in a fixed set.
578 // it only changes on reconfiguration.
579 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
580 for (uint32_t out = 0; out < bufs.count().get (*t); ++out) {
582 for (uint32_t pc = 0; pc < get_count() && !mapped; ++pc) {
583 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
585 uint32_t idx = out_map[pc].get (*t, o, &valid);
586 if (valid && idx == out) {
593 bufs.get (*t, out).silence (nframes, offset);
599 if (collect_signal_nframes > 0) {
601 //std::cerr << " output, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
602 //std::cerr << " streams " << internal_output_streams().n_audio() << std::endl;
604 _signal_analysis_outputs.set_count(internal_output_streams());
606 for (uint32_t i = 0; i < internal_output_streams().n_audio(); ++i) {
607 _signal_analysis_outputs.get_audio(i).read_from(
609 collect_signal_nframes,
610 _signal_analysis_collected_nframes); // offset is for target buffer
613 _signal_analysis_collected_nframes += collect_signal_nframes;
614 assert(_signal_analysis_collected_nframes <= _signal_analysis_collect_nframes_max);
616 if (_signal_analysis_collected_nframes == _signal_analysis_collect_nframes_max) {
617 _signal_analysis_collect_nframes_max = 0;
618 _signal_analysis_collected_nframes = 0;
620 AnalysisDataGathered(&_signal_analysis_inputs,
621 &_signal_analysis_outputs);
627 PluginInsert::silence (framecnt_t nframes)
633 ChanMapping in_map (natural_input_streams ());
634 ChanMapping out_map (natural_output_streams ());
636 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
637 (*i)->connect_and_run (_session.get_scratch_buffers ((*i)->get_info()->n_inputs, true), in_map, out_map, nframes, 0);
642 PluginInsert::run (BufferSet& bufs, framepos_t start_frame, framepos_t /*end_frame*/, pframes_t nframes, bool)
644 if (_pending_active) {
645 /* run as normal if we are active or moving from inactive to active */
647 if (_session.transport_rolling() || _session.bounce_processing()) {
648 automation_run (bufs, start_frame, nframes);
650 connect_and_run (bufs, nframes, 0, false);
654 // TODO use mapping in bypassed mode ?!
655 // -> do we bypass the processor or the plugin
657 uint32_t in = input_streams ().n_audio ();
658 uint32_t out = output_streams().n_audio ();
660 if (has_no_audio_inputs() || in == 0) {
662 /* silence all (audio) outputs. Should really declick
663 * at the transitions of "active"
666 for (uint32_t n = 0; n < out; ++n) {
667 bufs.get_audio (n).silence (nframes);
670 } else if (out > in) {
672 /* not active, but something has make up for any channel count increase
673 * for now , simply replicate last buffer
675 for (uint32_t n = in; n < out; ++n) {
676 bufs.get_audio(n).read_from(bufs.get_audio(in - 1), nframes);
680 bufs.count().set_audio (out);
683 _active = _pending_active;
685 /* we have no idea whether the plugin generated silence or not, so mark
686 * all buffers appropriately.
691 PluginInsert::automation_run (BufferSet& bufs, framepos_t start, pframes_t nframes)
693 Evoral::ControlEvent next_event (0, 0.0f);
694 framepos_t now = start;
695 framepos_t end = now + nframes;
696 framecnt_t offset = 0;
698 Glib::Threads::Mutex::Lock lm (control_lock(), Glib::Threads::TRY_LOCK);
701 connect_and_run (bufs, nframes, offset, false);
705 if (!find_next_event (now, end, next_event) || _plugins.front()->requires_fixed_sized_buffers()) {
707 /* no events have a time within the relevant range */
709 connect_and_run (bufs, nframes, offset, true, now);
715 framecnt_t cnt = min (((framecnt_t) ceil (next_event.when) - now), (framecnt_t) nframes);
717 connect_and_run (bufs, cnt, offset, true, now);
723 if (!find_next_event (now, end, next_event)) {
728 /* cleanup anything that is left to do */
731 connect_and_run (bufs, nframes, offset, true, now);
736 PluginInsert::default_parameter_value (const Evoral::Parameter& param)
738 if (param.type() != PluginAutomation)
741 if (_plugins.empty()) {
742 fatal << _("programming error: ") << X_("PluginInsert::default_parameter_value() called with no plugin")
744 abort(); /*NOTREACHED*/
747 return _plugins[0]->default_value (param.id());
752 PluginInsert::can_reset_all_parameters ()
756 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
758 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
760 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
764 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
770 if (ac->automation_state() & Play) {
775 return all && (params > 0);
779 PluginInsert::reset_parameters_to_default ()
783 for (uint32_t par = 0; par < _plugins[0]->parameter_count(); ++par) {
785 const uint32_t cid = _plugins[0]->nth_parameter (par, ok);
787 if (!ok || !_plugins[0]->parameter_is_input(cid)) {
791 const float dflt = _plugins[0]->default_value (cid);
792 const float curr = _plugins[0]->get_parameter (cid);
798 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter(PluginAutomation, 0, cid));
803 if (ac->automation_state() & Play) {
808 ac->set_value (dflt, Controllable::NoGroup);
813 boost::shared_ptr<Plugin>
814 PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
816 boost::shared_ptr<LadspaPlugin> lp;
817 boost::shared_ptr<LuaProc> lua;
819 boost::shared_ptr<LV2Plugin> lv2p;
821 #ifdef WINDOWS_VST_SUPPORT
822 boost::shared_ptr<WindowsVSTPlugin> vp;
825 boost::shared_ptr<LXVSTPlugin> lxvp;
827 #ifdef AUDIOUNIT_SUPPORT
828 boost::shared_ptr<AUPlugin> ap;
831 if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
832 return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
833 } else if ((lua = boost::dynamic_pointer_cast<LuaProc> (other)) != 0) {
834 return boost::shared_ptr<Plugin> (new LuaProc (*lua));
836 } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
837 return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
839 #ifdef WINDOWS_VST_SUPPORT
840 } else if ((vp = boost::dynamic_pointer_cast<WindowsVSTPlugin> (other)) != 0) {
841 return boost::shared_ptr<Plugin> (new WindowsVSTPlugin (*vp));
844 } else if ((lxvp = boost::dynamic_pointer_cast<LXVSTPlugin> (other)) != 0) {
845 return boost::shared_ptr<Plugin> (new LXVSTPlugin (*lxvp));
847 #ifdef AUDIOUNIT_SUPPORT
848 } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
849 return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
853 fatal << string_compose (_("programming error: %1"),
854 X_("unknown plugin type in PluginInsert::plugin_factory"))
856 abort(); /*NOTREACHED*/
857 return boost::shared_ptr<Plugin> ((Plugin*) 0);
861 PluginInsert::set_input_map (uint32_t num, ChanMapping m) {
862 if (num < _in_map.size()) {
863 bool changed = _in_map[num] != m;
866 PluginMapChanged (); /* EMIT SIGNAL */
872 PluginInsert::set_output_map (uint32_t num, ChanMapping m) {
873 if (num < _out_map.size()) {
874 bool changed = _out_map[num] != m;
877 PluginMapChanged (); /* EMIT SIGNAL */
883 PluginInsert::configure_io (ChanCount in, ChanCount out)
885 Match old_match = _match;
890 old_in = _configured_in;
891 old_out = _configured_out;
895 _configured_out = out;
897 /* get plugin configuration */
898 _match = private_can_support_io_configuration (in, out);
900 /* set the matching method and number of plugins that we will use to meet this configuration */
901 if (set_count (_match.plugins) == false) {
902 PluginIoReConfigure (); /* EMIT SIGNAL */
907 /* configure plugins */
908 switch (_match.method) {
911 if (_plugins.front()->configure_io (natural_input_streams(), out) == false) {
912 PluginIoReConfigure (); /* EMIT SIGNAL */
918 if (_match.strict_io) {
920 bool const r = _plugins.front()->can_support_io_configuration (in, dout);
922 if (_plugins.front()->configure_io (in, dout) == false) {
923 PluginIoReConfigure (); /* EMIT SIGNAL */
929 // no break -- fall through
931 if (_plugins.front()->configure_io (in, out) == false) {
932 PluginIoReConfigure (); /* EMIT SIGNAL */
939 bool mapping_changed = false;
940 if (old_in == in && old_out == out && _configured
941 && old_match.method == _match.method
942 && _in_map.size() == _out_map.size()
943 && _in_map.size() == get_count ()
945 /* If the configuraton has not changed, keep the mapping */
946 } else if (_match.custom_cfg && _configured) {
947 /* strip dead wood */
948 for (uint32_t pc = 0; pc < get_count(); ++pc) {
951 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
952 for (uint32_t i = 0; i < natural_input_streams().get (*t); ++i) {
954 uint32_t idx = _in_map[pc].get (*t, i, &valid);
955 if (valid && idx <= in.get (*t)) {
956 new_in.set (*t, i, idx);
959 for (uint32_t o = 0; o < natural_output_streams().get (*t); ++o) {
961 uint32_t idx = _out_map[pc].get (*t, o, &valid);
962 if (valid && idx <= out.get (*t)) {
963 new_out.set (*t, o, idx);
967 if (_in_map[pc] != new_in || _out_map[pc] != new_out) {
968 mapping_changed = true;
970 _in_map[pc] = new_in;
971 _out_map[pc] = new_out;
974 /* generate a new mapping */
978 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
979 if (_match.method == Split) {
980 _in_map[pc] = ChanMapping ();
981 /* connect inputs in round-robin fashion */
982 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
983 const uint32_t cend = _configured_in.get (*t);
984 if (cend == 0) { continue; }
986 for (uint32_t in = 0; in < natural_input_streams().get (*t); ++in) {
987 _in_map[pc].set (*t, in, c);
992 _in_map[pc] = ChanMapping (min (natural_input_streams (), in));
994 _out_map[pc] = ChanMapping (min (natural_output_streams(), out));
996 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
997 _in_map[pc].offset_to(*t, pc * natural_input_streams().get(*t));
998 _out_map[pc].offset_to(*t, pc * natural_output_streams().get(*t));
1000 mapping_changed = true;
1004 if (mapping_changed) {
1005 PluginMapChanged (); /* EMIT SIGNAL */
1008 cout << "----<<----\n";
1009 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i, ++pc) {
1010 cout << "Channel Map for " << name() << " plugin " << pc << "\n";
1011 cout << " * Inputs:\n" << _in_map[pc];
1012 cout << " * Outputs:\n" << _out_map[pc];
1014 cout << "---->>----\n";
1018 if (old_in != in || old_out != out
1019 || (old_match.method != _match.method && (old_match.method == Split || _match.method == Split))
1021 PluginIoReConfigure (); /* EMIT SIGNAL */
1024 // we don't know the analysis window size, so we must work with the
1025 // current buffer size here. each request for data fills in these
1026 // buffers and the analyser makes sure it gets enough data for the
1028 session().ensure_buffer_set (_signal_analysis_inputs, in);
1029 //_signal_analysis_inputs.set_count (in);
1031 session().ensure_buffer_set (_signal_analysis_outputs, out);
1032 //_signal_analysis_outputs.set_count (out);
1034 // std::cerr << "set counts to i" << in.n_audio() << "/o" << out.n_audio() << std::endl;
1037 return Processor::configure_io (in, out);
1040 /** Decide whether this PluginInsert can support a given IO configuration.
1041 * To do this, we run through a set of possible solutions in rough order of
1044 * @param in Required input channel count.
1045 * @param out Filled in with the output channel count if we return true.
1046 * @return true if the given IO configuration can be supported.
1049 PluginInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out)
1051 return private_can_support_io_configuration (in, out).method != Impossible;
1054 /** A private version of can_support_io_configuration which returns the method
1055 * by which the configuration can be matched, rather than just whether or not
1059 PluginInsert::private_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
1061 if (_plugins.empty()) {
1065 /* if a user specified a custom cfg, so be it. */
1068 return Match (ExactMatch, get_count(), false, true); // XXX
1071 /* try automatic configuration next */
1072 Match m = PluginInsert::automatic_can_support_io_configuration (inx, out);
1075 PluginInfoPtr info = _plugins.front()->get_info();
1076 ChanCount inputs = info->n_inputs;
1077 ChanCount outputs = info->n_outputs;
1078 ChanCount midi_bypass;
1080 /* handle case strict-i/o */
1081 if (_strict_io && m.method != Impossible) {
1084 /* special case MIDI instruments */
1085 if (is_midi_instrument()) {
1086 // output = midi-bypass + at most master-out channels.
1087 ChanCount max_out (DataType::AUDIO, 2); // TODO use master-out
1088 max_out.set (DataType::MIDI, out.get(DataType::MIDI));
1089 out = min (out, max_out);
1096 /* replicate processor to match output count (generators and such)
1097 * at least enough to feed every output port. */
1098 uint32_t f = 1; // at least one. e.g. control data filters, no in, no out.
1099 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1100 uint32_t nin = inputs.get (*t);
1101 if (nin == 0 || inx.get(*t) == 0) { continue; }
1102 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1105 return Match (Replicate, f);
1113 if (inx == out) { return m; }
1116 if (inx.get(DataType::MIDI) == 1
1117 && out.get (DataType::MIDI) == 0
1118 && outputs.get(DataType::MIDI) == 0) {
1119 out += ChanCount (DataType::MIDI, 1);
1124 if (m.method != Impossible) {
1128 if (info->reconfigurable_io()) {
1129 // houston, we have a problem.
1130 // TODO: match closest closes available config.
1131 // also handle strict_io
1132 return Match (Impossible, 0);
1135 // add at least as many plugins so that output count matches input count
1137 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1138 uint32_t nin = inputs.get (*t);
1139 uint32_t nout = outputs.get (*t);
1140 if (nin == 0 || inx.get(*t) == 0) { continue; }
1141 // prefer floor() so the count won't overly increase IFF (nin < nout)
1142 f = max (f, (uint32_t) floor (inx.get(*t) / (float)nout));
1144 if (f > 0 && outputs * f >= _configured_out) {
1146 return Match (Replicate, f);
1149 // add at least as many plugins needed to connect all inputs
1151 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1152 uint32_t nin = inputs.get (*t);
1153 if (nin == 0 || inx.get(*t) == 0) { continue; }
1154 f = max (f, (uint32_t) ceil (inx.get(*t) / (float)nin));
1157 return Match (Replicate, f);
1160 /* this is the original Ardour 3/4 behavior, mainly for backwards compatibility */
1162 PluginInsert::automatic_can_support_io_configuration (ChanCount const & inx, ChanCount& out) const
1164 if (_plugins.empty()) {
1168 PluginInfoPtr info = _plugins.front()->get_info();
1169 ChanCount in; in += inx;
1170 ChanCount midi_bypass;
1172 if (info->reconfigurable_io()) {
1173 /* Plugin has flexible I/O, so delegate to it */
1174 bool const r = _plugins.front()->can_support_io_configuration (in, out);
1176 return Match (Impossible, 0);
1179 return Match (Delegate, 1);
1182 ChanCount inputs = info->n_inputs;
1183 ChanCount outputs = info->n_outputs;
1185 if (in.get(DataType::MIDI) == 1 && outputs.get(DataType::MIDI) == 0) {
1186 DEBUG_TRACE ( DEBUG::Processors, string_compose ("bypassing midi-data around %1\n", name()));
1187 midi_bypass.set(DataType::MIDI, 1);
1189 if (in.get(DataType::MIDI) == 1 && inputs.get(DataType::MIDI) == 0) {
1190 DEBUG_TRACE ( DEBUG::Processors, string_compose ("hiding midi-port from plugin %1\n", name()));
1191 in.set(DataType::MIDI, 0);
1194 bool no_inputs = true;
1195 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1196 if (inputs.get (*t) != 0) {
1203 /* no inputs so we can take any input configuration since we throw it away */
1204 out = outputs + midi_bypass;
1205 return Match (NoInputs, 1);
1208 /* Plugin inputs match requested inputs exactly */
1210 out = outputs + midi_bypass;
1211 return Match (ExactMatch, 1);
1214 /* We may be able to run more than one copy of the plugin within this insert
1215 to cope with the insert having more inputs than the plugin.
1216 We allow replication only for plugins with either zero or 1 inputs and outputs
1217 for every valid data type.
1221 bool can_replicate = true;
1222 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1224 uint32_t nin = inputs.get (*t);
1226 // No inputs of this type
1227 if (nin == 0 && in.get(*t) == 0) {
1231 if (nin != 1 || outputs.get (*t) != 1) {
1232 can_replicate = false;
1236 // Potential factor not set yet
1238 f = in.get(*t) / nin;
1241 // Factor for this type does not match another type, can not replicate
1242 if (f != (in.get(*t) / nin)) {
1243 can_replicate = false;
1248 if (can_replicate) {
1249 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1250 out.set (*t, outputs.get(*t) * f);
1253 return Match (Replicate, f);
1256 /* If the processor has exactly one input of a given type, and
1257 the plugin has more, we can feed the single processor input
1258 to some or all of the plugin inputs. This is rather
1259 special-case-y, but the 1-to-many case is by far the
1260 simplest. How do I split thy 2 processor inputs to 3
1261 plugin inputs? Let me count the ways ...
1264 bool can_split = true;
1265 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1267 bool const can_split_type = (in.get (*t) == 1 && inputs.get (*t) > 1);
1268 bool const nothing_to_do_for_type = (in.get (*t) == 0 && inputs.get (*t) == 0);
1270 if (!can_split_type && !nothing_to_do_for_type) {
1276 out = outputs + midi_bypass;
1277 return Match (Split, 1);
1280 /* If the plugin has more inputs than we want, we can `hide' some of them
1281 by feeding them silence.
1284 bool could_hide = false;
1285 bool cannot_hide = false;
1286 ChanCount hide_channels;
1288 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
1289 if (inputs.get(*t) > in.get(*t)) {
1290 /* there is potential to hide, since the plugin has more inputs of type t than the insert */
1291 hide_channels.set (*t, inputs.get(*t) - in.get(*t));
1293 } else if (inputs.get(*t) < in.get(*t)) {
1294 /* we definitely cannot hide, since the plugin has fewer inputs of type t than the insert */
1299 if (could_hide && !cannot_hide) {
1300 out = outputs + midi_bypass;
1301 return Match (Hide, 1, false, false, hide_channels);
1304 midi_bypass.reset();
1305 return Match (Impossible, 0);
1310 PluginInsert::get_state ()
1312 return state (true);
1316 PluginInsert::state (bool full)
1318 XMLNode& node = Processor::state (full);
1320 node.add_property("type", _plugins[0]->state_node_name());
1321 node.add_property("unique-id", _plugins[0]->unique_id());
1322 node.add_property("count", string_compose("%1", _plugins.size()));
1324 /* remember actual i/o configuration (for later placeholder
1325 * in case the plugin goes missing) */
1326 node.add_child_nocopy (* _configured_in.state (X_("ConfiguredInput")));
1327 node.add_child_nocopy (* _configured_out.state (X_("ConfiguredOutput")));
1329 /* save custom i/o config */
1330 node.add_property("custom", _custom_cfg ? "yes" : "no");
1332 assert (_custom_out == _configured_out); // redundant
1333 for (uint32_t pc = 0; pc < get_count(); ++pc) {
1334 // TODO save _in_map[pc], _out_map[pc]
1338 _plugins[0]->set_insert_id(this->id());
1339 node.add_child_nocopy (_plugins[0]->get_state());
1341 for (Controls::iterator c = controls().begin(); c != controls().end(); ++c) {
1342 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> ((*c).second);
1344 node.add_child_nocopy (ac->get_state());
1352 PluginInsert::set_control_ids (const XMLNode& node, int version)
1354 const XMLNodeList& nlist = node.children();
1355 XMLNodeConstIterator iter;
1356 set<Evoral::Parameter>::const_iterator p;
1358 for (iter = nlist.begin(); iter != nlist.end(); ++iter) {
1359 if ((*iter)->name() == Controllable::xml_node_name) {
1360 const XMLProperty* prop;
1362 uint32_t p = (uint32_t)-1;
1364 if ((prop = (*iter)->property (X_("symbol"))) != 0) {
1365 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugins[0]);
1367 p = lv2plugin->port_index(prop->value().c_str());
1371 if (p == (uint32_t)-1 && (prop = (*iter)->property (X_("parameter"))) != 0) {
1372 p = atoi (prop->value());
1375 if (p != (uint32_t)-1) {
1377 /* this may create the new controllable */
1379 boost::shared_ptr<Evoral::Control> c = control (Evoral::Parameter (PluginAutomation, 0, p));
1381 #ifndef NO_PLUGIN_STATE
1385 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (c);
1387 ac->set_state (**iter, version);
1396 PluginInsert::set_state(const XMLNode& node, int version)
1398 XMLNodeList nlist = node.children();
1399 XMLNodeIterator niter;
1400 XMLPropertyList plist;
1401 const XMLProperty *prop;
1402 ARDOUR::PluginType type;
1404 if ((prop = node.property ("type")) == 0) {
1405 error << _("XML node describing plugin is missing the `type' field") << endmsg;
1409 if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */
1410 type = ARDOUR::LADSPA;
1411 } else if (prop->value() == X_("lv2")) {
1413 } else if (prop->value() == X_("windows-vst")) {
1414 type = ARDOUR::Windows_VST;
1415 } else if (prop->value() == X_("lxvst")) {
1416 type = ARDOUR::LXVST;
1417 } else if (prop->value() == X_("audiounit")) {
1418 type = ARDOUR::AudioUnit;
1419 } else if (prop->value() == X_("luaproc")) {
1422 error << string_compose (_("unknown plugin type %1 in plugin insert state"),
1428 prop = node.property ("unique-id");
1431 #ifdef WINDOWS_VST_SUPPORT
1432 /* older sessions contain VST plugins with only an "id" field.
1435 if (type == ARDOUR::Windows_VST) {
1436 prop = node.property ("id");
1440 #ifdef LXVST_SUPPORT
1441 /*There shouldn't be any older sessions with linuxVST support.. but anyway..*/
1443 if (type == ARDOUR::LXVST) {
1444 prop = node.property ("id");
1450 error << _("Plugin has no unique ID field") << endmsg;
1455 boost::shared_ptr<Plugin> plugin = find_plugin (_session, prop->value(), type);
1457 /* treat linux and windows VST plugins equivalent if they have the same uniqueID
1458 * allow to move sessions windows <> linux */
1459 #ifdef LXVST_SUPPORT
1460 if (plugin == 0 && type == ARDOUR::Windows_VST) {
1461 type = ARDOUR::LXVST;
1462 plugin = find_plugin (_session, prop->value(), type);
1466 #ifdef WINDOWS_VST_SUPPORT
1467 if (plugin == 0 && type == ARDOUR::LXVST) {
1468 type = ARDOUR::Windows_VST;
1469 plugin = find_plugin (_session, prop->value(), type);
1474 error << string_compose(
1475 _("Found a reference to a plugin (\"%1\") that is unknown.\n"
1476 "Perhaps it was removed or moved since it was last used."),
1482 if (type == ARDOUR::Lua) {
1483 XMLNode *ls = node.child (plugin->state_node_name().c_str());
1484 // we need to load the script to set the name and parameters.
1485 boost::shared_ptr<LuaProc> lp = boost::dynamic_pointer_cast<LuaProc>(plugin);
1487 lp->set_script_from_state (*ls);
1491 // The name of the PluginInsert comes from the plugin, nothing else
1492 _name = plugin->get_info()->name;
1496 // Processor::set_state() will set this, but too late
1497 // for it to be available when setting up plugin
1498 // state. We can't call Processor::set_state() until
1499 // the plugins themselves are created and added.
1503 if (_plugins.empty()) {
1504 /* if we are adding the first plugin, we will need to set
1505 up automatable controls.
1507 add_plugin (plugin);
1508 create_automatable_parameters ();
1509 set_control_ids (node, version);
1512 if ((prop = node.property ("count")) != 0) {
1513 sscanf (prop->value().c_str(), "%u", &count);
1516 if (_plugins.size() != count) {
1517 for (uint32_t n = 1; n < count; ++n) {
1518 add_plugin (plugin_factory (plugin));
1522 Processor::set_state (node, version);
1524 PBD::ID new_id = this->id();
1525 PBD::ID old_id = this->id();
1527 if ((prop = node.property ("id")) != 0) {
1528 old_id = prop->value ();
1531 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1533 /* find the node with the type-specific node name ("lv2", "ladspa", etc)
1534 and set all plugins to the same state.
1537 if ((*niter)->name() == plugin->state_node_name()) {
1539 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
1540 /* Plugin state can include external files which are named after the ID.
1542 * If regenerate_xml_or_string_ids() is set, the ID will already have
1543 * been changed, so we need to use the old ID from the XML to load the
1544 * state and then update the ID.
1546 * When copying a plugin-state, route_ui takes care of of updating the ID,
1547 * but we need to call set_insert_id() to clear the cached plugin-state
1548 * and force a change.
1550 if (!regenerate_xml_or_string_ids ()) {
1551 (*i)->set_insert_id (new_id);
1553 (*i)->set_insert_id (old_id);
1556 (*i)->set_state (**niter, version);
1558 if (regenerate_xml_or_string_ids ()) {
1559 (*i)->set_insert_id (new_id);
1567 if (version < 3000) {
1569 /* Only 2.X sessions need a call to set_parameter_state() - in 3.X and above
1570 this is all handled by Automatable
1573 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1574 if ((*niter)->name() == "Redirect") {
1575 /* XXX do we need to tackle placement? i think not (pd; oct 16 2009) */
1576 Processor::set_state (**niter, version);
1581 set_parameter_state_2X (node, version);
1584 if ((prop = node.property (X_("custom"))) != 0) {
1585 _custom_cfg = string_is_affirmative (prop->value());
1588 XMLNodeList kids = node.children ();
1589 for (XMLNodeIterator i = kids.begin(); i != kids.end(); ++i) {
1590 if ((*i)->name() == X_("ConfiguredOutput")) {
1591 _custom_out = ChanCount(**i);
1593 // TODO restore mappings for all 0 .. count.
1598 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
1602 (*i)->deactivate ();
1610 PluginInsert::update_id (PBD::ID id)
1613 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
1614 (*i)->set_insert_id (id);
1619 PluginInsert::set_state_dir (const std::string& d)
1621 // state() only saves the state of the first plugin
1622 _plugins[0]->set_state_dir (d);
1626 PluginInsert::set_parameter_state_2X (const XMLNode& node, int version)
1628 XMLNodeList nlist = node.children();
1629 XMLNodeIterator niter;
1631 /* look for port automation node */
1633 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1635 if ((*niter)->name() != port_automation_node_name) {
1641 XMLNodeConstIterator iter;
1646 cnodes = (*niter)->children ("port");
1648 for (iter = cnodes.begin(); iter != cnodes.end(); ++iter){
1652 if ((cprop = child->property("number")) != 0) {
1653 port = cprop->value().c_str();
1655 warning << _("PluginInsert: Auto: no ladspa port number") << endmsg;
1659 sscanf (port, "%" PRIu32, &port_id);
1661 if (port_id >= _plugins[0]->parameter_count()) {
1662 warning << _("PluginInsert: Auto: port id out of range") << endmsg;
1666 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(
1667 control(Evoral::Parameter(PluginAutomation, 0, port_id), true));
1669 if (c && c->alist()) {
1670 if (!child->children().empty()) {
1671 c->alist()->set_state (*child->children().front(), version);
1673 /* In some cases 2.X saves lists with min_yval and max_yval
1674 being FLT_MIN and FLT_MAX respectively. This causes problems
1675 in A3 because these min/max values are used to compute
1676 where GUI control points should be drawn. If we see such
1677 values, `correct' them to the min/max of the appropriate
1681 float min_y = c->alist()->get_min_y ();
1682 float max_y = c->alist()->get_max_y ();
1684 ParameterDescriptor desc;
1685 _plugins.front()->get_parameter_descriptor (port_id, desc);
1687 if (min_y == FLT_MIN) {
1691 if (max_y == FLT_MAX) {
1695 c->alist()->set_yrange (min_y, max_y);
1698 error << string_compose (_("PluginInsert: automatable control %1 not found - ignored"), port_id) << endmsg;
1710 PluginInsert::describe_parameter (Evoral::Parameter param)
1712 if (param.type() == PluginAutomation) {
1713 return _plugins[0]->describe_parameter (param);
1714 } else if (param.type() == PluginPropertyAutomation) {
1715 boost::shared_ptr<AutomationControl> c(automation_control(param));
1716 if (c && !c->desc().label.empty()) {
1717 return c->desc().label;
1720 return Automatable::describe_parameter(param);
1724 PluginInsert::signal_latency() const
1726 if (_user_latency) {
1727 return _user_latency;
1730 return _plugins[0]->signal_latency ();
1734 PluginInsert::type ()
1736 return plugin()->get_info()->type;
1739 PluginInsert::PluginControl::PluginControl (PluginInsert* p,
1740 const Evoral::Parameter& param,
1741 const ParameterDescriptor& desc,
1742 boost::shared_ptr<AutomationList> list)
1743 : AutomationControl (p->session(), param, desc, list, p->describe_parameter(param))
1747 alist()->reset_default (desc.normal);
1749 list->set_interpolation(Evoral::ControlList::Discrete);
1754 set_flags(Controllable::Toggle);
1758 /** @param val `user' value */
1760 PluginInsert::PluginControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override)
1763 _set_value (user_val, group_override);
1767 PluginInsert::PluginControl::set_value_unchecked (double user_val)
1769 /* used only by automation playback */
1770 _set_value (user_val, Controllable::NoGroup);
1774 PluginInsert::PluginControl::_set_value (double user_val, PBD::Controllable::GroupControlDisposition group_override)
1776 /* FIXME: probably should be taking out some lock here.. */
1778 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
1779 (*i)->set_parameter (_list->parameter().id(), user_val);
1782 boost::shared_ptr<Plugin> iasp = _plugin->_impulseAnalysisPlugin.lock();
1784 iasp->set_parameter (_list->parameter().id(), user_val);
1787 AutomationControl::set_value (user_val, group_override);
1791 PluginInsert::PluginControl::catch_up_with_external_value (double user_val)
1793 AutomationControl::set_value (user_val, Controllable::NoGroup);
1797 PluginInsert::PluginControl::get_state ()
1801 XMLNode& node (AutomationControl::get_state());
1802 ss << parameter().id();
1803 node.add_property (X_("parameter"), ss.str());
1805 boost::shared_ptr<LV2Plugin> lv2plugin = boost::dynamic_pointer_cast<LV2Plugin> (_plugin->_plugins[0]);
1807 node.add_property (X_("symbol"), lv2plugin->port_symbol (parameter().id()));
1814 /** @return `user' val */
1816 PluginInsert::PluginControl::get_value () const
1818 boost::shared_ptr<Plugin> plugin = _plugin->plugin (0);
1824 return plugin->get_parameter (_list->parameter().id());
1827 PluginInsert::PluginPropertyControl::PluginPropertyControl (PluginInsert* p,
1828 const Evoral::Parameter& param,
1829 const ParameterDescriptor& desc,
1830 boost::shared_ptr<AutomationList> list)
1831 : AutomationControl (p->session(), param, desc, list)
1835 alist()->set_yrange (desc.lower, desc.upper);
1836 alist()->reset_default (desc.normal);
1840 set_flags(Controllable::Toggle);
1845 PluginInsert::PluginPropertyControl::set_value (double user_val, PBD::Controllable::GroupControlDisposition /* group_override*/)
1848 set_value_unchecked (user_val);
1853 PluginInsert::PluginPropertyControl::set_value_unchecked (double user_val)
1855 /* Old numeric set_value(), coerce to appropriate datatype if possible.
1856 This is lossy, but better than nothing until Ardour's automation system
1857 can handle various datatypes all the way down. */
1858 const Variant value(_desc.datatype, user_val);
1859 if (value.type() == Variant::NOTHING) {
1860 error << "set_value(double) called for non-numeric property" << endmsg;
1864 for (Plugins::iterator i = _plugin->_plugins.begin(); i != _plugin->_plugins.end(); ++i) {
1865 (*i)->set_property(_list->parameter().id(), value);
1869 AutomationControl::set_value (user_val, Controllable::NoGroup);
1873 PluginInsert::PluginPropertyControl::get_state ()
1877 XMLNode& node (AutomationControl::get_state());
1878 ss << parameter().id();
1879 node.add_property (X_("property"), ss.str());
1880 node.remove_property (X_("value"));
1886 PluginInsert::PluginPropertyControl::get_value () const
1888 return _value.to_double();
1891 boost::shared_ptr<Plugin>
1892 PluginInsert::get_impulse_analysis_plugin()
1894 boost::shared_ptr<Plugin> ret;
1895 if (_impulseAnalysisPlugin.expired()) {
1896 ret = plugin_factory(_plugins[0]);
1897 ret->configure_io (internal_input_streams (), internal_output_streams ());
1898 _impulseAnalysisPlugin = ret;
1900 ret = _impulseAnalysisPlugin.lock();
1907 PluginInsert::collect_signal_for_analysis (framecnt_t nframes)
1909 // called from outside the audio thread, so this should be safe
1910 // only do audio as analysis is (currently) only for audio plugins
1911 _signal_analysis_inputs.ensure_buffers( DataType::AUDIO, internal_input_streams().n_audio(), nframes);
1912 _signal_analysis_outputs.ensure_buffers( DataType::AUDIO, internal_output_streams().n_audio(), nframes);
1914 _signal_analysis_collected_nframes = 0;
1915 _signal_analysis_collect_nframes_max = nframes;
1918 /** Add a plugin to our list */
1920 PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
1922 plugin->set_insert_id (this->id());
1924 if (_plugins.empty()) {
1925 /* first (and probably only) plugin instance - connect to relevant signals
1928 plugin->ParameterChangedExternally.connect_same_thread (*this, boost::bind (&PluginInsert::parameter_changed_externally, this, _1, _2));
1929 plugin->StartTouch.connect_same_thread (*this, boost::bind (&PluginInsert::start_touch, this, _1));
1930 plugin->EndTouch.connect_same_thread (*this, boost::bind (&PluginInsert::end_touch, this, _1));
1933 _plugins.push_back (plugin);
1937 PluginInsert::realtime_handle_transport_stopped ()
1939 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
1940 (*i)->realtime_handle_transport_stopped ();
1945 PluginInsert::realtime_locate ()
1947 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
1948 (*i)->realtime_locate ();
1953 PluginInsert::monitoring_changed ()
1955 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
1956 (*i)->monitoring_changed ();
1961 PluginInsert::start_touch (uint32_t param_id)
1963 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
1965 ac->start_touch (session().audible_frame());
1970 PluginInsert::end_touch (uint32_t param_id)
1972 boost::shared_ptr<AutomationControl> ac = automation_control (Evoral::Parameter (PluginAutomation, 0, param_id));
1974 ac->stop_touch (true, session().audible_frame());