2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/boost_debug.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/internal_return.h"
50 #include "ardour/internal_send.h"
51 #include "ardour/meter.h"
52 #include "ardour/delayline.h"
53 #include "ardour/midi_buffer.h"
54 #include "ardour/midi_port.h"
55 #include "ardour/monitor_processor.h"
56 #include "ardour/pannable.h"
57 #include "ardour/panner.h"
58 #include "ardour/panner_shell.h"
59 #include "ardour/plugin_insert.h"
60 #include "ardour/port.h"
61 #include "ardour/port_insert.h"
62 #include "ardour/processor.h"
63 #include "ardour/profile.h"
64 #include "ardour/route.h"
65 #include "ardour/route_group.h"
66 #include "ardour/send.h"
67 #include "ardour/session.h"
68 #include "ardour/unknown_processor.h"
69 #include "ardour/utils.h"
74 using namespace ARDOUR;
77 PBD::Signal0<void> Route::SyncOrderKeys;
78 PBD::Signal0<void> Route::RemoteControlIDChange;
80 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
81 : SessionObject (sess, name)
83 , GraphNode (sess._process_graph)
86 , _signal_latency_at_amp_position (0)
87 , _signal_latency_at_trim_position (0)
90 , _pending_process_reorder (0)
91 , _pending_signals (0)
93 , _pending_declick (true)
94 , _meter_point (MeterPostFader)
95 , _pending_meter_point (MeterPostFader)
96 , _meter_type (MeterPeak)
98 , _soloed_by_others_upstream (0)
99 , _soloed_by_others_downstream (0)
100 , _solo_isolated (false)
101 , _solo_isolated_by_upstream (0)
102 , _denormal_protection (false)
105 , _declickable (false)
106 , _mute_master (new MuteMaster (sess, name))
107 , _have_internal_generator (false)
109 , _default_type (default_type)
111 , _has_order_key (false)
112 , _remote_control_id (0)
114 , _in_configure_processors (false)
115 , _initial_io_setup (false)
116 , _custom_meter_position_noted (false)
118 processor_max_streams.reset();
124 /* set default meter type */
126 _meter_type = Config->get_meter_type_master ();
128 else if (dynamic_cast<Track*>(this)) {
129 _meter_type = Config->get_meter_type_track ();
131 _meter_type = Config->get_meter_type_bus ();
134 /* add standard controls */
136 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
137 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
138 _phase_control.reset (new PhaseControllable (X_("phase"), shared_from_this ()));
140 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
141 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
142 _phase_control->set_flags (Controllable::Flag (_phase_control->flags() | Controllable::Toggle));
144 add_control (_solo_control);
145 add_control (_mute_control);
146 add_control (_phase_control);
150 if (!(_flags & Route::MonitorOut)) {
151 _pannable.reset (new Pannable (_session));
154 /* input and output objects */
156 _input.reset (new IO (_session, _name, IO::Input, _default_type));
157 _output.reset (new IO (_session, _name, IO::Output, _default_type));
159 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
160 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
162 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
163 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
165 #if 0 // not used - just yet
166 if (!is_master() && !is_monitor() && !is_auditioner()) {
167 _delayline.reset (new DelayLine (_session, _name));
168 add_processor (_delayline, PreFader);
172 /* add amp processor */
174 _amp.reset (new Amp (_session));
175 add_processor (_amp, PostFader);
178 _amp->set_display_name ("Monitor");
181 // amp should exist before amp controls
182 _group_gain_control.reset (new GroupGainControllable (X_("groupgain"), shared_from_this ()));
183 _group_gain_control->set_flags (Controllable::Flag (_group_gain_control->flags() | Controllable::GainLike));
184 add_control (_group_gain_control);
187 _trim.reset (new Amp (_session, "trim"));
188 _trim->set_display_to_user (false);
190 if (dynamic_cast<AudioTrack*>(this)) {
191 /* we can't do this in the AudioTrack's constructor
192 * because _trim does not exit then
196 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
201 /* create standard processors: meter, main outs, monitor out;
202 they will be added to _processors by setup_invisible_processors ()
205 _meter.reset (new PeakMeter (_session, _name));
206 _meter->set_owner (this);
207 _meter->set_display_to_user (false);
210 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
211 _main_outs->activate ();
214 /* where we listen to tracks */
215 _intreturn.reset (new InternalReturn (_session));
216 _intreturn->activate ();
218 /* the thing that provides proper control over a control/monitor/listen bus
219 (such as per-channel cut, dim, solo, invert, etc).
221 _monitor_control.reset (new MonitorProcessor (_session));
222 _monitor_control->activate ();
225 if (is_master() || is_monitor() || is_auditioner()) {
226 _mute_master->set_solo_ignore (true);
229 /* now that we have _meter, its safe to connect to this */
232 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
233 configure_processors (0);
241 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
243 /* do this early so that we don't get incoming signals as we are going through destruction
248 /* don't use clear_processors here, as it depends on the session which may
249 be half-destroyed by now
252 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
253 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
254 (*i)->drop_references ();
257 _processors.clear ();
261 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
263 if (Config->get_remote_model() != UserOrdered) {
267 set_remote_control_id_internal (id, notify_class_listeners);
271 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
273 /* force IDs for master/monitor busses and prevent
274 any other route from accidentally getting these IDs
275 (i.e. legacy sessions)
278 if (is_master() && id != MasterBusRemoteControlID) {
279 id = MasterBusRemoteControlID;
282 if (is_monitor() && id != MonitorBusRemoteControlID) {
283 id = MonitorBusRemoteControlID;
290 /* don't allow it to collide */
292 if (!is_master () && !is_monitor() &&
293 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
294 id += MonitorBusRemoteControlID;
297 if (id != remote_control_id()) {
298 _remote_control_id = id;
299 RemoteControlIDChanged ();
301 if (notify_class_listeners) {
302 RemoteControlIDChange ();
308 Route::remote_control_id() const
311 return MasterBusRemoteControlID;
315 return MonitorBusRemoteControlID;
318 return _remote_control_id;
322 Route::has_order_key () const
324 return _has_order_key;
328 Route::order_key () const
334 Route::set_remote_control_id_explicit (uint32_t rid)
336 if (is_master() || is_monitor() || is_auditioner()) {
337 /* hard-coded remote IDs, or no remote ID */
341 if (_remote_control_id != rid) {
342 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
343 _remote_control_id = rid;
344 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
347 /* don't emit the class-level RID signal RemoteControlIDChange here,
348 leave that to the entity that changed the order key, so that we
349 don't get lots of emissions for no good reasons (e.g. when changing
350 all route order keys).
352 See Session::sync_remote_id_from_order_keys() for the (primary|only)
353 spot where that is emitted.
358 Route::set_order_key (uint32_t n)
360 _has_order_key = true;
362 if (_order_key == n) {
368 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
369 name(), order_key ()));
371 _session.set_dirty ();
375 Route::ensure_track_or_route_name(string name, Session &session)
377 string newname = name;
379 while (!session.io_name_is_legal (newname)) {
380 newname = bump_name_once (newname, ' ');
387 Route::inc_gain (gain_t fraction, void *src)
389 _amp->inc_gain (fraction, src);
393 Route::set_gain (gain_t val, void *src)
395 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
397 if (_route_group->is_relative()) {
399 gain_t usable_gain = _amp->gain();
400 if (usable_gain < 0.000001f) {
401 usable_gain = 0.000001f;
405 if (delta < 0.000001f) {
409 delta -= usable_gain;
414 gain_t factor = delta / usable_gain;
417 factor = _route_group->get_max_factor(factor);
418 if (factor == 0.0f) {
419 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
423 factor = _route_group->get_min_factor(factor);
424 if (factor == 0.0f) {
425 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
430 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
434 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
440 if (val == _amp->gain()) {
444 _amp->set_gain (val, src);
448 Route::inc_trim (gain_t fraction, void *src)
450 _trim->inc_gain (fraction, src);
454 Route::set_trim (gain_t val, void * /* src */)
456 // TODO route group, see set_gain()
457 _trim->set_gain (val, 0);
461 Route::maybe_declick (BufferSet&, framecnt_t, int)
463 /* this is the "bus" implementation and they never declick.
468 /** Process this route for one (sub) cycle (process thread)
470 * @param bufs Scratch buffers to use for the signal path
471 * @param start_frame Initial transport frame
472 * @param end_frame Final transport frame
473 * @param nframes Number of frames to output (to ports)
475 * Note that (end_frame - start_frame) may not be equal to nframes when the
476 * transport speed isn't 1.0 (eg varispeed).
479 Route::process_output_buffers (BufferSet& bufs,
480 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
481 int declick, bool gain_automation_ok)
483 /* Caller must hold process lock */
484 assert (!AudioEngine::instance()->process_lock().trylock());
486 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
488 // can this actually happen? functions calling process_output_buffers()
489 // already take a reader-lock.
490 bufs.silence (nframes, 0);
494 /* figure out if we're going to use gain automation */
495 if (gain_automation_ok) {
496 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
497 _amp->setup_gain_automation (
498 start_frame + _signal_latency_at_amp_position,
499 end_frame + _signal_latency_at_amp_position,
502 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
503 _trim->setup_gain_automation (
504 start_frame + _signal_latency_at_trim_position,
505 end_frame + _signal_latency_at_trim_position,
508 _amp->apply_gain_automation (false);
509 _trim->apply_gain_automation (false);
512 /* Tell main outs what to do about monitoring. We do this so that
513 on a transition between monitoring states we get a de-clicking gain
514 change in the _main_outs delivery, if config.get_use_monitor_fades()
517 We override this in the case where we have an internal generator.
519 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
521 _main_outs->no_outs_cuz_we_no_monitor (silence);
523 /* -------------------------------------------------------------------------------------------
524 GLOBAL DECLICK (for transport changes etc.)
525 ----------------------------------------------------------------------------------------- */
527 maybe_declick (bufs, nframes, declick);
528 _pending_declick = 0;
530 /* -------------------------------------------------------------------------------------------
531 DENORMAL CONTROL/PHASE INVERT
532 ----------------------------------------------------------------------------------------- */
534 if (_phase_invert.any ()) {
538 if (_denormal_protection || Config->get_denormal_protection()) {
540 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
541 Sample* const sp = i->data();
543 if (_phase_invert[chn]) {
544 for (pframes_t nx = 0; nx < nframes; ++nx) {
549 for (pframes_t nx = 0; nx < nframes; ++nx) {
557 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
558 Sample* const sp = i->data();
560 if (_phase_invert[chn]) {
561 for (pframes_t nx = 0; nx < nframes; ++nx) {
570 if (_denormal_protection || Config->get_denormal_protection()) {
572 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
573 Sample* const sp = i->data();
574 for (pframes_t nx = 0; nx < nframes; ++nx) {
582 /* -------------------------------------------------------------------------------------------
584 ----------------------------------------------------------------------------------------- */
586 /* set this to be true if the meter will already have been ::run() earlier */
587 bool const meter_already_run = metering_state() == MeteringInput;
589 framecnt_t latency = 0;
591 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
593 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
594 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
599 /* if it has any inputs, make sure they match */
600 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
601 if (bufs.count() != (*i)->input_streams()) {
603 DEBUG::Processors, string_compose (
604 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
605 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
612 /* should we NOT run plugins here if the route is inactive?
613 do we catch route != active somewhere higher?
616 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
617 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
620 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
621 bufs.set_count ((*i)->output_streams());
623 if ((*i)->active ()) {
624 latency += (*i)->signal_latency ();
630 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
631 boost::shared_ptr<Processor> endpoint,
632 bool include_endpoint, bool for_export, bool for_freeze)
634 /* If no processing is required, there's no need to go any further. */
635 if (!endpoint && !include_endpoint) {
639 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
640 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
641 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
643 /* trim is always at the top, for bounce no latency compensation is needed */
644 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
645 _trim->setup_gain_automation (start, start + nframes, nframes);
648 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
650 if (!include_endpoint && (*i) == endpoint) {
654 /* if we're not exporting, stop processing if we come across a routing processor. */
655 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
658 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
662 /* don't run any processors that does routing.
663 * oh, and don't bother with the peak meter either.
665 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
666 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
667 buffers.set_count ((*i)->output_streams());
668 latency += (*i)->signal_latency ();
671 if ((*i) == endpoint) {
678 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
679 bool include_endpoint, bool for_export, bool for_freeze) const
681 framecnt_t latency = 0;
682 if (!endpoint && !include_endpoint) {
686 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
687 if (!include_endpoint && (*i) == endpoint) {
690 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
693 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
696 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
697 latency += (*i)->signal_latency ();
699 if ((*i) == endpoint) {
707 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
708 bool include_endpoint, bool for_export, bool for_freeze) const
710 if (!endpoint && !include_endpoint) {
714 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
715 if (!include_endpoint && (*i) == endpoint) {
718 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
721 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
724 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
725 cc = (*i)->output_streams();
727 if ((*i) == endpoint) {
735 Route::n_process_buffers ()
737 return max (_input->n_ports(), processor_max_streams);
741 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
743 assert (is_monitor());
744 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
745 fill_buffers_with_input (bufs, _input, nframes);
746 passthru (bufs, start_frame, end_frame, nframes, declick);
750 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
754 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
756 /* control/monitor bus ignores input ports when something is
757 feeding the listen "stream". data will "arrive" into the
758 route from the intreturn processor element.
761 bufs.silence (nframes, 0);
764 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
765 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
769 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
771 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
773 bufs.set_count (_input->n_ports());
774 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
775 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
779 Route::set_listen (bool yn, void* src, bool group_override)
785 bool group_active = _route_group && _route_group->is_active() && _route_group->is_solo();
786 if (group_override && _route_group) {
787 group_active = !group_active;
790 if (_route_group && src != _route_group && group_active) {
791 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group, group_override));
796 if (yn != _monitor_send->active()) {
798 _monitor_send->activate ();
799 _mute_master->set_soloed_by_self (true);
801 _monitor_send->deactivate ();
802 _mute_master->set_soloed_by_self (false);
804 _mute_master->set_soloed_by_others (false);
806 listen_changed (src, group_override); /* EMIT SIGNAL */
812 Route::listening_via_monitor () const
815 return _monitor_send->active ();
822 Route::set_solo_safe (bool yn, void *src)
824 if (_solo_safe != yn) {
826 solo_safe_changed (src);
831 Route::solo_safe() const
837 Route::clear_all_solo_state ()
839 // ideally this function will never do anything, it only exists to forestall Murphy
840 bool emit_changed = false;
843 // these are really debug messages, but of possible interest.
845 PBD::info << string_compose (_("Cleared Explicit solo: %1\n"), name());
847 if (_soloed_by_others_upstream || _soloed_by_others_downstream) {
848 PBD::info << string_compose (_("Cleared Implicit solo: %1 up:%2 down:%3\n"),
849 name(), _soloed_by_others_upstream, _soloed_by_others_downstream);
853 if (!_self_solo && (_soloed_by_others_upstream || _soloed_by_others_downstream)) {
854 // if self-soled, set_solo() will do signal emission
858 _soloed_by_others_upstream = 0;
859 _soloed_by_others_downstream = 0;
862 PBD::Unwinder<bool> uw (_solo_safe, false);
863 set_solo (false, this);
867 set_mute_master_solo ();
868 solo_changed (false, this, false); /* EMIT SIGNAL */
873 Route::set_solo (bool yn, void *src, bool group_override)
876 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
880 if (is_master() || is_monitor() || is_auditioner()) {
881 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
885 bool group_active = _route_group && _route_group->is_active() && _route_group->is_solo();
886 if (group_override && _route_group) {
887 group_active = !group_active;
889 if (_route_group && src != _route_group && group_active) {
890 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group, group_override));
894 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
895 name(), yn, src, (src == _route_group), self_soloed()));
897 if (self_soloed() != yn) {
899 solo_changed (true, src, group_override); /* EMIT SIGNAL */
900 _solo_control->Changed (); /* EMIT SIGNAL */
903 assert (Config->get_solo_control_is_listen_control() || !_monitor_send || !_monitor_send->active());
905 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
906 Config->get_solo_mute_overrride().
909 if (yn && Profile->get_trx()) {
910 set_mute (false, src);
915 Route::set_self_solo (bool yn)
917 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
919 set_mute_master_solo ();
923 Route::mod_solo_by_others_upstream (int32_t delta)
925 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
926 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
928 uint32_t old_sbu = _soloed_by_others_upstream;
931 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
932 _soloed_by_others_upstream += delta;
934 _soloed_by_others_upstream = 0;
937 _soloed_by_others_upstream += delta;
940 DEBUG_TRACE (DEBUG::Solo, string_compose (
941 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
942 name(), delta, _soloed_by_others_upstream, old_sbu,
943 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
945 /* push the inverse solo change to everything that feeds us.
947 This is important for solo-within-group. When we solo 1 track out of N that
948 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
949 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
950 tracks that feed it. This will silence them if they were audible because
951 of a bus solo, but the newly soloed track will still be audible (because
954 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
958 if ((_self_solo || _soloed_by_others_downstream) &&
959 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
960 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
962 if (delta > 0 || !Config->get_exclusive_solo()) {
963 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
964 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
968 boost::shared_ptr<Route> sr = i->r.lock();
970 sr->mod_solo_by_others_downstream (-delta);
976 set_mute_master_solo ();
977 solo_changed (false, this, false); /* EMIT SIGNAL */
981 Route::mod_solo_by_others_downstream (int32_t delta)
983 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
984 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
987 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
988 _soloed_by_others_downstream += delta;
990 _soloed_by_others_downstream = 0;
993 _soloed_by_others_downstream += delta;
996 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
998 set_mute_master_solo ();
999 solo_changed (false, this, false); /* EMIT SIGNAL */
1003 Route::set_mute_master_solo ()
1005 _mute_master->set_soloed_by_self (self_soloed());
1006 _mute_master->set_soloed_by_others (soloed_by_others_downstream() || soloed_by_others_upstream());
1010 Route::mod_solo_isolated_by_upstream (bool yn, void* src)
1012 bool old = solo_isolated ();
1013 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod_solo_isolated_by_upstream cur: %2 d: %3\n",
1014 name(), _solo_isolated_by_upstream, yn ? "+1" : "-1"));
1017 if (_solo_isolated_by_upstream >= 1) {
1018 _solo_isolated_by_upstream--;
1020 _solo_isolated_by_upstream = 0;
1023 _solo_isolated_by_upstream++;
1026 if (solo_isolated() != old) {
1027 /* solo isolated status changed */
1028 _mute_master->set_solo_ignore (solo_isolated());
1029 solo_isolated_changed (src); /* EMIT SIGNAL */
1034 Route::set_solo_isolated (bool yn, void *src)
1036 if (is_master() || is_monitor() || is_auditioner()) {
1040 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
1041 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
1045 bool changed = false;
1048 if (_solo_isolated == false) {
1049 _mute_master->set_solo_ignore (true);
1052 _solo_isolated = true;
1054 if (_solo_isolated == true) {
1055 _solo_isolated = false;
1056 _mute_master->set_solo_ignore (false);
1066 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
1068 boost::shared_ptr<RouteList> routes = _session.get_routes ();
1069 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
1071 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
1076 bool does_feed = feeds (*i, &sends_only);
1078 if (does_feed && !sends_only) {
1079 (*i)->mod_solo_isolated_by_upstream (yn, src);
1083 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
1085 solo_isolated_changed (src); /* EMIT SIGNAL */
1089 Route::solo_isolated () const
1091 return (_solo_isolated == true) || (_solo_isolated_by_upstream > 0);
1095 Route::set_mute_points (MuteMaster::MutePoint mp)
1097 _mute_master->set_mute_points (mp);
1098 mute_points_changed (); /* EMIT SIGNAL */
1100 if (_mute_master->muted_by_self()) {
1101 mute_changed (this); /* EMIT SIGNAL */
1102 _mute_control->Changed (); /* EMIT SIGNAL */
1107 Route::set_mute (bool yn, void *src)
1109 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
1110 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
1114 if (muted() != yn) {
1115 _mute_master->set_muted_by_self (yn);
1116 /* allow any derived classes to respond to the mute change
1117 before anybody else knows about it.
1120 /* tell everyone else */
1121 mute_changed (src); /* EMIT SIGNAL */
1122 _mute_control->Changed (); /* EMIT SIGNAL */
1127 Route::muted () const
1129 return _mute_master->muted_by_self();
1133 Route::muted_by_others () const
1135 // This method is only used by route_ui for display state.
1136 // The real thing is MuteMaster::muted_by_others_at()
1138 //master is never muted by others
1142 //now check to see if something is soloed (and I am not)
1143 //see also MuteMaster::mute_gain_at()
1144 return (_session.soloing() && !soloed() && !solo_isolated());
1149 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1151 cerr << name << " {" << endl;
1152 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1153 p != procs.end(); ++p) {
1154 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1156 cerr << "}" << endl;
1160 /** Supposing that we want to insert a Processor at a given Placement, return
1161 * the processor to add the new one before (or 0 to add at the end).
1163 boost::shared_ptr<Processor>
1164 Route::before_processor_for_placement (Placement p)
1166 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1168 ProcessorList::iterator loc;
1170 if (p == PreFader) {
1171 /* generic pre-fader: insert immediately before the amp */
1172 loc = find (_processors.begin(), _processors.end(), _amp);
1174 /* generic post-fader: insert right before the main outs */
1175 loc = find (_processors.begin(), _processors.end(), _main_outs);
1178 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1181 /** Supposing that we want to insert a Processor at a given index, return
1182 * the processor to add the new one before (or 0 to add at the end).
1184 boost::shared_ptr<Processor>
1185 Route::before_processor_for_index (int index)
1188 return boost::shared_ptr<Processor> ();
1191 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1193 ProcessorList::iterator i = _processors.begin ();
1195 while (i != _processors.end() && j < index) {
1196 if ((*i)->display_to_user()) {
1203 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1206 /** Add a processor either pre- or post-fader
1207 * @return 0 on success, non-0 on failure.
1210 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1212 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1216 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1217 * @param index Index to add the processor at, or -1 to add at the end of the list.
1218 * @return 0 on success, non-0 on failure.
1221 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1223 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1226 /** Add a processor to the route.
1227 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1228 * @return 0 on success, non-0 on failure.
1231 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1233 assert (processor != _meter);
1234 assert (processor != _main_outs);
1236 DEBUG_TRACE (DEBUG::Processors, string_compose (
1237 "%1 adding processor %2\n", name(), processor->name()));
1239 if (!AudioEngine::instance()->connected() || !processor) {
1244 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1245 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1246 ProcessorState pstate (this);
1248 boost::shared_ptr<PluginInsert> pi;
1249 boost::shared_ptr<PortInsert> porti;
1251 if (processor == _amp) {
1252 /* Ensure that only one amp is in the list at any time */
1253 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1254 if (check != _processors.end()) {
1255 if (before == _amp) {
1256 /* Already in position; all is well */
1259 _processors.erase (check);
1264 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1266 ProcessorList::iterator loc;
1268 /* inserting before a processor; find it */
1269 loc = find (_processors.begin(), _processors.end(), before);
1270 if (loc == _processors.end ()) {
1275 /* inserting at end */
1276 loc = _processors.end ();
1279 _processors.insert (loc, processor);
1280 processor->set_owner (this);
1282 // Set up processor list channels. This will set processor->[input|output]_streams(),
1283 // configure redirect ports properly, etc.
1286 if (configure_processors_unlocked (err)) {
1288 configure_processors_unlocked (0); // it worked before we tried to add it ...
1293 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1295 if (pi->has_no_inputs ()) {
1296 /* generator plugin */
1297 _have_internal_generator = true;
1302 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
1303 processor->activate ();
1306 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1308 _output->set_user_latency (0);
1311 reset_instrument_info ();
1312 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1313 set_processor_positions ();
1319 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1321 const XMLProperty *prop;
1324 boost::shared_ptr<Processor> processor;
1326 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1327 so that we can add the processor in the right place (pre/post-fader)
1330 XMLNodeList const & children = node.children ();
1331 XMLNodeList::const_iterator i = children.begin ();
1333 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1337 Placement placement = PreFader;
1339 if (i != children.end()) {
1340 if ((prop = (*i)->property (X_("placement"))) != 0) {
1341 placement = Placement (string_2_enum (prop->value(), placement));
1345 if (node.name() == "Insert") {
1347 if ((prop = node.property ("type")) != 0) {
1349 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1350 prop->value() == "lv2" ||
1351 prop->value() == "windows-vst" ||
1352 prop->value() == "lxvst" ||
1353 prop->value() == "audiounit") {
1355 if (_session.get_disable_all_loaded_plugins ()) {
1356 processor.reset (new UnknownProcessor (_session, node));
1358 processor.reset (new PluginInsert (_session));
1363 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1368 } else if (node.name() == "Send") {
1370 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1371 processor.reset (new Send (_session, sendpan, _mute_master));
1375 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1379 if (processor->set_state (node, version)) {
1383 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1384 if (i != children.end()) {
1385 if ((prop = (*i)->property (X_("active"))) != 0) {
1386 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
1387 processor->activate();
1389 processor->deactivate();
1393 return (add_processor (processor, placement, 0, false) == 0);
1396 catch (failed_constructor &err) {
1397 warning << _("processor could not be created. Ignored.") << endmsg;
1403 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1405 /* NOTE: this is intended to be used ONLY when copying
1406 processors from another Route. Hence the subtle
1407 differences between this and ::add_processor()
1410 ProcessorList::iterator loc;
1413 loc = find(_processors.begin(), _processors.end(), before);
1415 /* nothing specified - at end */
1416 loc = _processors.end ();
1419 if (!_session.engine().connected()) {
1423 if (others.empty()) {
1428 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1429 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1430 ProcessorState pstate (this);
1432 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1438 boost::shared_ptr<PluginInsert> pi;
1440 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1444 _processors.insert (loc, *i);
1445 (*i)->set_owner (this);
1447 if ((*i)->active()) {
1451 /* Think: does this really need to be called for every processor in the loop? */
1453 if (configure_processors_unlocked (err)) {
1455 configure_processors_unlocked (0); // it worked before we tried to add it ...
1460 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1463 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1464 boost::shared_ptr<PluginInsert> pi;
1466 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1467 if (pi->has_no_inputs ()) {
1468 _have_internal_generator = true;
1474 _output->set_user_latency (0);
1477 reset_instrument_info ();
1478 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1479 set_processor_positions ();
1485 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1487 if (p == PreFader) {
1488 start = _processors.begin();
1489 end = find(_processors.begin(), _processors.end(), _amp);
1491 start = find(_processors.begin(), _processors.end(), _amp);
1493 end = _processors.end();
1497 /** Turn off all processors with a given placement
1498 * @param p Placement of processors to disable
1501 Route::disable_processors (Placement p)
1503 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1505 ProcessorList::iterator start, end;
1506 placement_range(p, start, end);
1508 for (ProcessorList::iterator i = start; i != end; ++i) {
1509 (*i)->deactivate ();
1512 _session.set_dirty ();
1515 /** Turn off all redirects
1518 Route::disable_processors ()
1520 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1522 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1523 (*i)->deactivate ();
1526 _session.set_dirty ();
1529 /** Turn off all redirects with a given placement
1530 * @param p Placement of redirects to disable
1533 Route::disable_plugins (Placement p)
1535 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1537 ProcessorList::iterator start, end;
1538 placement_range(p, start, end);
1540 for (ProcessorList::iterator i = start; i != end; ++i) {
1541 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1542 (*i)->deactivate ();
1546 _session.set_dirty ();
1549 /** Turn off all plugins
1552 Route::disable_plugins ()
1554 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1556 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1557 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1558 (*i)->deactivate ();
1562 _session.set_dirty ();
1567 Route::ab_plugins (bool forward)
1569 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1573 /* forward = turn off all active redirects, and mark them so that the next time
1574 we go the other way, we will revert them
1577 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1578 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1582 if ((*i)->active()) {
1583 (*i)->deactivate ();
1584 (*i)->set_next_ab_is_active (true);
1586 (*i)->set_next_ab_is_active (false);
1592 /* backward = if the redirect was marked to go active on the next ab, do so */
1594 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1596 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1600 if ((*i)->get_next_ab_is_active()) {
1603 (*i)->deactivate ();
1608 _session.set_dirty ();
1612 /** Remove processors with a given placement.
1613 * @param p Placement of processors to remove.
1616 Route::clear_processors (Placement p)
1618 if (!_session.engine().connected()) {
1622 bool already_deleting = _session.deletion_in_progress();
1623 if (!already_deleting) {
1624 _session.set_deletion_in_progress();
1628 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1629 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1630 ProcessorList new_list;
1631 ProcessorStreams err;
1632 bool seen_amp = false;
1634 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1640 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1642 /* you can't remove these */
1644 new_list.push_back (*i);
1651 new_list.push_back (*i);
1654 (*i)->drop_references ();
1662 (*i)->drop_references ();
1665 new_list.push_back (*i);
1672 _processors = new_list;
1673 configure_processors_unlocked (&err); // this can't fail
1676 processor_max_streams.reset();
1677 _have_internal_generator = false;
1678 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1679 set_processor_positions ();
1681 reset_instrument_info ();
1683 if (!already_deleting) {
1684 _session.clear_deletion_in_progress();
1689 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1691 // TODO once the export point can be configured properly, do something smarter here
1692 if (processor == _capturing_processor) {
1693 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1694 if (need_process_lock) {
1698 _capturing_processor.reset();
1700 if (need_process_lock) {
1705 /* these can never be removed */
1707 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1711 if (!_session.engine().connected()) {
1715 processor_max_streams.reset();
1718 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1719 if (need_process_lock) {
1723 /* Caller must hold process lock */
1724 assert (!AudioEngine::instance()->process_lock().trylock());
1726 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1728 ProcessorState pstate (this);
1730 ProcessorList::iterator i;
1731 bool removed = false;
1733 for (i = _processors.begin(); i != _processors.end(); ) {
1734 if (*i == processor) {
1736 /* move along, see failure case for configure_processors()
1737 where we may need to reconfigure the processor.
1740 /* stop redirects that send signals to JACK ports
1741 from causing noise as a result of no longer being
1745 boost::shared_ptr<IOProcessor> iop;
1747 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1751 i = _processors.erase (i);
1759 _output->set_user_latency (0);
1767 if (configure_processors_unlocked (err)) {
1769 /* we know this will work, because it worked before :) */
1770 configure_processors_unlocked (0);
1774 _have_internal_generator = false;
1776 for (i = _processors.begin(); i != _processors.end(); ++i) {
1777 boost::shared_ptr<PluginInsert> pi;
1779 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1780 if (pi->has_no_inputs ()) {
1781 _have_internal_generator = true;
1786 if (need_process_lock) {
1791 reset_instrument_info ();
1792 processor->drop_references ();
1793 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1794 set_processor_positions ();
1800 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1802 ProcessorList deleted;
1804 if (!_session.engine().connected()) {
1808 processor_max_streams.reset();
1811 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1812 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1813 ProcessorState pstate (this);
1815 ProcessorList::iterator i;
1816 boost::shared_ptr<Processor> processor;
1818 for (i = _processors.begin(); i != _processors.end(); ) {
1822 /* these can never be removed */
1824 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1829 /* see if its in the list of processors to delete */
1831 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1836 /* stop IOProcessors that send to JACK ports
1837 from causing noise as a result of no longer being
1841 boost::shared_ptr<IOProcessor> iop;
1843 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1847 deleted.push_back (processor);
1848 i = _processors.erase (i);
1851 if (deleted.empty()) {
1852 /* none of those in the requested list were found */
1856 _output->set_user_latency (0);
1858 if (configure_processors_unlocked (err)) {
1860 /* we know this will work, because it worked before :) */
1861 configure_processors_unlocked (0);
1866 _have_internal_generator = false;
1868 for (i = _processors.begin(); i != _processors.end(); ++i) {
1869 boost::shared_ptr<PluginInsert> pi;
1871 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1872 if (pi->has_no_inputs ()) {
1873 _have_internal_generator = true;
1880 /* now try to do what we need to so that those that were removed will be deleted */
1882 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1883 (*i)->drop_references ();
1886 reset_instrument_info ();
1887 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1888 set_processor_positions ();
1894 Route::reset_instrument_info ()
1896 boost::shared_ptr<Processor> instr = the_instrument();
1898 _instrument_info.set_internal_instrument (instr);
1902 /** Caller must hold process lock */
1904 Route::configure_processors (ProcessorStreams* err)
1906 #ifndef PLATFORM_WINDOWS
1907 assert (!AudioEngine::instance()->process_lock().trylock());
1910 if (!_in_configure_processors) {
1911 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1912 return configure_processors_unlocked (err);
1919 Route::input_streams () const
1921 return _input->n_ports ();
1924 list<pair<ChanCount, ChanCount> >
1925 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1927 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1929 return try_configure_processors_unlocked (in, err);
1932 list<pair<ChanCount, ChanCount> >
1933 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1935 // Check each processor in order to see if we can configure as requested
1937 list<pair<ChanCount, ChanCount> > configuration;
1940 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1941 DEBUG_TRACE (DEBUG::Processors, "{\n");
1943 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1945 if ((*p)->can_support_io_configuration(in, out)) {
1946 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1947 configuration.push_back(make_pair(in, out));
1950 // restriction for Monitor Section Processors
1951 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1952 /* do not allow to add/remove channels (for now)
1953 * The Monitor follows the master-bus and has no panner (unpan)
1954 * but do allow processors with midi-in to be added (e.g VSTs with control that
1955 * will remain unconnected)
1957 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1958 return list<pair<ChanCount, ChanCount> > ();
1960 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1961 // internal sends make no sense, only feedback
1962 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1963 return list<pair<ChanCount, ChanCount> > ();
1965 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1966 /* External Sends can be problematic. one can add/remove ports
1967 * there signal leaves the DAW to external monitors anyway, so there's
1968 * no real use for allowing them here anyway.
1970 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1971 return list<pair<ChanCount, ChanCount> > ();
1973 if (boost::dynamic_pointer_cast<Send> (*p)) {
1975 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1976 return list<pair<ChanCount, ChanCount> > ();
1985 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1986 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1987 DEBUG_TRACE (DEBUG::Processors, "}\n");
1988 return list<pair<ChanCount, ChanCount> > ();
1992 DEBUG_TRACE (DEBUG::Processors, "}\n");
1994 return configuration;
1997 /** Set the input/output configuration of each processor in the processors list.
1998 * Caller must hold process lock.
1999 * Return 0 on success, otherwise configuration is impossible.
2002 Route::configure_processors_unlocked (ProcessorStreams* err)
2004 #ifndef PLATFORM_WINDOWS
2005 assert (!AudioEngine::instance()->process_lock().trylock());
2008 if (_in_configure_processors) {
2012 /* put invisible processors where they should be */
2013 setup_invisible_processors ();
2015 _in_configure_processors = true;
2017 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
2019 if (configuration.empty ()) {
2020 _in_configure_processors = false;
2025 bool seen_mains_out = false;
2026 processor_out_streams = _input->n_ports();
2027 processor_max_streams.reset();
2029 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
2030 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
2032 if (!(*p)->configure_io(c->first, c->second)) {
2033 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
2035 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
2036 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
2038 boost::shared_ptr<PluginInsert> pi;
2039 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2040 /* plugins connected via Split Match may have more channels.
2041 * route/scratch buffers are needed for all of them*/
2042 processor_max_streams = ChanCount::max(processor_max_streams, pi->input_streams());
2043 processor_max_streams = ChanCount::max(processor_max_streams, pi->natural_input_streams());
2047 if (boost::dynamic_pointer_cast<Delivery> (*p)
2048 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
2049 /* main delivery will increase port count to match input.
2050 * the Delivery::Main is usually the last processor - followed only by
2053 seen_mains_out = true;
2055 if (!seen_mains_out) {
2056 processor_out_streams = out;
2062 _meter->set_max_channels (processor_max_streams);
2065 /* make sure we have sufficient scratch buffers to cope with the new processor
2068 _session.ensure_buffers (n_process_buffers ());
2070 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
2072 _in_configure_processors = false;
2076 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
2077 * @param state New active state for those processors.
2080 Route::all_visible_processors_active (bool state)
2082 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2084 if (_processors.empty()) {
2088 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2089 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2096 (*i)->deactivate ();
2100 _session.set_dirty ();
2104 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2106 /* check if re-order requires re-configuration of any processors
2107 * -> compare channel configuration for all processors
2109 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2110 ChanCount c = input_streams ();
2112 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2114 if (c != (*j)->input_streams()) {
2117 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2120 if ((*i)->input_streams() != c) {
2123 c = (*i)->output_streams();
2135 __attribute__((annotate("realtime")))
2138 Route::apply_processor_order (const ProcessorList& new_order)
2140 /* need to hold processor_lock; either read or write lock
2141 * and the engine process_lock.
2142 * Due to r/w lock ambiguity we can only assert the latter
2144 assert (!AudioEngine::instance()->process_lock().trylock());
2147 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2148 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2149 * processors in the current actual processor list that are hidden. Any visible processors
2150 * in the current list but not in "new_order" will be assumed to be deleted.
2153 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2154 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2155 * (note though that ::processors_reorder_needs_configure() ensured that
2156 * this function will only ever be called from the rt-thread if no processor were removed)
2158 * either way, I can't proove it, but an x-run due to re-order here is less likley
2159 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2162 ProcessorList as_it_will_be;
2163 ProcessorList::iterator oiter;
2164 ProcessorList::const_iterator niter;
2166 oiter = _processors.begin();
2167 niter = new_order.begin();
2169 while (niter != new_order.end()) {
2171 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2172 then append it to the temp list.
2174 Otherwise, see if the next processor in the old list is in the new list. if not,
2175 its been deleted. If its there, append it to the temp list.
2178 if (oiter == _processors.end()) {
2180 /* no more elements in the old list, so just stick the rest of
2181 the new order onto the temp list.
2184 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2185 while (niter != new_order.end()) {
2192 if (!(*oiter)->display_to_user()) {
2194 as_it_will_be.push_back (*oiter);
2198 /* visible processor: check that its in the new order */
2200 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2201 /* deleted: do nothing, shared_ptr<> will clean up */
2203 /* ignore this one, and add the next item from the new order instead */
2204 as_it_will_be.push_back (*niter);
2209 /* now remove from old order - its taken care of no matter what */
2210 oiter = _processors.erase (oiter);
2214 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2216 /* If the meter is in a custom position, find it and make a rough note of its position */
2217 maybe_note_meter_position ();
2221 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2223 // it a change is already queued, wait for it
2224 // (unless engine is stopped. apply immediately and proceed
2225 while (g_atomic_int_get (&_pending_process_reorder)) {
2226 if (!AudioEngine::instance()->running()) {
2227 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2228 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2230 apply_processor_order(_pending_processor_order);
2231 setup_invisible_processors ();
2233 g_atomic_int_set (&_pending_process_reorder, 0);
2235 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2236 set_processor_positions ();
2238 // TODO rather use a semaphore or something.
2239 // but since ::reorder_processors() is called
2240 // from the GUI thread, this is fine..
2245 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2247 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2248 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2249 ProcessorState pstate (this);
2251 apply_processor_order (new_order);
2253 if (configure_processors_unlocked (err)) {
2261 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2262 set_processor_positions ();
2265 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2266 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2268 // _pending_processor_order is protected by _processor_lock
2269 _pending_processor_order = new_order;
2270 g_atomic_int_set (&_pending_process_reorder, 1);
2283 Route::get_template()
2285 return state(false);
2289 Route::state(bool full_state)
2291 if (!_session._template_state_dir.empty()) {
2292 assert (!full_state); // only for templates
2293 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2296 XMLNode *node = new XMLNode("Route");
2297 ProcessorList::iterator i;
2300 id().print (buf, sizeof (buf));
2301 node->add_property("id", buf);
2302 node->add_property ("name", _name);
2303 node->add_property("default-type", _default_type.to_string());
2306 node->add_property("flags", enum_2_string (_flags));
2309 node->add_property("active", _active?"yes":"no");
2311 boost::to_string (_phase_invert, p);
2312 node->add_property("phase-invert", p);
2313 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2314 node->add_property("meter-point", enum_2_string (_meter_point));
2316 node->add_property("meter-type", enum_2_string (_meter_type));
2319 node->add_property("route-group", _route_group->name());
2322 snprintf (buf, sizeof (buf), "%d", _order_key);
2323 node->add_property ("order-key", buf);
2324 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2325 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2326 node->add_property ("soloed-by-upstream", buf);
2327 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2328 node->add_property ("soloed-by-downstream", buf);
2329 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2330 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2332 node->add_child_nocopy (_input->state (full_state));
2333 node->add_child_nocopy (_output->state (full_state));
2334 node->add_child_nocopy (_solo_control->get_state ());
2335 node->add_child_nocopy (_mute_control->get_state ());
2336 node->add_child_nocopy (_mute_master->get_state ());
2339 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2342 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2343 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2344 remote_control_node->add_property (X_("id"), buf);
2345 node->add_child_nocopy (*remote_control_node);
2347 if (_comment.length()) {
2348 XMLNode *cmt = node->add_child ("Comment");
2349 cmt->add_content (_comment);
2353 node->add_child_nocopy (_pannable->state (full_state));
2356 for (i = _processors.begin(); i != _processors.end(); ++i) {
2358 /* template save: do not include internal sends functioning as
2359 aux sends because the chance of the target ID
2360 in the session where this template is used
2363 similarly, do not save listen sends which connect to
2364 the monitor section, because these will always be
2367 boost::shared_ptr<InternalSend> is;
2369 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2370 if (is->role() == Delivery::Listen) {
2375 node->add_child_nocopy((*i)->state (full_state));
2379 node->add_child_copy (*_extra_xml);
2382 if (_custom_meter_position_noted) {
2383 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2385 after->id().print (buf, sizeof (buf));
2386 node->add_property (X_("processor-after-last-custom-meter"), buf);
2390 if (!_session._template_state_dir.empty()) {
2391 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2398 Route::set_state (const XMLNode& node, int version)
2400 if (version < 3000) {
2401 return set_state_2X (node, version);
2405 XMLNodeConstIterator niter;
2407 const XMLProperty *prop;
2409 if (node.name() != "Route"){
2410 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2414 if ((prop = node.property (X_("name"))) != 0) {
2415 Route::set_name (prop->value());
2419 _initial_io_setup = true;
2421 if ((prop = node.property (X_("flags"))) != 0) {
2422 _flags = Flag (string_2_enum (prop->value(), _flags));
2427 if (is_master() || is_monitor() || is_auditioner()) {
2428 _mute_master->set_solo_ignore (true);
2432 /* monitor bus does not get a panner, but if (re)created
2433 via XML, it will already have one by the time we
2434 call ::set_state(). so ... remove it.
2439 /* add all processors (except amp, which is always present) */
2441 nlist = node.children();
2442 XMLNode processor_state (X_("processor_state"));
2444 Stateful::save_extra_xml (node);
2446 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2450 if (child->name() == IO::state_node_name) {
2451 if ((prop = child->property (X_("direction"))) == 0) {
2455 if (prop->value() == "Input") {
2456 _input->set_state (*child, version);
2457 } else if (prop->value() == "Output") {
2458 _output->set_state (*child, version);
2462 if (child->name() == X_("Processor")) {
2463 processor_state.add_child_copy (*child);
2466 if (child->name() == X_("Pannable")) {
2468 _pannable->set_state (*child, version);
2470 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2475 if ((prop = node.property (X_("meter-point"))) != 0) {
2476 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2477 set_meter_point (mp, true);
2479 _meter->set_display_to_user (_meter_point == MeterCustom);
2483 if ((prop = node.property (X_("meter-type"))) != 0) {
2484 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2487 _initial_io_setup = false;
2489 set_processor_state (processor_state);
2491 // this looks up the internal instrument in processors
2492 reset_instrument_info();
2494 if ((prop = node.property ("self-solo")) != 0) {
2495 set_self_solo (string_is_affirmative (prop->value()));
2498 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2499 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2500 mod_solo_by_others_upstream (atoi (prop->value()));
2503 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2504 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2505 mod_solo_by_others_downstream (atoi (prop->value()));
2508 if ((prop = node.property ("solo-isolated")) != 0) {
2509 set_solo_isolated (string_is_affirmative (prop->value()), this);
2512 if ((prop = node.property ("solo-safe")) != 0) {
2513 set_solo_safe (string_is_affirmative (prop->value()), this);
2516 if ((prop = node.property (X_("phase-invert"))) != 0) {
2517 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2520 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2521 set_denormal_protection (string_is_affirmative (prop->value()));
2524 if ((prop = node.property (X_("active"))) != 0) {
2525 bool yn = string_is_affirmative (prop->value());
2526 _active = !yn; // force switch
2527 set_active (yn, this);
2530 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2531 set_order_key (atoi(prop->value()));
2534 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2538 string::size_type colon, equal;
2539 string remaining = prop->value();
2541 while (remaining.length()) {
2543 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2544 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2547 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2548 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2551 string keyname = remaining.substr (0, equal);
2553 if ((keyname == "EditorSort") || (keyname == "editor")) {
2554 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2560 colon = remaining.find_first_of (':');
2562 if (colon != string::npos) {
2563 remaining = remaining.substr (colon+1);
2570 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2571 PBD::ID id (prop->value ());
2572 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2573 ProcessorList::const_iterator i = _processors.begin ();
2574 while (i != _processors.end() && (*i)->id() != id) {
2578 if (i != _processors.end ()) {
2579 _processor_after_last_custom_meter = *i;
2580 _custom_meter_position_noted = true;
2584 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2587 if (child->name() == X_("Comment")) {
2589 /* XXX this is a terrible API design in libxml++ */
2591 XMLNode *cmt = *(child->children().begin());
2592 _comment = cmt->content();
2594 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2595 if (prop->value() == "solo") {
2596 _solo_control->set_state (*child, version);
2597 } else if (prop->value() == "mute") {
2598 _mute_control->set_state (*child, version);
2601 } else if (child->name() == X_("RemoteControl")) {
2602 if ((prop = child->property (X_("id"))) != 0) {
2604 sscanf (prop->value().c_str(), "%d", &x);
2605 set_remote_control_id_internal (x);
2608 } else if (child->name() == X_("MuteMaster")) {
2609 _mute_master->set_state (*child, version);
2611 } else if (child->name() == Automatable::xml_node_name) {
2612 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2620 Route::set_state_2X (const XMLNode& node, int version)
2622 LocaleGuard lg (X_("C"));
2624 XMLNodeConstIterator niter;
2626 const XMLProperty *prop;
2628 /* 2X things which still remain to be handled:
2634 if (node.name() != "Route") {
2635 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2639 if ((prop = node.property (X_("flags"))) != 0) {
2640 string f = prop->value ();
2641 boost::replace_all (f, "ControlOut", "MonitorOut");
2642 _flags = Flag (string_2_enum (f, _flags));
2647 if (is_master() || is_monitor() || is_auditioner()) {
2648 _mute_master->set_solo_ignore (true);
2651 if ((prop = node.property (X_("phase-invert"))) != 0) {
2652 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2653 if (string_is_affirmative (prop->value ())) {
2656 set_phase_invert (p);
2659 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2660 set_denormal_protection (string_is_affirmative (prop->value()));
2663 if ((prop = node.property (X_("soloed"))) != 0) {
2664 bool yn = string_is_affirmative (prop->value());
2666 /* XXX force reset of solo status */
2668 set_solo (yn, this);
2671 if ((prop = node.property (X_("muted"))) != 0) {
2674 bool muted = string_is_affirmative (prop->value());
2680 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2682 if (string_is_affirmative (prop->value())){
2683 mute_point = mute_point + "PreFader";
2688 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2690 if (string_is_affirmative (prop->value())){
2693 mute_point = mute_point + ",";
2696 mute_point = mute_point + "PostFader";
2701 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2703 if (string_is_affirmative (prop->value())){
2706 mute_point = mute_point + ",";
2709 mute_point = mute_point + "Listen";
2714 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2716 if (string_is_affirmative (prop->value())){
2719 mute_point = mute_point + ",";
2722 mute_point = mute_point + "Main";
2726 _mute_master->set_mute_points (mute_point);
2727 _mute_master->set_muted_by_self (true);
2731 if ((prop = node.property (X_("meter-point"))) != 0) {
2732 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2735 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2736 don't mean the same thing.
2739 if ((prop = node.property (X_("order-keys"))) != 0) {
2743 string::size_type colon, equal;
2744 string remaining = prop->value();
2746 while (remaining.length()) {
2748 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2749 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2752 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2753 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2756 string keyname = remaining.substr (0, equal);
2758 if (keyname == "EditorSort" || keyname == "editor") {
2759 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2765 colon = remaining.find_first_of (':');
2767 if (colon != string::npos) {
2768 remaining = remaining.substr (colon+1);
2777 nlist = node.children ();
2778 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2782 if (child->name() == IO::state_node_name) {
2784 /* there is a note in IO::set_state_2X() about why we have to call
2788 _input->set_state_2X (*child, version, true);
2789 _output->set_state_2X (*child, version, false);
2791 if ((prop = child->property (X_("name"))) != 0) {
2792 Route::set_name (prop->value ());
2797 if ((prop = child->property (X_("active"))) != 0) {
2798 bool yn = string_is_affirmative (prop->value());
2799 _active = !yn; // force switch
2800 set_active (yn, this);
2803 if ((prop = child->property (X_("gain"))) != 0) {
2806 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2807 _amp->gain_control()->set_value (val);
2811 /* Set up Panners in the IO */
2812 XMLNodeList io_nlist = child->children ();
2814 XMLNodeConstIterator io_niter;
2817 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2819 io_child = *io_niter;
2821 if (io_child->name() == X_("Panner")) {
2822 _main_outs->panner_shell()->set_state(*io_child, version);
2823 } else if (io_child->name() == X_("Automation")) {
2824 /* IO's automation is for the fader */
2825 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2831 XMLNodeList redirect_nodes;
2833 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2837 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2838 redirect_nodes.push_back(child);
2843 set_processor_state_2X (redirect_nodes, version);
2845 Stateful::save_extra_xml (node);
2847 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2850 if (child->name() == X_("Comment")) {
2852 /* XXX this is a terrible API design in libxml++ */
2854 XMLNode *cmt = *(child->children().begin());
2855 _comment = cmt->content();
2857 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2858 if (prop->value() == X_("solo")) {
2859 _solo_control->set_state (*child, version);
2860 } else if (prop->value() == X_("mute")) {
2861 _mute_control->set_state (*child, version);
2864 } else if (child->name() == X_("RemoteControl")) {
2865 if ((prop = child->property (X_("id"))) != 0) {
2867 sscanf (prop->value().c_str(), "%d", &x);
2868 set_remote_control_id_internal (x);
2878 Route::get_processor_state ()
2880 XMLNode* root = new XMLNode (X_("redirects"));
2881 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2882 root->add_child_nocopy ((*i)->state (true));
2889 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2891 /* We don't bother removing existing processors not in nList, as this
2892 method will only be called when creating a Route from scratch, not
2893 for undo purposes. Just put processors in at the appropriate place
2897 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2898 add_processor_from_xml_2X (**i, version);
2903 Route::set_processor_state (const XMLNode& node)
2905 const XMLNodeList &nlist = node.children();
2906 XMLNodeConstIterator niter;
2907 ProcessorList new_order;
2908 bool must_configure = false;
2910 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2912 XMLProperty* prop = (*niter)->property ("type");
2914 if (prop->value() == "amp") {
2915 _amp->set_state (**niter, Stateful::current_state_version);
2916 new_order.push_back (_amp);
2917 } else if (prop->value() == "trim") {
2918 _trim->set_state (**niter, Stateful::current_state_version);
2919 new_order.push_back (_trim);
2920 } else if (prop->value() == "meter") {
2921 _meter->set_state (**niter, Stateful::current_state_version);
2922 new_order.push_back (_meter);
2923 } else if (prop->value() == "delay") {
2925 _delayline->set_state (**niter, Stateful::current_state_version);
2926 new_order.push_back (_delayline);
2928 } else if (prop->value() == "main-outs") {
2929 _main_outs->set_state (**niter, Stateful::current_state_version);
2930 } else if (prop->value() == "intreturn") {
2932 _intreturn.reset (new InternalReturn (_session));
2933 must_configure = true;
2935 _intreturn->set_state (**niter, Stateful::current_state_version);
2936 } else if (is_monitor() && prop->value() == "monitor") {
2937 if (!_monitor_control) {
2938 _monitor_control.reset (new MonitorProcessor (_session));
2939 must_configure = true;
2941 _monitor_control->set_state (**niter, Stateful::current_state_version);
2942 } else if (prop->value() == "capture") {
2943 /* CapturingProcessor should never be restored, it's always
2944 added explicitly when needed */
2946 ProcessorList::iterator o;
2948 for (o = _processors.begin(); o != _processors.end(); ++o) {
2949 XMLProperty* id_prop = (*niter)->property(X_("id"));
2950 if (id_prop && (*o)->id() == id_prop->value()) {
2951 (*o)->set_state (**niter, Stateful::current_state_version);
2952 new_order.push_back (*o);
2957 // If the processor (*niter) is not on the route then create it
2959 if (o == _processors.end()) {
2961 boost::shared_ptr<Processor> processor;
2963 if (prop->value() == "intsend") {
2965 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2967 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2968 prop->value() == "lv2" ||
2969 prop->value() == "windows-vst" ||
2970 prop->value() == "lxvst" ||
2971 prop->value() == "audiounit") {
2973 if (_session.get_disable_all_loaded_plugins ()) {
2974 processor.reset (new UnknownProcessor (_session, **niter));
2976 processor.reset (new PluginInsert (_session));
2978 } else if (prop->value() == "port") {
2980 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2982 } else if (prop->value() == "send") {
2984 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2987 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2991 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2992 /* This processor could not be configured. Turn it into a UnknownProcessor */
2993 processor.reset (new UnknownProcessor (_session, **niter));
2996 /* we have to note the monitor send here, otherwise a new one will be created
2997 and the state of this one will be lost.
2999 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3000 if (isend && isend->role() == Delivery::Listen) {
3001 _monitor_send = isend;
3004 /* it doesn't matter if invisible processors are added here, as they
3005 will be sorted out by setup_invisible_processors () shortly.
3008 new_order.push_back (processor);
3009 must_configure = true;
3015 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3016 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3017 _processors = new_order;
3019 if (must_configure) {
3020 configure_processors_unlocked (0);
3023 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3025 (*i)->set_owner (this);
3026 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3028 boost::shared_ptr<PluginInsert> pi;
3030 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3031 if (pi->has_no_inputs ()) {
3032 _have_internal_generator = true;
3039 reset_instrument_info ();
3040 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3041 set_processor_positions ();
3045 Route::curve_reallocate ()
3047 // _gain_automation_curve.finish_resize ();
3048 // _pan_automation_curve.finish_resize ();
3052 Route::silence (framecnt_t nframes)
3054 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3059 silence_unlocked (nframes);
3063 Route::silence_unlocked (framecnt_t nframes)
3065 /* Must be called with the processor lock held */
3069 _output->silence (nframes);
3071 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3072 boost::shared_ptr<PluginInsert> pi;
3074 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3075 // skip plugins, they don't need anything when we're not active
3079 (*i)->silence (nframes);
3082 if (nframes == _session.get_block_size()) {
3089 Route::add_internal_return ()
3092 _intreturn.reset (new InternalReturn (_session));
3093 add_processor (_intreturn, PreFader);
3098 Route::add_send_to_internal_return (InternalSend* send)
3100 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3102 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3103 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3106 return d->add_send (send);
3112 Route::remove_send_from_internal_return (InternalSend* send)
3114 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3116 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3117 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3120 return d->remove_send (send);
3126 Route::enable_monitor_send ()
3128 /* Caller must hold process lock */
3129 assert (!AudioEngine::instance()->process_lock().trylock());
3131 /* master never sends to monitor section via the normal mechanism */
3132 assert (!is_master ());
3133 assert (!is_monitor ());
3135 /* make sure we have one */
3136 if (!_monitor_send) {
3137 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3138 _monitor_send->set_display_to_user (false);
3142 configure_processors (0);
3145 /** Add an aux send to a route.
3146 * @param route route to send to.
3147 * @param before Processor to insert before, or 0 to insert at the end.
3150 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3152 assert (route != _session.monitor_out ());
3155 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3157 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3159 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3161 if (d && d->target_route() == route) {
3162 /* already listening via the specified IO: do nothing */
3170 boost::shared_ptr<InternalSend> listener;
3173 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3174 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3175 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3178 add_processor (listener, before);
3180 } catch (failed_constructor& err) {
3188 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3190 ProcessorStreams err;
3191 ProcessorList::iterator tmp;
3194 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3196 /* have to do this early because otherwise processor reconfig
3197 * will put _monitor_send back in the list
3200 if (route == _session.monitor_out()) {
3201 _monitor_send.reset ();
3205 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3207 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3209 if (d && d->target_route() == route) {
3211 if (remove_processor (*x, &err, false) > 0) {
3217 /* list could have been demolished while we dropped the lock
3220 if (_session.engine().connected()) {
3221 /* i/o processors cannot be removed if the engine is not running
3222 * so don't live-loop in case the engine is N/A or dies
3232 Route::set_comment (string cmt, void *src)
3235 comment_changed (src);
3236 _session.set_dirty ();
3240 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3242 FeedRecord fr (other, via_sends_only);
3244 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3246 if (!result.second) {
3248 /* already a record for "other" - make sure sends-only information is correct */
3249 if (!via_sends_only && result.first->sends_only) {
3250 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3251 frp->sends_only = false;
3255 return result.second;
3259 Route::clear_fed_by ()
3265 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3267 const FedBy& fed_by (other->fed_by());
3269 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3270 boost::shared_ptr<Route> sr = f->r.lock();
3272 if (sr && (sr.get() == this)) {
3274 if (via_sends_only) {
3275 *via_sends_only = f->sends_only;
3286 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3288 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3290 if (_output->connected_to (other->input())) {
3291 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3292 if (via_send_only) {
3293 *via_send_only = false;
3300 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3302 boost::shared_ptr<IOProcessor> iop;
3304 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3305 if (iop->feeds (other)) {
3306 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3307 if (via_send_only) {
3308 *via_send_only = true;
3312 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3315 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3320 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3325 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3327 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3330 /** Called from the (non-realtime) butler thread when the transport is stopped */
3332 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3334 framepos_t now = _session.transport_frame();
3337 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3339 Automatable::transport_stopped (now);
3341 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3343 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3347 (*i)->transport_stopped (now);
3351 _roll_delay = _initial_delay;
3355 Route::input_change_handler (IOChange change, void * /*src*/)
3357 if ((change.type & IOChange::ConfigurationChanged)) {
3358 /* This is called with the process lock held if change
3359 contains ConfigurationChanged
3361 configure_processors (0);
3362 _phase_invert.resize (_input->n_ports().n_audio ());
3363 io_changed (); /* EMIT SIGNAL */
3366 if (_soloed_by_others_upstream || _solo_isolated_by_upstream) {
3369 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3370 if (_input->connected()) {
3371 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3372 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3376 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3377 if (does_feed && !sends_only) {
3378 if ((*i)->soloed()) {
3381 if ((*i)->solo_isolated()) {
3388 int delta = sbou - _soloed_by_others_upstream;
3389 int idelta = ibou - _solo_isolated_by_upstream;
3392 PBD::warning << string_compose (
3393 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3394 _name, ibou, _solo_isolated_by_upstream, idelta)
3399 if (_soloed_by_others_upstream) {
3400 // ignore new connections (they're not propagated)
3402 mod_solo_by_others_upstream (delta);
3406 if (_solo_isolated_by_upstream) {
3407 // solo-isolate currently only propagates downstream
3409 mod_solo_isolated_by_upstream (false, this);
3411 // TODO think: mod_solo_isolated_by_upstream() does not take delta arg,
3412 // but idelta can't be smaller than -1, can it?
3413 //_solo_isolated_by_upstream = ibou;
3416 // Session::route_solo_changed does not propagate indirect solo-changes
3417 // propagate downstream to tracks
3418 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3419 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3423 bool does_feed = feeds (*i, &sends_only);
3424 if (delta <= 0 && does_feed && !sends_only) {
3425 (*i)->mod_solo_by_others_upstream (delta);
3428 if (idelta < 0 && does_feed && !sends_only) {
3429 (*i)->mod_solo_isolated_by_upstream (false, this);
3436 Route::output_change_handler (IOChange change, void * /*src*/)
3438 if (_initial_io_setup) {
3442 if ((change.type & IOChange::ConfigurationChanged)) {
3443 /* This is called with the process lock held if change
3444 contains ConfigurationChanged
3446 configure_processors (0);
3449 _session.reset_monitor_section();
3452 io_changed (); /* EMIT SIGNAL */
3455 if (_soloed_by_others_downstream) {
3457 /* checking all all downstream routes for
3458 * explicit of implict solo is a rather drastic measure,
3459 * ideally the input_change_handler() of the other route
3460 * would propagate the change to us.
3462 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3463 if (_output->connected()) {
3464 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3465 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3469 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3470 if (does_feed && !sends_only) {
3471 if ((*i)->soloed()) {
3478 int delta = sbod - _soloed_by_others_downstream;
3480 // do not allow new connections to change implicit solo (no propagation)
3481 mod_solo_by_others_downstream (delta);
3482 // Session::route_solo_changed() does not propagate indirect solo-changes
3483 // propagate upstream to tracks
3484 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3485 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3489 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3490 if (delta != 0 && does_feed && !sends_only) {
3491 (*i)->mod_solo_by_others_downstream (delta);
3500 Route::pans_required () const
3502 if (n_outputs().n_audio() < 2) {
3506 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3510 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3512 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3518 if (n_outputs().n_total() == 0) {
3522 if (!_active || n_inputs() == ChanCount::ZERO) {
3523 silence_unlocked (nframes);
3527 if (session_state_changing) {
3528 if (_session.transport_speed() != 0.0f) {
3529 /* we're rolling but some state is changing (e.g. our diskstream contents)
3530 so we cannot use them. Be silent till this is over.
3532 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3534 silence_unlocked (nframes);
3537 /* we're really not rolling, so we're either delivery silence or actually
3538 monitoring, both of which are safe to do while session_state_changing is true.
3542 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3544 fill_buffers_with_input (bufs, _input, nframes);
3546 if (_meter_point == MeterInput) {
3547 _meter->run (bufs, start_frame, end_frame, nframes, true);
3550 _amp->apply_gain_automation (false);
3551 _trim->apply_gain_automation (false);
3552 passthru (bufs, start_frame, end_frame, nframes, 0);
3558 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3560 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3565 if (n_outputs().n_total() == 0) {
3569 if (!_active || n_inputs().n_total() == 0) {
3570 silence_unlocked (nframes);
3574 framepos_t unused = 0;
3576 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3582 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3584 fill_buffers_with_input (bufs, _input, nframes);
3586 if (_meter_point == MeterInput) {
3587 _meter->run (bufs, start_frame, end_frame, nframes, true);
3590 passthru (bufs, start_frame, end_frame, nframes, declick);
3596 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3603 Route::flush_processors ()
3605 /* XXX shouldn't really try to take this lock, since
3606 this is called from the RT audio thread.
3609 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3611 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3617 __attribute__((annotate("realtime")))
3620 Route::apply_processor_changes_rt ()
3622 int emissions = EmitNone;
3624 if (_pending_meter_point != _meter_point) {
3625 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3627 /* meters always have buffers for 'processor_max_streams'
3628 * they can be re-positioned without re-allocation */
3629 if (set_meter_point_unlocked()) {
3630 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3632 emissions |= EmitMeterChanged;
3637 bool changed = false;
3639 if (g_atomic_int_get (&_pending_process_reorder)) {
3640 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3642 apply_processor_order (_pending_processor_order);
3643 setup_invisible_processors ();
3645 g_atomic_int_set (&_pending_process_reorder, 0);
3646 emissions |= EmitRtProcessorChange;
3650 set_processor_positions ();
3652 if (emissions != 0) {
3653 g_atomic_int_set (&_pending_signals, emissions);
3660 Route::emit_pending_signals ()
3663 int sig = g_atomic_int_and (&_pending_signals, 0);
3664 if (sig & EmitMeterChanged) {
3665 _meter->emit_configuration_changed();
3666 meter_change (); /* EMIT SIGNAL */
3667 if (sig & EmitMeterVisibilityChange) {
3668 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3670 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3673 if (sig & EmitRtProcessorChange) {
3674 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3679 Route::set_meter_point (MeterPoint p, bool force)
3681 if (_pending_meter_point == p && !force) {
3685 if (force || !AudioEngine::instance()->running()) {
3686 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3687 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3688 _pending_meter_point = p;
3689 _meter->emit_configuration_changed();
3690 meter_change (); /* EMIT SIGNAL */
3691 if (set_meter_point_unlocked()) {
3692 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3694 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3697 _pending_meter_point = p;
3703 __attribute__((annotate("realtime")))
3706 Route::set_meter_point_unlocked ()
3709 /* Caller must hold process and processor write lock */
3710 assert (!AudioEngine::instance()->process_lock().trylock());
3711 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3712 assert (!lm.locked ());
3715 _meter_point = _pending_meter_point;
3717 bool meter_was_visible_to_user = _meter->display_to_user ();
3719 if (!_custom_meter_position_noted) {
3720 maybe_note_meter_position ();
3723 if (_meter_point != MeterCustom) {
3725 _meter->set_display_to_user (false);
3727 setup_invisible_processors ();
3730 _meter->set_display_to_user (true);
3732 /* If we have a previous position for the custom meter, try to put it there */
3733 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3735 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3736 if (i != _processors.end ()) {
3737 _processors.remove (_meter);
3738 _processors.insert (i, _meter);
3740 } else {// at end, right before the mains_out/panner
3741 _processors.remove (_meter);
3742 ProcessorList::iterator main = _processors.end();
3743 _processors.insert (--main, _meter);
3747 /* Set up the meter for its new position */
3749 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3753 if (loc == _processors.begin()) {
3754 m_in = _input->n_ports();
3756 ProcessorList::iterator before = loc;
3758 m_in = (*before)->output_streams ();
3761 _meter->reflect_inputs (m_in);
3763 /* we do not need to reconfigure the processors, because the meter
3764 (a) is always ready to handle processor_max_streams
3765 (b) is always an N-in/N-out processor, and thus moving
3766 it doesn't require any changes to the other processors.
3769 /* these should really be done after releasing the lock
3770 * but all those signals are subscribed to with gui_thread()
3773 return (_meter->display_to_user() != meter_was_visible_to_user);
3777 Route::listen_position_changed ()
3780 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3781 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3782 ProcessorState pstate (this);
3784 if (configure_processors_unlocked (0)) {
3785 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3787 configure_processors_unlocked (0); // it worked before we tried to add it ...
3792 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3793 _session.set_dirty ();
3796 boost::shared_ptr<CapturingProcessor>
3797 Route::add_export_point()
3799 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3800 if (!_capturing_processor) {
3802 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3803 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3805 _capturing_processor.reset (new CapturingProcessor (_session));
3806 _capturing_processor->activate ();
3808 configure_processors_unlocked (0);
3812 return _capturing_processor;
3816 Route::update_signal_latency ()
3818 framecnt_t l = _output->user_latency();
3819 framecnt_t lamp = 0;
3820 bool before_amp = true;
3821 framecnt_t ltrim = 0;
3822 bool before_trim = true;
3824 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3825 if ((*i)->active ()) {
3826 l += (*i)->signal_latency ();
3831 if ((*i) == _trim) {
3842 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3844 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3845 _signal_latency_at_amp_position = lamp;
3846 _signal_latency_at_trim_position = ltrim;
3848 if (_signal_latency != l) {
3849 _signal_latency = l;
3850 signal_latency_changed (); /* EMIT SIGNAL */
3853 return _signal_latency;
3857 Route::set_user_latency (framecnt_t nframes)
3859 _output->set_user_latency (nframes);
3860 _session.update_latency_compensation ();
3864 Route::set_latency_compensation (framecnt_t longest_session_latency)
3866 framecnt_t old = _initial_delay;
3868 if (_signal_latency < longest_session_latency) {
3869 _initial_delay = longest_session_latency - _signal_latency;
3874 DEBUG_TRACE (DEBUG::Latency, string_compose (
3875 "%1: compensate for maximum latency of %2,"
3876 "given own latency of %3, using initial delay of %4\n",
3877 name(), longest_session_latency, _signal_latency, _initial_delay));
3879 if (_initial_delay != old) {
3880 initial_delay_changed (); /* EMIT SIGNAL */
3883 if (_session.transport_stopped()) {
3884 _roll_delay = _initial_delay;
3888 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3889 : AutomationControl (r->session(),
3890 Evoral::Parameter (SoloAutomation),
3891 ParameterDescriptor(Evoral::Parameter (SoloAutomation)),
3892 boost::shared_ptr<AutomationList>(), name)
3895 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3896 gl->set_interpolation(Evoral::ControlList::Discrete);
3901 Route::SoloControllable::set_value (double val)
3904 set_value_unchecked (val);
3909 Route::SoloControllable::set_value_unchecked (double val)
3911 const bool bval = ((val >= 0.5) ? true : false);
3913 boost::shared_ptr<RouteList> rl (new RouteList);
3915 boost::shared_ptr<Route> r = _route.lock ();
3922 if (Config->get_solo_control_is_listen_control()) {
3923 _session.set_listen (rl, bval);
3925 _session.set_solo (rl, bval);
3930 Route::SoloControllable::get_value () const
3932 boost::shared_ptr<Route> r = _route.lock ();
3937 if (Config->get_solo_control_is_listen_control()) {
3938 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3940 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3944 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3945 : AutomationControl (r->session(),
3946 Evoral::Parameter (MuteAutomation),
3947 ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
3948 boost::shared_ptr<AutomationList>(),
3952 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3953 gl->set_interpolation(Evoral::ControlList::Discrete);
3958 Route::MuteControllable::set_superficial_value(bool muted)
3960 /* Note we can not use AutomationControl::set_value here since it will emit
3961 Changed(), but the value will not be correct to the observer. */
3963 const bool to_list = _list && ((AutomationList*)_list.get ())->automation_write ();
3964 const double where = _session.audible_frame ();
3966 /* Note that we really need this:
3967 * if (as == Touch && _list->in_new_write_pass ()) {
3968 * alist->start_write_pass (_session.audible_frame ());
3970 * here in the case of the user calling from a GUI or whatever.
3971 * Without the ability to distinguish between user and
3972 * automation-initiated changes, we lose the "touch mute"
3973 * behaviour we have in AutomationController::toggled ().
3975 _list->set_in_write_pass (true, false, where);
3978 Control::set_double (muted, where, to_list);
3982 Route::MuteControllable::set_value (double val)
3985 set_value_unchecked (val);
3990 Route::MuteControllable::set_value_unchecked (double val)
3992 const bool bval = ((val >= 0.5) ? true : false);
3994 boost::shared_ptr<Route> r = _route.lock ();
3999 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
4000 // Set superficial/automation value to drive controller (and possibly record)
4001 set_superficial_value (bval);
4002 // Playing back automation, set route mute directly
4003 r->set_mute (bval, this);
4005 // Set from user, queue mute event
4006 boost::shared_ptr<RouteList> rl (new RouteList);
4008 _session.set_mute (rl, bval, Session::rt_cleanup);
4013 Route::MuteControllable::get_value () const
4015 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
4016 // Playing back automation, get the value from the list
4017 return AutomationControl::get_value();
4020 // Not playing back automation, get the actual route mute value
4021 boost::shared_ptr<Route> r = _route.lock ();
4022 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
4025 Route::GroupGainControllable::GroupGainControllable (std::string name, boost::shared_ptr<Route> r)
4026 : AutomationControl (r->session(),
4027 Evoral::Parameter (GainAutomation),
4028 ParameterDescriptor (Evoral::Parameter (GainAutomation)),
4029 boost::shared_ptr<AutomationList>(),
4033 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(GainAutomation)));
4034 gl->set_interpolation(Evoral::ControlList::Discrete);
4039 Route::GroupGainControllable::set_value (double val)
4041 boost::shared_ptr<Route> r = _route.lock ();
4042 // I am not sure why I need the * .5 to make this work
4043 float normalized_position = r->gain_control()->interface_to_internal (val * 0.5);
4044 r->set_gain ((gain_t)normalized_position, this);
4048 Route::GroupGainControllable::get_value () const
4050 boost::shared_ptr<Route> r = _route.lock ();
4051 return 2.0 * r->gain_control()->internal_to_interface (r->gain_control()->get_value ());
4054 Route::PhaseControllable::PhaseControllable (std::string name, boost::shared_ptr<Route> r)
4055 : AutomationControl (r->session(),
4056 Evoral::Parameter (PhaseAutomation),
4057 ParameterDescriptor (Evoral::Parameter (PhaseAutomation)),
4058 boost::shared_ptr<AutomationList>(),
4062 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(PhaseAutomation)));
4063 gl->set_interpolation(Evoral::ControlList::Discrete);
4068 Route::PhaseControllable::set_value (double v)
4070 boost::shared_ptr<Route> r = _route.lock ();
4071 if (r->phase_invert().size()) {
4072 if (v == 0 || (v < 1 && v > 0.9) ) {
4073 r->set_phase_invert (_current_phase, false);
4075 r->set_phase_invert (_current_phase, true);
4081 Route::PhaseControllable::get_value () const
4083 boost::shared_ptr<Route> r = _route.lock ();
4084 return (double) r->phase_invert (_current_phase);
4088 Route::PhaseControllable::set_channel (uint32_t c)
4094 Route::PhaseControllable::channel () const
4096 return _current_phase;
4100 Route::set_block_size (pframes_t nframes)
4102 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4103 (*i)->set_block_size (nframes);
4106 _session.ensure_buffers (n_process_buffers ());
4110 Route::protect_automation ()
4112 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4113 (*i)->protect_automation();
4116 /** @param declick 1 to set a pending declick fade-in,
4117 * -1 to set a pending declick fade-out
4120 Route::set_pending_declick (int declick)
4123 /* this call is not allowed to turn off a pending declick */
4125 _pending_declick = declick;
4128 _pending_declick = 0;
4132 /** Shift automation forwards from a particular place, thereby inserting time.
4133 * Adds undo commands for any shifts that are performed.
4135 * @param pos Position to start shifting from.
4136 * @param frames Amount to shift forwards by.
4140 Route::shift (framepos_t pos, framecnt_t frames)
4142 /* gain automation */
4144 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4146 XMLNode &before = gc->alist()->get_state ();
4147 gc->alist()->shift (pos, frames);
4148 XMLNode &after = gc->alist()->get_state ();
4149 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4152 /* gain automation */
4154 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4156 XMLNode &before = gc->alist()->get_state ();
4157 gc->alist()->shift (pos, frames);
4158 XMLNode &after = gc->alist()->get_state ();
4159 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4162 // TODO mute automation ??
4164 /* pan automation */
4166 ControlSet::Controls& c (_pannable->controls());
4168 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4169 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4171 boost::shared_ptr<AutomationList> al = pc->alist();
4172 XMLNode& before = al->get_state ();
4173 al->shift (pos, frames);
4174 XMLNode& after = al->get_state ();
4175 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4180 /* redirect automation */
4182 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4183 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4185 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4187 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4188 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4190 boost::shared_ptr<AutomationList> al = ac->alist();
4191 XMLNode &before = al->get_state ();
4192 al->shift (pos, frames);
4193 XMLNode &after = al->get_state ();
4194 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4202 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4204 boost::shared_ptr<Processor> processor (p.lock ());
4205 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4209 pi->set_state_dir (d);
4213 Route::save_as_template (const string& path, const string& name)
4215 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4216 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4218 XMLNode& node (state (false));
4222 IO::set_name_in_state (*node.children().front(), name);
4224 tree.set_root (&node);
4226 /* return zero on success, non-zero otherwise */
4227 return !tree.write (path.c_str());
4232 Route::set_name (const string& str)
4234 if (str == name()) {
4238 string name = Route::ensure_track_or_route_name (str, _session);
4239 SessionObject::set_name (name);
4241 bool ret = (_input->set_name(name) && _output->set_name(name));
4244 /* rename the main outs. Leave other IO processors
4245 * with whatever name they already have, because its
4246 * just fine as it is (it will not contain the route
4247 * name if its a port insert, port send or port return).
4251 if (_main_outs->set_name (name)) {
4252 /* XXX returning false here is stupid because
4253 we already changed the route name.
4263 /** Set the name of a route in an XML description.
4264 * @param node XML <Route> node to set the name in.
4265 * @param name New name.
4268 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4270 node.add_property (X_("name"), name);
4272 XMLNodeList children = node.children();
4273 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4275 if ((*i)->name() == X_("IO")) {
4277 IO::set_name_in_state (**i, name);
4279 } else if ((*i)->name() == X_("Processor")) {
4281 XMLProperty* role = (*i)->property (X_("role"));
4282 if (role && role->value() == X_("Main")) {
4283 (*i)->add_property (X_("name"), name);
4286 } else if ((*i)->name() == X_("Diskstream")) {
4288 if (rename_playlist) {
4289 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4291 (*i)->add_property (X_("name"), name);
4297 boost::shared_ptr<Send>
4298 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4300 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4302 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4303 boost::shared_ptr<InternalSend> send;
4305 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4306 if (send->target_route() == target) {
4312 return boost::shared_ptr<Send>();
4315 /** @param c Audio channel index.
4316 * @param yn true to invert phase, otherwise false.
4319 Route::set_phase_invert (uint32_t c, bool yn)
4321 if (_phase_invert[c] != yn) {
4322 _phase_invert[c] = yn;
4323 phase_invert_changed (); /* EMIT SIGNAL */
4324 _session.set_dirty ();
4329 Route::set_phase_invert (boost::dynamic_bitset<> p)
4331 if (_phase_invert != p) {
4333 phase_invert_changed (); /* EMIT SIGNAL */
4334 _session.set_dirty ();
4339 Route::phase_invert (uint32_t c) const
4341 return _phase_invert[c];
4344 boost::dynamic_bitset<>
4345 Route::phase_invert () const
4347 return _phase_invert;
4351 Route::set_denormal_protection (bool yn)
4353 if (_denormal_protection != yn) {
4354 _denormal_protection = yn;
4355 denormal_protection_changed (); /* EMIT SIGNAL */
4360 Route::denormal_protection () const
4362 return _denormal_protection;
4366 Route::set_active (bool yn, void* src)
4368 if (_session.transport_rolling()) {
4372 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4373 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4377 if (_active != yn) {
4379 _input->set_active (yn);
4380 _output->set_active (yn);
4381 active_changed (); // EMIT SIGNAL
4382 _session.set_dirty ();
4386 boost::shared_ptr<Pannable>
4387 Route::pannable() const
4392 boost::shared_ptr<Panner>
4393 Route::panner() const
4396 return _main_outs->panner_shell()->panner();
4399 boost::shared_ptr<PannerShell>
4400 Route::panner_shell() const
4402 return _main_outs->panner_shell();
4405 boost::shared_ptr<AutomationControl>
4406 Route::gain_control() const
4408 return _amp->gain_control();
4411 boost::shared_ptr<AutomationControl>
4412 Route::trim_control() const
4414 return _trim->gain_control();
4417 boost::shared_ptr<AutomationControl>
4418 Route::get_control (const Evoral::Parameter& param)
4420 /* either we own the control or .... */
4422 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4426 /* maybe one of our processors does or ... */
4428 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4429 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4430 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4438 /* nobody does so we'll make a new one */
4440 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4447 boost::shared_ptr<Processor>
4448 Route::nth_plugin (uint32_t n)
4450 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4451 ProcessorList::iterator i;
4453 for (i = _processors.begin(); i != _processors.end(); ++i) {
4454 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4461 return boost::shared_ptr<Processor> ();
4464 boost::shared_ptr<Processor>
4465 Route::nth_send (uint32_t n)
4467 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4468 ProcessorList::iterator i;
4470 for (i = _processors.begin(); i != _processors.end(); ++i) {
4471 if (boost::dynamic_pointer_cast<Send> (*i)) {
4478 return boost::shared_ptr<Processor> ();
4482 Route::has_io_processor_named (const string& name)
4484 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4485 ProcessorList::iterator i;
4487 for (i = _processors.begin(); i != _processors.end(); ++i) {
4488 if (boost::dynamic_pointer_cast<Send> (*i) ||
4489 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4490 if ((*i)->name() == name) {
4499 MuteMaster::MutePoint
4500 Route::mute_points () const
4502 return _mute_master->mute_points ();
4506 Route::set_processor_positions ()
4508 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4510 bool had_amp = false;
4511 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4512 (*i)->set_pre_fader (!had_amp);
4519 /** Called when there is a proposed change to the input port count */
4521 Route::input_port_count_changing (ChanCount to)
4523 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4525 /* The processors cannot be configured with the new input arrangement, so
4531 /* The change is ok */
4535 /** Called when there is a proposed change to the output port count */
4537 Route::output_port_count_changing (ChanCount to)
4539 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4540 if (processor_out_streams.get(*t) > to.get(*t)) {
4544 /* The change is ok */
4549 Route::unknown_processors () const
4553 if (_session.get_disable_all_loaded_plugins ()) {
4554 // Do not list "missing plugins" if they are explicitly disabled
4558 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4559 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4560 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4561 p.push_back ((*i)->name ());
4570 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4572 /* we assume that all our input ports feed all our output ports. its not
4573 universally true, but the alternative is way too corner-case to worry about.
4576 LatencyRange all_connections;
4579 all_connections.min = 0;
4580 all_connections.max = 0;
4582 all_connections.min = ~((pframes_t) 0);
4583 all_connections.max = 0;
4585 /* iterate over all "from" ports and determine the latency range for all of their
4586 connections to the "outside" (outside of this Route).
4589 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4593 p->get_connected_latency_range (range, playback);
4595 all_connections.min = min (all_connections.min, range.min);
4596 all_connections.max = max (all_connections.max, range.max);
4600 /* set the "from" port latencies to the max/min range of all their connections */
4602 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4603 p->set_private_latency_range (all_connections, playback);
4606 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4608 all_connections.min += our_latency;
4609 all_connections.max += our_latency;
4611 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4612 p->set_private_latency_range (all_connections, playback);
4615 return all_connections.max;
4619 Route::set_private_port_latencies (bool playback) const
4621 framecnt_t own_latency = 0;
4623 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4624 OR LATENCY CALLBACK.
4626 This is called (early) from the latency callback. It computes the REAL
4627 latency associated with each port and stores the result as the "private"
4628 latency of the port. A later call to Route::set_public_port_latencies()
4629 sets all ports to the same value to reflect the fact that we do latency
4630 compensation and so all signals are delayed by the same amount as they
4631 flow through ardour.
4634 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4635 if ((*i)->active ()) {
4636 own_latency += (*i)->signal_latency ();
4641 /* playback: propagate latency from "outside the route" to outputs to inputs */
4642 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4644 /* capture: propagate latency from "outside the route" to inputs to outputs */
4645 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4650 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4652 /* this is called to set the JACK-visible port latencies, which take
4653 latency compensation into account.
4662 const PortSet& ports (_input->ports());
4663 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4664 p->set_public_latency_range (range, playback);
4669 const PortSet& ports (_output->ports());
4670 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4671 p->set_public_latency_range (range, playback);
4676 /** Put the invisible processors in the right place in _processors.
4677 * Must be called with a writer lock on _processor_lock held.
4680 __attribute__((annotate("realtime")))
4683 Route::setup_invisible_processors ()
4686 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4687 assert (!lm.locked ());
4691 /* too early to be doing this stuff */
4695 /* we'll build this new list here and then use it
4697 * TODO put the ProcessorList is on the stack for RT-safety.
4700 ProcessorList new_processors;
4702 /* find visible processors */
4704 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4705 if ((*i)->display_to_user ()) {
4706 new_processors.push_back (*i);
4712 ProcessorList::iterator amp = new_processors.begin ();
4713 while (amp != new_processors.end() && *amp != _amp) {
4717 assert (amp != new_processors.end ());
4719 /* and the processor after the amp */
4721 ProcessorList::iterator after_amp = amp;
4727 switch (_meter_point) {
4729 assert (!_meter->display_to_user ());
4730 new_processors.push_front (_meter);
4733 assert (!_meter->display_to_user ());
4734 new_processors.insert (amp, _meter);
4736 case MeterPostFader:
4737 /* do nothing here */
4740 /* do nothing here */
4743 /* the meter is visible, so we don't touch it here */
4750 assert (_main_outs);
4751 assert (!_main_outs->display_to_user ());
4752 new_processors.push_back (_main_outs);
4754 /* iterator for the main outs */
4756 ProcessorList::iterator main = new_processors.end();
4759 /* OUTPUT METERING */
4761 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4762 assert (!_meter->display_to_user ());
4764 /* add the processor just before or just after the main outs */
4766 ProcessorList::iterator meter_point = main;
4768 if (_meter_point == MeterOutput) {
4771 new_processors.insert (meter_point, _meter);
4776 if (_monitor_send && !is_monitor ()) {
4777 assert (!_monitor_send->display_to_user ());
4778 switch (Config->get_listen_position ()) {
4779 case PreFaderListen:
4780 switch (Config->get_pfl_position ()) {
4781 case PFLFromBeforeProcessors:
4782 new_processors.push_front (_monitor_send);
4784 case PFLFromAfterProcessors:
4785 new_processors.insert (amp, _monitor_send);
4788 _monitor_send->set_can_pan (false);
4790 case AfterFaderListen:
4791 switch (Config->get_afl_position ()) {
4792 case AFLFromBeforeProcessors:
4793 new_processors.insert (after_amp, _monitor_send);
4795 case AFLFromAfterProcessors:
4796 new_processors.insert (new_processors.end(), _monitor_send);
4799 _monitor_send->set_can_pan (true);
4804 #if 0 // not used - just yet
4805 if (!is_master() && !is_monitor() && !is_auditioner()) {
4806 new_processors.push_front (_delayline);
4810 /* MONITOR CONTROL */
4812 if (_monitor_control && is_monitor ()) {
4813 assert (!_monitor_control->display_to_user ());
4814 new_processors.insert (amp, _monitor_control);
4817 /* INTERNAL RETURN */
4819 /* doing this here means that any monitor control will come just after
4824 assert (!_intreturn->display_to_user ());
4825 new_processors.push_front (_intreturn);
4828 if (_trim && _trim->active()) {
4829 assert (!_trim->display_to_user ());
4830 new_processors.push_front (_trim);
4832 /* EXPORT PROCESSOR */
4834 if (_capturing_processor) {
4835 assert (!_capturing_processor->display_to_user ());
4836 new_processors.push_front (_capturing_processor);
4839 _processors = new_processors;
4841 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4842 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4847 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4848 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4849 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4856 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4857 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4861 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4862 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4869 /** If the meter point is `Custom', make a note of where the meter is.
4870 * This is so that if the meter point is subsequently set to something else,
4871 * and then back to custom, we can put the meter back where it was last time
4872 * custom was enabled.
4874 * Must be called with the _processor_lock held.
4877 Route::maybe_note_meter_position ()
4879 if (_meter_point != MeterCustom) {
4883 _custom_meter_position_noted = true;
4884 /* custom meter points range from after trim to before panner/main_outs
4885 * this is a limitation by the current processor UI
4887 bool seen_trim = false;
4888 _processor_after_last_custom_meter.reset();
4889 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4890 if ((*i) == _trim) {
4893 if ((*i) == _main_outs) {
4894 _processor_after_last_custom_meter = *i;
4897 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4899 _processor_after_last_custom_meter = _trim;
4901 ProcessorList::iterator j = i;
4903 assert(j != _processors.end ()); // main_outs should be before
4904 _processor_after_last_custom_meter = *j;
4909 assert(_processor_after_last_custom_meter.lock());
4912 boost::shared_ptr<Processor>
4913 Route::processor_by_id (PBD::ID id) const
4915 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4916 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4917 if ((*i)->id() == id) {
4922 return boost::shared_ptr<Processor> ();
4925 /** @return the monitoring state, or in other words what data we are pushing
4926 * into the route (data from the inputs, data from disk or silence)
4929 Route::monitoring_state () const
4931 return MonitoringInput;
4934 /** @return what we should be metering; either the data coming from the input
4935 * IO or the data that is flowing through the route.
4938 Route::metering_state () const
4940 return MeteringRoute;
4944 Route::has_external_redirects () const
4946 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4948 /* ignore inactive processors and obviously ignore the main
4949 * outs since everything has them and we don't care.
4952 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4960 boost::shared_ptr<Processor>
4961 Route::the_instrument () const
4963 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4964 return the_instrument_unlocked ();
4967 boost::shared_ptr<Processor>
4968 Route::the_instrument_unlocked () const
4970 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4971 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4972 if ((*i)->input_streams().n_midi() > 0 &&
4973 (*i)->output_streams().n_audio() > 0) {
4978 return boost::shared_ptr<Processor>();
4984 Route::non_realtime_locate (framepos_t pos)
4987 _pannable->transport_located (pos);
4990 if (_delayline.get()) {
4991 _delayline.get()->flush();
4995 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4996 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4998 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4999 (*i)->transport_located (pos);
5002 _roll_delay = _initial_delay;
5006 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5013 * We don't currently mix MIDI input together, so we don't need the
5014 * complex logic of the audio case.
5017 n_buffers = bufs.count().n_midi ();
5019 for (i = 0; i < n_buffers; ++i) {
5021 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5022 MidiBuffer& buf (bufs.get_midi (i));
5025 buf.copy (source_port->get_midi_buffer(nframes));
5027 buf.silence (nframes);
5033 n_buffers = bufs.count().n_audio();
5035 size_t n_ports = io->n_ports().n_audio();
5036 float scaling = 1.0f;
5038 if (n_ports > n_buffers) {
5039 scaling = ((float) n_buffers) / n_ports;
5042 for (i = 0; i < n_ports; ++i) {
5044 /* if there are more ports than buffers, map them onto buffers
5045 * in a round-robin fashion
5048 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5049 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5052 if (i < n_buffers) {
5054 /* first time through just copy a channel into
5058 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5060 if (scaling != 1.0f) {
5061 buf.apply_gain (scaling, nframes);
5066 /* on subsequent times around, merge data from
5067 * the port with what is already there
5070 if (scaling != 1.0f) {
5071 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5073 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5078 /* silence any remaining buffers */
5080 for (; i < n_buffers; ++i) {
5081 AudioBuffer& buf (bufs.get_audio (i));
5082 buf.silence (nframes);
5085 /* establish the initial setup of the buffer set, reflecting what was
5086 copied into it. unless, of course, we are the auditioner, in which
5087 case nothing was fed into it from the inputs at all.
5090 if (!is_auditioner()) {
5091 bufs.set_count (io->n_ports());
5095 boost::shared_ptr<AutomationControl>
5096 Route::pan_azimuth_control() const
5099 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5101 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5102 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5104 if (!_pannable || !panner()) {
5105 return boost::shared_ptr<AutomationControl>();
5107 return _pannable->pan_azimuth_control;
5111 boost::shared_ptr<AutomationControl>
5112 Route::pan_elevation_control() const
5114 if (Profile->get_mixbus() || !_pannable || !panner()) {
5115 return boost::shared_ptr<AutomationControl>();
5118 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5120 if (c.find (PanElevationAutomation) != c.end()) {
5121 return _pannable->pan_elevation_control;
5123 return boost::shared_ptr<AutomationControl>();
5126 boost::shared_ptr<AutomationControl>
5127 Route::pan_width_control() const
5129 if (Profile->get_mixbus() || !_pannable || !panner()) {
5130 return boost::shared_ptr<AutomationControl>();
5133 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5135 if (c.find (PanWidthAutomation) != c.end()) {
5136 return _pannable->pan_width_control;
5138 return boost::shared_ptr<AutomationControl>();
5141 boost::shared_ptr<AutomationControl>
5142 Route::pan_frontback_control() const
5144 if (Profile->get_mixbus() || !_pannable || !panner()) {
5145 return boost::shared_ptr<AutomationControl>();
5148 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5150 if (c.find (PanFrontBackAutomation) != c.end()) {
5151 return _pannable->pan_frontback_control;
5153 return boost::shared_ptr<AutomationControl>();
5156 boost::shared_ptr<AutomationControl>
5157 Route::pan_lfe_control() const
5159 if (Profile->get_mixbus() || !_pannable || !panner()) {
5160 return boost::shared_ptr<AutomationControl>();
5163 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5165 if (c.find (PanLFEAutomation) != c.end()) {
5166 return _pannable->pan_lfe_control;
5168 return boost::shared_ptr<AutomationControl>();
5173 Route::eq_band_cnt () const
5175 if (Profile->get_mixbus()) {
5178 /* Ardour has no well-known EQ object */
5183 boost::shared_ptr<AutomationControl>
5184 Route::eq_gain_controllable (uint32_t band) const
5187 boost::shared_ptr<PluginInsert> eq = ch_eq();
5190 return boost::shared_ptr<AutomationControl>();
5193 uint32_t port_number;
5196 if (is_master() || mixbus()) {
5203 if (is_master() || mixbus()) {
5210 if (is_master() || mixbus()) {
5217 return boost::shared_ptr<AutomationControl>();
5220 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5222 return boost::shared_ptr<AutomationControl>();
5225 boost::shared_ptr<AutomationControl>
5226 Route::eq_freq_controllable (uint32_t band) const
5230 if (mixbus() || is_master()) {
5231 /* no frequency controls for mixbusses or master */
5232 return boost::shared_ptr<AutomationControl>();
5235 boost::shared_ptr<PluginInsert> eq = ch_eq();
5238 return boost::shared_ptr<AutomationControl>();
5241 uint32_t port_number;
5253 return boost::shared_ptr<AutomationControl>();
5256 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5258 return boost::shared_ptr<AutomationControl>();
5262 boost::shared_ptr<AutomationControl>
5263 Route::eq_q_controllable (uint32_t band) const
5265 return boost::shared_ptr<AutomationControl>();
5268 boost::shared_ptr<AutomationControl>
5269 Route::eq_shape_controllable (uint32_t band) const
5271 return boost::shared_ptr<AutomationControl>();
5274 boost::shared_ptr<AutomationControl>
5275 Route::eq_enable_controllable () const
5278 boost::shared_ptr<PluginInsert> eq = ch_eq();
5281 return boost::shared_ptr<AutomationControl>();
5284 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5286 return boost::shared_ptr<AutomationControl>();
5290 boost::shared_ptr<AutomationControl>
5291 Route::eq_hpf_controllable () const
5294 boost::shared_ptr<PluginInsert> eq = ch_eq();
5297 return boost::shared_ptr<AutomationControl>();
5300 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5302 return boost::shared_ptr<AutomationControl>();
5307 Route::eq_band_name (uint32_t band) const
5309 if (Profile->get_mixbus()) {
5325 boost::shared_ptr<AutomationControl>
5326 Route::comp_enable_controllable () const
5329 boost::shared_ptr<PluginInsert> comp = ch_comp();
5332 return boost::shared_ptr<AutomationControl>();
5335 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5337 return boost::shared_ptr<AutomationControl>();
5340 boost::shared_ptr<AutomationControl>
5341 Route::comp_threshold_controllable () const
5344 boost::shared_ptr<PluginInsert> comp = ch_comp();
5347 return boost::shared_ptr<AutomationControl>();
5350 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5353 return boost::shared_ptr<AutomationControl>();
5356 boost::shared_ptr<AutomationControl>
5357 Route::comp_speed_controllable () const
5360 boost::shared_ptr<PluginInsert> comp = ch_comp();
5363 return boost::shared_ptr<AutomationControl>();
5366 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5368 return boost::shared_ptr<AutomationControl>();
5371 boost::shared_ptr<AutomationControl>
5372 Route::comp_mode_controllable () const
5375 boost::shared_ptr<PluginInsert> comp = ch_comp();
5378 return boost::shared_ptr<AutomationControl>();
5381 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5383 return boost::shared_ptr<AutomationControl>();
5386 boost::shared_ptr<AutomationControl>
5387 Route::comp_makeup_controllable () const
5390 boost::shared_ptr<PluginInsert> comp = ch_comp();
5393 return boost::shared_ptr<AutomationControl>();
5396 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5398 return boost::shared_ptr<AutomationControl>();
5401 boost::shared_ptr<AutomationControl>
5402 Route::comp_redux_controllable () const
5405 boost::shared_ptr<PluginInsert> comp = ch_comp();
5408 return boost::shared_ptr<AutomationControl>();
5411 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5413 return boost::shared_ptr<AutomationControl>();
5418 Route::comp_mode_name (uint32_t mode) const
5423 return _("Leveler");
5425 return _("Compressor");
5427 return _("Limiter");
5437 Route::comp_speed_name (uint32_t mode) const