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/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/event_type_map.h"
51 #include "ardour/gain_control.h"
52 #include "ardour/internal_return.h"
53 #include "ardour/internal_send.h"
54 #include "ardour/meter.h"
55 #include "ardour/delayline.h"
56 #include "ardour/midi_buffer.h"
57 #include "ardour/midi_port.h"
58 #include "ardour/monitor_processor.h"
59 #include "ardour/pannable.h"
60 #include "ardour/panner.h"
61 #include "ardour/panner_shell.h"
62 #include "ardour/parameter_descriptor.h"
63 #include "ardour/phase_control.h"
64 #include "ardour/plugin_insert.h"
65 #include "ardour/port.h"
66 #include "ardour/port_insert.h"
67 #include "ardour/processor.h"
68 #include "ardour/profile.h"
69 #include "ardour/route.h"
70 #include "ardour/route_group.h"
71 #include "ardour/send.h"
72 #include "ardour/session.h"
73 #include "ardour/solo_control.h"
74 #include "ardour/solo_isolate_control.h"
75 #include "ardour/types_convert.h"
76 #include "ardour/unknown_processor.h"
77 #include "ardour/utils.h"
78 #include "ardour/vca.h"
83 using namespace ARDOUR;
86 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
88 /** Base class for all routable/mixable objects (tracks and busses) */
89 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
90 : Stripable (sess, name, PresentationInfo (flag))
91 , GraphNode (sess._process_graph)
92 , Muteable (sess, name)
95 , _signal_latency_at_amp_position (0)
96 , _signal_latency_at_trim_position (0)
99 , _pending_process_reorder (0)
100 , _pending_signals (0)
101 , _pending_declick (true)
102 , _meter_point (MeterPostFader)
103 , _pending_meter_point (MeterPostFader)
104 , _meter_type (MeterPeak)
105 , _denormal_protection (false)
108 , _declickable (false)
109 , _have_internal_generator (false)
110 , _default_type (default_type)
112 , _in_configure_processors (false)
113 , _initial_io_setup (false)
114 , _in_sidechain_setup (false)
116 , _custom_meter_position_noted (false)
118 , _patch_selector_dialog (0)
120 processor_max_streams.reset();
123 boost::weak_ptr<Route>
124 Route::weakroute () {
125 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
131 /* set default meter type */
133 _meter_type = Config->get_meter_type_master ();
135 else if (dynamic_cast<Track*>(this)) {
136 _meter_type = Config->get_meter_type_track ();
138 _meter_type = Config->get_meter_type_bus ();
141 /* add standard controls */
143 _gain_control.reset (new GainControl (_session, GainAutomation));
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 /* While the route has-a gain-control for consistency with Stripable and VCA
146 * ownership is handed over to the Amp Processor which manages the
147 * state of the Control and AutomationList as part of its
148 * Automatable API. -- Don't call add_control () here.
151 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
152 add_control (_solo_control);
153 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
155 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
156 add_control (_mute_control);
158 _phase_control.reset (new PhaseControl (_session, X_("phase")));
159 add_control (_phase_control);
161 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
162 add_control (_solo_isolate_control);
164 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
165 add_control (_solo_safe_control);
169 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
170 _pannable.reset (new Pannable (_session));
173 /* input and output objects */
175 _input.reset (new IO (_session, _name, IO::Input, _default_type));
176 _output.reset (new IO (_session, _name, IO::Output, _default_type));
178 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
179 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
181 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
182 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
184 /* add the amp/fader processor.
185 * it should be the first processor to be added on every route.
188 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
189 add_processor (_amp, PostFader);
192 _amp->set_display_name (_("Monitor"));
195 #if 0 // not used - just yet
196 if (!is_master() && !is_monitor() && !is_auditioner()) {
197 _delayline.reset (new DelayLine (_session, _name));
198 add_processor (_delayline, PreFader);
204 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
205 _trim->set_display_to_user (false);
207 if (dynamic_cast<AudioTrack*>(this)) {
208 /* we can't do this in the AudioTrack's constructor
209 * because _trim does not exit then
213 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
218 /* create standard processors: meter, main outs, monitor out;
219 they will be added to _processors by setup_invisible_processors ()
222 _meter.reset (new PeakMeter (_session, _name));
223 _meter->set_owner (this);
224 _meter->set_display_to_user (false);
227 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
228 _main_outs->activate ();
231 /* where we listen to tracks */
232 _intreturn.reset (new InternalReturn (_session));
233 _intreturn->activate ();
235 /* the thing that provides proper control over a control/monitor/listen bus
236 (such as per-channel cut, dim, solo, invert, etc).
238 _monitor_control.reset (new MonitorProcessor (_session));
239 _monitor_control->activate ();
242 /* now that we have _meter, its safe to connect to this */
245 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
246 configure_processors (0);
254 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
256 /* do this early so that we don't get incoming signals as we are going through destruction
261 /* don't use clear_processors here, as it depends on the session which may
262 be half-destroyed by now
265 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
266 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
267 (*i)->drop_references ();
270 _processors.clear ();
274 Route::ensure_track_or_route_name(string name, Session &session)
276 string newname = name;
278 while (!session.io_name_is_legal (newname)) {
279 newname = bump_name_once (newname, ' ');
286 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
288 // TODO route group, see set_gain()
289 // _trim_control->route_set_value (val);
293 Route::maybe_declick (BufferSet&, framecnt_t, int)
295 /* this is the "bus" implementation and they never declick.
300 /** Process this route for one (sub) cycle (process thread)
302 * @param bufs Scratch buffers to use for the signal path
303 * @param start_frame Initial transport frame
304 * @param end_frame Final transport frame
305 * @param nframes Number of frames to output (to ports)
307 * Note that (end_frame - start_frame) may not be equal to nframes when the
308 * transport speed isn't 1.0 (eg varispeed).
311 Route::process_output_buffers (BufferSet& bufs,
312 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
313 int declick, bool gain_automation_ok)
315 /* Caller must hold process lock */
316 assert (!AudioEngine::instance()->process_lock().trylock());
318 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
320 // can this actually happen? functions calling process_output_buffers()
321 // already take a reader-lock.
322 bufs.silence (nframes, 0);
326 automation_run (start_frame, nframes);
328 /* figure out if we're going to use gain automation */
329 if (gain_automation_ok) {
330 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
331 _amp->setup_gain_automation (
332 start_frame + _signal_latency_at_amp_position,
333 end_frame + _signal_latency_at_amp_position,
336 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
337 _trim->setup_gain_automation (
338 start_frame + _signal_latency_at_trim_position,
339 end_frame + _signal_latency_at_trim_position,
342 _amp->apply_gain_automation (false);
343 _trim->apply_gain_automation (false);
346 /* Tell main outs what to do about monitoring. We do this so that
347 on a transition between monitoring states we get a de-clicking gain
348 change in the _main_outs delivery, if config.get_use_monitor_fades()
351 We override this in the case where we have an internal generator.
353 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
355 _main_outs->no_outs_cuz_we_no_monitor (silence);
357 /* -------------------------------------------------------------------------------------------
358 GLOBAL DECLICK (for transport changes etc.)
359 ----------------------------------------------------------------------------------------- */
361 maybe_declick (bufs, nframes, declick);
362 _pending_declick = 0;
364 /* -------------------------------------------------------------------------------------------
365 DENORMAL CONTROL/PHASE INVERT
366 ----------------------------------------------------------------------------------------- */
368 if (!_phase_control->none()) {
372 if (_denormal_protection || Config->get_denormal_protection()) {
374 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
375 Sample* const sp = i->data();
377 if (_phase_control->inverted (chn)) {
378 for (pframes_t nx = 0; nx < nframes; ++nx) {
383 for (pframes_t nx = 0; nx < nframes; ++nx) {
391 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
392 Sample* const sp = i->data();
394 if (_phase_control->inverted (chn)) {
395 for (pframes_t nx = 0; nx < nframes; ++nx) {
404 if (_denormal_protection || Config->get_denormal_protection()) {
406 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
407 Sample* const sp = i->data();
408 for (pframes_t nx = 0; nx < nframes; ++nx) {
416 /* -------------------------------------------------------------------------------------------
418 ----------------------------------------------------------------------------------------- */
420 /* set this to be true if the meter will already have been ::run() earlier */
421 bool const meter_already_run = metering_state() == MeteringInput;
423 framecnt_t latency = 0;
424 const double speed = _session.transport_speed ();
426 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
428 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
429 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
434 /* if it has any inputs, make sure they match */
435 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
436 if (bufs.count() != (*i)->input_streams()) {
438 DEBUG::Processors, string_compose (
439 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
440 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
447 /* should we NOT run plugins here if the route is inactive?
448 do we catch route != active somewhere higher?
451 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
452 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
454 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
455 const framecnt_t longest_session_latency = _initial_delay + _signal_latency;
456 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
457 _initial_delay + latency, longest_session_latency - latency);
460 //cerr << name() << " run " << (*i)->name() << endl;
461 (*i)->run (bufs, start_frame - latency, end_frame - latency, speed, nframes, *i != _processors.back());
462 bufs.set_count ((*i)->output_streams());
464 if ((*i)->active ()) {
465 latency += (*i)->signal_latency ();
471 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
472 boost::shared_ptr<Processor> endpoint,
473 bool include_endpoint, bool for_export, bool for_freeze)
475 /* If no processing is required, there's no need to go any further. */
476 if (!endpoint && !include_endpoint) {
480 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
481 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
482 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
484 /* trim is always at the top, for bounce no latency compensation is needed */
485 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
486 _trim->setup_gain_automation (start, start + nframes, nframes);
489 const double speed = _session.transport_speed ();
490 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
492 if (!include_endpoint && (*i) == endpoint) {
496 /* if we're *not* exporting, stop processing if we come across a routing processor. */
497 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
500 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
504 /* special case the panner (export outputs)
505 * Ideally we'd only run the panner, not the delivery itself...
506 * but panners need separate input/output buffers and some context
507 * (panshell, panner type, etc). AFAICT there is no ill side effect
508 * of re-using the main delivery when freewheeling/exporting a region.
510 if ((*i) == _main_outs) {
511 assert ((*i)->does_routing());
512 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
513 buffers.set_count ((*i)->output_streams());
516 /* don't run any processors that do routing.
517 * Also don't bother with metering.
519 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
520 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
521 buffers.set_count ((*i)->output_streams());
522 latency += (*i)->signal_latency ();
525 if ((*i) == endpoint) {
532 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
533 bool include_endpoint, bool for_export, bool for_freeze) const
535 framecnt_t latency = 0;
536 if (!endpoint && !include_endpoint) {
540 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
541 if (!include_endpoint && (*i) == endpoint) {
544 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
547 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
550 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
551 latency += (*i)->signal_latency ();
553 if ((*i) == endpoint) {
561 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
562 bool include_endpoint, bool for_export, bool for_freeze) const
564 if (!endpoint && !include_endpoint) {
568 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
569 if (!include_endpoint && (*i) == endpoint) {
572 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
575 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
578 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
579 cc = (*i)->output_streams();
581 if ((*i) == endpoint) {
589 Route::n_process_buffers ()
591 return max (_input->n_ports(), processor_max_streams);
595 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
597 assert (is_monitor());
598 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
599 fill_buffers_with_input (bufs, _input, nframes);
600 passthru (bufs, start_frame, end_frame, nframes, declick);
604 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
608 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
610 /* control/monitor bus ignores input ports when something is
611 feeding the listen "stream". data will "arrive" into the
612 route from the intreturn processor element.
615 bufs.silence (nframes, 0);
618 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
619 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
623 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
625 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
627 bufs.set_count (_input->n_ports());
628 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
629 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
633 Route::set_listen (bool yn)
636 if (_monitor_send->active() == yn) {
640 _monitor_send->activate ();
642 _monitor_send->deactivate ();
648 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
650 /* nothing to do if we're not using AFL/PFL. But if we are, we need
651 to alter the active state of the monitor send.
654 if (Config->get_solo_control_is_listen_control ()) {
655 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
660 Route::push_solo_isolate_upstream (int32_t delta)
662 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
664 boost::shared_ptr<RouteList> routes = _session.get_routes ();
665 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
667 if ((*i).get() == this || !(*i)->can_solo()) {
672 bool does_feed = feeds (*i, &sends_only);
674 if (does_feed && !sends_only) {
675 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
681 Route::push_solo_upstream (int delta)
683 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
684 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
688 boost::shared_ptr<Route> sr (i->r.lock());
690 sr->solo_control()->mod_solo_by_others_downstream (-delta);
697 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
699 cerr << name << " {" << endl;
700 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
701 p != procs.end(); ++p) {
702 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
708 /** Supposing that we want to insert a Processor at a given Placement, return
709 * the processor to add the new one before (or 0 to add at the end).
711 boost::shared_ptr<Processor>
712 Route::before_processor_for_placement (Placement p)
714 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
716 ProcessorList::iterator loc;
719 /* generic pre-fader: insert immediately before the amp */
720 loc = find (_processors.begin(), _processors.end(), _amp);
722 /* generic post-fader: insert right before the main outs */
723 loc = find (_processors.begin(), _processors.end(), _main_outs);
726 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
729 /** Supposing that we want to insert a Processor at a given index, return
730 * the processor to add the new one before (or 0 to add at the end).
732 boost::shared_ptr<Processor>
733 Route::before_processor_for_index (int index)
736 return boost::shared_ptr<Processor> ();
739 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
741 ProcessorList::iterator i = _processors.begin ();
743 while (i != _processors.end() && j < index) {
744 if ((*i)->display_to_user()) {
751 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
754 /** Add a processor either pre- or post-fader
755 * @return 0 on success, non-0 on failure.
758 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
760 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
764 /** Add a processor to a route such that it ends up with a given index into the visible processors.
765 * @param index Index to add the processor at, or -1 to add at the end of the list.
766 * @return 0 on success, non-0 on failure.
769 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
771 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
774 /** Add a processor to the route.
775 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
776 * @return 0 on success, non-0 on failure.
779 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
781 assert (processor != _meter);
782 assert (processor != _main_outs);
784 DEBUG_TRACE (DEBUG::Processors, string_compose (
785 "%1 adding processor %2\n", name(), processor->name()));
789 pl.push_back (processor);
790 int rv = add_processors (pl, before, err);
796 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
797 processor->activate ();
804 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
806 /* We cannot destruct the processor here (usually RT-thread
807 * with various locks held - in case of sends also io_locks).
808 * Queue for deletion in low-priority thread.
810 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
811 selfdestruct_sequence.push_back (wp);
815 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
817 XMLProperty const * prop;
820 boost::shared_ptr<Processor> processor;
822 /* bit of a hack: get the `placement' property from the <Redirect> tag here
823 so that we can add the processor in the right place (pre/post-fader)
826 XMLNodeList const & children = node.children ();
827 XMLNodeList::const_iterator i = children.begin ();
829 while (i != children.end() && (*i)->name() != X_("Redirect")) {
833 Placement placement = PreFader;
835 if (i != children.end()) {
836 if ((prop = (*i)->property (X_("placement"))) != 0) {
837 placement = Placement (string_2_enum (prop->value(), placement));
841 if (node.name() == "Insert") {
843 if ((prop = node.property ("type")) != 0) {
845 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
846 prop->value() == "lv2" ||
847 prop->value() == "windows-vst" ||
848 prop->value() == "mac-vst" ||
849 prop->value() == "lxvst" ||
850 prop->value() == "audiounit") {
852 if (_session.get_disable_all_loaded_plugins ()) {
853 processor.reset (new UnknownProcessor (_session, node));
855 processor.reset (new PluginInsert (_session));
856 processor->set_owner (this);
861 processor.reset (new PortInsert (_session, _pannable, _mute_master));
866 } else if (node.name() == "Send") {
868 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
869 processor.reset (new Send (_session, sendpan, _mute_master));
873 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
877 if (processor->set_state (node, version)) {
881 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
882 if (i != children.end()) {
883 if ((prop = (*i)->property (X_("active"))) != 0) {
884 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
885 processor->activate();
887 processor->deactivate();
891 return (add_processor (processor, placement, 0, false) == 0);
894 catch (failed_constructor &err) {
895 warning << _("processor could not be created. Ignored.") << endmsg;
901 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
902 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
905 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
906 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
910 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
912 ProcessorList::iterator loc;
913 boost::shared_ptr <PluginInsert> fanout;
915 if (g_atomic_int_get (&_pending_process_reorder)) {
916 /* we need to flush any pending re-order changes */
917 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
918 apply_processor_changes_rt ();
922 loc = find(_processors.begin(), _processors.end(), before);
923 if (loc == _processors.end ()) {
927 /* nothing specified - at end */
928 loc = _processors.end ();
931 if (others.empty()) {
935 ProcessorList to_skip;
937 // check if there's an instrument to replace or configure
938 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
939 boost::shared_ptr<PluginInsert> pi;
940 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
943 if (!pi->plugin ()->get_info ()->is_instrument ()) {
946 boost::shared_ptr<Processor> instrument = the_instrument ();
947 ChanCount in (DataType::MIDI, 1);
948 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
950 PluginSetupOptions flags = None;
953 in = instrument->input_streams ();
954 out = instrument->output_streams ();
956 if (pi->has_output_presets (in, out)) {
960 pi->set_strict_io (_strict_io);
962 PluginSetupOptions mask = None;
963 if (Config->get_ask_replace_instrument ()) {
966 if (Config->get_ask_setup_instrument ()) {
973 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
974 int mode = rv.get_value_or (0);
977 to_skip.push_back (*i); // don't add this one;
980 replace_processor (instrument, *i, err);
981 to_skip.push_back (*i);
986 if ((mode & 5) == 4) {
993 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
994 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
995 ProcessorState pstate (this);
997 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1002 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1003 if (check != to_skip.end()) {
1007 boost::shared_ptr<PluginInsert> pi;
1009 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1010 pi->set_strict_io (_strict_io);
1014 /* Ensure that only one amp is in the list at any time */
1015 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1016 if (check != _processors.end()) {
1017 if (before == _amp) {
1018 /* Already in position; all is well */
1021 _processors.erase (check);
1026 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1028 _processors.insert (loc, *i);
1029 (*i)->set_owner (this);
1032 if (configure_processors_unlocked (err, &lm)) {
1034 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1039 if (pi && pi->has_sidechain ()) {
1040 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1043 if ((*i)->active()) {
1044 // emit ActiveChanged() and latency_changed() if needed
1048 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1050 boost::shared_ptr<Send> send;
1051 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1052 send->SelfDestruct.connect_same_thread (*this,
1053 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1057 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1058 boost::shared_ptr<PluginInsert> pi;
1060 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1061 if (pi->has_no_inputs ()) {
1062 _have_internal_generator = true;
1068 _output->set_user_latency (0);
1071 reset_instrument_info ();
1072 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1073 set_processor_positions ();
1075 if (fanout && fanout->configured ()
1076 && fanout->output_streams().n_audio() > 2
1077 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1078 fan_out (); /* EMIT SIGNAL */
1084 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1086 if (p == PreFader) {
1087 start = _processors.begin();
1088 end = find(_processors.begin(), _processors.end(), _amp);
1090 start = find(_processors.begin(), _processors.end(), _amp);
1092 end = _processors.end();
1096 /** Turn off all processors with a given placement
1097 * @param p Placement of processors to disable
1100 Route::disable_processors (Placement p)
1102 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1104 ProcessorList::iterator start, end;
1105 placement_range(p, start, end);
1107 for (ProcessorList::iterator i = start; i != end; ++i) {
1108 (*i)->enable (false);
1111 _session.set_dirty ();
1114 /** Turn off all redirects
1117 Route::disable_processors ()
1119 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1121 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1122 (*i)->enable (false);
1125 _session.set_dirty ();
1128 /** Turn off all redirects with a given placement
1129 * @param p Placement of redirects to disable
1132 Route::disable_plugins (Placement p)
1134 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1136 ProcessorList::iterator start, end;
1137 placement_range(p, start, end);
1139 for (ProcessorList::iterator i = start; i != end; ++i) {
1140 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1141 (*i)->enable (false);
1145 _session.set_dirty ();
1148 /** Turn off all plugins
1151 Route::disable_plugins ()
1153 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1155 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1156 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1157 (*i)->enable (false);
1161 _session.set_dirty ();
1166 Route::ab_plugins (bool forward)
1168 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1172 /* forward = turn off all active redirects, and mark them so that the next time
1173 we go the other way, we will revert them
1176 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1177 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1180 if (!(*i)->display_to_user ()) {
1184 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1189 if ((*i)->enabled ()) {
1190 (*i)->enable (false);
1191 (*i)->set_next_ab_is_active (true);
1193 (*i)->set_next_ab_is_active (false);
1199 /* backward = if the redirect was marked to go active on the next ab, do so */
1201 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1202 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1205 if (!(*i)->display_to_user ()) {
1209 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1214 (*i)->enable ((*i)->get_next_ab_is_active ());
1218 _session.set_dirty ();
1222 /** Remove processors with a given placement.
1223 * @param p Placement of processors to remove.
1226 Route::clear_processors (Placement p)
1228 if (!_session.engine().connected()) {
1232 bool already_deleting = _session.deletion_in_progress();
1233 if (!already_deleting) {
1234 _session.set_deletion_in_progress();
1237 ProcessorList old_list = _processors;
1239 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1240 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1241 ProcessorList new_list;
1242 ProcessorStreams err;
1243 bool seen_amp = false;
1245 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1251 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1253 /* you can't remove these */
1255 new_list.push_back (*i);
1262 new_list.push_back (*i);
1265 (*i)->drop_references ();
1273 (*i)->drop_references ();
1276 new_list.push_back (*i);
1283 _processors = new_list;
1284 configure_processors_unlocked (&err, &lm); // this can't fail
1286 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1289 processor_max_streams.reset();
1290 _have_internal_generator = false;
1291 reset_instrument_info ();
1292 set_processor_positions ();
1294 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1296 if (!already_deleting) {
1297 _session.clear_deletion_in_progress();
1302 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1304 // TODO once the export point can be configured properly, do something smarter here
1305 if (processor == _capturing_processor) {
1306 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1307 if (need_process_lock) {
1311 _capturing_processor.reset();
1313 if (need_process_lock) {
1318 /* these can never be removed */
1320 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1324 if (!_session.engine().connected()) {
1328 processor_max_streams.reset();
1331 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1332 if (need_process_lock) {
1336 /* Caller must hold process lock */
1337 assert (!AudioEngine::instance()->process_lock().trylock());
1339 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1341 ProcessorState pstate (this);
1343 ProcessorList::iterator i;
1344 bool removed = false;
1346 for (i = _processors.begin(); i != _processors.end(); ) {
1347 if (*i == processor) {
1349 /* move along, see failure case for configure_processors()
1350 where we may need to reconfigure the processor.
1353 /* stop redirects that send signals to JACK ports
1354 from causing noise as a result of no longer being
1358 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1359 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1363 iop = pi->sidechain();
1370 i = _processors.erase (i);
1378 _output->set_user_latency (0);
1386 if (configure_processors_unlocked (err, &lm)) {
1388 /* we know this will work, because it worked before :) */
1389 configure_processors_unlocked (0, &lm);
1393 _have_internal_generator = false;
1395 for (i = _processors.begin(); i != _processors.end(); ++i) {
1396 boost::shared_ptr<PluginInsert> pi;
1398 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1399 if (pi->has_no_inputs ()) {
1400 _have_internal_generator = true;
1405 if (need_process_lock) {
1410 reset_instrument_info ();
1411 processor->drop_references ();
1412 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1413 set_processor_positions ();
1419 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1421 /* these can never be removed */
1422 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1425 /* and can't be used as substitute, either */
1426 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1430 /* I/Os are out, too */
1431 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1435 /* this function cannot be used to swap/reorder processors */
1436 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1440 if (!AudioEngine::instance()->connected() || !old || !sub) {
1444 /* ensure that sub is not owned by another route */
1445 if (sub->owner ()) {
1450 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1451 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1452 ProcessorState pstate (this);
1454 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1456 ProcessorList::iterator i;
1457 bool replaced = false;
1458 bool enable = old->enabled ();
1460 for (i = _processors.begin(); i != _processors.end(); ) {
1462 i = _processors.erase (i);
1463 _processors.insert (i, sub);
1464 sub->set_owner (this);
1477 boost::shared_ptr<PluginInsert> pi;
1478 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1479 pi->set_strict_io (true);
1483 if (configure_processors_unlocked (err, &lm)) {
1485 configure_processors_unlocked (0, &lm);
1489 _have_internal_generator = false;
1491 for (i = _processors.begin(); i != _processors.end(); ++i) {
1492 boost::shared_ptr<PluginInsert> pi;
1493 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1494 if (pi->has_no_inputs ()) {
1495 _have_internal_generator = true;
1505 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1506 _output->set_user_latency (0);
1509 reset_instrument_info ();
1510 old->drop_references ();
1511 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1512 set_processor_positions ();
1517 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1519 ProcessorList deleted;
1521 if (!_session.engine().connected()) {
1525 processor_max_streams.reset();
1528 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1529 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1530 ProcessorState pstate (this);
1532 ProcessorList::iterator i;
1533 boost::shared_ptr<Processor> processor;
1535 for (i = _processors.begin(); i != _processors.end(); ) {
1539 /* these can never be removed */
1541 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1546 /* see if its in the list of processors to delete */
1548 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1553 /* stop IOProcessors that send to JACK ports
1554 from causing noise as a result of no longer being
1558 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1559 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1562 iop = pi->sidechain();
1569 deleted.push_back (processor);
1570 i = _processors.erase (i);
1573 if (deleted.empty()) {
1574 /* none of those in the requested list were found */
1578 _output->set_user_latency (0);
1580 if (configure_processors_unlocked (err, &lm)) {
1582 /* we know this will work, because it worked before :) */
1583 configure_processors_unlocked (0, &lm);
1588 _have_internal_generator = false;
1590 for (i = _processors.begin(); i != _processors.end(); ++i) {
1591 boost::shared_ptr<PluginInsert> pi;
1593 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1594 if (pi->has_no_inputs ()) {
1595 _have_internal_generator = true;
1602 /* now try to do what we need to so that those that were removed will be deleted */
1604 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1605 (*i)->drop_references ();
1608 reset_instrument_info ();
1609 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1610 set_processor_positions ();
1616 Route::reset_instrument_info ()
1618 boost::shared_ptr<Processor> instr = the_instrument();
1620 _instrument_info.set_internal_instrument (instr);
1624 /** Caller must hold process lock */
1626 Route::configure_processors (ProcessorStreams* err)
1628 #ifndef PLATFORM_WINDOWS
1629 assert (!AudioEngine::instance()->process_lock().trylock());
1632 if (!_in_configure_processors) {
1633 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1634 return configure_processors_unlocked (err, &lm);
1641 Route::input_streams () const
1643 return _input->n_ports ();
1646 list<pair<ChanCount, ChanCount> >
1647 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1649 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1651 return try_configure_processors_unlocked (in, err);
1654 list<pair<ChanCount, ChanCount> >
1655 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1657 // Check each processor in order to see if we can configure as requested
1659 list<pair<ChanCount, ChanCount> > configuration;
1662 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1663 DEBUG_TRACE (DEBUG::Processors, "{\n");
1665 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1667 if ((*p)->can_support_io_configuration(in, out)) {
1669 if (boost::dynamic_pointer_cast<Delivery> (*p)
1670 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1672 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1673 /* with strict I/O the panner + output are forced to
1674 * follow the last processor's output.
1676 * Delivery::can_support_io_configuration() will only add ports,
1677 * but not remove excess ports.
1679 * This works because the delivery only requires
1680 * as many outputs as there are inputs.
1681 * Delivery::configure_io() will do the actual removal
1682 * by calling _output->ensure_io()
1684 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1685 /* ..but at least as many as there are master-inputs, if
1686 * the delivery is dealing with audio */
1687 // XXX this may need special-casing for mixbus (master-outputs)
1688 // and should maybe be a preference anyway ?!
1689 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1695 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1696 configuration.push_back(make_pair(in, out));
1699 // restriction for Monitor Section Processors
1700 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1701 /* Note: The Monitor follows the master-bus and has no panner.
1703 * The general idea is to only allow plugins that retain the channel-count
1704 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1705 * Then again 5.1 in, monitor stereo is a valid use-case.
1707 * and worse: we only refuse adding plugins *here*.
1709 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1710 * 2) change master-bus, add a channel
1711 * 2a) monitor-secion follows
1712 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1713 * 4) re-load session, monitor-processor remains unconfigured, crash.
1715 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1717 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1718 // internal sends make no sense, only feedback
1719 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1720 return list<pair<ChanCount, ChanCount> > ();
1722 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1723 /* External Sends can be problematic. one can add/remove ports
1724 * there signal leaves the DAW to external monitors anyway, so there's
1725 * no real use for allowing them here anyway.
1727 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1728 return list<pair<ChanCount, ChanCount> > ();
1730 if (boost::dynamic_pointer_cast<Send> (*p)) {
1732 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1733 return list<pair<ChanCount, ChanCount> > ();
1742 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1743 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1744 DEBUG_TRACE (DEBUG::Processors, "}\n");
1745 return list<pair<ChanCount, ChanCount> > ();
1749 DEBUG_TRACE (DEBUG::Processors, "}\n");
1751 return configuration;
1754 /** Set the input/output configuration of each processor in the processors list.
1755 * Caller must hold process lock.
1756 * Return 0 on success, otherwise configuration is impossible.
1759 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1761 #ifndef PLATFORM_WINDOWS
1762 assert (!AudioEngine::instance()->process_lock().trylock());
1765 if (_in_configure_processors) {
1769 /* put invisible processors where they should be */
1770 setup_invisible_processors ();
1772 _in_configure_processors = true;
1774 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1776 if (configuration.empty ()) {
1777 _in_configure_processors = false;
1782 bool seen_mains_out = false;
1783 processor_out_streams = _input->n_ports();
1784 processor_max_streams.reset();
1786 /* processor configure_io() may result in adding ports
1787 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1789 * with jack2 adding ports results in a graph-order callback,
1790 * which calls Session::resort_routes() and eventually
1791 * Route::direct_feeds_according_to_reality()
1792 * which takes a ReaderLock (_processor_lock).
1794 * so we can't hold a WriterLock here until jack2 threading
1797 * NB. we still hold the process lock
1799 * (ardour's own engines do call graph-order from the
1800 * process-thread and hence do not have this issue; besides
1801 * merely adding ports won't trigger a graph-order, only
1802 * making connections does)
1806 // TODO check for a potential ReaderLock after ReaderLock ??
1807 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1809 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1810 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1812 if (!(*p)->configure_io(c->first, c->second)) {
1813 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1814 _in_configure_processors = false;
1819 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1820 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1822 boost::shared_ptr<IOProcessor> iop;
1823 boost::shared_ptr<PluginInsert> pi;
1824 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1825 /* plugins connected via Split or Hide Match may have more channels.
1826 * route/scratch buffers are needed for all of them
1827 * The configuration may only be a subset (both input and output)
1829 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1831 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1832 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1833 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1837 if (boost::dynamic_pointer_cast<Delivery> (*p)
1838 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1839 /* main delivery will increase port count to match input.
1840 * the Delivery::Main is usually the last processor - followed only by
1843 seen_mains_out = true;
1845 if (!seen_mains_out) {
1846 processor_out_streams = out;
1855 _meter->set_max_channels (processor_max_streams);
1858 /* make sure we have sufficient scratch buffers to cope with the new processor
1861 _session.ensure_buffers (n_process_buffers ());
1863 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1865 _in_configure_processors = false;
1869 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1870 * @param state New active state for those processors.
1873 Route::all_visible_processors_active (bool state)
1875 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1877 if (_processors.empty()) {
1881 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1882 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1886 boost::shared_ptr<PluginInsert> pi;
1887 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1888 if (pi->is_channelstrip ()) {
1893 (*i)->enable (state);
1896 _session.set_dirty ();
1900 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1902 /* check if re-order requires re-configuration of any processors
1903 * -> compare channel configuration for all processors
1905 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1906 ChanCount c = input_streams ();
1908 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1910 if (c != (*j)->input_streams()) {
1913 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1916 if ((*i)->input_streams() != c) {
1919 c = (*i)->output_streams();
1931 __attribute__((annotate("realtime")))
1934 Route::apply_processor_order (const ProcessorList& new_order)
1936 /* need to hold processor_lock; either read or write lock
1937 * and the engine process_lock.
1938 * Due to r/w lock ambiguity we can only assert the latter
1940 assert (!AudioEngine::instance()->process_lock().trylock());
1943 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1944 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1945 * processors in the current actual processor list that are hidden. Any visible processors
1946 * in the current list but not in "new_order" will be assumed to be deleted.
1949 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1950 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1951 * (note though that ::processors_reorder_needs_configure() ensured that
1952 * this function will only ever be called from the rt-thread if no processor were removed)
1954 * either way, I can't proove it, but an x-run due to re-order here is less likley
1955 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1958 ProcessorList as_it_will_be;
1959 ProcessorList::iterator oiter;
1960 ProcessorList::const_iterator niter;
1962 oiter = _processors.begin();
1963 niter = new_order.begin();
1965 while (niter != new_order.end()) {
1967 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1968 then append it to the temp list.
1970 Otherwise, see if the next processor in the old list is in the new list. if not,
1971 its been deleted. If its there, append it to the temp list.
1974 if (oiter == _processors.end()) {
1976 /* no more elements in the old list, so just stick the rest of
1977 the new order onto the temp list.
1980 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1981 while (niter != new_order.end()) {
1988 if (!(*oiter)->display_to_user()) {
1990 as_it_will_be.push_back (*oiter);
1994 /* visible processor: check that its in the new order */
1996 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1997 /* deleted: do nothing, shared_ptr<> will clean up */
1999 /* ignore this one, and add the next item from the new order instead */
2000 as_it_will_be.push_back (*niter);
2005 /* now remove from old order - its taken care of no matter what */
2006 oiter = _processors.erase (oiter);
2010 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2012 /* If the meter is in a custom position, find it and make a rough note of its position */
2013 maybe_note_meter_position ();
2017 Route::move_instrument_down (bool postfader)
2019 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2020 ProcessorList new_order;
2021 boost::shared_ptr<Processor> instrument;
2022 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2023 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2024 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2026 } else if (instrument && *i == _amp) {
2028 new_order.push_back (*i);
2029 new_order.push_back (instrument);
2031 new_order.push_back (instrument);
2032 new_order.push_back (*i);
2035 new_order.push_back (*i);
2042 reorder_processors (new_order, 0);
2046 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2048 // it a change is already queued, wait for it
2049 // (unless engine is stopped. apply immediately and proceed
2050 while (g_atomic_int_get (&_pending_process_reorder)) {
2051 if (!AudioEngine::instance()->running()) {
2052 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2053 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2055 apply_processor_order(_pending_processor_order);
2056 setup_invisible_processors ();
2058 g_atomic_int_set (&_pending_process_reorder, 0);
2060 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2061 set_processor_positions ();
2063 // TODO rather use a semaphore or something.
2064 // but since ::reorder_processors() is called
2065 // from the GUI thread, this is fine..
2070 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2072 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2073 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2074 ProcessorState pstate (this);
2076 apply_processor_order (new_order);
2078 if (configure_processors_unlocked (err, &lm)) {
2086 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2087 set_processor_positions ();
2090 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2091 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2093 // _pending_processor_order is protected by _processor_lock
2094 _pending_processor_order = new_order;
2095 g_atomic_int_set (&_pending_process_reorder, 1);
2102 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2104 boost::shared_ptr<PluginInsert> pi;
2105 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2109 if (pi->has_sidechain () == add) {
2110 return true; // ?? call failed, but result is as expected.
2114 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2115 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2116 if (i == _processors.end ()) {
2122 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2123 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2124 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2126 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2128 if (!pi->add_sidechain ()) {
2132 if (!pi->del_sidechain ()) {
2138 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2143 pi->del_sidechain ();
2145 pi->add_sidechain ();
2146 // TODO restore side-chain's state.
2151 configure_processors_unlocked (0, &lm);
2154 if (pi->has_sidechain ()) {
2155 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2158 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2159 _session.set_dirty ();
2164 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2166 boost::shared_ptr<PluginInsert> pi;
2167 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2172 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2173 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2174 if (i == _processors.end ()) {
2180 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2181 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2183 const ChanCount& old (pi->preset_out ());
2184 if (!pi->set_preset_out (outs)) {
2185 return true; // no change, OK
2188 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2191 pi->set_preset_out (old);
2194 configure_processors_unlocked (0, &lm);
2197 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2198 _session.set_dirty ();
2203 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2206 return customize_plugin_insert (proc, 0, unused, unused);
2210 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2212 boost::shared_ptr<PluginInsert> pi;
2213 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2218 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2219 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2220 if (i == _processors.end ()) {
2226 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2227 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2229 bool old_cust = pi->custom_cfg ();
2230 uint32_t old_cnt = pi->get_count ();
2231 ChanCount old_chan = pi->output_streams ();
2232 ChanCount old_sinks = pi->natural_input_streams ();
2235 pi->set_custom_cfg (false);
2237 pi->set_custom_cfg (true);
2238 pi->set_count (count);
2239 pi->set_outputs (outs);
2240 pi->set_sinks (sinks);
2243 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2247 pi->set_count (old_cnt);
2248 pi->set_sinks (old_sinks);
2249 pi->set_outputs (old_chan);
2250 pi->set_custom_cfg (old_cust);
2254 configure_processors_unlocked (0, &lm);
2257 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2258 _session.set_dirty ();
2263 Route::set_strict_io (const bool enable)
2265 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2267 if (_strict_io != enable) {
2268 _strict_io = enable;
2269 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2270 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2271 boost::shared_ptr<PluginInsert> pi;
2272 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2273 pi->set_strict_io (_strict_io);
2277 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2281 _strict_io = !enable; // restore old value
2282 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2283 boost::shared_ptr<PluginInsert> pi;
2284 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2285 pi->set_strict_io (_strict_io);
2292 configure_processors (0);
2295 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2296 _session.set_dirty ();
2308 Route::get_template()
2310 return state(false);
2314 Route::state(bool full_state)
2316 if (!_session._template_state_dir.empty()) {
2317 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2320 XMLNode *node = new XMLNode("Route");
2321 ProcessorList::iterator i;
2323 node->set_property ("id", id ());
2324 node->set_property ("name", name());
2325 node->set_property ("default-type", _default_type);
2326 node->set_property ("strict-io", _strict_io);
2328 node->add_child_nocopy (_presentation_info.get_state());
2330 node->set_property ("active", _active);
2331 node->set_property ("denormal-protection", _denormal_protection);
2332 node->set_property ("meter-point", _meter_point);
2334 node->set_property ("meter-type", _meter_type);
2337 node->set_property ("route-group", _route_group->name());
2340 node->add_child_nocopy (_solo_control->get_state ());
2341 node->add_child_nocopy (_solo_isolate_control->get_state ());
2342 node->add_child_nocopy (_solo_safe_control->get_state ());
2344 node->add_child_nocopy (_input->state (full_state));
2345 node->add_child_nocopy (_output->state (full_state));
2346 node->add_child_nocopy (_mute_master->get_state ());
2348 node->add_child_nocopy (_mute_control->get_state ());
2349 node->add_child_nocopy (_phase_control->get_state ());
2352 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2355 if (_comment.length()) {
2356 XMLNode *cmt = node->add_child ("Comment");
2357 cmt->add_content (_comment);
2361 node->add_child_nocopy (_pannable->state (full_state));
2365 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2366 for (i = _processors.begin(); i != _processors.end(); ++i) {
2368 /* template save: do not include internal sends functioning as
2369 aux sends because the chance of the target ID
2370 in the session where this template is used
2373 similarly, do not save listen sends which connect to
2374 the monitor section, because these will always be
2377 boost::shared_ptr<InternalSend> is;
2379 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2380 if (is->role() == Delivery::Listen) {
2385 node->add_child_nocopy((*i)->state (full_state));
2390 node->add_child_copy (*_extra_xml);
2393 if (_custom_meter_position_noted) {
2394 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2396 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2400 if (!_session._template_state_dir.empty()) {
2401 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2404 node->add_child_copy (Slavable::get_state());
2410 Route::set_state (const XMLNode& node, int version)
2412 if (version < 3000) {
2413 return set_state_2X (node, version);
2417 XMLNodeConstIterator niter;
2420 if (node.name() != "Route"){
2421 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2425 std::string route_name;
2426 if (node.get_property (X_("name"), route_name)) {
2427 Route::set_name (route_name);
2431 _initial_io_setup = true;
2433 Stripable::set_state (node, version);
2435 node.get_property (X_("strict-io"), _strict_io);
2438 /* monitor bus does not get a panner, but if (re)created
2439 via XML, it will already have one by the time we
2440 call ::set_state(). so ... remove it.
2445 /* add all processors (except amp, which is always present) */
2447 nlist = node.children();
2448 XMLNode processor_state (X_("processor_state"));
2450 Stateful::save_extra_xml (node);
2452 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2456 if (child->name() == IO::state_node_name) {
2457 std::string direction;
2458 if (!child->get_property (X_("direction"), direction)) {
2462 if (direction == "Input") {
2463 _input->set_state (*child, version);
2464 } else if (direction == "Output") {
2465 _output->set_state (*child, version);
2468 } else if (child->name() == X_("Processor")) {
2469 processor_state.add_child_copy (*child);
2470 } else if (child->name() == X_("Pannable")) {
2472 _pannable->set_state (*child, version);
2474 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2476 } else if (child->name() == Slavable::xml_node_name) {
2477 Slavable::set_state (*child, version);
2482 if (node.get_property (X_("meter-point"), mp)) {
2483 set_meter_point (mp, true);
2485 _meter->set_display_to_user (_meter_point == MeterCustom);
2489 node.get_property (X_("meter-type"), _meter_type);
2491 _initial_io_setup = false;
2493 set_processor_state (processor_state);
2495 // this looks up the internal instrument in processors
2496 reset_instrument_info();
2498 bool denormal_protection;
2499 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2500 set_denormal_protection (denormal_protection);
2503 /* convert old 3001 state */
2504 std::string phase_invert_str;
2505 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2506 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2510 if (node.get_property (X_("active"), is_active)) {
2511 set_active (is_active, this);
2514 std::string id_string;
2515 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2516 PBD::ID id (id_string);
2517 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2518 ProcessorList::const_iterator i = _processors.begin ();
2519 while (i != _processors.end() && (*i)->id() != id) {
2523 if (i != _processors.end ()) {
2524 _processor_after_last_custom_meter = *i;
2525 _custom_meter_position_noted = true;
2529 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2532 if (child->name() == X_("Comment")) {
2534 /* XXX this is a terrible API design in libxml++ */
2536 XMLNode *cmt = *(child->children().begin());
2537 _comment = cmt->content();
2539 } else if (child->name() == Controllable::xml_node_name) {
2540 std::string control_name;
2541 if (!child->get_property (X_("name"), control_name)) {
2545 if (control_name == _solo_control->name()) {
2546 _solo_control->set_state (*child, version);
2547 } else if (control_name == _solo_safe_control->name()) {
2548 _solo_safe_control->set_state (*child, version);
2549 } else if (control_name == _solo_isolate_control->name()) {
2550 _solo_isolate_control->set_state (*child, version);
2551 } else if (control_name == _mute_control->name()) {
2552 _mute_control->set_state (*child, version);
2553 } else if (control_name == _phase_control->name()) {
2554 _phase_control->set_state (*child, version);
2556 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2557 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2558 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2560 ac->set_state (*child, version);
2564 } else if (child->name() == MuteMaster::xml_node_name) {
2565 _mute_master->set_state (*child, version);
2567 } else if (child->name() == Automatable::xml_node_name) {
2568 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2576 Route::set_state_2X (const XMLNode& node, int version)
2580 XMLNodeConstIterator niter;
2582 XMLProperty const * prop;
2584 /* 2X things which still remain to be handled:
2590 if (node.name() != "Route") {
2591 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2595 Stripable::set_state (node, version);
2597 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2598 set_denormal_protection (string_to<bool> (prop->value()));
2601 if ((prop = node.property (X_("muted"))) != 0) {
2604 bool muted = string_to<bool> (prop->value());
2610 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2612 if (string_to<bool> (prop->value())){
2613 mute_point = mute_point + "PreFader";
2618 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2620 if (string_to<bool> (prop->value())){
2623 mute_point = mute_point + ",";
2626 mute_point = mute_point + "PostFader";
2631 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2633 if (string_to<bool> (prop->value())){
2636 mute_point = mute_point + ",";
2639 mute_point = mute_point + "Listen";
2644 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2646 if (string_to<bool> (prop->value())){
2649 mute_point = mute_point + ",";
2652 mute_point = mute_point + "Main";
2656 _mute_master->set_mute_points (mute_point);
2657 _mute_master->set_muted_by_self (true);
2661 if ((prop = node.property (X_("meter-point"))) != 0) {
2662 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2667 nlist = node.children ();
2668 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2672 if (child->name() == IO::state_node_name) {
2674 /* there is a note in IO::set_state_2X() about why we have to call
2678 _input->set_state_2X (*child, version, true);
2679 _output->set_state_2X (*child, version, false);
2681 if ((prop = child->property (X_("name"))) != 0) {
2682 Route::set_name (prop->value ());
2687 if ((prop = child->property (X_("active"))) != 0) {
2688 bool yn = string_to<bool> (prop->value());
2689 _active = !yn; // force switch
2690 set_active (yn, this);
2693 if ((prop = child->property (X_("gain"))) != 0) {
2696 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2697 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2701 /* Set up Panners in the IO */
2702 XMLNodeList io_nlist = child->children ();
2704 XMLNodeConstIterator io_niter;
2707 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2709 io_child = *io_niter;
2711 if (io_child->name() == X_("Panner")) {
2712 _main_outs->panner_shell()->set_state(*io_child, version);
2713 } else if (io_child->name() == X_("Automation")) {
2714 /* IO's automation is for the fader */
2715 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2721 XMLNodeList redirect_nodes;
2723 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2727 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2728 redirect_nodes.push_back(child);
2733 set_processor_state_2X (redirect_nodes, version);
2735 Stateful::save_extra_xml (node);
2737 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2740 if (child->name() == X_("Comment")) {
2742 /* XXX this is a terrible API design in libxml++ */
2744 XMLNode *cmt = *(child->children().begin());
2745 _comment = cmt->content();
2747 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2748 if (prop->value() == X_("solo")) {
2749 _solo_control->set_state (*child, version);
2750 } else if (prop->value() == X_("mute")) {
2751 _mute_control->set_state (*child, version);
2761 Route::get_processor_state ()
2763 XMLNode* root = new XMLNode (X_("redirects"));
2764 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2765 root->add_child_nocopy ((*i)->state (true));
2772 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2774 /* We don't bother removing existing processors not in nList, as this
2775 method will only be called when creating a Route from scratch, not
2776 for undo purposes. Just put processors in at the appropriate place
2780 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2781 add_processor_from_xml_2X (**i, version);
2786 Route::set_processor_state (const XMLNode& node)
2788 const XMLNodeList &nlist = node.children();
2789 XMLNodeConstIterator niter;
2790 ProcessorList new_order;
2791 bool must_configure = false;
2793 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2795 XMLProperty* prop = (*niter)->property ("type");
2797 if (prop->value() == "amp") {
2798 _amp->set_state (**niter, Stateful::current_state_version);
2799 new_order.push_back (_amp);
2800 } else if (prop->value() == "trim") {
2801 _trim->set_state (**niter, Stateful::current_state_version);
2802 new_order.push_back (_trim);
2803 } else if (prop->value() == "meter") {
2804 _meter->set_state (**niter, Stateful::current_state_version);
2805 new_order.push_back (_meter);
2806 } else if (prop->value() == "delay") {
2808 _delayline->set_state (**niter, Stateful::current_state_version);
2809 new_order.push_back (_delayline);
2811 } else if (prop->value() == "main-outs") {
2812 _main_outs->set_state (**niter, Stateful::current_state_version);
2813 } else if (prop->value() == "intreturn") {
2815 _intreturn.reset (new InternalReturn (_session));
2816 must_configure = true;
2818 _intreturn->set_state (**niter, Stateful::current_state_version);
2819 } else if (is_monitor() && prop->value() == "monitor") {
2820 if (!_monitor_control) {
2821 _monitor_control.reset (new MonitorProcessor (_session));
2822 must_configure = true;
2824 _monitor_control->set_state (**niter, Stateful::current_state_version);
2825 } else if (prop->value() == "capture") {
2826 /* CapturingProcessor should never be restored, it's always
2827 added explicitly when needed */
2829 set_processor_state (**niter, prop, new_order, must_configure);
2833 ProcessorList old_list = _processors; // keep a copy
2835 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2836 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2837 /* re-assign _processors w/o process-lock.
2838 * if there's an IO-processor present in _processors but
2839 * not in new_order, it will be deleted and ~IO takes
2842 _processors = new_order;
2844 if (must_configure) {
2845 configure_processors_unlocked (0, &lm);
2848 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2850 (*i)->set_owner (this);
2851 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2853 boost::shared_ptr<PluginInsert> pi;
2855 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2856 if (pi->has_no_inputs ()) {
2857 _have_internal_generator = true;
2863 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2866 reset_instrument_info ();
2867 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2868 set_processor_positions ();
2872 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2874 ProcessorList::iterator o;
2876 for (o = _processors.begin(); o != _processors.end(); ++o) {
2877 XMLProperty const * id_prop = node.property(X_("id"));
2878 if (id_prop && (*o)->id() == id_prop->value()) {
2879 (*o)->set_state (node, Stateful::current_state_version);
2880 new_order.push_back (*o);
2885 // If the processor (node) is not on the route then create it
2887 if (o == _processors.end()) {
2889 boost::shared_ptr<Processor> processor;
2891 if (prop->value() == "intsend") {
2893 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2895 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2896 prop->value() == "lv2" ||
2897 prop->value() == "windows-vst" ||
2898 prop->value() == "mac-vst" ||
2899 prop->value() == "lxvst" ||
2900 prop->value() == "luaproc" ||
2901 prop->value() == "audiounit") {
2903 if (_session.get_disable_all_loaded_plugins ()) {
2904 processor.reset (new UnknownProcessor (_session, node));
2906 processor.reset (new PluginInsert (_session));
2907 processor->set_owner (this);
2909 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2910 pi->set_strict_io (true);
2914 } else if (prop->value() == "port") {
2916 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2918 } else if (prop->value() == "send") {
2920 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2921 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2922 send->SelfDestruct.connect_same_thread (*this,
2923 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2929 if (processor->set_state (node, Stateful::current_state_version) != 0) {
2930 /* This processor could not be configured. Turn it into a UnknownProcessor */
2931 processor.reset (new UnknownProcessor (_session, node));
2934 /* subscribe to Sidechain IO changes */
2935 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2936 if (pi && pi->has_sidechain ()) {
2937 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2940 /* we have to note the monitor send here, otherwise a new one will be created
2941 and the state of this one will be lost.
2943 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2944 if (isend && isend->role() == Delivery::Listen) {
2945 _monitor_send = isend;
2948 /* it doesn't matter if invisible processors are added here, as they
2949 will be sorted out by setup_invisible_processors () shortly.
2952 new_order.push_back (processor);
2953 must_configure = true;
2959 Route::curve_reallocate ()
2961 // _gain_automation_curve.finish_resize ();
2962 // _pan_automation_curve.finish_resize ();
2966 Route::silence (framecnt_t nframes)
2968 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2973 silence_unlocked (nframes);
2977 Route::silence_unlocked (framecnt_t nframes)
2979 /* Must be called with the processor lock held */
2981 const framepos_t now = _session.transport_frame ();
2985 _output->silence (nframes);
2987 // update owned automated controllables
2988 automation_run (now, nframes);
2990 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2991 boost::shared_ptr<PluginInsert> pi;
2993 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2994 /* evaluate automated automation controls */
2995 pi->automation_run (now, nframes);
2996 /* skip plugins, they don't need anything when we're not active */
3000 (*i)->silence (nframes, now);
3003 if (nframes == _session.get_block_size()) {
3010 Route::add_internal_return ()
3013 _intreturn.reset (new InternalReturn (_session));
3014 add_processor (_intreturn, PreFader);
3019 Route::add_send_to_internal_return (InternalSend* send)
3021 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3023 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3024 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3027 return d->add_send (send);
3033 Route::remove_send_from_internal_return (InternalSend* send)
3035 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3037 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3038 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3041 return d->remove_send (send);
3047 Route::enable_monitor_send ()
3049 /* Caller must hold process lock */
3050 assert (!AudioEngine::instance()->process_lock().trylock());
3052 /* master never sends to monitor section via the normal mechanism */
3053 assert (!is_master ());
3054 assert (!is_monitor ());
3056 /* make sure we have one */
3057 if (!_monitor_send) {
3058 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3059 _monitor_send->set_display_to_user (false);
3063 configure_processors (0);
3066 /** Add an aux send to a route.
3067 * @param route route to send to.
3068 * @param before Processor to insert before, or 0 to insert at the end.
3071 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3073 assert (route != _session.monitor_out ());
3076 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3078 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3080 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3082 if (d && d->target_route() == route) {
3083 /* already listening via the specified IO: do nothing */
3091 boost::shared_ptr<InternalSend> listener;
3094 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3095 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3098 add_processor (listener, before);
3100 } catch (failed_constructor& err) {
3108 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3110 ProcessorStreams err;
3111 ProcessorList::iterator tmp;
3114 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3116 /* have to do this early because otherwise processor reconfig
3117 * will put _monitor_send back in the list
3120 if (route == _session.monitor_out()) {
3121 _monitor_send.reset ();
3125 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3127 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3129 if (d && d->target_route() == route) {
3131 if (remove_processor (*x, &err, false) > 0) {
3137 /* list could have been demolished while we dropped the lock
3140 if (_session.engine().connected()) {
3141 /* i/o processors cannot be removed if the engine is not running
3142 * so don't live-loop in case the engine is N/A or dies
3152 Route::set_comment (string cmt, void *src)
3156 _session.set_dirty ();
3160 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3162 FeedRecord fr (other, via_sends_only);
3164 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3166 if (!result.second) {
3168 /* already a record for "other" - make sure sends-only information is correct */
3169 if (!via_sends_only && result.first->sends_only) {
3170 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3171 frp->sends_only = false;
3175 return result.second;
3179 Route::clear_fed_by ()
3185 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3187 const FedBy& fed_by (other->fed_by());
3189 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3190 boost::shared_ptr<Route> sr = f->r.lock();
3192 if (sr && (sr.get() == this)) {
3194 if (via_sends_only) {
3195 *via_sends_only = f->sends_only;
3206 Route::all_inputs () const
3208 /* TODO, if this works as expected,
3209 * cache the IOVector and maintain it via
3210 * input_change_handler(), sidechain_change_handler() etc
3213 ios.push_back (_input);
3215 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3216 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3218 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3219 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3222 iop = pi->sidechain();
3225 if (iop != 0 && iop->input()) {
3226 ios.push_back (iop->input());
3233 Route::all_outputs () const
3236 // _output is included via Delivery
3237 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3238 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3239 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3240 if (iop != 0 && iop->output()) {
3241 ios.push_back (iop->output());
3248 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3250 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3251 if (other->all_inputs().fed_by (_output)) {
3252 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3253 if (via_send_only) {
3254 *via_send_only = false;
3260 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3262 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3264 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3265 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3268 iop = pi->sidechain();
3272 boost::shared_ptr<const IO> iop_out = iop->output();
3273 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3274 // TODO this needs a delaylines in the Insert to align connections (!)
3275 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3278 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3279 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3280 if (via_send_only) {
3281 *via_send_only = true;
3285 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3288 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3293 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3298 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3300 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3304 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3306 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3309 /** Called from the (non-realtime) butler thread when the transport is stopped */
3311 Route::non_realtime_transport_stop (framepos_t now, bool flush)
3314 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3316 Automatable::non_realtime_transport_stop (now, flush);
3318 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3320 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3324 (*i)->non_realtime_transport_stop (now, flush);
3328 _roll_delay = _initial_delay;
3332 Route::input_change_handler (IOChange change, void * /*src*/)
3334 if ((change.type & IOChange::ConfigurationChanged)) {
3335 /* This is called with the process lock held if change
3336 contains ConfigurationChanged
3338 configure_processors (0);
3339 _phase_control->resize (_input->n_ports().n_audio ());
3340 io_changed (); /* EMIT SIGNAL */
3343 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3346 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3347 if (_input->connected()) {
3348 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3349 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3353 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3354 if (does_feed && !sends_only) {
3355 if ((*i)->soloed()) {
3358 if ((*i)->solo_isolate_control()->solo_isolated()) {
3365 int delta = sbou - _solo_control->soloed_by_others_upstream();
3366 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3369 PBD::warning << string_compose (
3370 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3371 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3376 if (_solo_control->soloed_by_others_upstream()) {
3377 // ignore new connections (they're not propagated)
3379 _solo_control->mod_solo_by_others_upstream (delta);
3383 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3384 // solo-isolate currently only propagates downstream
3386 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3388 //_solo_isolated_by_upstream = ibou;
3391 // Session::route_solo_changed does not propagate indirect solo-changes
3392 // propagate downstream to tracks
3393 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3394 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3398 bool does_feed = feeds (*i, &sends_only);
3399 if (delta <= 0 && does_feed && !sends_only) {
3400 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3403 if (idelta < 0 && does_feed && !sends_only) {
3404 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3411 Route::output_change_handler (IOChange change, void * /*src*/)
3413 if (_initial_io_setup) {
3417 if ((change.type & IOChange::ConfigurationChanged)) {
3418 /* This is called with the process lock held if change
3419 contains ConfigurationChanged
3421 configure_processors (0);
3424 _session.reset_monitor_section();
3427 io_changed (); /* EMIT SIGNAL */
3430 if ((change.type & IOChange::ConnectionsChanged)) {
3432 /* do this ONLY if connections have changed. Configuration
3433 * changes do not, by themselves alter solo upstream or
3434 * downstream status.
3437 if (_solo_control->soloed_by_others_downstream()) {
3439 /* checking all all downstream routes for
3440 * explicit of implict solo is a rather drastic measure,
3441 * ideally the input_change_handler() of the other route
3442 * would propagate the change to us.
3444 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3445 if (_output->connected()) {
3446 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3447 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3451 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3452 if (does_feed && !sends_only) {
3453 if ((*i)->soloed()) {
3461 int delta = sbod - _solo_control->soloed_by_others_downstream();
3463 // do not allow new connections to change implicit solo (no propagation)
3464 _solo_control->mod_solo_by_others_downstream (delta);
3465 // Session::route_solo_changed() does not propagate indirect solo-changes
3466 // propagate upstream to tracks
3467 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3468 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3469 if ((*i).get() == this || !can_solo()) {
3473 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3474 if (delta != 0 && does_feed && !sends_only) {
3475 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3485 Route::sidechain_change_handler (IOChange change, void* src)
3487 if (_initial_io_setup || _in_sidechain_setup) {
3491 input_change_handler (change, src);
3495 Route::pans_required () const
3497 if (n_outputs().n_audio() < 2) {
3501 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3505 Route::flush_processor_buffers_locked (framecnt_t nframes)
3507 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3508 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3510 d->flush_buffers (nframes);
3512 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3514 p->flush_buffers (nframes);
3521 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3523 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3530 silence_unlocked (nframes);
3534 if (session_state_changing) {
3535 if (_session.transport_speed() != 0.0f) {
3536 /* we're rolling but some state is changing (e.g. our diskstream contents)
3537 so we cannot use them. Be silent till this is over.
3539 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3541 silence_unlocked (nframes);
3544 /* we're really not rolling, so we're either delivery silence or actually
3545 monitoring, both of which are safe to do while session_state_changing is true.
3549 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3551 fill_buffers_with_input (bufs, _input, nframes);
3553 if (_meter_point == MeterInput) {
3554 _meter->run (bufs, start_frame, end_frame, 0.0, nframes, true);
3557 _amp->apply_gain_automation (false);
3558 _trim->apply_gain_automation (false);
3559 passthru (bufs, start_frame, end_frame, nframes, 0);
3561 flush_processor_buffers_locked (nframes);
3567 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3569 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3575 silence_unlocked (nframes);
3579 framepos_t unused = 0;
3581 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3587 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3589 fill_buffers_with_input (bufs, _input, nframes);
3591 if (_meter_point == MeterInput) {
3592 _meter->run (bufs, start_frame, end_frame, 1.0, nframes, true);
3595 passthru (bufs, start_frame, end_frame, nframes, declick);
3597 flush_processor_buffers_locked (nframes);
3603 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3606 flush_processor_buffers_locked (nframes);
3611 Route::flush_processors ()
3613 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3615 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3621 __attribute__((annotate("realtime")))
3624 Route::apply_processor_changes_rt ()
3626 int emissions = EmitNone;
3628 if (_pending_meter_point != _meter_point) {
3629 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3631 /* meters always have buffers for 'processor_max_streams'
3632 * they can be re-positioned without re-allocation */
3633 if (set_meter_point_unlocked()) {
3634 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3636 emissions |= EmitMeterChanged;
3641 bool changed = false;
3643 if (g_atomic_int_get (&_pending_process_reorder)) {
3644 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3646 apply_processor_order (_pending_processor_order);
3647 setup_invisible_processors ();
3649 g_atomic_int_set (&_pending_process_reorder, 0);
3650 emissions |= EmitRtProcessorChange;
3654 set_processor_positions ();
3656 if (emissions != 0) {
3657 g_atomic_int_set (&_pending_signals, emissions);
3660 return (!selfdestruct_sequence.empty ());
3664 Route::emit_pending_signals ()
3666 int sig = g_atomic_int_and (&_pending_signals, 0);
3667 if (sig & EmitMeterChanged) {
3668 _meter->emit_configuration_changed();
3669 meter_change (); /* EMIT SIGNAL */
3670 if (sig & EmitMeterVisibilityChange) {
3671 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3673 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3676 if (sig & EmitRtProcessorChange) {
3677 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3680 /* this would be a job for the butler.
3681 * Conceptually we should not take processe/processor locks here.
3682 * OTOH its more efficient (less overhead for summoning the butler and
3683 * telling her what do do) and signal emission is called
3684 * directly after the process callback, which decreases the chance
3685 * of x-runs when taking the locks.
3687 while (!selfdestruct_sequence.empty ()) {
3688 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3689 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3690 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3691 selfdestruct_sequence.pop_back ();
3694 remove_processor (proc);
3700 Route::set_meter_point (MeterPoint p, bool force)
3702 if (_pending_meter_point == p && !force) {
3706 if (force || !AudioEngine::instance()->running()) {
3707 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3708 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3709 _pending_meter_point = p;
3710 _meter->emit_configuration_changed();
3711 meter_change (); /* EMIT SIGNAL */
3712 if (set_meter_point_unlocked()) {
3713 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3715 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3718 _pending_meter_point = p;
3724 __attribute__((annotate("realtime")))
3727 Route::set_meter_point_unlocked ()
3730 /* Caller must hold process and processor write lock */
3731 assert (!AudioEngine::instance()->process_lock().trylock());
3732 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3733 assert (!lm.locked ());
3736 _meter_point = _pending_meter_point;
3738 bool meter_was_visible_to_user = _meter->display_to_user ();
3740 if (!_custom_meter_position_noted) {
3741 maybe_note_meter_position ();
3744 if (_meter_point != MeterCustom) {
3746 _meter->set_display_to_user (false);
3748 setup_invisible_processors ();
3751 _meter->set_display_to_user (true);
3753 /* If we have a previous position for the custom meter, try to put it there */
3754 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3756 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3757 if (i != _processors.end ()) {
3758 _processors.remove (_meter);
3759 _processors.insert (i, _meter);
3761 } else {// at end, right before the mains_out/panner
3762 _processors.remove (_meter);
3763 ProcessorList::iterator main = _processors.end();
3764 _processors.insert (--main, _meter);
3768 /* Set up the meter for its new position */
3770 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3774 if (loc == _processors.begin()) {
3775 m_in = _input->n_ports();
3777 ProcessorList::iterator before = loc;
3779 m_in = (*before)->output_streams ();
3782 _meter->reflect_inputs (m_in);
3784 /* we do not need to reconfigure the processors, because the meter
3785 (a) is always ready to handle processor_max_streams
3786 (b) is always an N-in/N-out processor, and thus moving
3787 it doesn't require any changes to the other processors.
3790 /* these should really be done after releasing the lock
3791 * but all those signals are subscribed to with gui_thread()
3794 return (_meter->display_to_user() != meter_was_visible_to_user);
3798 Route::listen_position_changed ()
3801 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3802 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3803 ProcessorState pstate (this);
3805 if (configure_processors_unlocked (0, &lm)) {
3806 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3808 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3813 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3814 _session.set_dirty ();
3817 boost::shared_ptr<CapturingProcessor>
3818 Route::add_export_point()
3820 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3821 if (!_capturing_processor) {
3823 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3824 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3826 // this aligns all tracks; but not tracks + busses
3827 assert (_session.worst_track_latency () >= _initial_delay);
3828 _capturing_processor.reset (new CapturingProcessor (_session, _session.worst_track_latency () - _initial_delay));
3829 _capturing_processor->activate ();
3831 configure_processors_unlocked (0, &lw);
3835 return _capturing_processor;
3839 Route::update_signal_latency ()
3841 framecnt_t l = _output->user_latency();
3842 framecnt_t lamp = 0;
3843 bool before_amp = true;
3844 framecnt_t ltrim = 0;
3845 bool before_trim = true;
3847 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3848 if ((*i)->active ()) {
3849 l += (*i)->signal_latency ();
3854 if ((*i) == _trim) {
3865 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3867 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3868 _signal_latency_at_amp_position = lamp;
3869 _signal_latency_at_trim_position = ltrim;
3871 if (_signal_latency != l) {
3872 _signal_latency = l;
3873 signal_latency_changed (); /* EMIT SIGNAL */
3876 return _signal_latency;
3880 Route::set_user_latency (framecnt_t nframes)
3882 _output->set_user_latency (nframes);
3883 _session.update_latency_compensation ();
3887 Route::set_latency_compensation (framecnt_t longest_session_latency)
3889 framecnt_t old = _initial_delay;
3891 if (_signal_latency < longest_session_latency) {
3892 _initial_delay = longest_session_latency - _signal_latency;
3897 DEBUG_TRACE (DEBUG::Latency, string_compose (
3898 "%1: compensate for maximum latency of %2,"
3899 "given own latency of %3, using initial delay of %4\n",
3900 name(), longest_session_latency, _signal_latency, _initial_delay));
3902 if (_initial_delay != old) {
3903 initial_delay_changed (); /* EMIT SIGNAL */
3906 if (_session.transport_stopped()) {
3907 _roll_delay = _initial_delay;
3912 Route::set_block_size (pframes_t nframes)
3914 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3915 (*i)->set_block_size (nframes);
3918 _session.ensure_buffers (n_process_buffers ());
3922 Route::protect_automation ()
3924 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3925 (*i)->protect_automation();
3928 /** @param declick 1 to set a pending declick fade-in,
3929 * -1 to set a pending declick fade-out
3932 Route::set_pending_declick (int declick)
3935 /* this call is not allowed to turn off a pending declick */
3937 _pending_declick = declick;
3940 _pending_declick = 0;
3944 /** Shift automation forwards from a particular place, thereby inserting time.
3945 * Adds undo commands for any shifts that are performed.
3947 * @param pos Position to start shifting from.
3948 * @param frames Amount to shift forwards by.
3952 Route::shift (framepos_t pos, framecnt_t frames)
3954 /* gain automation */
3956 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3958 XMLNode &before = gc->alist()->get_state ();
3959 gc->alist()->shift (pos, frames);
3960 XMLNode &after = gc->alist()->get_state ();
3961 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3964 /* gain automation */
3966 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3968 XMLNode &before = gc->alist()->get_state ();
3969 gc->alist()->shift (pos, frames);
3970 XMLNode &after = gc->alist()->get_state ();
3971 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3974 // TODO mute automation ??
3976 /* pan automation */
3978 ControlSet::Controls& c (_pannable->controls());
3980 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3981 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3983 boost::shared_ptr<AutomationList> al = pc->alist();
3984 XMLNode& before = al->get_state ();
3985 al->shift (pos, frames);
3986 XMLNode& after = al->get_state ();
3987 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3992 /* redirect automation */
3994 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3995 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3997 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3999 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4000 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4002 boost::shared_ptr<AutomationList> al = ac->alist();
4003 XMLNode &before = al->get_state ();
4004 al->shift (pos, frames);
4005 XMLNode &after = al->get_state ();
4006 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4014 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4016 boost::shared_ptr<Processor> processor (p.lock ());
4017 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4021 pi->set_state_dir (d);
4025 Route::save_as_template (const string& path, const string& name, const string& description)
4027 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4028 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4030 XMLNode& node (state (false));
4031 node.set_property (X_("name"), name);
4033 node.remove_nodes (X_("description"));
4034 if (!description.empty()) {
4035 XMLNode* desc = new XMLNode(X_("description"));
4036 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4037 desc->add_child_nocopy (*desc_cont);
4039 node.add_child_nocopy (*desc);
4044 IO::set_name_in_state (*node.children().front(), name);
4046 tree.set_root (&node);
4048 /* return zero on success, non-zero otherwise */
4049 return !tree.write (path.c_str());
4054 Route::set_name (const string& str)
4060 if (str == name()) {
4064 string name = Route::ensure_track_or_route_name (str, _session);
4065 SessionObject::set_name (name);
4067 bool ret = (_input->set_name(name) && _output->set_name(name));
4070 /* rename the main outs. Leave other IO processors
4071 * with whatever name they already have, because its
4072 * just fine as it is (it will not contain the route
4073 * name if its a port insert, port send or port return).
4077 if (_main_outs->set_name (name)) {
4078 /* XXX returning false here is stupid because
4079 we already changed the route name.
4089 /** Set the name of a route in an XML description.
4090 * @param node XML <Route> node to set the name in.
4091 * @param name New name.
4094 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4096 node.set_property (X_("name"), name);
4098 XMLNodeList children = node.children();
4099 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4101 if ((*i)->name() == X_("IO")) {
4103 IO::set_name_in_state (**i, name);
4105 } else if ((*i)->name() == X_("Processor")) {
4108 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4109 (*i)->set_property (X_("name"), name);
4112 } else if ((*i)->name() == X_("Diskstream")) {
4114 if (rename_playlist) {
4115 (*i)->set_property (X_("playlist"), name + ".1");
4117 (*i)->set_property (X_("name"), name);
4123 boost::shared_ptr<Send>
4124 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4126 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4128 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4129 boost::shared_ptr<InternalSend> send;
4131 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4132 if (send->target_route() == target) {
4138 return boost::shared_ptr<Send>();
4142 Route::set_denormal_protection (bool yn)
4144 if (_denormal_protection != yn) {
4145 _denormal_protection = yn;
4146 denormal_protection_changed (); /* EMIT SIGNAL */
4151 Route::denormal_protection () const
4153 return _denormal_protection;
4157 Route::set_active (bool yn, void* src)
4159 if (_session.transport_rolling()) {
4163 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4164 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4168 if (_active != yn) {
4170 _input->set_active (yn);
4171 _output->set_active (yn);
4172 flush_processors ();
4173 active_changed (); // EMIT SIGNAL
4174 _session.set_dirty ();
4178 boost::shared_ptr<Pannable>
4179 Route::pannable() const
4184 boost::shared_ptr<Panner>
4185 Route::panner() const
4188 return _main_outs->panner_shell()->panner();
4191 boost::shared_ptr<PannerShell>
4192 Route::panner_shell() const
4194 return _main_outs->panner_shell();
4197 boost::shared_ptr<GainControl>
4198 Route::gain_control() const
4200 return _gain_control;
4203 boost::shared_ptr<GainControl>
4204 Route::trim_control() const
4206 return _trim_control;
4209 boost::shared_ptr<PhaseControl>
4210 Route::phase_control() const
4212 return _phase_control;
4215 boost::shared_ptr<AutomationControl>
4216 Route::get_control (const Evoral::Parameter& param)
4218 /* either we own the control or .... */
4220 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4224 /* maybe one of our processors does or ... */
4226 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4227 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4228 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4236 /* nobody does so we'll make a new one */
4238 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4245 boost::shared_ptr<Processor>
4246 Route::nth_plugin (uint32_t n) const
4248 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4249 ProcessorList::const_iterator i;
4251 for (i = _processors.begin(); i != _processors.end(); ++i) {
4252 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4259 return boost::shared_ptr<Processor> ();
4262 boost::shared_ptr<Processor>
4263 Route::nth_send (uint32_t n) const
4265 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4266 ProcessorList::const_iterator i;
4268 for (i = _processors.begin(); i != _processors.end(); ++i) {
4269 if (boost::dynamic_pointer_cast<Send> (*i)) {
4271 if ((*i)->name().find (_("Monitor")) == 0) {
4272 /* send to monitor section is not considered
4273 to be an accessible send.
4284 return boost::shared_ptr<Processor> ();
4288 Route::has_io_processor_named (const string& name)
4290 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4291 ProcessorList::iterator i;
4293 for (i = _processors.begin(); i != _processors.end(); ++i) {
4294 if (boost::dynamic_pointer_cast<Send> (*i) ||
4295 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4296 if ((*i)->name() == name) {
4306 Route::set_processor_positions ()
4308 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4310 bool had_amp = false;
4311 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4312 (*i)->set_pre_fader (!had_amp);
4319 /** Called when there is a proposed change to the input port count */
4321 Route::input_port_count_changing (ChanCount to)
4323 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4325 /* The processors cannot be configured with the new input arrangement, so
4331 /* The change is ok */
4335 /** Called when there is a proposed change to the output port count */
4337 Route::output_port_count_changing (ChanCount to)
4339 if (_strict_io && !_in_configure_processors) {
4342 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4343 if (processor_out_streams.get(*t) > to.get(*t)) {
4347 /* The change is ok */
4352 Route::unknown_processors () const
4356 if (_session.get_disable_all_loaded_plugins ()) {
4357 // Do not list "missing plugins" if they are explicitly disabled
4361 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4362 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4363 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4364 p.push_back ((*i)->name ());
4373 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4375 /* we assume that all our input ports feed all our output ports. its not
4376 universally true, but the alternative is way too corner-case to worry about.
4379 LatencyRange all_connections;
4382 all_connections.min = 0;
4383 all_connections.max = 0;
4385 all_connections.min = ~((pframes_t) 0);
4386 all_connections.max = 0;
4388 /* iterate over all "from" ports and determine the latency range for all of their
4389 connections to the "outside" (outside of this Route).
4392 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4396 p->get_connected_latency_range (range, playback);
4398 all_connections.min = min (all_connections.min, range.min);
4399 all_connections.max = max (all_connections.max, range.max);
4403 /* set the "from" port latencies to the max/min range of all their connections */
4405 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4406 p->set_private_latency_range (all_connections, playback);
4409 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4411 all_connections.min += our_latency;
4412 all_connections.max += our_latency;
4414 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4415 p->set_private_latency_range (all_connections, playback);
4418 return all_connections.max;
4422 Route::set_private_port_latencies (bool playback) const
4424 framecnt_t own_latency = 0;
4426 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4427 OR LATENCY CALLBACK.
4429 This is called (early) from the latency callback. It computes the REAL
4430 latency associated with each port and stores the result as the "private"
4431 latency of the port. A later call to Route::set_public_port_latencies()
4432 sets all ports to the same value to reflect the fact that we do latency
4433 compensation and so all signals are delayed by the same amount as they
4434 flow through ardour.
4437 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4438 if ((*i)->active ()) {
4439 own_latency += (*i)->signal_latency ();
4444 /* playback: propagate latency from "outside the route" to outputs to inputs */
4445 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4447 /* capture: propagate latency from "outside the route" to inputs to outputs */
4448 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4453 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4455 /* this is called to set the JACK-visible port latencies, which take
4456 latency compensation into account.
4465 const PortSet& ports (_input->ports());
4466 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4467 p->set_public_latency_range (range, playback);
4472 const PortSet& ports (_output->ports());
4473 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4474 p->set_public_latency_range (range, playback);
4479 /** Put the invisible processors in the right place in _processors.
4480 * Must be called with a writer lock on _processor_lock held.
4483 __attribute__((annotate("realtime")))
4486 Route::setup_invisible_processors ()
4489 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4490 assert (!lm.locked ());
4494 /* too early to be doing this stuff */
4498 /* we'll build this new list here and then use it
4500 * TODO put the ProcessorList is on the stack for RT-safety.
4503 ProcessorList new_processors;
4505 /* find visible processors */
4507 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4508 if ((*i)->display_to_user ()) {
4509 new_processors.push_back (*i);
4515 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4517 if (amp == new_processors.end ()) {
4518 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4519 new_processors.push_front (_amp);
4520 amp = find (new_processors.begin(), new_processors.end(), _amp);
4523 /* and the processor after the amp */
4525 ProcessorList::iterator after_amp = amp;
4531 switch (_meter_point) {
4533 assert (!_meter->display_to_user ());
4534 new_processors.push_front (_meter);
4537 assert (!_meter->display_to_user ());
4538 new_processors.insert (amp, _meter);
4540 case MeterPostFader:
4541 /* do nothing here */
4544 /* do nothing here */
4547 /* the meter is visible, so we don't touch it here */
4554 assert (_main_outs);
4555 assert (!_main_outs->display_to_user ());
4556 new_processors.push_back (_main_outs);
4558 /* iterator for the main outs */
4560 ProcessorList::iterator main = new_processors.end();
4563 /* OUTPUT METERING */
4565 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4566 assert (!_meter->display_to_user ());
4568 /* add the processor just before or just after the main outs */
4570 ProcessorList::iterator meter_point = main;
4572 if (_meter_point == MeterOutput) {
4575 new_processors.insert (meter_point, _meter);
4580 if (_monitor_send && !is_monitor ()) {
4581 assert (!_monitor_send->display_to_user ());
4582 switch (Config->get_listen_position ()) {
4583 case PreFaderListen:
4584 switch (Config->get_pfl_position ()) {
4585 case PFLFromBeforeProcessors:
4586 new_processors.push_front (_monitor_send);
4588 case PFLFromAfterProcessors:
4589 new_processors.insert (amp, _monitor_send);
4592 _monitor_send->set_can_pan (false);
4594 case AfterFaderListen:
4595 switch (Config->get_afl_position ()) {
4596 case AFLFromBeforeProcessors:
4597 new_processors.insert (after_amp, _monitor_send);
4599 case AFLFromAfterProcessors:
4600 new_processors.insert (new_processors.end(), _monitor_send);
4603 _monitor_send->set_can_pan (true);
4608 #if 0 // not used - just yet
4609 if (!is_master() && !is_monitor() && !is_auditioner()) {
4610 new_processors.push_front (_delayline);
4614 /* MONITOR CONTROL */
4616 if (_monitor_control && is_monitor ()) {
4617 assert (!_monitor_control->display_to_user ());
4618 new_processors.insert (amp, _monitor_control);
4623 if (_trim && _trim->active()) {
4624 assert (!_trim->display_to_user ());
4625 new_processors.push_front (_trim);
4628 /* INTERNAL RETURN */
4630 /* doing this here means that any monitor control will come after
4631 the return and trim.
4635 assert (!_intreturn->display_to_user ());
4636 new_processors.push_front (_intreturn);
4639 /* EXPORT PROCESSOR */
4641 if (_capturing_processor) {
4642 assert (!_capturing_processor->display_to_user ());
4643 new_processors.push_front (_capturing_processor);
4646 _processors = new_processors;
4648 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4649 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4650 (*i)->enable (true);
4654 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4655 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4656 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4663 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4664 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4668 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4669 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4676 /** If the meter point is `Custom', make a note of where the meter is.
4677 * This is so that if the meter point is subsequently set to something else,
4678 * and then back to custom, we can put the meter back where it was last time
4679 * custom was enabled.
4681 * Must be called with the _processor_lock held.
4684 Route::maybe_note_meter_position ()
4686 if (_meter_point != MeterCustom) {
4690 _custom_meter_position_noted = true;
4691 /* custom meter points range from after trim to before panner/main_outs
4692 * this is a limitation by the current processor UI
4694 bool seen_trim = false;
4695 _processor_after_last_custom_meter.reset();
4696 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4697 if ((*i) == _trim) {
4700 if ((*i) == _main_outs) {
4701 _processor_after_last_custom_meter = *i;
4704 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4706 _processor_after_last_custom_meter = _trim;
4708 ProcessorList::iterator j = i;
4710 assert(j != _processors.end ()); // main_outs should be before
4711 _processor_after_last_custom_meter = *j;
4716 assert(_processor_after_last_custom_meter.lock());
4719 boost::shared_ptr<Processor>
4720 Route::processor_by_id (PBD::ID id) const
4722 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4723 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4724 if ((*i)->id() == id) {
4729 return boost::shared_ptr<Processor> ();
4732 /** @return the monitoring state, or in other words what data we are pushing
4733 * into the route (data from the inputs, data from disk or silence)
4736 Route::monitoring_state () const
4738 return MonitoringInput;
4741 /** @return what we should be metering; either the data coming from the input
4742 * IO or the data that is flowing through the route.
4745 Route::metering_state () const
4747 return MeteringRoute;
4751 Route::has_external_redirects () const
4753 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4755 /* ignore inactive processors and obviously ignore the main
4756 * outs since everything has them and we don't care.
4759 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4767 boost::shared_ptr<Processor>
4768 Route::the_instrument () const
4770 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4771 return the_instrument_unlocked ();
4774 boost::shared_ptr<Processor>
4775 Route::the_instrument_unlocked () const
4777 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4778 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4779 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4783 return boost::shared_ptr<Processor>();
4789 Route::non_realtime_locate (framepos_t pos)
4791 Automatable::non_realtime_locate (pos);
4794 _pannable->non_realtime_locate (pos);
4797 if (_delayline.get()) {
4798 _delayline.get()->flush();
4802 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4803 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4805 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4806 (*i)->non_realtime_locate (pos);
4809 _roll_delay = _initial_delay;
4813 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4820 * We don't currently mix MIDI input together, so we don't need the
4821 * complex logic of the audio case.
4824 n_buffers = bufs.count().n_midi ();
4826 for (i = 0; i < n_buffers; ++i) {
4828 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4829 MidiBuffer& buf (bufs.get_midi (i));
4832 buf.copy (source_port->get_midi_buffer(nframes));
4834 buf.silence (nframes);
4840 n_buffers = bufs.count().n_audio();
4842 size_t n_ports = io->n_ports().n_audio();
4843 float scaling = 1.0f;
4845 if (n_ports > n_buffers) {
4846 scaling = ((float) n_buffers) / n_ports;
4849 for (i = 0; i < n_ports; ++i) {
4851 /* if there are more ports than buffers, map them onto buffers
4852 * in a round-robin fashion
4855 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4856 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4858 if (i < n_buffers) {
4860 /* first time through just copy a channel into
4864 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4866 if (scaling != 1.0f) {
4867 buf.apply_gain (scaling, nframes);
4872 /* on subsequent times around, merge data from
4873 * the port with what is already there
4876 if (scaling != 1.0f) {
4877 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4879 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4884 /* silence any remaining buffers */
4886 for (; i < n_buffers; ++i) {
4887 AudioBuffer& buf (bufs.get_audio (i));
4888 buf.silence (nframes);
4891 /* establish the initial setup of the buffer set, reflecting what was
4892 copied into it. unless, of course, we are the auditioner, in which
4893 case nothing was fed into it from the inputs at all.
4896 if (!is_auditioner()) {
4897 bufs.set_count (io->n_ports());
4901 boost::shared_ptr<AutomationControl>
4902 Route::pan_azimuth_control() const
4905 # undef MIXBUS_PORTS_H
4906 # include "../../gtk2_ardour/mixbus_ports.h"
4907 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4909 return boost::shared_ptr<AutomationControl>();
4911 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4913 if (!_pannable || !panner()) {
4914 return boost::shared_ptr<AutomationControl>();
4916 return _pannable->pan_azimuth_control;
4920 boost::shared_ptr<AutomationControl>
4921 Route::pan_elevation_control() const
4923 if (Profile->get_mixbus() || !_pannable || !panner()) {
4924 return boost::shared_ptr<AutomationControl>();
4927 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4929 if (c.find (PanElevationAutomation) != c.end()) {
4930 return _pannable->pan_elevation_control;
4932 return boost::shared_ptr<AutomationControl>();
4935 boost::shared_ptr<AutomationControl>
4936 Route::pan_width_control() const
4939 if (mixbus() && _ch_pre) {
4941 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
4944 if (Profile->get_mixbus() || !_pannable || !panner()) {
4945 return boost::shared_ptr<AutomationControl>();
4948 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4950 if (c.find (PanWidthAutomation) != c.end()) {
4951 return _pannable->pan_width_control;
4953 return boost::shared_ptr<AutomationControl>();
4956 boost::shared_ptr<AutomationControl>
4957 Route::pan_frontback_control() const
4959 if (Profile->get_mixbus() || !_pannable || !panner()) {
4960 return boost::shared_ptr<AutomationControl>();
4963 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4965 if (c.find (PanFrontBackAutomation) != c.end()) {
4966 return _pannable->pan_frontback_control;
4968 return boost::shared_ptr<AutomationControl>();
4971 boost::shared_ptr<AutomationControl>
4972 Route::pan_lfe_control() const
4974 if (Profile->get_mixbus() || !_pannable || !panner()) {
4975 return boost::shared_ptr<AutomationControl>();
4978 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4980 if (c.find (PanLFEAutomation) != c.end()) {
4981 return _pannable->pan_lfe_control;
4983 return boost::shared_ptr<AutomationControl>();
4988 Route::eq_band_cnt () const
4990 if (Profile->get_mixbus()) {
4992 if (is_master() || mixbus()) {
5001 /* Ardour has no well-known EQ object */
5006 boost::shared_ptr<AutomationControl>
5007 Route::eq_gain_controllable (uint32_t band) const
5010 boost::shared_ptr<PluginInsert> eq = ch_eq();
5013 return boost::shared_ptr<AutomationControl>();
5016 uint32_t port_number;
5017 if (is_master() || mixbus()) {
5019 case 0: port_number = 4; break;
5020 case 1: port_number = 3; break;
5021 case 2: port_number = 2; break;
5023 return boost::shared_ptr<AutomationControl>();
5028 case 0: port_number = 14; break;
5029 case 1: port_number = 12; break;
5030 case 2: port_number = 10; break;
5031 case 3: port_number = 8; break;
5033 return boost::shared_ptr<AutomationControl>();
5037 case 0: port_number = 8; break;
5038 case 1: port_number = 6; break;
5039 case 2: port_number = 4; break;
5041 return boost::shared_ptr<AutomationControl>();
5046 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5048 return boost::shared_ptr<AutomationControl>();
5051 boost::shared_ptr<AutomationControl>
5052 Route::eq_freq_controllable (uint32_t band) const
5055 if (mixbus() || is_master()) {
5056 /* no frequency controls for mixbusses or master */
5057 return boost::shared_ptr<AutomationControl>();
5060 boost::shared_ptr<PluginInsert> eq = ch_eq();
5063 return boost::shared_ptr<AutomationControl>();
5066 uint32_t port_number;
5069 case 0: port_number = 13; break; // lo
5070 case 1: port_number = 11; break; // lo mid
5071 case 2: port_number = 9; break; // hi mid
5072 case 3: port_number = 7; break; // hi
5074 return boost::shared_ptr<AutomationControl>();
5078 case 0: port_number = 7; break;
5079 case 1: port_number = 5; break;
5080 case 2: port_number = 3; break;
5082 return boost::shared_ptr<AutomationControl>();
5086 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5088 return boost::shared_ptr<AutomationControl>();
5092 boost::shared_ptr<AutomationControl>
5093 Route::eq_q_controllable (uint32_t band) const
5095 return boost::shared_ptr<AutomationControl>();
5098 boost::shared_ptr<AutomationControl>
5099 Route::eq_shape_controllable (uint32_t band) const
5102 boost::shared_ptr<PluginInsert> eq = ch_eq();
5103 if (is_master() || mixbus() || !eq) {
5104 return boost::shared_ptr<AutomationControl>();
5108 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5111 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5117 return boost::shared_ptr<AutomationControl>();
5120 boost::shared_ptr<AutomationControl>
5121 Route::eq_enable_controllable () const
5124 boost::shared_ptr<PluginInsert> eq = ch_eq();
5127 return boost::shared_ptr<AutomationControl>();
5130 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5132 return boost::shared_ptr<AutomationControl>();
5136 boost::shared_ptr<AutomationControl>
5137 Route::filter_freq_controllable (bool hpf) const
5140 boost::shared_ptr<PluginInsert> eq = ch_eq();
5142 if (is_master() || mixbus() || !eq) {
5143 return boost::shared_ptr<AutomationControl>();
5147 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5149 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5153 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5155 return boost::shared_ptr<AutomationControl>();
5160 return boost::shared_ptr<AutomationControl>();
5164 boost::shared_ptr<AutomationControl>
5165 Route::filter_slope_controllable (bool) const
5167 return boost::shared_ptr<AutomationControl>();
5170 boost::shared_ptr<AutomationControl>
5171 Route::filter_enable_controllable (bool) const
5174 boost::shared_ptr<PluginInsert> eq = ch_eq();
5176 if (is_master() || mixbus() || !eq) {
5177 return boost::shared_ptr<AutomationControl>();
5180 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5182 return boost::shared_ptr<AutomationControl>();
5187 Route::eq_band_name (uint32_t band) const
5190 if (is_master() || mixbus()) {
5192 if (Profile->get_mixbus()) {
5194 case 0: return _("lo");
5195 case 1: return _("mid");
5196 case 2: return _("hi");
5197 default: return string();
5205 case 0: return _("lo");
5206 case 1: return _("lo mid");
5207 case 2: return _("hi mid");
5208 case 3: return _("hi");
5209 default: return string();
5215 boost::shared_ptr<AutomationControl>
5216 Route::comp_enable_controllable () const
5219 boost::shared_ptr<PluginInsert> comp = ch_comp();
5222 return boost::shared_ptr<AutomationControl>();
5225 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5227 return boost::shared_ptr<AutomationControl>();
5230 boost::shared_ptr<AutomationControl>
5231 Route::comp_threshold_controllable () const
5234 boost::shared_ptr<PluginInsert> comp = ch_comp();
5237 return boost::shared_ptr<AutomationControl>();
5240 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5243 return boost::shared_ptr<AutomationControl>();
5246 boost::shared_ptr<AutomationControl>
5247 Route::comp_speed_controllable () const
5250 boost::shared_ptr<PluginInsert> comp = ch_comp();
5253 return boost::shared_ptr<AutomationControl>();
5256 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5258 return boost::shared_ptr<AutomationControl>();
5261 boost::shared_ptr<AutomationControl>
5262 Route::comp_mode_controllable () const
5265 boost::shared_ptr<PluginInsert> comp = ch_comp();
5268 return boost::shared_ptr<AutomationControl>();
5271 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5273 return boost::shared_ptr<AutomationControl>();
5276 boost::shared_ptr<AutomationControl>
5277 Route::comp_makeup_controllable () const
5280 boost::shared_ptr<PluginInsert> comp = ch_comp();
5283 return boost::shared_ptr<AutomationControl>();
5286 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5288 return boost::shared_ptr<AutomationControl>();
5291 boost::shared_ptr<ReadOnlyControl>
5292 Route::comp_redux_controllable () const
5295 boost::shared_ptr<PluginInsert> comp = ch_comp();
5298 return boost::shared_ptr<ReadOnlyControl>();
5301 return comp->control_output (2);
5303 return comp->control_output (6);
5307 return boost::shared_ptr<ReadOnlyControl>();
5312 Route::comp_mode_name (uint32_t mode) const
5317 return _("Leveler");
5319 return _("Compressor");
5321 return _("Limiter");
5323 return mixbus() ? _("Sidechain") : _("Limiter");
5333 Route::comp_speed_name (uint32_t mode) const
5351 boost::shared_ptr<AutomationControl>
5352 Route::send_level_controllable (uint32_t n) const
5355 # undef MIXBUS_PORTS_H
5356 # include "../../gtk2_ardour/mixbus_ports.h"
5357 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5358 if (plug && !mixbus()) {
5359 uint32_t port_id = 0;
5361 case 0: port_id = port_channel_post_aux1_level; break;
5362 case 1: port_id = port_channel_post_aux2_level; break;
5363 case 2: port_id = port_channel_post_aux3_level; break;
5364 case 3: port_id = port_channel_post_aux4_level; break;
5365 case 4: port_id = port_channel_post_aux5_level; break;
5366 case 5: port_id = port_channel_post_aux6_level; break;
5367 case 6: port_id = port_channel_post_aux7_level; break;
5368 case 7: port_id = port_channel_post_aux8_level; break;
5370 case 8: port_id = port_channel_post_aux9_level; break;
5371 case 9: port_id = port_channel_post_aux10_level; break;
5372 case 10: port_id = port_channel_post_aux11_level; break;
5373 case 11: port_id = port_channel_post_aux12_level; break;
5380 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5391 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5393 return boost::shared_ptr<AutomationControl>();
5395 return s->gain_control ();
5398 boost::shared_ptr<AutomationControl>
5399 Route::send_enable_controllable (uint32_t n) const
5402 # undef MIXBUS_PORTS_H
5403 # include "../../gtk2_ardour/mixbus_ports.h"
5404 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5405 if (plug && !mixbus()) {
5406 uint32_t port_id = 0;
5408 case 0: port_id = port_channel_post_aux1_asgn; break;
5409 case 1: port_id = port_channel_post_aux2_asgn; break;
5410 case 2: port_id = port_channel_post_aux3_asgn; break;
5411 case 3: port_id = port_channel_post_aux4_asgn; break;
5412 case 4: port_id = port_channel_post_aux5_asgn; break;
5413 case 5: port_id = port_channel_post_aux6_asgn; break;
5414 case 6: port_id = port_channel_post_aux7_asgn; break;
5415 case 7: port_id = port_channel_post_aux8_asgn; break;
5417 case 8: port_id = port_channel_post_aux9_asgn; break;
5418 case 9: port_id = port_channel_post_aux10_asgn; break;
5419 case 10: port_id = port_channel_post_aux11_asgn; break;
5420 case 11: port_id = port_channel_post_aux12_asgn; break;
5427 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5438 /* although Ardour sends have enable/disable as part of the Processor
5439 * API, it is not exposed as a controllable.
5441 * XXX: we should fix this (make it click-free, automatable enable-control)
5443 return boost::shared_ptr<AutomationControl>();
5447 Route::send_name (uint32_t n) const
5450 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5451 if (plug && !mixbus()) {
5454 return _session.get_mixbus (n)->name();
5459 return _session.get_mixbus (n)->name();
5465 boost::shared_ptr<Processor> p = nth_send (n);
5473 boost::shared_ptr<AutomationControl>
5474 Route::master_send_enable_controllable () const
5477 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5479 return boost::shared_ptr<AutomationControl>();
5481 # undef MIXBUS_PORTS_H
5482 # include "../../gtk2_ardour/mixbus_ports.h"
5483 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5485 return boost::shared_ptr<AutomationControl>();
5490 Route::slaved () const
5492 if (!_gain_control) {
5495 /* just test one particular control, not all of them */
5496 return _gain_control->slaved ();
5500 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5502 if (!vca || !_gain_control) {
5506 /* just test one particular control, not all of them */
5508 return _gain_control->slaved_to (vca->gain_control());
5512 Route::muted_by_others_soloing () const
5514 if (!can_be_muted_by_others ()) {
5518 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5522 Route::clear_all_solo_state ()
5524 _solo_control->clear_all_solo_state ();
5527 boost::shared_ptr<AutomationControl>
5528 Route::automation_control_recurse (PBD::ID const & id) const
5530 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5536 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5538 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5539 if ((ac = (*i)->automation_control (id))) {
5544 return boost::shared_ptr<AutomationControl> ();
5548 Route::slavables () const
5550 SlavableControlList rv;
5551 rv.push_back (_gain_control);
5552 rv.push_back (_mute_control);
5553 rv.push_back (_solo_control);