2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/unwind.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_track.h"
41 #include "ardour/audio_port.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/boost_debug.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/plugin_insert.h"
62 #include "ardour/port.h"
63 #include "ardour/port_insert.h"
64 #include "ardour/processor.h"
65 #include "ardour/profile.h"
66 #include "ardour/route.h"
67 #include "ardour/route_group.h"
68 #include "ardour/send.h"
69 #include "ardour/session.h"
70 #include "ardour/unknown_processor.h"
71 #include "ardour/utils.h"
76 using namespace ARDOUR;
79 PBD::Signal0<void> Route::SyncOrderKeys;
80 PBD::Signal0<void> Route::RemoteControlIDChange;
81 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
83 /** Base class for all routable/mixable objects (tracks and busses) */
84 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
85 : SessionObject (sess, name)
87 , GraphNode (sess._process_graph)
90 , _signal_latency_at_amp_position (0)
91 , _signal_latency_at_trim_position (0)
94 , _pending_process_reorder (0)
95 , _pending_signals (0)
97 , _pending_declick (true)
98 , _meter_point (MeterPostFader)
99 , _pending_meter_point (MeterPostFader)
100 , _meter_type (MeterPeak)
102 , _soloed_by_others_upstream (0)
103 , _soloed_by_others_downstream (0)
104 , _solo_isolated (false)
105 , _solo_isolated_by_upstream (0)
106 , _denormal_protection (false)
109 , _declickable (false)
110 , _mute_master (new MuteMaster (sess, name))
111 , _have_internal_generator (false)
113 , _default_type (default_type)
115 , _has_order_key (false)
116 , _remote_control_id (0)
118 , _in_configure_processors (false)
119 , _initial_io_setup (false)
120 , _in_sidechain_setup (false)
122 , _custom_meter_position_noted (false)
125 processor_max_streams.reset();
131 /* set default meter type */
133 _meter_type = Config->get_meter_type_master ();
135 else if (dynamic_cast<Track*>(this)) {
136 _meter_type = Config->get_meter_type_track ();
138 _meter_type = Config->get_meter_type_bus ();
141 /* add standard controls */
143 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
144 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
145 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
147 _solo_isolate_control.reset (new SoloIsolateControllable (X_("solo-iso"), shared_from_this ()));
148 _solo_safe_control.reset (new SoloSafeControllable (X_("solo-safe"), shared_from_this ()));
150 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
151 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
152 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
154 add_control (_solo_control);
155 add_control (_mute_control);
156 add_control (_phase_control);
160 if (!(_flags & Route::MonitorOut)) {
161 _pannable.reset (new Pannable (_session));
164 /* input and output objects */
166 _input.reset (new IO (_session, _name, IO::Input, _default_type));
167 _output.reset (new IO (_session, _name, IO::Output, _default_type));
169 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
170 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
172 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
173 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
175 /* add the amp/fader processor.
176 * it should be the first processor to be added on every route.
179 _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
180 add_control (_gain_control);
182 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
183 add_processor (_amp, PostFader);
186 _amp->set_display_name (_("Monitor"));
189 #if 0 // not used - just yet
190 if (!is_master() && !is_monitor() && !is_auditioner()) {
191 _delayline.reset (new DelayLine (_session, _name));
192 add_processor (_delayline, PreFader);
198 _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
199 add_control (_trim_control);
201 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
202 _trim->set_display_to_user (false);
204 if (dynamic_cast<AudioTrack*>(this)) {
205 /* we can't do this in the AudioTrack's constructor
206 * because _trim does not exit then
210 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
215 /* create standard processors: meter, main outs, monitor out;
216 they will be added to _processors by setup_invisible_processors ()
219 _meter.reset (new PeakMeter (_session, _name));
220 _meter->set_owner (this);
221 _meter->set_display_to_user (false);
224 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
225 _main_outs->activate ();
228 /* where we listen to tracks */
229 _intreturn.reset (new InternalReturn (_session));
230 _intreturn->activate ();
232 /* the thing that provides proper control over a control/monitor/listen bus
233 (such as per-channel cut, dim, solo, invert, etc).
235 _monitor_control.reset (new MonitorProcessor (_session));
236 _monitor_control->activate ();
239 if (is_master() || is_monitor() || is_auditioner()) {
240 _mute_master->set_solo_ignore (true);
243 /* now that we have _meter, its safe to connect to this */
246 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
247 configure_processors (0);
255 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
257 /* do this early so that we don't get incoming signals as we are going through destruction
262 /* don't use clear_processors here, as it depends on the session which may
263 be half-destroyed by now
266 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
267 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
268 (*i)->drop_references ();
271 _processors.clear ();
275 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
277 if (Config->get_remote_model() != UserOrdered) {
281 set_remote_control_id_internal (id, notify_class_listeners);
285 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
287 /* force IDs for master/monitor busses and prevent
288 any other route from accidentally getting these IDs
289 (i.e. legacy sessions)
292 if (is_master() && id != MasterBusRemoteControlID) {
293 id = MasterBusRemoteControlID;
296 if (is_monitor() && id != MonitorBusRemoteControlID) {
297 id = MonitorBusRemoteControlID;
304 /* don't allow it to collide */
306 if (!is_master () && !is_monitor() &&
307 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
308 id += MonitorBusRemoteControlID;
311 if (id != remote_control_id()) {
312 _remote_control_id = id;
313 RemoteControlIDChanged ();
315 if (notify_class_listeners) {
316 RemoteControlIDChange ();
322 Route::remote_control_id() const
325 return MasterBusRemoteControlID;
329 return MonitorBusRemoteControlID;
332 return _remote_control_id;
336 Route::has_order_key () const
338 return _has_order_key;
342 Route::order_key () const
348 Route::set_remote_control_id_explicit (uint32_t rid)
350 if (is_master() || is_monitor() || is_auditioner()) {
351 /* hard-coded remote IDs, or no remote ID */
355 if (_remote_control_id != rid) {
356 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
357 _remote_control_id = rid;
358 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
361 /* don't emit the class-level RID signal RemoteControlIDChange here,
362 leave that to the entity that changed the order key, so that we
363 don't get lots of emissions for no good reasons (e.g. when changing
364 all route order keys).
366 See Session::sync_remote_id_from_order_keys() for the (primary|only)
367 spot where that is emitted.
372 Route::set_order_key (uint32_t n)
374 _has_order_key = true;
376 if (_order_key == n) {
382 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
383 name(), order_key ()));
385 _session.set_dirty ();
389 Route::ensure_track_or_route_name(string name, Session &session)
391 string newname = name;
393 while (!session.io_name_is_legal (newname)) {
394 newname = bump_name_once (newname, ' ');
401 Route::inc_gain (gain_t factor)
403 /* To be used ONLY when doing group-relative gain adjustment, from
407 float desired_gain = _gain_control->user_double();
409 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
410 // really?! what's the idea here?
411 _gain_control->route_set_value (0.000001f + (0.000001f * factor));
413 _gain_control->route_set_value (desired_gain + (desired_gain * factor));
418 Route::set_gain (gain_t val, Controllable::GroupControlDisposition group_override)
420 if (use_group (group_override, &RouteGroup::is_gain)) {
422 if (_route_group->is_relative()) {
424 gain_t usable_gain = _gain_control->get_value();
425 if (usable_gain < 0.000001f) {
426 usable_gain = 0.000001f;
430 if (delta < 0.000001f) {
434 delta -= usable_gain;
439 gain_t factor = delta / usable_gain;
442 factor = _route_group->get_max_factor(factor);
443 if (factor == 0.0f) {
444 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
448 factor = _route_group->get_min_factor(factor);
449 if (factor == 0.0f) {
450 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
455 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor));
459 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, Controllable::NoGroup));
465 if (val == _gain_control->get_value()) {
469 _gain_control->route_set_value (val);
473 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
475 // TODO route group, see set_gain()
476 _trim_control->route_set_value (val);
480 Route::maybe_declick (BufferSet&, framecnt_t, int)
482 /* this is the "bus" implementation and they never declick.
487 /** Process this route for one (sub) cycle (process thread)
489 * @param bufs Scratch buffers to use for the signal path
490 * @param start_frame Initial transport frame
491 * @param end_frame Final transport frame
492 * @param nframes Number of frames to output (to ports)
494 * Note that (end_frame - start_frame) may not be equal to nframes when the
495 * transport speed isn't 1.0 (eg varispeed).
498 Route::process_output_buffers (BufferSet& bufs,
499 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
500 int declick, bool gain_automation_ok)
502 /* Caller must hold process lock */
503 assert (!AudioEngine::instance()->process_lock().trylock());
505 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
507 // can this actually happen? functions calling process_output_buffers()
508 // already take a reader-lock.
509 bufs.silence (nframes, 0);
513 /* figure out if we're going to use gain automation */
514 if (gain_automation_ok) {
515 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
516 _amp->setup_gain_automation (
517 start_frame + _signal_latency_at_amp_position,
518 end_frame + _signal_latency_at_amp_position,
521 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
522 _trim->setup_gain_automation (
523 start_frame + _signal_latency_at_trim_position,
524 end_frame + _signal_latency_at_trim_position,
527 _amp->apply_gain_automation (false);
528 _trim->apply_gain_automation (false);
531 /* Tell main outs what to do about monitoring. We do this so that
532 on a transition between monitoring states we get a de-clicking gain
533 change in the _main_outs delivery, if config.get_use_monitor_fades()
536 We override this in the case where we have an internal generator.
538 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
540 _main_outs->no_outs_cuz_we_no_monitor (silence);
542 /* -------------------------------------------------------------------------------------------
543 GLOBAL DECLICK (for transport changes etc.)
544 ----------------------------------------------------------------------------------------- */
546 maybe_declick (bufs, nframes, declick);
547 _pending_declick = 0;
549 /* -------------------------------------------------------------------------------------------
550 DENORMAL CONTROL/PHASE INVERT
551 ----------------------------------------------------------------------------------------- */
553 if (_phase_invert.any ()) {
557 if (_denormal_protection || Config->get_denormal_protection()) {
559 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
560 Sample* const sp = i->data();
562 if (_phase_invert[chn]) {
563 for (pframes_t nx = 0; nx < nframes; ++nx) {
568 for (pframes_t nx = 0; nx < nframes; ++nx) {
576 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
577 Sample* const sp = i->data();
579 if (_phase_invert[chn]) {
580 for (pframes_t nx = 0; nx < nframes; ++nx) {
589 if (_denormal_protection || Config->get_denormal_protection()) {
591 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
592 Sample* const sp = i->data();
593 for (pframes_t nx = 0; nx < nframes; ++nx) {
601 /* -------------------------------------------------------------------------------------------
603 ----------------------------------------------------------------------------------------- */
605 /* set this to be true if the meter will already have been ::run() earlier */
606 bool const meter_already_run = metering_state() == MeteringInput;
608 framecnt_t latency = 0;
610 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
612 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
613 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
618 /* if it has any inputs, make sure they match */
619 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
620 if (bufs.count() != (*i)->input_streams()) {
622 DEBUG::Processors, string_compose (
623 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
624 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
631 /* should we NOT run plugins here if the route is inactive?
632 do we catch route != active somewhere higher?
635 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
636 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
639 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
640 bufs.set_count ((*i)->output_streams());
642 if ((*i)->active ()) {
643 latency += (*i)->signal_latency ();
649 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
650 boost::shared_ptr<Processor> endpoint,
651 bool include_endpoint, bool for_export, bool for_freeze)
653 /* If no processing is required, there's no need to go any further. */
654 if (!endpoint && !include_endpoint) {
658 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
659 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
660 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
662 /* trim is always at the top, for bounce no latency compensation is needed */
663 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
664 _trim->setup_gain_automation (start, start + nframes, nframes);
667 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
669 if (!include_endpoint && (*i) == endpoint) {
673 /* if we're *not* exporting, stop processing if we come across a routing processor. */
674 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
677 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
681 /* special case the panner (export outputs)
682 * Ideally we'd only run the panner, not the delivery itself...
683 * but panners need separate input/output buffers and some context
684 * (panshell, panner type, etc). AFAICT there is no ill side effect
685 * of re-using the main delivery when freewheeling/exporting a region.
687 if ((*i) == _main_outs) {
688 assert ((*i)->does_routing());
689 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
690 buffers.set_count ((*i)->output_streams());
693 /* don't run any processors that do routing.
694 * Also don't bother with metering.
696 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
697 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
698 buffers.set_count ((*i)->output_streams());
699 latency += (*i)->signal_latency ();
702 if ((*i) == endpoint) {
709 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
710 bool include_endpoint, bool for_export, bool for_freeze) const
712 framecnt_t latency = 0;
713 if (!endpoint && !include_endpoint) {
717 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
718 if (!include_endpoint && (*i) == endpoint) {
721 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
724 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
727 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
728 latency += (*i)->signal_latency ();
730 if ((*i) == endpoint) {
738 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
739 bool include_endpoint, bool for_export, bool for_freeze) const
741 if (!endpoint && !include_endpoint) {
745 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
746 if (!include_endpoint && (*i) == endpoint) {
749 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
752 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
755 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
756 cc = (*i)->output_streams();
758 if ((*i) == endpoint) {
766 Route::n_process_buffers ()
768 return max (_input->n_ports(), processor_max_streams);
772 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
774 assert (is_monitor());
775 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
776 fill_buffers_with_input (bufs, _input, nframes);
777 passthru (bufs, start_frame, end_frame, nframes, declick);
781 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
785 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
787 /* control/monitor bus ignores input ports when something is
788 feeding the listen "stream". data will "arrive" into the
789 route from the intreturn processor element.
792 bufs.silence (nframes, 0);
795 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
796 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
800 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
802 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
804 bufs.set_count (_input->n_ports());
805 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
806 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
810 Route::set_listen (bool yn, Controllable::GroupControlDisposition group_override)
816 if (use_group (group_override, &RouteGroup::is_solo)) {
817 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, Controllable::ForGroup));
822 if (yn != _monitor_send->active()) {
824 _monitor_send->activate ();
825 _mute_master->set_soloed_by_self (true);
827 _monitor_send->deactivate ();
828 _mute_master->set_soloed_by_self (false);
830 _mute_master->set_soloed_by_others (false);
832 listen_changed (group_override); /* EMIT SIGNAL */
838 Route::listening_via_monitor () const
841 return _monitor_send->active ();
848 Route::set_solo_safe (bool yn, Controllable::GroupControlDisposition /* group_override */)
850 if (_solo_safe != yn) {
852 solo_safe_changed (); /* EMIT SIGNAL */
853 _solo_safe_control->Changed(); /* EMIT SIGNAL */
858 Route::solo_safe() const
864 Route::clear_all_solo_state ()
866 // ideally this function will never do anything, it only exists to forestall Murphy
867 bool emit_changed = false;
870 // these are really debug messages, but of possible interest.
872 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
874 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
875 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
876 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
880 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
881 // if self-soled, set_solo() will do signal emission
885 _soloed_by_others_upstream = 0;
886 _soloed_by_others_downstream = 0;
889 PBD::Unwinder<bool> uw (_solo_safe, false);
890 set_solo (false, Controllable::NoGroup);
894 set_mute_master_solo ();
895 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
900 Route::set_solo (bool yn, Controllable::GroupControlDisposition group_override)
902 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, grp ? %3 currently self-soloed ? %4\n",
903 name(), yn, enum_2_string(group_override), self_soloed()));
906 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
910 if (is_master() || is_monitor() || is_auditioner()) {
911 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
915 if (use_group (group_override, &RouteGroup::is_solo)) {
916 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, Controllable::ForGroup));
920 if (self_soloed() != yn) {
922 solo_changed (true, group_override); /* EMIT SIGNAL */
923 _solo_control->Changed (); /* EMIT SIGNAL */
926 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
928 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
929 Config->get_solo_mute_overrride().
932 if (yn && Profile->get_trx()) {
933 set_mute (false, Controllable::UseGroup);
938 Route::set_self_solo (bool yn)
940 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
942 set_mute_master_solo ();
946 Route::mod_solo_by_others_upstream (int32_t delta)
948 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
949 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
951 uint32_t old_sbu = _soloed_by_others_upstream;
954 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
955 _soloed_by_others_upstream += delta;
957 _soloed_by_others_upstream = 0;
960 _soloed_by_others_upstream += delta;
963 DEBUG_TRACE (DEBUG::Solo, string_compose (
964 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
965 name(), delta, _soloed_by_others_upstream, old_sbu,
966 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
968 /* push the inverse solo change to everything that feeds us.
970 This is important for solo-within-group. When we solo 1 track out of N that
971 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
972 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
973 tracks that feed it. This will silence them if they were audible because
974 of a bus solo, but the newly soloed track will still be audible (because
977 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
981 if ((_self_solo || _soloed_by_others_downstream) &&
982 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
983 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
985 if (delta > 0 || !Config->get_exclusive_solo()) {
986 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
987 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
991 boost::shared_ptr<Route> sr = i->r.lock();
993 sr->mod_solo_by_others_downstream (-delta);
999 set_mute_master_solo ();
1000 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1004 Route::mod_solo_by_others_downstream (int32_t delta)
1006 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
1007 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
1010 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
1011 _soloed_by_others_downstream += delta;
1013 _soloed_by_others_downstream = 0;
1016 _soloed_by_others_downstream += delta;
1019 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
1021 set_mute_master_solo ();
1022 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1026 Route::set_mute_master_solo ()
1028 _mute_master->set_soloed_by_self (self_soloed());
1029 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1033 Route::mod_solo_isolated_by_upstream (bool yn)
1035 bool old = solo_isolated ();
1036 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1037 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1040 if (_solo_isolated_by_upstream >= 1) {
1041 _solo_isolated_by_upstream--;
1043 _solo_isolated_by_upstream = 0;
1046 _solo_isolated_by_upstream++;
1049 if (solo_isolated() != old) {
1050 /* solo isolated status changed */
1051 _mute_master->set_solo_ignore (solo_isolated());
1052 solo_isolated_changed (); /* EMIT SIGNAL */
1057 Route::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
1059 if (is_master() || is_monitor() || is_auditioner()) {
1063 if (use_group (group_override, &RouteGroup::is_solo)) {
1064 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, Controllable::ForGroup));
1068 bool changed = false;
1071 if (_solo_isolated == false) {
1072 _mute_master->set_solo_ignore (true);
1075 _solo_isolated = true;
1077 if (_solo_isolated == true) {
1078 _solo_isolated = false;
1079 _mute_master->set_solo_ignore (false);
1089 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1091 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1092 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1094 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1099 bool does_feed = feeds (*i, &sends_only);
1101 if (does_feed && !sends_only) {
1102 (*i)->mod_solo_isolated_by_upstream (yn);
1106 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1108 solo_isolated_changed (); /* EMIT SIGNAL */
1109 _solo_isolate_control->Changed(); /* EMIT SIGNAL */
1113 Route::solo_isolated () const
1115 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1119 Route::set_mute_points (MuteMaster::MutePoint mp)
1121 _mute_master->set_mute_points (mp);
1122 mute_points_changed (); /* EMIT SIGNAL */
1124 if (_mute_master->muted_by_self()) {
1125 mute_changed (); /* EMIT SIGNAL */
1126 _mute_control->Changed (); /* EMIT SIGNAL */
1131 Route::set_mute (bool yn, Controllable::GroupControlDisposition group_override)
1133 if (use_group (group_override, &RouteGroup::is_mute)) {
1134 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, Controllable::ForGroup));
1138 if (muted() != yn) {
1139 _mute_master->set_muted_by_self (yn);
1140 /* allow any derived classes to respond to the mute change
1141 before anybody else knows about it.
1144 /* tell everyone else */
1145 mute_changed (); /* EMIT SIGNAL */
1146 _mute_control->Changed (); /* EMIT SIGNAL */
1151 Route::muted () const
1153 return _mute_master->muted_by_self();
1157 Route::muted_by_others () const
1159 // This method is only used by route_ui for display state.
1160 // The real thing is MuteMaster::muted_by_others_at()
1162 //master is never muted by others
1166 //now check to see if something is soloed (and I am not)
1167 //see also MuteMaster::mute_gain_at()
1168 return (_session.soloing() && !soloed() && !solo_isolated());
1173 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1175 cerr << name << " {" << endl;
1176 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1177 p != procs.end(); ++p) {
1178 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1180 cerr << "}" << endl;
1184 /** Supposing that we want to insert a Processor at a given Placement, return
1185 * the processor to add the new one before (or 0 to add at the end).
1187 boost::shared_ptr<Processor>
1188 Route::before_processor_for_placement (Placement p)
1190 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1192 ProcessorList::iterator loc;
1194 if (p == PreFader) {
1195 /* generic pre-fader: insert immediately before the amp */
1196 loc = find (_processors.begin(), _processors.end(), _amp);
1198 /* generic post-fader: insert right before the main outs */
1199 loc = find (_processors.begin(), _processors.end(), _main_outs);
1202 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1205 /** Supposing that we want to insert a Processor at a given index, return
1206 * the processor to add the new one before (or 0 to add at the end).
1208 boost::shared_ptr<Processor>
1209 Route::before_processor_for_index (int index)
1212 return boost::shared_ptr<Processor> ();
1215 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1217 ProcessorList::iterator i = _processors.begin ();
1219 while (i != _processors.end() && j < index) {
1220 if ((*i)->display_to_user()) {
1227 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1230 /** Add a processor either pre- or post-fader
1231 * @return 0 on success, non-0 on failure.
1234 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1236 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1240 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1241 * @param index Index to add the processor at, or -1 to add at the end of the list.
1242 * @return 0 on success, non-0 on failure.
1245 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1247 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1250 /** Add a processor to the route.
1251 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1252 * @return 0 on success, non-0 on failure.
1255 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1257 assert (processor != _meter);
1258 assert (processor != _main_outs);
1260 DEBUG_TRACE (DEBUG::Processors, string_compose (
1261 "%1 adding processor %2\n", name(), processor->name()));
1265 pl.push_back (processor);
1266 int rv = add_processors (pl, before, err);
1272 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1273 processor->activate ();
1280 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
1282 /* We cannot destruct the processor here (usually RT-thread
1283 * with various locks held - in case of sends also io_locks).
1284 * Queue for deletion in low-priority thread.
1286 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
1287 selfdestruct_sequence.push_back (wp);
1291 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1293 XMLProperty const * prop;
1296 boost::shared_ptr<Processor> processor;
1298 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1299 so that we can add the processor in the right place (pre/post-fader)
1302 XMLNodeList const & children = node.children ();
1303 XMLNodeList::const_iterator i = children.begin ();
1305 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1309 Placement placement = PreFader;
1311 if (i != children.end()) {
1312 if ((prop = (*i)->property (X_("placement"))) != 0) {
1313 placement = Placement (string_2_enum (prop->value(), placement));
1317 if (node.name() == "Insert") {
1319 if ((prop = node.property ("type")) != 0) {
1321 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1322 prop->value() == "lv2" ||
1323 prop->value() == "windows-vst" ||
1324 prop->value() == "lxvst" ||
1325 prop->value() == "audiounit") {
1327 if (_session.get_disable_all_loaded_plugins ()) {
1328 processor.reset (new UnknownProcessor (_session, node));
1330 processor.reset (new PluginInsert (_session));
1331 processor->set_owner (this);
1336 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1341 } else if (node.name() == "Send") {
1343 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1344 processor.reset (new Send (_session, sendpan, _mute_master));
1348 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1352 if (processor->set_state (node, version)) {
1356 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1357 if (i != children.end()) {
1358 if ((prop = (*i)->property (X_("active"))) != 0) {
1359 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1360 processor->activate();
1362 processor->deactivate();
1366 return (add_processor (processor, placement, 0, false) == 0);
1369 catch (failed_constructor &err) {
1370 warning << _("processor could not be created. Ignored.") << endmsg;
1376 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1377 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
1380 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1381 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
1385 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1387 ProcessorList::iterator loc;
1390 loc = find(_processors.begin(), _processors.end(), before);
1391 if (loc == _processors.end ()) {
1395 /* nothing specified - at end */
1396 loc = _processors.end ();
1399 if (!AudioEngine::instance()->connected()) {
1403 if (others.empty()) {
1407 ProcessorList to_skip;
1409 // check if there's an instrument to replace or configure
1410 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1411 boost::shared_ptr<PluginInsert> pi;
1412 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1415 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1418 boost::shared_ptr<Processor> instrument = the_instrument ();
1419 ChanCount in (DataType::MIDI, 1);
1420 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1422 PluginSetupOptions flags = None;
1424 flags |= CanReplace;
1425 in = instrument->input_streams ();
1426 out = instrument->output_streams ();
1428 if (pi->has_output_presets (in, out)) {
1432 pi->set_strict_io (_strict_io);
1434 PluginSetupOptions mask = None;
1435 if (Config->get_ask_replace_instrument ()) {
1438 if (Config->get_ask_setup_instrument ()) {
1444 if (flags != None) {
1445 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
1446 switch (rv.get_value_or (0)) {
1448 to_skip.push_back (*i); // don't add this one;
1451 replace_processor (instrument, *i, err);
1452 to_skip.push_back (*i);
1461 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1462 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1463 ProcessorState pstate (this);
1465 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1470 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1471 if (check != to_skip.end()) {
1475 boost::shared_ptr<PluginInsert> pi;
1477 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1478 pi->set_strict_io (_strict_io);
1482 /* Ensure that only one amp is in the list at any time */
1483 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1484 if (check != _processors.end()) {
1485 if (before == _amp) {
1486 /* Already in position; all is well */
1489 _processors.erase (check);
1494 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1496 _processors.insert (loc, *i);
1497 (*i)->set_owner (this);
1500 if (configure_processors_unlocked (err, &lm)) {
1502 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1507 if ((*i)->active()) {
1511 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1513 boost::shared_ptr<Send> send;
1514 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1515 send->SelfDestruct.connect_same_thread (*this,
1516 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1520 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1521 boost::shared_ptr<PluginInsert> pi;
1523 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1524 if (pi->has_no_inputs ()) {
1525 _have_internal_generator = true;
1531 _output->set_user_latency (0);
1534 reset_instrument_info ();
1535 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1536 set_processor_positions ();
1542 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1544 if (p == PreFader) {
1545 start = _processors.begin();
1546 end = find(_processors.begin(), _processors.end(), _amp);
1548 start = find(_processors.begin(), _processors.end(), _amp);
1550 end = _processors.end();
1554 /** Turn off all processors with a given placement
1555 * @param p Placement of processors to disable
1558 Route::disable_processors (Placement p)
1560 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1562 ProcessorList::iterator start, end;
1563 placement_range(p, start, end);
1565 for (ProcessorList::iterator i = start; i != end; ++i) {
1566 (*i)->deactivate ();
1569 _session.set_dirty ();
1572 /** Turn off all redirects
1575 Route::disable_processors ()
1577 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1579 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1580 (*i)->deactivate ();
1583 _session.set_dirty ();
1586 /** Turn off all redirects with a given placement
1587 * @param p Placement of redirects to disable
1590 Route::disable_plugins (Placement p)
1592 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1594 ProcessorList::iterator start, end;
1595 placement_range(p, start, end);
1597 for (ProcessorList::iterator i = start; i != end; ++i) {
1598 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1599 (*i)->deactivate ();
1603 _session.set_dirty ();
1606 /** Turn off all plugins
1609 Route::disable_plugins ()
1611 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1613 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1614 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1615 (*i)->deactivate ();
1619 _session.set_dirty ();
1624 Route::ab_plugins (bool forward)
1626 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1630 /* forward = turn off all active redirects, and mark them so that the next time
1631 we go the other way, we will revert them
1634 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1635 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1639 if ((*i)->active()) {
1640 (*i)->deactivate ();
1641 (*i)->set_next_ab_is_active (true);
1643 (*i)->set_next_ab_is_active (false);
1649 /* backward = if the redirect was marked to go active on the next ab, do so */
1651 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1653 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1657 if ((*i)->get_next_ab_is_active()) {
1660 (*i)->deactivate ();
1665 _session.set_dirty ();
1669 /** Remove processors with a given placement.
1670 * @param p Placement of processors to remove.
1673 Route::clear_processors (Placement p)
1675 if (!_session.engine().connected()) {
1679 bool already_deleting = _session.deletion_in_progress();
1680 if (!already_deleting) {
1681 _session.set_deletion_in_progress();
1685 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1686 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1687 ProcessorList new_list;
1688 ProcessorStreams err;
1689 bool seen_amp = false;
1691 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1697 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1699 /* you can't remove these */
1701 new_list.push_back (*i);
1708 new_list.push_back (*i);
1711 (*i)->drop_references ();
1719 (*i)->drop_references ();
1722 new_list.push_back (*i);
1729 _processors = new_list;
1730 configure_processors_unlocked (&err, &lm); // this can't fail
1733 processor_max_streams.reset();
1734 _have_internal_generator = false;
1735 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1736 set_processor_positions ();
1738 reset_instrument_info ();
1740 if (!already_deleting) {
1741 _session.clear_deletion_in_progress();
1746 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1748 // TODO once the export point can be configured properly, do something smarter here
1749 if (processor == _capturing_processor) {
1750 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1751 if (need_process_lock) {
1755 _capturing_processor.reset();
1757 if (need_process_lock) {
1762 /* these can never be removed */
1764 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1768 if (!_session.engine().connected()) {
1772 processor_max_streams.reset();
1775 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1776 if (need_process_lock) {
1780 /* Caller must hold process lock */
1781 assert (!AudioEngine::instance()->process_lock().trylock());
1783 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1785 ProcessorState pstate (this);
1787 ProcessorList::iterator i;
1788 bool removed = false;
1790 for (i = _processors.begin(); i != _processors.end(); ) {
1791 if (*i == processor) {
1793 /* move along, see failure case for configure_processors()
1794 where we may need to reconfigure the processor.
1797 /* stop redirects that send signals to JACK ports
1798 from causing noise as a result of no longer being
1802 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1803 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1807 iop = pi->sidechain();
1814 i = _processors.erase (i);
1822 _output->set_user_latency (0);
1830 if (configure_processors_unlocked (err, &lm)) {
1832 /* we know this will work, because it worked before :) */
1833 configure_processors_unlocked (0, &lm);
1837 _have_internal_generator = false;
1839 for (i = _processors.begin(); i != _processors.end(); ++i) {
1840 boost::shared_ptr<PluginInsert> pi;
1842 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1843 if (pi->has_no_inputs ()) {
1844 _have_internal_generator = true;
1849 if (need_process_lock) {
1854 reset_instrument_info ();
1855 processor->drop_references ();
1856 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1857 set_processor_positions ();
1863 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1865 /* these can never be removed */
1866 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1869 /* and can't be used as substitute, either */
1870 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1874 /* I/Os are out, too */
1875 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1879 /* this function cannot be used to swap/reorder processors */
1880 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1884 if (!AudioEngine::instance()->connected() || !old || !sub) {
1888 /* ensure that sub is not owned by another route */
1889 if (sub->owner ()) {
1894 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1895 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1896 ProcessorState pstate (this);
1898 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1900 ProcessorList::iterator i;
1901 bool replaced = false;
1902 bool enable = old->active ();
1904 for (i = _processors.begin(); i != _processors.end(); ) {
1906 i = _processors.erase (i);
1907 _processors.insert (i, sub);
1908 sub->set_owner (this);
1921 boost::shared_ptr<PluginInsert> pi;
1922 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1923 pi->set_strict_io (true);
1927 if (configure_processors_unlocked (err, &lm)) {
1929 configure_processors_unlocked (0, &lm);
1933 _have_internal_generator = false;
1935 for (i = _processors.begin(); i != _processors.end(); ++i) {
1936 boost::shared_ptr<PluginInsert> pi;
1937 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1938 if (pi->has_no_inputs ()) {
1939 _have_internal_generator = true;
1949 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1950 _output->set_user_latency (0);
1953 reset_instrument_info ();
1954 old->drop_references ();
1955 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1956 set_processor_positions ();
1961 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1963 ProcessorList deleted;
1965 if (!_session.engine().connected()) {
1969 processor_max_streams.reset();
1972 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1973 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1974 ProcessorState pstate (this);
1976 ProcessorList::iterator i;
1977 boost::shared_ptr<Processor> processor;
1979 for (i = _processors.begin(); i != _processors.end(); ) {
1983 /* these can never be removed */
1985 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1990 /* see if its in the list of processors to delete */
1992 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1997 /* stop IOProcessors that send to JACK ports
1998 from causing noise as a result of no longer being
2002 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
2003 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2006 iop = pi->sidechain();
2013 deleted.push_back (processor);
2014 i = _processors.erase (i);
2017 if (deleted.empty()) {
2018 /* none of those in the requested list were found */
2022 _output->set_user_latency (0);
2024 if (configure_processors_unlocked (err, &lm)) {
2026 /* we know this will work, because it worked before :) */
2027 configure_processors_unlocked (0, &lm);
2032 _have_internal_generator = false;
2034 for (i = _processors.begin(); i != _processors.end(); ++i) {
2035 boost::shared_ptr<PluginInsert> pi;
2037 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2038 if (pi->has_no_inputs ()) {
2039 _have_internal_generator = true;
2046 /* now try to do what we need to so that those that were removed will be deleted */
2048 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
2049 (*i)->drop_references ();
2052 reset_instrument_info ();
2053 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2054 set_processor_positions ();
2060 Route::reset_instrument_info ()
2062 boost::shared_ptr<Processor> instr = the_instrument();
2064 _instrument_info.set_internal_instrument (instr);
2068 /** Caller must hold process lock */
2070 Route::configure_processors (ProcessorStreams* err)
2072 #ifndef PLATFORM_WINDOWS
2073 assert (!AudioEngine::instance()->process_lock().trylock());
2076 if (!_in_configure_processors) {
2077 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2078 return configure_processors_unlocked (err, &lm);
2085 Route::input_streams () const
2087 return _input->n_ports ();
2090 list<pair<ChanCount, ChanCount> >
2091 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
2093 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2095 return try_configure_processors_unlocked (in, err);
2098 list<pair<ChanCount, ChanCount> >
2099 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
2101 // Check each processor in order to see if we can configure as requested
2103 list<pair<ChanCount, ChanCount> > configuration;
2106 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
2107 DEBUG_TRACE (DEBUG::Processors, "{\n");
2109 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
2111 if ((*p)->can_support_io_configuration(in, out)) {
2113 if (boost::dynamic_pointer_cast<Delivery> (*p)
2114 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
2115 && !(is_monitor() || is_auditioner())
2116 && ( _strict_io || Profile->get_mixbus ())) {
2117 /* with strict I/O the panner + output are forced to
2118 * follow the last processor's output.
2120 * Delivery::can_support_io_configuration() will only add ports,
2121 * but not remove excess ports.
2123 * This works because the delivery only requires
2124 * as many outputs as there are inputs.
2125 * Delivery::configure_io() will do the actual removal
2126 * by calling _output->ensure_io()
2128 if (!is_master() && _session.master_out ()) {
2129 /* ..but at least as many as there are master-inputs */
2130 // XXX this may need special-casing for mixbus (master-outputs)
2131 // and should maybe be a preference anyway ?!
2132 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
2138 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
2139 configuration.push_back(make_pair(in, out));
2142 // restriction for Monitor Section Processors
2143 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
2144 /* do not allow to add/remove channels (for now)
2145 * The Monitor follows the master-bus and has no panner (unpan)
2146 * but do allow processors with midi-in to be added (e.g VSTs with control that
2147 * will remain unconnected)
2149 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
2150 return list<pair<ChanCount, ChanCount> > ();
2152 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
2153 // internal sends make no sense, only feedback
2154 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2155 return list<pair<ChanCount, ChanCount> > ();
2157 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
2158 /* External Sends can be problematic. one can add/remove ports
2159 * there signal leaves the DAW to external monitors anyway, so there's
2160 * no real use for allowing them here anyway.
2162 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
2163 return list<pair<ChanCount, ChanCount> > ();
2165 if (boost::dynamic_pointer_cast<Send> (*p)) {
2167 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2168 return list<pair<ChanCount, ChanCount> > ();
2177 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
2178 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
2179 DEBUG_TRACE (DEBUG::Processors, "}\n");
2180 return list<pair<ChanCount, ChanCount> > ();
2184 DEBUG_TRACE (DEBUG::Processors, "}\n");
2186 return configuration;
2189 /** Set the input/output configuration of each processor in the processors list.
2190 * Caller must hold process lock.
2191 * Return 0 on success, otherwise configuration is impossible.
2194 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
2196 #ifndef PLATFORM_WINDOWS
2197 assert (!AudioEngine::instance()->process_lock().trylock());
2200 if (_in_configure_processors) {
2204 /* put invisible processors where they should be */
2205 setup_invisible_processors ();
2207 _in_configure_processors = true;
2209 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2211 if (configuration.empty ()) {
2212 _in_configure_processors = false;
2217 bool seen_mains_out = false;
2218 processor_out_streams = _input->n_ports();
2219 processor_max_streams.reset();
2221 /* processor configure_io() may result in adding ports
2222 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
2224 * with jack2 adding ports results in a graph-order callback,
2225 * which calls Session::resort_routes() and eventually
2226 * Route::direct_feeds_according_to_reality()
2227 * which takes a ReaderLock (_processor_lock).
2229 * so we can't hold a WriterLock here until jack2 threading
2232 * NB. we still hold the process lock
2234 * (ardour's own engines do call graph-order from the
2235 * process-thread and hence do not have this issue; besides
2236 * merely adding ports won't trigger a graph-order, only
2237 * making connections does)
2241 // TODO check for a potential ReaderLock after ReaderLock ??
2242 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
2244 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2245 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2247 if (!(*p)->configure_io(c->first, c->second)) {
2248 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2249 _in_configure_processors = false;
2254 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2255 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2257 boost::shared_ptr<IOProcessor> iop;
2258 boost::shared_ptr<PluginInsert> pi;
2259 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2260 /* plugins connected via Split or Hide Match may have more channels.
2261 * route/scratch buffers are needed for all of them
2262 * The configuration may only be a subset (both input and output)
2264 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
2266 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
2267 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
2268 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
2272 if (boost::dynamic_pointer_cast<Delivery> (*p)
2273 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2274 /* main delivery will increase port count to match input.
2275 * the Delivery::Main is usually the last processor - followed only by
2278 seen_mains_out = true;
2280 if (!seen_mains_out) {
2281 processor_out_streams = out;
2290 _meter->set_max_channels (processor_max_streams);
2293 /* make sure we have sufficient scratch buffers to cope with the new processor
2296 _session.ensure_buffers (n_process_buffers ());
2298 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2300 _in_configure_processors = false;
2304 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2305 * @param state New active state for those processors.
2308 Route::all_visible_processors_active (bool state)
2310 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2312 if (_processors.empty()) {
2316 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2317 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2324 (*i)->deactivate ();
2328 _session.set_dirty ();
2332 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2334 /* check if re-order requires re-configuration of any processors
2335 * -> compare channel configuration for all processors
2337 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2338 ChanCount c = input_streams ();
2340 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2342 if (c != (*j)->input_streams()) {
2345 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2348 if ((*i)->input_streams() != c) {
2351 c = (*i)->output_streams();
2363 __attribute__((annotate("realtime")))
2366 Route::apply_processor_order (const ProcessorList& new_order)
2368 /* need to hold processor_lock; either read or write lock
2369 * and the engine process_lock.
2370 * Due to r/w lock ambiguity we can only assert the latter
2372 assert (!AudioEngine::instance()->process_lock().trylock());
2375 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2376 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2377 * processors in the current actual processor list that are hidden. Any visible processors
2378 * in the current list but not in "new_order" will be assumed to be deleted.
2381 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2382 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2383 * (note though that ::processors_reorder_needs_configure() ensured that
2384 * this function will only ever be called from the rt-thread if no processor were removed)
2386 * either way, I can't proove it, but an x-run due to re-order here is less likley
2387 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2390 ProcessorList as_it_will_be;
2391 ProcessorList::iterator oiter;
2392 ProcessorList::const_iterator niter;
2394 oiter = _processors.begin();
2395 niter = new_order.begin();
2397 while (niter != new_order.end()) {
2399 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2400 then append it to the temp list.
2402 Otherwise, see if the next processor in the old list is in the new list. if not,
2403 its been deleted. If its there, append it to the temp list.
2406 if (oiter == _processors.end()) {
2408 /* no more elements in the old list, so just stick the rest of
2409 the new order onto the temp list.
2412 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2413 while (niter != new_order.end()) {
2420 if (!(*oiter)->display_to_user()) {
2422 as_it_will_be.push_back (*oiter);
2426 /* visible processor: check that its in the new order */
2428 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2429 /* deleted: do nothing, shared_ptr<> will clean up */
2431 /* ignore this one, and add the next item from the new order instead */
2432 as_it_will_be.push_back (*niter);
2437 /* now remove from old order - its taken care of no matter what */
2438 oiter = _processors.erase (oiter);
2442 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2444 /* If the meter is in a custom position, find it and make a rough note of its position */
2445 maybe_note_meter_position ();
2449 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2451 // it a change is already queued, wait for it
2452 // (unless engine is stopped. apply immediately and proceed
2453 while (g_atomic_int_get (&_pending_process_reorder)) {
2454 if (!AudioEngine::instance()->running()) {
2455 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2456 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2458 apply_processor_order(_pending_processor_order);
2459 setup_invisible_processors ();
2461 g_atomic_int_set (&_pending_process_reorder, 0);
2463 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2464 set_processor_positions ();
2466 // TODO rather use a semaphore or something.
2467 // but since ::reorder_processors() is called
2468 // from the GUI thread, this is fine..
2473 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2475 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2476 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2477 ProcessorState pstate (this);
2479 apply_processor_order (new_order);
2481 if (configure_processors_unlocked (err, &lm)) {
2489 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2490 set_processor_positions ();
2493 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2494 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2496 // _pending_processor_order is protected by _processor_lock
2497 _pending_processor_order = new_order;
2498 g_atomic_int_set (&_pending_process_reorder, 1);
2505 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2507 boost::shared_ptr<PluginInsert> pi;
2508 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2512 if (pi->has_sidechain () == add) {
2513 return true; // ?? call failed, but result is as expected.
2517 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2518 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2519 if (i == _processors.end ()) {
2525 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2526 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2527 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2529 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2531 if (!pi->add_sidechain ()) {
2535 if (!pi->del_sidechain ()) {
2541 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2546 pi->del_sidechain ();
2548 pi->add_sidechain ();
2549 // TODO restore side-chain's state.
2554 configure_processors_unlocked (0, &lm);
2557 if (pi->has_sidechain ()) {
2558 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2561 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2562 _session.set_dirty ();
2567 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2569 boost::shared_ptr<PluginInsert> pi;
2570 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2575 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2576 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2577 if (i == _processors.end ()) {
2583 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2584 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2586 const ChanCount& old (pi->preset_out ());
2587 if (!pi->set_preset_out (outs)) {
2588 return true; // no change, OK
2591 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2594 pi->set_preset_out (old);
2597 configure_processors_unlocked (0, &lm);
2600 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2601 _session.set_dirty ();
2606 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2609 return customize_plugin_insert (proc, 0, unused, unused);
2613 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2615 boost::shared_ptr<PluginInsert> pi;
2616 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2621 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2622 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2623 if (i == _processors.end ()) {
2629 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2630 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2632 bool old_cust = pi->custom_cfg ();
2633 uint32_t old_cnt = pi->get_count ();
2634 ChanCount old_chan = pi->output_streams ();
2635 ChanCount old_sinks = pi->natural_input_streams ();
2638 pi->set_custom_cfg (false);
2640 pi->set_custom_cfg (true);
2641 pi->set_count (count);
2642 pi->set_outputs (outs);
2643 pi->set_sinks (sinks);
2646 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2650 pi->set_count (old_cnt);
2651 pi->set_sinks (old_sinks);
2652 pi->set_outputs (old_chan);
2653 pi->set_custom_cfg (old_cust);
2657 configure_processors_unlocked (0, &lm);
2660 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2661 _session.set_dirty ();
2666 Route::set_strict_io (const bool enable)
2668 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2670 if (_strict_io != enable) {
2671 _strict_io = enable;
2672 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2673 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2674 boost::shared_ptr<PluginInsert> pi;
2675 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2676 pi->set_strict_io (_strict_io);
2680 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2684 _strict_io = !enable; // restore old value
2685 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2686 boost::shared_ptr<PluginInsert> pi;
2687 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2688 pi->set_strict_io (_strict_io);
2695 configure_processors (0);
2698 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2699 _session.set_dirty ();
2711 Route::get_template()
2713 return state(false);
2717 Route::state(bool full_state)
2720 if (!_session._template_state_dir.empty()) {
2721 assert (!full_state); // only for templates
2722 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2725 XMLNode *node = new XMLNode("Route");
2726 ProcessorList::iterator i;
2729 id().print (buf, sizeof (buf));
2730 node->add_property("id", buf);
2731 node->add_property ("name", _name);
2732 node->add_property("default-type", _default_type.to_string());
2733 node->add_property ("strict-io", _strict_io);
2736 node->add_property("flags", enum_2_string (_flags));
2739 node->add_property("active", _active?"yes":"no");
2741 boost::to_string (_phase_invert, p);
2742 node->add_property("phase-invert", p);
2743 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2744 node->add_property("meter-point", enum_2_string (_meter_point));
2746 node->add_property("meter-type", enum_2_string (_meter_type));
2749 node->add_property("route-group", _route_group->name());
2752 snprintf (buf, sizeof (buf), "%d", _order_key);
2753 node->add_property ("order-key", buf);
2754 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2755 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2756 node->add_property ("soloed-by-upstream", buf);
2757 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2758 node->add_property ("soloed-by-downstream", buf);
2759 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2760 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2762 node->add_child_nocopy (_input->state (full_state));
2763 node->add_child_nocopy (_output->state (full_state));
2764 node->add_child_nocopy (_solo_control->get_state ());
2765 node->add_child_nocopy (_mute_control->get_state ());
2766 node->add_child_nocopy (_mute_master->get_state ());
2769 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2772 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2773 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2774 remote_control_node->add_property (X_("id"), buf);
2775 node->add_child_nocopy (*remote_control_node);
2777 if (_comment.length()) {
2778 XMLNode *cmt = node->add_child ("Comment");
2779 cmt->add_content (_comment);
2783 node->add_child_nocopy (_pannable->state (full_state));
2787 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2788 for (i = _processors.begin(); i != _processors.end(); ++i) {
2790 /* template save: do not include internal sends functioning as
2791 aux sends because the chance of the target ID
2792 in the session where this template is used
2795 similarly, do not save listen sends which connect to
2796 the monitor section, because these will always be
2799 boost::shared_ptr<InternalSend> is;
2801 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2802 if (is->role() == Delivery::Listen) {
2807 node->add_child_nocopy((*i)->state (full_state));
2812 node->add_child_copy (*_extra_xml);
2815 if (_custom_meter_position_noted) {
2816 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2818 after->id().print (buf, sizeof (buf));
2819 node->add_property (X_("processor-after-last-custom-meter"), buf);
2823 if (!_session._template_state_dir.empty()) {
2824 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2831 Route::set_state (const XMLNode& node, int version)
2833 if (version < 3000) {
2834 return set_state_2X (node, version);
2838 XMLNodeConstIterator niter;
2840 XMLProperty const * prop;
2842 if (node.name() != "Route"){
2843 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2847 if ((prop = node.property (X_("name"))) != 0) {
2848 Route::set_name (prop->value());
2852 _initial_io_setup = true;
2854 if ((prop = node.property (X_("flags"))) != 0) {
2855 _flags = Flag (string_2_enum (prop->value(), _flags));
2860 if ((prop = node.property (X_("strict-io"))) != 0) {
2861 _strict_io = string_is_affirmative (prop->value());
2864 if (is_master() || is_monitor() || is_auditioner()) {
2865 _mute_master->set_solo_ignore (true);
2869 /* monitor bus does not get a panner, but if (re)created
2870 via XML, it will already have one by the time we
2871 call ::set_state(). so ... remove it.
2876 /* add all processors (except amp, which is always present) */
2878 nlist = node.children();
2879 XMLNode processor_state (X_("processor_state"));
2881 Stateful::save_extra_xml (node);
2883 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2887 if (child->name() == IO::state_node_name) {
2888 if ((prop = child->property (X_("direction"))) == 0) {
2892 if (prop->value() == "Input") {
2893 _input->set_state (*child, version);
2894 } else if (prop->value() == "Output") {
2895 _output->set_state (*child, version);
2899 if (child->name() == X_("Processor")) {
2900 processor_state.add_child_copy (*child);
2903 if (child->name() == X_("Pannable")) {
2905 _pannable->set_state (*child, version);
2907 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2912 if ((prop = node.property (X_("meter-point"))) != 0) {
2913 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2914 set_meter_point (mp, true);
2916 _meter->set_display_to_user (_meter_point == MeterCustom);
2920 if ((prop = node.property (X_("meter-type"))) != 0) {
2921 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2924 _initial_io_setup = false;
2926 set_processor_state (processor_state);
2928 // this looks up the internal instrument in processors
2929 reset_instrument_info();
2931 if ((prop = node.property ("self-solo")) != 0) {
2932 set_self_solo (string_is_affirmative (prop->value()));
2935 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2936 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2937 mod_solo_by_others_upstream (atoi (prop->value()));
2940 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2941 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2942 mod_solo_by_others_downstream (atoi (prop->value()));
2945 if ((prop = node.property ("solo-isolated")) != 0) {
2946 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2949 if ((prop = node.property ("solo-safe")) != 0) {
2950 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2953 if ((prop = node.property (X_("phase-invert"))) != 0) {
2954 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2957 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2958 set_denormal_protection (string_is_affirmative (prop->value()));
2961 if ((prop = node.property (X_("active"))) != 0) {
2962 bool yn = string_is_affirmative (prop->value());
2963 set_active (yn, this);
2966 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2967 set_order_key (atoi(prop->value()));
2970 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2974 string::size_type colon, equal;
2975 string remaining = prop->value();
2977 while (remaining.length()) {
2979 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2980 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2983 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2984 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2987 string keyname = remaining.substr (0, equal);
2989 if ((keyname == "EditorSort") || (keyname == "editor")) {
2990 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2996 colon = remaining.find_first_of (':');
2998 if (colon != string::npos) {
2999 remaining = remaining.substr (colon+1);
3006 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
3007 PBD::ID id (prop->value ());
3008 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3009 ProcessorList::const_iterator i = _processors.begin ();
3010 while (i != _processors.end() && (*i)->id() != id) {
3014 if (i != _processors.end ()) {
3015 _processor_after_last_custom_meter = *i;
3016 _custom_meter_position_noted = true;
3020 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3023 if (child->name() == X_("Comment")) {
3025 /* XXX this is a terrible API design in libxml++ */
3027 XMLNode *cmt = *(child->children().begin());
3028 _comment = cmt->content();
3030 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3031 if (prop->value() == "solo") {
3032 _solo_control->set_state (*child, version);
3033 } else if (prop->value() == "mute") {
3034 _mute_control->set_state (*child, version);
3037 } else if (child->name() == X_("RemoteControl")) {
3038 if ((prop = child->property (X_("id"))) != 0) {
3040 sscanf (prop->value().c_str(), "%d", &x);
3041 set_remote_control_id_internal (x);
3044 } else if (child->name() == X_("MuteMaster")) {
3045 _mute_master->set_state (*child, version);
3047 } else if (child->name() == Automatable::xml_node_name) {
3048 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
3056 Route::set_state_2X (const XMLNode& node, int version)
3060 XMLNodeConstIterator niter;
3062 XMLProperty const * prop;
3064 /* 2X things which still remain to be handled:
3070 if (node.name() != "Route") {
3071 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
3075 if ((prop = node.property (X_("flags"))) != 0) {
3076 string f = prop->value ();
3077 boost::replace_all (f, "ControlOut", "MonitorOut");
3078 _flags = Flag (string_2_enum (f, _flags));
3083 if (is_master() || is_monitor() || is_auditioner()) {
3084 _mute_master->set_solo_ignore (true);
3087 if ((prop = node.property (X_("phase-invert"))) != 0) {
3088 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
3089 if (string_is_affirmative (prop->value ())) {
3092 set_phase_invert (p);
3095 if ((prop = node.property (X_("denormal-protection"))) != 0) {
3096 set_denormal_protection (string_is_affirmative (prop->value()));
3099 if ((prop = node.property (X_("soloed"))) != 0) {
3100 bool yn = string_is_affirmative (prop->value());
3102 /* XXX force reset of solo status */
3107 if ((prop = node.property (X_("muted"))) != 0) {
3110 bool muted = string_is_affirmative (prop->value());
3116 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
3118 if (string_is_affirmative (prop->value())){
3119 mute_point = mute_point + "PreFader";
3124 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
3126 if (string_is_affirmative (prop->value())){
3129 mute_point = mute_point + ",";
3132 mute_point = mute_point + "PostFader";
3137 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
3139 if (string_is_affirmative (prop->value())){
3142 mute_point = mute_point + ",";
3145 mute_point = mute_point + "Listen";
3150 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
3152 if (string_is_affirmative (prop->value())){
3155 mute_point = mute_point + ",";
3158 mute_point = mute_point + "Main";
3162 _mute_master->set_mute_points (mute_point);
3163 _mute_master->set_muted_by_self (true);
3167 if ((prop = node.property (X_("meter-point"))) != 0) {
3168 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
3171 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
3172 don't mean the same thing.
3175 if ((prop = node.property (X_("order-keys"))) != 0) {
3179 string::size_type colon, equal;
3180 string remaining = prop->value();
3182 while (remaining.length()) {
3184 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
3185 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3188 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
3189 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3192 string keyname = remaining.substr (0, equal);
3194 if (keyname == "EditorSort" || keyname == "editor") {
3195 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
3201 colon = remaining.find_first_of (':');
3203 if (colon != string::npos) {
3204 remaining = remaining.substr (colon+1);
3213 nlist = node.children ();
3214 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3218 if (child->name() == IO::state_node_name) {
3220 /* there is a note in IO::set_state_2X() about why we have to call
3224 _input->set_state_2X (*child, version, true);
3225 _output->set_state_2X (*child, version, false);
3227 if ((prop = child->property (X_("name"))) != 0) {
3228 Route::set_name (prop->value ());
3233 if ((prop = child->property (X_("active"))) != 0) {
3234 bool yn = string_is_affirmative (prop->value());
3235 _active = !yn; // force switch
3236 set_active (yn, this);
3239 if ((prop = child->property (X_("gain"))) != 0) {
3242 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
3243 _amp->gain_control()->set_value (val, Controllable::NoGroup);
3247 /* Set up Panners in the IO */
3248 XMLNodeList io_nlist = child->children ();
3250 XMLNodeConstIterator io_niter;
3253 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
3255 io_child = *io_niter;
3257 if (io_child->name() == X_("Panner")) {
3258 _main_outs->panner_shell()->set_state(*io_child, version);
3259 } else if (io_child->name() == X_("Automation")) {
3260 /* IO's automation is for the fader */
3261 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
3267 XMLNodeList redirect_nodes;
3269 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3273 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
3274 redirect_nodes.push_back(child);
3279 set_processor_state_2X (redirect_nodes, version);
3281 Stateful::save_extra_xml (node);
3283 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3286 if (child->name() == X_("Comment")) {
3288 /* XXX this is a terrible API design in libxml++ */
3290 XMLNode *cmt = *(child->children().begin());
3291 _comment = cmt->content();
3293 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3294 if (prop->value() == X_("solo")) {
3295 _solo_control->set_state (*child, version);
3296 } else if (prop->value() == X_("mute")) {
3297 _mute_control->set_state (*child, version);
3300 } else if (child->name() == X_("RemoteControl")) {
3301 if ((prop = child->property (X_("id"))) != 0) {
3303 sscanf (prop->value().c_str(), "%d", &x);
3304 set_remote_control_id_internal (x);
3314 Route::get_processor_state ()
3316 XMLNode* root = new XMLNode (X_("redirects"));
3317 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3318 root->add_child_nocopy ((*i)->state (true));
3325 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
3327 /* We don't bother removing existing processors not in nList, as this
3328 method will only be called when creating a Route from scratch, not
3329 for undo purposes. Just put processors in at the appropriate place
3333 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
3334 add_processor_from_xml_2X (**i, version);
3339 Route::set_processor_state (const XMLNode& node)
3341 const XMLNodeList &nlist = node.children();
3342 XMLNodeConstIterator niter;
3343 ProcessorList new_order;
3344 bool must_configure = false;
3346 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3348 XMLProperty const * prop = (*niter)->property ("type");
3350 if (prop->value() == "amp") {
3351 _amp->set_state (**niter, Stateful::current_state_version);
3352 new_order.push_back (_amp);
3353 } else if (prop->value() == "trim") {
3354 _trim->set_state (**niter, Stateful::current_state_version);
3355 new_order.push_back (_trim);
3356 } else if (prop->value() == "meter") {
3357 _meter->set_state (**niter, Stateful::current_state_version);
3358 new_order.push_back (_meter);
3359 } else if (prop->value() == "delay") {
3361 _delayline->set_state (**niter, Stateful::current_state_version);
3362 new_order.push_back (_delayline);
3364 } else if (prop->value() == "main-outs") {
3365 _main_outs->set_state (**niter, Stateful::current_state_version);
3366 } else if (prop->value() == "intreturn") {
3368 _intreturn.reset (new InternalReturn (_session));
3369 must_configure = true;
3371 _intreturn->set_state (**niter, Stateful::current_state_version);
3372 } else if (is_monitor() && prop->value() == "monitor") {
3373 if (!_monitor_control) {
3374 _monitor_control.reset (new MonitorProcessor (_session));
3375 must_configure = true;
3377 _monitor_control->set_state (**niter, Stateful::current_state_version);
3378 } else if (prop->value() == "capture") {
3379 /* CapturingProcessor should never be restored, it's always
3380 added explicitly when needed */
3382 ProcessorList::iterator o;
3384 for (o = _processors.begin(); o != _processors.end(); ++o) {
3385 XMLProperty const * id_prop = (*niter)->property(X_("id"));
3386 if (id_prop && (*o)->id() == id_prop->value()) {
3387 (*o)->set_state (**niter, Stateful::current_state_version);
3388 new_order.push_back (*o);
3393 // If the processor (*niter) is not on the route then create it
3395 if (o == _processors.end()) {
3397 boost::shared_ptr<Processor> processor;
3399 if (prop->value() == "intsend") {
3401 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3403 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3404 prop->value() == "lv2" ||
3405 prop->value() == "windows-vst" ||
3406 prop->value() == "lxvst" ||
3407 prop->value() == "luaproc" ||
3408 prop->value() == "audiounit") {
3410 if (_session.get_disable_all_loaded_plugins ()) {
3411 processor.reset (new UnknownProcessor (_session, **niter));
3413 processor.reset (new PluginInsert (_session));
3414 processor->set_owner (this);
3416 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3417 pi->set_strict_io (true);
3421 } else if (prop->value() == "port") {
3423 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3425 } else if (prop->value() == "send") {
3427 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3428 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3429 send->SelfDestruct.connect_same_thread (*this,
3430 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3433 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3437 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3438 /* This processor could not be configured. Turn it into a UnknownProcessor */
3439 processor.reset (new UnknownProcessor (_session, **niter));
3442 /* subscribe to Sidechain IO changes */
3443 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3444 if (pi && pi->has_sidechain ()) {
3445 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3448 /* we have to note the monitor send here, otherwise a new one will be created
3449 and the state of this one will be lost.
3451 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3452 if (isend && isend->role() == Delivery::Listen) {
3453 _monitor_send = isend;
3456 /* it doesn't matter if invisible processors are added here, as they
3457 will be sorted out by setup_invisible_processors () shortly.
3460 new_order.push_back (processor);
3461 must_configure = true;
3467 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3468 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3469 _processors = new_order;
3471 if (must_configure) {
3472 configure_processors_unlocked (0, &lm);
3475 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3477 (*i)->set_owner (this);
3478 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3480 boost::shared_ptr<PluginInsert> pi;
3482 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3483 if (pi->has_no_inputs ()) {
3484 _have_internal_generator = true;
3491 reset_instrument_info ();
3492 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3493 set_processor_positions ();
3497 Route::curve_reallocate ()
3499 // _gain_automation_curve.finish_resize ();
3500 // _pan_automation_curve.finish_resize ();
3504 Route::silence (framecnt_t nframes)
3506 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3511 silence_unlocked (nframes);
3515 Route::silence_unlocked (framecnt_t nframes)
3517 /* Must be called with the processor lock held */
3521 _output->silence (nframes);
3523 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3524 boost::shared_ptr<PluginInsert> pi;
3526 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3527 // skip plugins, they don't need anything when we're not active
3531 (*i)->silence (nframes);
3534 if (nframes == _session.get_block_size()) {
3541 Route::add_internal_return ()
3544 _intreturn.reset (new InternalReturn (_session));
3545 add_processor (_intreturn, PreFader);
3550 Route::add_send_to_internal_return (InternalSend* send)
3552 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3554 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3555 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3558 return d->add_send (send);
3564 Route::remove_send_from_internal_return (InternalSend* send)
3566 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3568 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3569 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3572 return d->remove_send (send);
3578 Route::enable_monitor_send ()
3580 /* Caller must hold process lock */
3581 assert (!AudioEngine::instance()->process_lock().trylock());
3583 /* master never sends to monitor section via the normal mechanism */
3584 assert (!is_master ());
3585 assert (!is_monitor ());
3587 /* make sure we have one */
3588 if (!_monitor_send) {
3589 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3590 _monitor_send->set_display_to_user (false);
3594 configure_processors (0);
3597 /** Add an aux send to a route.
3598 * @param route route to send to.
3599 * @param before Processor to insert before, or 0 to insert at the end.
3602 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3604 assert (route != _session.monitor_out ());
3607 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3609 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3611 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3613 if (d && d->target_route() == route) {
3614 /* already listening via the specified IO: do nothing */
3622 boost::shared_ptr<InternalSend> listener;
3625 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3626 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3627 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3630 add_processor (listener, before);
3632 } catch (failed_constructor& err) {
3640 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3642 ProcessorStreams err;
3643 ProcessorList::iterator tmp;
3646 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3648 /* have to do this early because otherwise processor reconfig
3649 * will put _monitor_send back in the list
3652 if (route == _session.monitor_out()) {
3653 _monitor_send.reset ();
3657 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3659 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3661 if (d && d->target_route() == route) {
3663 if (remove_processor (*x, &err, false) > 0) {
3669 /* list could have been demolished while we dropped the lock
3672 if (_session.engine().connected()) {
3673 /* i/o processors cannot be removed if the engine is not running
3674 * so don't live-loop in case the engine is N/A or dies
3684 Route::set_comment (string cmt, void *src)
3688 _session.set_dirty ();
3692 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3694 FeedRecord fr (other, via_sends_only);
3696 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3698 if (!result.second) {
3700 /* already a record for "other" - make sure sends-only information is correct */
3701 if (!via_sends_only && result.first->sends_only) {
3702 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3703 frp->sends_only = false;
3707 return result.second;
3711 Route::clear_fed_by ()
3717 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3719 const FedBy& fed_by (other->fed_by());
3721 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3722 boost::shared_ptr<Route> sr = f->r.lock();
3724 if (sr && (sr.get() == this)) {
3726 if (via_sends_only) {
3727 *via_sends_only = f->sends_only;
3738 Route::all_inputs () const
3740 /* TODO, if this works as expected,
3741 * cache the IOVector and maintain it via
3742 * input_change_handler(), sidechain_change_handler() etc
3745 ios.push_back (_input);
3747 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3748 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3750 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3751 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3754 iop = pi->sidechain();
3757 if (iop != 0 && iop->input()) {
3758 ios.push_back (iop->input());
3765 Route::all_outputs () const
3768 // _output is included via Delivery
3769 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3770 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3771 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3772 if (iop != 0 && iop->output()) {
3773 ios.push_back (iop->output());
3780 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3782 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3783 if (other->all_inputs().fed_by (_output)) {
3784 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3785 if (via_send_only) {
3786 *via_send_only = false;
3792 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3794 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3796 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3797 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3800 iop = pi->sidechain();
3804 boost::shared_ptr<const IO> iop_out = iop->output();
3805 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3806 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3807 if (via_send_only) {
3808 *via_send_only = true;
3812 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3815 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3820 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3825 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3827 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3831 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3833 return _session._current_route_graph.feeds (shared_from_this (), other);
3836 /** Called from the (non-realtime) butler thread when the transport is stopped */
3838 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3840 framepos_t now = _session.transport_frame();
3843 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3845 Automatable::transport_stopped (now);
3847 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3849 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3853 (*i)->transport_stopped (now);
3857 _roll_delay = _initial_delay;
3861 Route::input_change_handler (IOChange change, void * /*src*/)
3863 if ((change.type & IOChange::ConfigurationChanged)) {
3864 /* This is called with the process lock held if change
3865 contains ConfigurationChanged
3867 configure_processors (0);
3868 _phase_invert.resize (_input->n_ports().n_audio ());
3869 io_changed (); /* EMIT SIGNAL */
3872 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3875 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3876 if (_input->connected()) {
3877 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3878 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3882 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3883 if (does_feed && !sends_only) {
3884 if ((*i)->soloed()) {
3887 if ((*i)->solo_isolated()) {
3894 int delta = sbou - _soloed_by_others_upstream;
3895 int idelta = ibou - _solo_isolated_by_upstream;
3898 PBD::warning << string_compose (
3899 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3900 _name, ibou, _solo_isolated_by_upstream, idelta)
3905 if (_soloed_by_others_upstream) {
3906 // ignore new connections (they're not propagated)
3908 mod_solo_by_others_upstream (delta);
3912 if (_solo_isolated_by_upstream) {
3913 // solo-isolate currently only propagates downstream
3915 mod_solo_isolated_by_upstream (false);
3917 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3918 // but idelta can't be smaller than -1, can it?
3919 //_solo_isolated_by_upstream = ibou;
3922 // Session::route_solo_changed does not propagate indirect solo-changes
3923 // propagate downstream to tracks
3924 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3925 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3929 bool does_feed = feeds (*i, &sends_only);
3930 if (delta <= 0 && does_feed && !sends_only) {
3931 (*i)->mod_solo_by_others_upstream (delta);
3934 if (idelta < 0 && does_feed && !sends_only) {
3935 (*i)->mod_solo_isolated_by_upstream (false);
3942 Route::output_change_handler (IOChange change, void * /*src*/)
3944 if (_initial_io_setup) {
3948 if ((change.type & IOChange::ConfigurationChanged)) {
3949 /* This is called with the process lock held if change
3950 contains ConfigurationChanged
3952 configure_processors (0);
3955 _session.reset_monitor_section();
3958 io_changed (); /* EMIT SIGNAL */
3961 if (_soloed_by_others_downstream) {
3963 /* checking all all downstream routes for
3964 * explicit of implict solo is a rather drastic measure,
3965 * ideally the input_change_handler() of the other route
3966 * would propagate the change to us.
3968 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3969 if (_output->connected()) {
3970 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3971 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3975 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3976 if (does_feed && !sends_only) {
3977 if ((*i)->soloed()) {
3984 int delta = sbod - _soloed_by_others_downstream;
3986 // do not allow new connections to change implicit solo (no propagation)
3987 mod_solo_by_others_downstream (delta);
3988 // Session::route_solo_changed() does not propagate indirect solo-changes
3989 // propagate upstream to tracks
3990 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3991 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3995 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3996 if (delta != 0 && does_feed && !sends_only) {
3997 (*i)->mod_solo_by_others_downstream (delta);
4006 Route::sidechain_change_handler (IOChange change, void* src)
4008 if (_initial_io_setup || _in_sidechain_setup) {
4012 input_change_handler (change, src);
4016 Route::pans_required () const
4018 if (n_outputs().n_audio() < 2) {
4022 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
4026 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
4028 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4034 if (n_outputs().n_total() == 0) {
4038 if (!_active || n_inputs() == ChanCount::ZERO) {
4039 silence_unlocked (nframes);
4043 if (session_state_changing) {
4044 if (_session.transport_speed() != 0.0f) {
4045 /* we're rolling but some state is changing (e.g. our diskstream contents)
4046 so we cannot use them. Be silent till this is over.
4048 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
4050 silence_unlocked (nframes);
4053 /* we're really not rolling, so we're either delivery silence or actually
4054 monitoring, both of which are safe to do while session_state_changing is true.
4058 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4060 fill_buffers_with_input (bufs, _input, nframes);
4062 if (_meter_point == MeterInput) {
4063 _meter->run (bufs, start_frame, end_frame, nframes, true);
4066 _amp->apply_gain_automation (false);
4067 _trim->apply_gain_automation (false);
4068 passthru (bufs, start_frame, end_frame, nframes, 0);
4074 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
4076 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4081 if (n_outputs().n_total() == 0) {
4085 if (!_active || n_inputs().n_total() == 0) {
4086 silence_unlocked (nframes);
4090 framepos_t unused = 0;
4092 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
4098 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4100 fill_buffers_with_input (bufs, _input, nframes);
4102 if (_meter_point == MeterInput) {
4103 _meter->run (bufs, start_frame, end_frame, nframes, true);
4106 passthru (bufs, start_frame, end_frame, nframes, declick);
4112 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
4119 Route::flush_processors ()
4121 /* XXX shouldn't really try to take this lock, since
4122 this is called from the RT audio thread.
4125 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4127 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4133 __attribute__((annotate("realtime")))
4136 Route::apply_processor_changes_rt ()
4138 int emissions = EmitNone;
4140 if (_pending_meter_point != _meter_point) {
4141 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4143 /* meters always have buffers for 'processor_max_streams'
4144 * they can be re-positioned without re-allocation */
4145 if (set_meter_point_unlocked()) {
4146 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
4148 emissions |= EmitMeterChanged;
4153 bool changed = false;
4155 if (g_atomic_int_get (&_pending_process_reorder)) {
4156 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4158 apply_processor_order (_pending_processor_order);
4159 setup_invisible_processors ();
4161 g_atomic_int_set (&_pending_process_reorder, 0);
4162 emissions |= EmitRtProcessorChange;
4166 set_processor_positions ();
4168 if (emissions != 0) {
4169 g_atomic_int_set (&_pending_signals, emissions);
4172 return (!selfdestruct_sequence.empty ());
4176 Route::emit_pending_signals ()
4178 int sig = g_atomic_int_and (&_pending_signals, 0);
4179 if (sig & EmitMeterChanged) {
4180 _meter->emit_configuration_changed();
4181 meter_change (); /* EMIT SIGNAL */
4182 if (sig & EmitMeterVisibilityChange) {
4183 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4185 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4188 if (sig & EmitRtProcessorChange) {
4189 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
4192 /* this would be a job for the butler.
4193 * Conceptually we should not take processe/processor locks here.
4194 * OTOH its more efficient (less overhead for summoning the butler and
4195 * telling her what do do) and signal emission is called
4196 * directly after the process callback, which decreases the chance
4197 * of x-runs when taking the locks.
4199 while (!selfdestruct_sequence.empty ()) {
4200 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
4201 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
4202 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
4203 selfdestruct_sequence.pop_back ();
4206 remove_processor (proc);
4212 Route::set_meter_point (MeterPoint p, bool force)
4214 if (_pending_meter_point == p && !force) {
4218 if (force || !AudioEngine::instance()->running()) {
4219 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4220 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4221 _pending_meter_point = p;
4222 _meter->emit_configuration_changed();
4223 meter_change (); /* EMIT SIGNAL */
4224 if (set_meter_point_unlocked()) {
4225 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4227 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4230 _pending_meter_point = p;
4236 __attribute__((annotate("realtime")))
4239 Route::set_meter_point_unlocked ()
4242 /* Caller must hold process and processor write lock */
4243 assert (!AudioEngine::instance()->process_lock().trylock());
4244 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4245 assert (!lm.locked ());
4248 _meter_point = _pending_meter_point;
4250 bool meter_was_visible_to_user = _meter->display_to_user ();
4252 if (!_custom_meter_position_noted) {
4253 maybe_note_meter_position ();
4256 if (_meter_point != MeterCustom) {
4258 _meter->set_display_to_user (false);
4260 setup_invisible_processors ();
4263 _meter->set_display_to_user (true);
4265 /* If we have a previous position for the custom meter, try to put it there */
4266 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
4268 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
4269 if (i != _processors.end ()) {
4270 _processors.remove (_meter);
4271 _processors.insert (i, _meter);
4273 } else {// at end, right before the mains_out/panner
4274 _processors.remove (_meter);
4275 ProcessorList::iterator main = _processors.end();
4276 _processors.insert (--main, _meter);
4280 /* Set up the meter for its new position */
4282 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4286 if (loc == _processors.begin()) {
4287 m_in = _input->n_ports();
4289 ProcessorList::iterator before = loc;
4291 m_in = (*before)->output_streams ();
4294 _meter->reflect_inputs (m_in);
4296 /* we do not need to reconfigure the processors, because the meter
4297 (a) is always ready to handle processor_max_streams
4298 (b) is always an N-in/N-out processor, and thus moving
4299 it doesn't require any changes to the other processors.
4302 /* these should really be done after releasing the lock
4303 * but all those signals are subscribed to with gui_thread()
4306 return (_meter->display_to_user() != meter_was_visible_to_user);
4310 Route::listen_position_changed ()
4313 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4314 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4315 ProcessorState pstate (this);
4317 if (configure_processors_unlocked (0, &lm)) {
4318 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4320 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4325 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4326 _session.set_dirty ();
4329 boost::shared_ptr<CapturingProcessor>
4330 Route::add_export_point()
4332 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4333 if (!_capturing_processor) {
4335 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4336 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4338 _capturing_processor.reset (new CapturingProcessor (_session));
4339 _capturing_processor->activate ();
4341 configure_processors_unlocked (0, &lw);
4345 return _capturing_processor;
4349 Route::update_signal_latency ()
4351 framecnt_t l = _output->user_latency();
4352 framecnt_t lamp = 0;
4353 bool before_amp = true;
4354 framecnt_t ltrim = 0;
4355 bool before_trim = true;
4357 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4358 if ((*i)->active ()) {
4359 l += (*i)->signal_latency ();
4364 if ((*i) == _trim) {
4375 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
4377 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
4378 _signal_latency_at_amp_position = lamp;
4379 _signal_latency_at_trim_position = ltrim;
4381 if (_signal_latency != l) {
4382 _signal_latency = l;
4383 signal_latency_changed (); /* EMIT SIGNAL */
4386 return _signal_latency;
4390 Route::set_user_latency (framecnt_t nframes)
4392 _output->set_user_latency (nframes);
4393 _session.update_latency_compensation ();
4397 Route::set_latency_compensation (framecnt_t longest_session_latency)
4399 framecnt_t old = _initial_delay;
4401 if (_signal_latency < longest_session_latency) {
4402 _initial_delay = longest_session_latency - _signal_latency;
4407 DEBUG_TRACE (DEBUG::Latency, string_compose (
4408 "%1: compensate for maximum latency of %2,"
4409 "given own latency of %3, using initial delay of %4\n",
4410 name(), longest_session_latency, _signal_latency, _initial_delay));
4412 if (_initial_delay != old) {
4413 initial_delay_changed (); /* EMIT SIGNAL */
4416 if (_session.transport_stopped()) {
4417 _roll_delay = _initial_delay;
4422 Route::set_block_size (pframes_t nframes)
4424 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4425 (*i)->set_block_size (nframes);
4428 _session.ensure_buffers (n_process_buffers ());
4432 Route::protect_automation ()
4434 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4435 (*i)->protect_automation();
4438 /** @param declick 1 to set a pending declick fade-in,
4439 * -1 to set a pending declick fade-out
4442 Route::set_pending_declick (int declick)
4445 /* this call is not allowed to turn off a pending declick */
4447 _pending_declick = declick;
4450 _pending_declick = 0;
4454 /** Shift automation forwards from a particular place, thereby inserting time.
4455 * Adds undo commands for any shifts that are performed.
4457 * @param pos Position to start shifting from.
4458 * @param frames Amount to shift forwards by.
4462 Route::shift (framepos_t pos, framecnt_t frames)
4464 /* gain automation */
4466 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4468 XMLNode &before = gc->alist()->get_state ();
4469 gc->alist()->shift (pos, frames);
4470 XMLNode &after = gc->alist()->get_state ();
4471 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4474 /* gain automation */
4476 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4478 XMLNode &before = gc->alist()->get_state ();
4479 gc->alist()->shift (pos, frames);
4480 XMLNode &after = gc->alist()->get_state ();
4481 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4484 // TODO mute automation ??
4486 /* pan automation */
4488 ControlSet::Controls& c (_pannable->controls());
4490 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4491 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4493 boost::shared_ptr<AutomationList> al = pc->alist();
4494 XMLNode& before = al->get_state ();
4495 al->shift (pos, frames);
4496 XMLNode& after = al->get_state ();
4497 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4502 /* redirect automation */
4504 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4505 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4507 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4509 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4510 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4512 boost::shared_ptr<AutomationList> al = ac->alist();
4513 XMLNode &before = al->get_state ();
4514 al->shift (pos, frames);
4515 XMLNode &after = al->get_state ();
4516 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4524 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4526 boost::shared_ptr<Processor> processor (p.lock ());
4527 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4531 pi->set_state_dir (d);
4535 Route::save_as_template (const string& path, const string& name)
4537 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4538 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4540 XMLNode& node (state (false));
4544 IO::set_name_in_state (*node.children().front(), name);
4546 tree.set_root (&node);
4548 /* return zero on success, non-zero otherwise */
4549 return !tree.write (path.c_str());
4554 Route::set_name (const string& str)
4556 if (str == name()) {
4560 string name = Route::ensure_track_or_route_name (str, _session);
4561 SessionObject::set_name (name);
4563 bool ret = (_input->set_name(name) && _output->set_name(name));
4566 /* rename the main outs. Leave other IO processors
4567 * with whatever name they already have, because its
4568 * just fine as it is (it will not contain the route
4569 * name if its a port insert, port send or port return).
4573 if (_main_outs->set_name (name)) {
4574 /* XXX returning false here is stupid because
4575 we already changed the route name.
4585 /** Set the name of a route in an XML description.
4586 * @param node XML <Route> node to set the name in.
4587 * @param name New name.
4590 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4592 node.add_property (X_("name"), name);
4594 XMLNodeList children = node.children();
4595 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4597 if ((*i)->name() == X_("IO")) {
4599 IO::set_name_in_state (**i, name);
4601 } else if ((*i)->name() == X_("Processor")) {
4603 XMLProperty const * role = (*i)->property (X_("role"));
4604 if (role && role->value() == X_("Main")) {
4605 (*i)->add_property (X_("name"), name);
4608 } else if ((*i)->name() == X_("Diskstream")) {
4610 if (rename_playlist) {
4611 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4613 (*i)->add_property (X_("name"), name);
4619 boost::shared_ptr<Send>
4620 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4622 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4624 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4625 boost::shared_ptr<InternalSend> send;
4627 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4628 if (send->target_route() == target) {
4634 return boost::shared_ptr<Send>();
4637 /** @param c Audio channel index.
4638 * @param yn true to invert phase, otherwise false.
4641 Route::set_phase_invert (uint32_t c, bool yn)
4643 if (_phase_invert[c] != yn) {
4644 _phase_invert[c] = yn;
4645 phase_invert_changed (); /* EMIT SIGNAL */
4646 _phase_control->Changed(); /* EMIT SIGNAL */
4647 _session.set_dirty ();
4652 Route::set_phase_invert (boost::dynamic_bitset<> p)
4654 if (_phase_invert != p) {
4656 phase_invert_changed (); /* EMIT SIGNAL */
4657 _session.set_dirty ();
4662 Route::phase_invert (uint32_t c) const
4664 return _phase_invert[c];
4667 boost::dynamic_bitset<>
4668 Route::phase_invert () const
4670 return _phase_invert;
4674 Route::set_denormal_protection (bool yn)
4676 if (_denormal_protection != yn) {
4677 _denormal_protection = yn;
4678 denormal_protection_changed (); /* EMIT SIGNAL */
4683 Route::denormal_protection () const
4685 return _denormal_protection;
4689 Route::set_active (bool yn, void* src)
4691 if (_session.transport_rolling()) {
4695 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4696 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4700 if (_active != yn) {
4702 _input->set_active (yn);
4703 _output->set_active (yn);
4704 active_changed (); // EMIT SIGNAL
4705 _session.set_dirty ();
4709 boost::shared_ptr<Pannable>
4710 Route::pannable() const
4715 boost::shared_ptr<Panner>
4716 Route::panner() const
4719 return _main_outs->panner_shell()->panner();
4722 boost::shared_ptr<PannerShell>
4723 Route::panner_shell() const
4725 return _main_outs->panner_shell();
4728 boost::shared_ptr<GainControl>
4729 Route::gain_control() const
4731 return _gain_control;
4734 boost::shared_ptr<GainControl>
4735 Route::trim_control() const
4737 return _trim_control;
4740 boost::shared_ptr<Route::PhaseControllable>
4741 Route::phase_control() const
4743 if (phase_invert().size()) {
4744 return _phase_control;
4746 return boost::shared_ptr<PhaseControllable>();
4750 boost::shared_ptr<AutomationControl>
4751 Route::get_control (const Evoral::Parameter& param)
4753 /* either we own the control or .... */
4755 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4759 /* maybe one of our processors does or ... */
4761 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4762 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4763 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4771 /* nobody does so we'll make a new one */
4773 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4780 boost::shared_ptr<Processor>
4781 Route::nth_plugin (uint32_t n) const
4783 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4784 ProcessorList::const_iterator i;
4786 for (i = _processors.begin(); i != _processors.end(); ++i) {
4787 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4794 return boost::shared_ptr<Processor> ();
4797 boost::shared_ptr<Processor>
4798 Route::nth_send (uint32_t n) const
4800 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4801 ProcessorList::const_iterator i;
4803 for (i = _processors.begin(); i != _processors.end(); ++i) {
4804 if (boost::dynamic_pointer_cast<Send> (*i)) {
4806 if ((*i)->name().find (_("Monitor")) == 0) {
4807 /* send to monitor section is not considered
4808 to be an accessible send.
4819 return boost::shared_ptr<Processor> ();
4823 Route::has_io_processor_named (const string& name)
4825 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4826 ProcessorList::iterator i;
4828 for (i = _processors.begin(); i != _processors.end(); ++i) {
4829 if (boost::dynamic_pointer_cast<Send> (*i) ||
4830 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4831 if ((*i)->name() == name) {
4840 MuteMaster::MutePoint
4841 Route::mute_points () const
4843 return _mute_master->mute_points ();
4847 Route::set_processor_positions ()
4849 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4851 bool had_amp = false;
4852 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4853 (*i)->set_pre_fader (!had_amp);
4860 /** Called when there is a proposed change to the input port count */
4862 Route::input_port_count_changing (ChanCount to)
4864 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4866 /* The processors cannot be configured with the new input arrangement, so
4872 /* The change is ok */
4876 /** Called when there is a proposed change to the output port count */
4878 Route::output_port_count_changing (ChanCount to)
4880 if (_strict_io && !_in_configure_processors) {
4883 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4884 if (processor_out_streams.get(*t) > to.get(*t)) {
4888 /* The change is ok */
4893 Route::unknown_processors () const
4897 if (_session.get_disable_all_loaded_plugins ()) {
4898 // Do not list "missing plugins" if they are explicitly disabled
4902 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4903 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4904 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4905 p.push_back ((*i)->name ());
4914 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4916 /* we assume that all our input ports feed all our output ports. its not
4917 universally true, but the alternative is way too corner-case to worry about.
4920 LatencyRange all_connections;
4923 all_connections.min = 0;
4924 all_connections.max = 0;
4926 all_connections.min = ~((pframes_t) 0);
4927 all_connections.max = 0;
4929 /* iterate over all "from" ports and determine the latency range for all of their
4930 connections to the "outside" (outside of this Route).
4933 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4937 p->get_connected_latency_range (range, playback);
4939 all_connections.min = min (all_connections.min, range.min);
4940 all_connections.max = max (all_connections.max, range.max);
4944 /* set the "from" port latencies to the max/min range of all their connections */
4946 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4947 p->set_private_latency_range (all_connections, playback);
4950 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4952 all_connections.min += our_latency;
4953 all_connections.max += our_latency;
4955 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4956 p->set_private_latency_range (all_connections, playback);
4959 return all_connections.max;
4963 Route::set_private_port_latencies (bool playback) const
4965 framecnt_t own_latency = 0;
4967 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4968 OR LATENCY CALLBACK.
4970 This is called (early) from the latency callback. It computes the REAL
4971 latency associated with each port and stores the result as the "private"
4972 latency of the port. A later call to Route::set_public_port_latencies()
4973 sets all ports to the same value to reflect the fact that we do latency
4974 compensation and so all signals are delayed by the same amount as they
4975 flow through ardour.
4978 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4979 if ((*i)->active ()) {
4980 own_latency += (*i)->signal_latency ();
4985 /* playback: propagate latency from "outside the route" to outputs to inputs */
4986 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4988 /* capture: propagate latency from "outside the route" to inputs to outputs */
4989 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4994 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4996 /* this is called to set the JACK-visible port latencies, which take
4997 latency compensation into account.
5006 const PortSet& ports (_input->ports());
5007 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
5008 p->set_public_latency_range (range, playback);
5013 const PortSet& ports (_output->ports());
5014 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
5015 p->set_public_latency_range (range, playback);
5020 /** Put the invisible processors in the right place in _processors.
5021 * Must be called with a writer lock on _processor_lock held.
5024 __attribute__((annotate("realtime")))
5027 Route::setup_invisible_processors ()
5030 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
5031 assert (!lm.locked ());
5035 /* too early to be doing this stuff */
5039 /* we'll build this new list here and then use it
5041 * TODO put the ProcessorList is on the stack for RT-safety.
5044 ProcessorList new_processors;
5046 /* find visible processors */
5048 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5049 if ((*i)->display_to_user ()) {
5050 new_processors.push_back (*i);
5056 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
5058 if (amp == new_processors.end ()) {
5059 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
5060 new_processors.push_front (_amp);
5061 amp = find (new_processors.begin(), new_processors.end(), _amp);
5064 /* and the processor after the amp */
5066 ProcessorList::iterator after_amp = amp;
5072 switch (_meter_point) {
5074 assert (!_meter->display_to_user ());
5075 new_processors.push_front (_meter);
5078 assert (!_meter->display_to_user ());
5079 new_processors.insert (amp, _meter);
5081 case MeterPostFader:
5082 /* do nothing here */
5085 /* do nothing here */
5088 /* the meter is visible, so we don't touch it here */
5095 assert (_main_outs);
5096 assert (!_main_outs->display_to_user ());
5097 new_processors.push_back (_main_outs);
5099 /* iterator for the main outs */
5101 ProcessorList::iterator main = new_processors.end();
5104 /* OUTPUT METERING */
5106 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
5107 assert (!_meter->display_to_user ());
5109 /* add the processor just before or just after the main outs */
5111 ProcessorList::iterator meter_point = main;
5113 if (_meter_point == MeterOutput) {
5116 new_processors.insert (meter_point, _meter);
5121 if (_monitor_send && !is_monitor ()) {
5122 assert (!_monitor_send->display_to_user ());
5123 switch (Config->get_listen_position ()) {
5124 case PreFaderListen:
5125 switch (Config->get_pfl_position ()) {
5126 case PFLFromBeforeProcessors:
5127 new_processors.push_front (_monitor_send);
5129 case PFLFromAfterProcessors:
5130 new_processors.insert (amp, _monitor_send);
5133 _monitor_send->set_can_pan (false);
5135 case AfterFaderListen:
5136 switch (Config->get_afl_position ()) {
5137 case AFLFromBeforeProcessors:
5138 new_processors.insert (after_amp, _monitor_send);
5140 case AFLFromAfterProcessors:
5141 new_processors.insert (new_processors.end(), _monitor_send);
5144 _monitor_send->set_can_pan (true);
5149 #if 0 // not used - just yet
5150 if (!is_master() && !is_monitor() && !is_auditioner()) {
5151 new_processors.push_front (_delayline);
5155 /* MONITOR CONTROL */
5157 if (_monitor_control && is_monitor ()) {
5158 assert (!_monitor_control->display_to_user ());
5159 new_processors.insert (amp, _monitor_control);
5162 /* INTERNAL RETURN */
5164 /* doing this here means that any monitor control will come just after
5169 assert (!_intreturn->display_to_user ());
5170 new_processors.push_front (_intreturn);
5173 if (_trim && _trim->active()) {
5174 assert (!_trim->display_to_user ());
5175 new_processors.push_front (_trim);
5177 /* EXPORT PROCESSOR */
5179 if (_capturing_processor) {
5180 assert (!_capturing_processor->display_to_user ());
5181 new_processors.push_front (_capturing_processor);
5184 _processors = new_processors;
5186 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5187 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
5192 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5193 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5194 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5201 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5202 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5206 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5207 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5214 /** If the meter point is `Custom', make a note of where the meter is.
5215 * This is so that if the meter point is subsequently set to something else,
5216 * and then back to custom, we can put the meter back where it was last time
5217 * custom was enabled.
5219 * Must be called with the _processor_lock held.
5222 Route::maybe_note_meter_position ()
5224 if (_meter_point != MeterCustom) {
5228 _custom_meter_position_noted = true;
5229 /* custom meter points range from after trim to before panner/main_outs
5230 * this is a limitation by the current processor UI
5232 bool seen_trim = false;
5233 _processor_after_last_custom_meter.reset();
5234 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5235 if ((*i) == _trim) {
5238 if ((*i) == _main_outs) {
5239 _processor_after_last_custom_meter = *i;
5242 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5244 _processor_after_last_custom_meter = _trim;
5246 ProcessorList::iterator j = i;
5248 assert(j != _processors.end ()); // main_outs should be before
5249 _processor_after_last_custom_meter = *j;
5254 assert(_processor_after_last_custom_meter.lock());
5257 boost::shared_ptr<Processor>
5258 Route::processor_by_id (PBD::ID id) const
5260 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5261 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5262 if ((*i)->id() == id) {
5267 return boost::shared_ptr<Processor> ();
5270 /** @return the monitoring state, or in other words what data we are pushing
5271 * into the route (data from the inputs, data from disk or silence)
5274 Route::monitoring_state () const
5276 return MonitoringInput;
5279 /** @return what we should be metering; either the data coming from the input
5280 * IO or the data that is flowing through the route.
5283 Route::metering_state () const
5285 return MeteringRoute;
5289 Route::has_external_redirects () const
5291 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5293 /* ignore inactive processors and obviously ignore the main
5294 * outs since everything has them and we don't care.
5297 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5305 boost::shared_ptr<Processor>
5306 Route::the_instrument () const
5308 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5309 return the_instrument_unlocked ();
5312 boost::shared_ptr<Processor>
5313 Route::the_instrument_unlocked () const
5315 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5316 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5317 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5321 return boost::shared_ptr<Processor>();
5327 Route::non_realtime_locate (framepos_t pos)
5330 _pannable->transport_located (pos);
5333 if (_delayline.get()) {
5334 _delayline.get()->flush();
5338 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5339 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5341 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5342 (*i)->transport_located (pos);
5345 _roll_delay = _initial_delay;
5349 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5356 * We don't currently mix MIDI input together, so we don't need the
5357 * complex logic of the audio case.
5360 n_buffers = bufs.count().n_midi ();
5362 for (i = 0; i < n_buffers; ++i) {
5364 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5365 MidiBuffer& buf (bufs.get_midi (i));
5368 buf.copy (source_port->get_midi_buffer(nframes));
5370 buf.silence (nframes);
5376 n_buffers = bufs.count().n_audio();
5378 size_t n_ports = io->n_ports().n_audio();
5379 float scaling = 1.0f;
5381 if (n_ports > n_buffers) {
5382 scaling = ((float) n_buffers) / n_ports;
5385 for (i = 0; i < n_ports; ++i) {
5387 /* if there are more ports than buffers, map them onto buffers
5388 * in a round-robin fashion
5391 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5392 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5395 if (i < n_buffers) {
5397 /* first time through just copy a channel into
5401 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5403 if (scaling != 1.0f) {
5404 buf.apply_gain (scaling, nframes);
5409 /* on subsequent times around, merge data from
5410 * the port with what is already there
5413 if (scaling != 1.0f) {
5414 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5416 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5421 /* silence any remaining buffers */
5423 for (; i < n_buffers; ++i) {
5424 AudioBuffer& buf (bufs.get_audio (i));
5425 buf.silence (nframes);
5428 /* establish the initial setup of the buffer set, reflecting what was
5429 copied into it. unless, of course, we are the auditioner, in which
5430 case nothing was fed into it from the inputs at all.
5433 if (!is_auditioner()) {
5434 bufs.set_count (io->n_ports());
5438 boost::shared_ptr<AutomationControl>
5439 Route::pan_azimuth_control() const
5442 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5444 return boost::shared_ptr<AutomationControl>();
5446 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5447 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5449 if (!_pannable || !panner()) {
5450 return boost::shared_ptr<AutomationControl>();
5452 return _pannable->pan_azimuth_control;
5456 boost::shared_ptr<AutomationControl>
5457 Route::pan_elevation_control() const
5459 if (Profile->get_mixbus() || !_pannable || !panner()) {
5460 return boost::shared_ptr<AutomationControl>();
5463 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5465 if (c.find (PanElevationAutomation) != c.end()) {
5466 return _pannable->pan_elevation_control;
5468 return boost::shared_ptr<AutomationControl>();
5471 boost::shared_ptr<AutomationControl>
5472 Route::pan_width_control() const
5474 if (Profile->get_mixbus() || !_pannable || !panner()) {
5475 return boost::shared_ptr<AutomationControl>();
5478 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5480 if (c.find (PanWidthAutomation) != c.end()) {
5481 return _pannable->pan_width_control;
5483 return boost::shared_ptr<AutomationControl>();
5486 boost::shared_ptr<AutomationControl>
5487 Route::pan_frontback_control() const
5489 if (Profile->get_mixbus() || !_pannable || !panner()) {
5490 return boost::shared_ptr<AutomationControl>();
5493 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5495 if (c.find (PanFrontBackAutomation) != c.end()) {
5496 return _pannable->pan_frontback_control;
5498 return boost::shared_ptr<AutomationControl>();
5501 boost::shared_ptr<AutomationControl>
5502 Route::pan_lfe_control() const
5504 if (Profile->get_mixbus() || !_pannable || !panner()) {
5505 return boost::shared_ptr<AutomationControl>();
5508 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5510 if (c.find (PanLFEAutomation) != c.end()) {
5511 return _pannable->pan_lfe_control;
5513 return boost::shared_ptr<AutomationControl>();
5518 Route::eq_band_cnt () const
5520 if (Profile->get_mixbus()) {
5523 /* Ardour has no well-known EQ object */
5528 boost::shared_ptr<AutomationControl>
5529 Route::eq_gain_controllable (uint32_t band) const
5532 boost::shared_ptr<PluginInsert> eq = ch_eq();
5535 return boost::shared_ptr<AutomationControl>();
5538 uint32_t port_number;
5541 if (is_master() || mixbus()) {
5548 if (is_master() || mixbus()) {
5555 if (is_master() || mixbus()) {
5562 return boost::shared_ptr<AutomationControl>();
5565 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5567 return boost::shared_ptr<AutomationControl>();
5570 boost::shared_ptr<AutomationControl>
5571 Route::eq_freq_controllable (uint32_t band) const
5575 if (mixbus() || is_master()) {
5576 /* no frequency controls for mixbusses or master */
5577 return boost::shared_ptr<AutomationControl>();
5580 boost::shared_ptr<PluginInsert> eq = ch_eq();
5583 return boost::shared_ptr<AutomationControl>();
5586 uint32_t port_number;
5598 return boost::shared_ptr<AutomationControl>();
5601 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5603 return boost::shared_ptr<AutomationControl>();
5607 boost::shared_ptr<AutomationControl>
5608 Route::eq_q_controllable (uint32_t band) const
5610 return boost::shared_ptr<AutomationControl>();
5613 boost::shared_ptr<AutomationControl>
5614 Route::eq_shape_controllable (uint32_t band) const
5616 return boost::shared_ptr<AutomationControl>();
5619 boost::shared_ptr<AutomationControl>
5620 Route::eq_enable_controllable () const
5623 boost::shared_ptr<PluginInsert> eq = ch_eq();
5626 return boost::shared_ptr<AutomationControl>();
5629 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5631 return boost::shared_ptr<AutomationControl>();
5635 boost::shared_ptr<AutomationControl>
5636 Route::eq_hpf_controllable () const
5639 boost::shared_ptr<PluginInsert> eq = ch_eq();
5642 return boost::shared_ptr<AutomationControl>();
5645 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5647 return boost::shared_ptr<AutomationControl>();
5652 Route::eq_band_name (uint32_t band) const
5654 if (Profile->get_mixbus()) {
5670 boost::shared_ptr<AutomationControl>
5671 Route::comp_enable_controllable () const
5674 boost::shared_ptr<PluginInsert> comp = ch_comp();
5677 return boost::shared_ptr<AutomationControl>();
5680 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5682 return boost::shared_ptr<AutomationControl>();
5685 boost::shared_ptr<AutomationControl>
5686 Route::comp_threshold_controllable () const
5689 boost::shared_ptr<PluginInsert> comp = ch_comp();
5692 return boost::shared_ptr<AutomationControl>();
5695 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5698 return boost::shared_ptr<AutomationControl>();
5701 boost::shared_ptr<AutomationControl>
5702 Route::comp_speed_controllable () const
5705 boost::shared_ptr<PluginInsert> comp = ch_comp();
5708 return boost::shared_ptr<AutomationControl>();
5711 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5713 return boost::shared_ptr<AutomationControl>();
5716 boost::shared_ptr<AutomationControl>
5717 Route::comp_mode_controllable () const
5720 boost::shared_ptr<PluginInsert> comp = ch_comp();
5723 return boost::shared_ptr<AutomationControl>();
5726 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5728 return boost::shared_ptr<AutomationControl>();
5731 boost::shared_ptr<AutomationControl>
5732 Route::comp_makeup_controllable () const
5735 boost::shared_ptr<PluginInsert> comp = ch_comp();
5738 return boost::shared_ptr<AutomationControl>();
5741 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5743 return boost::shared_ptr<AutomationControl>();
5746 boost::shared_ptr<AutomationControl>
5747 Route::comp_redux_controllable () const
5750 boost::shared_ptr<PluginInsert> comp = ch_comp();
5753 return boost::shared_ptr<AutomationControl>();
5756 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5758 return boost::shared_ptr<AutomationControl>();
5763 Route::comp_mode_name (uint32_t mode) const
5768 return _("Leveler");
5770 return _("Compressor");
5772 return _("Limiter");
5774 return mixbus() ? _("Sidechain") : _("Limiter");
5784 Route::comp_speed_name (uint32_t mode) const
5802 boost::shared_ptr<AutomationControl>
5803 Route::send_level_controllable (uint32_t n) const
5806 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5808 return boost::shared_ptr<AutomationControl>();
5813 return boost::shared_ptr<AutomationControl>();
5816 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5817 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5819 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5821 return boost::shared_ptr<AutomationControl>();
5823 return s->gain_control ();
5827 boost::shared_ptr<AutomationControl>
5828 Route::send_enable_controllable (uint32_t n) const
5831 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5833 return boost::shared_ptr<AutomationControl>();
5838 return boost::shared_ptr<AutomationControl>();
5841 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5842 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5844 /* although Ardour sends have enable/disable as part of the Processor
5845 API, it is not exposed as a controllable.
5847 XXX: we should fix this.
5849 return boost::shared_ptr<AutomationControl>();
5854 Route::send_name (uint32_t n) const
5860 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5864 boost::shared_ptr<Processor> p = nth_send (n);
5873 boost::shared_ptr<AutomationControl>
5874 Route::master_send_enable_controllable () const
5877 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5879 return boost::shared_ptr<AutomationControl>();
5881 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5883 return boost::shared_ptr<AutomationControl>();