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/internal_return.h"
50 #include "ardour/internal_send.h"
51 #include "ardour/meter.h"
52 #include "ardour/delayline.h"
53 #include "ardour/midi_buffer.h"
54 #include "ardour/midi_port.h"
55 #include "ardour/monitor_processor.h"
56 #include "ardour/pannable.h"
57 #include "ardour/panner.h"
58 #include "ardour/panner_shell.h"
59 #include "ardour/plugin_insert.h"
60 #include "ardour/port.h"
61 #include "ardour/port_insert.h"
62 #include "ardour/processor.h"
63 #include "ardour/profile.h"
64 #include "ardour/route.h"
65 #include "ardour/route_group.h"
66 #include "ardour/send.h"
67 #include "ardour/session.h"
68 #include "ardour/unknown_processor.h"
69 #include "ardour/utils.h"
74 using namespace ARDOUR;
77 PBD::Signal0<void> Route::SyncOrderKeys;
78 PBD::Signal0<void> Route::RemoteControlIDChange;
80 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
81 : SessionObject (sess, name)
83 , GraphNode (sess._process_graph)
86 , _signal_latency_at_amp_position (0)
87 , _signal_latency_at_trim_position (0)
90 , _pending_process_reorder (0)
91 , _pending_signals (0)
93 , _pending_declick (true)
94 , _meter_point (MeterPostFader)
95 , _pending_meter_point (MeterPostFader)
96 , _meter_type (MeterPeak)
98 , _soloed_by_others_upstream (0)
99 , _soloed_by_others_downstream (0)
100 , _solo_isolated (false)
101 , _solo_isolated_by_upstream (0)
102 , _denormal_protection (false)
105 , _declickable (false)
106 , _mute_master (new MuteMaster (sess, name))
107 , _have_internal_generator (false)
109 , _default_type (default_type)
111 , _has_order_key (false)
112 , _remote_control_id (0)
114 , _in_configure_processors (false)
115 , _initial_io_setup (false)
116 , _custom_meter_position_noted (false)
118 processor_max_streams.reset();
124 /* set default meter type */
126 _meter_type = Config->get_meter_type_master ();
128 else if (dynamic_cast<Track*>(this)) {
129 _meter_type = Config->get_meter_type_track ();
131 _meter_type = Config->get_meter_type_bus ();
134 /* add standard controls */
136 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
137 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
138 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
140 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
141 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
142 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
144 add_control (_solo_control);
145 add_control (_mute_control);
146 add_control (_phase_control);
150 if (!(_flags & Route::MonitorOut)) {
151 _pannable.reset (new Pannable (_session));
154 /* input and output objects */
156 _input.reset (new IO (_session, _name, IO::Input, _default_type));
157 _output.reset (new IO (_session, _name, IO::Output, _default_type));
159 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
160 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
162 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
163 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
165 #if 0 // not used - just yet
166 if (!is_master() && !is_monitor() && !is_auditioner()) {
167 _delayline.reset (new DelayLine (_session, _name));
168 add_processor (_delayline, PreFader);
172 /* add amp processor */
174 _amp.reset (new Amp (_session));
175 add_processor (_amp, PostFader);
178 _amp->set_display_name ("Monitor");
182 _trim.reset (new Amp (_session, "trim"));
183 _trim->set_display_to_user (false);
185 if (dynamic_cast<AudioTrack*>(this)) {
186 /* we can't do this in the AudioTrack's constructor
187 * because _trim does not exit then
191 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
196 /* create standard processors: meter, main outs, monitor out;
197 they will be added to _processors by setup_invisible_processors ()
200 _meter.reset (new PeakMeter (_session, _name));
201 _meter->set_owner (this);
202 _meter->set_display_to_user (false);
205 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
206 _main_outs->activate ();
209 /* where we listen to tracks */
210 _intreturn.reset (new InternalReturn (_session));
211 _intreturn->activate ();
213 /* the thing that provides proper control over a control/monitor/listen bus
214 (such as per-channel cut, dim, solo, invert, etc).
216 _monitor_control.reset (new MonitorProcessor (_session));
217 _monitor_control->activate ();
220 if (is_master() || is_monitor() || is_auditioner()) {
221 _mute_master->set_solo_ignore (true);
224 /* now that we have _meter, its safe to connect to this */
227 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
228 configure_processors (0);
236 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
238 /* do this early so that we don't get incoming signals as we are going through destruction
243 /* don't use clear_processors here, as it depends on the session which may
244 be half-destroyed by now
247 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
248 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
249 (*i)->drop_references ();
252 _processors.clear ();
256 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
258 if (Config->get_remote_model() != UserOrdered) {
262 set_remote_control_id_internal (id, notify_class_listeners);
266 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
268 /* force IDs for master/monitor busses and prevent
269 any other route from accidentally getting these IDs
270 (i.e. legacy sessions)
273 if (is_master() && id != MasterBusRemoteControlID) {
274 id = MasterBusRemoteControlID;
277 if (is_monitor() && id != MonitorBusRemoteControlID) {
278 id = MonitorBusRemoteControlID;
285 /* don't allow it to collide */
287 if (!is_master () && !is_monitor() &&
288 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
289 id += MonitorBusRemoteControlID;
292 if (id != remote_control_id()) {
293 _remote_control_id = id;
294 RemoteControlIDChanged ();
296 if (notify_class_listeners) {
297 RemoteControlIDChange ();
303 Route::remote_control_id() const
306 return MasterBusRemoteControlID;
310 return MonitorBusRemoteControlID;
313 return _remote_control_id;
317 Route::has_order_key () const
319 return _has_order_key;
323 Route::order_key () const
329 Route::set_remote_control_id_explicit (uint32_t rid)
331 if (is_master() || is_monitor() || is_auditioner()) {
332 /* hard-coded remote IDs, or no remote ID */
336 if (_remote_control_id != rid) {
337 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
338 _remote_control_id = rid;
339 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
342 /* don't emit the class-level RID signal RemoteControlIDChange here,
343 leave that to the entity that changed the order key, so that we
344 don't get lots of emissions for no good reasons (e.g. when changing
345 all route order keys).
347 See Session::sync_remote_id_from_order_keys() for the (primary|only)
348 spot where that is emitted.
353 Route::set_order_key (uint32_t n)
355 _has_order_key = true;
357 if (_order_key == n) {
363 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
364 name(), order_key ()));
366 _session.set_dirty ();
370 Route::ensure_track_or_route_name(string name, Session &session)
372 string newname = name;
374 while (!session.io_name_is_legal (newname)) {
375 newname = bump_name_once (newname, ' ');
382 Route::inc_gain (gain_t fraction, void *src)
384 _amp->inc_gain (fraction, src);
388 Route::set_gain (gain_t val, void *src)
390 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
392 if (_route_group->is_relative()) {
394 gain_t usable_gain = _amp->gain();
395 if (usable_gain < 0.000001f) {
396 usable_gain = 0.000001f;
400 if (delta < 0.000001f) {
404 delta -= usable_gain;
409 gain_t factor = delta / usable_gain;
412 factor = _route_group->get_max_factor(factor);
413 if (factor == 0.0f) {
414 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
418 factor = _route_group->get_min_factor(factor);
419 if (factor == 0.0f) {
420 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
425 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
429 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
435 if (val == _amp->gain()) {
439 _amp->set_gain (val, src);
443 Route::inc_trim (gain_t fraction, void *src)
445 _trim->inc_gain (fraction, src);
449 Route::set_trim (gain_t val, void * /* src */)
451 // TODO route group, see set_gain()
452 _trim->set_gain (val, 0);
456 Route::maybe_declick (BufferSet&, framecnt_t, int)
458 /* this is the "bus" implementation and they never declick.
463 /** Process this route for one (sub) cycle (process thread)
465 * @param bufs Scratch buffers to use for the signal path
466 * @param start_frame Initial transport frame
467 * @param end_frame Final transport frame
468 * @param nframes Number of frames to output (to ports)
470 * Note that (end_frame - start_frame) may not be equal to nframes when the
471 * transport speed isn't 1.0 (eg varispeed).
474 Route::process_output_buffers (BufferSet& bufs,
475 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
476 int declick, bool gain_automation_ok)
478 /* Caller must hold process lock */
479 assert (!AudioEngine::instance()->process_lock().trylock());
481 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
483 // can this actually happen? functions calling process_output_buffers()
484 // already take a reader-lock.
485 bufs.silence (nframes, 0);
489 /* figure out if we're going to use gain automation */
490 if (gain_automation_ok) {
491 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
492 _amp->setup_gain_automation (
493 start_frame + _signal_latency_at_amp_position,
494 end_frame + _signal_latency_at_amp_position,
497 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
498 _trim->setup_gain_automation (
499 start_frame + _signal_latency_at_trim_position,
500 end_frame + _signal_latency_at_trim_position,
503 _amp->apply_gain_automation (false);
504 _trim->apply_gain_automation (false);
507 /* Tell main outs what to do about monitoring. We do this so that
508 on a transition between monitoring states we get a de-clicking gain
509 change in the _main_outs delivery, if config.get_use_monitor_fades()
512 We override this in the case where we have an internal generator.
514 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
516 _main_outs->no_outs_cuz_we_no_monitor (silence);
518 /* -------------------------------------------------------------------------------------------
519 GLOBAL DECLICK (for transport changes etc.)
520 ----------------------------------------------------------------------------------------- */
522 maybe_declick (bufs, nframes, declick);
523 _pending_declick = 0;
525 /* -------------------------------------------------------------------------------------------
526 DENORMAL CONTROL/PHASE INVERT
527 ----------------------------------------------------------------------------------------- */
529 if (_phase_invert.any ()) {
533 if (_denormal_protection || Config->get_denormal_protection()) {
535 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
536 Sample* const sp = i->data();
538 if (_phase_invert[chn]) {
539 for (pframes_t nx = 0; nx < nframes; ++nx) {
544 for (pframes_t nx = 0; nx < nframes; ++nx) {
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) {
565 if (_denormal_protection || Config->get_denormal_protection()) {
567 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
568 Sample* const sp = i->data();
569 for (pframes_t nx = 0; nx < nframes; ++nx) {
577 /* -------------------------------------------------------------------------------------------
579 ----------------------------------------------------------------------------------------- */
581 /* set this to be true if the meter will already have been ::run() earlier */
582 bool const meter_already_run = metering_state() == MeteringInput;
584 framecnt_t latency = 0;
586 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
588 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
589 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
594 /* if it has any inputs, make sure they match */
595 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
596 if (bufs.count() != (*i)->input_streams()) {
598 DEBUG::Processors, string_compose (
599 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
600 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
607 /* should we NOT run plugins here if the route is inactive?
608 do we catch route != active somewhere higher?
611 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
612 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
615 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
616 bufs.set_count ((*i)->output_streams());
618 if ((*i)->active ()) {
619 latency += (*i)->signal_latency ();
625 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
626 boost::shared_ptr<Processor> endpoint,
627 bool include_endpoint, bool for_export, bool for_freeze)
629 /* If no processing is required, there's no need to go any further. */
630 if (!endpoint && !include_endpoint) {
634 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
635 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
636 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
638 /* trim is always at the top, for bounce no latency compensation is needed */
639 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
640 _trim->setup_gain_automation (start, start + nframes, nframes);
643 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
645 if (!include_endpoint && (*i) == endpoint) {
649 /* if we're not exporting, stop processing if we come across a routing processor. */
650 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
653 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
657 /* don't run any processors that does routing.
658 * oh, and don't bother with the peak meter either.
660 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
661 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
662 buffers.set_count ((*i)->output_streams());
663 latency += (*i)->signal_latency ();
666 if ((*i) == endpoint) {
673 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
674 bool include_endpoint, bool for_export, bool for_freeze) const
676 framecnt_t latency = 0;
677 if (!endpoint && !include_endpoint) {
681 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
682 if (!include_endpoint && (*i) == endpoint) {
685 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
688 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
691 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
692 latency += (*i)->signal_latency ();
694 if ((*i) == endpoint) {
702 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
703 bool include_endpoint, bool for_export, bool for_freeze) const
705 if (!endpoint && !include_endpoint) {
709 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
710 if (!include_endpoint && (*i) == endpoint) {
713 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
716 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
719 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
720 cc = (*i)->output_streams();
722 if ((*i) == endpoint) {
730 Route::n_process_buffers ()
732 return max (_input->n_ports(), processor_max_streams);
736 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
738 assert (is_monitor());
739 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
740 fill_buffers_with_input (bufs, _input, nframes);
741 passthru (bufs, start_frame, end_frame, nframes, declick);
745 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
749 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
751 /* control/monitor bus ignores input ports when something is
752 feeding the listen "stream". data will "arrive" into the
753 route from the intreturn processor element.
756 bufs.silence (nframes, 0);
759 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
760 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
764 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
766 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
768 bufs.set_count (_input->n_ports());
769 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
770 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
774 Route::set_listen (bool yn, void* src, bool group_override)
780 bool group_active = _route_group && _route_group->is_active() && _route_group->is_solo();
781 if (group_override && _route_group) {
782 group_active = !group_active;
785 if (_route_group && src != _route_group && group_active) {
786 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group, group_override));
791 if (yn != _monitor_send->active()) {
793 _monitor_send->activate ();
794 _mute_master->set_soloed_by_self (true);
796 _monitor_send->deactivate ();
797 _mute_master->set_soloed_by_self (false);
799 _mute_master->set_soloed_by_others (false);
801 listen_changed (src, group_override); /* EMIT SIGNAL */
807 Route::listening_via_monitor () const
810 return _monitor_send->active ();
817 Route::set_solo_safe (bool yn, void *src)
819 if (_solo_safe != yn) {
821 solo_safe_changed (src);
826 Route::solo_safe() const
832 Route::clear_all_solo_state ()
834 // ideally this function will never do anything, it only exists to forestall Murphy
835 bool emit_changed = false;
838 // these are really debug messages, but of possible interest.
840 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
842 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
843 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
844 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
848 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
849 // if self-soled, set_solo() will do signal emission
853 _soloed_by_others_upstream = 0;
854 _soloed_by_others_downstream = 0;
857 PBD::Unwinder<bool> uw (_solo_safe, false);
858 set_solo (false, this);
862 set_mute_master_solo ();
863 solo_changed (false, this, false); /* EMIT SIGNAL */
868 Route::set_solo (bool yn, void *src, bool group_override)
871 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
875 if (is_master() || is_monitor() || is_auditioner()) {
876 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
880 bool group_active = _route_group && _route_group->is_active() && _route_group->is_solo();
881 if (group_override && _route_group) {
882 group_active = !group_active;
884 if (_route_group && src != _route_group && group_active) {
885 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group, group_override));
889 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
890 name(), yn, src, (src == _route_group), self_soloed()));
892 if (self_soloed() != yn) {
894 solo_changed (true, src, group_override); /* EMIT SIGNAL */
895 _solo_control->Changed (); /* EMIT SIGNAL */
898 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
900 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
901 Config->get_solo_mute_overrride().
904 if (yn && Profile->get_trx()) {
905 set_mute (false, src);
910 Route::set_self_solo (bool yn)
912 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
914 set_mute_master_solo ();
918 Route::mod_solo_by_others_upstream (int32_t delta)
920 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
921 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
923 uint32_t old_sbu = _soloed_by_others_upstream;
926 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
927 _soloed_by_others_upstream += delta;
929 _soloed_by_others_upstream = 0;
932 _soloed_by_others_upstream += delta;
935 DEBUG_TRACE (DEBUG::Solo, string_compose (
936 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
937 name(), delta, _soloed_by_others_upstream, old_sbu,
938 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
940 /* push the inverse solo change to everything that feeds us.
942 This is important for solo-within-group. When we solo 1 track out of N that
943 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
944 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
945 tracks that feed it. This will silence them if they were audible because
946 of a bus solo, but the newly soloed track will still be audible (because
949 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
953 if ((_self_solo || _soloed_by_others_downstream) &&
954 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
955 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
957 if (delta > 0 || !Config->get_exclusive_solo()) {
958 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
959 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
963 boost::shared_ptr<Route> sr = i->r.lock();
965 sr->mod_solo_by_others_downstream (-delta);
971 set_mute_master_solo ();
972 solo_changed (false, this, false); /* EMIT SIGNAL */
976 Route::mod_solo_by_others_downstream (int32_t delta)
978 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
979 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
982 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
983 _soloed_by_others_downstream += delta;
985 _soloed_by_others_downstream = 0;
988 _soloed_by_others_downstream += delta;
991 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
993 set_mute_master_solo ();
994 solo_changed (false, this, false); /* EMIT SIGNAL */
998 Route::set_mute_master_solo ()
1000 _mute_master->set_soloed_by_self (self_soloed());
1001 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1005 Route::mod_solo_isolated_by_upstream (bool yn, void* src)
1007 bool old = solo_isolated ();
1008 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1009 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1012 if (_solo_isolated_by_upstream >= 1) {
1013 _solo_isolated_by_upstream--;
1015 _solo_isolated_by_upstream = 0;
1018 _solo_isolated_by_upstream++;
1021 if (solo_isolated() != old) {
1022 /* solo isolated status changed */
1023 _mute_master->set_solo_ignore (solo_isolated());
1024 solo_isolated_changed (src); /* EMIT SIGNAL */
1029 Route::set_solo_isolated (bool yn, void *src)
1031 if (is_master() || is_monitor() || is_auditioner()) {
1035 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
1036 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
1040 bool changed = false;
1043 if (_solo_isolated == false) {
1044 _mute_master->set_solo_ignore (true);
1047 _solo_isolated = true;
1049 if (_solo_isolated == true) {
1050 _solo_isolated = false;
1051 _mute_master->set_solo_ignore (false);
1061 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1063 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1064 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1066 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1071 bool does_feed = feeds (*i, &sends_only);
1073 if (does_feed && !sends_only) {
1074 (*i)->mod_solo_isolated_by_upstream (yn, src);
1078 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1080 solo_isolated_changed (src); /* EMIT SIGNAL */
1084 Route::solo_isolated () const
1086 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1090 Route::set_mute_points (MuteMaster::MutePoint mp)
1092 _mute_master->set_mute_points (mp);
1093 mute_points_changed (); /* EMIT SIGNAL */
1095 if (_mute_master->muted_by_self()) {
1096 mute_changed (this); /* EMIT SIGNAL */
1097 _mute_control->Changed (); /* EMIT SIGNAL */
1102 Route::set_mute (bool yn, void *src)
1104 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
1105 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
1109 if (muted() != yn) {
1110 _mute_master->set_muted_by_self (yn);
1111 /* allow any derived classes to respond to the mute change
1112 before anybody else knows about it.
1115 /* tell everyone else */
1116 mute_changed (src); /* EMIT SIGNAL */
1117 _mute_control->Changed (); /* EMIT SIGNAL */
1122 Route::muted () const
1124 return _mute_master->muted_by_self();
1128 Route::muted_by_others () const
1130 // This method is only used by route_ui for display state.
1131 // The real thing is MuteMaster::muted_by_others_at()
1133 //master is never muted by others
1137 //now check to see if something is soloed (and I am not)
1138 //see also MuteMaster::mute_gain_at()
1139 return (_session.soloing() && !soloed() && !solo_isolated());
1144 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1146 cerr << name << " {" << endl;
1147 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1148 p != procs.end(); ++p) {
1149 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1151 cerr << "}" << endl;
1155 /** Supposing that we want to insert a Processor at a given Placement, return
1156 * the processor to add the new one before (or 0 to add at the end).
1158 boost::shared_ptr<Processor>
1159 Route::before_processor_for_placement (Placement p)
1161 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1163 ProcessorList::iterator loc;
1165 if (p == PreFader) {
1166 /* generic pre-fader: insert immediately before the amp */
1167 loc = find (_processors.begin(), _processors.end(), _amp);
1169 /* generic post-fader: insert right before the main outs */
1170 loc = find (_processors.begin(), _processors.end(), _main_outs);
1173 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1176 /** Supposing that we want to insert a Processor at a given index, return
1177 * the processor to add the new one before (or 0 to add at the end).
1179 boost::shared_ptr<Processor>
1180 Route::before_processor_for_index (int index)
1183 return boost::shared_ptr<Processor> ();
1186 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1188 ProcessorList::iterator i = _processors.begin ();
1190 while (i != _processors.end() && j < index) {
1191 if ((*i)->display_to_user()) {
1198 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1201 /** Add a processor either pre- or post-fader
1202 * @return 0 on success, non-0 on failure.
1205 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1207 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1211 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1212 * @param index Index to add the processor at, or -1 to add at the end of the list.
1213 * @return 0 on success, non-0 on failure.
1216 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1218 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1221 /** Add a processor to the route.
1222 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1223 * @return 0 on success, non-0 on failure.
1226 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1228 assert (processor != _meter);
1229 assert (processor != _main_outs);
1231 DEBUG_TRACE (DEBUG::Processors, string_compose (
1232 "%1 adding processor %2\n", name(), processor->name()));
1234 if (!AudioEngine::instance()->connected() || !processor) {
1239 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1240 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1241 ProcessorState pstate (this);
1243 boost::shared_ptr<PluginInsert> pi;
1244 boost::shared_ptr<PortInsert> porti;
1246 if (processor == _amp) {
1247 /* Ensure that only one amp is in the list at any time */
1248 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1249 if (check != _processors.end()) {
1250 if (before == _amp) {
1251 /* Already in position; all is well */
1254 _processors.erase (check);
1259 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1261 ProcessorList::iterator loc;
1263 /* inserting before a processor; find it */
1264 loc = find (_processors.begin(), _processors.end(), before);
1265 if (loc == _processors.end ()) {
1270 /* inserting at end */
1271 loc = _processors.end ();
1274 _processors.insert (loc, processor);
1275 processor->set_owner (this);
1277 // Set up processor list channels. This will set processor->[input|output]_streams(),
1278 // configure redirect ports properly, etc.
1281 if (configure_processors_unlocked (err)) {
1283 configure_processors_unlocked (0); // it worked before we tried to add it ...
1288 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1290 if (pi->has_no_inputs ()) {
1291 /* generator plugin */
1292 _have_internal_generator = true;
1297 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1298 processor->activate ();
1301 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1303 _output->set_user_latency (0);
1306 reset_instrument_info ();
1307 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1308 set_processor_positions ();
1314 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1316 const XMLProperty *prop;
1319 boost::shared_ptr<Processor> processor;
1321 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1322 so that we can add the processor in the right place (pre/post-fader)
1325 XMLNodeList const & children = node.children ();
1326 XMLNodeList::const_iterator i = children.begin ();
1328 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1332 Placement placement = PreFader;
1334 if (i != children.end()) {
1335 if ((prop = (*i)->property (X_("placement"))) != 0) {
1336 placement = Placement (string_2_enum (prop->value(), placement));
1340 if (node.name() == "Insert") {
1342 if ((prop = node.property ("type")) != 0) {
1344 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1345 prop->value() == "lv2" ||
1346 prop->value() == "windows-vst" ||
1347 prop->value() == "lxvst" ||
1348 prop->value() == "audiounit") {
1350 if (_session.get_disable_all_loaded_plugins ()) {
1351 processor.reset (new UnknownProcessor (_session, node));
1353 processor.reset (new PluginInsert (_session));
1358 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1363 } else if (node.name() == "Send") {
1365 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1366 processor.reset (new Send (_session, sendpan, _mute_master));
1370 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1374 if (processor->set_state (node, version)) {
1378 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1379 if (i != children.end()) {
1380 if ((prop = (*i)->property (X_("active"))) != 0) {
1381 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1382 processor->activate();
1384 processor->deactivate();
1388 return (add_processor (processor, placement, 0, false) == 0);
1391 catch (failed_constructor &err) {
1392 warning << _("processor could not be created. Ignored.") << endmsg;
1398 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1400 /* NOTE: this is intended to be used ONLY when copying
1401 processors from another Route. Hence the subtle
1402 differences between this and ::add_processor()
1405 ProcessorList::iterator loc;
1408 loc = find(_processors.begin(), _processors.end(), before);
1410 /* nothing specified - at end */
1411 loc = _processors.end ();
1414 if (!_session.engine().connected()) {
1418 if (others.empty()) {
1423 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1424 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1425 ProcessorState pstate (this);
1427 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1433 boost::shared_ptr<PluginInsert> pi;
1435 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1439 _processors.insert (loc, *i);
1440 (*i)->set_owner (this);
1442 if ((*i)->active()) {
1446 /* Think: does this really need to be called for every processor in the loop? */
1448 if (configure_processors_unlocked (err)) {
1450 configure_processors_unlocked (0); // it worked before we tried to add it ...
1455 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1458 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1459 boost::shared_ptr<PluginInsert> pi;
1461 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1462 if (pi->has_no_inputs ()) {
1463 _have_internal_generator = true;
1469 _output->set_user_latency (0);
1472 reset_instrument_info ();
1473 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1474 set_processor_positions ();
1480 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1482 if (p == PreFader) {
1483 start = _processors.begin();
1484 end = find(_processors.begin(), _processors.end(), _amp);
1486 start = find(_processors.begin(), _processors.end(), _amp);
1488 end = _processors.end();
1492 /** Turn off all processors with a given placement
1493 * @param p Placement of processors to disable
1496 Route::disable_processors (Placement p)
1498 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1500 ProcessorList::iterator start, end;
1501 placement_range(p, start, end);
1503 for (ProcessorList::iterator i = start; i != end; ++i) {
1504 (*i)->deactivate ();
1507 _session.set_dirty ();
1510 /** Turn off all redirects
1513 Route::disable_processors ()
1515 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1517 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1518 (*i)->deactivate ();
1521 _session.set_dirty ();
1524 /** Turn off all redirects with a given placement
1525 * @param p Placement of redirects to disable
1528 Route::disable_plugins (Placement p)
1530 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1532 ProcessorList::iterator start, end;
1533 placement_range(p, start, end);
1535 for (ProcessorList::iterator i = start; i != end; ++i) {
1536 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1537 (*i)->deactivate ();
1541 _session.set_dirty ();
1544 /** Turn off all plugins
1547 Route::disable_plugins ()
1549 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1551 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1552 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1553 (*i)->deactivate ();
1557 _session.set_dirty ();
1562 Route::ab_plugins (bool forward)
1564 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1568 /* forward = turn off all active redirects, and mark them so that the next time
1569 we go the other way, we will revert them
1572 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1573 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1577 if ((*i)->active()) {
1578 (*i)->deactivate ();
1579 (*i)->set_next_ab_is_active (true);
1581 (*i)->set_next_ab_is_active (false);
1587 /* backward = if the redirect was marked to go active on the next ab, do so */
1589 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1591 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1595 if ((*i)->get_next_ab_is_active()) {
1598 (*i)->deactivate ();
1603 _session.set_dirty ();
1607 /** Remove processors with a given placement.
1608 * @param p Placement of processors to remove.
1611 Route::clear_processors (Placement p)
1613 if (!_session.engine().connected()) {
1617 bool already_deleting = _session.deletion_in_progress();
1618 if (!already_deleting) {
1619 _session.set_deletion_in_progress();
1623 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1624 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1625 ProcessorList new_list;
1626 ProcessorStreams err;
1627 bool seen_amp = false;
1629 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1635 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1637 /* you can't remove these */
1639 new_list.push_back (*i);
1646 new_list.push_back (*i);
1649 (*i)->drop_references ();
1657 (*i)->drop_references ();
1660 new_list.push_back (*i);
1667 _processors = new_list;
1668 configure_processors_unlocked (&err); // this can't fail
1671 processor_max_streams.reset();
1672 _have_internal_generator = false;
1673 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1674 set_processor_positions ();
1676 reset_instrument_info ();
1678 if (!already_deleting) {
1679 _session.clear_deletion_in_progress();
1684 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1686 // TODO once the export point can be configured properly, do something smarter here
1687 if (processor == _capturing_processor) {
1688 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1689 if (need_process_lock) {
1693 _capturing_processor.reset();
1695 if (need_process_lock) {
1700 /* these can never be removed */
1702 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1706 if (!_session.engine().connected()) {
1710 processor_max_streams.reset();
1713 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1714 if (need_process_lock) {
1718 /* Caller must hold process lock */
1719 assert (!AudioEngine::instance()->process_lock().trylock());
1721 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1723 ProcessorState pstate (this);
1725 ProcessorList::iterator i;
1726 bool removed = false;
1728 for (i = _processors.begin(); i != _processors.end(); ) {
1729 if (*i == processor) {
1731 /* move along, see failure case for configure_processors()
1732 where we may need to reconfigure the processor.
1735 /* stop redirects that send signals to JACK ports
1736 from causing noise as a result of no longer being
1740 boost::shared_ptr<IOProcessor> iop;
1742 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1746 i = _processors.erase (i);
1754 _output->set_user_latency (0);
1762 if (configure_processors_unlocked (err)) {
1764 /* we know this will work, because it worked before :) */
1765 configure_processors_unlocked (0);
1769 _have_internal_generator = false;
1771 for (i = _processors.begin(); i != _processors.end(); ++i) {
1772 boost::shared_ptr<PluginInsert> pi;
1774 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1775 if (pi->has_no_inputs ()) {
1776 _have_internal_generator = true;
1781 if (need_process_lock) {
1786 reset_instrument_info ();
1787 processor->drop_references ();
1788 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1789 set_processor_positions ();
1795 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1797 ProcessorList deleted;
1799 if (!_session.engine().connected()) {
1803 processor_max_streams.reset();
1806 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1807 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1808 ProcessorState pstate (this);
1810 ProcessorList::iterator i;
1811 boost::shared_ptr<Processor> processor;
1813 for (i = _processors.begin(); i != _processors.end(); ) {
1817 /* these can never be removed */
1819 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1824 /* see if its in the list of processors to delete */
1826 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1831 /* stop IOProcessors that send to JACK ports
1832 from causing noise as a result of no longer being
1836 boost::shared_ptr<IOProcessor> iop;
1838 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1842 deleted.push_back (processor);
1843 i = _processors.erase (i);
1846 if (deleted.empty()) {
1847 /* none of those in the requested list were found */
1851 _output->set_user_latency (0);
1853 if (configure_processors_unlocked (err)) {
1855 /* we know this will work, because it worked before :) */
1856 configure_processors_unlocked (0);
1861 _have_internal_generator = false;
1863 for (i = _processors.begin(); i != _processors.end(); ++i) {
1864 boost::shared_ptr<PluginInsert> pi;
1866 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1867 if (pi->has_no_inputs ()) {
1868 _have_internal_generator = true;
1875 /* now try to do what we need to so that those that were removed will be deleted */
1877 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1878 (*i)->drop_references ();
1881 reset_instrument_info ();
1882 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1883 set_processor_positions ();
1889 Route::reset_instrument_info ()
1891 boost::shared_ptr<Processor> instr = the_instrument();
1893 _instrument_info.set_internal_instrument (instr);
1897 /** Caller must hold process lock */
1899 Route::configure_processors (ProcessorStreams* err)
1901 #ifndef PLATFORM_WINDOWS
1902 assert (!AudioEngine::instance()->process_lock().trylock());
1905 if (!_in_configure_processors) {
1906 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1907 return configure_processors_unlocked (err);
1914 Route::input_streams () const
1916 return _input->n_ports ();
1919 list<pair<ChanCount, ChanCount> >
1920 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1922 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1924 return try_configure_processors_unlocked (in, err);
1927 list<pair<ChanCount, ChanCount> >
1928 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1930 // Check each processor in order to see if we can configure as requested
1932 list<pair<ChanCount, ChanCount> > configuration;
1935 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1936 DEBUG_TRACE (DEBUG::Processors, "{\n");
1938 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1940 if ((*p)->can_support_io_configuration(in, out)) {
1941 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1942 configuration.push_back(make_pair(in, out));
1945 // restriction for Monitor Section Processors
1946 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1947 /* do not allow to add/remove channels (for now)
1948 * The Monitor follows the master-bus and has no panner (unpan)
1949 * but do allow processors with midi-in to be added (e.g VSTs with control that
1950 * will remain unconnected)
1952 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1953 return list<pair<ChanCount, ChanCount> > ();
1955 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1956 // internal sends make no sense, only feedback
1957 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1958 return list<pair<ChanCount, ChanCount> > ();
1960 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1961 /* External Sends can be problematic. one can add/remove ports
1962 * there signal leaves the DAW to external monitors anyway, so there's
1963 * no real use for allowing them here anyway.
1965 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1966 return list<pair<ChanCount, ChanCount> > ();
1968 if (boost::dynamic_pointer_cast<Send> (*p)) {
1970 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1971 return list<pair<ChanCount, ChanCount> > ();
1980 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1981 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1982 DEBUG_TRACE (DEBUG::Processors, "}\n");
1983 return list<pair<ChanCount, ChanCount> > ();
1987 DEBUG_TRACE (DEBUG::Processors, "}\n");
1989 return configuration;
1992 /** Set the input/output configuration of each processor in the processors list.
1993 * Caller must hold process lock.
1994 * Return 0 on success, otherwise configuration is impossible.
1997 Route::configure_processors_unlocked (ProcessorStreams* err)
1999 #ifndef PLATFORM_WINDOWS
2000 assert (!AudioEngine::instance()->process_lock().trylock());
2003 if (_in_configure_processors) {
2007 /* put invisible processors where they should be */
2008 setup_invisible_processors ();
2010 _in_configure_processors = true;
2012 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2014 if (configuration.empty ()) {
2015 _in_configure_processors = false;
2020 bool seen_mains_out = false;
2021 processor_out_streams = _input->n_ports();
2022 processor_max_streams.reset();
2024 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2025 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2027 if (!(*p)->configure_io(c->first, c->second)) {
2028 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2030 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2031 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2033 boost::shared_ptr<PluginInsert> pi;
2034 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2035 /* plugins connected via Split Match may have more channels.
2036 * route/scratch buffers are needed for all of them*/
2037 processor_max_streams = ChanCount::max(processor_max_streams, pi->input_streams());
2038 processor_max_streams = ChanCount::max(processor_max_streams, pi->natural_input_streams());
2042 if (boost::dynamic_pointer_cast<Delivery> (*p)
2043 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2044 /* main delivery will increase port count to match input.
2045 * the Delivery::Main is usually the last processor - followed only by
2048 seen_mains_out = true;
2050 if (!seen_mains_out) {
2051 processor_out_streams = out;
2057 _meter->set_max_channels (processor_max_streams);
2060 /* make sure we have sufficient scratch buffers to cope with the new processor
2063 _session.ensure_buffers (n_process_buffers ());
2065 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2067 _in_configure_processors = false;
2071 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2072 * @param state New active state for those processors.
2075 Route::all_visible_processors_active (bool state)
2077 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2079 if (_processors.empty()) {
2083 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2084 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2091 (*i)->deactivate ();
2095 _session.set_dirty ();
2099 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2101 /* check if re-order requires re-configuration of any processors
2102 * -> compare channel configuration for all processors
2104 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2105 ChanCount c = input_streams ();
2107 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2109 if (c != (*j)->input_streams()) {
2112 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2115 if ((*i)->input_streams() != c) {
2118 c = (*i)->output_streams();
2130 __attribute__((annotate("realtime")))
2133 Route::apply_processor_order (const ProcessorList& new_order)
2135 /* need to hold processor_lock; either read or write lock
2136 * and the engine process_lock.
2137 * Due to r/w lock ambiguity we can only assert the latter
2139 assert (!AudioEngine::instance()->process_lock().trylock());
2142 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2143 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2144 * processors in the current actual processor list that are hidden. Any visible processors
2145 * in the current list but not in "new_order" will be assumed to be deleted.
2148 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2149 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2150 * (note though that ::processors_reorder_needs_configure() ensured that
2151 * this function will only ever be called from the rt-thread if no processor were removed)
2153 * either way, I can't proove it, but an x-run due to re-order here is less likley
2154 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2157 ProcessorList as_it_will_be;
2158 ProcessorList::iterator oiter;
2159 ProcessorList::const_iterator niter;
2161 oiter = _processors.begin();
2162 niter = new_order.begin();
2164 while (niter != new_order.end()) {
2166 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2167 then append it to the temp list.
2169 Otherwise, see if the next processor in the old list is in the new list. if not,
2170 its been deleted. If its there, append it to the temp list.
2173 if (oiter == _processors.end()) {
2175 /* no more elements in the old list, so just stick the rest of
2176 the new order onto the temp list.
2179 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2180 while (niter != new_order.end()) {
2187 if (!(*oiter)->display_to_user()) {
2189 as_it_will_be.push_back (*oiter);
2193 /* visible processor: check that its in the new order */
2195 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2196 /* deleted: do nothing, shared_ptr<> will clean up */
2198 /* ignore this one, and add the next item from the new order instead */
2199 as_it_will_be.push_back (*niter);
2204 /* now remove from old order - its taken care of no matter what */
2205 oiter = _processors.erase (oiter);
2209 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2211 /* If the meter is in a custom position, find it and make a rough note of its position */
2212 maybe_note_meter_position ();
2216 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2218 // it a change is already queued, wait for it
2219 // (unless engine is stopped. apply immediately and proceed
2220 while (g_atomic_int_get (&_pending_process_reorder)) {
2221 if (!AudioEngine::instance()->running()) {
2222 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2223 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2225 apply_processor_order(_pending_processor_order);
2226 setup_invisible_processors ();
2228 g_atomic_int_set (&_pending_process_reorder, 0);
2230 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2231 set_processor_positions ();
2233 // TODO rather use a semaphore or something.
2234 // but since ::reorder_processors() is called
2235 // from the GUI thread, this is fine..
2240 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2242 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2243 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2244 ProcessorState pstate (this);
2246 apply_processor_order (new_order);
2248 if (configure_processors_unlocked (err)) {
2256 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2257 set_processor_positions ();
2260 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2261 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2263 // _pending_processor_order is protected by _processor_lock
2264 _pending_processor_order = new_order;
2265 g_atomic_int_set (&_pending_process_reorder, 1);
2278 Route::get_template()
2280 return state(false);
2284 Route::state(bool full_state)
2286 if (!_session._template_state_dir.empty()) {
2287 assert (!full_state); // only for templates
2288 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2291 XMLNode *node = new XMLNode("Route");
2292 ProcessorList::iterator i;
2295 id().print (buf, sizeof (buf));
2296 node->add_property("id", buf);
2297 node->add_property ("name", _name);
2298 node->add_property("default-type", _default_type.to_string());
2301 node->add_property("flags", enum_2_string (_flags));
2304 node->add_property("active", _active?"yes":"no");
2306 boost::to_string (_phase_invert, p);
2307 node->add_property("phase-invert", p);
2308 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2309 node->add_property("meter-point", enum_2_string (_meter_point));
2311 node->add_property("meter-type", enum_2_string (_meter_type));
2314 node->add_property("route-group", _route_group->name());
2317 snprintf (buf, sizeof (buf), "%d", _order_key);
2318 node->add_property ("order-key", buf);
2319 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2320 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2321 node->add_property ("soloed-by-upstream", buf);
2322 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2323 node->add_property ("soloed-by-downstream", buf);
2324 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2325 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2327 node->add_child_nocopy (_input->state (full_state));
2328 node->add_child_nocopy (_output->state (full_state));
2329 node->add_child_nocopy (_solo_control->get_state ());
2330 node->add_child_nocopy (_mute_control->get_state ());
2331 node->add_child_nocopy (_mute_master->get_state ());
2334 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2337 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2338 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2339 remote_control_node->add_property (X_("id"), buf);
2340 node->add_child_nocopy (*remote_control_node);
2342 if (_comment.length()) {
2343 XMLNode *cmt = node->add_child ("Comment");
2344 cmt->add_content (_comment);
2348 node->add_child_nocopy (_pannable->state (full_state));
2351 for (i = _processors.begin(); i != _processors.end(); ++i) {
2353 /* template save: do not include internal sends functioning as
2354 aux sends because the chance of the target ID
2355 in the session where this template is used
2358 similarly, do not save listen sends which connect to
2359 the monitor section, because these will always be
2362 boost::shared_ptr<InternalSend> is;
2364 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2365 if (is->role() == Delivery::Listen) {
2370 node->add_child_nocopy((*i)->state (full_state));
2374 node->add_child_copy (*_extra_xml);
2377 if (_custom_meter_position_noted) {
2378 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2380 after->id().print (buf, sizeof (buf));
2381 node->add_property (X_("processor-after-last-custom-meter"), buf);
2385 if (!_session._template_state_dir.empty()) {
2386 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2393 Route::set_state (const XMLNode& node, int version)
2395 if (version < 3000) {
2396 return set_state_2X (node, version);
2400 XMLNodeConstIterator niter;
2402 const XMLProperty *prop;
2404 if (node.name() != "Route"){
2405 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2409 if ((prop = node.property (X_("name"))) != 0) {
2410 Route::set_name (prop->value());
2414 _initial_io_setup = true;
2416 if ((prop = node.property (X_("flags"))) != 0) {
2417 _flags = Flag (string_2_enum (prop->value(), _flags));
2422 if (is_master() || is_monitor() || is_auditioner()) {
2423 _mute_master->set_solo_ignore (true);
2427 /* monitor bus does not get a panner, but if (re)created
2428 via XML, it will already have one by the time we
2429 call ::set_state(). so ... remove it.
2434 /* add all processors (except amp, which is always present) */
2436 nlist = node.children();
2437 XMLNode processor_state (X_("processor_state"));
2439 Stateful::save_extra_xml (node);
2441 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2445 if (child->name() == IO::state_node_name) {
2446 if ((prop = child->property (X_("direction"))) == 0) {
2450 if (prop->value() == "Input") {
2451 _input->set_state (*child, version);
2452 } else if (prop->value() == "Output") {
2453 _output->set_state (*child, version);
2457 if (child->name() == X_("Processor")) {
2458 processor_state.add_child_copy (*child);
2461 if (child->name() == X_("Pannable")) {
2463 _pannable->set_state (*child, version);
2465 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2470 if ((prop = node.property (X_("meter-point"))) != 0) {
2471 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2472 set_meter_point (mp, true);
2474 _meter->set_display_to_user (_meter_point == MeterCustom);
2478 if ((prop = node.property (X_("meter-type"))) != 0) {
2479 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2482 _initial_io_setup = false;
2484 set_processor_state (processor_state);
2486 // this looks up the internal instrument in processors
2487 reset_instrument_info();
2489 if ((prop = node.property ("self-solo")) != 0) {
2490 set_self_solo (string_is_affirmative (prop->value()));
2493 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2494 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2495 mod_solo_by_others_upstream (atoi (prop->value()));
2498 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2499 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2500 mod_solo_by_others_downstream (atoi (prop->value()));
2503 if ((prop = node.property ("solo-isolated")) != 0) {
2504 set_solo_isolated (string_is_affirmative (prop->value()), this);
2507 if ((prop = node.property ("solo-safe")) != 0) {
2508 set_solo_safe (string_is_affirmative (prop->value()), this);
2511 if ((prop = node.property (X_("phase-invert"))) != 0) {
2512 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2515 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2516 set_denormal_protection (string_is_affirmative (prop->value()));
2519 if ((prop = node.property (X_("active"))) != 0) {
2520 bool yn = string_is_affirmative (prop->value());
2521 _active = !yn; // force switch
2522 set_active (yn, this);
2525 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2526 set_order_key (atoi(prop->value()));
2529 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2533 string::size_type colon, equal;
2534 string remaining = prop->value();
2536 while (remaining.length()) {
2538 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2539 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2542 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2543 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2546 string keyname = remaining.substr (0, equal);
2548 if ((keyname == "EditorSort") || (keyname == "editor")) {
2549 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2555 colon = remaining.find_first_of (':');
2557 if (colon != string::npos) {
2558 remaining = remaining.substr (colon+1);
2565 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2566 PBD::ID id (prop->value ());
2567 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2568 ProcessorList::const_iterator i = _processors.begin ();
2569 while (i != _processors.end() && (*i)->id() != id) {
2573 if (i != _processors.end ()) {
2574 _processor_after_last_custom_meter = *i;
2575 _custom_meter_position_noted = true;
2579 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2582 if (child->name() == X_("Comment")) {
2584 /* XXX this is a terrible API design in libxml++ */
2586 XMLNode *cmt = *(child->children().begin());
2587 _comment = cmt->content();
2589 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2590 if (prop->value() == "solo") {
2591 _solo_control->set_state (*child, version);
2592 } else if (prop->value() == "mute") {
2593 _mute_control->set_state (*child, version);
2596 } else if (child->name() == X_("RemoteControl")) {
2597 if ((prop = child->property (X_("id"))) != 0) {
2599 sscanf (prop->value().c_str(), "%d", &x);
2600 set_remote_control_id_internal (x);
2603 } else if (child->name() == X_("MuteMaster")) {
2604 _mute_master->set_state (*child, version);
2606 } else if (child->name() == Automatable::xml_node_name) {
2607 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2615 Route::set_state_2X (const XMLNode& node, int version)
2617 LocaleGuard lg (X_("C"));
2619 XMLNodeConstIterator niter;
2621 const XMLProperty *prop;
2623 /* 2X things which still remain to be handled:
2629 if (node.name() != "Route") {
2630 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2634 if ((prop = node.property (X_("flags"))) != 0) {
2635 string f = prop->value ();
2636 boost::replace_all (f, "ControlOut", "MonitorOut");
2637 _flags = Flag (string_2_enum (f, _flags));
2642 if (is_master() || is_monitor() || is_auditioner()) {
2643 _mute_master->set_solo_ignore (true);
2646 if ((prop = node.property (X_("phase-invert"))) != 0) {
2647 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2648 if (string_is_affirmative (prop->value ())) {
2651 set_phase_invert (p);
2654 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2655 set_denormal_protection (string_is_affirmative (prop->value()));
2658 if ((prop = node.property (X_("soloed"))) != 0) {
2659 bool yn = string_is_affirmative (prop->value());
2661 /* XXX force reset of solo status */
2663 set_solo (yn, this);
2666 if ((prop = node.property (X_("muted"))) != 0) {
2669 bool muted = string_is_affirmative (prop->value());
2675 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2677 if (string_is_affirmative (prop->value())){
2678 mute_point = mute_point + "PreFader";
2683 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2685 if (string_is_affirmative (prop->value())){
2688 mute_point = mute_point + ",";
2691 mute_point = mute_point + "PostFader";
2696 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2698 if (string_is_affirmative (prop->value())){
2701 mute_point = mute_point + ",";
2704 mute_point = mute_point + "Listen";
2709 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2711 if (string_is_affirmative (prop->value())){
2714 mute_point = mute_point + ",";
2717 mute_point = mute_point + "Main";
2721 _mute_master->set_mute_points (mute_point);
2722 _mute_master->set_muted_by_self (true);
2726 if ((prop = node.property (X_("meter-point"))) != 0) {
2727 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2730 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2731 don't mean the same thing.
2734 if ((prop = node.property (X_("order-keys"))) != 0) {
2738 string::size_type colon, equal;
2739 string remaining = prop->value();
2741 while (remaining.length()) {
2743 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2744 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2747 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2748 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2751 string keyname = remaining.substr (0, equal);
2753 if (keyname == "EditorSort" || keyname == "editor") {
2754 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2760 colon = remaining.find_first_of (':');
2762 if (colon != string::npos) {
2763 remaining = remaining.substr (colon+1);
2772 nlist = node.children ();
2773 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2777 if (child->name() == IO::state_node_name) {
2779 /* there is a note in IO::set_state_2X() about why we have to call
2783 _input->set_state_2X (*child, version, true);
2784 _output->set_state_2X (*child, version, false);
2786 if ((prop = child->property (X_("name"))) != 0) {
2787 Route::set_name (prop->value ());
2792 if ((prop = child->property (X_("active"))) != 0) {
2793 bool yn = string_is_affirmative (prop->value());
2794 _active = !yn; // force switch
2795 set_active (yn, this);
2798 if ((prop = child->property (X_("gain"))) != 0) {
2801 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2802 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2806 /* Set up Panners in the IO */
2807 XMLNodeList io_nlist = child->children ();
2809 XMLNodeConstIterator io_niter;
2812 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2814 io_child = *io_niter;
2816 if (io_child->name() == X_("Panner")) {
2817 _main_outs->panner_shell()->set_state(*io_child, version);
2818 } else if (io_child->name() == X_("Automation")) {
2819 /* IO's automation is for the fader */
2820 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2826 XMLNodeList redirect_nodes;
2828 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2832 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2833 redirect_nodes.push_back(child);
2838 set_processor_state_2X (redirect_nodes, version);
2840 Stateful::save_extra_xml (node);
2842 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2845 if (child->name() == X_("Comment")) {
2847 /* XXX this is a terrible API design in libxml++ */
2849 XMLNode *cmt = *(child->children().begin());
2850 _comment = cmt->content();
2852 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2853 if (prop->value() == X_("solo")) {
2854 _solo_control->set_state (*child, version);
2855 } else if (prop->value() == X_("mute")) {
2856 _mute_control->set_state (*child, version);
2859 } else if (child->name() == X_("RemoteControl")) {
2860 if ((prop = child->property (X_("id"))) != 0) {
2862 sscanf (prop->value().c_str(), "%d", &x);
2863 set_remote_control_id_internal (x);
2873 Route::get_processor_state ()
2875 XMLNode* root = new XMLNode (X_("redirects"));
2876 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2877 root->add_child_nocopy ((*i)->state (true));
2884 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2886 /* We don't bother removing existing processors not in nList, as this
2887 method will only be called when creating a Route from scratch, not
2888 for undo purposes. Just put processors in at the appropriate place
2892 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2893 add_processor_from_xml_2X (**i, version);
2898 Route::set_processor_state (const XMLNode& node)
2900 const XMLNodeList &nlist = node.children();
2901 XMLNodeConstIterator niter;
2902 ProcessorList new_order;
2903 bool must_configure = false;
2905 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2907 XMLProperty* prop = (*niter)->property ("type");
2909 if (prop->value() == "amp") {
2910 _amp->set_state (**niter, Stateful::current_state_version);
2911 new_order.push_back (_amp);
2912 } else if (prop->value() == "trim") {
2913 _trim->set_state (**niter, Stateful::current_state_version);
2914 new_order.push_back (_trim);
2915 } else if (prop->value() == "meter") {
2916 _meter->set_state (**niter, Stateful::current_state_version);
2917 new_order.push_back (_meter);
2918 } else if (prop->value() == "delay") {
2920 _delayline->set_state (**niter, Stateful::current_state_version);
2921 new_order.push_back (_delayline);
2923 } else if (prop->value() == "main-outs") {
2924 _main_outs->set_state (**niter, Stateful::current_state_version);
2925 } else if (prop->value() == "intreturn") {
2927 _intreturn.reset (new InternalReturn (_session));
2928 must_configure = true;
2930 _intreturn->set_state (**niter, Stateful::current_state_version);
2931 } else if (is_monitor() && prop->value() == "monitor") {
2932 if (!_monitor_control) {
2933 _monitor_control.reset (new MonitorProcessor (_session));
2934 must_configure = true;
2936 _monitor_control->set_state (**niter, Stateful::current_state_version);
2937 } else if (prop->value() == "capture") {
2938 /* CapturingProcessor should never be restored, it's always
2939 added explicitly when needed */
2941 ProcessorList::iterator o;
2943 for (o = _processors.begin(); o != _processors.end(); ++o) {
2944 XMLProperty* id_prop = (*niter)->property(X_("id"));
2945 if (id_prop && (*o)->id() == id_prop->value()) {
2946 (*o)->set_state (**niter, Stateful::current_state_version);
2947 new_order.push_back (*o);
2952 // If the processor (*niter) is not on the route then create it
2954 if (o == _processors.end()) {
2956 boost::shared_ptr<Processor> processor;
2958 if (prop->value() == "intsend") {
2960 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2962 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2963 prop->value() == "lv2" ||
2964 prop->value() == "windows-vst" ||
2965 prop->value() == "lxvst" ||
2966 prop->value() == "audiounit") {
2968 if (_session.get_disable_all_loaded_plugins ()) {
2969 processor.reset (new UnknownProcessor (_session, **niter));
2971 processor.reset (new PluginInsert (_session));
2973 } else if (prop->value() == "port") {
2975 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2977 } else if (prop->value() == "send") {
2979 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2982 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2986 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2987 /* This processor could not be configured. Turn it into a UnknownProcessor */
2988 processor.reset (new UnknownProcessor (_session, **niter));
2991 /* we have to note the monitor send here, otherwise a new one will be created
2992 and the state of this one will be lost.
2994 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2995 if (isend && isend->role() == Delivery::Listen) {
2996 _monitor_send = isend;
2999 /* it doesn't matter if invisible processors are added here, as they
3000 will be sorted out by setup_invisible_processors () shortly.
3003 new_order.push_back (processor);
3004 must_configure = true;
3010 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3011 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3012 _processors = new_order;
3014 if (must_configure) {
3015 configure_processors_unlocked (0);
3018 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3020 (*i)->set_owner (this);
3021 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3023 boost::shared_ptr<PluginInsert> pi;
3025 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3026 if (pi->has_no_inputs ()) {
3027 _have_internal_generator = true;
3034 reset_instrument_info ();
3035 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3036 set_processor_positions ();
3040 Route::curve_reallocate ()
3042 // _gain_automation_curve.finish_resize ();
3043 // _pan_automation_curve.finish_resize ();
3047 Route::silence (framecnt_t nframes)
3049 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3054 silence_unlocked (nframes);
3058 Route::silence_unlocked (framecnt_t nframes)
3060 /* Must be called with the processor lock held */
3064 _output->silence (nframes);
3066 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3067 boost::shared_ptr<PluginInsert> pi;
3069 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3070 // skip plugins, they don't need anything when we're not active
3074 (*i)->silence (nframes);
3077 if (nframes == _session.get_block_size()) {
3084 Route::add_internal_return ()
3087 _intreturn.reset (new InternalReturn (_session));
3088 add_processor (_intreturn, PreFader);
3093 Route::add_send_to_internal_return (InternalSend* send)
3095 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3097 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3098 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3101 return d->add_send (send);
3107 Route::remove_send_from_internal_return (InternalSend* send)
3109 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3111 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3112 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3115 return d->remove_send (send);
3121 Route::enable_monitor_send ()
3123 /* Caller must hold process lock */
3124 assert (!AudioEngine::instance()->process_lock().trylock());
3126 /* master never sends to monitor section via the normal mechanism */
3127 assert (!is_master ());
3128 assert (!is_monitor ());
3130 /* make sure we have one */
3131 if (!_monitor_send) {
3132 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3133 _monitor_send->set_display_to_user (false);
3137 configure_processors (0);
3140 /** Add an aux send to a route.
3141 * @param route route to send to.
3142 * @param before Processor to insert before, or 0 to insert at the end.
3145 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3147 assert (route != _session.monitor_out ());
3150 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3152 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3154 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3156 if (d && d->target_route() == route) {
3157 /* already listening via the specified IO: do nothing */
3165 boost::shared_ptr<InternalSend> listener;
3168 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3169 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3170 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3173 add_processor (listener, before);
3175 } catch (failed_constructor& err) {
3183 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3185 ProcessorStreams err;
3186 ProcessorList::iterator tmp;
3189 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3191 /* have to do this early because otherwise processor reconfig
3192 * will put _monitor_send back in the list
3195 if (route == _session.monitor_out()) {
3196 _monitor_send.reset ();
3200 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3202 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3204 if (d && d->target_route() == route) {
3206 if (remove_processor (*x, &err, false) > 0) {
3212 /* list could have been demolished while we dropped the lock
3215 if (_session.engine().connected()) {
3216 /* i/o processors cannot be removed if the engine is not running
3217 * so don't live-loop in case the engine is N/A or dies
3227 Route::set_comment (string cmt, void *src)
3230 comment_changed (src);
3231 _session.set_dirty ();
3235 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3237 FeedRecord fr (other, via_sends_only);
3239 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3241 if (!result.second) {
3243 /* already a record for "other" - make sure sends-only information is correct */
3244 if (!via_sends_only && result.first->sends_only) {
3245 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3246 frp->sends_only = false;
3250 return result.second;
3254 Route::clear_fed_by ()
3260 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3262 const FedBy& fed_by (other->fed_by());
3264 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3265 boost::shared_ptr<Route> sr = f->r.lock();
3267 if (sr && (sr.get() == this)) {
3269 if (via_sends_only) {
3270 *via_sends_only = f->sends_only;
3281 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3283 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3285 if (_output->connected_to (other->input())) {
3286 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3287 if (via_send_only) {
3288 *via_send_only = false;
3295 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3297 boost::shared_ptr<IOProcessor> iop;
3299 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3300 if (iop->feeds (other)) {
3301 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3302 if (via_send_only) {
3303 *via_send_only = true;
3307 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3310 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3315 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3320 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3322 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3325 /** Called from the (non-realtime) butler thread when the transport is stopped */
3327 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3329 framepos_t now = _session.transport_frame();
3332 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3334 Automatable::transport_stopped (now);
3336 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3338 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3342 (*i)->transport_stopped (now);
3346 _roll_delay = _initial_delay;
3350 Route::input_change_handler (IOChange change, void * /*src*/)
3352 if ((change.type & IOChange::ConfigurationChanged)) {
3353 /* This is called with the process lock held if change
3354 contains ConfigurationChanged
3356 configure_processors (0);
3357 _phase_invert.resize (_input->n_ports().n_audio ());
3358 io_changed (); /* EMIT SIGNAL */
3361 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3364 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3365 if (_input->connected()) {
3366 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3367 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3371 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3372 if (does_feed && !sends_only) {
3373 if ((*i)->soloed()) {
3376 if ((*i)->solo_isolated()) {
3383 int delta = sbou - _soloed_by_others_upstream;
3384 int idelta = ibou - _solo_isolated_by_upstream;
3387 PBD::warning << string_compose (
3388 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3389 _name, ibou, _solo_isolated_by_upstream, idelta)
3394 if (_soloed_by_others_upstream) {
3395 // ignore new connections (they're not propagated)
3397 mod_solo_by_others_upstream (delta);
3401 if (_solo_isolated_by_upstream) {
3402 // solo-isolate currently only propagates downstream
3404 mod_solo_isolated_by_upstream (false, this);
3406 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3407 // but idelta can't be smaller than -1, can it?
3408 //_solo_isolated_by_upstream = ibou;
3411 // Session::route_solo_changed does not propagate indirect solo-changes
3412 // propagate downstream to tracks
3413 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3414 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3418 bool does_feed = feeds (*i, &sends_only);
3419 if (delta <= 0 && does_feed && !sends_only) {
3420 (*i)->mod_solo_by_others_upstream (delta);
3423 if (idelta < 0 && does_feed && !sends_only) {
3424 (*i)->mod_solo_isolated_by_upstream (false, this);
3431 Route::output_change_handler (IOChange change, void * /*src*/)
3433 if (_initial_io_setup) {
3437 if ((change.type & IOChange::ConfigurationChanged)) {
3438 /* This is called with the process lock held if change
3439 contains ConfigurationChanged
3441 configure_processors (0);
3444 _session.reset_monitor_section();
3447 io_changed (); /* EMIT SIGNAL */
3450 if (_soloed_by_others_downstream) {
3452 /* checking all all downstream routes for
3453 * explicit of implict solo is a rather drastic measure,
3454 * ideally the input_change_handler() of the other route
3455 * would propagate the change to us.
3457 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3458 if (_output->connected()) {
3459 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3460 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3464 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3465 if (does_feed && !sends_only) {
3466 if ((*i)->soloed()) {
3473 int delta = sbod - _soloed_by_others_downstream;
3475 // do not allow new connections to change implicit solo (no propagation)
3476 mod_solo_by_others_downstream (delta);
3477 // Session::route_solo_changed() does not propagate indirect solo-changes
3478 // propagate upstream to tracks
3479 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3480 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3484 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3485 if (delta != 0 && does_feed && !sends_only) {
3486 (*i)->mod_solo_by_others_downstream (delta);
3495 Route::pans_required () const
3497 if (n_outputs().n_audio() < 2) {
3501 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3505 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3507 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3513 if (n_outputs().n_total() == 0) {
3517 if (!_active || n_inputs() == ChanCount::ZERO) {
3518 silence_unlocked (nframes);
3522 if (session_state_changing) {
3523 if (_session.transport_speed() != 0.0f) {
3524 /* we're rolling but some state is changing (e.g. our diskstream contents)
3525 so we cannot use them. Be silent till this is over.
3527 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3529 silence_unlocked (nframes);
3532 /* we're really not rolling, so we're either delivery silence or actually
3533 monitoring, both of which are safe to do while session_state_changing is true.
3537 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3539 fill_buffers_with_input (bufs, _input, nframes);
3541 if (_meter_point == MeterInput) {
3542 _meter->run (bufs, start_frame, end_frame, nframes, true);
3545 _amp->apply_gain_automation (false);
3546 _trim->apply_gain_automation (false);
3547 passthru (bufs, start_frame, end_frame, nframes, 0);
3553 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3555 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3560 if (n_outputs().n_total() == 0) {
3564 if (!_active || n_inputs().n_total() == 0) {
3565 silence_unlocked (nframes);
3569 framepos_t unused = 0;
3571 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3577 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3579 fill_buffers_with_input (bufs, _input, nframes);
3581 if (_meter_point == MeterInput) {
3582 _meter->run (bufs, start_frame, end_frame, nframes, true);
3585 passthru (bufs, start_frame, end_frame, nframes, declick);
3591 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3598 Route::flush_processors ()
3600 /* XXX shouldn't really try to take this lock, since
3601 this is called from the RT audio thread.
3604 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3606 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3612 __attribute__((annotate("realtime")))
3615 Route::apply_processor_changes_rt ()
3617 int emissions = EmitNone;
3619 if (_pending_meter_point != _meter_point) {
3620 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3622 /* meters always have buffers for 'processor_max_streams'
3623 * they can be re-positioned without re-allocation */
3624 if (set_meter_point_unlocked()) {
3625 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3627 emissions |= EmitMeterChanged;
3632 bool changed = false;
3634 if (g_atomic_int_get (&_pending_process_reorder)) {
3635 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3637 apply_processor_order (_pending_processor_order);
3638 setup_invisible_processors ();
3640 g_atomic_int_set (&_pending_process_reorder, 0);
3641 emissions |= EmitRtProcessorChange;
3645 set_processor_positions ();
3647 if (emissions != 0) {
3648 g_atomic_int_set (&_pending_signals, emissions);
3655 Route::emit_pending_signals ()
3658 int sig = g_atomic_int_and (&_pending_signals, 0);
3659 if (sig & EmitMeterChanged) {
3660 _meter->emit_configuration_changed();
3661 meter_change (); /* EMIT SIGNAL */
3662 if (sig & EmitMeterVisibilityChange) {
3663 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3665 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3668 if (sig & EmitRtProcessorChange) {
3669 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3674 Route::set_meter_point (MeterPoint p, bool force)
3676 if (_pending_meter_point == p && !force) {
3680 if (force || !AudioEngine::instance()->running()) {
3681 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3682 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3683 _pending_meter_point = p;
3684 _meter->emit_configuration_changed();
3685 meter_change (); /* EMIT SIGNAL */
3686 if (set_meter_point_unlocked()) {
3687 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3689 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3692 _pending_meter_point = p;
3698 __attribute__((annotate("realtime")))
3701 Route::set_meter_point_unlocked ()
3704 /* Caller must hold process and processor write lock */
3705 assert (!AudioEngine::instance()->process_lock().trylock());
3706 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3707 assert (!lm.locked ());
3710 _meter_point = _pending_meter_point;
3712 bool meter_was_visible_to_user = _meter->display_to_user ();
3714 if (!_custom_meter_position_noted) {
3715 maybe_note_meter_position ();
3718 if (_meter_point != MeterCustom) {
3720 _meter->set_display_to_user (false);
3722 setup_invisible_processors ();
3725 _meter->set_display_to_user (true);
3727 /* If we have a previous position for the custom meter, try to put it there */
3728 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3730 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3731 if (i != _processors.end ()) {
3732 _processors.remove (_meter);
3733 _processors.insert (i, _meter);
3735 } else {// at end, right before the mains_out/panner
3736 _processors.remove (_meter);
3737 ProcessorList::iterator main = _processors.end();
3738 _processors.insert (--main, _meter);
3742 /* Set up the meter for its new position */
3744 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3748 if (loc == _processors.begin()) {
3749 m_in = _input->n_ports();
3751 ProcessorList::iterator before = loc;
3753 m_in = (*before)->output_streams ();
3756 _meter->reflect_inputs (m_in);
3758 /* we do not need to reconfigure the processors, because the meter
3759 (a) is always ready to handle processor_max_streams
3760 (b) is always an N-in/N-out processor, and thus moving
3761 it doesn't require any changes to the other processors.
3764 /* these should really be done after releasing the lock
3765 * but all those signals are subscribed to with gui_thread()
3768 return (_meter->display_to_user() != meter_was_visible_to_user);
3772 Route::listen_position_changed ()
3775 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3776 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3777 ProcessorState pstate (this);
3779 if (configure_processors_unlocked (0)) {
3780 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3782 configure_processors_unlocked (0); // it worked before we tried to add it ...
3787 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3788 _session.set_dirty ();
3791 boost::shared_ptr<CapturingProcessor>
3792 Route::add_export_point()
3794 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3795 if (!_capturing_processor) {
3797 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3798 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3800 _capturing_processor.reset (new CapturingProcessor (_session));
3801 _capturing_processor->activate ();
3803 configure_processors_unlocked (0);
3807 return _capturing_processor;
3811 Route::update_signal_latency ()
3813 framecnt_t l = _output->user_latency();
3814 framecnt_t lamp = 0;
3815 bool before_amp = true;
3816 framecnt_t ltrim = 0;
3817 bool before_trim = true;
3819 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3820 if ((*i)->active ()) {
3821 l += (*i)->signal_latency ();
3826 if ((*i) == _trim) {
3837 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3839 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3840 _signal_latency_at_amp_position = lamp;
3841 _signal_latency_at_trim_position = ltrim;
3843 if (_signal_latency != l) {
3844 _signal_latency = l;
3845 signal_latency_changed (); /* EMIT SIGNAL */
3848 return _signal_latency;
3852 Route::set_user_latency (framecnt_t nframes)
3854 _output->set_user_latency (nframes);
3855 _session.update_latency_compensation ();
3859 Route::set_latency_compensation (framecnt_t longest_session_latency)
3861 framecnt_t old = _initial_delay;
3863 if (_signal_latency < longest_session_latency) {
3864 _initial_delay = longest_session_latency - _signal_latency;
3869 DEBUG_TRACE (DEBUG::Latency, string_compose (
3870 "%1: compensate for maximum latency of %2,"
3871 "given own latency of %3, using initial delay of %4\n",
3872 name(), longest_session_latency, _signal_latency, _initial_delay));
3874 if (_initial_delay != old) {
3875 initial_delay_changed (); /* EMIT SIGNAL */
3878 if (_session.transport_stopped()) {
3879 _roll_delay = _initial_delay;
3884 Route::set_control (RouteAutomationControl& control, double val, PBD::Controllable::GroupControlDisposition /*group_override*/)
3886 boost::shared_ptr<RouteList> rl;
3888 switch (control.parameter().type()) {
3889 case GainAutomation:
3890 /* route must mediate group control */
3891 set_gain (val, this); /* any "src" argument will do other than our route group */
3895 case RecEnableAutomation:
3896 /* session must mediate group control */
3897 rl.reset (new RouteList);
3898 rl->push_back (shared_from_this());
3899 _session.set_record_enabled (rl, val >= 0.5 ? true : false);
3903 case SoloAutomation:
3904 /* session must mediate group control */
3905 rl.reset (new RouteList);
3906 rl->push_back (shared_from_this());
3907 if (Config->get_solo_control_is_listen_control()) {
3908 _session.set_listen (rl, val >= 0.5 ? true : false);
3910 _session.set_solo (rl, val >= 0.5 ? true : false);
3916 case MuteAutomation:
3917 /* session must mediate group control */
3918 rl.reset (new RouteList);
3919 rl->push_back (shared_from_this());
3920 _session.set_mute (rl, !muted());
3924 case PanAzimuthAutomation:
3925 case PanElevationAutomation:
3926 case PanWidthAutomation:
3927 case PanFrontBackAutomation:
3928 case PanLFEAutomation:
3932 /* Not a route automation control */
3936 control.route_set_value (val);
3940 Route::RouteAutomationControl::RouteAutomationControl (const std::string& name,
3941 AutomationType atype,
3942 boost::shared_ptr<AutomationList> alist,
3943 boost::shared_ptr<Route> r)
3944 : AutomationControl (r->session(), Evoral::Parameter (atype),
3945 ParameterDescriptor (Evoral::Parameter (atype)),
3951 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3952 : RouteAutomationControl (name, SoloAutomation, boost::shared_ptr<AutomationList>(), r)
3954 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3955 gl->set_interpolation(Evoral::ControlList::Discrete);
3960 Route::SoloControllable::set_value (double val, PBD::Controllable::GroupControlDisposition /* group_override */)
3963 set_value_unchecked (val);
3968 Route::SoloControllable::set_value_unchecked (double val)
3970 const bool bval = ((val >= 0.5) ? true : false);
3972 boost::shared_ptr<RouteList> rl (new RouteList);
3974 boost::shared_ptr<Route> r = _route.lock ();
3981 if (Config->get_solo_control_is_listen_control()) {
3982 _session.set_listen (rl, bval);
3984 _session.set_solo (rl, bval);
3989 Route::SoloControllable::get_value () const
3991 boost::shared_ptr<Route> r = _route.lock ();
3996 if (Config->get_solo_control_is_listen_control()) {
3997 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3999 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
4003 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
4004 : RouteAutomationControl (name, MuteAutomation, boost::shared_ptr<AutomationList>(), r)
4007 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
4008 gl->set_interpolation(Evoral::ControlList::Discrete);
4013 Route::MuteControllable::set_superficial_value(bool muted)
4015 /* Note we can not use AutomationControl::set_value here since it will emit
4016 Changed(), but the value will not be correct to the observer. */
4018 const bool to_list = _list && ((AutomationList*)_list.get ())->automation_write ();
4019 const double where = _session.audible_frame ();
4021 /* Note that we really need this:
4022 * if (as == Touch && _list->in_new_write_pass ()) {
4023 * alist->start_write_pass (_session.audible_frame ());
4025 * here in the case of the user calling from a GUI or whatever.
4026 * Without the ability to distinguish between user and
4027 * automation-initiated changes, we lose the "touch mute"
4028 * behaviour we have in AutomationController::toggled ().
4030 _list->set_in_write_pass (true, false, where);
4033 Control::set_double (muted, where, to_list);
4037 Route::MuteControllable::set_value (double val, PBD::Controllable::GroupControlDisposition /* group_override */)
4040 set_value_unchecked (val);
4045 Route::MuteControllable::set_value_unchecked (double val)
4047 const bool bval = ((val >= 0.5) ? true : false);
4049 boost::shared_ptr<Route> r = _route.lock ();
4054 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
4055 // Set superficial/automation value to drive controller (and possibly record)
4056 set_superficial_value (bval);
4057 // Playing back automation, set route mute directly
4058 r->set_mute (bval, this);
4060 // Set from user, queue mute event
4061 boost::shared_ptr<RouteList> rl (new RouteList);
4063 _session.set_mute (rl, bval, Session::rt_cleanup);
4068 Route::MuteControllable::get_value () const
4070 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
4071 // Playing back automation, get the value from the list
4072 return AutomationControl::get_value();
4075 // Not playing back automation, get the actual route mute value
4076 boost::shared_ptr<Route> r = _route.lock ();
4077 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
4080 Route::PhaseControllable::PhaseControllable (std::string name, boost::shared_ptr<Route> r)
4081 : RouteAutomationControl (name, PhaseAutomation, boost::shared_ptr<AutomationList>(), r)
4083 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(PhaseAutomation)));
4084 gl->set_interpolation(Evoral::ControlList::Discrete);
4089 Route::PhaseControllable::set_value (double v, PBD::Controllable::GroupControlDisposition /* group_override */)
4091 boost::shared_ptr<Route> r = _route.lock ();
4092 if (r->phase_invert().size()) {
4093 if (v == 0 || (v < 1 && v > 0.9) ) {
4094 r->set_phase_invert (_current_phase, false);
4096 r->set_phase_invert (_current_phase, true);
4102 Route::PhaseControllable::get_value () const
4104 boost::shared_ptr<Route> r = _route.lock ();
4105 return (double) r->phase_invert (_current_phase);
4109 Route::PhaseControllable::set_channel (uint32_t c)
4115 Route::PhaseControllable::channel () const
4117 return _current_phase;
4121 Route::set_block_size (pframes_t nframes)
4123 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4124 (*i)->set_block_size (nframes);
4127 _session.ensure_buffers (n_process_buffers ());
4131 Route::protect_automation ()
4133 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4134 (*i)->protect_automation();
4137 /** @param declick 1 to set a pending declick fade-in,
4138 * -1 to set a pending declick fade-out
4141 Route::set_pending_declick (int declick)
4144 /* this call is not allowed to turn off a pending declick */
4146 _pending_declick = declick;
4149 _pending_declick = 0;
4153 /** Shift automation forwards from a particular place, thereby inserting time.
4154 * Adds undo commands for any shifts that are performed.
4156 * @param pos Position to start shifting from.
4157 * @param frames Amount to shift forwards by.
4161 Route::shift (framepos_t pos, framecnt_t frames)
4163 /* gain automation */
4165 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4167 XMLNode &before = gc->alist()->get_state ();
4168 gc->alist()->shift (pos, frames);
4169 XMLNode &after = gc->alist()->get_state ();
4170 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4173 /* gain automation */
4175 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4177 XMLNode &before = gc->alist()->get_state ();
4178 gc->alist()->shift (pos, frames);
4179 XMLNode &after = gc->alist()->get_state ();
4180 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4183 // TODO mute automation ??
4185 /* pan automation */
4187 ControlSet::Controls& c (_pannable->controls());
4189 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4190 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4192 boost::shared_ptr<AutomationList> al = pc->alist();
4193 XMLNode& before = al->get_state ();
4194 al->shift (pos, frames);
4195 XMLNode& after = al->get_state ();
4196 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4201 /* redirect automation */
4203 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4204 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4206 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4208 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4209 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4211 boost::shared_ptr<AutomationList> al = ac->alist();
4212 XMLNode &before = al->get_state ();
4213 al->shift (pos, frames);
4214 XMLNode &after = al->get_state ();
4215 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4223 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4225 boost::shared_ptr<Processor> processor (p.lock ());
4226 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4230 pi->set_state_dir (d);
4234 Route::save_as_template (const string& path, const string& name)
4236 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4237 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4239 XMLNode& node (state (false));
4243 IO::set_name_in_state (*node.children().front(), name);
4245 tree.set_root (&node);
4247 /* return zero on success, non-zero otherwise */
4248 return !tree.write (path.c_str());
4253 Route::set_name (const string& str)
4255 if (str == name()) {
4259 string name = Route::ensure_track_or_route_name (str, _session);
4260 SessionObject::set_name (name);
4262 bool ret = (_input->set_name(name) && _output->set_name(name));
4265 /* rename the main outs. Leave other IO processors
4266 * with whatever name they already have, because its
4267 * just fine as it is (it will not contain the route
4268 * name if its a port insert, port send or port return).
4272 if (_main_outs->set_name (name)) {
4273 /* XXX returning false here is stupid because
4274 we already changed the route name.
4284 /** Set the name of a route in an XML description.
4285 * @param node XML <Route> node to set the name in.
4286 * @param name New name.
4289 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4291 node.add_property (X_("name"), name);
4293 XMLNodeList children = node.children();
4294 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4296 if ((*i)->name() == X_("IO")) {
4298 IO::set_name_in_state (**i, name);
4300 } else if ((*i)->name() == X_("Processor")) {
4302 XMLProperty* role = (*i)->property (X_("role"));
4303 if (role && role->value() == X_("Main")) {
4304 (*i)->add_property (X_("name"), name);
4307 } else if ((*i)->name() == X_("Diskstream")) {
4309 if (rename_playlist) {
4310 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4312 (*i)->add_property (X_("name"), name);
4318 boost::shared_ptr<Send>
4319 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4321 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4323 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4324 boost::shared_ptr<InternalSend> send;
4326 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4327 if (send->target_route() == target) {
4333 return boost::shared_ptr<Send>();
4336 /** @param c Audio channel index.
4337 * @param yn true to invert phase, otherwise false.
4340 Route::set_phase_invert (uint32_t c, bool yn)
4342 if (_phase_invert[c] != yn) {
4343 _phase_invert[c] = yn;
4344 phase_invert_changed (); /* EMIT SIGNAL */
4345 _session.set_dirty ();
4350 Route::set_phase_invert (boost::dynamic_bitset<> p)
4352 if (_phase_invert != p) {
4354 phase_invert_changed (); /* EMIT SIGNAL */
4355 _session.set_dirty ();
4360 Route::phase_invert (uint32_t c) const
4362 return _phase_invert[c];
4365 boost::dynamic_bitset<>
4366 Route::phase_invert () const
4368 return _phase_invert;
4372 Route::set_denormal_protection (bool yn)
4374 if (_denormal_protection != yn) {
4375 _denormal_protection = yn;
4376 denormal_protection_changed (); /* EMIT SIGNAL */
4381 Route::denormal_protection () const
4383 return _denormal_protection;
4387 Route::set_active (bool yn, void* src)
4389 if (_session.transport_rolling()) {
4393 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4394 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4398 if (_active != yn) {
4400 _input->set_active (yn);
4401 _output->set_active (yn);
4402 active_changed (); // EMIT SIGNAL
4403 _session.set_dirty ();
4407 boost::shared_ptr<Pannable>
4408 Route::pannable() const
4413 boost::shared_ptr<Panner>
4414 Route::panner() const
4417 return _main_outs->panner_shell()->panner();
4420 boost::shared_ptr<PannerShell>
4421 Route::panner_shell() const
4423 return _main_outs->panner_shell();
4426 boost::shared_ptr<AutomationControl>
4427 Route::gain_control() const
4429 return _amp->gain_control();
4432 boost::shared_ptr<AutomationControl>
4433 Route::trim_control() const
4435 return _trim->gain_control();
4438 boost::shared_ptr<AutomationControl>
4439 Route::get_control (const Evoral::Parameter& param)
4441 /* either we own the control or .... */
4443 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4447 /* maybe one of our processors does or ... */
4449 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4450 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4451 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4459 /* nobody does so we'll make a new one */
4461 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4468 boost::shared_ptr<Processor>
4469 Route::nth_plugin (uint32_t n)
4471 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4472 ProcessorList::iterator i;
4474 for (i = _processors.begin(); i != _processors.end(); ++i) {
4475 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4482 return boost::shared_ptr<Processor> ();
4485 boost::shared_ptr<Processor>
4486 Route::nth_send (uint32_t n)
4488 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4489 ProcessorList::iterator i;
4491 for (i = _processors.begin(); i != _processors.end(); ++i) {
4492 if (boost::dynamic_pointer_cast<Send> (*i)) {
4499 return boost::shared_ptr<Processor> ();
4503 Route::has_io_processor_named (const string& name)
4505 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4506 ProcessorList::iterator i;
4508 for (i = _processors.begin(); i != _processors.end(); ++i) {
4509 if (boost::dynamic_pointer_cast<Send> (*i) ||
4510 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4511 if ((*i)->name() == name) {
4520 MuteMaster::MutePoint
4521 Route::mute_points () const
4523 return _mute_master->mute_points ();
4527 Route::set_processor_positions ()
4529 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4531 bool had_amp = false;
4532 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4533 (*i)->set_pre_fader (!had_amp);
4540 /** Called when there is a proposed change to the input port count */
4542 Route::input_port_count_changing (ChanCount to)
4544 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4546 /* The processors cannot be configured with the new input arrangement, so
4552 /* The change is ok */
4556 /** Called when there is a proposed change to the output port count */
4558 Route::output_port_count_changing (ChanCount to)
4560 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4561 if (processor_out_streams.get(*t) > to.get(*t)) {
4565 /* The change is ok */
4570 Route::unknown_processors () const
4574 if (_session.get_disable_all_loaded_plugins ()) {
4575 // Do not list "missing plugins" if they are explicitly disabled
4579 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4580 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4581 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4582 p.push_back ((*i)->name ());
4591 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4593 /* we assume that all our input ports feed all our output ports. its not
4594 universally true, but the alternative is way too corner-case to worry about.
4597 LatencyRange all_connections;
4600 all_connections.min = 0;
4601 all_connections.max = 0;
4603 all_connections.min = ~((pframes_t) 0);
4604 all_connections.max = 0;
4606 /* iterate over all "from" ports and determine the latency range for all of their
4607 connections to the "outside" (outside of this Route).
4610 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4614 p->get_connected_latency_range (range, playback);
4616 all_connections.min = min (all_connections.min, range.min);
4617 all_connections.max = max (all_connections.max, range.max);
4621 /* set the "from" port latencies to the max/min range of all their connections */
4623 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4624 p->set_private_latency_range (all_connections, playback);
4627 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4629 all_connections.min += our_latency;
4630 all_connections.max += our_latency;
4632 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4633 p->set_private_latency_range (all_connections, playback);
4636 return all_connections.max;
4640 Route::set_private_port_latencies (bool playback) const
4642 framecnt_t own_latency = 0;
4644 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4645 OR LATENCY CALLBACK.
4647 This is called (early) from the latency callback. It computes the REAL
4648 latency associated with each port and stores the result as the "private"
4649 latency of the port. A later call to Route::set_public_port_latencies()
4650 sets all ports to the same value to reflect the fact that we do latency
4651 compensation and so all signals are delayed by the same amount as they
4652 flow through ardour.
4655 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4656 if ((*i)->active ()) {
4657 own_latency += (*i)->signal_latency ();
4662 /* playback: propagate latency from "outside the route" to outputs to inputs */
4663 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4665 /* capture: propagate latency from "outside the route" to inputs to outputs */
4666 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4671 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4673 /* this is called to set the JACK-visible port latencies, which take
4674 latency compensation into account.
4683 const PortSet& ports (_input->ports());
4684 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4685 p->set_public_latency_range (range, playback);
4690 const PortSet& ports (_output->ports());
4691 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4692 p->set_public_latency_range (range, playback);
4697 /** Put the invisible processors in the right place in _processors.
4698 * Must be called with a writer lock on _processor_lock held.
4701 __attribute__((annotate("realtime")))
4704 Route::setup_invisible_processors ()
4707 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4708 assert (!lm.locked ());
4712 /* too early to be doing this stuff */
4716 /* we'll build this new list here and then use it
4718 * TODO put the ProcessorList is on the stack for RT-safety.
4721 ProcessorList new_processors;
4723 /* find visible processors */
4725 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4726 if ((*i)->display_to_user ()) {
4727 new_processors.push_back (*i);
4733 ProcessorList::iterator amp = new_processors.begin ();
4734 while (amp != new_processors.end() && *amp != _amp) {
4738 assert (amp != new_processors.end ());
4740 /* and the processor after the amp */
4742 ProcessorList::iterator after_amp = amp;
4748 switch (_meter_point) {
4750 assert (!_meter->display_to_user ());
4751 new_processors.push_front (_meter);
4754 assert (!_meter->display_to_user ());
4755 new_processors.insert (amp, _meter);
4757 case MeterPostFader:
4758 /* do nothing here */
4761 /* do nothing here */
4764 /* the meter is visible, so we don't touch it here */
4771 assert (_main_outs);
4772 assert (!_main_outs->display_to_user ());
4773 new_processors.push_back (_main_outs);
4775 /* iterator for the main outs */
4777 ProcessorList::iterator main = new_processors.end();
4780 /* OUTPUT METERING */
4782 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4783 assert (!_meter->display_to_user ());
4785 /* add the processor just before or just after the main outs */
4787 ProcessorList::iterator meter_point = main;
4789 if (_meter_point == MeterOutput) {
4792 new_processors.insert (meter_point, _meter);
4797 if (_monitor_send && !is_monitor ()) {
4798 assert (!_monitor_send->display_to_user ());
4799 switch (Config->get_listen_position ()) {
4800 case PreFaderListen:
4801 switch (Config->get_pfl_position ()) {
4802 case PFLFromBeforeProcessors:
4803 new_processors.push_front (_monitor_send);
4805 case PFLFromAfterProcessors:
4806 new_processors.insert (amp, _monitor_send);
4809 _monitor_send->set_can_pan (false);
4811 case AfterFaderListen:
4812 switch (Config->get_afl_position ()) {
4813 case AFLFromBeforeProcessors:
4814 new_processors.insert (after_amp, _monitor_send);
4816 case AFLFromAfterProcessors:
4817 new_processors.insert (new_processors.end(), _monitor_send);
4820 _monitor_send->set_can_pan (true);
4825 #if 0 // not used - just yet
4826 if (!is_master() && !is_monitor() && !is_auditioner()) {
4827 new_processors.push_front (_delayline);
4831 /* MONITOR CONTROL */
4833 if (_monitor_control && is_monitor ()) {
4834 assert (!_monitor_control->display_to_user ());
4835 new_processors.insert (amp, _monitor_control);
4838 /* INTERNAL RETURN */
4840 /* doing this here means that any monitor control will come just after
4845 assert (!_intreturn->display_to_user ());
4846 new_processors.push_front (_intreturn);
4849 if (_trim && _trim->active()) {
4850 assert (!_trim->display_to_user ());
4851 new_processors.push_front (_trim);
4853 /* EXPORT PROCESSOR */
4855 if (_capturing_processor) {
4856 assert (!_capturing_processor->display_to_user ());
4857 new_processors.push_front (_capturing_processor);
4860 _processors = new_processors;
4862 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4863 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4868 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4869 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4870 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4877 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4878 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4882 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4883 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4890 /** If the meter point is `Custom', make a note of where the meter is.
4891 * This is so that if the meter point is subsequently set to something else,
4892 * and then back to custom, we can put the meter back where it was last time
4893 * custom was enabled.
4895 * Must be called with the _processor_lock held.
4898 Route::maybe_note_meter_position ()
4900 if (_meter_point != MeterCustom) {
4904 _custom_meter_position_noted = true;
4905 /* custom meter points range from after trim to before panner/main_outs
4906 * this is a limitation by the current processor UI
4908 bool seen_trim = false;
4909 _processor_after_last_custom_meter.reset();
4910 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4911 if ((*i) == _trim) {
4914 if ((*i) == _main_outs) {
4915 _processor_after_last_custom_meter = *i;
4918 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4920 _processor_after_last_custom_meter = _trim;
4922 ProcessorList::iterator j = i;
4924 assert(j != _processors.end ()); // main_outs should be before
4925 _processor_after_last_custom_meter = *j;
4930 assert(_processor_after_last_custom_meter.lock());
4933 boost::shared_ptr<Processor>
4934 Route::processor_by_id (PBD::ID id) const
4936 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4937 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4938 if ((*i)->id() == id) {
4943 return boost::shared_ptr<Processor> ();
4946 /** @return the monitoring state, or in other words what data we are pushing
4947 * into the route (data from the inputs, data from disk or silence)
4950 Route::monitoring_state () const
4952 return MonitoringInput;
4955 /** @return what we should be metering; either the data coming from the input
4956 * IO or the data that is flowing through the route.
4959 Route::metering_state () const
4961 return MeteringRoute;
4965 Route::has_external_redirects () const
4967 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4969 /* ignore inactive processors and obviously ignore the main
4970 * outs since everything has them and we don't care.
4973 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4981 boost::shared_ptr<Processor>
4982 Route::the_instrument () const
4984 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4985 return the_instrument_unlocked ();
4988 boost::shared_ptr<Processor>
4989 Route::the_instrument_unlocked () const
4991 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4992 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4993 if ((*i)->input_streams().n_midi() > 0 &&
4994 (*i)->output_streams().n_audio() > 0) {
4999 return boost::shared_ptr<Processor>();
5005 Route::non_realtime_locate (framepos_t pos)
5008 _pannable->transport_located (pos);
5011 if (_delayline.get()) {
5012 _delayline.get()->flush();
5016 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5017 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5019 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5020 (*i)->transport_located (pos);
5023 _roll_delay = _initial_delay;
5027 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5034 * We don't currently mix MIDI input together, so we don't need the
5035 * complex logic of the audio case.
5038 n_buffers = bufs.count().n_midi ();
5040 for (i = 0; i < n_buffers; ++i) {
5042 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5043 MidiBuffer& buf (bufs.get_midi (i));
5046 buf.copy (source_port->get_midi_buffer(nframes));
5048 buf.silence (nframes);
5054 n_buffers = bufs.count().n_audio();
5056 size_t n_ports = io->n_ports().n_audio();
5057 float scaling = 1.0f;
5059 if (n_ports > n_buffers) {
5060 scaling = ((float) n_buffers) / n_ports;
5063 for (i = 0; i < n_ports; ++i) {
5065 /* if there are more ports than buffers, map them onto buffers
5066 * in a round-robin fashion
5069 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5070 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5073 if (i < n_buffers) {
5075 /* first time through just copy a channel into
5079 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5081 if (scaling != 1.0f) {
5082 buf.apply_gain (scaling, nframes);
5087 /* on subsequent times around, merge data from
5088 * the port with what is already there
5091 if (scaling != 1.0f) {
5092 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5094 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5099 /* silence any remaining buffers */
5101 for (; i < n_buffers; ++i) {
5102 AudioBuffer& buf (bufs.get_audio (i));
5103 buf.silence (nframes);
5106 /* establish the initial setup of the buffer set, reflecting what was
5107 copied into it. unless, of course, we are the auditioner, in which
5108 case nothing was fed into it from the inputs at all.
5111 if (!is_auditioner()) {
5112 bufs.set_count (io->n_ports());
5116 boost::shared_ptr<AutomationControl>
5117 Route::pan_azimuth_control() const
5120 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5122 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5123 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5125 if (!_pannable || !panner()) {
5126 return boost::shared_ptr<AutomationControl>();
5128 return _pannable->pan_azimuth_control;
5132 boost::shared_ptr<AutomationControl>
5133 Route::pan_elevation_control() const
5135 if (Profile->get_mixbus() || !_pannable || !panner()) {
5136 return boost::shared_ptr<AutomationControl>();
5139 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5141 if (c.find (PanElevationAutomation) != c.end()) {
5142 return _pannable->pan_elevation_control;
5144 return boost::shared_ptr<AutomationControl>();
5147 boost::shared_ptr<AutomationControl>
5148 Route::pan_width_control() const
5150 if (Profile->get_mixbus() || !_pannable || !panner()) {
5151 return boost::shared_ptr<AutomationControl>();
5154 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5156 if (c.find (PanWidthAutomation) != c.end()) {
5157 return _pannable->pan_width_control;
5159 return boost::shared_ptr<AutomationControl>();
5162 boost::shared_ptr<AutomationControl>
5163 Route::pan_frontback_control() const
5165 if (Profile->get_mixbus() || !_pannable || !panner()) {
5166 return boost::shared_ptr<AutomationControl>();
5169 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5171 if (c.find (PanFrontBackAutomation) != c.end()) {
5172 return _pannable->pan_frontback_control;
5174 return boost::shared_ptr<AutomationControl>();
5177 boost::shared_ptr<AutomationControl>
5178 Route::pan_lfe_control() const
5180 if (Profile->get_mixbus() || !_pannable || !panner()) {
5181 return boost::shared_ptr<AutomationControl>();
5184 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5186 if (c.find (PanLFEAutomation) != c.end()) {
5187 return _pannable->pan_lfe_control;
5189 return boost::shared_ptr<AutomationControl>();
5194 Route::eq_band_cnt () const
5196 if (Profile->get_mixbus()) {
5199 /* Ardour has no well-known EQ object */
5204 boost::shared_ptr<AutomationControl>
5205 Route::eq_gain_controllable (uint32_t band) const
5208 boost::shared_ptr<PluginInsert> eq = ch_eq();
5211 return boost::shared_ptr<AutomationControl>();
5214 uint32_t port_number;
5217 if (is_master() || mixbus()) {
5224 if (is_master() || mixbus()) {
5231 if (is_master() || mixbus()) {
5238 return boost::shared_ptr<AutomationControl>();
5241 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5243 return boost::shared_ptr<AutomationControl>();
5246 boost::shared_ptr<AutomationControl>
5247 Route::eq_freq_controllable (uint32_t band) const
5251 if (mixbus() || is_master()) {
5252 /* no frequency controls for mixbusses or master */
5253 return boost::shared_ptr<AutomationControl>();
5256 boost::shared_ptr<PluginInsert> eq = ch_eq();
5259 return boost::shared_ptr<AutomationControl>();
5262 uint32_t port_number;
5274 return boost::shared_ptr<AutomationControl>();
5277 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5279 return boost::shared_ptr<AutomationControl>();
5283 boost::shared_ptr<AutomationControl>
5284 Route::eq_q_controllable (uint32_t band) const
5286 return boost::shared_ptr<AutomationControl>();
5289 boost::shared_ptr<AutomationControl>
5290 Route::eq_shape_controllable (uint32_t band) const
5292 return boost::shared_ptr<AutomationControl>();
5295 boost::shared_ptr<AutomationControl>
5296 Route::eq_enable_controllable () const
5299 boost::shared_ptr<PluginInsert> eq = ch_eq();
5302 return boost::shared_ptr<AutomationControl>();
5305 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5307 return boost::shared_ptr<AutomationControl>();
5311 boost::shared_ptr<AutomationControl>
5312 Route::eq_hpf_controllable () const
5315 boost::shared_ptr<PluginInsert> eq = ch_eq();
5318 return boost::shared_ptr<AutomationControl>();
5321 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5323 return boost::shared_ptr<AutomationControl>();
5328 Route::eq_band_name (uint32_t band) const
5330 if (Profile->get_mixbus()) {
5346 boost::shared_ptr<AutomationControl>
5347 Route::comp_enable_controllable () const
5350 boost::shared_ptr<PluginInsert> comp = ch_comp();
5353 return boost::shared_ptr<AutomationControl>();
5356 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5358 return boost::shared_ptr<AutomationControl>();
5361 boost::shared_ptr<AutomationControl>
5362 Route::comp_threshold_controllable () const
5365 boost::shared_ptr<PluginInsert> comp = ch_comp();
5368 return boost::shared_ptr<AutomationControl>();
5371 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5374 return boost::shared_ptr<AutomationControl>();
5377 boost::shared_ptr<AutomationControl>
5378 Route::comp_speed_controllable () const
5381 boost::shared_ptr<PluginInsert> comp = ch_comp();
5384 return boost::shared_ptr<AutomationControl>();
5387 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5389 return boost::shared_ptr<AutomationControl>();
5392 boost::shared_ptr<AutomationControl>
5393 Route::comp_mode_controllable () const
5396 boost::shared_ptr<PluginInsert> comp = ch_comp();
5399 return boost::shared_ptr<AutomationControl>();
5402 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5404 return boost::shared_ptr<AutomationControl>();
5407 boost::shared_ptr<AutomationControl>
5408 Route::comp_makeup_controllable () const
5411 boost::shared_ptr<PluginInsert> comp = ch_comp();
5414 return boost::shared_ptr<AutomationControl>();
5417 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5419 return boost::shared_ptr<AutomationControl>();
5422 boost::shared_ptr<AutomationControl>
5423 Route::comp_redux_controllable () const
5426 boost::shared_ptr<PluginInsert> comp = ch_comp();
5429 return boost::shared_ptr<AutomationControl>();
5432 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5434 return boost::shared_ptr<AutomationControl>();
5439 Route::comp_mode_name (uint32_t mode) const
5444 return _("Leveler");
5446 return _("Compressor");
5448 return _("Limiter");
5458 Route::comp_speed_name (uint32_t mode) const