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;
82 /** Base class for all routable/mixable objects (tracks and busses) */
83 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
84 : SessionObject (sess, name)
86 , GraphNode (sess._process_graph)
89 , _signal_latency_at_amp_position (0)
90 , _signal_latency_at_trim_position (0)
93 , _pending_process_reorder (0)
94 , _pending_signals (0)
96 , _pending_declick (true)
97 , _meter_point (MeterPostFader)
98 , _pending_meter_point (MeterPostFader)
99 , _meter_type (MeterPeak)
101 , _soloed_by_others_upstream (0)
102 , _soloed_by_others_downstream (0)
103 , _solo_isolated (false)
104 , _solo_isolated_by_upstream (0)
105 , _denormal_protection (false)
108 , _declickable (false)
109 , _mute_master (new MuteMaster (sess, name))
110 , _have_internal_generator (false)
112 , _default_type (default_type)
114 , _has_order_key (false)
115 , _remote_control_id (0)
117 , _in_configure_processors (false)
118 , _initial_io_setup (false)
119 , _in_sidechain_setup (false)
121 , _custom_meter_position_noted (false)
124 processor_max_streams.reset();
130 /* set default meter type */
132 _meter_type = Config->get_meter_type_master ();
134 else if (dynamic_cast<Track*>(this)) {
135 _meter_type = Config->get_meter_type_track ();
137 _meter_type = Config->get_meter_type_bus ();
140 /* add standard controls */
142 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
143 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
144 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
146 _solo_isolate_control.reset (new SoloIsolateControllable (X_("solo-iso"), shared_from_this ()));
147 _solo_safe_control.reset (new SoloSafeControllable (X_("solo-safe"), shared_from_this ()));
149 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
150 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
151 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
153 add_control (_solo_control);
154 add_control (_mute_control);
155 add_control (_phase_control);
159 if (!(_flags & Route::MonitorOut)) {
160 _pannable.reset (new Pannable (_session));
163 /* input and output objects */
165 _input.reset (new IO (_session, _name, IO::Input, _default_type));
166 _output.reset (new IO (_session, _name, IO::Output, _default_type));
168 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
169 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
171 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
172 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
174 #if 0 // not used - just yet
175 if (!is_master() && !is_monitor() && !is_auditioner()) {
176 _delayline.reset (new DelayLine (_session, _name));
177 add_processor (_delayline, PreFader);
181 /* add amp processor */
183 _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
184 add_control (_gain_control);
186 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
187 add_processor (_amp, PostFader);
190 _amp->set_display_name (_("Monitor"));
195 _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
196 add_control (_trim_control);
198 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
199 _trim->set_display_to_user (false);
201 if (dynamic_cast<AudioTrack*>(this)) {
202 /* we can't do this in the AudioTrack's constructor
203 * because _trim does not exit then
207 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
212 /* create standard processors: meter, main outs, monitor out;
213 they will be added to _processors by setup_invisible_processors ()
216 _meter.reset (new PeakMeter (_session, _name));
217 _meter->set_owner (this);
218 _meter->set_display_to_user (false);
221 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
222 _main_outs->activate ();
225 /* where we listen to tracks */
226 _intreturn.reset (new InternalReturn (_session));
227 _intreturn->activate ();
229 /* the thing that provides proper control over a control/monitor/listen bus
230 (such as per-channel cut, dim, solo, invert, etc).
232 _monitor_control.reset (new MonitorProcessor (_session));
233 _monitor_control->activate ();
236 if (is_master() || is_monitor() || is_auditioner()) {
237 _mute_master->set_solo_ignore (true);
240 /* now that we have _meter, its safe to connect to this */
243 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
244 configure_processors (0);
252 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
254 /* do this early so that we don't get incoming signals as we are going through destruction
259 /* don't use clear_processors here, as it depends on the session which may
260 be half-destroyed by now
263 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
264 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
265 (*i)->drop_references ();
268 _processors.clear ();
272 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
274 if (Config->get_remote_model() != UserOrdered) {
278 set_remote_control_id_internal (id, notify_class_listeners);
282 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
284 /* force IDs for master/monitor busses and prevent
285 any other route from accidentally getting these IDs
286 (i.e. legacy sessions)
289 if (is_master() && id != MasterBusRemoteControlID) {
290 id = MasterBusRemoteControlID;
293 if (is_monitor() && id != MonitorBusRemoteControlID) {
294 id = MonitorBusRemoteControlID;
301 /* don't allow it to collide */
303 if (!is_master () && !is_monitor() &&
304 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
305 id += MonitorBusRemoteControlID;
308 if (id != remote_control_id()) {
309 _remote_control_id = id;
310 RemoteControlIDChanged ();
312 if (notify_class_listeners) {
313 RemoteControlIDChange ();
319 Route::remote_control_id() const
322 return MasterBusRemoteControlID;
326 return MonitorBusRemoteControlID;
329 return _remote_control_id;
333 Route::has_order_key () const
335 return _has_order_key;
339 Route::order_key () const
345 Route::set_remote_control_id_explicit (uint32_t rid)
347 if (is_master() || is_monitor() || is_auditioner()) {
348 /* hard-coded remote IDs, or no remote ID */
352 if (_remote_control_id != rid) {
353 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
354 _remote_control_id = rid;
355 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
358 /* don't emit the class-level RID signal RemoteControlIDChange here,
359 leave that to the entity that changed the order key, so that we
360 don't get lots of emissions for no good reasons (e.g. when changing
361 all route order keys).
363 See Session::sync_remote_id_from_order_keys() for the (primary|only)
364 spot where that is emitted.
369 Route::set_order_key (uint32_t n)
371 _has_order_key = true;
373 if (_order_key == n) {
379 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
380 name(), order_key ()));
382 _session.set_dirty ();
386 Route::ensure_track_or_route_name(string name, Session &session)
388 string newname = name;
390 while (!session.io_name_is_legal (newname)) {
391 newname = bump_name_once (newname, ' ');
398 Route::inc_gain (gain_t factor)
400 /* To be used ONLY when doing group-relative gain adjustment, from
404 float desired_gain = _gain_control->user_double();
406 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
407 // really?! what's the idea here?
408 _gain_control->route_set_value (0.000001f + (0.000001f * factor));
410 _gain_control->route_set_value (desired_gain + (desired_gain * factor));
415 Route::set_gain (gain_t val, Controllable::GroupControlDisposition group_override)
417 if (use_group (group_override, &RouteGroup::is_gain)) {
419 if (_route_group->is_relative()) {
421 gain_t usable_gain = _gain_control->get_value();
422 if (usable_gain < 0.000001f) {
423 usable_gain = 0.000001f;
427 if (delta < 0.000001f) {
431 delta -= usable_gain;
436 gain_t factor = delta / usable_gain;
439 factor = _route_group->get_max_factor(factor);
440 if (factor == 0.0f) {
441 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
445 factor = _route_group->get_min_factor(factor);
446 if (factor == 0.0f) {
447 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
452 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor));
456 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, Controllable::NoGroup));
462 if (val == _gain_control->get_value()) {
466 _gain_control->route_set_value (val);
470 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
472 // TODO route group, see set_gain()
473 _trim_control->route_set_value (val);
477 Route::maybe_declick (BufferSet&, framecnt_t, int)
479 /* this is the "bus" implementation and they never declick.
484 /** Process this route for one (sub) cycle (process thread)
486 * @param bufs Scratch buffers to use for the signal path
487 * @param start_frame Initial transport frame
488 * @param end_frame Final transport frame
489 * @param nframes Number of frames to output (to ports)
491 * Note that (end_frame - start_frame) may not be equal to nframes when the
492 * transport speed isn't 1.0 (eg varispeed).
495 Route::process_output_buffers (BufferSet& bufs,
496 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
497 int declick, bool gain_automation_ok)
499 /* Caller must hold process lock */
500 assert (!AudioEngine::instance()->process_lock().trylock());
502 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
504 // can this actually happen? functions calling process_output_buffers()
505 // already take a reader-lock.
506 bufs.silence (nframes, 0);
510 /* figure out if we're going to use gain automation */
511 if (gain_automation_ok) {
512 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
513 _amp->setup_gain_automation (
514 start_frame + _signal_latency_at_amp_position,
515 end_frame + _signal_latency_at_amp_position,
518 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
519 _trim->setup_gain_automation (
520 start_frame + _signal_latency_at_trim_position,
521 end_frame + _signal_latency_at_trim_position,
524 _amp->apply_gain_automation (false);
525 _trim->apply_gain_automation (false);
528 /* Tell main outs what to do about monitoring. We do this so that
529 on a transition between monitoring states we get a de-clicking gain
530 change in the _main_outs delivery, if config.get_use_monitor_fades()
533 We override this in the case where we have an internal generator.
535 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
537 _main_outs->no_outs_cuz_we_no_monitor (silence);
539 /* -------------------------------------------------------------------------------------------
540 GLOBAL DECLICK (for transport changes etc.)
541 ----------------------------------------------------------------------------------------- */
543 maybe_declick (bufs, nframes, declick);
544 _pending_declick = 0;
546 /* -------------------------------------------------------------------------------------------
547 DENORMAL CONTROL/PHASE INVERT
548 ----------------------------------------------------------------------------------------- */
550 if (_phase_invert.any ()) {
554 if (_denormal_protection || Config->get_denormal_protection()) {
556 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
557 Sample* const sp = i->data();
559 if (_phase_invert[chn]) {
560 for (pframes_t nx = 0; nx < nframes; ++nx) {
565 for (pframes_t nx = 0; nx < nframes; ++nx) {
573 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
574 Sample* const sp = i->data();
576 if (_phase_invert[chn]) {
577 for (pframes_t nx = 0; nx < nframes; ++nx) {
586 if (_denormal_protection || Config->get_denormal_protection()) {
588 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
589 Sample* const sp = i->data();
590 for (pframes_t nx = 0; nx < nframes; ++nx) {
598 /* -------------------------------------------------------------------------------------------
600 ----------------------------------------------------------------------------------------- */
602 /* set this to be true if the meter will already have been ::run() earlier */
603 bool const meter_already_run = metering_state() == MeteringInput;
605 framecnt_t latency = 0;
607 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
609 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
610 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
615 /* if it has any inputs, make sure they match */
616 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
617 if (bufs.count() != (*i)->input_streams()) {
619 DEBUG::Processors, string_compose (
620 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
621 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
628 /* should we NOT run plugins here if the route is inactive?
629 do we catch route != active somewhere higher?
632 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
633 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
636 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
637 bufs.set_count ((*i)->output_streams());
639 if ((*i)->active ()) {
640 latency += (*i)->signal_latency ();
646 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
647 boost::shared_ptr<Processor> endpoint,
648 bool include_endpoint, bool for_export, bool for_freeze)
650 /* If no processing is required, there's no need to go any further. */
651 if (!endpoint && !include_endpoint) {
655 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
656 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
657 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
659 /* trim is always at the top, for bounce no latency compensation is needed */
660 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
661 _trim->setup_gain_automation (start, start + nframes, nframes);
664 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
666 if (!include_endpoint && (*i) == endpoint) {
670 /* if we're *not* exporting, stop processing if we come across a routing processor. */
671 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
674 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
678 /* special case the panner (export outputs)
679 * Ideally we'd only run the panner, not the delivery itself...
680 * but panners need separate input/output buffers and some context
681 * (panshell, panner type, etc). AFAICT there is no ill side effect
682 * of re-using the main delivery when freewheeling/exporting a region.
684 if ((*i) == _main_outs) {
685 assert ((*i)->does_routing());
686 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
687 buffers.set_count ((*i)->output_streams());
690 /* don't run any processors that do routing.
691 * Also don't bother with metering.
693 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
694 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
695 buffers.set_count ((*i)->output_streams());
696 latency += (*i)->signal_latency ();
699 if ((*i) == endpoint) {
706 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
707 bool include_endpoint, bool for_export, bool for_freeze) const
709 framecnt_t latency = 0;
710 if (!endpoint && !include_endpoint) {
714 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
715 if (!include_endpoint && (*i) == endpoint) {
718 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
721 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
724 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
725 latency += (*i)->signal_latency ();
727 if ((*i) == endpoint) {
735 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
736 bool include_endpoint, bool for_export, bool for_freeze) const
738 if (!endpoint && !include_endpoint) {
742 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
743 if (!include_endpoint && (*i) == endpoint) {
746 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
749 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
752 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
753 cc = (*i)->output_streams();
755 if ((*i) == endpoint) {
763 Route::n_process_buffers ()
765 return max (_input->n_ports(), processor_max_streams);
769 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
771 assert (is_monitor());
772 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
773 fill_buffers_with_input (bufs, _input, nframes);
774 passthru (bufs, start_frame, end_frame, nframes, declick);
778 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
782 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
784 /* control/monitor bus ignores input ports when something is
785 feeding the listen "stream". data will "arrive" into the
786 route from the intreturn processor element.
789 bufs.silence (nframes, 0);
792 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
793 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
797 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
799 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
801 bufs.set_count (_input->n_ports());
802 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
803 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
807 Route::set_listen (bool yn, Controllable::GroupControlDisposition group_override)
813 if (use_group (group_override, &RouteGroup::is_solo)) {
814 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, Controllable::ForGroup));
819 if (yn != _monitor_send->active()) {
821 _monitor_send->activate ();
822 _mute_master->set_soloed_by_self (true);
824 _monitor_send->deactivate ();
825 _mute_master->set_soloed_by_self (false);
827 _mute_master->set_soloed_by_others (false);
829 listen_changed (group_override); /* EMIT SIGNAL */
835 Route::listening_via_monitor () const
838 return _monitor_send->active ();
845 Route::set_solo_safe (bool yn, Controllable::GroupControlDisposition /* group_override */)
847 if (_solo_safe != yn) {
849 solo_safe_changed (); /* EMIT SIGNAL */
850 _solo_safe_control->Changed(); /* EMIT SIGNAL */
855 Route::solo_safe() const
861 Route::clear_all_solo_state ()
863 // ideally this function will never do anything, it only exists to forestall Murphy
864 bool emit_changed = false;
867 // these are really debug messages, but of possible interest.
869 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
871 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
872 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
873 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
877 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
878 // if self-soled, set_solo() will do signal emission
882 _soloed_by_others_upstream = 0;
883 _soloed_by_others_downstream = 0;
886 PBD::Unwinder<bool> uw (_solo_safe, false);
887 set_solo (false, Controllable::NoGroup);
891 set_mute_master_solo ();
892 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
897 Route::set_solo (bool yn, Controllable::GroupControlDisposition group_override)
899 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, grp ? %3 currently self-soloed ? %4\n",
900 name(), yn, enum_2_string(group_override), self_soloed()));
903 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
907 if (is_master() || is_monitor() || is_auditioner()) {
908 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
912 if (use_group (group_override, &RouteGroup::is_solo)) {
913 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, Controllable::ForGroup));
917 if (self_soloed() != yn) {
919 solo_changed (true, group_override); /* EMIT SIGNAL */
920 _solo_control->Changed (); /* EMIT SIGNAL */
923 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
925 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
926 Config->get_solo_mute_overrride().
929 if (yn && Profile->get_trx()) {
930 set_mute (false, Controllable::UseGroup);
935 Route::set_self_solo (bool yn)
937 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
939 set_mute_master_solo ();
943 Route::mod_solo_by_others_upstream (int32_t delta)
945 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
946 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
948 uint32_t old_sbu = _soloed_by_others_upstream;
951 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
952 _soloed_by_others_upstream += delta;
954 _soloed_by_others_upstream = 0;
957 _soloed_by_others_upstream += delta;
960 DEBUG_TRACE (DEBUG::Solo, string_compose (
961 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
962 name(), delta, _soloed_by_others_upstream, old_sbu,
963 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
965 /* push the inverse solo change to everything that feeds us.
967 This is important for solo-within-group. When we solo 1 track out of N that
968 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
969 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
970 tracks that feed it. This will silence them if they were audible because
971 of a bus solo, but the newly soloed track will still be audible (because
974 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
978 if ((_self_solo || _soloed_by_others_downstream) &&
979 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
980 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
982 if (delta > 0 || !Config->get_exclusive_solo()) {
983 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
984 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
988 boost::shared_ptr<Route> sr = i->r.lock();
990 sr->mod_solo_by_others_downstream (-delta);
996 set_mute_master_solo ();
997 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1001 Route::mod_solo_by_others_downstream (int32_t delta)
1003 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
1004 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
1007 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
1008 _soloed_by_others_downstream += delta;
1010 _soloed_by_others_downstream = 0;
1013 _soloed_by_others_downstream += delta;
1016 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
1018 set_mute_master_solo ();
1019 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1023 Route::set_mute_master_solo ()
1025 _mute_master->set_soloed_by_self (self_soloed());
1026 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1030 Route::mod_solo_isolated_by_upstream (bool yn)
1032 bool old = solo_isolated ();
1033 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1034 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1037 if (_solo_isolated_by_upstream >= 1) {
1038 _solo_isolated_by_upstream--;
1040 _solo_isolated_by_upstream = 0;
1043 _solo_isolated_by_upstream++;
1046 if (solo_isolated() != old) {
1047 /* solo isolated status changed */
1048 _mute_master->set_solo_ignore (solo_isolated());
1049 solo_isolated_changed (); /* EMIT SIGNAL */
1054 Route::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
1056 if (is_master() || is_monitor() || is_auditioner()) {
1060 if (use_group (group_override, &RouteGroup::is_solo)) {
1061 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, Controllable::ForGroup));
1065 bool changed = false;
1068 if (_solo_isolated == false) {
1069 _mute_master->set_solo_ignore (true);
1072 _solo_isolated = true;
1074 if (_solo_isolated == true) {
1075 _solo_isolated = false;
1076 _mute_master->set_solo_ignore (false);
1086 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1088 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1089 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1091 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1096 bool does_feed = feeds (*i, &sends_only);
1098 if (does_feed && !sends_only) {
1099 (*i)->mod_solo_isolated_by_upstream (yn);
1103 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1105 solo_isolated_changed (); /* EMIT SIGNAL */
1106 _solo_isolate_control->Changed(); /* EMIT SIGNAL */
1110 Route::solo_isolated () const
1112 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1116 Route::set_mute_points (MuteMaster::MutePoint mp)
1118 _mute_master->set_mute_points (mp);
1119 mute_points_changed (); /* EMIT SIGNAL */
1121 if (_mute_master->muted_by_self()) {
1122 mute_changed (); /* EMIT SIGNAL */
1123 _mute_control->Changed (); /* EMIT SIGNAL */
1128 Route::set_mute (bool yn, Controllable::GroupControlDisposition group_override)
1130 if (use_group (group_override, &RouteGroup::is_mute)) {
1131 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, Controllable::ForGroup));
1135 if (muted() != yn) {
1136 _mute_master->set_muted_by_self (yn);
1137 /* allow any derived classes to respond to the mute change
1138 before anybody else knows about it.
1141 /* tell everyone else */
1142 mute_changed (); /* EMIT SIGNAL */
1143 _mute_control->Changed (); /* EMIT SIGNAL */
1148 Route::muted () const
1150 return _mute_master->muted_by_self();
1154 Route::muted_by_others () const
1156 // This method is only used by route_ui for display state.
1157 // The real thing is MuteMaster::muted_by_others_at()
1159 //master is never muted by others
1163 //now check to see if something is soloed (and I am not)
1164 //see also MuteMaster::mute_gain_at()
1165 return (_session.soloing() && !soloed() && !solo_isolated());
1170 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1172 cerr << name << " {" << endl;
1173 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1174 p != procs.end(); ++p) {
1175 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1177 cerr << "}" << endl;
1181 /** Supposing that we want to insert a Processor at a given Placement, return
1182 * the processor to add the new one before (or 0 to add at the end).
1184 boost::shared_ptr<Processor>
1185 Route::before_processor_for_placement (Placement p)
1187 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1189 ProcessorList::iterator loc;
1191 if (p == PreFader) {
1192 /* generic pre-fader: insert immediately before the amp */
1193 loc = find (_processors.begin(), _processors.end(), _amp);
1195 /* generic post-fader: insert right before the main outs */
1196 loc = find (_processors.begin(), _processors.end(), _main_outs);
1199 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1202 /** Supposing that we want to insert a Processor at a given index, return
1203 * the processor to add the new one before (or 0 to add at the end).
1205 boost::shared_ptr<Processor>
1206 Route::before_processor_for_index (int index)
1209 return boost::shared_ptr<Processor> ();
1212 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1214 ProcessorList::iterator i = _processors.begin ();
1216 while (i != _processors.end() && j < index) {
1217 if ((*i)->display_to_user()) {
1224 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1227 /** Add a processor either pre- or post-fader
1228 * @return 0 on success, non-0 on failure.
1231 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1233 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1237 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1238 * @param index Index to add the processor at, or -1 to add at the end of the list.
1239 * @return 0 on success, non-0 on failure.
1242 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1244 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1247 /** Add a processor to the route.
1248 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1249 * @return 0 on success, non-0 on failure.
1252 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1254 assert (processor != _meter);
1255 assert (processor != _main_outs);
1257 DEBUG_TRACE (DEBUG::Processors, string_compose (
1258 "%1 adding processor %2\n", name(), processor->name()));
1262 pl.push_back (processor);
1263 int rv = add_processors (pl, before, err);
1269 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1270 processor->activate ();
1277 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
1279 /* We cannot destruct the processor here (usually RT-thread
1280 * with various locks held - in case of sends also io_locks).
1281 * Queue for deletion in low-priority thread.
1283 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
1284 selfdestruct_sequence.push_back (wp);
1288 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1290 XMLProperty const * prop;
1293 boost::shared_ptr<Processor> processor;
1295 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1296 so that we can add the processor in the right place (pre/post-fader)
1299 XMLNodeList const & children = node.children ();
1300 XMLNodeList::const_iterator i = children.begin ();
1302 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1306 Placement placement = PreFader;
1308 if (i != children.end()) {
1309 if ((prop = (*i)->property (X_("placement"))) != 0) {
1310 placement = Placement (string_2_enum (prop->value(), placement));
1314 if (node.name() == "Insert") {
1316 if ((prop = node.property ("type")) != 0) {
1318 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1319 prop->value() == "lv2" ||
1320 prop->value() == "windows-vst" ||
1321 prop->value() == "lxvst" ||
1322 prop->value() == "audiounit") {
1324 if (_session.get_disable_all_loaded_plugins ()) {
1325 processor.reset (new UnknownProcessor (_session, node));
1327 processor.reset (new PluginInsert (_session));
1328 processor->set_owner (this);
1333 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1338 } else if (node.name() == "Send") {
1340 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1341 processor.reset (new Send (_session, sendpan, _mute_master));
1345 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1349 if (processor->set_state (node, version)) {
1353 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1354 if (i != children.end()) {
1355 if ((prop = (*i)->property (X_("active"))) != 0) {
1356 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1357 processor->activate();
1359 processor->deactivate();
1363 return (add_processor (processor, placement, 0, false) == 0);
1366 catch (failed_constructor &err) {
1367 warning << _("processor could not be created. Ignored.") << endmsg;
1373 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1375 ProcessorList::iterator loc;
1378 loc = find(_processors.begin(), _processors.end(), before);
1379 if (loc == _processors.end ()) {
1383 /* nothing specified - at end */
1384 loc = _processors.end ();
1387 if (!AudioEngine::instance()->connected()) {
1391 if (others.empty()) {
1396 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1397 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1398 ProcessorState pstate (this);
1400 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1406 boost::shared_ptr<PluginInsert> pi;
1408 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1409 pi->set_strict_io (_strict_io);
1413 /* Ensure that only one amp is in the list at any time */
1414 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1415 if (check != _processors.end()) {
1416 if (before == _amp) {
1417 /* Already in position; all is well */
1420 _processors.erase (check);
1425 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1427 _processors.insert (loc, *i);
1428 (*i)->set_owner (this);
1431 if (configure_processors_unlocked (err, &lm)) {
1433 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1438 if ((*i)->active()) {
1442 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1444 boost::shared_ptr<Send> send;
1445 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1446 send->SelfDestruct.connect_same_thread (*this,
1447 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1451 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1452 boost::shared_ptr<PluginInsert> pi;
1454 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1455 if (pi->has_no_inputs ()) {
1456 _have_internal_generator = true;
1462 _output->set_user_latency (0);
1465 reset_instrument_info ();
1466 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1467 set_processor_positions ();
1473 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1475 if (p == PreFader) {
1476 start = _processors.begin();
1477 end = find(_processors.begin(), _processors.end(), _amp);
1479 start = find(_processors.begin(), _processors.end(), _amp);
1481 end = _processors.end();
1485 /** Turn off all processors with a given placement
1486 * @param p Placement of processors to disable
1489 Route::disable_processors (Placement p)
1491 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1493 ProcessorList::iterator start, end;
1494 placement_range(p, start, end);
1496 for (ProcessorList::iterator i = start; i != end; ++i) {
1497 (*i)->deactivate ();
1500 _session.set_dirty ();
1503 /** Turn off all redirects
1506 Route::disable_processors ()
1508 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1510 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1511 (*i)->deactivate ();
1514 _session.set_dirty ();
1517 /** Turn off all redirects with a given placement
1518 * @param p Placement of redirects to disable
1521 Route::disable_plugins (Placement p)
1523 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1525 ProcessorList::iterator start, end;
1526 placement_range(p, start, end);
1528 for (ProcessorList::iterator i = start; i != end; ++i) {
1529 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1530 (*i)->deactivate ();
1534 _session.set_dirty ();
1537 /** Turn off all plugins
1540 Route::disable_plugins ()
1542 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1544 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1545 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1546 (*i)->deactivate ();
1550 _session.set_dirty ();
1555 Route::ab_plugins (bool forward)
1557 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1561 /* forward = turn off all active redirects, and mark them so that the next time
1562 we go the other way, we will revert them
1565 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1566 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1570 if ((*i)->active()) {
1571 (*i)->deactivate ();
1572 (*i)->set_next_ab_is_active (true);
1574 (*i)->set_next_ab_is_active (false);
1580 /* backward = if the redirect was marked to go active on the next ab, do so */
1582 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1584 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1588 if ((*i)->get_next_ab_is_active()) {
1591 (*i)->deactivate ();
1596 _session.set_dirty ();
1600 /** Remove processors with a given placement.
1601 * @param p Placement of processors to remove.
1604 Route::clear_processors (Placement p)
1606 if (!_session.engine().connected()) {
1610 bool already_deleting = _session.deletion_in_progress();
1611 if (!already_deleting) {
1612 _session.set_deletion_in_progress();
1616 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1617 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1618 ProcessorList new_list;
1619 ProcessorStreams err;
1620 bool seen_amp = false;
1622 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1628 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1630 /* you can't remove these */
1632 new_list.push_back (*i);
1639 new_list.push_back (*i);
1642 (*i)->drop_references ();
1650 (*i)->drop_references ();
1653 new_list.push_back (*i);
1660 _processors = new_list;
1661 configure_processors_unlocked (&err, &lm); // this can't fail
1664 processor_max_streams.reset();
1665 _have_internal_generator = false;
1666 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1667 set_processor_positions ();
1669 reset_instrument_info ();
1671 if (!already_deleting) {
1672 _session.clear_deletion_in_progress();
1677 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1679 // TODO once the export point can be configured properly, do something smarter here
1680 if (processor == _capturing_processor) {
1681 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1682 if (need_process_lock) {
1686 _capturing_processor.reset();
1688 if (need_process_lock) {
1693 /* these can never be removed */
1695 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1699 if (!_session.engine().connected()) {
1703 processor_max_streams.reset();
1706 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1707 if (need_process_lock) {
1711 /* Caller must hold process lock */
1712 assert (!AudioEngine::instance()->process_lock().trylock());
1714 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1716 ProcessorState pstate (this);
1718 ProcessorList::iterator i;
1719 bool removed = false;
1721 for (i = _processors.begin(); i != _processors.end(); ) {
1722 if (*i == processor) {
1724 /* move along, see failure case for configure_processors()
1725 where we may need to reconfigure the processor.
1728 /* stop redirects that send signals to JACK ports
1729 from causing noise as a result of no longer being
1733 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1734 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1738 iop = pi->sidechain();
1745 i = _processors.erase (i);
1753 _output->set_user_latency (0);
1761 if (configure_processors_unlocked (err, &lm)) {
1763 /* we know this will work, because it worked before :) */
1764 configure_processors_unlocked (0, &lm);
1768 _have_internal_generator = false;
1770 for (i = _processors.begin(); i != _processors.end(); ++i) {
1771 boost::shared_ptr<PluginInsert> pi;
1773 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1774 if (pi->has_no_inputs ()) {
1775 _have_internal_generator = true;
1780 if (need_process_lock) {
1785 reset_instrument_info ();
1786 processor->drop_references ();
1787 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1788 set_processor_positions ();
1794 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1796 /* these can never be removed */
1797 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1800 /* and can't be used as substitute, either */
1801 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1805 /* I/Os are out, too */
1806 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1810 /* this function cannot be used to swap/reorder processors */
1811 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1815 if (!AudioEngine::instance()->connected() || !old || !sub) {
1819 /* ensure that sub is not owned by another route */
1820 if (sub->owner ()) {
1825 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1826 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1827 ProcessorState pstate (this);
1829 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1831 ProcessorList::iterator i;
1832 bool replaced = false;
1833 bool enable = old->active ();
1835 for (i = _processors.begin(); i != _processors.end(); ) {
1837 i = _processors.erase (i);
1838 _processors.insert (i, sub);
1839 sub->set_owner (this);
1852 boost::shared_ptr<PluginInsert> pi;
1853 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1854 pi->set_strict_io (true);
1858 if (configure_processors_unlocked (err, &lm)) {
1860 configure_processors_unlocked (0, &lm);
1864 _have_internal_generator = false;
1866 for (i = _processors.begin(); i != _processors.end(); ++i) {
1867 boost::shared_ptr<PluginInsert> pi;
1868 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1869 if (pi->has_no_inputs ()) {
1870 _have_internal_generator = true;
1880 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1881 _output->set_user_latency (0);
1884 reset_instrument_info ();
1885 old->drop_references ();
1886 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1887 set_processor_positions ();
1892 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1894 ProcessorList deleted;
1896 if (!_session.engine().connected()) {
1900 processor_max_streams.reset();
1903 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1904 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1905 ProcessorState pstate (this);
1907 ProcessorList::iterator i;
1908 boost::shared_ptr<Processor> processor;
1910 for (i = _processors.begin(); i != _processors.end(); ) {
1914 /* these can never be removed */
1916 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1921 /* see if its in the list of processors to delete */
1923 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1928 /* stop IOProcessors that send to JACK ports
1929 from causing noise as a result of no longer being
1933 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1934 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1937 iop = pi->sidechain();
1944 deleted.push_back (processor);
1945 i = _processors.erase (i);
1948 if (deleted.empty()) {
1949 /* none of those in the requested list were found */
1953 _output->set_user_latency (0);
1955 if (configure_processors_unlocked (err, &lm)) {
1957 /* we know this will work, because it worked before :) */
1958 configure_processors_unlocked (0, &lm);
1963 _have_internal_generator = false;
1965 for (i = _processors.begin(); i != _processors.end(); ++i) {
1966 boost::shared_ptr<PluginInsert> pi;
1968 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1969 if (pi->has_no_inputs ()) {
1970 _have_internal_generator = true;
1977 /* now try to do what we need to so that those that were removed will be deleted */
1979 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1980 (*i)->drop_references ();
1983 reset_instrument_info ();
1984 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1985 set_processor_positions ();
1991 Route::reset_instrument_info ()
1993 boost::shared_ptr<Processor> instr = the_instrument();
1995 _instrument_info.set_internal_instrument (instr);
1999 /** Caller must hold process lock */
2001 Route::configure_processors (ProcessorStreams* err)
2003 #ifndef PLATFORM_WINDOWS
2004 assert (!AudioEngine::instance()->process_lock().trylock());
2007 if (!_in_configure_processors) {
2008 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2009 return configure_processors_unlocked (err, &lm);
2016 Route::input_streams () const
2018 return _input->n_ports ();
2021 list<pair<ChanCount, ChanCount> >
2022 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
2024 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2026 return try_configure_processors_unlocked (in, err);
2029 list<pair<ChanCount, ChanCount> >
2030 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
2032 // Check each processor in order to see if we can configure as requested
2034 list<pair<ChanCount, ChanCount> > configuration;
2037 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
2038 DEBUG_TRACE (DEBUG::Processors, "{\n");
2040 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
2042 if ((*p)->can_support_io_configuration(in, out)) {
2044 if (boost::dynamic_pointer_cast<Delivery> (*p)
2045 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
2046 && !(is_monitor() || is_auditioner())
2047 && ( _strict_io || Profile->get_mixbus ())) {
2048 /* with strict I/O the panner + output are forced to
2049 * follow the last processor's output.
2051 * Delivery::can_support_io_configuration() will only add ports,
2052 * but not remove excess ports.
2054 * This works because the delivery only requires
2055 * as many outputs as there are inputs.
2056 * Delivery::configure_io() will do the actual removal
2057 * by calling _output->ensure_io()
2059 if (!is_master() && _session.master_out ()) {
2060 /* ..but at least as many as there are master-inputs */
2061 // XXX this may need special-casing for mixbus (master-outputs)
2062 // and should maybe be a preference anyway ?!
2063 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
2069 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
2070 configuration.push_back(make_pair(in, out));
2073 // restriction for Monitor Section Processors
2074 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
2075 /* do not allow to add/remove channels (for now)
2076 * The Monitor follows the master-bus and has no panner (unpan)
2077 * but do allow processors with midi-in to be added (e.g VSTs with control that
2078 * will remain unconnected)
2080 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
2081 return list<pair<ChanCount, ChanCount> > ();
2083 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
2084 // internal sends make no sense, only feedback
2085 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2086 return list<pair<ChanCount, ChanCount> > ();
2088 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
2089 /* External Sends can be problematic. one can add/remove ports
2090 * there signal leaves the DAW to external monitors anyway, so there's
2091 * no real use for allowing them here anyway.
2093 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
2094 return list<pair<ChanCount, ChanCount> > ();
2096 if (boost::dynamic_pointer_cast<Send> (*p)) {
2098 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2099 return list<pair<ChanCount, ChanCount> > ();
2108 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
2109 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
2110 DEBUG_TRACE (DEBUG::Processors, "}\n");
2111 return list<pair<ChanCount, ChanCount> > ();
2115 DEBUG_TRACE (DEBUG::Processors, "}\n");
2117 return configuration;
2120 /** Set the input/output configuration of each processor in the processors list.
2121 * Caller must hold process lock.
2122 * Return 0 on success, otherwise configuration is impossible.
2125 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
2127 #ifndef PLATFORM_WINDOWS
2128 assert (!AudioEngine::instance()->process_lock().trylock());
2131 if (_in_configure_processors) {
2135 /* put invisible processors where they should be */
2136 setup_invisible_processors ();
2138 _in_configure_processors = true;
2140 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2142 if (configuration.empty ()) {
2143 _in_configure_processors = false;
2148 bool seen_mains_out = false;
2149 processor_out_streams = _input->n_ports();
2150 processor_max_streams.reset();
2152 /* processor configure_io() may result in adding ports
2153 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
2155 * with jack2 adding ports results in a graph-order callback,
2156 * which calls Session::resort_routes() and eventually
2157 * Route::direct_feeds_according_to_reality()
2158 * which takes a ReaderLock (_processor_lock).
2160 * so we can't hold a WriterLock here until jack2 threading
2163 * NB. we still hold the process lock
2165 * (ardour's own engines do call graph-order from the
2166 * process-thread and hence do not have this issue; besides
2167 * merely adding ports won't trigger a graph-order, only
2168 * making connections does)
2172 // TODO check for a potential ReaderLock after ReaderLock ??
2173 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
2175 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2176 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2178 if (!(*p)->configure_io(c->first, c->second)) {
2179 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2180 _in_configure_processors = false;
2185 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2186 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2188 boost::shared_ptr<IOProcessor> iop;
2189 boost::shared_ptr<PluginInsert> pi;
2190 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2191 /* plugins connected via Split or Hide Match may have more channels.
2192 * route/scratch buffers are needed for all of them
2193 * The configuration may only be a subset (both input and output)
2195 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
2197 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
2198 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
2199 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
2203 if (boost::dynamic_pointer_cast<Delivery> (*p)
2204 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2205 /* main delivery will increase port count to match input.
2206 * the Delivery::Main is usually the last processor - followed only by
2209 seen_mains_out = true;
2211 if (!seen_mains_out) {
2212 processor_out_streams = out;
2221 _meter->set_max_channels (processor_max_streams);
2224 /* make sure we have sufficient scratch buffers to cope with the new processor
2227 _session.ensure_buffers (n_process_buffers ());
2229 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2231 _in_configure_processors = false;
2235 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2236 * @param state New active state for those processors.
2239 Route::all_visible_processors_active (bool state)
2241 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2243 if (_processors.empty()) {
2247 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2248 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2255 (*i)->deactivate ();
2259 _session.set_dirty ();
2263 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2265 /* check if re-order requires re-configuration of any processors
2266 * -> compare channel configuration for all processors
2268 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2269 ChanCount c = input_streams ();
2271 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2273 if (c != (*j)->input_streams()) {
2276 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2279 if ((*i)->input_streams() != c) {
2282 c = (*i)->output_streams();
2294 __attribute__((annotate("realtime")))
2297 Route::apply_processor_order (const ProcessorList& new_order)
2299 /* need to hold processor_lock; either read or write lock
2300 * and the engine process_lock.
2301 * Due to r/w lock ambiguity we can only assert the latter
2303 assert (!AudioEngine::instance()->process_lock().trylock());
2306 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2307 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2308 * processors in the current actual processor list that are hidden. Any visible processors
2309 * in the current list but not in "new_order" will be assumed to be deleted.
2312 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2313 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2314 * (note though that ::processors_reorder_needs_configure() ensured that
2315 * this function will only ever be called from the rt-thread if no processor were removed)
2317 * either way, I can't proove it, but an x-run due to re-order here is less likley
2318 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2321 ProcessorList as_it_will_be;
2322 ProcessorList::iterator oiter;
2323 ProcessorList::const_iterator niter;
2325 oiter = _processors.begin();
2326 niter = new_order.begin();
2328 while (niter != new_order.end()) {
2330 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2331 then append it to the temp list.
2333 Otherwise, see if the next processor in the old list is in the new list. if not,
2334 its been deleted. If its there, append it to the temp list.
2337 if (oiter == _processors.end()) {
2339 /* no more elements in the old list, so just stick the rest of
2340 the new order onto the temp list.
2343 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2344 while (niter != new_order.end()) {
2351 if (!(*oiter)->display_to_user()) {
2353 as_it_will_be.push_back (*oiter);
2357 /* visible processor: check that its in the new order */
2359 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2360 /* deleted: do nothing, shared_ptr<> will clean up */
2362 /* ignore this one, and add the next item from the new order instead */
2363 as_it_will_be.push_back (*niter);
2368 /* now remove from old order - its taken care of no matter what */
2369 oiter = _processors.erase (oiter);
2373 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2375 /* If the meter is in a custom position, find it and make a rough note of its position */
2376 maybe_note_meter_position ();
2380 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2382 // it a change is already queued, wait for it
2383 // (unless engine is stopped. apply immediately and proceed
2384 while (g_atomic_int_get (&_pending_process_reorder)) {
2385 if (!AudioEngine::instance()->running()) {
2386 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2387 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2389 apply_processor_order(_pending_processor_order);
2390 setup_invisible_processors ();
2392 g_atomic_int_set (&_pending_process_reorder, 0);
2394 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2395 set_processor_positions ();
2397 // TODO rather use a semaphore or something.
2398 // but since ::reorder_processors() is called
2399 // from the GUI thread, this is fine..
2404 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2406 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2407 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2408 ProcessorState pstate (this);
2410 apply_processor_order (new_order);
2412 if (configure_processors_unlocked (err, &lm)) {
2420 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2421 set_processor_positions ();
2424 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2425 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2427 // _pending_processor_order is protected by _processor_lock
2428 _pending_processor_order = new_order;
2429 g_atomic_int_set (&_pending_process_reorder, 1);
2436 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2438 boost::shared_ptr<PluginInsert> pi;
2439 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2443 if (pi->has_sidechain () == add) {
2444 return true; // ?? call failed, but result is as expected.
2448 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2449 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2450 if (i == _processors.end ()) {
2456 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2457 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2458 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2460 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2462 if (!pi->add_sidechain ()) {
2466 if (!pi->del_sidechain ()) {
2472 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2477 pi->del_sidechain ();
2479 pi->add_sidechain ();
2480 // TODO restore side-chain's state.
2485 configure_processors_unlocked (0, &lm);
2488 if (pi->has_sidechain ()) {
2489 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2492 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2493 _session.set_dirty ();
2498 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2500 boost::shared_ptr<PluginInsert> pi;
2501 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2506 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2507 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2508 if (i == _processors.end ()) {
2514 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2515 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2517 const ChanCount& old (pi->preset_out ());
2518 if (!pi->set_preset_out (outs)) {
2519 return true; // no change, OK
2522 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2525 pi->set_preset_out (old);
2528 configure_processors_unlocked (0, &lm);
2531 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2532 _session.set_dirty ();
2537 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2540 return customize_plugin_insert (proc, 0, unused, unused);
2544 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2546 boost::shared_ptr<PluginInsert> pi;
2547 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2552 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2553 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2554 if (i == _processors.end ()) {
2560 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2561 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2563 bool old_cust = pi->custom_cfg ();
2564 uint32_t old_cnt = pi->get_count ();
2565 ChanCount old_chan = pi->output_streams ();
2566 ChanCount old_sinks = pi->natural_input_streams ();
2569 pi->set_custom_cfg (false);
2571 pi->set_custom_cfg (true);
2572 pi->set_count (count);
2573 pi->set_outputs (outs);
2574 pi->set_sinks (sinks);
2577 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2581 pi->set_count (old_cnt);
2582 pi->set_sinks (old_sinks);
2583 pi->set_outputs (old_chan);
2584 pi->set_custom_cfg (old_cust);
2588 configure_processors_unlocked (0, &lm);
2591 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2592 _session.set_dirty ();
2597 Route::set_strict_io (const bool enable)
2599 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2601 if (_strict_io != enable) {
2602 _strict_io = enable;
2603 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2604 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2605 boost::shared_ptr<PluginInsert> pi;
2606 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2607 pi->set_strict_io (_strict_io);
2611 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2615 _strict_io = !enable; // restore old value
2616 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2617 boost::shared_ptr<PluginInsert> pi;
2618 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2619 pi->set_strict_io (_strict_io);
2626 configure_processors (0);
2629 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2630 _session.set_dirty ();
2642 Route::get_template()
2644 return state(false);
2648 Route::state(bool full_state)
2651 if (!_session._template_state_dir.empty()) {
2652 assert (!full_state); // only for templates
2653 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2656 XMLNode *node = new XMLNode("Route");
2657 ProcessorList::iterator i;
2660 id().print (buf, sizeof (buf));
2661 node->add_property("id", buf);
2662 node->add_property ("name", _name);
2663 node->add_property("default-type", _default_type.to_string());
2664 node->add_property ("strict-io", _strict_io);
2667 node->add_property("flags", enum_2_string (_flags));
2670 node->add_property("active", _active?"yes":"no");
2672 boost::to_string (_phase_invert, p);
2673 node->add_property("phase-invert", p);
2674 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2675 node->add_property("meter-point", enum_2_string (_meter_point));
2677 node->add_property("meter-type", enum_2_string (_meter_type));
2680 node->add_property("route-group", _route_group->name());
2683 snprintf (buf, sizeof (buf), "%d", _order_key);
2684 node->add_property ("order-key", buf);
2685 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2686 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2687 node->add_property ("soloed-by-upstream", buf);
2688 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2689 node->add_property ("soloed-by-downstream", buf);
2690 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2691 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2693 node->add_child_nocopy (_input->state (full_state));
2694 node->add_child_nocopy (_output->state (full_state));
2695 node->add_child_nocopy (_solo_control->get_state ());
2696 node->add_child_nocopy (_mute_control->get_state ());
2697 node->add_child_nocopy (_mute_master->get_state ());
2700 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2703 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2704 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2705 remote_control_node->add_property (X_("id"), buf);
2706 node->add_child_nocopy (*remote_control_node);
2708 if (_comment.length()) {
2709 XMLNode *cmt = node->add_child ("Comment");
2710 cmt->add_content (_comment);
2714 node->add_child_nocopy (_pannable->state (full_state));
2717 for (i = _processors.begin(); i != _processors.end(); ++i) {
2719 /* template save: do not include internal sends functioning as
2720 aux sends because the chance of the target ID
2721 in the session where this template is used
2724 similarly, do not save listen sends which connect to
2725 the monitor section, because these will always be
2728 boost::shared_ptr<InternalSend> is;
2730 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2731 if (is->role() == Delivery::Listen) {
2736 node->add_child_nocopy((*i)->state (full_state));
2740 node->add_child_copy (*_extra_xml);
2743 if (_custom_meter_position_noted) {
2744 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2746 after->id().print (buf, sizeof (buf));
2747 node->add_property (X_("processor-after-last-custom-meter"), buf);
2751 if (!_session._template_state_dir.empty()) {
2752 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2759 Route::set_state (const XMLNode& node, int version)
2761 if (version < 3000) {
2762 return set_state_2X (node, version);
2766 XMLNodeConstIterator niter;
2768 XMLProperty const * prop;
2770 if (node.name() != "Route"){
2771 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2775 if ((prop = node.property (X_("name"))) != 0) {
2776 Route::set_name (prop->value());
2780 _initial_io_setup = true;
2782 if ((prop = node.property (X_("flags"))) != 0) {
2783 _flags = Flag (string_2_enum (prop->value(), _flags));
2788 if ((prop = node.property (X_("strict-io"))) != 0) {
2789 _strict_io = string_is_affirmative (prop->value());
2792 if (is_master() || is_monitor() || is_auditioner()) {
2793 _mute_master->set_solo_ignore (true);
2797 /* monitor bus does not get a panner, but if (re)created
2798 via XML, it will already have one by the time we
2799 call ::set_state(). so ... remove it.
2804 /* add all processors (except amp, which is always present) */
2806 nlist = node.children();
2807 XMLNode processor_state (X_("processor_state"));
2809 Stateful::save_extra_xml (node);
2811 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2815 if (child->name() == IO::state_node_name) {
2816 if ((prop = child->property (X_("direction"))) == 0) {
2820 if (prop->value() == "Input") {
2821 _input->set_state (*child, version);
2822 } else if (prop->value() == "Output") {
2823 _output->set_state (*child, version);
2827 if (child->name() == X_("Processor")) {
2828 processor_state.add_child_copy (*child);
2831 if (child->name() == X_("Pannable")) {
2833 _pannable->set_state (*child, version);
2835 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2840 if ((prop = node.property (X_("meter-point"))) != 0) {
2841 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2842 set_meter_point (mp, true);
2844 _meter->set_display_to_user (_meter_point == MeterCustom);
2848 if ((prop = node.property (X_("meter-type"))) != 0) {
2849 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2852 _initial_io_setup = false;
2854 set_processor_state (processor_state);
2856 // this looks up the internal instrument in processors
2857 reset_instrument_info();
2859 if ((prop = node.property ("self-solo")) != 0) {
2860 set_self_solo (string_is_affirmative (prop->value()));
2863 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2864 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2865 mod_solo_by_others_upstream (atoi (prop->value()));
2868 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2869 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2870 mod_solo_by_others_downstream (atoi (prop->value()));
2873 if ((prop = node.property ("solo-isolated")) != 0) {
2874 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2877 if ((prop = node.property ("solo-safe")) != 0) {
2878 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2881 if ((prop = node.property (X_("phase-invert"))) != 0) {
2882 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2885 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2886 set_denormal_protection (string_is_affirmative (prop->value()));
2889 if ((prop = node.property (X_("active"))) != 0) {
2890 bool yn = string_is_affirmative (prop->value());
2891 set_active (yn, this);
2894 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2895 set_order_key (atoi(prop->value()));
2898 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2902 string::size_type colon, equal;
2903 string remaining = prop->value();
2905 while (remaining.length()) {
2907 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2908 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2911 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2912 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2915 string keyname = remaining.substr (0, equal);
2917 if ((keyname == "EditorSort") || (keyname == "editor")) {
2918 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2924 colon = remaining.find_first_of (':');
2926 if (colon != string::npos) {
2927 remaining = remaining.substr (colon+1);
2934 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2935 PBD::ID id (prop->value ());
2936 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2937 ProcessorList::const_iterator i = _processors.begin ();
2938 while (i != _processors.end() && (*i)->id() != id) {
2942 if (i != _processors.end ()) {
2943 _processor_after_last_custom_meter = *i;
2944 _custom_meter_position_noted = true;
2948 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2951 if (child->name() == X_("Comment")) {
2953 /* XXX this is a terrible API design in libxml++ */
2955 XMLNode *cmt = *(child->children().begin());
2956 _comment = cmt->content();
2958 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2959 if (prop->value() == "solo") {
2960 _solo_control->set_state (*child, version);
2961 } else if (prop->value() == "mute") {
2962 _mute_control->set_state (*child, version);
2965 } else if (child->name() == X_("RemoteControl")) {
2966 if ((prop = child->property (X_("id"))) != 0) {
2968 sscanf (prop->value().c_str(), "%d", &x);
2969 set_remote_control_id_internal (x);
2972 } else if (child->name() == X_("MuteMaster")) {
2973 _mute_master->set_state (*child, version);
2975 } else if (child->name() == Automatable::xml_node_name) {
2976 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2984 Route::set_state_2X (const XMLNode& node, int version)
2988 XMLNodeConstIterator niter;
2990 XMLProperty const * prop;
2992 /* 2X things which still remain to be handled:
2998 if (node.name() != "Route") {
2999 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
3003 if ((prop = node.property (X_("flags"))) != 0) {
3004 string f = prop->value ();
3005 boost::replace_all (f, "ControlOut", "MonitorOut");
3006 _flags = Flag (string_2_enum (f, _flags));
3011 if (is_master() || is_monitor() || is_auditioner()) {
3012 _mute_master->set_solo_ignore (true);
3015 if ((prop = node.property (X_("phase-invert"))) != 0) {
3016 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
3017 if (string_is_affirmative (prop->value ())) {
3020 set_phase_invert (p);
3023 if ((prop = node.property (X_("denormal-protection"))) != 0) {
3024 set_denormal_protection (string_is_affirmative (prop->value()));
3027 if ((prop = node.property (X_("soloed"))) != 0) {
3028 bool yn = string_is_affirmative (prop->value());
3030 /* XXX force reset of solo status */
3035 if ((prop = node.property (X_("muted"))) != 0) {
3038 bool muted = string_is_affirmative (prop->value());
3044 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
3046 if (string_is_affirmative (prop->value())){
3047 mute_point = mute_point + "PreFader";
3052 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
3054 if (string_is_affirmative (prop->value())){
3057 mute_point = mute_point + ",";
3060 mute_point = mute_point + "PostFader";
3065 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
3067 if (string_is_affirmative (prop->value())){
3070 mute_point = mute_point + ",";
3073 mute_point = mute_point + "Listen";
3078 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
3080 if (string_is_affirmative (prop->value())){
3083 mute_point = mute_point + ",";
3086 mute_point = mute_point + "Main";
3090 _mute_master->set_mute_points (mute_point);
3091 _mute_master->set_muted_by_self (true);
3095 if ((prop = node.property (X_("meter-point"))) != 0) {
3096 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
3099 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
3100 don't mean the same thing.
3103 if ((prop = node.property (X_("order-keys"))) != 0) {
3107 string::size_type colon, equal;
3108 string remaining = prop->value();
3110 while (remaining.length()) {
3112 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
3113 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3116 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
3117 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3120 string keyname = remaining.substr (0, equal);
3122 if (keyname == "EditorSort" || keyname == "editor") {
3123 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
3129 colon = remaining.find_first_of (':');
3131 if (colon != string::npos) {
3132 remaining = remaining.substr (colon+1);
3141 nlist = node.children ();
3142 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3146 if (child->name() == IO::state_node_name) {
3148 /* there is a note in IO::set_state_2X() about why we have to call
3152 _input->set_state_2X (*child, version, true);
3153 _output->set_state_2X (*child, version, false);
3155 if ((prop = child->property (X_("name"))) != 0) {
3156 Route::set_name (prop->value ());
3161 if ((prop = child->property (X_("active"))) != 0) {
3162 bool yn = string_is_affirmative (prop->value());
3163 _active = !yn; // force switch
3164 set_active (yn, this);
3167 if ((prop = child->property (X_("gain"))) != 0) {
3170 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
3171 _amp->gain_control()->set_value (val, Controllable::NoGroup);
3175 /* Set up Panners in the IO */
3176 XMLNodeList io_nlist = child->children ();
3178 XMLNodeConstIterator io_niter;
3181 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
3183 io_child = *io_niter;
3185 if (io_child->name() == X_("Panner")) {
3186 _main_outs->panner_shell()->set_state(*io_child, version);
3187 } else if (io_child->name() == X_("Automation")) {
3188 /* IO's automation is for the fader */
3189 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
3195 XMLNodeList redirect_nodes;
3197 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3201 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
3202 redirect_nodes.push_back(child);
3207 set_processor_state_2X (redirect_nodes, version);
3209 Stateful::save_extra_xml (node);
3211 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3214 if (child->name() == X_("Comment")) {
3216 /* XXX this is a terrible API design in libxml++ */
3218 XMLNode *cmt = *(child->children().begin());
3219 _comment = cmt->content();
3221 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3222 if (prop->value() == X_("solo")) {
3223 _solo_control->set_state (*child, version);
3224 } else if (prop->value() == X_("mute")) {
3225 _mute_control->set_state (*child, version);
3228 } else if (child->name() == X_("RemoteControl")) {
3229 if ((prop = child->property (X_("id"))) != 0) {
3231 sscanf (prop->value().c_str(), "%d", &x);
3232 set_remote_control_id_internal (x);
3242 Route::get_processor_state ()
3244 XMLNode* root = new XMLNode (X_("redirects"));
3245 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3246 root->add_child_nocopy ((*i)->state (true));
3253 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
3255 /* We don't bother removing existing processors not in nList, as this
3256 method will only be called when creating a Route from scratch, not
3257 for undo purposes. Just put processors in at the appropriate place
3261 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
3262 add_processor_from_xml_2X (**i, version);
3267 Route::set_processor_state (const XMLNode& node)
3269 const XMLNodeList &nlist = node.children();
3270 XMLNodeConstIterator niter;
3271 ProcessorList new_order;
3272 bool must_configure = false;
3274 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3276 XMLProperty const * prop = (*niter)->property ("type");
3278 if (prop->value() == "amp") {
3279 _amp->set_state (**niter, Stateful::current_state_version);
3280 new_order.push_back (_amp);
3281 } else if (prop->value() == "trim") {
3282 _trim->set_state (**niter, Stateful::current_state_version);
3283 new_order.push_back (_trim);
3284 } else if (prop->value() == "meter") {
3285 _meter->set_state (**niter, Stateful::current_state_version);
3286 new_order.push_back (_meter);
3287 } else if (prop->value() == "delay") {
3289 _delayline->set_state (**niter, Stateful::current_state_version);
3290 new_order.push_back (_delayline);
3292 } else if (prop->value() == "main-outs") {
3293 _main_outs->set_state (**niter, Stateful::current_state_version);
3294 } else if (prop->value() == "intreturn") {
3296 _intreturn.reset (new InternalReturn (_session));
3297 must_configure = true;
3299 _intreturn->set_state (**niter, Stateful::current_state_version);
3300 } else if (is_monitor() && prop->value() == "monitor") {
3301 if (!_monitor_control) {
3302 _monitor_control.reset (new MonitorProcessor (_session));
3303 must_configure = true;
3305 _monitor_control->set_state (**niter, Stateful::current_state_version);
3306 } else if (prop->value() == "capture") {
3307 /* CapturingProcessor should never be restored, it's always
3308 added explicitly when needed */
3310 ProcessorList::iterator o;
3312 for (o = _processors.begin(); o != _processors.end(); ++o) {
3313 XMLProperty const * id_prop = (*niter)->property(X_("id"));
3314 if (id_prop && (*o)->id() == id_prop->value()) {
3315 (*o)->set_state (**niter, Stateful::current_state_version);
3316 new_order.push_back (*o);
3321 // If the processor (*niter) is not on the route then create it
3323 if (o == _processors.end()) {
3325 boost::shared_ptr<Processor> processor;
3327 if (prop->value() == "intsend") {
3329 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3331 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3332 prop->value() == "lv2" ||
3333 prop->value() == "windows-vst" ||
3334 prop->value() == "lxvst" ||
3335 prop->value() == "luaproc" ||
3336 prop->value() == "audiounit") {
3338 if (_session.get_disable_all_loaded_plugins ()) {
3339 processor.reset (new UnknownProcessor (_session, **niter));
3341 processor.reset (new PluginInsert (_session));
3342 processor->set_owner (this);
3344 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3345 pi->set_strict_io (true);
3349 } else if (prop->value() == "port") {
3351 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3353 } else if (prop->value() == "send") {
3355 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3356 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3357 send->SelfDestruct.connect_same_thread (*this,
3358 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3361 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3365 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3366 /* This processor could not be configured. Turn it into a UnknownProcessor */
3367 processor.reset (new UnknownProcessor (_session, **niter));
3370 /* subscribe to Sidechain IO changes */
3371 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3372 if (pi && pi->has_sidechain ()) {
3373 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3376 /* we have to note the monitor send here, otherwise a new one will be created
3377 and the state of this one will be lost.
3379 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3380 if (isend && isend->role() == Delivery::Listen) {
3381 _monitor_send = isend;
3384 /* it doesn't matter if invisible processors are added here, as they
3385 will be sorted out by setup_invisible_processors () shortly.
3388 new_order.push_back (processor);
3389 must_configure = true;
3395 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3396 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3397 _processors = new_order;
3399 if (must_configure) {
3400 configure_processors_unlocked (0, &lm);
3403 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3405 (*i)->set_owner (this);
3406 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3408 boost::shared_ptr<PluginInsert> pi;
3410 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3411 if (pi->has_no_inputs ()) {
3412 _have_internal_generator = true;
3419 reset_instrument_info ();
3420 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3421 set_processor_positions ();
3425 Route::curve_reallocate ()
3427 // _gain_automation_curve.finish_resize ();
3428 // _pan_automation_curve.finish_resize ();
3432 Route::silence (framecnt_t nframes)
3434 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3439 silence_unlocked (nframes);
3443 Route::silence_unlocked (framecnt_t nframes)
3445 /* Must be called with the processor lock held */
3449 _output->silence (nframes);
3451 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3452 boost::shared_ptr<PluginInsert> pi;
3454 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3455 // skip plugins, they don't need anything when we're not active
3459 (*i)->silence (nframes);
3462 if (nframes == _session.get_block_size()) {
3469 Route::add_internal_return ()
3472 _intreturn.reset (new InternalReturn (_session));
3473 add_processor (_intreturn, PreFader);
3478 Route::add_send_to_internal_return (InternalSend* send)
3480 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3482 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3483 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3486 return d->add_send (send);
3492 Route::remove_send_from_internal_return (InternalSend* send)
3494 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3496 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3497 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3500 return d->remove_send (send);
3506 Route::enable_monitor_send ()
3508 /* Caller must hold process lock */
3509 assert (!AudioEngine::instance()->process_lock().trylock());
3511 /* master never sends to monitor section via the normal mechanism */
3512 assert (!is_master ());
3513 assert (!is_monitor ());
3515 /* make sure we have one */
3516 if (!_monitor_send) {
3517 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3518 _monitor_send->set_display_to_user (false);
3522 configure_processors (0);
3525 /** Add an aux send to a route.
3526 * @param route route to send to.
3527 * @param before Processor to insert before, or 0 to insert at the end.
3530 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3532 assert (route != _session.monitor_out ());
3535 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3537 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3539 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3541 if (d && d->target_route() == route) {
3542 /* already listening via the specified IO: do nothing */
3550 boost::shared_ptr<InternalSend> listener;
3553 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3554 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3555 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3558 add_processor (listener, before);
3560 } catch (failed_constructor& err) {
3568 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3570 ProcessorStreams err;
3571 ProcessorList::iterator tmp;
3574 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3576 /* have to do this early because otherwise processor reconfig
3577 * will put _monitor_send back in the list
3580 if (route == _session.monitor_out()) {
3581 _monitor_send.reset ();
3585 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3587 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3589 if (d && d->target_route() == route) {
3591 if (remove_processor (*x, &err, false) > 0) {
3597 /* list could have been demolished while we dropped the lock
3600 if (_session.engine().connected()) {
3601 /* i/o processors cannot be removed if the engine is not running
3602 * so don't live-loop in case the engine is N/A or dies
3612 Route::set_comment (string cmt, void *src)
3616 _session.set_dirty ();
3620 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3622 FeedRecord fr (other, via_sends_only);
3624 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3626 if (!result.second) {
3628 /* already a record for "other" - make sure sends-only information is correct */
3629 if (!via_sends_only && result.first->sends_only) {
3630 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3631 frp->sends_only = false;
3635 return result.second;
3639 Route::clear_fed_by ()
3645 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3647 const FedBy& fed_by (other->fed_by());
3649 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3650 boost::shared_ptr<Route> sr = f->r.lock();
3652 if (sr && (sr.get() == this)) {
3654 if (via_sends_only) {
3655 *via_sends_only = f->sends_only;
3666 Route::all_inputs () const
3668 /* TODO, if this works as expected,
3669 * cache the IOVector and maintain it via
3670 * input_change_handler(), sidechain_change_handler() etc
3673 ios.push_back (_input);
3675 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3676 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3678 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3679 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3682 iop = pi->sidechain();
3685 if (iop != 0 && iop->input()) {
3686 ios.push_back (iop->input());
3693 Route::all_outputs () const
3696 // _output is included via Delivery
3697 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3698 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3699 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3700 if (iop != 0 && iop->output()) {
3701 ios.push_back (iop->output());
3708 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3710 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3711 if (other->all_inputs().fed_by (_output)) {
3712 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3713 if (via_send_only) {
3714 *via_send_only = false;
3720 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3722 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3724 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3725 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3728 iop = pi->sidechain();
3732 boost::shared_ptr<const IO> iop_out = iop->output();
3733 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3734 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3735 if (via_send_only) {
3736 *via_send_only = true;
3740 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3743 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3748 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3753 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3755 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3759 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3761 return _session._current_route_graph.feeds (shared_from_this (), other);
3764 /** Called from the (non-realtime) butler thread when the transport is stopped */
3766 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3768 framepos_t now = _session.transport_frame();
3771 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3773 Automatable::transport_stopped (now);
3775 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3777 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3781 (*i)->transport_stopped (now);
3785 _roll_delay = _initial_delay;
3789 Route::input_change_handler (IOChange change, void * /*src*/)
3791 if ((change.type & IOChange::ConfigurationChanged)) {
3792 /* This is called with the process lock held if change
3793 contains ConfigurationChanged
3795 configure_processors (0);
3796 _phase_invert.resize (_input->n_ports().n_audio ());
3797 io_changed (); /* EMIT SIGNAL */
3800 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3803 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3804 if (_input->connected()) {
3805 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3806 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3810 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3811 if (does_feed && !sends_only) {
3812 if ((*i)->soloed()) {
3815 if ((*i)->solo_isolated()) {
3822 int delta = sbou - _soloed_by_others_upstream;
3823 int idelta = ibou - _solo_isolated_by_upstream;
3826 PBD::warning << string_compose (
3827 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3828 _name, ibou, _solo_isolated_by_upstream, idelta)
3833 if (_soloed_by_others_upstream) {
3834 // ignore new connections (they're not propagated)
3836 mod_solo_by_others_upstream (delta);
3840 if (_solo_isolated_by_upstream) {
3841 // solo-isolate currently only propagates downstream
3843 mod_solo_isolated_by_upstream (false);
3845 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3846 // but idelta can't be smaller than -1, can it?
3847 //_solo_isolated_by_upstream = ibou;
3850 // Session::route_solo_changed does not propagate indirect solo-changes
3851 // propagate downstream to tracks
3852 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3853 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3857 bool does_feed = feeds (*i, &sends_only);
3858 if (delta <= 0 && does_feed && !sends_only) {
3859 (*i)->mod_solo_by_others_upstream (delta);
3862 if (idelta < 0 && does_feed && !sends_only) {
3863 (*i)->mod_solo_isolated_by_upstream (false);
3870 Route::output_change_handler (IOChange change, void * /*src*/)
3872 if (_initial_io_setup) {
3876 if ((change.type & IOChange::ConfigurationChanged)) {
3877 /* This is called with the process lock held if change
3878 contains ConfigurationChanged
3880 configure_processors (0);
3883 _session.reset_monitor_section();
3886 io_changed (); /* EMIT SIGNAL */
3889 if (_soloed_by_others_downstream) {
3891 /* checking all all downstream routes for
3892 * explicit of implict solo is a rather drastic measure,
3893 * ideally the input_change_handler() of the other route
3894 * would propagate the change to us.
3896 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3897 if (_output->connected()) {
3898 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3899 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3903 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3904 if (does_feed && !sends_only) {
3905 if ((*i)->soloed()) {
3912 int delta = sbod - _soloed_by_others_downstream;
3914 // do not allow new connections to change implicit solo (no propagation)
3915 mod_solo_by_others_downstream (delta);
3916 // Session::route_solo_changed() does not propagate indirect solo-changes
3917 // propagate upstream to tracks
3918 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3919 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3923 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3924 if (delta != 0 && does_feed && !sends_only) {
3925 (*i)->mod_solo_by_others_downstream (delta);
3934 Route::sidechain_change_handler (IOChange change, void* src)
3936 if (_initial_io_setup || _in_sidechain_setup) {
3940 input_change_handler (change, src);
3944 Route::pans_required () const
3946 if (n_outputs().n_audio() < 2) {
3950 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3954 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3956 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3962 if (n_outputs().n_total() == 0) {
3966 if (!_active || n_inputs() == ChanCount::ZERO) {
3967 silence_unlocked (nframes);
3971 if (session_state_changing) {
3972 if (_session.transport_speed() != 0.0f) {
3973 /* we're rolling but some state is changing (e.g. our diskstream contents)
3974 so we cannot use them. Be silent till this is over.
3976 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3978 silence_unlocked (nframes);
3981 /* we're really not rolling, so we're either delivery silence or actually
3982 monitoring, both of which are safe to do while session_state_changing is true.
3986 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3988 fill_buffers_with_input (bufs, _input, nframes);
3990 if (_meter_point == MeterInput) {
3991 _meter->run (bufs, start_frame, end_frame, nframes, true);
3994 _amp->apply_gain_automation (false);
3995 _trim->apply_gain_automation (false);
3996 passthru (bufs, start_frame, end_frame, nframes, 0);
4002 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
4004 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4009 if (n_outputs().n_total() == 0) {
4013 if (!_active || n_inputs().n_total() == 0) {
4014 silence_unlocked (nframes);
4018 framepos_t unused = 0;
4020 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
4026 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4028 fill_buffers_with_input (bufs, _input, nframes);
4030 if (_meter_point == MeterInput) {
4031 _meter->run (bufs, start_frame, end_frame, nframes, true);
4034 passthru (bufs, start_frame, end_frame, nframes, declick);
4040 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
4047 Route::flush_processors ()
4049 /* XXX shouldn't really try to take this lock, since
4050 this is called from the RT audio thread.
4053 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4055 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4061 __attribute__((annotate("realtime")))
4064 Route::apply_processor_changes_rt ()
4066 int emissions = EmitNone;
4068 if (_pending_meter_point != _meter_point) {
4069 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4071 /* meters always have buffers for 'processor_max_streams'
4072 * they can be re-positioned without re-allocation */
4073 if (set_meter_point_unlocked()) {
4074 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
4076 emissions |= EmitMeterChanged;
4081 bool changed = false;
4083 if (g_atomic_int_get (&_pending_process_reorder)) {
4084 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4086 apply_processor_order (_pending_processor_order);
4087 setup_invisible_processors ();
4089 g_atomic_int_set (&_pending_process_reorder, 0);
4090 emissions |= EmitRtProcessorChange;
4094 set_processor_positions ();
4096 if (emissions != 0) {
4097 g_atomic_int_set (&_pending_signals, emissions);
4100 return (!selfdestruct_sequence.empty ());
4104 Route::emit_pending_signals ()
4106 int sig = g_atomic_int_and (&_pending_signals, 0);
4107 if (sig & EmitMeterChanged) {
4108 _meter->emit_configuration_changed();
4109 meter_change (); /* EMIT SIGNAL */
4110 if (sig & EmitMeterVisibilityChange) {
4111 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4113 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4116 if (sig & EmitRtProcessorChange) {
4117 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
4120 /* this would be a job for the butler.
4121 * Conceptually we should not take processe/processor locks here.
4122 * OTOH its more efficient (less overhead for summoning the butler and
4123 * telling her what do do) and signal emission is called
4124 * directly after the process callback, which decreases the chance
4125 * of x-runs when taking the locks.
4127 while (!selfdestruct_sequence.empty ()) {
4128 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
4129 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
4130 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
4131 selfdestruct_sequence.pop_back ();
4134 remove_processor (proc);
4140 Route::set_meter_point (MeterPoint p, bool force)
4142 if (_pending_meter_point == p && !force) {
4146 if (force || !AudioEngine::instance()->running()) {
4147 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4148 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4149 _pending_meter_point = p;
4150 _meter->emit_configuration_changed();
4151 meter_change (); /* EMIT SIGNAL */
4152 if (set_meter_point_unlocked()) {
4153 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4155 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4158 _pending_meter_point = p;
4164 __attribute__((annotate("realtime")))
4167 Route::set_meter_point_unlocked ()
4170 /* Caller must hold process and processor write lock */
4171 assert (!AudioEngine::instance()->process_lock().trylock());
4172 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4173 assert (!lm.locked ());
4176 _meter_point = _pending_meter_point;
4178 bool meter_was_visible_to_user = _meter->display_to_user ();
4180 if (!_custom_meter_position_noted) {
4181 maybe_note_meter_position ();
4184 if (_meter_point != MeterCustom) {
4186 _meter->set_display_to_user (false);
4188 setup_invisible_processors ();
4191 _meter->set_display_to_user (true);
4193 /* If we have a previous position for the custom meter, try to put it there */
4194 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
4196 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
4197 if (i != _processors.end ()) {
4198 _processors.remove (_meter);
4199 _processors.insert (i, _meter);
4201 } else {// at end, right before the mains_out/panner
4202 _processors.remove (_meter);
4203 ProcessorList::iterator main = _processors.end();
4204 _processors.insert (--main, _meter);
4208 /* Set up the meter for its new position */
4210 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4214 if (loc == _processors.begin()) {
4215 m_in = _input->n_ports();
4217 ProcessorList::iterator before = loc;
4219 m_in = (*before)->output_streams ();
4222 _meter->reflect_inputs (m_in);
4224 /* we do not need to reconfigure the processors, because the meter
4225 (a) is always ready to handle processor_max_streams
4226 (b) is always an N-in/N-out processor, and thus moving
4227 it doesn't require any changes to the other processors.
4230 /* these should really be done after releasing the lock
4231 * but all those signals are subscribed to with gui_thread()
4234 return (_meter->display_to_user() != meter_was_visible_to_user);
4238 Route::listen_position_changed ()
4241 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4242 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4243 ProcessorState pstate (this);
4245 if (configure_processors_unlocked (0, &lm)) {
4246 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4248 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4253 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4254 _session.set_dirty ();
4257 boost::shared_ptr<CapturingProcessor>
4258 Route::add_export_point()
4260 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4261 if (!_capturing_processor) {
4263 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4264 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4266 _capturing_processor.reset (new CapturingProcessor (_session));
4267 _capturing_processor->activate ();
4269 configure_processors_unlocked (0, &lw);
4273 return _capturing_processor;
4277 Route::update_signal_latency ()
4279 framecnt_t l = _output->user_latency();
4280 framecnt_t lamp = 0;
4281 bool before_amp = true;
4282 framecnt_t ltrim = 0;
4283 bool before_trim = true;
4285 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4286 if ((*i)->active ()) {
4287 l += (*i)->signal_latency ();
4292 if ((*i) == _trim) {
4303 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
4305 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
4306 _signal_latency_at_amp_position = lamp;
4307 _signal_latency_at_trim_position = ltrim;
4309 if (_signal_latency != l) {
4310 _signal_latency = l;
4311 signal_latency_changed (); /* EMIT SIGNAL */
4314 return _signal_latency;
4318 Route::set_user_latency (framecnt_t nframes)
4320 _output->set_user_latency (nframes);
4321 _session.update_latency_compensation ();
4325 Route::set_latency_compensation (framecnt_t longest_session_latency)
4327 framecnt_t old = _initial_delay;
4329 if (_signal_latency < longest_session_latency) {
4330 _initial_delay = longest_session_latency - _signal_latency;
4335 DEBUG_TRACE (DEBUG::Latency, string_compose (
4336 "%1: compensate for maximum latency of %2,"
4337 "given own latency of %3, using initial delay of %4\n",
4338 name(), longest_session_latency, _signal_latency, _initial_delay));
4340 if (_initial_delay != old) {
4341 initial_delay_changed (); /* EMIT SIGNAL */
4344 if (_session.transport_stopped()) {
4345 _roll_delay = _initial_delay;
4350 Route::set_block_size (pframes_t nframes)
4352 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4353 (*i)->set_block_size (nframes);
4356 _session.ensure_buffers (n_process_buffers ());
4360 Route::protect_automation ()
4362 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4363 (*i)->protect_automation();
4366 /** @param declick 1 to set a pending declick fade-in,
4367 * -1 to set a pending declick fade-out
4370 Route::set_pending_declick (int declick)
4373 /* this call is not allowed to turn off a pending declick */
4375 _pending_declick = declick;
4378 _pending_declick = 0;
4382 /** Shift automation forwards from a particular place, thereby inserting time.
4383 * Adds undo commands for any shifts that are performed.
4385 * @param pos Position to start shifting from.
4386 * @param frames Amount to shift forwards by.
4390 Route::shift (framepos_t pos, framecnt_t frames)
4392 /* gain automation */
4394 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4396 XMLNode &before = gc->alist()->get_state ();
4397 gc->alist()->shift (pos, frames);
4398 XMLNode &after = gc->alist()->get_state ();
4399 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4402 /* gain automation */
4404 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4406 XMLNode &before = gc->alist()->get_state ();
4407 gc->alist()->shift (pos, frames);
4408 XMLNode &after = gc->alist()->get_state ();
4409 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4412 // TODO mute automation ??
4414 /* pan automation */
4416 ControlSet::Controls& c (_pannable->controls());
4418 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4419 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4421 boost::shared_ptr<AutomationList> al = pc->alist();
4422 XMLNode& before = al->get_state ();
4423 al->shift (pos, frames);
4424 XMLNode& after = al->get_state ();
4425 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4430 /* redirect automation */
4432 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4433 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4435 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4437 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4438 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4440 boost::shared_ptr<AutomationList> al = ac->alist();
4441 XMLNode &before = al->get_state ();
4442 al->shift (pos, frames);
4443 XMLNode &after = al->get_state ();
4444 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4452 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4454 boost::shared_ptr<Processor> processor (p.lock ());
4455 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4459 pi->set_state_dir (d);
4463 Route::save_as_template (const string& path, const string& name)
4465 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4466 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4468 XMLNode& node (state (false));
4472 IO::set_name_in_state (*node.children().front(), name);
4474 tree.set_root (&node);
4476 /* return zero on success, non-zero otherwise */
4477 return !tree.write (path.c_str());
4482 Route::set_name (const string& str)
4484 if (str == name()) {
4488 string name = Route::ensure_track_or_route_name (str, _session);
4489 SessionObject::set_name (name);
4491 bool ret = (_input->set_name(name) && _output->set_name(name));
4494 /* rename the main outs. Leave other IO processors
4495 * with whatever name they already have, because its
4496 * just fine as it is (it will not contain the route
4497 * name if its a port insert, port send or port return).
4501 if (_main_outs->set_name (name)) {
4502 /* XXX returning false here is stupid because
4503 we already changed the route name.
4513 /** Set the name of a route in an XML description.
4514 * @param node XML <Route> node to set the name in.
4515 * @param name New name.
4518 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4520 node.add_property (X_("name"), name);
4522 XMLNodeList children = node.children();
4523 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4525 if ((*i)->name() == X_("IO")) {
4527 IO::set_name_in_state (**i, name);
4529 } else if ((*i)->name() == X_("Processor")) {
4531 XMLProperty const * role = (*i)->property (X_("role"));
4532 if (role && role->value() == X_("Main")) {
4533 (*i)->add_property (X_("name"), name);
4536 } else if ((*i)->name() == X_("Diskstream")) {
4538 if (rename_playlist) {
4539 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4541 (*i)->add_property (X_("name"), name);
4547 boost::shared_ptr<Send>
4548 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4550 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4552 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4553 boost::shared_ptr<InternalSend> send;
4555 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4556 if (send->target_route() == target) {
4562 return boost::shared_ptr<Send>();
4565 /** @param c Audio channel index.
4566 * @param yn true to invert phase, otherwise false.
4569 Route::set_phase_invert (uint32_t c, bool yn)
4571 if (_phase_invert[c] != yn) {
4572 _phase_invert[c] = yn;
4573 phase_invert_changed (); /* EMIT SIGNAL */
4574 _phase_control->Changed(); /* EMIT SIGNAL */
4575 _session.set_dirty ();
4580 Route::set_phase_invert (boost::dynamic_bitset<> p)
4582 if (_phase_invert != p) {
4584 phase_invert_changed (); /* EMIT SIGNAL */
4585 _session.set_dirty ();
4590 Route::phase_invert (uint32_t c) const
4592 return _phase_invert[c];
4595 boost::dynamic_bitset<>
4596 Route::phase_invert () const
4598 return _phase_invert;
4602 Route::set_denormal_protection (bool yn)
4604 if (_denormal_protection != yn) {
4605 _denormal_protection = yn;
4606 denormal_protection_changed (); /* EMIT SIGNAL */
4611 Route::denormal_protection () const
4613 return _denormal_protection;
4617 Route::set_active (bool yn, void* src)
4619 if (_session.transport_rolling()) {
4623 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4624 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4628 if (_active != yn) {
4630 _input->set_active (yn);
4631 _output->set_active (yn);
4632 active_changed (); // EMIT SIGNAL
4633 _session.set_dirty ();
4637 boost::shared_ptr<Pannable>
4638 Route::pannable() const
4643 boost::shared_ptr<Panner>
4644 Route::panner() const
4647 return _main_outs->panner_shell()->panner();
4650 boost::shared_ptr<PannerShell>
4651 Route::panner_shell() const
4653 return _main_outs->panner_shell();
4656 boost::shared_ptr<GainControl>
4657 Route::gain_control() const
4659 return _gain_control;
4662 boost::shared_ptr<GainControl>
4663 Route::trim_control() const
4665 return _trim_control;
4668 boost::shared_ptr<Route::PhaseControllable>
4669 Route::phase_control() const
4671 if (phase_invert().size()) {
4672 return _phase_control;
4674 return boost::shared_ptr<PhaseControllable>();
4678 boost::shared_ptr<AutomationControl>
4679 Route::get_control (const Evoral::Parameter& param)
4681 /* either we own the control or .... */
4683 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4687 /* maybe one of our processors does or ... */
4689 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4690 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4691 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4699 /* nobody does so we'll make a new one */
4701 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4708 boost::shared_ptr<Processor>
4709 Route::nth_plugin (uint32_t n) const
4711 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4712 ProcessorList::const_iterator i;
4714 for (i = _processors.begin(); i != _processors.end(); ++i) {
4715 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4722 return boost::shared_ptr<Processor> ();
4725 boost::shared_ptr<Processor>
4726 Route::nth_send (uint32_t n) const
4728 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4729 ProcessorList::const_iterator i;
4731 for (i = _processors.begin(); i != _processors.end(); ++i) {
4732 if (boost::dynamic_pointer_cast<Send> (*i)) {
4734 if ((*i)->name().find (_("Monitor")) == 0) {
4735 /* send to monitor section is not considered
4736 to be an accessible send.
4747 return boost::shared_ptr<Processor> ();
4751 Route::has_io_processor_named (const string& name)
4753 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4754 ProcessorList::iterator i;
4756 for (i = _processors.begin(); i != _processors.end(); ++i) {
4757 if (boost::dynamic_pointer_cast<Send> (*i) ||
4758 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4759 if ((*i)->name() == name) {
4768 MuteMaster::MutePoint
4769 Route::mute_points () const
4771 return _mute_master->mute_points ();
4775 Route::set_processor_positions ()
4777 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4779 bool had_amp = false;
4780 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4781 (*i)->set_pre_fader (!had_amp);
4788 /** Called when there is a proposed change to the input port count */
4790 Route::input_port_count_changing (ChanCount to)
4792 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4794 /* The processors cannot be configured with the new input arrangement, so
4800 /* The change is ok */
4804 /** Called when there is a proposed change to the output port count */
4806 Route::output_port_count_changing (ChanCount to)
4808 if (_strict_io && !_in_configure_processors) {
4811 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4812 if (processor_out_streams.get(*t) > to.get(*t)) {
4816 /* The change is ok */
4821 Route::unknown_processors () const
4825 if (_session.get_disable_all_loaded_plugins ()) {
4826 // Do not list "missing plugins" if they are explicitly disabled
4830 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4831 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4832 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4833 p.push_back ((*i)->name ());
4842 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4844 /* we assume that all our input ports feed all our output ports. its not
4845 universally true, but the alternative is way too corner-case to worry about.
4848 LatencyRange all_connections;
4851 all_connections.min = 0;
4852 all_connections.max = 0;
4854 all_connections.min = ~((pframes_t) 0);
4855 all_connections.max = 0;
4857 /* iterate over all "from" ports and determine the latency range for all of their
4858 connections to the "outside" (outside of this Route).
4861 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4865 p->get_connected_latency_range (range, playback);
4867 all_connections.min = min (all_connections.min, range.min);
4868 all_connections.max = max (all_connections.max, range.max);
4872 /* set the "from" port latencies to the max/min range of all their connections */
4874 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4875 p->set_private_latency_range (all_connections, playback);
4878 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4880 all_connections.min += our_latency;
4881 all_connections.max += our_latency;
4883 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4884 p->set_private_latency_range (all_connections, playback);
4887 return all_connections.max;
4891 Route::set_private_port_latencies (bool playback) const
4893 framecnt_t own_latency = 0;
4895 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4896 OR LATENCY CALLBACK.
4898 This is called (early) from the latency callback. It computes the REAL
4899 latency associated with each port and stores the result as the "private"
4900 latency of the port. A later call to Route::set_public_port_latencies()
4901 sets all ports to the same value to reflect the fact that we do latency
4902 compensation and so all signals are delayed by the same amount as they
4903 flow through ardour.
4906 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4907 if ((*i)->active ()) {
4908 own_latency += (*i)->signal_latency ();
4913 /* playback: propagate latency from "outside the route" to outputs to inputs */
4914 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4916 /* capture: propagate latency from "outside the route" to inputs to outputs */
4917 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4922 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4924 /* this is called to set the JACK-visible port latencies, which take
4925 latency compensation into account.
4934 const PortSet& ports (_input->ports());
4935 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4936 p->set_public_latency_range (range, playback);
4941 const PortSet& ports (_output->ports());
4942 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4943 p->set_public_latency_range (range, playback);
4948 /** Put the invisible processors in the right place in _processors.
4949 * Must be called with a writer lock on _processor_lock held.
4952 __attribute__((annotate("realtime")))
4955 Route::setup_invisible_processors ()
4958 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4959 assert (!lm.locked ());
4963 /* too early to be doing this stuff */
4967 /* we'll build this new list here and then use it
4969 * TODO put the ProcessorList is on the stack for RT-safety.
4972 ProcessorList new_processors;
4974 /* find visible processors */
4976 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4977 if ((*i)->display_to_user ()) {
4978 new_processors.push_back (*i);
4984 ProcessorList::iterator amp = new_processors.begin ();
4985 while (amp != new_processors.end() && *amp != _amp) {
4989 assert (amp != new_processors.end ());
4991 /* and the processor after the amp */
4993 ProcessorList::iterator after_amp = amp;
4999 switch (_meter_point) {
5001 assert (!_meter->display_to_user ());
5002 new_processors.push_front (_meter);
5005 assert (!_meter->display_to_user ());
5006 new_processors.insert (amp, _meter);
5008 case MeterPostFader:
5009 /* do nothing here */
5012 /* do nothing here */
5015 /* the meter is visible, so we don't touch it here */
5022 assert (_main_outs);
5023 assert (!_main_outs->display_to_user ());
5024 new_processors.push_back (_main_outs);
5026 /* iterator for the main outs */
5028 ProcessorList::iterator main = new_processors.end();
5031 /* OUTPUT METERING */
5033 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
5034 assert (!_meter->display_to_user ());
5036 /* add the processor just before or just after the main outs */
5038 ProcessorList::iterator meter_point = main;
5040 if (_meter_point == MeterOutput) {
5043 new_processors.insert (meter_point, _meter);
5048 if (_monitor_send && !is_monitor ()) {
5049 assert (!_monitor_send->display_to_user ());
5050 switch (Config->get_listen_position ()) {
5051 case PreFaderListen:
5052 switch (Config->get_pfl_position ()) {
5053 case PFLFromBeforeProcessors:
5054 new_processors.push_front (_monitor_send);
5056 case PFLFromAfterProcessors:
5057 new_processors.insert (amp, _monitor_send);
5060 _monitor_send->set_can_pan (false);
5062 case AfterFaderListen:
5063 switch (Config->get_afl_position ()) {
5064 case AFLFromBeforeProcessors:
5065 new_processors.insert (after_amp, _monitor_send);
5067 case AFLFromAfterProcessors:
5068 new_processors.insert (new_processors.end(), _monitor_send);
5071 _monitor_send->set_can_pan (true);
5076 #if 0 // not used - just yet
5077 if (!is_master() && !is_monitor() && !is_auditioner()) {
5078 new_processors.push_front (_delayline);
5082 /* MONITOR CONTROL */
5084 if (_monitor_control && is_monitor ()) {
5085 assert (!_monitor_control->display_to_user ());
5086 new_processors.insert (amp, _monitor_control);
5089 /* INTERNAL RETURN */
5091 /* doing this here means that any monitor control will come just after
5096 assert (!_intreturn->display_to_user ());
5097 new_processors.push_front (_intreturn);
5100 if (_trim && _trim->active()) {
5101 assert (!_trim->display_to_user ());
5102 new_processors.push_front (_trim);
5104 /* EXPORT PROCESSOR */
5106 if (_capturing_processor) {
5107 assert (!_capturing_processor->display_to_user ());
5108 new_processors.push_front (_capturing_processor);
5111 _processors = new_processors;
5113 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5114 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
5119 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5120 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5121 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5128 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5129 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5133 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5134 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5141 /** If the meter point is `Custom', make a note of where the meter is.
5142 * This is so that if the meter point is subsequently set to something else,
5143 * and then back to custom, we can put the meter back where it was last time
5144 * custom was enabled.
5146 * Must be called with the _processor_lock held.
5149 Route::maybe_note_meter_position ()
5151 if (_meter_point != MeterCustom) {
5155 _custom_meter_position_noted = true;
5156 /* custom meter points range from after trim to before panner/main_outs
5157 * this is a limitation by the current processor UI
5159 bool seen_trim = false;
5160 _processor_after_last_custom_meter.reset();
5161 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5162 if ((*i) == _trim) {
5165 if ((*i) == _main_outs) {
5166 _processor_after_last_custom_meter = *i;
5169 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5171 _processor_after_last_custom_meter = _trim;
5173 ProcessorList::iterator j = i;
5175 assert(j != _processors.end ()); // main_outs should be before
5176 _processor_after_last_custom_meter = *j;
5181 assert(_processor_after_last_custom_meter.lock());
5184 boost::shared_ptr<Processor>
5185 Route::processor_by_id (PBD::ID id) const
5187 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5188 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5189 if ((*i)->id() == id) {
5194 return boost::shared_ptr<Processor> ();
5197 /** @return the monitoring state, or in other words what data we are pushing
5198 * into the route (data from the inputs, data from disk or silence)
5201 Route::monitoring_state () const
5203 return MonitoringInput;
5206 /** @return what we should be metering; either the data coming from the input
5207 * IO or the data that is flowing through the route.
5210 Route::metering_state () const
5212 return MeteringRoute;
5216 Route::has_external_redirects () const
5218 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5220 /* ignore inactive processors and obviously ignore the main
5221 * outs since everything has them and we don't care.
5224 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5232 boost::shared_ptr<Processor>
5233 Route::the_instrument () const
5235 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5236 return the_instrument_unlocked ();
5239 boost::shared_ptr<Processor>
5240 Route::the_instrument_unlocked () const
5242 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5243 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5244 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5248 return boost::shared_ptr<Processor>();
5254 Route::non_realtime_locate (framepos_t pos)
5257 _pannable->transport_located (pos);
5260 if (_delayline.get()) {
5261 _delayline.get()->flush();
5265 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5266 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5269 (*i)->transport_located (pos);
5272 _roll_delay = _initial_delay;
5276 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5283 * We don't currently mix MIDI input together, so we don't need the
5284 * complex logic of the audio case.
5287 n_buffers = bufs.count().n_midi ();
5289 for (i = 0; i < n_buffers; ++i) {
5291 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5292 MidiBuffer& buf (bufs.get_midi (i));
5295 buf.copy (source_port->get_midi_buffer(nframes));
5297 buf.silence (nframes);
5303 n_buffers = bufs.count().n_audio();
5305 size_t n_ports = io->n_ports().n_audio();
5306 float scaling = 1.0f;
5308 if (n_ports > n_buffers) {
5309 scaling = ((float) n_buffers) / n_ports;
5312 for (i = 0; i < n_ports; ++i) {
5314 /* if there are more ports than buffers, map them onto buffers
5315 * in a round-robin fashion
5318 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5319 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5322 if (i < n_buffers) {
5324 /* first time through just copy a channel into
5328 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5330 if (scaling != 1.0f) {
5331 buf.apply_gain (scaling, nframes);
5336 /* on subsequent times around, merge data from
5337 * the port with what is already there
5340 if (scaling != 1.0f) {
5341 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5343 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5348 /* silence any remaining buffers */
5350 for (; i < n_buffers; ++i) {
5351 AudioBuffer& buf (bufs.get_audio (i));
5352 buf.silence (nframes);
5355 /* establish the initial setup of the buffer set, reflecting what was
5356 copied into it. unless, of course, we are the auditioner, in which
5357 case nothing was fed into it from the inputs at all.
5360 if (!is_auditioner()) {
5361 bufs.set_count (io->n_ports());
5365 boost::shared_ptr<AutomationControl>
5366 Route::pan_azimuth_control() const
5369 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5371 return boost::shared_ptr<AutomationControl>();
5373 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5374 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5376 if (!_pannable || !panner()) {
5377 return boost::shared_ptr<AutomationControl>();
5379 return _pannable->pan_azimuth_control;
5383 boost::shared_ptr<AutomationControl>
5384 Route::pan_elevation_control() const
5386 if (Profile->get_mixbus() || !_pannable || !panner()) {
5387 return boost::shared_ptr<AutomationControl>();
5390 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5392 if (c.find (PanElevationAutomation) != c.end()) {
5393 return _pannable->pan_elevation_control;
5395 return boost::shared_ptr<AutomationControl>();
5398 boost::shared_ptr<AutomationControl>
5399 Route::pan_width_control() const
5401 if (Profile->get_mixbus() || !_pannable || !panner()) {
5402 return boost::shared_ptr<AutomationControl>();
5405 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5407 if (c.find (PanWidthAutomation) != c.end()) {
5408 return _pannable->pan_width_control;
5410 return boost::shared_ptr<AutomationControl>();
5413 boost::shared_ptr<AutomationControl>
5414 Route::pan_frontback_control() const
5416 if (Profile->get_mixbus() || !_pannable || !panner()) {
5417 return boost::shared_ptr<AutomationControl>();
5420 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5422 if (c.find (PanFrontBackAutomation) != c.end()) {
5423 return _pannable->pan_frontback_control;
5425 return boost::shared_ptr<AutomationControl>();
5428 boost::shared_ptr<AutomationControl>
5429 Route::pan_lfe_control() const
5431 if (Profile->get_mixbus() || !_pannable || !panner()) {
5432 return boost::shared_ptr<AutomationControl>();
5435 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5437 if (c.find (PanLFEAutomation) != c.end()) {
5438 return _pannable->pan_lfe_control;
5440 return boost::shared_ptr<AutomationControl>();
5445 Route::eq_band_cnt () const
5447 if (Profile->get_mixbus()) {
5450 /* Ardour has no well-known EQ object */
5455 boost::shared_ptr<AutomationControl>
5456 Route::eq_gain_controllable (uint32_t band) const
5459 boost::shared_ptr<PluginInsert> eq = ch_eq();
5462 return boost::shared_ptr<AutomationControl>();
5465 uint32_t port_number;
5468 if (is_master() || mixbus()) {
5475 if (is_master() || mixbus()) {
5482 if (is_master() || mixbus()) {
5489 return boost::shared_ptr<AutomationControl>();
5492 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5494 return boost::shared_ptr<AutomationControl>();
5497 boost::shared_ptr<AutomationControl>
5498 Route::eq_freq_controllable (uint32_t band) const
5502 if (mixbus() || is_master()) {
5503 /* no frequency controls for mixbusses or master */
5504 return boost::shared_ptr<AutomationControl>();
5507 boost::shared_ptr<PluginInsert> eq = ch_eq();
5510 return boost::shared_ptr<AutomationControl>();
5513 uint32_t port_number;
5525 return boost::shared_ptr<AutomationControl>();
5528 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5530 return boost::shared_ptr<AutomationControl>();
5534 boost::shared_ptr<AutomationControl>
5535 Route::eq_q_controllable (uint32_t band) const
5537 return boost::shared_ptr<AutomationControl>();
5540 boost::shared_ptr<AutomationControl>
5541 Route::eq_shape_controllable (uint32_t band) const
5543 return boost::shared_ptr<AutomationControl>();
5546 boost::shared_ptr<AutomationControl>
5547 Route::eq_enable_controllable () const
5550 boost::shared_ptr<PluginInsert> eq = ch_eq();
5553 return boost::shared_ptr<AutomationControl>();
5556 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5558 return boost::shared_ptr<AutomationControl>();
5562 boost::shared_ptr<AutomationControl>
5563 Route::eq_hpf_controllable () const
5566 boost::shared_ptr<PluginInsert> eq = ch_eq();
5569 return boost::shared_ptr<AutomationControl>();
5572 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5574 return boost::shared_ptr<AutomationControl>();
5579 Route::eq_band_name (uint32_t band) const
5581 if (Profile->get_mixbus()) {
5597 boost::shared_ptr<AutomationControl>
5598 Route::comp_enable_controllable () const
5601 boost::shared_ptr<PluginInsert> comp = ch_comp();
5604 return boost::shared_ptr<AutomationControl>();
5607 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5609 return boost::shared_ptr<AutomationControl>();
5612 boost::shared_ptr<AutomationControl>
5613 Route::comp_threshold_controllable () const
5616 boost::shared_ptr<PluginInsert> comp = ch_comp();
5619 return boost::shared_ptr<AutomationControl>();
5622 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5625 return boost::shared_ptr<AutomationControl>();
5628 boost::shared_ptr<AutomationControl>
5629 Route::comp_speed_controllable () const
5632 boost::shared_ptr<PluginInsert> comp = ch_comp();
5635 return boost::shared_ptr<AutomationControl>();
5638 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5640 return boost::shared_ptr<AutomationControl>();
5643 boost::shared_ptr<AutomationControl>
5644 Route::comp_mode_controllable () const
5647 boost::shared_ptr<PluginInsert> comp = ch_comp();
5650 return boost::shared_ptr<AutomationControl>();
5653 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5655 return boost::shared_ptr<AutomationControl>();
5658 boost::shared_ptr<AutomationControl>
5659 Route::comp_makeup_controllable () const
5662 boost::shared_ptr<PluginInsert> comp = ch_comp();
5665 return boost::shared_ptr<AutomationControl>();
5668 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5670 return boost::shared_ptr<AutomationControl>();
5673 boost::shared_ptr<AutomationControl>
5674 Route::comp_redux_controllable () const
5677 boost::shared_ptr<PluginInsert> comp = ch_comp();
5680 return boost::shared_ptr<AutomationControl>();
5683 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5685 return boost::shared_ptr<AutomationControl>();
5690 Route::comp_mode_name (uint32_t mode) const
5695 return _("Leveler");
5697 return _("Compressor");
5699 return _("Limiter");
5701 return mixbus() ? _("Sidechain") : _("Limiter");
5711 Route::comp_speed_name (uint32_t mode) const
5729 boost::shared_ptr<AutomationControl>
5730 Route::send_level_controllable (uint32_t n) const
5733 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5735 return boost::shared_ptr<AutomationControl>();
5740 return boost::shared_ptr<AutomationControl>();
5743 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5744 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5746 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5748 return boost::shared_ptr<AutomationControl>();
5750 return s->gain_control ();
5754 boost::shared_ptr<AutomationControl>
5755 Route::send_enable_controllable (uint32_t n) const
5758 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5760 return boost::shared_ptr<AutomationControl>();
5765 return boost::shared_ptr<AutomationControl>();
5768 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5769 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5771 /* although Ardour sends have enable/disable as part of the Processor
5772 API, it is not exposed as a controllable.
5774 XXX: we should fix this.
5776 return boost::shared_ptr<AutomationControl>();
5781 Route::send_name (uint32_t n) const
5787 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5791 boost::shared_ptr<Processor> p = nth_send (n);
5800 boost::shared_ptr<AutomationControl>
5801 Route::master_send_enable_controllable () const
5804 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5806 return boost::shared_ptr<AutomationControl>();
5808 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5810 return boost::shared_ptr<AutomationControl>();