2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/unwind.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_track.h"
41 #include "ardour/audio_port.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/boost_debug.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/plugin_insert.h"
62 #include "ardour/port.h"
63 #include "ardour/port_insert.h"
64 #include "ardour/processor.h"
65 #include "ardour/profile.h"
66 #include "ardour/route.h"
67 #include "ardour/route_group.h"
68 #include "ardour/send.h"
69 #include "ardour/session.h"
70 #include "ardour/unknown_processor.h"
71 #include "ardour/utils.h"
76 using namespace ARDOUR;
79 PBD::Signal0<void> Route::SyncOrderKeys;
80 PBD::Signal0<void> Route::RemoteControlIDChange;
81 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
83 /** Base class for all routable/mixable objects (tracks and busses) */
84 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
85 : SessionObject (sess, name)
87 , GraphNode (sess._process_graph)
90 , _signal_latency_at_amp_position (0)
91 , _signal_latency_at_trim_position (0)
94 , _pending_process_reorder (0)
95 , _pending_signals (0)
97 , _pending_declick (true)
98 , _meter_point (MeterPostFader)
99 , _pending_meter_point (MeterPostFader)
100 , _meter_type (MeterPeak)
102 , _soloed_by_others_upstream (0)
103 , _soloed_by_others_downstream (0)
104 , _solo_isolated (false)
105 , _solo_isolated_by_upstream (0)
106 , _denormal_protection (false)
109 , _declickable (false)
110 , _mute_master (new MuteMaster (sess, name))
111 , _have_internal_generator (false)
113 , _default_type (default_type)
115 , _has_order_key (false)
116 , _remote_control_id (0)
118 , _in_configure_processors (false)
119 , _initial_io_setup (false)
120 , _in_sidechain_setup (false)
122 , _custom_meter_position_noted (false)
125 processor_max_streams.reset();
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 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
144 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
145 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
147 _solo_isolate_control.reset (new SoloIsolateControllable (X_("solo-iso"), shared_from_this ()));
148 _solo_safe_control.reset (new SoloSafeControllable (X_("solo-safe"), shared_from_this ()));
150 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
151 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
152 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
154 add_control (_solo_control);
155 add_control (_mute_control);
156 add_control (_phase_control);
160 if (!(_flags & Route::MonitorOut)) {
161 _pannable.reset (new Pannable (_session));
164 /* input and output objects */
166 _input.reset (new IO (_session, _name, IO::Input, _default_type));
167 _output.reset (new IO (_session, _name, IO::Output, _default_type));
169 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
170 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
172 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
173 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
175 #if 0 // not used - just yet
176 if (!is_master() && !is_monitor() && !is_auditioner()) {
177 _delayline.reset (new DelayLine (_session, _name));
178 add_processor (_delayline, PreFader);
182 /* add amp processor */
184 _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
185 add_control (_gain_control);
187 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
188 add_processor (_amp, PostFader);
191 _amp->set_display_name (_("Monitor"));
196 _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
197 add_control (_trim_control);
199 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
200 _trim->set_display_to_user (false);
202 if (dynamic_cast<AudioTrack*>(this)) {
203 /* we can't do this in the AudioTrack's constructor
204 * because _trim does not exit then
208 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
213 /* create standard processors: meter, main outs, monitor out;
214 they will be added to _processors by setup_invisible_processors ()
217 _meter.reset (new PeakMeter (_session, _name));
218 _meter->set_owner (this);
219 _meter->set_display_to_user (false);
222 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
223 _main_outs->activate ();
226 /* where we listen to tracks */
227 _intreturn.reset (new InternalReturn (_session));
228 _intreturn->activate ();
230 /* the thing that provides proper control over a control/monitor/listen bus
231 (such as per-channel cut, dim, solo, invert, etc).
233 _monitor_control.reset (new MonitorProcessor (_session));
234 _monitor_control->activate ();
237 if (is_master() || is_monitor() || is_auditioner()) {
238 _mute_master->set_solo_ignore (true);
241 /* now that we have _meter, its safe to connect to this */
244 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
245 configure_processors (0);
253 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
255 /* do this early so that we don't get incoming signals as we are going through destruction
260 /* don't use clear_processors here, as it depends on the session which may
261 be half-destroyed by now
264 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
265 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
266 (*i)->drop_references ();
269 _processors.clear ();
273 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
275 if (Config->get_remote_model() != UserOrdered) {
279 set_remote_control_id_internal (id, notify_class_listeners);
283 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
285 /* force IDs for master/monitor busses and prevent
286 any other route from accidentally getting these IDs
287 (i.e. legacy sessions)
290 if (is_master() && id != MasterBusRemoteControlID) {
291 id = MasterBusRemoteControlID;
294 if (is_monitor() && id != MonitorBusRemoteControlID) {
295 id = MonitorBusRemoteControlID;
302 /* don't allow it to collide */
304 if (!is_master () && !is_monitor() &&
305 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
306 id += MonitorBusRemoteControlID;
309 if (id != remote_control_id()) {
310 _remote_control_id = id;
311 RemoteControlIDChanged ();
313 if (notify_class_listeners) {
314 RemoteControlIDChange ();
320 Route::remote_control_id() const
323 return MasterBusRemoteControlID;
327 return MonitorBusRemoteControlID;
330 return _remote_control_id;
334 Route::has_order_key () const
336 return _has_order_key;
340 Route::order_key () const
346 Route::set_remote_control_id_explicit (uint32_t rid)
348 if (is_master() || is_monitor() || is_auditioner()) {
349 /* hard-coded remote IDs, or no remote ID */
353 if (_remote_control_id != rid) {
354 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
355 _remote_control_id = rid;
356 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
359 /* don't emit the class-level RID signal RemoteControlIDChange here,
360 leave that to the entity that changed the order key, so that we
361 don't get lots of emissions for no good reasons (e.g. when changing
362 all route order keys).
364 See Session::sync_remote_id_from_order_keys() for the (primary|only)
365 spot where that is emitted.
370 Route::set_order_key (uint32_t n)
372 _has_order_key = true;
374 if (_order_key == n) {
380 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
381 name(), order_key ()));
383 _session.set_dirty ();
387 Route::ensure_track_or_route_name(string name, Session &session)
389 string newname = name;
391 while (!session.io_name_is_legal (newname)) {
392 newname = bump_name_once (newname, ' ');
399 Route::inc_gain (gain_t factor)
401 /* To be used ONLY when doing group-relative gain adjustment, from
405 float desired_gain = _gain_control->user_double();
407 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
408 // really?! what's the idea here?
409 _gain_control->route_set_value (0.000001f + (0.000001f * factor));
411 _gain_control->route_set_value (desired_gain + (desired_gain * factor));
416 Route::set_gain (gain_t val, Controllable::GroupControlDisposition group_override)
418 if (use_group (group_override, &RouteGroup::is_gain)) {
420 if (_route_group->is_relative()) {
422 gain_t usable_gain = _gain_control->get_value();
423 if (usable_gain < 0.000001f) {
424 usable_gain = 0.000001f;
428 if (delta < 0.000001f) {
432 delta -= usable_gain;
437 gain_t factor = delta / usable_gain;
440 factor = _route_group->get_max_factor(factor);
441 if (factor == 0.0f) {
442 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
446 factor = _route_group->get_min_factor(factor);
447 if (factor == 0.0f) {
448 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
453 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor));
457 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, Controllable::NoGroup));
463 if (val == _gain_control->get_value()) {
467 _gain_control->route_set_value (val);
471 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
473 // TODO route group, see set_gain()
474 _trim_control->route_set_value (val);
478 Route::maybe_declick (BufferSet&, framecnt_t, int)
480 /* this is the "bus" implementation and they never declick.
485 /** Process this route for one (sub) cycle (process thread)
487 * @param bufs Scratch buffers to use for the signal path
488 * @param start_frame Initial transport frame
489 * @param end_frame Final transport frame
490 * @param nframes Number of frames to output (to ports)
492 * Note that (end_frame - start_frame) may not be equal to nframes when the
493 * transport speed isn't 1.0 (eg varispeed).
496 Route::process_output_buffers (BufferSet& bufs,
497 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
498 int declick, bool gain_automation_ok)
500 /* Caller must hold process lock */
501 assert (!AudioEngine::instance()->process_lock().trylock());
503 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
505 // can this actually happen? functions calling process_output_buffers()
506 // already take a reader-lock.
507 bufs.silence (nframes, 0);
511 /* figure out if we're going to use gain automation */
512 if (gain_automation_ok) {
513 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
514 _amp->setup_gain_automation (
515 start_frame + _signal_latency_at_amp_position,
516 end_frame + _signal_latency_at_amp_position,
519 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
520 _trim->setup_gain_automation (
521 start_frame + _signal_latency_at_trim_position,
522 end_frame + _signal_latency_at_trim_position,
525 _amp->apply_gain_automation (false);
526 _trim->apply_gain_automation (false);
529 /* Tell main outs what to do about monitoring. We do this so that
530 on a transition between monitoring states we get a de-clicking gain
531 change in the _main_outs delivery, if config.get_use_monitor_fades()
534 We override this in the case where we have an internal generator.
536 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
538 _main_outs->no_outs_cuz_we_no_monitor (silence);
540 /* -------------------------------------------------------------------------------------------
541 GLOBAL DECLICK (for transport changes etc.)
542 ----------------------------------------------------------------------------------------- */
544 maybe_declick (bufs, nframes, declick);
545 _pending_declick = 0;
547 /* -------------------------------------------------------------------------------------------
548 DENORMAL CONTROL/PHASE INVERT
549 ----------------------------------------------------------------------------------------- */
551 if (_phase_invert.any ()) {
555 if (_denormal_protection || Config->get_denormal_protection()) {
557 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
558 Sample* const sp = i->data();
560 if (_phase_invert[chn]) {
561 for (pframes_t nx = 0; nx < nframes; ++nx) {
566 for (pframes_t nx = 0; nx < nframes; ++nx) {
574 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
575 Sample* const sp = i->data();
577 if (_phase_invert[chn]) {
578 for (pframes_t nx = 0; nx < nframes; ++nx) {
587 if (_denormal_protection || Config->get_denormal_protection()) {
589 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
590 Sample* const sp = i->data();
591 for (pframes_t nx = 0; nx < nframes; ++nx) {
599 /* -------------------------------------------------------------------------------------------
601 ----------------------------------------------------------------------------------------- */
603 /* set this to be true if the meter will already have been ::run() earlier */
604 bool const meter_already_run = metering_state() == MeteringInput;
606 framecnt_t latency = 0;
608 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
610 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
611 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
616 /* if it has any inputs, make sure they match */
617 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
618 if (bufs.count() != (*i)->input_streams()) {
620 DEBUG::Processors, string_compose (
621 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
622 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
629 /* should we NOT run plugins here if the route is inactive?
630 do we catch route != active somewhere higher?
633 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
634 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
637 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
638 bufs.set_count ((*i)->output_streams());
640 if ((*i)->active ()) {
641 latency += (*i)->signal_latency ();
647 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
648 boost::shared_ptr<Processor> endpoint,
649 bool include_endpoint, bool for_export, bool for_freeze)
651 /* If no processing is required, there's no need to go any further. */
652 if (!endpoint && !include_endpoint) {
656 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
657 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
658 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
660 /* trim is always at the top, for bounce no latency compensation is needed */
661 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
662 _trim->setup_gain_automation (start, start + nframes, nframes);
665 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
667 if (!include_endpoint && (*i) == endpoint) {
671 /* if we're *not* exporting, stop processing if we come across a routing processor. */
672 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
675 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
679 /* special case the panner (export outputs)
680 * Ideally we'd only run the panner, not the delivery itself...
681 * but panners need separate input/output buffers and some context
682 * (panshell, panner type, etc). AFAICT there is no ill side effect
683 * of re-using the main delivery when freewheeling/exporting a region.
685 if ((*i) == _main_outs) {
686 assert ((*i)->does_routing());
687 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
688 buffers.set_count ((*i)->output_streams());
691 /* don't run any processors that do routing.
692 * Also don't bother with metering.
694 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
695 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
696 buffers.set_count ((*i)->output_streams());
697 latency += (*i)->signal_latency ();
700 if ((*i) == endpoint) {
707 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
708 bool include_endpoint, bool for_export, bool for_freeze) const
710 framecnt_t latency = 0;
711 if (!endpoint && !include_endpoint) {
715 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
716 if (!include_endpoint && (*i) == endpoint) {
719 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
722 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
725 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
726 latency += (*i)->signal_latency ();
728 if ((*i) == endpoint) {
736 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
737 bool include_endpoint, bool for_export, bool for_freeze) const
739 if (!endpoint && !include_endpoint) {
743 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
744 if (!include_endpoint && (*i) == endpoint) {
747 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
750 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
753 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
754 cc = (*i)->output_streams();
756 if ((*i) == endpoint) {
764 Route::n_process_buffers ()
766 return max (_input->n_ports(), processor_max_streams);
770 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
772 assert (is_monitor());
773 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
774 fill_buffers_with_input (bufs, _input, nframes);
775 passthru (bufs, start_frame, end_frame, nframes, declick);
779 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
783 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
785 /* control/monitor bus ignores input ports when something is
786 feeding the listen "stream". data will "arrive" into the
787 route from the intreturn processor element.
790 bufs.silence (nframes, 0);
793 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
794 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
798 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
800 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
802 bufs.set_count (_input->n_ports());
803 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
804 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
808 Route::set_listen (bool yn, Controllable::GroupControlDisposition group_override)
814 if (use_group (group_override, &RouteGroup::is_solo)) {
815 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, Controllable::ForGroup));
820 if (yn != _monitor_send->active()) {
822 _monitor_send->activate ();
823 _mute_master->set_soloed_by_self (true);
825 _monitor_send->deactivate ();
826 _mute_master->set_soloed_by_self (false);
828 _mute_master->set_soloed_by_others (false);
830 listen_changed (group_override); /* EMIT SIGNAL */
836 Route::listening_via_monitor () const
839 return _monitor_send->active ();
846 Route::set_solo_safe (bool yn, Controllable::GroupControlDisposition /* group_override */)
848 if (_solo_safe != yn) {
850 solo_safe_changed (); /* EMIT SIGNAL */
851 _solo_safe_control->Changed(); /* EMIT SIGNAL */
856 Route::solo_safe() const
862 Route::clear_all_solo_state ()
864 // ideally this function will never do anything, it only exists to forestall Murphy
865 bool emit_changed = false;
868 // these are really debug messages, but of possible interest.
870 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
872 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
873 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
874 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
878 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
879 // if self-soled, set_solo() will do signal emission
883 _soloed_by_others_upstream = 0;
884 _soloed_by_others_downstream = 0;
887 PBD::Unwinder<bool> uw (_solo_safe, false);
888 set_solo (false, Controllable::NoGroup);
892 set_mute_master_solo ();
893 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
898 Route::set_solo (bool yn, Controllable::GroupControlDisposition group_override)
900 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, grp ? %3 currently self-soloed ? %4\n",
901 name(), yn, enum_2_string(group_override), self_soloed()));
904 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
908 if (is_master() || is_monitor() || is_auditioner()) {
909 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
913 if (use_group (group_override, &RouteGroup::is_solo)) {
914 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, Controllable::ForGroup));
918 if (self_soloed() != yn) {
920 solo_changed (true, group_override); /* EMIT SIGNAL */
921 _solo_control->Changed (); /* EMIT SIGNAL */
924 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
926 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
927 Config->get_solo_mute_overrride().
930 if (yn && Profile->get_trx()) {
931 set_mute (false, Controllable::UseGroup);
936 Route::set_self_solo (bool yn)
938 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
940 set_mute_master_solo ();
944 Route::mod_solo_by_others_upstream (int32_t delta)
946 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
947 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
949 uint32_t old_sbu = _soloed_by_others_upstream;
952 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
953 _soloed_by_others_upstream += delta;
955 _soloed_by_others_upstream = 0;
958 _soloed_by_others_upstream += delta;
961 DEBUG_TRACE (DEBUG::Solo, string_compose (
962 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
963 name(), delta, _soloed_by_others_upstream, old_sbu,
964 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
966 /* push the inverse solo change to everything that feeds us.
968 This is important for solo-within-group. When we solo 1 track out of N that
969 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
970 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
971 tracks that feed it. This will silence them if they were audible because
972 of a bus solo, but the newly soloed track will still be audible (because
975 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
979 if ((_self_solo || _soloed_by_others_downstream) &&
980 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
981 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
983 if (delta > 0 || !Config->get_exclusive_solo()) {
984 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
985 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
989 boost::shared_ptr<Route> sr = i->r.lock();
991 sr->mod_solo_by_others_downstream (-delta);
997 set_mute_master_solo ();
998 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1002 Route::mod_solo_by_others_downstream (int32_t delta)
1004 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
1005 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
1008 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
1009 _soloed_by_others_downstream += delta;
1011 _soloed_by_others_downstream = 0;
1014 _soloed_by_others_downstream += delta;
1017 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
1019 set_mute_master_solo ();
1020 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1024 Route::set_mute_master_solo ()
1026 _mute_master->set_soloed_by_self (self_soloed());
1027 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1031 Route::mod_solo_isolated_by_upstream (bool yn)
1033 bool old = solo_isolated ();
1034 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1035 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1038 if (_solo_isolated_by_upstream >= 1) {
1039 _solo_isolated_by_upstream--;
1041 _solo_isolated_by_upstream = 0;
1044 _solo_isolated_by_upstream++;
1047 if (solo_isolated() != old) {
1048 /* solo isolated status changed */
1049 _mute_master->set_solo_ignore (solo_isolated());
1050 solo_isolated_changed (); /* EMIT SIGNAL */
1055 Route::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
1057 if (is_master() || is_monitor() || is_auditioner()) {
1061 if (use_group (group_override, &RouteGroup::is_solo)) {
1062 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, Controllable::ForGroup));
1066 bool changed = false;
1069 if (_solo_isolated == false) {
1070 _mute_master->set_solo_ignore (true);
1073 _solo_isolated = true;
1075 if (_solo_isolated == true) {
1076 _solo_isolated = false;
1077 _mute_master->set_solo_ignore (false);
1087 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1089 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1090 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1092 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1097 bool does_feed = feeds (*i, &sends_only);
1099 if (does_feed && !sends_only) {
1100 (*i)->mod_solo_isolated_by_upstream (yn);
1104 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1106 solo_isolated_changed (); /* EMIT SIGNAL */
1107 _solo_isolate_control->Changed(); /* EMIT SIGNAL */
1111 Route::solo_isolated () const
1113 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1117 Route::set_mute_points (MuteMaster::MutePoint mp)
1119 _mute_master->set_mute_points (mp);
1120 mute_points_changed (); /* EMIT SIGNAL */
1122 if (_mute_master->muted_by_self()) {
1123 mute_changed (); /* EMIT SIGNAL */
1124 _mute_control->Changed (); /* EMIT SIGNAL */
1129 Route::set_mute (bool yn, Controllable::GroupControlDisposition group_override)
1131 if (use_group (group_override, &RouteGroup::is_mute)) {
1132 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, Controllable::ForGroup));
1136 if (muted() != yn) {
1137 _mute_master->set_muted_by_self (yn);
1138 /* allow any derived classes to respond to the mute change
1139 before anybody else knows about it.
1142 /* tell everyone else */
1143 mute_changed (); /* EMIT SIGNAL */
1144 _mute_control->Changed (); /* EMIT SIGNAL */
1149 Route::muted () const
1151 return _mute_master->muted_by_self();
1155 Route::muted_by_others () const
1157 // This method is only used by route_ui for display state.
1158 // The real thing is MuteMaster::muted_by_others_at()
1160 //master is never muted by others
1164 //now check to see if something is soloed (and I am not)
1165 //see also MuteMaster::mute_gain_at()
1166 return (_session.soloing() && !soloed() && !solo_isolated());
1171 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1173 cerr << name << " {" << endl;
1174 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1175 p != procs.end(); ++p) {
1176 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1178 cerr << "}" << endl;
1182 /** Supposing that we want to insert a Processor at a given Placement, return
1183 * the processor to add the new one before (or 0 to add at the end).
1185 boost::shared_ptr<Processor>
1186 Route::before_processor_for_placement (Placement p)
1188 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1190 ProcessorList::iterator loc;
1192 if (p == PreFader) {
1193 /* generic pre-fader: insert immediately before the amp */
1194 loc = find (_processors.begin(), _processors.end(), _amp);
1196 /* generic post-fader: insert right before the main outs */
1197 loc = find (_processors.begin(), _processors.end(), _main_outs);
1200 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1203 /** Supposing that we want to insert a Processor at a given index, return
1204 * the processor to add the new one before (or 0 to add at the end).
1206 boost::shared_ptr<Processor>
1207 Route::before_processor_for_index (int index)
1210 return boost::shared_ptr<Processor> ();
1213 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1215 ProcessorList::iterator i = _processors.begin ();
1217 while (i != _processors.end() && j < index) {
1218 if ((*i)->display_to_user()) {
1225 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1228 /** Add a processor either pre- or post-fader
1229 * @return 0 on success, non-0 on failure.
1232 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1234 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1238 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1239 * @param index Index to add the processor at, or -1 to add at the end of the list.
1240 * @return 0 on success, non-0 on failure.
1243 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1245 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1248 /** Add a processor to the route.
1249 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1250 * @return 0 on success, non-0 on failure.
1253 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1255 assert (processor != _meter);
1256 assert (processor != _main_outs);
1258 DEBUG_TRACE (DEBUG::Processors, string_compose (
1259 "%1 adding processor %2\n", name(), processor->name()));
1263 pl.push_back (processor);
1264 int rv = add_processors (pl, before, err);
1270 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1271 processor->activate ();
1278 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
1280 /* We cannot destruct the processor here (usually RT-thread
1281 * with various locks held - in case of sends also io_locks).
1282 * Queue for deletion in low-priority thread.
1284 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
1285 selfdestruct_sequence.push_back (wp);
1289 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1291 XMLProperty const * prop;
1294 boost::shared_ptr<Processor> processor;
1296 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1297 so that we can add the processor in the right place (pre/post-fader)
1300 XMLNodeList const & children = node.children ();
1301 XMLNodeList::const_iterator i = children.begin ();
1303 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1307 Placement placement = PreFader;
1309 if (i != children.end()) {
1310 if ((prop = (*i)->property (X_("placement"))) != 0) {
1311 placement = Placement (string_2_enum (prop->value(), placement));
1315 if (node.name() == "Insert") {
1317 if ((prop = node.property ("type")) != 0) {
1319 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1320 prop->value() == "lv2" ||
1321 prop->value() == "windows-vst" ||
1322 prop->value() == "lxvst" ||
1323 prop->value() == "audiounit") {
1325 if (_session.get_disable_all_loaded_plugins ()) {
1326 processor.reset (new UnknownProcessor (_session, node));
1328 processor.reset (new PluginInsert (_session));
1329 processor->set_owner (this);
1334 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1339 } else if (node.name() == "Send") {
1341 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1342 processor.reset (new Send (_session, sendpan, _mute_master));
1346 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1350 if (processor->set_state (node, version)) {
1354 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1355 if (i != children.end()) {
1356 if ((prop = (*i)->property (X_("active"))) != 0) {
1357 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1358 processor->activate();
1360 processor->deactivate();
1364 return (add_processor (processor, placement, 0, false) == 0);
1367 catch (failed_constructor &err) {
1368 warning << _("processor could not be created. Ignored.") << endmsg;
1374 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1375 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
1378 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1379 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
1383 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1385 ProcessorList::iterator loc;
1388 loc = find(_processors.begin(), _processors.end(), before);
1389 if (loc == _processors.end ()) {
1393 /* nothing specified - at end */
1394 loc = _processors.end ();
1397 if (!AudioEngine::instance()->connected()) {
1401 if (others.empty()) {
1405 ProcessorList to_skip;
1407 // check if there's an instrument to replace or configure
1408 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1409 boost::shared_ptr<PluginInsert> pi;
1410 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1413 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1416 boost::shared_ptr<Processor> instrument = the_instrument ();
1417 ChanCount in (DataType::MIDI, 1);
1418 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1420 PluginSetupOptions flags = None;
1422 flags |= CanReplace;
1423 in = instrument->input_streams ();
1424 out = instrument->output_streams ();
1426 if (pi->has_output_presets (in, out)) {
1430 pi->set_strict_io (_strict_io);
1432 PluginSetupOptions mask = None;
1433 if (Config->get_ask_replace_instrument ()) {
1436 if (Config->get_ask_setup_instrument ()) {
1442 if (flags != None) {
1443 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
1444 switch (rv.get_value_or (0)) {
1446 to_skip.push_back (*i); // don't add this one;
1449 replace_processor (instrument, *i, err);
1450 to_skip.push_back (*i);
1459 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1460 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1461 ProcessorState pstate (this);
1463 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1468 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1469 if (check != to_skip.end()) {
1473 boost::shared_ptr<PluginInsert> pi;
1475 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1476 pi->set_strict_io (_strict_io);
1480 /* Ensure that only one amp is in the list at any time */
1481 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1482 if (check != _processors.end()) {
1483 if (before == _amp) {
1484 /* Already in position; all is well */
1487 _processors.erase (check);
1492 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1494 _processors.insert (loc, *i);
1495 (*i)->set_owner (this);
1498 if (configure_processors_unlocked (err, &lm)) {
1500 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1505 if ((*i)->active()) {
1509 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1511 boost::shared_ptr<Send> send;
1512 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1513 send->SelfDestruct.connect_same_thread (*this,
1514 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1518 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1519 boost::shared_ptr<PluginInsert> pi;
1521 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1522 if (pi->has_no_inputs ()) {
1523 _have_internal_generator = true;
1529 _output->set_user_latency (0);
1532 reset_instrument_info ();
1533 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1534 set_processor_positions ();
1540 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1542 if (p == PreFader) {
1543 start = _processors.begin();
1544 end = find(_processors.begin(), _processors.end(), _amp);
1546 start = find(_processors.begin(), _processors.end(), _amp);
1548 end = _processors.end();
1552 /** Turn off all processors with a given placement
1553 * @param p Placement of processors to disable
1556 Route::disable_processors (Placement p)
1558 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1560 ProcessorList::iterator start, end;
1561 placement_range(p, start, end);
1563 for (ProcessorList::iterator i = start; i != end; ++i) {
1564 (*i)->deactivate ();
1567 _session.set_dirty ();
1570 /** Turn off all redirects
1573 Route::disable_processors ()
1575 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1577 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1578 (*i)->deactivate ();
1581 _session.set_dirty ();
1584 /** Turn off all redirects with a given placement
1585 * @param p Placement of redirects to disable
1588 Route::disable_plugins (Placement p)
1590 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1592 ProcessorList::iterator start, end;
1593 placement_range(p, start, end);
1595 for (ProcessorList::iterator i = start; i != end; ++i) {
1596 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1597 (*i)->deactivate ();
1601 _session.set_dirty ();
1604 /** Turn off all plugins
1607 Route::disable_plugins ()
1609 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1611 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1612 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1613 (*i)->deactivate ();
1617 _session.set_dirty ();
1622 Route::ab_plugins (bool forward)
1624 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1628 /* forward = turn off all active redirects, and mark them so that the next time
1629 we go the other way, we will revert them
1632 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1633 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1637 if ((*i)->active()) {
1638 (*i)->deactivate ();
1639 (*i)->set_next_ab_is_active (true);
1641 (*i)->set_next_ab_is_active (false);
1647 /* backward = if the redirect was marked to go active on the next ab, do so */
1649 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1651 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1655 if ((*i)->get_next_ab_is_active()) {
1658 (*i)->deactivate ();
1663 _session.set_dirty ();
1667 /** Remove processors with a given placement.
1668 * @param p Placement of processors to remove.
1671 Route::clear_processors (Placement p)
1673 if (!_session.engine().connected()) {
1677 bool already_deleting = _session.deletion_in_progress();
1678 if (!already_deleting) {
1679 _session.set_deletion_in_progress();
1683 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1684 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1685 ProcessorList new_list;
1686 ProcessorStreams err;
1687 bool seen_amp = false;
1689 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1695 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1697 /* you can't remove these */
1699 new_list.push_back (*i);
1706 new_list.push_back (*i);
1709 (*i)->drop_references ();
1717 (*i)->drop_references ();
1720 new_list.push_back (*i);
1727 _processors = new_list;
1728 configure_processors_unlocked (&err, &lm); // this can't fail
1731 processor_max_streams.reset();
1732 _have_internal_generator = false;
1733 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1734 set_processor_positions ();
1736 reset_instrument_info ();
1738 if (!already_deleting) {
1739 _session.clear_deletion_in_progress();
1744 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1746 // TODO once the export point can be configured properly, do something smarter here
1747 if (processor == _capturing_processor) {
1748 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1749 if (need_process_lock) {
1753 _capturing_processor.reset();
1755 if (need_process_lock) {
1760 /* these can never be removed */
1762 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1766 if (!_session.engine().connected()) {
1770 processor_max_streams.reset();
1773 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1774 if (need_process_lock) {
1778 /* Caller must hold process lock */
1779 assert (!AudioEngine::instance()->process_lock().trylock());
1781 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1783 ProcessorState pstate (this);
1785 ProcessorList::iterator i;
1786 bool removed = false;
1788 for (i = _processors.begin(); i != _processors.end(); ) {
1789 if (*i == processor) {
1791 /* move along, see failure case for configure_processors()
1792 where we may need to reconfigure the processor.
1795 /* stop redirects that send signals to JACK ports
1796 from causing noise as a result of no longer being
1800 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1801 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1805 iop = pi->sidechain();
1812 i = _processors.erase (i);
1820 _output->set_user_latency (0);
1828 if (configure_processors_unlocked (err, &lm)) {
1830 /* we know this will work, because it worked before :) */
1831 configure_processors_unlocked (0, &lm);
1835 _have_internal_generator = false;
1837 for (i = _processors.begin(); i != _processors.end(); ++i) {
1838 boost::shared_ptr<PluginInsert> pi;
1840 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1841 if (pi->has_no_inputs ()) {
1842 _have_internal_generator = true;
1847 if (need_process_lock) {
1852 reset_instrument_info ();
1853 processor->drop_references ();
1854 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1855 set_processor_positions ();
1861 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1863 /* these can never be removed */
1864 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1867 /* and can't be used as substitute, either */
1868 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1872 /* I/Os are out, too */
1873 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1877 /* this function cannot be used to swap/reorder processors */
1878 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1882 if (!AudioEngine::instance()->connected() || !old || !sub) {
1886 /* ensure that sub is not owned by another route */
1887 if (sub->owner ()) {
1892 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1893 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1894 ProcessorState pstate (this);
1896 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1898 ProcessorList::iterator i;
1899 bool replaced = false;
1900 bool enable = old->active ();
1902 for (i = _processors.begin(); i != _processors.end(); ) {
1904 i = _processors.erase (i);
1905 _processors.insert (i, sub);
1906 sub->set_owner (this);
1919 boost::shared_ptr<PluginInsert> pi;
1920 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1921 pi->set_strict_io (true);
1925 if (configure_processors_unlocked (err, &lm)) {
1927 configure_processors_unlocked (0, &lm);
1931 _have_internal_generator = false;
1933 for (i = _processors.begin(); i != _processors.end(); ++i) {
1934 boost::shared_ptr<PluginInsert> pi;
1935 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1936 if (pi->has_no_inputs ()) {
1937 _have_internal_generator = true;
1947 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1948 _output->set_user_latency (0);
1951 reset_instrument_info ();
1952 old->drop_references ();
1953 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1954 set_processor_positions ();
1959 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1961 ProcessorList deleted;
1963 if (!_session.engine().connected()) {
1967 processor_max_streams.reset();
1970 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1971 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1972 ProcessorState pstate (this);
1974 ProcessorList::iterator i;
1975 boost::shared_ptr<Processor> processor;
1977 for (i = _processors.begin(); i != _processors.end(); ) {
1981 /* these can never be removed */
1983 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1988 /* see if its in the list of processors to delete */
1990 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1995 /* stop IOProcessors that send to JACK ports
1996 from causing noise as a result of no longer being
2000 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
2001 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2004 iop = pi->sidechain();
2011 deleted.push_back (processor);
2012 i = _processors.erase (i);
2015 if (deleted.empty()) {
2016 /* none of those in the requested list were found */
2020 _output->set_user_latency (0);
2022 if (configure_processors_unlocked (err, &lm)) {
2024 /* we know this will work, because it worked before :) */
2025 configure_processors_unlocked (0, &lm);
2030 _have_internal_generator = false;
2032 for (i = _processors.begin(); i != _processors.end(); ++i) {
2033 boost::shared_ptr<PluginInsert> pi;
2035 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2036 if (pi->has_no_inputs ()) {
2037 _have_internal_generator = true;
2044 /* now try to do what we need to so that those that were removed will be deleted */
2046 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
2047 (*i)->drop_references ();
2050 reset_instrument_info ();
2051 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2052 set_processor_positions ();
2058 Route::reset_instrument_info ()
2060 boost::shared_ptr<Processor> instr = the_instrument();
2062 _instrument_info.set_internal_instrument (instr);
2066 /** Caller must hold process lock */
2068 Route::configure_processors (ProcessorStreams* err)
2070 #ifndef PLATFORM_WINDOWS
2071 assert (!AudioEngine::instance()->process_lock().trylock());
2074 if (!_in_configure_processors) {
2075 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2076 return configure_processors_unlocked (err, &lm);
2083 Route::input_streams () const
2085 return _input->n_ports ();
2088 list<pair<ChanCount, ChanCount> >
2089 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
2091 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2093 return try_configure_processors_unlocked (in, err);
2096 list<pair<ChanCount, ChanCount> >
2097 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
2099 // Check each processor in order to see if we can configure as requested
2101 list<pair<ChanCount, ChanCount> > configuration;
2104 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
2105 DEBUG_TRACE (DEBUG::Processors, "{\n");
2107 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
2109 if ((*p)->can_support_io_configuration(in, out)) {
2111 if (boost::dynamic_pointer_cast<Delivery> (*p)
2112 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
2113 && !(is_monitor() || is_auditioner())
2114 && ( _strict_io || Profile->get_mixbus ())) {
2115 /* with strict I/O the panner + output are forced to
2116 * follow the last processor's output.
2118 * Delivery::can_support_io_configuration() will only add ports,
2119 * but not remove excess ports.
2121 * This works because the delivery only requires
2122 * as many outputs as there are inputs.
2123 * Delivery::configure_io() will do the actual removal
2124 * by calling _output->ensure_io()
2126 if (!is_master() && _session.master_out ()) {
2127 /* ..but at least as many as there are master-inputs */
2128 // XXX this may need special-casing for mixbus (master-outputs)
2129 // and should maybe be a preference anyway ?!
2130 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
2136 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
2137 configuration.push_back(make_pair(in, out));
2140 // restriction for Monitor Section Processors
2141 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
2142 /* do not allow to add/remove channels (for now)
2143 * The Monitor follows the master-bus and has no panner (unpan)
2144 * but do allow processors with midi-in to be added (e.g VSTs with control that
2145 * will remain unconnected)
2147 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
2148 return list<pair<ChanCount, ChanCount> > ();
2150 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
2151 // internal sends make no sense, only feedback
2152 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2153 return list<pair<ChanCount, ChanCount> > ();
2155 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
2156 /* External Sends can be problematic. one can add/remove ports
2157 * there signal leaves the DAW to external monitors anyway, so there's
2158 * no real use for allowing them here anyway.
2160 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
2161 return list<pair<ChanCount, ChanCount> > ();
2163 if (boost::dynamic_pointer_cast<Send> (*p)) {
2165 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2166 return list<pair<ChanCount, ChanCount> > ();
2175 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
2176 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
2177 DEBUG_TRACE (DEBUG::Processors, "}\n");
2178 return list<pair<ChanCount, ChanCount> > ();
2182 DEBUG_TRACE (DEBUG::Processors, "}\n");
2184 return configuration;
2187 /** Set the input/output configuration of each processor in the processors list.
2188 * Caller must hold process lock.
2189 * Return 0 on success, otherwise configuration is impossible.
2192 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
2194 #ifndef PLATFORM_WINDOWS
2195 assert (!AudioEngine::instance()->process_lock().trylock());
2198 if (_in_configure_processors) {
2202 /* put invisible processors where they should be */
2203 setup_invisible_processors ();
2205 _in_configure_processors = true;
2207 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2209 if (configuration.empty ()) {
2210 _in_configure_processors = false;
2215 bool seen_mains_out = false;
2216 processor_out_streams = _input->n_ports();
2217 processor_max_streams.reset();
2219 /* processor configure_io() may result in adding ports
2220 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
2222 * with jack2 adding ports results in a graph-order callback,
2223 * which calls Session::resort_routes() and eventually
2224 * Route::direct_feeds_according_to_reality()
2225 * which takes a ReaderLock (_processor_lock).
2227 * so we can't hold a WriterLock here until jack2 threading
2230 * NB. we still hold the process lock
2232 * (ardour's own engines do call graph-order from the
2233 * process-thread and hence do not have this issue; besides
2234 * merely adding ports won't trigger a graph-order, only
2235 * making connections does)
2239 // TODO check for a potential ReaderLock after ReaderLock ??
2240 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
2242 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2243 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2245 if (!(*p)->configure_io(c->first, c->second)) {
2246 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2247 _in_configure_processors = false;
2252 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2253 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2255 boost::shared_ptr<IOProcessor> iop;
2256 boost::shared_ptr<PluginInsert> pi;
2257 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2258 /* plugins connected via Split or Hide Match may have more channels.
2259 * route/scratch buffers are needed for all of them
2260 * The configuration may only be a subset (both input and output)
2262 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
2264 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
2265 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
2266 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
2270 if (boost::dynamic_pointer_cast<Delivery> (*p)
2271 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2272 /* main delivery will increase port count to match input.
2273 * the Delivery::Main is usually the last processor - followed only by
2276 seen_mains_out = true;
2278 if (!seen_mains_out) {
2279 processor_out_streams = out;
2288 _meter->set_max_channels (processor_max_streams);
2291 /* make sure we have sufficient scratch buffers to cope with the new processor
2294 _session.ensure_buffers (n_process_buffers ());
2296 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2298 _in_configure_processors = false;
2302 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2303 * @param state New active state for those processors.
2306 Route::all_visible_processors_active (bool state)
2308 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2310 if (_processors.empty()) {
2314 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2315 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2322 (*i)->deactivate ();
2326 _session.set_dirty ();
2330 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2332 /* check if re-order requires re-configuration of any processors
2333 * -> compare channel configuration for all processors
2335 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2336 ChanCount c = input_streams ();
2338 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2340 if (c != (*j)->input_streams()) {
2343 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2346 if ((*i)->input_streams() != c) {
2349 c = (*i)->output_streams();
2361 __attribute__((annotate("realtime")))
2364 Route::apply_processor_order (const ProcessorList& new_order)
2366 /* need to hold processor_lock; either read or write lock
2367 * and the engine process_lock.
2368 * Due to r/w lock ambiguity we can only assert the latter
2370 assert (!AudioEngine::instance()->process_lock().trylock());
2373 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2374 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2375 * processors in the current actual processor list that are hidden. Any visible processors
2376 * in the current list but not in "new_order" will be assumed to be deleted.
2379 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2380 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2381 * (note though that ::processors_reorder_needs_configure() ensured that
2382 * this function will only ever be called from the rt-thread if no processor were removed)
2384 * either way, I can't proove it, but an x-run due to re-order here is less likley
2385 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2388 ProcessorList as_it_will_be;
2389 ProcessorList::iterator oiter;
2390 ProcessorList::const_iterator niter;
2392 oiter = _processors.begin();
2393 niter = new_order.begin();
2395 while (niter != new_order.end()) {
2397 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2398 then append it to the temp list.
2400 Otherwise, see if the next processor in the old list is in the new list. if not,
2401 its been deleted. If its there, append it to the temp list.
2404 if (oiter == _processors.end()) {
2406 /* no more elements in the old list, so just stick the rest of
2407 the new order onto the temp list.
2410 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2411 while (niter != new_order.end()) {
2418 if (!(*oiter)->display_to_user()) {
2420 as_it_will_be.push_back (*oiter);
2424 /* visible processor: check that its in the new order */
2426 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2427 /* deleted: do nothing, shared_ptr<> will clean up */
2429 /* ignore this one, and add the next item from the new order instead */
2430 as_it_will_be.push_back (*niter);
2435 /* now remove from old order - its taken care of no matter what */
2436 oiter = _processors.erase (oiter);
2440 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2442 /* If the meter is in a custom position, find it and make a rough note of its position */
2443 maybe_note_meter_position ();
2447 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2449 // it a change is already queued, wait for it
2450 // (unless engine is stopped. apply immediately and proceed
2451 while (g_atomic_int_get (&_pending_process_reorder)) {
2452 if (!AudioEngine::instance()->running()) {
2453 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2454 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2456 apply_processor_order(_pending_processor_order);
2457 setup_invisible_processors ();
2459 g_atomic_int_set (&_pending_process_reorder, 0);
2461 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2462 set_processor_positions ();
2464 // TODO rather use a semaphore or something.
2465 // but since ::reorder_processors() is called
2466 // from the GUI thread, this is fine..
2471 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2473 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2474 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2475 ProcessorState pstate (this);
2477 apply_processor_order (new_order);
2479 if (configure_processors_unlocked (err, &lm)) {
2487 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2488 set_processor_positions ();
2491 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2492 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2494 // _pending_processor_order is protected by _processor_lock
2495 _pending_processor_order = new_order;
2496 g_atomic_int_set (&_pending_process_reorder, 1);
2503 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2505 boost::shared_ptr<PluginInsert> pi;
2506 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2510 if (pi->has_sidechain () == add) {
2511 return true; // ?? call failed, but result is as expected.
2515 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2516 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2517 if (i == _processors.end ()) {
2523 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2524 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2525 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2527 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2529 if (!pi->add_sidechain ()) {
2533 if (!pi->del_sidechain ()) {
2539 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2544 pi->del_sidechain ();
2546 pi->add_sidechain ();
2547 // TODO restore side-chain's state.
2552 configure_processors_unlocked (0, &lm);
2555 if (pi->has_sidechain ()) {
2556 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2559 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2560 _session.set_dirty ();
2565 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2567 boost::shared_ptr<PluginInsert> pi;
2568 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2573 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2574 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2575 if (i == _processors.end ()) {
2581 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2582 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2584 const ChanCount& old (pi->preset_out ());
2585 if (!pi->set_preset_out (outs)) {
2586 return true; // no change, OK
2589 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2592 pi->set_preset_out (old);
2595 configure_processors_unlocked (0, &lm);
2598 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2599 _session.set_dirty ();
2604 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2607 return customize_plugin_insert (proc, 0, unused, unused);
2611 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2613 boost::shared_ptr<PluginInsert> pi;
2614 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2619 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2620 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2621 if (i == _processors.end ()) {
2627 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2628 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2630 bool old_cust = pi->custom_cfg ();
2631 uint32_t old_cnt = pi->get_count ();
2632 ChanCount old_chan = pi->output_streams ();
2633 ChanCount old_sinks = pi->natural_input_streams ();
2636 pi->set_custom_cfg (false);
2638 pi->set_custom_cfg (true);
2639 pi->set_count (count);
2640 pi->set_outputs (outs);
2641 pi->set_sinks (sinks);
2644 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2648 pi->set_count (old_cnt);
2649 pi->set_sinks (old_sinks);
2650 pi->set_outputs (old_chan);
2651 pi->set_custom_cfg (old_cust);
2655 configure_processors_unlocked (0, &lm);
2658 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2659 _session.set_dirty ();
2664 Route::set_strict_io (const bool enable)
2666 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2668 if (_strict_io != enable) {
2669 _strict_io = enable;
2670 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2671 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2672 boost::shared_ptr<PluginInsert> pi;
2673 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2674 pi->set_strict_io (_strict_io);
2678 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2682 _strict_io = !enable; // restore old value
2683 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2684 boost::shared_ptr<PluginInsert> pi;
2685 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2686 pi->set_strict_io (_strict_io);
2693 configure_processors (0);
2696 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2697 _session.set_dirty ();
2709 Route::get_template()
2711 return state(false);
2715 Route::state(bool full_state)
2718 if (!_session._template_state_dir.empty()) {
2719 assert (!full_state); // only for templates
2720 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2723 XMLNode *node = new XMLNode("Route");
2724 ProcessorList::iterator i;
2727 id().print (buf, sizeof (buf));
2728 node->add_property("id", buf);
2729 node->add_property ("name", _name);
2730 node->add_property("default-type", _default_type.to_string());
2731 node->add_property ("strict-io", _strict_io);
2734 node->add_property("flags", enum_2_string (_flags));
2737 node->add_property("active", _active?"yes":"no");
2739 boost::to_string (_phase_invert, p);
2740 node->add_property("phase-invert", p);
2741 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2742 node->add_property("meter-point", enum_2_string (_meter_point));
2744 node->add_property("meter-type", enum_2_string (_meter_type));
2747 node->add_property("route-group", _route_group->name());
2750 snprintf (buf, sizeof (buf), "%d", _order_key);
2751 node->add_property ("order-key", buf);
2752 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2753 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2754 node->add_property ("soloed-by-upstream", buf);
2755 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2756 node->add_property ("soloed-by-downstream", buf);
2757 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2758 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2760 node->add_child_nocopy (_input->state (full_state));
2761 node->add_child_nocopy (_output->state (full_state));
2762 node->add_child_nocopy (_solo_control->get_state ());
2763 node->add_child_nocopy (_mute_control->get_state ());
2764 node->add_child_nocopy (_mute_master->get_state ());
2767 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2770 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2771 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2772 remote_control_node->add_property (X_("id"), buf);
2773 node->add_child_nocopy (*remote_control_node);
2775 if (_comment.length()) {
2776 XMLNode *cmt = node->add_child ("Comment");
2777 cmt->add_content (_comment);
2781 node->add_child_nocopy (_pannable->state (full_state));
2784 for (i = _processors.begin(); i != _processors.end(); ++i) {
2786 /* template save: do not include internal sends functioning as
2787 aux sends because the chance of the target ID
2788 in the session where this template is used
2791 similarly, do not save listen sends which connect to
2792 the monitor section, because these will always be
2795 boost::shared_ptr<InternalSend> is;
2797 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2798 if (is->role() == Delivery::Listen) {
2803 node->add_child_nocopy((*i)->state (full_state));
2807 node->add_child_copy (*_extra_xml);
2810 if (_custom_meter_position_noted) {
2811 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2813 after->id().print (buf, sizeof (buf));
2814 node->add_property (X_("processor-after-last-custom-meter"), buf);
2818 if (!_session._template_state_dir.empty()) {
2819 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2826 Route::set_state (const XMLNode& node, int version)
2828 if (version < 3000) {
2829 return set_state_2X (node, version);
2833 XMLNodeConstIterator niter;
2835 XMLProperty const * prop;
2837 if (node.name() != "Route"){
2838 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2842 if ((prop = node.property (X_("name"))) != 0) {
2843 Route::set_name (prop->value());
2847 _initial_io_setup = true;
2849 if ((prop = node.property (X_("flags"))) != 0) {
2850 _flags = Flag (string_2_enum (prop->value(), _flags));
2855 if ((prop = node.property (X_("strict-io"))) != 0) {
2856 _strict_io = string_is_affirmative (prop->value());
2859 if (is_master() || is_monitor() || is_auditioner()) {
2860 _mute_master->set_solo_ignore (true);
2864 /* monitor bus does not get a panner, but if (re)created
2865 via XML, it will already have one by the time we
2866 call ::set_state(). so ... remove it.
2871 /* add all processors (except amp, which is always present) */
2873 nlist = node.children();
2874 XMLNode processor_state (X_("processor_state"));
2876 Stateful::save_extra_xml (node);
2878 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2882 if (child->name() == IO::state_node_name) {
2883 if ((prop = child->property (X_("direction"))) == 0) {
2887 if (prop->value() == "Input") {
2888 _input->set_state (*child, version);
2889 } else if (prop->value() == "Output") {
2890 _output->set_state (*child, version);
2894 if (child->name() == X_("Processor")) {
2895 processor_state.add_child_copy (*child);
2898 if (child->name() == X_("Pannable")) {
2900 _pannable->set_state (*child, version);
2902 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2907 if ((prop = node.property (X_("meter-point"))) != 0) {
2908 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2909 set_meter_point (mp, true);
2911 _meter->set_display_to_user (_meter_point == MeterCustom);
2915 if ((prop = node.property (X_("meter-type"))) != 0) {
2916 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2919 _initial_io_setup = false;
2921 set_processor_state (processor_state);
2923 // this looks up the internal instrument in processors
2924 reset_instrument_info();
2926 if ((prop = node.property ("self-solo")) != 0) {
2927 set_self_solo (string_is_affirmative (prop->value()));
2930 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2931 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2932 mod_solo_by_others_upstream (atoi (prop->value()));
2935 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2936 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2937 mod_solo_by_others_downstream (atoi (prop->value()));
2940 if ((prop = node.property ("solo-isolated")) != 0) {
2941 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2944 if ((prop = node.property ("solo-safe")) != 0) {
2945 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2948 if ((prop = node.property (X_("phase-invert"))) != 0) {
2949 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2952 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2953 set_denormal_protection (string_is_affirmative (prop->value()));
2956 if ((prop = node.property (X_("active"))) != 0) {
2957 bool yn = string_is_affirmative (prop->value());
2958 set_active (yn, this);
2961 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2962 set_order_key (atoi(prop->value()));
2965 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2969 string::size_type colon, equal;
2970 string remaining = prop->value();
2972 while (remaining.length()) {
2974 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2975 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2978 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2979 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2982 string keyname = remaining.substr (0, equal);
2984 if ((keyname == "EditorSort") || (keyname == "editor")) {
2985 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2991 colon = remaining.find_first_of (':');
2993 if (colon != string::npos) {
2994 remaining = remaining.substr (colon+1);
3001 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
3002 PBD::ID id (prop->value ());
3003 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3004 ProcessorList::const_iterator i = _processors.begin ();
3005 while (i != _processors.end() && (*i)->id() != id) {
3009 if (i != _processors.end ()) {
3010 _processor_after_last_custom_meter = *i;
3011 _custom_meter_position_noted = true;
3015 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3018 if (child->name() == X_("Comment")) {
3020 /* XXX this is a terrible API design in libxml++ */
3022 XMLNode *cmt = *(child->children().begin());
3023 _comment = cmt->content();
3025 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3026 if (prop->value() == "solo") {
3027 _solo_control->set_state (*child, version);
3028 } else if (prop->value() == "mute") {
3029 _mute_control->set_state (*child, version);
3032 } else if (child->name() == X_("RemoteControl")) {
3033 if ((prop = child->property (X_("id"))) != 0) {
3035 sscanf (prop->value().c_str(), "%d", &x);
3036 set_remote_control_id_internal (x);
3039 } else if (child->name() == X_("MuteMaster")) {
3040 _mute_master->set_state (*child, version);
3042 } else if (child->name() == Automatable::xml_node_name) {
3043 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
3051 Route::set_state_2X (const XMLNode& node, int version)
3055 XMLNodeConstIterator niter;
3057 XMLProperty const * prop;
3059 /* 2X things which still remain to be handled:
3065 if (node.name() != "Route") {
3066 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
3070 if ((prop = node.property (X_("flags"))) != 0) {
3071 string f = prop->value ();
3072 boost::replace_all (f, "ControlOut", "MonitorOut");
3073 _flags = Flag (string_2_enum (f, _flags));
3078 if (is_master() || is_monitor() || is_auditioner()) {
3079 _mute_master->set_solo_ignore (true);
3082 if ((prop = node.property (X_("phase-invert"))) != 0) {
3083 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
3084 if (string_is_affirmative (prop->value ())) {
3087 set_phase_invert (p);
3090 if ((prop = node.property (X_("denormal-protection"))) != 0) {
3091 set_denormal_protection (string_is_affirmative (prop->value()));
3094 if ((prop = node.property (X_("soloed"))) != 0) {
3095 bool yn = string_is_affirmative (prop->value());
3097 /* XXX force reset of solo status */
3102 if ((prop = node.property (X_("muted"))) != 0) {
3105 bool muted = string_is_affirmative (prop->value());
3111 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
3113 if (string_is_affirmative (prop->value())){
3114 mute_point = mute_point + "PreFader";
3119 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
3121 if (string_is_affirmative (prop->value())){
3124 mute_point = mute_point + ",";
3127 mute_point = mute_point + "PostFader";
3132 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
3134 if (string_is_affirmative (prop->value())){
3137 mute_point = mute_point + ",";
3140 mute_point = mute_point + "Listen";
3145 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
3147 if (string_is_affirmative (prop->value())){
3150 mute_point = mute_point + ",";
3153 mute_point = mute_point + "Main";
3157 _mute_master->set_mute_points (mute_point);
3158 _mute_master->set_muted_by_self (true);
3162 if ((prop = node.property (X_("meter-point"))) != 0) {
3163 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
3166 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
3167 don't mean the same thing.
3170 if ((prop = node.property (X_("order-keys"))) != 0) {
3174 string::size_type colon, equal;
3175 string remaining = prop->value();
3177 while (remaining.length()) {
3179 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
3180 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3183 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
3184 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3187 string keyname = remaining.substr (0, equal);
3189 if (keyname == "EditorSort" || keyname == "editor") {
3190 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
3196 colon = remaining.find_first_of (':');
3198 if (colon != string::npos) {
3199 remaining = remaining.substr (colon+1);
3208 nlist = node.children ();
3209 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3213 if (child->name() == IO::state_node_name) {
3215 /* there is a note in IO::set_state_2X() about why we have to call
3219 _input->set_state_2X (*child, version, true);
3220 _output->set_state_2X (*child, version, false);
3222 if ((prop = child->property (X_("name"))) != 0) {
3223 Route::set_name (prop->value ());
3228 if ((prop = child->property (X_("active"))) != 0) {
3229 bool yn = string_is_affirmative (prop->value());
3230 _active = !yn; // force switch
3231 set_active (yn, this);
3234 if ((prop = child->property (X_("gain"))) != 0) {
3237 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
3238 _amp->gain_control()->set_value (val, Controllable::NoGroup);
3242 /* Set up Panners in the IO */
3243 XMLNodeList io_nlist = child->children ();
3245 XMLNodeConstIterator io_niter;
3248 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
3250 io_child = *io_niter;
3252 if (io_child->name() == X_("Panner")) {
3253 _main_outs->panner_shell()->set_state(*io_child, version);
3254 } else if (io_child->name() == X_("Automation")) {
3255 /* IO's automation is for the fader */
3256 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
3262 XMLNodeList redirect_nodes;
3264 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3268 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
3269 redirect_nodes.push_back(child);
3274 set_processor_state_2X (redirect_nodes, version);
3276 Stateful::save_extra_xml (node);
3278 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3281 if (child->name() == X_("Comment")) {
3283 /* XXX this is a terrible API design in libxml++ */
3285 XMLNode *cmt = *(child->children().begin());
3286 _comment = cmt->content();
3288 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3289 if (prop->value() == X_("solo")) {
3290 _solo_control->set_state (*child, version);
3291 } else if (prop->value() == X_("mute")) {
3292 _mute_control->set_state (*child, version);
3295 } else if (child->name() == X_("RemoteControl")) {
3296 if ((prop = child->property (X_("id"))) != 0) {
3298 sscanf (prop->value().c_str(), "%d", &x);
3299 set_remote_control_id_internal (x);
3309 Route::get_processor_state ()
3311 XMLNode* root = new XMLNode (X_("redirects"));
3312 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3313 root->add_child_nocopy ((*i)->state (true));
3320 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
3322 /* We don't bother removing existing processors not in nList, as this
3323 method will only be called when creating a Route from scratch, not
3324 for undo purposes. Just put processors in at the appropriate place
3328 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
3329 add_processor_from_xml_2X (**i, version);
3334 Route::set_processor_state (const XMLNode& node)
3336 const XMLNodeList &nlist = node.children();
3337 XMLNodeConstIterator niter;
3338 ProcessorList new_order;
3339 bool must_configure = false;
3341 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3343 XMLProperty const * prop = (*niter)->property ("type");
3345 if (prop->value() == "amp") {
3346 _amp->set_state (**niter, Stateful::current_state_version);
3347 new_order.push_back (_amp);
3348 } else if (prop->value() == "trim") {
3349 _trim->set_state (**niter, Stateful::current_state_version);
3350 new_order.push_back (_trim);
3351 } else if (prop->value() == "meter") {
3352 _meter->set_state (**niter, Stateful::current_state_version);
3353 new_order.push_back (_meter);
3354 } else if (prop->value() == "delay") {
3356 _delayline->set_state (**niter, Stateful::current_state_version);
3357 new_order.push_back (_delayline);
3359 } else if (prop->value() == "main-outs") {
3360 _main_outs->set_state (**niter, Stateful::current_state_version);
3361 } else if (prop->value() == "intreturn") {
3363 _intreturn.reset (new InternalReturn (_session));
3364 must_configure = true;
3366 _intreturn->set_state (**niter, Stateful::current_state_version);
3367 } else if (is_monitor() && prop->value() == "monitor") {
3368 if (!_monitor_control) {
3369 _monitor_control.reset (new MonitorProcessor (_session));
3370 must_configure = true;
3372 _monitor_control->set_state (**niter, Stateful::current_state_version);
3373 } else if (prop->value() == "capture") {
3374 /* CapturingProcessor should never be restored, it's always
3375 added explicitly when needed */
3377 ProcessorList::iterator o;
3379 for (o = _processors.begin(); o != _processors.end(); ++o) {
3380 XMLProperty const * id_prop = (*niter)->property(X_("id"));
3381 if (id_prop && (*o)->id() == id_prop->value()) {
3382 (*o)->set_state (**niter, Stateful::current_state_version);
3383 new_order.push_back (*o);
3388 // If the processor (*niter) is not on the route then create it
3390 if (o == _processors.end()) {
3392 boost::shared_ptr<Processor> processor;
3394 if (prop->value() == "intsend") {
3396 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3398 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3399 prop->value() == "lv2" ||
3400 prop->value() == "windows-vst" ||
3401 prop->value() == "lxvst" ||
3402 prop->value() == "luaproc" ||
3403 prop->value() == "audiounit") {
3405 if (_session.get_disable_all_loaded_plugins ()) {
3406 processor.reset (new UnknownProcessor (_session, **niter));
3408 processor.reset (new PluginInsert (_session));
3409 processor->set_owner (this);
3411 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3412 pi->set_strict_io (true);
3416 } else if (prop->value() == "port") {
3418 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3420 } else if (prop->value() == "send") {
3422 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3423 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3424 send->SelfDestruct.connect_same_thread (*this,
3425 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3428 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3432 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3433 /* This processor could not be configured. Turn it into a UnknownProcessor */
3434 processor.reset (new UnknownProcessor (_session, **niter));
3437 /* subscribe to Sidechain IO changes */
3438 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3439 if (pi && pi->has_sidechain ()) {
3440 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3443 /* we have to note the monitor send here, otherwise a new one will be created
3444 and the state of this one will be lost.
3446 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3447 if (isend && isend->role() == Delivery::Listen) {
3448 _monitor_send = isend;
3451 /* it doesn't matter if invisible processors are added here, as they
3452 will be sorted out by setup_invisible_processors () shortly.
3455 new_order.push_back (processor);
3456 must_configure = true;
3462 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3463 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3464 _processors = new_order;
3466 if (must_configure) {
3467 configure_processors_unlocked (0, &lm);
3470 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3472 (*i)->set_owner (this);
3473 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3475 boost::shared_ptr<PluginInsert> pi;
3477 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3478 if (pi->has_no_inputs ()) {
3479 _have_internal_generator = true;
3486 reset_instrument_info ();
3487 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3488 set_processor_positions ();
3492 Route::curve_reallocate ()
3494 // _gain_automation_curve.finish_resize ();
3495 // _pan_automation_curve.finish_resize ();
3499 Route::silence (framecnt_t nframes)
3501 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3506 silence_unlocked (nframes);
3510 Route::silence_unlocked (framecnt_t nframes)
3512 /* Must be called with the processor lock held */
3516 _output->silence (nframes);
3518 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3519 boost::shared_ptr<PluginInsert> pi;
3521 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3522 // skip plugins, they don't need anything when we're not active
3526 (*i)->silence (nframes);
3529 if (nframes == _session.get_block_size()) {
3536 Route::add_internal_return ()
3539 _intreturn.reset (new InternalReturn (_session));
3540 add_processor (_intreturn, PreFader);
3545 Route::add_send_to_internal_return (InternalSend* send)
3547 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3549 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3550 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3553 return d->add_send (send);
3559 Route::remove_send_from_internal_return (InternalSend* send)
3561 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3563 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3564 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3567 return d->remove_send (send);
3573 Route::enable_monitor_send ()
3575 /* Caller must hold process lock */
3576 assert (!AudioEngine::instance()->process_lock().trylock());
3578 /* master never sends to monitor section via the normal mechanism */
3579 assert (!is_master ());
3580 assert (!is_monitor ());
3582 /* make sure we have one */
3583 if (!_monitor_send) {
3584 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3585 _monitor_send->set_display_to_user (false);
3589 configure_processors (0);
3592 /** Add an aux send to a route.
3593 * @param route route to send to.
3594 * @param before Processor to insert before, or 0 to insert at the end.
3597 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3599 assert (route != _session.monitor_out ());
3602 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3604 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3606 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3608 if (d && d->target_route() == route) {
3609 /* already listening via the specified IO: do nothing */
3617 boost::shared_ptr<InternalSend> listener;
3620 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3621 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3622 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3625 add_processor (listener, before);
3627 } catch (failed_constructor& err) {
3635 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3637 ProcessorStreams err;
3638 ProcessorList::iterator tmp;
3641 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3643 /* have to do this early because otherwise processor reconfig
3644 * will put _monitor_send back in the list
3647 if (route == _session.monitor_out()) {
3648 _monitor_send.reset ();
3652 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3654 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3656 if (d && d->target_route() == route) {
3658 if (remove_processor (*x, &err, false) > 0) {
3664 /* list could have been demolished while we dropped the lock
3667 if (_session.engine().connected()) {
3668 /* i/o processors cannot be removed if the engine is not running
3669 * so don't live-loop in case the engine is N/A or dies
3679 Route::set_comment (string cmt, void *src)
3683 _session.set_dirty ();
3687 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3689 FeedRecord fr (other, via_sends_only);
3691 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3693 if (!result.second) {
3695 /* already a record for "other" - make sure sends-only information is correct */
3696 if (!via_sends_only && result.first->sends_only) {
3697 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3698 frp->sends_only = false;
3702 return result.second;
3706 Route::clear_fed_by ()
3712 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3714 const FedBy& fed_by (other->fed_by());
3716 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3717 boost::shared_ptr<Route> sr = f->r.lock();
3719 if (sr && (sr.get() == this)) {
3721 if (via_sends_only) {
3722 *via_sends_only = f->sends_only;
3733 Route::all_inputs () const
3735 /* TODO, if this works as expected,
3736 * cache the IOVector and maintain it via
3737 * input_change_handler(), sidechain_change_handler() etc
3740 ios.push_back (_input);
3742 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3743 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3745 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3746 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3749 iop = pi->sidechain();
3752 if (iop != 0 && iop->input()) {
3753 ios.push_back (iop->input());
3760 Route::all_outputs () const
3763 // _output is included via Delivery
3764 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3765 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3766 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3767 if (iop != 0 && iop->output()) {
3768 ios.push_back (iop->output());
3775 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3777 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3778 if (other->all_inputs().fed_by (_output)) {
3779 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3780 if (via_send_only) {
3781 *via_send_only = false;
3787 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3789 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3791 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3792 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3795 iop = pi->sidechain();
3799 boost::shared_ptr<const IO> iop_out = iop->output();
3800 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3801 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3802 if (via_send_only) {
3803 *via_send_only = true;
3807 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3810 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3815 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3820 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3822 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3826 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3828 return _session._current_route_graph.feeds (shared_from_this (), other);
3831 /** Called from the (non-realtime) butler thread when the transport is stopped */
3833 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3835 framepos_t now = _session.transport_frame();
3838 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3840 Automatable::transport_stopped (now);
3842 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3844 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3848 (*i)->transport_stopped (now);
3852 _roll_delay = _initial_delay;
3856 Route::input_change_handler (IOChange change, void * /*src*/)
3858 if ((change.type & IOChange::ConfigurationChanged)) {
3859 /* This is called with the process lock held if change
3860 contains ConfigurationChanged
3862 configure_processors (0);
3863 _phase_invert.resize (_input->n_ports().n_audio ());
3864 io_changed (); /* EMIT SIGNAL */
3867 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3870 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3871 if (_input->connected()) {
3872 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3873 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3877 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3878 if (does_feed && !sends_only) {
3879 if ((*i)->soloed()) {
3882 if ((*i)->solo_isolated()) {
3889 int delta = sbou - _soloed_by_others_upstream;
3890 int idelta = ibou - _solo_isolated_by_upstream;
3893 PBD::warning << string_compose (
3894 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3895 _name, ibou, _solo_isolated_by_upstream, idelta)
3900 if (_soloed_by_others_upstream) {
3901 // ignore new connections (they're not propagated)
3903 mod_solo_by_others_upstream (delta);
3907 if (_solo_isolated_by_upstream) {
3908 // solo-isolate currently only propagates downstream
3910 mod_solo_isolated_by_upstream (false);
3912 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3913 // but idelta can't be smaller than -1, can it?
3914 //_solo_isolated_by_upstream = ibou;
3917 // Session::route_solo_changed does not propagate indirect solo-changes
3918 // propagate downstream to tracks
3919 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3920 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3924 bool does_feed = feeds (*i, &sends_only);
3925 if (delta <= 0 && does_feed && !sends_only) {
3926 (*i)->mod_solo_by_others_upstream (delta);
3929 if (idelta < 0 && does_feed && !sends_only) {
3930 (*i)->mod_solo_isolated_by_upstream (false);
3937 Route::output_change_handler (IOChange change, void * /*src*/)
3939 if (_initial_io_setup) {
3943 if ((change.type & IOChange::ConfigurationChanged)) {
3944 /* This is called with the process lock held if change
3945 contains ConfigurationChanged
3947 configure_processors (0);
3950 _session.reset_monitor_section();
3953 io_changed (); /* EMIT SIGNAL */
3956 if (_soloed_by_others_downstream) {
3958 /* checking all all downstream routes for
3959 * explicit of implict solo is a rather drastic measure,
3960 * ideally the input_change_handler() of the other route
3961 * would propagate the change to us.
3963 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3964 if (_output->connected()) {
3965 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3966 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3970 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3971 if (does_feed && !sends_only) {
3972 if ((*i)->soloed()) {
3979 int delta = sbod - _soloed_by_others_downstream;
3981 // do not allow new connections to change implicit solo (no propagation)
3982 mod_solo_by_others_downstream (delta);
3983 // Session::route_solo_changed() does not propagate indirect solo-changes
3984 // propagate upstream to tracks
3985 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3986 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3990 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3991 if (delta != 0 && does_feed && !sends_only) {
3992 (*i)->mod_solo_by_others_downstream (delta);
4001 Route::sidechain_change_handler (IOChange change, void* src)
4003 if (_initial_io_setup || _in_sidechain_setup) {
4007 input_change_handler (change, src);
4011 Route::pans_required () const
4013 if (n_outputs().n_audio() < 2) {
4017 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
4021 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
4023 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4029 if (n_outputs().n_total() == 0) {
4033 if (!_active || n_inputs() == ChanCount::ZERO) {
4034 silence_unlocked (nframes);
4038 if (session_state_changing) {
4039 if (_session.transport_speed() != 0.0f) {
4040 /* we're rolling but some state is changing (e.g. our diskstream contents)
4041 so we cannot use them. Be silent till this is over.
4043 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
4045 silence_unlocked (nframes);
4048 /* we're really not rolling, so we're either delivery silence or actually
4049 monitoring, both of which are safe to do while session_state_changing is true.
4053 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4055 fill_buffers_with_input (bufs, _input, nframes);
4057 if (_meter_point == MeterInput) {
4058 _meter->run (bufs, start_frame, end_frame, nframes, true);
4061 _amp->apply_gain_automation (false);
4062 _trim->apply_gain_automation (false);
4063 passthru (bufs, start_frame, end_frame, nframes, 0);
4069 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
4071 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4076 if (n_outputs().n_total() == 0) {
4080 if (!_active || n_inputs().n_total() == 0) {
4081 silence_unlocked (nframes);
4085 framepos_t unused = 0;
4087 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
4093 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4095 fill_buffers_with_input (bufs, _input, nframes);
4097 if (_meter_point == MeterInput) {
4098 _meter->run (bufs, start_frame, end_frame, nframes, true);
4101 passthru (bufs, start_frame, end_frame, nframes, declick);
4107 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
4114 Route::flush_processors ()
4116 /* XXX shouldn't really try to take this lock, since
4117 this is called from the RT audio thread.
4120 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4122 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4128 __attribute__((annotate("realtime")))
4131 Route::apply_processor_changes_rt ()
4133 int emissions = EmitNone;
4135 if (_pending_meter_point != _meter_point) {
4136 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4138 /* meters always have buffers for 'processor_max_streams'
4139 * they can be re-positioned without re-allocation */
4140 if (set_meter_point_unlocked()) {
4141 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
4143 emissions |= EmitMeterChanged;
4148 bool changed = false;
4150 if (g_atomic_int_get (&_pending_process_reorder)) {
4151 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4153 apply_processor_order (_pending_processor_order);
4154 setup_invisible_processors ();
4156 g_atomic_int_set (&_pending_process_reorder, 0);
4157 emissions |= EmitRtProcessorChange;
4161 set_processor_positions ();
4163 if (emissions != 0) {
4164 g_atomic_int_set (&_pending_signals, emissions);
4167 return (!selfdestruct_sequence.empty ());
4171 Route::emit_pending_signals ()
4173 int sig = g_atomic_int_and (&_pending_signals, 0);
4174 if (sig & EmitMeterChanged) {
4175 _meter->emit_configuration_changed();
4176 meter_change (); /* EMIT SIGNAL */
4177 if (sig & EmitMeterVisibilityChange) {
4178 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4180 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4183 if (sig & EmitRtProcessorChange) {
4184 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
4187 /* this would be a job for the butler.
4188 * Conceptually we should not take processe/processor locks here.
4189 * OTOH its more efficient (less overhead for summoning the butler and
4190 * telling her what do do) and signal emission is called
4191 * directly after the process callback, which decreases the chance
4192 * of x-runs when taking the locks.
4194 while (!selfdestruct_sequence.empty ()) {
4195 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
4196 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
4197 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
4198 selfdestruct_sequence.pop_back ();
4201 remove_processor (proc);
4207 Route::set_meter_point (MeterPoint p, bool force)
4209 if (_pending_meter_point == p && !force) {
4213 if (force || !AudioEngine::instance()->running()) {
4214 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4215 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4216 _pending_meter_point = p;
4217 _meter->emit_configuration_changed();
4218 meter_change (); /* EMIT SIGNAL */
4219 if (set_meter_point_unlocked()) {
4220 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4222 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4225 _pending_meter_point = p;
4231 __attribute__((annotate("realtime")))
4234 Route::set_meter_point_unlocked ()
4237 /* Caller must hold process and processor write lock */
4238 assert (!AudioEngine::instance()->process_lock().trylock());
4239 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4240 assert (!lm.locked ());
4243 _meter_point = _pending_meter_point;
4245 bool meter_was_visible_to_user = _meter->display_to_user ();
4247 if (!_custom_meter_position_noted) {
4248 maybe_note_meter_position ();
4251 if (_meter_point != MeterCustom) {
4253 _meter->set_display_to_user (false);
4255 setup_invisible_processors ();
4258 _meter->set_display_to_user (true);
4260 /* If we have a previous position for the custom meter, try to put it there */
4261 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
4263 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
4264 if (i != _processors.end ()) {
4265 _processors.remove (_meter);
4266 _processors.insert (i, _meter);
4268 } else {// at end, right before the mains_out/panner
4269 _processors.remove (_meter);
4270 ProcessorList::iterator main = _processors.end();
4271 _processors.insert (--main, _meter);
4275 /* Set up the meter for its new position */
4277 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4281 if (loc == _processors.begin()) {
4282 m_in = _input->n_ports();
4284 ProcessorList::iterator before = loc;
4286 m_in = (*before)->output_streams ();
4289 _meter->reflect_inputs (m_in);
4291 /* we do not need to reconfigure the processors, because the meter
4292 (a) is always ready to handle processor_max_streams
4293 (b) is always an N-in/N-out processor, and thus moving
4294 it doesn't require any changes to the other processors.
4297 /* these should really be done after releasing the lock
4298 * but all those signals are subscribed to with gui_thread()
4301 return (_meter->display_to_user() != meter_was_visible_to_user);
4305 Route::listen_position_changed ()
4308 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4309 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4310 ProcessorState pstate (this);
4312 if (configure_processors_unlocked (0, &lm)) {
4313 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4315 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4320 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4321 _session.set_dirty ();
4324 boost::shared_ptr<CapturingProcessor>
4325 Route::add_export_point()
4327 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4328 if (!_capturing_processor) {
4330 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4331 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4333 _capturing_processor.reset (new CapturingProcessor (_session));
4334 _capturing_processor->activate ();
4336 configure_processors_unlocked (0, &lw);
4340 return _capturing_processor;
4344 Route::update_signal_latency ()
4346 framecnt_t l = _output->user_latency();
4347 framecnt_t lamp = 0;
4348 bool before_amp = true;
4349 framecnt_t ltrim = 0;
4350 bool before_trim = true;
4352 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4353 if ((*i)->active ()) {
4354 l += (*i)->signal_latency ();
4359 if ((*i) == _trim) {
4370 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
4372 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
4373 _signal_latency_at_amp_position = lamp;
4374 _signal_latency_at_trim_position = ltrim;
4376 if (_signal_latency != l) {
4377 _signal_latency = l;
4378 signal_latency_changed (); /* EMIT SIGNAL */
4381 return _signal_latency;
4385 Route::set_user_latency (framecnt_t nframes)
4387 _output->set_user_latency (nframes);
4388 _session.update_latency_compensation ();
4392 Route::set_latency_compensation (framecnt_t longest_session_latency)
4394 framecnt_t old = _initial_delay;
4396 if (_signal_latency < longest_session_latency) {
4397 _initial_delay = longest_session_latency - _signal_latency;
4402 DEBUG_TRACE (DEBUG::Latency, string_compose (
4403 "%1: compensate for maximum latency of %2,"
4404 "given own latency of %3, using initial delay of %4\n",
4405 name(), longest_session_latency, _signal_latency, _initial_delay));
4407 if (_initial_delay != old) {
4408 initial_delay_changed (); /* EMIT SIGNAL */
4411 if (_session.transport_stopped()) {
4412 _roll_delay = _initial_delay;
4417 Route::set_block_size (pframes_t nframes)
4419 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4420 (*i)->set_block_size (nframes);
4423 _session.ensure_buffers (n_process_buffers ());
4427 Route::protect_automation ()
4429 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4430 (*i)->protect_automation();
4433 /** @param declick 1 to set a pending declick fade-in,
4434 * -1 to set a pending declick fade-out
4437 Route::set_pending_declick (int declick)
4440 /* this call is not allowed to turn off a pending declick */
4442 _pending_declick = declick;
4445 _pending_declick = 0;
4449 /** Shift automation forwards from a particular place, thereby inserting time.
4450 * Adds undo commands for any shifts that are performed.
4452 * @param pos Position to start shifting from.
4453 * @param frames Amount to shift forwards by.
4457 Route::shift (framepos_t pos, framecnt_t frames)
4459 /* gain automation */
4461 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4463 XMLNode &before = gc->alist()->get_state ();
4464 gc->alist()->shift (pos, frames);
4465 XMLNode &after = gc->alist()->get_state ();
4466 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4469 /* gain automation */
4471 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4473 XMLNode &before = gc->alist()->get_state ();
4474 gc->alist()->shift (pos, frames);
4475 XMLNode &after = gc->alist()->get_state ();
4476 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4479 // TODO mute automation ??
4481 /* pan automation */
4483 ControlSet::Controls& c (_pannable->controls());
4485 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4486 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4488 boost::shared_ptr<AutomationList> al = pc->alist();
4489 XMLNode& before = al->get_state ();
4490 al->shift (pos, frames);
4491 XMLNode& after = al->get_state ();
4492 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4497 /* redirect automation */
4499 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4500 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4502 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4504 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4505 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4507 boost::shared_ptr<AutomationList> al = ac->alist();
4508 XMLNode &before = al->get_state ();
4509 al->shift (pos, frames);
4510 XMLNode &after = al->get_state ();
4511 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4519 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4521 boost::shared_ptr<Processor> processor (p.lock ());
4522 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4526 pi->set_state_dir (d);
4530 Route::save_as_template (const string& path, const string& name)
4532 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4533 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4535 XMLNode& node (state (false));
4539 IO::set_name_in_state (*node.children().front(), name);
4541 tree.set_root (&node);
4543 /* return zero on success, non-zero otherwise */
4544 return !tree.write (path.c_str());
4549 Route::set_name (const string& str)
4551 if (str == name()) {
4555 string name = Route::ensure_track_or_route_name (str, _session);
4556 SessionObject::set_name (name);
4558 bool ret = (_input->set_name(name) && _output->set_name(name));
4561 /* rename the main outs. Leave other IO processors
4562 * with whatever name they already have, because its
4563 * just fine as it is (it will not contain the route
4564 * name if its a port insert, port send or port return).
4568 if (_main_outs->set_name (name)) {
4569 /* XXX returning false here is stupid because
4570 we already changed the route name.
4580 /** Set the name of a route in an XML description.
4581 * @param node XML <Route> node to set the name in.
4582 * @param name New name.
4585 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4587 node.add_property (X_("name"), name);
4589 XMLNodeList children = node.children();
4590 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4592 if ((*i)->name() == X_("IO")) {
4594 IO::set_name_in_state (**i, name);
4596 } else if ((*i)->name() == X_("Processor")) {
4598 XMLProperty const * role = (*i)->property (X_("role"));
4599 if (role && role->value() == X_("Main")) {
4600 (*i)->add_property (X_("name"), name);
4603 } else if ((*i)->name() == X_("Diskstream")) {
4605 if (rename_playlist) {
4606 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4608 (*i)->add_property (X_("name"), name);
4614 boost::shared_ptr<Send>
4615 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4617 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4619 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4620 boost::shared_ptr<InternalSend> send;
4622 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4623 if (send->target_route() == target) {
4629 return boost::shared_ptr<Send>();
4632 /** @param c Audio channel index.
4633 * @param yn true to invert phase, otherwise false.
4636 Route::set_phase_invert (uint32_t c, bool yn)
4638 if (_phase_invert[c] != yn) {
4639 _phase_invert[c] = yn;
4640 phase_invert_changed (); /* EMIT SIGNAL */
4641 _phase_control->Changed(); /* EMIT SIGNAL */
4642 _session.set_dirty ();
4647 Route::set_phase_invert (boost::dynamic_bitset<> p)
4649 if (_phase_invert != p) {
4651 phase_invert_changed (); /* EMIT SIGNAL */
4652 _session.set_dirty ();
4657 Route::phase_invert (uint32_t c) const
4659 return _phase_invert[c];
4662 boost::dynamic_bitset<>
4663 Route::phase_invert () const
4665 return _phase_invert;
4669 Route::set_denormal_protection (bool yn)
4671 if (_denormal_protection != yn) {
4672 _denormal_protection = yn;
4673 denormal_protection_changed (); /* EMIT SIGNAL */
4678 Route::denormal_protection () const
4680 return _denormal_protection;
4684 Route::set_active (bool yn, void* src)
4686 if (_session.transport_rolling()) {
4690 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4691 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4695 if (_active != yn) {
4697 _input->set_active (yn);
4698 _output->set_active (yn);
4699 active_changed (); // EMIT SIGNAL
4700 _session.set_dirty ();
4704 boost::shared_ptr<Pannable>
4705 Route::pannable() const
4710 boost::shared_ptr<Panner>
4711 Route::panner() const
4714 return _main_outs->panner_shell()->panner();
4717 boost::shared_ptr<PannerShell>
4718 Route::panner_shell() const
4720 return _main_outs->panner_shell();
4723 boost::shared_ptr<GainControl>
4724 Route::gain_control() const
4726 return _gain_control;
4729 boost::shared_ptr<GainControl>
4730 Route::trim_control() const
4732 return _trim_control;
4735 boost::shared_ptr<Route::PhaseControllable>
4736 Route::phase_control() const
4738 if (phase_invert().size()) {
4739 return _phase_control;
4741 return boost::shared_ptr<PhaseControllable>();
4745 boost::shared_ptr<AutomationControl>
4746 Route::get_control (const Evoral::Parameter& param)
4748 /* either we own the control or .... */
4750 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4754 /* maybe one of our processors does or ... */
4756 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4757 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4758 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4766 /* nobody does so we'll make a new one */
4768 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4775 boost::shared_ptr<Processor>
4776 Route::nth_plugin (uint32_t n) const
4778 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4779 ProcessorList::const_iterator i;
4781 for (i = _processors.begin(); i != _processors.end(); ++i) {
4782 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4789 return boost::shared_ptr<Processor> ();
4792 boost::shared_ptr<Processor>
4793 Route::nth_send (uint32_t n) const
4795 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4796 ProcessorList::const_iterator i;
4798 for (i = _processors.begin(); i != _processors.end(); ++i) {
4799 if (boost::dynamic_pointer_cast<Send> (*i)) {
4801 if ((*i)->name().find (_("Monitor")) == 0) {
4802 /* send to monitor section is not considered
4803 to be an accessible send.
4814 return boost::shared_ptr<Processor> ();
4818 Route::has_io_processor_named (const string& name)
4820 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4821 ProcessorList::iterator i;
4823 for (i = _processors.begin(); i != _processors.end(); ++i) {
4824 if (boost::dynamic_pointer_cast<Send> (*i) ||
4825 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4826 if ((*i)->name() == name) {
4835 MuteMaster::MutePoint
4836 Route::mute_points () const
4838 return _mute_master->mute_points ();
4842 Route::set_processor_positions ()
4844 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4846 bool had_amp = false;
4847 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4848 (*i)->set_pre_fader (!had_amp);
4855 /** Called when there is a proposed change to the input port count */
4857 Route::input_port_count_changing (ChanCount to)
4859 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4861 /* The processors cannot be configured with the new input arrangement, so
4867 /* The change is ok */
4871 /** Called when there is a proposed change to the output port count */
4873 Route::output_port_count_changing (ChanCount to)
4875 if (_strict_io && !_in_configure_processors) {
4878 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4879 if (processor_out_streams.get(*t) > to.get(*t)) {
4883 /* The change is ok */
4888 Route::unknown_processors () const
4892 if (_session.get_disable_all_loaded_plugins ()) {
4893 // Do not list "missing plugins" if they are explicitly disabled
4897 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4898 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4899 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4900 p.push_back ((*i)->name ());
4909 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4911 /* we assume that all our input ports feed all our output ports. its not
4912 universally true, but the alternative is way too corner-case to worry about.
4915 LatencyRange all_connections;
4918 all_connections.min = 0;
4919 all_connections.max = 0;
4921 all_connections.min = ~((pframes_t) 0);
4922 all_connections.max = 0;
4924 /* iterate over all "from" ports and determine the latency range for all of their
4925 connections to the "outside" (outside of this Route).
4928 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4932 p->get_connected_latency_range (range, playback);
4934 all_connections.min = min (all_connections.min, range.min);
4935 all_connections.max = max (all_connections.max, range.max);
4939 /* set the "from" port latencies to the max/min range of all their connections */
4941 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4942 p->set_private_latency_range (all_connections, playback);
4945 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4947 all_connections.min += our_latency;
4948 all_connections.max += our_latency;
4950 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4951 p->set_private_latency_range (all_connections, playback);
4954 return all_connections.max;
4958 Route::set_private_port_latencies (bool playback) const
4960 framecnt_t own_latency = 0;
4962 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4963 OR LATENCY CALLBACK.
4965 This is called (early) from the latency callback. It computes the REAL
4966 latency associated with each port and stores the result as the "private"
4967 latency of the port. A later call to Route::set_public_port_latencies()
4968 sets all ports to the same value to reflect the fact that we do latency
4969 compensation and so all signals are delayed by the same amount as they
4970 flow through ardour.
4973 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4974 if ((*i)->active ()) {
4975 own_latency += (*i)->signal_latency ();
4980 /* playback: propagate latency from "outside the route" to outputs to inputs */
4981 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4983 /* capture: propagate latency from "outside the route" to inputs to outputs */
4984 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4989 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4991 /* this is called to set the JACK-visible port latencies, which take
4992 latency compensation into account.
5001 const PortSet& ports (_input->ports());
5002 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
5003 p->set_public_latency_range (range, playback);
5008 const PortSet& ports (_output->ports());
5009 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
5010 p->set_public_latency_range (range, playback);
5015 /** Put the invisible processors in the right place in _processors.
5016 * Must be called with a writer lock on _processor_lock held.
5019 __attribute__((annotate("realtime")))
5022 Route::setup_invisible_processors ()
5025 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
5026 assert (!lm.locked ());
5030 /* too early to be doing this stuff */
5034 /* we'll build this new list here and then use it
5036 * TODO put the ProcessorList is on the stack for RT-safety.
5039 ProcessorList new_processors;
5041 /* find visible processors */
5043 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5044 if ((*i)->display_to_user ()) {
5045 new_processors.push_back (*i);
5051 ProcessorList::iterator amp = new_processors.begin ();
5052 while (amp != new_processors.end() && *amp != _amp) {
5056 assert (amp != new_processors.end ());
5058 /* and the processor after the amp */
5060 ProcessorList::iterator after_amp = amp;
5066 switch (_meter_point) {
5068 assert (!_meter->display_to_user ());
5069 new_processors.push_front (_meter);
5072 assert (!_meter->display_to_user ());
5073 new_processors.insert (amp, _meter);
5075 case MeterPostFader:
5076 /* do nothing here */
5079 /* do nothing here */
5082 /* the meter is visible, so we don't touch it here */
5089 assert (_main_outs);
5090 assert (!_main_outs->display_to_user ());
5091 new_processors.push_back (_main_outs);
5093 /* iterator for the main outs */
5095 ProcessorList::iterator main = new_processors.end();
5098 /* OUTPUT METERING */
5100 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
5101 assert (!_meter->display_to_user ());
5103 /* add the processor just before or just after the main outs */
5105 ProcessorList::iterator meter_point = main;
5107 if (_meter_point == MeterOutput) {
5110 new_processors.insert (meter_point, _meter);
5115 if (_monitor_send && !is_monitor ()) {
5116 assert (!_monitor_send->display_to_user ());
5117 switch (Config->get_listen_position ()) {
5118 case PreFaderListen:
5119 switch (Config->get_pfl_position ()) {
5120 case PFLFromBeforeProcessors:
5121 new_processors.push_front (_monitor_send);
5123 case PFLFromAfterProcessors:
5124 new_processors.insert (amp, _monitor_send);
5127 _monitor_send->set_can_pan (false);
5129 case AfterFaderListen:
5130 switch (Config->get_afl_position ()) {
5131 case AFLFromBeforeProcessors:
5132 new_processors.insert (after_amp, _monitor_send);
5134 case AFLFromAfterProcessors:
5135 new_processors.insert (new_processors.end(), _monitor_send);
5138 _monitor_send->set_can_pan (true);
5143 #if 0 // not used - just yet
5144 if (!is_master() && !is_monitor() && !is_auditioner()) {
5145 new_processors.push_front (_delayline);
5149 /* MONITOR CONTROL */
5151 if (_monitor_control && is_monitor ()) {
5152 assert (!_monitor_control->display_to_user ());
5153 new_processors.insert (amp, _monitor_control);
5156 /* INTERNAL RETURN */
5158 /* doing this here means that any monitor control will come just after
5163 assert (!_intreturn->display_to_user ());
5164 new_processors.push_front (_intreturn);
5167 if (_trim && _trim->active()) {
5168 assert (!_trim->display_to_user ());
5169 new_processors.push_front (_trim);
5171 /* EXPORT PROCESSOR */
5173 if (_capturing_processor) {
5174 assert (!_capturing_processor->display_to_user ());
5175 new_processors.push_front (_capturing_processor);
5178 _processors = new_processors;
5180 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5181 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
5186 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5187 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5188 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5195 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5196 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5200 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5201 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5208 /** If the meter point is `Custom', make a note of where the meter is.
5209 * This is so that if the meter point is subsequently set to something else,
5210 * and then back to custom, we can put the meter back where it was last time
5211 * custom was enabled.
5213 * Must be called with the _processor_lock held.
5216 Route::maybe_note_meter_position ()
5218 if (_meter_point != MeterCustom) {
5222 _custom_meter_position_noted = true;
5223 /* custom meter points range from after trim to before panner/main_outs
5224 * this is a limitation by the current processor UI
5226 bool seen_trim = false;
5227 _processor_after_last_custom_meter.reset();
5228 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5229 if ((*i) == _trim) {
5232 if ((*i) == _main_outs) {
5233 _processor_after_last_custom_meter = *i;
5236 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5238 _processor_after_last_custom_meter = _trim;
5240 ProcessorList::iterator j = i;
5242 assert(j != _processors.end ()); // main_outs should be before
5243 _processor_after_last_custom_meter = *j;
5248 assert(_processor_after_last_custom_meter.lock());
5251 boost::shared_ptr<Processor>
5252 Route::processor_by_id (PBD::ID id) const
5254 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5255 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5256 if ((*i)->id() == id) {
5261 return boost::shared_ptr<Processor> ();
5264 /** @return the monitoring state, or in other words what data we are pushing
5265 * into the route (data from the inputs, data from disk or silence)
5268 Route::monitoring_state () const
5270 return MonitoringInput;
5273 /** @return what we should be metering; either the data coming from the input
5274 * IO or the data that is flowing through the route.
5277 Route::metering_state () const
5279 return MeteringRoute;
5283 Route::has_external_redirects () const
5285 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5287 /* ignore inactive processors and obviously ignore the main
5288 * outs since everything has them and we don't care.
5291 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5299 boost::shared_ptr<Processor>
5300 Route::the_instrument () const
5302 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5303 return the_instrument_unlocked ();
5306 boost::shared_ptr<Processor>
5307 Route::the_instrument_unlocked () const
5309 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5310 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5311 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5315 return boost::shared_ptr<Processor>();
5321 Route::non_realtime_locate (framepos_t pos)
5324 _pannable->transport_located (pos);
5327 if (_delayline.get()) {
5328 _delayline.get()->flush();
5332 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5333 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5335 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5336 (*i)->transport_located (pos);
5339 _roll_delay = _initial_delay;
5343 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5350 * We don't currently mix MIDI input together, so we don't need the
5351 * complex logic of the audio case.
5354 n_buffers = bufs.count().n_midi ();
5356 for (i = 0; i < n_buffers; ++i) {
5358 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5359 MidiBuffer& buf (bufs.get_midi (i));
5362 buf.copy (source_port->get_midi_buffer(nframes));
5364 buf.silence (nframes);
5370 n_buffers = bufs.count().n_audio();
5372 size_t n_ports = io->n_ports().n_audio();
5373 float scaling = 1.0f;
5375 if (n_ports > n_buffers) {
5376 scaling = ((float) n_buffers) / n_ports;
5379 for (i = 0; i < n_ports; ++i) {
5381 /* if there are more ports than buffers, map them onto buffers
5382 * in a round-robin fashion
5385 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5386 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5389 if (i < n_buffers) {
5391 /* first time through just copy a channel into
5395 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5397 if (scaling != 1.0f) {
5398 buf.apply_gain (scaling, nframes);
5403 /* on subsequent times around, merge data from
5404 * the port with what is already there
5407 if (scaling != 1.0f) {
5408 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5410 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5415 /* silence any remaining buffers */
5417 for (; i < n_buffers; ++i) {
5418 AudioBuffer& buf (bufs.get_audio (i));
5419 buf.silence (nframes);
5422 /* establish the initial setup of the buffer set, reflecting what was
5423 copied into it. unless, of course, we are the auditioner, in which
5424 case nothing was fed into it from the inputs at all.
5427 if (!is_auditioner()) {
5428 bufs.set_count (io->n_ports());
5432 boost::shared_ptr<AutomationControl>
5433 Route::pan_azimuth_control() const
5436 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5438 return boost::shared_ptr<AutomationControl>();
5440 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5441 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5443 if (!_pannable || !panner()) {
5444 return boost::shared_ptr<AutomationControl>();
5446 return _pannable->pan_azimuth_control;
5450 boost::shared_ptr<AutomationControl>
5451 Route::pan_elevation_control() const
5453 if (Profile->get_mixbus() || !_pannable || !panner()) {
5454 return boost::shared_ptr<AutomationControl>();
5457 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5459 if (c.find (PanElevationAutomation) != c.end()) {
5460 return _pannable->pan_elevation_control;
5462 return boost::shared_ptr<AutomationControl>();
5465 boost::shared_ptr<AutomationControl>
5466 Route::pan_width_control() const
5468 if (Profile->get_mixbus() || !_pannable || !panner()) {
5469 return boost::shared_ptr<AutomationControl>();
5472 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5474 if (c.find (PanWidthAutomation) != c.end()) {
5475 return _pannable->pan_width_control;
5477 return boost::shared_ptr<AutomationControl>();
5480 boost::shared_ptr<AutomationControl>
5481 Route::pan_frontback_control() const
5483 if (Profile->get_mixbus() || !_pannable || !panner()) {
5484 return boost::shared_ptr<AutomationControl>();
5487 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5489 if (c.find (PanFrontBackAutomation) != c.end()) {
5490 return _pannable->pan_frontback_control;
5492 return boost::shared_ptr<AutomationControl>();
5495 boost::shared_ptr<AutomationControl>
5496 Route::pan_lfe_control() const
5498 if (Profile->get_mixbus() || !_pannable || !panner()) {
5499 return boost::shared_ptr<AutomationControl>();
5502 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5504 if (c.find (PanLFEAutomation) != c.end()) {
5505 return _pannable->pan_lfe_control;
5507 return boost::shared_ptr<AutomationControl>();
5512 Route::eq_band_cnt () const
5514 if (Profile->get_mixbus()) {
5517 /* Ardour has no well-known EQ object */
5522 boost::shared_ptr<AutomationControl>
5523 Route::eq_gain_controllable (uint32_t band) const
5526 boost::shared_ptr<PluginInsert> eq = ch_eq();
5529 return boost::shared_ptr<AutomationControl>();
5532 uint32_t port_number;
5535 if (is_master() || mixbus()) {
5542 if (is_master() || mixbus()) {
5549 if (is_master() || mixbus()) {
5556 return boost::shared_ptr<AutomationControl>();
5559 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5561 return boost::shared_ptr<AutomationControl>();
5564 boost::shared_ptr<AutomationControl>
5565 Route::eq_freq_controllable (uint32_t band) const
5569 if (mixbus() || is_master()) {
5570 /* no frequency controls for mixbusses or master */
5571 return boost::shared_ptr<AutomationControl>();
5574 boost::shared_ptr<PluginInsert> eq = ch_eq();
5577 return boost::shared_ptr<AutomationControl>();
5580 uint32_t port_number;
5592 return boost::shared_ptr<AutomationControl>();
5595 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5597 return boost::shared_ptr<AutomationControl>();
5601 boost::shared_ptr<AutomationControl>
5602 Route::eq_q_controllable (uint32_t band) const
5604 return boost::shared_ptr<AutomationControl>();
5607 boost::shared_ptr<AutomationControl>
5608 Route::eq_shape_controllable (uint32_t band) const
5610 return boost::shared_ptr<AutomationControl>();
5613 boost::shared_ptr<AutomationControl>
5614 Route::eq_enable_controllable () const
5617 boost::shared_ptr<PluginInsert> eq = ch_eq();
5620 return boost::shared_ptr<AutomationControl>();
5623 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5625 return boost::shared_ptr<AutomationControl>();
5629 boost::shared_ptr<AutomationControl>
5630 Route::eq_hpf_controllable () const
5633 boost::shared_ptr<PluginInsert> eq = ch_eq();
5636 return boost::shared_ptr<AutomationControl>();
5639 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5641 return boost::shared_ptr<AutomationControl>();
5646 Route::eq_band_name (uint32_t band) const
5648 if (Profile->get_mixbus()) {
5664 boost::shared_ptr<AutomationControl>
5665 Route::comp_enable_controllable () const
5668 boost::shared_ptr<PluginInsert> comp = ch_comp();
5671 return boost::shared_ptr<AutomationControl>();
5674 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5676 return boost::shared_ptr<AutomationControl>();
5679 boost::shared_ptr<AutomationControl>
5680 Route::comp_threshold_controllable () const
5683 boost::shared_ptr<PluginInsert> comp = ch_comp();
5686 return boost::shared_ptr<AutomationControl>();
5689 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5692 return boost::shared_ptr<AutomationControl>();
5695 boost::shared_ptr<AutomationControl>
5696 Route::comp_speed_controllable () const
5699 boost::shared_ptr<PluginInsert> comp = ch_comp();
5702 return boost::shared_ptr<AutomationControl>();
5705 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5707 return boost::shared_ptr<AutomationControl>();
5710 boost::shared_ptr<AutomationControl>
5711 Route::comp_mode_controllable () const
5714 boost::shared_ptr<PluginInsert> comp = ch_comp();
5717 return boost::shared_ptr<AutomationControl>();
5720 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5722 return boost::shared_ptr<AutomationControl>();
5725 boost::shared_ptr<AutomationControl>
5726 Route::comp_makeup_controllable () const
5729 boost::shared_ptr<PluginInsert> comp = ch_comp();
5732 return boost::shared_ptr<AutomationControl>();
5735 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5737 return boost::shared_ptr<AutomationControl>();
5740 boost::shared_ptr<AutomationControl>
5741 Route::comp_redux_controllable () const
5744 boost::shared_ptr<PluginInsert> comp = ch_comp();
5747 return boost::shared_ptr<AutomationControl>();
5750 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5752 return boost::shared_ptr<AutomationControl>();
5757 Route::comp_mode_name (uint32_t mode) const
5762 return _("Leveler");
5764 return _("Compressor");
5766 return _("Limiter");
5768 return mixbus() ? _("Sidechain") : _("Limiter");
5778 Route::comp_speed_name (uint32_t mode) const
5796 boost::shared_ptr<AutomationControl>
5797 Route::send_level_controllable (uint32_t n) const
5800 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5802 return boost::shared_ptr<AutomationControl>();
5807 return boost::shared_ptr<AutomationControl>();
5810 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5811 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5813 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5815 return boost::shared_ptr<AutomationControl>();
5817 return s->gain_control ();
5821 boost::shared_ptr<AutomationControl>
5822 Route::send_enable_controllable (uint32_t n) const
5825 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5827 return boost::shared_ptr<AutomationControl>();
5832 return boost::shared_ptr<AutomationControl>();
5835 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5836 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5838 /* although Ardour sends have enable/disable as part of the Processor
5839 API, it is not exposed as a controllable.
5841 XXX: we should fix this.
5843 return boost::shared_ptr<AutomationControl>();
5848 Route::send_name (uint32_t n) const
5854 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5858 boost::shared_ptr<Processor> p = nth_send (n);
5867 boost::shared_ptr<AutomationControl>
5868 Route::master_send_enable_controllable () const
5871 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5873 return boost::shared_ptr<AutomationControl>();
5875 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5877 return boost::shared_ptr<AutomationControl>();