2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/boost_debug.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/plugin_insert.h"
62 #include "ardour/port.h"
63 #include "ardour/port_insert.h"
64 #include "ardour/processor.h"
65 #include "ardour/profile.h"
66 #include "ardour/route.h"
67 #include "ardour/route_group.h"
68 #include "ardour/send.h"
69 #include "ardour/session.h"
70 #include "ardour/unknown_processor.h"
71 #include "ardour/utils.h"
76 using namespace ARDOUR;
79 PBD::Signal0<void> Route::SyncOrderKeys;
80 PBD::Signal0<void> Route::RemoteControlIDChange;
82 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
83 : SessionObject (sess, name)
85 , GraphNode (sess._process_graph)
88 , _signal_latency_at_amp_position (0)
89 , _signal_latency_at_trim_position (0)
92 , _pending_process_reorder (0)
93 , _pending_signals (0)
95 , _pending_declick (true)
96 , _meter_point (MeterPostFader)
97 , _pending_meter_point (MeterPostFader)
98 , _meter_type (MeterPeak)
100 , _soloed_by_others_upstream (0)
101 , _soloed_by_others_downstream (0)
102 , _solo_isolated (false)
103 , _solo_isolated_by_upstream (0)
104 , _denormal_protection (false)
107 , _declickable (false)
108 , _mute_master (new MuteMaster (sess, name))
109 , _have_internal_generator (false)
111 , _default_type (default_type)
113 , _has_order_key (false)
114 , _remote_control_id (0)
116 , _in_configure_processors (false)
117 , _initial_io_setup (false)
118 , _custom_meter_position_noted (false)
120 processor_max_streams.reset();
126 /* set default meter type */
128 _meter_type = Config->get_meter_type_master ();
130 else if (dynamic_cast<Track*>(this)) {
131 _meter_type = Config->get_meter_type_track ();
133 _meter_type = Config->get_meter_type_bus ();
136 /* add standard controls */
138 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
139 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
140 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
142 _solo_isolate_control.reset (new SoloIsolateControllable (X_("solo-iso"), shared_from_this ()));
143 _solo_safe_control.reset (new SoloSafeControllable (X_("solo-safe"), shared_from_this ()));
145 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
146 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
147 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
149 add_control (_solo_control);
150 add_control (_mute_control);
151 add_control (_phase_control);
155 if (!(_flags & Route::MonitorOut)) {
156 _pannable.reset (new Pannable (_session));
159 /* input and output objects */
161 _input.reset (new IO (_session, _name, IO::Input, _default_type));
162 _output.reset (new IO (_session, _name, IO::Output, _default_type));
164 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
165 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
167 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
168 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
170 #if 0 // not used - just yet
171 if (!is_master() && !is_monitor() && !is_auditioner()) {
172 _delayline.reset (new DelayLine (_session, _name));
173 add_processor (_delayline, PreFader);
177 /* add amp processor */
179 _gain_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, GainAutomation, shared_from_this ()));
180 add_control (_gain_control);
182 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
183 add_processor (_amp, PostFader);
186 _amp->set_display_name (_("Monitor"));
191 _trim_control = boost::shared_ptr<GainControllable> (new GainControllable (_session, TrimAutomation, shared_from_this ()));
192 add_control (_trim_control);
194 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
195 _trim->set_display_to_user (false);
197 if (dynamic_cast<AudioTrack*>(this)) {
198 /* we can't do this in the AudioTrack's constructor
199 * because _trim does not exit then
203 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
208 /* create standard processors: meter, main outs, monitor out;
209 they will be added to _processors by setup_invisible_processors ()
212 _meter.reset (new PeakMeter (_session, _name));
213 _meter->set_owner (this);
214 _meter->set_display_to_user (false);
217 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
218 _main_outs->activate ();
221 /* where we listen to tracks */
222 _intreturn.reset (new InternalReturn (_session));
223 _intreturn->activate ();
225 /* the thing that provides proper control over a control/monitor/listen bus
226 (such as per-channel cut, dim, solo, invert, etc).
228 _monitor_control.reset (new MonitorProcessor (_session));
229 _monitor_control->activate ();
232 if (is_master() || is_monitor() || is_auditioner()) {
233 _mute_master->set_solo_ignore (true);
236 /* now that we have _meter, its safe to connect to this */
239 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
240 configure_processors (0);
248 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
250 /* do this early so that we don't get incoming signals as we are going through destruction
255 /* don't use clear_processors here, as it depends on the session which may
256 be half-destroyed by now
259 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
260 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
261 (*i)->drop_references ();
264 _processors.clear ();
268 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
270 if (Config->get_remote_model() != UserOrdered) {
274 set_remote_control_id_internal (id, notify_class_listeners);
278 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
280 /* force IDs for master/monitor busses and prevent
281 any other route from accidentally getting these IDs
282 (i.e. legacy sessions)
285 if (is_master() && id != MasterBusRemoteControlID) {
286 id = MasterBusRemoteControlID;
289 if (is_monitor() && id != MonitorBusRemoteControlID) {
290 id = MonitorBusRemoteControlID;
297 /* don't allow it to collide */
299 if (!is_master () && !is_monitor() &&
300 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
301 id += MonitorBusRemoteControlID;
304 if (id != remote_control_id()) {
305 _remote_control_id = id;
306 RemoteControlIDChanged ();
308 if (notify_class_listeners) {
309 RemoteControlIDChange ();
315 Route::remote_control_id() const
318 return MasterBusRemoteControlID;
322 return MonitorBusRemoteControlID;
325 return _remote_control_id;
329 Route::has_order_key () const
331 return _has_order_key;
335 Route::order_key () const
341 Route::set_remote_control_id_explicit (uint32_t rid)
343 if (is_master() || is_monitor() || is_auditioner()) {
344 /* hard-coded remote IDs, or no remote ID */
348 if (_remote_control_id != rid) {
349 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
350 _remote_control_id = rid;
351 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
354 /* don't emit the class-level RID signal RemoteControlIDChange here,
355 leave that to the entity that changed the order key, so that we
356 don't get lots of emissions for no good reasons (e.g. when changing
357 all route order keys).
359 See Session::sync_remote_id_from_order_keys() for the (primary|only)
360 spot where that is emitted.
365 Route::set_order_key (uint32_t n)
367 _has_order_key = true;
369 if (_order_key == n) {
375 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
376 name(), order_key ()));
378 _session.set_dirty ();
382 Route::ensure_track_or_route_name(string name, Session &session)
384 string newname = name;
386 while (!session.io_name_is_legal (newname)) {
387 newname = bump_name_once (newname, ' ');
394 Route::inc_gain (gain_t factor)
396 /* To be used ONLY when doing group-relative gain adjustment, from
400 float desired_gain = _gain_control->user_double();
402 if (fabsf (desired_gain) < GAIN_COEFF_SMALL) {
403 // really?! what's the idea here?
404 _gain_control->route_set_value (0.000001f + (0.000001f * factor));
406 _gain_control->route_set_value (desired_gain + (desired_gain * factor));
411 Route::set_gain (gain_t val, Controllable::GroupControlDisposition group_override)
413 if (use_group (group_override, &RouteGroup::is_gain)) {
415 if (_route_group->is_relative()) {
417 gain_t usable_gain = _gain_control->get_value();
418 if (usable_gain < 0.000001f) {
419 usable_gain = 0.000001f;
423 if (delta < 0.000001f) {
427 delta -= usable_gain;
432 gain_t factor = delta / usable_gain;
435 factor = _route_group->get_max_factor(factor);
436 if (factor == 0.0f) {
437 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
441 factor = _route_group->get_min_factor(factor);
442 if (factor == 0.0f) {
443 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
448 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor));
452 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, Controllable::NoGroup));
458 if (val == _gain_control->get_value()) {
462 _gain_control->route_set_value (val);
466 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
468 // TODO route group, see set_gain()
469 _trim_control->route_set_value (val);
473 Route::maybe_declick (BufferSet&, framecnt_t, int)
475 /* this is the "bus" implementation and they never declick.
480 /** Process this route for one (sub) cycle (process thread)
482 * @param bufs Scratch buffers to use for the signal path
483 * @param start_frame Initial transport frame
484 * @param end_frame Final transport frame
485 * @param nframes Number of frames to output (to ports)
487 * Note that (end_frame - start_frame) may not be equal to nframes when the
488 * transport speed isn't 1.0 (eg varispeed).
491 Route::process_output_buffers (BufferSet& bufs,
492 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
493 int declick, bool gain_automation_ok)
495 /* Caller must hold process lock */
496 assert (!AudioEngine::instance()->process_lock().trylock());
498 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
500 // can this actually happen? functions calling process_output_buffers()
501 // already take a reader-lock.
502 bufs.silence (nframes, 0);
506 /* figure out if we're going to use gain automation */
507 if (gain_automation_ok) {
508 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
509 _amp->setup_gain_automation (
510 start_frame + _signal_latency_at_amp_position,
511 end_frame + _signal_latency_at_amp_position,
514 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
515 _trim->setup_gain_automation (
516 start_frame + _signal_latency_at_trim_position,
517 end_frame + _signal_latency_at_trim_position,
520 _amp->apply_gain_automation (false);
521 _trim->apply_gain_automation (false);
524 /* Tell main outs what to do about monitoring. We do this so that
525 on a transition between monitoring states we get a de-clicking gain
526 change in the _main_outs delivery, if config.get_use_monitor_fades()
529 We override this in the case where we have an internal generator.
531 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
533 _main_outs->no_outs_cuz_we_no_monitor (silence);
535 /* -------------------------------------------------------------------------------------------
536 GLOBAL DECLICK (for transport changes etc.)
537 ----------------------------------------------------------------------------------------- */
539 maybe_declick (bufs, nframes, declick);
540 _pending_declick = 0;
542 /* -------------------------------------------------------------------------------------------
543 DENORMAL CONTROL/PHASE INVERT
544 ----------------------------------------------------------------------------------------- */
546 if (_phase_invert.any ()) {
550 if (_denormal_protection || Config->get_denormal_protection()) {
552 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
553 Sample* const sp = i->data();
555 if (_phase_invert[chn]) {
556 for (pframes_t nx = 0; nx < nframes; ++nx) {
561 for (pframes_t nx = 0; nx < nframes; ++nx) {
569 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
570 Sample* const sp = i->data();
572 if (_phase_invert[chn]) {
573 for (pframes_t nx = 0; nx < nframes; ++nx) {
582 if (_denormal_protection || Config->get_denormal_protection()) {
584 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
585 Sample* const sp = i->data();
586 for (pframes_t nx = 0; nx < nframes; ++nx) {
594 /* -------------------------------------------------------------------------------------------
596 ----------------------------------------------------------------------------------------- */
598 /* set this to be true if the meter will already have been ::run() earlier */
599 bool const meter_already_run = metering_state() == MeteringInput;
601 framecnt_t latency = 0;
603 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
605 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
606 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
611 /* if it has any inputs, make sure they match */
612 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
613 if (bufs.count() != (*i)->input_streams()) {
615 DEBUG::Processors, string_compose (
616 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
617 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
624 /* should we NOT run plugins here if the route is inactive?
625 do we catch route != active somewhere higher?
628 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
629 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
632 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
633 bufs.set_count ((*i)->output_streams());
635 if ((*i)->active ()) {
636 latency += (*i)->signal_latency ();
642 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
643 boost::shared_ptr<Processor> endpoint,
644 bool include_endpoint, bool for_export, bool for_freeze)
646 /* If no processing is required, there's no need to go any further. */
647 if (!endpoint && !include_endpoint) {
651 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
652 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
653 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
655 /* trim is always at the top, for bounce no latency compensation is needed */
656 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
657 _trim->setup_gain_automation (start, start + nframes, nframes);
660 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
662 if (!include_endpoint && (*i) == endpoint) {
666 /* if we're not exporting, stop processing if we come across a routing processor. */
667 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
670 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
674 /* don't run any processors that does routing.
675 * oh, and don't bother with the peak meter either.
677 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
678 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
679 buffers.set_count ((*i)->output_streams());
680 latency += (*i)->signal_latency ();
683 if ((*i) == endpoint) {
690 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
691 bool include_endpoint, bool for_export, bool for_freeze) const
693 framecnt_t latency = 0;
694 if (!endpoint && !include_endpoint) {
698 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
699 if (!include_endpoint && (*i) == endpoint) {
702 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
705 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
708 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
709 latency += (*i)->signal_latency ();
711 if ((*i) == endpoint) {
719 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
720 bool include_endpoint, bool for_export, bool for_freeze) const
722 if (!endpoint && !include_endpoint) {
726 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
727 if (!include_endpoint && (*i) == endpoint) {
730 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
733 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
736 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
737 cc = (*i)->output_streams();
739 if ((*i) == endpoint) {
747 Route::n_process_buffers ()
749 return max (_input->n_ports(), processor_max_streams);
753 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
755 assert (is_monitor());
756 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
757 fill_buffers_with_input (bufs, _input, nframes);
758 passthru (bufs, start_frame, end_frame, nframes, declick);
762 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
766 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
768 /* control/monitor bus ignores input ports when something is
769 feeding the listen "stream". data will "arrive" into the
770 route from the intreturn processor element.
773 bufs.silence (nframes, 0);
776 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
777 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
781 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
783 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
785 bufs.set_count (_input->n_ports());
786 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
787 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
791 Route::set_listen (bool yn, Controllable::GroupControlDisposition group_override)
797 if (use_group (group_override, &RouteGroup::is_solo)) {
798 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, Controllable::NoGroup));
803 if (yn != _monitor_send->active()) {
805 _monitor_send->activate ();
806 _mute_master->set_soloed_by_self (true);
808 _monitor_send->deactivate ();
809 _mute_master->set_soloed_by_self (false);
811 _mute_master->set_soloed_by_others (false);
813 listen_changed (group_override); /* EMIT SIGNAL */
819 Route::listening_via_monitor () const
822 return _monitor_send->active ();
829 Route::set_solo_safe (bool yn, Controllable::GroupControlDisposition /* group_override */)
831 if (_solo_safe != yn) {
833 solo_safe_changed (); /* EMIT SIGNAL */
834 _solo_safe_control->Changed(); /* EMIT SIGNAL */
839 Route::solo_safe() const
845 Route::clear_all_solo_state ()
847 // ideally this function will never do anything, it only exists to forestall Murphy
848 bool emit_changed = false;
851 // these are really debug messages, but of possible interest.
853 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
855 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
856 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
857 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
861 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
862 // if self-soled, set_solo() will do signal emission
866 _soloed_by_others_upstream = 0;
867 _soloed_by_others_downstream = 0;
870 PBD::Unwinder<bool> uw (_solo_safe, false);
871 set_solo (false, Controllable::NoGroup);
875 set_mute_master_solo ();
876 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
881 Route::set_solo (bool yn, Controllable::GroupControlDisposition group_override)
884 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
888 if (is_master() || is_monitor() || is_auditioner()) {
889 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
893 if (use_group (group_override, &RouteGroup::is_solo)) {
894 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, Controllable::NoGroup));
898 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, grp ? %3 currently self-soloed ? %4\n",
899 name(), yn, enum_2_string(group_override), self_soloed()));
901 if (self_soloed() != yn) {
903 solo_changed (true, group_override); /* EMIT SIGNAL */
904 _solo_control->Changed (); /* EMIT SIGNAL */
907 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
909 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
910 Config->get_solo_mute_overrride().
913 if (yn && Profile->get_trx()) {
914 set_mute (false, Controllable::UseGroup);
919 Route::set_self_solo (bool yn)
921 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
923 set_mute_master_solo ();
927 Route::mod_solo_by_others_upstream (int32_t delta)
929 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
930 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
932 uint32_t old_sbu = _soloed_by_others_upstream;
935 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
936 _soloed_by_others_upstream += delta;
938 _soloed_by_others_upstream = 0;
941 _soloed_by_others_upstream += delta;
944 DEBUG_TRACE (DEBUG::Solo, string_compose (
945 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
946 name(), delta, _soloed_by_others_upstream, old_sbu,
947 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
949 /* push the inverse solo change to everything that feeds us.
951 This is important for solo-within-group. When we solo 1 track out of N that
952 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
953 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
954 tracks that feed it. This will silence them if they were audible because
955 of a bus solo, but the newly soloed track will still be audible (because
958 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
962 if ((_self_solo || _soloed_by_others_downstream) &&
963 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
964 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
966 if (delta > 0 || !Config->get_exclusive_solo()) {
967 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
968 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
972 boost::shared_ptr<Route> sr = i->r.lock();
974 sr->mod_solo_by_others_downstream (-delta);
980 set_mute_master_solo ();
981 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
985 Route::mod_solo_by_others_downstream (int32_t delta)
987 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
988 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
991 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
992 _soloed_by_others_downstream += delta;
994 _soloed_by_others_downstream = 0;
997 _soloed_by_others_downstream += delta;
1000 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
1002 set_mute_master_solo ();
1003 solo_changed (false, Controllable::UseGroup); /* EMIT SIGNAL */
1007 Route::set_mute_master_solo ()
1009 _mute_master->set_soloed_by_self (self_soloed());
1010 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1014 Route::mod_solo_isolated_by_upstream (bool yn)
1016 bool old = solo_isolated ();
1017 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1018 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1021 if (_solo_isolated_by_upstream >= 1) {
1022 _solo_isolated_by_upstream--;
1024 _solo_isolated_by_upstream = 0;
1027 _solo_isolated_by_upstream++;
1030 if (solo_isolated() != old) {
1031 /* solo isolated status changed */
1032 _mute_master->set_solo_ignore (solo_isolated());
1033 solo_isolated_changed (); /* EMIT SIGNAL */
1038 Route::set_solo_isolated (bool yn, Controllable::GroupControlDisposition group_override)
1040 if (is_master() || is_monitor() || is_auditioner()) {
1044 if (use_group (group_override, &RouteGroup::is_solo)) {
1045 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, Controllable::NoGroup));
1049 bool changed = false;
1052 if (_solo_isolated == false) {
1053 _mute_master->set_solo_ignore (true);
1056 _solo_isolated = true;
1058 if (_solo_isolated == true) {
1059 _solo_isolated = false;
1060 _mute_master->set_solo_ignore (false);
1070 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1072 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1073 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1075 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1080 bool does_feed = feeds (*i, &sends_only);
1082 if (does_feed && !sends_only) {
1083 (*i)->mod_solo_isolated_by_upstream (yn);
1087 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1089 solo_isolated_changed (); /* EMIT SIGNAL */
1090 _solo_isolate_control->Changed(); /* EMIT SIGNAL */
1094 Route::solo_isolated () const
1096 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1100 Route::set_mute_points (MuteMaster::MutePoint mp)
1102 _mute_master->set_mute_points (mp);
1103 mute_points_changed (); /* EMIT SIGNAL */
1105 if (_mute_master->muted_by_self()) {
1106 mute_changed (); /* EMIT SIGNAL */
1107 _mute_control->Changed (); /* EMIT SIGNAL */
1112 Route::set_mute (bool yn, Controllable::GroupControlDisposition group_override)
1114 if (use_group (group_override, &RouteGroup::is_mute)) {
1115 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, Controllable::NoGroup));
1119 if (muted() != yn) {
1120 _mute_master->set_muted_by_self (yn);
1121 /* allow any derived classes to respond to the mute change
1122 before anybody else knows about it.
1125 /* tell everyone else */
1126 mute_changed (); /* EMIT SIGNAL */
1127 _mute_control->Changed (); /* EMIT SIGNAL */
1132 Route::muted () const
1134 return _mute_master->muted_by_self();
1138 Route::muted_by_others () const
1140 // This method is only used by route_ui for display state.
1141 // The real thing is MuteMaster::muted_by_others_at()
1143 //master is never muted by others
1147 //now check to see if something is soloed (and I am not)
1148 //see also MuteMaster::mute_gain_at()
1149 return (_session.soloing() && !soloed() && !solo_isolated());
1154 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1156 cerr << name << " {" << endl;
1157 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1158 p != procs.end(); ++p) {
1159 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1161 cerr << "}" << endl;
1165 /** Supposing that we want to insert a Processor at a given Placement, return
1166 * the processor to add the new one before (or 0 to add at the end).
1168 boost::shared_ptr<Processor>
1169 Route::before_processor_for_placement (Placement p)
1171 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1173 ProcessorList::iterator loc;
1175 if (p == PreFader) {
1176 /* generic pre-fader: insert immediately before the amp */
1177 loc = find (_processors.begin(), _processors.end(), _amp);
1179 /* generic post-fader: insert right before the main outs */
1180 loc = find (_processors.begin(), _processors.end(), _main_outs);
1183 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1186 /** Supposing that we want to insert a Processor at a given index, return
1187 * the processor to add the new one before (or 0 to add at the end).
1189 boost::shared_ptr<Processor>
1190 Route::before_processor_for_index (int index)
1193 return boost::shared_ptr<Processor> ();
1196 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1198 ProcessorList::iterator i = _processors.begin ();
1200 while (i != _processors.end() && j < index) {
1201 if ((*i)->display_to_user()) {
1208 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1211 /** Add a processor either pre- or post-fader
1212 * @return 0 on success, non-0 on failure.
1215 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1217 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1221 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1222 * @param index Index to add the processor at, or -1 to add at the end of the list.
1223 * @return 0 on success, non-0 on failure.
1226 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1228 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1231 /** Add a processor to the route.
1232 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1233 * @return 0 on success, non-0 on failure.
1236 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1238 assert (processor != _meter);
1239 assert (processor != _main_outs);
1241 DEBUG_TRACE (DEBUG::Processors, string_compose (
1242 "%1 adding processor %2\n", name(), processor->name()));
1244 if (!AudioEngine::instance()->connected() || !processor) {
1249 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1250 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1251 ProcessorState pstate (this);
1253 boost::shared_ptr<PluginInsert> pi;
1254 boost::shared_ptr<PortInsert> porti;
1256 if (processor == _amp) {
1257 /* Ensure that only one amp is in the list at any time */
1258 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1259 if (check != _processors.end()) {
1260 if (before == _amp) {
1261 /* Already in position; all is well */
1264 _processors.erase (check);
1269 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1271 ProcessorList::iterator loc;
1273 /* inserting before a processor; find it */
1274 loc = find (_processors.begin(), _processors.end(), before);
1275 if (loc == _processors.end ()) {
1280 /* inserting at end */
1281 loc = _processors.end ();
1284 _processors.insert (loc, processor);
1285 processor->set_owner (this);
1287 // Set up processor list channels. This will set processor->[input|output]_streams(),
1288 // configure redirect ports properly, etc.
1291 if (configure_processors_unlocked (err)) {
1293 configure_processors_unlocked (0); // it worked before we tried to add it ...
1298 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1300 if (pi->has_no_inputs ()) {
1301 /* generator plugin */
1302 _have_internal_generator = true;
1307 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1308 processor->activate ();
1311 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1313 _output->set_user_latency (0);
1316 reset_instrument_info ();
1317 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1318 set_processor_positions ();
1324 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1326 const XMLProperty *prop;
1329 boost::shared_ptr<Processor> processor;
1331 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1332 so that we can add the processor in the right place (pre/post-fader)
1335 XMLNodeList const & children = node.children ();
1336 XMLNodeList::const_iterator i = children.begin ();
1338 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1342 Placement placement = PreFader;
1344 if (i != children.end()) {
1345 if ((prop = (*i)->property (X_("placement"))) != 0) {
1346 placement = Placement (string_2_enum (prop->value(), placement));
1350 if (node.name() == "Insert") {
1352 if ((prop = node.property ("type")) != 0) {
1354 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1355 prop->value() == "lv2" ||
1356 prop->value() == "windows-vst" ||
1357 prop->value() == "lxvst" ||
1358 prop->value() == "audiounit") {
1360 if (_session.get_disable_all_loaded_plugins ()) {
1361 processor.reset (new UnknownProcessor (_session, node));
1363 processor.reset (new PluginInsert (_session));
1368 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1373 } else if (node.name() == "Send") {
1375 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1376 processor.reset (new Send (_session, sendpan, _mute_master));
1380 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1384 if (processor->set_state (node, version)) {
1388 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1389 if (i != children.end()) {
1390 if ((prop = (*i)->property (X_("active"))) != 0) {
1391 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1392 processor->activate();
1394 processor->deactivate();
1398 return (add_processor (processor, placement, 0, false) == 0);
1401 catch (failed_constructor &err) {
1402 warning << _("processor could not be created. Ignored.") << endmsg;
1408 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1410 /* NOTE: this is intended to be used ONLY when copying
1411 processors from another Route. Hence the subtle
1412 differences between this and ::add_processor()
1415 ProcessorList::iterator loc;
1418 loc = find(_processors.begin(), _processors.end(), before);
1420 /* nothing specified - at end */
1421 loc = _processors.end ();
1424 if (!_session.engine().connected()) {
1428 if (others.empty()) {
1433 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1434 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1435 ProcessorState pstate (this);
1437 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1443 boost::shared_ptr<PluginInsert> pi;
1445 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1449 _processors.insert (loc, *i);
1450 (*i)->set_owner (this);
1452 if ((*i)->active()) {
1456 /* Think: does this really need to be called for every processor in the loop? */
1458 if (configure_processors_unlocked (err)) {
1460 configure_processors_unlocked (0); // it worked before we tried to add it ...
1465 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1468 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1469 boost::shared_ptr<PluginInsert> pi;
1471 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1472 if (pi->has_no_inputs ()) {
1473 _have_internal_generator = true;
1479 _output->set_user_latency (0);
1482 reset_instrument_info ();
1483 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1484 set_processor_positions ();
1490 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1492 if (p == PreFader) {
1493 start = _processors.begin();
1494 end = find(_processors.begin(), _processors.end(), _amp);
1496 start = find(_processors.begin(), _processors.end(), _amp);
1498 end = _processors.end();
1502 /** Turn off all processors with a given placement
1503 * @param p Placement of processors to disable
1506 Route::disable_processors (Placement p)
1508 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1510 ProcessorList::iterator start, end;
1511 placement_range(p, start, end);
1513 for (ProcessorList::iterator i = start; i != end; ++i) {
1514 (*i)->deactivate ();
1517 _session.set_dirty ();
1520 /** Turn off all redirects
1523 Route::disable_processors ()
1525 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1527 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1528 (*i)->deactivate ();
1531 _session.set_dirty ();
1534 /** Turn off all redirects with a given placement
1535 * @param p Placement of redirects to disable
1538 Route::disable_plugins (Placement p)
1540 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1542 ProcessorList::iterator start, end;
1543 placement_range(p, start, end);
1545 for (ProcessorList::iterator i = start; i != end; ++i) {
1546 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1547 (*i)->deactivate ();
1551 _session.set_dirty ();
1554 /** Turn off all plugins
1557 Route::disable_plugins ()
1559 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1561 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1562 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1563 (*i)->deactivate ();
1567 _session.set_dirty ();
1572 Route::ab_plugins (bool forward)
1574 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1578 /* forward = turn off all active redirects, and mark them so that the next time
1579 we go the other way, we will revert them
1582 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1583 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1587 if ((*i)->active()) {
1588 (*i)->deactivate ();
1589 (*i)->set_next_ab_is_active (true);
1591 (*i)->set_next_ab_is_active (false);
1597 /* backward = if the redirect was marked to go active on the next ab, do so */
1599 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1601 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1605 if ((*i)->get_next_ab_is_active()) {
1608 (*i)->deactivate ();
1613 _session.set_dirty ();
1617 /** Remove processors with a given placement.
1618 * @param p Placement of processors to remove.
1621 Route::clear_processors (Placement p)
1623 if (!_session.engine().connected()) {
1627 bool already_deleting = _session.deletion_in_progress();
1628 if (!already_deleting) {
1629 _session.set_deletion_in_progress();
1633 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1634 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1635 ProcessorList new_list;
1636 ProcessorStreams err;
1637 bool seen_amp = false;
1639 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1645 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1647 /* you can't remove these */
1649 new_list.push_back (*i);
1656 new_list.push_back (*i);
1659 (*i)->drop_references ();
1667 (*i)->drop_references ();
1670 new_list.push_back (*i);
1677 _processors = new_list;
1678 configure_processors_unlocked (&err); // this can't fail
1681 processor_max_streams.reset();
1682 _have_internal_generator = false;
1683 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1684 set_processor_positions ();
1686 reset_instrument_info ();
1688 if (!already_deleting) {
1689 _session.clear_deletion_in_progress();
1694 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1696 // TODO once the export point can be configured properly, do something smarter here
1697 if (processor == _capturing_processor) {
1698 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1699 if (need_process_lock) {
1703 _capturing_processor.reset();
1705 if (need_process_lock) {
1710 /* these can never be removed */
1712 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1716 if (!_session.engine().connected()) {
1720 processor_max_streams.reset();
1723 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1724 if (need_process_lock) {
1728 /* Caller must hold process lock */
1729 assert (!AudioEngine::instance()->process_lock().trylock());
1731 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1733 ProcessorState pstate (this);
1735 ProcessorList::iterator i;
1736 bool removed = false;
1738 for (i = _processors.begin(); i != _processors.end(); ) {
1739 if (*i == processor) {
1741 /* move along, see failure case for configure_processors()
1742 where we may need to reconfigure the processor.
1745 /* stop redirects that send signals to JACK ports
1746 from causing noise as a result of no longer being
1750 boost::shared_ptr<IOProcessor> iop;
1752 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1756 i = _processors.erase (i);
1764 _output->set_user_latency (0);
1772 if (configure_processors_unlocked (err)) {
1774 /* we know this will work, because it worked before :) */
1775 configure_processors_unlocked (0);
1779 _have_internal_generator = false;
1781 for (i = _processors.begin(); i != _processors.end(); ++i) {
1782 boost::shared_ptr<PluginInsert> pi;
1784 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1785 if (pi->has_no_inputs ()) {
1786 _have_internal_generator = true;
1791 if (need_process_lock) {
1796 reset_instrument_info ();
1797 processor->drop_references ();
1798 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1799 set_processor_positions ();
1805 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1807 ProcessorList deleted;
1809 if (!_session.engine().connected()) {
1813 processor_max_streams.reset();
1816 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1817 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1818 ProcessorState pstate (this);
1820 ProcessorList::iterator i;
1821 boost::shared_ptr<Processor> processor;
1823 for (i = _processors.begin(); i != _processors.end(); ) {
1827 /* these can never be removed */
1829 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1834 /* see if its in the list of processors to delete */
1836 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1841 /* stop IOProcessors that send to JACK ports
1842 from causing noise as a result of no longer being
1846 boost::shared_ptr<IOProcessor> iop;
1848 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1852 deleted.push_back (processor);
1853 i = _processors.erase (i);
1856 if (deleted.empty()) {
1857 /* none of those in the requested list were found */
1861 _output->set_user_latency (0);
1863 if (configure_processors_unlocked (err)) {
1865 /* we know this will work, because it worked before :) */
1866 configure_processors_unlocked (0);
1871 _have_internal_generator = false;
1873 for (i = _processors.begin(); i != _processors.end(); ++i) {
1874 boost::shared_ptr<PluginInsert> pi;
1876 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1877 if (pi->has_no_inputs ()) {
1878 _have_internal_generator = true;
1885 /* now try to do what we need to so that those that were removed will be deleted */
1887 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1888 (*i)->drop_references ();
1891 reset_instrument_info ();
1892 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1893 set_processor_positions ();
1899 Route::reset_instrument_info ()
1901 boost::shared_ptr<Processor> instr = the_instrument();
1903 _instrument_info.set_internal_instrument (instr);
1907 /** Caller must hold process lock */
1909 Route::configure_processors (ProcessorStreams* err)
1911 #ifndef PLATFORM_WINDOWS
1912 assert (!AudioEngine::instance()->process_lock().trylock());
1915 if (!_in_configure_processors) {
1916 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1917 return configure_processors_unlocked (err);
1924 Route::input_streams () const
1926 return _input->n_ports ();
1929 list<pair<ChanCount, ChanCount> >
1930 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1932 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1934 return try_configure_processors_unlocked (in, err);
1937 list<pair<ChanCount, ChanCount> >
1938 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1940 // Check each processor in order to see if we can configure as requested
1942 list<pair<ChanCount, ChanCount> > configuration;
1945 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1946 DEBUG_TRACE (DEBUG::Processors, "{\n");
1948 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1950 if ((*p)->can_support_io_configuration(in, out)) {
1951 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1952 configuration.push_back(make_pair(in, out));
1955 // restriction for Monitor Section Processors
1956 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1957 /* do not allow to add/remove channels (for now)
1958 * The Monitor follows the master-bus and has no panner (unpan)
1959 * but do allow processors with midi-in to be added (e.g VSTs with control that
1960 * will remain unconnected)
1962 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1963 return list<pair<ChanCount, ChanCount> > ();
1965 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1966 // internal sends make no sense, only feedback
1967 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1968 return list<pair<ChanCount, ChanCount> > ();
1970 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1971 /* External Sends can be problematic. one can add/remove ports
1972 * there signal leaves the DAW to external monitors anyway, so there's
1973 * no real use for allowing them here anyway.
1975 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1976 return list<pair<ChanCount, ChanCount> > ();
1978 if (boost::dynamic_pointer_cast<Send> (*p)) {
1980 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1981 return list<pair<ChanCount, ChanCount> > ();
1990 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1991 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1992 DEBUG_TRACE (DEBUG::Processors, "}\n");
1993 return list<pair<ChanCount, ChanCount> > ();
1997 DEBUG_TRACE (DEBUG::Processors, "}\n");
1999 return configuration;
2002 /** Set the input/output configuration of each processor in the processors list.
2003 * Caller must hold process lock.
2004 * Return 0 on success, otherwise configuration is impossible.
2007 Route::configure_processors_unlocked (ProcessorStreams* err)
2009 #ifndef PLATFORM_WINDOWS
2010 assert (!AudioEngine::instance()->process_lock().trylock());
2013 if (_in_configure_processors) {
2017 /* put invisible processors where they should be */
2018 setup_invisible_processors ();
2020 _in_configure_processors = true;
2022 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2024 if (configuration.empty ()) {
2025 _in_configure_processors = false;
2030 bool seen_mains_out = false;
2031 processor_out_streams = _input->n_ports();
2032 processor_max_streams.reset();
2034 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2035 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2037 if (!(*p)->configure_io(c->first, c->second)) {
2038 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2040 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2041 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2043 boost::shared_ptr<PluginInsert> pi;
2044 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2045 /* plugins connected via Split Match may have more channels.
2046 * route/scratch buffers are needed for all of them*/
2047 processor_max_streams = ChanCount::max(processor_max_streams, pi->input_streams());
2048 processor_max_streams = ChanCount::max(processor_max_streams, pi->natural_input_streams());
2052 if (boost::dynamic_pointer_cast<Delivery> (*p)
2053 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2054 /* main delivery will increase port count to match input.
2055 * the Delivery::Main is usually the last processor - followed only by
2058 seen_mains_out = true;
2060 if (!seen_mains_out) {
2061 processor_out_streams = out;
2067 _meter->set_max_channels (processor_max_streams);
2070 /* make sure we have sufficient scratch buffers to cope with the new processor
2073 _session.ensure_buffers (n_process_buffers ());
2075 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2077 _in_configure_processors = false;
2081 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2082 * @param state New active state for those processors.
2085 Route::all_visible_processors_active (bool state)
2087 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2089 if (_processors.empty()) {
2093 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2094 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2101 (*i)->deactivate ();
2105 _session.set_dirty ();
2109 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2111 /* check if re-order requires re-configuration of any processors
2112 * -> compare channel configuration for all processors
2114 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2115 ChanCount c = input_streams ();
2117 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2119 if (c != (*j)->input_streams()) {
2122 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2125 if ((*i)->input_streams() != c) {
2128 c = (*i)->output_streams();
2140 __attribute__((annotate("realtime")))
2143 Route::apply_processor_order (const ProcessorList& new_order)
2145 /* need to hold processor_lock; either read or write lock
2146 * and the engine process_lock.
2147 * Due to r/w lock ambiguity we can only assert the latter
2149 assert (!AudioEngine::instance()->process_lock().trylock());
2152 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2153 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2154 * processors in the current actual processor list that are hidden. Any visible processors
2155 * in the current list but not in "new_order" will be assumed to be deleted.
2158 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2159 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2160 * (note though that ::processors_reorder_needs_configure() ensured that
2161 * this function will only ever be called from the rt-thread if no processor were removed)
2163 * either way, I can't proove it, but an x-run due to re-order here is less likley
2164 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2167 ProcessorList as_it_will_be;
2168 ProcessorList::iterator oiter;
2169 ProcessorList::const_iterator niter;
2171 oiter = _processors.begin();
2172 niter = new_order.begin();
2174 while (niter != new_order.end()) {
2176 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2177 then append it to the temp list.
2179 Otherwise, see if the next processor in the old list is in the new list. if not,
2180 its been deleted. If its there, append it to the temp list.
2183 if (oiter == _processors.end()) {
2185 /* no more elements in the old list, so just stick the rest of
2186 the new order onto the temp list.
2189 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2190 while (niter != new_order.end()) {
2197 if (!(*oiter)->display_to_user()) {
2199 as_it_will_be.push_back (*oiter);
2203 /* visible processor: check that its in the new order */
2205 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2206 /* deleted: do nothing, shared_ptr<> will clean up */
2208 /* ignore this one, and add the next item from the new order instead */
2209 as_it_will_be.push_back (*niter);
2214 /* now remove from old order - its taken care of no matter what */
2215 oiter = _processors.erase (oiter);
2219 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2221 /* If the meter is in a custom position, find it and make a rough note of its position */
2222 maybe_note_meter_position ();
2226 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2228 // it a change is already queued, wait for it
2229 // (unless engine is stopped. apply immediately and proceed
2230 while (g_atomic_int_get (&_pending_process_reorder)) {
2231 if (!AudioEngine::instance()->running()) {
2232 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2233 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2235 apply_processor_order(_pending_processor_order);
2236 setup_invisible_processors ();
2238 g_atomic_int_set (&_pending_process_reorder, 0);
2240 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2241 set_processor_positions ();
2243 // TODO rather use a semaphore or something.
2244 // but since ::reorder_processors() is called
2245 // from the GUI thread, this is fine..
2250 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2252 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2253 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2254 ProcessorState pstate (this);
2256 apply_processor_order (new_order);
2258 if (configure_processors_unlocked (err)) {
2266 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2267 set_processor_positions ();
2270 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2271 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2273 // _pending_processor_order is protected by _processor_lock
2274 _pending_processor_order = new_order;
2275 g_atomic_int_set (&_pending_process_reorder, 1);
2288 Route::get_template()
2290 return state(false);
2294 Route::state(bool full_state)
2296 if (!_session._template_state_dir.empty()) {
2297 assert (!full_state); // only for templates
2298 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2301 XMLNode *node = new XMLNode("Route");
2302 ProcessorList::iterator i;
2305 id().print (buf, sizeof (buf));
2306 node->add_property("id", buf);
2307 node->add_property ("name", _name);
2308 node->add_property("default-type", _default_type.to_string());
2311 node->add_property("flags", enum_2_string (_flags));
2314 node->add_property("active", _active?"yes":"no");
2316 boost::to_string (_phase_invert, p);
2317 node->add_property("phase-invert", p);
2318 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2319 node->add_property("meter-point", enum_2_string (_meter_point));
2321 node->add_property("meter-type", enum_2_string (_meter_type));
2324 node->add_property("route-group", _route_group->name());
2327 snprintf (buf, sizeof (buf), "%d", _order_key);
2328 node->add_property ("order-key", buf);
2329 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2330 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2331 node->add_property ("soloed-by-upstream", buf);
2332 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2333 node->add_property ("soloed-by-downstream", buf);
2334 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2335 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2337 node->add_child_nocopy (_input->state (full_state));
2338 node->add_child_nocopy (_output->state (full_state));
2339 node->add_child_nocopy (_solo_control->get_state ());
2340 node->add_child_nocopy (_mute_control->get_state ());
2341 node->add_child_nocopy (_mute_master->get_state ());
2344 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2347 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2348 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2349 remote_control_node->add_property (X_("id"), buf);
2350 node->add_child_nocopy (*remote_control_node);
2352 if (_comment.length()) {
2353 XMLNode *cmt = node->add_child ("Comment");
2354 cmt->add_content (_comment);
2358 node->add_child_nocopy (_pannable->state (full_state));
2361 for (i = _processors.begin(); i != _processors.end(); ++i) {
2363 /* template save: do not include internal sends functioning as
2364 aux sends because the chance of the target ID
2365 in the session where this template is used
2368 similarly, do not save listen sends which connect to
2369 the monitor section, because these will always be
2372 boost::shared_ptr<InternalSend> is;
2374 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2375 if (is->role() == Delivery::Listen) {
2380 node->add_child_nocopy((*i)->state (full_state));
2384 node->add_child_copy (*_extra_xml);
2387 if (_custom_meter_position_noted) {
2388 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2390 after->id().print (buf, sizeof (buf));
2391 node->add_property (X_("processor-after-last-custom-meter"), buf);
2395 if (!_session._template_state_dir.empty()) {
2396 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2403 Route::set_state (const XMLNode& node, int version)
2405 if (version < 3000) {
2406 return set_state_2X (node, version);
2410 XMLNodeConstIterator niter;
2412 const XMLProperty *prop;
2414 if (node.name() != "Route"){
2415 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2419 if ((prop = node.property (X_("name"))) != 0) {
2420 Route::set_name (prop->value());
2424 _initial_io_setup = true;
2426 if ((prop = node.property (X_("flags"))) != 0) {
2427 _flags = Flag (string_2_enum (prop->value(), _flags));
2432 if (is_master() || is_monitor() || is_auditioner()) {
2433 _mute_master->set_solo_ignore (true);
2437 /* monitor bus does not get a panner, but if (re)created
2438 via XML, it will already have one by the time we
2439 call ::set_state(). so ... remove it.
2444 /* add all processors (except amp, which is always present) */
2446 nlist = node.children();
2447 XMLNode processor_state (X_("processor_state"));
2449 Stateful::save_extra_xml (node);
2451 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2455 if (child->name() == IO::state_node_name) {
2456 if ((prop = child->property (X_("direction"))) == 0) {
2460 if (prop->value() == "Input") {
2461 _input->set_state (*child, version);
2462 } else if (prop->value() == "Output") {
2463 _output->set_state (*child, version);
2467 if (child->name() == X_("Processor")) {
2468 processor_state.add_child_copy (*child);
2471 if (child->name() == X_("Pannable")) {
2473 _pannable->set_state (*child, version);
2475 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2480 if ((prop = node.property (X_("meter-point"))) != 0) {
2481 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2482 set_meter_point (mp, true);
2484 _meter->set_display_to_user (_meter_point == MeterCustom);
2488 if ((prop = node.property (X_("meter-type"))) != 0) {
2489 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2492 _initial_io_setup = false;
2494 set_processor_state (processor_state);
2496 // this looks up the internal instrument in processors
2497 reset_instrument_info();
2499 if ((prop = node.property ("self-solo")) != 0) {
2500 set_self_solo (string_is_affirmative (prop->value()));
2503 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2504 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2505 mod_solo_by_others_upstream (atoi (prop->value()));
2508 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2509 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2510 mod_solo_by_others_downstream (atoi (prop->value()));
2513 if ((prop = node.property ("solo-isolated")) != 0) {
2514 set_solo_isolated (string_is_affirmative (prop->value()), Controllable::NoGroup);
2517 if ((prop = node.property ("solo-safe")) != 0) {
2518 set_solo_safe (string_is_affirmative (prop->value()), Controllable::NoGroup);
2521 if ((prop = node.property (X_("phase-invert"))) != 0) {
2522 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2525 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2526 set_denormal_protection (string_is_affirmative (prop->value()));
2529 if ((prop = node.property (X_("active"))) != 0) {
2530 bool yn = string_is_affirmative (prop->value());
2531 _active = !yn; // force switch
2532 set_active (yn, this);
2535 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2536 set_order_key (atoi(prop->value()));
2539 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2543 string::size_type colon, equal;
2544 string remaining = prop->value();
2546 while (remaining.length()) {
2548 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2549 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2552 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2553 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2556 string keyname = remaining.substr (0, equal);
2558 if ((keyname == "EditorSort") || (keyname == "editor")) {
2559 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2565 colon = remaining.find_first_of (':');
2567 if (colon != string::npos) {
2568 remaining = remaining.substr (colon+1);
2575 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2576 PBD::ID id (prop->value ());
2577 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2578 ProcessorList::const_iterator i = _processors.begin ();
2579 while (i != _processors.end() && (*i)->id() != id) {
2583 if (i != _processors.end ()) {
2584 _processor_after_last_custom_meter = *i;
2585 _custom_meter_position_noted = true;
2589 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2592 if (child->name() == X_("Comment")) {
2594 /* XXX this is a terrible API design in libxml++ */
2596 XMLNode *cmt = *(child->children().begin());
2597 _comment = cmt->content();
2599 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2600 if (prop->value() == "solo") {
2601 _solo_control->set_state (*child, version);
2602 } else if (prop->value() == "mute") {
2603 _mute_control->set_state (*child, version);
2606 } else if (child->name() == X_("RemoteControl")) {
2607 if ((prop = child->property (X_("id"))) != 0) {
2609 sscanf (prop->value().c_str(), "%d", &x);
2610 set_remote_control_id_internal (x);
2613 } else if (child->name() == X_("MuteMaster")) {
2614 _mute_master->set_state (*child, version);
2616 } else if (child->name() == Automatable::xml_node_name) {
2617 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2625 Route::set_state_2X (const XMLNode& node, int version)
2627 LocaleGuard lg (X_("C"));
2629 XMLNodeConstIterator niter;
2631 const XMLProperty *prop;
2633 /* 2X things which still remain to be handled:
2639 if (node.name() != "Route") {
2640 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2644 if ((prop = node.property (X_("flags"))) != 0) {
2645 string f = prop->value ();
2646 boost::replace_all (f, "ControlOut", "MonitorOut");
2647 _flags = Flag (string_2_enum (f, _flags));
2652 if (is_master() || is_monitor() || is_auditioner()) {
2653 _mute_master->set_solo_ignore (true);
2656 if ((prop = node.property (X_("phase-invert"))) != 0) {
2657 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2658 if (string_is_affirmative (prop->value ())) {
2661 set_phase_invert (p);
2664 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2665 set_denormal_protection (string_is_affirmative (prop->value()));
2668 if ((prop = node.property (X_("soloed"))) != 0) {
2669 bool yn = string_is_affirmative (prop->value());
2671 /* XXX force reset of solo status */
2676 if ((prop = node.property (X_("muted"))) != 0) {
2679 bool muted = string_is_affirmative (prop->value());
2685 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2687 if (string_is_affirmative (prop->value())){
2688 mute_point = mute_point + "PreFader";
2693 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2695 if (string_is_affirmative (prop->value())){
2698 mute_point = mute_point + ",";
2701 mute_point = mute_point + "PostFader";
2706 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2708 if (string_is_affirmative (prop->value())){
2711 mute_point = mute_point + ",";
2714 mute_point = mute_point + "Listen";
2719 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2721 if (string_is_affirmative (prop->value())){
2724 mute_point = mute_point + ",";
2727 mute_point = mute_point + "Main";
2731 _mute_master->set_mute_points (mute_point);
2732 _mute_master->set_muted_by_self (true);
2736 if ((prop = node.property (X_("meter-point"))) != 0) {
2737 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2740 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2741 don't mean the same thing.
2744 if ((prop = node.property (X_("order-keys"))) != 0) {
2748 string::size_type colon, equal;
2749 string remaining = prop->value();
2751 while (remaining.length()) {
2753 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2754 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2757 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2758 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2761 string keyname = remaining.substr (0, equal);
2763 if (keyname == "EditorSort" || keyname == "editor") {
2764 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2770 colon = remaining.find_first_of (':');
2772 if (colon != string::npos) {
2773 remaining = remaining.substr (colon+1);
2782 nlist = node.children ();
2783 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2787 if (child->name() == IO::state_node_name) {
2789 /* there is a note in IO::set_state_2X() about why we have to call
2793 _input->set_state_2X (*child, version, true);
2794 _output->set_state_2X (*child, version, false);
2796 if ((prop = child->property (X_("name"))) != 0) {
2797 Route::set_name (prop->value ());
2802 if ((prop = child->property (X_("active"))) != 0) {
2803 bool yn = string_is_affirmative (prop->value());
2804 _active = !yn; // force switch
2805 set_active (yn, this);
2808 if ((prop = child->property (X_("gain"))) != 0) {
2811 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2812 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2816 /* Set up Panners in the IO */
2817 XMLNodeList io_nlist = child->children ();
2819 XMLNodeConstIterator io_niter;
2822 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2824 io_child = *io_niter;
2826 if (io_child->name() == X_("Panner")) {
2827 _main_outs->panner_shell()->set_state(*io_child, version);
2828 } else if (io_child->name() == X_("Automation")) {
2829 /* IO's automation is for the fader */
2830 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2836 XMLNodeList redirect_nodes;
2838 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2842 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2843 redirect_nodes.push_back(child);
2848 set_processor_state_2X (redirect_nodes, version);
2850 Stateful::save_extra_xml (node);
2852 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2855 if (child->name() == X_("Comment")) {
2857 /* XXX this is a terrible API design in libxml++ */
2859 XMLNode *cmt = *(child->children().begin());
2860 _comment = cmt->content();
2862 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2863 if (prop->value() == X_("solo")) {
2864 _solo_control->set_state (*child, version);
2865 } else if (prop->value() == X_("mute")) {
2866 _mute_control->set_state (*child, version);
2869 } else if (child->name() == X_("RemoteControl")) {
2870 if ((prop = child->property (X_("id"))) != 0) {
2872 sscanf (prop->value().c_str(), "%d", &x);
2873 set_remote_control_id_internal (x);
2883 Route::get_processor_state ()
2885 XMLNode* root = new XMLNode (X_("redirects"));
2886 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2887 root->add_child_nocopy ((*i)->state (true));
2894 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2896 /* We don't bother removing existing processors not in nList, as this
2897 method will only be called when creating a Route from scratch, not
2898 for undo purposes. Just put processors in at the appropriate place
2902 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2903 add_processor_from_xml_2X (**i, version);
2908 Route::set_processor_state (const XMLNode& node)
2910 const XMLNodeList &nlist = node.children();
2911 XMLNodeConstIterator niter;
2912 ProcessorList new_order;
2913 bool must_configure = false;
2915 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2917 XMLProperty* prop = (*niter)->property ("type");
2919 if (prop->value() == "amp") {
2920 _amp->set_state (**niter, Stateful::current_state_version);
2921 new_order.push_back (_amp);
2922 } else if (prop->value() == "trim") {
2923 _trim->set_state (**niter, Stateful::current_state_version);
2924 new_order.push_back (_trim);
2925 } else if (prop->value() == "meter") {
2926 _meter->set_state (**niter, Stateful::current_state_version);
2927 new_order.push_back (_meter);
2928 } else if (prop->value() == "delay") {
2930 _delayline->set_state (**niter, Stateful::current_state_version);
2931 new_order.push_back (_delayline);
2933 } else if (prop->value() == "main-outs") {
2934 _main_outs->set_state (**niter, Stateful::current_state_version);
2935 } else if (prop->value() == "intreturn") {
2937 _intreturn.reset (new InternalReturn (_session));
2938 must_configure = true;
2940 _intreturn->set_state (**niter, Stateful::current_state_version);
2941 } else if (is_monitor() && prop->value() == "monitor") {
2942 if (!_monitor_control) {
2943 _monitor_control.reset (new MonitorProcessor (_session));
2944 must_configure = true;
2946 _monitor_control->set_state (**niter, Stateful::current_state_version);
2947 } else if (prop->value() == "capture") {
2948 /* CapturingProcessor should never be restored, it's always
2949 added explicitly when needed */
2951 ProcessorList::iterator o;
2953 for (o = _processors.begin(); o != _processors.end(); ++o) {
2954 XMLProperty* id_prop = (*niter)->property(X_("id"));
2955 if (id_prop && (*o)->id() == id_prop->value()) {
2956 (*o)->set_state (**niter, Stateful::current_state_version);
2957 new_order.push_back (*o);
2962 // If the processor (*niter) is not on the route then create it
2964 if (o == _processors.end()) {
2966 boost::shared_ptr<Processor> processor;
2968 if (prop->value() == "intsend") {
2970 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2972 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2973 prop->value() == "lv2" ||
2974 prop->value() == "windows-vst" ||
2975 prop->value() == "lxvst" ||
2976 prop->value() == "audiounit") {
2978 if (_session.get_disable_all_loaded_plugins ()) {
2979 processor.reset (new UnknownProcessor (_session, **niter));
2981 processor.reset (new PluginInsert (_session));
2983 } else if (prop->value() == "port") {
2985 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2987 } else if (prop->value() == "send") {
2989 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2992 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2996 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2997 /* This processor could not be configured. Turn it into a UnknownProcessor */
2998 processor.reset (new UnknownProcessor (_session, **niter));
3001 /* we have to note the monitor send here, otherwise a new one will be created
3002 and the state of this one will be lost.
3004 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3005 if (isend && isend->role() == Delivery::Listen) {
3006 _monitor_send = isend;
3009 /* it doesn't matter if invisible processors are added here, as they
3010 will be sorted out by setup_invisible_processors () shortly.
3013 new_order.push_back (processor);
3014 must_configure = true;
3020 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3021 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3022 _processors = new_order;
3024 if (must_configure) {
3025 configure_processors_unlocked (0);
3028 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3030 (*i)->set_owner (this);
3031 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3033 boost::shared_ptr<PluginInsert> pi;
3035 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3036 if (pi->has_no_inputs ()) {
3037 _have_internal_generator = true;
3044 reset_instrument_info ();
3045 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3046 set_processor_positions ();
3050 Route::curve_reallocate ()
3052 // _gain_automation_curve.finish_resize ();
3053 // _pan_automation_curve.finish_resize ();
3057 Route::silence (framecnt_t nframes)
3059 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3064 silence_unlocked (nframes);
3068 Route::silence_unlocked (framecnt_t nframes)
3070 /* Must be called with the processor lock held */
3074 _output->silence (nframes);
3076 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3077 boost::shared_ptr<PluginInsert> pi;
3079 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3080 // skip plugins, they don't need anything when we're not active
3084 (*i)->silence (nframes);
3087 if (nframes == _session.get_block_size()) {
3094 Route::add_internal_return ()
3097 _intreturn.reset (new InternalReturn (_session));
3098 add_processor (_intreturn, PreFader);
3103 Route::add_send_to_internal_return (InternalSend* send)
3105 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3107 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3108 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3111 return d->add_send (send);
3117 Route::remove_send_from_internal_return (InternalSend* send)
3119 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3121 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3122 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3125 return d->remove_send (send);
3131 Route::enable_monitor_send ()
3133 /* Caller must hold process lock */
3134 assert (!AudioEngine::instance()->process_lock().trylock());
3136 /* master never sends to monitor section via the normal mechanism */
3137 assert (!is_master ());
3138 assert (!is_monitor ());
3140 /* make sure we have one */
3141 if (!_monitor_send) {
3142 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3143 _monitor_send->set_display_to_user (false);
3147 configure_processors (0);
3150 /** Add an aux send to a route.
3151 * @param route route to send to.
3152 * @param before Processor to insert before, or 0 to insert at the end.
3155 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3157 assert (route != _session.monitor_out ());
3160 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3162 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3164 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3166 if (d && d->target_route() == route) {
3167 /* already listening via the specified IO: do nothing */
3175 boost::shared_ptr<InternalSend> listener;
3178 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3179 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3180 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3183 add_processor (listener, before);
3185 } catch (failed_constructor& err) {
3193 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3195 ProcessorStreams err;
3196 ProcessorList::iterator tmp;
3199 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3201 /* have to do this early because otherwise processor reconfig
3202 * will put _monitor_send back in the list
3205 if (route == _session.monitor_out()) {
3206 _monitor_send.reset ();
3210 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3212 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3214 if (d && d->target_route() == route) {
3216 if (remove_processor (*x, &err, false) > 0) {
3222 /* list could have been demolished while we dropped the lock
3225 if (_session.engine().connected()) {
3226 /* i/o processors cannot be removed if the engine is not running
3227 * so don't live-loop in case the engine is N/A or dies
3237 Route::set_comment (string cmt, void *src)
3241 _session.set_dirty ();
3245 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3247 FeedRecord fr (other, via_sends_only);
3249 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3251 if (!result.second) {
3253 /* already a record for "other" - make sure sends-only information is correct */
3254 if (!via_sends_only && result.first->sends_only) {
3255 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3256 frp->sends_only = false;
3260 return result.second;
3264 Route::clear_fed_by ()
3270 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3272 const FedBy& fed_by (other->fed_by());
3274 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3275 boost::shared_ptr<Route> sr = f->r.lock();
3277 if (sr && (sr.get() == this)) {
3279 if (via_sends_only) {
3280 *via_sends_only = f->sends_only;
3291 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3293 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3295 if (_output->connected_to (other->input())) {
3296 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3297 if (via_send_only) {
3298 *via_send_only = false;
3305 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3307 boost::shared_ptr<IOProcessor> iop;
3309 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3310 if (iop->feeds (other)) {
3311 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3312 if (via_send_only) {
3313 *via_send_only = true;
3317 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3320 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3325 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3330 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3332 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3335 /** Called from the (non-realtime) butler thread when the transport is stopped */
3337 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3339 framepos_t now = _session.transport_frame();
3342 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3344 Automatable::transport_stopped (now);
3346 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3348 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3352 (*i)->transport_stopped (now);
3356 _roll_delay = _initial_delay;
3360 Route::input_change_handler (IOChange change, void * /*src*/)
3362 if ((change.type & IOChange::ConfigurationChanged)) {
3363 /* This is called with the process lock held if change
3364 contains ConfigurationChanged
3366 configure_processors (0);
3367 _phase_invert.resize (_input->n_ports().n_audio ());
3368 io_changed (); /* EMIT SIGNAL */
3371 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3374 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3375 if (_input->connected()) {
3376 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3377 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3381 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3382 if (does_feed && !sends_only) {
3383 if ((*i)->soloed()) {
3386 if ((*i)->solo_isolated()) {
3393 int delta = sbou - _soloed_by_others_upstream;
3394 int idelta = ibou - _solo_isolated_by_upstream;
3397 PBD::warning << string_compose (
3398 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3399 _name, ibou, _solo_isolated_by_upstream, idelta)
3404 if (_soloed_by_others_upstream) {
3405 // ignore new connections (they're not propagated)
3407 mod_solo_by_others_upstream (delta);
3411 if (_solo_isolated_by_upstream) {
3412 // solo-isolate currently only propagates downstream
3414 mod_solo_isolated_by_upstream (false);
3416 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3417 // but idelta can't be smaller than -1, can it?
3418 //_solo_isolated_by_upstream = ibou;
3421 // Session::route_solo_changed does not propagate indirect solo-changes
3422 // propagate downstream to tracks
3423 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3424 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3428 bool does_feed = feeds (*i, &sends_only);
3429 if (delta <= 0 && does_feed && !sends_only) {
3430 (*i)->mod_solo_by_others_upstream (delta);
3433 if (idelta < 0 && does_feed && !sends_only) {
3434 (*i)->mod_solo_isolated_by_upstream (false);
3441 Route::output_change_handler (IOChange change, void * /*src*/)
3443 if (_initial_io_setup) {
3447 if ((change.type & IOChange::ConfigurationChanged)) {
3448 /* This is called with the process lock held if change
3449 contains ConfigurationChanged
3451 configure_processors (0);
3454 _session.reset_monitor_section();
3457 io_changed (); /* EMIT SIGNAL */
3460 if (_soloed_by_others_downstream) {
3462 /* checking all all downstream routes for
3463 * explicit of implict solo is a rather drastic measure,
3464 * ideally the input_change_handler() of the other route
3465 * would propagate the change to us.
3467 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3468 if (_output->connected()) {
3469 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3470 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3474 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3475 if (does_feed && !sends_only) {
3476 if ((*i)->soloed()) {
3483 int delta = sbod - _soloed_by_others_downstream;
3485 // do not allow new connections to change implicit solo (no propagation)
3486 mod_solo_by_others_downstream (delta);
3487 // Session::route_solo_changed() does not propagate indirect solo-changes
3488 // propagate upstream to tracks
3489 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3490 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3494 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3495 if (delta != 0 && does_feed && !sends_only) {
3496 (*i)->mod_solo_by_others_downstream (delta);
3505 Route::pans_required () const
3507 if (n_outputs().n_audio() < 2) {
3511 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3515 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3517 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3523 if (n_outputs().n_total() == 0) {
3527 if (!_active || n_inputs() == ChanCount::ZERO) {
3528 silence_unlocked (nframes);
3532 if (session_state_changing) {
3533 if (_session.transport_speed() != 0.0f) {
3534 /* we're rolling but some state is changing (e.g. our diskstream contents)
3535 so we cannot use them. Be silent till this is over.
3537 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3539 silence_unlocked (nframes);
3542 /* we're really not rolling, so we're either delivery silence or actually
3543 monitoring, both of which are safe to do while session_state_changing is true.
3547 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3549 fill_buffers_with_input (bufs, _input, nframes);
3551 if (_meter_point == MeterInput) {
3552 _meter->run (bufs, start_frame, end_frame, nframes, true);
3555 _amp->apply_gain_automation (false);
3556 _trim->apply_gain_automation (false);
3557 passthru (bufs, start_frame, end_frame, nframes, 0);
3563 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3565 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3570 if (n_outputs().n_total() == 0) {
3574 if (!_active || n_inputs().n_total() == 0) {
3575 silence_unlocked (nframes);
3579 framepos_t unused = 0;
3581 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3587 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3589 fill_buffers_with_input (bufs, _input, nframes);
3591 if (_meter_point == MeterInput) {
3592 _meter->run (bufs, start_frame, end_frame, nframes, true);
3595 passthru (bufs, start_frame, end_frame, nframes, declick);
3601 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3608 Route::flush_processors ()
3610 /* XXX shouldn't really try to take this lock, since
3611 this is called from the RT audio thread.
3614 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3616 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3622 __attribute__((annotate("realtime")))
3625 Route::apply_processor_changes_rt ()
3627 int emissions = EmitNone;
3629 if (_pending_meter_point != _meter_point) {
3630 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3632 /* meters always have buffers for 'processor_max_streams'
3633 * they can be re-positioned without re-allocation */
3634 if (set_meter_point_unlocked()) {
3635 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3637 emissions |= EmitMeterChanged;
3642 bool changed = false;
3644 if (g_atomic_int_get (&_pending_process_reorder)) {
3645 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3647 apply_processor_order (_pending_processor_order);
3648 setup_invisible_processors ();
3650 g_atomic_int_set (&_pending_process_reorder, 0);
3651 emissions |= EmitRtProcessorChange;
3655 set_processor_positions ();
3657 if (emissions != 0) {
3658 g_atomic_int_set (&_pending_signals, emissions);
3665 Route::emit_pending_signals ()
3668 int sig = g_atomic_int_and (&_pending_signals, 0);
3669 if (sig & EmitMeterChanged) {
3670 _meter->emit_configuration_changed();
3671 meter_change (); /* EMIT SIGNAL */
3672 if (sig & EmitMeterVisibilityChange) {
3673 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3675 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3678 if (sig & EmitRtProcessorChange) {
3679 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3684 Route::set_meter_point (MeterPoint p, bool force)
3686 if (_pending_meter_point == p && !force) {
3690 if (force || !AudioEngine::instance()->running()) {
3691 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3692 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3693 _pending_meter_point = p;
3694 _meter->emit_configuration_changed();
3695 meter_change (); /* EMIT SIGNAL */
3696 if (set_meter_point_unlocked()) {
3697 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3699 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3702 _pending_meter_point = p;
3708 __attribute__((annotate("realtime")))
3711 Route::set_meter_point_unlocked ()
3714 /* Caller must hold process and processor write lock */
3715 assert (!AudioEngine::instance()->process_lock().trylock());
3716 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3717 assert (!lm.locked ());
3720 _meter_point = _pending_meter_point;
3722 bool meter_was_visible_to_user = _meter->display_to_user ();
3724 if (!_custom_meter_position_noted) {
3725 maybe_note_meter_position ();
3728 if (_meter_point != MeterCustom) {
3730 _meter->set_display_to_user (false);
3732 setup_invisible_processors ();
3735 _meter->set_display_to_user (true);
3737 /* If we have a previous position for the custom meter, try to put it there */
3738 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3740 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3741 if (i != _processors.end ()) {
3742 _processors.remove (_meter);
3743 _processors.insert (i, _meter);
3745 } else {// at end, right before the mains_out/panner
3746 _processors.remove (_meter);
3747 ProcessorList::iterator main = _processors.end();
3748 _processors.insert (--main, _meter);
3752 /* Set up the meter for its new position */
3754 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3758 if (loc == _processors.begin()) {
3759 m_in = _input->n_ports();
3761 ProcessorList::iterator before = loc;
3763 m_in = (*before)->output_streams ();
3766 _meter->reflect_inputs (m_in);
3768 /* we do not need to reconfigure the processors, because the meter
3769 (a) is always ready to handle processor_max_streams
3770 (b) is always an N-in/N-out processor, and thus moving
3771 it doesn't require any changes to the other processors.
3774 /* these should really be done after releasing the lock
3775 * but all those signals are subscribed to with gui_thread()
3778 return (_meter->display_to_user() != meter_was_visible_to_user);
3782 Route::listen_position_changed ()
3785 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3786 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3787 ProcessorState pstate (this);
3789 if (configure_processors_unlocked (0)) {
3790 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3792 configure_processors_unlocked (0); // it worked before we tried to add it ...
3797 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3798 _session.set_dirty ();
3801 boost::shared_ptr<CapturingProcessor>
3802 Route::add_export_point()
3804 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3805 if (!_capturing_processor) {
3807 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3808 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3810 _capturing_processor.reset (new CapturingProcessor (_session));
3811 _capturing_processor->activate ();
3813 configure_processors_unlocked (0);
3817 return _capturing_processor;
3821 Route::update_signal_latency ()
3823 framecnt_t l = _output->user_latency();
3824 framecnt_t lamp = 0;
3825 bool before_amp = true;
3826 framecnt_t ltrim = 0;
3827 bool before_trim = true;
3829 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3830 if ((*i)->active ()) {
3831 l += (*i)->signal_latency ();
3836 if ((*i) == _trim) {
3847 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3849 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3850 _signal_latency_at_amp_position = lamp;
3851 _signal_latency_at_trim_position = ltrim;
3853 if (_signal_latency != l) {
3854 _signal_latency = l;
3855 signal_latency_changed (); /* EMIT SIGNAL */
3858 return _signal_latency;
3862 Route::set_user_latency (framecnt_t nframes)
3864 _output->set_user_latency (nframes);
3865 _session.update_latency_compensation ();
3869 Route::set_latency_compensation (framecnt_t longest_session_latency)
3871 framecnt_t old = _initial_delay;
3873 if (_signal_latency < longest_session_latency) {
3874 _initial_delay = longest_session_latency - _signal_latency;
3879 DEBUG_TRACE (DEBUG::Latency, string_compose (
3880 "%1: compensate for maximum latency of %2,"
3881 "given own latency of %3, using initial delay of %4\n",
3882 name(), longest_session_latency, _signal_latency, _initial_delay));
3884 if (_initial_delay != old) {
3885 initial_delay_changed (); /* EMIT SIGNAL */
3888 if (_session.transport_stopped()) {
3889 _roll_delay = _initial_delay;
3894 Route::set_block_size (pframes_t nframes)
3896 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3897 (*i)->set_block_size (nframes);
3900 _session.ensure_buffers (n_process_buffers ());
3904 Route::protect_automation ()
3906 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3907 (*i)->protect_automation();
3910 /** @param declick 1 to set a pending declick fade-in,
3911 * -1 to set a pending declick fade-out
3914 Route::set_pending_declick (int declick)
3917 /* this call is not allowed to turn off a pending declick */
3919 _pending_declick = declick;
3922 _pending_declick = 0;
3926 /** Shift automation forwards from a particular place, thereby inserting time.
3927 * Adds undo commands for any shifts that are performed.
3929 * @param pos Position to start shifting from.
3930 * @param frames Amount to shift forwards by.
3934 Route::shift (framepos_t pos, framecnt_t frames)
3936 /* gain automation */
3938 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3940 XMLNode &before = gc->alist()->get_state ();
3941 gc->alist()->shift (pos, frames);
3942 XMLNode &after = gc->alist()->get_state ();
3943 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3946 /* gain automation */
3948 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3950 XMLNode &before = gc->alist()->get_state ();
3951 gc->alist()->shift (pos, frames);
3952 XMLNode &after = gc->alist()->get_state ();
3953 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3956 // TODO mute automation ??
3958 /* pan automation */
3960 ControlSet::Controls& c (_pannable->controls());
3962 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3963 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3965 boost::shared_ptr<AutomationList> al = pc->alist();
3966 XMLNode& before = al->get_state ();
3967 al->shift (pos, frames);
3968 XMLNode& after = al->get_state ();
3969 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3974 /* redirect automation */
3976 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3977 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3979 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3981 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3982 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3984 boost::shared_ptr<AutomationList> al = ac->alist();
3985 XMLNode &before = al->get_state ();
3986 al->shift (pos, frames);
3987 XMLNode &after = al->get_state ();
3988 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3996 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
3998 boost::shared_ptr<Processor> processor (p.lock ());
3999 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4003 pi->set_state_dir (d);
4007 Route::save_as_template (const string& path, const string& name)
4009 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4010 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4012 XMLNode& node (state (false));
4016 IO::set_name_in_state (*node.children().front(), name);
4018 tree.set_root (&node);
4020 /* return zero on success, non-zero otherwise */
4021 return !tree.write (path.c_str());
4026 Route::set_name (const string& str)
4028 if (str == name()) {
4032 string name = Route::ensure_track_or_route_name (str, _session);
4033 SessionObject::set_name (name);
4035 bool ret = (_input->set_name(name) && _output->set_name(name));
4038 /* rename the main outs. Leave other IO processors
4039 * with whatever name they already have, because its
4040 * just fine as it is (it will not contain the route
4041 * name if its a port insert, port send or port return).
4045 if (_main_outs->set_name (name)) {
4046 /* XXX returning false here is stupid because
4047 we already changed the route name.
4057 /** Set the name of a route in an XML description.
4058 * @param node XML <Route> node to set the name in.
4059 * @param name New name.
4062 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4064 node.add_property (X_("name"), name);
4066 XMLNodeList children = node.children();
4067 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4069 if ((*i)->name() == X_("IO")) {
4071 IO::set_name_in_state (**i, name);
4073 } else if ((*i)->name() == X_("Processor")) {
4075 XMLProperty* role = (*i)->property (X_("role"));
4076 if (role && role->value() == X_("Main")) {
4077 (*i)->add_property (X_("name"), name);
4080 } else if ((*i)->name() == X_("Diskstream")) {
4082 if (rename_playlist) {
4083 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4085 (*i)->add_property (X_("name"), name);
4091 boost::shared_ptr<Send>
4092 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4094 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4096 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4097 boost::shared_ptr<InternalSend> send;
4099 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4100 if (send->target_route() == target) {
4106 return boost::shared_ptr<Send>();
4109 /** @param c Audio channel index.
4110 * @param yn true to invert phase, otherwise false.
4113 Route::set_phase_invert (uint32_t c, bool yn)
4115 if (_phase_invert[c] != yn) {
4116 _phase_invert[c] = yn;
4117 phase_invert_changed (); /* EMIT SIGNAL */
4118 _phase_control->Changed(); /* EMIT SIGNAL */
4119 _session.set_dirty ();
4124 Route::set_phase_invert (boost::dynamic_bitset<> p)
4126 if (_phase_invert != p) {
4128 phase_invert_changed (); /* EMIT SIGNAL */
4129 _session.set_dirty ();
4134 Route::phase_invert (uint32_t c) const
4136 return _phase_invert[c];
4139 boost::dynamic_bitset<>
4140 Route::phase_invert () const
4142 return _phase_invert;
4146 Route::set_denormal_protection (bool yn)
4148 if (_denormal_protection != yn) {
4149 _denormal_protection = yn;
4150 denormal_protection_changed (); /* EMIT SIGNAL */
4155 Route::denormal_protection () const
4157 return _denormal_protection;
4161 Route::set_active (bool yn, void* src)
4163 if (_session.transport_rolling()) {
4167 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4168 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4172 if (_active != yn) {
4174 _input->set_active (yn);
4175 _output->set_active (yn);
4176 active_changed (); // EMIT SIGNAL
4177 _session.set_dirty ();
4181 boost::shared_ptr<Pannable>
4182 Route::pannable() const
4187 boost::shared_ptr<Panner>
4188 Route::panner() const
4191 return _main_outs->panner_shell()->panner();
4194 boost::shared_ptr<PannerShell>
4195 Route::panner_shell() const
4197 return _main_outs->panner_shell();
4200 boost::shared_ptr<GainControl>
4201 Route::gain_control() const
4203 return _gain_control;
4206 boost::shared_ptr<GainControl>
4207 Route::trim_control() const
4209 return _trim_control;
4212 boost::shared_ptr<Route::PhaseControllable>
4213 Route::phase_control() const
4215 if (phase_invert().size()) {
4216 return _phase_control;
4218 return boost::shared_ptr<PhaseControllable>();
4222 boost::shared_ptr<AutomationControl>
4223 Route::get_control (const Evoral::Parameter& param)
4225 /* either we own the control or .... */
4227 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4231 /* maybe one of our processors does or ... */
4233 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4234 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4235 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4243 /* nobody does so we'll make a new one */
4245 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4252 boost::shared_ptr<Processor>
4253 Route::nth_plugin (uint32_t n) const
4255 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4256 ProcessorList::const_iterator i;
4258 for (i = _processors.begin(); i != _processors.end(); ++i) {
4259 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4266 return boost::shared_ptr<Processor> ();
4269 boost::shared_ptr<Processor>
4270 Route::nth_send (uint32_t n) const
4272 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4273 ProcessorList::const_iterator i;
4275 for (i = _processors.begin(); i != _processors.end(); ++i) {
4276 if (boost::dynamic_pointer_cast<Send> (*i)) {
4278 if ((*i)->name().find (_("Monitor")) == 0) {
4279 /* send to monitor section is not considered
4280 to be an accessible send.
4291 return boost::shared_ptr<Processor> ();
4295 Route::has_io_processor_named (const string& name)
4297 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4298 ProcessorList::iterator i;
4300 for (i = _processors.begin(); i != _processors.end(); ++i) {
4301 if (boost::dynamic_pointer_cast<Send> (*i) ||
4302 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4303 if ((*i)->name() == name) {
4312 MuteMaster::MutePoint
4313 Route::mute_points () const
4315 return _mute_master->mute_points ();
4319 Route::set_processor_positions ()
4321 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4323 bool had_amp = false;
4324 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4325 (*i)->set_pre_fader (!had_amp);
4332 /** Called when there is a proposed change to the input port count */
4334 Route::input_port_count_changing (ChanCount to)
4336 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4338 /* The processors cannot be configured with the new input arrangement, so
4344 /* The change is ok */
4348 /** Called when there is a proposed change to the output port count */
4350 Route::output_port_count_changing (ChanCount to)
4352 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4353 if (processor_out_streams.get(*t) > to.get(*t)) {
4357 /* The change is ok */
4362 Route::unknown_processors () const
4366 if (_session.get_disable_all_loaded_plugins ()) {
4367 // Do not list "missing plugins" if they are explicitly disabled
4371 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4372 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4373 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4374 p.push_back ((*i)->name ());
4383 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4385 /* we assume that all our input ports feed all our output ports. its not
4386 universally true, but the alternative is way too corner-case to worry about.
4389 LatencyRange all_connections;
4392 all_connections.min = 0;
4393 all_connections.max = 0;
4395 all_connections.min = ~((pframes_t) 0);
4396 all_connections.max = 0;
4398 /* iterate over all "from" ports and determine the latency range for all of their
4399 connections to the "outside" (outside of this Route).
4402 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4406 p->get_connected_latency_range (range, playback);
4408 all_connections.min = min (all_connections.min, range.min);
4409 all_connections.max = max (all_connections.max, range.max);
4413 /* set the "from" port latencies to the max/min range of all their connections */
4415 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4416 p->set_private_latency_range (all_connections, playback);
4419 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4421 all_connections.min += our_latency;
4422 all_connections.max += our_latency;
4424 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4425 p->set_private_latency_range (all_connections, playback);
4428 return all_connections.max;
4432 Route::set_private_port_latencies (bool playback) const
4434 framecnt_t own_latency = 0;
4436 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4437 OR LATENCY CALLBACK.
4439 This is called (early) from the latency callback. It computes the REAL
4440 latency associated with each port and stores the result as the "private"
4441 latency of the port. A later call to Route::set_public_port_latencies()
4442 sets all ports to the same value to reflect the fact that we do latency
4443 compensation and so all signals are delayed by the same amount as they
4444 flow through ardour.
4447 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4448 if ((*i)->active ()) {
4449 own_latency += (*i)->signal_latency ();
4454 /* playback: propagate latency from "outside the route" to outputs to inputs */
4455 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4457 /* capture: propagate latency from "outside the route" to inputs to outputs */
4458 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4463 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4465 /* this is called to set the JACK-visible port latencies, which take
4466 latency compensation into account.
4475 const PortSet& ports (_input->ports());
4476 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4477 p->set_public_latency_range (range, playback);
4482 const PortSet& ports (_output->ports());
4483 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4484 p->set_public_latency_range (range, playback);
4489 /** Put the invisible processors in the right place in _processors.
4490 * Must be called with a writer lock on _processor_lock held.
4493 __attribute__((annotate("realtime")))
4496 Route::setup_invisible_processors ()
4499 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4500 assert (!lm.locked ());
4504 /* too early to be doing this stuff */
4508 /* we'll build this new list here and then use it
4510 * TODO put the ProcessorList is on the stack for RT-safety.
4513 ProcessorList new_processors;
4515 /* find visible processors */
4517 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4518 if ((*i)->display_to_user ()) {
4519 new_processors.push_back (*i);
4525 ProcessorList::iterator amp = new_processors.begin ();
4526 while (amp != new_processors.end() && *amp != _amp) {
4530 assert (amp != new_processors.end ());
4532 /* and the processor after the amp */
4534 ProcessorList::iterator after_amp = amp;
4540 switch (_meter_point) {
4542 assert (!_meter->display_to_user ());
4543 new_processors.push_front (_meter);
4546 assert (!_meter->display_to_user ());
4547 new_processors.insert (amp, _meter);
4549 case MeterPostFader:
4550 /* do nothing here */
4553 /* do nothing here */
4556 /* the meter is visible, so we don't touch it here */
4563 assert (_main_outs);
4564 assert (!_main_outs->display_to_user ());
4565 new_processors.push_back (_main_outs);
4567 /* iterator for the main outs */
4569 ProcessorList::iterator main = new_processors.end();
4572 /* OUTPUT METERING */
4574 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4575 assert (!_meter->display_to_user ());
4577 /* add the processor just before or just after the main outs */
4579 ProcessorList::iterator meter_point = main;
4581 if (_meter_point == MeterOutput) {
4584 new_processors.insert (meter_point, _meter);
4589 if (_monitor_send && !is_monitor ()) {
4590 assert (!_monitor_send->display_to_user ());
4591 switch (Config->get_listen_position ()) {
4592 case PreFaderListen:
4593 switch (Config->get_pfl_position ()) {
4594 case PFLFromBeforeProcessors:
4595 new_processors.push_front (_monitor_send);
4597 case PFLFromAfterProcessors:
4598 new_processors.insert (amp, _monitor_send);
4601 _monitor_send->set_can_pan (false);
4603 case AfterFaderListen:
4604 switch (Config->get_afl_position ()) {
4605 case AFLFromBeforeProcessors:
4606 new_processors.insert (after_amp, _monitor_send);
4608 case AFLFromAfterProcessors:
4609 new_processors.insert (new_processors.end(), _monitor_send);
4612 _monitor_send->set_can_pan (true);
4617 #if 0 // not used - just yet
4618 if (!is_master() && !is_monitor() && !is_auditioner()) {
4619 new_processors.push_front (_delayline);
4623 /* MONITOR CONTROL */
4625 if (_monitor_control && is_monitor ()) {
4626 assert (!_monitor_control->display_to_user ());
4627 new_processors.insert (amp, _monitor_control);
4630 /* INTERNAL RETURN */
4632 /* doing this here means that any monitor control will come just after
4637 assert (!_intreturn->display_to_user ());
4638 new_processors.push_front (_intreturn);
4641 if (_trim && _trim->active()) {
4642 assert (!_trim->display_to_user ());
4643 new_processors.push_front (_trim);
4645 /* EXPORT PROCESSOR */
4647 if (_capturing_processor) {
4648 assert (!_capturing_processor->display_to_user ());
4649 new_processors.push_front (_capturing_processor);
4652 _processors = new_processors;
4654 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4655 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4660 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4661 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4662 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4669 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4670 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4674 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4675 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4682 /** If the meter point is `Custom', make a note of where the meter is.
4683 * This is so that if the meter point is subsequently set to something else,
4684 * and then back to custom, we can put the meter back where it was last time
4685 * custom was enabled.
4687 * Must be called with the _processor_lock held.
4690 Route::maybe_note_meter_position ()
4692 if (_meter_point != MeterCustom) {
4696 _custom_meter_position_noted = true;
4697 /* custom meter points range from after trim to before panner/main_outs
4698 * this is a limitation by the current processor UI
4700 bool seen_trim = false;
4701 _processor_after_last_custom_meter.reset();
4702 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4703 if ((*i) == _trim) {
4706 if ((*i) == _main_outs) {
4707 _processor_after_last_custom_meter = *i;
4710 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4712 _processor_after_last_custom_meter = _trim;
4714 ProcessorList::iterator j = i;
4716 assert(j != _processors.end ()); // main_outs should be before
4717 _processor_after_last_custom_meter = *j;
4722 assert(_processor_after_last_custom_meter.lock());
4725 boost::shared_ptr<Processor>
4726 Route::processor_by_id (PBD::ID id) const
4728 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4729 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4730 if ((*i)->id() == id) {
4735 return boost::shared_ptr<Processor> ();
4738 /** @return the monitoring state, or in other words what data we are pushing
4739 * into the route (data from the inputs, data from disk or silence)
4742 Route::monitoring_state () const
4744 return MonitoringInput;
4747 /** @return what we should be metering; either the data coming from the input
4748 * IO or the data that is flowing through the route.
4751 Route::metering_state () const
4753 return MeteringRoute;
4757 Route::has_external_redirects () const
4759 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4761 /* ignore inactive processors and obviously ignore the main
4762 * outs since everything has them and we don't care.
4765 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4773 boost::shared_ptr<Processor>
4774 Route::the_instrument () const
4776 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4777 return the_instrument_unlocked ();
4780 boost::shared_ptr<Processor>
4781 Route::the_instrument_unlocked () const
4783 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4784 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4785 if ((*i)->input_streams().n_midi() > 0 &&
4786 (*i)->output_streams().n_audio() > 0) {
4791 return boost::shared_ptr<Processor>();
4797 Route::non_realtime_locate (framepos_t pos)
4800 _pannable->transport_located (pos);
4803 if (_delayline.get()) {
4804 _delayline.get()->flush();
4808 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4809 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4811 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4812 (*i)->transport_located (pos);
4815 _roll_delay = _initial_delay;
4819 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4826 * We don't currently mix MIDI input together, so we don't need the
4827 * complex logic of the audio case.
4830 n_buffers = bufs.count().n_midi ();
4832 for (i = 0; i < n_buffers; ++i) {
4834 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4835 MidiBuffer& buf (bufs.get_midi (i));
4838 buf.copy (source_port->get_midi_buffer(nframes));
4840 buf.silence (nframes);
4846 n_buffers = bufs.count().n_audio();
4848 size_t n_ports = io->n_ports().n_audio();
4849 float scaling = 1.0f;
4851 if (n_ports > n_buffers) {
4852 scaling = ((float) n_buffers) / n_ports;
4855 for (i = 0; i < n_ports; ++i) {
4857 /* if there are more ports than buffers, map them onto buffers
4858 * in a round-robin fashion
4861 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4862 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4865 if (i < n_buffers) {
4867 /* first time through just copy a channel into
4871 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4873 if (scaling != 1.0f) {
4874 buf.apply_gain (scaling, nframes);
4879 /* on subsequent times around, merge data from
4880 * the port with what is already there
4883 if (scaling != 1.0f) {
4884 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4886 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4891 /* silence any remaining buffers */
4893 for (; i < n_buffers; ++i) {
4894 AudioBuffer& buf (bufs.get_audio (i));
4895 buf.silence (nframes);
4898 /* establish the initial setup of the buffer set, reflecting what was
4899 copied into it. unless, of course, we are the auditioner, in which
4900 case nothing was fed into it from the inputs at all.
4903 if (!is_auditioner()) {
4904 bufs.set_count (io->n_ports());
4908 boost::shared_ptr<AutomationControl>
4909 Route::pan_azimuth_control() const
4912 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4914 return boost::shared_ptr<AutomationControl>();
4916 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
4917 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4919 if (!_pannable || !panner()) {
4920 return boost::shared_ptr<AutomationControl>();
4922 return _pannable->pan_azimuth_control;
4926 boost::shared_ptr<AutomationControl>
4927 Route::pan_elevation_control() const
4929 if (Profile->get_mixbus() || !_pannable || !panner()) {
4930 return boost::shared_ptr<AutomationControl>();
4933 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4935 if (c.find (PanElevationAutomation) != c.end()) {
4936 return _pannable->pan_elevation_control;
4938 return boost::shared_ptr<AutomationControl>();
4941 boost::shared_ptr<AutomationControl>
4942 Route::pan_width_control() const
4944 if (Profile->get_mixbus() || !_pannable || !panner()) {
4945 return boost::shared_ptr<AutomationControl>();
4948 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4950 if (c.find (PanWidthAutomation) != c.end()) {
4951 return _pannable->pan_width_control;
4953 return boost::shared_ptr<AutomationControl>();
4956 boost::shared_ptr<AutomationControl>
4957 Route::pan_frontback_control() const
4959 if (Profile->get_mixbus() || !_pannable || !panner()) {
4960 return boost::shared_ptr<AutomationControl>();
4963 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4965 if (c.find (PanFrontBackAutomation) != c.end()) {
4966 return _pannable->pan_frontback_control;
4968 return boost::shared_ptr<AutomationControl>();
4971 boost::shared_ptr<AutomationControl>
4972 Route::pan_lfe_control() const
4974 if (Profile->get_mixbus() || !_pannable || !panner()) {
4975 return boost::shared_ptr<AutomationControl>();
4978 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4980 if (c.find (PanLFEAutomation) != c.end()) {
4981 return _pannable->pan_lfe_control;
4983 return boost::shared_ptr<AutomationControl>();
4988 Route::eq_band_cnt () const
4990 if (Profile->get_mixbus()) {
4993 /* Ardour has no well-known EQ object */
4998 boost::shared_ptr<AutomationControl>
4999 Route::eq_gain_controllable (uint32_t band) const
5002 boost::shared_ptr<PluginInsert> eq = ch_eq();
5005 return boost::shared_ptr<AutomationControl>();
5008 uint32_t port_number;
5011 if (is_master() || mixbus()) {
5018 if (is_master() || mixbus()) {
5025 if (is_master() || mixbus()) {
5032 return boost::shared_ptr<AutomationControl>();
5035 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5037 return boost::shared_ptr<AutomationControl>();
5040 boost::shared_ptr<AutomationControl>
5041 Route::eq_freq_controllable (uint32_t band) const
5045 if (mixbus() || is_master()) {
5046 /* no frequency controls for mixbusses or master */
5047 return boost::shared_ptr<AutomationControl>();
5050 boost::shared_ptr<PluginInsert> eq = ch_eq();
5053 return boost::shared_ptr<AutomationControl>();
5056 uint32_t port_number;
5068 return boost::shared_ptr<AutomationControl>();
5071 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5073 return boost::shared_ptr<AutomationControl>();
5077 boost::shared_ptr<AutomationControl>
5078 Route::eq_q_controllable (uint32_t band) const
5080 return boost::shared_ptr<AutomationControl>();
5083 boost::shared_ptr<AutomationControl>
5084 Route::eq_shape_controllable (uint32_t band) const
5086 return boost::shared_ptr<AutomationControl>();
5089 boost::shared_ptr<AutomationControl>
5090 Route::eq_enable_controllable () const
5093 boost::shared_ptr<PluginInsert> eq = ch_eq();
5096 return boost::shared_ptr<AutomationControl>();
5099 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5101 return boost::shared_ptr<AutomationControl>();
5105 boost::shared_ptr<AutomationControl>
5106 Route::eq_hpf_controllable () const
5109 boost::shared_ptr<PluginInsert> eq = ch_eq();
5112 return boost::shared_ptr<AutomationControl>();
5115 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5117 return boost::shared_ptr<AutomationControl>();
5122 Route::eq_band_name (uint32_t band) const
5124 if (Profile->get_mixbus()) {
5140 boost::shared_ptr<AutomationControl>
5141 Route::comp_enable_controllable () const
5144 boost::shared_ptr<PluginInsert> comp = ch_comp();
5147 return boost::shared_ptr<AutomationControl>();
5150 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5152 return boost::shared_ptr<AutomationControl>();
5155 boost::shared_ptr<AutomationControl>
5156 Route::comp_threshold_controllable () const
5159 boost::shared_ptr<PluginInsert> comp = ch_comp();
5162 return boost::shared_ptr<AutomationControl>();
5165 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5168 return boost::shared_ptr<AutomationControl>();
5171 boost::shared_ptr<AutomationControl>
5172 Route::comp_speed_controllable () const
5175 boost::shared_ptr<PluginInsert> comp = ch_comp();
5178 return boost::shared_ptr<AutomationControl>();
5181 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5183 return boost::shared_ptr<AutomationControl>();
5186 boost::shared_ptr<AutomationControl>
5187 Route::comp_mode_controllable () const
5190 boost::shared_ptr<PluginInsert> comp = ch_comp();
5193 return boost::shared_ptr<AutomationControl>();
5196 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5198 return boost::shared_ptr<AutomationControl>();
5201 boost::shared_ptr<AutomationControl>
5202 Route::comp_makeup_controllable () const
5205 boost::shared_ptr<PluginInsert> comp = ch_comp();
5208 return boost::shared_ptr<AutomationControl>();
5211 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5213 return boost::shared_ptr<AutomationControl>();
5216 boost::shared_ptr<AutomationControl>
5217 Route::comp_redux_controllable () const
5220 boost::shared_ptr<PluginInsert> comp = ch_comp();
5223 return boost::shared_ptr<AutomationControl>();
5226 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5228 return boost::shared_ptr<AutomationControl>();
5233 Route::comp_mode_name (uint32_t mode) const
5238 return _("Leveler");
5240 return _("Compressor");
5242 return _("Limiter");
5244 return mixbus() ? _("Sidechain") : _("Limiter");
5254 Route::comp_speed_name (uint32_t mode) const
5272 boost::shared_ptr<AutomationControl>
5273 Route::send_level_controllable (uint32_t n) const
5276 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5278 return boost::shared_ptr<AutomationControl>();
5283 return boost::shared_ptr<AutomationControl>();
5286 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5287 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5289 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5291 return boost::shared_ptr<AutomationControl>();
5293 return s->gain_control ();
5297 boost::shared_ptr<AutomationControl>
5298 Route::send_enable_controllable (uint32_t n) const
5301 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5303 return boost::shared_ptr<AutomationControl>();
5308 return boost::shared_ptr<AutomationControl>();
5311 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5312 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5314 /* although Ardour sends have enable/disable as part of the Processor
5315 API, it is not exposed as a controllable.
5317 XXX: we should fix this.
5319 return boost::shared_ptr<AutomationControl>();
5324 Route::send_name (uint32_t n) const
5330 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5334 boost::shared_ptr<Processor> p = nth_send (n);
5343 boost::shared_ptr<AutomationControl>
5344 Route::master_send_enable_controllable () const
5347 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5349 return boost::shared_ptr<AutomationControl>();
5351 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5353 return boost::shared_ptr<AutomationControl>();