2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/boost_debug.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/plugin_insert.h"
61 #include "ardour/port.h"
62 #include "ardour/port_insert.h"
63 #include "ardour/processor.h"
64 #include "ardour/profile.h"
65 #include "ardour/route.h"
66 #include "ardour/route_group.h"
67 #include "ardour/send.h"
68 #include "ardour/session.h"
69 #include "ardour/unknown_processor.h"
70 #include "ardour/utils.h"
75 using namespace ARDOUR;
78 PBD::Signal0<void> Route::SyncOrderKeys;
79 PBD::Signal0<void> Route::RemoteControlIDChange;
81 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
82 : SessionObject (sess, name)
84 , GraphNode (sess._process_graph)
87 , _signal_latency_at_amp_position (0)
88 , _signal_latency_at_trim_position (0)
91 , _pending_process_reorder (0)
92 , _pending_signals (0)
94 , _pending_declick (true)
95 , _meter_point (MeterPostFader)
96 , _pending_meter_point (MeterPostFader)
97 , _meter_type (MeterPeak)
99 , _soloed_by_others_upstream (0)
100 , _soloed_by_others_downstream (0)
101 , _solo_isolated (false)
102 , _solo_isolated_by_upstream (0)
103 , _denormal_protection (false)
106 , _declickable (false)
107 , _mute_master (new MuteMaster (sess, name))
108 , _have_internal_generator (false)
110 , _default_type (default_type)
112 , _has_order_key (false)
113 , _remote_control_id (0)
115 , _in_configure_processors (false)
116 , _initial_io_setup (false)
117 , _custom_meter_position_noted (false)
119 processor_max_streams.reset();
125 /* set default meter type */
127 _meter_type = Config->get_meter_type_master ();
129 else if (dynamic_cast<Track*>(this)) {
130 _meter_type = Config->get_meter_type_track ();
132 _meter_type = Config->get_meter_type_bus ();
135 /* add standard controls */
137 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
138 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
139 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
141 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
142 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
143 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
145 add_control (_solo_control);
146 add_control (_mute_control);
147 add_control (_phase_control);
151 if (!(_flags & Route::MonitorOut)) {
152 _pannable.reset (new Pannable (_session));
155 /* input and output objects */
157 _input.reset (new IO (_session, _name, IO::Input, _default_type));
158 _output.reset (new IO (_session, _name, IO::Output, _default_type));
160 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
161 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
163 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
164 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
166 #if 0 // not used - just yet
167 if (!is_master() && !is_monitor() && !is_auditioner()) {
168 _delayline.reset (new DelayLine (_session, _name));
169 add_processor (_delayline, PreFader);
173 /* add amp processor */
175 _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
176 add_control (_gain_control);
178 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
179 add_processor (_amp, PostFader);
182 _amp->set_display_name (_("Monitor"));
187 _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
188 add_control (_trim_control);
190 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
191 _trim->set_display_to_user (false);
193 if (dynamic_cast<AudioTrack*>(this)) {
194 /* we can't do this in the AudioTrack's constructor
195 * because _trim does not exit then
199 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
204 /* create standard processors: meter, main outs, monitor out;
205 they will be added to _processors by setup_invisible_processors ()
208 _meter.reset (new PeakMeter (_session, _name));
209 _meter->set_owner (this);
210 _meter->set_display_to_user (false);
213 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
214 _main_outs->activate ();
217 /* where we listen to tracks */
218 _intreturn.reset (new InternalReturn (_session));
219 _intreturn->activate ();
221 /* the thing that provides proper control over a control/monitor/listen bus
222 (such as per-channel cut, dim, solo, invert, etc).
224 _monitor_control.reset (new MonitorProcessor (_session));
225 _monitor_control->activate ();
228 if (is_master() || is_monitor() || is_auditioner()) {
229 _mute_master->set_solo_ignore (true);
232 /* now that we have _meter, its safe to connect to this */
235 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
236 configure_processors (0);
244 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
246 /* do this early so that we don't get incoming signals as we are going through destruction
251 /* don't use clear_processors here, as it depends on the session which may
252 be half-destroyed by now
255 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
256 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
257 (*i)->drop_references ();
260 _processors.clear ();
264 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
266 if (Config->get_remote_model() != UserOrdered) {
270 set_remote_control_id_internal (id, notify_class_listeners);
274 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
276 /* force IDs for master/monitor busses and prevent
277 any other route from accidentally getting these IDs
278 (i.e. legacy sessions)
281 if (is_master() && id != MasterBusRemoteControlID) {
282 id = MasterBusRemoteControlID;
285 if (is_monitor() && id != MonitorBusRemoteControlID) {
286 id = MonitorBusRemoteControlID;
293 /* don't allow it to collide */
295 if (!is_master () && !is_monitor() &&
296 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
297 id += MonitorBusRemoteControlID;
300 if (id != remote_control_id()) {
301 _remote_control_id = id;
302 RemoteControlIDChanged ();
304 if (notify_class_listeners) {
305 RemoteControlIDChange ();
311 Route::remote_control_id() const
314 return MasterBusRemoteControlID;
318 return MonitorBusRemoteControlID;
321 return _remote_control_id;
325 Route::has_order_key () const
327 return _has_order_key;
331 Route::order_key () const
337 Route::set_remote_control_id_explicit (uint32_t rid)
339 if (is_master() || is_monitor() || is_auditioner()) {
340 /* hard-coded remote IDs, or no remote ID */
344 if (_remote_control_id != rid) {
345 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
346 _remote_control_id = rid;
347 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
350 /* don't emit the class-level RID signal RemoteControlIDChange here,
351 leave that to the entity that changed the order key, so that we
352 don't get lots of emissions for no good reasons (e.g. when changing
353 all route order keys).
355 See Session::sync_remote_id_from_order_keys() for the (primary|only)
356 spot where that is emitted.
361 Route::set_order_key (uint32_t n)
363 _has_order_key = true;
365 if (_order_key == n) {
371 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
372 name(), order_key ()));
374 _session.set_dirty ();
378 Route::ensure_track_or_route_name(string name, Session &session)
380 string newname = name;
382 while (!session.io_name_is_legal (newname)) {
383 newname = bump_name_once (newname, ' ');
390 Route::inc_gain (gain_t factor)
392 /* To be used ONLY when doing group-relative gain adjustment, from
396 float desired_gain = _gain_control->user_double();
398 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
399 // really?! what's the idea here?
400 _gain_control->route_set_value (0.000001f + (0.000001f * factor));
402 _gain_control->route_set_value (desired_gain + (desired_gain * factor));
407 Route::set_gain (gain_t val, Controllable::GroupControlDisposition group_override)
409 if (use_group (group_override, &RouteGroup::is_gain)) {
411 if (_route_group->is_relative()) {
413 gain_t usable_gain = _gain_control->get_value();
414 if (usable_gain < 0.000001f) {
415 usable_gain = 0.000001f;
419 if (delta < 0.000001f) {
423 delta -= usable_gain;
428 gain_t factor = delta / usable_gain;
431 factor = _route_group->get_max_factor(factor);
432 if (factor == 0.0f) {
433 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
437 factor = _route_group->get_min_factor(factor);
438 if (factor == 0.0f) {
439 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
444 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor));
448 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, Controllable::NoGroup));
454 if (val == _gain_control->get_value()) {
458 _gain_control->route_set_value (val);
462 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
464 // TODO route group, see set_gain()
465 _trim_control->route_set_value (val);
469 Route::maybe_declick (BufferSet&, framecnt_t, int)
471 /* this is the "bus" implementation and they never declick.
476 /** Process this route for one (sub) cycle (process thread)
478 * @param bufs Scratch buffers to use for the signal path
479 * @param start_frame Initial transport frame
480 * @param end_frame Final transport frame
481 * @param nframes Number of frames to output (to ports)
483 * Note that (end_frame - start_frame) may not be equal to nframes when the
484 * transport speed isn't 1.0 (eg varispeed).
487 Route::process_output_buffers (BufferSet& bufs,
488 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
489 int declick, bool gain_automation_ok)
491 /* Caller must hold process lock */
492 assert (!AudioEngine::instance()->process_lock().trylock());
494 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
496 // can this actually happen? functions calling process_output_buffers()
497 // already take a reader-lock.
498 bufs.silence (nframes, 0);
502 /* figure out if we're going to use gain automation */
503 if (gain_automation_ok) {
504 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
505 _amp->setup_gain_automation (
506 start_frame + _signal_latency_at_amp_position,
507 end_frame + _signal_latency_at_amp_position,
510 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
511 _trim->setup_gain_automation (
512 start_frame + _signal_latency_at_trim_position,
513 end_frame + _signal_latency_at_trim_position,
516 _amp->apply_gain_automation (false);
517 _trim->apply_gain_automation (false);
520 /* Tell main outs what to do about monitoring. We do this so that
521 on a transition between monitoring states we get a de-clicking gain
522 change in the _main_outs delivery, if config.get_use_monitor_fades()
525 We override this in the case where we have an internal generator.
527 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
529 _main_outs->no_outs_cuz_we_no_monitor (silence);
531 /* -------------------------------------------------------------------------------------------
532 GLOBAL DECLICK (for transport changes etc.)
533 ----------------------------------------------------------------------------------------- */
535 maybe_declick (bufs, nframes, declick);
536 _pending_declick = 0;
538 /* -------------------------------------------------------------------------------------------
539 DENORMAL CONTROL/PHASE INVERT
540 ----------------------------------------------------------------------------------------- */
542 if (_phase_invert.any ()) {
546 if (_denormal_protection || Config->get_denormal_protection()) {
548 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
549 Sample* const sp = i->data();
551 if (_phase_invert[chn]) {
552 for (pframes_t nx = 0; nx < nframes; ++nx) {
557 for (pframes_t nx = 0; nx < nframes; ++nx) {
565 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
566 Sample* const sp = i->data();
568 if (_phase_invert[chn]) {
569 for (pframes_t nx = 0; nx < nframes; ++nx) {
578 if (_denormal_protection || Config->get_denormal_protection()) {
580 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
581 Sample* const sp = i->data();
582 for (pframes_t nx = 0; nx < nframes; ++nx) {
590 /* -------------------------------------------------------------------------------------------
592 ----------------------------------------------------------------------------------------- */
594 /* set this to be true if the meter will already have been ::run() earlier */
595 bool const meter_already_run = metering_state() == MeteringInput;
597 framecnt_t latency = 0;
599 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
601 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
602 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
607 /* if it has any inputs, make sure they match */
608 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
609 if (bufs.count() != (*i)->input_streams()) {
611 DEBUG::Processors, string_compose (
612 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
613 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
620 /* should we NOT run plugins here if the route is inactive?
621 do we catch route != active somewhere higher?
624 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
625 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
628 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
629 bufs.set_count ((*i)->output_streams());
631 if ((*i)->active ()) {
632 latency += (*i)->signal_latency ();
638 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
639 boost::shared_ptr<Processor> endpoint,
640 bool include_endpoint, bool for_export, bool for_freeze)
642 /* If no processing is required, there's no need to go any further. */
643 if (!endpoint && !include_endpoint) {
647 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
648 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
649 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
651 /* trim is always at the top, for bounce no latency compensation is needed */
652 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
653 _trim->setup_gain_automation (start, start + nframes, nframes);
656 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
658 if (!include_endpoint && (*i) == endpoint) {
662 /* if we're not exporting, stop processing if we come across a routing processor. */
663 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
666 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
670 /* don't run any processors that does routing.
671 * oh, and don't bother with the peak meter either.
673 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
674 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
675 buffers.set_count ((*i)->output_streams());
676 latency += (*i)->signal_latency ();
679 if ((*i) == endpoint) {
686 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
687 bool include_endpoint, bool for_export, bool for_freeze) const
689 framecnt_t latency = 0;
690 if (!endpoint && !include_endpoint) {
694 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
695 if (!include_endpoint && (*i) == endpoint) {
698 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
701 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
704 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
705 latency += (*i)->signal_latency ();
707 if ((*i) == endpoint) {
715 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
716 bool include_endpoint, bool for_export, bool for_freeze) const
718 if (!endpoint && !include_endpoint) {
722 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
723 if (!include_endpoint && (*i) == endpoint) {
726 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
729 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
732 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
733 cc = (*i)->output_streams();
735 if ((*i) == endpoint) {
743 Route::n_process_buffers ()
745 return max (_input->n_ports(), processor_max_streams);
749 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
751 assert (is_monitor());
752 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
753 fill_buffers_with_input (bufs, _input, nframes);
754 passthru (bufs, start_frame, end_frame, nframes, declick);
758 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
762 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
764 /* control/monitor bus ignores input ports when something is
765 feeding the listen "stream". data will "arrive" into the
766 route from the intreturn processor element.
769 bufs.silence (nframes, 0);
772 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
773 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
777 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
779 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
781 bufs.set_count (_input->n_ports());
782 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
783 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
787 Route::set_listen (bool yn, Controllable::GroupControlDisposition group_override)
793 if (use_group (group_override, &RouteGroup::is_solo)) {
794 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, Controllable::NoGroup));
799 if (yn != _monitor_send->active()) {
801 _monitor_send->activate ();
802 _mute_master->set_soloed_by_self (true);
804 _monitor_send->deactivate ();
805 _mute_master->set_soloed_by_self (false);
807 _mute_master->set_soloed_by_others (false);
809 listen_changed (group_override); /* EMIT SIGNAL */
815 Route::listening_via_monitor () const
818 return _monitor_send->active ();
825 Route::set_solo_safe (bool yn, Controllable::GroupControlDisposition /* group_override */)
827 if (_solo_safe != yn) {
829 solo_safe_changed ();
834 Route::solo_safe() const
840 Route::clear_all_solo_state ()
842 // ideally this function will never do anything, it only exists to forestall Murphy
843 bool emit_changed = false;
846 // these are really debug messages, but of possible interest.
848 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
850 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
851 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
852 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
856 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
857 // if self-soled, set_solo() will do signal emission
861 _soloed_by_others_upstream = 0;
862 _soloed_by_others_downstream = 0;
865 PBD::Unwinder<bool> uw (_solo_safe, false);
866 set_solo (false, Controllable::NoGroup);
870 set_mute_master_solo ();
871 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
876 Route::set_solo (bool yn, Controllable::GroupControlDisposition group_override)
879 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
883 if (is_master() || is_monitor() || is_auditioner()) {
884 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
888 if (use_group (group_override, &RouteGroup::is_solo)) {
889 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, Controllable::NoGroup));
893 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, grp ? %3 currently self-soloed ? %4\n",
894 name(), yn, enum_2_string(group_override), self_soloed()));
896 if (self_soloed() != yn) {
898 solo_changed (true, group_override); /* EMIT SIGNAL */
899 _solo_control->Changed (); /* EMIT SIGNAL */
902 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
904 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
905 Config->get_solo_mute_overrride().
908 if (yn && Profile->get_trx()) {
909 set_mute (false, Controllable::UseGroup);
914 Route::set_self_solo (bool yn)
916 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
918 set_mute_master_solo ();
922 Route::mod_solo_by_others_upstream (int32_t delta)
924 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
925 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
927 uint32_t old_sbu = _soloed_by_others_upstream;
930 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
931 _soloed_by_others_upstream += delta;
933 _soloed_by_others_upstream = 0;
936 _soloed_by_others_upstream += delta;
939 DEBUG_TRACE (DEBUG::Solo, string_compose (
940 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
941 name(), delta, _soloed_by_others_upstream, old_sbu,
942 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
944 /* push the inverse solo change to everything that feeds us.
946 This is important for solo-within-group. When we solo 1 track out of N that
947 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
948 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
949 tracks that feed it. This will silence them if they were audible because
950 of a bus solo, but the newly soloed track will still be audible (because
953 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
957 if ((_self_solo || _soloed_by_others_downstream) &&
958 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
959 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
961 if (delta > 0 || !Config->get_exclusive_solo()) {
962 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
963 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
967 boost::shared_ptr<Route> sr = i->r.lock();
969 sr->mod_solo_by_others_downstream (-delta);
975 set_mute_master_solo ();
976 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
980 Route::mod_solo_by_others_downstream (int32_t delta)
982 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
983 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
986 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
987 _soloed_by_others_downstream += delta;
989 _soloed_by_others_downstream = 0;
992 _soloed_by_others_downstream += delta;
995 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
997 set_mute_master_solo ();
998 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1002 Route::set_mute_master_solo ()
1004 _mute_master->set_soloed_by_self (self_soloed());
1005 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1009 Route::mod_solo_isolated_by_upstream (bool yn)
1011 bool old = solo_isolated ();
1012 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1013 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1016 if (_solo_isolated_by_upstream >= 1) {
1017 _solo_isolated_by_upstream--;
1019 _solo_isolated_by_upstream = 0;
1022 _solo_isolated_by_upstream++;
1025 if (solo_isolated() != old) {
1026 /* solo isolated status changed */
1027 _mute_master->set_solo_ignore (solo_isolated());
1028 solo_isolated_changed (); /* EMIT SIGNAL */
1033 Route::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
1035 if (is_master() || is_monitor() || is_auditioner()) {
1039 if (use_group (group_override, &RouteGroup::is_solo)) {
1040 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, Controllable::NoGroup));
1044 bool changed = false;
1047 if (_solo_isolated == false) {
1048 _mute_master->set_solo_ignore (true);
1051 _solo_isolated = true;
1053 if (_solo_isolated == true) {
1054 _solo_isolated = false;
1055 _mute_master->set_solo_ignore (false);
1065 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1067 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1068 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1070 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1075 bool does_feed = feeds (*i, &sends_only);
1077 if (does_feed && !sends_only) {
1078 (*i)->mod_solo_isolated_by_upstream (yn);
1082 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1084 solo_isolated_changed (); /* EMIT SIGNAL */
1088 Route::solo_isolated () const
1090 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1094 Route::set_mute_points (MuteMaster::MutePoint mp)
1096 _mute_master->set_mute_points (mp);
1097 mute_points_changed (); /* EMIT SIGNAL */
1099 if (_mute_master->muted_by_self()) {
1100 mute_changed (); /* EMIT SIGNAL */
1101 _mute_control->Changed (); /* EMIT SIGNAL */
1106 Route::set_mute (bool yn, Controllable::GroupControlDisposition group_override)
1108 if (use_group (group_override, &RouteGroup::is_mute)) {
1109 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, Controllable::NoGroup));
1113 if (muted() != yn) {
1114 _mute_master->set_muted_by_self (yn);
1115 /* allow any derived classes to respond to the mute change
1116 before anybody else knows about it.
1119 /* tell everyone else */
1120 mute_changed (); /* EMIT SIGNAL */
1121 _mute_control->Changed (); /* EMIT SIGNAL */
1126 Route::muted () const
1128 return _mute_master->muted_by_self();
1132 Route::muted_by_others () const
1134 // This method is only used by route_ui for display state.
1135 // The real thing is MuteMaster::muted_by_others_at()
1137 //master is never muted by others
1141 //now check to see if something is soloed (and I am not)
1142 //see also MuteMaster::mute_gain_at()
1143 return (_session.soloing() && !soloed() && !solo_isolated());
1148 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1150 cerr << name << " {" << endl;
1151 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1152 p != procs.end(); ++p) {
1153 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1155 cerr << "}" << endl;
1159 /** Supposing that we want to insert a Processor at a given Placement, return
1160 * the processor to add the new one before (or 0 to add at the end).
1162 boost::shared_ptr<Processor>
1163 Route::before_processor_for_placement (Placement p)
1165 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1167 ProcessorList::iterator loc;
1169 if (p == PreFader) {
1170 /* generic pre-fader: insert immediately before the amp */
1171 loc = find (_processors.begin(), _processors.end(), _amp);
1173 /* generic post-fader: insert right before the main outs */
1174 loc = find (_processors.begin(), _processors.end(), _main_outs);
1177 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1180 /** Supposing that we want to insert a Processor at a given index, return
1181 * the processor to add the new one before (or 0 to add at the end).
1183 boost::shared_ptr<Processor>
1184 Route::before_processor_for_index (int index)
1187 return boost::shared_ptr<Processor> ();
1190 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1192 ProcessorList::iterator i = _processors.begin ();
1194 while (i != _processors.end() && j < index) {
1195 if ((*i)->display_to_user()) {
1202 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1205 /** Add a processor either pre- or post-fader
1206 * @return 0 on success, non-0 on failure.
1209 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1211 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1215 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1216 * @param index Index to add the processor at, or -1 to add at the end of the list.
1217 * @return 0 on success, non-0 on failure.
1220 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1222 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1225 /** Add a processor to the route.
1226 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1227 * @return 0 on success, non-0 on failure.
1230 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1232 assert (processor != _meter);
1233 assert (processor != _main_outs);
1235 DEBUG_TRACE (DEBUG::Processors, string_compose (
1236 "%1 adding processor %2\n", name(), processor->name()));
1238 if (!AudioEngine::instance()->connected() || !processor) {
1243 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1244 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1245 ProcessorState pstate (this);
1247 boost::shared_ptr<PluginInsert> pi;
1248 boost::shared_ptr<PortInsert> porti;
1250 if (processor == _amp) {
1251 /* Ensure that only one amp is in the list at any time */
1252 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1253 if (check != _processors.end()) {
1254 if (before == _amp) {
1255 /* Already in position; all is well */
1258 _processors.erase (check);
1263 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1265 ProcessorList::iterator loc;
1267 /* inserting before a processor; find it */
1268 loc = find (_processors.begin(), _processors.end(), before);
1269 if (loc == _processors.end ()) {
1274 /* inserting at end */
1275 loc = _processors.end ();
1278 _processors.insert (loc, processor);
1279 processor->set_owner (this);
1281 // Set up processor list channels. This will set processor->[input|output]_streams(),
1282 // configure redirect ports properly, etc.
1285 if (configure_processors_unlocked (err)) {
1287 configure_processors_unlocked (0); // it worked before we tried to add it ...
1292 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1294 if (pi->has_no_inputs ()) {
1295 /* generator plugin */
1296 _have_internal_generator = true;
1301 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1302 processor->activate ();
1305 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1307 _output->set_user_latency (0);
1310 reset_instrument_info ();
1311 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1312 set_processor_positions ();
1318 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1320 const XMLProperty *prop;
1323 boost::shared_ptr<Processor> processor;
1325 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1326 so that we can add the processor in the right place (pre/post-fader)
1329 XMLNodeList const & children = node.children ();
1330 XMLNodeList::const_iterator i = children.begin ();
1332 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1336 Placement placement = PreFader;
1338 if (i != children.end()) {
1339 if ((prop = (*i)->property (X_("placement"))) != 0) {
1340 placement = Placement (string_2_enum (prop->value(), placement));
1344 if (node.name() == "Insert") {
1346 if ((prop = node.property ("type")) != 0) {
1348 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1349 prop->value() == "lv2" ||
1350 prop->value() == "windows-vst" ||
1351 prop->value() == "lxvst" ||
1352 prop->value() == "audiounit") {
1354 if (_session.get_disable_all_loaded_plugins ()) {
1355 processor.reset (new UnknownProcessor (_session, node));
1357 processor.reset (new PluginInsert (_session));
1362 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1367 } else if (node.name() == "Send") {
1369 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1370 processor.reset (new Send (_session, sendpan, _mute_master));
1374 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1378 if (processor->set_state (node, version)) {
1382 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1383 if (i != children.end()) {
1384 if ((prop = (*i)->property (X_("active"))) != 0) {
1385 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1386 processor->activate();
1388 processor->deactivate();
1392 return (add_processor (processor, placement, 0, false) == 0);
1395 catch (failed_constructor &err) {
1396 warning << _("processor could not be created. Ignored.") << endmsg;
1402 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1404 /* NOTE: this is intended to be used ONLY when copying
1405 processors from another Route. Hence the subtle
1406 differences between this and ::add_processor()
1409 ProcessorList::iterator loc;
1412 loc = find(_processors.begin(), _processors.end(), before);
1414 /* nothing specified - at end */
1415 loc = _processors.end ();
1418 if (!_session.engine().connected()) {
1422 if (others.empty()) {
1427 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1428 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1429 ProcessorState pstate (this);
1431 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1437 boost::shared_ptr<PluginInsert> pi;
1439 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1443 _processors.insert (loc, *i);
1444 (*i)->set_owner (this);
1446 if ((*i)->active()) {
1450 /* Think: does this really need to be called for every processor in the loop? */
1452 if (configure_processors_unlocked (err)) {
1454 configure_processors_unlocked (0); // it worked before we tried to add it ...
1459 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1462 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1463 boost::shared_ptr<PluginInsert> pi;
1465 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1466 if (pi->has_no_inputs ()) {
1467 _have_internal_generator = true;
1473 _output->set_user_latency (0);
1476 reset_instrument_info ();
1477 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1478 set_processor_positions ();
1484 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1486 if (p == PreFader) {
1487 start = _processors.begin();
1488 end = find(_processors.begin(), _processors.end(), _amp);
1490 start = find(_processors.begin(), _processors.end(), _amp);
1492 end = _processors.end();
1496 /** Turn off all processors with a given placement
1497 * @param p Placement of processors to disable
1500 Route::disable_processors (Placement p)
1502 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1504 ProcessorList::iterator start, end;
1505 placement_range(p, start, end);
1507 for (ProcessorList::iterator i = start; i != end; ++i) {
1508 (*i)->deactivate ();
1511 _session.set_dirty ();
1514 /** Turn off all redirects
1517 Route::disable_processors ()
1519 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1521 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1522 (*i)->deactivate ();
1525 _session.set_dirty ();
1528 /** Turn off all redirects with a given placement
1529 * @param p Placement of redirects to disable
1532 Route::disable_plugins (Placement p)
1534 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1536 ProcessorList::iterator start, end;
1537 placement_range(p, start, end);
1539 for (ProcessorList::iterator i = start; i != end; ++i) {
1540 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1541 (*i)->deactivate ();
1545 _session.set_dirty ();
1548 /** Turn off all plugins
1551 Route::disable_plugins ()
1553 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1555 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1556 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1557 (*i)->deactivate ();
1561 _session.set_dirty ();
1566 Route::ab_plugins (bool forward)
1568 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1572 /* forward = turn off all active redirects, and mark them so that the next time
1573 we go the other way, we will revert them
1576 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1577 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1581 if ((*i)->active()) {
1582 (*i)->deactivate ();
1583 (*i)->set_next_ab_is_active (true);
1585 (*i)->set_next_ab_is_active (false);
1591 /* backward = if the redirect was marked to go active on the next ab, do so */
1593 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1595 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1599 if ((*i)->get_next_ab_is_active()) {
1602 (*i)->deactivate ();
1607 _session.set_dirty ();
1611 /** Remove processors with a given placement.
1612 * @param p Placement of processors to remove.
1615 Route::clear_processors (Placement p)
1617 if (!_session.engine().connected()) {
1621 bool already_deleting = _session.deletion_in_progress();
1622 if (!already_deleting) {
1623 _session.set_deletion_in_progress();
1627 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1628 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1629 ProcessorList new_list;
1630 ProcessorStreams err;
1631 bool seen_amp = false;
1633 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1639 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1641 /* you can't remove these */
1643 new_list.push_back (*i);
1650 new_list.push_back (*i);
1653 (*i)->drop_references ();
1661 (*i)->drop_references ();
1664 new_list.push_back (*i);
1671 _processors = new_list;
1672 configure_processors_unlocked (&err); // this can't fail
1675 processor_max_streams.reset();
1676 _have_internal_generator = false;
1677 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1678 set_processor_positions ();
1680 reset_instrument_info ();
1682 if (!already_deleting) {
1683 _session.clear_deletion_in_progress();
1688 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1690 // TODO once the export point can be configured properly, do something smarter here
1691 if (processor == _capturing_processor) {
1692 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1693 if (need_process_lock) {
1697 _capturing_processor.reset();
1699 if (need_process_lock) {
1704 /* these can never be removed */
1706 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1710 if (!_session.engine().connected()) {
1714 processor_max_streams.reset();
1717 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1718 if (need_process_lock) {
1722 /* Caller must hold process lock */
1723 assert (!AudioEngine::instance()->process_lock().trylock());
1725 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1727 ProcessorState pstate (this);
1729 ProcessorList::iterator i;
1730 bool removed = false;
1732 for (i = _processors.begin(); i != _processors.end(); ) {
1733 if (*i == processor) {
1735 /* move along, see failure case for configure_processors()
1736 where we may need to reconfigure the processor.
1739 /* stop redirects that send signals to JACK ports
1740 from causing noise as a result of no longer being
1744 boost::shared_ptr<IOProcessor> iop;
1746 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1750 i = _processors.erase (i);
1758 _output->set_user_latency (0);
1766 if (configure_processors_unlocked (err)) {
1768 /* we know this will work, because it worked before :) */
1769 configure_processors_unlocked (0);
1773 _have_internal_generator = false;
1775 for (i = _processors.begin(); i != _processors.end(); ++i) {
1776 boost::shared_ptr<PluginInsert> pi;
1778 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1779 if (pi->has_no_inputs ()) {
1780 _have_internal_generator = true;
1785 if (need_process_lock) {
1790 reset_instrument_info ();
1791 processor->drop_references ();
1792 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1793 set_processor_positions ();
1799 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1801 ProcessorList deleted;
1803 if (!_session.engine().connected()) {
1807 processor_max_streams.reset();
1810 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1811 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1812 ProcessorState pstate (this);
1814 ProcessorList::iterator i;
1815 boost::shared_ptr<Processor> processor;
1817 for (i = _processors.begin(); i != _processors.end(); ) {
1821 /* these can never be removed */
1823 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1828 /* see if its in the list of processors to delete */
1830 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1835 /* stop IOProcessors that send to JACK ports
1836 from causing noise as a result of no longer being
1840 boost::shared_ptr<IOProcessor> iop;
1842 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1846 deleted.push_back (processor);
1847 i = _processors.erase (i);
1850 if (deleted.empty()) {
1851 /* none of those in the requested list were found */
1855 _output->set_user_latency (0);
1857 if (configure_processors_unlocked (err)) {
1859 /* we know this will work, because it worked before :) */
1860 configure_processors_unlocked (0);
1865 _have_internal_generator = false;
1867 for (i = _processors.begin(); i != _processors.end(); ++i) {
1868 boost::shared_ptr<PluginInsert> pi;
1870 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1871 if (pi->has_no_inputs ()) {
1872 _have_internal_generator = true;
1879 /* now try to do what we need to so that those that were removed will be deleted */
1881 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1882 (*i)->drop_references ();
1885 reset_instrument_info ();
1886 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1887 set_processor_positions ();
1893 Route::reset_instrument_info ()
1895 boost::shared_ptr<Processor> instr = the_instrument();
1897 _instrument_info.set_internal_instrument (instr);
1901 /** Caller must hold process lock */
1903 Route::configure_processors (ProcessorStreams* err)
1905 #ifndef PLATFORM_WINDOWS
1906 assert (!AudioEngine::instance()->process_lock().trylock());
1909 if (!_in_configure_processors) {
1910 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1911 return configure_processors_unlocked (err);
1918 Route::input_streams () const
1920 return _input->n_ports ();
1923 list<pair<ChanCount, ChanCount> >
1924 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1926 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1928 return try_configure_processors_unlocked (in, err);
1931 list<pair<ChanCount, ChanCount> >
1932 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1934 // Check each processor in order to see if we can configure as requested
1936 list<pair<ChanCount, ChanCount> > configuration;
1939 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1940 DEBUG_TRACE (DEBUG::Processors, "{\n");
1942 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1944 if ((*p)->can_support_io_configuration(in, out)) {
1945 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1946 configuration.push_back(make_pair(in, out));
1949 // restriction for Monitor Section Processors
1950 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1951 /* do not allow to add/remove channels (for now)
1952 * The Monitor follows the master-bus and has no panner (unpan)
1953 * but do allow processors with midi-in to be added (e.g VSTs with control that
1954 * will remain unconnected)
1956 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1957 return list<pair<ChanCount, ChanCount> > ();
1959 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1960 // internal sends make no sense, only feedback
1961 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1962 return list<pair<ChanCount, ChanCount> > ();
1964 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1965 /* External Sends can be problematic. one can add/remove ports
1966 * there signal leaves the DAW to external monitors anyway, so there's
1967 * no real use for allowing them here anyway.
1969 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1970 return list<pair<ChanCount, ChanCount> > ();
1972 if (boost::dynamic_pointer_cast<Send> (*p)) {
1974 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1975 return list<pair<ChanCount, ChanCount> > ();
1984 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1985 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1986 DEBUG_TRACE (DEBUG::Processors, "}\n");
1987 return list<pair<ChanCount, ChanCount> > ();
1991 DEBUG_TRACE (DEBUG::Processors, "}\n");
1993 return configuration;
1996 /** Set the input/output configuration of each processor in the processors list.
1997 * Caller must hold process lock.
1998 * Return 0 on success, otherwise configuration is impossible.
2001 Route::configure_processors_unlocked (ProcessorStreams* err)
2003 #ifndef PLATFORM_WINDOWS
2004 assert (!AudioEngine::instance()->process_lock().trylock());
2007 if (_in_configure_processors) {
2011 /* put invisible processors where they should be */
2012 setup_invisible_processors ();
2014 _in_configure_processors = true;
2016 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2018 if (configuration.empty ()) {
2019 _in_configure_processors = false;
2024 bool seen_mains_out = false;
2025 processor_out_streams = _input->n_ports();
2026 processor_max_streams.reset();
2028 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2029 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2031 if (!(*p)->configure_io(c->first, c->second)) {
2032 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2034 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2035 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2037 boost::shared_ptr<PluginInsert> pi;
2038 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2039 /* plugins connected via Split Match may have more channels.
2040 * route/scratch buffers are needed for all of them*/
2041 processor_max_streams = ChanCount::max(processor_max_streams, pi->input_streams());
2042 processor_max_streams = ChanCount::max(processor_max_streams, pi->natural_input_streams());
2046 if (boost::dynamic_pointer_cast<Delivery> (*p)
2047 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2048 /* main delivery will increase port count to match input.
2049 * the Delivery::Main is usually the last processor - followed only by
2052 seen_mains_out = true;
2054 if (!seen_mains_out) {
2055 processor_out_streams = out;
2061 _meter->set_max_channels (processor_max_streams);
2064 /* make sure we have sufficient scratch buffers to cope with the new processor
2067 _session.ensure_buffers (n_process_buffers ());
2069 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2071 _in_configure_processors = false;
2075 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2076 * @param state New active state for those processors.
2079 Route::all_visible_processors_active (bool state)
2081 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2083 if (_processors.empty()) {
2087 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2088 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2095 (*i)->deactivate ();
2099 _session.set_dirty ();
2103 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2105 /* check if re-order requires re-configuration of any processors
2106 * -> compare channel configuration for all processors
2108 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2109 ChanCount c = input_streams ();
2111 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2113 if (c != (*j)->input_streams()) {
2116 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2119 if ((*i)->input_streams() != c) {
2122 c = (*i)->output_streams();
2134 __attribute__((annotate("realtime")))
2137 Route::apply_processor_order (const ProcessorList& new_order)
2139 /* need to hold processor_lock; either read or write lock
2140 * and the engine process_lock.
2141 * Due to r/w lock ambiguity we can only assert the latter
2143 assert (!AudioEngine::instance()->process_lock().trylock());
2146 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2147 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2148 * processors in the current actual processor list that are hidden. Any visible processors
2149 * in the current list but not in "new_order" will be assumed to be deleted.
2152 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2153 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2154 * (note though that ::processors_reorder_needs_configure() ensured that
2155 * this function will only ever be called from the rt-thread if no processor were removed)
2157 * either way, I can't proove it, but an x-run due to re-order here is less likley
2158 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2161 ProcessorList as_it_will_be;
2162 ProcessorList::iterator oiter;
2163 ProcessorList::const_iterator niter;
2165 oiter = _processors.begin();
2166 niter = new_order.begin();
2168 while (niter != new_order.end()) {
2170 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2171 then append it to the temp list.
2173 Otherwise, see if the next processor in the old list is in the new list. if not,
2174 its been deleted. If its there, append it to the temp list.
2177 if (oiter == _processors.end()) {
2179 /* no more elements in the old list, so just stick the rest of
2180 the new order onto the temp list.
2183 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2184 while (niter != new_order.end()) {
2191 if (!(*oiter)->display_to_user()) {
2193 as_it_will_be.push_back (*oiter);
2197 /* visible processor: check that its in the new order */
2199 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2200 /* deleted: do nothing, shared_ptr<> will clean up */
2202 /* ignore this one, and add the next item from the new order instead */
2203 as_it_will_be.push_back (*niter);
2208 /* now remove from old order - its taken care of no matter what */
2209 oiter = _processors.erase (oiter);
2213 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2215 /* If the meter is in a custom position, find it and make a rough note of its position */
2216 maybe_note_meter_position ();
2220 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2222 // it a change is already queued, wait for it
2223 // (unless engine is stopped. apply immediately and proceed
2224 while (g_atomic_int_get (&_pending_process_reorder)) {
2225 if (!AudioEngine::instance()->running()) {
2226 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2227 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2229 apply_processor_order(_pending_processor_order);
2230 setup_invisible_processors ();
2232 g_atomic_int_set (&_pending_process_reorder, 0);
2234 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2235 set_processor_positions ();
2237 // TODO rather use a semaphore or something.
2238 // but since ::reorder_processors() is called
2239 // from the GUI thread, this is fine..
2244 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2246 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2247 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2248 ProcessorState pstate (this);
2250 apply_processor_order (new_order);
2252 if (configure_processors_unlocked (err)) {
2260 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2261 set_processor_positions ();
2264 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2265 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2267 // _pending_processor_order is protected by _processor_lock
2268 _pending_processor_order = new_order;
2269 g_atomic_int_set (&_pending_process_reorder, 1);
2282 Route::get_template()
2284 return state(false);
2288 Route::state(bool full_state)
2290 if (!_session._template_state_dir.empty()) {
2291 assert (!full_state); // only for templates
2292 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2295 XMLNode *node = new XMLNode("Route");
2296 ProcessorList::iterator i;
2299 id().print (buf, sizeof (buf));
2300 node->add_property("id", buf);
2301 node->add_property ("name", _name);
2302 node->add_property("default-type", _default_type.to_string());
2305 node->add_property("flags", enum_2_string (_flags));
2308 node->add_property("active", _active?"yes":"no");
2310 boost::to_string (_phase_invert, p);
2311 node->add_property("phase-invert", p);
2312 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2313 node->add_property("meter-point", enum_2_string (_meter_point));
2315 node->add_property("meter-type", enum_2_string (_meter_type));
2318 node->add_property("route-group", _route_group->name());
2321 snprintf (buf, sizeof (buf), "%d", _order_key);
2322 node->add_property ("order-key", buf);
2323 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2324 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2325 node->add_property ("soloed-by-upstream", buf);
2326 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2327 node->add_property ("soloed-by-downstream", buf);
2328 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2329 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2331 node->add_child_nocopy (_input->state (full_state));
2332 node->add_child_nocopy (_output->state (full_state));
2333 node->add_child_nocopy (_solo_control->get_state ());
2334 node->add_child_nocopy (_mute_control->get_state ());
2335 node->add_child_nocopy (_mute_master->get_state ());
2338 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2341 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2342 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2343 remote_control_node->add_property (X_("id"), buf);
2344 node->add_child_nocopy (*remote_control_node);
2346 if (_comment.length()) {
2347 XMLNode *cmt = node->add_child ("Comment");
2348 cmt->add_content (_comment);
2352 node->add_child_nocopy (_pannable->state (full_state));
2355 for (i = _processors.begin(); i != _processors.end(); ++i) {
2357 /* template save: do not include internal sends functioning as
2358 aux sends because the chance of the target ID
2359 in the session where this template is used
2362 similarly, do not save listen sends which connect to
2363 the monitor section, because these will always be
2366 boost::shared_ptr<InternalSend> is;
2368 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2369 if (is->role() == Delivery::Listen) {
2374 node->add_child_nocopy((*i)->state (full_state));
2378 node->add_child_copy (*_extra_xml);
2381 if (_custom_meter_position_noted) {
2382 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2384 after->id().print (buf, sizeof (buf));
2385 node->add_property (X_("processor-after-last-custom-meter"), buf);
2389 if (!_session._template_state_dir.empty()) {
2390 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2397 Route::set_state (const XMLNode& node, int version)
2399 if (version < 3000) {
2400 return set_state_2X (node, version);
2404 XMLNodeConstIterator niter;
2406 const XMLProperty *prop;
2408 if (node.name() != "Route"){
2409 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2413 if ((prop = node.property (X_("name"))) != 0) {
2414 Route::set_name (prop->value());
2418 _initial_io_setup = true;
2420 if ((prop = node.property (X_("flags"))) != 0) {
2421 _flags = Flag (string_2_enum (prop->value(), _flags));
2426 if (is_master() || is_monitor() || is_auditioner()) {
2427 _mute_master->set_solo_ignore (true);
2431 /* monitor bus does not get a panner, but if (re)created
2432 via XML, it will already have one by the time we
2433 call ::set_state(). so ... remove it.
2438 /* add all processors (except amp, which is always present) */
2440 nlist = node.children();
2441 XMLNode processor_state (X_("processor_state"));
2443 Stateful::save_extra_xml (node);
2445 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2449 if (child->name() == IO::state_node_name) {
2450 if ((prop = child->property (X_("direction"))) == 0) {
2454 if (prop->value() == "Input") {
2455 _input->set_state (*child, version);
2456 } else if (prop->value() == "Output") {
2457 _output->set_state (*child, version);
2461 if (child->name() == X_("Processor")) {
2462 processor_state.add_child_copy (*child);
2465 if (child->name() == X_("Pannable")) {
2467 _pannable->set_state (*child, version);
2469 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2474 if ((prop = node.property (X_("meter-point"))) != 0) {
2475 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2476 set_meter_point (mp, true);
2478 _meter->set_display_to_user (_meter_point == MeterCustom);
2482 if ((prop = node.property (X_("meter-type"))) != 0) {
2483 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2486 _initial_io_setup = false;
2488 set_processor_state (processor_state);
2490 // this looks up the internal instrument in processors
2491 reset_instrument_info();
2493 if ((prop = node.property ("self-solo")) != 0) {
2494 set_self_solo (string_is_affirmative (prop->value()));
2497 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2498 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2499 mod_solo_by_others_upstream (atoi (prop->value()));
2502 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2503 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2504 mod_solo_by_others_downstream (atoi (prop->value()));
2507 if ((prop = node.property ("solo-isolated")) != 0) {
2508 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2511 if ((prop = node.property ("solo-safe")) != 0) {
2512 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2515 if ((prop = node.property (X_("phase-invert"))) != 0) {
2516 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2519 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2520 set_denormal_protection (string_is_affirmative (prop->value()));
2523 if ((prop = node.property (X_("active"))) != 0) {
2524 bool yn = string_is_affirmative (prop->value());
2525 _active = !yn; // force switch
2526 set_active (yn, this);
2529 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2530 set_order_key (atoi(prop->value()));
2533 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2537 string::size_type colon, equal;
2538 string remaining = prop->value();
2540 while (remaining.length()) {
2542 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2543 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2546 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2547 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2550 string keyname = remaining.substr (0, equal);
2552 if ((keyname == "EditorSort") || (keyname == "editor")) {
2553 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2559 colon = remaining.find_first_of (':');
2561 if (colon != string::npos) {
2562 remaining = remaining.substr (colon+1);
2569 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2570 PBD::ID id (prop->value ());
2571 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2572 ProcessorList::const_iterator i = _processors.begin ();
2573 while (i != _processors.end() && (*i)->id() != id) {
2577 if (i != _processors.end ()) {
2578 _processor_after_last_custom_meter = *i;
2579 _custom_meter_position_noted = true;
2583 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2586 if (child->name() == X_("Comment")) {
2588 /* XXX this is a terrible API design in libxml++ */
2590 XMLNode *cmt = *(child->children().begin());
2591 _comment = cmt->content();
2593 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2594 if (prop->value() == "solo") {
2595 _solo_control->set_state (*child, version);
2596 } else if (prop->value() == "mute") {
2597 _mute_control->set_state (*child, version);
2600 } else if (child->name() == X_("RemoteControl")) {
2601 if ((prop = child->property (X_("id"))) != 0) {
2603 sscanf (prop->value().c_str(), "%d", &x);
2604 set_remote_control_id_internal (x);
2607 } else if (child->name() == X_("MuteMaster")) {
2608 _mute_master->set_state (*child, version);
2610 } else if (child->name() == Automatable::xml_node_name) {
2611 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2619 Route::set_state_2X (const XMLNode& node, int version)
2621 LocaleGuard lg (X_("C"));
2623 XMLNodeConstIterator niter;
2625 const XMLProperty *prop;
2627 /* 2X things which still remain to be handled:
2633 if (node.name() != "Route") {
2634 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2638 if ((prop = node.property (X_("flags"))) != 0) {
2639 string f = prop->value ();
2640 boost::replace_all (f, "ControlOut", "MonitorOut");
2641 _flags = Flag (string_2_enum (f, _flags));
2646 if (is_master() || is_monitor() || is_auditioner()) {
2647 _mute_master->set_solo_ignore (true);
2650 if ((prop = node.property (X_("phase-invert"))) != 0) {
2651 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2652 if (string_is_affirmative (prop->value ())) {
2655 set_phase_invert (p);
2658 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2659 set_denormal_protection (string_is_affirmative (prop->value()));
2662 if ((prop = node.property (X_("soloed"))) != 0) {
2663 bool yn = string_is_affirmative (prop->value());
2665 /* XXX force reset of solo status */
2670 if ((prop = node.property (X_("muted"))) != 0) {
2673 bool muted = string_is_affirmative (prop->value());
2679 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2681 if (string_is_affirmative (prop->value())){
2682 mute_point = mute_point + "PreFader";
2687 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2689 if (string_is_affirmative (prop->value())){
2692 mute_point = mute_point + ",";
2695 mute_point = mute_point + "PostFader";
2700 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2702 if (string_is_affirmative (prop->value())){
2705 mute_point = mute_point + ",";
2708 mute_point = mute_point + "Listen";
2713 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2715 if (string_is_affirmative (prop->value())){
2718 mute_point = mute_point + ",";
2721 mute_point = mute_point + "Main";
2725 _mute_master->set_mute_points (mute_point);
2726 _mute_master->set_muted_by_self (true);
2730 if ((prop = node.property (X_("meter-point"))) != 0) {
2731 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2734 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2735 don't mean the same thing.
2738 if ((prop = node.property (X_("order-keys"))) != 0) {
2742 string::size_type colon, equal;
2743 string remaining = prop->value();
2745 while (remaining.length()) {
2747 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2748 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2751 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2752 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2755 string keyname = remaining.substr (0, equal);
2757 if (keyname == "EditorSort" || keyname == "editor") {
2758 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2764 colon = remaining.find_first_of (':');
2766 if (colon != string::npos) {
2767 remaining = remaining.substr (colon+1);
2776 nlist = node.children ();
2777 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2781 if (child->name() == IO::state_node_name) {
2783 /* there is a note in IO::set_state_2X() about why we have to call
2787 _input->set_state_2X (*child, version, true);
2788 _output->set_state_2X (*child, version, false);
2790 if ((prop = child->property (X_("name"))) != 0) {
2791 Route::set_name (prop->value ());
2796 if ((prop = child->property (X_("active"))) != 0) {
2797 bool yn = string_is_affirmative (prop->value());
2798 _active = !yn; // force switch
2799 set_active (yn, this);
2802 if ((prop = child->property (X_("gain"))) != 0) {
2805 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2806 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2810 /* Set up Panners in the IO */
2811 XMLNodeList io_nlist = child->children ();
2813 XMLNodeConstIterator io_niter;
2816 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2818 io_child = *io_niter;
2820 if (io_child->name() == X_("Panner")) {
2821 _main_outs->panner_shell()->set_state(*io_child, version);
2822 } else if (io_child->name() == X_("Automation")) {
2823 /* IO's automation is for the fader */
2824 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2830 XMLNodeList redirect_nodes;
2832 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2836 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2837 redirect_nodes.push_back(child);
2842 set_processor_state_2X (redirect_nodes, version);
2844 Stateful::save_extra_xml (node);
2846 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2849 if (child->name() == X_("Comment")) {
2851 /* XXX this is a terrible API design in libxml++ */
2853 XMLNode *cmt = *(child->children().begin());
2854 _comment = cmt->content();
2856 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2857 if (prop->value() == X_("solo")) {
2858 _solo_control->set_state (*child, version);
2859 } else if (prop->value() == X_("mute")) {
2860 _mute_control->set_state (*child, version);
2863 } else if (child->name() == X_("RemoteControl")) {
2864 if ((prop = child->property (X_("id"))) != 0) {
2866 sscanf (prop->value().c_str(), "%d", &x);
2867 set_remote_control_id_internal (x);
2877 Route::get_processor_state ()
2879 XMLNode* root = new XMLNode (X_("redirects"));
2880 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2881 root->add_child_nocopy ((*i)->state (true));
2888 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2890 /* We don't bother removing existing processors not in nList, as this
2891 method will only be called when creating a Route from scratch, not
2892 for undo purposes. Just put processors in at the appropriate place
2896 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2897 add_processor_from_xml_2X (**i, version);
2902 Route::set_processor_state (const XMLNode& node)
2904 const XMLNodeList &nlist = node.children();
2905 XMLNodeConstIterator niter;
2906 ProcessorList new_order;
2907 bool must_configure = false;
2909 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2911 XMLProperty* prop = (*niter)->property ("type");
2913 if (prop->value() == "amp") {
2914 _amp->set_state (**niter, Stateful::current_state_version);
2915 new_order.push_back (_amp);
2916 } else if (prop->value() == "trim") {
2917 _trim->set_state (**niter, Stateful::current_state_version);
2918 new_order.push_back (_trim);
2919 } else if (prop->value() == "meter") {
2920 _meter->set_state (**niter, Stateful::current_state_version);
2921 new_order.push_back (_meter);
2922 } else if (prop->value() == "delay") {
2924 _delayline->set_state (**niter, Stateful::current_state_version);
2925 new_order.push_back (_delayline);
2927 } else if (prop->value() == "main-outs") {
2928 _main_outs->set_state (**niter, Stateful::current_state_version);
2929 } else if (prop->value() == "intreturn") {
2931 _intreturn.reset (new InternalReturn (_session));
2932 must_configure = true;
2934 _intreturn->set_state (**niter, Stateful::current_state_version);
2935 } else if (is_monitor() && prop->value() == "monitor") {
2936 if (!_monitor_control) {
2937 _monitor_control.reset (new MonitorProcessor (_session));
2938 must_configure = true;
2940 _monitor_control->set_state (**niter, Stateful::current_state_version);
2941 } else if (prop->value() == "capture") {
2942 /* CapturingProcessor should never be restored, it's always
2943 added explicitly when needed */
2945 ProcessorList::iterator o;
2947 for (o = _processors.begin(); o != _processors.end(); ++o) {
2948 XMLProperty* id_prop = (*niter)->property(X_("id"));
2949 if (id_prop && (*o)->id() == id_prop->value()) {
2950 (*o)->set_state (**niter, Stateful::current_state_version);
2951 new_order.push_back (*o);
2956 // If the processor (*niter) is not on the route then create it
2958 if (o == _processors.end()) {
2960 boost::shared_ptr<Processor> processor;
2962 if (prop->value() == "intsend") {
2964 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2966 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2967 prop->value() == "lv2" ||
2968 prop->value() == "windows-vst" ||
2969 prop->value() == "lxvst" ||
2970 prop->value() == "audiounit") {
2972 if (_session.get_disable_all_loaded_plugins ()) {
2973 processor.reset (new UnknownProcessor (_session, **niter));
2975 processor.reset (new PluginInsert (_session));
2977 } else if (prop->value() == "port") {
2979 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2981 } else if (prop->value() == "send") {
2983 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2986 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2990 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2991 /* This processor could not be configured. Turn it into a UnknownProcessor */
2992 processor.reset (new UnknownProcessor (_session, **niter));
2995 /* we have to note the monitor send here, otherwise a new one will be created
2996 and the state of this one will be lost.
2998 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2999 if (isend && isend->role() == Delivery::Listen) {
3000 _monitor_send = isend;
3003 /* it doesn't matter if invisible processors are added here, as they
3004 will be sorted out by setup_invisible_processors () shortly.
3007 new_order.push_back (processor);
3008 must_configure = true;
3014 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3015 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3016 _processors = new_order;
3018 if (must_configure) {
3019 configure_processors_unlocked (0);
3022 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3024 (*i)->set_owner (this);
3025 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3027 boost::shared_ptr<PluginInsert> pi;
3029 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3030 if (pi->has_no_inputs ()) {
3031 _have_internal_generator = true;
3038 reset_instrument_info ();
3039 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3040 set_processor_positions ();
3044 Route::curve_reallocate ()
3046 // _gain_automation_curve.finish_resize ();
3047 // _pan_automation_curve.finish_resize ();
3051 Route::silence (framecnt_t nframes)
3053 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3058 silence_unlocked (nframes);
3062 Route::silence_unlocked (framecnt_t nframes)
3064 /* Must be called with the processor lock held */
3068 _output->silence (nframes);
3070 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3071 boost::shared_ptr<PluginInsert> pi;
3073 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3074 // skip plugins, they don't need anything when we're not active
3078 (*i)->silence (nframes);
3081 if (nframes == _session.get_block_size()) {
3088 Route::add_internal_return ()
3091 _intreturn.reset (new InternalReturn (_session));
3092 add_processor (_intreturn, PreFader);
3097 Route::add_send_to_internal_return (InternalSend* send)
3099 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3101 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3102 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3105 return d->add_send (send);
3111 Route::remove_send_from_internal_return (InternalSend* send)
3113 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3115 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3116 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3119 return d->remove_send (send);
3125 Route::enable_monitor_send ()
3127 /* Caller must hold process lock */
3128 assert (!AudioEngine::instance()->process_lock().trylock());
3130 /* master never sends to monitor section via the normal mechanism */
3131 assert (!is_master ());
3132 assert (!is_monitor ());
3134 /* make sure we have one */
3135 if (!_monitor_send) {
3136 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3137 _monitor_send->set_display_to_user (false);
3141 configure_processors (0);
3144 /** Add an aux send to a route.
3145 * @param route route to send to.
3146 * @param before Processor to insert before, or 0 to insert at the end.
3149 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3151 assert (route != _session.monitor_out ());
3154 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3156 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3158 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3160 if (d && d->target_route() == route) {
3161 /* already listening via the specified IO: do nothing */
3169 boost::shared_ptr<InternalSend> listener;
3172 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3173 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3174 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3177 add_processor (listener, before);
3179 } catch (failed_constructor& err) {
3187 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3189 ProcessorStreams err;
3190 ProcessorList::iterator tmp;
3193 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3195 /* have to do this early because otherwise processor reconfig
3196 * will put _monitor_send back in the list
3199 if (route == _session.monitor_out()) {
3200 _monitor_send.reset ();
3204 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3206 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3208 if (d && d->target_route() == route) {
3210 if (remove_processor (*x, &err, false) > 0) {
3216 /* list could have been demolished while we dropped the lock
3219 if (_session.engine().connected()) {
3220 /* i/o processors cannot be removed if the engine is not running
3221 * so don't live-loop in case the engine is N/A or dies
3231 Route::set_comment (string cmt, void *src)
3235 _session.set_dirty ();
3239 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3241 FeedRecord fr (other, via_sends_only);
3243 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3245 if (!result.second) {
3247 /* already a record for "other" - make sure sends-only information is correct */
3248 if (!via_sends_only && result.first->sends_only) {
3249 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3250 frp->sends_only = false;
3254 return result.second;
3258 Route::clear_fed_by ()
3264 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3266 const FedBy& fed_by (other->fed_by());
3268 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3269 boost::shared_ptr<Route> sr = f->r.lock();
3271 if (sr && (sr.get() == this)) {
3273 if (via_sends_only) {
3274 *via_sends_only = f->sends_only;
3285 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3287 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3289 if (_output->connected_to (other->input())) {
3290 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3291 if (via_send_only) {
3292 *via_send_only = false;
3299 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3301 boost::shared_ptr<IOProcessor> iop;
3303 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3304 if (iop->feeds (other)) {
3305 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3306 if (via_send_only) {
3307 *via_send_only = true;
3311 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3314 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3319 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3324 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3326 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3329 /** Called from the (non-realtime) butler thread when the transport is stopped */
3331 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3333 framepos_t now = _session.transport_frame();
3336 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3338 Automatable::transport_stopped (now);
3340 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3342 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3346 (*i)->transport_stopped (now);
3350 _roll_delay = _initial_delay;
3354 Route::input_change_handler (IOChange change, void * /*src*/)
3356 if ((change.type & IOChange::ConfigurationChanged)) {
3357 /* This is called with the process lock held if change
3358 contains ConfigurationChanged
3360 configure_processors (0);
3361 _phase_invert.resize (_input->n_ports().n_audio ());
3362 io_changed (); /* EMIT SIGNAL */
3365 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3368 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3369 if (_input->connected()) {
3370 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3371 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3375 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3376 if (does_feed && !sends_only) {
3377 if ((*i)->soloed()) {
3380 if ((*i)->solo_isolated()) {
3387 int delta = sbou - _soloed_by_others_upstream;
3388 int idelta = ibou - _solo_isolated_by_upstream;
3391 PBD::warning << string_compose (
3392 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3393 _name, ibou, _solo_isolated_by_upstream, idelta)
3398 if (_soloed_by_others_upstream) {
3399 // ignore new connections (they're not propagated)
3401 mod_solo_by_others_upstream (delta);
3405 if (_solo_isolated_by_upstream) {
3406 // solo-isolate currently only propagates downstream
3408 mod_solo_isolated_by_upstream (false);
3410 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3411 // but idelta can't be smaller than -1, can it?
3412 //_solo_isolated_by_upstream = ibou;
3415 // Session::route_solo_changed does not propagate indirect solo-changes
3416 // propagate downstream to tracks
3417 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3418 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3422 bool does_feed = feeds (*i, &sends_only);
3423 if (delta <= 0 && does_feed && !sends_only) {
3424 (*i)->mod_solo_by_others_upstream (delta);
3427 if (idelta < 0 && does_feed && !sends_only) {
3428 (*i)->mod_solo_isolated_by_upstream (false);
3435 Route::output_change_handler (IOChange change, void * /*src*/)
3437 if (_initial_io_setup) {
3441 if ((change.type & IOChange::ConfigurationChanged)) {
3442 /* This is called with the process lock held if change
3443 contains ConfigurationChanged
3445 configure_processors (0);
3448 _session.reset_monitor_section();
3451 io_changed (); /* EMIT SIGNAL */
3454 if (_soloed_by_others_downstream) {
3456 /* checking all all downstream routes for
3457 * explicit of implict solo is a rather drastic measure,
3458 * ideally the input_change_handler() of the other route
3459 * would propagate the change to us.
3461 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3462 if (_output->connected()) {
3463 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3464 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3468 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3469 if (does_feed && !sends_only) {
3470 if ((*i)->soloed()) {
3477 int delta = sbod - _soloed_by_others_downstream;
3479 // do not allow new connections to change implicit solo (no propagation)
3480 mod_solo_by_others_downstream (delta);
3481 // Session::route_solo_changed() does not propagate indirect solo-changes
3482 // propagate upstream to tracks
3483 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3484 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3488 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3489 if (delta != 0 && does_feed && !sends_only) {
3490 (*i)->mod_solo_by_others_downstream (delta);
3499 Route::pans_required () const
3501 if (n_outputs().n_audio() < 2) {
3505 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3509 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3511 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3517 if (n_outputs().n_total() == 0) {
3521 if (!_active || n_inputs() == ChanCount::ZERO) {
3522 silence_unlocked (nframes);
3526 if (session_state_changing) {
3527 if (_session.transport_speed() != 0.0f) {
3528 /* we're rolling but some state is changing (e.g. our diskstream contents)
3529 so we cannot use them. Be silent till this is over.
3531 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3533 silence_unlocked (nframes);
3536 /* we're really not rolling, so we're either delivery silence or actually
3537 monitoring, both of which are safe to do while session_state_changing is true.
3541 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3543 fill_buffers_with_input (bufs, _input, nframes);
3545 if (_meter_point == MeterInput) {
3546 _meter->run (bufs, start_frame, end_frame, nframes, true);
3549 _amp->apply_gain_automation (false);
3550 _trim->apply_gain_automation (false);
3551 passthru (bufs, start_frame, end_frame, nframes, 0);
3557 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3559 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3564 if (n_outputs().n_total() == 0) {
3568 if (!_active || n_inputs().n_total() == 0) {
3569 silence_unlocked (nframes);
3573 framepos_t unused = 0;
3575 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3581 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3583 fill_buffers_with_input (bufs, _input, nframes);
3585 if (_meter_point == MeterInput) {
3586 _meter->run (bufs, start_frame, end_frame, nframes, true);
3589 passthru (bufs, start_frame, end_frame, nframes, declick);
3595 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3602 Route::flush_processors ()
3604 /* XXX shouldn't really try to take this lock, since
3605 this is called from the RT audio thread.
3608 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3610 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3616 __attribute__((annotate("realtime")))
3619 Route::apply_processor_changes_rt ()
3621 int emissions = EmitNone;
3623 if (_pending_meter_point != _meter_point) {
3624 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3626 /* meters always have buffers for 'processor_max_streams'
3627 * they can be re-positioned without re-allocation */
3628 if (set_meter_point_unlocked()) {
3629 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3631 emissions |= EmitMeterChanged;
3636 bool changed = false;
3638 if (g_atomic_int_get (&_pending_process_reorder)) {
3639 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3641 apply_processor_order (_pending_processor_order);
3642 setup_invisible_processors ();
3644 g_atomic_int_set (&_pending_process_reorder, 0);
3645 emissions |= EmitRtProcessorChange;
3649 set_processor_positions ();
3651 if (emissions != 0) {
3652 g_atomic_int_set (&_pending_signals, emissions);
3659 Route::emit_pending_signals ()
3662 int sig = g_atomic_int_and (&_pending_signals, 0);
3663 if (sig & EmitMeterChanged) {
3664 _meter->emit_configuration_changed();
3665 meter_change (); /* EMIT SIGNAL */
3666 if (sig & EmitMeterVisibilityChange) {
3667 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3669 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3672 if (sig & EmitRtProcessorChange) {
3673 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3678 Route::set_meter_point (MeterPoint p, bool force)
3680 if (_pending_meter_point == p && !force) {
3684 if (force || !AudioEngine::instance()->running()) {
3685 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3686 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3687 _pending_meter_point = p;
3688 _meter->emit_configuration_changed();
3689 meter_change (); /* EMIT SIGNAL */
3690 if (set_meter_point_unlocked()) {
3691 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3693 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3696 _pending_meter_point = p;
3702 __attribute__((annotate("realtime")))
3705 Route::set_meter_point_unlocked ()
3708 /* Caller must hold process and processor write lock */
3709 assert (!AudioEngine::instance()->process_lock().trylock());
3710 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3711 assert (!lm.locked ());
3714 _meter_point = _pending_meter_point;
3716 bool meter_was_visible_to_user = _meter->display_to_user ();
3718 if (!_custom_meter_position_noted) {
3719 maybe_note_meter_position ();
3722 if (_meter_point != MeterCustom) {
3724 _meter->set_display_to_user (false);
3726 setup_invisible_processors ();
3729 _meter->set_display_to_user (true);
3731 /* If we have a previous position for the custom meter, try to put it there */
3732 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3734 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3735 if (i != _processors.end ()) {
3736 _processors.remove (_meter);
3737 _processors.insert (i, _meter);
3739 } else {// at end, right before the mains_out/panner
3740 _processors.remove (_meter);
3741 ProcessorList::iterator main = _processors.end();
3742 _processors.insert (--main, _meter);
3746 /* Set up the meter for its new position */
3748 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3752 if (loc == _processors.begin()) {
3753 m_in = _input->n_ports();
3755 ProcessorList::iterator before = loc;
3757 m_in = (*before)->output_streams ();
3760 _meter->reflect_inputs (m_in);
3762 /* we do not need to reconfigure the processors, because the meter
3763 (a) is always ready to handle processor_max_streams
3764 (b) is always an N-in/N-out processor, and thus moving
3765 it doesn't require any changes to the other processors.
3768 /* these should really be done after releasing the lock
3769 * but all those signals are subscribed to with gui_thread()
3772 return (_meter->display_to_user() != meter_was_visible_to_user);
3776 Route::listen_position_changed ()
3779 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3780 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3781 ProcessorState pstate (this);
3783 if (configure_processors_unlocked (0)) {
3784 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3786 configure_processors_unlocked (0); // it worked before we tried to add it ...
3791 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3792 _session.set_dirty ();
3795 boost::shared_ptr<CapturingProcessor>
3796 Route::add_export_point()
3798 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3799 if (!_capturing_processor) {
3801 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3802 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3804 _capturing_processor.reset (new CapturingProcessor (_session));
3805 _capturing_processor->activate ();
3807 configure_processors_unlocked (0);
3811 return _capturing_processor;
3815 Route::update_signal_latency ()
3817 framecnt_t l = _output->user_latency();
3818 framecnt_t lamp = 0;
3819 bool before_amp = true;
3820 framecnt_t ltrim = 0;
3821 bool before_trim = true;
3823 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3824 if ((*i)->active ()) {
3825 l += (*i)->signal_latency ();
3830 if ((*i) == _trim) {
3841 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3843 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3844 _signal_latency_at_amp_position = lamp;
3845 _signal_latency_at_trim_position = ltrim;
3847 if (_signal_latency != l) {
3848 _signal_latency = l;
3849 signal_latency_changed (); /* EMIT SIGNAL */
3852 return _signal_latency;
3856 Route::set_user_latency (framecnt_t nframes)
3858 _output->set_user_latency (nframes);
3859 _session.update_latency_compensation ();
3863 Route::set_latency_compensation (framecnt_t longest_session_latency)
3865 framecnt_t old = _initial_delay;
3867 if (_signal_latency < longest_session_latency) {
3868 _initial_delay = longest_session_latency - _signal_latency;
3873 DEBUG_TRACE (DEBUG::Latency, string_compose (
3874 "%1: compensate for maximum latency of %2,"
3875 "given own latency of %3, using initial delay of %4\n",
3876 name(), longest_session_latency, _signal_latency, _initial_delay));
3878 if (_initial_delay != old) {
3879 initial_delay_changed (); /* EMIT SIGNAL */
3882 if (_session.transport_stopped()) {
3883 _roll_delay = _initial_delay;
3888 Route::set_control (AutomationType type, double val, PBD::Controllable::GroupControlDisposition group_override)
3890 boost::shared_ptr<RouteList> rl;
3893 case GainAutomation:
3894 /* route must mediate group control */
3895 set_gain (val, group_override);
3899 case TrimAutomation:
3900 /* route must mediate group control */
3901 set_trim (val, group_override);
3905 case RecEnableAutomation:
3906 /* session must mediate group control */
3907 rl.reset (new RouteList);
3908 rl->push_back (shared_from_this());
3909 _session.set_record_enabled (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
3913 case SoloAutomation:
3914 /* session must mediate group control */
3915 rl.reset (new RouteList);
3916 rl->push_back (shared_from_this());
3917 if (Config->get_solo_control_is_listen_control()) {
3918 _session.set_listen (rl, val >= 0.5 ? true : false, Session::rt_cleanup, group_override);
3920 _session.set_solo (rl, val >= 0.5 ? true : false);
3926 case MuteAutomation:
3927 /* session must mediate group control */
3928 rl.reset (new RouteList);
3929 rl->push_back (shared_from_this());
3930 _session.set_mute (rl, !muted(), Session::rt_cleanup, group_override);
3935 /* Not a route automation control */
3936 fatal << string_compose (_("programming error: %1%2\n"), X_("illegal type of route automation control passed to Route::set_control(): "), enum_2_string(type)) << endmsg;
3943 Route::RouteAutomationControl::RouteAutomationControl (const std::string& name,
3944 AutomationType atype,
3945 boost::shared_ptr<AutomationList> alist,
3946 boost::shared_ptr<Route> r)
3947 : AutomationControl (r->session(), Evoral::Parameter (atype),
3948 ParameterDescriptor (Evoral::Parameter (atype)),
3954 Route::GainControllable::GainControllable (Session& s, AutomationType atype, boost::shared_ptr<Route> r)
3955 : GainControl (s, Evoral::Parameter(atype))
3961 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3962 : RouteAutomationControl (name, SoloAutomation, boost::shared_ptr<AutomationList>(), r)
3964 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3965 gl->set_interpolation(Evoral::ControlList::Discrete);
3970 Route::SoloControllable::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
3973 _set_value (val, group_override);
3978 Route::SoloControllable::_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
3980 const bool bval = ((val >= 0.5) ? true : false);
3982 boost::shared_ptr<RouteList> rl (new RouteList);
3984 boost::shared_ptr<Route> r = _route.lock ();
3991 if (Config->get_solo_control_is_listen_control()) {
3992 _session.set_listen (rl, bval, Session::rt_cleanup, group_override);
3994 _session.set_solo (rl, bval, Session::rt_cleanup, group_override);
3999 Route::SoloControllable::set_value_unchecked (double val)
4001 /* Used only by automation playback */
4003 _set_value (val, Controllable::NoGroup);
4007 Route::SoloControllable::get_value () const
4009 boost::shared_ptr<Route> r = _route.lock ();
4014 if (Config->get_solo_control_is_listen_control()) {
4015 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
4017 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
4021 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
4022 : RouteAutomationControl (name, MuteAutomation, boost::shared_ptr<AutomationList>(), r)
4025 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
4026 gl->set_interpolation(Evoral::ControlList::Discrete);
4031 Route::MuteControllable::set_superficial_value(bool muted)
4033 /* Note we can not use AutomationControl::set_value here since it will emit
4034 Changed(), but the value will not be correct to the observer. */
4036 const bool to_list = _list && ((AutomationList*)_list.get ())->automation_write ();
4037 const double where = _session.audible_frame ();
4039 /* Note that we really need this:
4040 * if (as == Touch && _list->in_new_write_pass ()) {
4041 * alist->start_write_pass (_session.audible_frame ());
4043 * here in the case of the user calling from a GUI or whatever.
4044 * Without the ability to distinguish between user and
4045 * automation-initiated changes, we lose the "touch mute"
4046 * behaviour we have in AutomationController::toggled ().
4048 _list->set_in_write_pass (true, false, where);
4051 Control::set_double (muted, where, to_list);
4055 Route::MuteControllable::set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
4058 _set_value (val, group_override);
4063 Route::MuteControllable::set_value_unchecked (double val)
4065 /* used only automation playback */
4066 _set_value (val, Controllable::NoGroup);
4070 Route::MuteControllable::_set_value (double val, Controllable::GroupControlDisposition group_override)
4072 const bool bval = ((val >= 0.5) ? true : false);
4074 boost::shared_ptr<Route> r = _route.lock ();
4079 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
4080 // Set superficial/automation value to drive controller (and possibly record)
4081 set_superficial_value (bval);
4082 // Playing back automation, set route mute directly
4083 r->set_mute (bval, Controllable::NoGroup);
4085 // Set from user, queue mute event
4086 boost::shared_ptr<RouteList> rl (new RouteList);
4088 _session.set_mute (rl, bval, Session::rt_cleanup, group_override);
4093 Route::MuteControllable::get_value () const
4095 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
4096 // Playing back automation, get the value from the list
4097 return AutomationControl::get_value();
4100 // Not playing back automation, get the actual route mute value
4101 boost::shared_ptr<Route> r = _route.lock ();
4102 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
4105 Route::PhaseControllable::PhaseControllable (std::string name, boost::shared_ptr<Route> r)
4106 : RouteAutomationControl (name, PhaseAutomation, boost::shared_ptr<AutomationList>(), r)
4108 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(PhaseAutomation)));
4109 gl->set_interpolation(Evoral::ControlList::Discrete);
4114 Route::PhaseControllable::set_value (double v, PBD::Controllable::GroupControlDisposition /* group_override */)
4116 boost::shared_ptr<Route> r = _route.lock ();
4117 if (r->phase_invert().size()) {
4118 if (v == 0 || (v < 1 && v > 0.9) ) {
4119 r->set_phase_invert (_current_phase, false);
4121 r->set_phase_invert (_current_phase, true);
4127 Route::PhaseControllable::get_value () const
4129 boost::shared_ptr<Route> r = _route.lock ();
4130 return (double) r->phase_invert (_current_phase);
4134 Route::PhaseControllable::set_channel (uint32_t c)
4140 Route::PhaseControllable::channel () const
4142 return _current_phase;
4146 Route::set_block_size (pframes_t nframes)
4148 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4149 (*i)->set_block_size (nframes);
4152 _session.ensure_buffers (n_process_buffers ());
4156 Route::protect_automation ()
4158 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4159 (*i)->protect_automation();
4162 /** @param declick 1 to set a pending declick fade-in,
4163 * -1 to set a pending declick fade-out
4166 Route::set_pending_declick (int declick)
4169 /* this call is not allowed to turn off a pending declick */
4171 _pending_declick = declick;
4174 _pending_declick = 0;
4178 /** Shift automation forwards from a particular place, thereby inserting time.
4179 * Adds undo commands for any shifts that are performed.
4181 * @param pos Position to start shifting from.
4182 * @param frames Amount to shift forwards by.
4186 Route::shift (framepos_t pos, framecnt_t frames)
4188 /* gain automation */
4190 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4192 XMLNode &before = gc->alist()->get_state ();
4193 gc->alist()->shift (pos, frames);
4194 XMLNode &after = gc->alist()->get_state ();
4195 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4198 /* gain automation */
4200 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4202 XMLNode &before = gc->alist()->get_state ();
4203 gc->alist()->shift (pos, frames);
4204 XMLNode &after = gc->alist()->get_state ();
4205 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4208 // TODO mute automation ??
4210 /* pan automation */
4212 ControlSet::Controls& c (_pannable->controls());
4214 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4215 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4217 boost::shared_ptr<AutomationList> al = pc->alist();
4218 XMLNode& before = al->get_state ();
4219 al->shift (pos, frames);
4220 XMLNode& after = al->get_state ();
4221 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4226 /* redirect automation */
4228 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4229 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4231 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4233 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4234 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4236 boost::shared_ptr<AutomationList> al = ac->alist();
4237 XMLNode &before = al->get_state ();
4238 al->shift (pos, frames);
4239 XMLNode &after = al->get_state ();
4240 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4248 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4250 boost::shared_ptr<Processor> processor (p.lock ());
4251 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4255 pi->set_state_dir (d);
4259 Route::save_as_template (const string& path, const string& name)
4261 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4262 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4264 XMLNode& node (state (false));
4268 IO::set_name_in_state (*node.children().front(), name);
4270 tree.set_root (&node);
4272 /* return zero on success, non-zero otherwise */
4273 return !tree.write (path.c_str());
4278 Route::set_name (const string& str)
4280 if (str == name()) {
4284 string name = Route::ensure_track_or_route_name (str, _session);
4285 SessionObject::set_name (name);
4287 bool ret = (_input->set_name(name) && _output->set_name(name));
4290 /* rename the main outs. Leave other IO processors
4291 * with whatever name they already have, because its
4292 * just fine as it is (it will not contain the route
4293 * name if its a port insert, port send or port return).
4297 if (_main_outs->set_name (name)) {
4298 /* XXX returning false here is stupid because
4299 we already changed the route name.
4309 /** Set the name of a route in an XML description.
4310 * @param node XML <Route> node to set the name in.
4311 * @param name New name.
4314 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4316 node.add_property (X_("name"), name);
4318 XMLNodeList children = node.children();
4319 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4321 if ((*i)->name() == X_("IO")) {
4323 IO::set_name_in_state (**i, name);
4325 } else if ((*i)->name() == X_("Processor")) {
4327 XMLProperty* role = (*i)->property (X_("role"));
4328 if (role && role->value() == X_("Main")) {
4329 (*i)->add_property (X_("name"), name);
4332 } else if ((*i)->name() == X_("Diskstream")) {
4334 if (rename_playlist) {
4335 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4337 (*i)->add_property (X_("name"), name);
4343 boost::shared_ptr<Send>
4344 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4346 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4348 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4349 boost::shared_ptr<InternalSend> send;
4351 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4352 if (send->target_route() == target) {
4358 return boost::shared_ptr<Send>();
4361 /** @param c Audio channel index.
4362 * @param yn true to invert phase, otherwise false.
4365 Route::set_phase_invert (uint32_t c, bool yn)
4367 if (_phase_invert[c] != yn) {
4368 _phase_invert[c] = yn;
4369 phase_invert_changed (); /* EMIT SIGNAL */
4370 _session.set_dirty ();
4375 Route::set_phase_invert (boost::dynamic_bitset<> p)
4377 if (_phase_invert != p) {
4379 phase_invert_changed (); /* EMIT SIGNAL */
4380 _session.set_dirty ();
4385 Route::phase_invert (uint32_t c) const
4387 return _phase_invert[c];
4390 boost::dynamic_bitset<>
4391 Route::phase_invert () const
4393 return _phase_invert;
4397 Route::set_denormal_protection (bool yn)
4399 if (_denormal_protection != yn) {
4400 _denormal_protection = yn;
4401 denormal_protection_changed (); /* EMIT SIGNAL */
4406 Route::denormal_protection () const
4408 return _denormal_protection;
4412 Route::set_active (bool yn, void* src)
4414 if (_session.transport_rolling()) {
4418 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4419 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4423 if (_active != yn) {
4425 _input->set_active (yn);
4426 _output->set_active (yn);
4427 active_changed (); // EMIT SIGNAL
4428 _session.set_dirty ();
4432 boost::shared_ptr<Pannable>
4433 Route::pannable() const
4438 boost::shared_ptr<Panner>
4439 Route::panner() const
4442 return _main_outs->panner_shell()->panner();
4445 boost::shared_ptr<PannerShell>
4446 Route::panner_shell() const
4448 return _main_outs->panner_shell();
4451 boost::shared_ptr<GainControl>
4452 Route::gain_control() const
4454 return _gain_control;
4457 boost::shared_ptr<GainControl>
4458 Route::trim_control() const
4460 return _trim_control;
4463 boost::shared_ptr<AutomationControl>
4464 Route::get_control (const Evoral::Parameter& param)
4466 /* either we own the control or .... */
4468 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4472 /* maybe one of our processors does or ... */
4474 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4475 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4476 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4484 /* nobody does so we'll make a new one */
4486 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4493 boost::shared_ptr<Processor>
4494 Route::nth_plugin (uint32_t n)
4496 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4497 ProcessorList::iterator i;
4499 for (i = _processors.begin(); i != _processors.end(); ++i) {
4500 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4507 return boost::shared_ptr<Processor> ();
4510 boost::shared_ptr<Processor>
4511 Route::nth_send (uint32_t n)
4513 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4514 ProcessorList::iterator i;
4516 for (i = _processors.begin(); i != _processors.end(); ++i) {
4517 if (boost::dynamic_pointer_cast<Send> (*i)) {
4524 return boost::shared_ptr<Processor> ();
4528 Route::has_io_processor_named (const string& name)
4530 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4531 ProcessorList::iterator i;
4533 for (i = _processors.begin(); i != _processors.end(); ++i) {
4534 if (boost::dynamic_pointer_cast<Send> (*i) ||
4535 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4536 if ((*i)->name() == name) {
4545 MuteMaster::MutePoint
4546 Route::mute_points () const
4548 return _mute_master->mute_points ();
4552 Route::set_processor_positions ()
4554 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4556 bool had_amp = false;
4557 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4558 (*i)->set_pre_fader (!had_amp);
4565 /** Called when there is a proposed change to the input port count */
4567 Route::input_port_count_changing (ChanCount to)
4569 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4571 /* The processors cannot be configured with the new input arrangement, so
4577 /* The change is ok */
4581 /** Called when there is a proposed change to the output port count */
4583 Route::output_port_count_changing (ChanCount to)
4585 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4586 if (processor_out_streams.get(*t) > to.get(*t)) {
4590 /* The change is ok */
4595 Route::unknown_processors () const
4599 if (_session.get_disable_all_loaded_plugins ()) {
4600 // Do not list "missing plugins" if they are explicitly disabled
4604 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4605 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4606 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4607 p.push_back ((*i)->name ());
4616 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4618 /* we assume that all our input ports feed all our output ports. its not
4619 universally true, but the alternative is way too corner-case to worry about.
4622 LatencyRange all_connections;
4625 all_connections.min = 0;
4626 all_connections.max = 0;
4628 all_connections.min = ~((pframes_t) 0);
4629 all_connections.max = 0;
4631 /* iterate over all "from" ports and determine the latency range for all of their
4632 connections to the "outside" (outside of this Route).
4635 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4639 p->get_connected_latency_range (range, playback);
4641 all_connections.min = min (all_connections.min, range.min);
4642 all_connections.max = max (all_connections.max, range.max);
4646 /* set the "from" port latencies to the max/min range of all their connections */
4648 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4649 p->set_private_latency_range (all_connections, playback);
4652 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4654 all_connections.min += our_latency;
4655 all_connections.max += our_latency;
4657 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4658 p->set_private_latency_range (all_connections, playback);
4661 return all_connections.max;
4665 Route::set_private_port_latencies (bool playback) const
4667 framecnt_t own_latency = 0;
4669 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4670 OR LATENCY CALLBACK.
4672 This is called (early) from the latency callback. It computes the REAL
4673 latency associated with each port and stores the result as the "private"
4674 latency of the port. A later call to Route::set_public_port_latencies()
4675 sets all ports to the same value to reflect the fact that we do latency
4676 compensation and so all signals are delayed by the same amount as they
4677 flow through ardour.
4680 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4681 if ((*i)->active ()) {
4682 own_latency += (*i)->signal_latency ();
4687 /* playback: propagate latency from "outside the route" to outputs to inputs */
4688 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4690 /* capture: propagate latency from "outside the route" to inputs to outputs */
4691 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4696 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4698 /* this is called to set the JACK-visible port latencies, which take
4699 latency compensation into account.
4708 const PortSet& ports (_input->ports());
4709 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4710 p->set_public_latency_range (range, playback);
4715 const PortSet& ports (_output->ports());
4716 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4717 p->set_public_latency_range (range, playback);
4722 /** Put the invisible processors in the right place in _processors.
4723 * Must be called with a writer lock on _processor_lock held.
4726 __attribute__((annotate("realtime")))
4729 Route::setup_invisible_processors ()
4732 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4733 assert (!lm.locked ());
4737 /* too early to be doing this stuff */
4741 /* we'll build this new list here and then use it
4743 * TODO put the ProcessorList is on the stack for RT-safety.
4746 ProcessorList new_processors;
4748 /* find visible processors */
4750 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4751 if ((*i)->display_to_user ()) {
4752 new_processors.push_back (*i);
4758 ProcessorList::iterator amp = new_processors.begin ();
4759 while (amp != new_processors.end() && *amp != _amp) {
4763 assert (amp != new_processors.end ());
4765 /* and the processor after the amp */
4767 ProcessorList::iterator after_amp = amp;
4773 switch (_meter_point) {
4775 assert (!_meter->display_to_user ());
4776 new_processors.push_front (_meter);
4779 assert (!_meter->display_to_user ());
4780 new_processors.insert (amp, _meter);
4782 case MeterPostFader:
4783 /* do nothing here */
4786 /* do nothing here */
4789 /* the meter is visible, so we don't touch it here */
4796 assert (_main_outs);
4797 assert (!_main_outs->display_to_user ());
4798 new_processors.push_back (_main_outs);
4800 /* iterator for the main outs */
4802 ProcessorList::iterator main = new_processors.end();
4805 /* OUTPUT METERING */
4807 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4808 assert (!_meter->display_to_user ());
4810 /* add the processor just before or just after the main outs */
4812 ProcessorList::iterator meter_point = main;
4814 if (_meter_point == MeterOutput) {
4817 new_processors.insert (meter_point, _meter);
4822 if (_monitor_send && !is_monitor ()) {
4823 assert (!_monitor_send->display_to_user ());
4824 switch (Config->get_listen_position ()) {
4825 case PreFaderListen:
4826 switch (Config->get_pfl_position ()) {
4827 case PFLFromBeforeProcessors:
4828 new_processors.push_front (_monitor_send);
4830 case PFLFromAfterProcessors:
4831 new_processors.insert (amp, _monitor_send);
4834 _monitor_send->set_can_pan (false);
4836 case AfterFaderListen:
4837 switch (Config->get_afl_position ()) {
4838 case AFLFromBeforeProcessors:
4839 new_processors.insert (after_amp, _monitor_send);
4841 case AFLFromAfterProcessors:
4842 new_processors.insert (new_processors.end(), _monitor_send);
4845 _monitor_send->set_can_pan (true);
4850 #if 0 // not used - just yet
4851 if (!is_master() && !is_monitor() && !is_auditioner()) {
4852 new_processors.push_front (_delayline);
4856 /* MONITOR CONTROL */
4858 if (_monitor_control && is_monitor ()) {
4859 assert (!_monitor_control->display_to_user ());
4860 new_processors.insert (amp, _monitor_control);
4863 /* INTERNAL RETURN */
4865 /* doing this here means that any monitor control will come just after
4870 assert (!_intreturn->display_to_user ());
4871 new_processors.push_front (_intreturn);
4874 if (_trim && _trim->active()) {
4875 assert (!_trim->display_to_user ());
4876 new_processors.push_front (_trim);
4878 /* EXPORT PROCESSOR */
4880 if (_capturing_processor) {
4881 assert (!_capturing_processor->display_to_user ());
4882 new_processors.push_front (_capturing_processor);
4885 _processors = new_processors;
4887 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4888 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4893 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4894 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4895 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4902 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4903 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4907 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4908 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4915 /** If the meter point is `Custom', make a note of where the meter is.
4916 * This is so that if the meter point is subsequently set to something else,
4917 * and then back to custom, we can put the meter back where it was last time
4918 * custom was enabled.
4920 * Must be called with the _processor_lock held.
4923 Route::maybe_note_meter_position ()
4925 if (_meter_point != MeterCustom) {
4929 _custom_meter_position_noted = true;
4930 /* custom meter points range from after trim to before panner/main_outs
4931 * this is a limitation by the current processor UI
4933 bool seen_trim = false;
4934 _processor_after_last_custom_meter.reset();
4935 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4936 if ((*i) == _trim) {
4939 if ((*i) == _main_outs) {
4940 _processor_after_last_custom_meter = *i;
4943 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4945 _processor_after_last_custom_meter = _trim;
4947 ProcessorList::iterator j = i;
4949 assert(j != _processors.end ()); // main_outs should be before
4950 _processor_after_last_custom_meter = *j;
4955 assert(_processor_after_last_custom_meter.lock());
4958 boost::shared_ptr<Processor>
4959 Route::processor_by_id (PBD::ID id) const
4961 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4962 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4963 if ((*i)->id() == id) {
4968 return boost::shared_ptr<Processor> ();
4971 /** @return the monitoring state, or in other words what data we are pushing
4972 * into the route (data from the inputs, data from disk or silence)
4975 Route::monitoring_state () const
4977 return MonitoringInput;
4980 /** @return what we should be metering; either the data coming from the input
4981 * IO or the data that is flowing through the route.
4984 Route::metering_state () const
4986 return MeteringRoute;
4990 Route::has_external_redirects () const
4992 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4994 /* ignore inactive processors and obviously ignore the main
4995 * outs since everything has them and we don't care.
4998 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5006 boost::shared_ptr<Processor>
5007 Route::the_instrument () const
5009 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5010 return the_instrument_unlocked ();
5013 boost::shared_ptr<Processor>
5014 Route::the_instrument_unlocked () const
5016 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5017 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
5018 if ((*i)->input_streams().n_midi() > 0 &&
5019 (*i)->output_streams().n_audio() > 0) {
5024 return boost::shared_ptr<Processor>();
5030 Route::non_realtime_locate (framepos_t pos)
5033 _pannable->transport_located (pos);
5036 if (_delayline.get()) {
5037 _delayline.get()->flush();
5041 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5042 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5044 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5045 (*i)->transport_located (pos);
5048 _roll_delay = _initial_delay;
5052 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5059 * We don't currently mix MIDI input together, so we don't need the
5060 * complex logic of the audio case.
5063 n_buffers = bufs.count().n_midi ();
5065 for (i = 0; i < n_buffers; ++i) {
5067 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5068 MidiBuffer& buf (bufs.get_midi (i));
5071 buf.copy (source_port->get_midi_buffer(nframes));
5073 buf.silence (nframes);
5079 n_buffers = bufs.count().n_audio();
5081 size_t n_ports = io->n_ports().n_audio();
5082 float scaling = 1.0f;
5084 if (n_ports > n_buffers) {
5085 scaling = ((float) n_buffers) / n_ports;
5088 for (i = 0; i < n_ports; ++i) {
5090 /* if there are more ports than buffers, map them onto buffers
5091 * in a round-robin fashion
5094 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5095 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5098 if (i < n_buffers) {
5100 /* first time through just copy a channel into
5104 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5106 if (scaling != 1.0f) {
5107 buf.apply_gain (scaling, nframes);
5112 /* on subsequent times around, merge data from
5113 * the port with what is already there
5116 if (scaling != 1.0f) {
5117 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5119 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5124 /* silence any remaining buffers */
5126 for (; i < n_buffers; ++i) {
5127 AudioBuffer& buf (bufs.get_audio (i));
5128 buf.silence (nframes);
5131 /* establish the initial setup of the buffer set, reflecting what was
5132 copied into it. unless, of course, we are the auditioner, in which
5133 case nothing was fed into it from the inputs at all.
5136 if (!is_auditioner()) {
5137 bufs.set_count (io->n_ports());
5141 boost::shared_ptr<AutomationControl>
5142 Route::pan_azimuth_control() const
5145 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5147 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5148 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5150 if (!_pannable || !panner()) {
5151 return boost::shared_ptr<AutomationControl>();
5153 return _pannable->pan_azimuth_control;
5157 boost::shared_ptr<AutomationControl>
5158 Route::pan_elevation_control() const
5160 if (Profile->get_mixbus() || !_pannable || !panner()) {
5161 return boost::shared_ptr<AutomationControl>();
5164 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5166 if (c.find (PanElevationAutomation) != c.end()) {
5167 return _pannable->pan_elevation_control;
5169 return boost::shared_ptr<AutomationControl>();
5172 boost::shared_ptr<AutomationControl>
5173 Route::pan_width_control() const
5175 if (Profile->get_mixbus() || !_pannable || !panner()) {
5176 return boost::shared_ptr<AutomationControl>();
5179 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5181 if (c.find (PanWidthAutomation) != c.end()) {
5182 return _pannable->pan_width_control;
5184 return boost::shared_ptr<AutomationControl>();
5187 boost::shared_ptr<AutomationControl>
5188 Route::pan_frontback_control() const
5190 if (Profile->get_mixbus() || !_pannable || !panner()) {
5191 return boost::shared_ptr<AutomationControl>();
5194 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5196 if (c.find (PanFrontBackAutomation) != c.end()) {
5197 return _pannable->pan_frontback_control;
5199 return boost::shared_ptr<AutomationControl>();
5202 boost::shared_ptr<AutomationControl>
5203 Route::pan_lfe_control() const
5205 if (Profile->get_mixbus() || !_pannable || !panner()) {
5206 return boost::shared_ptr<AutomationControl>();
5209 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5211 if (c.find (PanLFEAutomation) != c.end()) {
5212 return _pannable->pan_lfe_control;
5214 return boost::shared_ptr<AutomationControl>();
5219 Route::eq_band_cnt () const
5221 if (Profile->get_mixbus()) {
5224 /* Ardour has no well-known EQ object */
5229 boost::shared_ptr<AutomationControl>
5230 Route::eq_gain_controllable (uint32_t band) const
5233 boost::shared_ptr<PluginInsert> eq = ch_eq();
5236 return boost::shared_ptr<AutomationControl>();
5239 uint32_t port_number;
5242 if (is_master() || mixbus()) {
5249 if (is_master() || mixbus()) {
5256 if (is_master() || mixbus()) {
5263 return boost::shared_ptr<AutomationControl>();
5266 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5268 return boost::shared_ptr<AutomationControl>();
5271 boost::shared_ptr<AutomationControl>
5272 Route::eq_freq_controllable (uint32_t band) const
5276 if (mixbus() || is_master()) {
5277 /* no frequency controls for mixbusses or master */
5278 return boost::shared_ptr<AutomationControl>();
5281 boost::shared_ptr<PluginInsert> eq = ch_eq();
5284 return boost::shared_ptr<AutomationControl>();
5287 uint32_t port_number;
5299 return boost::shared_ptr<AutomationControl>();
5302 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5304 return boost::shared_ptr<AutomationControl>();
5308 boost::shared_ptr<AutomationControl>
5309 Route::eq_q_controllable (uint32_t band) const
5311 return boost::shared_ptr<AutomationControl>();
5314 boost::shared_ptr<AutomationControl>
5315 Route::eq_shape_controllable (uint32_t band) const
5317 return boost::shared_ptr<AutomationControl>();
5320 boost::shared_ptr<AutomationControl>
5321 Route::eq_enable_controllable () const
5324 boost::shared_ptr<PluginInsert> eq = ch_eq();
5327 return boost::shared_ptr<AutomationControl>();
5330 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5332 return boost::shared_ptr<AutomationControl>();
5336 boost::shared_ptr<AutomationControl>
5337 Route::eq_hpf_controllable () const
5340 boost::shared_ptr<PluginInsert> eq = ch_eq();
5343 return boost::shared_ptr<AutomationControl>();
5346 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5348 return boost::shared_ptr<AutomationControl>();
5353 Route::eq_band_name (uint32_t band) const
5355 if (Profile->get_mixbus()) {
5371 boost::shared_ptr<AutomationControl>
5372 Route::comp_enable_controllable () const
5375 boost::shared_ptr<PluginInsert> comp = ch_comp();
5378 return boost::shared_ptr<AutomationControl>();
5381 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5383 return boost::shared_ptr<AutomationControl>();
5386 boost::shared_ptr<AutomationControl>
5387 Route::comp_threshold_controllable () const
5390 boost::shared_ptr<PluginInsert> comp = ch_comp();
5393 return boost::shared_ptr<AutomationControl>();
5396 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5399 return boost::shared_ptr<AutomationControl>();
5402 boost::shared_ptr<AutomationControl>
5403 Route::comp_speed_controllable () const
5406 boost::shared_ptr<PluginInsert> comp = ch_comp();
5409 return boost::shared_ptr<AutomationControl>();
5412 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5414 return boost::shared_ptr<AutomationControl>();
5417 boost::shared_ptr<AutomationControl>
5418 Route::comp_mode_controllable () const
5421 boost::shared_ptr<PluginInsert> comp = ch_comp();
5424 return boost::shared_ptr<AutomationControl>();
5427 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5429 return boost::shared_ptr<AutomationControl>();
5432 boost::shared_ptr<AutomationControl>
5433 Route::comp_makeup_controllable () const
5436 boost::shared_ptr<PluginInsert> comp = ch_comp();
5439 return boost::shared_ptr<AutomationControl>();
5442 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5444 return boost::shared_ptr<AutomationControl>();
5447 boost::shared_ptr<AutomationControl>
5448 Route::comp_redux_controllable () const
5451 boost::shared_ptr<PluginInsert> comp = ch_comp();
5454 return boost::shared_ptr<AutomationControl>();
5457 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5459 return boost::shared_ptr<AutomationControl>();
5464 Route::comp_mode_name (uint32_t mode) const
5469 return _("Leveler");
5471 return _("Compressor");
5473 return _("Limiter");
5483 Route::comp_speed_name (uint32_t mode) const