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"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_track.h"
41 #include "ardour/audio_port.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/buffer.h"
44 #include "ardour/buffer_set.h"
45 #include "ardour/capturing_processor.h"
46 #include "ardour/debug.h"
47 #include "ardour/delivery.h"
48 #include "ardour/internal_return.h"
49 #include "ardour/internal_send.h"
50 #include "ardour/meter.h"
51 #include "ardour/delayline.h"
52 #include "ardour/midi_buffer.h"
53 #include "ardour/midi_port.h"
54 #include "ardour/monitor_processor.h"
55 #include "ardour/pannable.h"
56 #include "ardour/panner.h"
57 #include "ardour/panner_shell.h"
58 #include "ardour/plugin_insert.h"
59 #include "ardour/port.h"
60 #include "ardour/port_insert.h"
61 #include "ardour/processor.h"
62 #include "ardour/route.h"
63 #include "ardour/route_group.h"
64 #include "ardour/send.h"
65 #include "ardour/session.h"
66 #include "ardour/unknown_processor.h"
67 #include "ardour/utils.h"
72 using namespace ARDOUR;
75 PBD::Signal0<void> Route::SyncOrderKeys;
76 PBD::Signal0<void> Route::RemoteControlIDChange;
78 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
79 : SessionObject (sess, name)
81 , GraphNode (sess._process_graph)
84 , _signal_latency_at_amp_position (0)
88 , _pending_declick (true)
89 , _meter_point (MeterPostFader)
90 , _meter_type (MeterPeak)
92 , _soloed_by_others_upstream (0)
93 , _soloed_by_others_downstream (0)
95 , _denormal_protection (false)
98 , _declickable (false)
99 , _mute_master (new MuteMaster (sess, name))
100 , _have_internal_generator (false)
102 , _default_type (default_type)
104 , _has_order_key (false)
105 , _remote_control_id (0)
107 , _in_configure_processors (false)
108 , _initial_io_setup (false)
109 , _custom_meter_position_noted (false)
110 , _last_custom_meter_was_at_end (false)
113 _meter_type = MeterK20;
115 processor_max_streams.reset();
121 /* add standard controls */
123 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
124 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
126 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
127 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
129 add_control (_solo_control);
130 add_control (_mute_control);
134 if (!(_flags & Route::MonitorOut)) {
135 _pannable.reset (new Pannable (_session));
138 /* input and output objects */
140 _input.reset (new IO (_session, _name, IO::Input, _default_type));
141 _output.reset (new IO (_session, _name, IO::Output, _default_type));
143 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
144 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
146 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
147 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
149 #if 0 // not used - just yet
150 if (!is_master() && !is_monitor() && !is_auditioner()) {
151 _delayline.reset (new DelayLine (_session, _name));
152 add_processor (_delayline, PreFader);
156 /* add amp processor */
158 _amp.reset (new Amp (_session));
159 add_processor (_amp, PostFader);
162 _trim.reset (new Amp (_session, "trim"));
163 _trim->set_display_to_user (false);
165 if (dynamic_cast<AudioTrack*>(this)) {
166 /* we can't do this in the AudioTrack's constructor
167 * because _trim does not exit then
171 else if (!dynamic_cast<Track*>(this) && ! (is_master() || is_monitor() || is_auditioner())) {
176 /* create standard processors: meter, main outs, monitor out;
177 they will be added to _processors by setup_invisible_processors ()
180 _meter.reset (new PeakMeter (_session, _name));
181 _meter->set_owner (this);
182 _meter->set_display_to_user (false);
185 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
186 _main_outs->activate ();
189 /* where we listen to tracks */
190 _intreturn.reset (new InternalReturn (_session));
191 _intreturn->activate ();
193 /* the thing that provides proper control over a control/monitor/listen bus
194 (such as per-channel cut, dim, solo, invert, etc).
196 _monitor_control.reset (new MonitorProcessor (_session));
197 _monitor_control->activate ();
200 if (is_master() || is_monitor() || is_auditioner()) {
201 _mute_master->set_solo_ignore (true);
204 /* now that we have _meter, its safe to connect to this */
206 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
209 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
210 configure_processors (0);
218 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
220 /* do this early so that we don't get incoming signals as we are going through destruction
225 /* don't use clear_processors here, as it depends on the session which may
226 be half-destroyed by now
229 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
230 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
231 (*i)->drop_references ();
234 _processors.clear ();
238 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
240 if (Config->get_remote_model() != UserOrdered) {
244 set_remote_control_id_internal (id, notify_class_listeners);
248 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
250 /* force IDs for master/monitor busses and prevent
251 any other route from accidentally getting these IDs
252 (i.e. legacy sessions)
255 if (is_master() && id != MasterBusRemoteControlID) {
256 id = MasterBusRemoteControlID;
259 if (is_monitor() && id != MonitorBusRemoteControlID) {
260 id = MonitorBusRemoteControlID;
267 /* don't allow it to collide */
269 if (!is_master () && !is_monitor() &&
270 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
271 id += MonitorBusRemoteControlID;
274 if (id != remote_control_id()) {
275 _remote_control_id = id;
276 RemoteControlIDChanged ();
278 if (notify_class_listeners) {
279 RemoteControlIDChange ();
285 Route::remote_control_id() const
288 return MasterBusRemoteControlID;
292 return MonitorBusRemoteControlID;
295 return _remote_control_id;
299 Route::has_order_key () const
301 return _has_order_key;
305 Route::order_key () const
311 Route::set_remote_control_id_explicit (uint32_t rid)
313 if (is_master() || is_monitor() || is_auditioner()) {
314 /* hard-coded remote IDs, or no remote ID */
318 if (_remote_control_id != rid) {
319 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
320 _remote_control_id = rid;
321 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
324 /* don't emit the class-level RID signal RemoteControlIDChange here,
325 leave that to the entity that changed the order key, so that we
326 don't get lots of emissions for no good reasons (e.g. when changing
327 all route order keys).
329 See Session::sync_remote_id_from_order_keys() for the (primary|only)
330 spot where that is emitted.
335 Route::set_order_key (uint32_t n)
337 _has_order_key = true;
339 if (_order_key == n) {
345 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
346 name(), order_key ()));
348 _session.set_dirty ();
352 Route::ensure_track_or_route_name(string name, Session &session)
354 string newname = name;
356 while (!session.io_name_is_legal (newname)) {
357 newname = bump_name_once (newname, '.');
365 Route::inc_gain (gain_t fraction, void *src)
367 _amp->inc_gain (fraction, src);
371 Route::set_gain (gain_t val, void *src)
373 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
375 if (_route_group->is_relative()) {
377 gain_t usable_gain = _amp->gain();
378 if (usable_gain < 0.000001f) {
379 usable_gain = 0.000001f;
383 if (delta < 0.000001f) {
387 delta -= usable_gain;
392 gain_t factor = delta / usable_gain;
395 factor = _route_group->get_max_factor(factor);
396 if (factor == 0.0f) {
397 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
401 factor = _route_group->get_min_factor(factor);
402 if (factor == 0.0f) {
403 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
408 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
412 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
418 if (val == _amp->gain()) {
422 _amp->set_gain (val, src);
426 Route::inc_trim (gain_t fraction, void *src)
428 _trim->inc_gain (fraction, src);
432 Route::set_trim (gain_t val, void * /* src */)
434 // TODO route group, see set_gain()
435 _trim->set_gain (val, 0);
439 Route::maybe_declick (BufferSet&, framecnt_t, int)
441 /* this is the "bus" implementation and they never declick.
446 /** Process this route for one (sub) cycle (process thread)
448 * @param bufs Scratch buffers to use for the signal path
449 * @param start_frame Initial transport frame
450 * @param end_frame Final transport frame
451 * @param nframes Number of frames to output (to ports)
453 * Note that (end_frame - start_frame) may not be equal to nframes when the
454 * transport speed isn't 1.0 (eg varispeed).
457 Route::process_output_buffers (BufferSet& bufs,
458 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
459 int declick, bool gain_automation_ok)
461 /* Caller must hold process lock */
462 assert (!AudioEngine::instance()->process_lock().trylock());
464 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
466 bufs.silence (nframes, 0);
470 /* figure out if we're going to use gain automation */
471 if (gain_automation_ok) {
472 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
473 _amp->setup_gain_automation (
474 start_frame + _signal_latency_at_amp_position,
475 end_frame + _signal_latency_at_amp_position,
478 _amp->apply_gain_automation (false);
481 /* Tell main outs what to do about monitoring. We do this so that
482 on a transition between monitoring states we get a de-clicking gain
483 change in the _main_outs delivery.
485 bool silence = monitoring_state () == MonitoringSilence;
487 //but we override this in the case where we have an internal generator
488 if ( _have_internal_generator )
491 _main_outs->no_outs_cuz_we_no_monitor (silence);
493 /* -------------------------------------------------------------------------------------------
494 GLOBAL DECLICK (for transport changes etc.)
495 ----------------------------------------------------------------------------------------- */
497 maybe_declick (bufs, nframes, declick);
498 _pending_declick = 0;
500 /* -------------------------------------------------------------------------------------------
501 DENORMAL CONTROL/PHASE INVERT
502 ----------------------------------------------------------------------------------------- */
504 if (_phase_invert.any ()) {
508 if (_denormal_protection || Config->get_denormal_protection()) {
510 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
511 Sample* const sp = i->data();
513 if (_phase_invert[chn]) {
514 for (pframes_t nx = 0; nx < nframes; ++nx) {
519 for (pframes_t nx = 0; nx < nframes; ++nx) {
527 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
528 Sample* const sp = i->data();
530 if (_phase_invert[chn]) {
531 for (pframes_t nx = 0; nx < nframes; ++nx) {
540 if (_denormal_protection || Config->get_denormal_protection()) {
542 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
543 Sample* const sp = i->data();
544 for (pframes_t nx = 0; nx < nframes; ++nx) {
552 /* -------------------------------------------------------------------------------------------
554 ----------------------------------------------------------------------------------------- */
556 /* set this to be true if the meter will already have been ::run() earlier */
557 bool const meter_already_run = metering_state() == MeteringInput;
559 framecnt_t latency = 0;
561 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
563 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
564 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
569 /* if it has any inputs, make sure they match */
570 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
571 if (bufs.count() != (*i)->input_streams()) {
573 DEBUG::Processors, string_compose (
574 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
575 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
582 /* should we NOT run plugins here if the route is inactive?
583 do we catch route != active somewhere higher?
586 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
587 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
590 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
591 bufs.set_count ((*i)->output_streams());
593 if ((*i)->active ()) {
594 latency += (*i)->signal_latency ();
600 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
601 boost::shared_ptr<Processor> endpoint,
602 bool include_endpoint, bool for_export, bool for_freeze)
604 /* If no processing is required, there's no need to go any further. */
605 if (!endpoint && !include_endpoint) {
609 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
610 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
611 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
614 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
616 if (!include_endpoint && (*i) == endpoint) {
620 /* if we're not exporting, stop processing if we come across a routing processor. */
621 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
624 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
628 /* don't run any processors that does routing.
629 * oh, and don't bother with the peak meter either.
631 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
632 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
633 buffers.set_count ((*i)->output_streams());
634 latency += (*i)->signal_latency ();
637 if ((*i) == endpoint) {
644 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
645 bool include_endpoint, bool for_export, bool for_freeze) const
647 framecnt_t latency = 0;
648 if (!endpoint && !include_endpoint) {
652 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
653 if (!include_endpoint && (*i) == endpoint) {
656 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
659 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
662 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
663 latency += (*i)->signal_latency ();
665 if ((*i) == endpoint) {
673 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
674 bool include_endpoint, bool for_export, bool for_freeze) const
676 if (!endpoint && !include_endpoint) {
680 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
681 if (!include_endpoint && (*i) == endpoint) {
684 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
687 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
690 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
691 cc = (*i)->output_streams();
693 if ((*i) == endpoint) {
701 Route::n_process_buffers ()
703 return max (_input->n_ports(), processor_max_streams);
707 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
709 assert (is_monitor());
710 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
711 fill_buffers_with_input (bufs, _input, nframes);
712 passthru (bufs, start_frame, end_frame, nframes, declick);
716 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
720 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
722 /* control/monitor bus ignores input ports when something is
723 feeding the listen "stream". data will "arrive" into the
724 route from the intreturn processor element.
727 bufs.silence (nframes, 0);
730 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
731 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
735 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
737 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
739 bufs.set_count (_input->n_ports());
740 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
741 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
745 Route::set_listen (bool yn, void* src)
751 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
752 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
757 if (yn != _monitor_send->active()) {
759 _monitor_send->activate ();
760 _mute_master->set_soloed (true);
762 _monitor_send->deactivate ();
763 _mute_master->set_soloed (false);
766 listen_changed (src); /* EMIT SIGNAL */
772 Route::listening_via_monitor () const
775 return _monitor_send->active ();
782 Route::set_solo_safe (bool yn, void *src)
784 if (_solo_safe != yn) {
786 solo_safe_changed (src);
791 Route::solo_safe() const
797 Route::set_solo (bool yn, void *src)
800 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
804 if (is_master() || is_monitor() || is_auditioner()) {
805 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
809 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
810 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
814 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
815 name(), yn, src, (src == _route_group), self_soloed()));
817 if (self_soloed() != yn) {
819 set_mute_master_solo ();
820 solo_changed (true, src); /* EMIT SIGNAL */
821 _solo_control->Changed (); /* EMIT SIGNAL */
826 Route::set_self_solo (bool yn)
828 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
833 Route::mod_solo_by_others_upstream (int32_t delta)
836 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-upstream due to solo-safe\n", name()));
840 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
841 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
843 uint32_t old_sbu = _soloed_by_others_upstream;
846 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
847 _soloed_by_others_upstream += delta;
849 _soloed_by_others_upstream = 0;
852 _soloed_by_others_upstream += delta;
855 DEBUG_TRACE (DEBUG::Solo, string_compose (
856 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
857 name(), delta, _soloed_by_others_upstream, old_sbu,
858 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
860 /* push the inverse solo change to everything that feeds us.
862 This is important for solo-within-group. When we solo 1 track out of N that
863 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
864 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
865 tracks that feed it. This will silence them if they were audible because
866 of a bus solo, but the newly soloed track will still be audible (because
869 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
873 if ((_self_solo || _soloed_by_others_downstream) &&
874 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
875 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
877 if (delta > 0 || !Config->get_exclusive_solo()) {
878 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
879 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
880 boost::shared_ptr<Route> sr = i->r.lock();
882 sr->mod_solo_by_others_downstream (-delta);
888 set_mute_master_solo ();
889 solo_changed (false, this);
893 Route::mod_solo_by_others_downstream (int32_t delta)
896 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-downstream due to solo safe\n", name()));
900 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
901 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
904 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
905 _soloed_by_others_downstream += delta;
907 _soloed_by_others_downstream = 0;
910 _soloed_by_others_downstream += delta;
913 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
915 set_mute_master_solo ();
916 solo_changed (false, this);
920 Route::set_mute_master_solo ()
922 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
926 Route::set_solo_isolated (bool yn, void *src)
928 if (is_master() || is_monitor() || is_auditioner()) {
932 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
933 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
937 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
939 boost::shared_ptr<RouteList> routes = _session.get_routes ();
940 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
942 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
947 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
949 if (does_feed && !sends_only) {
950 (*i)->set_solo_isolated (yn, (*i)->route_group());
954 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
956 bool changed = false;
959 if (_solo_isolated == 0) {
960 _mute_master->set_solo_ignore (true);
965 if (_solo_isolated > 0) {
967 if (_solo_isolated == 0) {
968 _mute_master->set_solo_ignore (false);
975 solo_isolated_changed (src);
980 Route::solo_isolated () const
982 return _solo_isolated > 0;
986 Route::set_mute_points (MuteMaster::MutePoint mp)
988 _mute_master->set_mute_points (mp);
989 mute_points_changed (); /* EMIT SIGNAL */
991 if (_mute_master->muted_by_self()) {
992 mute_changed (this); /* EMIT SIGNAL */
993 _mute_control->Changed (); /* EMIT SIGNAL */
998 Route::set_mute (bool yn, void *src)
1000 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
1001 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
1005 if (muted() != yn) {
1006 _mute_master->set_muted_by_self (yn);
1007 /* allow any derived classes to respond to the mute change
1008 before anybody else knows about it.
1011 /* tell everyone else */
1012 mute_changed (src); /* EMIT SIGNAL */
1013 _mute_control->Changed (); /* EMIT SIGNAL */
1018 Route::muted () const
1020 return _mute_master->muted_by_self();
1025 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1027 cerr << name << " {" << endl;
1028 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1029 p != procs.end(); ++p) {
1030 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1032 cerr << "}" << endl;
1036 /** Supposing that we want to insert a Processor at a given Placement, return
1037 * the processor to add the new one before (or 0 to add at the end).
1039 boost::shared_ptr<Processor>
1040 Route::before_processor_for_placement (Placement p)
1042 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1044 ProcessorList::iterator loc;
1046 if (p == PreFader) {
1047 /* generic pre-fader: insert immediately before the amp */
1048 loc = find (_processors.begin(), _processors.end(), _amp);
1050 /* generic post-fader: insert right before the main outs */
1051 loc = find (_processors.begin(), _processors.end(), _main_outs);
1054 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1057 /** Supposing that we want to insert a Processor at a given index, return
1058 * the processor to add the new one before (or 0 to add at the end).
1060 boost::shared_ptr<Processor>
1061 Route::before_processor_for_index (int index)
1064 return boost::shared_ptr<Processor> ();
1067 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1069 ProcessorList::iterator i = _processors.begin ();
1071 while (i != _processors.end() && j < index) {
1072 if ((*i)->display_to_user()) {
1079 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1082 /** Add a processor either pre- or post-fader
1083 * @return 0 on success, non-0 on failure.
1086 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1088 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1092 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1093 * @param index Index to add the processor at, or -1 to add at the end of the list.
1094 * @return 0 on success, non-0 on failure.
1097 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1099 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1102 /** Add a processor to the route.
1103 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1104 * @return 0 on success, non-0 on failure.
1107 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1109 assert (processor != _meter);
1110 assert (processor != _main_outs);
1112 DEBUG_TRACE (DEBUG::Processors, string_compose (
1113 "%1 adding processor %2\n", name(), processor->name()));
1115 if (!AudioEngine::instance()->connected() || !processor) {
1120 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1121 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1122 ProcessorState pstate (this);
1124 boost::shared_ptr<PluginInsert> pi;
1125 boost::shared_ptr<PortInsert> porti;
1127 if (processor == _amp) {
1128 /* Ensure that only one amp is in the list at any time */
1129 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1130 if (check != _processors.end()) {
1131 if (before == _amp) {
1132 /* Already in position; all is well */
1135 _processors.erase (check);
1140 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1142 ProcessorList::iterator loc;
1144 /* inserting before a processor; find it */
1145 loc = find (_processors.begin(), _processors.end(), before);
1146 if (loc == _processors.end ()) {
1151 /* inserting at end */
1152 loc = _processors.end ();
1155 _processors.insert (loc, processor);
1156 processor->set_owner (this);
1158 // Set up processor list channels. This will set processor->[input|output]_streams(),
1159 // configure redirect ports properly, etc.
1162 if (configure_processors_unlocked (err)) {
1164 configure_processors_unlocked (0); // it worked before we tried to add it ...
1169 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1171 if (pi->has_no_inputs ()) {
1172 /* generator plugin */
1173 _have_internal_generator = true;
1178 if (activation_allowed && !_session.get_disable_all_loaded_plugins()) {
1179 processor->activate ();
1182 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1184 _output->set_user_latency (0);
1187 reset_instrument_info ();
1188 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1189 set_processor_positions ();
1195 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1197 const XMLProperty *prop;
1200 boost::shared_ptr<Processor> processor;
1202 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1203 so that we can add the processor in the right place (pre/post-fader)
1206 XMLNodeList const & children = node.children ();
1207 XMLNodeList::const_iterator i = children.begin ();
1209 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1213 Placement placement = PreFader;
1215 if (i != children.end()) {
1216 if ((prop = (*i)->property (X_("placement"))) != 0) {
1217 placement = Placement (string_2_enum (prop->value(), placement));
1221 if (node.name() == "Insert") {
1223 if ((prop = node.property ("type")) != 0) {
1225 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1226 prop->value() == "lv2" ||
1227 prop->value() == "windows-vst" ||
1228 prop->value() == "lxvst" ||
1229 prop->value() == "audiounit") {
1231 processor.reset (new PluginInsert (_session));
1235 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1240 } else if (node.name() == "Send") {
1242 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1243 processor.reset (new Send (_session, sendpan, _mute_master));
1247 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1251 if (processor->set_state (node, version)) {
1255 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1256 if (i != children.end()) {
1257 if ((prop = (*i)->property (X_("active"))) != 0) {
1258 if ( string_is_affirmative (prop->value()) && !_session.get_disable_all_loaded_plugins() )
1259 processor->activate();
1261 processor->deactivate();
1265 return (add_processor (processor, placement, 0, false) == 0);
1268 catch (failed_constructor &err) {
1269 warning << _("processor could not be created. Ignored.") << endmsg;
1275 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1277 /* NOTE: this is intended to be used ONLY when copying
1278 processors from another Route. Hence the subtle
1279 differences between this and ::add_processor()
1282 ProcessorList::iterator loc;
1285 loc = find(_processors.begin(), _processors.end(), before);
1287 /* nothing specified - at end */
1288 loc = _processors.end ();
1291 if (!_session.engine().connected()) {
1295 if (others.empty()) {
1300 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1301 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1302 ProcessorState pstate (this);
1304 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1310 boost::shared_ptr<PluginInsert> pi;
1312 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1316 _processors.insert (loc, *i);
1317 (*i)->set_owner (this);
1319 if ((*i)->active()) {
1323 /* Think: does this really need to be called for every processor in the loop? */
1325 if (configure_processors_unlocked (err)) {
1327 configure_processors_unlocked (0); // it worked before we tried to add it ...
1332 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1335 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1336 boost::shared_ptr<PluginInsert> pi;
1338 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1339 if (pi->has_no_inputs ()) {
1340 _have_internal_generator = true;
1346 _output->set_user_latency (0);
1349 reset_instrument_info ();
1350 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1351 set_processor_positions ();
1357 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1359 if (p == PreFader) {
1360 start = _processors.begin();
1361 end = find(_processors.begin(), _processors.end(), _amp);
1363 start = find(_processors.begin(), _processors.end(), _amp);
1365 end = _processors.end();
1369 /** Turn off all processors with a given placement
1370 * @param p Placement of processors to disable
1373 Route::disable_processors (Placement p)
1375 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1377 ProcessorList::iterator start, end;
1378 placement_range(p, start, end);
1380 for (ProcessorList::iterator i = start; i != end; ++i) {
1381 (*i)->deactivate ();
1384 _session.set_dirty ();
1387 /** Turn off all redirects
1390 Route::disable_processors ()
1392 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1394 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1395 (*i)->deactivate ();
1398 _session.set_dirty ();
1401 /** Turn off all redirects with a given placement
1402 * @param p Placement of redirects to disable
1405 Route::disable_plugins (Placement p)
1407 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1409 ProcessorList::iterator start, end;
1410 placement_range(p, start, end);
1412 for (ProcessorList::iterator i = start; i != end; ++i) {
1413 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1414 (*i)->deactivate ();
1418 _session.set_dirty ();
1421 /** Turn off all plugins
1424 Route::disable_plugins ()
1426 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1428 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1429 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1430 (*i)->deactivate ();
1434 _session.set_dirty ();
1439 Route::ab_plugins (bool forward)
1441 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1445 /* forward = turn off all active redirects, and mark them so that the next time
1446 we go the other way, we will revert them
1449 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1450 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1454 if ((*i)->active()) {
1455 (*i)->deactivate ();
1456 (*i)->set_next_ab_is_active (true);
1458 (*i)->set_next_ab_is_active (false);
1464 /* backward = if the redirect was marked to go active on the next ab, do so */
1466 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1468 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1472 if ((*i)->get_next_ab_is_active()) {
1475 (*i)->deactivate ();
1480 _session.set_dirty ();
1484 /** Remove processors with a given placement.
1485 * @param p Placement of processors to remove.
1488 Route::clear_processors (Placement p)
1490 if (!_session.engine().connected()) {
1494 bool already_deleting = _session.deletion_in_progress();
1495 if (!already_deleting) {
1496 _session.set_deletion_in_progress();
1500 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1501 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1502 ProcessorList new_list;
1503 ProcessorStreams err;
1504 bool seen_amp = false;
1506 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1512 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline) {
1514 /* you can't remove these */
1516 new_list.push_back (*i);
1523 new_list.push_back (*i);
1526 (*i)->drop_references ();
1534 (*i)->drop_references ();
1537 new_list.push_back (*i);
1544 _processors = new_list;
1545 configure_processors_unlocked (&err); // this can't fail
1548 processor_max_streams.reset();
1549 _have_internal_generator = false;
1550 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1551 set_processor_positions ();
1553 reset_instrument_info ();
1555 if (!already_deleting) {
1556 _session.clear_deletion_in_progress();
1561 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1563 // TODO once the export point can be configured properly, do something smarter here
1564 if (processor == _capturing_processor) {
1565 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1566 if (need_process_lock) {
1570 _capturing_processor.reset();
1572 if (need_process_lock) {
1577 /* these can never be removed */
1579 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1583 if (!_session.engine().connected()) {
1587 processor_max_streams.reset();
1590 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1591 if (need_process_lock) {
1595 /* Caller must hold process lock */
1596 assert (!AudioEngine::instance()->process_lock().trylock());
1598 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1600 ProcessorState pstate (this);
1602 ProcessorList::iterator i;
1603 bool removed = false;
1605 for (i = _processors.begin(); i != _processors.end(); ) {
1606 if (*i == processor) {
1608 /* move along, see failure case for configure_processors()
1609 where we may need to reconfigure the processor.
1612 /* stop redirects that send signals to JACK ports
1613 from causing noise as a result of no longer being
1617 boost::shared_ptr<IOProcessor> iop;
1619 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1623 i = _processors.erase (i);
1631 _output->set_user_latency (0);
1639 if (configure_processors_unlocked (err)) {
1641 /* we know this will work, because it worked before :) */
1642 configure_processors_unlocked (0);
1646 _have_internal_generator = false;
1648 for (i = _processors.begin(); i != _processors.end(); ++i) {
1649 boost::shared_ptr<PluginInsert> pi;
1651 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1652 if (pi->has_no_inputs ()) {
1653 _have_internal_generator = true;
1658 if (need_process_lock) {
1663 reset_instrument_info ();
1664 processor->drop_references ();
1665 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1666 set_processor_positions ();
1672 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1674 ProcessorList deleted;
1676 if (!_session.engine().connected()) {
1680 processor_max_streams.reset();
1683 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1684 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1685 ProcessorState pstate (this);
1687 ProcessorList::iterator i;
1688 boost::shared_ptr<Processor> processor;
1690 for (i = _processors.begin(); i != _processors.end(); ) {
1694 /* these can never be removed */
1696 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1701 /* see if its in the list of processors to delete */
1703 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1708 /* stop IOProcessors that send to JACK ports
1709 from causing noise as a result of no longer being
1713 boost::shared_ptr<IOProcessor> iop;
1715 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1719 deleted.push_back (processor);
1720 i = _processors.erase (i);
1723 if (deleted.empty()) {
1724 /* none of those in the requested list were found */
1728 _output->set_user_latency (0);
1730 if (configure_processors_unlocked (err)) {
1732 /* we know this will work, because it worked before :) */
1733 configure_processors_unlocked (0);
1738 _have_internal_generator = false;
1740 for (i = _processors.begin(); i != _processors.end(); ++i) {
1741 boost::shared_ptr<PluginInsert> pi;
1743 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1744 if (pi->has_no_inputs ()) {
1745 _have_internal_generator = true;
1752 /* now try to do what we need to so that those that were removed will be deleted */
1754 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1755 (*i)->drop_references ();
1758 reset_instrument_info ();
1759 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1760 set_processor_positions ();
1766 Route::reset_instrument_info ()
1768 boost::shared_ptr<Processor> instr = the_instrument();
1770 _instrument_info.set_internal_instrument (instr);
1774 /** Caller must hold process lock */
1776 Route::configure_processors (ProcessorStreams* err)
1778 #ifndef PLATFORM_WINDOWS
1779 assert (!AudioEngine::instance()->process_lock().trylock());
1782 if (!_in_configure_processors) {
1783 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1784 return configure_processors_unlocked (err);
1791 Route::input_streams () const
1793 return _input->n_ports ();
1796 list<pair<ChanCount, ChanCount> >
1797 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1799 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1801 return try_configure_processors_unlocked (in, err);
1804 list<pair<ChanCount, ChanCount> >
1805 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1807 // Check each processor in order to see if we can configure as requested
1809 list<pair<ChanCount, ChanCount> > configuration;
1812 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1813 DEBUG_TRACE (DEBUG::Processors, "{\n");
1815 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1817 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1818 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1819 DEBUG_TRACE (DEBUG::Processors, "}\n");
1820 return list<pair<ChanCount, ChanCount> > ();
1823 if ((*p)->can_support_io_configuration(in, out)) {
1824 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1825 configuration.push_back(make_pair(in, out));
1832 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1833 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1834 DEBUG_TRACE (DEBUG::Processors, "}\n");
1835 return list<pair<ChanCount, ChanCount> > ();
1839 DEBUG_TRACE (DEBUG::Processors, "}\n");
1841 return configuration;
1844 /** Set the input/output configuration of each processor in the processors list.
1845 * Caller must hold process lock.
1846 * Return 0 on success, otherwise configuration is impossible.
1849 Route::configure_processors_unlocked (ProcessorStreams* err)
1851 #ifndef PLATFORM_WINDOWS
1852 assert (!AudioEngine::instance()->process_lock().trylock());
1855 if (_in_configure_processors) {
1859 /* put invisible processors where they should be */
1860 setup_invisible_processors ();
1862 _in_configure_processors = true;
1864 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1866 if (configuration.empty ()) {
1867 _in_configure_processors = false;
1872 bool seen_mains_out = false;
1873 processor_out_streams = _input->n_ports();
1874 processor_max_streams.reset();
1876 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1877 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1879 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1883 (*p)->configure_io(c->first, c->second);
1884 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1885 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1888 if (boost::dynamic_pointer_cast<Delivery> (*p)
1889 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1890 /* main delivery will increase port count to match input.
1891 * the Delivery::Main is usually the last processor - followed only by
1894 seen_mains_out = true;
1896 if (!seen_mains_out) {
1897 processor_out_streams = out;
1903 _meter->reset_max_channels (processor_max_streams);
1906 /* make sure we have sufficient scratch buffers to cope with the new processor
1909 _session.ensure_buffers (n_process_buffers ());
1911 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1913 _in_configure_processors = false;
1917 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1918 * @param state New active state for those processors.
1921 Route::all_visible_processors_active (bool state)
1923 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1925 if (_processors.empty()) {
1929 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1930 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1937 (*i)->deactivate ();
1941 _session.set_dirty ();
1945 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1947 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1948 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1949 processors in the current actual processor list that are hidden. Any visible processors
1950 in the current list but not in "new_order" will be assumed to be deleted.
1954 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1955 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1956 ProcessorState pstate (this);
1958 ProcessorList::iterator oiter;
1959 ProcessorList::const_iterator niter;
1960 ProcessorList as_it_will_be;
1962 oiter = _processors.begin();
1963 niter = new_order.begin();
1965 while (niter != new_order.end()) {
1967 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1968 then append it to the temp list.
1970 Otherwise, see if the next processor in the old list is in the new list. if not,
1971 its been deleted. If its there, append it to the temp list.
1974 if (oiter == _processors.end()) {
1976 /* no more elements in the old list, so just stick the rest of
1977 the new order onto the temp list.
1980 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1981 while (niter != new_order.end()) {
1988 if (!(*oiter)->display_to_user()) {
1990 as_it_will_be.push_back (*oiter);
1994 /* visible processor: check that its in the new order */
1996 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1997 /* deleted: do nothing, shared_ptr<> will clean up */
1999 /* ignore this one, and add the next item from the new order instead */
2000 as_it_will_be.push_back (*niter);
2005 /* now remove from old order - its taken care of no matter what */
2006 oiter = _processors.erase (oiter);
2011 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2013 /* If the meter is in a custom position, find it and make a rough note of its position */
2014 maybe_note_meter_position ();
2016 if (configure_processors_unlocked (err)) {
2022 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2023 set_processor_positions ();
2035 Route::get_template()
2037 return state(false);
2041 Route::state(bool full_state)
2043 XMLNode *node = new XMLNode("Route");
2044 ProcessorList::iterator i;
2047 id().print (buf, sizeof (buf));
2048 node->add_property("id", buf);
2049 node->add_property ("name", _name);
2050 node->add_property("default-type", _default_type.to_string());
2053 node->add_property("flags", enum_2_string (_flags));
2056 node->add_property("active", _active?"yes":"no");
2058 boost::to_string (_phase_invert, p);
2059 node->add_property("phase-invert", p);
2060 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2061 node->add_property("meter-point", enum_2_string (_meter_point));
2063 node->add_property("meter-type", enum_2_string (_meter_type));
2066 node->add_property("route-group", _route_group->name());
2069 snprintf (buf, sizeof (buf), "%d", _order_key);
2070 node->add_property ("order-key", buf);
2071 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2072 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2073 node->add_property ("soloed-by-upstream", buf);
2074 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2075 node->add_property ("soloed-by-downstream", buf);
2076 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2077 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2079 node->add_child_nocopy (_input->state (full_state));
2080 node->add_child_nocopy (_output->state (full_state));
2081 node->add_child_nocopy (_solo_control->get_state ());
2082 node->add_child_nocopy (_mute_control->get_state ());
2083 node->add_child_nocopy (_mute_master->get_state ());
2086 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2089 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2090 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2091 remote_control_node->add_property (X_("id"), buf);
2092 node->add_child_nocopy (*remote_control_node);
2094 if (_comment.length()) {
2095 XMLNode *cmt = node->add_child ("Comment");
2096 cmt->add_content (_comment);
2100 node->add_child_nocopy (_pannable->state (full_state));
2103 for (i = _processors.begin(); i != _processors.end(); ++i) {
2105 /* template save: do not include internal sends functioning as
2106 aux sends because the chance of the target ID
2107 in the session where this template is used
2110 similarly, do not save listen sends which connect to
2111 the monitor section, because these will always be
2114 boost::shared_ptr<InternalSend> is;
2116 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2117 if (is->role() == Delivery::Listen) {
2122 node->add_child_nocopy((*i)->state (full_state));
2126 node->add_child_copy (*_extra_xml);
2129 if (_custom_meter_position_noted) {
2130 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2132 after->id().print (buf, sizeof (buf));
2133 node->add_property (X_("processor-after-last-custom-meter"), buf);
2136 node->add_property (X_("last-custom-meter-was-at-end"), _last_custom_meter_was_at_end ? "yes" : "no");
2143 Route::set_state (const XMLNode& node, int version)
2145 if (version < 3000) {
2146 return set_state_2X (node, version);
2150 XMLNodeConstIterator niter;
2152 const XMLProperty *prop;
2154 if (node.name() != "Route"){
2155 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2159 if ((prop = node.property (X_("name"))) != 0) {
2160 Route::set_name (prop->value());
2164 _initial_io_setup = true;
2166 if ((prop = node.property (X_("flags"))) != 0) {
2167 _flags = Flag (string_2_enum (prop->value(), _flags));
2172 if (is_master() || is_monitor() || is_auditioner()) {
2173 _mute_master->set_solo_ignore (true);
2177 /* monitor bus does not get a panner, but if (re)created
2178 via XML, it will already have one by the time we
2179 call ::set_state(). so ... remove it.
2184 /* add all processors (except amp, which is always present) */
2186 nlist = node.children();
2187 XMLNode processor_state (X_("processor_state"));
2189 Stateful::save_extra_xml (node);
2191 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2195 if (child->name() == IO::state_node_name) {
2196 if ((prop = child->property (X_("direction"))) == 0) {
2200 if (prop->value() == "Input") {
2201 _input->set_state (*child, version);
2202 } else if (prop->value() == "Output") {
2203 _output->set_state (*child, version);
2207 if (child->name() == X_("Processor")) {
2208 processor_state.add_child_copy (*child);
2211 if (child->name() == X_("Pannable")) {
2213 _pannable->set_state (*child, version);
2215 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2220 if ((prop = node.property (X_("meter-point"))) != 0) {
2221 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2222 set_meter_point (mp, true);
2224 _meter->set_display_to_user (_meter_point == MeterCustom);
2228 if ((prop = node.property (X_("meter-type"))) != 0) {
2229 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2232 _initial_io_setup = false;
2234 set_processor_state (processor_state);
2236 // this looks up the internal instrument in processors
2237 reset_instrument_info();
2239 if ((prop = node.property ("self-solo")) != 0) {
2240 set_self_solo (string_is_affirmative (prop->value()));
2243 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2244 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2245 mod_solo_by_others_upstream (atoi (prop->value()));
2248 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2249 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2250 mod_solo_by_others_downstream (atoi (prop->value()));
2253 if ((prop = node.property ("solo-isolated")) != 0) {
2254 set_solo_isolated (string_is_affirmative (prop->value()), this);
2257 if ((prop = node.property ("solo-safe")) != 0) {
2258 set_solo_safe (string_is_affirmative (prop->value()), this);
2261 if ((prop = node.property (X_("phase-invert"))) != 0) {
2262 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2265 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2266 set_denormal_protection (string_is_affirmative (prop->value()));
2269 if ((prop = node.property (X_("active"))) != 0) {
2270 bool yn = string_is_affirmative (prop->value());
2271 _active = !yn; // force switch
2272 set_active (yn, this);
2275 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2276 set_order_key (atoi(prop->value()));
2279 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2283 string::size_type colon, equal;
2284 string remaining = prop->value();
2286 while (remaining.length()) {
2288 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2289 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2292 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2293 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2296 string keyname = remaining.substr (0, equal);
2298 if ((keyname == "EditorSort") || (keyname == "editor")) {
2299 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2305 colon = remaining.find_first_of (':');
2307 if (colon != string::npos) {
2308 remaining = remaining.substr (colon+1);
2315 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2316 PBD::ID id (prop->value ());
2317 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2318 ProcessorList::const_iterator i = _processors.begin ();
2319 while (i != _processors.end() && (*i)->id() != id) {
2323 if (i != _processors.end ()) {
2324 _processor_after_last_custom_meter = *i;
2325 _custom_meter_position_noted = true;
2329 if ((prop = node.property (X_("last-custom-meter-was-at-end"))) != 0) {
2330 _last_custom_meter_was_at_end = string_is_affirmative (prop->value ());
2333 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2336 if (child->name() == X_("Comment")) {
2338 /* XXX this is a terrible API design in libxml++ */
2340 XMLNode *cmt = *(child->children().begin());
2341 _comment = cmt->content();
2343 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2344 if (prop->value() == "solo") {
2345 _solo_control->set_state (*child, version);
2346 } else if (prop->value() == "mute") {
2347 _mute_control->set_state (*child, version);
2350 } else if (child->name() == X_("RemoteControl")) {
2351 if ((prop = child->property (X_("id"))) != 0) {
2353 sscanf (prop->value().c_str(), "%d", &x);
2354 set_remote_control_id_internal (x);
2357 } else if (child->name() == X_("MuteMaster")) {
2358 _mute_master->set_state (*child, version);
2360 } else if (child->name() == Automatable::xml_node_name) {
2361 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2369 Route::set_state_2X (const XMLNode& node, int version)
2371 LocaleGuard lg (X_("C"));
2373 XMLNodeConstIterator niter;
2375 const XMLProperty *prop;
2377 /* 2X things which still remain to be handled:
2383 if (node.name() != "Route") {
2384 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2388 if ((prop = node.property (X_("flags"))) != 0) {
2389 string f = prop->value ();
2390 boost::replace_all (f, "ControlOut", "MonitorOut");
2391 _flags = Flag (string_2_enum (f, _flags));
2396 if (is_master() || is_monitor() || is_auditioner()) {
2397 _mute_master->set_solo_ignore (true);
2400 if ((prop = node.property (X_("phase-invert"))) != 0) {
2401 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2402 if (string_is_affirmative (prop->value ())) {
2405 set_phase_invert (p);
2408 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2409 set_denormal_protection (string_is_affirmative (prop->value()));
2412 if ((prop = node.property (X_("soloed"))) != 0) {
2413 bool yn = string_is_affirmative (prop->value());
2415 /* XXX force reset of solo status */
2417 set_solo (yn, this);
2420 if ((prop = node.property (X_("muted"))) != 0) {
2423 bool muted = string_is_affirmative (prop->value());
2429 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2431 if (string_is_affirmative (prop->value())){
2432 mute_point = mute_point + "PreFader";
2437 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2439 if (string_is_affirmative (prop->value())){
2442 mute_point = mute_point + ",";
2445 mute_point = mute_point + "PostFader";
2450 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2452 if (string_is_affirmative (prop->value())){
2455 mute_point = mute_point + ",";
2458 mute_point = mute_point + "Listen";
2463 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2465 if (string_is_affirmative (prop->value())){
2468 mute_point = mute_point + ",";
2471 mute_point = mute_point + "Main";
2475 _mute_master->set_mute_points (mute_point);
2476 _mute_master->set_muted_by_self (true);
2480 if ((prop = node.property (X_("meter-point"))) != 0) {
2481 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2484 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2485 don't mean the same thing.
2488 if ((prop = node.property (X_("order-keys"))) != 0) {
2492 string::size_type colon, equal;
2493 string remaining = prop->value();
2495 while (remaining.length()) {
2497 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2498 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2501 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2502 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2505 string keyname = remaining.substr (0, equal);
2507 if (keyname == "EditorSort" || keyname == "editor") {
2508 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2514 colon = remaining.find_first_of (':');
2516 if (colon != string::npos) {
2517 remaining = remaining.substr (colon+1);
2526 nlist = node.children ();
2527 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2531 if (child->name() == IO::state_node_name) {
2533 /* there is a note in IO::set_state_2X() about why we have to call
2537 _input->set_state_2X (*child, version, true);
2538 _output->set_state_2X (*child, version, false);
2540 if ((prop = child->property (X_("name"))) != 0) {
2541 Route::set_name (prop->value ());
2546 if ((prop = child->property (X_("active"))) != 0) {
2547 bool yn = string_is_affirmative (prop->value());
2548 _active = !yn; // force switch
2549 set_active (yn, this);
2552 if ((prop = child->property (X_("gain"))) != 0) {
2555 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2556 _amp->gain_control()->set_value (val);
2560 /* Set up Panners in the IO */
2561 XMLNodeList io_nlist = child->children ();
2563 XMLNodeConstIterator io_niter;
2566 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2568 io_child = *io_niter;
2570 if (io_child->name() == X_("Panner")) {
2571 _main_outs->panner_shell()->set_state(*io_child, version);
2572 } else if (io_child->name() == X_("Automation")) {
2573 /* IO's automation is for the fader */
2574 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2580 XMLNodeList redirect_nodes;
2582 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2586 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2587 redirect_nodes.push_back(child);
2592 set_processor_state_2X (redirect_nodes, version);
2594 Stateful::save_extra_xml (node);
2596 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2599 if (child->name() == X_("Comment")) {
2601 /* XXX this is a terrible API design in libxml++ */
2603 XMLNode *cmt = *(child->children().begin());
2604 _comment = cmt->content();
2606 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2607 if (prop->value() == X_("solo")) {
2608 _solo_control->set_state (*child, version);
2609 } else if (prop->value() == X_("mute")) {
2610 _mute_control->set_state (*child, version);
2613 } else if (child->name() == X_("RemoteControl")) {
2614 if ((prop = child->property (X_("id"))) != 0) {
2616 sscanf (prop->value().c_str(), "%d", &x);
2617 set_remote_control_id_internal (x);
2627 Route::get_processor_state ()
2629 XMLNode* root = new XMLNode (X_("redirects"));
2630 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2631 root->add_child_nocopy ((*i)->state (true));
2638 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2640 /* We don't bother removing existing processors not in nList, as this
2641 method will only be called when creating a Route from scratch, not
2642 for undo purposes. Just put processors in at the appropriate place
2646 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2647 add_processor_from_xml_2X (**i, version);
2652 Route::set_processor_state (const XMLNode& node)
2654 const XMLNodeList &nlist = node.children();
2655 XMLNodeConstIterator niter;
2656 ProcessorList new_order;
2657 bool must_configure = false;
2659 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2661 XMLProperty* prop = (*niter)->property ("type");
2663 if (prop->value() == "amp") {
2664 _amp->set_state (**niter, Stateful::current_state_version);
2665 new_order.push_back (_amp);
2666 } else if (prop->value() == "trim") {
2667 _trim->set_state (**niter, Stateful::current_state_version);
2668 new_order.push_back (_trim);
2669 } else if (prop->value() == "meter") {
2670 _meter->set_state (**niter, Stateful::current_state_version);
2671 new_order.push_back (_meter);
2672 } else if (prop->value() == "delay") {
2674 _delayline->set_state (**niter, Stateful::current_state_version);
2675 new_order.push_back (_delayline);
2677 } else if (prop->value() == "main-outs") {
2678 _main_outs->set_state (**niter, Stateful::current_state_version);
2679 } else if (prop->value() == "intreturn") {
2681 _intreturn.reset (new InternalReturn (_session));
2682 must_configure = true;
2684 _intreturn->set_state (**niter, Stateful::current_state_version);
2685 } else if (is_monitor() && prop->value() == "monitor") {
2686 if (!_monitor_control) {
2687 _monitor_control.reset (new MonitorProcessor (_session));
2688 must_configure = true;
2690 _monitor_control->set_state (**niter, Stateful::current_state_version);
2691 } else if (prop->value() == "capture") {
2692 /* CapturingProcessor should never be restored, it's always
2693 added explicitly when needed */
2695 ProcessorList::iterator o;
2697 for (o = _processors.begin(); o != _processors.end(); ++o) {
2698 XMLProperty* id_prop = (*niter)->property(X_("id"));
2699 if (id_prop && (*o)->id() == id_prop->value()) {
2700 (*o)->set_state (**niter, Stateful::current_state_version);
2701 new_order.push_back (*o);
2706 // If the processor (*niter) is not on the route then create it
2708 if (o == _processors.end()) {
2710 boost::shared_ptr<Processor> processor;
2712 if (prop->value() == "intsend") {
2714 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2716 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2717 prop->value() == "lv2" ||
2718 prop->value() == "windows-vst" ||
2719 prop->value() == "lxvst" ||
2720 prop->value() == "audiounit") {
2722 processor.reset (new PluginInsert(_session));
2724 } else if (prop->value() == "port") {
2726 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2728 } else if (prop->value() == "send") {
2730 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2733 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2737 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2738 /* This processor could not be configured. Turn it into a UnknownProcessor */
2739 processor.reset (new UnknownProcessor (_session, **niter));
2742 /* we have to note the monitor send here, otherwise a new one will be created
2743 and the state of this one will be lost.
2745 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2746 if (isend && isend->role() == Delivery::Listen) {
2747 _monitor_send = isend;
2750 /* it doesn't matter if invisible processors are added here, as they
2751 will be sorted out by setup_invisible_processors () shortly.
2754 new_order.push_back (processor);
2755 must_configure = true;
2761 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2762 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2763 _processors = new_order;
2765 if (must_configure) {
2766 configure_processors_unlocked (0);
2769 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2771 (*i)->set_owner (this);
2772 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2774 boost::shared_ptr<PluginInsert> pi;
2776 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2777 if (pi->has_no_inputs ()) {
2778 _have_internal_generator = true;
2785 reset_instrument_info ();
2786 processors_changed (RouteProcessorChange ());
2787 set_processor_positions ();
2791 Route::curve_reallocate ()
2793 // _gain_automation_curve.finish_resize ();
2794 // _pan_automation_curve.finish_resize ();
2798 Route::silence (framecnt_t nframes)
2800 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2805 silence_unlocked (nframes);
2809 Route::silence_unlocked (framecnt_t nframes)
2811 /* Must be called with the processor lock held */
2815 _output->silence (nframes);
2817 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2818 boost::shared_ptr<PluginInsert> pi;
2820 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2821 // skip plugins, they don't need anything when we're not active
2825 (*i)->silence (nframes);
2828 if (nframes == _session.get_block_size()) {
2835 Route::add_internal_return ()
2838 _intreturn.reset (new InternalReturn (_session));
2839 add_processor (_intreturn, PreFader);
2844 Route::add_send_to_internal_return (InternalSend* send)
2846 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2848 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2849 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2852 return d->add_send (send);
2858 Route::remove_send_from_internal_return (InternalSend* send)
2860 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2862 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2863 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2866 return d->remove_send (send);
2872 Route::enable_monitor_send ()
2874 /* Caller must hold process lock */
2875 assert (!AudioEngine::instance()->process_lock().trylock());
2877 /* master never sends to monitor section via the normal mechanism */
2878 assert (!is_master ());
2879 assert (!is_monitor ());
2881 /* make sure we have one */
2882 if (!_monitor_send) {
2883 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
2884 _monitor_send->set_display_to_user (false);
2888 configure_processors (0);
2891 /** Add an aux send to a route.
2892 * @param route route to send to.
2893 * @param before Processor to insert before, or 0 to insert at the end.
2896 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2898 assert (route != _session.monitor_out ());
2901 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2903 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2905 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2907 if (d && d->target_route() == route) {
2908 /* already listening via the specified IO: do nothing */
2916 boost::shared_ptr<InternalSend> listener;
2919 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2920 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
2921 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
2924 add_processor (listener, before);
2926 } catch (failed_constructor& err) {
2934 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
2936 ProcessorStreams err;
2937 ProcessorList::iterator tmp;
2940 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
2942 /* have to do this early because otherwise processor reconfig
2943 * will put _monitor_send back in the list
2946 if (route == _session.monitor_out()) {
2947 _monitor_send.reset ();
2951 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2953 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2955 if (d && d->target_route() == route) {
2957 remove_processor (*x, &err, false);
2960 /* list could have been demolished while we dropped the lock
2971 Route::set_comment (string cmt, void *src)
2974 comment_changed (src);
2975 _session.set_dirty ();
2979 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2981 FeedRecord fr (other, via_sends_only);
2983 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2985 if (!result.second) {
2987 /* already a record for "other" - make sure sends-only information is correct */
2988 if (!via_sends_only && result.first->sends_only) {
2989 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2990 frp->sends_only = false;
2994 return result.second;
2998 Route::clear_fed_by ()
3004 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3006 const FedBy& fed_by (other->fed_by());
3008 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3009 boost::shared_ptr<Route> sr = f->r.lock();
3011 if (sr && (sr.get() == this)) {
3013 if (via_sends_only) {
3014 *via_sends_only = f->sends_only;
3025 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3027 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3029 if (_output->connected_to (other->input())) {
3030 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3031 if (via_send_only) {
3032 *via_send_only = false;
3039 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3041 boost::shared_ptr<IOProcessor> iop;
3043 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3044 if (iop->feeds (other)) {
3045 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3046 if (via_send_only) {
3047 *via_send_only = true;
3051 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3054 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3059 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3064 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3066 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3069 /** Called from the (non-realtime) butler thread when the transport is stopped */
3071 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3073 framepos_t now = _session.transport_frame();
3076 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3078 Automatable::transport_stopped (now);
3080 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3082 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3086 (*i)->transport_stopped (now);
3090 _roll_delay = _initial_delay;
3094 Route::input_change_handler (IOChange change, void * /*src*/)
3096 bool need_to_queue_solo_change = true;
3098 if ((change.type & IOChange::ConfigurationChanged)) {
3099 /* This is called with the process lock held if change
3100 contains ConfigurationChanged
3102 need_to_queue_solo_change = false;
3103 configure_processors (0);
3104 _phase_invert.resize (_input->n_ports().n_audio ());
3105 io_changed (); /* EMIT SIGNAL */
3108 if (!_input->connected() && _soloed_by_others_upstream) {
3109 if (need_to_queue_solo_change) {
3110 _session.cancel_solo_after_disconnect (shared_from_this(), true);
3112 cancel_solo_after_disconnect (true);
3118 Route::output_change_handler (IOChange change, void * /*src*/)
3120 bool need_to_queue_solo_change = true;
3121 if (_initial_io_setup) {
3125 if ((change.type & IOChange::ConfigurationChanged)) {
3126 /* This is called with the process lock held if change
3127 contains ConfigurationChanged
3129 need_to_queue_solo_change = false;
3130 configure_processors (0);
3133 _session.reset_monitor_section();
3136 io_changed (); /* EMIT SIGNAL */
3139 if (!_output->connected() && _soloed_by_others_downstream) {
3140 if (need_to_queue_solo_change) {
3141 _session.cancel_solo_after_disconnect (shared_from_this(), false);
3143 cancel_solo_after_disconnect (false);
3149 Route::cancel_solo_after_disconnect (bool upstream)
3152 _soloed_by_others_upstream = 0;
3154 _soloed_by_others_downstream = 0;
3156 set_mute_master_solo ();
3157 solo_changed (false, this);
3161 Route::pans_required () const
3163 if (n_outputs().n_audio() < 2) {
3167 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3171 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3173 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3179 if (n_outputs().n_total() == 0) {
3183 if (!_active || n_inputs() == ChanCount::ZERO) {
3184 silence_unlocked (nframes);
3188 if (session_state_changing) {
3189 if (_session.transport_speed() != 0.0f) {
3190 /* we're rolling but some state is changing (e.g. our diskstream contents)
3191 so we cannot use them. Be silent till this is over.
3193 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3195 silence_unlocked (nframes);
3198 /* we're really not rolling, so we're either delivery silence or actually
3199 monitoring, both of which are safe to do while session_state_changing is true.
3203 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3205 fill_buffers_with_input (bufs, _input, nframes);
3207 if (_meter_point == MeterInput) {
3208 _meter->run (bufs, start_frame, end_frame, nframes, true);
3211 _amp->apply_gain_automation (false);
3212 passthru (bufs, start_frame, end_frame, nframes, 0);
3218 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3220 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3225 if (n_outputs().n_total() == 0) {
3229 if (!_active || n_inputs().n_total() == 0) {
3230 silence_unlocked (nframes);
3234 framepos_t unused = 0;
3236 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3242 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3244 fill_buffers_with_input (bufs, _input, nframes);
3246 if (_meter_point == MeterInput) {
3247 _meter->run (bufs, start_frame, end_frame, nframes, true);
3250 passthru (bufs, start_frame, end_frame, nframes, declick);
3256 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3263 Route::flush_processors ()
3265 /* XXX shouldn't really try to take this lock, since
3266 this is called from the RT audio thread.
3269 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3271 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3277 Route::set_meter_point (MeterPoint p, bool force)
3279 if (_meter_point == p && !force) {
3283 bool meter_was_visible_to_user = _meter->display_to_user ();
3286 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3287 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3289 maybe_note_meter_position ();
3293 if (_meter_point != MeterCustom) {
3295 _meter->set_display_to_user (false);
3297 setup_invisible_processors ();
3301 _meter->set_display_to_user (true);
3303 /* If we have a previous position for the custom meter, try to put it there */
3304 if (_custom_meter_position_noted) {
3305 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3308 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3309 if (i != _processors.end ()) {
3310 _processors.remove (_meter);
3311 _processors.insert (i, _meter);
3313 } else if (_last_custom_meter_was_at_end) {
3314 _processors.remove (_meter);
3315 _processors.push_back (_meter);
3320 /* Set up the meter for its new position */
3322 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3326 if (loc == _processors.begin()) {
3327 m_in = _input->n_ports();
3329 ProcessorList::iterator before = loc;
3331 m_in = (*before)->output_streams ();
3334 _meter->reflect_inputs (m_in);
3336 /* we do not need to reconfigure the processors, because the meter
3337 (a) is always ready to handle processor_max_streams
3338 (b) is always an N-in/N-out processor, and thus moving
3339 it doesn't require any changes to the other processors.
3343 meter_change (); /* EMIT SIGNAL */
3345 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3347 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3351 Route::listen_position_changed ()
3354 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3355 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3356 ProcessorState pstate (this);
3358 if (configure_processors_unlocked (0)) {
3360 configure_processors_unlocked (0); // it worked before we tried to add it ...
3365 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3366 _session.set_dirty ();
3369 boost::shared_ptr<CapturingProcessor>
3370 Route::add_export_point()
3372 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3373 if (!_capturing_processor) {
3375 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3376 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3378 _capturing_processor.reset (new CapturingProcessor (_session));
3379 _capturing_processor->activate ();
3381 configure_processors_unlocked (0);
3385 return _capturing_processor;
3389 Route::update_signal_latency ()
3391 framecnt_t l = _output->user_latency();
3392 framecnt_t lamp = 0;
3393 bool before_amp = true;
3395 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3396 if ((*i)->active ()) {
3397 l += (*i)->signal_latency ();
3407 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3409 _signal_latency_at_amp_position = lamp;
3410 if (_signal_latency != l) {
3411 _signal_latency = l;
3412 signal_latency_changed (); /* EMIT SIGNAL */
3415 return _signal_latency;
3419 Route::set_user_latency (framecnt_t nframes)
3421 _output->set_user_latency (nframes);
3422 _session.update_latency_compensation ();
3426 Route::set_latency_compensation (framecnt_t longest_session_latency)
3428 framecnt_t old = _initial_delay;
3430 if (_signal_latency < longest_session_latency) {
3431 _initial_delay = longest_session_latency - _signal_latency;
3436 DEBUG_TRACE (DEBUG::Latency, string_compose (
3437 "%1: compensate for maximum latency of %2,"
3438 "given own latency of %3, using initial delay of %4\n",
3439 name(), longest_session_latency, _signal_latency, _initial_delay));
3441 if (_initial_delay != old) {
3442 initial_delay_changed (); /* EMIT SIGNAL */
3445 if (_session.transport_stopped()) {
3446 _roll_delay = _initial_delay;
3450 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3451 : AutomationControl (r->session(),
3452 Evoral::Parameter (SoloAutomation),
3453 ParameterDescriptor(Evoral::Parameter (SoloAutomation)),
3454 boost::shared_ptr<AutomationList>(), name)
3457 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3458 gl->set_interpolation(Evoral::ControlList::Discrete);
3463 Route::SoloControllable::set_value (double val)
3465 const bool bval = ((val >= 0.5) ? true : false);
3467 boost::shared_ptr<RouteList> rl (new RouteList);
3469 boost::shared_ptr<Route> r = _route.lock ();
3476 if (Config->get_solo_control_is_listen_control()) {
3477 _session.set_listen (rl, bval);
3479 _session.set_solo (rl, bval);
3484 Route::SoloControllable::get_value () const
3486 boost::shared_ptr<Route> r = _route.lock ();
3491 if (Config->get_solo_control_is_listen_control()) {
3492 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3494 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3498 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3499 : AutomationControl (r->session(),
3500 Evoral::Parameter (MuteAutomation),
3501 ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
3502 boost::shared_ptr<AutomationList>(),
3506 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3507 gl->set_interpolation(Evoral::ControlList::Discrete);
3512 Route::MuteControllable::set_superficial_value(bool muted)
3514 /* Note we can not use AutomationControl::set_value here since it will emit
3515 Changed(), but the value will not be correct to the observer. */
3517 bool to_list = _list && ((AutomationList*)_list.get())->automation_write();
3519 Control::set_double (muted, _session.transport_frame(), to_list);
3523 Route::MuteControllable::set_value (double val)
3525 const bool bval = ((val >= 0.5) ? true : false);
3527 boost::shared_ptr<Route> r = _route.lock ();
3532 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3533 // Playing back automation, set route mute directly
3534 r->set_mute (bval, this);
3536 // Set from user, queue mute event
3537 boost::shared_ptr<RouteList> rl (new RouteList);
3539 _session.set_mute (rl, bval, Session::rt_cleanup);
3542 // Set superficial/automation value to drive controller (and possibly record)
3543 set_superficial_value(bval);
3547 Route::MuteControllable::get_value () const
3549 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3550 // Playing back automation, get the value from the list
3551 return AutomationControl::get_value();
3554 // Not playing back automation, get the actual route mute value
3555 boost::shared_ptr<Route> r = _route.lock ();
3556 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3560 Route::set_block_size (pframes_t nframes)
3562 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3563 (*i)->set_block_size (nframes);
3566 _session.ensure_buffers (n_process_buffers ());
3570 Route::protect_automation ()
3572 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3573 (*i)->protect_automation();
3576 /** @param declick 1 to set a pending declick fade-in,
3577 * -1 to set a pending declick fade-out
3580 Route::set_pending_declick (int declick)
3583 /* this call is not allowed to turn off a pending declick */
3585 _pending_declick = declick;
3588 _pending_declick = 0;
3592 /** Shift automation forwards from a particular place, thereby inserting time.
3593 * Adds undo commands for any shifts that are performed.
3595 * @param pos Position to start shifting from.
3596 * @param frames Amount to shift forwards by.
3600 Route::shift (framepos_t pos, framecnt_t frames)
3602 /* gain automation */
3604 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3606 XMLNode &before = gc->alist()->get_state ();
3607 gc->alist()->shift (pos, frames);
3608 XMLNode &after = gc->alist()->get_state ();
3609 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3612 /* pan automation */
3614 ControlSet::Controls& c (_pannable->controls());
3616 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3617 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3619 boost::shared_ptr<AutomationList> al = pc->alist();
3620 XMLNode& before = al->get_state ();
3621 al->shift (pos, frames);
3622 XMLNode& after = al->get_state ();
3623 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3628 /* redirect automation */
3630 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3631 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3633 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3635 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3636 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3638 boost::shared_ptr<AutomationList> al = ac->alist();
3639 XMLNode &before = al->get_state ();
3640 al->shift (pos, frames);
3641 XMLNode &after = al->get_state ();
3642 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3651 Route::save_as_template (const string& path, const string& name)
3653 XMLNode& node (state (false));
3656 IO::set_name_in_state (*node.children().front(), name);
3658 tree.set_root (&node);
3659 return tree.write (path.c_str());
3664 Route::set_name (const string& str)
3666 if (str == name()) {
3670 string name = Route::ensure_track_or_route_name (str, _session);
3671 SessionObject::set_name (name);
3673 bool ret = (_input->set_name(name) && _output->set_name(name));
3676 /* rename the main outs. Leave other IO processors
3677 * with whatever name they already have, because its
3678 * just fine as it is (it will not contain the route
3679 * name if its a port insert, port send or port return).
3683 if (_main_outs->set_name (name)) {
3684 /* XXX returning false here is stupid because
3685 we already changed the route name.
3695 /** Set the name of a route in an XML description.
3696 * @param node XML <Route> node to set the name in.
3697 * @param name New name.
3700 Route::set_name_in_state (XMLNode& node, string const & name)
3702 node.add_property (X_("name"), name);
3704 XMLNodeList children = node.children();
3705 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3707 if ((*i)->name() == X_("IO")) {
3709 IO::set_name_in_state (**i, name);
3711 } else if ((*i)->name() == X_("Processor")) {
3713 XMLProperty* role = (*i)->property (X_("role"));
3714 if (role && role->value() == X_("Main")) {
3715 (*i)->add_property (X_("name"), name);
3718 } else if ((*i)->name() == X_("Diskstream")) {
3720 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3721 (*i)->add_property (X_("name"), name);
3727 boost::shared_ptr<Send>
3728 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3730 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3732 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3733 boost::shared_ptr<InternalSend> send;
3735 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3736 if (send->target_route() == target) {
3742 return boost::shared_ptr<Send>();
3745 /** @param c Audio channel index.
3746 * @param yn true to invert phase, otherwise false.
3749 Route::set_phase_invert (uint32_t c, bool yn)
3751 if (_phase_invert[c] != yn) {
3752 _phase_invert[c] = yn;
3753 phase_invert_changed (); /* EMIT SIGNAL */
3754 _session.set_dirty ();
3759 Route::set_phase_invert (boost::dynamic_bitset<> p)
3761 if (_phase_invert != p) {
3763 phase_invert_changed (); /* EMIT SIGNAL */
3764 _session.set_dirty ();
3769 Route::phase_invert (uint32_t c) const
3771 return _phase_invert[c];
3774 boost::dynamic_bitset<>
3775 Route::phase_invert () const
3777 return _phase_invert;
3781 Route::set_denormal_protection (bool yn)
3783 if (_denormal_protection != yn) {
3784 _denormal_protection = yn;
3785 denormal_protection_changed (); /* EMIT SIGNAL */
3790 Route::denormal_protection () const
3792 return _denormal_protection;
3796 Route::set_active (bool yn, void* src)
3798 if (_session.transport_rolling()) {
3802 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3803 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3807 if (_active != yn) {
3809 _input->set_active (yn);
3810 _output->set_active (yn);
3811 active_changed (); // EMIT SIGNAL
3812 _session.set_dirty ();
3819 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3825 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3827 boost::shared_ptr<Send> s;
3828 boost::shared_ptr<Return> r;
3830 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3831 s->meter()->meter();
3832 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3833 r->meter()->meter ();
3838 boost::shared_ptr<Pannable>
3839 Route::pannable() const
3844 boost::shared_ptr<Panner>
3845 Route::panner() const
3848 return _main_outs->panner_shell()->panner();
3851 boost::shared_ptr<PannerShell>
3852 Route::panner_shell() const
3854 return _main_outs->panner_shell();
3857 boost::shared_ptr<AutomationControl>
3858 Route::gain_control() const
3860 return _amp->gain_control();
3863 boost::shared_ptr<AutomationControl>
3864 Route::get_control (const Evoral::Parameter& param)
3866 /* either we own the control or .... */
3868 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3872 /* maybe one of our processors does or ... */
3874 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3875 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3876 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3884 /* nobody does so we'll make a new one */
3886 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3893 boost::shared_ptr<Processor>
3894 Route::nth_plugin (uint32_t n)
3896 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3897 ProcessorList::iterator i;
3899 for (i = _processors.begin(); i != _processors.end(); ++i) {
3900 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3907 return boost::shared_ptr<Processor> ();
3910 boost::shared_ptr<Processor>
3911 Route::nth_send (uint32_t n)
3913 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3914 ProcessorList::iterator i;
3916 for (i = _processors.begin(); i != _processors.end(); ++i) {
3917 if (boost::dynamic_pointer_cast<Send> (*i)) {
3924 return boost::shared_ptr<Processor> ();
3928 Route::has_io_processor_named (const string& name)
3930 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3931 ProcessorList::iterator i;
3933 for (i = _processors.begin(); i != _processors.end(); ++i) {
3934 if (boost::dynamic_pointer_cast<Send> (*i) ||
3935 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3936 if ((*i)->name() == name) {
3945 MuteMaster::MutePoint
3946 Route::mute_points () const
3948 return _mute_master->mute_points ();
3952 Route::set_processor_positions ()
3954 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3956 bool had_amp = false;
3957 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3958 (*i)->set_pre_fader (!had_amp);
3959 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3965 /** Called when there is a proposed change to the input port count */
3967 Route::input_port_count_changing (ChanCount to)
3969 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3971 /* The processors cannot be configured with the new input arrangement, so
3977 /* The change is ok */
3981 /** Called when there is a proposed change to the output port count */
3983 Route::output_port_count_changing (ChanCount to)
3985 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
3986 if (processor_out_streams.get(*t) > to.get(*t)) {
3990 /* The change is ok */
3995 Route::unknown_processors () const
3999 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4000 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4001 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4002 p.push_back ((*i)->name ());
4011 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4013 /* we assume that all our input ports feed all our output ports. its not
4014 universally true, but the alternative is way too corner-case to worry about.
4017 LatencyRange all_connections;
4020 all_connections.min = 0;
4021 all_connections.max = 0;
4023 all_connections.min = ~((pframes_t) 0);
4024 all_connections.max = 0;
4026 /* iterate over all "from" ports and determine the latency range for all of their
4027 connections to the "outside" (outside of this Route).
4030 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4034 p->get_connected_latency_range (range, playback);
4036 all_connections.min = min (all_connections.min, range.min);
4037 all_connections.max = max (all_connections.max, range.max);
4041 /* set the "from" port latencies to the max/min range of all their connections */
4043 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4044 p->set_private_latency_range (all_connections, playback);
4047 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4049 all_connections.min += our_latency;
4050 all_connections.max += our_latency;
4052 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4053 p->set_private_latency_range (all_connections, playback);
4056 return all_connections.max;
4060 Route::set_private_port_latencies (bool playback) const
4062 framecnt_t own_latency = 0;
4064 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4065 OR LATENCY CALLBACK.
4067 This is called (early) from the latency callback. It computes the REAL
4068 latency associated with each port and stores the result as the "private"
4069 latency of the port. A later call to Route::set_public_port_latencies()
4070 sets all ports to the same value to reflect the fact that we do latency
4071 compensation and so all signals are delayed by the same amount as they
4072 flow through ardour.
4075 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4076 if ((*i)->active ()) {
4077 own_latency += (*i)->signal_latency ();
4082 /* playback: propagate latency from "outside the route" to outputs to inputs */
4083 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4085 /* capture: propagate latency from "outside the route" to inputs to outputs */
4086 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4091 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4093 /* this is called to set the JACK-visible port latencies, which take
4094 latency compensation into account.
4103 const PortSet& ports (_input->ports());
4104 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4105 p->set_public_latency_range (range, playback);
4110 const PortSet& ports (_output->ports());
4111 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4112 p->set_public_latency_range (range, playback);
4117 /** Put the invisible processors in the right place in _processors.
4118 * Must be called with a writer lock on _processor_lock held.
4121 Route::setup_invisible_processors ()
4124 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4125 assert (!lm.locked ());
4129 /* too early to be doing this stuff */
4133 /* we'll build this new list here and then use it */
4135 ProcessorList new_processors;
4137 /* find visible processors */
4139 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4140 if ((*i)->display_to_user ()) {
4141 new_processors.push_back (*i);
4147 ProcessorList::iterator amp = new_processors.begin ();
4148 while (amp != new_processors.end() && boost::dynamic_pointer_cast<Amp> (*amp) == 0) {
4152 assert (amp != new_processors.end ());
4154 /* and the processor after the amp */
4156 ProcessorList::iterator after_amp = amp;
4162 switch (_meter_point) {
4164 assert (!_meter->display_to_user ());
4165 new_processors.push_front (_meter);
4168 assert (!_meter->display_to_user ());
4169 new_processors.insert (amp, _meter);
4171 case MeterPostFader:
4172 /* do nothing here */
4175 /* do nothing here */
4178 /* the meter is visible, so we don't touch it here */
4185 assert (_main_outs);
4186 assert (!_main_outs->display_to_user ());
4187 new_processors.push_back (_main_outs);
4189 /* iterator for the main outs */
4191 ProcessorList::iterator main = new_processors.end();
4194 /* OUTPUT METERING */
4196 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4197 assert (!_meter->display_to_user ());
4199 /* add the processor just before or just after the main outs */
4201 ProcessorList::iterator meter_point = main;
4203 if (_meter_point == MeterOutput) {
4206 new_processors.insert (meter_point, _meter);
4211 if (_monitor_send && !is_monitor ()) {
4212 assert (!_monitor_send->display_to_user ());
4213 if (Config->get_solo_control_is_listen_control()) {
4214 switch (Config->get_listen_position ()) {
4215 case PreFaderListen:
4216 switch (Config->get_pfl_position ()) {
4217 case PFLFromBeforeProcessors:
4218 new_processors.push_front (_monitor_send);
4220 case PFLFromAfterProcessors:
4221 new_processors.insert (amp, _monitor_send);
4224 _monitor_send->set_can_pan (false);
4226 case AfterFaderListen:
4227 switch (Config->get_afl_position ()) {
4228 case AFLFromBeforeProcessors:
4229 new_processors.insert (after_amp, _monitor_send);
4231 case AFLFromAfterProcessors:
4232 new_processors.insert (new_processors.end(), _monitor_send);
4235 _monitor_send->set_can_pan (true);
4239 new_processors.insert (new_processors.end(), _monitor_send);
4240 _monitor_send->set_can_pan (false);
4244 #if 0 // not used - just yet
4245 if (!is_master() && !is_monitor() && !is_auditioner()) {
4246 new_processors.push_front (_delayline);
4250 /* MONITOR CONTROL */
4252 if (_monitor_control && is_monitor ()) {
4253 assert (!_monitor_control->display_to_user ());
4254 new_processors.push_front (_monitor_control);
4257 /* INTERNAL RETURN */
4259 /* doing this here means that any monitor control will come just after
4264 assert (!_intreturn->display_to_user ());
4265 new_processors.push_front (_intreturn);
4268 if (_trim && _trim->active()) {
4269 assert (!_trim->display_to_user ());
4270 new_processors.push_front (_trim);
4272 /* EXPORT PROCESSOR */
4274 if (_capturing_processor) {
4275 assert (!_capturing_processor->display_to_user ());
4276 new_processors.push_front (_capturing_processor);
4279 _processors = new_processors;
4281 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4282 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4283 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4290 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4291 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4295 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4296 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4303 /** If the meter point is `Custom', make a note of where the meter is.
4304 * This is so that if the meter point is subsequently set to something else,
4305 * and then back to custom, we can put the meter back where it was last time
4306 * custom was enabled.
4308 * Must be called with the _processor_lock held.
4311 Route::maybe_note_meter_position ()
4313 if (_meter_point != MeterCustom) {
4317 _custom_meter_position_noted = true;
4318 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4319 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4320 ProcessorList::iterator j = i;
4322 if (j != _processors.end ()) {
4323 _processor_after_last_custom_meter = *j;
4324 _last_custom_meter_was_at_end = false;
4326 _last_custom_meter_was_at_end = true;
4332 boost::shared_ptr<Processor>
4333 Route::processor_by_id (PBD::ID id) const
4335 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4336 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4337 if ((*i)->id() == id) {
4342 return boost::shared_ptr<Processor> ();
4345 /** @return the monitoring state, or in other words what data we are pushing
4346 * into the route (data from the inputs, data from disk or silence)
4349 Route::monitoring_state () const
4351 return MonitoringInput;
4354 /** @return what we should be metering; either the data coming from the input
4355 * IO or the data that is flowing through the route.
4358 Route::metering_state () const
4360 return MeteringRoute;
4364 Route::has_external_redirects () const
4366 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4368 /* ignore inactive processors and obviously ignore the main
4369 * outs since everything has them and we don't care.
4372 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4380 boost::shared_ptr<Processor>
4381 Route::the_instrument () const
4383 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4384 return the_instrument_unlocked ();
4387 boost::shared_ptr<Processor>
4388 Route::the_instrument_unlocked () const
4390 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4391 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4392 if ((*i)->input_streams().n_midi() > 0 &&
4393 (*i)->output_streams().n_audio() > 0) {
4398 return boost::shared_ptr<Processor>();
4404 Route::non_realtime_locate (framepos_t pos)
4407 _pannable->transport_located (pos);
4410 if (_delayline.get()) {
4411 _delayline.get()->flush();
4415 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4416 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4418 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4419 (*i)->transport_located (pos);
4425 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4432 * We don't currently mix MIDI input together, so we don't need the
4433 * complex logic of the audio case.
4436 n_buffers = bufs.count().n_midi ();
4438 for (i = 0; i < n_buffers; ++i) {
4440 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4441 MidiBuffer& buf (bufs.get_midi (i));
4444 buf.copy (source_port->get_midi_buffer(nframes));
4446 buf.silence (nframes);
4452 n_buffers = bufs.count().n_audio();
4454 size_t n_ports = io->n_ports().n_audio();
4455 float scaling = 1.0f;
4457 if (n_ports > n_buffers) {
4458 scaling = ((float) n_buffers) / n_ports;
4461 for (i = 0; i < n_ports; ++i) {
4463 /* if there are more ports than buffers, map them onto buffers
4464 * in a round-robin fashion
4467 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4468 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4471 if (i < n_buffers) {
4473 /* first time through just copy a channel into
4477 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4479 if (scaling != 1.0f) {
4480 buf.apply_gain (scaling, nframes);
4485 /* on subsequent times around, merge data from
4486 * the port with what is already there
4489 if (scaling != 1.0f) {
4490 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4492 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4497 /* silence any remaining buffers */
4499 for (; i < n_buffers; ++i) {
4500 AudioBuffer& buf (bufs.get_audio (i));
4501 buf.silence (nframes);
4504 /* establish the initial setup of the buffer set, reflecting what was
4505 copied into it. unless, of course, we are the auditioner, in which
4506 case nothing was fed into it from the inputs at all.
4509 if (!is_auditioner()) {
4510 bufs.set_count (io->n_ports());