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"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/unwind.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_track.h"
41 #include "ardour/audio_port.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/boost_debug.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/phase_control.h"
62 #include "ardour/plugin_insert.h"
63 #include "ardour/port.h"
64 #include "ardour/port_insert.h"
65 #include "ardour/processor.h"
66 #include "ardour/profile.h"
67 #include "ardour/route.h"
68 #include "ardour/route_group.h"
69 #include "ardour/send.h"
70 #include "ardour/session.h"
71 #include "ardour/solo_control.h"
72 #include "ardour/solo_isolate_control.h"
73 #include "ardour/unknown_processor.h"
74 #include "ardour/utils.h"
75 #include "ardour/vca.h"
80 using namespace ARDOUR;
83 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
85 /** Base class for all routable/mixable objects (tracks and busses) */
86 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
87 : Stripable (sess, name, PresentationInfo (flag))
88 , GraphNode (sess._process_graph)
89 , Muteable (sess, name)
93 , _signal_latency_at_amp_position (0)
94 , _signal_latency_at_trim_position (0)
97 , _pending_process_reorder (0)
98 , _pending_signals (0)
99 , _pending_declick (true)
100 , _meter_point (MeterPostFader)
101 , _pending_meter_point (MeterPostFader)
102 , _meter_type (MeterPeak)
103 , _denormal_protection (false)
106 , _declickable (false)
107 , _have_internal_generator (false)
108 , _default_type (default_type)
110 , _in_configure_processors (false)
111 , _initial_io_setup (false)
112 , _in_sidechain_setup (false)
114 , _custom_meter_position_noted (false)
117 processor_max_streams.reset();
123 /* set default meter type */
125 _meter_type = Config->get_meter_type_master ();
127 else if (dynamic_cast<Track*>(this)) {
128 _meter_type = Config->get_meter_type_track ();
130 _meter_type = Config->get_meter_type_bus ();
133 /* add standard controls */
135 _gain_control.reset (new GainControl (_session, GainAutomation));
136 add_control (_gain_control);
138 _trim_control.reset (new GainControl (_session, TrimAutomation));
139 add_control (_trim_control);
141 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
142 add_control (_solo_control);
143 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
145 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
146 add_control (_mute_control);
148 _phase_control.reset (new PhaseControl (_session, X_("phase")));
149 add_control (_phase_control);
151 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
152 add_control (_solo_isolate_control);
154 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
155 add_control (_solo_safe_control);
159 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
160 _pannable.reset (new Pannable (_session));
163 /* input and output objects */
165 _input.reset (new IO (_session, _name, IO::Input, _default_type));
166 _output.reset (new IO (_session, _name, IO::Output, _default_type));
168 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
169 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
171 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
172 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
174 /* add the amp/fader processor.
175 * it should be the first processor to be added on every route.
178 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
179 add_processor (_amp, PostFader);
182 _amp->set_display_name (_("Monitor"));
185 #if 0 // not used - just yet
186 if (!is_master() && !is_monitor() && !is_auditioner()) {
187 _delayline.reset (new DelayLine (_session, _name));
188 add_processor (_delayline, PreFader);
194 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
195 _trim->set_display_to_user (false);
197 if (dynamic_cast<AudioTrack*>(this)) {
198 /* we can't do this in the AudioTrack's constructor
199 * because _trim does not exit then
203 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
208 /* create standard processors: meter, main outs, monitor out;
209 they will be added to _processors by setup_invisible_processors ()
212 _meter.reset (new PeakMeter (_session, _name));
213 _meter->set_owner (this);
214 _meter->set_display_to_user (false);
217 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
218 _main_outs->activate ();
221 /* where we listen to tracks */
222 _intreturn.reset (new InternalReturn (_session));
223 _intreturn->activate ();
225 /* the thing that provides proper control over a control/monitor/listen bus
226 (such as per-channel cut, dim, solo, invert, etc).
228 _monitor_control.reset (new MonitorProcessor (_session));
229 _monitor_control->activate ();
232 if (is_master() || is_monitor() || is_auditioner()) {
233 _mute_master->set_solo_ignore (true);
236 /* now that we have _meter, its safe to connect to this */
239 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
240 configure_processors (0);
248 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
250 /* do this early so that we don't get incoming signals as we are going through destruction
255 /* don't use clear_processors here, as it depends on the session which may
256 be half-destroyed by now
259 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
260 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
261 (*i)->drop_references ();
264 _processors.clear ();
268 Route::ensure_track_or_route_name(string name, Session &session)
270 string newname = name;
272 while (!session.io_name_is_legal (newname)) {
273 newname = bump_name_once (newname, ' ');
280 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
282 // TODO route group, see set_gain()
283 // _trim_control->route_set_value (val);
287 Route::maybe_declick (BufferSet&, framecnt_t, int)
289 /* this is the "bus" implementation and they never declick.
294 /** Process this route for one (sub) cycle (process thread)
296 * @param bufs Scratch buffers to use for the signal path
297 * @param start_frame Initial transport frame
298 * @param end_frame Final transport frame
299 * @param nframes Number of frames to output (to ports)
301 * Note that (end_frame - start_frame) may not be equal to nframes when the
302 * transport speed isn't 1.0 (eg varispeed).
305 Route::process_output_buffers (BufferSet& bufs,
306 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
307 int declick, bool gain_automation_ok)
309 /* Caller must hold process lock */
310 assert (!AudioEngine::instance()->process_lock().trylock());
312 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
314 // can this actually happen? functions calling process_output_buffers()
315 // already take a reader-lock.
316 bufs.silence (nframes, 0);
320 /* figure out if we're going to use gain automation */
321 if (gain_automation_ok) {
322 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
323 _amp->setup_gain_automation (
324 start_frame + _signal_latency_at_amp_position,
325 end_frame + _signal_latency_at_amp_position,
328 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
329 _trim->setup_gain_automation (
330 start_frame + _signal_latency_at_trim_position,
331 end_frame + _signal_latency_at_trim_position,
334 _amp->apply_gain_automation (false);
335 _trim->apply_gain_automation (false);
338 /* Tell main outs what to do about monitoring. We do this so that
339 on a transition between monitoring states we get a de-clicking gain
340 change in the _main_outs delivery, if config.get_use_monitor_fades()
343 We override this in the case where we have an internal generator.
345 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
347 _main_outs->no_outs_cuz_we_no_monitor (silence);
349 /* -------------------------------------------------------------------------------------------
350 GLOBAL DECLICK (for transport changes etc.)
351 ----------------------------------------------------------------------------------------- */
353 maybe_declick (bufs, nframes, declick);
354 _pending_declick = 0;
356 /* -------------------------------------------------------------------------------------------
357 DENORMAL CONTROL/PHASE INVERT
358 ----------------------------------------------------------------------------------------- */
360 if (!_phase_control->none()) {
364 if (_denormal_protection || Config->get_denormal_protection()) {
366 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
367 Sample* const sp = i->data();
369 if (_phase_control->inverted (chn)) {
370 for (pframes_t nx = 0; nx < nframes; ++nx) {
375 for (pframes_t nx = 0; nx < nframes; ++nx) {
383 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
384 Sample* const sp = i->data();
386 if (_phase_control->inverted (chn)) {
387 for (pframes_t nx = 0; nx < nframes; ++nx) {
396 if (_denormal_protection || Config->get_denormal_protection()) {
398 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
399 Sample* const sp = i->data();
400 for (pframes_t nx = 0; nx < nframes; ++nx) {
408 /* -------------------------------------------------------------------------------------------
410 ----------------------------------------------------------------------------------------- */
412 /* set this to be true if the meter will already have been ::run() earlier */
413 bool const meter_already_run = metering_state() == MeteringInput;
415 framecnt_t latency = 0;
417 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
419 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
420 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
425 /* if it has any inputs, make sure they match */
426 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
427 if (bufs.count() != (*i)->input_streams()) {
429 DEBUG::Processors, string_compose (
430 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
431 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
438 /* should we NOT run plugins here if the route is inactive?
439 do we catch route != active somewhere higher?
442 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
443 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
446 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
447 bufs.set_count ((*i)->output_streams());
449 if ((*i)->active ()) {
450 latency += (*i)->signal_latency ();
456 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
457 boost::shared_ptr<Processor> endpoint,
458 bool include_endpoint, bool for_export, bool for_freeze)
460 /* If no processing is required, there's no need to go any further. */
461 if (!endpoint && !include_endpoint) {
465 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
466 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
467 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
469 /* trim is always at the top, for bounce no latency compensation is needed */
470 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
471 _trim->setup_gain_automation (start, start + nframes, nframes);
474 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
476 if (!include_endpoint && (*i) == endpoint) {
480 /* if we're *not* exporting, stop processing if we come across a routing processor. */
481 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
484 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
488 /* special case the panner (export outputs)
489 * Ideally we'd only run the panner, not the delivery itself...
490 * but panners need separate input/output buffers and some context
491 * (panshell, panner type, etc). AFAICT there is no ill side effect
492 * of re-using the main delivery when freewheeling/exporting a region.
494 if ((*i) == _main_outs) {
495 assert ((*i)->does_routing());
496 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
497 buffers.set_count ((*i)->output_streams());
500 /* don't run any processors that do routing.
501 * Also don't bother with metering.
503 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
504 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
505 buffers.set_count ((*i)->output_streams());
506 latency += (*i)->signal_latency ();
509 if ((*i) == endpoint) {
516 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
517 bool include_endpoint, bool for_export, bool for_freeze) const
519 framecnt_t latency = 0;
520 if (!endpoint && !include_endpoint) {
524 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
525 if (!include_endpoint && (*i) == endpoint) {
528 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
531 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
534 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
535 latency += (*i)->signal_latency ();
537 if ((*i) == endpoint) {
545 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
546 bool include_endpoint, bool for_export, bool for_freeze) const
548 if (!endpoint && !include_endpoint) {
552 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
553 if (!include_endpoint && (*i) == endpoint) {
556 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
559 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
562 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
563 cc = (*i)->output_streams();
565 if ((*i) == endpoint) {
573 Route::n_process_buffers ()
575 return max (_input->n_ports(), processor_max_streams);
579 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
581 assert (is_monitor());
582 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
583 fill_buffers_with_input (bufs, _input, nframes);
584 passthru (bufs, start_frame, end_frame, nframes, declick);
588 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
592 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
594 /* control/monitor bus ignores input ports when something is
595 feeding the listen "stream". data will "arrive" into the
596 route from the intreturn processor element.
599 bufs.silence (nframes, 0);
602 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
603 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
607 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
609 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
611 bufs.set_count (_input->n_ports());
612 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
613 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
617 Route::set_listen (bool yn)
621 _monitor_send->activate ();
623 _monitor_send->deactivate ();
629 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
631 /* nothing to do if we're not using AFL/PFL. But if we are, we need
632 to alter the active state of the monitor send.
635 if (Config->get_solo_control_is_listen_control ()) {
636 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
641 Route::push_solo_isolate_upstream (int32_t delta)
643 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
645 boost::shared_ptr<RouteList> routes = _session.get_routes ();
646 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
648 if ((*i).get() == this || !(*i)->can_solo()) {
653 bool does_feed = feeds (*i, &sends_only);
655 if (does_feed && !sends_only) {
656 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
662 Route::push_solo_upstream (int delta)
664 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
665 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
669 boost::shared_ptr<Route> sr (i->r.lock());
671 sr->solo_control()->mod_solo_by_others_downstream (-delta);
678 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
680 cerr << name << " {" << endl;
681 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
682 p != procs.end(); ++p) {
683 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
689 /** Supposing that we want to insert a Processor at a given Placement, return
690 * the processor to add the new one before (or 0 to add at the end).
692 boost::shared_ptr<Processor>
693 Route::before_processor_for_placement (Placement p)
695 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
697 ProcessorList::iterator loc;
700 /* generic pre-fader: insert immediately before the amp */
701 loc = find (_processors.begin(), _processors.end(), _amp);
703 /* generic post-fader: insert right before the main outs */
704 loc = find (_processors.begin(), _processors.end(), _main_outs);
707 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
710 /** Supposing that we want to insert a Processor at a given index, return
711 * the processor to add the new one before (or 0 to add at the end).
713 boost::shared_ptr<Processor>
714 Route::before_processor_for_index (int index)
717 return boost::shared_ptr<Processor> ();
720 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
722 ProcessorList::iterator i = _processors.begin ();
724 while (i != _processors.end() && j < index) {
725 if ((*i)->display_to_user()) {
732 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
735 /** Add a processor either pre- or post-fader
736 * @return 0 on success, non-0 on failure.
739 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
741 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
745 /** Add a processor to a route such that it ends up with a given index into the visible processors.
746 * @param index Index to add the processor at, or -1 to add at the end of the list.
747 * @return 0 on success, non-0 on failure.
750 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
752 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
755 /** Add a processor to the route.
756 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
757 * @return 0 on success, non-0 on failure.
760 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
762 assert (processor != _meter);
763 assert (processor != _main_outs);
765 DEBUG_TRACE (DEBUG::Processors, string_compose (
766 "%1 adding processor %2\n", name(), processor->name()));
770 pl.push_back (processor);
771 int rv = add_processors (pl, before, err);
777 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
778 processor->activate ();
785 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
787 /* We cannot destruct the processor here (usually RT-thread
788 * with various locks held - in case of sends also io_locks).
789 * Queue for deletion in low-priority thread.
791 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
792 selfdestruct_sequence.push_back (wp);
796 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
798 XMLProperty const * prop;
801 boost::shared_ptr<Processor> processor;
803 /* bit of a hack: get the `placement' property from the <Redirect> tag here
804 so that we can add the processor in the right place (pre/post-fader)
807 XMLNodeList const & children = node.children ();
808 XMLNodeList::const_iterator i = children.begin ();
810 while (i != children.end() && (*i)->name() != X_("Redirect")) {
814 Placement placement = PreFader;
816 if (i != children.end()) {
817 if ((prop = (*i)->property (X_("placement"))) != 0) {
818 placement = Placement (string_2_enum (prop->value(), placement));
822 if (node.name() == "Insert") {
824 if ((prop = node.property ("type")) != 0) {
826 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
827 prop->value() == "lv2" ||
828 prop->value() == "windows-vst" ||
829 prop->value() == "lxvst" ||
830 prop->value() == "audiounit") {
832 if (_session.get_disable_all_loaded_plugins ()) {
833 processor.reset (new UnknownProcessor (_session, node));
835 processor.reset (new PluginInsert (_session));
836 processor->set_owner (this);
841 processor.reset (new PortInsert (_session, _pannable, _mute_master));
846 } else if (node.name() == "Send") {
848 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
849 processor.reset (new Send (_session, sendpan, _mute_master));
853 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
857 if (processor->set_state (node, version)) {
861 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
862 if (i != children.end()) {
863 if ((prop = (*i)->property (X_("active"))) != 0) {
864 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
865 processor->activate();
867 processor->deactivate();
871 return (add_processor (processor, placement, 0, false) == 0);
874 catch (failed_constructor &err) {
875 warning << _("processor could not be created. Ignored.") << endmsg;
881 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
882 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
885 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
886 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
890 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
892 ProcessorList::iterator loc;
895 loc = find(_processors.begin(), _processors.end(), before);
896 if (loc == _processors.end ()) {
900 /* nothing specified - at end */
901 loc = _processors.end ();
904 if (!AudioEngine::instance()->connected()) {
908 if (others.empty()) {
912 ProcessorList to_skip;
914 // check if there's an instrument to replace or configure
915 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
916 boost::shared_ptr<PluginInsert> pi;
917 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
920 if (!pi->plugin ()->get_info ()->is_instrument ()) {
923 boost::shared_ptr<Processor> instrument = the_instrument ();
924 ChanCount in (DataType::MIDI, 1);
925 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
927 PluginSetupOptions flags = None;
930 in = instrument->input_streams ();
931 out = instrument->output_streams ();
933 if (pi->has_output_presets (in, out)) {
937 pi->set_strict_io (_strict_io);
939 PluginSetupOptions mask = None;
940 if (Config->get_ask_replace_instrument ()) {
943 if (Config->get_ask_setup_instrument ()) {
950 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
951 switch (rv.get_value_or (0)) {
953 to_skip.push_back (*i); // don't add this one;
956 replace_processor (instrument, *i, err);
957 to_skip.push_back (*i);
966 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
967 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
968 ProcessorState pstate (this);
970 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
975 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
976 if (check != to_skip.end()) {
980 boost::shared_ptr<PluginInsert> pi;
982 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
983 pi->set_strict_io (_strict_io);
987 /* Ensure that only one amp is in the list at any time */
988 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
989 if (check != _processors.end()) {
990 if (before == _amp) {
991 /* Already in position; all is well */
994 _processors.erase (check);
999 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1001 _processors.insert (loc, *i);
1002 (*i)->set_owner (this);
1005 if (configure_processors_unlocked (err, &lm)) {
1007 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1012 if ((*i)->active()) {
1016 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1018 boost::shared_ptr<Send> send;
1019 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1020 send->SelfDestruct.connect_same_thread (*this,
1021 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1025 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1026 boost::shared_ptr<PluginInsert> pi;
1028 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1029 if (pi->has_no_inputs ()) {
1030 _have_internal_generator = true;
1036 _output->set_user_latency (0);
1039 reset_instrument_info ();
1040 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1041 set_processor_positions ();
1047 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1049 if (p == PreFader) {
1050 start = _processors.begin();
1051 end = find(_processors.begin(), _processors.end(), _amp);
1053 start = find(_processors.begin(), _processors.end(), _amp);
1055 end = _processors.end();
1059 /** Turn off all processors with a given placement
1060 * @param p Placement of processors to disable
1063 Route::disable_processors (Placement p)
1065 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1067 ProcessorList::iterator start, end;
1068 placement_range(p, start, end);
1070 for (ProcessorList::iterator i = start; i != end; ++i) {
1071 (*i)->deactivate ();
1074 _session.set_dirty ();
1077 /** Turn off all redirects
1080 Route::disable_processors ()
1082 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1084 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1085 (*i)->deactivate ();
1088 _session.set_dirty ();
1091 /** Turn off all redirects with a given placement
1092 * @param p Placement of redirects to disable
1095 Route::disable_plugins (Placement p)
1097 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1099 ProcessorList::iterator start, end;
1100 placement_range(p, start, end);
1102 for (ProcessorList::iterator i = start; i != end; ++i) {
1103 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1104 (*i)->deactivate ();
1108 _session.set_dirty ();
1111 /** Turn off all plugins
1114 Route::disable_plugins ()
1116 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1118 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1119 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1120 (*i)->deactivate ();
1124 _session.set_dirty ();
1129 Route::ab_plugins (bool forward)
1131 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1135 /* forward = turn off all active redirects, and mark them so that the next time
1136 we go the other way, we will revert them
1139 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1140 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1144 if ((*i)->active()) {
1145 (*i)->deactivate ();
1146 (*i)->set_next_ab_is_active (true);
1148 (*i)->set_next_ab_is_active (false);
1154 /* backward = if the redirect was marked to go active on the next ab, do so */
1156 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1158 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1162 if ((*i)->get_next_ab_is_active()) {
1165 (*i)->deactivate ();
1170 _session.set_dirty ();
1174 /** Remove processors with a given placement.
1175 * @param p Placement of processors to remove.
1178 Route::clear_processors (Placement p)
1180 if (!_session.engine().connected()) {
1184 bool already_deleting = _session.deletion_in_progress();
1185 if (!already_deleting) {
1186 _session.set_deletion_in_progress();
1190 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1191 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1192 ProcessorList new_list;
1193 ProcessorStreams err;
1194 bool seen_amp = false;
1196 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1202 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1204 /* you can't remove these */
1206 new_list.push_back (*i);
1213 new_list.push_back (*i);
1216 (*i)->drop_references ();
1224 (*i)->drop_references ();
1227 new_list.push_back (*i);
1234 _processors = new_list;
1235 configure_processors_unlocked (&err, &lm); // this can't fail
1238 processor_max_streams.reset();
1239 _have_internal_generator = false;
1240 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1241 set_processor_positions ();
1243 reset_instrument_info ();
1245 if (!already_deleting) {
1246 _session.clear_deletion_in_progress();
1251 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1253 // TODO once the export point can be configured properly, do something smarter here
1254 if (processor == _capturing_processor) {
1255 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1256 if (need_process_lock) {
1260 _capturing_processor.reset();
1262 if (need_process_lock) {
1267 /* these can never be removed */
1269 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1273 if (!_session.engine().connected()) {
1277 processor_max_streams.reset();
1280 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1281 if (need_process_lock) {
1285 /* Caller must hold process lock */
1286 assert (!AudioEngine::instance()->process_lock().trylock());
1288 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1290 ProcessorState pstate (this);
1292 ProcessorList::iterator i;
1293 bool removed = false;
1295 for (i = _processors.begin(); i != _processors.end(); ) {
1296 if (*i == processor) {
1298 /* move along, see failure case for configure_processors()
1299 where we may need to reconfigure the processor.
1302 /* stop redirects that send signals to JACK ports
1303 from causing noise as a result of no longer being
1307 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1308 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1312 iop = pi->sidechain();
1319 i = _processors.erase (i);
1327 _output->set_user_latency (0);
1335 if (configure_processors_unlocked (err, &lm)) {
1337 /* we know this will work, because it worked before :) */
1338 configure_processors_unlocked (0, &lm);
1342 _have_internal_generator = false;
1344 for (i = _processors.begin(); i != _processors.end(); ++i) {
1345 boost::shared_ptr<PluginInsert> pi;
1347 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1348 if (pi->has_no_inputs ()) {
1349 _have_internal_generator = true;
1354 if (need_process_lock) {
1359 reset_instrument_info ();
1360 processor->drop_references ();
1361 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1362 set_processor_positions ();
1368 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1370 /* these can never be removed */
1371 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1374 /* and can't be used as substitute, either */
1375 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1379 /* I/Os are out, too */
1380 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1384 /* this function cannot be used to swap/reorder processors */
1385 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1389 if (!AudioEngine::instance()->connected() || !old || !sub) {
1393 /* ensure that sub is not owned by another route */
1394 if (sub->owner ()) {
1399 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1400 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1401 ProcessorState pstate (this);
1403 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1405 ProcessorList::iterator i;
1406 bool replaced = false;
1407 bool enable = old->active ();
1409 for (i = _processors.begin(); i != _processors.end(); ) {
1411 i = _processors.erase (i);
1412 _processors.insert (i, sub);
1413 sub->set_owner (this);
1426 boost::shared_ptr<PluginInsert> pi;
1427 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1428 pi->set_strict_io (true);
1432 if (configure_processors_unlocked (err, &lm)) {
1434 configure_processors_unlocked (0, &lm);
1438 _have_internal_generator = false;
1440 for (i = _processors.begin(); i != _processors.end(); ++i) {
1441 boost::shared_ptr<PluginInsert> pi;
1442 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1443 if (pi->has_no_inputs ()) {
1444 _have_internal_generator = true;
1454 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1455 _output->set_user_latency (0);
1458 reset_instrument_info ();
1459 old->drop_references ();
1460 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1461 set_processor_positions ();
1466 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1468 ProcessorList deleted;
1470 if (!_session.engine().connected()) {
1474 processor_max_streams.reset();
1477 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1478 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1479 ProcessorState pstate (this);
1481 ProcessorList::iterator i;
1482 boost::shared_ptr<Processor> processor;
1484 for (i = _processors.begin(); i != _processors.end(); ) {
1488 /* these can never be removed */
1490 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1495 /* see if its in the list of processors to delete */
1497 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1502 /* stop IOProcessors that send to JACK ports
1503 from causing noise as a result of no longer being
1507 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1508 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1511 iop = pi->sidechain();
1518 deleted.push_back (processor);
1519 i = _processors.erase (i);
1522 if (deleted.empty()) {
1523 /* none of those in the requested list were found */
1527 _output->set_user_latency (0);
1529 if (configure_processors_unlocked (err, &lm)) {
1531 /* we know this will work, because it worked before :) */
1532 configure_processors_unlocked (0, &lm);
1537 _have_internal_generator = false;
1539 for (i = _processors.begin(); i != _processors.end(); ++i) {
1540 boost::shared_ptr<PluginInsert> pi;
1542 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1543 if (pi->has_no_inputs ()) {
1544 _have_internal_generator = true;
1551 /* now try to do what we need to so that those that were removed will be deleted */
1553 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1554 (*i)->drop_references ();
1557 reset_instrument_info ();
1558 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1559 set_processor_positions ();
1565 Route::reset_instrument_info ()
1567 boost::shared_ptr<Processor> instr = the_instrument();
1569 _instrument_info.set_internal_instrument (instr);
1573 /** Caller must hold process lock */
1575 Route::configure_processors (ProcessorStreams* err)
1577 #ifndef PLATFORM_WINDOWS
1578 assert (!AudioEngine::instance()->process_lock().trylock());
1581 if (!_in_configure_processors) {
1582 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1583 return configure_processors_unlocked (err, &lm);
1590 Route::input_streams () const
1592 return _input->n_ports ();
1595 list<pair<ChanCount, ChanCount> >
1596 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1598 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1600 return try_configure_processors_unlocked (in, err);
1603 list<pair<ChanCount, ChanCount> >
1604 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1606 // Check each processor in order to see if we can configure as requested
1608 list<pair<ChanCount, ChanCount> > configuration;
1611 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1612 DEBUG_TRACE (DEBUG::Processors, "{\n");
1614 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1616 if ((*p)->can_support_io_configuration(in, out)) {
1618 if (boost::dynamic_pointer_cast<Delivery> (*p)
1619 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1620 && !(is_monitor() || is_auditioner())
1621 && ( _strict_io || Profile->get_mixbus ())) {
1622 /* with strict I/O the panner + output are forced to
1623 * follow the last processor's output.
1625 * Delivery::can_support_io_configuration() will only add ports,
1626 * but not remove excess ports.
1628 * This works because the delivery only requires
1629 * as many outputs as there are inputs.
1630 * Delivery::configure_io() will do the actual removal
1631 * by calling _output->ensure_io()
1633 if (!is_master() && _session.master_out ()) {
1634 /* ..but at least as many as there are master-inputs */
1635 // XXX this may need special-casing for mixbus (master-outputs)
1636 // and should maybe be a preference anyway ?!
1637 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1643 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1644 configuration.push_back(make_pair(in, out));
1647 // restriction for Monitor Section Processors
1648 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1649 /* do not allow to add/remove channels (for now)
1650 * The Monitor follows the master-bus and has no panner (unpan)
1651 * but do allow processors with midi-in to be added (e.g VSTs with control that
1652 * will remain unconnected)
1654 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1655 return list<pair<ChanCount, ChanCount> > ();
1657 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1658 // internal sends make no sense, only feedback
1659 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1660 return list<pair<ChanCount, ChanCount> > ();
1662 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1663 /* External Sends can be problematic. one can add/remove ports
1664 * there signal leaves the DAW to external monitors anyway, so there's
1665 * no real use for allowing them here anyway.
1667 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1668 return list<pair<ChanCount, ChanCount> > ();
1670 if (boost::dynamic_pointer_cast<Send> (*p)) {
1672 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1673 return list<pair<ChanCount, ChanCount> > ();
1682 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1683 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1684 DEBUG_TRACE (DEBUG::Processors, "}\n");
1685 return list<pair<ChanCount, ChanCount> > ();
1689 DEBUG_TRACE (DEBUG::Processors, "}\n");
1691 return configuration;
1694 /** Set the input/output configuration of each processor in the processors list.
1695 * Caller must hold process lock.
1696 * Return 0 on success, otherwise configuration is impossible.
1699 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1701 #ifndef PLATFORM_WINDOWS
1702 assert (!AudioEngine::instance()->process_lock().trylock());
1705 if (_in_configure_processors) {
1709 /* put invisible processors where they should be */
1710 setup_invisible_processors ();
1712 _in_configure_processors = true;
1714 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1716 if (configuration.empty ()) {
1717 _in_configure_processors = false;
1722 bool seen_mains_out = false;
1723 processor_out_streams = _input->n_ports();
1724 processor_max_streams.reset();
1726 /* processor configure_io() may result in adding ports
1727 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1729 * with jack2 adding ports results in a graph-order callback,
1730 * which calls Session::resort_routes() and eventually
1731 * Route::direct_feeds_according_to_reality()
1732 * which takes a ReaderLock (_processor_lock).
1734 * so we can't hold a WriterLock here until jack2 threading
1737 * NB. we still hold the process lock
1739 * (ardour's own engines do call graph-order from the
1740 * process-thread and hence do not have this issue; besides
1741 * merely adding ports won't trigger a graph-order, only
1742 * making connections does)
1746 // TODO check for a potential ReaderLock after ReaderLock ??
1747 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1749 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1750 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1752 if (!(*p)->configure_io(c->first, c->second)) {
1753 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1754 _in_configure_processors = false;
1759 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1760 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1762 boost::shared_ptr<IOProcessor> iop;
1763 boost::shared_ptr<PluginInsert> pi;
1764 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1765 /* plugins connected via Split or Hide Match may have more channels.
1766 * route/scratch buffers are needed for all of them
1767 * The configuration may only be a subset (both input and output)
1769 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1771 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1772 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1773 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1777 if (boost::dynamic_pointer_cast<Delivery> (*p)
1778 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1779 /* main delivery will increase port count to match input.
1780 * the Delivery::Main is usually the last processor - followed only by
1783 seen_mains_out = true;
1785 if (!seen_mains_out) {
1786 processor_out_streams = out;
1795 _meter->set_max_channels (processor_max_streams);
1798 /* make sure we have sufficient scratch buffers to cope with the new processor
1801 _session.ensure_buffers (n_process_buffers ());
1803 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1805 _in_configure_processors = false;
1809 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1810 * @param state New active state for those processors.
1813 Route::all_visible_processors_active (bool state)
1815 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1817 if (_processors.empty()) {
1821 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1822 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1829 (*i)->deactivate ();
1833 _session.set_dirty ();
1837 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1839 /* check if re-order requires re-configuration of any processors
1840 * -> compare channel configuration for all processors
1842 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1843 ChanCount c = input_streams ();
1845 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1847 if (c != (*j)->input_streams()) {
1850 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1853 if ((*i)->input_streams() != c) {
1856 c = (*i)->output_streams();
1868 __attribute__((annotate("realtime")))
1871 Route::apply_processor_order (const ProcessorList& new_order)
1873 /* need to hold processor_lock; either read or write lock
1874 * and the engine process_lock.
1875 * Due to r/w lock ambiguity we can only assert the latter
1877 assert (!AudioEngine::instance()->process_lock().trylock());
1880 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1881 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1882 * processors in the current actual processor list that are hidden. Any visible processors
1883 * in the current list but not in "new_order" will be assumed to be deleted.
1886 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1887 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1888 * (note though that ::processors_reorder_needs_configure() ensured that
1889 * this function will only ever be called from the rt-thread if no processor were removed)
1891 * either way, I can't proove it, but an x-run due to re-order here is less likley
1892 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1895 ProcessorList as_it_will_be;
1896 ProcessorList::iterator oiter;
1897 ProcessorList::const_iterator niter;
1899 oiter = _processors.begin();
1900 niter = new_order.begin();
1902 while (niter != new_order.end()) {
1904 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1905 then append it to the temp list.
1907 Otherwise, see if the next processor in the old list is in the new list. if not,
1908 its been deleted. If its there, append it to the temp list.
1911 if (oiter == _processors.end()) {
1913 /* no more elements in the old list, so just stick the rest of
1914 the new order onto the temp list.
1917 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1918 while (niter != new_order.end()) {
1925 if (!(*oiter)->display_to_user()) {
1927 as_it_will_be.push_back (*oiter);
1931 /* visible processor: check that its in the new order */
1933 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1934 /* deleted: do nothing, shared_ptr<> will clean up */
1936 /* ignore this one, and add the next item from the new order instead */
1937 as_it_will_be.push_back (*niter);
1942 /* now remove from old order - its taken care of no matter what */
1943 oiter = _processors.erase (oiter);
1947 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1949 /* If the meter is in a custom position, find it and make a rough note of its position */
1950 maybe_note_meter_position ();
1954 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1956 // it a change is already queued, wait for it
1957 // (unless engine is stopped. apply immediately and proceed
1958 while (g_atomic_int_get (&_pending_process_reorder)) {
1959 if (!AudioEngine::instance()->running()) {
1960 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
1961 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1963 apply_processor_order(_pending_processor_order);
1964 setup_invisible_processors ();
1966 g_atomic_int_set (&_pending_process_reorder, 0);
1968 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1969 set_processor_positions ();
1971 // TODO rather use a semaphore or something.
1972 // but since ::reorder_processors() is called
1973 // from the GUI thread, this is fine..
1978 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
1980 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1981 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1982 ProcessorState pstate (this);
1984 apply_processor_order (new_order);
1986 if (configure_processors_unlocked (err, &lm)) {
1994 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1995 set_processor_positions ();
1998 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
1999 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2001 // _pending_processor_order is protected by _processor_lock
2002 _pending_processor_order = new_order;
2003 g_atomic_int_set (&_pending_process_reorder, 1);
2010 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2012 boost::shared_ptr<PluginInsert> pi;
2013 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2017 if (pi->has_sidechain () == add) {
2018 return true; // ?? call failed, but result is as expected.
2022 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2023 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2024 if (i == _processors.end ()) {
2030 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2031 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2032 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2034 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2036 if (!pi->add_sidechain ()) {
2040 if (!pi->del_sidechain ()) {
2046 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2051 pi->del_sidechain ();
2053 pi->add_sidechain ();
2054 // TODO restore side-chain's state.
2059 configure_processors_unlocked (0, &lm);
2062 if (pi->has_sidechain ()) {
2063 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2066 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2067 _session.set_dirty ();
2072 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2074 boost::shared_ptr<PluginInsert> pi;
2075 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2080 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2081 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2082 if (i == _processors.end ()) {
2088 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2089 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2091 const ChanCount& old (pi->preset_out ());
2092 if (!pi->set_preset_out (outs)) {
2093 return true; // no change, OK
2096 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2099 pi->set_preset_out (old);
2102 configure_processors_unlocked (0, &lm);
2105 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2106 _session.set_dirty ();
2111 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2114 return customize_plugin_insert (proc, 0, unused, unused);
2118 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2120 boost::shared_ptr<PluginInsert> pi;
2121 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2126 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2127 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2128 if (i == _processors.end ()) {
2134 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2135 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2137 bool old_cust = pi->custom_cfg ();
2138 uint32_t old_cnt = pi->get_count ();
2139 ChanCount old_chan = pi->output_streams ();
2140 ChanCount old_sinks = pi->natural_input_streams ();
2143 pi->set_custom_cfg (false);
2145 pi->set_custom_cfg (true);
2146 pi->set_count (count);
2147 pi->set_outputs (outs);
2148 pi->set_sinks (sinks);
2151 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2155 pi->set_count (old_cnt);
2156 pi->set_sinks (old_sinks);
2157 pi->set_outputs (old_chan);
2158 pi->set_custom_cfg (old_cust);
2162 configure_processors_unlocked (0, &lm);
2165 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2166 _session.set_dirty ();
2171 Route::set_strict_io (const bool enable)
2173 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2175 if (_strict_io != enable) {
2176 _strict_io = enable;
2177 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2178 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2179 boost::shared_ptr<PluginInsert> pi;
2180 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2181 pi->set_strict_io (_strict_io);
2185 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2189 _strict_io = !enable; // restore old value
2190 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2191 boost::shared_ptr<PluginInsert> pi;
2192 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2193 pi->set_strict_io (_strict_io);
2200 configure_processors (0);
2203 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2204 _session.set_dirty ();
2216 Route::get_template()
2218 return state(false);
2222 Route::state(bool full_state)
2225 if (!_session._template_state_dir.empty()) {
2226 assert (!full_state); // only for templates
2227 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2230 XMLNode *node = new XMLNode("Route");
2231 ProcessorList::iterator i;
2234 id().print (buf, sizeof (buf));
2235 node->add_property("id", buf);
2236 node->add_property ("name", _name);
2237 node->add_property("default-type", _default_type.to_string());
2238 node->add_property ("strict-io", _strict_io);
2240 Stripable::add_state (*node);
2242 node->add_property("active", _active?"yes":"no");
2244 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2245 node->add_property("meter-point", enum_2_string (_meter_point));
2247 node->add_property("meter-type", enum_2_string (_meter_type));
2250 node->add_property("route-group", _route_group->name());
2253 node->add_child_nocopy (_solo_control->get_state ());
2254 node->add_child_nocopy (_solo_isolate_control->get_state ());
2255 node->add_child_nocopy (_solo_safe_control->get_state ());
2257 node->add_child_nocopy (_input->state (full_state));
2258 node->add_child_nocopy (_output->state (full_state));
2259 node->add_child_nocopy (_mute_master->get_state ());
2261 node->add_child_nocopy (_mute_control->get_state ());
2262 node->add_child_nocopy (_phase_control->get_state ());
2265 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2268 if (_comment.length()) {
2269 XMLNode *cmt = node->add_child ("Comment");
2270 cmt->add_content (_comment);
2274 node->add_child_nocopy (_pannable->state (full_state));
2278 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2279 for (i = _processors.begin(); i != _processors.end(); ++i) {
2281 /* template save: do not include internal sends functioning as
2282 aux sends because the chance of the target ID
2283 in the session where this template is used
2286 similarly, do not save listen sends which connect to
2287 the monitor section, because these will always be
2290 boost::shared_ptr<InternalSend> is;
2292 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2293 if (is->role() == Delivery::Listen) {
2298 node->add_child_nocopy((*i)->state (full_state));
2303 node->add_child_copy (*_extra_xml);
2306 if (_custom_meter_position_noted) {
2307 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2309 after->id().print (buf, sizeof (buf));
2310 node->add_property (X_("processor-after-last-custom-meter"), buf);
2314 if (!_session._template_state_dir.empty()) {
2315 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2318 node->add_child_copy (Slavable::get_state());
2324 Route::set_state (const XMLNode& node, int version)
2326 if (version < 3000) {
2327 return set_state_2X (node, version);
2331 XMLNodeConstIterator niter;
2333 XMLProperty const * prop;
2335 if (node.name() != "Route"){
2336 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2340 if ((prop = node.property (X_("name"))) != 0) {
2341 Route::set_name (prop->value());
2345 _initial_io_setup = true;
2347 Stripable::set_state (node, version);
2349 if ((prop = node.property (X_("strict-io"))) != 0) {
2350 _strict_io = string_is_affirmative (prop->value());
2354 _mute_master->set_solo_ignore (true);
2358 /* monitor bus does not get a panner, but if (re)created
2359 via XML, it will already have one by the time we
2360 call ::set_state(). so ... remove it.
2365 /* add all processors (except amp, which is always present) */
2367 nlist = node.children();
2368 XMLNode processor_state (X_("processor_state"));
2370 Stateful::save_extra_xml (node);
2372 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2376 if (child->name() == IO::state_node_name) {
2377 if ((prop = child->property (X_("direction"))) == 0) {
2381 if (prop->value() == "Input") {
2382 _input->set_state (*child, version);
2383 } else if (prop->value() == "Output") {
2384 _output->set_state (*child, version);
2387 } else if (child->name() == X_("Processor")) {
2388 processor_state.add_child_copy (*child);
2389 } else if (child->name() == X_("Pannable")) {
2391 _pannable->set_state (*child, version);
2393 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2395 } else if (child->name() == Controllable::xml_node_name) {
2396 if ((prop = child->property (X_("name"))) == 0) {
2400 if (prop->value() == _gain_control->name()) {
2401 _gain_control->set_state (*child, version);
2402 } else if (prop->value() == _solo_control->name()) {
2403 _solo_control->set_state (*child, version);
2404 } else if (prop->value() == _solo_safe_control->name()) {
2405 _solo_safe_control->set_state (*child, version);
2406 } else if (prop->value() == _solo_isolate_control->name()) {
2407 _solo_isolate_control->set_state (*child, version);
2408 } else if (prop->value() == _solo_control->name()) {
2409 _mute_control->set_state (*child, version);
2411 } else if (child->name() == Slavable::xml_node_name) {
2412 Slavable::set_state (*child, version);
2416 if ((prop = node.property (X_("meter-point"))) != 0) {
2417 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2418 set_meter_point (mp, true);
2420 _meter->set_display_to_user (_meter_point == MeterCustom);
2424 if ((prop = node.property (X_("meter-type"))) != 0) {
2425 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2428 _initial_io_setup = false;
2430 set_processor_state (processor_state);
2432 // this looks up the internal instrument in processors
2433 reset_instrument_info();
2435 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2436 set_denormal_protection (string_is_affirmative (prop->value()));
2439 if ((prop = node.property (X_("active"))) != 0) {
2440 bool yn = string_is_affirmative (prop->value());
2441 set_active (yn, this);
2444 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2445 PBD::ID id (prop->value ());
2446 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2447 ProcessorList::const_iterator i = _processors.begin ();
2448 while (i != _processors.end() && (*i)->id() != id) {
2452 if (i != _processors.end ()) {
2453 _processor_after_last_custom_meter = *i;
2454 _custom_meter_position_noted = true;
2458 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2461 if (child->name() == X_("Comment")) {
2463 /* XXX this is a terrible API design in libxml++ */
2465 XMLNode *cmt = *(child->children().begin());
2466 _comment = cmt->content();
2468 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2469 if (prop->value() == "solo") {
2470 _solo_control->set_state (*child, version);
2471 } else if (prop->value() == "mute") {
2472 _mute_control->set_state (*child, version);
2475 } else if (child->name() == MuteMaster::xml_node_name) {
2476 _mute_master->set_state (*child, version);
2478 } else if (child->name() == Automatable::xml_node_name) {
2479 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2487 Route::set_state_2X (const XMLNode& node, int version)
2491 XMLNodeConstIterator niter;
2493 XMLProperty const * prop;
2495 /* 2X things which still remain to be handled:
2501 if (node.name() != "Route") {
2502 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2506 Stripable::set_state (node, version);
2508 if (is_master() || is_monitor() || is_auditioner()) {
2509 _mute_master->set_solo_ignore (true);
2512 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2513 set_denormal_protection (string_is_affirmative (prop->value()));
2516 if ((prop = node.property (X_("muted"))) != 0) {
2519 bool muted = string_is_affirmative (prop->value());
2525 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2527 if (string_is_affirmative (prop->value())){
2528 mute_point = mute_point + "PreFader";
2533 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2535 if (string_is_affirmative (prop->value())){
2538 mute_point = mute_point + ",";
2541 mute_point = mute_point + "PostFader";
2546 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2548 if (string_is_affirmative (prop->value())){
2551 mute_point = mute_point + ",";
2554 mute_point = mute_point + "Listen";
2559 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2561 if (string_is_affirmative (prop->value())){
2564 mute_point = mute_point + ",";
2567 mute_point = mute_point + "Main";
2571 _mute_master->set_mute_points (mute_point);
2572 _mute_master->set_muted_by_self (true);
2576 if ((prop = node.property (X_("meter-point"))) != 0) {
2577 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2582 nlist = node.children ();
2583 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2587 if (child->name() == IO::state_node_name) {
2589 /* there is a note in IO::set_state_2X() about why we have to call
2593 _input->set_state_2X (*child, version, true);
2594 _output->set_state_2X (*child, version, false);
2596 if ((prop = child->property (X_("name"))) != 0) {
2597 Route::set_name (prop->value ());
2602 if ((prop = child->property (X_("active"))) != 0) {
2603 bool yn = string_is_affirmative (prop->value());
2604 _active = !yn; // force switch
2605 set_active (yn, this);
2608 if ((prop = child->property (X_("gain"))) != 0) {
2611 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2612 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2616 /* Set up Panners in the IO */
2617 XMLNodeList io_nlist = child->children ();
2619 XMLNodeConstIterator io_niter;
2622 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2624 io_child = *io_niter;
2626 if (io_child->name() == X_("Panner")) {
2627 _main_outs->panner_shell()->set_state(*io_child, version);
2628 } else if (io_child->name() == X_("Automation")) {
2629 /* IO's automation is for the fader */
2630 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2636 XMLNodeList redirect_nodes;
2638 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2642 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2643 redirect_nodes.push_back(child);
2648 set_processor_state_2X (redirect_nodes, version);
2650 Stateful::save_extra_xml (node);
2652 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2655 if (child->name() == X_("Comment")) {
2657 /* XXX this is a terrible API design in libxml++ */
2659 XMLNode *cmt = *(child->children().begin());
2660 _comment = cmt->content();
2662 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2663 if (prop->value() == X_("solo")) {
2664 _solo_control->set_state (*child, version);
2665 } else if (prop->value() == X_("mute")) {
2666 _mute_control->set_state (*child, version);
2676 Route::get_processor_state ()
2678 XMLNode* root = new XMLNode (X_("redirects"));
2679 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2680 root->add_child_nocopy ((*i)->state (true));
2687 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2689 /* We don't bother removing existing processors not in nList, as this
2690 method will only be called when creating a Route from scratch, not
2691 for undo purposes. Just put processors in at the appropriate place
2695 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2696 add_processor_from_xml_2X (**i, version);
2701 Route::set_processor_state (const XMLNode& node)
2703 const XMLNodeList &nlist = node.children();
2704 XMLNodeConstIterator niter;
2705 ProcessorList new_order;
2706 bool must_configure = false;
2708 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2710 XMLProperty* prop = (*niter)->property ("type");
2712 if (prop->value() == "amp") {
2713 _amp->set_state (**niter, Stateful::current_state_version);
2714 new_order.push_back (_amp);
2715 } else if (prop->value() == "trim") {
2716 _trim->set_state (**niter, Stateful::current_state_version);
2717 new_order.push_back (_trim);
2718 } else if (prop->value() == "meter") {
2719 _meter->set_state (**niter, Stateful::current_state_version);
2720 new_order.push_back (_meter);
2721 } else if (prop->value() == "delay") {
2723 _delayline->set_state (**niter, Stateful::current_state_version);
2724 new_order.push_back (_delayline);
2726 } else if (prop->value() == "main-outs") {
2727 _main_outs->set_state (**niter, Stateful::current_state_version);
2728 } else if (prop->value() == "intreturn") {
2730 _intreturn.reset (new InternalReturn (_session));
2731 must_configure = true;
2733 _intreturn->set_state (**niter, Stateful::current_state_version);
2734 } else if (is_monitor() && prop->value() == "monitor") {
2735 if (!_monitor_control) {
2736 _monitor_control.reset (new MonitorProcessor (_session));
2737 must_configure = true;
2739 _monitor_control->set_state (**niter, Stateful::current_state_version);
2740 } else if (prop->value() == "capture") {
2741 /* CapturingProcessor should never be restored, it's always
2742 added explicitly when needed */
2744 ProcessorList::iterator o;
2746 for (o = _processors.begin(); o != _processors.end(); ++o) {
2747 XMLProperty const * id_prop = (*niter)->property(X_("id"));
2748 if (id_prop && (*o)->id() == id_prop->value()) {
2749 (*o)->set_state (**niter, Stateful::current_state_version);
2750 new_order.push_back (*o);
2755 // If the processor (*niter) is not on the route then create it
2757 if (o == _processors.end()) {
2759 boost::shared_ptr<Processor> processor;
2761 if (prop->value() == "intsend") {
2763 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2765 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2766 prop->value() == "lv2" ||
2767 prop->value() == "windows-vst" ||
2768 prop->value() == "lxvst" ||
2769 prop->value() == "luaproc" ||
2770 prop->value() == "audiounit") {
2772 if (_session.get_disable_all_loaded_plugins ()) {
2773 processor.reset (new UnknownProcessor (_session, **niter));
2775 processor.reset (new PluginInsert (_session));
2776 processor->set_owner (this);
2778 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2779 pi->set_strict_io (true);
2783 } else if (prop->value() == "port") {
2785 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2787 } else if (prop->value() == "send") {
2789 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2790 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2791 send->SelfDestruct.connect_same_thread (*this,
2792 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2795 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2799 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2800 /* This processor could not be configured. Turn it into a UnknownProcessor */
2801 processor.reset (new UnknownProcessor (_session, **niter));
2804 /* subscribe to Sidechain IO changes */
2805 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2806 if (pi && pi->has_sidechain ()) {
2807 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2810 /* we have to note the monitor send here, otherwise a new one will be created
2811 and the state of this one will be lost.
2813 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2814 if (isend && isend->role() == Delivery::Listen) {
2815 _monitor_send = isend;
2818 /* it doesn't matter if invisible processors are added here, as they
2819 will be sorted out by setup_invisible_processors () shortly.
2822 new_order.push_back (processor);
2823 must_configure = true;
2829 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2830 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2831 _processors = new_order;
2833 if (must_configure) {
2834 configure_processors_unlocked (0, &lm);
2837 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2839 (*i)->set_owner (this);
2840 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2842 boost::shared_ptr<PluginInsert> pi;
2844 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2845 if (pi->has_no_inputs ()) {
2846 _have_internal_generator = true;
2853 reset_instrument_info ();
2854 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2855 set_processor_positions ();
2859 Route::curve_reallocate ()
2861 // _gain_automation_curve.finish_resize ();
2862 // _pan_automation_curve.finish_resize ();
2866 Route::silence (framecnt_t nframes)
2868 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2873 silence_unlocked (nframes);
2877 Route::silence_unlocked (framecnt_t nframes)
2879 /* Must be called with the processor lock held */
2883 _output->silence (nframes);
2885 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2886 boost::shared_ptr<PluginInsert> pi;
2888 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2889 // skip plugins, they don't need anything when we're not active
2893 (*i)->silence (nframes);
2896 if (nframes == _session.get_block_size()) {
2903 Route::add_internal_return ()
2906 _intreturn.reset (new InternalReturn (_session));
2907 add_processor (_intreturn, PreFader);
2912 Route::add_send_to_internal_return (InternalSend* send)
2914 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2916 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2917 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2920 return d->add_send (send);
2926 Route::remove_send_from_internal_return (InternalSend* send)
2928 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2930 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2931 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2934 return d->remove_send (send);
2940 Route::enable_monitor_send ()
2942 /* Caller must hold process lock */
2943 assert (!AudioEngine::instance()->process_lock().trylock());
2945 /* master never sends to monitor section via the normal mechanism */
2946 assert (!is_master ());
2947 assert (!is_monitor ());
2949 /* make sure we have one */
2950 if (!_monitor_send) {
2951 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
2952 _monitor_send->set_display_to_user (false);
2956 configure_processors (0);
2959 /** Add an aux send to a route.
2960 * @param route route to send to.
2961 * @param before Processor to insert before, or 0 to insert at the end.
2964 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2966 assert (route != _session.monitor_out ());
2969 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2971 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2973 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2975 if (d && d->target_route() == route) {
2976 /* already listening via the specified IO: do nothing */
2984 boost::shared_ptr<InternalSend> listener;
2987 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2988 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
2989 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
2992 add_processor (listener, before);
2994 } catch (failed_constructor& err) {
3002 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3004 ProcessorStreams err;
3005 ProcessorList::iterator tmp;
3008 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3010 /* have to do this early because otherwise processor reconfig
3011 * will put _monitor_send back in the list
3014 if (route == _session.monitor_out()) {
3015 _monitor_send.reset ();
3019 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3021 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3023 if (d && d->target_route() == route) {
3025 if (remove_processor (*x, &err, false) > 0) {
3031 /* list could have been demolished while we dropped the lock
3034 if (_session.engine().connected()) {
3035 /* i/o processors cannot be removed if the engine is not running
3036 * so don't live-loop in case the engine is N/A or dies
3046 Route::set_comment (string cmt, void *src)
3050 _session.set_dirty ();
3054 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3056 FeedRecord fr (other, via_sends_only);
3058 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3060 if (!result.second) {
3062 /* already a record for "other" - make sure sends-only information is correct */
3063 if (!via_sends_only && result.first->sends_only) {
3064 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3065 frp->sends_only = false;
3069 return result.second;
3073 Route::clear_fed_by ()
3079 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3081 const FedBy& fed_by (other->fed_by());
3083 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3084 boost::shared_ptr<Route> sr = f->r.lock();
3086 if (sr && (sr.get() == this)) {
3088 if (via_sends_only) {
3089 *via_sends_only = f->sends_only;
3100 Route::all_inputs () const
3102 /* TODO, if this works as expected,
3103 * cache the IOVector and maintain it via
3104 * input_change_handler(), sidechain_change_handler() etc
3107 ios.push_back (_input);
3109 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3110 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3112 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3113 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3116 iop = pi->sidechain();
3119 if (iop != 0 && iop->input()) {
3120 ios.push_back (iop->input());
3127 Route::all_outputs () const
3130 // _output is included via Delivery
3131 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3132 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3133 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3134 if (iop != 0 && iop->output()) {
3135 ios.push_back (iop->output());
3142 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3144 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3145 if (other->all_inputs().fed_by (_output)) {
3146 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3147 if (via_send_only) {
3148 *via_send_only = false;
3154 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3156 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3158 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3159 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3162 iop = pi->sidechain();
3166 boost::shared_ptr<const IO> iop_out = iop->output();
3167 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3168 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3169 if (via_send_only) {
3170 *via_send_only = true;
3174 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3177 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3182 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3187 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3189 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3193 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3195 return _session._current_route_graph.feeds (shared_from_this (), other);
3198 /** Called from the (non-realtime) butler thread when the transport is stopped */
3200 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3202 framepos_t now = _session.transport_frame();
3205 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3207 Automatable::transport_stopped (now);
3209 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3211 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3215 (*i)->transport_stopped (now);
3219 _roll_delay = _initial_delay;
3223 Route::input_change_handler (IOChange change, void * /*src*/)
3225 if ((change.type & IOChange::ConfigurationChanged)) {
3226 /* This is called with the process lock held if change
3227 contains ConfigurationChanged
3229 configure_processors (0);
3230 _phase_control->resize (_input->n_ports().n_audio ());
3231 io_changed (); /* EMIT SIGNAL */
3234 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3237 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3238 if (_input->connected()) {
3239 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3240 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3244 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3245 if (does_feed && !sends_only) {
3246 if ((*i)->soloed()) {
3249 if ((*i)->solo_isolate_control()->solo_isolated()) {
3256 int delta = sbou - _solo_control->soloed_by_others_upstream();
3257 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3260 PBD::warning << string_compose (
3261 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3262 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3267 if (_solo_control->soloed_by_others_upstream()) {
3268 // ignore new connections (they're not propagated)
3270 _solo_control->mod_solo_by_others_upstream (delta);
3274 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3275 // solo-isolate currently only propagates downstream
3277 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3279 //_solo_isolated_by_upstream = ibou;
3282 // Session::route_solo_changed does not propagate indirect solo-changes
3283 // propagate downstream to tracks
3284 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3285 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3289 bool does_feed = feeds (*i, &sends_only);
3290 if (delta <= 0 && does_feed && !sends_only) {
3291 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3294 if (idelta < 0 && does_feed && !sends_only) {
3295 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3302 Route::output_change_handler (IOChange change, void * /*src*/)
3304 if (_initial_io_setup) {
3308 if ((change.type & IOChange::ConfigurationChanged)) {
3309 /* This is called with the process lock held if change
3310 contains ConfigurationChanged
3312 configure_processors (0);
3315 _session.reset_monitor_section();
3318 io_changed (); /* EMIT SIGNAL */
3321 if (_solo_control->soloed_by_others_downstream()) {
3323 /* checking all all downstream routes for
3324 * explicit of implict solo is a rather drastic measure,
3325 * ideally the input_change_handler() of the other route
3326 * would propagate the change to us.
3328 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3329 if (_output->connected()) {
3330 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3331 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3335 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3336 if (does_feed && !sends_only) {
3337 if ((*i)->soloed()) {
3344 int delta = sbod - _solo_control->soloed_by_others_downstream();
3346 // do not allow new connections to change implicit solo (no propagation)
3347 _solo_control->mod_solo_by_others_downstream (delta);
3348 // Session::route_solo_changed() does not propagate indirect solo-changes
3349 // propagate upstream to tracks
3350 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3351 if ((*i).get() == this || !can_solo()) {
3355 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3356 if (delta != 0 && does_feed && !sends_only) {
3357 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3366 Route::sidechain_change_handler (IOChange change, void* src)
3368 if (_initial_io_setup || _in_sidechain_setup) {
3372 input_change_handler (change, src);
3376 Route::pans_required () const
3378 if (n_outputs().n_audio() < 2) {
3382 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3386 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3388 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3394 if (n_outputs().n_total() == 0) {
3398 if (!_active || n_inputs() == ChanCount::ZERO) {
3399 silence_unlocked (nframes);
3403 if (session_state_changing) {
3404 if (_session.transport_speed() != 0.0f) {
3405 /* we're rolling but some state is changing (e.g. our diskstream contents)
3406 so we cannot use them. Be silent till this is over.
3408 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3410 silence_unlocked (nframes);
3413 /* we're really not rolling, so we're either delivery silence or actually
3414 monitoring, both of which are safe to do while session_state_changing is true.
3418 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3420 fill_buffers_with_input (bufs, _input, nframes);
3422 if (_meter_point == MeterInput) {
3423 _meter->run (bufs, start_frame, end_frame, nframes, true);
3426 _amp->apply_gain_automation (false);
3427 _trim->apply_gain_automation (false);
3428 passthru (bufs, start_frame, end_frame, nframes, 0);
3434 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3436 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3441 if (n_outputs().n_total() == 0) {
3445 if (!_active || n_inputs().n_total() == 0) {
3446 silence_unlocked (nframes);
3450 framepos_t unused = 0;
3452 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3458 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3460 fill_buffers_with_input (bufs, _input, nframes);
3462 if (_meter_point == MeterInput) {
3463 _meter->run (bufs, start_frame, end_frame, nframes, true);
3466 passthru (bufs, start_frame, end_frame, nframes, declick);
3472 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3479 Route::flush_processors ()
3481 /* XXX shouldn't really try to take this lock, since
3482 this is called from the RT audio thread.
3485 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3487 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3493 __attribute__((annotate("realtime")))
3496 Route::apply_processor_changes_rt ()
3498 int emissions = EmitNone;
3500 if (_pending_meter_point != _meter_point) {
3501 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3503 /* meters always have buffers for 'processor_max_streams'
3504 * they can be re-positioned without re-allocation */
3505 if (set_meter_point_unlocked()) {
3506 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3508 emissions |= EmitMeterChanged;
3513 bool changed = false;
3515 if (g_atomic_int_get (&_pending_process_reorder)) {
3516 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3518 apply_processor_order (_pending_processor_order);
3519 setup_invisible_processors ();
3521 g_atomic_int_set (&_pending_process_reorder, 0);
3522 emissions |= EmitRtProcessorChange;
3526 set_processor_positions ();
3528 if (emissions != 0) {
3529 g_atomic_int_set (&_pending_signals, emissions);
3532 return (!selfdestruct_sequence.empty ());
3536 Route::emit_pending_signals ()
3538 int sig = g_atomic_int_and (&_pending_signals, 0);
3539 if (sig & EmitMeterChanged) {
3540 _meter->emit_configuration_changed();
3541 meter_change (); /* EMIT SIGNAL */
3542 if (sig & EmitMeterVisibilityChange) {
3543 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3545 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3548 if (sig & EmitRtProcessorChange) {
3549 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3552 /* this would be a job for the butler.
3553 * Conceptually we should not take processe/processor locks here.
3554 * OTOH its more efficient (less overhead for summoning the butler and
3555 * telling her what do do) and signal emission is called
3556 * directly after the process callback, which decreases the chance
3557 * of x-runs when taking the locks.
3559 while (!selfdestruct_sequence.empty ()) {
3560 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3561 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3562 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3563 selfdestruct_sequence.pop_back ();
3566 remove_processor (proc);
3572 Route::set_meter_point (MeterPoint p, bool force)
3574 if (_pending_meter_point == p && !force) {
3578 if (force || !AudioEngine::instance()->running()) {
3579 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3580 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3581 _pending_meter_point = p;
3582 _meter->emit_configuration_changed();
3583 meter_change (); /* EMIT SIGNAL */
3584 if (set_meter_point_unlocked()) {
3585 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3587 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3590 _pending_meter_point = p;
3596 __attribute__((annotate("realtime")))
3599 Route::set_meter_point_unlocked ()
3602 /* Caller must hold process and processor write lock */
3603 assert (!AudioEngine::instance()->process_lock().trylock());
3604 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3605 assert (!lm.locked ());
3608 _meter_point = _pending_meter_point;
3610 bool meter_was_visible_to_user = _meter->display_to_user ();
3612 if (!_custom_meter_position_noted) {
3613 maybe_note_meter_position ();
3616 if (_meter_point != MeterCustom) {
3618 _meter->set_display_to_user (false);
3620 setup_invisible_processors ();
3623 _meter->set_display_to_user (true);
3625 /* If we have a previous position for the custom meter, try to put it there */
3626 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3628 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3629 if (i != _processors.end ()) {
3630 _processors.remove (_meter);
3631 _processors.insert (i, _meter);
3633 } else {// at end, right before the mains_out/panner
3634 _processors.remove (_meter);
3635 ProcessorList::iterator main = _processors.end();
3636 _processors.insert (--main, _meter);
3640 /* Set up the meter for its new position */
3642 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3646 if (loc == _processors.begin()) {
3647 m_in = _input->n_ports();
3649 ProcessorList::iterator before = loc;
3651 m_in = (*before)->output_streams ();
3654 _meter->reflect_inputs (m_in);
3656 /* we do not need to reconfigure the processors, because the meter
3657 (a) is always ready to handle processor_max_streams
3658 (b) is always an N-in/N-out processor, and thus moving
3659 it doesn't require any changes to the other processors.
3662 /* these should really be done after releasing the lock
3663 * but all those signals are subscribed to with gui_thread()
3666 return (_meter->display_to_user() != meter_was_visible_to_user);
3670 Route::listen_position_changed ()
3673 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3674 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3675 ProcessorState pstate (this);
3677 if (configure_processors_unlocked (0, &lm)) {
3678 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3680 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3685 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3686 _session.set_dirty ();
3689 boost::shared_ptr<CapturingProcessor>
3690 Route::add_export_point()
3692 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3693 if (!_capturing_processor) {
3695 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3696 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3698 _capturing_processor.reset (new CapturingProcessor (_session));
3699 _capturing_processor->activate ();
3701 configure_processors_unlocked (0, &lw);
3705 return _capturing_processor;
3709 Route::update_signal_latency ()
3711 framecnt_t l = _output->user_latency();
3712 framecnt_t lamp = 0;
3713 bool before_amp = true;
3714 framecnt_t ltrim = 0;
3715 bool before_trim = true;
3717 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3718 if ((*i)->active ()) {
3719 l += (*i)->signal_latency ();
3724 if ((*i) == _trim) {
3735 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3737 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3738 _signal_latency_at_amp_position = lamp;
3739 _signal_latency_at_trim_position = ltrim;
3741 if (_signal_latency != l) {
3742 _signal_latency = l;
3743 signal_latency_changed (); /* EMIT SIGNAL */
3746 return _signal_latency;
3750 Route::set_user_latency (framecnt_t nframes)
3752 _output->set_user_latency (nframes);
3753 _session.update_latency_compensation ();
3757 Route::set_latency_compensation (framecnt_t longest_session_latency)
3759 framecnt_t old = _initial_delay;
3761 if (_signal_latency < longest_session_latency) {
3762 _initial_delay = longest_session_latency - _signal_latency;
3767 DEBUG_TRACE (DEBUG::Latency, string_compose (
3768 "%1: compensate for maximum latency of %2,"
3769 "given own latency of %3, using initial delay of %4\n",
3770 name(), longest_session_latency, _signal_latency, _initial_delay));
3772 if (_initial_delay != old) {
3773 initial_delay_changed (); /* EMIT SIGNAL */
3776 if (_session.transport_stopped()) {
3777 _roll_delay = _initial_delay;
3782 Route::set_block_size (pframes_t nframes)
3784 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3785 (*i)->set_block_size (nframes);
3788 _session.ensure_buffers (n_process_buffers ());
3792 Route::protect_automation ()
3794 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3795 (*i)->protect_automation();
3798 /** @param declick 1 to set a pending declick fade-in,
3799 * -1 to set a pending declick fade-out
3802 Route::set_pending_declick (int declick)
3805 /* this call is not allowed to turn off a pending declick */
3807 _pending_declick = declick;
3810 _pending_declick = 0;
3814 /** Shift automation forwards from a particular place, thereby inserting time.
3815 * Adds undo commands for any shifts that are performed.
3817 * @param pos Position to start shifting from.
3818 * @param frames Amount to shift forwards by.
3822 Route::shift (framepos_t pos, framecnt_t frames)
3824 /* gain automation */
3826 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3828 XMLNode &before = gc->alist()->get_state ();
3829 gc->alist()->shift (pos, frames);
3830 XMLNode &after = gc->alist()->get_state ();
3831 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3834 /* gain automation */
3836 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3838 XMLNode &before = gc->alist()->get_state ();
3839 gc->alist()->shift (pos, frames);
3840 XMLNode &after = gc->alist()->get_state ();
3841 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3844 // TODO mute automation ??
3846 /* pan automation */
3848 ControlSet::Controls& c (_pannable->controls());
3850 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3851 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3853 boost::shared_ptr<AutomationList> al = pc->alist();
3854 XMLNode& before = al->get_state ();
3855 al->shift (pos, frames);
3856 XMLNode& after = al->get_state ();
3857 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3862 /* redirect automation */
3864 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3865 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3867 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3869 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3870 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3872 boost::shared_ptr<AutomationList> al = ac->alist();
3873 XMLNode &before = al->get_state ();
3874 al->shift (pos, frames);
3875 XMLNode &after = al->get_state ();
3876 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3884 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
3886 boost::shared_ptr<Processor> processor (p.lock ());
3887 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3891 pi->set_state_dir (d);
3895 Route::save_as_template (const string& path, const string& name)
3897 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
3898 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
3900 XMLNode& node (state (false));
3904 IO::set_name_in_state (*node.children().front(), name);
3906 tree.set_root (&node);
3908 /* return zero on success, non-zero otherwise */
3909 return !tree.write (path.c_str());
3914 Route::set_name (const string& str)
3916 if (str == name()) {
3920 string name = Route::ensure_track_or_route_name (str, _session);
3921 SessionObject::set_name (name);
3923 bool ret = (_input->set_name(name) && _output->set_name(name));
3926 /* rename the main outs. Leave other IO processors
3927 * with whatever name they already have, because its
3928 * just fine as it is (it will not contain the route
3929 * name if its a port insert, port send or port return).
3933 if (_main_outs->set_name (name)) {
3934 /* XXX returning false here is stupid because
3935 we already changed the route name.
3945 /** Set the name of a route in an XML description.
3946 * @param node XML <Route> node to set the name in.
3947 * @param name New name.
3950 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
3952 node.add_property (X_("name"), name);
3954 XMLNodeList children = node.children();
3955 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3957 if ((*i)->name() == X_("IO")) {
3959 IO::set_name_in_state (**i, name);
3961 } else if ((*i)->name() == X_("Processor")) {
3963 XMLProperty const * role = (*i)->property (X_("role"));
3964 if (role && role->value() == X_("Main")) {
3965 (*i)->add_property (X_("name"), name);
3968 } else if ((*i)->name() == X_("Diskstream")) {
3970 if (rename_playlist) {
3971 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3973 (*i)->add_property (X_("name"), name);
3979 boost::shared_ptr<Send>
3980 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3982 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3984 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3985 boost::shared_ptr<InternalSend> send;
3987 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3988 if (send->target_route() == target) {
3994 return boost::shared_ptr<Send>();
3998 Route::set_denormal_protection (bool yn)
4000 if (_denormal_protection != yn) {
4001 _denormal_protection = yn;
4002 denormal_protection_changed (); /* EMIT SIGNAL */
4007 Route::denormal_protection () const
4009 return _denormal_protection;
4013 Route::set_active (bool yn, void* src)
4015 if (_session.transport_rolling()) {
4019 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4020 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4024 if (_active != yn) {
4026 _input->set_active (yn);
4027 _output->set_active (yn);
4028 active_changed (); // EMIT SIGNAL
4029 _session.set_dirty ();
4033 boost::shared_ptr<Pannable>
4034 Route::pannable() const
4039 boost::shared_ptr<Panner>
4040 Route::panner() const
4043 return _main_outs->panner_shell()->panner();
4046 boost::shared_ptr<PannerShell>
4047 Route::panner_shell() const
4049 return _main_outs->panner_shell();
4052 boost::shared_ptr<GainControl>
4053 Route::gain_control() const
4055 return _gain_control;
4058 boost::shared_ptr<GainControl>
4059 Route::trim_control() const
4061 return _trim_control;
4064 boost::shared_ptr<PhaseControl>
4065 Route::phase_control() const
4067 return _phase_control;
4070 boost::shared_ptr<AutomationControl>
4071 Route::get_control (const Evoral::Parameter& param)
4073 /* either we own the control or .... */
4075 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4079 /* maybe one of our processors does or ... */
4081 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4082 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4083 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4091 /* nobody does so we'll make a new one */
4093 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4100 boost::shared_ptr<Processor>
4101 Route::nth_plugin (uint32_t n) const
4103 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4104 ProcessorList::const_iterator i;
4106 for (i = _processors.begin(); i != _processors.end(); ++i) {
4107 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4114 return boost::shared_ptr<Processor> ();
4117 boost::shared_ptr<Processor>
4118 Route::nth_send (uint32_t n) const
4120 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4121 ProcessorList::const_iterator i;
4123 for (i = _processors.begin(); i != _processors.end(); ++i) {
4124 if (boost::dynamic_pointer_cast<Send> (*i)) {
4126 if ((*i)->name().find (_("Monitor")) == 0) {
4127 /* send to monitor section is not considered
4128 to be an accessible send.
4139 return boost::shared_ptr<Processor> ();
4143 Route::has_io_processor_named (const string& name)
4145 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4146 ProcessorList::iterator i;
4148 for (i = _processors.begin(); i != _processors.end(); ++i) {
4149 if (boost::dynamic_pointer_cast<Send> (*i) ||
4150 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4151 if ((*i)->name() == name) {
4161 Route::set_processor_positions ()
4163 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4165 bool had_amp = false;
4166 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4167 (*i)->set_pre_fader (!had_amp);
4174 /** Called when there is a proposed change to the input port count */
4176 Route::input_port_count_changing (ChanCount to)
4178 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4180 /* The processors cannot be configured with the new input arrangement, so
4186 /* The change is ok */
4190 /** Called when there is a proposed change to the output port count */
4192 Route::output_port_count_changing (ChanCount to)
4194 if (_strict_io && !_in_configure_processors) {
4197 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4198 if (processor_out_streams.get(*t) > to.get(*t)) {
4202 /* The change is ok */
4207 Route::unknown_processors () const
4211 if (_session.get_disable_all_loaded_plugins ()) {
4212 // Do not list "missing plugins" if they are explicitly disabled
4216 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4217 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4218 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4219 p.push_back ((*i)->name ());
4228 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4230 /* we assume that all our input ports feed all our output ports. its not
4231 universally true, but the alternative is way too corner-case to worry about.
4234 LatencyRange all_connections;
4237 all_connections.min = 0;
4238 all_connections.max = 0;
4240 all_connections.min = ~((pframes_t) 0);
4241 all_connections.max = 0;
4243 /* iterate over all "from" ports and determine the latency range for all of their
4244 connections to the "outside" (outside of this Route).
4247 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4251 p->get_connected_latency_range (range, playback);
4253 all_connections.min = min (all_connections.min, range.min);
4254 all_connections.max = max (all_connections.max, range.max);
4258 /* set the "from" port latencies to the max/min range of all their connections */
4260 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4261 p->set_private_latency_range (all_connections, playback);
4264 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4266 all_connections.min += our_latency;
4267 all_connections.max += our_latency;
4269 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4270 p->set_private_latency_range (all_connections, playback);
4273 return all_connections.max;
4277 Route::set_private_port_latencies (bool playback) const
4279 framecnt_t own_latency = 0;
4281 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4282 OR LATENCY CALLBACK.
4284 This is called (early) from the latency callback. It computes the REAL
4285 latency associated with each port and stores the result as the "private"
4286 latency of the port. A later call to Route::set_public_port_latencies()
4287 sets all ports to the same value to reflect the fact that we do latency
4288 compensation and so all signals are delayed by the same amount as they
4289 flow through ardour.
4292 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4293 if ((*i)->active ()) {
4294 own_latency += (*i)->signal_latency ();
4299 /* playback: propagate latency from "outside the route" to outputs to inputs */
4300 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4302 /* capture: propagate latency from "outside the route" to inputs to outputs */
4303 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4308 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4310 /* this is called to set the JACK-visible port latencies, which take
4311 latency compensation into account.
4320 const PortSet& ports (_input->ports());
4321 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4322 p->set_public_latency_range (range, playback);
4327 const PortSet& ports (_output->ports());
4328 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4329 p->set_public_latency_range (range, playback);
4334 /** Put the invisible processors in the right place in _processors.
4335 * Must be called with a writer lock on _processor_lock held.
4338 __attribute__((annotate("realtime")))
4341 Route::setup_invisible_processors ()
4344 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4345 assert (!lm.locked ());
4349 /* too early to be doing this stuff */
4353 /* we'll build this new list here and then use it
4355 * TODO put the ProcessorList is on the stack for RT-safety.
4358 ProcessorList new_processors;
4360 /* find visible processors */
4362 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4363 if ((*i)->display_to_user ()) {
4364 new_processors.push_back (*i);
4370 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4372 if (amp == new_processors.end ()) {
4373 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4374 new_processors.push_front (_amp);
4375 amp = find (new_processors.begin(), new_processors.end(), _amp);
4378 /* and the processor after the amp */
4380 ProcessorList::iterator after_amp = amp;
4386 switch (_meter_point) {
4388 assert (!_meter->display_to_user ());
4389 new_processors.push_front (_meter);
4392 assert (!_meter->display_to_user ());
4393 new_processors.insert (amp, _meter);
4395 case MeterPostFader:
4396 /* do nothing here */
4399 /* do nothing here */
4402 /* the meter is visible, so we don't touch it here */
4409 assert (_main_outs);
4410 assert (!_main_outs->display_to_user ());
4411 new_processors.push_back (_main_outs);
4413 /* iterator for the main outs */
4415 ProcessorList::iterator main = new_processors.end();
4418 /* OUTPUT METERING */
4420 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4421 assert (!_meter->display_to_user ());
4423 /* add the processor just before or just after the main outs */
4425 ProcessorList::iterator meter_point = main;
4427 if (_meter_point == MeterOutput) {
4430 new_processors.insert (meter_point, _meter);
4435 if (_monitor_send && !is_monitor ()) {
4436 assert (!_monitor_send->display_to_user ());
4437 switch (Config->get_listen_position ()) {
4438 case PreFaderListen:
4439 switch (Config->get_pfl_position ()) {
4440 case PFLFromBeforeProcessors:
4441 new_processors.push_front (_monitor_send);
4443 case PFLFromAfterProcessors:
4444 new_processors.insert (amp, _monitor_send);
4447 _monitor_send->set_can_pan (false);
4449 case AfterFaderListen:
4450 switch (Config->get_afl_position ()) {
4451 case AFLFromBeforeProcessors:
4452 new_processors.insert (after_amp, _monitor_send);
4454 case AFLFromAfterProcessors:
4455 new_processors.insert (new_processors.end(), _monitor_send);
4458 _monitor_send->set_can_pan (true);
4463 #if 0 // not used - just yet
4464 if (!is_master() && !is_monitor() && !is_auditioner()) {
4465 new_processors.push_front (_delayline);
4469 /* MONITOR CONTROL */
4471 if (_monitor_control && is_monitor ()) {
4472 assert (!_monitor_control->display_to_user ());
4473 new_processors.insert (amp, _monitor_control);
4476 /* INTERNAL RETURN */
4478 /* doing this here means that any monitor control will come just after
4483 assert (!_intreturn->display_to_user ());
4484 new_processors.push_front (_intreturn);
4487 if (_trim && _trim->active()) {
4488 assert (!_trim->display_to_user ());
4489 new_processors.push_front (_trim);
4491 /* EXPORT PROCESSOR */
4493 if (_capturing_processor) {
4494 assert (!_capturing_processor->display_to_user ());
4495 new_processors.push_front (_capturing_processor);
4498 _processors = new_processors;
4500 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4501 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4506 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4507 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4508 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4515 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4516 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4520 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4521 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4528 /** If the meter point is `Custom', make a note of where the meter is.
4529 * This is so that if the meter point is subsequently set to something else,
4530 * and then back to custom, we can put the meter back where it was last time
4531 * custom was enabled.
4533 * Must be called with the _processor_lock held.
4536 Route::maybe_note_meter_position ()
4538 if (_meter_point != MeterCustom) {
4542 _custom_meter_position_noted = true;
4543 /* custom meter points range from after trim to before panner/main_outs
4544 * this is a limitation by the current processor UI
4546 bool seen_trim = false;
4547 _processor_after_last_custom_meter.reset();
4548 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4549 if ((*i) == _trim) {
4552 if ((*i) == _main_outs) {
4553 _processor_after_last_custom_meter = *i;
4556 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4558 _processor_after_last_custom_meter = _trim;
4560 ProcessorList::iterator j = i;
4562 assert(j != _processors.end ()); // main_outs should be before
4563 _processor_after_last_custom_meter = *j;
4568 assert(_processor_after_last_custom_meter.lock());
4571 boost::shared_ptr<Processor>
4572 Route::processor_by_id (PBD::ID id) const
4574 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4575 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4576 if ((*i)->id() == id) {
4581 return boost::shared_ptr<Processor> ();
4584 /** @return the monitoring state, or in other words what data we are pushing
4585 * into the route (data from the inputs, data from disk or silence)
4588 Route::monitoring_state () const
4590 return MonitoringInput;
4593 /** @return what we should be metering; either the data coming from the input
4594 * IO or the data that is flowing through the route.
4597 Route::metering_state () const
4599 return MeteringRoute;
4603 Route::has_external_redirects () const
4605 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4607 /* ignore inactive processors and obviously ignore the main
4608 * outs since everything has them and we don't care.
4611 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4619 boost::shared_ptr<Processor>
4620 Route::the_instrument () const
4622 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4623 return the_instrument_unlocked ();
4626 boost::shared_ptr<Processor>
4627 Route::the_instrument_unlocked () const
4629 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4630 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4631 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4635 return boost::shared_ptr<Processor>();
4641 Route::non_realtime_locate (framepos_t pos)
4644 _pannable->transport_located (pos);
4647 if (_delayline.get()) {
4648 _delayline.get()->flush();
4652 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4653 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4655 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4656 (*i)->transport_located (pos);
4659 _roll_delay = _initial_delay;
4663 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4670 * We don't currently mix MIDI input together, so we don't need the
4671 * complex logic of the audio case.
4674 n_buffers = bufs.count().n_midi ();
4676 for (i = 0; i < n_buffers; ++i) {
4678 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4679 MidiBuffer& buf (bufs.get_midi (i));
4682 buf.copy (source_port->get_midi_buffer(nframes));
4684 buf.silence (nframes);
4690 n_buffers = bufs.count().n_audio();
4692 size_t n_ports = io->n_ports().n_audio();
4693 float scaling = 1.0f;
4695 if (n_ports > n_buffers) {
4696 scaling = ((float) n_buffers) / n_ports;
4699 for (i = 0; i < n_ports; ++i) {
4701 /* if there are more ports than buffers, map them onto buffers
4702 * in a round-robin fashion
4705 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4706 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4709 if (i < n_buffers) {
4711 /* first time through just copy a channel into
4715 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4717 if (scaling != 1.0f) {
4718 buf.apply_gain (scaling, nframes);
4723 /* on subsequent times around, merge data from
4724 * the port with what is already there
4727 if (scaling != 1.0f) {
4728 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4730 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4735 /* silence any remaining buffers */
4737 for (; i < n_buffers; ++i) {
4738 AudioBuffer& buf (bufs.get_audio (i));
4739 buf.silence (nframes);
4742 /* establish the initial setup of the buffer set, reflecting what was
4743 copied into it. unless, of course, we are the auditioner, in which
4744 case nothing was fed into it from the inputs at all.
4747 if (!is_auditioner()) {
4748 bufs.set_count (io->n_ports());
4752 boost::shared_ptr<AutomationControl>
4753 Route::pan_azimuth_control() const
4756 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4758 return boost::shared_ptr<AutomationControl>();
4760 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
4761 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4763 if (!_pannable || !panner()) {
4764 return boost::shared_ptr<AutomationControl>();
4766 return _pannable->pan_azimuth_control;
4770 boost::shared_ptr<AutomationControl>
4771 Route::pan_elevation_control() const
4773 if (Profile->get_mixbus() || !_pannable || !panner()) {
4774 return boost::shared_ptr<AutomationControl>();
4777 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4779 if (c.find (PanElevationAutomation) != c.end()) {
4780 return _pannable->pan_elevation_control;
4782 return boost::shared_ptr<AutomationControl>();
4785 boost::shared_ptr<AutomationControl>
4786 Route::pan_width_control() const
4788 if (Profile->get_mixbus() || !_pannable || !panner()) {
4789 return boost::shared_ptr<AutomationControl>();
4792 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4794 if (c.find (PanWidthAutomation) != c.end()) {
4795 return _pannable->pan_width_control;
4797 return boost::shared_ptr<AutomationControl>();
4800 boost::shared_ptr<AutomationControl>
4801 Route::pan_frontback_control() const
4803 if (Profile->get_mixbus() || !_pannable || !panner()) {
4804 return boost::shared_ptr<AutomationControl>();
4807 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4809 if (c.find (PanFrontBackAutomation) != c.end()) {
4810 return _pannable->pan_frontback_control;
4812 return boost::shared_ptr<AutomationControl>();
4815 boost::shared_ptr<AutomationControl>
4816 Route::pan_lfe_control() const
4818 if (Profile->get_mixbus() || !_pannable || !panner()) {
4819 return boost::shared_ptr<AutomationControl>();
4822 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4824 if (c.find (PanLFEAutomation) != c.end()) {
4825 return _pannable->pan_lfe_control;
4827 return boost::shared_ptr<AutomationControl>();
4832 Route::eq_band_cnt () const
4834 if (Profile->get_mixbus()) {
4837 /* Ardour has no well-known EQ object */
4842 boost::shared_ptr<AutomationControl>
4843 Route::eq_gain_controllable (uint32_t band) const
4846 boost::shared_ptr<PluginInsert> eq = ch_eq();
4849 return boost::shared_ptr<AutomationControl>();
4852 uint32_t port_number;
4855 if (is_master() || mixbus()) {
4862 if (is_master() || mixbus()) {
4869 if (is_master() || mixbus()) {
4876 return boost::shared_ptr<AutomationControl>();
4879 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
4881 return boost::shared_ptr<AutomationControl>();
4884 boost::shared_ptr<AutomationControl>
4885 Route::eq_freq_controllable (uint32_t band) const
4889 if (mixbus() || is_master()) {
4890 /* no frequency controls for mixbusses or master */
4891 return boost::shared_ptr<AutomationControl>();
4894 boost::shared_ptr<PluginInsert> eq = ch_eq();
4897 return boost::shared_ptr<AutomationControl>();
4900 uint32_t port_number;
4912 return boost::shared_ptr<AutomationControl>();
4915 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
4917 return boost::shared_ptr<AutomationControl>();
4921 boost::shared_ptr<AutomationControl>
4922 Route::eq_q_controllable (uint32_t band) const
4924 return boost::shared_ptr<AutomationControl>();
4927 boost::shared_ptr<AutomationControl>
4928 Route::eq_shape_controllable (uint32_t band) const
4930 return boost::shared_ptr<AutomationControl>();
4933 boost::shared_ptr<AutomationControl>
4934 Route::eq_enable_controllable () const
4937 boost::shared_ptr<PluginInsert> eq = ch_eq();
4940 return boost::shared_ptr<AutomationControl>();
4943 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
4945 return boost::shared_ptr<AutomationControl>();
4949 boost::shared_ptr<AutomationControl>
4950 Route::eq_hpf_controllable () const
4953 boost::shared_ptr<PluginInsert> eq = ch_eq();
4956 return boost::shared_ptr<AutomationControl>();
4959 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
4961 return boost::shared_ptr<AutomationControl>();
4966 Route::eq_band_name (uint32_t band) const
4968 if (Profile->get_mixbus()) {
4984 boost::shared_ptr<AutomationControl>
4985 Route::comp_enable_controllable () const
4988 boost::shared_ptr<PluginInsert> comp = ch_comp();
4991 return boost::shared_ptr<AutomationControl>();
4994 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
4996 return boost::shared_ptr<AutomationControl>();
4999 boost::shared_ptr<AutomationControl>
5000 Route::comp_threshold_controllable () const
5003 boost::shared_ptr<PluginInsert> comp = ch_comp();
5006 return boost::shared_ptr<AutomationControl>();
5009 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5012 return boost::shared_ptr<AutomationControl>();
5015 boost::shared_ptr<AutomationControl>
5016 Route::comp_speed_controllable () const
5019 boost::shared_ptr<PluginInsert> comp = ch_comp();
5022 return boost::shared_ptr<AutomationControl>();
5025 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5027 return boost::shared_ptr<AutomationControl>();
5030 boost::shared_ptr<AutomationControl>
5031 Route::comp_mode_controllable () const
5034 boost::shared_ptr<PluginInsert> comp = ch_comp();
5037 return boost::shared_ptr<AutomationControl>();
5040 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5042 return boost::shared_ptr<AutomationControl>();
5045 boost::shared_ptr<AutomationControl>
5046 Route::comp_makeup_controllable () const
5049 boost::shared_ptr<PluginInsert> comp = ch_comp();
5052 return boost::shared_ptr<AutomationControl>();
5055 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5057 return boost::shared_ptr<AutomationControl>();
5060 boost::shared_ptr<AutomationControl>
5061 Route::comp_redux_controllable () const
5064 boost::shared_ptr<PluginInsert> comp = ch_comp();
5067 return boost::shared_ptr<AutomationControl>();
5070 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5072 return boost::shared_ptr<AutomationControl>();
5077 Route::comp_mode_name (uint32_t mode) const
5082 return _("Leveler");
5084 return _("Compressor");
5086 return _("Limiter");
5088 return mixbus() ? _("Sidechain") : _("Limiter");
5098 Route::comp_speed_name (uint32_t mode) const
5116 boost::shared_ptr<AutomationControl>
5117 Route::send_level_controllable (uint32_t n) const
5120 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5122 return boost::shared_ptr<AutomationControl>();
5127 return boost::shared_ptr<AutomationControl>();
5130 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5131 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5133 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5135 return boost::shared_ptr<AutomationControl>();
5137 return s->gain_control ();
5141 boost::shared_ptr<AutomationControl>
5142 Route::send_enable_controllable (uint32_t n) const
5145 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5147 return boost::shared_ptr<AutomationControl>();
5152 return boost::shared_ptr<AutomationControl>();
5155 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5156 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5158 /* although Ardour sends have enable/disable as part of the Processor
5159 API, it is not exposed as a controllable.
5161 XXX: we should fix this.
5163 return boost::shared_ptr<AutomationControl>();
5168 Route::send_name (uint32_t n) const
5174 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5178 boost::shared_ptr<Processor> p = nth_send (n);
5187 boost::shared_ptr<AutomationControl>
5188 Route::master_send_enable_controllable () const
5191 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5193 return boost::shared_ptr<AutomationControl>();
5195 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5197 return boost::shared_ptr<AutomationControl>();
5202 Route::slaved () const
5204 if (!_gain_control) {
5207 /* just test one particular control, not all of them */
5208 return _gain_control->slaved ();
5212 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5214 if (!vca || !_gain_control) {
5218 /* just test one particular control, not all of them */
5220 return _gain_control->slaved_to (vca->gain_control());
5224 Route::muted_by_others_soloing () const
5226 if (!can_be_muted_by_others ()) {
5230 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5234 Route::clear_all_solo_state ()
5236 double v = _solo_safe_control->get_value ();
5238 _solo_control->clear_all_solo_state ();
5241 _solo_safe_control->set_value (v, Controllable::NoGroup);