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/boost_debug.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/plugin_insert.h"
62 #include "ardour/port.h"
63 #include "ardour/port_insert.h"
64 #include "ardour/processor.h"
65 #include "ardour/profile.h"
66 #include "ardour/route.h"
67 #include "ardour/route_group.h"
68 #include "ardour/send.h"
69 #include "ardour/session.h"
70 #include "ardour/unknown_processor.h"
71 #include "ardour/utils.h"
76 using namespace ARDOUR;
79 PBD::Signal0<void> Route::SyncOrderKeys;
80 PBD::Signal0<void> Route::RemoteControlIDChange;
82 /** Base class for all routable/mixable objects (tracks and busses) */
83 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
84 : SessionObject (sess, name)
86 , GraphNode (sess._process_graph)
89 , _signal_latency_at_amp_position (0)
90 , _signal_latency_at_trim_position (0)
93 , _pending_process_reorder (0)
94 , _pending_signals (0)
96 , _pending_declick (true)
97 , _meter_point (MeterPostFader)
98 , _pending_meter_point (MeterPostFader)
99 , _meter_type (MeterPeak)
101 , _soloed_by_others_upstream (0)
102 , _soloed_by_others_downstream (0)
103 , _solo_isolated (false)
104 , _solo_isolated_by_upstream (0)
105 , _denormal_protection (false)
108 , _declickable (false)
109 , _mute_master (new MuteMaster (sess, name))
110 , _have_internal_generator (false)
112 , _default_type (default_type)
114 , _has_order_key (false)
115 , _remote_control_id (0)
117 , _in_configure_processors (false)
118 , _initial_io_setup (false)
119 , _in_sidechain_setup (false)
121 , _custom_meter_position_noted (false)
123 processor_max_streams.reset();
129 /* set default meter type */
131 _meter_type = Config->get_meter_type_master ();
133 else if (dynamic_cast<Track*>(this)) {
134 _meter_type = Config->get_meter_type_track ();
136 _meter_type = Config->get_meter_type_bus ();
139 /* add standard controls */
141 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
142 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
143 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
145 _solo_isolate_control.reset (new SoloIsolateControllable (X_("solo-iso"), shared_from_this ()));
146 _solo_safe_control.reset (new SoloSafeControllable (X_("solo-safe"), shared_from_this ()));
148 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
149 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
150 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
152 add_control (_solo_control);
153 add_control (_mute_control);
154 add_control (_phase_control);
158 if (!(_flags & Route::MonitorOut)) {
159 _pannable.reset (new Pannable (_session));
162 /* input and output objects */
164 _input.reset (new IO (_session, _name, IO::Input, _default_type));
165 _output.reset (new IO (_session, _name, IO::Output, _default_type));
167 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
168 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
170 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
171 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
173 #if 0 // not used - just yet
174 if (!is_master() && !is_monitor() && !is_auditioner()) {
175 _delayline.reset (new DelayLine (_session, _name));
176 add_processor (_delayline, PreFader);
180 /* add amp processor */
182 _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
183 add_control (_gain_control);
185 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
186 add_processor (_amp, PostFader);
189 _amp->set_display_name (_("Monitor"));
194 _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
195 add_control (_trim_control);
197 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
198 _trim->set_display_to_user (false);
200 if (dynamic_cast<AudioTrack*>(this)) {
201 /* we can't do this in the AudioTrack's constructor
202 * because _trim does not exit then
206 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
211 /* create standard processors: meter, main outs, monitor out;
212 they will be added to _processors by setup_invisible_processors ()
215 _meter.reset (new PeakMeter (_session, _name));
216 _meter->set_owner (this);
217 _meter->set_display_to_user (false);
220 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
221 _main_outs->activate ();
224 /* where we listen to tracks */
225 _intreturn.reset (new InternalReturn (_session));
226 _intreturn->activate ();
228 /* the thing that provides proper control over a control/monitor/listen bus
229 (such as per-channel cut, dim, solo, invert, etc).
231 _monitor_control.reset (new MonitorProcessor (_session));
232 _monitor_control->activate ();
235 if (is_master() || is_monitor() || is_auditioner()) {
236 _mute_master->set_solo_ignore (true);
239 /* now that we have _meter, its safe to connect to this */
242 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
243 configure_processors (0);
251 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
253 /* do this early so that we don't get incoming signals as we are going through destruction
258 /* don't use clear_processors here, as it depends on the session which may
259 be half-destroyed by now
262 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
263 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
264 (*i)->drop_references ();
267 _processors.clear ();
271 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
273 if (Config->get_remote_model() != UserOrdered) {
277 set_remote_control_id_internal (id, notify_class_listeners);
281 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
283 /* force IDs for master/monitor busses and prevent
284 any other route from accidentally getting these IDs
285 (i.e. legacy sessions)
288 if (is_master() && id != MasterBusRemoteControlID) {
289 id = MasterBusRemoteControlID;
292 if (is_monitor() && id != MonitorBusRemoteControlID) {
293 id = MonitorBusRemoteControlID;
300 /* don't allow it to collide */
302 if (!is_master () && !is_monitor() &&
303 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
304 id += MonitorBusRemoteControlID;
307 if (id != remote_control_id()) {
308 _remote_control_id = id;
309 RemoteControlIDChanged ();
311 if (notify_class_listeners) {
312 RemoteControlIDChange ();
318 Route::remote_control_id() const
321 return MasterBusRemoteControlID;
325 return MonitorBusRemoteControlID;
328 return _remote_control_id;
332 Route::has_order_key () const
334 return _has_order_key;
338 Route::order_key () const
344 Route::set_remote_control_id_explicit (uint32_t rid)
346 if (is_master() || is_monitor() || is_auditioner()) {
347 /* hard-coded remote IDs, or no remote ID */
351 if (_remote_control_id != rid) {
352 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
353 _remote_control_id = rid;
354 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
357 /* don't emit the class-level RID signal RemoteControlIDChange here,
358 leave that to the entity that changed the order key, so that we
359 don't get lots of emissions for no good reasons (e.g. when changing
360 all route order keys).
362 See Session::sync_remote_id_from_order_keys() for the (primary|only)
363 spot where that is emitted.
368 Route::set_order_key (uint32_t n)
370 _has_order_key = true;
372 if (_order_key == n) {
378 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
379 name(), order_key ()));
381 _session.set_dirty ();
385 Route::ensure_track_or_route_name(string name, Session &session)
387 string newname = name;
389 while (!session.io_name_is_legal (newname)) {
390 newname = bump_name_once (newname, ' ');
397 Route::inc_gain (gain_t factor)
399 /* To be used ONLY when doing group-relative gain adjustment, from
403 float desired_gain = _gain_control->user_double();
405 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
406 // really?! what's the idea here?
407 _gain_control->route_set_value (0.000001f + (0.000001f * factor));
409 _gain_control->route_set_value (desired_gain + (desired_gain * factor));
414 Route::set_gain (gain_t val, Controllable::GroupControlDisposition group_override)
416 if (use_group (group_override, &RouteGroup::is_gain)) {
418 if (_route_group->is_relative()) {
420 gain_t usable_gain = _gain_control->get_value();
421 if (usable_gain < 0.000001f) {
422 usable_gain = 0.000001f;
426 if (delta < 0.000001f) {
430 delta -= usable_gain;
435 gain_t factor = delta / usable_gain;
438 factor = _route_group->get_max_factor(factor);
439 if (factor == 0.0f) {
440 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
444 factor = _route_group->get_min_factor(factor);
445 if (factor == 0.0f) {
446 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
451 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor));
455 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, Controllable::NoGroup));
461 if (val == _gain_control->get_value()) {
465 _gain_control->route_set_value (val);
469 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
471 // TODO route group, see set_gain()
472 _trim_control->route_set_value (val);
476 Route::maybe_declick (BufferSet&, framecnt_t, int)
478 /* this is the "bus" implementation and they never declick.
483 /** Process this route for one (sub) cycle (process thread)
485 * @param bufs Scratch buffers to use for the signal path
486 * @param start_frame Initial transport frame
487 * @param end_frame Final transport frame
488 * @param nframes Number of frames to output (to ports)
490 * Note that (end_frame - start_frame) may not be equal to nframes when the
491 * transport speed isn't 1.0 (eg varispeed).
494 Route::process_output_buffers (BufferSet& bufs,
495 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
496 int declick, bool gain_automation_ok)
498 /* Caller must hold process lock */
499 assert (!AudioEngine::instance()->process_lock().trylock());
501 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
503 // can this actually happen? functions calling process_output_buffers()
504 // already take a reader-lock.
505 bufs.silence (nframes, 0);
509 /* figure out if we're going to use gain automation */
510 if (gain_automation_ok) {
511 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
512 _amp->setup_gain_automation (
513 start_frame + _signal_latency_at_amp_position,
514 end_frame + _signal_latency_at_amp_position,
517 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
518 _trim->setup_gain_automation (
519 start_frame + _signal_latency_at_trim_position,
520 end_frame + _signal_latency_at_trim_position,
523 _amp->apply_gain_automation (false);
524 _trim->apply_gain_automation (false);
527 /* Tell main outs what to do about monitoring. We do this so that
528 on a transition between monitoring states we get a de-clicking gain
529 change in the _main_outs delivery, if config.get_use_monitor_fades()
532 We override this in the case where we have an internal generator.
534 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
536 _main_outs->no_outs_cuz_we_no_monitor (silence);
538 /* -------------------------------------------------------------------------------------------
539 GLOBAL DECLICK (for transport changes etc.)
540 ----------------------------------------------------------------------------------------- */
542 maybe_declick (bufs, nframes, declick);
543 _pending_declick = 0;
545 /* -------------------------------------------------------------------------------------------
546 DENORMAL CONTROL/PHASE INVERT
547 ----------------------------------------------------------------------------------------- */
549 if (_phase_invert.any ()) {
553 if (_denormal_protection || Config->get_denormal_protection()) {
555 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
556 Sample* const sp = i->data();
558 if (_phase_invert[chn]) {
559 for (pframes_t nx = 0; nx < nframes; ++nx) {
564 for (pframes_t nx = 0; nx < nframes; ++nx) {
572 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
573 Sample* const sp = i->data();
575 if (_phase_invert[chn]) {
576 for (pframes_t nx = 0; nx < nframes; ++nx) {
585 if (_denormal_protection || Config->get_denormal_protection()) {
587 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
588 Sample* const sp = i->data();
589 for (pframes_t nx = 0; nx < nframes; ++nx) {
597 /* -------------------------------------------------------------------------------------------
599 ----------------------------------------------------------------------------------------- */
601 /* set this to be true if the meter will already have been ::run() earlier */
602 bool const meter_already_run = metering_state() == MeteringInput;
604 framecnt_t latency = 0;
606 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
608 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
609 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
614 /* if it has any inputs, make sure they match */
615 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
616 if (bufs.count() != (*i)->input_streams()) {
618 DEBUG::Processors, string_compose (
619 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
620 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
627 /* should we NOT run plugins here if the route is inactive?
628 do we catch route != active somewhere higher?
631 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
632 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
635 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
636 bufs.set_count ((*i)->output_streams());
638 if ((*i)->active ()) {
639 latency += (*i)->signal_latency ();
645 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
646 boost::shared_ptr<Processor> endpoint,
647 bool include_endpoint, bool for_export, bool for_freeze)
649 /* If no processing is required, there's no need to go any further. */
650 if (!endpoint && !include_endpoint) {
654 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
655 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
656 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
658 /* trim is always at the top, for bounce no latency compensation is needed */
659 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
660 _trim->setup_gain_automation (start, start + nframes, nframes);
663 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
665 if (!include_endpoint && (*i) == endpoint) {
669 /* if we're *not* exporting, stop processing if we come across a routing processor. */
670 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
673 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
677 /* special case the panner (export outputs)
678 * Ideally we'd only run the panner, not the delivery itself...
679 * but panners need separate input/output buffers and some context
680 * (panshell, panner type, etc). AFAICT there is no ill side effect
681 * of re-using the main delivery when freewheeling/exporting a region.
683 if ((*i) == _main_outs) {
684 assert ((*i)->does_routing());
685 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
686 buffers.set_count ((*i)->output_streams());
689 /* don't run any processors that do routing.
690 * Also don't bother with metering.
692 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
693 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
694 buffers.set_count ((*i)->output_streams());
695 latency += (*i)->signal_latency ();
698 if ((*i) == endpoint) {
705 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
706 bool include_endpoint, bool for_export, bool for_freeze) const
708 framecnt_t latency = 0;
709 if (!endpoint && !include_endpoint) {
713 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
714 if (!include_endpoint && (*i) == endpoint) {
717 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
720 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
723 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
724 latency += (*i)->signal_latency ();
726 if ((*i) == endpoint) {
734 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
735 bool include_endpoint, bool for_export, bool for_freeze) const
737 if (!endpoint && !include_endpoint) {
741 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
742 if (!include_endpoint && (*i) == endpoint) {
745 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
748 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
751 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
752 cc = (*i)->output_streams();
754 if ((*i) == endpoint) {
762 Route::n_process_buffers ()
764 return max (_input->n_ports(), processor_max_streams);
768 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
770 assert (is_monitor());
771 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
772 fill_buffers_with_input (bufs, _input, nframes);
773 passthru (bufs, start_frame, end_frame, nframes, declick);
777 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
781 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
783 /* control/monitor bus ignores input ports when something is
784 feeding the listen "stream". data will "arrive" into the
785 route from the intreturn processor element.
788 bufs.silence (nframes, 0);
791 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
792 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
796 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
798 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
800 bufs.set_count (_input->n_ports());
801 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
802 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
806 Route::set_listen (bool yn, Controllable::GroupControlDisposition group_override)
812 if (use_group (group_override, &RouteGroup::is_solo)) {
813 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, Controllable::ForGroup));
818 if (yn != _monitor_send->active()) {
820 _monitor_send->activate ();
821 _mute_master->set_soloed_by_self (true);
823 _monitor_send->deactivate ();
824 _mute_master->set_soloed_by_self (false);
826 _mute_master->set_soloed_by_others (false);
828 listen_changed (group_override); /* EMIT SIGNAL */
834 Route::listening_via_monitor () const
837 return _monitor_send->active ();
844 Route::set_solo_safe (bool yn, Controllable::GroupControlDisposition /* group_override */)
846 if (_solo_safe != yn) {
848 solo_safe_changed (); /* EMIT SIGNAL */
849 _solo_safe_control->Changed(); /* EMIT SIGNAL */
854 Route::solo_safe() const
860 Route::clear_all_solo_state ()
862 // ideally this function will never do anything, it only exists to forestall Murphy
863 bool emit_changed = false;
866 // these are really debug messages, but of possible interest.
868 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
870 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
871 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
872 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
876 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
877 // if self-soled, set_solo() will do signal emission
881 _soloed_by_others_upstream = 0;
882 _soloed_by_others_downstream = 0;
885 PBD::Unwinder<bool> uw (_solo_safe, false);
886 set_solo (false, Controllable::NoGroup);
890 set_mute_master_solo ();
891 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
896 Route::set_solo (bool yn, Controllable::GroupControlDisposition group_override)
898 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, grp ? %3 currently self-soloed ? %4\n",
899 name(), yn, enum_2_string(group_override), self_soloed()));
902 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
906 if (is_master() || is_monitor() || is_auditioner()) {
907 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
911 if (use_group (group_override, &RouteGroup::is_solo)) {
912 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, Controllable::ForGroup));
916 if (self_soloed() != yn) {
918 solo_changed (true, group_override); /* EMIT SIGNAL */
919 _solo_control->Changed (); /* EMIT SIGNAL */
922 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
924 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
925 Config->get_solo_mute_overrride().
928 if (yn && Profile->get_trx()) {
929 set_mute (false, Controllable::UseGroup);
934 Route::set_self_solo (bool yn)
936 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
938 set_mute_master_solo ();
942 Route::mod_solo_by_others_upstream (int32_t delta)
944 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
945 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
947 uint32_t old_sbu = _soloed_by_others_upstream;
950 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
951 _soloed_by_others_upstream += delta;
953 _soloed_by_others_upstream = 0;
956 _soloed_by_others_upstream += delta;
959 DEBUG_TRACE (DEBUG::Solo, string_compose (
960 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
961 name(), delta, _soloed_by_others_upstream, old_sbu,
962 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
964 /* push the inverse solo change to everything that feeds us.
966 This is important for solo-within-group. When we solo 1 track out of N that
967 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
968 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
969 tracks that feed it. This will silence them if they were audible because
970 of a bus solo, but the newly soloed track will still be audible (because
973 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
977 if ((_self_solo || _soloed_by_others_downstream) &&
978 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
979 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
981 if (delta > 0 || !Config->get_exclusive_solo()) {
982 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
983 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
987 boost::shared_ptr<Route> sr = i->r.lock();
989 sr->mod_solo_by_others_downstream (-delta);
995 set_mute_master_solo ();
996 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1000 Route::mod_solo_by_others_downstream (int32_t delta)
1002 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
1003 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
1006 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
1007 _soloed_by_others_downstream += delta;
1009 _soloed_by_others_downstream = 0;
1012 _soloed_by_others_downstream += delta;
1015 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
1017 set_mute_master_solo ();
1018 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1022 Route::set_mute_master_solo ()
1024 _mute_master->set_soloed_by_self (self_soloed());
1025 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1029 Route::mod_solo_isolated_by_upstream (bool yn)
1031 bool old = solo_isolated ();
1032 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1033 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1036 if (_solo_isolated_by_upstream >= 1) {
1037 _solo_isolated_by_upstream--;
1039 _solo_isolated_by_upstream = 0;
1042 _solo_isolated_by_upstream++;
1045 if (solo_isolated() != old) {
1046 /* solo isolated status changed */
1047 _mute_master->set_solo_ignore (solo_isolated());
1048 solo_isolated_changed (); /* EMIT SIGNAL */
1053 Route::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
1055 if (is_master() || is_monitor() || is_auditioner()) {
1059 if (use_group (group_override, &RouteGroup::is_solo)) {
1060 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, Controllable::ForGroup));
1064 bool changed = false;
1067 if (_solo_isolated == false) {
1068 _mute_master->set_solo_ignore (true);
1071 _solo_isolated = true;
1073 if (_solo_isolated == true) {
1074 _solo_isolated = false;
1075 _mute_master->set_solo_ignore (false);
1085 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1087 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1088 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1090 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1095 bool does_feed = feeds (*i, &sends_only);
1097 if (does_feed && !sends_only) {
1098 (*i)->mod_solo_isolated_by_upstream (yn);
1102 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1104 solo_isolated_changed (); /* EMIT SIGNAL */
1105 _solo_isolate_control->Changed(); /* EMIT SIGNAL */
1109 Route::solo_isolated () const
1111 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1115 Route::set_mute_points (MuteMaster::MutePoint mp)
1117 _mute_master->set_mute_points (mp);
1118 mute_points_changed (); /* EMIT SIGNAL */
1120 if (_mute_master->muted_by_self()) {
1121 mute_changed (); /* EMIT SIGNAL */
1122 _mute_control->Changed (); /* EMIT SIGNAL */
1127 Route::set_mute (bool yn, Controllable::GroupControlDisposition group_override)
1129 if (use_group (group_override, &RouteGroup::is_mute)) {
1130 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, Controllable::ForGroup));
1134 if (muted() != yn) {
1135 _mute_master->set_muted_by_self (yn);
1136 /* allow any derived classes to respond to the mute change
1137 before anybody else knows about it.
1140 /* tell everyone else */
1141 mute_changed (); /* EMIT SIGNAL */
1142 _mute_control->Changed (); /* EMIT SIGNAL */
1147 Route::muted () const
1149 return _mute_master->muted_by_self();
1153 Route::muted_by_others () const
1155 // This method is only used by route_ui for display state.
1156 // The real thing is MuteMaster::muted_by_others_at()
1158 //master is never muted by others
1162 //now check to see if something is soloed (and I am not)
1163 //see also MuteMaster::mute_gain_at()
1164 return (_session.soloing() && !soloed() && !solo_isolated());
1169 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1171 cerr << name << " {" << endl;
1172 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1173 p != procs.end(); ++p) {
1174 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1176 cerr << "}" << endl;
1180 /** Supposing that we want to insert a Processor at a given Placement, return
1181 * the processor to add the new one before (or 0 to add at the end).
1183 boost::shared_ptr<Processor>
1184 Route::before_processor_for_placement (Placement p)
1186 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1188 ProcessorList::iterator loc;
1190 if (p == PreFader) {
1191 /* generic pre-fader: insert immediately before the amp */
1192 loc = find (_processors.begin(), _processors.end(), _amp);
1194 /* generic post-fader: insert right before the main outs */
1195 loc = find (_processors.begin(), _processors.end(), _main_outs);
1198 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1201 /** Supposing that we want to insert a Processor at a given index, return
1202 * the processor to add the new one before (or 0 to add at the end).
1204 boost::shared_ptr<Processor>
1205 Route::before_processor_for_index (int index)
1208 return boost::shared_ptr<Processor> ();
1211 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1213 ProcessorList::iterator i = _processors.begin ();
1215 while (i != _processors.end() && j < index) {
1216 if ((*i)->display_to_user()) {
1223 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1226 /** Add a processor either pre- or post-fader
1227 * @return 0 on success, non-0 on failure.
1230 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1232 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1236 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1237 * @param index Index to add the processor at, or -1 to add at the end of the list.
1238 * @return 0 on success, non-0 on failure.
1241 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1243 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1246 /** Add a processor to the route.
1247 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1248 * @return 0 on success, non-0 on failure.
1251 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1253 assert (processor != _meter);
1254 assert (processor != _main_outs);
1256 DEBUG_TRACE (DEBUG::Processors, string_compose (
1257 "%1 adding processor %2\n", name(), processor->name()));
1259 if (!AudioEngine::instance()->connected() || !processor) {
1264 boost::shared_ptr<PluginInsert> pi;
1265 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1266 pi->set_strict_io (true);
1271 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1272 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1273 ProcessorState pstate (this);
1275 boost::shared_ptr<PluginInsert> pi;
1276 boost::shared_ptr<PortInsert> porti;
1278 if (processor == _amp) {
1279 /* Ensure that only one amp is in the list at any time */
1280 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1281 if (check != _processors.end()) {
1282 if (before == _amp) {
1283 /* Already in position; all is well */
1286 _processors.erase (check);
1291 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1293 ProcessorList::iterator loc;
1295 /* inserting before a processor; find it */
1296 loc = find (_processors.begin(), _processors.end(), before);
1297 if (loc == _processors.end ()) {
1302 /* inserting at end */
1303 loc = _processors.end ();
1306 _processors.insert (loc, processor);
1307 processor->set_owner (this);
1309 // Set up processor list channels. This will set processor->[input|output]_streams(),
1310 // configure redirect ports properly, etc.
1313 if (configure_processors_unlocked (err)) {
1315 configure_processors_unlocked (0); // it worked before we tried to add it ...
1320 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1322 if (pi->has_no_inputs ()) {
1323 /* generator plugin */
1324 _have_internal_generator = true;
1329 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1330 processor->activate ();
1333 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1335 _output->set_user_latency (0);
1338 reset_instrument_info ();
1339 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1340 set_processor_positions ();
1342 boost::shared_ptr<Send> send;
1343 if ((send = boost::dynamic_pointer_cast<Send> (processor))) {
1344 send->SelfDestruct.connect_same_thread (*this,
1345 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
1352 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
1354 /* We cannot destruct the processor here (usually RT-thread
1355 * with various locks held - in case of sends also io_locks).
1356 * Queue for deletion in low-priority thread.
1358 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
1359 selfdestruct_sequence.push_back (wp);
1363 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1365 const XMLProperty *prop;
1368 boost::shared_ptr<Processor> processor;
1370 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1371 so that we can add the processor in the right place (pre/post-fader)
1374 XMLNodeList const & children = node.children ();
1375 XMLNodeList::const_iterator i = children.begin ();
1377 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1381 Placement placement = PreFader;
1383 if (i != children.end()) {
1384 if ((prop = (*i)->property (X_("placement"))) != 0) {
1385 placement = Placement (string_2_enum (prop->value(), placement));
1389 if (node.name() == "Insert") {
1391 if ((prop = node.property ("type")) != 0) {
1393 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1394 prop->value() == "lv2" ||
1395 prop->value() == "windows-vst" ||
1396 prop->value() == "lxvst" ||
1397 prop->value() == "audiounit") {
1399 if (_session.get_disable_all_loaded_plugins ()) {
1400 processor.reset (new UnknownProcessor (_session, node));
1402 processor.reset (new PluginInsert (_session));
1403 processor->set_owner (this);
1408 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1413 } else if (node.name() == "Send") {
1415 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1416 processor.reset (new Send (_session, sendpan, _mute_master));
1420 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1424 if (processor->set_state (node, version)) {
1428 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1429 if (i != children.end()) {
1430 if ((prop = (*i)->property (X_("active"))) != 0) {
1431 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1432 processor->activate();
1434 processor->deactivate();
1438 return (add_processor (processor, placement, 0, false) == 0);
1441 catch (failed_constructor &err) {
1442 warning << _("processor could not be created. Ignored.") << endmsg;
1448 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1450 /* NOTE: this is intended to be used ONLY when copying
1451 processors from another Route. Hence the subtle
1452 differences between this and ::add_processor()
1455 ProcessorList::iterator loc;
1458 loc = find(_processors.begin(), _processors.end(), before);
1460 /* nothing specified - at end */
1461 loc = _processors.end ();
1464 if (!_session.engine().connected()) {
1468 if (others.empty()) {
1473 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1474 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1475 ProcessorState pstate (this);
1477 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1483 boost::shared_ptr<PluginInsert> pi;
1485 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1486 pi->set_strict_io (_strict_io);
1489 _processors.insert (loc, *i);
1490 (*i)->set_owner (this);
1492 if ((*i)->active()) {
1496 /* Think: does this really need to be called for every processor in the loop? */
1498 if (configure_processors_unlocked (err)) {
1500 configure_processors_unlocked (0); // it worked before we tried to add it ...
1505 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1508 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1509 boost::shared_ptr<PluginInsert> pi;
1511 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1512 if (pi->has_no_inputs ()) {
1513 _have_internal_generator = true;
1519 _output->set_user_latency (0);
1522 reset_instrument_info ();
1523 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1524 set_processor_positions ();
1530 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1532 if (p == PreFader) {
1533 start = _processors.begin();
1534 end = find(_processors.begin(), _processors.end(), _amp);
1536 start = find(_processors.begin(), _processors.end(), _amp);
1538 end = _processors.end();
1542 /** Turn off all processors with a given placement
1543 * @param p Placement of processors to disable
1546 Route::disable_processors (Placement p)
1548 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1550 ProcessorList::iterator start, end;
1551 placement_range(p, start, end);
1553 for (ProcessorList::iterator i = start; i != end; ++i) {
1554 (*i)->deactivate ();
1557 _session.set_dirty ();
1560 /** Turn off all redirects
1563 Route::disable_processors ()
1565 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1567 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1568 (*i)->deactivate ();
1571 _session.set_dirty ();
1574 /** Turn off all redirects with a given placement
1575 * @param p Placement of redirects to disable
1578 Route::disable_plugins (Placement p)
1580 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1582 ProcessorList::iterator start, end;
1583 placement_range(p, start, end);
1585 for (ProcessorList::iterator i = start; i != end; ++i) {
1586 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1587 (*i)->deactivate ();
1591 _session.set_dirty ();
1594 /** Turn off all plugins
1597 Route::disable_plugins ()
1599 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1601 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1602 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1603 (*i)->deactivate ();
1607 _session.set_dirty ();
1612 Route::ab_plugins (bool forward)
1614 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1618 /* forward = turn off all active redirects, and mark them so that the next time
1619 we go the other way, we will revert them
1622 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1623 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1627 if ((*i)->active()) {
1628 (*i)->deactivate ();
1629 (*i)->set_next_ab_is_active (true);
1631 (*i)->set_next_ab_is_active (false);
1637 /* backward = if the redirect was marked to go active on the next ab, do so */
1639 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1641 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1645 if ((*i)->get_next_ab_is_active()) {
1648 (*i)->deactivate ();
1653 _session.set_dirty ();
1657 /** Remove processors with a given placement.
1658 * @param p Placement of processors to remove.
1661 Route::clear_processors (Placement p)
1663 if (!_session.engine().connected()) {
1667 bool already_deleting = _session.deletion_in_progress();
1668 if (!already_deleting) {
1669 _session.set_deletion_in_progress();
1673 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1674 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1675 ProcessorList new_list;
1676 ProcessorStreams err;
1677 bool seen_amp = false;
1679 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1685 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1687 /* you can't remove these */
1689 new_list.push_back (*i);
1696 new_list.push_back (*i);
1699 (*i)->drop_references ();
1707 (*i)->drop_references ();
1710 new_list.push_back (*i);
1717 _processors = new_list;
1718 configure_processors_unlocked (&err); // this can't fail
1721 processor_max_streams.reset();
1722 _have_internal_generator = false;
1723 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1724 set_processor_positions ();
1726 reset_instrument_info ();
1728 if (!already_deleting) {
1729 _session.clear_deletion_in_progress();
1734 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1736 // TODO once the export point can be configured properly, do something smarter here
1737 if (processor == _capturing_processor) {
1738 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1739 if (need_process_lock) {
1743 _capturing_processor.reset();
1745 if (need_process_lock) {
1750 /* these can never be removed */
1752 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1756 if (!_session.engine().connected()) {
1760 processor_max_streams.reset();
1763 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1764 if (need_process_lock) {
1768 /* Caller must hold process lock */
1769 assert (!AudioEngine::instance()->process_lock().trylock());
1771 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1773 ProcessorState pstate (this);
1775 ProcessorList::iterator i;
1776 bool removed = false;
1778 for (i = _processors.begin(); i != _processors.end(); ) {
1779 if (*i == processor) {
1781 /* move along, see failure case for configure_processors()
1782 where we may need to reconfigure the processor.
1785 /* stop redirects that send signals to JACK ports
1786 from causing noise as a result of no longer being
1790 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1791 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1795 iop = pi->sidechain();
1802 i = _processors.erase (i);
1810 _output->set_user_latency (0);
1818 if (configure_processors_unlocked (err)) {
1820 /* we know this will work, because it worked before :) */
1821 configure_processors_unlocked (0);
1825 _have_internal_generator = false;
1827 for (i = _processors.begin(); i != _processors.end(); ++i) {
1828 boost::shared_ptr<PluginInsert> pi;
1830 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1831 if (pi->has_no_inputs ()) {
1832 _have_internal_generator = true;
1837 if (need_process_lock) {
1842 reset_instrument_info ();
1843 processor->drop_references ();
1844 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1845 set_processor_positions ();
1851 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1853 /* these can never be removed */
1854 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1857 /* and can't be used as substitute, either */
1858 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1862 /* I/Os are out, too */
1863 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1867 /* this function cannot be used to swap/reorder processors */
1868 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1872 if (!AudioEngine::instance()->connected() || !old || !sub) {
1876 /* ensure that sub is not owned by another route */
1877 if (sub->owner ()) {
1882 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1883 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1884 ProcessorState pstate (this);
1886 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1888 ProcessorList::iterator i;
1889 bool replaced = false;
1890 bool enable = old->active ();
1892 for (i = _processors.begin(); i != _processors.end(); ) {
1894 i = _processors.erase (i);
1895 _processors.insert (i, sub);
1896 sub->set_owner (this);
1909 boost::shared_ptr<PluginInsert> pi;
1910 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1911 pi->set_strict_io (true);
1915 if (configure_processors_unlocked (err)) {
1917 configure_processors_unlocked (0);
1921 _have_internal_generator = false;
1923 for (i = _processors.begin(); i != _processors.end(); ++i) {
1924 boost::shared_ptr<PluginInsert> pi;
1925 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1926 if (pi->has_no_inputs ()) {
1927 _have_internal_generator = true;
1937 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1938 _output->set_user_latency (0);
1941 reset_instrument_info ();
1942 old->drop_references ();
1943 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1944 set_processor_positions ();
1949 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1951 ProcessorList deleted;
1953 if (!_session.engine().connected()) {
1957 processor_max_streams.reset();
1960 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1961 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1962 ProcessorState pstate (this);
1964 ProcessorList::iterator i;
1965 boost::shared_ptr<Processor> processor;
1967 for (i = _processors.begin(); i != _processors.end(); ) {
1971 /* these can never be removed */
1973 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1978 /* see if its in the list of processors to delete */
1980 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1985 /* stop IOProcessors that send to JACK ports
1986 from causing noise as a result of no longer being
1990 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1991 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1994 iop = pi->sidechain();
2001 deleted.push_back (processor);
2002 i = _processors.erase (i);
2005 if (deleted.empty()) {
2006 /* none of those in the requested list were found */
2010 _output->set_user_latency (0);
2012 if (configure_processors_unlocked (err)) {
2014 /* we know this will work, because it worked before :) */
2015 configure_processors_unlocked (0);
2020 _have_internal_generator = false;
2022 for (i = _processors.begin(); i != _processors.end(); ++i) {
2023 boost::shared_ptr<PluginInsert> pi;
2025 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2026 if (pi->has_no_inputs ()) {
2027 _have_internal_generator = true;
2034 /* now try to do what we need to so that those that were removed will be deleted */
2036 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
2037 (*i)->drop_references ();
2040 reset_instrument_info ();
2041 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2042 set_processor_positions ();
2048 Route::reset_instrument_info ()
2050 boost::shared_ptr<Processor> instr = the_instrument();
2052 _instrument_info.set_internal_instrument (instr);
2056 /** Caller must hold process lock */
2058 Route::configure_processors (ProcessorStreams* err)
2060 #ifndef PLATFORM_WINDOWS
2061 assert (!AudioEngine::instance()->process_lock().trylock());
2064 if (!_in_configure_processors) {
2065 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2066 return configure_processors_unlocked (err);
2073 Route::input_streams () const
2075 return _input->n_ports ();
2078 list<pair<ChanCount, ChanCount> >
2079 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
2081 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2083 return try_configure_processors_unlocked (in, err);
2086 list<pair<ChanCount, ChanCount> >
2087 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
2089 // Check each processor in order to see if we can configure as requested
2091 list<pair<ChanCount, ChanCount> > configuration;
2094 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
2095 DEBUG_TRACE (DEBUG::Processors, "{\n");
2097 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
2099 if ((*p)->can_support_io_configuration(in, out)) {
2101 if (boost::dynamic_pointer_cast<Delivery> (*p)
2102 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
2103 && !(is_monitor() || is_auditioner())
2104 && ( _strict_io || Profile->get_mixbus ())) {
2105 /* with strict I/O the panner + output are forced to
2106 * follow the last processor's output.
2108 * Delivery::can_support_io_configuration() will only add ports,
2109 * but not remove excess ports.
2111 * This works because the delivery only requires
2112 * as many outputs as there are inputs.
2113 * Delivery::configure_io() will do the actual removal
2114 * by calling _output->ensure_io()
2116 if (!is_master() && _session.master_out ()) {
2117 /* ..but at least as many as there are master-inputs */
2118 // XXX this may need special-casing for mixbus (master-outputs)
2119 // and should maybe be a preference anyway ?!
2120 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
2126 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
2127 configuration.push_back(make_pair(in, out));
2130 // restriction for Monitor Section Processors
2131 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
2132 /* do not allow to add/remove channels (for now)
2133 * The Monitor follows the master-bus and has no panner (unpan)
2134 * but do allow processors with midi-in to be added (e.g VSTs with control that
2135 * will remain unconnected)
2137 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
2138 return list<pair<ChanCount, ChanCount> > ();
2140 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
2141 // internal sends make no sense, only feedback
2142 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2143 return list<pair<ChanCount, ChanCount> > ();
2145 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
2146 /* External Sends can be problematic. one can add/remove ports
2147 * there signal leaves the DAW to external monitors anyway, so there's
2148 * no real use for allowing them here anyway.
2150 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
2151 return list<pair<ChanCount, ChanCount> > ();
2153 if (boost::dynamic_pointer_cast<Send> (*p)) {
2155 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
2156 return list<pair<ChanCount, ChanCount> > ();
2165 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
2166 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
2167 DEBUG_TRACE (DEBUG::Processors, "}\n");
2168 return list<pair<ChanCount, ChanCount> > ();
2172 DEBUG_TRACE (DEBUG::Processors, "}\n");
2174 return configuration;
2177 /** Set the input/output configuration of each processor in the processors list.
2178 * Caller must hold process lock.
2179 * Return 0 on success, otherwise configuration is impossible.
2182 Route::configure_processors_unlocked (ProcessorStreams* err)
2184 #ifndef PLATFORM_WINDOWS
2185 assert (!AudioEngine::instance()->process_lock().trylock());
2188 if (_in_configure_processors) {
2192 /* put invisible processors where they should be */
2193 setup_invisible_processors ();
2195 _in_configure_processors = true;
2197 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2199 if (configuration.empty ()) {
2200 _in_configure_processors = false;
2205 bool seen_mains_out = false;
2206 processor_out_streams = _input->n_ports();
2207 processor_max_streams.reset();
2209 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2210 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2212 if (!(*p)->configure_io(c->first, c->second)) {
2213 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2214 _in_configure_processors = false;
2217 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2218 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2220 boost::shared_ptr<IOProcessor> iop;
2221 boost::shared_ptr<PluginInsert> pi;
2222 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2223 /* plugins connected via Split or Hide Match may have more channels.
2224 * route/scratch buffers are needed for all of them
2225 * The configuration may only be a subset (both input and output)
2227 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
2229 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
2230 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
2231 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
2235 if (boost::dynamic_pointer_cast<Delivery> (*p)
2236 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2237 /* main delivery will increase port count to match input.
2238 * the Delivery::Main is usually the last processor - followed only by
2241 seen_mains_out = true;
2243 if (!seen_mains_out) {
2244 processor_out_streams = out;
2250 _meter->set_max_channels (processor_max_streams);
2253 /* make sure we have sufficient scratch buffers to cope with the new processor
2256 _session.ensure_buffers (n_process_buffers ());
2258 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2260 _in_configure_processors = false;
2264 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2265 * @param state New active state for those processors.
2268 Route::all_visible_processors_active (bool state)
2270 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2272 if (_processors.empty()) {
2276 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2277 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2284 (*i)->deactivate ();
2288 _session.set_dirty ();
2292 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2294 /* check if re-order requires re-configuration of any processors
2295 * -> compare channel configuration for all processors
2297 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2298 ChanCount c = input_streams ();
2300 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2302 if (c != (*j)->input_streams()) {
2305 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2308 if ((*i)->input_streams() != c) {
2311 c = (*i)->output_streams();
2323 __attribute__((annotate("realtime")))
2326 Route::apply_processor_order (const ProcessorList& new_order)
2328 /* need to hold processor_lock; either read or write lock
2329 * and the engine process_lock.
2330 * Due to r/w lock ambiguity we can only assert the latter
2332 assert (!AudioEngine::instance()->process_lock().trylock());
2335 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2336 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2337 * processors in the current actual processor list that are hidden. Any visible processors
2338 * in the current list but not in "new_order" will be assumed to be deleted.
2341 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2342 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2343 * (note though that ::processors_reorder_needs_configure() ensured that
2344 * this function will only ever be called from the rt-thread if no processor were removed)
2346 * either way, I can't proove it, but an x-run due to re-order here is less likley
2347 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2350 ProcessorList as_it_will_be;
2351 ProcessorList::iterator oiter;
2352 ProcessorList::const_iterator niter;
2354 oiter = _processors.begin();
2355 niter = new_order.begin();
2357 while (niter != new_order.end()) {
2359 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2360 then append it to the temp list.
2362 Otherwise, see if the next processor in the old list is in the new list. if not,
2363 its been deleted. If its there, append it to the temp list.
2366 if (oiter == _processors.end()) {
2368 /* no more elements in the old list, so just stick the rest of
2369 the new order onto the temp list.
2372 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2373 while (niter != new_order.end()) {
2380 if (!(*oiter)->display_to_user()) {
2382 as_it_will_be.push_back (*oiter);
2386 /* visible processor: check that its in the new order */
2388 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2389 /* deleted: do nothing, shared_ptr<> will clean up */
2391 /* ignore this one, and add the next item from the new order instead */
2392 as_it_will_be.push_back (*niter);
2397 /* now remove from old order - its taken care of no matter what */
2398 oiter = _processors.erase (oiter);
2402 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2404 /* If the meter is in a custom position, find it and make a rough note of its position */
2405 maybe_note_meter_position ();
2409 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2411 // it a change is already queued, wait for it
2412 // (unless engine is stopped. apply immediately and proceed
2413 while (g_atomic_int_get (&_pending_process_reorder)) {
2414 if (!AudioEngine::instance()->running()) {
2415 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2416 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2418 apply_processor_order(_pending_processor_order);
2419 setup_invisible_processors ();
2421 g_atomic_int_set (&_pending_process_reorder, 0);
2423 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2424 set_processor_positions ();
2426 // TODO rather use a semaphore or something.
2427 // but since ::reorder_processors() is called
2428 // from the GUI thread, this is fine..
2433 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2435 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2436 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2437 ProcessorState pstate (this);
2439 apply_processor_order (new_order);
2441 if (configure_processors_unlocked (err)) {
2449 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2450 set_processor_positions ();
2453 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2454 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2456 // _pending_processor_order is protected by _processor_lock
2457 _pending_processor_order = new_order;
2458 g_atomic_int_set (&_pending_process_reorder, 1);
2465 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2467 boost::shared_ptr<PluginInsert> pi;
2468 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2472 if (pi->has_sidechain () == add) {
2473 return true; // ?? call failed, but result is as expected.
2477 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2478 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2479 if (i == _processors.end ()) {
2485 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2486 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2487 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2489 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2491 if (!pi->add_sidechain ()) {
2495 if (!pi->del_sidechain ()) {
2501 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2506 pi->del_sidechain ();
2508 pi->add_sidechain ();
2509 // TODO restore side-chain's state.
2514 configure_processors_unlocked (0);
2517 if (pi->has_sidechain ()) {
2518 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2521 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2522 _session.set_dirty ();
2527 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2529 boost::shared_ptr<PluginInsert> pi;
2530 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2535 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2536 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2537 if (i == _processors.end ()) {
2543 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2544 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2546 const ChanCount& old (pi->preset_out ());
2547 if (!pi->set_preset_out (outs)) {
2548 return true; // no change, OK
2551 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2554 pi->set_preset_out (old);
2557 configure_processors_unlocked (0);
2560 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2561 _session.set_dirty ();
2566 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2569 return customize_plugin_insert (proc, 0, unused, unused);
2573 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2575 boost::shared_ptr<PluginInsert> pi;
2576 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2581 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2582 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2583 if (i == _processors.end ()) {
2589 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2590 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2592 bool old_cust = pi->custom_cfg ();
2593 uint32_t old_cnt = pi->get_count ();
2594 ChanCount old_chan = pi->output_streams ();
2595 ChanCount old_sinks = pi->natural_input_streams ();
2598 pi->set_custom_cfg (false);
2600 pi->set_custom_cfg (true);
2601 pi->set_count (count);
2602 pi->set_outputs (outs);
2603 pi->set_sinks (sinks);
2606 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2610 pi->set_count (old_cnt);
2611 pi->set_sinks (old_sinks);
2612 pi->set_outputs (old_chan);
2613 pi->set_custom_cfg (old_cust);
2617 configure_processors_unlocked (0);
2620 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2621 _session.set_dirty ();
2626 Route::set_strict_io (const bool enable)
2628 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2630 if (_strict_io != enable) {
2631 _strict_io = enable;
2632 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2633 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2634 boost::shared_ptr<PluginInsert> pi;
2635 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2636 pi->set_strict_io (_strict_io);
2640 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2644 _strict_io = !enable; // restore old value
2645 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2646 boost::shared_ptr<PluginInsert> pi;
2647 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2648 pi->set_strict_io (_strict_io);
2655 configure_processors (0);
2658 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2659 _session.set_dirty ();
2671 Route::get_template()
2673 return state(false);
2677 Route::state(bool full_state)
2679 if (!_session._template_state_dir.empty()) {
2680 assert (!full_state); // only for templates
2681 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2684 XMLNode *node = new XMLNode("Route");
2685 ProcessorList::iterator i;
2688 id().print (buf, sizeof (buf));
2689 node->add_property("id", buf);
2690 node->add_property ("name", _name);
2691 node->add_property("default-type", _default_type.to_string());
2692 node->add_property ("strict-io", _strict_io);
2695 node->add_property("flags", enum_2_string (_flags));
2698 node->add_property("active", _active?"yes":"no");
2700 boost::to_string (_phase_invert, p);
2701 node->add_property("phase-invert", p);
2702 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2703 node->add_property("meter-point", enum_2_string (_meter_point));
2705 node->add_property("meter-type", enum_2_string (_meter_type));
2708 node->add_property("route-group", _route_group->name());
2711 snprintf (buf, sizeof (buf), "%d", _order_key);
2712 node->add_property ("order-key", buf);
2713 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2714 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2715 node->add_property ("soloed-by-upstream", buf);
2716 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2717 node->add_property ("soloed-by-downstream", buf);
2718 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2719 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2721 node->add_child_nocopy (_input->state (full_state));
2722 node->add_child_nocopy (_output->state (full_state));
2723 node->add_child_nocopy (_solo_control->get_state ());
2724 node->add_child_nocopy (_mute_control->get_state ());
2725 node->add_child_nocopy (_mute_master->get_state ());
2728 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2731 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2732 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2733 remote_control_node->add_property (X_("id"), buf);
2734 node->add_child_nocopy (*remote_control_node);
2736 if (_comment.length()) {
2737 XMLNode *cmt = node->add_child ("Comment");
2738 cmt->add_content (_comment);
2742 node->add_child_nocopy (_pannable->state (full_state));
2745 for (i = _processors.begin(); i != _processors.end(); ++i) {
2747 /* template save: do not include internal sends functioning as
2748 aux sends because the chance of the target ID
2749 in the session where this template is used
2752 similarly, do not save listen sends which connect to
2753 the monitor section, because these will always be
2756 boost::shared_ptr<InternalSend> is;
2758 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2759 if (is->role() == Delivery::Listen) {
2764 node->add_child_nocopy((*i)->state (full_state));
2768 node->add_child_copy (*_extra_xml);
2771 if (_custom_meter_position_noted) {
2772 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2774 after->id().print (buf, sizeof (buf));
2775 node->add_property (X_("processor-after-last-custom-meter"), buf);
2779 if (!_session._template_state_dir.empty()) {
2780 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2787 Route::set_state (const XMLNode& node, int version)
2789 if (version < 3000) {
2790 return set_state_2X (node, version);
2794 XMLNodeConstIterator niter;
2796 const XMLProperty *prop;
2798 if (node.name() != "Route"){
2799 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2803 if ((prop = node.property (X_("name"))) != 0) {
2804 Route::set_name (prop->value());
2808 _initial_io_setup = true;
2810 if ((prop = node.property (X_("flags"))) != 0) {
2811 _flags = Flag (string_2_enum (prop->value(), _flags));
2816 if ((prop = node.property (X_("strict-io"))) != 0) {
2817 _strict_io = string_is_affirmative (prop->value());
2820 if (is_master() || is_monitor() || is_auditioner()) {
2821 _mute_master->set_solo_ignore (true);
2825 /* monitor bus does not get a panner, but if (re)created
2826 via XML, it will already have one by the time we
2827 call ::set_state(). so ... remove it.
2832 /* add all processors (except amp, which is always present) */
2834 nlist = node.children();
2835 XMLNode processor_state (X_("processor_state"));
2837 Stateful::save_extra_xml (node);
2839 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2843 if (child->name() == IO::state_node_name) {
2844 if ((prop = child->property (X_("direction"))) == 0) {
2848 if (prop->value() == "Input") {
2849 _input->set_state (*child, version);
2850 } else if (prop->value() == "Output") {
2851 _output->set_state (*child, version);
2855 if (child->name() == X_("Processor")) {
2856 processor_state.add_child_copy (*child);
2859 if (child->name() == X_("Pannable")) {
2861 _pannable->set_state (*child, version);
2863 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2868 if ((prop = node.property (X_("meter-point"))) != 0) {
2869 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2870 set_meter_point (mp, true);
2872 _meter->set_display_to_user (_meter_point == MeterCustom);
2876 if ((prop = node.property (X_("meter-type"))) != 0) {
2877 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2880 _initial_io_setup = false;
2882 set_processor_state (processor_state);
2884 // this looks up the internal instrument in processors
2885 reset_instrument_info();
2887 if ((prop = node.property ("self-solo")) != 0) {
2888 set_self_solo (string_is_affirmative (prop->value()));
2891 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2892 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2893 mod_solo_by_others_upstream (atoi (prop->value()));
2896 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2897 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2898 mod_solo_by_others_downstream (atoi (prop->value()));
2901 if ((prop = node.property ("solo-isolated")) != 0) {
2902 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2905 if ((prop = node.property ("solo-safe")) != 0) {
2906 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2909 if ((prop = node.property (X_("phase-invert"))) != 0) {
2910 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2913 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2914 set_denormal_protection (string_is_affirmative (prop->value()));
2917 if ((prop = node.property (X_("active"))) != 0) {
2918 bool yn = string_is_affirmative (prop->value());
2919 _active = !yn; // force switch
2920 set_active (yn, this);
2923 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2924 set_order_key (atoi(prop->value()));
2927 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2931 string::size_type colon, equal;
2932 string remaining = prop->value();
2934 while (remaining.length()) {
2936 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2937 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2940 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2941 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2944 string keyname = remaining.substr (0, equal);
2946 if ((keyname == "EditorSort") || (keyname == "editor")) {
2947 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2953 colon = remaining.find_first_of (':');
2955 if (colon != string::npos) {
2956 remaining = remaining.substr (colon+1);
2963 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2964 PBD::ID id (prop->value ());
2965 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2966 ProcessorList::const_iterator i = _processors.begin ();
2967 while (i != _processors.end() && (*i)->id() != id) {
2971 if (i != _processors.end ()) {
2972 _processor_after_last_custom_meter = *i;
2973 _custom_meter_position_noted = true;
2977 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2980 if (child->name() == X_("Comment")) {
2982 /* XXX this is a terrible API design in libxml++ */
2984 XMLNode *cmt = *(child->children().begin());
2985 _comment = cmt->content();
2987 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2988 if (prop->value() == "solo") {
2989 _solo_control->set_state (*child, version);
2990 } else if (prop->value() == "mute") {
2991 _mute_control->set_state (*child, version);
2994 } else if (child->name() == X_("RemoteControl")) {
2995 if ((prop = child->property (X_("id"))) != 0) {
2997 sscanf (prop->value().c_str(), "%d", &x);
2998 set_remote_control_id_internal (x);
3001 } else if (child->name() == X_("MuteMaster")) {
3002 _mute_master->set_state (*child, version);
3004 } else if (child->name() == Automatable::xml_node_name) {
3005 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
3013 Route::set_state_2X (const XMLNode& node, int version)
3015 LocaleGuard lg (X_("C"));
3017 XMLNodeConstIterator niter;
3019 const XMLProperty *prop;
3021 /* 2X things which still remain to be handled:
3027 if (node.name() != "Route") {
3028 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
3032 if ((prop = node.property (X_("flags"))) != 0) {
3033 string f = prop->value ();
3034 boost::replace_all (f, "ControlOut", "MonitorOut");
3035 _flags = Flag (string_2_enum (f, _flags));
3040 if (is_master() || is_monitor() || is_auditioner()) {
3041 _mute_master->set_solo_ignore (true);
3044 if ((prop = node.property (X_("phase-invert"))) != 0) {
3045 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
3046 if (string_is_affirmative (prop->value ())) {
3049 set_phase_invert (p);
3052 if ((prop = node.property (X_("denormal-protection"))) != 0) {
3053 set_denormal_protection (string_is_affirmative (prop->value()));
3056 if ((prop = node.property (X_("soloed"))) != 0) {
3057 bool yn = string_is_affirmative (prop->value());
3059 /* XXX force reset of solo status */
3064 if ((prop = node.property (X_("muted"))) != 0) {
3067 bool muted = string_is_affirmative (prop->value());
3073 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
3075 if (string_is_affirmative (prop->value())){
3076 mute_point = mute_point + "PreFader";
3081 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
3083 if (string_is_affirmative (prop->value())){
3086 mute_point = mute_point + ",";
3089 mute_point = mute_point + "PostFader";
3094 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
3096 if (string_is_affirmative (prop->value())){
3099 mute_point = mute_point + ",";
3102 mute_point = mute_point + "Listen";
3107 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
3109 if (string_is_affirmative (prop->value())){
3112 mute_point = mute_point + ",";
3115 mute_point = mute_point + "Main";
3119 _mute_master->set_mute_points (mute_point);
3120 _mute_master->set_muted_by_self (true);
3124 if ((prop = node.property (X_("meter-point"))) != 0) {
3125 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
3128 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
3129 don't mean the same thing.
3132 if ((prop = node.property (X_("order-keys"))) != 0) {
3136 string::size_type colon, equal;
3137 string remaining = prop->value();
3139 while (remaining.length()) {
3141 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
3142 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3145 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
3146 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
3149 string keyname = remaining.substr (0, equal);
3151 if (keyname == "EditorSort" || keyname == "editor") {
3152 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
3158 colon = remaining.find_first_of (':');
3160 if (colon != string::npos) {
3161 remaining = remaining.substr (colon+1);
3170 nlist = node.children ();
3171 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3175 if (child->name() == IO::state_node_name) {
3177 /* there is a note in IO::set_state_2X() about why we have to call
3181 _input->set_state_2X (*child, version, true);
3182 _output->set_state_2X (*child, version, false);
3184 if ((prop = child->property (X_("name"))) != 0) {
3185 Route::set_name (prop->value ());
3190 if ((prop = child->property (X_("active"))) != 0) {
3191 bool yn = string_is_affirmative (prop->value());
3192 _active = !yn; // force switch
3193 set_active (yn, this);
3196 if ((prop = child->property (X_("gain"))) != 0) {
3199 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
3200 _amp->gain_control()->set_value (val, Controllable::NoGroup);
3204 /* Set up Panners in the IO */
3205 XMLNodeList io_nlist = child->children ();
3207 XMLNodeConstIterator io_niter;
3210 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
3212 io_child = *io_niter;
3214 if (io_child->name() == X_("Panner")) {
3215 _main_outs->panner_shell()->set_state(*io_child, version);
3216 } else if (io_child->name() == X_("Automation")) {
3217 /* IO's automation is for the fader */
3218 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
3224 XMLNodeList redirect_nodes;
3226 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3230 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
3231 redirect_nodes.push_back(child);
3236 set_processor_state_2X (redirect_nodes, version);
3238 Stateful::save_extra_xml (node);
3240 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
3243 if (child->name() == X_("Comment")) {
3245 /* XXX this is a terrible API design in libxml++ */
3247 XMLNode *cmt = *(child->children().begin());
3248 _comment = cmt->content();
3250 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
3251 if (prop->value() == X_("solo")) {
3252 _solo_control->set_state (*child, version);
3253 } else if (prop->value() == X_("mute")) {
3254 _mute_control->set_state (*child, version);
3257 } else if (child->name() == X_("RemoteControl")) {
3258 if ((prop = child->property (X_("id"))) != 0) {
3260 sscanf (prop->value().c_str(), "%d", &x);
3261 set_remote_control_id_internal (x);
3271 Route::get_processor_state ()
3273 XMLNode* root = new XMLNode (X_("redirects"));
3274 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3275 root->add_child_nocopy ((*i)->state (true));
3282 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
3284 /* We don't bother removing existing processors not in nList, as this
3285 method will only be called when creating a Route from scratch, not
3286 for undo purposes. Just put processors in at the appropriate place
3290 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
3291 add_processor_from_xml_2X (**i, version);
3296 Route::set_processor_state (const XMLNode& node)
3298 const XMLNodeList &nlist = node.children();
3299 XMLNodeConstIterator niter;
3300 ProcessorList new_order;
3301 bool must_configure = false;
3303 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
3305 XMLProperty* prop = (*niter)->property ("type");
3307 if (prop->value() == "amp") {
3308 _amp->set_state (**niter, Stateful::current_state_version);
3309 new_order.push_back (_amp);
3310 } else if (prop->value() == "trim") {
3311 _trim->set_state (**niter, Stateful::current_state_version);
3312 new_order.push_back (_trim);
3313 } else if (prop->value() == "meter") {
3314 _meter->set_state (**niter, Stateful::current_state_version);
3315 new_order.push_back (_meter);
3316 } else if (prop->value() == "delay") {
3318 _delayline->set_state (**niter, Stateful::current_state_version);
3319 new_order.push_back (_delayline);
3321 } else if (prop->value() == "main-outs") {
3322 _main_outs->set_state (**niter, Stateful::current_state_version);
3323 } else if (prop->value() == "intreturn") {
3325 _intreturn.reset (new InternalReturn (_session));
3326 must_configure = true;
3328 _intreturn->set_state (**niter, Stateful::current_state_version);
3329 } else if (is_monitor() && prop->value() == "monitor") {
3330 if (!_monitor_control) {
3331 _monitor_control.reset (new MonitorProcessor (_session));
3332 must_configure = true;
3334 _monitor_control->set_state (**niter, Stateful::current_state_version);
3335 } else if (prop->value() == "capture") {
3336 /* CapturingProcessor should never be restored, it's always
3337 added explicitly when needed */
3339 ProcessorList::iterator o;
3341 for (o = _processors.begin(); o != _processors.end(); ++o) {
3342 XMLProperty* id_prop = (*niter)->property(X_("id"));
3343 if (id_prop && (*o)->id() == id_prop->value()) {
3344 (*o)->set_state (**niter, Stateful::current_state_version);
3345 new_order.push_back (*o);
3350 // If the processor (*niter) is not on the route then create it
3352 if (o == _processors.end()) {
3354 boost::shared_ptr<Processor> processor;
3356 if (prop->value() == "intsend") {
3358 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3360 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3361 prop->value() == "lv2" ||
3362 prop->value() == "windows-vst" ||
3363 prop->value() == "lxvst" ||
3364 prop->value() == "luaproc" ||
3365 prop->value() == "audiounit") {
3367 if (_session.get_disable_all_loaded_plugins ()) {
3368 processor.reset (new UnknownProcessor (_session, **niter));
3370 processor.reset (new PluginInsert (_session));
3371 processor->set_owner (this);
3373 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3374 pi->set_strict_io (true);
3378 } else if (prop->value() == "port") {
3380 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3382 } else if (prop->value() == "send") {
3384 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3385 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3386 send->SelfDestruct.connect_same_thread (*this,
3387 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3390 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3394 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3395 /* This processor could not be configured. Turn it into a UnknownProcessor */
3396 processor.reset (new UnknownProcessor (_session, **niter));
3399 /* subscribe to Sidechain IO changes */
3400 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3401 if (pi && pi->has_sidechain ()) {
3402 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3405 /* we have to note the monitor send here, otherwise a new one will be created
3406 and the state of this one will be lost.
3408 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3409 if (isend && isend->role() == Delivery::Listen) {
3410 _monitor_send = isend;
3413 /* it doesn't matter if invisible processors are added here, as they
3414 will be sorted out by setup_invisible_processors () shortly.
3417 new_order.push_back (processor);
3418 must_configure = true;
3424 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3425 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3426 _processors = new_order;
3428 if (must_configure) {
3429 configure_processors_unlocked (0);
3432 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3434 (*i)->set_owner (this);
3435 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3437 boost::shared_ptr<PluginInsert> pi;
3439 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3440 if (pi->has_no_inputs ()) {
3441 _have_internal_generator = true;
3448 reset_instrument_info ();
3449 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3450 set_processor_positions ();
3454 Route::curve_reallocate ()
3456 // _gain_automation_curve.finish_resize ();
3457 // _pan_automation_curve.finish_resize ();
3461 Route::silence (framecnt_t nframes)
3463 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3468 silence_unlocked (nframes);
3472 Route::silence_unlocked (framecnt_t nframes)
3474 /* Must be called with the processor lock held */
3478 _output->silence (nframes);
3480 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3481 boost::shared_ptr<PluginInsert> pi;
3483 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3484 // skip plugins, they don't need anything when we're not active
3488 (*i)->silence (nframes);
3491 if (nframes == _session.get_block_size()) {
3498 Route::add_internal_return ()
3501 _intreturn.reset (new InternalReturn (_session));
3502 add_processor (_intreturn, PreFader);
3507 Route::add_send_to_internal_return (InternalSend* send)
3509 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3511 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3512 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3515 return d->add_send (send);
3521 Route::remove_send_from_internal_return (InternalSend* send)
3523 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3525 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3526 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3529 return d->remove_send (send);
3535 Route::enable_monitor_send ()
3537 /* Caller must hold process lock */
3538 assert (!AudioEngine::instance()->process_lock().trylock());
3540 /* master never sends to monitor section via the normal mechanism */
3541 assert (!is_master ());
3542 assert (!is_monitor ());
3544 /* make sure we have one */
3545 if (!_monitor_send) {
3546 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3547 _monitor_send->set_display_to_user (false);
3551 configure_processors (0);
3554 /** Add an aux send to a route.
3555 * @param route route to send to.
3556 * @param before Processor to insert before, or 0 to insert at the end.
3559 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3561 assert (route != _session.monitor_out ());
3564 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3566 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3568 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3570 if (d && d->target_route() == route) {
3571 /* already listening via the specified IO: do nothing */
3579 boost::shared_ptr<InternalSend> listener;
3582 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3583 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3584 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3587 add_processor (listener, before);
3589 } catch (failed_constructor& err) {
3597 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3599 ProcessorStreams err;
3600 ProcessorList::iterator tmp;
3603 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3605 /* have to do this early because otherwise processor reconfig
3606 * will put _monitor_send back in the list
3609 if (route == _session.monitor_out()) {
3610 _monitor_send.reset ();
3614 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3616 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3618 if (d && d->target_route() == route) {
3620 if (remove_processor (*x, &err, false) > 0) {
3626 /* list could have been demolished while we dropped the lock
3629 if (_session.engine().connected()) {
3630 /* i/o processors cannot be removed if the engine is not running
3631 * so don't live-loop in case the engine is N/A or dies
3641 Route::set_comment (string cmt, void *src)
3645 _session.set_dirty ();
3649 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3651 FeedRecord fr (other, via_sends_only);
3653 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3655 if (!result.second) {
3657 /* already a record for "other" - make sure sends-only information is correct */
3658 if (!via_sends_only && result.first->sends_only) {
3659 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3660 frp->sends_only = false;
3664 return result.second;
3668 Route::clear_fed_by ()
3674 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3676 const FedBy& fed_by (other->fed_by());
3678 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3679 boost::shared_ptr<Route> sr = f->r.lock();
3681 if (sr && (sr.get() == this)) {
3683 if (via_sends_only) {
3684 *via_sends_only = f->sends_only;
3695 Route::all_inputs () const
3697 /* TODO, if this works as expected,
3698 * cache the IOVector and maintain it via
3699 * input_change_handler(), sidechain_change_handler() etc
3702 ios.push_back (_input);
3704 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3705 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3707 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3708 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3711 iop = pi->sidechain();
3714 if (iop != 0 && iop->input()) {
3715 ios.push_back (iop->input());
3722 Route::all_outputs () const
3725 // _output is included via Delivery
3726 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3727 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3728 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3729 if (iop != 0 && iop->output()) {
3730 ios.push_back (iop->output());
3737 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3739 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3740 if (other->all_inputs().fed_by (_output)) {
3741 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3742 if (via_send_only) {
3743 *via_send_only = false;
3750 Glib::Threads::RWLock::ReaderLock lm (_processor_lock); // XXX
3751 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3753 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3754 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3757 iop = pi->sidechain();
3761 boost::shared_ptr<const IO> iop_out = iop->output();
3762 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3763 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3764 if (via_send_only) {
3765 *via_send_only = true;
3769 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3772 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3777 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3782 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3784 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3788 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3790 return _session._current_route_graph.feeds (shared_from_this (), other);
3793 /** Called from the (non-realtime) butler thread when the transport is stopped */
3795 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3797 framepos_t now = _session.transport_frame();
3800 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3802 Automatable::transport_stopped (now);
3804 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3806 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3810 (*i)->transport_stopped (now);
3814 _roll_delay = _initial_delay;
3818 Route::input_change_handler (IOChange change, void * /*src*/)
3820 if ((change.type & IOChange::ConfigurationChanged)) {
3821 /* This is called with the process lock held if change
3822 contains ConfigurationChanged
3824 configure_processors (0);
3825 _phase_invert.resize (_input->n_ports().n_audio ());
3826 io_changed (); /* EMIT SIGNAL */
3829 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3832 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3833 if (_input->connected()) {
3834 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3835 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3839 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3840 if (does_feed && !sends_only) {
3841 if ((*i)->soloed()) {
3844 if ((*i)->solo_isolated()) {
3851 int delta = sbou - _soloed_by_others_upstream;
3852 int idelta = ibou - _solo_isolated_by_upstream;
3855 PBD::warning << string_compose (
3856 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3857 _name, ibou, _solo_isolated_by_upstream, idelta)
3862 if (_soloed_by_others_upstream) {
3863 // ignore new connections (they're not propagated)
3865 mod_solo_by_others_upstream (delta);
3869 if (_solo_isolated_by_upstream) {
3870 // solo-isolate currently only propagates downstream
3872 mod_solo_isolated_by_upstream (false);
3874 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3875 // but idelta can't be smaller than -1, can it?
3876 //_solo_isolated_by_upstream = ibou;
3879 // Session::route_solo_changed does not propagate indirect solo-changes
3880 // propagate downstream to tracks
3881 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3882 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3886 bool does_feed = feeds (*i, &sends_only);
3887 if (delta <= 0 && does_feed && !sends_only) {
3888 (*i)->mod_solo_by_others_upstream (delta);
3891 if (idelta < 0 && does_feed && !sends_only) {
3892 (*i)->mod_solo_isolated_by_upstream (false);
3899 Route::output_change_handler (IOChange change, void * /*src*/)
3901 if (_initial_io_setup) {
3905 if ((change.type & IOChange::ConfigurationChanged)) {
3906 /* This is called with the process lock held if change
3907 contains ConfigurationChanged
3909 configure_processors (0);
3912 _session.reset_monitor_section();
3915 io_changed (); /* EMIT SIGNAL */
3918 if (_soloed_by_others_downstream) {
3920 /* checking all all downstream routes for
3921 * explicit of implict solo is a rather drastic measure,
3922 * ideally the input_change_handler() of the other route
3923 * would propagate the change to us.
3925 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3926 if (_output->connected()) {
3927 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3928 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3932 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3933 if (does_feed && !sends_only) {
3934 if ((*i)->soloed()) {
3941 int delta = sbod - _soloed_by_others_downstream;
3943 // do not allow new connections to change implicit solo (no propagation)
3944 mod_solo_by_others_downstream (delta);
3945 // Session::route_solo_changed() does not propagate indirect solo-changes
3946 // propagate upstream to tracks
3947 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3948 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3952 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3953 if (delta != 0 && does_feed && !sends_only) {
3954 (*i)->mod_solo_by_others_downstream (delta);
3963 Route::sidechain_change_handler (IOChange change, void* src)
3965 if (_initial_io_setup || _in_sidechain_setup) {
3969 input_change_handler (change, src);
3973 Route::pans_required () const
3975 if (n_outputs().n_audio() < 2) {
3979 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3983 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3985 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3991 if (n_outputs().n_total() == 0) {
3995 if (!_active || n_inputs() == ChanCount::ZERO) {
3996 silence_unlocked (nframes);
4000 if (session_state_changing) {
4001 if (_session.transport_speed() != 0.0f) {
4002 /* we're rolling but some state is changing (e.g. our diskstream contents)
4003 so we cannot use them. Be silent till this is over.
4005 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
4007 silence_unlocked (nframes);
4010 /* we're really not rolling, so we're either delivery silence or actually
4011 monitoring, both of which are safe to do while session_state_changing is true.
4015 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4017 fill_buffers_with_input (bufs, _input, nframes);
4019 if (_meter_point == MeterInput) {
4020 _meter->run (bufs, start_frame, end_frame, nframes, true);
4023 _amp->apply_gain_automation (false);
4024 _trim->apply_gain_automation (false);
4025 passthru (bufs, start_frame, end_frame, nframes, 0);
4031 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
4033 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4038 if (n_outputs().n_total() == 0) {
4042 if (!_active || n_inputs().n_total() == 0) {
4043 silence_unlocked (nframes);
4047 framepos_t unused = 0;
4049 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
4055 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
4057 fill_buffers_with_input (bufs, _input, nframes);
4059 if (_meter_point == MeterInput) {
4060 _meter->run (bufs, start_frame, end_frame, nframes, true);
4063 passthru (bufs, start_frame, end_frame, nframes, declick);
4069 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
4076 Route::flush_processors ()
4078 /* XXX shouldn't really try to take this lock, since
4079 this is called from the RT audio thread.
4082 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4084 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4090 __attribute__((annotate("realtime")))
4093 Route::apply_processor_changes_rt ()
4095 int emissions = EmitNone;
4097 if (_pending_meter_point != _meter_point) {
4098 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4100 /* meters always have buffers for 'processor_max_streams'
4101 * they can be re-positioned without re-allocation */
4102 if (set_meter_point_unlocked()) {
4103 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
4105 emissions |= EmitMeterChanged;
4110 bool changed = false;
4112 if (g_atomic_int_get (&_pending_process_reorder)) {
4113 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
4115 apply_processor_order (_pending_processor_order);
4116 setup_invisible_processors ();
4118 g_atomic_int_set (&_pending_process_reorder, 0);
4119 emissions |= EmitRtProcessorChange;
4123 set_processor_positions ();
4125 if (emissions != 0) {
4126 g_atomic_int_set (&_pending_signals, emissions);
4129 return (!selfdestruct_sequence.empty ());
4133 Route::emit_pending_signals ()
4135 int sig = g_atomic_int_and (&_pending_signals, 0);
4136 if (sig & EmitMeterChanged) {
4137 _meter->emit_configuration_changed();
4138 meter_change (); /* EMIT SIGNAL */
4139 if (sig & EmitMeterVisibilityChange) {
4140 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4142 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4145 if (sig & EmitRtProcessorChange) {
4146 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
4149 /* this would be a job for the butler.
4150 * Conceptually we should not take processe/processor locks here.
4151 * OTOH its more efficient (less overhead for summoning the butler and
4152 * telling her what do do) and signal emission is called
4153 * directly after the process callback, which decreases the chance
4154 * of x-runs when taking the locks.
4156 while (!selfdestruct_sequence.empty ()) {
4157 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
4158 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
4159 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
4160 selfdestruct_sequence.pop_back ();
4163 remove_processor (proc);
4169 Route::set_meter_point (MeterPoint p, bool force)
4171 if (_pending_meter_point == p && !force) {
4175 if (force || !AudioEngine::instance()->running()) {
4176 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4177 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4178 _pending_meter_point = p;
4179 _meter->emit_configuration_changed();
4180 meter_change (); /* EMIT SIGNAL */
4181 if (set_meter_point_unlocked()) {
4182 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
4184 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
4187 _pending_meter_point = p;
4193 __attribute__((annotate("realtime")))
4196 Route::set_meter_point_unlocked ()
4199 /* Caller must hold process and processor write lock */
4200 assert (!AudioEngine::instance()->process_lock().trylock());
4201 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4202 assert (!lm.locked ());
4205 _meter_point = _pending_meter_point;
4207 bool meter_was_visible_to_user = _meter->display_to_user ();
4209 if (!_custom_meter_position_noted) {
4210 maybe_note_meter_position ();
4213 if (_meter_point != MeterCustom) {
4215 _meter->set_display_to_user (false);
4217 setup_invisible_processors ();
4220 _meter->set_display_to_user (true);
4222 /* If we have a previous position for the custom meter, try to put it there */
4223 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
4225 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
4226 if (i != _processors.end ()) {
4227 _processors.remove (_meter);
4228 _processors.insert (i, _meter);
4230 } else {// at end, right before the mains_out/panner
4231 _processors.remove (_meter);
4232 ProcessorList::iterator main = _processors.end();
4233 _processors.insert (--main, _meter);
4237 /* Set up the meter for its new position */
4239 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4243 if (loc == _processors.begin()) {
4244 m_in = _input->n_ports();
4246 ProcessorList::iterator before = loc;
4248 m_in = (*before)->output_streams ();
4251 _meter->reflect_inputs (m_in);
4253 /* we do not need to reconfigure the processors, because the meter
4254 (a) is always ready to handle processor_max_streams
4255 (b) is always an N-in/N-out processor, and thus moving
4256 it doesn't require any changes to the other processors.
4259 /* these should really be done after releasing the lock
4260 * but all those signals are subscribed to with gui_thread()
4263 return (_meter->display_to_user() != meter_was_visible_to_user);
4267 Route::listen_position_changed ()
4270 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4271 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4272 ProcessorState pstate (this);
4274 if (configure_processors_unlocked (0)) {
4275 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4277 configure_processors_unlocked (0); // it worked before we tried to add it ...
4282 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4283 _session.set_dirty ();
4286 boost::shared_ptr<CapturingProcessor>
4287 Route::add_export_point()
4289 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4290 if (!_capturing_processor) {
4292 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4293 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4295 _capturing_processor.reset (new CapturingProcessor (_session));
4296 _capturing_processor->activate ();
4298 configure_processors_unlocked (0);
4302 return _capturing_processor;
4306 Route::update_signal_latency ()
4308 framecnt_t l = _output->user_latency();
4309 framecnt_t lamp = 0;
4310 bool before_amp = true;
4311 framecnt_t ltrim = 0;
4312 bool before_trim = true;
4314 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4315 if ((*i)->active ()) {
4316 l += (*i)->signal_latency ();
4321 if ((*i) == _trim) {
4332 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
4334 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
4335 _signal_latency_at_amp_position = lamp;
4336 _signal_latency_at_trim_position = ltrim;
4338 if (_signal_latency != l) {
4339 _signal_latency = l;
4340 signal_latency_changed (); /* EMIT SIGNAL */
4343 return _signal_latency;
4347 Route::set_user_latency (framecnt_t nframes)
4349 _output->set_user_latency (nframes);
4350 _session.update_latency_compensation ();
4354 Route::set_latency_compensation (framecnt_t longest_session_latency)
4356 framecnt_t old = _initial_delay;
4358 if (_signal_latency < longest_session_latency) {
4359 _initial_delay = longest_session_latency - _signal_latency;
4364 DEBUG_TRACE (DEBUG::Latency, string_compose (
4365 "%1: compensate for maximum latency of %2,"
4366 "given own latency of %3, using initial delay of %4\n",
4367 name(), longest_session_latency, _signal_latency, _initial_delay));
4369 if (_initial_delay != old) {
4370 initial_delay_changed (); /* EMIT SIGNAL */
4373 if (_session.transport_stopped()) {
4374 _roll_delay = _initial_delay;
4379 Route::set_block_size (pframes_t nframes)
4381 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4382 (*i)->set_block_size (nframes);
4385 _session.ensure_buffers (n_process_buffers ());
4389 Route::protect_automation ()
4391 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4392 (*i)->protect_automation();
4395 /** @param declick 1 to set a pending declick fade-in,
4396 * -1 to set a pending declick fade-out
4399 Route::set_pending_declick (int declick)
4402 /* this call is not allowed to turn off a pending declick */
4404 _pending_declick = declick;
4407 _pending_declick = 0;
4411 /** Shift automation forwards from a particular place, thereby inserting time.
4412 * Adds undo commands for any shifts that are performed.
4414 * @param pos Position to start shifting from.
4415 * @param frames Amount to shift forwards by.
4419 Route::shift (framepos_t pos, framecnt_t frames)
4421 /* gain automation */
4423 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4425 XMLNode &before = gc->alist()->get_state ();
4426 gc->alist()->shift (pos, frames);
4427 XMLNode &after = gc->alist()->get_state ();
4428 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4431 /* gain automation */
4433 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4435 XMLNode &before = gc->alist()->get_state ();
4436 gc->alist()->shift (pos, frames);
4437 XMLNode &after = gc->alist()->get_state ();
4438 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4441 // TODO mute automation ??
4443 /* pan automation */
4445 ControlSet::Controls& c (_pannable->controls());
4447 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4448 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4450 boost::shared_ptr<AutomationList> al = pc->alist();
4451 XMLNode& before = al->get_state ();
4452 al->shift (pos, frames);
4453 XMLNode& after = al->get_state ();
4454 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4459 /* redirect automation */
4461 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4462 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4464 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4466 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4467 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4469 boost::shared_ptr<AutomationList> al = ac->alist();
4470 XMLNode &before = al->get_state ();
4471 al->shift (pos, frames);
4472 XMLNode &after = al->get_state ();
4473 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4481 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4483 boost::shared_ptr<Processor> processor (p.lock ());
4484 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4488 pi->set_state_dir (d);
4492 Route::save_as_template (const string& path, const string& name)
4494 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4495 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4497 XMLNode& node (state (false));
4501 IO::set_name_in_state (*node.children().front(), name);
4503 tree.set_root (&node);
4505 /* return zero on success, non-zero otherwise */
4506 return !tree.write (path.c_str());
4511 Route::set_name (const string& str)
4513 if (str == name()) {
4517 string name = Route::ensure_track_or_route_name (str, _session);
4518 SessionObject::set_name (name);
4520 bool ret = (_input->set_name(name) && _output->set_name(name));
4523 /* rename the main outs. Leave other IO processors
4524 * with whatever name they already have, because its
4525 * just fine as it is (it will not contain the route
4526 * name if its a port insert, port send or port return).
4530 if (_main_outs->set_name (name)) {
4531 /* XXX returning false here is stupid because
4532 we already changed the route name.
4542 /** Set the name of a route in an XML description.
4543 * @param node XML <Route> node to set the name in.
4544 * @param name New name.
4547 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4549 node.add_property (X_("name"), name);
4551 XMLNodeList children = node.children();
4552 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4554 if ((*i)->name() == X_("IO")) {
4556 IO::set_name_in_state (**i, name);
4558 } else if ((*i)->name() == X_("Processor")) {
4560 XMLProperty* role = (*i)->property (X_("role"));
4561 if (role && role->value() == X_("Main")) {
4562 (*i)->add_property (X_("name"), name);
4565 } else if ((*i)->name() == X_("Diskstream")) {
4567 if (rename_playlist) {
4568 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4570 (*i)->add_property (X_("name"), name);
4576 boost::shared_ptr<Send>
4577 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4579 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4581 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4582 boost::shared_ptr<InternalSend> send;
4584 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4585 if (send->target_route() == target) {
4591 return boost::shared_ptr<Send>();
4594 /** @param c Audio channel index.
4595 * @param yn true to invert phase, otherwise false.
4598 Route::set_phase_invert (uint32_t c, bool yn)
4600 if (_phase_invert[c] != yn) {
4601 _phase_invert[c] = yn;
4602 phase_invert_changed (); /* EMIT SIGNAL */
4603 _phase_control->Changed(); /* EMIT SIGNAL */
4604 _session.set_dirty ();
4609 Route::set_phase_invert (boost::dynamic_bitset<> p)
4611 if (_phase_invert != p) {
4613 phase_invert_changed (); /* EMIT SIGNAL */
4614 _session.set_dirty ();
4619 Route::phase_invert (uint32_t c) const
4621 return _phase_invert[c];
4624 boost::dynamic_bitset<>
4625 Route::phase_invert () const
4627 return _phase_invert;
4631 Route::set_denormal_protection (bool yn)
4633 if (_denormal_protection != yn) {
4634 _denormal_protection = yn;
4635 denormal_protection_changed (); /* EMIT SIGNAL */
4640 Route::denormal_protection () const
4642 return _denormal_protection;
4646 Route::set_active (bool yn, void* src)
4648 if (_session.transport_rolling()) {
4652 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4653 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4657 if (_active != yn) {
4659 _input->set_active (yn);
4660 _output->set_active (yn);
4661 active_changed (); // EMIT SIGNAL
4662 _session.set_dirty ();
4666 boost::shared_ptr<Pannable>
4667 Route::pannable() const
4672 boost::shared_ptr<Panner>
4673 Route::panner() const
4676 return _main_outs->panner_shell()->panner();
4679 boost::shared_ptr<PannerShell>
4680 Route::panner_shell() const
4682 return _main_outs->panner_shell();
4685 boost::shared_ptr<GainControl>
4686 Route::gain_control() const
4688 return _gain_control;
4691 boost::shared_ptr<GainControl>
4692 Route::trim_control() const
4694 return _trim_control;
4697 boost::shared_ptr<Route::PhaseControllable>
4698 Route::phase_control() const
4700 if (phase_invert().size()) {
4701 return _phase_control;
4703 return boost::shared_ptr<PhaseControllable>();
4707 boost::shared_ptr<AutomationControl>
4708 Route::get_control (const Evoral::Parameter& param)
4710 /* either we own the control or .... */
4712 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4716 /* maybe one of our processors does or ... */
4718 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4719 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4720 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4728 /* nobody does so we'll make a new one */
4730 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4737 boost::shared_ptr<Processor>
4738 Route::nth_plugin (uint32_t n) const
4740 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4741 ProcessorList::const_iterator i;
4743 for (i = _processors.begin(); i != _processors.end(); ++i) {
4744 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4751 return boost::shared_ptr<Processor> ();
4754 boost::shared_ptr<Processor>
4755 Route::nth_send (uint32_t n) const
4757 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4758 ProcessorList::const_iterator i;
4760 for (i = _processors.begin(); i != _processors.end(); ++i) {
4761 if (boost::dynamic_pointer_cast<Send> (*i)) {
4763 if ((*i)->name().find (_("Monitor")) == 0) {
4764 /* send to monitor section is not considered
4765 to be an accessible send.
4776 return boost::shared_ptr<Processor> ();
4780 Route::has_io_processor_named (const string& name)
4782 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4783 ProcessorList::iterator i;
4785 for (i = _processors.begin(); i != _processors.end(); ++i) {
4786 if (boost::dynamic_pointer_cast<Send> (*i) ||
4787 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4788 if ((*i)->name() == name) {
4797 MuteMaster::MutePoint
4798 Route::mute_points () const
4800 return _mute_master->mute_points ();
4804 Route::set_processor_positions ()
4806 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4808 bool had_amp = false;
4809 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4810 (*i)->set_pre_fader (!had_amp);
4817 /** Called when there is a proposed change to the input port count */
4819 Route::input_port_count_changing (ChanCount to)
4821 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4823 /* The processors cannot be configured with the new input arrangement, so
4829 /* The change is ok */
4833 /** Called when there is a proposed change to the output port count */
4835 Route::output_port_count_changing (ChanCount to)
4837 if (_strict_io && !_in_configure_processors) {
4840 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4841 if (processor_out_streams.get(*t) > to.get(*t)) {
4845 /* The change is ok */
4850 Route::unknown_processors () const
4854 if (_session.get_disable_all_loaded_plugins ()) {
4855 // Do not list "missing plugins" if they are explicitly disabled
4859 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4860 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4861 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4862 p.push_back ((*i)->name ());
4871 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4873 /* we assume that all our input ports feed all our output ports. its not
4874 universally true, but the alternative is way too corner-case to worry about.
4877 LatencyRange all_connections;
4880 all_connections.min = 0;
4881 all_connections.max = 0;
4883 all_connections.min = ~((pframes_t) 0);
4884 all_connections.max = 0;
4886 /* iterate over all "from" ports and determine the latency range for all of their
4887 connections to the "outside" (outside of this Route).
4890 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4894 p->get_connected_latency_range (range, playback);
4896 all_connections.min = min (all_connections.min, range.min);
4897 all_connections.max = max (all_connections.max, range.max);
4901 /* set the "from" port latencies to the max/min range of all their connections */
4903 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4904 p->set_private_latency_range (all_connections, playback);
4907 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4909 all_connections.min += our_latency;
4910 all_connections.max += our_latency;
4912 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4913 p->set_private_latency_range (all_connections, playback);
4916 return all_connections.max;
4920 Route::set_private_port_latencies (bool playback) const
4922 framecnt_t own_latency = 0;
4924 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4925 OR LATENCY CALLBACK.
4927 This is called (early) from the latency callback. It computes the REAL
4928 latency associated with each port and stores the result as the "private"
4929 latency of the port. A later call to Route::set_public_port_latencies()
4930 sets all ports to the same value to reflect the fact that we do latency
4931 compensation and so all signals are delayed by the same amount as they
4932 flow through ardour.
4935 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4936 if ((*i)->active ()) {
4937 own_latency += (*i)->signal_latency ();
4942 /* playback: propagate latency from "outside the route" to outputs to inputs */
4943 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4945 /* capture: propagate latency from "outside the route" to inputs to outputs */
4946 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4951 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4953 /* this is called to set the JACK-visible port latencies, which take
4954 latency compensation into account.
4963 const PortSet& ports (_input->ports());
4964 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4965 p->set_public_latency_range (range, playback);
4970 const PortSet& ports (_output->ports());
4971 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4972 p->set_public_latency_range (range, playback);
4977 /** Put the invisible processors in the right place in _processors.
4978 * Must be called with a writer lock on _processor_lock held.
4981 __attribute__((annotate("realtime")))
4984 Route::setup_invisible_processors ()
4987 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4988 assert (!lm.locked ());
4992 /* too early to be doing this stuff */
4996 /* we'll build this new list here and then use it
4998 * TODO put the ProcessorList is on the stack for RT-safety.
5001 ProcessorList new_processors;
5003 /* find visible processors */
5005 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5006 if ((*i)->display_to_user ()) {
5007 new_processors.push_back (*i);
5013 ProcessorList::iterator amp = new_processors.begin ();
5014 while (amp != new_processors.end() && *amp != _amp) {
5018 assert (amp != new_processors.end ());
5020 /* and the processor after the amp */
5022 ProcessorList::iterator after_amp = amp;
5028 switch (_meter_point) {
5030 assert (!_meter->display_to_user ());
5031 new_processors.push_front (_meter);
5034 assert (!_meter->display_to_user ());
5035 new_processors.insert (amp, _meter);
5037 case MeterPostFader:
5038 /* do nothing here */
5041 /* do nothing here */
5044 /* the meter is visible, so we don't touch it here */
5051 assert (_main_outs);
5052 assert (!_main_outs->display_to_user ());
5053 new_processors.push_back (_main_outs);
5055 /* iterator for the main outs */
5057 ProcessorList::iterator main = new_processors.end();
5060 /* OUTPUT METERING */
5062 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
5063 assert (!_meter->display_to_user ());
5065 /* add the processor just before or just after the main outs */
5067 ProcessorList::iterator meter_point = main;
5069 if (_meter_point == MeterOutput) {
5072 new_processors.insert (meter_point, _meter);
5077 if (_monitor_send && !is_monitor ()) {
5078 assert (!_monitor_send->display_to_user ());
5079 switch (Config->get_listen_position ()) {
5080 case PreFaderListen:
5081 switch (Config->get_pfl_position ()) {
5082 case PFLFromBeforeProcessors:
5083 new_processors.push_front (_monitor_send);
5085 case PFLFromAfterProcessors:
5086 new_processors.insert (amp, _monitor_send);
5089 _monitor_send->set_can_pan (false);
5091 case AfterFaderListen:
5092 switch (Config->get_afl_position ()) {
5093 case AFLFromBeforeProcessors:
5094 new_processors.insert (after_amp, _monitor_send);
5096 case AFLFromAfterProcessors:
5097 new_processors.insert (new_processors.end(), _monitor_send);
5100 _monitor_send->set_can_pan (true);
5105 #if 0 // not used - just yet
5106 if (!is_master() && !is_monitor() && !is_auditioner()) {
5107 new_processors.push_front (_delayline);
5111 /* MONITOR CONTROL */
5113 if (_monitor_control && is_monitor ()) {
5114 assert (!_monitor_control->display_to_user ());
5115 new_processors.insert (amp, _monitor_control);
5118 /* INTERNAL RETURN */
5120 /* doing this here means that any monitor control will come just after
5125 assert (!_intreturn->display_to_user ());
5126 new_processors.push_front (_intreturn);
5129 if (_trim && _trim->active()) {
5130 assert (!_trim->display_to_user ());
5131 new_processors.push_front (_trim);
5133 /* EXPORT PROCESSOR */
5135 if (_capturing_processor) {
5136 assert (!_capturing_processor->display_to_user ());
5137 new_processors.push_front (_capturing_processor);
5140 _processors = new_processors;
5142 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5143 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
5148 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5149 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5150 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5157 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5158 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5162 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5163 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5170 /** If the meter point is `Custom', make a note of where the meter is.
5171 * This is so that if the meter point is subsequently set to something else,
5172 * and then back to custom, we can put the meter back where it was last time
5173 * custom was enabled.
5175 * Must be called with the _processor_lock held.
5178 Route::maybe_note_meter_position ()
5180 if (_meter_point != MeterCustom) {
5184 _custom_meter_position_noted = true;
5185 /* custom meter points range from after trim to before panner/main_outs
5186 * this is a limitation by the current processor UI
5188 bool seen_trim = false;
5189 _processor_after_last_custom_meter.reset();
5190 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5191 if ((*i) == _trim) {
5194 if ((*i) == _main_outs) {
5195 _processor_after_last_custom_meter = *i;
5198 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5200 _processor_after_last_custom_meter = _trim;
5202 ProcessorList::iterator j = i;
5204 assert(j != _processors.end ()); // main_outs should be before
5205 _processor_after_last_custom_meter = *j;
5210 assert(_processor_after_last_custom_meter.lock());
5213 boost::shared_ptr<Processor>
5214 Route::processor_by_id (PBD::ID id) const
5216 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5217 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5218 if ((*i)->id() == id) {
5223 return boost::shared_ptr<Processor> ();
5226 /** @return the monitoring state, or in other words what data we are pushing
5227 * into the route (data from the inputs, data from disk or silence)
5230 Route::monitoring_state () const
5232 return MonitoringInput;
5235 /** @return what we should be metering; either the data coming from the input
5236 * IO or the data that is flowing through the route.
5239 Route::metering_state () const
5241 return MeteringRoute;
5245 Route::has_external_redirects () const
5247 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5249 /* ignore inactive processors and obviously ignore the main
5250 * outs since everything has them and we don't care.
5253 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5261 boost::shared_ptr<Processor>
5262 Route::the_instrument () const
5264 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5265 return the_instrument_unlocked ();
5268 boost::shared_ptr<Processor>
5269 Route::the_instrument_unlocked () const
5271 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5272 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
5273 if ((*i)->input_streams().n_midi() > 0 &&
5274 (*i)->output_streams().n_audio() > 0) {
5279 return boost::shared_ptr<Processor>();
5285 Route::non_realtime_locate (framepos_t pos)
5288 _pannable->transport_located (pos);
5291 if (_delayline.get()) {
5292 _delayline.get()->flush();
5296 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5297 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5299 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5300 (*i)->transport_located (pos);
5303 _roll_delay = _initial_delay;
5307 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5314 * We don't currently mix MIDI input together, so we don't need the
5315 * complex logic of the audio case.
5318 n_buffers = bufs.count().n_midi ();
5320 for (i = 0; i < n_buffers; ++i) {
5322 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5323 MidiBuffer& buf (bufs.get_midi (i));
5326 buf.copy (source_port->get_midi_buffer(nframes));
5328 buf.silence (nframes);
5334 n_buffers = bufs.count().n_audio();
5336 size_t n_ports = io->n_ports().n_audio();
5337 float scaling = 1.0f;
5339 if (n_ports > n_buffers) {
5340 scaling = ((float) n_buffers) / n_ports;
5343 for (i = 0; i < n_ports; ++i) {
5345 /* if there are more ports than buffers, map them onto buffers
5346 * in a round-robin fashion
5349 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5350 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5353 if (i < n_buffers) {
5355 /* first time through just copy a channel into
5359 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5361 if (scaling != 1.0f) {
5362 buf.apply_gain (scaling, nframes);
5367 /* on subsequent times around, merge data from
5368 * the port with what is already there
5371 if (scaling != 1.0f) {
5372 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5374 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5379 /* silence any remaining buffers */
5381 for (; i < n_buffers; ++i) {
5382 AudioBuffer& buf (bufs.get_audio (i));
5383 buf.silence (nframes);
5386 /* establish the initial setup of the buffer set, reflecting what was
5387 copied into it. unless, of course, we are the auditioner, in which
5388 case nothing was fed into it from the inputs at all.
5391 if (!is_auditioner()) {
5392 bufs.set_count (io->n_ports());
5396 boost::shared_ptr<AutomationControl>
5397 Route::pan_azimuth_control() const
5400 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5402 return boost::shared_ptr<AutomationControl>();
5404 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5405 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5407 if (!_pannable || !panner()) {
5408 return boost::shared_ptr<AutomationControl>();
5410 return _pannable->pan_azimuth_control;
5414 boost::shared_ptr<AutomationControl>
5415 Route::pan_elevation_control() const
5417 if (Profile->get_mixbus() || !_pannable || !panner()) {
5418 return boost::shared_ptr<AutomationControl>();
5421 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5423 if (c.find (PanElevationAutomation) != c.end()) {
5424 return _pannable->pan_elevation_control;
5426 return boost::shared_ptr<AutomationControl>();
5429 boost::shared_ptr<AutomationControl>
5430 Route::pan_width_control() const
5432 if (Profile->get_mixbus() || !_pannable || !panner()) {
5433 return boost::shared_ptr<AutomationControl>();
5436 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5438 if (c.find (PanWidthAutomation) != c.end()) {
5439 return _pannable->pan_width_control;
5441 return boost::shared_ptr<AutomationControl>();
5444 boost::shared_ptr<AutomationControl>
5445 Route::pan_frontback_control() const
5447 if (Profile->get_mixbus() || !_pannable || !panner()) {
5448 return boost::shared_ptr<AutomationControl>();
5451 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5453 if (c.find (PanFrontBackAutomation) != c.end()) {
5454 return _pannable->pan_frontback_control;
5456 return boost::shared_ptr<AutomationControl>();
5459 boost::shared_ptr<AutomationControl>
5460 Route::pan_lfe_control() const
5462 if (Profile->get_mixbus() || !_pannable || !panner()) {
5463 return boost::shared_ptr<AutomationControl>();
5466 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5468 if (c.find (PanLFEAutomation) != c.end()) {
5469 return _pannable->pan_lfe_control;
5471 return boost::shared_ptr<AutomationControl>();
5476 Route::eq_band_cnt () const
5478 if (Profile->get_mixbus()) {
5481 /* Ardour has no well-known EQ object */
5486 boost::shared_ptr<AutomationControl>
5487 Route::eq_gain_controllable (uint32_t band) const
5490 boost::shared_ptr<PluginInsert> eq = ch_eq();
5493 return boost::shared_ptr<AutomationControl>();
5496 uint32_t port_number;
5499 if (is_master() || mixbus()) {
5506 if (is_master() || mixbus()) {
5513 if (is_master() || mixbus()) {
5520 return boost::shared_ptr<AutomationControl>();
5523 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5525 return boost::shared_ptr<AutomationControl>();
5528 boost::shared_ptr<AutomationControl>
5529 Route::eq_freq_controllable (uint32_t band) const
5533 if (mixbus() || is_master()) {
5534 /* no frequency controls for mixbusses or master */
5535 return boost::shared_ptr<AutomationControl>();
5538 boost::shared_ptr<PluginInsert> eq = ch_eq();
5541 return boost::shared_ptr<AutomationControl>();
5544 uint32_t port_number;
5556 return boost::shared_ptr<AutomationControl>();
5559 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5561 return boost::shared_ptr<AutomationControl>();
5565 boost::shared_ptr<AutomationControl>
5566 Route::eq_q_controllable (uint32_t band) const
5568 return boost::shared_ptr<AutomationControl>();
5571 boost::shared_ptr<AutomationControl>
5572 Route::eq_shape_controllable (uint32_t band) const
5574 return boost::shared_ptr<AutomationControl>();
5577 boost::shared_ptr<AutomationControl>
5578 Route::eq_enable_controllable () const
5581 boost::shared_ptr<PluginInsert> eq = ch_eq();
5584 return boost::shared_ptr<AutomationControl>();
5587 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5589 return boost::shared_ptr<AutomationControl>();
5593 boost::shared_ptr<AutomationControl>
5594 Route::eq_hpf_controllable () const
5597 boost::shared_ptr<PluginInsert> eq = ch_eq();
5600 return boost::shared_ptr<AutomationControl>();
5603 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5605 return boost::shared_ptr<AutomationControl>();
5610 Route::eq_band_name (uint32_t band) const
5612 if (Profile->get_mixbus()) {
5628 boost::shared_ptr<AutomationControl>
5629 Route::comp_enable_controllable () const
5632 boost::shared_ptr<PluginInsert> comp = ch_comp();
5635 return boost::shared_ptr<AutomationControl>();
5638 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5640 return boost::shared_ptr<AutomationControl>();
5643 boost::shared_ptr<AutomationControl>
5644 Route::comp_threshold_controllable () const
5647 boost::shared_ptr<PluginInsert> comp = ch_comp();
5650 return boost::shared_ptr<AutomationControl>();
5653 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5656 return boost::shared_ptr<AutomationControl>();
5659 boost::shared_ptr<AutomationControl>
5660 Route::comp_speed_controllable () const
5663 boost::shared_ptr<PluginInsert> comp = ch_comp();
5666 return boost::shared_ptr<AutomationControl>();
5669 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5671 return boost::shared_ptr<AutomationControl>();
5674 boost::shared_ptr<AutomationControl>
5675 Route::comp_mode_controllable () const
5678 boost::shared_ptr<PluginInsert> comp = ch_comp();
5681 return boost::shared_ptr<AutomationControl>();
5684 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5686 return boost::shared_ptr<AutomationControl>();
5689 boost::shared_ptr<AutomationControl>
5690 Route::comp_makeup_controllable () const
5693 boost::shared_ptr<PluginInsert> comp = ch_comp();
5696 return boost::shared_ptr<AutomationControl>();
5699 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5701 return boost::shared_ptr<AutomationControl>();
5704 boost::shared_ptr<AutomationControl>
5705 Route::comp_redux_controllable () const
5708 boost::shared_ptr<PluginInsert> comp = ch_comp();
5711 return boost::shared_ptr<AutomationControl>();
5714 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5716 return boost::shared_ptr<AutomationControl>();
5721 Route::comp_mode_name (uint32_t mode) const
5726 return _("Leveler");
5728 return _("Compressor");
5730 return _("Limiter");
5732 return mixbus() ? _("Sidechain") : _("Limiter");
5742 Route::comp_speed_name (uint32_t mode) const
5760 boost::shared_ptr<AutomationControl>
5761 Route::send_level_controllable (uint32_t n) const
5764 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5766 return boost::shared_ptr<AutomationControl>();
5771 return boost::shared_ptr<AutomationControl>();
5774 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5775 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5777 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5779 return boost::shared_ptr<AutomationControl>();
5781 return s->gain_control ();
5785 boost::shared_ptr<AutomationControl>
5786 Route::send_enable_controllable (uint32_t n) const
5789 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5791 return boost::shared_ptr<AutomationControl>();
5796 return boost::shared_ptr<AutomationControl>();
5799 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5800 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5802 /* although Ardour sends have enable/disable as part of the Processor
5803 API, it is not exposed as a controllable.
5805 XXX: we should fix this.
5807 return boost::shared_ptr<AutomationControl>();
5812 Route::send_name (uint32_t n) const
5818 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5822 boost::shared_ptr<Processor> p = nth_send (n);
5831 boost::shared_ptr<AutomationControl>
5832 Route::master_send_enable_controllable () const
5835 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5837 return boost::shared_ptr<AutomationControl>();
5839 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5841 return boost::shared_ptr<AutomationControl>();