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"
27 #include "pbd/failed_constructor.h"
28 #include "pbd/xml++.h"
29 #include "pbd/convert.h"
31 #include "ardour/audio_buffer.h"
32 #include "ardour/automation_list.h"
33 #include "ardour/buffer_set.h"
34 #include "ardour/event_type_map.h"
35 #include "ardour/ladspa_plugin.h"
36 #include "ardour/plugin.h"
37 #include "ardour/plugin_insert.h"
38 #include "ardour/port.h"
39 #include "ardour/route.h"
42 #include "ardour/lv2_plugin.h"
46 #include "ardour/vst_plugin.h"
49 #ifdef HAVE_AUDIOUNITS
50 #include "ardour/audio_unit.h"
53 #include "ardour/audioengine.h"
54 #include "ardour/session.h"
55 #include "ardour/types.h"
60 using namespace ARDOUR;
63 const string PluginInsert::port_automation_node_name = "PortAutomation";
65 PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug)
66 : Processor (s, (plug ? plug->name() : string ("toBeRenamed")))
67 , _signal_analysis_collected_nframes(0)
68 , _signal_analysis_collect_nframes_max(0)
71 /* the first is the master */
74 _plugins.push_back (plug);
77 Glib::Mutex::Lock em (_session.engine().process_lock());
78 IO::PortCountChanged (max(input_streams(), output_streams()));
83 PluginInsert::set_count (uint32_t num)
85 bool require_state = !_plugins.empty();
87 /* this is a bad idea.... we shouldn't do this while active.
88 only a route holding their redirect_lock should be calling this
93 } else if (num > _plugins.size()) {
94 uint32_t diff = num - _plugins.size();
96 for (uint32_t n = 0; n < diff; ++n) {
97 add_plugin_with_activation (_plugins[0]);
100 /* XXX do something */
104 } else if (num < _plugins.size()) {
105 uint32_t diff = _plugins.size() - num;
106 for (uint32_t n= 0; n < diff; ++n) {
114 PluginInsert::~PluginInsert ()
119 PluginInsert::control_list_automation_state_changed (Evoral::Parameter which, AutoState s)
121 if (which.type() != PluginAutomation)
124 boost::shared_ptr<AutomationControl> c
125 = boost::dynamic_pointer_cast<AutomationControl>(control (which));
128 _plugins[0]->set_parameter (which.id(), c->list()->eval (_session.transport_frame()));
133 PluginInsert::output_streams() const
135 ChanCount out = _plugins.front()->get_info()->n_outputs;
137 if (out == ChanCount::INFINITE) {
138 return _plugins.front()->output_streams ();
140 out.set_audio (out.n_audio() * _plugins.size());
141 out.set_midi (out.n_midi() * _plugins.size());
147 PluginInsert::input_streams() const
149 ChanCount in = _plugins[0]->get_info()->n_inputs;
153 /* we are splitting 1 processor input to multiple plugin inputs,
154 so we have a maximum of 1 stream of each type.
156 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
157 if (in.get (*t) > 1) {
163 } else if (in == ChanCount::INFINITE) {
164 return _plugins[0]->input_streams ();
166 in.set_audio (in.n_audio() * _plugins.size());
167 in.set_midi (in.n_midi() * _plugins.size());
173 PluginInsert::natural_output_streams() const
175 return _plugins[0]->get_info()->n_outputs;
179 PluginInsert::natural_input_streams() const
181 return _plugins[0]->get_info()->n_inputs;
185 PluginInsert::is_generator() const
187 /* XXX more finesse is possible here. VST plugins have a
188 a specific "instrument" flag, for example.
191 return _plugins[0]->get_info()->n_inputs.n_audio() == 0;
195 PluginInsert::set_automatable ()
197 set<Evoral::Parameter> a = _plugins.front()->automatable ();
199 Plugin::ParameterDescriptor desc;
201 for (set<Evoral::Parameter>::iterator i = a.begin(); i != a.end(); ++i) {
202 if (i->type() == PluginAutomation) {
204 Evoral::Parameter param(*i);
206 _plugins.front()->get_parameter_descriptor(i->id(), desc);
208 /* the Parameter belonging to the actual plugin doesn't have its range set
209 but we want the Controllable related to this Parameter to have those limits.
212 param.set_range (desc.lower, desc.upper, _plugins.front()->default_value(i->id()), desc.toggled);
213 can_automate (param);
214 boost::shared_ptr<AutomationList> list(new AutomationList(param));
215 add_control (boost::shared_ptr<AutomationControl> (new PluginControl(this, param, list)));
221 PluginInsert::parameter_changed (Evoral::Parameter which, float val)
223 if (which.type() != PluginAutomation)
226 Plugins::iterator i = _plugins.begin();
228 /* don't set the first plugin, just all the slaves */
230 if (i != _plugins.end()) {
232 for (; i != _plugins.end(); ++i) {
233 (*i)->set_parameter (which, val);
239 PluginInsert::set_block_size (pframes_t nframes)
242 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
243 if ((*i)->set_block_size (nframes) != 0) {
251 PluginInsert::activate ()
253 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
257 Processor::activate ();
261 PluginInsert::deactivate ()
263 Processor::deactivate ();
265 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
271 PluginInsert::flush ()
273 for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
279 PluginInsert::connect_and_run (BufferSet& bufs, pframes_t nframes, framecnt_t offset, bool with_auto, framepos_t now)
281 // Calculate if, and how many frames we need to collect for analysis
282 framecnt_t collect_signal_nframes = (_signal_analysis_collect_nframes_max -
283 _signal_analysis_collected_nframes);
284 if (nframes < collect_signal_nframes) { // we might not get all frames now
285 collect_signal_nframes = nframes;
288 ChanMapping in_map(input_streams());
289 ChanMapping out_map(output_streams());
292 /* fix the input mapping so that we have maps for each of the plugin's inputs */
293 in_map = ChanMapping (natural_input_streams ());
295 /* copy the first stream's buffer contents to the others */
296 /* XXX: audio only */
297 Sample const * mono = bufs.get_audio (in_map.get (DataType::AUDIO, 0)).data (offset);
298 for (uint32_t i = input_streams().n_audio(); i < natural_input_streams().n_audio(); ++i) {
299 memcpy (bufs.get_audio (in_map.get (DataType::AUDIO, i)).data() + offset, mono + offset, sizeof (Sample) * (nframes - offset));
303 /* Note that we've already required that plugins
304 be able to handle in-place processing.
311 for (Controls::iterator li = controls().begin(); li != controls().end(); ++li, ++n) {
313 boost::shared_ptr<AutomationControl> c
314 = boost::dynamic_pointer_cast<AutomationControl>(li->second);
316 if (c->parameter().type() == PluginAutomation && c->automation_playback()) {
319 const float val = c->list()->rt_safe_eval (now, valid);
329 if (collect_signal_nframes > 0) {
331 //std::cerr << "collect input, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
332 //std::cerr << " streams " << input_streams().n_audio() << std::endl;
333 //std::cerr << "filling buffer with " << collect_signal_nframes << " frames at " << _signal_analysis_collected_nframes << std::endl;
335 _signal_analysis_inputs.set_count(input_streams());
337 for (uint32_t i = 0; i < input_streams().n_audio(); ++i) {
338 _signal_analysis_inputs.get_audio(i).read_from(
340 collect_signal_nframes,
341 _signal_analysis_collected_nframes); // offset is for target buffer
346 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
347 (*i)->connect_and_run(bufs, in_map, out_map, nframes, offset);
348 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
349 in_map.offset_to(*t, natural_input_streams().get(*t));
350 out_map.offset_to(*t, natural_output_streams().get(*t));
354 if (collect_signal_nframes > 0) {
356 //std::cerr << " output, bufs " << bufs.count().n_audio() << " count, " << bufs.available().n_audio() << " available" << std::endl;
357 //std::cerr << " streams " << output_streams().n_audio() << std::endl;
359 _signal_analysis_outputs.set_count(output_streams());
361 for (uint32_t i = 0; i < output_streams().n_audio(); ++i) {
362 _signal_analysis_outputs.get_audio(i).read_from(
364 collect_signal_nframes,
365 _signal_analysis_collected_nframes); // offset is for target buffer
368 _signal_analysis_collected_nframes += collect_signal_nframes;
369 assert(_signal_analysis_collected_nframes <= _signal_analysis_collect_nframes_max);
371 if (_signal_analysis_collected_nframes == _signal_analysis_collect_nframes_max) {
372 _signal_analysis_collect_nframes_max = 0;
373 _signal_analysis_collected_nframes = 0;
375 AnalysisDataGathered(&_signal_analysis_inputs,
376 &_signal_analysis_outputs);
379 /* leave remaining channel buffers alone */
383 PluginInsert::silence (framecnt_t nframes)
389 ChanMapping in_map(input_streams());
390 ChanMapping out_map(output_streams());
393 /* fix the input mapping so that we have maps for each of the plugin's inputs */
394 in_map = ChanMapping (natural_input_streams ());
397 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
398 (*i)->connect_and_run (_session.get_silent_buffers ((*i)->get_info()->n_inputs), in_map, out_map, nframes, 0);
403 PluginInsert::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t nframes, bool)
405 if (_pending_active) {
406 /* run as normal if we are active or moving from inactive to active */
408 if (_session.transport_rolling()) {
409 automation_run (bufs, nframes);
411 connect_and_run (bufs, nframes, 0, false);
416 /* FIXME: type, audio only */
418 uint32_t in = _plugins[0]->get_info()->n_inputs.n_audio();
419 uint32_t out = _plugins[0]->get_info()->n_outputs.n_audio();
423 /* not active, but something has make up for any channel count increase */
425 for (uint32_t n = out - in; n < out; ++n) {
426 memcpy (bufs.get_audio(n).data(), bufs.get_audio(in - 1).data(), sizeof (Sample) * nframes);
430 bufs.count().set_audio(out);
433 _active = _pending_active;
437 PluginInsert::set_parameter (Evoral::Parameter param, float val)
439 if (param.type() != PluginAutomation) {
443 /* the others will be set from the event triggered by this */
445 _plugins[0]->set_parameter (param.id(), val);
447 boost::shared_ptr<AutomationControl> ac
448 = boost::dynamic_pointer_cast<AutomationControl>(control(param));
453 warning << "set_parameter called for nonexistant parameter "
454 << EventTypeMap::instance().to_symbol(param) << endmsg;
457 _session.set_dirty();
461 PluginInsert::get_parameter (Evoral::Parameter param)
463 if (param.type() != PluginAutomation) {
466 assert (!_plugins.empty ());
467 return _plugins[0]->get_parameter (param.id());
472 PluginInsert::automation_run (BufferSet& bufs, pframes_t nframes)
474 Evoral::ControlEvent next_event (0, 0.0f);
475 framepos_t now = _session.transport_frame ();
476 framepos_t end = now + nframes;
477 framecnt_t offset = 0;
479 Glib::Mutex::Lock lm (control_lock(), Glib::TRY_LOCK);
482 connect_and_run (bufs, nframes, offset, false);
486 if (!find_next_event (now, end, next_event) || requires_fixed_sized_buffers()) {
488 /* no events have a time within the relevant range */
490 connect_and_run (bufs, nframes, offset, true, now);
496 framecnt_t cnt = min (((framecnt_t) ceil (next_event.when) - now), (framecnt_t) nframes);
498 connect_and_run (bufs, cnt, offset, true, now);
504 if (!find_next_event (now, end, next_event)) {
509 /* cleanup anything that is left to do */
512 connect_and_run (bufs, nframes, offset, true, now);
517 PluginInsert::default_parameter_value (const Evoral::Parameter& param)
519 if (param.type() != PluginAutomation)
522 if (_plugins.empty()) {
523 fatal << _("programming error: ") << X_("PluginInsert::default_parameter_value() called with no plugin")
528 return _plugins[0]->default_value (param.id());
531 boost::shared_ptr<Plugin>
532 PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
534 boost::shared_ptr<LadspaPlugin> lp;
536 boost::shared_ptr<LV2Plugin> lv2p;
539 boost::shared_ptr<VSTPlugin> vp;
541 #ifdef HAVE_AUDIOUNITS
542 boost::shared_ptr<AUPlugin> ap;
545 if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
546 return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
548 } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
549 return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
552 } else if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (other)) != 0) {
553 return boost::shared_ptr<Plugin> (new VSTPlugin (*vp));
555 #ifdef HAVE_AUDIOUNITS
556 } else if ((ap = boost::dynamic_pointer_cast<AUPlugin> (other)) != 0) {
557 return boost::shared_ptr<Plugin> (new AUPlugin (*ap));
561 fatal << string_compose (_("programming error: %1"),
562 X_("unknown plugin type in PluginInsert::plugin_factory"))
565 return boost::shared_ptr<Plugin> ((Plugin*) 0);
569 PluginInsert::configure_io (ChanCount in, ChanCount out)
571 if (set_count (count_for_configuration (in, out)) == false) {
572 set_splitting (false);
576 if (_plugins.front()->get_info()->n_inputs <= in) {
577 set_splitting (false);
578 if (_plugins.front()->configure_io (in, out) == false) {
582 /* we must be splitting a single processor input to
583 multiple plugin inputs
585 set_splitting (true);
586 _plugins.front()->configure_io (_plugins.front()->get_info()->n_inputs, out);
589 // we don't know the analysis window size, so we must work with the
590 // current buffer size here. each request for data fills in these
591 // buffers and the analyser makes sure it gets enough data for the
593 session().ensure_buffer_set (_signal_analysis_inputs, in);
594 //_signal_analysis_inputs.set_count (in);
596 session().ensure_buffer_set (_signal_analysis_outputs, out);
597 //_signal_analysis_outputs.set_count (out);
599 // std::cerr << "set counts to i" << in.n_audio() << "/o" << out.n_audio() << std::endl;
601 return Processor::configure_io (in, out);
605 PluginInsert::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
607 // Plugin has flexible I/O, so delegate to it
608 if (_plugins.front()->reconfigurable_io()) {
609 return _plugins.front()->can_support_io_configuration (in, out);
612 ChanCount inputs = _plugins[0]->get_info()->n_inputs;
613 ChanCount outputs = _plugins[0]->get_info()->n_outputs;
615 // Plugin inputs match requested inputs exactly
621 // See if replication is possible
622 // We can replicate if there exists a single factor f such that, for every type,
623 // the number of plugin inputs * f = the requested number of inputs
625 bool can_replicate = true;
626 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
627 // No inputs of this type
628 if (inputs.get(*t) == 0 && in.get(*t) == 0) {
631 // Plugin has more inputs than requested, can not replicate
632 } else if (inputs.get(*t) >= in.get(*t)) {
633 can_replicate = false;
636 // Plugin inputs is not a factor of requested inputs, can not replicate
637 } else if (inputs.get(*t) == 0 || in.get(*t) % inputs.get(*t) != 0) {
638 can_replicate = false;
641 // Potential factor not set yet
643 f = in.get(*t) / inputs.get(*t);;
646 // Factor for this type does not match another type, can not replicate
647 if (f != (in.get(*t) / inputs.get(*t))) {
648 can_replicate = false;
654 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
655 out.set (*t, outputs.get(*t) * f);
660 /* If the processor has exactly one input of a given type, and
661 the plugin has more, we can feed the single processor input
662 to some or all of the plugin inputs. This is rather
663 special-case-y, but the 1-to-many case is by far the
664 simplest. How do I split thy 2 processor inputs to 3
665 plugin inputs? Let me count the ways ...
668 bool can_split = true;
669 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
671 bool const can_split_type = (in.get (*t) == 1 && inputs.get (*t) > 1);
672 bool const nothing_to_do_for_type = (in.get (*t) == 0 && inputs.get (*t) == 0);
674 if (!can_split_type && !nothing_to_do_for_type) {
687 /* Number of plugin instances required to support a given channel configuration.
691 PluginInsert::count_for_configuration (ChanCount in, ChanCount /*out*/) const
693 if (_plugins.front()->reconfigurable_io()) {
694 /* plugin has flexible I/O, so the answer is always 1 */
695 /* this could change if we ever decide to replicate AU's */
699 // FIXME: take 'out' into consideration
701 ChanCount outputs = _plugins[0]->get_info()->n_outputs;
702 ChanCount inputs = _plugins[0]->get_info()->n_inputs;
704 if (inputs.n_total() == 0) {
705 /* instrument plugin, always legal, but throws away any existing streams */
709 if (inputs.n_total() == 1 && outputs == inputs
710 && ((inputs.n_audio() == 0 && in.n_audio() == 0)
711 || (inputs.n_midi() == 0 && in.n_midi() == 0))) {
712 /* mono plugin, replicate as needed to match in */
722 /* more plugin inputs than processor inputs, so we are splitting */
726 // assumes in is valid, so we must be replicating
727 if (inputs.n_total() < in.n_total()
728 && (in.n_total() % inputs.n_total() == 0)) {
730 return in.n_total() / inputs.n_total();
738 PluginInsert::get_state(void)
744 PluginInsert::state (bool full)
746 XMLNode& node = Processor::state (full);
748 node.add_property("type", _plugins[0]->state_node_name());
749 node.add_property("unique-id", _plugins[0]->unique_id());
750 node.add_property("count", string_compose("%1", _plugins.size()));
751 node.add_child_nocopy (_plugins[0]->get_state());
753 for (Controls::iterator c = controls().begin(); c != controls().end(); ++c) {
754 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> ((*c).second);
756 node.add_child_nocopy (ac->get_state());
764 PluginInsert::set_control_ids (const XMLNode& node, int version)
766 const XMLNodeList& nlist = node.children();
767 XMLNodeConstIterator iter;
768 set<Evoral::Parameter>::const_iterator p;
770 for (iter = nlist.begin(); iter != nlist.end(); ++iter) {
771 if ((*iter)->name() == Controllable::xml_node_name) {
772 const XMLProperty* prop;
774 if ((prop = (*iter)->property (X_("parameter"))) != 0) {
775 uint32_t p = atoi (prop->value());
776 boost::shared_ptr<Evoral::Control> c = control (Evoral::Parameter (PluginAutomation, 0, p));
780 boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (c);
782 ac->set_state (**iter, version);
789 PluginInsert::set_state(const XMLNode& node, int version)
791 XMLNodeList nlist = node.children();
792 XMLNodeIterator niter;
793 XMLPropertyList plist;
794 const XMLProperty *prop;
795 ARDOUR::PluginType type;
797 if ((prop = node.property ("type")) == 0) {
798 error << _("XML node describing plugin is missing the `type' field") << endmsg;
802 if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */
803 type = ARDOUR::LADSPA;
804 } else if (prop->value() == X_("lv2")) {
806 } else if (prop->value() == X_("vst")) {
808 } else if (prop->value() == X_("audiounit")) {
809 type = ARDOUR::AudioUnit;
811 error << string_compose (_("unknown plugin type %1 in plugin insert state"),
817 prop = node.property ("unique-id");
821 /* older sessions contain VST plugins with only an "id" field.
824 if (type == ARDOUR::VST) {
825 prop = node.property ("id");
831 error << _("Plugin has no unique ID field") << endmsg;
836 boost::shared_ptr<Plugin> plugin;
838 plugin = find_plugin (_session, prop->value(), type);
841 error << string_compose(_("Found a reference to a plugin (\"%1\") that is unknown.\n"
842 "Perhaps it was removed or moved since it was last used."), prop->value())
848 bool need_automatables = true;
850 if (_plugins.empty()) {
851 /* if we are adding the first plugin, we will need to set
852 up automatable controls.
854 need_automatables = true;
857 if ((prop = node.property ("count")) != 0) {
858 sscanf (prop->value().c_str(), "%u", &count);
861 if (_plugins.size() != count) {
863 add_plugin_with_activation (plugin);
865 for (uint32_t n = 1; n < count; ++n) {
866 add_plugin_with_activation (plugin_factory (plugin));
870 if (need_automatables) {
872 set_control_ids (node, version);
875 /* Handle the node list for this Processor (or Insert if an A2 session) */
876 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
878 if ((*niter)->name() == plugin->state_node_name()) {
880 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
881 (*i)->set_state (**niter, version);
887 Processor::set_state (node, version);
889 if (version < 3000) {
891 /* Only 2.X sessions need a call to set_parameter_state() - in 3.X and above
892 this is all handled by Automatable
895 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
896 if ((*niter)->name() == "Redirect") {
897 /* XXX do we need to tackle placement? i think not (pd; oct 16 2009) */
898 Processor::set_state (**niter, version);
903 set_parameter_state_2X (node, version);
906 // The name of the PluginInsert comes from the plugin, nothing else
907 _name = plugin->get_info()->name;
909 /* catch up on I/O */
912 Glib::Mutex::Lock em (_session.engine().process_lock());
913 IO::PortCountChanged (max(input_streams(), output_streams()));
920 PluginInsert::set_parameter_state_2X (const XMLNode& node, int version)
922 XMLNodeList nlist = node.children();
923 XMLNodeIterator niter;
925 /* look for port automation node */
927 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
929 if ((*niter)->name() != port_automation_node_name) {
935 XMLNodeConstIterator iter;
940 cnodes = (*niter)->children ("port");
942 for (iter = cnodes.begin(); iter != cnodes.end(); ++iter){
946 if ((cprop = child->property("number")) != 0) {
947 port = cprop->value().c_str();
949 warning << _("PluginInsert: Auto: no ladspa port number") << endmsg;
953 sscanf (port, "%" PRIu32, &port_id);
955 if (port_id >= _plugins[0]->parameter_count()) {
956 warning << _("PluginInsert: Auto: port id out of range") << endmsg;
960 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(
961 control(Evoral::Parameter(PluginAutomation, 0, port_id), true));
964 if (!child->children().empty()) {
965 c->alist()->set_state (*child->children().front(), version);
967 /* In some cases 2.X saves lists with min_yval and max_yval
968 being FLT_MIN and FLT_MAX respectively. This causes problems
969 in A3 because these min/max values are used to compute
970 where GUI control points should be drawn. If we see such
971 values, `correct' them to the min/max of the appropriate
975 float min_y = c->alist()->get_min_y ();
976 float max_y = c->alist()->get_max_y ();
978 Plugin::ParameterDescriptor desc;
979 _plugins.front()->get_parameter_descriptor (port_id, desc);
981 if (min_y == FLT_MIN) {
985 if (max_y == FLT_MAX) {
989 c->alist()->set_yrange (min_y, max_y);
992 error << string_compose (_("PluginInsert: automatable control %1 not found - ignored"), port_id) << endmsg;
1004 PluginInsert::describe_parameter (Evoral::Parameter param)
1006 if (param.type() != PluginAutomation) {
1007 return Automatable::describe_parameter(param);
1010 return _plugins[0]->describe_parameter (param);
1014 PluginInsert::signal_latency() const
1016 if (_user_latency) {
1017 return _user_latency;
1020 return _plugins[0]->signal_latency ();
1024 PluginInsert::type ()
1026 return plugin()->get_info()->type;
1029 PluginInsert::PluginControl::PluginControl (PluginInsert* p, const Evoral::Parameter ¶m, boost::shared_ptr<AutomationList> list)
1030 : AutomationControl (p->session(), param, list, p->describe_parameter(param))
1033 Plugin::ParameterDescriptor desc;
1034 p->plugin(0)->get_parameter_descriptor (param.id(), desc);
1035 _logarithmic = desc.logarithmic;
1036 _toggled = desc.toggled;
1040 PluginInsert::PluginControl::set_value (double val)
1042 /* FIXME: probably should be taking out some lock here.. */
1052 /*const float range = _list->get_max_y() - _list->get_min_y();
1053 const float lower = _list->get_min_y();
1055 if (!_logarithmic) {
1056 val = lower + (range * val);
1058 float log_lower = 0.0f;
1060 log_lower = log(lower);
1063 val = exp(log_lower + log(range) * val);
1068 for (Plugins::iterator i = _plugin->_plugins.begin();
1069 i != _plugin->_plugins.end(); ++i) {
1070 (*i)->set_parameter (_list->parameter().id(), val);
1073 boost::shared_ptr<Plugin> iasp = _plugin->_impulseAnalysisPlugin.lock();
1075 iasp->set_parameter (_list->parameter().id(), val);
1078 AutomationControl::set_value(val);
1082 PluginInsert::PluginControl::get_state ()
1086 XMLNode& node (AutomationControl::get_state());
1087 ss << parameter().id();
1088 node.add_property (X_("parameter"), ss.str());
1094 PluginInsert::PluginControl::get_value (void) const
1096 /* FIXME: probably should be taking out some lock here.. */
1098 double val = _plugin->get_parameter (_list->parameter());
1112 return ((val - lower) / range);
1116 boost::shared_ptr<Plugin>
1117 PluginInsert::get_impulse_analysis_plugin()
1119 boost::shared_ptr<Plugin> ret;
1120 if (_impulseAnalysisPlugin.expired()) {
1121 ret = plugin_factory(_plugins[0]);
1122 _impulseAnalysisPlugin = ret;
1124 ret = _impulseAnalysisPlugin.lock();
1131 PluginInsert::collect_signal_for_analysis (framecnt_t nframes)
1133 // called from outside the audio thread, so this should be safe
1134 // only do audio as analysis is (currently) only for audio plugins
1135 _signal_analysis_inputs.ensure_buffers( DataType::AUDIO, input_streams().n_audio(), nframes);
1136 _signal_analysis_outputs.ensure_buffers( DataType::AUDIO, output_streams().n_audio(), nframes);
1138 _signal_analysis_collected_nframes = 0;
1139 _signal_analysis_collect_nframes_max = nframes;
1142 /** Add a plugin to our list and activate it if we have already been activated */
1144 PluginInsert::add_plugin_with_activation (boost::shared_ptr<Plugin> plugin)
1146 _plugins.push_back (plugin);
1148 plugin->activate ();
1153 PluginInsert::realtime_handle_transport_stopped ()
1155 for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
1156 (*i)->realtime_handle_transport_stopped ();
1161 PluginInsert::set_splitting (bool s)
1163 if (_splitting == s) {
1168 SplittingChanged (); /* EMIT SIGNAL */