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);
177 // amp should exist before amp controls
178 _group_gain_control.reset (new GroupGainControllable (X_("groupgain"), shared_from_this ()));
179 _group_gain_control->set_flags (Controllable::Flag (_group_gain_control->flags() | Controllable::GainLike));
180 add_control (_group_gain_control);
183 _trim.reset (new Amp (_session, "trim"));
184 _trim->set_display_to_user (false);
186 if (dynamic_cast<AudioTrack*>(this)) {
187 /* we can't do this in the AudioTrack's constructor
188 * because _trim does not exit then
192 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
197 /* create standard processors: meter, main outs, monitor out;
198 they will be added to _processors by setup_invisible_processors ()
201 _meter.reset (new PeakMeter (_session, _name));
202 _meter->set_owner (this);
203 _meter->set_display_to_user (false);
206 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
207 _main_outs->activate ();
210 /* where we listen to tracks */
211 _intreturn.reset (new InternalReturn (_session));
212 _intreturn->activate ();
214 /* the thing that provides proper control over a control/monitor/listen bus
215 (such as per-channel cut, dim, solo, invert, etc).
217 _monitor_control.reset (new MonitorProcessor (_session));
218 _monitor_control->activate ();
221 if (is_master() || is_monitor() || is_auditioner()) {
222 _mute_master->set_solo_ignore (true);
225 /* now that we have _meter, its safe to connect to this */
228 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
229 configure_processors (0);
237 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
239 /* do this early so that we don't get incoming signals as we are going through destruction
244 /* don't use clear_processors here, as it depends on the session which may
245 be half-destroyed by now
248 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
249 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
250 (*i)->drop_references ();
253 _processors.clear ();
257 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
259 if (Config->get_remote_model() != UserOrdered) {
263 set_remote_control_id_internal (id, notify_class_listeners);
267 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
269 /* force IDs for master/monitor busses and prevent
270 any other route from accidentally getting these IDs
271 (i.e. legacy sessions)
274 if (is_master() && id != MasterBusRemoteControlID) {
275 id = MasterBusRemoteControlID;
278 if (is_monitor() && id != MonitorBusRemoteControlID) {
279 id = MonitorBusRemoteControlID;
286 /* don't allow it to collide */
288 if (!is_master () && !is_monitor() &&
289 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
290 id += MonitorBusRemoteControlID;
293 if (id != remote_control_id()) {
294 _remote_control_id = id;
295 RemoteControlIDChanged ();
297 if (notify_class_listeners) {
298 RemoteControlIDChange ();
304 Route::remote_control_id() const
307 return MasterBusRemoteControlID;
311 return MonitorBusRemoteControlID;
314 return _remote_control_id;
318 Route::has_order_key () const
320 return _has_order_key;
324 Route::order_key () const
330 Route::set_remote_control_id_explicit (uint32_t rid)
332 if (is_master() || is_monitor() || is_auditioner()) {
333 /* hard-coded remote IDs, or no remote ID */
337 if (_remote_control_id != rid) {
338 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
339 _remote_control_id = rid;
340 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
343 /* don't emit the class-level RID signal RemoteControlIDChange here,
344 leave that to the entity that changed the order key, so that we
345 don't get lots of emissions for no good reasons (e.g. when changing
346 all route order keys).
348 See Session::sync_remote_id_from_order_keys() for the (primary|only)
349 spot where that is emitted.
354 Route::set_order_key (uint32_t n)
356 _has_order_key = true;
358 if (_order_key == n) {
364 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
365 name(), order_key ()));
367 _session.set_dirty ();
371 Route::ensure_track_or_route_name(string name, Session &session)
373 string newname = name;
375 while (!session.io_name_is_legal (newname)) {
376 newname = bump_name_once (newname, ' ');
383 Route::inc_gain (gain_t fraction, void *src)
385 _amp->inc_gain (fraction, src);
389 Route::set_gain (gain_t val, void *src)
391 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
393 if (_route_group->is_relative()) {
395 gain_t usable_gain = _amp->gain();
396 if (usable_gain < 0.000001f) {
397 usable_gain = 0.000001f;
401 if (delta < 0.000001f) {
405 delta -= usable_gain;
410 gain_t factor = delta / usable_gain;
413 factor = _route_group->get_max_factor(factor);
414 if (factor == 0.0f) {
415 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
419 factor = _route_group->get_min_factor(factor);
420 if (factor == 0.0f) {
421 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
426 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
430 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
436 if (val == _amp->gain()) {
440 _amp->set_gain (val, src);
444 Route::inc_trim (gain_t fraction, void *src)
446 _trim->inc_gain (fraction, src);
450 Route::set_trim (gain_t val, void * /* src */)
452 // TODO route group, see set_gain()
453 _trim->set_gain (val, 0);
457 Route::maybe_declick (BufferSet&, framecnt_t, int)
459 /* this is the "bus" implementation and they never declick.
464 /** Process this route for one (sub) cycle (process thread)
466 * @param bufs Scratch buffers to use for the signal path
467 * @param start_frame Initial transport frame
468 * @param end_frame Final transport frame
469 * @param nframes Number of frames to output (to ports)
471 * Note that (end_frame - start_frame) may not be equal to nframes when the
472 * transport speed isn't 1.0 (eg varispeed).
475 Route::process_output_buffers (BufferSet& bufs,
476 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
477 int declick, bool gain_automation_ok)
479 /* Caller must hold process lock */
480 assert (!AudioEngine::instance()->process_lock().trylock());
482 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
484 // can this actually happen? functions calling process_output_buffers()
485 // already take a reader-lock.
486 bufs.silence (nframes, 0);
490 /* figure out if we're going to use gain automation */
491 if (gain_automation_ok) {
492 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
493 _amp->setup_gain_automation (
494 start_frame + _signal_latency_at_amp_position,
495 end_frame + _signal_latency_at_amp_position,
498 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
499 _trim->setup_gain_automation (
500 start_frame + _signal_latency_at_trim_position,
501 end_frame + _signal_latency_at_trim_position,
504 _amp->apply_gain_automation (false);
505 _trim->apply_gain_automation (false);
508 /* Tell main outs what to do about monitoring. We do this so that
509 on a transition between monitoring states we get a de-clicking gain
510 change in the _main_outs delivery, if config.get_use_monitor_fades()
513 We override this in the case where we have an internal generator.
515 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
517 _main_outs->no_outs_cuz_we_no_monitor (silence);
519 /* -------------------------------------------------------------------------------------------
520 GLOBAL DECLICK (for transport changes etc.)
521 ----------------------------------------------------------------------------------------- */
523 maybe_declick (bufs, nframes, declick);
524 _pending_declick = 0;
526 /* -------------------------------------------------------------------------------------------
527 DENORMAL CONTROL/PHASE INVERT
528 ----------------------------------------------------------------------------------------- */
530 if (_phase_invert.any ()) {
534 if (_denormal_protection || Config->get_denormal_protection()) {
536 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
537 Sample* const sp = i->data();
539 if (_phase_invert[chn]) {
540 for (pframes_t nx = 0; nx < nframes; ++nx) {
545 for (pframes_t nx = 0; nx < nframes; ++nx) {
553 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
554 Sample* const sp = i->data();
556 if (_phase_invert[chn]) {
557 for (pframes_t nx = 0; nx < nframes; ++nx) {
566 if (_denormal_protection || Config->get_denormal_protection()) {
568 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
569 Sample* const sp = i->data();
570 for (pframes_t nx = 0; nx < nframes; ++nx) {
578 /* -------------------------------------------------------------------------------------------
580 ----------------------------------------------------------------------------------------- */
582 /* set this to be true if the meter will already have been ::run() earlier */
583 bool const meter_already_run = metering_state() == MeteringInput;
585 framecnt_t latency = 0;
587 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
589 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
590 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
595 /* if it has any inputs, make sure they match */
596 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
597 if (bufs.count() != (*i)->input_streams()) {
599 DEBUG::Processors, string_compose (
600 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
601 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
608 /* should we NOT run plugins here if the route is inactive?
609 do we catch route != active somewhere higher?
612 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
613 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
616 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
617 bufs.set_count ((*i)->output_streams());
619 if ((*i)->active ()) {
620 latency += (*i)->signal_latency ();
626 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
627 boost::shared_ptr<Processor> endpoint,
628 bool include_endpoint, bool for_export, bool for_freeze)
630 /* If no processing is required, there's no need to go any further. */
631 if (!endpoint && !include_endpoint) {
635 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
636 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
637 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
639 /* trim is always at the top, for bounce no latency compensation is needed */
640 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
641 _trim->setup_gain_automation (start, start + nframes, nframes);
644 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
646 if (!include_endpoint && (*i) == endpoint) {
650 /* if we're not exporting, stop processing if we come across a routing processor. */
651 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
654 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
658 /* don't run any processors that does routing.
659 * oh, and don't bother with the peak meter either.
661 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
662 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
663 buffers.set_count ((*i)->output_streams());
664 latency += (*i)->signal_latency ();
667 if ((*i) == endpoint) {
674 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
675 bool include_endpoint, bool for_export, bool for_freeze) const
677 framecnt_t latency = 0;
678 if (!endpoint && !include_endpoint) {
682 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
683 if (!include_endpoint && (*i) == endpoint) {
686 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
689 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
692 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
693 latency += (*i)->signal_latency ();
695 if ((*i) == endpoint) {
703 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
704 bool include_endpoint, bool for_export, bool for_freeze) const
706 if (!endpoint && !include_endpoint) {
710 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
711 if (!include_endpoint && (*i) == endpoint) {
714 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
717 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
720 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
721 cc = (*i)->output_streams();
723 if ((*i) == endpoint) {
731 Route::n_process_buffers ()
733 return max (_input->n_ports(), processor_max_streams);
737 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
739 assert (is_monitor());
740 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
741 fill_buffers_with_input (bufs, _input, nframes);
742 passthru (bufs, start_frame, end_frame, nframes, declick);
746 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
750 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
752 /* control/monitor bus ignores input ports when something is
753 feeding the listen "stream". data will "arrive" into the
754 route from the intreturn processor element.
757 bufs.silence (nframes, 0);
760 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
761 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
765 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
767 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
769 bufs.set_count (_input->n_ports());
770 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
771 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
775 Route::set_listen (bool yn, void* src, bool group_override)
781 bool group_active = _route_group && _route_group->is_active() && _route_group->is_solo();
782 if (group_override && _route_group) {
783 group_active = !group_active;
786 if (_route_group && src != _route_group && group_active) {
787 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group, group_override));
792 if (yn != _monitor_send->active()) {
794 _monitor_send->activate ();
795 _mute_master->set_soloed_by_self (true);
797 _monitor_send->deactivate ();
798 _mute_master->set_soloed_by_self (false);
800 _mute_master->set_soloed_by_others (false);
802 listen_changed (src, group_override); /* EMIT SIGNAL */
808 Route::listening_via_monitor () const
811 return _monitor_send->active ();
818 Route::set_solo_safe (bool yn, void *src)
820 if (_solo_safe != yn) {
822 solo_safe_changed (src);
827 Route::solo_safe() const
833 Route::clear_all_solo_state ()
835 // ideally this function will never do anything, it only exists to forestall Murphy
836 bool emit_changed = false;
839 // these are really debug messages, but of possible interest.
841 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
843 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
844 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
845 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
849 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
850 // if self-soled, set_solo() will do signal emission
854 _soloed_by_others_upstream = 0;
855 _soloed_by_others_downstream = 0;
858 PBD::Unwinder<bool> uw (_solo_safe, false);
859 set_solo (false, this);
863 set_mute_master_solo ();
864 solo_changed (false, this, false); /* EMIT SIGNAL */
869 Route::set_solo (bool yn, void *src, bool group_override)
872 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
876 if (is_master() || is_monitor() || is_auditioner()) {
877 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
881 bool group_active = _route_group && _route_group->is_active() && _route_group->is_solo();
882 if (group_override && _route_group) {
883 group_active = !group_active;
885 if (_route_group && src != _route_group && group_active) {
886 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group, group_override));
890 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
891 name(), yn, src, (src == _route_group), self_soloed()));
893 if (self_soloed() != yn) {
895 solo_changed (true, src, group_override); /* EMIT SIGNAL */
896 _solo_control->Changed (); /* EMIT SIGNAL */
899 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
901 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
902 Config->get_solo_mute_overrride().
905 if (yn && Profile->get_trx()) {
906 set_mute (false, src);
911 Route::set_self_solo (bool yn)
913 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
915 set_mute_master_solo ();
919 Route::mod_solo_by_others_upstream (int32_t delta)
921 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
922 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
924 uint32_t old_sbu = _soloed_by_others_upstream;
927 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
928 _soloed_by_others_upstream += delta;
930 _soloed_by_others_upstream = 0;
933 _soloed_by_others_upstream += delta;
936 DEBUG_TRACE (DEBUG::Solo, string_compose (
937 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
938 name(), delta, _soloed_by_others_upstream, old_sbu,
939 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
941 /* push the inverse solo change to everything that feeds us.
943 This is important for solo-within-group. When we solo 1 track out of N that
944 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
945 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
946 tracks that feed it. This will silence them if they were audible because
947 of a bus solo, but the newly soloed track will still be audible (because
950 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
954 if ((_self_solo || _soloed_by_others_downstream) &&
955 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
956 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
958 if (delta > 0 || !Config->get_exclusive_solo()) {
959 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
960 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
964 boost::shared_ptr<Route> sr = i->r.lock();
966 sr->mod_solo_by_others_downstream (-delta);
972 set_mute_master_solo ();
973 solo_changed (false, this, false); /* EMIT SIGNAL */
977 Route::mod_solo_by_others_downstream (int32_t delta)
979 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
980 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
983 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
984 _soloed_by_others_downstream += delta;
986 _soloed_by_others_downstream = 0;
989 _soloed_by_others_downstream += delta;
992 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
994 set_mute_master_solo ();
995 solo_changed (false, this, false); /* EMIT SIGNAL */
999 Route::set_mute_master_solo ()
1001 _mute_master->set_soloed_by_self (self_soloed());
1002 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1006 Route::mod_solo_isolated_by_upstream (bool yn, void* src)
1008 bool old = solo_isolated ();
1009 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1010 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1013 if (_solo_isolated_by_upstream >= 1) {
1014 _solo_isolated_by_upstream--;
1016 _solo_isolated_by_upstream = 0;
1019 _solo_isolated_by_upstream++;
1022 if (solo_isolated() != old) {
1023 /* solo isolated status changed */
1024 _mute_master->set_solo_ignore (solo_isolated());
1025 solo_isolated_changed (src); /* EMIT SIGNAL */
1030 Route::set_solo_isolated (bool yn, void *src)
1032 if (is_master() || is_monitor() || is_auditioner()) {
1036 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
1037 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
1041 bool changed = false;
1044 if (_solo_isolated == false) {
1045 _mute_master->set_solo_ignore (true);
1048 _solo_isolated = true;
1050 if (_solo_isolated == true) {
1051 _solo_isolated = false;
1052 _mute_master->set_solo_ignore (false);
1062 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1064 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1065 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1067 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1072 bool does_feed = feeds (*i, &sends_only);
1074 if (does_feed && !sends_only) {
1075 (*i)->mod_solo_isolated_by_upstream (yn, src);
1079 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1081 solo_isolated_changed (src); /* EMIT SIGNAL */
1085 Route::solo_isolated () const
1087 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1091 Route::set_mute_points (MuteMaster::MutePoint mp)
1093 _mute_master->set_mute_points (mp);
1094 mute_points_changed (); /* EMIT SIGNAL */
1096 if (_mute_master->muted_by_self()) {
1097 mute_changed (this); /* EMIT SIGNAL */
1098 _mute_control->Changed (); /* EMIT SIGNAL */
1103 Route::set_mute (bool yn, void *src)
1105 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
1106 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
1110 if (muted() != yn) {
1111 _mute_master->set_muted_by_self (yn);
1112 /* allow any derived classes to respond to the mute change
1113 before anybody else knows about it.
1116 /* tell everyone else */
1117 mute_changed (src); /* EMIT SIGNAL */
1118 _mute_control->Changed (); /* EMIT SIGNAL */
1123 Route::muted () const
1125 return _mute_master->muted_by_self();
1129 Route::muted_by_others () const
1131 // This method is only used by route_ui for display state.
1132 // The real thing is MuteMaster::muted_by_others_at()
1134 //master is never muted by others
1138 //now check to see if something is soloed (and I am not)
1139 //see also MuteMaster::mute_gain_at()
1140 return (_session.soloing() && !soloed() && !solo_isolated());
1145 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1147 cerr << name << " {" << endl;
1148 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1149 p != procs.end(); ++p) {
1150 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1152 cerr << "}" << endl;
1156 /** Supposing that we want to insert a Processor at a given Placement, return
1157 * the processor to add the new one before (or 0 to add at the end).
1159 boost::shared_ptr<Processor>
1160 Route::before_processor_for_placement (Placement p)
1162 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1164 ProcessorList::iterator loc;
1166 if (p == PreFader) {
1167 /* generic pre-fader: insert immediately before the amp */
1168 loc = find (_processors.begin(), _processors.end(), _amp);
1170 /* generic post-fader: insert right before the main outs */
1171 loc = find (_processors.begin(), _processors.end(), _main_outs);
1174 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1177 /** Supposing that we want to insert a Processor at a given index, return
1178 * the processor to add the new one before (or 0 to add at the end).
1180 boost::shared_ptr<Processor>
1181 Route::before_processor_for_index (int index)
1184 return boost::shared_ptr<Processor> ();
1187 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1189 ProcessorList::iterator i = _processors.begin ();
1191 while (i != _processors.end() && j < index) {
1192 if ((*i)->display_to_user()) {
1199 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1202 /** Add a processor either pre- or post-fader
1203 * @return 0 on success, non-0 on failure.
1206 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1208 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1212 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1213 * @param index Index to add the processor at, or -1 to add at the end of the list.
1214 * @return 0 on success, non-0 on failure.
1217 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1219 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1222 /** Add a processor to the route.
1223 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1224 * @return 0 on success, non-0 on failure.
1227 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1229 assert (processor != _meter);
1230 assert (processor != _main_outs);
1232 DEBUG_TRACE (DEBUG::Processors, string_compose (
1233 "%1 adding processor %2\n", name(), processor->name()));
1235 if (!AudioEngine::instance()->connected() || !processor) {
1240 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1241 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1242 ProcessorState pstate (this);
1244 boost::shared_ptr<PluginInsert> pi;
1245 boost::shared_ptr<PortInsert> porti;
1247 if (processor == _amp) {
1248 /* Ensure that only one amp is in the list at any time */
1249 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1250 if (check != _processors.end()) {
1251 if (before == _amp) {
1252 /* Already in position; all is well */
1255 _processors.erase (check);
1260 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1262 ProcessorList::iterator loc;
1264 /* inserting before a processor; find it */
1265 loc = find (_processors.begin(), _processors.end(), before);
1266 if (loc == _processors.end ()) {
1271 /* inserting at end */
1272 loc = _processors.end ();
1275 _processors.insert (loc, processor);
1276 processor->set_owner (this);
1278 // Set up processor list channels. This will set processor->[input|output]_streams(),
1279 // configure redirect ports properly, etc.
1282 if (configure_processors_unlocked (err)) {
1284 configure_processors_unlocked (0); // it worked before we tried to add it ...
1289 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1291 if (pi->has_no_inputs ()) {
1292 /* generator plugin */
1293 _have_internal_generator = true;
1298 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1299 processor->activate ();
1302 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1304 _output->set_user_latency (0);
1307 reset_instrument_info ();
1308 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1309 set_processor_positions ();
1315 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1317 const XMLProperty *prop;
1320 boost::shared_ptr<Processor> processor;
1322 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1323 so that we can add the processor in the right place (pre/post-fader)
1326 XMLNodeList const & children = node.children ();
1327 XMLNodeList::const_iterator i = children.begin ();
1329 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1333 Placement placement = PreFader;
1335 if (i != children.end()) {
1336 if ((prop = (*i)->property (X_("placement"))) != 0) {
1337 placement = Placement (string_2_enum (prop->value(), placement));
1341 if (node.name() == "Insert") {
1343 if ((prop = node.property ("type")) != 0) {
1345 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1346 prop->value() == "lv2" ||
1347 prop->value() == "windows-vst" ||
1348 prop->value() == "lxvst" ||
1349 prop->value() == "audiounit") {
1351 if (_session.get_disable_all_loaded_plugins ()) {
1352 processor.reset (new UnknownProcessor (_session, node));
1354 processor.reset (new PluginInsert (_session));
1359 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1364 } else if (node.name() == "Send") {
1366 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1367 processor.reset (new Send (_session, sendpan, _mute_master));
1371 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1375 if (processor->set_state (node, version)) {
1379 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1380 if (i != children.end()) {
1381 if ((prop = (*i)->property (X_("active"))) != 0) {
1382 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1383 processor->activate();
1385 processor->deactivate();
1389 return (add_processor (processor, placement, 0, false) == 0);
1392 catch (failed_constructor &err) {
1393 warning << _("processor could not be created. Ignored.") << endmsg;
1399 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1401 /* NOTE: this is intended to be used ONLY when copying
1402 processors from another Route. Hence the subtle
1403 differences between this and ::add_processor()
1406 ProcessorList::iterator loc;
1409 loc = find(_processors.begin(), _processors.end(), before);
1411 /* nothing specified - at end */
1412 loc = _processors.end ();
1415 if (!_session.engine().connected()) {
1419 if (others.empty()) {
1424 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1425 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1426 ProcessorState pstate (this);
1428 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1434 boost::shared_ptr<PluginInsert> pi;
1436 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1440 _processors.insert (loc, *i);
1441 (*i)->set_owner (this);
1443 if ((*i)->active()) {
1447 /* Think: does this really need to be called for every processor in the loop? */
1449 if (configure_processors_unlocked (err)) {
1451 configure_processors_unlocked (0); // it worked before we tried to add it ...
1456 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1459 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1460 boost::shared_ptr<PluginInsert> pi;
1462 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1463 if (pi->has_no_inputs ()) {
1464 _have_internal_generator = true;
1470 _output->set_user_latency (0);
1473 reset_instrument_info ();
1474 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1475 set_processor_positions ();
1481 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1483 if (p == PreFader) {
1484 start = _processors.begin();
1485 end = find(_processors.begin(), _processors.end(), _amp);
1487 start = find(_processors.begin(), _processors.end(), _amp);
1489 end = _processors.end();
1493 /** Turn off all processors with a given placement
1494 * @param p Placement of processors to disable
1497 Route::disable_processors (Placement p)
1499 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1501 ProcessorList::iterator start, end;
1502 placement_range(p, start, end);
1504 for (ProcessorList::iterator i = start; i != end; ++i) {
1505 (*i)->deactivate ();
1508 _session.set_dirty ();
1511 /** Turn off all redirects
1514 Route::disable_processors ()
1516 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1518 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1519 (*i)->deactivate ();
1522 _session.set_dirty ();
1525 /** Turn off all redirects with a given placement
1526 * @param p Placement of redirects to disable
1529 Route::disable_plugins (Placement p)
1531 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1533 ProcessorList::iterator start, end;
1534 placement_range(p, start, end);
1536 for (ProcessorList::iterator i = start; i != end; ++i) {
1537 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1538 (*i)->deactivate ();
1542 _session.set_dirty ();
1545 /** Turn off all plugins
1548 Route::disable_plugins ()
1550 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1552 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1553 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1554 (*i)->deactivate ();
1558 _session.set_dirty ();
1563 Route::ab_plugins (bool forward)
1565 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1569 /* forward = turn off all active redirects, and mark them so that the next time
1570 we go the other way, we will revert them
1573 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1574 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1578 if ((*i)->active()) {
1579 (*i)->deactivate ();
1580 (*i)->set_next_ab_is_active (true);
1582 (*i)->set_next_ab_is_active (false);
1588 /* backward = if the redirect was marked to go active on the next ab, do so */
1590 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1592 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1596 if ((*i)->get_next_ab_is_active()) {
1599 (*i)->deactivate ();
1604 _session.set_dirty ();
1608 /** Remove processors with a given placement.
1609 * @param p Placement of processors to remove.
1612 Route::clear_processors (Placement p)
1614 if (!_session.engine().connected()) {
1618 bool already_deleting = _session.deletion_in_progress();
1619 if (!already_deleting) {
1620 _session.set_deletion_in_progress();
1624 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1625 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1626 ProcessorList new_list;
1627 ProcessorStreams err;
1628 bool seen_amp = false;
1630 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1636 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1638 /* you can't remove these */
1640 new_list.push_back (*i);
1647 new_list.push_back (*i);
1650 (*i)->drop_references ();
1658 (*i)->drop_references ();
1661 new_list.push_back (*i);
1668 _processors = new_list;
1669 configure_processors_unlocked (&err); // this can't fail
1672 processor_max_streams.reset();
1673 _have_internal_generator = false;
1674 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1675 set_processor_positions ();
1677 reset_instrument_info ();
1679 if (!already_deleting) {
1680 _session.clear_deletion_in_progress();
1685 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1687 // TODO once the export point can be configured properly, do something smarter here
1688 if (processor == _capturing_processor) {
1689 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1690 if (need_process_lock) {
1694 _capturing_processor.reset();
1696 if (need_process_lock) {
1701 /* these can never be removed */
1703 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1707 if (!_session.engine().connected()) {
1711 processor_max_streams.reset();
1714 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1715 if (need_process_lock) {
1719 /* Caller must hold process lock */
1720 assert (!AudioEngine::instance()->process_lock().trylock());
1722 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1724 ProcessorState pstate (this);
1726 ProcessorList::iterator i;
1727 bool removed = false;
1729 for (i = _processors.begin(); i != _processors.end(); ) {
1730 if (*i == processor) {
1732 /* move along, see failure case for configure_processors()
1733 where we may need to reconfigure the processor.
1736 /* stop redirects that send signals to JACK ports
1737 from causing noise as a result of no longer being
1741 boost::shared_ptr<IOProcessor> iop;
1743 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1747 i = _processors.erase (i);
1755 _output->set_user_latency (0);
1763 if (configure_processors_unlocked (err)) {
1765 /* we know this will work, because it worked before :) */
1766 configure_processors_unlocked (0);
1770 _have_internal_generator = false;
1772 for (i = _processors.begin(); i != _processors.end(); ++i) {
1773 boost::shared_ptr<PluginInsert> pi;
1775 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1776 if (pi->has_no_inputs ()) {
1777 _have_internal_generator = true;
1782 if (need_process_lock) {
1787 reset_instrument_info ();
1788 processor->drop_references ();
1789 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1790 set_processor_positions ();
1796 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1798 ProcessorList deleted;
1800 if (!_session.engine().connected()) {
1804 processor_max_streams.reset();
1807 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1808 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1809 ProcessorState pstate (this);
1811 ProcessorList::iterator i;
1812 boost::shared_ptr<Processor> processor;
1814 for (i = _processors.begin(); i != _processors.end(); ) {
1818 /* these can never be removed */
1820 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1825 /* see if its in the list of processors to delete */
1827 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1832 /* stop IOProcessors that send to JACK ports
1833 from causing noise as a result of no longer being
1837 boost::shared_ptr<IOProcessor> iop;
1839 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1843 deleted.push_back (processor);
1844 i = _processors.erase (i);
1847 if (deleted.empty()) {
1848 /* none of those in the requested list were found */
1852 _output->set_user_latency (0);
1854 if (configure_processors_unlocked (err)) {
1856 /* we know this will work, because it worked before :) */
1857 configure_processors_unlocked (0);
1862 _have_internal_generator = false;
1864 for (i = _processors.begin(); i != _processors.end(); ++i) {
1865 boost::shared_ptr<PluginInsert> pi;
1867 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1868 if (pi->has_no_inputs ()) {
1869 _have_internal_generator = true;
1876 /* now try to do what we need to so that those that were removed will be deleted */
1878 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1879 (*i)->drop_references ();
1882 reset_instrument_info ();
1883 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1884 set_processor_positions ();
1890 Route::reset_instrument_info ()
1892 boost::shared_ptr<Processor> instr = the_instrument();
1894 _instrument_info.set_internal_instrument (instr);
1898 /** Caller must hold process lock */
1900 Route::configure_processors (ProcessorStreams* err)
1902 #ifndef PLATFORM_WINDOWS
1903 assert (!AudioEngine::instance()->process_lock().trylock());
1906 if (!_in_configure_processors) {
1907 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1908 return configure_processors_unlocked (err);
1915 Route::input_streams () const
1917 return _input->n_ports ();
1920 list<pair<ChanCount, ChanCount> >
1921 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1923 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1925 return try_configure_processors_unlocked (in, err);
1928 list<pair<ChanCount, ChanCount> >
1929 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1931 // Check each processor in order to see if we can configure as requested
1933 list<pair<ChanCount, ChanCount> > configuration;
1936 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1937 DEBUG_TRACE (DEBUG::Processors, "{\n");
1939 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1941 if ((*p)->can_support_io_configuration(in, out)) {
1942 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1943 configuration.push_back(make_pair(in, out));
1950 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1951 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1952 DEBUG_TRACE (DEBUG::Processors, "}\n");
1953 return list<pair<ChanCount, ChanCount> > ();
1957 DEBUG_TRACE (DEBUG::Processors, "}\n");
1959 return configuration;
1962 /** Set the input/output configuration of each processor in the processors list.
1963 * Caller must hold process lock.
1964 * Return 0 on success, otherwise configuration is impossible.
1967 Route::configure_processors_unlocked (ProcessorStreams* err)
1969 #ifndef PLATFORM_WINDOWS
1970 assert (!AudioEngine::instance()->process_lock().trylock());
1973 if (_in_configure_processors) {
1977 /* put invisible processors where they should be */
1978 setup_invisible_processors ();
1980 _in_configure_processors = true;
1982 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1984 if (configuration.empty ()) {
1985 _in_configure_processors = false;
1990 bool seen_mains_out = false;
1991 processor_out_streams = _input->n_ports();
1992 processor_max_streams.reset();
1994 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1995 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1997 if (!(*p)->configure_io(c->first, c->second)) {
1998 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2000 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2001 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2003 boost::shared_ptr<PluginInsert> pi;
2004 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2005 /* plugins connected via Split Match may have more channels.
2006 * route/scratch buffers are needed for all of them*/
2007 processor_max_streams = ChanCount::max(processor_max_streams, pi->input_streams());
2008 processor_max_streams = ChanCount::max(processor_max_streams, pi->natural_input_streams());
2012 if (boost::dynamic_pointer_cast<Delivery> (*p)
2013 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2014 /* main delivery will increase port count to match input.
2015 * the Delivery::Main is usually the last processor - followed only by
2018 seen_mains_out = true;
2020 if (!seen_mains_out) {
2021 processor_out_streams = out;
2027 _meter->set_max_channels (processor_max_streams);
2030 /* make sure we have sufficient scratch buffers to cope with the new processor
2033 _session.ensure_buffers (n_process_buffers ());
2035 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2037 _in_configure_processors = false;
2041 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2042 * @param state New active state for those processors.
2045 Route::all_visible_processors_active (bool state)
2047 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2049 if (_processors.empty()) {
2053 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2054 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2061 (*i)->deactivate ();
2065 _session.set_dirty ();
2069 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2071 /* check if re-order requires re-configuration of any processors
2072 * -> compare channel configuration for all processors
2074 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2075 ChanCount c = input_streams ();
2077 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2079 if (c != (*j)->input_streams()) {
2082 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2085 if ((*i)->input_streams() != c) {
2088 c = (*i)->output_streams();
2100 __attribute__((annotate("realtime")))
2103 Route::apply_processor_order (const ProcessorList& new_order)
2105 /* need to hold processor_lock; either read or write lock
2106 * and the engine process_lock.
2107 * Due to r/w lock ambiguity we can only assert the latter
2109 assert (!AudioEngine::instance()->process_lock().trylock());
2112 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2113 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2114 * processors in the current actual processor list that are hidden. Any visible processors
2115 * in the current list but not in "new_order" will be assumed to be deleted.
2118 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2119 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2120 * (note though that ::processors_reorder_needs_configure() ensured that
2121 * this function will only ever be called from the rt-thread if no processor were removed)
2123 * either way, I can't proove it, but an x-run due to re-order here is less likley
2124 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2127 ProcessorList as_it_will_be;
2128 ProcessorList::iterator oiter;
2129 ProcessorList::const_iterator niter;
2131 oiter = _processors.begin();
2132 niter = new_order.begin();
2134 while (niter != new_order.end()) {
2136 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2137 then append it to the temp list.
2139 Otherwise, see if the next processor in the old list is in the new list. if not,
2140 its been deleted. If its there, append it to the temp list.
2143 if (oiter == _processors.end()) {
2145 /* no more elements in the old list, so just stick the rest of
2146 the new order onto the temp list.
2149 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2150 while (niter != new_order.end()) {
2157 if (!(*oiter)->display_to_user()) {
2159 as_it_will_be.push_back (*oiter);
2163 /* visible processor: check that its in the new order */
2165 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2166 /* deleted: do nothing, shared_ptr<> will clean up */
2168 /* ignore this one, and add the next item from the new order instead */
2169 as_it_will_be.push_back (*niter);
2174 /* now remove from old order - its taken care of no matter what */
2175 oiter = _processors.erase (oiter);
2179 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2181 /* If the meter is in a custom position, find it and make a rough note of its position */
2182 maybe_note_meter_position ();
2186 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2188 // it a change is already queued, wait for it
2189 // (unless engine is stopped. apply immediately and proceed
2190 while (g_atomic_int_get (&_pending_process_reorder)) {
2191 if (!AudioEngine::instance()->running()) {
2192 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2193 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2195 apply_processor_order(_pending_processor_order);
2196 setup_invisible_processors ();
2198 g_atomic_int_set (&_pending_process_reorder, 0);
2200 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2201 set_processor_positions ();
2203 // TODO rather use a semaphore or something.
2204 // but since ::reorder_processors() is called
2205 // from the GUI thread, this is fine..
2210 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2212 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2213 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2214 ProcessorState pstate (this);
2216 apply_processor_order (new_order);
2218 if (configure_processors_unlocked (err)) {
2226 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2227 set_processor_positions ();
2230 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2231 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2233 // _pending_processor_order is protected by _processor_lock
2234 _pending_processor_order = new_order;
2235 g_atomic_int_set (&_pending_process_reorder, 1);
2248 Route::get_template()
2250 return state(false);
2254 Route::state(bool full_state)
2256 if (!_session._template_state_dir.empty()) {
2257 assert (!full_state); // only for templates
2258 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2261 XMLNode *node = new XMLNode("Route");
2262 ProcessorList::iterator i;
2265 id().print (buf, sizeof (buf));
2266 node->add_property("id", buf);
2267 node->add_property ("name", _name);
2268 node->add_property("default-type", _default_type.to_string());
2271 node->add_property("flags", enum_2_string (_flags));
2274 node->add_property("active", _active?"yes":"no");
2276 boost::to_string (_phase_invert, p);
2277 node->add_property("phase-invert", p);
2278 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2279 node->add_property("meter-point", enum_2_string (_meter_point));
2281 node->add_property("meter-type", enum_2_string (_meter_type));
2284 node->add_property("route-group", _route_group->name());
2287 snprintf (buf, sizeof (buf), "%d", _order_key);
2288 node->add_property ("order-key", buf);
2289 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2290 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2291 node->add_property ("soloed-by-upstream", buf);
2292 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2293 node->add_property ("soloed-by-downstream", buf);
2294 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2295 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2297 node->add_child_nocopy (_input->state (full_state));
2298 node->add_child_nocopy (_output->state (full_state));
2299 node->add_child_nocopy (_solo_control->get_state ());
2300 node->add_child_nocopy (_mute_control->get_state ());
2301 node->add_child_nocopy (_mute_master->get_state ());
2304 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2307 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2308 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2309 remote_control_node->add_property (X_("id"), buf);
2310 node->add_child_nocopy (*remote_control_node);
2312 if (_comment.length()) {
2313 XMLNode *cmt = node->add_child ("Comment");
2314 cmt->add_content (_comment);
2318 node->add_child_nocopy (_pannable->state (full_state));
2321 for (i = _processors.begin(); i != _processors.end(); ++i) {
2323 /* template save: do not include internal sends functioning as
2324 aux sends because the chance of the target ID
2325 in the session where this template is used
2328 similarly, do not save listen sends which connect to
2329 the monitor section, because these will always be
2332 boost::shared_ptr<InternalSend> is;
2334 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2335 if (is->role() == Delivery::Listen) {
2340 node->add_child_nocopy((*i)->state (full_state));
2344 node->add_child_copy (*_extra_xml);
2347 if (_custom_meter_position_noted) {
2348 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2350 after->id().print (buf, sizeof (buf));
2351 node->add_property (X_("processor-after-last-custom-meter"), buf);
2355 if (!_session._template_state_dir.empty()) {
2356 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2363 Route::set_state (const XMLNode& node, int version)
2365 if (version < 3000) {
2366 return set_state_2X (node, version);
2370 XMLNodeConstIterator niter;
2372 const XMLProperty *prop;
2374 if (node.name() != "Route"){
2375 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2379 if ((prop = node.property (X_("name"))) != 0) {
2380 Route::set_name (prop->value());
2384 _initial_io_setup = true;
2386 if ((prop = node.property (X_("flags"))) != 0) {
2387 _flags = Flag (string_2_enum (prop->value(), _flags));
2392 if (is_master() || is_monitor() || is_auditioner()) {
2393 _mute_master->set_solo_ignore (true);
2397 /* monitor bus does not get a panner, but if (re)created
2398 via XML, it will already have one by the time we
2399 call ::set_state(). so ... remove it.
2404 /* add all processors (except amp, which is always present) */
2406 nlist = node.children();
2407 XMLNode processor_state (X_("processor_state"));
2409 Stateful::save_extra_xml (node);
2411 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2415 if (child->name() == IO::state_node_name) {
2416 if ((prop = child->property (X_("direction"))) == 0) {
2420 if (prop->value() == "Input") {
2421 _input->set_state (*child, version);
2422 } else if (prop->value() == "Output") {
2423 _output->set_state (*child, version);
2427 if (child->name() == X_("Processor")) {
2428 processor_state.add_child_copy (*child);
2431 if (child->name() == X_("Pannable")) {
2433 _pannable->set_state (*child, version);
2435 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2440 if ((prop = node.property (X_("meter-point"))) != 0) {
2441 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2442 set_meter_point (mp, true);
2444 _meter->set_display_to_user (_meter_point == MeterCustom);
2448 if ((prop = node.property (X_("meter-type"))) != 0) {
2449 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2452 _initial_io_setup = false;
2454 set_processor_state (processor_state);
2456 // this looks up the internal instrument in processors
2457 reset_instrument_info();
2459 if ((prop = node.property ("self-solo")) != 0) {
2460 set_self_solo (string_is_affirmative (prop->value()));
2463 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2464 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2465 mod_solo_by_others_upstream (atoi (prop->value()));
2468 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2469 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2470 mod_solo_by_others_downstream (atoi (prop->value()));
2473 if ((prop = node.property ("solo-isolated")) != 0) {
2474 set_solo_isolated (string_is_affirmative (prop->value()), this);
2477 if ((prop = node.property ("solo-safe")) != 0) {
2478 set_solo_safe (string_is_affirmative (prop->value()), this);
2481 if ((prop = node.property (X_("phase-invert"))) != 0) {
2482 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2485 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2486 set_denormal_protection (string_is_affirmative (prop->value()));
2489 if ((prop = node.property (X_("active"))) != 0) {
2490 bool yn = string_is_affirmative (prop->value());
2491 _active = !yn; // force switch
2492 set_active (yn, this);
2495 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2496 set_order_key (atoi(prop->value()));
2499 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2503 string::size_type colon, equal;
2504 string remaining = prop->value();
2506 while (remaining.length()) {
2508 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2509 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2512 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2513 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2516 string keyname = remaining.substr (0, equal);
2518 if ((keyname == "EditorSort") || (keyname == "editor")) {
2519 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2525 colon = remaining.find_first_of (':');
2527 if (colon != string::npos) {
2528 remaining = remaining.substr (colon+1);
2535 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2536 PBD::ID id (prop->value ());
2537 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2538 ProcessorList::const_iterator i = _processors.begin ();
2539 while (i != _processors.end() && (*i)->id() != id) {
2543 if (i != _processors.end ()) {
2544 _processor_after_last_custom_meter = *i;
2545 _custom_meter_position_noted = true;
2549 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2552 if (child->name() == X_("Comment")) {
2554 /* XXX this is a terrible API design in libxml++ */
2556 XMLNode *cmt = *(child->children().begin());
2557 _comment = cmt->content();
2559 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2560 if (prop->value() == "solo") {
2561 _solo_control->set_state (*child, version);
2562 } else if (prop->value() == "mute") {
2563 _mute_control->set_state (*child, version);
2566 } else if (child->name() == X_("RemoteControl")) {
2567 if ((prop = child->property (X_("id"))) != 0) {
2569 sscanf (prop->value().c_str(), "%d", &x);
2570 set_remote_control_id_internal (x);
2573 } else if (child->name() == X_("MuteMaster")) {
2574 _mute_master->set_state (*child, version);
2576 } else if (child->name() == Automatable::xml_node_name) {
2577 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2585 Route::set_state_2X (const XMLNode& node, int version)
2587 LocaleGuard lg (X_("C"));
2589 XMLNodeConstIterator niter;
2591 const XMLProperty *prop;
2593 /* 2X things which still remain to be handled:
2599 if (node.name() != "Route") {
2600 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2604 if ((prop = node.property (X_("flags"))) != 0) {
2605 string f = prop->value ();
2606 boost::replace_all (f, "ControlOut", "MonitorOut");
2607 _flags = Flag (string_2_enum (f, _flags));
2612 if (is_master() || is_monitor() || is_auditioner()) {
2613 _mute_master->set_solo_ignore (true);
2616 if ((prop = node.property (X_("phase-invert"))) != 0) {
2617 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2618 if (string_is_affirmative (prop->value ())) {
2621 set_phase_invert (p);
2624 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2625 set_denormal_protection (string_is_affirmative (prop->value()));
2628 if ((prop = node.property (X_("soloed"))) != 0) {
2629 bool yn = string_is_affirmative (prop->value());
2631 /* XXX force reset of solo status */
2633 set_solo (yn, this);
2636 if ((prop = node.property (X_("muted"))) != 0) {
2639 bool muted = string_is_affirmative (prop->value());
2645 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2647 if (string_is_affirmative (prop->value())){
2648 mute_point = mute_point + "PreFader";
2653 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2655 if (string_is_affirmative (prop->value())){
2658 mute_point = mute_point + ",";
2661 mute_point = mute_point + "PostFader";
2666 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2668 if (string_is_affirmative (prop->value())){
2671 mute_point = mute_point + ",";
2674 mute_point = mute_point + "Listen";
2679 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2681 if (string_is_affirmative (prop->value())){
2684 mute_point = mute_point + ",";
2687 mute_point = mute_point + "Main";
2691 _mute_master->set_mute_points (mute_point);
2692 _mute_master->set_muted_by_self (true);
2696 if ((prop = node.property (X_("meter-point"))) != 0) {
2697 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2700 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2701 don't mean the same thing.
2704 if ((prop = node.property (X_("order-keys"))) != 0) {
2708 string::size_type colon, equal;
2709 string remaining = prop->value();
2711 while (remaining.length()) {
2713 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2714 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2717 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2718 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2721 string keyname = remaining.substr (0, equal);
2723 if (keyname == "EditorSort" || keyname == "editor") {
2724 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2730 colon = remaining.find_first_of (':');
2732 if (colon != string::npos) {
2733 remaining = remaining.substr (colon+1);
2742 nlist = node.children ();
2743 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2747 if (child->name() == IO::state_node_name) {
2749 /* there is a note in IO::set_state_2X() about why we have to call
2753 _input->set_state_2X (*child, version, true);
2754 _output->set_state_2X (*child, version, false);
2756 if ((prop = child->property (X_("name"))) != 0) {
2757 Route::set_name (prop->value ());
2762 if ((prop = child->property (X_("active"))) != 0) {
2763 bool yn = string_is_affirmative (prop->value());
2764 _active = !yn; // force switch
2765 set_active (yn, this);
2768 if ((prop = child->property (X_("gain"))) != 0) {
2771 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2772 _amp->gain_control()->set_value (val);
2776 /* Set up Panners in the IO */
2777 XMLNodeList io_nlist = child->children ();
2779 XMLNodeConstIterator io_niter;
2782 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2784 io_child = *io_niter;
2786 if (io_child->name() == X_("Panner")) {
2787 _main_outs->panner_shell()->set_state(*io_child, version);
2788 } else if (io_child->name() == X_("Automation")) {
2789 /* IO's automation is for the fader */
2790 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2796 XMLNodeList redirect_nodes;
2798 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2802 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2803 redirect_nodes.push_back(child);
2808 set_processor_state_2X (redirect_nodes, version);
2810 Stateful::save_extra_xml (node);
2812 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2815 if (child->name() == X_("Comment")) {
2817 /* XXX this is a terrible API design in libxml++ */
2819 XMLNode *cmt = *(child->children().begin());
2820 _comment = cmt->content();
2822 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2823 if (prop->value() == X_("solo")) {
2824 _solo_control->set_state (*child, version);
2825 } else if (prop->value() == X_("mute")) {
2826 _mute_control->set_state (*child, version);
2829 } else if (child->name() == X_("RemoteControl")) {
2830 if ((prop = child->property (X_("id"))) != 0) {
2832 sscanf (prop->value().c_str(), "%d", &x);
2833 set_remote_control_id_internal (x);
2843 Route::get_processor_state ()
2845 XMLNode* root = new XMLNode (X_("redirects"));
2846 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2847 root->add_child_nocopy ((*i)->state (true));
2854 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2856 /* We don't bother removing existing processors not in nList, as this
2857 method will only be called when creating a Route from scratch, not
2858 for undo purposes. Just put processors in at the appropriate place
2862 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2863 add_processor_from_xml_2X (**i, version);
2868 Route::set_processor_state (const XMLNode& node)
2870 const XMLNodeList &nlist = node.children();
2871 XMLNodeConstIterator niter;
2872 ProcessorList new_order;
2873 bool must_configure = false;
2875 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2877 XMLProperty* prop = (*niter)->property ("type");
2879 if (prop->value() == "amp") {
2880 _amp->set_state (**niter, Stateful::current_state_version);
2881 new_order.push_back (_amp);
2882 } else if (prop->value() == "trim") {
2883 _trim->set_state (**niter, Stateful::current_state_version);
2884 new_order.push_back (_trim);
2885 } else if (prop->value() == "meter") {
2886 _meter->set_state (**niter, Stateful::current_state_version);
2887 new_order.push_back (_meter);
2888 } else if (prop->value() == "delay") {
2890 _delayline->set_state (**niter, Stateful::current_state_version);
2891 new_order.push_back (_delayline);
2893 } else if (prop->value() == "main-outs") {
2894 _main_outs->set_state (**niter, Stateful::current_state_version);
2895 } else if (prop->value() == "intreturn") {
2897 _intreturn.reset (new InternalReturn (_session));
2898 must_configure = true;
2900 _intreturn->set_state (**niter, Stateful::current_state_version);
2901 } else if (is_monitor() && prop->value() == "monitor") {
2902 if (!_monitor_control) {
2903 _monitor_control.reset (new MonitorProcessor (_session));
2904 must_configure = true;
2906 _monitor_control->set_state (**niter, Stateful::current_state_version);
2907 } else if (prop->value() == "capture") {
2908 /* CapturingProcessor should never be restored, it's always
2909 added explicitly when needed */
2911 ProcessorList::iterator o;
2913 for (o = _processors.begin(); o != _processors.end(); ++o) {
2914 XMLProperty* id_prop = (*niter)->property(X_("id"));
2915 if (id_prop && (*o)->id() == id_prop->value()) {
2916 (*o)->set_state (**niter, Stateful::current_state_version);
2917 new_order.push_back (*o);
2922 // If the processor (*niter) is not on the route then create it
2924 if (o == _processors.end()) {
2926 boost::shared_ptr<Processor> processor;
2928 if (prop->value() == "intsend") {
2930 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2932 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2933 prop->value() == "lv2" ||
2934 prop->value() == "windows-vst" ||
2935 prop->value() == "lxvst" ||
2936 prop->value() == "audiounit") {
2938 if (_session.get_disable_all_loaded_plugins ()) {
2939 processor.reset (new UnknownProcessor (_session, **niter));
2941 processor.reset (new PluginInsert (_session));
2943 } else if (prop->value() == "port") {
2945 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2947 } else if (prop->value() == "send") {
2949 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2952 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2956 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2957 /* This processor could not be configured. Turn it into a UnknownProcessor */
2958 processor.reset (new UnknownProcessor (_session, **niter));
2961 /* we have to note the monitor send here, otherwise a new one will be created
2962 and the state of this one will be lost.
2964 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2965 if (isend && isend->role() == Delivery::Listen) {
2966 _monitor_send = isend;
2969 /* it doesn't matter if invisible processors are added here, as they
2970 will be sorted out by setup_invisible_processors () shortly.
2973 new_order.push_back (processor);
2974 must_configure = true;
2980 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2981 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2982 _processors = new_order;
2984 if (must_configure) {
2985 configure_processors_unlocked (0);
2988 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2990 (*i)->set_owner (this);
2991 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2993 boost::shared_ptr<PluginInsert> pi;
2995 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2996 if (pi->has_no_inputs ()) {
2997 _have_internal_generator = true;
3004 reset_instrument_info ();
3005 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3006 set_processor_positions ();
3010 Route::curve_reallocate ()
3012 // _gain_automation_curve.finish_resize ();
3013 // _pan_automation_curve.finish_resize ();
3017 Route::silence (framecnt_t nframes)
3019 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3024 silence_unlocked (nframes);
3028 Route::silence_unlocked (framecnt_t nframes)
3030 /* Must be called with the processor lock held */
3034 _output->silence (nframes);
3036 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3037 boost::shared_ptr<PluginInsert> pi;
3039 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3040 // skip plugins, they don't need anything when we're not active
3044 (*i)->silence (nframes);
3047 if (nframes == _session.get_block_size()) {
3054 Route::add_internal_return ()
3057 _intreturn.reset (new InternalReturn (_session));
3058 add_processor (_intreturn, PreFader);
3063 Route::add_send_to_internal_return (InternalSend* send)
3065 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3067 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3068 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3071 return d->add_send (send);
3077 Route::remove_send_from_internal_return (InternalSend* send)
3079 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3081 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3082 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3085 return d->remove_send (send);
3091 Route::enable_monitor_send ()
3093 /* Caller must hold process lock */
3094 assert (!AudioEngine::instance()->process_lock().trylock());
3096 /* master never sends to monitor section via the normal mechanism */
3097 assert (!is_master ());
3098 assert (!is_monitor ());
3100 /* make sure we have one */
3101 if (!_monitor_send) {
3102 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3103 _monitor_send->set_display_to_user (false);
3107 configure_processors (0);
3110 /** Add an aux send to a route.
3111 * @param route route to send to.
3112 * @param before Processor to insert before, or 0 to insert at the end.
3115 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3117 assert (route != _session.monitor_out ());
3120 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3122 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3124 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3126 if (d && d->target_route() == route) {
3127 /* already listening via the specified IO: do nothing */
3135 boost::shared_ptr<InternalSend> listener;
3138 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3139 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3140 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3143 add_processor (listener, before);
3145 } catch (failed_constructor& err) {
3153 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3155 ProcessorStreams err;
3156 ProcessorList::iterator tmp;
3159 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3161 /* have to do this early because otherwise processor reconfig
3162 * will put _monitor_send back in the list
3165 if (route == _session.monitor_out()) {
3166 _monitor_send.reset ();
3170 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3172 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3174 if (d && d->target_route() == route) {
3176 if (remove_processor (*x, &err, false) > 0) {
3182 /* list could have been demolished while we dropped the lock
3185 if (_session.engine().connected()) {
3186 /* i/o processors cannot be removed if the engine is not running
3187 * so don't live-loop in case the engine is N/A or dies
3197 Route::set_comment (string cmt, void *src)
3200 comment_changed (src);
3201 _session.set_dirty ();
3205 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3207 FeedRecord fr (other, via_sends_only);
3209 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3211 if (!result.second) {
3213 /* already a record for "other" - make sure sends-only information is correct */
3214 if (!via_sends_only && result.first->sends_only) {
3215 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3216 frp->sends_only = false;
3220 return result.second;
3224 Route::clear_fed_by ()
3230 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3232 const FedBy& fed_by (other->fed_by());
3234 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3235 boost::shared_ptr<Route> sr = f->r.lock();
3237 if (sr && (sr.get() == this)) {
3239 if (via_sends_only) {
3240 *via_sends_only = f->sends_only;
3251 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3253 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3255 if (_output->connected_to (other->input())) {
3256 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3257 if (via_send_only) {
3258 *via_send_only = false;
3265 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3267 boost::shared_ptr<IOProcessor> iop;
3269 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3270 if (iop->feeds (other)) {
3271 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3272 if (via_send_only) {
3273 *via_send_only = true;
3277 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3280 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3285 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3290 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3292 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3295 /** Called from the (non-realtime) butler thread when the transport is stopped */
3297 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3299 framepos_t now = _session.transport_frame();
3302 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3304 Automatable::transport_stopped (now);
3306 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3308 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3312 (*i)->transport_stopped (now);
3316 _roll_delay = _initial_delay;
3320 Route::input_change_handler (IOChange change, void * /*src*/)
3322 if ((change.type & IOChange::ConfigurationChanged)) {
3323 /* This is called with the process lock held if change
3324 contains ConfigurationChanged
3326 configure_processors (0);
3327 _phase_invert.resize (_input->n_ports().n_audio ());
3328 io_changed (); /* EMIT SIGNAL */
3331 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3334 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3335 if (_input->connected()) {
3336 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3337 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3341 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3342 if (does_feed && !sends_only) {
3343 if ((*i)->soloed()) {
3346 if ((*i)->solo_isolated()) {
3353 int delta = sbou - _soloed_by_others_upstream;
3354 int idelta = ibou - _solo_isolated_by_upstream;
3357 PBD::warning << string_compose (
3358 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3359 _name, ibou, _solo_isolated_by_upstream, idelta)
3364 if (_soloed_by_others_upstream) {
3365 // ignore new connections (they're not propagated)
3367 mod_solo_by_others_upstream (delta);
3371 if (_solo_isolated_by_upstream) {
3372 // solo-isolate currently only propagates downstream
3374 mod_solo_isolated_by_upstream (false, this);
3376 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3377 // but idelta can't be smaller than -1, can it?
3378 //_solo_isolated_by_upstream = ibou;
3381 // Session::route_solo_changed does not propagate indirect solo-changes
3382 // propagate downstream to tracks
3383 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3384 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3388 bool does_feed = feeds (*i, &sends_only);
3389 if (delta <= 0 && does_feed && !sends_only) {
3390 (*i)->mod_solo_by_others_upstream (delta);
3393 if (idelta < 0 && does_feed && !sends_only) {
3394 (*i)->mod_solo_isolated_by_upstream (false, this);
3401 Route::output_change_handler (IOChange change, void * /*src*/)
3403 if (_initial_io_setup) {
3407 if ((change.type & IOChange::ConfigurationChanged)) {
3408 /* This is called with the process lock held if change
3409 contains ConfigurationChanged
3411 configure_processors (0);
3414 _session.reset_monitor_section();
3417 io_changed (); /* EMIT SIGNAL */
3420 if (_soloed_by_others_downstream) {
3422 /* checking all all downstream routes for
3423 * explicit of implict solo is a rather drastic measure,
3424 * ideally the input_change_handler() of the other route
3425 * would propagate the change to us.
3427 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3428 if (_output->connected()) {
3429 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3430 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3434 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3435 if (does_feed && !sends_only) {
3436 if ((*i)->soloed()) {
3443 int delta = sbod - _soloed_by_others_downstream;
3445 // do not allow new connections to change implicit solo (no propagation)
3446 mod_solo_by_others_downstream (delta);
3447 // Session::route_solo_changed() does not propagate indirect solo-changes
3448 // propagate upstream to tracks
3449 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3450 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3454 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3455 if (delta != 0 && does_feed && !sends_only) {
3456 (*i)->mod_solo_by_others_downstream (delta);
3465 Route::pans_required () const
3467 if (n_outputs().n_audio() < 2) {
3471 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3475 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3477 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3483 if (n_outputs().n_total() == 0) {
3487 if (!_active || n_inputs() == ChanCount::ZERO) {
3488 silence_unlocked (nframes);
3492 if (session_state_changing) {
3493 if (_session.transport_speed() != 0.0f) {
3494 /* we're rolling but some state is changing (e.g. our diskstream contents)
3495 so we cannot use them. Be silent till this is over.
3497 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3499 silence_unlocked (nframes);
3502 /* we're really not rolling, so we're either delivery silence or actually
3503 monitoring, both of which are safe to do while session_state_changing is true.
3507 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3509 fill_buffers_with_input (bufs, _input, nframes);
3511 if (_meter_point == MeterInput) {
3512 _meter->run (bufs, start_frame, end_frame, nframes, true);
3515 _amp->apply_gain_automation (false);
3516 _trim->apply_gain_automation (false);
3517 passthru (bufs, start_frame, end_frame, nframes, 0);
3523 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3525 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3530 if (n_outputs().n_total() == 0) {
3534 if (!_active || n_inputs().n_total() == 0) {
3535 silence_unlocked (nframes);
3539 framepos_t unused = 0;
3541 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3547 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3549 fill_buffers_with_input (bufs, _input, nframes);
3551 if (_meter_point == MeterInput) {
3552 _meter->run (bufs, start_frame, end_frame, nframes, true);
3555 passthru (bufs, start_frame, end_frame, nframes, declick);
3561 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3568 Route::flush_processors ()
3570 /* XXX shouldn't really try to take this lock, since
3571 this is called from the RT audio thread.
3574 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3576 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3582 __attribute__((annotate("realtime")))
3585 Route::apply_processor_changes_rt ()
3587 int emissions = EmitNone;
3589 if (_pending_meter_point != _meter_point) {
3590 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3592 /* meters always have buffers for 'processor_max_streams'
3593 * they can be re-positioned without re-allocation */
3594 if (set_meter_point_unlocked()) {
3595 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3597 emissions |= EmitMeterChanged;
3602 bool changed = false;
3604 if (g_atomic_int_get (&_pending_process_reorder)) {
3605 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3607 apply_processor_order (_pending_processor_order);
3608 setup_invisible_processors ();
3610 g_atomic_int_set (&_pending_process_reorder, 0);
3611 emissions |= EmitRtProcessorChange;
3615 set_processor_positions ();
3617 if (emissions != 0) {
3618 g_atomic_int_set (&_pending_signals, emissions);
3625 Route::emit_pending_signals ()
3628 int sig = g_atomic_int_and (&_pending_signals, 0);
3629 if (sig & EmitMeterChanged) {
3630 _meter->emit_configuration_changed();
3631 meter_change (); /* EMIT SIGNAL */
3632 if (sig & EmitMeterVisibilityChange) {
3633 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3635 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3638 if (sig & EmitRtProcessorChange) {
3639 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3644 Route::set_meter_point (MeterPoint p, bool force)
3646 if (_pending_meter_point == p && !force) {
3650 if (force || !AudioEngine::instance()->running()) {
3651 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3652 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3653 _pending_meter_point = p;
3654 _meter->emit_configuration_changed();
3655 meter_change (); /* EMIT SIGNAL */
3656 if (set_meter_point_unlocked()) {
3657 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3659 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3662 _pending_meter_point = p;
3668 __attribute__((annotate("realtime")))
3671 Route::set_meter_point_unlocked ()
3674 /* Caller must hold process and processor write lock */
3675 assert (!AudioEngine::instance()->process_lock().trylock());
3676 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3677 assert (!lm.locked ());
3680 _meter_point = _pending_meter_point;
3682 bool meter_was_visible_to_user = _meter->display_to_user ();
3684 if (!_custom_meter_position_noted) {
3685 maybe_note_meter_position ();
3688 if (_meter_point != MeterCustom) {
3690 _meter->set_display_to_user (false);
3692 setup_invisible_processors ();
3695 _meter->set_display_to_user (true);
3697 /* If we have a previous position for the custom meter, try to put it there */
3698 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3700 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3701 if (i != _processors.end ()) {
3702 _processors.remove (_meter);
3703 _processors.insert (i, _meter);
3705 } else {// at end, right before the mains_out/panner
3706 _processors.remove (_meter);
3707 ProcessorList::iterator main = _processors.end();
3708 _processors.insert (--main, _meter);
3712 /* Set up the meter for its new position */
3714 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3718 if (loc == _processors.begin()) {
3719 m_in = _input->n_ports();
3721 ProcessorList::iterator before = loc;
3723 m_in = (*before)->output_streams ();
3726 _meter->reflect_inputs (m_in);
3728 /* we do not need to reconfigure the processors, because the meter
3729 (a) is always ready to handle processor_max_streams
3730 (b) is always an N-in/N-out processor, and thus moving
3731 it doesn't require any changes to the other processors.
3734 /* these should really be done after releasing the lock
3735 * but all those signals are subscribed to with gui_thread()
3738 return (_meter->display_to_user() != meter_was_visible_to_user);
3742 Route::listen_position_changed ()
3745 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3746 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3747 ProcessorState pstate (this);
3749 if (configure_processors_unlocked (0)) {
3750 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3752 configure_processors_unlocked (0); // it worked before we tried to add it ...
3757 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3758 _session.set_dirty ();
3761 boost::shared_ptr<CapturingProcessor>
3762 Route::add_export_point()
3764 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3765 if (!_capturing_processor) {
3767 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3768 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3770 _capturing_processor.reset (new CapturingProcessor (_session));
3771 _capturing_processor->activate ();
3773 configure_processors_unlocked (0);
3777 return _capturing_processor;
3781 Route::update_signal_latency ()
3783 framecnt_t l = _output->user_latency();
3784 framecnt_t lamp = 0;
3785 bool before_amp = true;
3786 framecnt_t ltrim = 0;
3787 bool before_trim = true;
3789 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3790 if ((*i)->active ()) {
3791 l += (*i)->signal_latency ();
3796 if ((*i) == _trim) {
3807 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3809 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3810 _signal_latency_at_amp_position = lamp;
3811 _signal_latency_at_trim_position = ltrim;
3813 if (_signal_latency != l) {
3814 _signal_latency = l;
3815 signal_latency_changed (); /* EMIT SIGNAL */
3818 return _signal_latency;
3822 Route::set_user_latency (framecnt_t nframes)
3824 _output->set_user_latency (nframes);
3825 _session.update_latency_compensation ();
3829 Route::set_latency_compensation (framecnt_t longest_session_latency)
3831 framecnt_t old = _initial_delay;
3833 if (_signal_latency < longest_session_latency) {
3834 _initial_delay = longest_session_latency - _signal_latency;
3839 DEBUG_TRACE (DEBUG::Latency, string_compose (
3840 "%1: compensate for maximum latency of %2,"
3841 "given own latency of %3, using initial delay of %4\n",
3842 name(), longest_session_latency, _signal_latency, _initial_delay));
3844 if (_initial_delay != old) {
3845 initial_delay_changed (); /* EMIT SIGNAL */
3848 if (_session.transport_stopped()) {
3849 _roll_delay = _initial_delay;
3853 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3854 : AutomationControl (r->session(),
3855 Evoral::Parameter (SoloAutomation),
3856 ParameterDescriptor(Evoral::Parameter (SoloAutomation)),
3857 boost::shared_ptr<AutomationList>(), name)
3860 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3861 gl->set_interpolation(Evoral::ControlList::Discrete);
3866 Route::SoloControllable::set_value (double val)
3869 set_value_unchecked (val);
3874 Route::SoloControllable::set_value_unchecked (double val)
3876 const bool bval = ((val >= 0.5) ? true : false);
3878 boost::shared_ptr<RouteList> rl (new RouteList);
3880 boost::shared_ptr<Route> r = _route.lock ();
3887 if (Config->get_solo_control_is_listen_control()) {
3888 _session.set_listen (rl, bval);
3890 _session.set_solo (rl, bval);
3895 Route::SoloControllable::get_value () const
3897 boost::shared_ptr<Route> r = _route.lock ();
3902 if (Config->get_solo_control_is_listen_control()) {
3903 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3905 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3909 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3910 : AutomationControl (r->session(),
3911 Evoral::Parameter (MuteAutomation),
3912 ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
3913 boost::shared_ptr<AutomationList>(),
3917 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3918 gl->set_interpolation(Evoral::ControlList::Discrete);
3923 Route::MuteControllable::set_superficial_value(bool muted)
3925 /* Note we can not use AutomationControl::set_value here since it will emit
3926 Changed(), but the value will not be correct to the observer. */
3928 const bool to_list = _list && ((AutomationList*)_list.get ())->automation_write ();
3929 const double where = _session.audible_frame ();
3931 /* Note that we really need this:
3932 * if (as == Touch && _list->in_new_write_pass ()) {
3933 * alist->start_write_pass (_session.audible_frame ());
3935 * here in the case of the user calling from a GUI or whatever.
3936 * Without the ability to distinguish between user and
3937 * automation-initiated changes, we lose the "touch mute"
3938 * behaviour we have in AutomationController::toggled ().
3940 _list->set_in_write_pass (true, false, where);
3943 Control::set_double (muted, where, to_list);
3947 Route::MuteControllable::set_value (double val)
3950 set_value_unchecked (val);
3955 Route::MuteControllable::set_value_unchecked (double val)
3957 const bool bval = ((val >= 0.5) ? true : false);
3959 boost::shared_ptr<Route> r = _route.lock ();
3964 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3965 // Set superficial/automation value to drive controller (and possibly record)
3966 set_superficial_value (bval);
3967 // Playing back automation, set route mute directly
3968 r->set_mute (bval, this);
3970 // Set from user, queue mute event
3971 boost::shared_ptr<RouteList> rl (new RouteList);
3973 _session.set_mute (rl, bval, Session::rt_cleanup);
3978 Route::MuteControllable::get_value () const
3980 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3981 // Playing back automation, get the value from the list
3982 return AutomationControl::get_value();
3985 // Not playing back automation, get the actual route mute value
3986 boost::shared_ptr<Route> r = _route.lock ();
3987 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3990 Route::GroupGainControllable::GroupGainControllable (std::string name, boost::shared_ptr<Route> r)
3991 : AutomationControl (r->session(),
3992 Evoral::Parameter (GainAutomation),
3993 ParameterDescriptor (Evoral::Parameter (GainAutomation)),
3994 boost::shared_ptr<AutomationList>(),
3998 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(GainAutomation)));
3999 gl->set_interpolation(Evoral::ControlList::Discrete);
4004 Route::GroupGainControllable::set_value (double val)
4006 boost::shared_ptr<Route> r = _route.lock ();
4007 // I am not sure why I need the * .5 to make this work
4008 float normalized_position = r->gain_control()->interface_to_internal (val * 0.5);
4009 r->set_gain ((gain_t)normalized_position, this);
4013 Route::GroupGainControllable::get_value () const
4015 boost::shared_ptr<Route> r = _route.lock ();
4016 return 2.0 * r->gain_control()->internal_to_interface (r->gain_control()->get_value ());
4019 Route::PhaseControllable::PhaseControllable (std::string name, boost::shared_ptr<Route> r)
4020 : AutomationControl (r->session(),
4021 Evoral::Parameter (PhaseAutomation),
4022 ParameterDescriptor (Evoral::Parameter (PhaseAutomation)),
4023 boost::shared_ptr<AutomationList>(),
4027 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(PhaseAutomation)));
4028 gl->set_interpolation(Evoral::ControlList::Discrete);
4033 Route::PhaseControllable::set_value (double v)
4035 boost::shared_ptr<Route> r = _route.lock ();
4036 if (r->phase_invert().size()) {
4037 if (v == 0 || (v < 1 && v > 0.9) ) {
4038 r->set_phase_invert (_current_phase, false);
4040 r->set_phase_invert (_current_phase, true);
4046 Route::PhaseControllable::get_value () const
4048 boost::shared_ptr<Route> r = _route.lock ();
4049 return (double) r->phase_invert (_current_phase);
4053 Route::PhaseControllable::set_channel (uint32_t c)
4059 Route::PhaseControllable::channel () const
4061 return _current_phase;
4065 Route::set_block_size (pframes_t nframes)
4067 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4068 (*i)->set_block_size (nframes);
4071 _session.ensure_buffers (n_process_buffers ());
4075 Route::protect_automation ()
4077 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4078 (*i)->protect_automation();
4081 /** @param declick 1 to set a pending declick fade-in,
4082 * -1 to set a pending declick fade-out
4085 Route::set_pending_declick (int declick)
4088 /* this call is not allowed to turn off a pending declick */
4090 _pending_declick = declick;
4093 _pending_declick = 0;
4097 /** Shift automation forwards from a particular place, thereby inserting time.
4098 * Adds undo commands for any shifts that are performed.
4100 * @param pos Position to start shifting from.
4101 * @param frames Amount to shift forwards by.
4105 Route::shift (framepos_t pos, framecnt_t frames)
4107 /* gain automation */
4109 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4111 XMLNode &before = gc->alist()->get_state ();
4112 gc->alist()->shift (pos, frames);
4113 XMLNode &after = gc->alist()->get_state ();
4114 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4117 /* gain automation */
4119 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4121 XMLNode &before = gc->alist()->get_state ();
4122 gc->alist()->shift (pos, frames);
4123 XMLNode &after = gc->alist()->get_state ();
4124 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4127 // TODO mute automation ??
4129 /* pan automation */
4131 ControlSet::Controls& c (_pannable->controls());
4133 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4134 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4136 boost::shared_ptr<AutomationList> al = pc->alist();
4137 XMLNode& before = al->get_state ();
4138 al->shift (pos, frames);
4139 XMLNode& after = al->get_state ();
4140 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4145 /* redirect automation */
4147 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4148 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4150 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4152 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4153 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4155 boost::shared_ptr<AutomationList> al = ac->alist();
4156 XMLNode &before = al->get_state ();
4157 al->shift (pos, frames);
4158 XMLNode &after = al->get_state ();
4159 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4167 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4169 boost::shared_ptr<Processor> processor (p.lock ());
4170 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4174 pi->set_state_dir (d);
4178 Route::save_as_template (const string& path, const string& name)
4180 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4181 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4183 XMLNode& node (state (false));
4187 IO::set_name_in_state (*node.children().front(), name);
4189 tree.set_root (&node);
4191 /* return zero on success, non-zero otherwise */
4192 return !tree.write (path.c_str());
4197 Route::set_name (const string& str)
4199 if (str == name()) {
4203 string name = Route::ensure_track_or_route_name (str, _session);
4204 SessionObject::set_name (name);
4206 bool ret = (_input->set_name(name) && _output->set_name(name));
4209 /* rename the main outs. Leave other IO processors
4210 * with whatever name they already have, because its
4211 * just fine as it is (it will not contain the route
4212 * name if its a port insert, port send or port return).
4216 if (_main_outs->set_name (name)) {
4217 /* XXX returning false here is stupid because
4218 we already changed the route name.
4228 /** Set the name of a route in an XML description.
4229 * @param node XML <Route> node to set the name in.
4230 * @param name New name.
4233 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4235 node.add_property (X_("name"), name);
4237 XMLNodeList children = node.children();
4238 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4240 if ((*i)->name() == X_("IO")) {
4242 IO::set_name_in_state (**i, name);
4244 } else if ((*i)->name() == X_("Processor")) {
4246 XMLProperty* role = (*i)->property (X_("role"));
4247 if (role && role->value() == X_("Main")) {
4248 (*i)->add_property (X_("name"), name);
4251 } else if ((*i)->name() == X_("Diskstream")) {
4253 if (rename_playlist) {
4254 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4256 (*i)->add_property (X_("name"), name);
4262 boost::shared_ptr<Send>
4263 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4265 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4267 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4268 boost::shared_ptr<InternalSend> send;
4270 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4271 if (send->target_route() == target) {
4277 return boost::shared_ptr<Send>();
4280 /** @param c Audio channel index.
4281 * @param yn true to invert phase, otherwise false.
4284 Route::set_phase_invert (uint32_t c, bool yn)
4286 if (_phase_invert[c] != yn) {
4287 _phase_invert[c] = yn;
4288 phase_invert_changed (); /* EMIT SIGNAL */
4289 _session.set_dirty ();
4294 Route::set_phase_invert (boost::dynamic_bitset<> p)
4296 if (_phase_invert != p) {
4298 phase_invert_changed (); /* EMIT SIGNAL */
4299 _session.set_dirty ();
4304 Route::phase_invert (uint32_t c) const
4306 return _phase_invert[c];
4309 boost::dynamic_bitset<>
4310 Route::phase_invert () const
4312 return _phase_invert;
4316 Route::set_denormal_protection (bool yn)
4318 if (_denormal_protection != yn) {
4319 _denormal_protection = yn;
4320 denormal_protection_changed (); /* EMIT SIGNAL */
4325 Route::denormal_protection () const
4327 return _denormal_protection;
4331 Route::set_active (bool yn, void* src)
4333 if (_session.transport_rolling()) {
4337 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4338 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4342 if (_active != yn) {
4344 _input->set_active (yn);
4345 _output->set_active (yn);
4346 active_changed (); // EMIT SIGNAL
4347 _session.set_dirty ();
4351 boost::shared_ptr<Pannable>
4352 Route::pannable() const
4357 boost::shared_ptr<Panner>
4358 Route::panner() const
4361 return _main_outs->panner_shell()->panner();
4364 boost::shared_ptr<PannerShell>
4365 Route::panner_shell() const
4367 return _main_outs->panner_shell();
4370 boost::shared_ptr<AutomationControl>
4371 Route::gain_control() const
4373 return _amp->gain_control();
4376 boost::shared_ptr<AutomationControl>
4377 Route::trim_control() const
4379 return _trim->gain_control();
4382 boost::shared_ptr<AutomationControl>
4383 Route::get_control (const Evoral::Parameter& param)
4385 /* either we own the control or .... */
4387 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4391 /* maybe one of our processors does or ... */
4393 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4394 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4395 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4403 /* nobody does so we'll make a new one */
4405 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4412 boost::shared_ptr<Processor>
4413 Route::nth_plugin (uint32_t n)
4415 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4416 ProcessorList::iterator i;
4418 for (i = _processors.begin(); i != _processors.end(); ++i) {
4419 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4426 return boost::shared_ptr<Processor> ();
4429 boost::shared_ptr<Processor>
4430 Route::nth_send (uint32_t n)
4432 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4433 ProcessorList::iterator i;
4435 for (i = _processors.begin(); i != _processors.end(); ++i) {
4436 if (boost::dynamic_pointer_cast<Send> (*i)) {
4443 return boost::shared_ptr<Processor> ();
4447 Route::has_io_processor_named (const string& name)
4449 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4450 ProcessorList::iterator i;
4452 for (i = _processors.begin(); i != _processors.end(); ++i) {
4453 if (boost::dynamic_pointer_cast<Send> (*i) ||
4454 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4455 if ((*i)->name() == name) {
4464 MuteMaster::MutePoint
4465 Route::mute_points () const
4467 return _mute_master->mute_points ();
4471 Route::set_processor_positions ()
4473 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4475 bool had_amp = false;
4476 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4477 (*i)->set_pre_fader (!had_amp);
4484 /** Called when there is a proposed change to the input port count */
4486 Route::input_port_count_changing (ChanCount to)
4488 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4490 /* The processors cannot be configured with the new input arrangement, so
4496 /* The change is ok */
4500 /** Called when there is a proposed change to the output port count */
4502 Route::output_port_count_changing (ChanCount to)
4504 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4505 if (processor_out_streams.get(*t) > to.get(*t)) {
4509 /* The change is ok */
4514 Route::unknown_processors () const
4518 if (_session.get_disable_all_loaded_plugins ()) {
4519 // Do not list "missing plugins" if they are explicitly disabled
4523 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4524 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4525 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4526 p.push_back ((*i)->name ());
4535 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4537 /* we assume that all our input ports feed all our output ports. its not
4538 universally true, but the alternative is way too corner-case to worry about.
4541 LatencyRange all_connections;
4544 all_connections.min = 0;
4545 all_connections.max = 0;
4547 all_connections.min = ~((pframes_t) 0);
4548 all_connections.max = 0;
4550 /* iterate over all "from" ports and determine the latency range for all of their
4551 connections to the "outside" (outside of this Route).
4554 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4558 p->get_connected_latency_range (range, playback);
4560 all_connections.min = min (all_connections.min, range.min);
4561 all_connections.max = max (all_connections.max, range.max);
4565 /* set the "from" port latencies to the max/min range of all their connections */
4567 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4568 p->set_private_latency_range (all_connections, playback);
4571 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4573 all_connections.min += our_latency;
4574 all_connections.max += our_latency;
4576 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4577 p->set_private_latency_range (all_connections, playback);
4580 return all_connections.max;
4584 Route::set_private_port_latencies (bool playback) const
4586 framecnt_t own_latency = 0;
4588 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4589 OR LATENCY CALLBACK.
4591 This is called (early) from the latency callback. It computes the REAL
4592 latency associated with each port and stores the result as the "private"
4593 latency of the port. A later call to Route::set_public_port_latencies()
4594 sets all ports to the same value to reflect the fact that we do latency
4595 compensation and so all signals are delayed by the same amount as they
4596 flow through ardour.
4599 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4600 if ((*i)->active ()) {
4601 own_latency += (*i)->signal_latency ();
4606 /* playback: propagate latency from "outside the route" to outputs to inputs */
4607 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4609 /* capture: propagate latency from "outside the route" to inputs to outputs */
4610 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4615 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4617 /* this is called to set the JACK-visible port latencies, which take
4618 latency compensation into account.
4627 const PortSet& ports (_input->ports());
4628 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4629 p->set_public_latency_range (range, playback);
4634 const PortSet& ports (_output->ports());
4635 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4636 p->set_public_latency_range (range, playback);
4641 /** Put the invisible processors in the right place in _processors.
4642 * Must be called with a writer lock on _processor_lock held.
4645 __attribute__((annotate("realtime")))
4648 Route::setup_invisible_processors ()
4651 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4652 assert (!lm.locked ());
4656 /* too early to be doing this stuff */
4660 /* we'll build this new list here and then use it
4662 * TODO put the ProcessorList is on the stack for RT-safety.
4665 ProcessorList new_processors;
4667 /* find visible processors */
4669 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4670 if ((*i)->display_to_user ()) {
4671 new_processors.push_back (*i);
4677 ProcessorList::iterator amp = new_processors.begin ();
4678 while (amp != new_processors.end() && *amp != _amp) {
4682 assert (amp != new_processors.end ());
4684 /* and the processor after the amp */
4686 ProcessorList::iterator after_amp = amp;
4692 switch (_meter_point) {
4694 assert (!_meter->display_to_user ());
4695 new_processors.push_front (_meter);
4698 assert (!_meter->display_to_user ());
4699 new_processors.insert (amp, _meter);
4701 case MeterPostFader:
4702 /* do nothing here */
4705 /* do nothing here */
4708 /* the meter is visible, so we don't touch it here */
4715 assert (_main_outs);
4716 assert (!_main_outs->display_to_user ());
4717 new_processors.push_back (_main_outs);
4719 /* iterator for the main outs */
4721 ProcessorList::iterator main = new_processors.end();
4724 /* OUTPUT METERING */
4726 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4727 assert (!_meter->display_to_user ());
4729 /* add the processor just before or just after the main outs */
4731 ProcessorList::iterator meter_point = main;
4733 if (_meter_point == MeterOutput) {
4736 new_processors.insert (meter_point, _meter);
4741 if (_monitor_send && !is_monitor ()) {
4742 assert (!_monitor_send->display_to_user ());
4743 switch (Config->get_listen_position ()) {
4744 case PreFaderListen:
4745 switch (Config->get_pfl_position ()) {
4746 case PFLFromBeforeProcessors:
4747 new_processors.push_front (_monitor_send);
4749 case PFLFromAfterProcessors:
4750 new_processors.insert (amp, _monitor_send);
4753 _monitor_send->set_can_pan (false);
4755 case AfterFaderListen:
4756 switch (Config->get_afl_position ()) {
4757 case AFLFromBeforeProcessors:
4758 new_processors.insert (after_amp, _monitor_send);
4760 case AFLFromAfterProcessors:
4761 new_processors.insert (new_processors.end(), _monitor_send);
4764 _monitor_send->set_can_pan (true);
4769 #if 0 // not used - just yet
4770 if (!is_master() && !is_monitor() && !is_auditioner()) {
4771 new_processors.push_front (_delayline);
4775 /* MONITOR CONTROL */
4777 if (_monitor_control && is_monitor ()) {
4778 assert (!_monitor_control->display_to_user ());
4779 new_processors.push_front (_monitor_control);
4782 /* INTERNAL RETURN */
4784 /* doing this here means that any monitor control will come just after
4789 assert (!_intreturn->display_to_user ());
4790 new_processors.push_front (_intreturn);
4793 if (_trim && _trim->active()) {
4794 assert (!_trim->display_to_user ());
4795 new_processors.push_front (_trim);
4797 /* EXPORT PROCESSOR */
4799 if (_capturing_processor) {
4800 assert (!_capturing_processor->display_to_user ());
4801 new_processors.push_front (_capturing_processor);
4804 _processors = new_processors;
4806 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4807 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4812 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4813 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4814 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4821 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4822 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4826 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4827 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4834 /** If the meter point is `Custom', make a note of where the meter is.
4835 * This is so that if the meter point is subsequently set to something else,
4836 * and then back to custom, we can put the meter back where it was last time
4837 * custom was enabled.
4839 * Must be called with the _processor_lock held.
4842 Route::maybe_note_meter_position ()
4844 if (_meter_point != MeterCustom) {
4848 _custom_meter_position_noted = true;
4849 /* custom meter points range from after trim to before panner/main_outs
4850 * this is a limitation by the current processor UI
4852 bool seen_trim = false;
4853 _processor_after_last_custom_meter.reset();
4854 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4855 if ((*i) == _trim) {
4858 if ((*i) == _main_outs) {
4859 _processor_after_last_custom_meter = *i;
4862 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4864 _processor_after_last_custom_meter = _trim;
4866 ProcessorList::iterator j = i;
4868 assert(j != _processors.end ()); // main_outs should be before
4869 _processor_after_last_custom_meter = *j;
4874 assert(_processor_after_last_custom_meter.lock());
4877 boost::shared_ptr<Processor>
4878 Route::processor_by_id (PBD::ID id) const
4880 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4881 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4882 if ((*i)->id() == id) {
4887 return boost::shared_ptr<Processor> ();
4890 /** @return the monitoring state, or in other words what data we are pushing
4891 * into the route (data from the inputs, data from disk or silence)
4894 Route::monitoring_state () const
4896 return MonitoringInput;
4899 /** @return what we should be metering; either the data coming from the input
4900 * IO or the data that is flowing through the route.
4903 Route::metering_state () const
4905 return MeteringRoute;
4909 Route::has_external_redirects () const
4911 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4913 /* ignore inactive processors and obviously ignore the main
4914 * outs since everything has them and we don't care.
4917 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4925 boost::shared_ptr<Processor>
4926 Route::the_instrument () const
4928 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4929 return the_instrument_unlocked ();
4932 boost::shared_ptr<Processor>
4933 Route::the_instrument_unlocked () const
4935 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4936 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4937 if ((*i)->input_streams().n_midi() > 0 &&
4938 (*i)->output_streams().n_audio() > 0) {
4943 return boost::shared_ptr<Processor>();
4949 Route::non_realtime_locate (framepos_t pos)
4952 _pannable->transport_located (pos);
4955 if (_delayline.get()) {
4956 _delayline.get()->flush();
4960 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4961 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4963 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4964 (*i)->transport_located (pos);
4967 _roll_delay = _initial_delay;
4971 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4978 * We don't currently mix MIDI input together, so we don't need the
4979 * complex logic of the audio case.
4982 n_buffers = bufs.count().n_midi ();
4984 for (i = 0; i < n_buffers; ++i) {
4986 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4987 MidiBuffer& buf (bufs.get_midi (i));
4990 buf.copy (source_port->get_midi_buffer(nframes));
4992 buf.silence (nframes);
4998 n_buffers = bufs.count().n_audio();
5000 size_t n_ports = io->n_ports().n_audio();
5001 float scaling = 1.0f;
5003 if (n_ports > n_buffers) {
5004 scaling = ((float) n_buffers) / n_ports;
5007 for (i = 0; i < n_ports; ++i) {
5009 /* if there are more ports than buffers, map them onto buffers
5010 * in a round-robin fashion
5013 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5014 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5017 if (i < n_buffers) {
5019 /* first time through just copy a channel into
5023 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5025 if (scaling != 1.0f) {
5026 buf.apply_gain (scaling, nframes);
5031 /* on subsequent times around, merge data from
5032 * the port with what is already there
5035 if (scaling != 1.0f) {
5036 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5038 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5043 /* silence any remaining buffers */
5045 for (; i < n_buffers; ++i) {
5046 AudioBuffer& buf (bufs.get_audio (i));
5047 buf.silence (nframes);
5050 /* establish the initial setup of the buffer set, reflecting what was
5051 copied into it. unless, of course, we are the auditioner, in which
5052 case nothing was fed into it from the inputs at all.
5055 if (!is_auditioner()) {
5056 bufs.set_count (io->n_ports());
5060 boost::shared_ptr<AutomationControl>
5061 Route::pan_azimuth_control() const
5064 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5066 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5067 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5069 if (!_pannable || !panner()) {
5070 return boost::shared_ptr<AutomationControl>();
5072 return _pannable->pan_azimuth_control;
5076 boost::shared_ptr<AutomationControl>
5077 Route::pan_elevation_control() const
5079 if (Profile->get_mixbus() || !_pannable || !panner()) {
5080 return boost::shared_ptr<AutomationControl>();
5083 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5085 if (c.find (PanElevationAutomation) != c.end()) {
5086 return _pannable->pan_elevation_control;
5088 return boost::shared_ptr<AutomationControl>();
5091 boost::shared_ptr<AutomationControl>
5092 Route::pan_width_control() const
5094 if (Profile->get_mixbus() || !_pannable || !panner()) {
5095 return boost::shared_ptr<AutomationControl>();
5098 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5100 if (c.find (PanWidthAutomation) != c.end()) {
5101 return _pannable->pan_width_control;
5103 return boost::shared_ptr<AutomationControl>();
5106 boost::shared_ptr<AutomationControl>
5107 Route::pan_frontback_control() const
5109 if (Profile->get_mixbus() || !_pannable || !panner()) {
5110 return boost::shared_ptr<AutomationControl>();
5113 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5115 if (c.find (PanFrontBackAutomation) != c.end()) {
5116 return _pannable->pan_frontback_control;
5118 return boost::shared_ptr<AutomationControl>();
5121 boost::shared_ptr<AutomationControl>
5122 Route::pan_lfe_control() const
5124 if (Profile->get_mixbus() || !_pannable || !panner()) {
5125 return boost::shared_ptr<AutomationControl>();
5128 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5130 if (c.find (PanLFEAutomation) != c.end()) {
5131 return _pannable->pan_lfe_control;
5133 return boost::shared_ptr<AutomationControl>();
5138 Route::eq_band_cnt () const
5140 if (Profile->get_mixbus()) {
5143 /* Ardour has no well-known EQ object */
5148 boost::shared_ptr<AutomationControl>
5149 Route::eq_gain_controllable (uint32_t band) const
5152 boost::shared_ptr<PluginInsert> eq = ch_eq();
5155 return boost::shared_ptr<AutomationControl>();
5158 uint32_t port_number;
5161 if (is_master() || mixbus()) {
5168 if (is_master() || mixbus()) {
5175 if (is_master() || mixbus()) {
5182 return boost::shared_ptr<AutomationControl>();
5185 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5187 return boost::shared_ptr<AutomationControl>();
5190 boost::shared_ptr<AutomationControl>
5191 Route::eq_freq_controllable (uint32_t band) const
5195 if (mixbus() || is_master()) {
5196 /* no frequency controls for mixbusses or master */
5197 return boost::shared_ptr<AutomationControl>();
5200 boost::shared_ptr<PluginInsert> eq = ch_eq();
5203 return boost::shared_ptr<AutomationControl>();
5206 uint32_t port_number;
5218 return boost::shared_ptr<AutomationControl>();
5221 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5223 return boost::shared_ptr<AutomationControl>();
5227 boost::shared_ptr<AutomationControl>
5228 Route::eq_q_controllable (uint32_t band) const
5230 return boost::shared_ptr<AutomationControl>();
5233 boost::shared_ptr<AutomationControl>
5234 Route::eq_shape_controllable (uint32_t band) const
5236 return boost::shared_ptr<AutomationControl>();
5239 boost::shared_ptr<AutomationControl>
5240 Route::eq_enable_controllable () const
5243 boost::shared_ptr<PluginInsert> eq = ch_eq();
5246 return boost::shared_ptr<AutomationControl>();
5249 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5251 return boost::shared_ptr<AutomationControl>();
5255 boost::shared_ptr<AutomationControl>
5256 Route::eq_hpf_controllable () const
5259 boost::shared_ptr<PluginInsert> eq = ch_eq();
5262 return boost::shared_ptr<AutomationControl>();
5265 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5267 return boost::shared_ptr<AutomationControl>();
5272 Route::eq_band_name (uint32_t band) const
5274 if (Profile->get_mixbus()) {
5290 boost::shared_ptr<AutomationControl>
5291 Route::comp_enable_controllable () const
5294 boost::shared_ptr<PluginInsert> comp = ch_comp();
5297 return boost::shared_ptr<AutomationControl>();
5300 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5302 return boost::shared_ptr<AutomationControl>();
5305 boost::shared_ptr<AutomationControl>
5306 Route::comp_threshold_controllable () const
5309 boost::shared_ptr<PluginInsert> comp = ch_comp();
5312 return boost::shared_ptr<AutomationControl>();
5315 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5318 return boost::shared_ptr<AutomationControl>();
5321 boost::shared_ptr<AutomationControl>
5322 Route::comp_speed_controllable () const
5325 boost::shared_ptr<PluginInsert> comp = ch_comp();
5328 return boost::shared_ptr<AutomationControl>();
5331 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5333 return boost::shared_ptr<AutomationControl>();
5336 boost::shared_ptr<AutomationControl>
5337 Route::comp_mode_controllable () const
5340 boost::shared_ptr<PluginInsert> comp = ch_comp();
5343 return boost::shared_ptr<AutomationControl>();
5346 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5348 return boost::shared_ptr<AutomationControl>();
5351 boost::shared_ptr<AutomationControl>
5352 Route::comp_makeup_controllable () const
5355 boost::shared_ptr<PluginInsert> comp = ch_comp();
5358 return boost::shared_ptr<AutomationControl>();
5361 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5363 return boost::shared_ptr<AutomationControl>();
5366 boost::shared_ptr<AutomationControl>
5367 Route::comp_redux_controllable () const
5370 boost::shared_ptr<PluginInsert> comp = ch_comp();
5373 return boost::shared_ptr<AutomationControl>();
5376 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5378 return boost::shared_ptr<AutomationControl>();
5383 Route::comp_mode_name (uint32_t mode) const
5388 return _("Leveler");
5390 return _("Compressor");
5392 return _("Limiter");
5402 Route::comp_speed_name (uint32_t mode) const