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));
2785 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2786 for (i = _processors.begin(); i != _processors.end(); ++i) {
2788 /* template save: do not include internal sends functioning as
2789 aux sends because the chance of the target ID
2790 in the session where this template is used
2793 similarly, do not save listen sends which connect to
2794 the monitor section, because these will always be
2797 boost::shared_ptr<InternalSend> is;
2799 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2800 if (is->role() == Delivery::Listen) {
2805 node->add_child_nocopy((*i)->state (full_state));
2810 node->add_child_copy (*_extra_xml);
2813 if (_custom_meter_position_noted) {
2814 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2816 after->id().print (buf, sizeof (buf));
2817 node->add_property (X_("processor-after-last-custom-meter"), buf);
2821 if (!_session._template_state_dir.empty()) {
2822 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2829 Route::set_state (const XMLNode& node, int version)
2831 if (version < 3000) {
2832 return set_state_2X (node, version);
2836 XMLNodeConstIterator niter;
2838 XMLProperty const * prop;
2840 if (node.name() != "Route"){
2841 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2845 if ((prop = node.property (X_("name"))) != 0) {
2846 Route::set_name (prop->value());
2850 _initial_io_setup = true;
2852 if ((prop = node.property (X_("flags"))) != 0) {
2853 _flags = Flag (string_2_enum (prop->value(), _flags));
2858 if ((prop = node.property (X_("strict-io"))) != 0) {
2859 _strict_io = string_is_affirmative (prop->value());
2862 if (is_master() || is_monitor() || is_auditioner()) {
2863 _mute_master->set_solo_ignore (true);
2867 /* monitor bus does not get a panner, but if (re)created
2868 via XML, it will already have one by the time we
2869 call ::set_state(). so ... remove it.
2874 /* add all processors (except amp, which is always present) */
2876 nlist = node.children();
2877 XMLNode processor_state (X_("processor_state"));
2879 Stateful::save_extra_xml (node);
2881 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2885 if (child->name() == IO::state_node_name) {
2886 if ((prop = child->property (X_("direction"))) == 0) {
2890 if (prop->value() == "Input") {
2891 _input->set_state (*child, version);
2892 } else if (prop->value() == "Output") {
2893 _output->set_state (*child, version);
2897 if (child->name() == X_("Processor")) {
2898 processor_state.add_child_copy (*child);
2901 if (child->name() == X_("Pannable")) {
2903 _pannable->set_state (*child, version);
2905 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2910 if ((prop = node.property (X_("meter-point"))) != 0) {
2911 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2912 set_meter_point (mp, true);
2914 _meter->set_display_to_user (_meter_point == MeterCustom);
2918 if ((prop = node.property (X_("meter-type"))) != 0) {
2919 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2922 _initial_io_setup = false;
2924 set_processor_state (processor_state);
2926 // this looks up the internal instrument in processors
2927 reset_instrument_info();
2929 if ((prop = node.property ("self-solo")) != 0) {
2930 set_self_solo (string_is_affirmative (prop->value()));
2933 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2934 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2935 mod_solo_by_others_upstream (atoi (prop->value()));
2938 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2939 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2940 mod_solo_by_others_downstream (atoi (prop->value()));
2943 if ((prop = node.property ("solo-isolated")) != 0) {
2944 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2947 if ((prop = node.property ("solo-safe")) != 0) {
2948 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2951 if ((prop = node.property (X_("phase-invert"))) != 0) {
2952 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2955 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2956 set_denormal_protection (string_is_affirmative (prop->value()));
2959 if ((prop = node.property (X_("active"))) != 0) {
2960 bool yn = string_is_affirmative (prop->value());
2961 set_active (yn, this);
2964 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2965 set_order_key (atoi(prop->value()));
2968 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2972 string::size_type colon, equal;
2973 string remaining = prop->value();
2975 while (remaining.length()) {
2977 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2978 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2981 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2982 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2985 string keyname = remaining.substr (0, equal);
2987 if ((keyname == "EditorSort") || (keyname == "editor")) {
2988 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2994 colon = remaining.find_first_of (':');
2996 if (colon != string::npos) {
2997 remaining = remaining.substr (colon+1);
3004 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
3005 PBD::ID id (prop->value ());
3006 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3007 ProcessorList::const_iterator i = _processors.begin ();
3008 while (i != _processors.end() && (*i)->id() != id) {
3012 if (i != _processors.end ()) {
3013 _processor_after_last_custom_meter = *i;
3014 _custom_meter_position_noted = true;
3018 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3021 if (child->name() == X_("Comment")) {
3023 /* XXX this is a terrible API design in libxml++ */
3025 XMLNode *cmt = *(child->children().begin());
3026 _comment = cmt->content();
3028 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3029 if (prop->value() == "solo") {
3030 _solo_control->set_state (*child, version);
3031 } else if (prop->value() == "mute") {
3032 _mute_control->set_state (*child, version);
3035 } else if (child->name() == X_("RemoteControl")) {
3036 if ((prop = child->property (X_("id"))) != 0) {
3038 sscanf (prop->value().c_str(), "%d", &x);
3039 set_remote_control_id_internal (x);
3042 } else if (child->name() == X_("MuteMaster")) {
3043 _mute_master->set_state (*child, version);
3045 } else if (child->name() == Automatable::xml_node_name) {
3046 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
3054 Route::set_state_2X (const XMLNode& node, int version)
3058 XMLNodeConstIterator niter;
3060 XMLProperty const * prop;
3062 /* 2X things which still remain to be handled:
3068 if (node.name() != "Route") {
3069 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
3073 if ((prop = node.property (X_("flags"))) != 0) {
3074 string f = prop->value ();
3075 boost::replace_all (f, "ControlOut", "MonitorOut");
3076 _flags = Flag (string_2_enum (f, _flags));
3081 if (is_master() || is_monitor() || is_auditioner()) {
3082 _mute_master->set_solo_ignore (true);
3085 if ((prop = node.property (X_("phase-invert"))) != 0) {
3086 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
3087 if (string_is_affirmative (prop->value ())) {
3090 set_phase_invert (p);
3093 if ((prop = node.property (X_("denormal-protection"))) != 0) {
3094 set_denormal_protection (string_is_affirmative (prop->value()));
3097 if ((prop = node.property (X_("soloed"))) != 0) {
3098 bool yn = string_is_affirmative (prop->value());
3100 /* XXX force reset of solo status */
3105 if ((prop = node.property (X_("muted"))) != 0) {
3108 bool muted = string_is_affirmative (prop->value());
3114 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
3116 if (string_is_affirmative (prop->value())){
3117 mute_point = mute_point + "PreFader";
3122 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
3124 if (string_is_affirmative (prop->value())){
3127 mute_point = mute_point + ",";
3130 mute_point = mute_point + "PostFader";
3135 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
3137 if (string_is_affirmative (prop->value())){
3140 mute_point = mute_point + ",";
3143 mute_point = mute_point + "Listen";
3148 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
3150 if (string_is_affirmative (prop->value())){
3153 mute_point = mute_point + ",";
3156 mute_point = mute_point + "Main";
3160 _mute_master->set_mute_points (mute_point);
3161 _mute_master->set_muted_by_self (true);
3165 if ((prop = node.property (X_("meter-point"))) != 0) {
3166 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
3169 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
3170 don't mean the same thing.
3173 if ((prop = node.property (X_("order-keys"))) != 0) {
3177 string::size_type colon, equal;
3178 string remaining = prop->value();
3180 while (remaining.length()) {
3182 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
3183 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3186 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
3187 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3190 string keyname = remaining.substr (0, equal);
3192 if (keyname == "EditorSort" || keyname == "editor") {
3193 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
3199 colon = remaining.find_first_of (':');
3201 if (colon != string::npos) {
3202 remaining = remaining.substr (colon+1);
3211 nlist = node.children ();
3212 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3216 if (child->name() == IO::state_node_name) {
3218 /* there is a note in IO::set_state_2X() about why we have to call
3222 _input->set_state_2X (*child, version, true);
3223 _output->set_state_2X (*child, version, false);
3225 if ((prop = child->property (X_("name"))) != 0) {
3226 Route::set_name (prop->value ());
3231 if ((prop = child->property (X_("active"))) != 0) {
3232 bool yn = string_is_affirmative (prop->value());
3233 _active = !yn; // force switch
3234 set_active (yn, this);
3237 if ((prop = child->property (X_("gain"))) != 0) {
3240 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
3241 _amp->gain_control()->set_value (val, Controllable::NoGroup);
3245 /* Set up Panners in the IO */
3246 XMLNodeList io_nlist = child->children ();
3248 XMLNodeConstIterator io_niter;
3251 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
3253 io_child = *io_niter;
3255 if (io_child->name() == X_("Panner")) {
3256 _main_outs->panner_shell()->set_state(*io_child, version);
3257 } else if (io_child->name() == X_("Automation")) {
3258 /* IO's automation is for the fader */
3259 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
3265 XMLNodeList redirect_nodes;
3267 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3271 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
3272 redirect_nodes.push_back(child);
3277 set_processor_state_2X (redirect_nodes, version);
3279 Stateful::save_extra_xml (node);
3281 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3284 if (child->name() == X_("Comment")) {
3286 /* XXX this is a terrible API design in libxml++ */
3288 XMLNode *cmt = *(child->children().begin());
3289 _comment = cmt->content();
3291 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3292 if (prop->value() == X_("solo")) {
3293 _solo_control->set_state (*child, version);
3294 } else if (prop->value() == X_("mute")) {
3295 _mute_control->set_state (*child, version);
3298 } else if (child->name() == X_("RemoteControl")) {
3299 if ((prop = child->property (X_("id"))) != 0) {
3301 sscanf (prop->value().c_str(), "%d", &x);
3302 set_remote_control_id_internal (x);
3312 Route::get_processor_state ()
3314 XMLNode* root = new XMLNode (X_("redirects"));
3315 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3316 root->add_child_nocopy ((*i)->state (true));
3323 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
3325 /* We don't bother removing existing processors not in nList, as this
3326 method will only be called when creating a Route from scratch, not
3327 for undo purposes. Just put processors in at the appropriate place
3331 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
3332 add_processor_from_xml_2X (**i, version);
3337 Route::set_processor_state (const XMLNode& node)
3339 const XMLNodeList &nlist = node.children();
3340 XMLNodeConstIterator niter;
3341 ProcessorList new_order;
3342 bool must_configure = false;
3344 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3346 XMLProperty const * prop = (*niter)->property ("type");
3348 if (prop->value() == "amp") {
3349 _amp->set_state (**niter, Stateful::current_state_version);
3350 new_order.push_back (_amp);
3351 } else if (prop->value() == "trim") {
3352 _trim->set_state (**niter, Stateful::current_state_version);
3353 new_order.push_back (_trim);
3354 } else if (prop->value() == "meter") {
3355 _meter->set_state (**niter, Stateful::current_state_version);
3356 new_order.push_back (_meter);
3357 } else if (prop->value() == "delay") {
3359 _delayline->set_state (**niter, Stateful::current_state_version);
3360 new_order.push_back (_delayline);
3362 } else if (prop->value() == "main-outs") {
3363 _main_outs->set_state (**niter, Stateful::current_state_version);
3364 } else if (prop->value() == "intreturn") {
3366 _intreturn.reset (new InternalReturn (_session));
3367 must_configure = true;
3369 _intreturn->set_state (**niter, Stateful::current_state_version);
3370 } else if (is_monitor() && prop->value() == "monitor") {
3371 if (!_monitor_control) {
3372 _monitor_control.reset (new MonitorProcessor (_session));
3373 must_configure = true;
3375 _monitor_control->set_state (**niter, Stateful::current_state_version);
3376 } else if (prop->value() == "capture") {
3377 /* CapturingProcessor should never be restored, it's always
3378 added explicitly when needed */
3380 ProcessorList::iterator o;
3382 for (o = _processors.begin(); o != _processors.end(); ++o) {
3383 XMLProperty const * id_prop = (*niter)->property(X_("id"));
3384 if (id_prop && (*o)->id() == id_prop->value()) {
3385 (*o)->set_state (**niter, Stateful::current_state_version);
3386 new_order.push_back (*o);
3391 // If the processor (*niter) is not on the route then create it
3393 if (o == _processors.end()) {
3395 boost::shared_ptr<Processor> processor;
3397 if (prop->value() == "intsend") {
3399 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3401 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3402 prop->value() == "lv2" ||
3403 prop->value() == "windows-vst" ||
3404 prop->value() == "lxvst" ||
3405 prop->value() == "luaproc" ||
3406 prop->value() == "audiounit") {
3408 if (_session.get_disable_all_loaded_plugins ()) {
3409 processor.reset (new UnknownProcessor (_session, **niter));
3411 processor.reset (new PluginInsert (_session));
3412 processor->set_owner (this);
3414 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3415 pi->set_strict_io (true);
3419 } else if (prop->value() == "port") {
3421 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3423 } else if (prop->value() == "send") {
3425 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3426 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3427 send->SelfDestruct.connect_same_thread (*this,
3428 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3431 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3435 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3436 /* This processor could not be configured. Turn it into a UnknownProcessor */
3437 processor.reset (new UnknownProcessor (_session, **niter));
3440 /* subscribe to Sidechain IO changes */
3441 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3442 if (pi && pi->has_sidechain ()) {
3443 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3446 /* we have to note the monitor send here, otherwise a new one will be created
3447 and the state of this one will be lost.
3449 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3450 if (isend && isend->role() == Delivery::Listen) {
3451 _monitor_send = isend;
3454 /* it doesn't matter if invisible processors are added here, as they
3455 will be sorted out by setup_invisible_processors () shortly.
3458 new_order.push_back (processor);
3459 must_configure = true;
3465 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3466 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3467 _processors = new_order;
3469 if (must_configure) {
3470 configure_processors_unlocked (0, &lm);
3473 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3475 (*i)->set_owner (this);
3476 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3478 boost::shared_ptr<PluginInsert> pi;
3480 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3481 if (pi->has_no_inputs ()) {
3482 _have_internal_generator = true;
3489 reset_instrument_info ();
3490 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3491 set_processor_positions ();
3495 Route::curve_reallocate ()
3497 // _gain_automation_curve.finish_resize ();
3498 // _pan_automation_curve.finish_resize ();
3502 Route::silence (framecnt_t nframes)
3504 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3509 silence_unlocked (nframes);
3513 Route::silence_unlocked (framecnt_t nframes)
3515 /* Must be called with the processor lock held */
3519 _output->silence (nframes);
3521 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3522 boost::shared_ptr<PluginInsert> pi;
3524 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3525 // skip plugins, they don't need anything when we're not active
3529 (*i)->silence (nframes);
3532 if (nframes == _session.get_block_size()) {
3539 Route::add_internal_return ()
3542 _intreturn.reset (new InternalReturn (_session));
3543 add_processor (_intreturn, PreFader);
3548 Route::add_send_to_internal_return (InternalSend* send)
3550 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3552 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3553 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3556 return d->add_send (send);
3562 Route::remove_send_from_internal_return (InternalSend* send)
3564 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3566 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3567 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3570 return d->remove_send (send);
3576 Route::enable_monitor_send ()
3578 /* Caller must hold process lock */
3579 assert (!AudioEngine::instance()->process_lock().trylock());
3581 /* master never sends to monitor section via the normal mechanism */
3582 assert (!is_master ());
3583 assert (!is_monitor ());
3585 /* make sure we have one */
3586 if (!_monitor_send) {
3587 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3588 _monitor_send->set_display_to_user (false);
3592 configure_processors (0);
3595 /** Add an aux send to a route.
3596 * @param route route to send to.
3597 * @param before Processor to insert before, or 0 to insert at the end.
3600 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3602 assert (route != _session.monitor_out ());
3605 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3607 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3609 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3611 if (d && d->target_route() == route) {
3612 /* already listening via the specified IO: do nothing */
3620 boost::shared_ptr<InternalSend> listener;
3623 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3624 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3625 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3628 add_processor (listener, before);
3630 } catch (failed_constructor& err) {
3638 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3640 ProcessorStreams err;
3641 ProcessorList::iterator tmp;
3644 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3646 /* have to do this early because otherwise processor reconfig
3647 * will put _monitor_send back in the list
3650 if (route == _session.monitor_out()) {
3651 _monitor_send.reset ();
3655 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3657 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3659 if (d && d->target_route() == route) {
3661 if (remove_processor (*x, &err, false) > 0) {
3667 /* list could have been demolished while we dropped the lock
3670 if (_session.engine().connected()) {
3671 /* i/o processors cannot be removed if the engine is not running
3672 * so don't live-loop in case the engine is N/A or dies
3682 Route::set_comment (string cmt, void *src)
3686 _session.set_dirty ();
3690 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3692 FeedRecord fr (other, via_sends_only);
3694 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3696 if (!result.second) {
3698 /* already a record for "other" - make sure sends-only information is correct */
3699 if (!via_sends_only && result.first->sends_only) {
3700 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3701 frp->sends_only = false;
3705 return result.second;
3709 Route::clear_fed_by ()
3715 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3717 const FedBy& fed_by (other->fed_by());
3719 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3720 boost::shared_ptr<Route> sr = f->r.lock();
3722 if (sr && (sr.get() == this)) {
3724 if (via_sends_only) {
3725 *via_sends_only = f->sends_only;
3736 Route::all_inputs () const
3738 /* TODO, if this works as expected,
3739 * cache the IOVector and maintain it via
3740 * input_change_handler(), sidechain_change_handler() etc
3743 ios.push_back (_input);
3745 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3746 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3748 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3749 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3752 iop = pi->sidechain();
3755 if (iop != 0 && iop->input()) {
3756 ios.push_back (iop->input());
3763 Route::all_outputs () const
3766 // _output is included via Delivery
3767 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3768 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3769 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3770 if (iop != 0 && iop->output()) {
3771 ios.push_back (iop->output());
3778 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3780 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3781 if (other->all_inputs().fed_by (_output)) {
3782 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3783 if (via_send_only) {
3784 *via_send_only = false;
3790 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3792 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3794 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3795 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3798 iop = pi->sidechain();
3802 boost::shared_ptr<const IO> iop_out = iop->output();
3803 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3804 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3805 if (via_send_only) {
3806 *via_send_only = true;
3810 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3813 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3818 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3823 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3825 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3829 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3831 return _session._current_route_graph.feeds (shared_from_this (), other);
3834 /** Called from the (non-realtime) butler thread when the transport is stopped */
3836 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3838 framepos_t now = _session.transport_frame();
3841 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3843 Automatable::transport_stopped (now);
3845 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3847 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3851 (*i)->transport_stopped (now);
3855 _roll_delay = _initial_delay;
3859 Route::input_change_handler (IOChange change, void * /*src*/)
3861 if ((change.type & IOChange::ConfigurationChanged)) {
3862 /* This is called with the process lock held if change
3863 contains ConfigurationChanged
3865 configure_processors (0);
3866 _phase_invert.resize (_input->n_ports().n_audio ());
3867 io_changed (); /* EMIT SIGNAL */
3870 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3873 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3874 if (_input->connected()) {
3875 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3876 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3880 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3881 if (does_feed && !sends_only) {
3882 if ((*i)->soloed()) {
3885 if ((*i)->solo_isolated()) {
3892 int delta = sbou - _soloed_by_others_upstream;
3893 int idelta = ibou - _solo_isolated_by_upstream;
3896 PBD::warning << string_compose (
3897 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3898 _name, ibou, _solo_isolated_by_upstream, idelta)
3903 if (_soloed_by_others_upstream) {
3904 // ignore new connections (they're not propagated)
3906 mod_solo_by_others_upstream (delta);
3910 if (_solo_isolated_by_upstream) {
3911 // solo-isolate currently only propagates downstream
3913 mod_solo_isolated_by_upstream (false);
3915 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3916 // but idelta can't be smaller than -1, can it?
3917 //_solo_isolated_by_upstream = ibou;
3920 // Session::route_solo_changed does not propagate indirect solo-changes
3921 // propagate downstream to tracks
3922 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3923 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3927 bool does_feed = feeds (*i, &sends_only);
3928 if (delta <= 0 && does_feed && !sends_only) {
3929 (*i)->mod_solo_by_others_upstream (delta);
3932 if (idelta < 0 && does_feed && !sends_only) {
3933 (*i)->mod_solo_isolated_by_upstream (false);
3940 Route::output_change_handler (IOChange change, void * /*src*/)
3942 if (_initial_io_setup) {
3946 if ((change.type & IOChange::ConfigurationChanged)) {
3947 /* This is called with the process lock held if change
3948 contains ConfigurationChanged
3950 configure_processors (0);
3953 _session.reset_monitor_section();
3956 io_changed (); /* EMIT SIGNAL */
3959 if (_soloed_by_others_downstream) {
3961 /* checking all all downstream routes for
3962 * explicit of implict solo is a rather drastic measure,
3963 * ideally the input_change_handler() of the other route
3964 * would propagate the change to us.
3966 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3967 if (_output->connected()) {
3968 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3969 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3973 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3974 if (does_feed && !sends_only) {
3975 if ((*i)->soloed()) {
3982 int delta = sbod - _soloed_by_others_downstream;
3984 // do not allow new connections to change implicit solo (no propagation)
3985 mod_solo_by_others_downstream (delta);
3986 // Session::route_solo_changed() does not propagate indirect solo-changes
3987 // propagate upstream to tracks
3988 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3989 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3993 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3994 if (delta != 0 && does_feed && !sends_only) {
3995 (*i)->mod_solo_by_others_downstream (delta);
4004 Route::sidechain_change_handler (IOChange change, void* src)
4006 if (_initial_io_setup || _in_sidechain_setup) {
4010 input_change_handler (change, src);
4014 Route::pans_required () const
4016 if (n_outputs().n_audio() < 2) {
4020 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
4024 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
4026 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4032 if (n_outputs().n_total() == 0) {
4036 if (!_active || n_inputs() == ChanCount::ZERO) {
4037 silence_unlocked (nframes);
4041 if (session_state_changing) {
4042 if (_session.transport_speed() != 0.0f) {
4043 /* we're rolling but some state is changing (e.g. our diskstream contents)
4044 so we cannot use them. Be silent till this is over.
4046 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
4048 silence_unlocked (nframes);
4051 /* we're really not rolling, so we're either delivery silence or actually
4052 monitoring, both of which are safe to do while session_state_changing is true.
4056 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4058 fill_buffers_with_input (bufs, _input, nframes);
4060 if (_meter_point == MeterInput) {
4061 _meter->run (bufs, start_frame, end_frame, nframes, true);
4064 _amp->apply_gain_automation (false);
4065 _trim->apply_gain_automation (false);
4066 passthru (bufs, start_frame, end_frame, nframes, 0);
4072 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
4074 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4079 if (n_outputs().n_total() == 0) {
4083 if (!_active || n_inputs().n_total() == 0) {
4084 silence_unlocked (nframes);
4088 framepos_t unused = 0;
4090 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
4096 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4098 fill_buffers_with_input (bufs, _input, nframes);
4100 if (_meter_point == MeterInput) {
4101 _meter->run (bufs, start_frame, end_frame, nframes, true);
4104 passthru (bufs, start_frame, end_frame, nframes, declick);
4110 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
4117 Route::flush_processors ()
4119 /* XXX shouldn't really try to take this lock, since
4120 this is called from the RT audio thread.
4123 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4125 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4131 __attribute__((annotate("realtime")))
4134 Route::apply_processor_changes_rt ()
4136 int emissions = EmitNone;
4138 if (_pending_meter_point != _meter_point) {
4139 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4141 /* meters always have buffers for 'processor_max_streams'
4142 * they can be re-positioned without re-allocation */
4143 if (set_meter_point_unlocked()) {
4144 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
4146 emissions |= EmitMeterChanged;
4151 bool changed = false;
4153 if (g_atomic_int_get (&_pending_process_reorder)) {
4154 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4156 apply_processor_order (_pending_processor_order);
4157 setup_invisible_processors ();
4159 g_atomic_int_set (&_pending_process_reorder, 0);
4160 emissions |= EmitRtProcessorChange;
4164 set_processor_positions ();
4166 if (emissions != 0) {
4167 g_atomic_int_set (&_pending_signals, emissions);
4170 return (!selfdestruct_sequence.empty ());
4174 Route::emit_pending_signals ()
4176 int sig = g_atomic_int_and (&_pending_signals, 0);
4177 if (sig & EmitMeterChanged) {
4178 _meter->emit_configuration_changed();
4179 meter_change (); /* EMIT SIGNAL */
4180 if (sig & EmitMeterVisibilityChange) {
4181 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4183 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4186 if (sig & EmitRtProcessorChange) {
4187 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
4190 /* this would be a job for the butler.
4191 * Conceptually we should not take processe/processor locks here.
4192 * OTOH its more efficient (less overhead for summoning the butler and
4193 * telling her what do do) and signal emission is called
4194 * directly after the process callback, which decreases the chance
4195 * of x-runs when taking the locks.
4197 while (!selfdestruct_sequence.empty ()) {
4198 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
4199 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
4200 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
4201 selfdestruct_sequence.pop_back ();
4204 remove_processor (proc);
4210 Route::set_meter_point (MeterPoint p, bool force)
4212 if (_pending_meter_point == p && !force) {
4216 if (force || !AudioEngine::instance()->running()) {
4217 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4218 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4219 _pending_meter_point = p;
4220 _meter->emit_configuration_changed();
4221 meter_change (); /* EMIT SIGNAL */
4222 if (set_meter_point_unlocked()) {
4223 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4225 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4228 _pending_meter_point = p;
4234 __attribute__((annotate("realtime")))
4237 Route::set_meter_point_unlocked ()
4240 /* Caller must hold process and processor write lock */
4241 assert (!AudioEngine::instance()->process_lock().trylock());
4242 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4243 assert (!lm.locked ());
4246 _meter_point = _pending_meter_point;
4248 bool meter_was_visible_to_user = _meter->display_to_user ();
4250 if (!_custom_meter_position_noted) {
4251 maybe_note_meter_position ();
4254 if (_meter_point != MeterCustom) {
4256 _meter->set_display_to_user (false);
4258 setup_invisible_processors ();
4261 _meter->set_display_to_user (true);
4263 /* If we have a previous position for the custom meter, try to put it there */
4264 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
4266 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
4267 if (i != _processors.end ()) {
4268 _processors.remove (_meter);
4269 _processors.insert (i, _meter);
4271 } else {// at end, right before the mains_out/panner
4272 _processors.remove (_meter);
4273 ProcessorList::iterator main = _processors.end();
4274 _processors.insert (--main, _meter);
4278 /* Set up the meter for its new position */
4280 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4284 if (loc == _processors.begin()) {
4285 m_in = _input->n_ports();
4287 ProcessorList::iterator before = loc;
4289 m_in = (*before)->output_streams ();
4292 _meter->reflect_inputs (m_in);
4294 /* we do not need to reconfigure the processors, because the meter
4295 (a) is always ready to handle processor_max_streams
4296 (b) is always an N-in/N-out processor, and thus moving
4297 it doesn't require any changes to the other processors.
4300 /* these should really be done after releasing the lock
4301 * but all those signals are subscribed to with gui_thread()
4304 return (_meter->display_to_user() != meter_was_visible_to_user);
4308 Route::listen_position_changed ()
4311 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4312 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4313 ProcessorState pstate (this);
4315 if (configure_processors_unlocked (0, &lm)) {
4316 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4318 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4323 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4324 _session.set_dirty ();
4327 boost::shared_ptr<CapturingProcessor>
4328 Route::add_export_point()
4330 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4331 if (!_capturing_processor) {
4333 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4334 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4336 _capturing_processor.reset (new CapturingProcessor (_session));
4337 _capturing_processor->activate ();
4339 configure_processors_unlocked (0, &lw);
4343 return _capturing_processor;
4347 Route::update_signal_latency ()
4349 framecnt_t l = _output->user_latency();
4350 framecnt_t lamp = 0;
4351 bool before_amp = true;
4352 framecnt_t ltrim = 0;
4353 bool before_trim = true;
4355 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4356 if ((*i)->active ()) {
4357 l += (*i)->signal_latency ();
4362 if ((*i) == _trim) {
4373 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
4375 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
4376 _signal_latency_at_amp_position = lamp;
4377 _signal_latency_at_trim_position = ltrim;
4379 if (_signal_latency != l) {
4380 _signal_latency = l;
4381 signal_latency_changed (); /* EMIT SIGNAL */
4384 return _signal_latency;
4388 Route::set_user_latency (framecnt_t nframes)
4390 _output->set_user_latency (nframes);
4391 _session.update_latency_compensation ();
4395 Route::set_latency_compensation (framecnt_t longest_session_latency)
4397 framecnt_t old = _initial_delay;
4399 if (_signal_latency < longest_session_latency) {
4400 _initial_delay = longest_session_latency - _signal_latency;
4405 DEBUG_TRACE (DEBUG::Latency, string_compose (
4406 "%1: compensate for maximum latency of %2,"
4407 "given own latency of %3, using initial delay of %4\n",
4408 name(), longest_session_latency, _signal_latency, _initial_delay));
4410 if (_initial_delay != old) {
4411 initial_delay_changed (); /* EMIT SIGNAL */
4414 if (_session.transport_stopped()) {
4415 _roll_delay = _initial_delay;
4420 Route::set_block_size (pframes_t nframes)
4422 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4423 (*i)->set_block_size (nframes);
4426 _session.ensure_buffers (n_process_buffers ());
4430 Route::protect_automation ()
4432 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4433 (*i)->protect_automation();
4436 /** @param declick 1 to set a pending declick fade-in,
4437 * -1 to set a pending declick fade-out
4440 Route::set_pending_declick (int declick)
4443 /* this call is not allowed to turn off a pending declick */
4445 _pending_declick = declick;
4448 _pending_declick = 0;
4452 /** Shift automation forwards from a particular place, thereby inserting time.
4453 * Adds undo commands for any shifts that are performed.
4455 * @param pos Position to start shifting from.
4456 * @param frames Amount to shift forwards by.
4460 Route::shift (framepos_t pos, framecnt_t frames)
4462 /* gain automation */
4464 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4466 XMLNode &before = gc->alist()->get_state ();
4467 gc->alist()->shift (pos, frames);
4468 XMLNode &after = gc->alist()->get_state ();
4469 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4472 /* gain automation */
4474 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4476 XMLNode &before = gc->alist()->get_state ();
4477 gc->alist()->shift (pos, frames);
4478 XMLNode &after = gc->alist()->get_state ();
4479 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4482 // TODO mute automation ??
4484 /* pan automation */
4486 ControlSet::Controls& c (_pannable->controls());
4488 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4489 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4491 boost::shared_ptr<AutomationList> al = pc->alist();
4492 XMLNode& before = al->get_state ();
4493 al->shift (pos, frames);
4494 XMLNode& after = al->get_state ();
4495 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4500 /* redirect automation */
4502 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4503 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4505 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4507 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4508 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4510 boost::shared_ptr<AutomationList> al = ac->alist();
4511 XMLNode &before = al->get_state ();
4512 al->shift (pos, frames);
4513 XMLNode &after = al->get_state ();
4514 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4522 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4524 boost::shared_ptr<Processor> processor (p.lock ());
4525 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4529 pi->set_state_dir (d);
4533 Route::save_as_template (const string& path, const string& name)
4535 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4536 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4538 XMLNode& node (state (false));
4542 IO::set_name_in_state (*node.children().front(), name);
4544 tree.set_root (&node);
4546 /* return zero on success, non-zero otherwise */
4547 return !tree.write (path.c_str());
4552 Route::set_name (const string& str)
4554 if (str == name()) {
4558 string name = Route::ensure_track_or_route_name (str, _session);
4559 SessionObject::set_name (name);
4561 bool ret = (_input->set_name(name) && _output->set_name(name));
4564 /* rename the main outs. Leave other IO processors
4565 * with whatever name they already have, because its
4566 * just fine as it is (it will not contain the route
4567 * name if its a port insert, port send or port return).
4571 if (_main_outs->set_name (name)) {
4572 /* XXX returning false here is stupid because
4573 we already changed the route name.
4583 /** Set the name of a route in an XML description.
4584 * @param node XML <Route> node to set the name in.
4585 * @param name New name.
4588 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4590 node.add_property (X_("name"), name);
4592 XMLNodeList children = node.children();
4593 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4595 if ((*i)->name() == X_("IO")) {
4597 IO::set_name_in_state (**i, name);
4599 } else if ((*i)->name() == X_("Processor")) {
4601 XMLProperty const * role = (*i)->property (X_("role"));
4602 if (role && role->value() == X_("Main")) {
4603 (*i)->add_property (X_("name"), name);
4606 } else if ((*i)->name() == X_("Diskstream")) {
4608 if (rename_playlist) {
4609 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4611 (*i)->add_property (X_("name"), name);
4617 boost::shared_ptr<Send>
4618 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4620 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4622 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4623 boost::shared_ptr<InternalSend> send;
4625 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4626 if (send->target_route() == target) {
4632 return boost::shared_ptr<Send>();
4635 /** @param c Audio channel index.
4636 * @param yn true to invert phase, otherwise false.
4639 Route::set_phase_invert (uint32_t c, bool yn)
4641 if (_phase_invert[c] != yn) {
4642 _phase_invert[c] = yn;
4643 phase_invert_changed (); /* EMIT SIGNAL */
4644 _phase_control->Changed(); /* EMIT SIGNAL */
4645 _session.set_dirty ();
4650 Route::set_phase_invert (boost::dynamic_bitset<> p)
4652 if (_phase_invert != p) {
4654 phase_invert_changed (); /* EMIT SIGNAL */
4655 _session.set_dirty ();
4660 Route::phase_invert (uint32_t c) const
4662 return _phase_invert[c];
4665 boost::dynamic_bitset<>
4666 Route::phase_invert () const
4668 return _phase_invert;
4672 Route::set_denormal_protection (bool yn)
4674 if (_denormal_protection != yn) {
4675 _denormal_protection = yn;
4676 denormal_protection_changed (); /* EMIT SIGNAL */
4681 Route::denormal_protection () const
4683 return _denormal_protection;
4687 Route::set_active (bool yn, void* src)
4689 if (_session.transport_rolling()) {
4693 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4694 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4698 if (_active != yn) {
4700 _input->set_active (yn);
4701 _output->set_active (yn);
4702 active_changed (); // EMIT SIGNAL
4703 _session.set_dirty ();
4707 boost::shared_ptr<Pannable>
4708 Route::pannable() const
4713 boost::shared_ptr<Panner>
4714 Route::panner() const
4717 return _main_outs->panner_shell()->panner();
4720 boost::shared_ptr<PannerShell>
4721 Route::panner_shell() const
4723 return _main_outs->panner_shell();
4726 boost::shared_ptr<GainControl>
4727 Route::gain_control() const
4729 return _gain_control;
4732 boost::shared_ptr<GainControl>
4733 Route::trim_control() const
4735 return _trim_control;
4738 boost::shared_ptr<Route::PhaseControllable>
4739 Route::phase_control() const
4741 if (phase_invert().size()) {
4742 return _phase_control;
4744 return boost::shared_ptr<PhaseControllable>();
4748 boost::shared_ptr<AutomationControl>
4749 Route::get_control (const Evoral::Parameter& param)
4751 /* either we own the control or .... */
4753 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4757 /* maybe one of our processors does or ... */
4759 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4760 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4761 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4769 /* nobody does so we'll make a new one */
4771 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4778 boost::shared_ptr<Processor>
4779 Route::nth_plugin (uint32_t n) const
4781 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4782 ProcessorList::const_iterator i;
4784 for (i = _processors.begin(); i != _processors.end(); ++i) {
4785 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4792 return boost::shared_ptr<Processor> ();
4795 boost::shared_ptr<Processor>
4796 Route::nth_send (uint32_t n) const
4798 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4799 ProcessorList::const_iterator i;
4801 for (i = _processors.begin(); i != _processors.end(); ++i) {
4802 if (boost::dynamic_pointer_cast<Send> (*i)) {
4804 if ((*i)->name().find (_("Monitor")) == 0) {
4805 /* send to monitor section is not considered
4806 to be an accessible send.
4817 return boost::shared_ptr<Processor> ();
4821 Route::has_io_processor_named (const string& name)
4823 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4824 ProcessorList::iterator i;
4826 for (i = _processors.begin(); i != _processors.end(); ++i) {
4827 if (boost::dynamic_pointer_cast<Send> (*i) ||
4828 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4829 if ((*i)->name() == name) {
4838 MuteMaster::MutePoint
4839 Route::mute_points () const
4841 return _mute_master->mute_points ();
4845 Route::set_processor_positions ()
4847 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4849 bool had_amp = false;
4850 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4851 (*i)->set_pre_fader (!had_amp);
4858 /** Called when there is a proposed change to the input port count */
4860 Route::input_port_count_changing (ChanCount to)
4862 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4864 /* The processors cannot be configured with the new input arrangement, so
4870 /* The change is ok */
4874 /** Called when there is a proposed change to the output port count */
4876 Route::output_port_count_changing (ChanCount to)
4878 if (_strict_io && !_in_configure_processors) {
4881 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4882 if (processor_out_streams.get(*t) > to.get(*t)) {
4886 /* The change is ok */
4891 Route::unknown_processors () const
4895 if (_session.get_disable_all_loaded_plugins ()) {
4896 // Do not list "missing plugins" if they are explicitly disabled
4900 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4901 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4902 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4903 p.push_back ((*i)->name ());
4912 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4914 /* we assume that all our input ports feed all our output ports. its not
4915 universally true, but the alternative is way too corner-case to worry about.
4918 LatencyRange all_connections;
4921 all_connections.min = 0;
4922 all_connections.max = 0;
4924 all_connections.min = ~((pframes_t) 0);
4925 all_connections.max = 0;
4927 /* iterate over all "from" ports and determine the latency range for all of their
4928 connections to the "outside" (outside of this Route).
4931 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4935 p->get_connected_latency_range (range, playback);
4937 all_connections.min = min (all_connections.min, range.min);
4938 all_connections.max = max (all_connections.max, range.max);
4942 /* set the "from" port latencies to the max/min range of all their connections */
4944 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4945 p->set_private_latency_range (all_connections, playback);
4948 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4950 all_connections.min += our_latency;
4951 all_connections.max += our_latency;
4953 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4954 p->set_private_latency_range (all_connections, playback);
4957 return all_connections.max;
4961 Route::set_private_port_latencies (bool playback) const
4963 framecnt_t own_latency = 0;
4965 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4966 OR LATENCY CALLBACK.
4968 This is called (early) from the latency callback. It computes the REAL
4969 latency associated with each port and stores the result as the "private"
4970 latency of the port. A later call to Route::set_public_port_latencies()
4971 sets all ports to the same value to reflect the fact that we do latency
4972 compensation and so all signals are delayed by the same amount as they
4973 flow through ardour.
4976 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4977 if ((*i)->active ()) {
4978 own_latency += (*i)->signal_latency ();
4983 /* playback: propagate latency from "outside the route" to outputs to inputs */
4984 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4986 /* capture: propagate latency from "outside the route" to inputs to outputs */
4987 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4992 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4994 /* this is called to set the JACK-visible port latencies, which take
4995 latency compensation into account.
5004 const PortSet& ports (_input->ports());
5005 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
5006 p->set_public_latency_range (range, playback);
5011 const PortSet& ports (_output->ports());
5012 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
5013 p->set_public_latency_range (range, playback);
5018 /** Put the invisible processors in the right place in _processors.
5019 * Must be called with a writer lock on _processor_lock held.
5022 __attribute__((annotate("realtime")))
5025 Route::setup_invisible_processors ()
5028 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
5029 assert (!lm.locked ());
5033 /* too early to be doing this stuff */
5037 /* we'll build this new list here and then use it
5039 * TODO put the ProcessorList is on the stack for RT-safety.
5042 ProcessorList new_processors;
5044 /* find visible processors */
5046 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5047 if ((*i)->display_to_user ()) {
5048 new_processors.push_back (*i);
5054 ProcessorList::iterator amp = new_processors.begin ();
5055 while (amp != new_processors.end() && *amp != _amp) {
5059 assert (amp != new_processors.end ());
5061 /* and the processor after the amp */
5063 ProcessorList::iterator after_amp = amp;
5069 switch (_meter_point) {
5071 assert (!_meter->display_to_user ());
5072 new_processors.push_front (_meter);
5075 assert (!_meter->display_to_user ());
5076 new_processors.insert (amp, _meter);
5078 case MeterPostFader:
5079 /* do nothing here */
5082 /* do nothing here */
5085 /* the meter is visible, so we don't touch it here */
5092 assert (_main_outs);
5093 assert (!_main_outs->display_to_user ());
5094 new_processors.push_back (_main_outs);
5096 /* iterator for the main outs */
5098 ProcessorList::iterator main = new_processors.end();
5101 /* OUTPUT METERING */
5103 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
5104 assert (!_meter->display_to_user ());
5106 /* add the processor just before or just after the main outs */
5108 ProcessorList::iterator meter_point = main;
5110 if (_meter_point == MeterOutput) {
5113 new_processors.insert (meter_point, _meter);
5118 if (_monitor_send && !is_monitor ()) {
5119 assert (!_monitor_send->display_to_user ());
5120 switch (Config->get_listen_position ()) {
5121 case PreFaderListen:
5122 switch (Config->get_pfl_position ()) {
5123 case PFLFromBeforeProcessors:
5124 new_processors.push_front (_monitor_send);
5126 case PFLFromAfterProcessors:
5127 new_processors.insert (amp, _monitor_send);
5130 _monitor_send->set_can_pan (false);
5132 case AfterFaderListen:
5133 switch (Config->get_afl_position ()) {
5134 case AFLFromBeforeProcessors:
5135 new_processors.insert (after_amp, _monitor_send);
5137 case AFLFromAfterProcessors:
5138 new_processors.insert (new_processors.end(), _monitor_send);
5141 _monitor_send->set_can_pan (true);
5146 #if 0 // not used - just yet
5147 if (!is_master() && !is_monitor() && !is_auditioner()) {
5148 new_processors.push_front (_delayline);
5152 /* MONITOR CONTROL */
5154 if (_monitor_control && is_monitor ()) {
5155 assert (!_monitor_control->display_to_user ());
5156 new_processors.insert (amp, _monitor_control);
5159 /* INTERNAL RETURN */
5161 /* doing this here means that any monitor control will come just after
5166 assert (!_intreturn->display_to_user ());
5167 new_processors.push_front (_intreturn);
5170 if (_trim && _trim->active()) {
5171 assert (!_trim->display_to_user ());
5172 new_processors.push_front (_trim);
5174 /* EXPORT PROCESSOR */
5176 if (_capturing_processor) {
5177 assert (!_capturing_processor->display_to_user ());
5178 new_processors.push_front (_capturing_processor);
5181 _processors = new_processors;
5183 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5184 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
5189 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5190 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5191 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5198 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5199 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5203 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5204 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5211 /** If the meter point is `Custom', make a note of where the meter is.
5212 * This is so that if the meter point is subsequently set to something else,
5213 * and then back to custom, we can put the meter back where it was last time
5214 * custom was enabled.
5216 * Must be called with the _processor_lock held.
5219 Route::maybe_note_meter_position ()
5221 if (_meter_point != MeterCustom) {
5225 _custom_meter_position_noted = true;
5226 /* custom meter points range from after trim to before panner/main_outs
5227 * this is a limitation by the current processor UI
5229 bool seen_trim = false;
5230 _processor_after_last_custom_meter.reset();
5231 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5232 if ((*i) == _trim) {
5235 if ((*i) == _main_outs) {
5236 _processor_after_last_custom_meter = *i;
5239 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5241 _processor_after_last_custom_meter = _trim;
5243 ProcessorList::iterator j = i;
5245 assert(j != _processors.end ()); // main_outs should be before
5246 _processor_after_last_custom_meter = *j;
5251 assert(_processor_after_last_custom_meter.lock());
5254 boost::shared_ptr<Processor>
5255 Route::processor_by_id (PBD::ID id) const
5257 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5258 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5259 if ((*i)->id() == id) {
5264 return boost::shared_ptr<Processor> ();
5267 /** @return the monitoring state, or in other words what data we are pushing
5268 * into the route (data from the inputs, data from disk or silence)
5271 Route::monitoring_state () const
5273 return MonitoringInput;
5276 /** @return what we should be metering; either the data coming from the input
5277 * IO or the data that is flowing through the route.
5280 Route::metering_state () const
5282 return MeteringRoute;
5286 Route::has_external_redirects () const
5288 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5290 /* ignore inactive processors and obviously ignore the main
5291 * outs since everything has them and we don't care.
5294 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5302 boost::shared_ptr<Processor>
5303 Route::the_instrument () const
5305 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5306 return the_instrument_unlocked ();
5309 boost::shared_ptr<Processor>
5310 Route::the_instrument_unlocked () const
5312 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5313 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5314 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5318 return boost::shared_ptr<Processor>();
5324 Route::non_realtime_locate (framepos_t pos)
5327 _pannable->transport_located (pos);
5330 if (_delayline.get()) {
5331 _delayline.get()->flush();
5335 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5336 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5338 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5339 (*i)->transport_located (pos);
5342 _roll_delay = _initial_delay;
5346 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5353 * We don't currently mix MIDI input together, so we don't need the
5354 * complex logic of the audio case.
5357 n_buffers = bufs.count().n_midi ();
5359 for (i = 0; i < n_buffers; ++i) {
5361 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5362 MidiBuffer& buf (bufs.get_midi (i));
5365 buf.copy (source_port->get_midi_buffer(nframes));
5367 buf.silence (nframes);
5373 n_buffers = bufs.count().n_audio();
5375 size_t n_ports = io->n_ports().n_audio();
5376 float scaling = 1.0f;
5378 if (n_ports > n_buffers) {
5379 scaling = ((float) n_buffers) / n_ports;
5382 for (i = 0; i < n_ports; ++i) {
5384 /* if there are more ports than buffers, map them onto buffers
5385 * in a round-robin fashion
5388 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5389 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5392 if (i < n_buffers) {
5394 /* first time through just copy a channel into
5398 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5400 if (scaling != 1.0f) {
5401 buf.apply_gain (scaling, nframes);
5406 /* on subsequent times around, merge data from
5407 * the port with what is already there
5410 if (scaling != 1.0f) {
5411 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5413 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5418 /* silence any remaining buffers */
5420 for (; i < n_buffers; ++i) {
5421 AudioBuffer& buf (bufs.get_audio (i));
5422 buf.silence (nframes);
5425 /* establish the initial setup of the buffer set, reflecting what was
5426 copied into it. unless, of course, we are the auditioner, in which
5427 case nothing was fed into it from the inputs at all.
5430 if (!is_auditioner()) {
5431 bufs.set_count (io->n_ports());
5435 boost::shared_ptr<AutomationControl>
5436 Route::pan_azimuth_control() const
5439 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5441 return boost::shared_ptr<AutomationControl>();
5443 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5444 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5446 if (!_pannable || !panner()) {
5447 return boost::shared_ptr<AutomationControl>();
5449 return _pannable->pan_azimuth_control;
5453 boost::shared_ptr<AutomationControl>
5454 Route::pan_elevation_control() const
5456 if (Profile->get_mixbus() || !_pannable || !panner()) {
5457 return boost::shared_ptr<AutomationControl>();
5460 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5462 if (c.find (PanElevationAutomation) != c.end()) {
5463 return _pannable->pan_elevation_control;
5465 return boost::shared_ptr<AutomationControl>();
5468 boost::shared_ptr<AutomationControl>
5469 Route::pan_width_control() const
5471 if (Profile->get_mixbus() || !_pannable || !panner()) {
5472 return boost::shared_ptr<AutomationControl>();
5475 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5477 if (c.find (PanWidthAutomation) != c.end()) {
5478 return _pannable->pan_width_control;
5480 return boost::shared_ptr<AutomationControl>();
5483 boost::shared_ptr<AutomationControl>
5484 Route::pan_frontback_control() const
5486 if (Profile->get_mixbus() || !_pannable || !panner()) {
5487 return boost::shared_ptr<AutomationControl>();
5490 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5492 if (c.find (PanFrontBackAutomation) != c.end()) {
5493 return _pannable->pan_frontback_control;
5495 return boost::shared_ptr<AutomationControl>();
5498 boost::shared_ptr<AutomationControl>
5499 Route::pan_lfe_control() const
5501 if (Profile->get_mixbus() || !_pannable || !panner()) {
5502 return boost::shared_ptr<AutomationControl>();
5505 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5507 if (c.find (PanLFEAutomation) != c.end()) {
5508 return _pannable->pan_lfe_control;
5510 return boost::shared_ptr<AutomationControl>();
5515 Route::eq_band_cnt () const
5517 if (Profile->get_mixbus()) {
5520 /* Ardour has no well-known EQ object */
5525 boost::shared_ptr<AutomationControl>
5526 Route::eq_gain_controllable (uint32_t band) const
5529 boost::shared_ptr<PluginInsert> eq = ch_eq();
5532 return boost::shared_ptr<AutomationControl>();
5535 uint32_t port_number;
5538 if (is_master() || mixbus()) {
5545 if (is_master() || mixbus()) {
5552 if (is_master() || mixbus()) {
5559 return boost::shared_ptr<AutomationControl>();
5562 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5564 return boost::shared_ptr<AutomationControl>();
5567 boost::shared_ptr<AutomationControl>
5568 Route::eq_freq_controllable (uint32_t band) const
5572 if (mixbus() || is_master()) {
5573 /* no frequency controls for mixbusses or master */
5574 return boost::shared_ptr<AutomationControl>();
5577 boost::shared_ptr<PluginInsert> eq = ch_eq();
5580 return boost::shared_ptr<AutomationControl>();
5583 uint32_t port_number;
5595 return boost::shared_ptr<AutomationControl>();
5598 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5600 return boost::shared_ptr<AutomationControl>();
5604 boost::shared_ptr<AutomationControl>
5605 Route::eq_q_controllable (uint32_t band) const
5607 return boost::shared_ptr<AutomationControl>();
5610 boost::shared_ptr<AutomationControl>
5611 Route::eq_shape_controllable (uint32_t band) const
5613 return boost::shared_ptr<AutomationControl>();
5616 boost::shared_ptr<AutomationControl>
5617 Route::eq_enable_controllable () const
5620 boost::shared_ptr<PluginInsert> eq = ch_eq();
5623 return boost::shared_ptr<AutomationControl>();
5626 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5628 return boost::shared_ptr<AutomationControl>();
5632 boost::shared_ptr<AutomationControl>
5633 Route::eq_hpf_controllable () const
5636 boost::shared_ptr<PluginInsert> eq = ch_eq();
5639 return boost::shared_ptr<AutomationControl>();
5642 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5644 return boost::shared_ptr<AutomationControl>();
5649 Route::eq_band_name (uint32_t band) const
5651 if (Profile->get_mixbus()) {
5667 boost::shared_ptr<AutomationControl>
5668 Route::comp_enable_controllable () const
5671 boost::shared_ptr<PluginInsert> comp = ch_comp();
5674 return boost::shared_ptr<AutomationControl>();
5677 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5679 return boost::shared_ptr<AutomationControl>();
5682 boost::shared_ptr<AutomationControl>
5683 Route::comp_threshold_controllable () const
5686 boost::shared_ptr<PluginInsert> comp = ch_comp();
5689 return boost::shared_ptr<AutomationControl>();
5692 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5695 return boost::shared_ptr<AutomationControl>();
5698 boost::shared_ptr<AutomationControl>
5699 Route::comp_speed_controllable () const
5702 boost::shared_ptr<PluginInsert> comp = ch_comp();
5705 return boost::shared_ptr<AutomationControl>();
5708 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5710 return boost::shared_ptr<AutomationControl>();
5713 boost::shared_ptr<AutomationControl>
5714 Route::comp_mode_controllable () const
5717 boost::shared_ptr<PluginInsert> comp = ch_comp();
5720 return boost::shared_ptr<AutomationControl>();
5723 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5725 return boost::shared_ptr<AutomationControl>();
5728 boost::shared_ptr<AutomationControl>
5729 Route::comp_makeup_controllable () const
5732 boost::shared_ptr<PluginInsert> comp = ch_comp();
5735 return boost::shared_ptr<AutomationControl>();
5738 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5740 return boost::shared_ptr<AutomationControl>();
5743 boost::shared_ptr<AutomationControl>
5744 Route::comp_redux_controllable () const
5747 boost::shared_ptr<PluginInsert> comp = ch_comp();
5750 return boost::shared_ptr<AutomationControl>();
5753 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5755 return boost::shared_ptr<AutomationControl>();
5760 Route::comp_mode_name (uint32_t mode) const
5765 return _("Leveler");
5767 return _("Compressor");
5769 return _("Limiter");
5771 return mixbus() ? _("Sidechain") : _("Limiter");
5781 Route::comp_speed_name (uint32_t mode) const
5799 boost::shared_ptr<AutomationControl>
5800 Route::send_level_controllable (uint32_t n) const
5803 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5805 return boost::shared_ptr<AutomationControl>();
5810 return boost::shared_ptr<AutomationControl>();
5813 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5814 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5816 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5818 return boost::shared_ptr<AutomationControl>();
5820 return s->gain_control ();
5824 boost::shared_ptr<AutomationControl>
5825 Route::send_enable_controllable (uint32_t n) const
5828 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5830 return boost::shared_ptr<AutomationControl>();
5835 return boost::shared_ptr<AutomationControl>();
5838 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5839 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5841 /* although Ardour sends have enable/disable as part of the Processor
5842 API, it is not exposed as a controllable.
5844 XXX: we should fix this.
5846 return boost::shared_ptr<AutomationControl>();
5851 Route::send_name (uint32_t n) const
5857 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5861 boost::shared_ptr<Processor> p = nth_send (n);
5870 boost::shared_ptr<AutomationControl>
5871 Route::master_send_enable_controllable () const
5874 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5876 return boost::shared_ptr<AutomationControl>();
5878 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5880 return boost::shared_ptr<AutomationControl>();