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 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
83 : SessionObject (sess, name)
85 , GraphNode (sess._process_graph)
88 , _signal_latency_at_amp_position (0)
89 , _signal_latency_at_trim_position (0)
92 , _pending_process_reorder (0)
93 , _pending_signals (0)
95 , _pending_declick (true)
96 , _meter_point (MeterPostFader)
97 , _pending_meter_point (MeterPostFader)
98 , _meter_type (MeterPeak)
100 , _soloed_by_others_upstream (0)
101 , _soloed_by_others_downstream (0)
102 , _solo_isolated (false)
103 , _solo_isolated_by_upstream (0)
104 , _denormal_protection (false)
107 , _declickable (false)
108 , _mute_master (new MuteMaster (sess, name))
109 , _have_internal_generator (false)
111 , _default_type (default_type)
113 , _has_order_key (false)
114 , _remote_control_id (0)
116 , _in_configure_processors (false)
117 , _initial_io_setup (false)
118 , _custom_meter_position_noted (false)
120 processor_max_streams.reset();
126 /* set default meter type */
128 _meter_type = Config->get_meter_type_master ();
130 else if (dynamic_cast<Track*>(this)) {
131 _meter_type = Config->get_meter_type_track ();
133 _meter_type = Config->get_meter_type_bus ();
136 /* add standard controls */
138 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
139 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
140 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
142 _solo_isolate_control.reset (new SoloIsolateControllable (X_("solo-iso"), shared_from_this ()));
143 _solo_safe_control.reset (new SoloSafeControllable (X_("solo-safe"), shared_from_this ()));
145 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
146 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
147 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
149 add_control (_solo_control);
150 add_control (_mute_control);
151 add_control (_phase_control);
155 if (!(_flags & Route::MonitorOut)) {
156 _pannable.reset (new Pannable (_session));
159 /* input and output objects */
161 _input.reset (new IO (_session, _name, IO::Input, _default_type));
162 _output.reset (new IO (_session, _name, IO::Output, _default_type));
164 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
165 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
167 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
168 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
170 #if 0 // not used - just yet
171 if (!is_master() && !is_monitor() && !is_auditioner()) {
172 _delayline.reset (new DelayLine (_session, _name));
173 add_processor (_delayline, PreFader);
177 /* add amp processor */
179 _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
180 add_control (_gain_control);
182 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
183 add_processor (_amp, PostFader);
186 _amp->set_display_name (_("Monitor"));
191 _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
192 add_control (_trim_control);
194 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
195 _trim->set_display_to_user (false);
197 if (dynamic_cast<AudioTrack*>(this)) {
198 /* we can't do this in the AudioTrack's constructor
199 * because _trim does not exit then
203 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
208 /* create standard processors: meter, main outs, monitor out;
209 they will be added to _processors by setup_invisible_processors ()
212 _meter.reset (new PeakMeter (_session, _name));
213 _meter->set_owner (this);
214 _meter->set_display_to_user (false);
217 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
218 _main_outs->activate ();
221 /* where we listen to tracks */
222 _intreturn.reset (new InternalReturn (_session));
223 _intreturn->activate ();
225 /* the thing that provides proper control over a control/monitor/listen bus
226 (such as per-channel cut, dim, solo, invert, etc).
228 _monitor_control.reset (new MonitorProcessor (_session));
229 _monitor_control->activate ();
232 if (is_master() || is_monitor() || is_auditioner()) {
233 _mute_master->set_solo_ignore (true);
236 /* now that we have _meter, its safe to connect to this */
239 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
240 configure_processors (0);
248 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
250 /* do this early so that we don't get incoming signals as we are going through destruction
255 /* don't use clear_processors here, as it depends on the session which may
256 be half-destroyed by now
259 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
260 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
261 (*i)->drop_references ();
264 _processors.clear ();
268 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
270 if (Config->get_remote_model() != UserOrdered) {
274 set_remote_control_id_internal (id, notify_class_listeners);
278 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
280 /* force IDs for master/monitor busses and prevent
281 any other route from accidentally getting these IDs
282 (i.e. legacy sessions)
285 if (is_master() && id != MasterBusRemoteControlID) {
286 id = MasterBusRemoteControlID;
289 if (is_monitor() && id != MonitorBusRemoteControlID) {
290 id = MonitorBusRemoteControlID;
297 /* don't allow it to collide */
299 if (!is_master () && !is_monitor() &&
300 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
301 id += MonitorBusRemoteControlID;
304 if (id != remote_control_id()) {
305 _remote_control_id = id;
306 RemoteControlIDChanged ();
308 if (notify_class_listeners) {
309 RemoteControlIDChange ();
315 Route::remote_control_id() const
318 return MasterBusRemoteControlID;
322 return MonitorBusRemoteControlID;
325 return _remote_control_id;
329 Route::has_order_key () const
331 return _has_order_key;
335 Route::order_key () const
341 Route::set_remote_control_id_explicit (uint32_t rid)
343 if (is_master() || is_monitor() || is_auditioner()) {
344 /* hard-coded remote IDs, or no remote ID */
348 if (_remote_control_id != rid) {
349 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
350 _remote_control_id = rid;
351 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
354 /* don't emit the class-level RID signal RemoteControlIDChange here,
355 leave that to the entity that changed the order key, so that we
356 don't get lots of emissions for no good reasons (e.g. when changing
357 all route order keys).
359 See Session::sync_remote_id_from_order_keys() for the (primary|only)
360 spot where that is emitted.
365 Route::set_order_key (uint32_t n)
367 _has_order_key = true;
369 if (_order_key == n) {
375 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
376 name(), order_key ()));
378 _session.set_dirty ();
382 Route::ensure_track_or_route_name(string name, Session &session)
384 string newname = name;
386 while (!session.io_name_is_legal (newname)) {
387 newname = bump_name_once (newname, ' ');
394 Route::inc_gain (gain_t factor)
396 /* To be used ONLY when doing group-relative gain adjustment, from
400 float desired_gain = _gain_control->user_double();
402 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
403 // really?! what's the idea here?
404 _gain_control->route_set_value (0.000001f + (0.000001f * factor));
406 _gain_control->route_set_value (desired_gain + (desired_gain * factor));
411 Route::set_gain (gain_t val, Controllable::GroupControlDisposition group_override)
413 if (use_group (group_override, &RouteGroup::is_gain)) {
415 if (_route_group->is_relative()) {
417 gain_t usable_gain = _gain_control->get_value();
418 if (usable_gain < 0.000001f) {
419 usable_gain = 0.000001f;
423 if (delta < 0.000001f) {
427 delta -= usable_gain;
432 gain_t factor = delta / usable_gain;
435 factor = _route_group->get_max_factor(factor);
436 if (factor == 0.0f) {
437 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
441 factor = _route_group->get_min_factor(factor);
442 if (factor == 0.0f) {
443 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
448 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor));
452 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, Controllable::NoGroup));
458 if (val == _gain_control->get_value()) {
462 _gain_control->route_set_value (val);
466 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
468 // TODO route group, see set_gain()
469 _trim_control->route_set_value (val);
473 Route::maybe_declick (BufferSet&, framecnt_t, int)
475 /* this is the "bus" implementation and they never declick.
480 /** Process this route for one (sub) cycle (process thread)
482 * @param bufs Scratch buffers to use for the signal path
483 * @param start_frame Initial transport frame
484 * @param end_frame Final transport frame
485 * @param nframes Number of frames to output (to ports)
487 * Note that (end_frame - start_frame) may not be equal to nframes when the
488 * transport speed isn't 1.0 (eg varispeed).
491 Route::process_output_buffers (BufferSet& bufs,
492 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
493 int declick, bool gain_automation_ok)
495 /* Caller must hold process lock */
496 assert (!AudioEngine::instance()->process_lock().trylock());
498 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
500 // can this actually happen? functions calling process_output_buffers()
501 // already take a reader-lock.
502 bufs.silence (nframes, 0);
506 /* figure out if we're going to use gain automation */
507 if (gain_automation_ok) {
508 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
509 _amp->setup_gain_automation (
510 start_frame + _signal_latency_at_amp_position,
511 end_frame + _signal_latency_at_amp_position,
514 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
515 _trim->setup_gain_automation (
516 start_frame + _signal_latency_at_trim_position,
517 end_frame + _signal_latency_at_trim_position,
520 _amp->apply_gain_automation (false);
521 _trim->apply_gain_automation (false);
524 /* Tell main outs what to do about monitoring. We do this so that
525 on a transition between monitoring states we get a de-clicking gain
526 change in the _main_outs delivery, if config.get_use_monitor_fades()
529 We override this in the case where we have an internal generator.
531 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
533 _main_outs->no_outs_cuz_we_no_monitor (silence);
535 /* -------------------------------------------------------------------------------------------
536 GLOBAL DECLICK (for transport changes etc.)
537 ----------------------------------------------------------------------------------------- */
539 maybe_declick (bufs, nframes, declick);
540 _pending_declick = 0;
542 /* -------------------------------------------------------------------------------------------
543 DENORMAL CONTROL/PHASE INVERT
544 ----------------------------------------------------------------------------------------- */
546 if (_phase_invert.any ()) {
550 if (_denormal_protection || Config->get_denormal_protection()) {
552 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
553 Sample* const sp = i->data();
555 if (_phase_invert[chn]) {
556 for (pframes_t nx = 0; nx < nframes; ++nx) {
561 for (pframes_t nx = 0; nx < nframes; ++nx) {
569 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
570 Sample* const sp = i->data();
572 if (_phase_invert[chn]) {
573 for (pframes_t nx = 0; nx < nframes; ++nx) {
582 if (_denormal_protection || Config->get_denormal_protection()) {
584 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
585 Sample* const sp = i->data();
586 for (pframes_t nx = 0; nx < nframes; ++nx) {
594 /* -------------------------------------------------------------------------------------------
596 ----------------------------------------------------------------------------------------- */
598 /* set this to be true if the meter will already have been ::run() earlier */
599 bool const meter_already_run = metering_state() == MeteringInput;
601 framecnt_t latency = 0;
603 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
605 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
606 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
611 /* if it has any inputs, make sure they match */
612 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
613 if (bufs.count() != (*i)->input_streams()) {
615 DEBUG::Processors, string_compose (
616 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
617 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
624 /* should we NOT run plugins here if the route is inactive?
625 do we catch route != active somewhere higher?
628 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
629 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
632 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
633 bufs.set_count ((*i)->output_streams());
635 if ((*i)->active ()) {
636 latency += (*i)->signal_latency ();
642 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
643 boost::shared_ptr<Processor> endpoint,
644 bool include_endpoint, bool for_export, bool for_freeze)
646 /* If no processing is required, there's no need to go any further. */
647 if (!endpoint && !include_endpoint) {
651 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
652 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
653 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
655 /* trim is always at the top, for bounce no latency compensation is needed */
656 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
657 _trim->setup_gain_automation (start, start + nframes, nframes);
660 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
662 if (!include_endpoint && (*i) == endpoint) {
666 /* if we're *not* exporting, stop processing if we come across a routing processor. */
667 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
670 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
674 /* special case the panner (export outputs)
675 * Ideally we'd only run the panner, not the delivery itself...
676 * but panners need separate input/output buffers and some context
677 * (panshell, panner type, etc). AFAICT there is no ill side effect
678 * of re-using the main delivery when freewheeling/exporting a region.
680 if ((*i) == _main_outs) {
681 assert ((*i)->does_routing());
682 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
683 buffers.set_count ((*i)->output_streams());
686 /* don't run any processors that do routing.
687 * Also don't bother with metering.
689 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
690 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
691 buffers.set_count ((*i)->output_streams());
692 latency += (*i)->signal_latency ();
695 if ((*i) == endpoint) {
702 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
703 bool include_endpoint, bool for_export, bool for_freeze) const
705 framecnt_t latency = 0;
706 if (!endpoint && !include_endpoint) {
710 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
711 if (!include_endpoint && (*i) == endpoint) {
714 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
717 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
720 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
721 latency += (*i)->signal_latency ();
723 if ((*i) == endpoint) {
731 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
732 bool include_endpoint, bool for_export, bool for_freeze) const
734 if (!endpoint && !include_endpoint) {
738 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
739 if (!include_endpoint && (*i) == endpoint) {
742 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
745 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
748 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
749 cc = (*i)->output_streams();
751 if ((*i) == endpoint) {
759 Route::n_process_buffers ()
761 return max (_input->n_ports(), processor_max_streams);
765 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
767 assert (is_monitor());
768 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
769 fill_buffers_with_input (bufs, _input, nframes);
770 passthru (bufs, start_frame, end_frame, nframes, declick);
774 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
778 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
780 /* control/monitor bus ignores input ports when something is
781 feeding the listen "stream". data will "arrive" into the
782 route from the intreturn processor element.
785 bufs.silence (nframes, 0);
788 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
789 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
793 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
795 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
797 bufs.set_count (_input->n_ports());
798 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
799 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
803 Route::set_listen (bool yn, Controllable::GroupControlDisposition group_override)
809 if (use_group (group_override, &RouteGroup::is_solo)) {
810 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, Controllable::ForGroup));
815 if (yn != _monitor_send->active()) {
817 _monitor_send->activate ();
818 _mute_master->set_soloed_by_self (true);
820 _monitor_send->deactivate ();
821 _mute_master->set_soloed_by_self (false);
823 _mute_master->set_soloed_by_others (false);
825 listen_changed (group_override); /* EMIT SIGNAL */
831 Route::listening_via_monitor () const
834 return _monitor_send->active ();
841 Route::set_solo_safe (bool yn, Controllable::GroupControlDisposition /* group_override */)
843 if (_solo_safe != yn) {
845 solo_safe_changed (); /* EMIT SIGNAL */
846 _solo_safe_control->Changed(); /* EMIT SIGNAL */
851 Route::solo_safe() const
857 Route::clear_all_solo_state ()
859 // ideally this function will never do anything, it only exists to forestall Murphy
860 bool emit_changed = false;
863 // these are really debug messages, but of possible interest.
865 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
867 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
868 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
869 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
873 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
874 // if self-soled, set_solo() will do signal emission
878 _soloed_by_others_upstream = 0;
879 _soloed_by_others_downstream = 0;
882 PBD::Unwinder<bool> uw (_solo_safe, false);
883 set_solo (false, Controllable::NoGroup);
887 set_mute_master_solo ();
888 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
893 Route::set_solo (bool yn, Controllable::GroupControlDisposition group_override)
895 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, grp ? %3 currently self-soloed ? %4\n",
896 name(), yn, enum_2_string(group_override), self_soloed()));
899 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
903 if (is_master() || is_monitor() || is_auditioner()) {
904 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
908 if (use_group (group_override, &RouteGroup::is_solo)) {
909 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, Controllable::ForGroup));
913 if (self_soloed() != yn) {
915 solo_changed (true, group_override); /* EMIT SIGNAL */
916 _solo_control->Changed (); /* EMIT SIGNAL */
919 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
921 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
922 Config->get_solo_mute_overrride().
925 if (yn && Profile->get_trx()) {
926 set_mute (false, Controllable::UseGroup);
931 Route::set_self_solo (bool yn)
933 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
935 set_mute_master_solo ();
939 Route::mod_solo_by_others_upstream (int32_t delta)
941 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
942 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
944 uint32_t old_sbu = _soloed_by_others_upstream;
947 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
948 _soloed_by_others_upstream += delta;
950 _soloed_by_others_upstream = 0;
953 _soloed_by_others_upstream += delta;
956 DEBUG_TRACE (DEBUG::Solo, string_compose (
957 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
958 name(), delta, _soloed_by_others_upstream, old_sbu,
959 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
961 /* push the inverse solo change to everything that feeds us.
963 This is important for solo-within-group. When we solo 1 track out of N that
964 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
965 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
966 tracks that feed it. This will silence them if they were audible because
967 of a bus solo, but the newly soloed track will still be audible (because
970 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
974 if ((_self_solo || _soloed_by_others_downstream) &&
975 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
976 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
978 if (delta > 0 || !Config->get_exclusive_solo()) {
979 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
980 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
984 boost::shared_ptr<Route> sr = i->r.lock();
986 sr->mod_solo_by_others_downstream (-delta);
992 set_mute_master_solo ();
993 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
997 Route::mod_solo_by_others_downstream (int32_t delta)
999 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
1000 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
1003 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
1004 _soloed_by_others_downstream += delta;
1006 _soloed_by_others_downstream = 0;
1009 _soloed_by_others_downstream += delta;
1012 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
1014 set_mute_master_solo ();
1015 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1019 Route::set_mute_master_solo ()
1021 _mute_master->set_soloed_by_self (self_soloed());
1022 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1026 Route::mod_solo_isolated_by_upstream (bool yn)
1028 bool old = solo_isolated ();
1029 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1030 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1033 if (_solo_isolated_by_upstream >= 1) {
1034 _solo_isolated_by_upstream--;
1036 _solo_isolated_by_upstream = 0;
1039 _solo_isolated_by_upstream++;
1042 if (solo_isolated() != old) {
1043 /* solo isolated status changed */
1044 _mute_master->set_solo_ignore (solo_isolated());
1045 solo_isolated_changed (); /* EMIT SIGNAL */
1050 Route::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
1052 if (is_master() || is_monitor() || is_auditioner()) {
1056 if (use_group (group_override, &RouteGroup::is_solo)) {
1057 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, Controllable::ForGroup));
1061 bool changed = false;
1064 if (_solo_isolated == false) {
1065 _mute_master->set_solo_ignore (true);
1068 _solo_isolated = true;
1070 if (_solo_isolated == true) {
1071 _solo_isolated = false;
1072 _mute_master->set_solo_ignore (false);
1082 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1084 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1085 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1087 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1092 bool does_feed = feeds (*i, &sends_only);
1094 if (does_feed && !sends_only) {
1095 (*i)->mod_solo_isolated_by_upstream (yn);
1099 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1101 solo_isolated_changed (); /* EMIT SIGNAL */
1102 _solo_isolate_control->Changed(); /* EMIT SIGNAL */
1106 Route::solo_isolated () const
1108 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1112 Route::set_mute_points (MuteMaster::MutePoint mp)
1114 _mute_master->set_mute_points (mp);
1115 mute_points_changed (); /* EMIT SIGNAL */
1117 if (_mute_master->muted_by_self()) {
1118 mute_changed (); /* EMIT SIGNAL */
1119 _mute_control->Changed (); /* EMIT SIGNAL */
1124 Route::set_mute (bool yn, Controllable::GroupControlDisposition group_override)
1126 if (use_group (group_override, &RouteGroup::is_mute)) {
1127 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, Controllable::ForGroup));
1131 if (muted() != yn) {
1132 _mute_master->set_muted_by_self (yn);
1133 /* allow any derived classes to respond to the mute change
1134 before anybody else knows about it.
1137 /* tell everyone else */
1138 mute_changed (); /* EMIT SIGNAL */
1139 _mute_control->Changed (); /* EMIT SIGNAL */
1144 Route::muted () const
1146 return _mute_master->muted_by_self();
1150 Route::muted_by_others () const
1152 // This method is only used by route_ui for display state.
1153 // The real thing is MuteMaster::muted_by_others_at()
1155 //master is never muted by others
1159 //now check to see if something is soloed (and I am not)
1160 //see also MuteMaster::mute_gain_at()
1161 return (_session.soloing() && !soloed() && !solo_isolated());
1166 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1168 cerr << name << " {" << endl;
1169 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1170 p != procs.end(); ++p) {
1171 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1173 cerr << "}" << endl;
1177 /** Supposing that we want to insert a Processor at a given Placement, return
1178 * the processor to add the new one before (or 0 to add at the end).
1180 boost::shared_ptr<Processor>
1181 Route::before_processor_for_placement (Placement p)
1183 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1185 ProcessorList::iterator loc;
1187 if (p == PreFader) {
1188 /* generic pre-fader: insert immediately before the amp */
1189 loc = find (_processors.begin(), _processors.end(), _amp);
1191 /* generic post-fader: insert right before the main outs */
1192 loc = find (_processors.begin(), _processors.end(), _main_outs);
1195 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1198 /** Supposing that we want to insert a Processor at a given index, return
1199 * the processor to add the new one before (or 0 to add at the end).
1201 boost::shared_ptr<Processor>
1202 Route::before_processor_for_index (int index)
1205 return boost::shared_ptr<Processor> ();
1208 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1210 ProcessorList::iterator i = _processors.begin ();
1212 while (i != _processors.end() && j < index) {
1213 if ((*i)->display_to_user()) {
1220 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1223 /** Add a processor either pre- or post-fader
1224 * @return 0 on success, non-0 on failure.
1227 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1229 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1233 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1234 * @param index Index to add the processor at, or -1 to add at the end of the list.
1235 * @return 0 on success, non-0 on failure.
1238 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1240 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1243 /** Add a processor to the route.
1244 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1245 * @return 0 on success, non-0 on failure.
1248 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1250 assert (processor != _meter);
1251 assert (processor != _main_outs);
1253 DEBUG_TRACE (DEBUG::Processors, string_compose (
1254 "%1 adding processor %2\n", name(), processor->name()));
1256 if (!AudioEngine::instance()->connected() || !processor) {
1261 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1262 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1263 ProcessorState pstate (this);
1265 boost::shared_ptr<PluginInsert> pi;
1266 boost::shared_ptr<PortInsert> porti;
1268 if (processor == _amp) {
1269 /* Ensure that only one amp is in the list at any time */
1270 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1271 if (check != _processors.end()) {
1272 if (before == _amp) {
1273 /* Already in position; all is well */
1276 _processors.erase (check);
1281 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1283 ProcessorList::iterator loc;
1285 /* inserting before a processor; find it */
1286 loc = find (_processors.begin(), _processors.end(), before);
1287 if (loc == _processors.end ()) {
1292 /* inserting at end */
1293 loc = _processors.end ();
1296 _processors.insert (loc, processor);
1297 processor->set_owner (this);
1299 // Set up processor list channels. This will set processor->[input|output]_streams(),
1300 // configure redirect ports properly, etc.
1303 if (configure_processors_unlocked (err)) {
1305 configure_processors_unlocked (0); // it worked before we tried to add it ...
1310 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1312 if (pi->has_no_inputs ()) {
1313 /* generator plugin */
1314 _have_internal_generator = true;
1319 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1320 processor->activate ();
1323 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1325 _output->set_user_latency (0);
1328 reset_instrument_info ();
1329 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1330 set_processor_positions ();
1336 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1338 const XMLProperty *prop;
1341 boost::shared_ptr<Processor> processor;
1343 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1344 so that we can add the processor in the right place (pre/post-fader)
1347 XMLNodeList const & children = node.children ();
1348 XMLNodeList::const_iterator i = children.begin ();
1350 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1354 Placement placement = PreFader;
1356 if (i != children.end()) {
1357 if ((prop = (*i)->property (X_("placement"))) != 0) {
1358 placement = Placement (string_2_enum (prop->value(), placement));
1362 if (node.name() == "Insert") {
1364 if ((prop = node.property ("type")) != 0) {
1366 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1367 prop->value() == "lv2" ||
1368 prop->value() == "windows-vst" ||
1369 prop->value() == "lxvst" ||
1370 prop->value() == "audiounit") {
1372 if (_session.get_disable_all_loaded_plugins ()) {
1373 processor.reset (new UnknownProcessor (_session, node));
1375 processor.reset (new PluginInsert (_session));
1380 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1385 } else if (node.name() == "Send") {
1387 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1388 processor.reset (new Send (_session, sendpan, _mute_master));
1392 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1396 if (processor->set_state (node, version)) {
1400 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1401 if (i != children.end()) {
1402 if ((prop = (*i)->property (X_("active"))) != 0) {
1403 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1404 processor->activate();
1406 processor->deactivate();
1410 return (add_processor (processor, placement, 0, false) == 0);
1413 catch (failed_constructor &err) {
1414 warning << _("processor could not be created. Ignored.") << endmsg;
1420 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1422 /* NOTE: this is intended to be used ONLY when copying
1423 processors from another Route. Hence the subtle
1424 differences between this and ::add_processor()
1427 ProcessorList::iterator loc;
1430 loc = find(_processors.begin(), _processors.end(), before);
1432 /* nothing specified - at end */
1433 loc = _processors.end ();
1436 if (!_session.engine().connected()) {
1440 if (others.empty()) {
1445 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1446 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1447 ProcessorState pstate (this);
1449 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1455 boost::shared_ptr<PluginInsert> pi;
1457 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1461 _processors.insert (loc, *i);
1462 (*i)->set_owner (this);
1464 if ((*i)->active()) {
1468 /* Think: does this really need to be called for every processor in the loop? */
1470 if (configure_processors_unlocked (err)) {
1472 configure_processors_unlocked (0); // it worked before we tried to add it ...
1477 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1480 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1481 boost::shared_ptr<PluginInsert> pi;
1483 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1484 if (pi->has_no_inputs ()) {
1485 _have_internal_generator = true;
1491 _output->set_user_latency (0);
1494 reset_instrument_info ();
1495 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1496 set_processor_positions ();
1502 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1504 if (p == PreFader) {
1505 start = _processors.begin();
1506 end = find(_processors.begin(), _processors.end(), _amp);
1508 start = find(_processors.begin(), _processors.end(), _amp);
1510 end = _processors.end();
1514 /** Turn off all processors with a given placement
1515 * @param p Placement of processors to disable
1518 Route::disable_processors (Placement p)
1520 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1522 ProcessorList::iterator start, end;
1523 placement_range(p, start, end);
1525 for (ProcessorList::iterator i = start; i != end; ++i) {
1526 (*i)->deactivate ();
1529 _session.set_dirty ();
1532 /** Turn off all redirects
1535 Route::disable_processors ()
1537 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1539 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1540 (*i)->deactivate ();
1543 _session.set_dirty ();
1546 /** Turn off all redirects with a given placement
1547 * @param p Placement of redirects to disable
1550 Route::disable_plugins (Placement p)
1552 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1554 ProcessorList::iterator start, end;
1555 placement_range(p, start, end);
1557 for (ProcessorList::iterator i = start; i != end; ++i) {
1558 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1559 (*i)->deactivate ();
1563 _session.set_dirty ();
1566 /** Turn off all plugins
1569 Route::disable_plugins ()
1571 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1573 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1574 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1575 (*i)->deactivate ();
1579 _session.set_dirty ();
1584 Route::ab_plugins (bool forward)
1586 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1590 /* forward = turn off all active redirects, and mark them so that the next time
1591 we go the other way, we will revert them
1594 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1595 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1599 if ((*i)->active()) {
1600 (*i)->deactivate ();
1601 (*i)->set_next_ab_is_active (true);
1603 (*i)->set_next_ab_is_active (false);
1609 /* backward = if the redirect was marked to go active on the next ab, do so */
1611 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1613 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1617 if ((*i)->get_next_ab_is_active()) {
1620 (*i)->deactivate ();
1625 _session.set_dirty ();
1629 /** Remove processors with a given placement.
1630 * @param p Placement of processors to remove.
1633 Route::clear_processors (Placement p)
1635 if (!_session.engine().connected()) {
1639 bool already_deleting = _session.deletion_in_progress();
1640 if (!already_deleting) {
1641 _session.set_deletion_in_progress();
1645 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1646 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1647 ProcessorList new_list;
1648 ProcessorStreams err;
1649 bool seen_amp = false;
1651 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1657 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1659 /* you can't remove these */
1661 new_list.push_back (*i);
1668 new_list.push_back (*i);
1671 (*i)->drop_references ();
1679 (*i)->drop_references ();
1682 new_list.push_back (*i);
1689 _processors = new_list;
1690 configure_processors_unlocked (&err); // this can't fail
1693 processor_max_streams.reset();
1694 _have_internal_generator = false;
1695 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1696 set_processor_positions ();
1698 reset_instrument_info ();
1700 if (!already_deleting) {
1701 _session.clear_deletion_in_progress();
1706 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1708 // TODO once the export point can be configured properly, do something smarter here
1709 if (processor == _capturing_processor) {
1710 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1711 if (need_process_lock) {
1715 _capturing_processor.reset();
1717 if (need_process_lock) {
1722 /* these can never be removed */
1724 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1728 if (!_session.engine().connected()) {
1732 processor_max_streams.reset();
1735 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1736 if (need_process_lock) {
1740 /* Caller must hold process lock */
1741 assert (!AudioEngine::instance()->process_lock().trylock());
1743 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1745 ProcessorState pstate (this);
1747 ProcessorList::iterator i;
1748 bool removed = false;
1750 for (i = _processors.begin(); i != _processors.end(); ) {
1751 if (*i == processor) {
1753 /* move along, see failure case for configure_processors()
1754 where we may need to reconfigure the processor.
1757 /* stop redirects that send signals to JACK ports
1758 from causing noise as a result of no longer being
1762 boost::shared_ptr<IOProcessor> iop;
1764 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1768 i = _processors.erase (i);
1776 _output->set_user_latency (0);
1784 if (configure_processors_unlocked (err)) {
1786 /* we know this will work, because it worked before :) */
1787 configure_processors_unlocked (0);
1791 _have_internal_generator = false;
1793 for (i = _processors.begin(); i != _processors.end(); ++i) {
1794 boost::shared_ptr<PluginInsert> pi;
1796 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1797 if (pi->has_no_inputs ()) {
1798 _have_internal_generator = true;
1803 if (need_process_lock) {
1808 reset_instrument_info ();
1809 processor->drop_references ();
1810 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1811 set_processor_positions ();
1817 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1819 ProcessorList deleted;
1821 if (!_session.engine().connected()) {
1825 processor_max_streams.reset();
1828 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1829 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1830 ProcessorState pstate (this);
1832 ProcessorList::iterator i;
1833 boost::shared_ptr<Processor> processor;
1835 for (i = _processors.begin(); i != _processors.end(); ) {
1839 /* these can never be removed */
1841 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1846 /* see if its in the list of processors to delete */
1848 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1853 /* stop IOProcessors that send to JACK ports
1854 from causing noise as a result of no longer being
1858 boost::shared_ptr<IOProcessor> iop;
1860 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1864 deleted.push_back (processor);
1865 i = _processors.erase (i);
1868 if (deleted.empty()) {
1869 /* none of those in the requested list were found */
1873 _output->set_user_latency (0);
1875 if (configure_processors_unlocked (err)) {
1877 /* we know this will work, because it worked before :) */
1878 configure_processors_unlocked (0);
1883 _have_internal_generator = false;
1885 for (i = _processors.begin(); i != _processors.end(); ++i) {
1886 boost::shared_ptr<PluginInsert> pi;
1888 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1889 if (pi->has_no_inputs ()) {
1890 _have_internal_generator = true;
1897 /* now try to do what we need to so that those that were removed will be deleted */
1899 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1900 (*i)->drop_references ();
1903 reset_instrument_info ();
1904 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1905 set_processor_positions ();
1911 Route::reset_instrument_info ()
1913 boost::shared_ptr<Processor> instr = the_instrument();
1915 _instrument_info.set_internal_instrument (instr);
1919 /** Caller must hold process lock */
1921 Route::configure_processors (ProcessorStreams* err)
1923 #ifndef PLATFORM_WINDOWS
1924 assert (!AudioEngine::instance()->process_lock().trylock());
1927 if (!_in_configure_processors) {
1928 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1929 return configure_processors_unlocked (err);
1936 Route::input_streams () const
1938 return _input->n_ports ();
1941 list<pair<ChanCount, ChanCount> >
1942 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1944 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1946 return try_configure_processors_unlocked (in, err);
1949 list<pair<ChanCount, ChanCount> >
1950 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1952 // Check each processor in order to see if we can configure as requested
1954 list<pair<ChanCount, ChanCount> > configuration;
1957 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1958 DEBUG_TRACE (DEBUG::Processors, "{\n");
1960 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1962 if ((*p)->can_support_io_configuration(in, out)) {
1963 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1964 configuration.push_back(make_pair(in, out));
1967 // restriction for Monitor Section Processors
1968 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1969 /* do not allow to add/remove channels (for now)
1970 * The Monitor follows the master-bus and has no panner (unpan)
1971 * but do allow processors with midi-in to be added (e.g VSTs with control that
1972 * will remain unconnected)
1974 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1975 return list<pair<ChanCount, ChanCount> > ();
1977 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1978 // internal sends make no sense, only feedback
1979 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1980 return list<pair<ChanCount, ChanCount> > ();
1982 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1983 /* External Sends can be problematic. one can add/remove ports
1984 * there signal leaves the DAW to external monitors anyway, so there's
1985 * no real use for allowing them here anyway.
1987 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1988 return list<pair<ChanCount, ChanCount> > ();
1990 if (boost::dynamic_pointer_cast<Send> (*p)) {
1992 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1993 return list<pair<ChanCount, ChanCount> > ();
2002 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
2003 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
2004 DEBUG_TRACE (DEBUG::Processors, "}\n");
2005 return list<pair<ChanCount, ChanCount> > ();
2009 DEBUG_TRACE (DEBUG::Processors, "}\n");
2011 return configuration;
2014 /** Set the input/output configuration of each processor in the processors list.
2015 * Caller must hold process lock.
2016 * Return 0 on success, otherwise configuration is impossible.
2019 Route::configure_processors_unlocked (ProcessorStreams* err)
2021 #ifndef PLATFORM_WINDOWS
2022 assert (!AudioEngine::instance()->process_lock().trylock());
2025 if (_in_configure_processors) {
2029 /* put invisible processors where they should be */
2030 setup_invisible_processors ();
2032 _in_configure_processors = true;
2034 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2036 if (configuration.empty ()) {
2037 _in_configure_processors = false;
2042 bool seen_mains_out = false;
2043 processor_out_streams = _input->n_ports();
2044 processor_max_streams.reset();
2046 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2047 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2049 if (!(*p)->configure_io(c->first, c->second)) {
2050 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2052 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2053 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2055 boost::shared_ptr<PluginInsert> pi;
2056 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2057 /* plugins connected via Split Match may have more channels.
2058 * route/scratch buffers are needed for all of them*/
2059 processor_max_streams = ChanCount::max(processor_max_streams, pi->input_streams());
2060 processor_max_streams = ChanCount::max(processor_max_streams, pi->natural_input_streams());
2064 if (boost::dynamic_pointer_cast<Delivery> (*p)
2065 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2066 /* main delivery will increase port count to match input.
2067 * the Delivery::Main is usually the last processor - followed only by
2070 seen_mains_out = true;
2072 if (!seen_mains_out) {
2073 processor_out_streams = out;
2079 _meter->set_max_channels (processor_max_streams);
2082 /* make sure we have sufficient scratch buffers to cope with the new processor
2085 _session.ensure_buffers (n_process_buffers ());
2087 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2089 _in_configure_processors = false;
2093 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2094 * @param state New active state for those processors.
2097 Route::all_visible_processors_active (bool state)
2099 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2101 if (_processors.empty()) {
2105 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2106 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2113 (*i)->deactivate ();
2117 _session.set_dirty ();
2121 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2123 /* check if re-order requires re-configuration of any processors
2124 * -> compare channel configuration for all processors
2126 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2127 ChanCount c = input_streams ();
2129 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2131 if (c != (*j)->input_streams()) {
2134 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2137 if ((*i)->input_streams() != c) {
2140 c = (*i)->output_streams();
2152 __attribute__((annotate("realtime")))
2155 Route::apply_processor_order (const ProcessorList& new_order)
2157 /* need to hold processor_lock; either read or write lock
2158 * and the engine process_lock.
2159 * Due to r/w lock ambiguity we can only assert the latter
2161 assert (!AudioEngine::instance()->process_lock().trylock());
2164 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2165 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2166 * processors in the current actual processor list that are hidden. Any visible processors
2167 * in the current list but not in "new_order" will be assumed to be deleted.
2170 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2171 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2172 * (note though that ::processors_reorder_needs_configure() ensured that
2173 * this function will only ever be called from the rt-thread if no processor were removed)
2175 * either way, I can't proove it, but an x-run due to re-order here is less likley
2176 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2179 ProcessorList as_it_will_be;
2180 ProcessorList::iterator oiter;
2181 ProcessorList::const_iterator niter;
2183 oiter = _processors.begin();
2184 niter = new_order.begin();
2186 while (niter != new_order.end()) {
2188 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2189 then append it to the temp list.
2191 Otherwise, see if the next processor in the old list is in the new list. if not,
2192 its been deleted. If its there, append it to the temp list.
2195 if (oiter == _processors.end()) {
2197 /* no more elements in the old list, so just stick the rest of
2198 the new order onto the temp list.
2201 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2202 while (niter != new_order.end()) {
2209 if (!(*oiter)->display_to_user()) {
2211 as_it_will_be.push_back (*oiter);
2215 /* visible processor: check that its in the new order */
2217 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2218 /* deleted: do nothing, shared_ptr<> will clean up */
2220 /* ignore this one, and add the next item from the new order instead */
2221 as_it_will_be.push_back (*niter);
2226 /* now remove from old order - its taken care of no matter what */
2227 oiter = _processors.erase (oiter);
2231 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2233 /* If the meter is in a custom position, find it and make a rough note of its position */
2234 maybe_note_meter_position ();
2238 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2240 // it a change is already queued, wait for it
2241 // (unless engine is stopped. apply immediately and proceed
2242 while (g_atomic_int_get (&_pending_process_reorder)) {
2243 if (!AudioEngine::instance()->running()) {
2244 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2245 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2247 apply_processor_order(_pending_processor_order);
2248 setup_invisible_processors ();
2250 g_atomic_int_set (&_pending_process_reorder, 0);
2252 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2253 set_processor_positions ();
2255 // TODO rather use a semaphore or something.
2256 // but since ::reorder_processors() is called
2257 // from the GUI thread, this is fine..
2262 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2264 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2265 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2266 ProcessorState pstate (this);
2268 apply_processor_order (new_order);
2270 if (configure_processors_unlocked (err)) {
2278 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2279 set_processor_positions ();
2282 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2283 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2285 // _pending_processor_order is protected by _processor_lock
2286 _pending_processor_order = new_order;
2287 g_atomic_int_set (&_pending_process_reorder, 1);
2300 Route::get_template()
2302 return state(false);
2306 Route::state(bool full_state)
2308 if (!_session._template_state_dir.empty()) {
2309 assert (!full_state); // only for templates
2310 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2313 XMLNode *node = new XMLNode("Route");
2314 ProcessorList::iterator i;
2317 id().print (buf, sizeof (buf));
2318 node->add_property("id", buf);
2319 node->add_property ("name", _name);
2320 node->add_property("default-type", _default_type.to_string());
2323 node->add_property("flags", enum_2_string (_flags));
2326 node->add_property("active", _active?"yes":"no");
2328 boost::to_string (_phase_invert, p);
2329 node->add_property("phase-invert", p);
2330 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2331 node->add_property("meter-point", enum_2_string (_meter_point));
2333 node->add_property("meter-type", enum_2_string (_meter_type));
2336 node->add_property("route-group", _route_group->name());
2339 snprintf (buf, sizeof (buf), "%d", _order_key);
2340 node->add_property ("order-key", buf);
2341 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2342 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2343 node->add_property ("soloed-by-upstream", buf);
2344 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2345 node->add_property ("soloed-by-downstream", buf);
2346 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2347 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2349 node->add_child_nocopy (_input->state (full_state));
2350 node->add_child_nocopy (_output->state (full_state));
2351 node->add_child_nocopy (_solo_control->get_state ());
2352 node->add_child_nocopy (_mute_control->get_state ());
2353 node->add_child_nocopy (_mute_master->get_state ());
2356 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2359 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2360 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2361 remote_control_node->add_property (X_("id"), buf);
2362 node->add_child_nocopy (*remote_control_node);
2364 if (_comment.length()) {
2365 XMLNode *cmt = node->add_child ("Comment");
2366 cmt->add_content (_comment);
2370 node->add_child_nocopy (_pannable->state (full_state));
2373 for (i = _processors.begin(); i != _processors.end(); ++i) {
2375 /* template save: do not include internal sends functioning as
2376 aux sends because the chance of the target ID
2377 in the session where this template is used
2380 similarly, do not save listen sends which connect to
2381 the monitor section, because these will always be
2384 boost::shared_ptr<InternalSend> is;
2386 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2387 if (is->role() == Delivery::Listen) {
2392 node->add_child_nocopy((*i)->state (full_state));
2396 node->add_child_copy (*_extra_xml);
2399 if (_custom_meter_position_noted) {
2400 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2402 after->id().print (buf, sizeof (buf));
2403 node->add_property (X_("processor-after-last-custom-meter"), buf);
2407 if (!_session._template_state_dir.empty()) {
2408 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2415 Route::set_state (const XMLNode& node, int version)
2417 if (version < 3000) {
2418 return set_state_2X (node, version);
2422 XMLNodeConstIterator niter;
2424 const XMLProperty *prop;
2426 if (node.name() != "Route"){
2427 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2431 if ((prop = node.property (X_("name"))) != 0) {
2432 Route::set_name (prop->value());
2436 _initial_io_setup = true;
2438 if ((prop = node.property (X_("flags"))) != 0) {
2439 _flags = Flag (string_2_enum (prop->value(), _flags));
2444 if (is_master() || is_monitor() || is_auditioner()) {
2445 _mute_master->set_solo_ignore (true);
2449 /* monitor bus does not get a panner, but if (re)created
2450 via XML, it will already have one by the time we
2451 call ::set_state(). so ... remove it.
2456 /* add all processors (except amp, which is always present) */
2458 nlist = node.children();
2459 XMLNode processor_state (X_("processor_state"));
2461 Stateful::save_extra_xml (node);
2463 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2467 if (child->name() == IO::state_node_name) {
2468 if ((prop = child->property (X_("direction"))) == 0) {
2472 if (prop->value() == "Input") {
2473 _input->set_state (*child, version);
2474 } else if (prop->value() == "Output") {
2475 _output->set_state (*child, version);
2479 if (child->name() == X_("Processor")) {
2480 processor_state.add_child_copy (*child);
2483 if (child->name() == X_("Pannable")) {
2485 _pannable->set_state (*child, version);
2487 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2492 if ((prop = node.property (X_("meter-point"))) != 0) {
2493 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2494 set_meter_point (mp, true);
2496 _meter->set_display_to_user (_meter_point == MeterCustom);
2500 if ((prop = node.property (X_("meter-type"))) != 0) {
2501 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2504 _initial_io_setup = false;
2506 set_processor_state (processor_state);
2508 // this looks up the internal instrument in processors
2509 reset_instrument_info();
2511 if ((prop = node.property ("self-solo")) != 0) {
2512 set_self_solo (string_is_affirmative (prop->value()));
2515 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2516 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2517 mod_solo_by_others_upstream (atoi (prop->value()));
2520 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2521 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2522 mod_solo_by_others_downstream (atoi (prop->value()));
2525 if ((prop = node.property ("solo-isolated")) != 0) {
2526 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2529 if ((prop = node.property ("solo-safe")) != 0) {
2530 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2533 if ((prop = node.property (X_("phase-invert"))) != 0) {
2534 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2537 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2538 set_denormal_protection (string_is_affirmative (prop->value()));
2541 if ((prop = node.property (X_("active"))) != 0) {
2542 bool yn = string_is_affirmative (prop->value());
2543 _active = !yn; // force switch
2544 set_active (yn, this);
2547 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2548 set_order_key (atoi(prop->value()));
2551 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2555 string::size_type colon, equal;
2556 string remaining = prop->value();
2558 while (remaining.length()) {
2560 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2561 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2564 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2565 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2568 string keyname = remaining.substr (0, equal);
2570 if ((keyname == "EditorSort") || (keyname == "editor")) {
2571 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2577 colon = remaining.find_first_of (':');
2579 if (colon != string::npos) {
2580 remaining = remaining.substr (colon+1);
2587 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2588 PBD::ID id (prop->value ());
2589 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2590 ProcessorList::const_iterator i = _processors.begin ();
2591 while (i != _processors.end() && (*i)->id() != id) {
2595 if (i != _processors.end ()) {
2596 _processor_after_last_custom_meter = *i;
2597 _custom_meter_position_noted = true;
2601 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2604 if (child->name() == X_("Comment")) {
2606 /* XXX this is a terrible API design in libxml++ */
2608 XMLNode *cmt = *(child->children().begin());
2609 _comment = cmt->content();
2611 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2612 if (prop->value() == "solo") {
2613 _solo_control->set_state (*child, version);
2614 } else if (prop->value() == "mute") {
2615 _mute_control->set_state (*child, version);
2618 } else if (child->name() == X_("RemoteControl")) {
2619 if ((prop = child->property (X_("id"))) != 0) {
2621 sscanf (prop->value().c_str(), "%d", &x);
2622 set_remote_control_id_internal (x);
2625 } else if (child->name() == X_("MuteMaster")) {
2626 _mute_master->set_state (*child, version);
2628 } else if (child->name() == Automatable::xml_node_name) {
2629 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2637 Route::set_state_2X (const XMLNode& node, int version)
2639 LocaleGuard lg (X_("C"));
2641 XMLNodeConstIterator niter;
2643 const XMLProperty *prop;
2645 /* 2X things which still remain to be handled:
2651 if (node.name() != "Route") {
2652 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2656 if ((prop = node.property (X_("flags"))) != 0) {
2657 string f = prop->value ();
2658 boost::replace_all (f, "ControlOut", "MonitorOut");
2659 _flags = Flag (string_2_enum (f, _flags));
2664 if (is_master() || is_monitor() || is_auditioner()) {
2665 _mute_master->set_solo_ignore (true);
2668 if ((prop = node.property (X_("phase-invert"))) != 0) {
2669 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2670 if (string_is_affirmative (prop->value ())) {
2673 set_phase_invert (p);
2676 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2677 set_denormal_protection (string_is_affirmative (prop->value()));
2680 if ((prop = node.property (X_("soloed"))) != 0) {
2681 bool yn = string_is_affirmative (prop->value());
2683 /* XXX force reset of solo status */
2688 if ((prop = node.property (X_("muted"))) != 0) {
2691 bool muted = string_is_affirmative (prop->value());
2697 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2699 if (string_is_affirmative (prop->value())){
2700 mute_point = mute_point + "PreFader";
2705 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2707 if (string_is_affirmative (prop->value())){
2710 mute_point = mute_point + ",";
2713 mute_point = mute_point + "PostFader";
2718 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2720 if (string_is_affirmative (prop->value())){
2723 mute_point = mute_point + ",";
2726 mute_point = mute_point + "Listen";
2731 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2733 if (string_is_affirmative (prop->value())){
2736 mute_point = mute_point + ",";
2739 mute_point = mute_point + "Main";
2743 _mute_master->set_mute_points (mute_point);
2744 _mute_master->set_muted_by_self (true);
2748 if ((prop = node.property (X_("meter-point"))) != 0) {
2749 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2752 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2753 don't mean the same thing.
2756 if ((prop = node.property (X_("order-keys"))) != 0) {
2760 string::size_type colon, equal;
2761 string remaining = prop->value();
2763 while (remaining.length()) {
2765 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2766 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2769 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2770 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2773 string keyname = remaining.substr (0, equal);
2775 if (keyname == "EditorSort" || keyname == "editor") {
2776 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2782 colon = remaining.find_first_of (':');
2784 if (colon != string::npos) {
2785 remaining = remaining.substr (colon+1);
2794 nlist = node.children ();
2795 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2799 if (child->name() == IO::state_node_name) {
2801 /* there is a note in IO::set_state_2X() about why we have to call
2805 _input->set_state_2X (*child, version, true);
2806 _output->set_state_2X (*child, version, false);
2808 if ((prop = child->property (X_("name"))) != 0) {
2809 Route::set_name (prop->value ());
2814 if ((prop = child->property (X_("active"))) != 0) {
2815 bool yn = string_is_affirmative (prop->value());
2816 _active = !yn; // force switch
2817 set_active (yn, this);
2820 if ((prop = child->property (X_("gain"))) != 0) {
2823 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2824 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2828 /* Set up Panners in the IO */
2829 XMLNodeList io_nlist = child->children ();
2831 XMLNodeConstIterator io_niter;
2834 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2836 io_child = *io_niter;
2838 if (io_child->name() == X_("Panner")) {
2839 _main_outs->panner_shell()->set_state(*io_child, version);
2840 } else if (io_child->name() == X_("Automation")) {
2841 /* IO's automation is for the fader */
2842 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2848 XMLNodeList redirect_nodes;
2850 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2854 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2855 redirect_nodes.push_back(child);
2860 set_processor_state_2X (redirect_nodes, version);
2862 Stateful::save_extra_xml (node);
2864 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2867 if (child->name() == X_("Comment")) {
2869 /* XXX this is a terrible API design in libxml++ */
2871 XMLNode *cmt = *(child->children().begin());
2872 _comment = cmt->content();
2874 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2875 if (prop->value() == X_("solo")) {
2876 _solo_control->set_state (*child, version);
2877 } else if (prop->value() == X_("mute")) {
2878 _mute_control->set_state (*child, version);
2881 } else if (child->name() == X_("RemoteControl")) {
2882 if ((prop = child->property (X_("id"))) != 0) {
2884 sscanf (prop->value().c_str(), "%d", &x);
2885 set_remote_control_id_internal (x);
2895 Route::get_processor_state ()
2897 XMLNode* root = new XMLNode (X_("redirects"));
2898 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2899 root->add_child_nocopy ((*i)->state (true));
2906 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2908 /* We don't bother removing existing processors not in nList, as this
2909 method will only be called when creating a Route from scratch, not
2910 for undo purposes. Just put processors in at the appropriate place
2914 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2915 add_processor_from_xml_2X (**i, version);
2920 Route::set_processor_state (const XMLNode& node)
2922 const XMLNodeList &nlist = node.children();
2923 XMLNodeConstIterator niter;
2924 ProcessorList new_order;
2925 bool must_configure = false;
2927 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2929 XMLProperty* prop = (*niter)->property ("type");
2931 if (prop->value() == "amp") {
2932 _amp->set_state (**niter, Stateful::current_state_version);
2933 new_order.push_back (_amp);
2934 } else if (prop->value() == "trim") {
2935 _trim->set_state (**niter, Stateful::current_state_version);
2936 new_order.push_back (_trim);
2937 } else if (prop->value() == "meter") {
2938 _meter->set_state (**niter, Stateful::current_state_version);
2939 new_order.push_back (_meter);
2940 } else if (prop->value() == "delay") {
2942 _delayline->set_state (**niter, Stateful::current_state_version);
2943 new_order.push_back (_delayline);
2945 } else if (prop->value() == "main-outs") {
2946 _main_outs->set_state (**niter, Stateful::current_state_version);
2947 } else if (prop->value() == "intreturn") {
2949 _intreturn.reset (new InternalReturn (_session));
2950 must_configure = true;
2952 _intreturn->set_state (**niter, Stateful::current_state_version);
2953 } else if (is_monitor() && prop->value() == "monitor") {
2954 if (!_monitor_control) {
2955 _monitor_control.reset (new MonitorProcessor (_session));
2956 must_configure = true;
2958 _monitor_control->set_state (**niter, Stateful::current_state_version);
2959 } else if (prop->value() == "capture") {
2960 /* CapturingProcessor should never be restored, it's always
2961 added explicitly when needed */
2963 ProcessorList::iterator o;
2965 for (o = _processors.begin(); o != _processors.end(); ++o) {
2966 XMLProperty* id_prop = (*niter)->property(X_("id"));
2967 if (id_prop && (*o)->id() == id_prop->value()) {
2968 (*o)->set_state (**niter, Stateful::current_state_version);
2969 new_order.push_back (*o);
2974 // If the processor (*niter) is not on the route then create it
2976 if (o == _processors.end()) {
2978 boost::shared_ptr<Processor> processor;
2980 if (prop->value() == "intsend") {
2982 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2984 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2985 prop->value() == "lv2" ||
2986 prop->value() == "windows-vst" ||
2987 prop->value() == "lxvst" ||
2988 prop->value() == "luaproc" ||
2989 prop->value() == "audiounit") {
2991 if (_session.get_disable_all_loaded_plugins ()) {
2992 processor.reset (new UnknownProcessor (_session, **niter));
2994 processor.reset (new PluginInsert (_session));
2996 } else if (prop->value() == "port") {
2998 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3000 } else if (prop->value() == "send") {
3002 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3005 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3009 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3010 /* This processor could not be configured. Turn it into a UnknownProcessor */
3011 processor.reset (new UnknownProcessor (_session, **niter));
3014 /* we have to note the monitor send here, otherwise a new one will be created
3015 and the state of this one will be lost.
3017 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3018 if (isend && isend->role() == Delivery::Listen) {
3019 _monitor_send = isend;
3022 /* it doesn't matter if invisible processors are added here, as they
3023 will be sorted out by setup_invisible_processors () shortly.
3026 new_order.push_back (processor);
3027 must_configure = true;
3033 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3034 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3035 _processors = new_order;
3037 if (must_configure) {
3038 configure_processors_unlocked (0);
3041 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3043 (*i)->set_owner (this);
3044 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3046 boost::shared_ptr<PluginInsert> pi;
3048 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3049 if (pi->has_no_inputs ()) {
3050 _have_internal_generator = true;
3057 reset_instrument_info ();
3058 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3059 set_processor_positions ();
3063 Route::curve_reallocate ()
3065 // _gain_automation_curve.finish_resize ();
3066 // _pan_automation_curve.finish_resize ();
3070 Route::silence (framecnt_t nframes)
3072 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3077 silence_unlocked (nframes);
3081 Route::silence_unlocked (framecnt_t nframes)
3083 /* Must be called with the processor lock held */
3087 _output->silence (nframes);
3089 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3090 boost::shared_ptr<PluginInsert> pi;
3092 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3093 // skip plugins, they don't need anything when we're not active
3097 (*i)->silence (nframes);
3100 if (nframes == _session.get_block_size()) {
3107 Route::add_internal_return ()
3110 _intreturn.reset (new InternalReturn (_session));
3111 add_processor (_intreturn, PreFader);
3116 Route::add_send_to_internal_return (InternalSend* send)
3118 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3120 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3121 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3124 return d->add_send (send);
3130 Route::remove_send_from_internal_return (InternalSend* send)
3132 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3134 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3135 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3138 return d->remove_send (send);
3144 Route::enable_monitor_send ()
3146 /* Caller must hold process lock */
3147 assert (!AudioEngine::instance()->process_lock().trylock());
3149 /* master never sends to monitor section via the normal mechanism */
3150 assert (!is_master ());
3151 assert (!is_monitor ());
3153 /* make sure we have one */
3154 if (!_monitor_send) {
3155 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3156 _monitor_send->set_display_to_user (false);
3160 configure_processors (0);
3163 /** Add an aux send to a route.
3164 * @param route route to send to.
3165 * @param before Processor to insert before, or 0 to insert at the end.
3168 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3170 assert (route != _session.monitor_out ());
3173 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3175 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3177 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3179 if (d && d->target_route() == route) {
3180 /* already listening via the specified IO: do nothing */
3188 boost::shared_ptr<InternalSend> listener;
3191 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3192 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3193 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3196 add_processor (listener, before);
3198 } catch (failed_constructor& err) {
3206 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3208 ProcessorStreams err;
3209 ProcessorList::iterator tmp;
3212 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3214 /* have to do this early because otherwise processor reconfig
3215 * will put _monitor_send back in the list
3218 if (route == _session.monitor_out()) {
3219 _monitor_send.reset ();
3223 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3225 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3227 if (d && d->target_route() == route) {
3229 if (remove_processor (*x, &err, false) > 0) {
3235 /* list could have been demolished while we dropped the lock
3238 if (_session.engine().connected()) {
3239 /* i/o processors cannot be removed if the engine is not running
3240 * so don't live-loop in case the engine is N/A or dies
3250 Route::set_comment (string cmt, void *src)
3254 _session.set_dirty ();
3258 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3260 FeedRecord fr (other, via_sends_only);
3262 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3264 if (!result.second) {
3266 /* already a record for "other" - make sure sends-only information is correct */
3267 if (!via_sends_only && result.first->sends_only) {
3268 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3269 frp->sends_only = false;
3273 return result.second;
3277 Route::clear_fed_by ()
3283 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3285 const FedBy& fed_by (other->fed_by());
3287 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3288 boost::shared_ptr<Route> sr = f->r.lock();
3290 if (sr && (sr.get() == this)) {
3292 if (via_sends_only) {
3293 *via_sends_only = f->sends_only;
3304 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3306 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3308 if (_output->connected_to (other->input())) {
3309 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3310 if (via_send_only) {
3311 *via_send_only = false;
3318 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3320 boost::shared_ptr<IOProcessor> iop;
3322 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3323 if (iop->feeds (other)) {
3324 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3325 if (via_send_only) {
3326 *via_send_only = true;
3330 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3333 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3338 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3343 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3345 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3348 /** Called from the (non-realtime) butler thread when the transport is stopped */
3350 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3352 framepos_t now = _session.transport_frame();
3355 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3357 Automatable::transport_stopped (now);
3359 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3361 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3365 (*i)->transport_stopped (now);
3369 _roll_delay = _initial_delay;
3373 Route::input_change_handler (IOChange change, void * /*src*/)
3375 if ((change.type & IOChange::ConfigurationChanged)) {
3376 /* This is called with the process lock held if change
3377 contains ConfigurationChanged
3379 configure_processors (0);
3380 _phase_invert.resize (_input->n_ports().n_audio ());
3381 io_changed (); /* EMIT SIGNAL */
3384 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3387 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3388 if (_input->connected()) {
3389 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3390 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3394 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3395 if (does_feed && !sends_only) {
3396 if ((*i)->soloed()) {
3399 if ((*i)->solo_isolated()) {
3406 int delta = sbou - _soloed_by_others_upstream;
3407 int idelta = ibou - _solo_isolated_by_upstream;
3410 PBD::warning << string_compose (
3411 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3412 _name, ibou, _solo_isolated_by_upstream, idelta)
3417 if (_soloed_by_others_upstream) {
3418 // ignore new connections (they're not propagated)
3420 mod_solo_by_others_upstream (delta);
3424 if (_solo_isolated_by_upstream) {
3425 // solo-isolate currently only propagates downstream
3427 mod_solo_isolated_by_upstream (false);
3429 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3430 // but idelta can't be smaller than -1, can it?
3431 //_solo_isolated_by_upstream = ibou;
3434 // Session::route_solo_changed does not propagate indirect solo-changes
3435 // propagate downstream to tracks
3436 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3437 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3441 bool does_feed = feeds (*i, &sends_only);
3442 if (delta <= 0 && does_feed && !sends_only) {
3443 (*i)->mod_solo_by_others_upstream (delta);
3446 if (idelta < 0 && does_feed && !sends_only) {
3447 (*i)->mod_solo_isolated_by_upstream (false);
3454 Route::output_change_handler (IOChange change, void * /*src*/)
3456 if (_initial_io_setup) {
3460 if ((change.type & IOChange::ConfigurationChanged)) {
3461 /* This is called with the process lock held if change
3462 contains ConfigurationChanged
3464 configure_processors (0);
3467 _session.reset_monitor_section();
3470 io_changed (); /* EMIT SIGNAL */
3473 if (_soloed_by_others_downstream) {
3475 /* checking all all downstream routes for
3476 * explicit of implict solo is a rather drastic measure,
3477 * ideally the input_change_handler() of the other route
3478 * would propagate the change to us.
3480 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3481 if (_output->connected()) {
3482 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3483 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3487 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3488 if (does_feed && !sends_only) {
3489 if ((*i)->soloed()) {
3496 int delta = sbod - _soloed_by_others_downstream;
3498 // do not allow new connections to change implicit solo (no propagation)
3499 mod_solo_by_others_downstream (delta);
3500 // Session::route_solo_changed() does not propagate indirect solo-changes
3501 // propagate upstream to tracks
3502 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3503 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3507 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3508 if (delta != 0 && does_feed && !sends_only) {
3509 (*i)->mod_solo_by_others_downstream (delta);
3518 Route::pans_required () const
3520 if (n_outputs().n_audio() < 2) {
3524 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3528 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3530 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3536 if (n_outputs().n_total() == 0) {
3540 if (!_active || n_inputs() == ChanCount::ZERO) {
3541 silence_unlocked (nframes);
3545 if (session_state_changing) {
3546 if (_session.transport_speed() != 0.0f) {
3547 /* we're rolling but some state is changing (e.g. our diskstream contents)
3548 so we cannot use them. Be silent till this is over.
3550 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3552 silence_unlocked (nframes);
3555 /* we're really not rolling, so we're either delivery silence or actually
3556 monitoring, both of which are safe to do while session_state_changing is true.
3560 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3562 fill_buffers_with_input (bufs, _input, nframes);
3564 if (_meter_point == MeterInput) {
3565 _meter->run (bufs, start_frame, end_frame, nframes, true);
3568 _amp->apply_gain_automation (false);
3569 _trim->apply_gain_automation (false);
3570 passthru (bufs, start_frame, end_frame, nframes, 0);
3576 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3578 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3583 if (n_outputs().n_total() == 0) {
3587 if (!_active || n_inputs().n_total() == 0) {
3588 silence_unlocked (nframes);
3592 framepos_t unused = 0;
3594 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3600 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3602 fill_buffers_with_input (bufs, _input, nframes);
3604 if (_meter_point == MeterInput) {
3605 _meter->run (bufs, start_frame, end_frame, nframes, true);
3608 passthru (bufs, start_frame, end_frame, nframes, declick);
3614 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3621 Route::flush_processors ()
3623 /* XXX shouldn't really try to take this lock, since
3624 this is called from the RT audio thread.
3627 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3629 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3635 __attribute__((annotate("realtime")))
3638 Route::apply_processor_changes_rt ()
3640 int emissions = EmitNone;
3642 if (_pending_meter_point != _meter_point) {
3643 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3645 /* meters always have buffers for 'processor_max_streams'
3646 * they can be re-positioned without re-allocation */
3647 if (set_meter_point_unlocked()) {
3648 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3650 emissions |= EmitMeterChanged;
3655 bool changed = false;
3657 if (g_atomic_int_get (&_pending_process_reorder)) {
3658 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3660 apply_processor_order (_pending_processor_order);
3661 setup_invisible_processors ();
3663 g_atomic_int_set (&_pending_process_reorder, 0);
3664 emissions |= EmitRtProcessorChange;
3668 set_processor_positions ();
3670 if (emissions != 0) {
3671 g_atomic_int_set (&_pending_signals, emissions);
3678 Route::emit_pending_signals ()
3681 int sig = g_atomic_int_and (&_pending_signals, 0);
3682 if (sig & EmitMeterChanged) {
3683 _meter->emit_configuration_changed();
3684 meter_change (); /* EMIT SIGNAL */
3685 if (sig & EmitMeterVisibilityChange) {
3686 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3688 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3691 if (sig & EmitRtProcessorChange) {
3692 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3697 Route::set_meter_point (MeterPoint p, bool force)
3699 if (_pending_meter_point == p && !force) {
3703 if (force || !AudioEngine::instance()->running()) {
3704 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3705 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3706 _pending_meter_point = p;
3707 _meter->emit_configuration_changed();
3708 meter_change (); /* EMIT SIGNAL */
3709 if (set_meter_point_unlocked()) {
3710 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3712 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3715 _pending_meter_point = p;
3721 __attribute__((annotate("realtime")))
3724 Route::set_meter_point_unlocked ()
3727 /* Caller must hold process and processor write lock */
3728 assert (!AudioEngine::instance()->process_lock().trylock());
3729 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3730 assert (!lm.locked ());
3733 _meter_point = _pending_meter_point;
3735 bool meter_was_visible_to_user = _meter->display_to_user ();
3737 if (!_custom_meter_position_noted) {
3738 maybe_note_meter_position ();
3741 if (_meter_point != MeterCustom) {
3743 _meter->set_display_to_user (false);
3745 setup_invisible_processors ();
3748 _meter->set_display_to_user (true);
3750 /* If we have a previous position for the custom meter, try to put it there */
3751 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3753 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3754 if (i != _processors.end ()) {
3755 _processors.remove (_meter);
3756 _processors.insert (i, _meter);
3758 } else {// at end, right before the mains_out/panner
3759 _processors.remove (_meter);
3760 ProcessorList::iterator main = _processors.end();
3761 _processors.insert (--main, _meter);
3765 /* Set up the meter for its new position */
3767 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3771 if (loc == _processors.begin()) {
3772 m_in = _input->n_ports();
3774 ProcessorList::iterator before = loc;
3776 m_in = (*before)->output_streams ();
3779 _meter->reflect_inputs (m_in);
3781 /* we do not need to reconfigure the processors, because the meter
3782 (a) is always ready to handle processor_max_streams
3783 (b) is always an N-in/N-out processor, and thus moving
3784 it doesn't require any changes to the other processors.
3787 /* these should really be done after releasing the lock
3788 * but all those signals are subscribed to with gui_thread()
3791 return (_meter->display_to_user() != meter_was_visible_to_user);
3795 Route::listen_position_changed ()
3798 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3799 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3800 ProcessorState pstate (this);
3802 if (configure_processors_unlocked (0)) {
3803 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3805 configure_processors_unlocked (0); // it worked before we tried to add it ...
3810 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3811 _session.set_dirty ();
3814 boost::shared_ptr<CapturingProcessor>
3815 Route::add_export_point()
3817 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3818 if (!_capturing_processor) {
3820 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3821 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3823 _capturing_processor.reset (new CapturingProcessor (_session));
3824 _capturing_processor->activate ();
3826 configure_processors_unlocked (0);
3830 return _capturing_processor;
3834 Route::update_signal_latency ()
3836 framecnt_t l = _output->user_latency();
3837 framecnt_t lamp = 0;
3838 bool before_amp = true;
3839 framecnt_t ltrim = 0;
3840 bool before_trim = true;
3842 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3843 if ((*i)->active ()) {
3844 l += (*i)->signal_latency ();
3849 if ((*i) == _trim) {
3860 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3862 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3863 _signal_latency_at_amp_position = lamp;
3864 _signal_latency_at_trim_position = ltrim;
3866 if (_signal_latency != l) {
3867 _signal_latency = l;
3868 signal_latency_changed (); /* EMIT SIGNAL */
3871 return _signal_latency;
3875 Route::set_user_latency (framecnt_t nframes)
3877 _output->set_user_latency (nframes);
3878 _session.update_latency_compensation ();
3882 Route::set_latency_compensation (framecnt_t longest_session_latency)
3884 framecnt_t old = _initial_delay;
3886 if (_signal_latency < longest_session_latency) {
3887 _initial_delay = longest_session_latency - _signal_latency;
3892 DEBUG_TRACE (DEBUG::Latency, string_compose (
3893 "%1: compensate for maximum latency of %2,"
3894 "given own latency of %3, using initial delay of %4\n",
3895 name(), longest_session_latency, _signal_latency, _initial_delay));
3897 if (_initial_delay != old) {
3898 initial_delay_changed (); /* EMIT SIGNAL */
3901 if (_session.transport_stopped()) {
3902 _roll_delay = _initial_delay;
3907 Route::set_block_size (pframes_t nframes)
3909 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3910 (*i)->set_block_size (nframes);
3913 _session.ensure_buffers (n_process_buffers ());
3917 Route::protect_automation ()
3919 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3920 (*i)->protect_automation();
3923 /** @param declick 1 to set a pending declick fade-in,
3924 * -1 to set a pending declick fade-out
3927 Route::set_pending_declick (int declick)
3930 /* this call is not allowed to turn off a pending declick */
3932 _pending_declick = declick;
3935 _pending_declick = 0;
3939 /** Shift automation forwards from a particular place, thereby inserting time.
3940 * Adds undo commands for any shifts that are performed.
3942 * @param pos Position to start shifting from.
3943 * @param frames Amount to shift forwards by.
3947 Route::shift (framepos_t pos, framecnt_t frames)
3949 /* gain automation */
3951 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3953 XMLNode &before = gc->alist()->get_state ();
3954 gc->alist()->shift (pos, frames);
3955 XMLNode &after = gc->alist()->get_state ();
3956 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3959 /* gain automation */
3961 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3963 XMLNode &before = gc->alist()->get_state ();
3964 gc->alist()->shift (pos, frames);
3965 XMLNode &after = gc->alist()->get_state ();
3966 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3969 // TODO mute automation ??
3971 /* pan automation */
3973 ControlSet::Controls& c (_pannable->controls());
3975 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3976 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3978 boost::shared_ptr<AutomationList> al = pc->alist();
3979 XMLNode& before = al->get_state ();
3980 al->shift (pos, frames);
3981 XMLNode& after = al->get_state ();
3982 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3987 /* redirect automation */
3989 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3990 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3992 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3994 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3995 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3997 boost::shared_ptr<AutomationList> al = ac->alist();
3998 XMLNode &before = al->get_state ();
3999 al->shift (pos, frames);
4000 XMLNode &after = al->get_state ();
4001 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4009 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4011 boost::shared_ptr<Processor> processor (p.lock ());
4012 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4016 pi->set_state_dir (d);
4020 Route::save_as_template (const string& path, const string& name)
4022 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4023 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4025 XMLNode& node (state (false));
4029 IO::set_name_in_state (*node.children().front(), name);
4031 tree.set_root (&node);
4033 /* return zero on success, non-zero otherwise */
4034 return !tree.write (path.c_str());
4039 Route::set_name (const string& str)
4041 if (str == name()) {
4045 string name = Route::ensure_track_or_route_name (str, _session);
4046 SessionObject::set_name (name);
4048 bool ret = (_input->set_name(name) && _output->set_name(name));
4051 /* rename the main outs. Leave other IO processors
4052 * with whatever name they already have, because its
4053 * just fine as it is (it will not contain the route
4054 * name if its a port insert, port send or port return).
4058 if (_main_outs->set_name (name)) {
4059 /* XXX returning false here is stupid because
4060 we already changed the route name.
4070 /** Set the name of a route in an XML description.
4071 * @param node XML <Route> node to set the name in.
4072 * @param name New name.
4075 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4077 node.add_property (X_("name"), name);
4079 XMLNodeList children = node.children();
4080 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4082 if ((*i)->name() == X_("IO")) {
4084 IO::set_name_in_state (**i, name);
4086 } else if ((*i)->name() == X_("Processor")) {
4088 XMLProperty* role = (*i)->property (X_("role"));
4089 if (role && role->value() == X_("Main")) {
4090 (*i)->add_property (X_("name"), name);
4093 } else if ((*i)->name() == X_("Diskstream")) {
4095 if (rename_playlist) {
4096 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4098 (*i)->add_property (X_("name"), name);
4104 boost::shared_ptr<Send>
4105 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4107 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4109 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4110 boost::shared_ptr<InternalSend> send;
4112 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4113 if (send->target_route() == target) {
4119 return boost::shared_ptr<Send>();
4122 /** @param c Audio channel index.
4123 * @param yn true to invert phase, otherwise false.
4126 Route::set_phase_invert (uint32_t c, bool yn)
4128 if (_phase_invert[c] != yn) {
4129 _phase_invert[c] = yn;
4130 phase_invert_changed (); /* EMIT SIGNAL */
4131 _phase_control->Changed(); /* EMIT SIGNAL */
4132 _session.set_dirty ();
4137 Route::set_phase_invert (boost::dynamic_bitset<> p)
4139 if (_phase_invert != p) {
4141 phase_invert_changed (); /* EMIT SIGNAL */
4142 _session.set_dirty ();
4147 Route::phase_invert (uint32_t c) const
4149 return _phase_invert[c];
4152 boost::dynamic_bitset<>
4153 Route::phase_invert () const
4155 return _phase_invert;
4159 Route::set_denormal_protection (bool yn)
4161 if (_denormal_protection != yn) {
4162 _denormal_protection = yn;
4163 denormal_protection_changed (); /* EMIT SIGNAL */
4168 Route::denormal_protection () const
4170 return _denormal_protection;
4174 Route::set_active (bool yn, void* src)
4176 if (_session.transport_rolling()) {
4180 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4181 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4185 if (_active != yn) {
4187 _input->set_active (yn);
4188 _output->set_active (yn);
4189 active_changed (); // EMIT SIGNAL
4190 _session.set_dirty ();
4194 boost::shared_ptr<Pannable>
4195 Route::pannable() const
4200 boost::shared_ptr<Panner>
4201 Route::panner() const
4204 return _main_outs->panner_shell()->panner();
4207 boost::shared_ptr<PannerShell>
4208 Route::panner_shell() const
4210 return _main_outs->panner_shell();
4213 boost::shared_ptr<GainControl>
4214 Route::gain_control() const
4216 return _gain_control;
4219 boost::shared_ptr<GainControl>
4220 Route::trim_control() const
4222 return _trim_control;
4225 boost::shared_ptr<Route::PhaseControllable>
4226 Route::phase_control() const
4228 if (phase_invert().size()) {
4229 return _phase_control;
4231 return boost::shared_ptr<PhaseControllable>();
4235 boost::shared_ptr<AutomationControl>
4236 Route::get_control (const Evoral::Parameter& param)
4238 /* either we own the control or .... */
4240 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4244 /* maybe one of our processors does or ... */
4246 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4247 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4248 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4256 /* nobody does so we'll make a new one */
4258 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4265 boost::shared_ptr<Processor>
4266 Route::nth_plugin (uint32_t n) const
4268 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4269 ProcessorList::const_iterator i;
4271 for (i = _processors.begin(); i != _processors.end(); ++i) {
4272 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4279 return boost::shared_ptr<Processor> ();
4282 boost::shared_ptr<Processor>
4283 Route::nth_send (uint32_t n) const
4285 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4286 ProcessorList::const_iterator i;
4288 for (i = _processors.begin(); i != _processors.end(); ++i) {
4289 if (boost::dynamic_pointer_cast<Send> (*i)) {
4291 if ((*i)->name().find (_("Monitor")) == 0) {
4292 /* send to monitor section is not considered
4293 to be an accessible send.
4304 return boost::shared_ptr<Processor> ();
4308 Route::has_io_processor_named (const string& name)
4310 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4311 ProcessorList::iterator i;
4313 for (i = _processors.begin(); i != _processors.end(); ++i) {
4314 if (boost::dynamic_pointer_cast<Send> (*i) ||
4315 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4316 if ((*i)->name() == name) {
4325 MuteMaster::MutePoint
4326 Route::mute_points () const
4328 return _mute_master->mute_points ();
4332 Route::set_processor_positions ()
4334 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4336 bool had_amp = false;
4337 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4338 (*i)->set_pre_fader (!had_amp);
4345 /** Called when there is a proposed change to the input port count */
4347 Route::input_port_count_changing (ChanCount to)
4349 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4351 /* The processors cannot be configured with the new input arrangement, so
4357 /* The change is ok */
4361 /** Called when there is a proposed change to the output port count */
4363 Route::output_port_count_changing (ChanCount to)
4365 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4366 if (processor_out_streams.get(*t) > to.get(*t)) {
4370 /* The change is ok */
4375 Route::unknown_processors () const
4379 if (_session.get_disable_all_loaded_plugins ()) {
4380 // Do not list "missing plugins" if they are explicitly disabled
4384 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4385 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4386 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4387 p.push_back ((*i)->name ());
4396 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4398 /* we assume that all our input ports feed all our output ports. its not
4399 universally true, but the alternative is way too corner-case to worry about.
4402 LatencyRange all_connections;
4405 all_connections.min = 0;
4406 all_connections.max = 0;
4408 all_connections.min = ~((pframes_t) 0);
4409 all_connections.max = 0;
4411 /* iterate over all "from" ports and determine the latency range for all of their
4412 connections to the "outside" (outside of this Route).
4415 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4419 p->get_connected_latency_range (range, playback);
4421 all_connections.min = min (all_connections.min, range.min);
4422 all_connections.max = max (all_connections.max, range.max);
4426 /* set the "from" port latencies to the max/min range of all their connections */
4428 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4429 p->set_private_latency_range (all_connections, playback);
4432 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4434 all_connections.min += our_latency;
4435 all_connections.max += our_latency;
4437 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4438 p->set_private_latency_range (all_connections, playback);
4441 return all_connections.max;
4445 Route::set_private_port_latencies (bool playback) const
4447 framecnt_t own_latency = 0;
4449 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4450 OR LATENCY CALLBACK.
4452 This is called (early) from the latency callback. It computes the REAL
4453 latency associated with each port and stores the result as the "private"
4454 latency of the port. A later call to Route::set_public_port_latencies()
4455 sets all ports to the same value to reflect the fact that we do latency
4456 compensation and so all signals are delayed by the same amount as they
4457 flow through ardour.
4460 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4461 if ((*i)->active ()) {
4462 own_latency += (*i)->signal_latency ();
4467 /* playback: propagate latency from "outside the route" to outputs to inputs */
4468 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4470 /* capture: propagate latency from "outside the route" to inputs to outputs */
4471 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4476 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4478 /* this is called to set the JACK-visible port latencies, which take
4479 latency compensation into account.
4488 const PortSet& ports (_input->ports());
4489 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4490 p->set_public_latency_range (range, playback);
4495 const PortSet& ports (_output->ports());
4496 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4497 p->set_public_latency_range (range, playback);
4502 /** Put the invisible processors in the right place in _processors.
4503 * Must be called with a writer lock on _processor_lock held.
4506 __attribute__((annotate("realtime")))
4509 Route::setup_invisible_processors ()
4512 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4513 assert (!lm.locked ());
4517 /* too early to be doing this stuff */
4521 /* we'll build this new list here and then use it
4523 * TODO put the ProcessorList is on the stack for RT-safety.
4526 ProcessorList new_processors;
4528 /* find visible processors */
4530 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4531 if ((*i)->display_to_user ()) {
4532 new_processors.push_back (*i);
4538 ProcessorList::iterator amp = new_processors.begin ();
4539 while (amp != new_processors.end() && *amp != _amp) {
4543 assert (amp != new_processors.end ());
4545 /* and the processor after the amp */
4547 ProcessorList::iterator after_amp = amp;
4553 switch (_meter_point) {
4555 assert (!_meter->display_to_user ());
4556 new_processors.push_front (_meter);
4559 assert (!_meter->display_to_user ());
4560 new_processors.insert (amp, _meter);
4562 case MeterPostFader:
4563 /* do nothing here */
4566 /* do nothing here */
4569 /* the meter is visible, so we don't touch it here */
4576 assert (_main_outs);
4577 assert (!_main_outs->display_to_user ());
4578 new_processors.push_back (_main_outs);
4580 /* iterator for the main outs */
4582 ProcessorList::iterator main = new_processors.end();
4585 /* OUTPUT METERING */
4587 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4588 assert (!_meter->display_to_user ());
4590 /* add the processor just before or just after the main outs */
4592 ProcessorList::iterator meter_point = main;
4594 if (_meter_point == MeterOutput) {
4597 new_processors.insert (meter_point, _meter);
4602 if (_monitor_send && !is_monitor ()) {
4603 assert (!_monitor_send->display_to_user ());
4604 switch (Config->get_listen_position ()) {
4605 case PreFaderListen:
4606 switch (Config->get_pfl_position ()) {
4607 case PFLFromBeforeProcessors:
4608 new_processors.push_front (_monitor_send);
4610 case PFLFromAfterProcessors:
4611 new_processors.insert (amp, _monitor_send);
4614 _monitor_send->set_can_pan (false);
4616 case AfterFaderListen:
4617 switch (Config->get_afl_position ()) {
4618 case AFLFromBeforeProcessors:
4619 new_processors.insert (after_amp, _monitor_send);
4621 case AFLFromAfterProcessors:
4622 new_processors.insert (new_processors.end(), _monitor_send);
4625 _monitor_send->set_can_pan (true);
4630 #if 0 // not used - just yet
4631 if (!is_master() && !is_monitor() && !is_auditioner()) {
4632 new_processors.push_front (_delayline);
4636 /* MONITOR CONTROL */
4638 if (_monitor_control && is_monitor ()) {
4639 assert (!_monitor_control->display_to_user ());
4640 new_processors.insert (amp, _monitor_control);
4643 /* INTERNAL RETURN */
4645 /* doing this here means that any monitor control will come just after
4650 assert (!_intreturn->display_to_user ());
4651 new_processors.push_front (_intreturn);
4654 if (_trim && _trim->active()) {
4655 assert (!_trim->display_to_user ());
4656 new_processors.push_front (_trim);
4658 /* EXPORT PROCESSOR */
4660 if (_capturing_processor) {
4661 assert (!_capturing_processor->display_to_user ());
4662 new_processors.push_front (_capturing_processor);
4665 _processors = new_processors;
4667 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4668 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4673 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4674 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4675 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4682 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4683 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4687 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4688 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4695 /** If the meter point is `Custom', make a note of where the meter is.
4696 * This is so that if the meter point is subsequently set to something else,
4697 * and then back to custom, we can put the meter back where it was last time
4698 * custom was enabled.
4700 * Must be called with the _processor_lock held.
4703 Route::maybe_note_meter_position ()
4705 if (_meter_point != MeterCustom) {
4709 _custom_meter_position_noted = true;
4710 /* custom meter points range from after trim to before panner/main_outs
4711 * this is a limitation by the current processor UI
4713 bool seen_trim = false;
4714 _processor_after_last_custom_meter.reset();
4715 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4716 if ((*i) == _trim) {
4719 if ((*i) == _main_outs) {
4720 _processor_after_last_custom_meter = *i;
4723 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4725 _processor_after_last_custom_meter = _trim;
4727 ProcessorList::iterator j = i;
4729 assert(j != _processors.end ()); // main_outs should be before
4730 _processor_after_last_custom_meter = *j;
4735 assert(_processor_after_last_custom_meter.lock());
4738 boost::shared_ptr<Processor>
4739 Route::processor_by_id (PBD::ID id) const
4741 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4742 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4743 if ((*i)->id() == id) {
4748 return boost::shared_ptr<Processor> ();
4751 /** @return the monitoring state, or in other words what data we are pushing
4752 * into the route (data from the inputs, data from disk or silence)
4755 Route::monitoring_state () const
4757 return MonitoringInput;
4760 /** @return what we should be metering; either the data coming from the input
4761 * IO or the data that is flowing through the route.
4764 Route::metering_state () const
4766 return MeteringRoute;
4770 Route::has_external_redirects () const
4772 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4774 /* ignore inactive processors and obviously ignore the main
4775 * outs since everything has them and we don't care.
4778 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4786 boost::shared_ptr<Processor>
4787 Route::the_instrument () const
4789 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4790 return the_instrument_unlocked ();
4793 boost::shared_ptr<Processor>
4794 Route::the_instrument_unlocked () const
4796 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4797 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4798 if ((*i)->input_streams().n_midi() > 0 &&
4799 (*i)->output_streams().n_audio() > 0) {
4804 return boost::shared_ptr<Processor>();
4810 Route::non_realtime_locate (framepos_t pos)
4813 _pannable->transport_located (pos);
4816 if (_delayline.get()) {
4817 _delayline.get()->flush();
4821 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4822 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4824 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4825 (*i)->transport_located (pos);
4828 _roll_delay = _initial_delay;
4832 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4839 * We don't currently mix MIDI input together, so we don't need the
4840 * complex logic of the audio case.
4843 n_buffers = bufs.count().n_midi ();
4845 for (i = 0; i < n_buffers; ++i) {
4847 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4848 MidiBuffer& buf (bufs.get_midi (i));
4851 buf.copy (source_port->get_midi_buffer(nframes));
4853 buf.silence (nframes);
4859 n_buffers = bufs.count().n_audio();
4861 size_t n_ports = io->n_ports().n_audio();
4862 float scaling = 1.0f;
4864 if (n_ports > n_buffers) {
4865 scaling = ((float) n_buffers) / n_ports;
4868 for (i = 0; i < n_ports; ++i) {
4870 /* if there are more ports than buffers, map them onto buffers
4871 * in a round-robin fashion
4874 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4875 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4878 if (i < n_buffers) {
4880 /* first time through just copy a channel into
4884 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4886 if (scaling != 1.0f) {
4887 buf.apply_gain (scaling, nframes);
4892 /* on subsequent times around, merge data from
4893 * the port with what is already there
4896 if (scaling != 1.0f) {
4897 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4899 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4904 /* silence any remaining buffers */
4906 for (; i < n_buffers; ++i) {
4907 AudioBuffer& buf (bufs.get_audio (i));
4908 buf.silence (nframes);
4911 /* establish the initial setup of the buffer set, reflecting what was
4912 copied into it. unless, of course, we are the auditioner, in which
4913 case nothing was fed into it from the inputs at all.
4916 if (!is_auditioner()) {
4917 bufs.set_count (io->n_ports());
4921 boost::shared_ptr<AutomationControl>
4922 Route::pan_azimuth_control() const
4925 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4927 return boost::shared_ptr<AutomationControl>();
4929 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
4930 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4932 if (!_pannable || !panner()) {
4933 return boost::shared_ptr<AutomationControl>();
4935 return _pannable->pan_azimuth_control;
4939 boost::shared_ptr<AutomationControl>
4940 Route::pan_elevation_control() const
4942 if (Profile->get_mixbus() || !_pannable || !panner()) {
4943 return boost::shared_ptr<AutomationControl>();
4946 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4948 if (c.find (PanElevationAutomation) != c.end()) {
4949 return _pannable->pan_elevation_control;
4951 return boost::shared_ptr<AutomationControl>();
4954 boost::shared_ptr<AutomationControl>
4955 Route::pan_width_control() const
4957 if (Profile->get_mixbus() || !_pannable || !panner()) {
4958 return boost::shared_ptr<AutomationControl>();
4961 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4963 if (c.find (PanWidthAutomation) != c.end()) {
4964 return _pannable->pan_width_control;
4966 return boost::shared_ptr<AutomationControl>();
4969 boost::shared_ptr<AutomationControl>
4970 Route::pan_frontback_control() const
4972 if (Profile->get_mixbus() || !_pannable || !panner()) {
4973 return boost::shared_ptr<AutomationControl>();
4976 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4978 if (c.find (PanFrontBackAutomation) != c.end()) {
4979 return _pannable->pan_frontback_control;
4981 return boost::shared_ptr<AutomationControl>();
4984 boost::shared_ptr<AutomationControl>
4985 Route::pan_lfe_control() const
4987 if (Profile->get_mixbus() || !_pannable || !panner()) {
4988 return boost::shared_ptr<AutomationControl>();
4991 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4993 if (c.find (PanLFEAutomation) != c.end()) {
4994 return _pannable->pan_lfe_control;
4996 return boost::shared_ptr<AutomationControl>();
5001 Route::eq_band_cnt () const
5003 if (Profile->get_mixbus()) {
5006 /* Ardour has no well-known EQ object */
5011 boost::shared_ptr<AutomationControl>
5012 Route::eq_gain_controllable (uint32_t band) const
5015 boost::shared_ptr<PluginInsert> eq = ch_eq();
5018 return boost::shared_ptr<AutomationControl>();
5021 uint32_t port_number;
5024 if (is_master() || mixbus()) {
5031 if (is_master() || mixbus()) {
5038 if (is_master() || mixbus()) {
5045 return boost::shared_ptr<AutomationControl>();
5048 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5050 return boost::shared_ptr<AutomationControl>();
5053 boost::shared_ptr<AutomationControl>
5054 Route::eq_freq_controllable (uint32_t band) const
5058 if (mixbus() || is_master()) {
5059 /* no frequency controls for mixbusses or master */
5060 return boost::shared_ptr<AutomationControl>();
5063 boost::shared_ptr<PluginInsert> eq = ch_eq();
5066 return boost::shared_ptr<AutomationControl>();
5069 uint32_t port_number;
5081 return boost::shared_ptr<AutomationControl>();
5084 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5086 return boost::shared_ptr<AutomationControl>();
5090 boost::shared_ptr<AutomationControl>
5091 Route::eq_q_controllable (uint32_t band) const
5093 return boost::shared_ptr<AutomationControl>();
5096 boost::shared_ptr<AutomationControl>
5097 Route::eq_shape_controllable (uint32_t band) const
5099 return boost::shared_ptr<AutomationControl>();
5102 boost::shared_ptr<AutomationControl>
5103 Route::eq_enable_controllable () const
5106 boost::shared_ptr<PluginInsert> eq = ch_eq();
5109 return boost::shared_ptr<AutomationControl>();
5112 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5114 return boost::shared_ptr<AutomationControl>();
5118 boost::shared_ptr<AutomationControl>
5119 Route::eq_hpf_controllable () const
5122 boost::shared_ptr<PluginInsert> eq = ch_eq();
5125 return boost::shared_ptr<AutomationControl>();
5128 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5130 return boost::shared_ptr<AutomationControl>();
5135 Route::eq_band_name (uint32_t band) const
5137 if (Profile->get_mixbus()) {
5153 boost::shared_ptr<AutomationControl>
5154 Route::comp_enable_controllable () const
5157 boost::shared_ptr<PluginInsert> comp = ch_comp();
5160 return boost::shared_ptr<AutomationControl>();
5163 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5165 return boost::shared_ptr<AutomationControl>();
5168 boost::shared_ptr<AutomationControl>
5169 Route::comp_threshold_controllable () const
5172 boost::shared_ptr<PluginInsert> comp = ch_comp();
5175 return boost::shared_ptr<AutomationControl>();
5178 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5181 return boost::shared_ptr<AutomationControl>();
5184 boost::shared_ptr<AutomationControl>
5185 Route::comp_speed_controllable () const
5188 boost::shared_ptr<PluginInsert> comp = ch_comp();
5191 return boost::shared_ptr<AutomationControl>();
5194 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5196 return boost::shared_ptr<AutomationControl>();
5199 boost::shared_ptr<AutomationControl>
5200 Route::comp_mode_controllable () const
5203 boost::shared_ptr<PluginInsert> comp = ch_comp();
5206 return boost::shared_ptr<AutomationControl>();
5209 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5211 return boost::shared_ptr<AutomationControl>();
5214 boost::shared_ptr<AutomationControl>
5215 Route::comp_makeup_controllable () const
5218 boost::shared_ptr<PluginInsert> comp = ch_comp();
5221 return boost::shared_ptr<AutomationControl>();
5224 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5226 return boost::shared_ptr<AutomationControl>();
5229 boost::shared_ptr<AutomationControl>
5230 Route::comp_redux_controllable () const
5233 boost::shared_ptr<PluginInsert> comp = ch_comp();
5236 return boost::shared_ptr<AutomationControl>();
5239 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5241 return boost::shared_ptr<AutomationControl>();
5246 Route::comp_mode_name (uint32_t mode) const
5251 return _("Leveler");
5253 return _("Compressor");
5255 return _("Limiter");
5257 return mixbus() ? _("Sidechain") : _("Limiter");
5267 Route::comp_speed_name (uint32_t mode) const
5285 boost::shared_ptr<AutomationControl>
5286 Route::send_level_controllable (uint32_t n) const
5289 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5291 return boost::shared_ptr<AutomationControl>();
5296 return boost::shared_ptr<AutomationControl>();
5299 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5300 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5302 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5304 return boost::shared_ptr<AutomationControl>();
5306 return s->gain_control ();
5310 boost::shared_ptr<AutomationControl>
5311 Route::send_enable_controllable (uint32_t n) const
5314 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5316 return boost::shared_ptr<AutomationControl>();
5321 return boost::shared_ptr<AutomationControl>();
5324 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5325 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5327 /* although Ardour sends have enable/disable as part of the Processor
5328 API, it is not exposed as a controllable.
5330 XXX: we should fix this.
5332 return boost::shared_ptr<AutomationControl>();
5337 Route::send_name (uint32_t n) const
5343 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5347 boost::shared_ptr<Processor> p = nth_send (n);
5356 boost::shared_ptr<AutomationControl>
5357 Route::master_send_enable_controllable () const
5360 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5362 return boost::shared_ptr<AutomationControl>();
5364 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5366 return boost::shared_ptr<AutomationControl>();