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 /* give derived classes a chance to add processors before we configure */
244 add_processors_oh_children_of_mine ();
246 /* now that we have _meter, its safe to connect to this */
249 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
250 configure_processors (0);
258 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
260 /* do this early so that we don't get incoming signals as we are going through destruction
265 /* don't use clear_processors here, as it depends on the session which may
266 be half-destroyed by now
269 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
270 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
271 (*i)->drop_references ();
274 _processors.clear ();
278 Route::ensure_track_or_route_name(string name, Session &session)
280 string newname = name;
282 while (!session.io_name_is_legal (newname)) {
283 newname = bump_name_once (newname, ' ');
290 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
292 // TODO route group, see set_gain()
293 // _trim_control->route_set_value (val);
297 Route::maybe_declick (BufferSet&, framecnt_t, int)
299 /* this is the "bus" implementation and they never declick.
304 /** Process this route for one (sub) cycle (process thread)
306 * @param bufs Scratch buffers to use for the signal path
307 * @param start_frame Initial transport frame
308 * @param end_frame Final transport frame
309 * @param nframes Number of frames to output (to ports)
311 * Note that (end_frame - start_frame) may not be equal to nframes when the
312 * transport speed isn't 1.0 (eg varispeed).
315 Route::process_output_buffers (BufferSet& bufs,
316 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
317 int declick, bool gain_automation_ok)
319 /* Caller must hold process lock */
320 assert (!AudioEngine::instance()->process_lock().trylock());
322 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
324 // can this actually happen? functions calling process_output_buffers()
325 // already take a reader-lock.
326 bufs.silence (nframes, 0);
330 automation_run (start_frame, nframes);
332 /* figure out if we're going to use gain automation */
333 if (gain_automation_ok) {
334 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
335 _amp->setup_gain_automation (
336 start_frame + _signal_latency_at_amp_position,
337 end_frame + _signal_latency_at_amp_position,
340 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
341 _trim->setup_gain_automation (
342 start_frame + _signal_latency_at_trim_position,
343 end_frame + _signal_latency_at_trim_position,
346 _amp->apply_gain_automation (false);
347 _trim->apply_gain_automation (false);
350 /* Tell main outs what to do about monitoring. We do this so that
351 on a transition between monitoring states we get a de-clicking gain
352 change in the _main_outs delivery, if config.get_use_monitor_fades()
355 We override this in the case where we have an internal generator.
357 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
359 _main_outs->no_outs_cuz_we_no_monitor (silence);
361 /* -------------------------------------------------------------------------------------------
362 GLOBAL DECLICK (for transport changes etc.)
363 ----------------------------------------------------------------------------------------- */
365 maybe_declick (bufs, nframes, declick);
366 _pending_declick = 0;
368 /* -------------------------------------------------------------------------------------------
369 DENORMAL CONTROL/PHASE INVERT
370 ----------------------------------------------------------------------------------------- */
372 if (!_phase_control->none()) {
376 if (_denormal_protection || Config->get_denormal_protection()) {
378 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
379 Sample* const sp = i->data();
381 if (_phase_control->inverted (chn)) {
382 for (pframes_t nx = 0; nx < nframes; ++nx) {
387 for (pframes_t nx = 0; nx < nframes; ++nx) {
395 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
396 Sample* const sp = i->data();
398 if (_phase_control->inverted (chn)) {
399 for (pframes_t nx = 0; nx < nframes; ++nx) {
408 if (_denormal_protection || Config->get_denormal_protection()) {
410 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
411 Sample* const sp = i->data();
412 for (pframes_t nx = 0; nx < nframes; ++nx) {
420 /* -------------------------------------------------------------------------------------------
422 ----------------------------------------------------------------------------------------- */
424 /* set this to be true if the meter will already have been ::run() earlier */
425 bool const meter_already_run = metering_state() == MeteringInput;
427 framecnt_t latency = 0;
428 const double speed = _session.transport_speed ();
430 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
432 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
433 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
438 /* if it has any inputs, make sure they match */
439 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
440 if (bufs.count() != (*i)->input_streams()) {
442 DEBUG::Processors, string_compose (
443 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
444 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
451 /* should we NOT run plugins here if the route is inactive?
452 do we catch route != active somewhere higher?
455 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
456 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
458 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
459 const framecnt_t longest_session_latency = _initial_delay + _signal_latency;
460 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
461 _initial_delay + latency, longest_session_latency - latency);
464 //cerr << name() << " run " << (*i)->name() << endl;
465 (*i)->run (bufs, start_frame - latency, end_frame - latency, speed, nframes, *i != _processors.back());
466 bufs.set_count ((*i)->output_streams());
468 if ((*i)->active ()) {
469 latency += (*i)->signal_latency ();
475 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
476 boost::shared_ptr<Processor> endpoint,
477 bool include_endpoint, bool for_export, bool for_freeze)
479 /* If no processing is required, there's no need to go any further. */
480 if (!endpoint && !include_endpoint) {
484 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
485 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
486 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
488 /* trim is always at the top, for bounce no latency compensation is needed */
489 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
490 _trim->setup_gain_automation (start, start + nframes, nframes);
493 const double speed = _session.transport_speed ();
494 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
496 if (!include_endpoint && (*i) == endpoint) {
500 /* if we're *not* exporting, stop processing if we come across a routing processor. */
501 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
504 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
508 /* special case the panner (export outputs)
509 * Ideally we'd only run the panner, not the delivery itself...
510 * but panners need separate input/output buffers and some context
511 * (panshell, panner type, etc). AFAICT there is no ill side effect
512 * of re-using the main delivery when freewheeling/exporting a region.
514 if ((*i) == _main_outs) {
515 assert ((*i)->does_routing());
516 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
517 buffers.set_count ((*i)->output_streams());
520 /* don't run any processors that do routing.
521 * Also don't bother with metering.
523 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
524 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
525 buffers.set_count ((*i)->output_streams());
526 latency += (*i)->signal_latency ();
529 if ((*i) == endpoint) {
536 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
537 bool include_endpoint, bool for_export, bool for_freeze) const
539 framecnt_t latency = 0;
540 if (!endpoint && !include_endpoint) {
544 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
545 if (!include_endpoint && (*i) == endpoint) {
548 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
551 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
554 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
555 latency += (*i)->signal_latency ();
557 if ((*i) == endpoint) {
565 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
566 bool include_endpoint, bool for_export, bool for_freeze) const
568 if (!endpoint && !include_endpoint) {
572 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
573 if (!include_endpoint && (*i) == endpoint) {
576 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
579 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
582 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
583 cc = (*i)->output_streams();
585 if ((*i) == endpoint) {
593 Route::n_process_buffers ()
595 return max (_input->n_ports(), processor_max_streams);
599 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
601 assert (is_monitor());
602 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
603 fill_buffers_with_input (bufs, _input, nframes);
604 passthru (bufs, start_frame, end_frame, nframes, declick);
608 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
612 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
614 /* control/monitor bus ignores input ports when something is
615 feeding the listen "stream". data will "arrive" into the
616 route from the intreturn processor element.
619 bufs.silence (nframes, 0);
622 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
623 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
627 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
629 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
631 bufs.set_count (_input->n_ports());
632 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
633 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
637 Route::set_listen (bool yn)
640 if (_monitor_send->active() == yn) {
644 _monitor_send->activate ();
646 _monitor_send->deactivate ();
652 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
654 /* nothing to do if we're not using AFL/PFL. But if we are, we need
655 to alter the active state of the monitor send.
658 if (Config->get_solo_control_is_listen_control ()) {
659 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
664 Route::push_solo_isolate_upstream (int32_t delta)
666 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
668 boost::shared_ptr<RouteList> routes = _session.get_routes ();
669 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
671 if ((*i).get() == this || !(*i)->can_solo()) {
676 bool does_feed = feeds (*i, &sends_only);
678 if (does_feed && !sends_only) {
679 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
685 Route::push_solo_upstream (int delta)
687 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
688 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
692 boost::shared_ptr<Route> sr (i->r.lock());
694 sr->solo_control()->mod_solo_by_others_downstream (-delta);
701 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
703 cerr << name << " {" << endl;
704 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
705 p != procs.end(); ++p) {
706 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
712 /** Supposing that we want to insert a Processor at a given Placement, return
713 * the processor to add the new one before (or 0 to add at the end).
715 boost::shared_ptr<Processor>
716 Route::before_processor_for_placement (Placement p)
718 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
720 ProcessorList::iterator loc;
723 /* generic pre-fader: insert immediately before the amp */
724 loc = find (_processors.begin(), _processors.end(), _amp);
726 /* generic post-fader: insert right before the main outs */
727 loc = find (_processors.begin(), _processors.end(), _main_outs);
730 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
733 /** Supposing that we want to insert a Processor at a given index, return
734 * the processor to add the new one before (or 0 to add at the end).
736 boost::shared_ptr<Processor>
737 Route::before_processor_for_index (int index)
740 return boost::shared_ptr<Processor> ();
743 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
745 ProcessorList::iterator i = _processors.begin ();
747 while (i != _processors.end() && j < index) {
748 if ((*i)->display_to_user()) {
755 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
758 /** Add a processor either pre- or post-fader
759 * @return 0 on success, non-0 on failure.
762 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
764 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
768 /** Add a processor to a route such that it ends up with a given index into the visible processors.
769 * @param index Index to add the processor at, or -1 to add at the end of the list.
770 * @return 0 on success, non-0 on failure.
773 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
775 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
778 /** Add a processor to the route.
779 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
780 * @return 0 on success, non-0 on failure.
783 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
785 assert (processor != _meter);
786 assert (processor != _main_outs);
788 DEBUG_TRACE (DEBUG::Processors, string_compose (
789 "%1 adding processor %2\n", name(), processor->name()));
793 pl.push_back (processor);
794 int rv = add_processors (pl, before, err);
800 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
801 processor->activate ();
808 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
810 /* We cannot destruct the processor here (usually RT-thread
811 * with various locks held - in case of sends also io_locks).
812 * Queue for deletion in low-priority thread.
814 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
815 selfdestruct_sequence.push_back (wp);
819 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
821 XMLProperty const * prop;
824 boost::shared_ptr<Processor> processor;
826 /* bit of a hack: get the `placement' property from the <Redirect> tag here
827 so that we can add the processor in the right place (pre/post-fader)
830 XMLNodeList const & children = node.children ();
831 XMLNodeList::const_iterator i = children.begin ();
833 while (i != children.end() && (*i)->name() != X_("Redirect")) {
837 Placement placement = PreFader;
839 if (i != children.end()) {
840 if ((prop = (*i)->property (X_("placement"))) != 0) {
841 placement = Placement (string_2_enum (prop->value(), placement));
845 if (node.name() == "Insert") {
847 if ((prop = node.property ("type")) != 0) {
849 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
850 prop->value() == "lv2" ||
851 prop->value() == "windows-vst" ||
852 prop->value() == "mac-vst" ||
853 prop->value() == "lxvst" ||
854 prop->value() == "audiounit") {
856 if (_session.get_disable_all_loaded_plugins ()) {
857 processor.reset (new UnknownProcessor (_session, node));
859 processor.reset (new PluginInsert (_session));
860 processor->set_owner (this);
865 processor.reset (new PortInsert (_session, _pannable, _mute_master));
870 } else if (node.name() == "Send") {
872 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
873 processor.reset (new Send (_session, sendpan, _mute_master));
877 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
881 if (processor->set_state (node, version)) {
885 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
886 if (i != children.end()) {
887 if ((prop = (*i)->property (X_("active"))) != 0) {
888 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
889 processor->activate();
891 processor->deactivate();
895 return (add_processor (processor, placement, 0, false) == 0);
898 catch (failed_constructor &err) {
899 warning << _("processor could not be created. Ignored.") << endmsg;
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));
909 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
910 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
914 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
916 ProcessorList::iterator loc;
917 boost::shared_ptr <PluginInsert> fanout;
919 if (g_atomic_int_get (&_pending_process_reorder)) {
920 /* we need to flush any pending re-order changes */
921 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
922 apply_processor_changes_rt ();
926 loc = find(_processors.begin(), _processors.end(), before);
927 if (loc == _processors.end ()) {
931 /* nothing specified - at end */
932 loc = _processors.end ();
935 if (others.empty()) {
939 ProcessorList to_skip;
941 // check if there's an instrument to replace or configure
942 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
943 boost::shared_ptr<PluginInsert> pi;
944 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
947 if (!pi->plugin ()->get_info ()->is_instrument ()) {
950 boost::shared_ptr<Processor> instrument = the_instrument ();
951 ChanCount in (DataType::MIDI, 1);
952 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
954 PluginSetupOptions flags = None;
957 in = instrument->input_streams ();
958 out = instrument->output_streams ();
960 if (pi->has_output_presets (in, out)) {
964 pi->set_strict_io (_strict_io);
966 PluginSetupOptions mask = None;
967 if (Config->get_ask_replace_instrument ()) {
970 if (Config->get_ask_setup_instrument ()) {
977 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
978 int mode = rv.get_value_or (0);
981 to_skip.push_back (*i); // don't add this one;
984 replace_processor (instrument, *i, err);
985 to_skip.push_back (*i);
990 if ((mode & 5) == 4) {
997 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
998 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
999 ProcessorState pstate (this);
1001 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1006 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1007 if (check != to_skip.end()) {
1011 boost::shared_ptr<PluginInsert> pi;
1013 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1014 pi->set_strict_io (_strict_io);
1018 /* Ensure that only one amp is in the list at any time */
1019 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1020 if (check != _processors.end()) {
1021 if (before == _amp) {
1022 /* Already in position; all is well */
1025 _processors.erase (check);
1030 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1032 _processors.insert (loc, *i);
1033 (*i)->set_owner (this);
1036 if (configure_processors_unlocked (err, &lm)) {
1038 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1043 if (pi && pi->has_sidechain ()) {
1044 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1047 if ((*i)->active()) {
1048 // emit ActiveChanged() and latency_changed() if needed
1052 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1054 boost::shared_ptr<Send> send;
1055 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1056 send->SelfDestruct.connect_same_thread (*this,
1057 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1061 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1062 boost::shared_ptr<PluginInsert> pi;
1064 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1065 if (pi->has_no_inputs ()) {
1066 _have_internal_generator = true;
1072 _output->set_user_latency (0);
1075 reset_instrument_info ();
1076 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1077 set_processor_positions ();
1079 if (fanout && fanout->configured ()
1080 && fanout->output_streams().n_audio() > 2
1081 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1082 fan_out (); /* EMIT SIGNAL */
1088 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1090 if (p == PreFader) {
1091 start = _processors.begin();
1092 end = find(_processors.begin(), _processors.end(), _amp);
1094 start = find(_processors.begin(), _processors.end(), _amp);
1096 end = _processors.end();
1100 /** Turn off all processors with a given placement
1101 * @param p Placement of processors to disable
1104 Route::disable_processors (Placement p)
1106 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1108 ProcessorList::iterator start, end;
1109 placement_range(p, start, end);
1111 for (ProcessorList::iterator i = start; i != end; ++i) {
1112 (*i)->enable (false);
1115 _session.set_dirty ();
1118 /** Turn off all redirects
1121 Route::disable_processors ()
1123 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1125 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1126 (*i)->enable (false);
1129 _session.set_dirty ();
1132 /** Turn off all redirects with a given placement
1133 * @param p Placement of redirects to disable
1136 Route::disable_plugins (Placement p)
1138 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1140 ProcessorList::iterator start, end;
1141 placement_range(p, start, end);
1143 for (ProcessorList::iterator i = start; i != end; ++i) {
1144 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1145 (*i)->enable (false);
1149 _session.set_dirty ();
1152 /** Turn off all plugins
1155 Route::disable_plugins ()
1157 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1159 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1160 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1161 (*i)->enable (false);
1165 _session.set_dirty ();
1170 Route::ab_plugins (bool forward)
1172 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1176 /* forward = turn off all active redirects, and mark them so that the next time
1177 we go the other way, we will revert them
1180 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1181 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1184 if (!(*i)->display_to_user ()) {
1188 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1193 if ((*i)->enabled ()) {
1194 (*i)->enable (false);
1195 (*i)->set_next_ab_is_active (true);
1197 (*i)->set_next_ab_is_active (false);
1203 /* backward = if the redirect was marked to go active on the next ab, do so */
1205 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1206 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1209 if (!(*i)->display_to_user ()) {
1213 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1218 (*i)->enable ((*i)->get_next_ab_is_active ());
1222 _session.set_dirty ();
1226 /** Remove processors with a given placement.
1227 * @param p Placement of processors to remove.
1230 Route::clear_processors (Placement p)
1232 if (!_session.engine().connected()) {
1236 bool already_deleting = _session.deletion_in_progress();
1237 if (!already_deleting) {
1238 _session.set_deletion_in_progress();
1241 ProcessorList old_list = _processors;
1243 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1244 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1245 ProcessorList new_list;
1246 ProcessorStreams err;
1247 bool seen_amp = false;
1249 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1255 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1257 /* you can't remove these */
1259 new_list.push_back (*i);
1266 new_list.push_back (*i);
1269 (*i)->drop_references ();
1277 (*i)->drop_references ();
1280 new_list.push_back (*i);
1287 _processors = new_list;
1288 configure_processors_unlocked (&err, &lm); // this can't fail
1290 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1293 processor_max_streams.reset();
1294 _have_internal_generator = false;
1295 reset_instrument_info ();
1296 set_processor_positions ();
1298 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1300 if (!already_deleting) {
1301 _session.clear_deletion_in_progress();
1306 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1308 // TODO once the export point can be configured properly, do something smarter here
1309 if (processor == _capturing_processor) {
1310 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1311 if (need_process_lock) {
1315 _capturing_processor.reset();
1317 if (need_process_lock) {
1322 /* these can never be removed */
1324 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1328 if (!_session.engine().connected()) {
1332 processor_max_streams.reset();
1335 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1336 if (need_process_lock) {
1340 /* Caller must hold process lock */
1341 assert (!AudioEngine::instance()->process_lock().trylock());
1343 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1345 ProcessorState pstate (this);
1347 ProcessorList::iterator i;
1348 bool removed = false;
1350 for (i = _processors.begin(); i != _processors.end(); ) {
1351 if (*i == processor) {
1353 /* move along, see failure case for configure_processors()
1354 where we may need to reconfigure the processor.
1357 /* stop redirects that send signals to JACK ports
1358 from causing noise as a result of no longer being
1362 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1363 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1367 iop = pi->sidechain();
1374 i = _processors.erase (i);
1382 _output->set_user_latency (0);
1390 if (configure_processors_unlocked (err, &lm)) {
1392 /* we know this will work, because it worked before :) */
1393 configure_processors_unlocked (0, &lm);
1397 _have_internal_generator = false;
1399 for (i = _processors.begin(); i != _processors.end(); ++i) {
1400 boost::shared_ptr<PluginInsert> pi;
1402 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1403 if (pi->has_no_inputs ()) {
1404 _have_internal_generator = true;
1409 if (need_process_lock) {
1414 reset_instrument_info ();
1415 processor->drop_references ();
1416 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1417 set_processor_positions ();
1423 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1425 /* these can never be removed */
1426 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1429 /* and can't be used as substitute, either */
1430 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1434 /* I/Os are out, too */
1435 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1439 /* this function cannot be used to swap/reorder processors */
1440 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1444 if (!AudioEngine::instance()->connected() || !old || !sub) {
1448 /* ensure that sub is not owned by another route */
1449 if (sub->owner ()) {
1454 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1455 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1456 ProcessorState pstate (this);
1458 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1460 ProcessorList::iterator i;
1461 bool replaced = false;
1462 bool enable = old->enabled ();
1464 for (i = _processors.begin(); i != _processors.end(); ) {
1466 i = _processors.erase (i);
1467 _processors.insert (i, sub);
1468 sub->set_owner (this);
1481 boost::shared_ptr<PluginInsert> pi;
1482 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1483 pi->set_strict_io (true);
1487 if (configure_processors_unlocked (err, &lm)) {
1489 configure_processors_unlocked (0, &lm);
1493 _have_internal_generator = false;
1495 for (i = _processors.begin(); i != _processors.end(); ++i) {
1496 boost::shared_ptr<PluginInsert> pi;
1497 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1498 if (pi->has_no_inputs ()) {
1499 _have_internal_generator = true;
1509 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1510 _output->set_user_latency (0);
1513 reset_instrument_info ();
1514 old->drop_references ();
1515 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1516 set_processor_positions ();
1521 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1523 ProcessorList deleted;
1525 if (!_session.engine().connected()) {
1529 processor_max_streams.reset();
1532 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1533 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1534 ProcessorState pstate (this);
1536 ProcessorList::iterator i;
1537 boost::shared_ptr<Processor> processor;
1539 for (i = _processors.begin(); i != _processors.end(); ) {
1543 /* these can never be removed */
1545 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1550 /* see if its in the list of processors to delete */
1552 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1557 /* stop IOProcessors that send to JACK ports
1558 from causing noise as a result of no longer being
1562 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1563 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1566 iop = pi->sidechain();
1573 deleted.push_back (processor);
1574 i = _processors.erase (i);
1577 if (deleted.empty()) {
1578 /* none of those in the requested list were found */
1582 _output->set_user_latency (0);
1584 if (configure_processors_unlocked (err, &lm)) {
1586 /* we know this will work, because it worked before :) */
1587 configure_processors_unlocked (0, &lm);
1592 _have_internal_generator = false;
1594 for (i = _processors.begin(); i != _processors.end(); ++i) {
1595 boost::shared_ptr<PluginInsert> pi;
1597 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1598 if (pi->has_no_inputs ()) {
1599 _have_internal_generator = true;
1606 /* now try to do what we need to so that those that were removed will be deleted */
1608 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1609 (*i)->drop_references ();
1612 reset_instrument_info ();
1613 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1614 set_processor_positions ();
1620 Route::reset_instrument_info ()
1622 boost::shared_ptr<Processor> instr = the_instrument();
1624 _instrument_info.set_internal_instrument (instr);
1628 /** Caller must hold process lock */
1630 Route::configure_processors (ProcessorStreams* err)
1632 #ifndef PLATFORM_WINDOWS
1633 assert (!AudioEngine::instance()->process_lock().trylock());
1636 if (!_in_configure_processors) {
1637 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1638 return configure_processors_unlocked (err, &lm);
1645 Route::input_streams () const
1647 return _input->n_ports ();
1650 list<pair<ChanCount, ChanCount> >
1651 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1653 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1655 return try_configure_processors_unlocked (in, err);
1658 list<pair<ChanCount, ChanCount> >
1659 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1661 // Check each processor in order to see if we can configure as requested
1663 list<pair<ChanCount, ChanCount> > configuration;
1666 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1667 DEBUG_TRACE (DEBUG::Processors, "{\n");
1669 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1671 if ((*p)->can_support_io_configuration(in, out)) {
1673 if (boost::dynamic_pointer_cast<Delivery> (*p)
1674 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1676 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1677 /* with strict I/O the panner + output are forced to
1678 * follow the last processor's output.
1680 * Delivery::can_support_io_configuration() will only add ports,
1681 * but not remove excess ports.
1683 * This works because the delivery only requires
1684 * as many outputs as there are inputs.
1685 * Delivery::configure_io() will do the actual removal
1686 * by calling _output->ensure_io()
1688 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1689 /* ..but at least as many as there are master-inputs, if
1690 * the delivery is dealing with audio */
1691 // XXX this may need special-casing for mixbus (master-outputs)
1692 // and should maybe be a preference anyway ?!
1693 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1699 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1700 configuration.push_back(make_pair(in, out));
1703 // restriction for Monitor Section Processors
1704 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1705 /* Note: The Monitor follows the master-bus and has no panner.
1707 * The general idea is to only allow plugins that retain the channel-count
1708 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1709 * Then again 5.1 in, monitor stereo is a valid use-case.
1711 * and worse: we only refuse adding plugins *here*.
1713 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1714 * 2) change master-bus, add a channel
1715 * 2a) monitor-secion follows
1716 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1717 * 4) re-load session, monitor-processor remains unconfigured, crash.
1719 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1721 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1722 // internal sends make no sense, only feedback
1723 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1724 return list<pair<ChanCount, ChanCount> > ();
1726 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1727 /* External Sends can be problematic. one can add/remove ports
1728 * there signal leaves the DAW to external monitors anyway, so there's
1729 * no real use for allowing them here anyway.
1731 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1732 return list<pair<ChanCount, ChanCount> > ();
1734 if (boost::dynamic_pointer_cast<Send> (*p)) {
1736 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1737 return list<pair<ChanCount, ChanCount> > ();
1746 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1747 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1748 DEBUG_TRACE (DEBUG::Processors, "}\n");
1749 return list<pair<ChanCount, ChanCount> > ();
1753 DEBUG_TRACE (DEBUG::Processors, "}\n");
1755 return configuration;
1758 /** Set the input/output configuration of each processor in the processors list.
1759 * Caller must hold process lock.
1760 * Return 0 on success, otherwise configuration is impossible.
1763 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1765 #ifndef PLATFORM_WINDOWS
1766 assert (!AudioEngine::instance()->process_lock().trylock());
1769 if (_in_configure_processors) {
1773 /* put invisible processors where they should be */
1774 setup_invisible_processors ();
1776 _in_configure_processors = true;
1778 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1780 if (configuration.empty ()) {
1781 _in_configure_processors = false;
1786 bool seen_mains_out = false;
1787 processor_out_streams = _input->n_ports();
1788 processor_max_streams.reset();
1790 /* processor configure_io() may result in adding ports
1791 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1793 * with jack2 adding ports results in a graph-order callback,
1794 * which calls Session::resort_routes() and eventually
1795 * Route::direct_feeds_according_to_reality()
1796 * which takes a ReaderLock (_processor_lock).
1798 * so we can't hold a WriterLock here until jack2 threading
1801 * NB. we still hold the process lock
1803 * (ardour's own engines do call graph-order from the
1804 * process-thread and hence do not have this issue; besides
1805 * merely adding ports won't trigger a graph-order, only
1806 * making connections does)
1810 // TODO check for a potential ReaderLock after ReaderLock ??
1811 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1813 framecnt_t chain_latency = _input->latency ();
1815 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1816 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1818 if (!(*p)->configure_io(c->first, c->second)) {
1819 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1820 _in_configure_processors = false;
1826 (*p)->set_input_latency (chain_latency);
1827 chain_latency += (*p)->signal_latency ();
1829 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1830 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1832 boost::shared_ptr<IOProcessor> iop;
1833 boost::shared_ptr<PluginInsert> pi;
1834 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1835 /* plugins connected via Split or Hide Match may have more channels.
1836 * route/scratch buffers are needed for all of them
1837 * The configuration may only be a subset (both input and output)
1839 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1841 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1842 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1843 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1847 if (boost::dynamic_pointer_cast<Delivery> (*p)
1848 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1849 /* main delivery will increase port count to match input.
1850 * the Delivery::Main is usually the last processor - followed only by
1853 seen_mains_out = true;
1855 if (!seen_mains_out) {
1856 processor_out_streams = out;
1865 _meter->set_max_channels (processor_max_streams);
1868 /* make sure we have sufficient scratch buffers to cope with the new processor
1871 _session.ensure_buffers (n_process_buffers ());
1873 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1875 _in_configure_processors = false;
1879 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1880 * @param state New active state for those processors.
1883 Route::all_visible_processors_active (bool state)
1885 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1887 if (_processors.empty()) {
1891 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1892 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1896 boost::shared_ptr<PluginInsert> pi;
1897 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1898 if (pi->is_channelstrip ()) {
1903 (*i)->enable (state);
1906 _session.set_dirty ();
1910 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1912 /* check if re-order requires re-configuration of any processors
1913 * -> compare channel configuration for all processors
1915 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1916 ChanCount c = input_streams ();
1918 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1920 if (c != (*j)->input_streams()) {
1923 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1926 if ((*i)->input_streams() != c) {
1929 c = (*i)->output_streams();
1941 __attribute__((annotate("realtime")))
1944 Route::apply_processor_order (const ProcessorList& new_order)
1946 /* need to hold processor_lock; either read or write lock
1947 * and the engine process_lock.
1948 * Due to r/w lock ambiguity we can only assert the latter
1950 assert (!AudioEngine::instance()->process_lock().trylock());
1953 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1954 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1955 * processors in the current actual processor list that are hidden. Any visible processors
1956 * in the current list but not in "new_order" will be assumed to be deleted.
1959 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1960 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1961 * (note though that ::processors_reorder_needs_configure() ensured that
1962 * this function will only ever be called from the rt-thread if no processor were removed)
1964 * either way, I can't proove it, but an x-run due to re-order here is less likley
1965 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1968 ProcessorList as_it_will_be;
1969 ProcessorList::iterator oiter;
1970 ProcessorList::const_iterator niter;
1972 oiter = _processors.begin();
1973 niter = new_order.begin();
1975 while (niter != new_order.end()) {
1977 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1978 then append it to the temp list.
1980 Otherwise, see if the next processor in the old list is in the new list. if not,
1981 its been deleted. If its there, append it to the temp list.
1984 if (oiter == _processors.end()) {
1986 /* no more elements in the old list, so just stick the rest of
1987 the new order onto the temp list.
1990 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1991 while (niter != new_order.end()) {
1998 if (!(*oiter)->display_to_user()) {
2000 as_it_will_be.push_back (*oiter);
2004 /* visible processor: check that its in the new order */
2006 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2007 /* deleted: do nothing, shared_ptr<> will clean up */
2009 /* ignore this one, and add the next item from the new order instead */
2010 as_it_will_be.push_back (*niter);
2015 /* now remove from old order - its taken care of no matter what */
2016 oiter = _processors.erase (oiter);
2020 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2022 /* If the meter is in a custom position, find it and make a rough note of its position */
2023 maybe_note_meter_position ();
2027 Route::move_instrument_down (bool postfader)
2029 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2030 ProcessorList new_order;
2031 boost::shared_ptr<Processor> instrument;
2032 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2033 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2034 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2036 } else if (instrument && *i == _amp) {
2038 new_order.push_back (*i);
2039 new_order.push_back (instrument);
2041 new_order.push_back (instrument);
2042 new_order.push_back (*i);
2045 new_order.push_back (*i);
2052 reorder_processors (new_order, 0);
2056 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2058 // it a change is already queued, wait for it
2059 // (unless engine is stopped. apply immediately and proceed
2060 while (g_atomic_int_get (&_pending_process_reorder)) {
2061 if (!AudioEngine::instance()->running()) {
2062 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2063 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2065 apply_processor_order(_pending_processor_order);
2066 setup_invisible_processors ();
2068 g_atomic_int_set (&_pending_process_reorder, 0);
2070 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2071 set_processor_positions ();
2073 // TODO rather use a semaphore or something.
2074 // but since ::reorder_processors() is called
2075 // from the GUI thread, this is fine..
2080 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2082 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2083 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2084 ProcessorState pstate (this);
2086 apply_processor_order (new_order);
2088 if (configure_processors_unlocked (err, &lm)) {
2096 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2097 set_processor_positions ();
2100 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2101 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2103 // _pending_processor_order is protected by _processor_lock
2104 _pending_processor_order = new_order;
2105 g_atomic_int_set (&_pending_process_reorder, 1);
2112 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2114 boost::shared_ptr<PluginInsert> pi;
2115 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2119 if (pi->has_sidechain () == add) {
2120 return true; // ?? call failed, but result is as expected.
2124 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2125 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2126 if (i == _processors.end ()) {
2132 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2133 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2134 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2136 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2138 if (!pi->add_sidechain ()) {
2142 if (!pi->del_sidechain ()) {
2148 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2153 pi->del_sidechain ();
2155 pi->add_sidechain ();
2156 // TODO restore side-chain's state.
2161 configure_processors_unlocked (0, &lm);
2164 if (pi->has_sidechain ()) {
2165 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2168 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2169 _session.set_dirty ();
2174 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2176 boost::shared_ptr<PluginInsert> pi;
2177 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2182 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2183 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2184 if (i == _processors.end ()) {
2190 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2191 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2193 const ChanCount& old (pi->preset_out ());
2194 if (!pi->set_preset_out (outs)) {
2195 return true; // no change, OK
2198 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2201 pi->set_preset_out (old);
2204 configure_processors_unlocked (0, &lm);
2207 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2208 _session.set_dirty ();
2213 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2216 return customize_plugin_insert (proc, 0, unused, unused);
2220 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2222 boost::shared_ptr<PluginInsert> pi;
2223 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2228 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2229 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2230 if (i == _processors.end ()) {
2236 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2237 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2239 bool old_cust = pi->custom_cfg ();
2240 uint32_t old_cnt = pi->get_count ();
2241 ChanCount old_chan = pi->output_streams ();
2242 ChanCount old_sinks = pi->natural_input_streams ();
2245 pi->set_custom_cfg (false);
2247 pi->set_custom_cfg (true);
2248 pi->set_count (count);
2249 pi->set_outputs (outs);
2250 pi->set_sinks (sinks);
2253 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2257 pi->set_count (old_cnt);
2258 pi->set_sinks (old_sinks);
2259 pi->set_outputs (old_chan);
2260 pi->set_custom_cfg (old_cust);
2264 configure_processors_unlocked (0, &lm);
2267 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2268 _session.set_dirty ();
2273 Route::set_strict_io (const bool enable)
2275 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2277 if (_strict_io != enable) {
2278 _strict_io = enable;
2279 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2280 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2281 boost::shared_ptr<PluginInsert> pi;
2282 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2283 pi->set_strict_io (_strict_io);
2287 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2291 _strict_io = !enable; // restore old value
2292 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2293 boost::shared_ptr<PluginInsert> pi;
2294 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2295 pi->set_strict_io (_strict_io);
2302 configure_processors (0);
2305 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2306 _session.set_dirty ();
2318 Route::get_template()
2320 return state(false);
2324 Route::state(bool full_state)
2326 if (!_session._template_state_dir.empty()) {
2327 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2330 XMLNode *node = new XMLNode("Route");
2331 ProcessorList::iterator i;
2333 node->set_property ("id", id ());
2334 node->set_property ("name", name());
2335 node->set_property ("default-type", _default_type);
2336 node->set_property ("strict-io", _strict_io);
2338 node->add_child_nocopy (_presentation_info.get_state());
2340 node->set_property ("active", _active);
2341 node->set_property ("denormal-protection", _denormal_protection);
2342 node->set_property ("meter-point", _meter_point);
2344 node->set_property ("meter-type", _meter_type);
2347 node->set_property ("route-group", _route_group->name());
2350 node->add_child_nocopy (_solo_control->get_state ());
2351 node->add_child_nocopy (_solo_isolate_control->get_state ());
2352 node->add_child_nocopy (_solo_safe_control->get_state ());
2354 node->add_child_nocopy (_input->state (full_state));
2355 node->add_child_nocopy (_output->state (full_state));
2356 node->add_child_nocopy (_mute_master->get_state ());
2358 node->add_child_nocopy (_mute_control->get_state ());
2359 node->add_child_nocopy (_phase_control->get_state ());
2362 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2365 if (_comment.length()) {
2366 XMLNode *cmt = node->add_child ("Comment");
2367 cmt->add_content (_comment);
2371 node->add_child_nocopy (_pannable->state (full_state));
2375 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2376 for (i = _processors.begin(); i != _processors.end(); ++i) {
2378 /* template save: do not include internal sends functioning as
2379 aux sends because the chance of the target ID
2380 in the session where this template is used
2383 similarly, do not save listen sends which connect to
2384 the monitor section, because these will always be
2387 boost::shared_ptr<InternalSend> is;
2389 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2390 if (is->role() == Delivery::Listen) {
2395 node->add_child_nocopy((*i)->state (full_state));
2400 node->add_child_copy (*_extra_xml);
2403 if (_custom_meter_position_noted) {
2404 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2406 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2410 if (!_session._template_state_dir.empty()) {
2411 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2414 node->add_child_copy (Slavable::get_state());
2420 Route::set_state (const XMLNode& node, int version)
2422 if (version < 3000) {
2423 return set_state_2X (node, version);
2427 XMLNodeConstIterator niter;
2430 if (node.name() != "Route"){
2431 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2435 std::string route_name;
2436 if (node.get_property (X_("name"), route_name)) {
2437 Route::set_name (route_name);
2441 _initial_io_setup = true;
2443 Stripable::set_state (node, version);
2445 node.get_property (X_("strict-io"), _strict_io);
2448 /* monitor bus does not get a panner, but if (re)created
2449 via XML, it will already have one by the time we
2450 call ::set_state(). so ... remove it.
2455 /* add all processors (except amp, which is always present) */
2457 nlist = node.children();
2458 XMLNode processor_state (X_("processor_state"));
2460 Stateful::save_extra_xml (node);
2462 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2466 if (child->name() == IO::state_node_name) {
2467 std::string direction;
2468 if (!child->get_property (X_("direction"), direction)) {
2472 if (direction == "Input") {
2473 _input->set_state (*child, version);
2474 } else if (direction == "Output") {
2475 _output->set_state (*child, version);
2478 } else if (child->name() == X_("Processor")) {
2479 processor_state.add_child_copy (*child);
2480 } else if (child->name() == X_("Pannable")) {
2482 _pannable->set_state (*child, version);
2484 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2486 } else if (child->name() == Slavable::xml_node_name) {
2487 Slavable::set_state (*child, version);
2492 if (node.get_property (X_("meter-point"), mp)) {
2493 set_meter_point (mp, true);
2495 _meter->set_display_to_user (_meter_point == MeterCustom);
2499 node.get_property (X_("meter-type"), _meter_type);
2501 _initial_io_setup = false;
2503 set_processor_state (processor_state);
2505 // this looks up the internal instrument in processors
2506 reset_instrument_info();
2508 bool denormal_protection;
2509 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2510 set_denormal_protection (denormal_protection);
2513 /* convert old 3001 state */
2514 std::string phase_invert_str;
2515 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2516 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2520 if (node.get_property (X_("active"), is_active)) {
2521 set_active (is_active, this);
2524 std::string id_string;
2525 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2526 PBD::ID id (id_string);
2527 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2528 ProcessorList::const_iterator i = _processors.begin ();
2529 while (i != _processors.end() && (*i)->id() != id) {
2533 if (i != _processors.end ()) {
2534 _processor_after_last_custom_meter = *i;
2535 _custom_meter_position_noted = true;
2539 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2542 if (child->name() == X_("Comment")) {
2544 /* XXX this is a terrible API design in libxml++ */
2546 XMLNode *cmt = *(child->children().begin());
2547 _comment = cmt->content();
2549 } else if (child->name() == Controllable::xml_node_name) {
2550 std::string control_name;
2551 if (!child->get_property (X_("name"), control_name)) {
2555 if (control_name == _solo_control->name()) {
2556 _solo_control->set_state (*child, version);
2557 } else if (control_name == _solo_safe_control->name()) {
2558 _solo_safe_control->set_state (*child, version);
2559 } else if (control_name == _solo_isolate_control->name()) {
2560 _solo_isolate_control->set_state (*child, version);
2561 } else if (control_name == _mute_control->name()) {
2562 _mute_control->set_state (*child, version);
2563 } else if (control_name == _phase_control->name()) {
2564 _phase_control->set_state (*child, version);
2566 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2567 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2568 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2570 ac->set_state (*child, version);
2574 } else if (child->name() == MuteMaster::xml_node_name) {
2575 _mute_master->set_state (*child, version);
2577 } else if (child->name() == Automatable::xml_node_name) {
2578 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2586 Route::set_state_2X (const XMLNode& node, int version)
2590 XMLNodeConstIterator niter;
2592 XMLProperty const * prop;
2594 /* 2X things which still remain to be handled:
2600 if (node.name() != "Route") {
2601 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2605 Stripable::set_state (node, version);
2607 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2608 set_denormal_protection (string_to<bool> (prop->value()));
2611 if ((prop = node.property (X_("muted"))) != 0) {
2614 bool muted = string_to<bool> (prop->value());
2620 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2622 if (string_to<bool> (prop->value())){
2623 mute_point = mute_point + "PreFader";
2628 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2630 if (string_to<bool> (prop->value())){
2633 mute_point = mute_point + ",";
2636 mute_point = mute_point + "PostFader";
2641 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2643 if (string_to<bool> (prop->value())){
2646 mute_point = mute_point + ",";
2649 mute_point = mute_point + "Listen";
2654 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2656 if (string_to<bool> (prop->value())){
2659 mute_point = mute_point + ",";
2662 mute_point = mute_point + "Main";
2666 _mute_master->set_mute_points (mute_point);
2667 _mute_master->set_muted_by_self (true);
2671 if ((prop = node.property (X_("meter-point"))) != 0) {
2672 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2677 nlist = node.children ();
2678 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2682 if (child->name() == IO::state_node_name) {
2684 /* there is a note in IO::set_state_2X() about why we have to call
2688 _input->set_state_2X (*child, version, true);
2689 _output->set_state_2X (*child, version, false);
2691 if ((prop = child->property (X_("name"))) != 0) {
2692 Route::set_name (prop->value ());
2697 if ((prop = child->property (X_("active"))) != 0) {
2698 bool yn = string_to<bool> (prop->value());
2699 _active = !yn; // force switch
2700 set_active (yn, this);
2703 if ((prop = child->property (X_("gain"))) != 0) {
2706 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2707 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2711 /* Set up Panners in the IO */
2712 XMLNodeList io_nlist = child->children ();
2714 XMLNodeConstIterator io_niter;
2717 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2719 io_child = *io_niter;
2721 if (io_child->name() == X_("Panner")) {
2722 _main_outs->panner_shell()->set_state(*io_child, version);
2723 } else if (io_child->name() == X_("Automation")) {
2724 /* IO's automation is for the fader */
2725 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2731 XMLNodeList redirect_nodes;
2733 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2737 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2738 redirect_nodes.push_back(child);
2743 set_processor_state_2X (redirect_nodes, version);
2745 Stateful::save_extra_xml (node);
2747 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2750 if (child->name() == X_("Comment")) {
2752 /* XXX this is a terrible API design in libxml++ */
2754 XMLNode *cmt = *(child->children().begin());
2755 _comment = cmt->content();
2757 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2758 if (prop->value() == X_("solo")) {
2759 _solo_control->set_state (*child, version);
2760 } else if (prop->value() == X_("mute")) {
2761 _mute_control->set_state (*child, version);
2771 Route::get_processor_state ()
2773 XMLNode* root = new XMLNode (X_("redirects"));
2774 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2775 root->add_child_nocopy ((*i)->state (true));
2782 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2784 /* We don't bother removing existing processors not in nList, as this
2785 method will only be called when creating a Route from scratch, not
2786 for undo purposes. Just put processors in at the appropriate place
2790 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2791 add_processor_from_xml_2X (**i, version);
2796 Route::set_processor_state (const XMLNode& node)
2798 const XMLNodeList &nlist = node.children();
2799 XMLNodeConstIterator niter;
2800 ProcessorList new_order;
2801 bool must_configure = false;
2803 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2805 XMLProperty* prop = (*niter)->property ("type");
2807 if (prop->value() == "amp") {
2808 _amp->set_state (**niter, Stateful::current_state_version);
2809 new_order.push_back (_amp);
2810 } else if (prop->value() == "trim") {
2811 _trim->set_state (**niter, Stateful::current_state_version);
2812 new_order.push_back (_trim);
2813 } else if (prop->value() == "meter") {
2814 _meter->set_state (**niter, Stateful::current_state_version);
2815 new_order.push_back (_meter);
2816 } else if (prop->value() == "delay") {
2818 _delayline->set_state (**niter, Stateful::current_state_version);
2819 new_order.push_back (_delayline);
2821 } else if (prop->value() == "main-outs") {
2822 _main_outs->set_state (**niter, Stateful::current_state_version);
2823 } else if (prop->value() == "intreturn") {
2825 _intreturn.reset (new InternalReturn (_session));
2826 must_configure = true;
2828 _intreturn->set_state (**niter, Stateful::current_state_version);
2829 } else if (is_monitor() && prop->value() == "monitor") {
2830 if (!_monitor_control) {
2831 _monitor_control.reset (new MonitorProcessor (_session));
2832 must_configure = true;
2834 _monitor_control->set_state (**niter, Stateful::current_state_version);
2835 } else if (prop->value() == "capture") {
2836 /* CapturingProcessor should never be restored, it's always
2837 added explicitly when needed */
2839 set_processor_state (**niter, prop, new_order, must_configure);
2843 ProcessorList old_list = _processors; // keep a copy
2845 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2846 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2847 /* re-assign _processors w/o process-lock.
2848 * if there's an IO-processor present in _processors but
2849 * not in new_order, it will be deleted and ~IO takes
2852 _processors = new_order;
2854 if (must_configure) {
2855 configure_processors_unlocked (0, &lm);
2858 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2860 (*i)->set_owner (this);
2861 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2863 boost::shared_ptr<PluginInsert> pi;
2865 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2866 if (pi->has_no_inputs ()) {
2867 _have_internal_generator = true;
2873 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2876 reset_instrument_info ();
2877 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2878 set_processor_positions ();
2882 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2884 ProcessorList::iterator o;
2886 for (o = _processors.begin(); o != _processors.end(); ++o) {
2887 XMLProperty const * id_prop = node.property(X_("id"));
2888 if (id_prop && (*o)->id() == id_prop->value()) {
2889 (*o)->set_state (node, Stateful::current_state_version);
2890 new_order.push_back (*o);
2895 // If the processor (node) is not on the route then create it
2897 if (o == _processors.end()) {
2899 boost::shared_ptr<Processor> processor;
2901 if (prop->value() == "intsend") {
2903 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2905 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2906 prop->value() == "lv2" ||
2907 prop->value() == "windows-vst" ||
2908 prop->value() == "mac-vst" ||
2909 prop->value() == "lxvst" ||
2910 prop->value() == "luaproc" ||
2911 prop->value() == "audiounit") {
2913 if (_session.get_disable_all_loaded_plugins ()) {
2914 processor.reset (new UnknownProcessor (_session, node));
2916 processor.reset (new PluginInsert (_session));
2917 processor->set_owner (this);
2919 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2920 pi->set_strict_io (true);
2924 } else if (prop->value() == "port") {
2926 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2928 } else if (prop->value() == "send") {
2930 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2931 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2932 send->SelfDestruct.connect_same_thread (*this,
2933 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2939 if (processor->set_state (node, Stateful::current_state_version) != 0) {
2940 /* This processor could not be configured. Turn it into a UnknownProcessor */
2941 processor.reset (new UnknownProcessor (_session, node));
2944 /* subscribe to Sidechain IO changes */
2945 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2946 if (pi && pi->has_sidechain ()) {
2947 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2950 /* we have to note the monitor send here, otherwise a new one will be created
2951 and the state of this one will be lost.
2953 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2954 if (isend && isend->role() == Delivery::Listen) {
2955 _monitor_send = isend;
2958 /* it doesn't matter if invisible processors are added here, as they
2959 will be sorted out by setup_invisible_processors () shortly.
2962 new_order.push_back (processor);
2963 must_configure = true;
2969 Route::curve_reallocate ()
2971 // _gain_automation_curve.finish_resize ();
2972 // _pan_automation_curve.finish_resize ();
2976 Route::silence (framecnt_t nframes)
2978 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2983 silence_unlocked (nframes);
2987 Route::silence_unlocked (framecnt_t nframes)
2989 /* Must be called with the processor lock held */
2991 const framepos_t now = _session.transport_frame ();
2995 _output->silence (nframes);
2997 // update owned automated controllables
2998 automation_run (now, nframes);
3000 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3001 boost::shared_ptr<PluginInsert> pi;
3003 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3004 /* evaluate automated automation controls */
3005 pi->automation_run (now, nframes);
3006 /* skip plugins, they don't need anything when we're not active */
3010 (*i)->silence (nframes, now);
3013 if (nframes == _session.get_block_size()) {
3020 Route::add_internal_return ()
3023 _intreturn.reset (new InternalReturn (_session));
3024 add_processor (_intreturn, PreFader);
3029 Route::add_send_to_internal_return (InternalSend* send)
3031 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3033 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3034 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3037 return d->add_send (send);
3043 Route::remove_send_from_internal_return (InternalSend* send)
3045 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3047 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3048 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3051 return d->remove_send (send);
3057 Route::enable_monitor_send ()
3059 /* Caller must hold process lock */
3060 assert (!AudioEngine::instance()->process_lock().trylock());
3062 /* master never sends to monitor section via the normal mechanism */
3063 assert (!is_master ());
3064 assert (!is_monitor ());
3066 /* make sure we have one */
3067 if (!_monitor_send) {
3068 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3069 _monitor_send->set_display_to_user (false);
3073 configure_processors (0);
3076 /** Add an aux send to a route.
3077 * @param route route to send to.
3078 * @param before Processor to insert before, or 0 to insert at the end.
3081 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3083 assert (route != _session.monitor_out ());
3086 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3088 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3090 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3092 if (d && d->target_route() == route) {
3093 /* already listening via the specified IO: do nothing */
3101 boost::shared_ptr<InternalSend> listener;
3104 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3105 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3108 add_processor (listener, before);
3110 } catch (failed_constructor& err) {
3118 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3120 ProcessorStreams err;
3121 ProcessorList::iterator tmp;
3124 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3126 /* have to do this early because otherwise processor reconfig
3127 * will put _monitor_send back in the list
3130 if (route == _session.monitor_out()) {
3131 _monitor_send.reset ();
3135 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3137 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3139 if (d && d->target_route() == route) {
3141 if (remove_processor (*x, &err, false) > 0) {
3147 /* list could have been demolished while we dropped the lock
3150 if (_session.engine().connected()) {
3151 /* i/o processors cannot be removed if the engine is not running
3152 * so don't live-loop in case the engine is N/A or dies
3162 Route::set_comment (string cmt, void *src)
3166 _session.set_dirty ();
3170 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3172 FeedRecord fr (other, via_sends_only);
3174 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3176 if (!result.second) {
3178 /* already a record for "other" - make sure sends-only information is correct */
3179 if (!via_sends_only && result.first->sends_only) {
3180 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3181 frp->sends_only = false;
3185 return result.second;
3189 Route::clear_fed_by ()
3195 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3197 const FedBy& fed_by (other->fed_by());
3199 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3200 boost::shared_ptr<Route> sr = f->r.lock();
3202 if (sr && (sr.get() == this)) {
3204 if (via_sends_only) {
3205 *via_sends_only = f->sends_only;
3216 Route::all_inputs () const
3218 /* TODO, if this works as expected,
3219 * cache the IOVector and maintain it via
3220 * input_change_handler(), sidechain_change_handler() etc
3223 ios.push_back (_input);
3225 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3226 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3228 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3229 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3232 iop = pi->sidechain();
3235 if (iop != 0 && iop->input()) {
3236 ios.push_back (iop->input());
3243 Route::all_outputs () const
3246 // _output is included via Delivery
3247 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3248 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3249 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3250 if (iop != 0 && iop->output()) {
3251 ios.push_back (iop->output());
3258 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3260 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3261 if (other->all_inputs().fed_by (_output)) {
3262 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3263 if (via_send_only) {
3264 *via_send_only = false;
3270 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3272 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3274 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3275 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3278 iop = pi->sidechain();
3282 boost::shared_ptr<const IO> iop_out = iop->output();
3283 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3284 // TODO this needs a delaylines in the Insert to align connections (!)
3285 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3288 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3289 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3290 if (via_send_only) {
3291 *via_send_only = true;
3295 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3298 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3303 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3308 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3310 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3314 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3316 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3319 /** Called from the (non-realtime) butler thread when the transport is stopped */
3321 Route::non_realtime_transport_stop (framepos_t now, bool flush)
3324 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3326 Automatable::non_realtime_transport_stop (now, flush);
3328 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3330 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3334 (*i)->non_realtime_transport_stop (now, flush);
3338 _roll_delay = _initial_delay;
3342 Route::input_change_handler (IOChange change, void * /*src*/)
3344 if ((change.type & IOChange::ConfigurationChanged)) {
3345 /* This is called with the process lock held if change
3346 contains ConfigurationChanged
3348 configure_processors (0);
3349 _phase_control->resize (_input->n_ports().n_audio ());
3350 io_changed (); /* EMIT SIGNAL */
3353 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3356 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3357 if (_input->connected()) {
3358 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3359 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3363 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3364 if (does_feed && !sends_only) {
3365 if ((*i)->soloed()) {
3368 if ((*i)->solo_isolate_control()->solo_isolated()) {
3375 int delta = sbou - _solo_control->soloed_by_others_upstream();
3376 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3379 PBD::warning << string_compose (
3380 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3381 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3386 if (_solo_control->soloed_by_others_upstream()) {
3387 // ignore new connections (they're not propagated)
3389 _solo_control->mod_solo_by_others_upstream (delta);
3393 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3394 // solo-isolate currently only propagates downstream
3396 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3398 //_solo_isolated_by_upstream = ibou;
3401 // Session::route_solo_changed does not propagate indirect solo-changes
3402 // propagate downstream to tracks
3403 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3404 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3408 bool does_feed = feeds (*i, &sends_only);
3409 if (delta <= 0 && does_feed && !sends_only) {
3410 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3413 if (idelta < 0 && does_feed && !sends_only) {
3414 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3421 Route::output_change_handler (IOChange change, void * /*src*/)
3423 if (_initial_io_setup) {
3427 if ((change.type & IOChange::ConfigurationChanged)) {
3428 /* This is called with the process lock held if change
3429 contains ConfigurationChanged
3431 configure_processors (0);
3434 _session.reset_monitor_section();
3437 io_changed (); /* EMIT SIGNAL */
3440 if ((change.type & IOChange::ConnectionsChanged)) {
3442 /* do this ONLY if connections have changed. Configuration
3443 * changes do not, by themselves alter solo upstream or
3444 * downstream status.
3447 if (_solo_control->soloed_by_others_downstream()) {
3449 /* checking all all downstream routes for
3450 * explicit of implict solo is a rather drastic measure,
3451 * ideally the input_change_handler() of the other route
3452 * would propagate the change to us.
3454 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3455 if (_output->connected()) {
3456 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3457 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3461 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3462 if (does_feed && !sends_only) {
3463 if ((*i)->soloed()) {
3471 int delta = sbod - _solo_control->soloed_by_others_downstream();
3473 // do not allow new connections to change implicit solo (no propagation)
3474 _solo_control->mod_solo_by_others_downstream (delta);
3475 // Session::route_solo_changed() does not propagate indirect solo-changes
3476 // propagate upstream to tracks
3477 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3478 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3479 if ((*i).get() == this || !can_solo()) {
3483 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3484 if (delta != 0 && does_feed && !sends_only) {
3485 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3495 Route::sidechain_change_handler (IOChange change, void* src)
3497 if (_initial_io_setup || _in_sidechain_setup) {
3501 input_change_handler (change, src);
3505 Route::pans_required () const
3507 if (n_outputs().n_audio() < 2) {
3511 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3515 Route::flush_processor_buffers_locked (framecnt_t nframes)
3517 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3518 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3520 d->flush_buffers (nframes);
3522 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3524 p->flush_buffers (nframes);
3531 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3533 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3540 silence_unlocked (nframes);
3544 if (session_state_changing) {
3545 if (_session.transport_speed() != 0.0f) {
3546 /* we're rolling but some state is changing (e.g. our diskstream contents)
3547 so we cannot use them. Be silent till this is over.
3549 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3551 silence_unlocked (nframes);
3554 /* we're really not rolling, so we're either delivery silence or actually
3555 monitoring, both of which are safe to do while session_state_changing is true.
3559 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3561 fill_buffers_with_input (bufs, _input, nframes);
3563 if (_meter_point == MeterInput) {
3564 _meter->run (bufs, start_frame, end_frame, 0.0, nframes, true);
3567 _amp->apply_gain_automation (false);
3568 _trim->apply_gain_automation (false);
3569 passthru (bufs, start_frame, end_frame, nframes, 0);
3571 flush_processor_buffers_locked (nframes);
3577 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3579 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3585 silence_unlocked (nframes);
3589 framepos_t unused = 0;
3591 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3597 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3599 fill_buffers_with_input (bufs, _input, nframes);
3601 if (_meter_point == MeterInput) {
3602 _meter->run (bufs, start_frame, end_frame, 1.0, nframes, true);
3605 passthru (bufs, start_frame, end_frame, nframes, declick);
3607 flush_processor_buffers_locked (nframes);
3613 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3616 flush_processor_buffers_locked (nframes);
3621 Route::flush_processors ()
3623 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3625 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3631 __attribute__((annotate("realtime")))
3634 Route::apply_processor_changes_rt ()
3636 int emissions = EmitNone;
3638 if (_pending_meter_point != _meter_point) {
3639 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3641 /* meters always have buffers for 'processor_max_streams'
3642 * they can be re-positioned without re-allocation */
3643 if (set_meter_point_unlocked()) {
3644 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3646 emissions |= EmitMeterChanged;
3651 bool changed = false;
3653 if (g_atomic_int_get (&_pending_process_reorder)) {
3654 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3656 apply_processor_order (_pending_processor_order);
3657 setup_invisible_processors ();
3659 g_atomic_int_set (&_pending_process_reorder, 0);
3660 emissions |= EmitRtProcessorChange;
3664 set_processor_positions ();
3666 if (emissions != 0) {
3667 g_atomic_int_set (&_pending_signals, emissions);
3670 return (!selfdestruct_sequence.empty ());
3674 Route::emit_pending_signals ()
3676 int sig = g_atomic_int_and (&_pending_signals, 0);
3677 if (sig & EmitMeterChanged) {
3678 _meter->emit_configuration_changed();
3679 meter_change (); /* EMIT SIGNAL */
3680 if (sig & EmitMeterVisibilityChange) {
3681 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3683 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3686 if (sig & EmitRtProcessorChange) {
3687 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3690 /* this would be a job for the butler.
3691 * Conceptually we should not take processe/processor locks here.
3692 * OTOH its more efficient (less overhead for summoning the butler and
3693 * telling her what do do) and signal emission is called
3694 * directly after the process callback, which decreases the chance
3695 * of x-runs when taking the locks.
3697 while (!selfdestruct_sequence.empty ()) {
3698 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3699 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3700 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3701 selfdestruct_sequence.pop_back ();
3704 remove_processor (proc);
3710 Route::set_meter_point (MeterPoint p, bool force)
3712 if (_pending_meter_point == p && !force) {
3716 if (force || !AudioEngine::instance()->running()) {
3717 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3718 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3719 _pending_meter_point = p;
3720 _meter->emit_configuration_changed();
3721 meter_change (); /* EMIT SIGNAL */
3722 if (set_meter_point_unlocked()) {
3723 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3725 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3728 _pending_meter_point = p;
3734 __attribute__((annotate("realtime")))
3737 Route::set_meter_point_unlocked ()
3740 /* Caller must hold process and processor write lock */
3741 assert (!AudioEngine::instance()->process_lock().trylock());
3742 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3743 assert (!lm.locked ());
3746 _meter_point = _pending_meter_point;
3748 bool meter_was_visible_to_user = _meter->display_to_user ();
3750 if (!_custom_meter_position_noted) {
3751 maybe_note_meter_position ();
3754 if (_meter_point != MeterCustom) {
3756 _meter->set_display_to_user (false);
3758 setup_invisible_processors ();
3761 _meter->set_display_to_user (true);
3763 /* If we have a previous position for the custom meter, try to put it there */
3764 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3766 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3767 if (i != _processors.end ()) {
3768 _processors.remove (_meter);
3769 _processors.insert (i, _meter);
3771 } else {// at end, right before the mains_out/panner
3772 _processors.remove (_meter);
3773 ProcessorList::iterator main = _processors.end();
3774 _processors.insert (--main, _meter);
3778 /* Set up the meter for its new position */
3780 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3784 if (loc == _processors.begin()) {
3785 m_in = _input->n_ports();
3787 ProcessorList::iterator before = loc;
3789 m_in = (*before)->output_streams ();
3792 _meter->reflect_inputs (m_in);
3794 /* we do not need to reconfigure the processors, because the meter
3795 (a) is always ready to handle processor_max_streams
3796 (b) is always an N-in/N-out processor, and thus moving
3797 it doesn't require any changes to the other processors.
3800 /* these should really be done after releasing the lock
3801 * but all those signals are subscribed to with gui_thread()
3804 return (_meter->display_to_user() != meter_was_visible_to_user);
3808 Route::listen_position_changed ()
3811 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3812 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3813 ProcessorState pstate (this);
3815 if (configure_processors_unlocked (0, &lm)) {
3816 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3818 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3823 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3824 _session.set_dirty ();
3827 boost::shared_ptr<CapturingProcessor>
3828 Route::add_export_point()
3830 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3831 if (!_capturing_processor) {
3833 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3834 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3836 // this aligns all tracks; but not tracks + busses
3837 assert (_session.worst_track_latency () >= _initial_delay);
3838 _capturing_processor.reset (new CapturingProcessor (_session, _session.worst_track_latency () - _initial_delay));
3839 _capturing_processor->activate ();
3841 configure_processors_unlocked (0, &lw);
3845 return _capturing_processor;
3849 Route::update_signal_latency ()
3851 framecnt_t l = _output->user_latency();
3852 framecnt_t lamp = 0;
3853 bool before_amp = true;
3854 framecnt_t ltrim = 0;
3855 bool before_trim = true;
3857 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3858 if ((*i)->active ()) {
3859 l += (*i)->signal_latency ();
3864 if ((*i) == _trim) {
3875 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3877 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3878 _signal_latency_at_amp_position = lamp;
3879 _signal_latency_at_trim_position = ltrim;
3881 if (_signal_latency != l) {
3882 _signal_latency = l;
3883 signal_latency_changed (); /* EMIT SIGNAL */
3886 return _signal_latency;
3890 Route::set_user_latency (framecnt_t nframes)
3892 _output->set_user_latency (nframes);
3893 _session.update_latency_compensation ();
3897 Route::set_latency_compensation (framecnt_t longest_session_latency)
3899 framecnt_t old = _initial_delay;
3901 if (_signal_latency < longest_session_latency) {
3902 _initial_delay = longest_session_latency - _signal_latency;
3907 DEBUG_TRACE (DEBUG::Latency, string_compose (
3908 "%1: compensate for maximum latency of %2,"
3909 "given own latency of %3, using initial delay of %4\n",
3910 name(), longest_session_latency, _signal_latency, _initial_delay));
3912 if (_initial_delay != old) {
3913 initial_delay_changed (); /* EMIT SIGNAL */
3916 if (_session.transport_stopped()) {
3917 _roll_delay = _initial_delay;
3922 Route::set_block_size (pframes_t nframes)
3924 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3925 (*i)->set_block_size (nframes);
3928 _session.ensure_buffers (n_process_buffers ());
3932 Route::protect_automation ()
3934 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3935 (*i)->protect_automation();
3938 /** @param declick 1 to set a pending declick fade-in,
3939 * -1 to set a pending declick fade-out
3942 Route::set_pending_declick (int declick)
3945 /* this call is not allowed to turn off a pending declick */
3947 _pending_declick = declick;
3950 _pending_declick = 0;
3954 /** Shift automation forwards from a particular place, thereby inserting time.
3955 * Adds undo commands for any shifts that are performed.
3957 * @param pos Position to start shifting from.
3958 * @param frames Amount to shift forwards by.
3962 Route::shift (framepos_t pos, framecnt_t frames)
3964 /* gain automation */
3966 boost::shared_ptr<AutomationControl> gc = _amp->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 /* gain automation */
3976 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3978 XMLNode &before = gc->alist()->get_state ();
3979 gc->alist()->shift (pos, frames);
3980 XMLNode &after = gc->alist()->get_state ();
3981 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3984 // TODO mute automation ??
3986 /* pan automation */
3988 ControlSet::Controls& c (_pannable->controls());
3990 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3991 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3993 boost::shared_ptr<AutomationList> al = pc->alist();
3994 XMLNode& before = al->get_state ();
3995 al->shift (pos, frames);
3996 XMLNode& after = al->get_state ();
3997 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4002 /* redirect automation */
4004 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4005 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4007 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4009 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4010 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4012 boost::shared_ptr<AutomationList> al = ac->alist();
4013 XMLNode &before = al->get_state ();
4014 al->shift (pos, frames);
4015 XMLNode &after = al->get_state ();
4016 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4024 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4026 boost::shared_ptr<Processor> processor (p.lock ());
4027 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4031 pi->set_state_dir (d);
4035 Route::save_as_template (const string& path, const string& name, const string& description)
4037 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4038 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4040 XMLNode& node (state (false));
4041 node.set_property (X_("name"), name);
4043 node.remove_nodes (X_("description"));
4044 if (!description.empty()) {
4045 XMLNode* desc = new XMLNode(X_("description"));
4046 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4047 desc->add_child_nocopy (*desc_cont);
4049 node.add_child_nocopy (*desc);
4054 IO::set_name_in_state (*node.children().front(), name);
4056 tree.set_root (&node);
4058 /* return zero on success, non-zero otherwise */
4059 return !tree.write (path.c_str());
4064 Route::set_name (const string& str)
4070 if (str == name()) {
4074 string name = Route::ensure_track_or_route_name (str, _session);
4075 SessionObject::set_name (name);
4077 bool ret = (_input->set_name(name) && _output->set_name(name));
4080 /* rename the main outs. Leave other IO processors
4081 * with whatever name they already have, because its
4082 * just fine as it is (it will not contain the route
4083 * name if its a port insert, port send or port return).
4087 if (_main_outs->set_name (name)) {
4088 /* XXX returning false here is stupid because
4089 we already changed the route name.
4099 /** Set the name of a route in an XML description.
4100 * @param node XML <Route> node to set the name in.
4101 * @param name New name.
4104 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4106 node.set_property (X_("name"), name);
4108 XMLNodeList children = node.children();
4109 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4111 if ((*i)->name() == X_("IO")) {
4113 IO::set_name_in_state (**i, name);
4115 } else if ((*i)->name() == X_("Processor")) {
4118 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4119 (*i)->set_property (X_("name"), name);
4122 } else if ((*i)->name() == X_("Diskstream")) {
4124 if (rename_playlist) {
4125 (*i)->set_property (X_("playlist"), name + ".1");
4127 (*i)->set_property (X_("name"), name);
4133 boost::shared_ptr<Send>
4134 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4136 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4138 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4139 boost::shared_ptr<InternalSend> send;
4141 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4142 if (send->target_route() == target) {
4148 return boost::shared_ptr<Send>();
4152 Route::set_denormal_protection (bool yn)
4154 if (_denormal_protection != yn) {
4155 _denormal_protection = yn;
4156 denormal_protection_changed (); /* EMIT SIGNAL */
4161 Route::denormal_protection () const
4163 return _denormal_protection;
4167 Route::set_active (bool yn, void* src)
4169 if (_session.transport_rolling()) {
4173 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4174 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4178 if (_active != yn) {
4180 _input->set_active (yn);
4181 _output->set_active (yn);
4182 flush_processors ();
4183 active_changed (); // EMIT SIGNAL
4184 _session.set_dirty ();
4188 boost::shared_ptr<Pannable>
4189 Route::pannable() const
4194 boost::shared_ptr<Panner>
4195 Route::panner() const
4198 return _main_outs->panner_shell()->panner();
4201 boost::shared_ptr<PannerShell>
4202 Route::panner_shell() const
4204 return _main_outs->panner_shell();
4207 boost::shared_ptr<GainControl>
4208 Route::gain_control() const
4210 return _gain_control;
4213 boost::shared_ptr<GainControl>
4214 Route::trim_control() const
4216 return _trim_control;
4219 boost::shared_ptr<PhaseControl>
4220 Route::phase_control() const
4222 return _phase_control;
4225 boost::shared_ptr<AutomationControl>
4226 Route::get_control (const Evoral::Parameter& param)
4228 /* either we own the control or .... */
4230 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4234 /* maybe one of our processors does or ... */
4236 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4237 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4238 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4246 /* nobody does so we'll make a new one */
4248 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4255 boost::shared_ptr<Processor>
4256 Route::nth_plugin (uint32_t n) const
4258 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4259 ProcessorList::const_iterator i;
4261 for (i = _processors.begin(); i != _processors.end(); ++i) {
4262 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4269 return boost::shared_ptr<Processor> ();
4272 boost::shared_ptr<Processor>
4273 Route::nth_send (uint32_t n) const
4275 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4276 ProcessorList::const_iterator i;
4278 for (i = _processors.begin(); i != _processors.end(); ++i) {
4279 if (boost::dynamic_pointer_cast<Send> (*i)) {
4281 if ((*i)->name().find (_("Monitor")) == 0) {
4282 /* send to monitor section is not considered
4283 to be an accessible send.
4294 return boost::shared_ptr<Processor> ();
4298 Route::has_io_processor_named (const string& name)
4300 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4301 ProcessorList::iterator i;
4303 for (i = _processors.begin(); i != _processors.end(); ++i) {
4304 if (boost::dynamic_pointer_cast<Send> (*i) ||
4305 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4306 if ((*i)->name() == name) {
4316 Route::set_processor_positions ()
4318 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4320 bool had_amp = false;
4321 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4322 (*i)->set_pre_fader (!had_amp);
4329 /** Called when there is a proposed change to the input port count */
4331 Route::input_port_count_changing (ChanCount to)
4333 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4335 /* The processors cannot be configured with the new input arrangement, so
4341 /* The change is ok */
4345 /** Called when there is a proposed change to the output port count */
4347 Route::output_port_count_changing (ChanCount to)
4349 if (_strict_io && !_in_configure_processors) {
4352 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4353 if (processor_out_streams.get(*t) > to.get(*t)) {
4357 /* The change is ok */
4362 Route::unknown_processors () const
4366 if (_session.get_disable_all_loaded_plugins ()) {
4367 // Do not list "missing plugins" if they are explicitly disabled
4371 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4372 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4373 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4374 p.push_back ((*i)->name ());
4383 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4385 /* we assume that all our input ports feed all our output ports. its not
4386 universally true, but the alternative is way too corner-case to worry about.
4389 LatencyRange all_connections;
4392 all_connections.min = 0;
4393 all_connections.max = 0;
4395 all_connections.min = ~((pframes_t) 0);
4396 all_connections.max = 0;
4398 /* iterate over all "from" ports and determine the latency range for all of their
4399 connections to the "outside" (outside of this Route).
4402 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4406 p->get_connected_latency_range (range, playback);
4408 all_connections.min = min (all_connections.min, range.min);
4409 all_connections.max = max (all_connections.max, range.max);
4413 /* set the "from" port latencies to the max/min range of all their connections */
4415 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4416 p->set_private_latency_range (all_connections, playback);
4419 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4421 all_connections.min += our_latency;
4422 all_connections.max += our_latency;
4424 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4425 p->set_private_latency_range (all_connections, playback);
4428 return all_connections.max;
4432 Route::set_private_port_latencies (bool playback) const
4434 framecnt_t own_latency = 0;
4436 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4437 OR LATENCY CALLBACK.
4439 This is called (early) from the latency callback. It computes the REAL
4440 latency associated with each port and stores the result as the "private"
4441 latency of the port. A later call to Route::set_public_port_latencies()
4442 sets all ports to the same value to reflect the fact that we do latency
4443 compensation and so all signals are delayed by the same amount as they
4444 flow through ardour.
4447 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4448 if ((*i)->active ()) {
4449 own_latency += (*i)->signal_latency ();
4454 /* playback: propagate latency from "outside the route" to outputs to inputs */
4455 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4457 /* capture: propagate latency from "outside the route" to inputs to outputs */
4458 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4463 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4465 /* this is called to set the JACK-visible port latencies, which take
4466 latency compensation into account.
4475 const PortSet& ports (_input->ports());
4476 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4477 p->set_public_latency_range (range, playback);
4482 const PortSet& ports (_output->ports());
4483 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4484 p->set_public_latency_range (range, playback);
4489 /** Put the invisible processors in the right place in _processors.
4490 * Must be called with a writer lock on _processor_lock held.
4493 __attribute__((annotate("realtime")))
4496 Route::setup_invisible_processors ()
4499 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4500 assert (!lm.locked ());
4504 /* too early to be doing this stuff */
4508 /* we'll build this new list here and then use it
4510 * TODO put the ProcessorList is on the stack for RT-safety.
4513 ProcessorList new_processors;
4515 /* find visible processors */
4517 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4518 if ((*i)->display_to_user ()) {
4519 new_processors.push_back (*i);
4525 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4527 if (amp == new_processors.end ()) {
4528 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4529 new_processors.push_front (_amp);
4530 amp = find (new_processors.begin(), new_processors.end(), _amp);
4533 /* and the processor after the amp */
4535 ProcessorList::iterator after_amp = amp;
4541 switch (_meter_point) {
4543 assert (!_meter->display_to_user ());
4544 new_processors.push_front (_meter);
4547 assert (!_meter->display_to_user ());
4548 new_processors.insert (amp, _meter);
4550 case MeterPostFader:
4551 /* do nothing here */
4554 /* do nothing here */
4557 /* the meter is visible, so we don't touch it here */
4564 assert (_main_outs);
4565 assert (!_main_outs->display_to_user ());
4566 new_processors.push_back (_main_outs);
4568 /* iterator for the main outs */
4570 ProcessorList::iterator main = new_processors.end();
4573 /* OUTPUT METERING */
4575 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4576 assert (!_meter->display_to_user ());
4578 /* add the processor just before or just after the main outs */
4580 ProcessorList::iterator meter_point = main;
4582 if (_meter_point == MeterOutput) {
4585 new_processors.insert (meter_point, _meter);
4590 if (_monitor_send && !is_monitor ()) {
4591 assert (!_monitor_send->display_to_user ());
4592 switch (Config->get_listen_position ()) {
4593 case PreFaderListen:
4594 switch (Config->get_pfl_position ()) {
4595 case PFLFromBeforeProcessors:
4596 new_processors.push_front (_monitor_send);
4598 case PFLFromAfterProcessors:
4599 new_processors.insert (amp, _monitor_send);
4602 _monitor_send->set_can_pan (false);
4604 case AfterFaderListen:
4605 switch (Config->get_afl_position ()) {
4606 case AFLFromBeforeProcessors:
4607 new_processors.insert (after_amp, _monitor_send);
4609 case AFLFromAfterProcessors:
4610 new_processors.insert (new_processors.end(), _monitor_send);
4613 _monitor_send->set_can_pan (true);
4618 #if 0 // not used - just yet
4619 if (!is_master() && !is_monitor() && !is_auditioner()) {
4620 new_processors.push_front (_delayline);
4624 /* MONITOR CONTROL */
4626 if (_monitor_control && is_monitor ()) {
4627 assert (!_monitor_control->display_to_user ());
4628 new_processors.insert (amp, _monitor_control);
4633 if (_trim && _trim->active()) {
4634 assert (!_trim->display_to_user ());
4635 new_processors.push_front (_trim);
4638 /* INTERNAL RETURN */
4640 /* doing this here means that any monitor control will come after
4641 the return and trim.
4645 assert (!_intreturn->display_to_user ());
4646 new_processors.push_front (_intreturn);
4649 /* EXPORT PROCESSOR */
4651 if (_capturing_processor) {
4652 assert (!_capturing_processor->display_to_user ());
4653 new_processors.push_front (_capturing_processor);
4656 setup_invisible_processors_oh_children_of_mine (new_processors);
4658 _processors = new_processors;
4660 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4661 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4662 (*i)->enable (true);
4666 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4667 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4668 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4675 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4676 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4680 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4681 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4688 /** If the meter point is `Custom', make a note of where the meter is.
4689 * This is so that if the meter point is subsequently set to something else,
4690 * and then back to custom, we can put the meter back where it was last time
4691 * custom was enabled.
4693 * Must be called with the _processor_lock held.
4696 Route::maybe_note_meter_position ()
4698 if (_meter_point != MeterCustom) {
4702 _custom_meter_position_noted = true;
4703 /* custom meter points range from after trim to before panner/main_outs
4704 * this is a limitation by the current processor UI
4706 bool seen_trim = false;
4707 _processor_after_last_custom_meter.reset();
4708 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4709 if ((*i) == _trim) {
4712 if ((*i) == _main_outs) {
4713 _processor_after_last_custom_meter = *i;
4716 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4718 _processor_after_last_custom_meter = _trim;
4720 ProcessorList::iterator j = i;
4722 assert(j != _processors.end ()); // main_outs should be before
4723 _processor_after_last_custom_meter = *j;
4728 assert(_processor_after_last_custom_meter.lock());
4731 boost::shared_ptr<Processor>
4732 Route::processor_by_id (PBD::ID id) const
4734 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4735 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4736 if ((*i)->id() == id) {
4741 return boost::shared_ptr<Processor> ();
4744 /** @return the monitoring state, or in other words what data we are pushing
4745 * into the route (data from the inputs, data from disk or silence)
4748 Route::monitoring_state () const
4750 return MonitoringInput;
4753 /** @return what we should be metering; either the data coming from the input
4754 * IO or the data that is flowing through the route.
4757 Route::metering_state () const
4759 return MeteringRoute;
4763 Route::has_external_redirects () const
4765 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4767 /* ignore inactive processors and obviously ignore the main
4768 * outs since everything has them and we don't care.
4771 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4779 boost::shared_ptr<Processor>
4780 Route::the_instrument () const
4782 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4783 return the_instrument_unlocked ();
4786 boost::shared_ptr<Processor>
4787 Route::the_instrument_unlocked () const
4789 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4790 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4791 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4795 return boost::shared_ptr<Processor>();
4801 Route::non_realtime_locate (framepos_t pos)
4803 Automatable::non_realtime_locate (pos);
4806 _pannable->non_realtime_locate (pos);
4809 if (_delayline.get()) {
4810 _delayline.get()->flush();
4814 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4815 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4817 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4818 (*i)->non_realtime_locate (pos);
4821 _roll_delay = _initial_delay;
4825 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4832 * We don't currently mix MIDI input together, so we don't need the
4833 * complex logic of the audio case.
4836 n_buffers = bufs.count().n_midi ();
4838 for (i = 0; i < n_buffers; ++i) {
4840 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4841 MidiBuffer& buf (bufs.get_midi (i));
4844 buf.copy (source_port->get_midi_buffer(nframes));
4846 buf.silence (nframes);
4852 n_buffers = bufs.count().n_audio();
4854 size_t n_ports = io->n_ports().n_audio();
4855 float scaling = 1.0f;
4857 if (n_ports > n_buffers) {
4858 scaling = ((float) n_buffers) / n_ports;
4861 for (i = 0; i < n_ports; ++i) {
4863 /* if there are more ports than buffers, map them onto buffers
4864 * in a round-robin fashion
4867 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4868 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4870 if (i < n_buffers) {
4872 /* first time through just copy a channel into
4876 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4878 if (scaling != 1.0f) {
4879 buf.apply_gain (scaling, nframes);
4884 /* on subsequent times around, merge data from
4885 * the port with what is already there
4888 if (scaling != 1.0f) {
4889 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4891 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4896 /* silence any remaining buffers */
4898 for (; i < n_buffers; ++i) {
4899 AudioBuffer& buf (bufs.get_audio (i));
4900 buf.silence (nframes);
4903 /* establish the initial setup of the buffer set, reflecting what was
4904 copied into it. unless, of course, we are the auditioner, in which
4905 case nothing was fed into it from the inputs at all.
4908 if (!is_auditioner()) {
4909 bufs.set_count (io->n_ports());
4913 boost::shared_ptr<AutomationControl>
4914 Route::pan_azimuth_control() const
4917 # undef MIXBUS_PORTS_H
4918 # include "../../gtk2_ardour/mixbus_ports.h"
4919 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4921 return boost::shared_ptr<AutomationControl>();
4923 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4925 if (!_pannable || !panner()) {
4926 return boost::shared_ptr<AutomationControl>();
4928 return _pannable->pan_azimuth_control;
4932 boost::shared_ptr<AutomationControl>
4933 Route::pan_elevation_control() const
4935 if (Profile->get_mixbus() || !_pannable || !panner()) {
4936 return boost::shared_ptr<AutomationControl>();
4939 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4941 if (c.find (PanElevationAutomation) != c.end()) {
4942 return _pannable->pan_elevation_control;
4944 return boost::shared_ptr<AutomationControl>();
4947 boost::shared_ptr<AutomationControl>
4948 Route::pan_width_control() const
4951 if (mixbus() && _ch_pre) {
4953 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
4956 if (Profile->get_mixbus() || !_pannable || !panner()) {
4957 return boost::shared_ptr<AutomationControl>();
4960 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4962 if (c.find (PanWidthAutomation) != c.end()) {
4963 return _pannable->pan_width_control;
4965 return boost::shared_ptr<AutomationControl>();
4968 boost::shared_ptr<AutomationControl>
4969 Route::pan_frontback_control() const
4971 if (Profile->get_mixbus() || !_pannable || !panner()) {
4972 return boost::shared_ptr<AutomationControl>();
4975 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4977 if (c.find (PanFrontBackAutomation) != c.end()) {
4978 return _pannable->pan_frontback_control;
4980 return boost::shared_ptr<AutomationControl>();
4983 boost::shared_ptr<AutomationControl>
4984 Route::pan_lfe_control() const
4986 if (Profile->get_mixbus() || !_pannable || !panner()) {
4987 return boost::shared_ptr<AutomationControl>();
4990 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4992 if (c.find (PanLFEAutomation) != c.end()) {
4993 return _pannable->pan_lfe_control;
4995 return boost::shared_ptr<AutomationControl>();
5000 Route::eq_band_cnt () const
5002 if (Profile->get_mixbus()) {
5004 if (is_master() || mixbus()) {
5013 /* Ardour has no well-known EQ object */
5018 boost::shared_ptr<AutomationControl>
5019 Route::eq_gain_controllable (uint32_t band) const
5022 boost::shared_ptr<PluginInsert> eq = ch_eq();
5025 return boost::shared_ptr<AutomationControl>();
5028 uint32_t port_number;
5029 if (is_master() || mixbus()) {
5031 case 0: port_number = 4; break;
5032 case 1: port_number = 3; break;
5033 case 2: port_number = 2; break;
5035 return boost::shared_ptr<AutomationControl>();
5040 case 0: port_number = 14; break;
5041 case 1: port_number = 12; break;
5042 case 2: port_number = 10; break;
5043 case 3: port_number = 8; break;
5045 return boost::shared_ptr<AutomationControl>();
5049 case 0: port_number = 8; break;
5050 case 1: port_number = 6; break;
5051 case 2: port_number = 4; break;
5053 return boost::shared_ptr<AutomationControl>();
5058 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5060 return boost::shared_ptr<AutomationControl>();
5063 boost::shared_ptr<AutomationControl>
5064 Route::eq_freq_controllable (uint32_t band) const
5067 if (mixbus() || is_master()) {
5068 /* no frequency controls for mixbusses or master */
5069 return boost::shared_ptr<AutomationControl>();
5072 boost::shared_ptr<PluginInsert> eq = ch_eq();
5075 return boost::shared_ptr<AutomationControl>();
5078 uint32_t port_number;
5081 case 0: port_number = 13; break; // lo
5082 case 1: port_number = 11; break; // lo mid
5083 case 2: port_number = 9; break; // hi mid
5084 case 3: port_number = 7; break; // hi
5086 return boost::shared_ptr<AutomationControl>();
5090 case 0: port_number = 7; break;
5091 case 1: port_number = 5; break;
5092 case 2: port_number = 3; break;
5094 return boost::shared_ptr<AutomationControl>();
5098 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5100 return boost::shared_ptr<AutomationControl>();
5104 boost::shared_ptr<AutomationControl>
5105 Route::eq_q_controllable (uint32_t band) const
5107 return boost::shared_ptr<AutomationControl>();
5110 boost::shared_ptr<AutomationControl>
5111 Route::eq_shape_controllable (uint32_t band) const
5114 boost::shared_ptr<PluginInsert> eq = ch_eq();
5115 if (is_master() || mixbus() || !eq) {
5116 return boost::shared_ptr<AutomationControl>();
5120 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5123 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5129 return boost::shared_ptr<AutomationControl>();
5132 boost::shared_ptr<AutomationControl>
5133 Route::eq_enable_controllable () const
5136 boost::shared_ptr<PluginInsert> eq = ch_eq();
5139 return boost::shared_ptr<AutomationControl>();
5142 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5144 return boost::shared_ptr<AutomationControl>();
5148 boost::shared_ptr<AutomationControl>
5149 Route::filter_freq_controllable (bool hpf) const
5152 boost::shared_ptr<PluginInsert> eq = ch_eq();
5154 if (is_master() || mixbus() || !eq) {
5155 return boost::shared_ptr<AutomationControl>();
5159 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5161 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5165 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5167 return boost::shared_ptr<AutomationControl>();
5172 return boost::shared_ptr<AutomationControl>();
5176 boost::shared_ptr<AutomationControl>
5177 Route::filter_slope_controllable (bool) const
5179 return boost::shared_ptr<AutomationControl>();
5182 boost::shared_ptr<AutomationControl>
5183 Route::filter_enable_controllable (bool) const
5186 boost::shared_ptr<PluginInsert> eq = ch_eq();
5188 if (is_master() || mixbus() || !eq) {
5189 return boost::shared_ptr<AutomationControl>();
5192 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5194 return boost::shared_ptr<AutomationControl>();
5199 Route::eq_band_name (uint32_t band) const
5202 if (is_master() || mixbus()) {
5204 if (Profile->get_mixbus()) {
5206 case 0: return _("lo");
5207 case 1: return _("mid");
5208 case 2: return _("hi");
5209 default: return string();
5217 case 0: return _("lo");
5218 case 1: return _("lo mid");
5219 case 2: return _("hi mid");
5220 case 3: return _("hi");
5221 default: return string();
5227 boost::shared_ptr<AutomationControl>
5228 Route::comp_enable_controllable () const
5231 boost::shared_ptr<PluginInsert> comp = ch_comp();
5234 return boost::shared_ptr<AutomationControl>();
5237 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5239 return boost::shared_ptr<AutomationControl>();
5242 boost::shared_ptr<AutomationControl>
5243 Route::comp_threshold_controllable () const
5246 boost::shared_ptr<PluginInsert> comp = ch_comp();
5249 return boost::shared_ptr<AutomationControl>();
5252 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5255 return boost::shared_ptr<AutomationControl>();
5258 boost::shared_ptr<AutomationControl>
5259 Route::comp_speed_controllable () const
5262 boost::shared_ptr<PluginInsert> comp = ch_comp();
5265 return boost::shared_ptr<AutomationControl>();
5268 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5270 return boost::shared_ptr<AutomationControl>();
5273 boost::shared_ptr<AutomationControl>
5274 Route::comp_mode_controllable () const
5277 boost::shared_ptr<PluginInsert> comp = ch_comp();
5280 return boost::shared_ptr<AutomationControl>();
5283 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5285 return boost::shared_ptr<AutomationControl>();
5288 boost::shared_ptr<AutomationControl>
5289 Route::comp_makeup_controllable () const
5292 boost::shared_ptr<PluginInsert> comp = ch_comp();
5295 return boost::shared_ptr<AutomationControl>();
5298 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5300 return boost::shared_ptr<AutomationControl>();
5303 boost::shared_ptr<ReadOnlyControl>
5304 Route::comp_redux_controllable () const
5307 boost::shared_ptr<PluginInsert> comp = ch_comp();
5310 return boost::shared_ptr<ReadOnlyControl>();
5313 return comp->control_output (2);
5315 return comp->control_output (6);
5319 return boost::shared_ptr<ReadOnlyControl>();
5324 Route::comp_mode_name (uint32_t mode) const
5329 return _("Leveler");
5331 return _("Compressor");
5333 return _("Limiter");
5335 return mixbus() ? _("Sidechain") : _("Limiter");
5345 Route::comp_speed_name (uint32_t mode) const
5363 boost::shared_ptr<AutomationControl>
5364 Route::send_level_controllable (uint32_t n) const
5367 # undef MIXBUS_PORTS_H
5368 # include "../../gtk2_ardour/mixbus_ports.h"
5369 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5370 if (plug && !mixbus()) {
5371 uint32_t port_id = 0;
5373 case 0: port_id = port_channel_post_aux1_level; break;
5374 case 1: port_id = port_channel_post_aux2_level; break;
5375 case 2: port_id = port_channel_post_aux3_level; break;
5376 case 3: port_id = port_channel_post_aux4_level; break;
5377 case 4: port_id = port_channel_post_aux5_level; break;
5378 case 5: port_id = port_channel_post_aux6_level; break;
5379 case 6: port_id = port_channel_post_aux7_level; break;
5380 case 7: port_id = port_channel_post_aux8_level; break;
5382 case 8: port_id = port_channel_post_aux9_level; break;
5383 case 9: port_id = port_channel_post_aux10_level; break;
5384 case 10: port_id = port_channel_post_aux11_level; break;
5385 case 11: port_id = port_channel_post_aux12_level; break;
5392 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5403 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5405 return boost::shared_ptr<AutomationControl>();
5407 return s->gain_control ();
5410 boost::shared_ptr<AutomationControl>
5411 Route::send_enable_controllable (uint32_t n) const
5414 # undef MIXBUS_PORTS_H
5415 # include "../../gtk2_ardour/mixbus_ports.h"
5416 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5417 if (plug && !mixbus()) {
5418 uint32_t port_id = 0;
5420 case 0: port_id = port_channel_post_aux1_asgn; break;
5421 case 1: port_id = port_channel_post_aux2_asgn; break;
5422 case 2: port_id = port_channel_post_aux3_asgn; break;
5423 case 3: port_id = port_channel_post_aux4_asgn; break;
5424 case 4: port_id = port_channel_post_aux5_asgn; break;
5425 case 5: port_id = port_channel_post_aux6_asgn; break;
5426 case 6: port_id = port_channel_post_aux7_asgn; break;
5427 case 7: port_id = port_channel_post_aux8_asgn; break;
5429 case 8: port_id = port_channel_post_aux9_asgn; break;
5430 case 9: port_id = port_channel_post_aux10_asgn; break;
5431 case 10: port_id = port_channel_post_aux11_asgn; break;
5432 case 11: port_id = port_channel_post_aux12_asgn; break;
5439 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5450 /* although Ardour sends have enable/disable as part of the Processor
5451 * API, it is not exposed as a controllable.
5453 * XXX: we should fix this (make it click-free, automatable enable-control)
5455 return boost::shared_ptr<AutomationControl>();
5459 Route::send_name (uint32_t n) const
5462 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5463 if (plug && !mixbus()) {
5466 return _session.get_mixbus (n)->name();
5471 return _session.get_mixbus (n)->name();
5477 boost::shared_ptr<Processor> p = nth_send (n);
5485 boost::shared_ptr<AutomationControl>
5486 Route::master_send_enable_controllable () const
5489 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5491 return boost::shared_ptr<AutomationControl>();
5493 # undef MIXBUS_PORTS_H
5494 # include "../../gtk2_ardour/mixbus_ports.h"
5495 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5497 return boost::shared_ptr<AutomationControl>();
5502 Route::slaved () const
5504 if (!_gain_control) {
5507 /* just test one particular control, not all of them */
5508 return _gain_control->slaved ();
5512 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5514 if (!vca || !_gain_control) {
5518 /* just test one particular control, not all of them */
5520 return _gain_control->slaved_to (vca->gain_control());
5524 Route::muted_by_others_soloing () const
5526 if (!can_be_muted_by_others ()) {
5530 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5534 Route::clear_all_solo_state ()
5536 _solo_control->clear_all_solo_state ();
5539 boost::shared_ptr<AutomationControl>
5540 Route::automation_control_recurse (PBD::ID const & id) const
5542 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5548 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5550 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5551 if ((ac = (*i)->automation_control (id))) {
5556 return boost::shared_ptr<AutomationControl> ();
5560 Route::slavables () const
5562 SlavableControlList rv;
5563 rv.push_back (_gain_control);
5564 rv.push_back (_mute_control);
5565 rv.push_back (_solo_control);