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_port.h"
41 #include "ardour/audioengine.h"
42 #include "ardour/buffer.h"
43 #include "ardour/buffer_set.h"
44 #include "ardour/capturing_processor.h"
45 #include "ardour/debug.h"
46 #include "ardour/delivery.h"
47 #include "ardour/internal_return.h"
48 #include "ardour/internal_send.h"
49 #include "ardour/meter.h"
50 #include "ardour/delayline.h"
51 #include "ardour/midi_buffer.h"
52 #include "ardour/midi_port.h"
53 #include "ardour/monitor_processor.h"
54 #include "ardour/pannable.h"
55 #include "ardour/panner.h"
56 #include "ardour/panner_shell.h"
57 #include "ardour/plugin_insert.h"
58 #include "ardour/port.h"
59 #include "ardour/port_insert.h"
60 #include "ardour/processor.h"
61 #include "ardour/route.h"
62 #include "ardour/route_group.h"
63 #include "ardour/send.h"
64 #include "ardour/session.h"
65 #include "ardour/unknown_processor.h"
66 #include "ardour/utils.h"
71 using namespace ARDOUR;
74 PBD::Signal0<void> Route::SyncOrderKeys;
75 PBD::Signal0<void> Route::RemoteControlIDChange;
77 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
78 : SessionObject (sess, name)
80 , GraphNode (sess._process_graph)
83 , _signal_latency_at_amp_position (0)
86 , _declicked_silent (true)
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);
161 /* create standard processors: meter, main outs, monitor out;
162 they will be added to _processors by setup_invisible_processors ()
165 _meter.reset (new PeakMeter (_session, _name));
166 _meter->set_owner (this);
167 _meter->set_display_to_user (false);
170 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
171 _main_outs->activate ();
174 /* where we listen to tracks */
175 _intreturn.reset (new InternalReturn (_session));
176 _intreturn->activate ();
178 /* the thing that provides proper control over a control/monitor/listen bus
179 (such as per-channel cut, dim, solo, invert, etc).
181 _monitor_control.reset (new MonitorProcessor (_session));
182 _monitor_control->activate ();
185 if (is_master() || is_monitor() || is_auditioner()) {
186 _mute_master->set_solo_ignore (true);
189 /* now that we have _meter, its safe to connect to this */
191 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
194 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
195 configure_processors (0);
203 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
205 /* do this early so that we don't get incoming signals as we are going through destruction
210 /* don't use clear_processors here, as it depends on the session which may
211 be half-destroyed by now
214 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
215 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
216 (*i)->drop_references ();
219 _processors.clear ();
223 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
225 if (Config->get_remote_model() != UserOrdered) {
229 set_remote_control_id_internal (id, notify_class_listeners);
233 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
235 /* force IDs for master/monitor busses and prevent
236 any other route from accidentally getting these IDs
237 (i.e. legacy sessions)
240 if (is_master() && id != MasterBusRemoteControlID) {
241 id = MasterBusRemoteControlID;
244 if (is_monitor() && id != MonitorBusRemoteControlID) {
245 id = MonitorBusRemoteControlID;
252 /* don't allow it to collide */
254 if (!is_master () && !is_monitor() &&
255 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
256 id += MonitorBusRemoteControlID;
259 if (id != remote_control_id()) {
260 _remote_control_id = id;
261 RemoteControlIDChanged ();
263 if (notify_class_listeners) {
264 RemoteControlIDChange ();
270 Route::remote_control_id() const
273 return MasterBusRemoteControlID;
277 return MonitorBusRemoteControlID;
280 return _remote_control_id;
284 Route::has_order_key () const
286 return _has_order_key;
290 Route::order_key () const
296 Route::set_remote_control_id_explicit (uint32_t rid)
298 if (is_master() || is_monitor() || is_auditioner()) {
299 /* hard-coded remote IDs, or no remote ID */
303 if (_remote_control_id != rid) {
304 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
305 _remote_control_id = rid;
306 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
309 /* don't emit the class-level RID signal RemoteControlIDChange here,
310 leave that to the entity that changed the order key, so that we
311 don't get lots of emissions for no good reasons (e.g. when changing
312 all route order keys).
314 See Session::sync_remote_id_from_order_keys() for the (primary|only)
315 spot where that is emitted.
320 Route::set_order_key (uint32_t n)
322 _has_order_key = true;
324 if (_order_key == n) {
330 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
331 name(), order_key ()));
333 _session.set_dirty ();
337 Route::ensure_track_or_route_name(string name, Session &session)
339 string newname = name;
341 while (!session.io_name_is_legal (newname)) {
342 newname = bump_name_once (newname, '.');
350 Route::inc_gain (gain_t fraction, void *src)
352 _amp->inc_gain (fraction, src);
356 Route::set_gain (gain_t val, void *src)
358 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
360 if (_route_group->is_relative()) {
362 gain_t usable_gain = _amp->gain();
363 if (usable_gain < 0.000001f) {
364 usable_gain = 0.000001f;
368 if (delta < 0.000001f) {
372 delta -= usable_gain;
377 gain_t factor = delta / usable_gain;
380 factor = _route_group->get_max_factor(factor);
381 if (factor == 0.0f) {
382 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
386 factor = _route_group->get_min_factor(factor);
387 if (factor == 0.0f) {
388 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
393 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
397 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
403 if (val == _amp->gain()) {
407 _amp->set_gain (val, src);
411 Route::maybe_declick (BufferSet&, framecnt_t, int)
413 /* this is the "bus" implementation and they never declick.
418 /** Process this route for one (sub) cycle (process thread)
420 * @param bufs Scratch buffers to use for the signal path
421 * @param start_frame Initial transport frame
422 * @param end_frame Final transport frame
423 * @param nframes Number of frames to output (to ports)
425 * Note that (end_frame - start_frame) may not be equal to nframes when the
426 * transport speed isn't 1.0 (eg varispeed).
429 Route::process_output_buffers (BufferSet& bufs,
430 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
431 int declick, bool gain_automation_ok)
433 /* Caller must hold process lock */
434 assert (!AudioEngine::instance()->process_lock().trylock());
436 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
438 bufs.silence (nframes, 0);
442 /* figure out if we're going to use gain automation */
443 if (gain_automation_ok) {
444 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
445 _amp->setup_gain_automation (
446 start_frame + _signal_latency_at_amp_position,
447 end_frame + _signal_latency_at_amp_position,
450 _amp->apply_gain_automation (false);
453 /* Tell main outs what to do about monitoring. We do this so that
454 on a transition between monitoring states we get a de-clicking gain
455 change in the _main_outs delivery.
457 bool silence = monitoring_state () == MonitoringSilence;
459 //but we override this in the case where we have an internal generator
460 if ( _have_internal_generator )
463 _main_outs->no_outs_cuz_we_no_monitor (silence);
465 /* -------------------------------------------------------------------------------------------
466 GLOBAL DECLICK (for transport changes etc.)
467 ----------------------------------------------------------------------------------------- */
469 if (_declickable && _declicked_silent && declick <= 0) {
470 bufs.silence (nframes, 0);
473 maybe_declick (bufs, nframes, declick);
476 _declicked_silent = true;
478 else if (declick > 0) {
479 _declicked_silent = false;
481 _pending_declick = 0;
483 /* -------------------------------------------------------------------------------------------
484 DENORMAL CONTROL/PHASE INVERT
485 ----------------------------------------------------------------------------------------- */
487 if (_phase_invert.any ()) {
491 if (_denormal_protection || Config->get_denormal_protection()) {
493 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
494 Sample* const sp = i->data();
496 if (_phase_invert[chn]) {
497 for (pframes_t nx = 0; nx < nframes; ++nx) {
502 for (pframes_t nx = 0; nx < nframes; ++nx) {
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) {
523 if (_denormal_protection || Config->get_denormal_protection()) {
525 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
526 Sample* const sp = i->data();
527 for (pframes_t nx = 0; nx < nframes; ++nx) {
535 /* -------------------------------------------------------------------------------------------
537 ----------------------------------------------------------------------------------------- */
539 /* set this to be true if the meter will already have been ::run() earlier */
540 bool const meter_already_run = metering_state() == MeteringInput;
542 framecnt_t latency = 0;
544 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
546 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
547 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
552 /* if it has any inputs, make sure they match */
553 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
554 if (bufs.count() != (*i)->input_streams()) {
556 DEBUG::Processors, string_compose (
557 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
558 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
565 /* should we NOT run plugins here if the route is inactive?
566 do we catch route != active somewhere higher?
569 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
570 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
573 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
574 bufs.set_count ((*i)->output_streams());
576 if ((*i)->active ()) {
577 latency += (*i)->signal_latency ();
583 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
584 boost::shared_ptr<Processor> endpoint,
585 bool include_endpoint, bool for_export, bool for_freeze)
587 /* If no processing is required, there's no need to go any further. */
588 if (!endpoint && !include_endpoint) {
592 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
593 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
594 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
597 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
599 if (!include_endpoint && (*i) == endpoint) {
603 /* if we're not exporting, stop processing if we come across a routing processor. */
604 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
607 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
611 /* don't run any processors that does routing.
612 * oh, and don't bother with the peak meter either.
614 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
615 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
616 buffers.set_count ((*i)->output_streams());
617 latency += (*i)->signal_latency ();
620 if ((*i) == endpoint) {
627 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
628 bool include_endpoint, bool for_export, bool for_freeze) const
630 framecnt_t latency = 0;
631 if (!endpoint && !include_endpoint) {
635 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
636 if (!include_endpoint && (*i) == endpoint) {
639 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
642 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
645 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
646 latency += (*i)->signal_latency ();
648 if ((*i) == endpoint) {
656 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
657 bool include_endpoint, bool for_export, bool for_freeze) const
659 if (!endpoint && !include_endpoint) {
663 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
664 if (!include_endpoint && (*i) == endpoint) {
667 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
670 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
673 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
674 cc = (*i)->output_streams();
676 if ((*i) == endpoint) {
684 Route::n_process_buffers ()
686 return max (_input->n_ports(), processor_max_streams);
690 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
692 assert (is_monitor());
693 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
694 fill_buffers_with_input (bufs, _input, nframes);
695 passthru (bufs, start_frame, end_frame, nframes, declick);
699 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
703 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
705 /* control/monitor bus ignores input ports when something is
706 feeding the listen "stream". data will "arrive" into the
707 route from the intreturn processor element.
710 bufs.silence (nframes, 0);
713 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
714 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
718 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
720 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
722 bufs.set_count (_input->n_ports());
723 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
724 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
728 Route::set_listen (bool yn, void* src)
734 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
735 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
740 if (yn != _monitor_send->active()) {
742 _monitor_send->activate ();
743 _mute_master->set_soloed (true);
745 _monitor_send->deactivate ();
746 _mute_master->set_soloed (false);
749 listen_changed (src); /* EMIT SIGNAL */
755 Route::listening_via_monitor () const
758 return _monitor_send->active ();
765 Route::set_solo_safe (bool yn, void *src)
767 if (_solo_safe != yn) {
769 solo_safe_changed (src);
774 Route::solo_safe() const
780 Route::set_solo (bool yn, void *src)
783 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
787 if (is_master() || is_monitor() || is_auditioner()) {
788 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
792 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
793 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
797 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
798 name(), yn, src, (src == _route_group), self_soloed()));
800 if (self_soloed() != yn) {
802 set_mute_master_solo ();
803 solo_changed (true, src); /* EMIT SIGNAL */
804 _solo_control->Changed (); /* EMIT SIGNAL */
809 Route::set_self_solo (bool yn)
811 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
816 Route::mod_solo_by_others_upstream (int32_t delta)
819 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-upstream due to solo-safe\n", name()));
823 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
824 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
826 uint32_t old_sbu = _soloed_by_others_upstream;
829 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
830 _soloed_by_others_upstream += delta;
832 _soloed_by_others_upstream = 0;
835 _soloed_by_others_upstream += delta;
838 DEBUG_TRACE (DEBUG::Solo, string_compose (
839 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
840 name(), delta, _soloed_by_others_upstream, old_sbu,
841 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
843 /* push the inverse solo change to everything that feeds us.
845 This is important for solo-within-group. When we solo 1 track out of N that
846 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
847 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
848 tracks that feed it. This will silence them if they were audible because
849 of a bus solo, but the newly soloed track will still be audible (because
852 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
856 if ((_self_solo || _soloed_by_others_downstream) &&
857 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
858 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
860 if (delta > 0 || !Config->get_exclusive_solo()) {
861 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
862 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
863 boost::shared_ptr<Route> sr = i->r.lock();
865 sr->mod_solo_by_others_downstream (-delta);
871 set_mute_master_solo ();
872 solo_changed (false, this);
876 Route::mod_solo_by_others_downstream (int32_t delta)
879 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-downstream due to solo safe\n", name()));
883 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
884 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
887 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
888 _soloed_by_others_downstream += delta;
890 _soloed_by_others_downstream = 0;
893 _soloed_by_others_downstream += delta;
896 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
898 set_mute_master_solo ();
899 solo_changed (false, this);
903 Route::set_mute_master_solo ()
905 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
909 Route::set_solo_isolated (bool yn, void *src)
911 if (is_master() || is_monitor() || is_auditioner()) {
915 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
916 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
920 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
922 boost::shared_ptr<RouteList> routes = _session.get_routes ();
923 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
925 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
930 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
932 if (does_feed && !sends_only) {
933 (*i)->set_solo_isolated (yn, (*i)->route_group());
937 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
939 bool changed = false;
942 if (_solo_isolated == 0) {
943 _mute_master->set_solo_ignore (true);
948 if (_solo_isolated > 0) {
950 if (_solo_isolated == 0) {
951 _mute_master->set_solo_ignore (false);
958 solo_isolated_changed (src);
963 Route::solo_isolated () const
965 return _solo_isolated > 0;
969 Route::set_mute_points (MuteMaster::MutePoint mp)
971 _mute_master->set_mute_points (mp);
972 mute_points_changed (); /* EMIT SIGNAL */
974 if (_mute_master->muted_by_self()) {
975 mute_changed (this); /* EMIT SIGNAL */
976 _mute_control->Changed (); /* EMIT SIGNAL */
981 Route::set_mute (bool yn, void *src)
983 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
984 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
989 _mute_master->set_muted_by_self (yn);
990 /* allow any derived classes to respond to the mute change
991 before anybody else knows about it.
994 /* tell everyone else */
995 mute_changed (src); /* EMIT SIGNAL */
996 _mute_control->Changed (); /* EMIT SIGNAL */
1001 Route::muted () const
1003 return _mute_master->muted_by_self();
1008 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1010 cerr << name << " {" << endl;
1011 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1012 p != procs.end(); ++p) {
1013 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1015 cerr << "}" << endl;
1019 /** Supposing that we want to insert a Processor at a given Placement, return
1020 * the processor to add the new one before (or 0 to add at the end).
1022 boost::shared_ptr<Processor>
1023 Route::before_processor_for_placement (Placement p)
1025 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1027 ProcessorList::iterator loc;
1029 if (p == PreFader) {
1030 /* generic pre-fader: insert immediately before the amp */
1031 loc = find (_processors.begin(), _processors.end(), _amp);
1033 /* generic post-fader: insert right before the main outs */
1034 loc = find (_processors.begin(), _processors.end(), _main_outs);
1037 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1040 /** Supposing that we want to insert a Processor at a given index, return
1041 * the processor to add the new one before (or 0 to add at the end).
1043 boost::shared_ptr<Processor>
1044 Route::before_processor_for_index (int index)
1047 return boost::shared_ptr<Processor> ();
1050 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1052 ProcessorList::iterator i = _processors.begin ();
1054 while (i != _processors.end() && j < index) {
1055 if ((*i)->display_to_user()) {
1062 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1065 /** Add a processor either pre- or post-fader
1066 * @return 0 on success, non-0 on failure.
1069 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1071 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1075 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1076 * @param index Index to add the processor at, or -1 to add at the end of the list.
1077 * @return 0 on success, non-0 on failure.
1080 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1082 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1085 /** Add a processor to the route.
1086 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1087 * @return 0 on success, non-0 on failure.
1090 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1092 assert (processor != _meter);
1093 assert (processor != _main_outs);
1095 DEBUG_TRACE (DEBUG::Processors, string_compose (
1096 "%1 adding processor %2\n", name(), processor->name()));
1098 if (!AudioEngine::instance()->connected() || !processor) {
1103 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1104 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1105 ProcessorState pstate (this);
1107 boost::shared_ptr<PluginInsert> pi;
1108 boost::shared_ptr<PortInsert> porti;
1110 if (processor == _amp) {
1111 /* Ensure that only one amp is in the list at any time */
1112 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1113 if (check != _processors.end()) {
1114 if (before == _amp) {
1115 /* Already in position; all is well */
1118 _processors.erase (check);
1123 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1125 ProcessorList::iterator loc;
1127 /* inserting before a processor; find it */
1128 loc = find (_processors.begin(), _processors.end(), before);
1129 if (loc == _processors.end ()) {
1134 /* inserting at end */
1135 loc = _processors.end ();
1138 _processors.insert (loc, processor);
1139 processor->set_owner (this);
1141 // Set up processor list channels. This will set processor->[input|output]_streams(),
1142 // configure redirect ports properly, etc.
1145 if (configure_processors_unlocked (err)) {
1147 configure_processors_unlocked (0); // it worked before we tried to add it ...
1152 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1154 if (pi->has_no_inputs ()) {
1155 /* generator plugin */
1156 _have_internal_generator = true;
1161 if (activation_allowed && !_session.get_disable_all_loaded_plugins()) {
1162 processor->activate ();
1165 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1167 _output->set_user_latency (0);
1170 reset_instrument_info ();
1171 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1172 set_processor_positions ();
1178 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1180 const XMLProperty *prop;
1183 boost::shared_ptr<Processor> processor;
1185 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1186 so that we can add the processor in the right place (pre/post-fader)
1189 XMLNodeList const & children = node.children ();
1190 XMLNodeList::const_iterator i = children.begin ();
1192 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1196 Placement placement = PreFader;
1198 if (i != children.end()) {
1199 if ((prop = (*i)->property (X_("placement"))) != 0) {
1200 placement = Placement (string_2_enum (prop->value(), placement));
1204 if (node.name() == "Insert") {
1206 if ((prop = node.property ("type")) != 0) {
1208 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1209 prop->value() == "lv2" ||
1210 prop->value() == "windows-vst" ||
1211 prop->value() == "lxvst" ||
1212 prop->value() == "audiounit") {
1214 processor.reset (new PluginInsert (_session));
1218 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1223 } else if (node.name() == "Send") {
1225 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1226 processor.reset (new Send (_session, sendpan, _mute_master));
1230 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1234 if (processor->set_state (node, version)) {
1238 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1239 if (i != children.end()) {
1240 if ((prop = (*i)->property (X_("active"))) != 0) {
1241 if ( string_is_affirmative (prop->value()) && !_session.get_disable_all_loaded_plugins() )
1242 processor->activate();
1244 processor->deactivate();
1248 return (add_processor (processor, placement, 0, false) == 0);
1251 catch (failed_constructor &err) {
1252 warning << _("processor could not be created. Ignored.") << endmsg;
1258 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1260 /* NOTE: this is intended to be used ONLY when copying
1261 processors from another Route. Hence the subtle
1262 differences between this and ::add_processor()
1265 ProcessorList::iterator loc;
1268 loc = find(_processors.begin(), _processors.end(), before);
1270 /* nothing specified - at end */
1271 loc = _processors.end ();
1274 if (!_session.engine().connected()) {
1278 if (others.empty()) {
1283 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1284 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1285 ProcessorState pstate (this);
1287 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1293 boost::shared_ptr<PluginInsert> pi;
1295 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1299 _processors.insert (loc, *i);
1300 (*i)->set_owner (this);
1302 if ((*i)->active()) {
1306 /* Think: does this really need to be called for every processor in the loop? */
1308 if (configure_processors_unlocked (err)) {
1310 configure_processors_unlocked (0); // it worked before we tried to add it ...
1315 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1318 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1319 boost::shared_ptr<PluginInsert> pi;
1321 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1322 if (pi->has_no_inputs ()) {
1323 _have_internal_generator = true;
1329 _output->set_user_latency (0);
1332 reset_instrument_info ();
1333 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1334 set_processor_positions ();
1340 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1342 if (p == PreFader) {
1343 start = _processors.begin();
1344 end = find(_processors.begin(), _processors.end(), _amp);
1346 start = find(_processors.begin(), _processors.end(), _amp);
1348 end = _processors.end();
1352 /** Turn off all processors with a given placement
1353 * @param p Placement of processors to disable
1356 Route::disable_processors (Placement p)
1358 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1360 ProcessorList::iterator start, end;
1361 placement_range(p, start, end);
1363 for (ProcessorList::iterator i = start; i != end; ++i) {
1364 (*i)->deactivate ();
1367 _session.set_dirty ();
1370 /** Turn off all redirects
1373 Route::disable_processors ()
1375 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1377 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1378 (*i)->deactivate ();
1381 _session.set_dirty ();
1384 /** Turn off all redirects with a given placement
1385 * @param p Placement of redirects to disable
1388 Route::disable_plugins (Placement p)
1390 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1392 ProcessorList::iterator start, end;
1393 placement_range(p, start, end);
1395 for (ProcessorList::iterator i = start; i != end; ++i) {
1396 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1397 (*i)->deactivate ();
1401 _session.set_dirty ();
1404 /** Turn off all plugins
1407 Route::disable_plugins ()
1409 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1411 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1412 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1413 (*i)->deactivate ();
1417 _session.set_dirty ();
1422 Route::ab_plugins (bool forward)
1424 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1428 /* forward = turn off all active redirects, and mark them so that the next time
1429 we go the other way, we will revert them
1432 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1433 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1437 if ((*i)->active()) {
1438 (*i)->deactivate ();
1439 (*i)->set_next_ab_is_active (true);
1441 (*i)->set_next_ab_is_active (false);
1447 /* backward = if the redirect was marked to go active on the next ab, do so */
1449 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1451 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1455 if ((*i)->get_next_ab_is_active()) {
1458 (*i)->deactivate ();
1463 _session.set_dirty ();
1467 /** Remove processors with a given placement.
1468 * @param p Placement of processors to remove.
1471 Route::clear_processors (Placement p)
1473 if (!_session.engine().connected()) {
1477 bool already_deleting = _session.deletion_in_progress();
1478 if (!already_deleting) {
1479 _session.set_deletion_in_progress();
1483 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1484 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1485 ProcessorList new_list;
1486 ProcessorStreams err;
1487 bool seen_amp = false;
1489 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1495 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline) {
1497 /* you can't remove these */
1499 new_list.push_back (*i);
1506 new_list.push_back (*i);
1509 (*i)->drop_references ();
1517 (*i)->drop_references ();
1520 new_list.push_back (*i);
1527 _processors = new_list;
1528 configure_processors_unlocked (&err); // this can't fail
1531 processor_max_streams.reset();
1532 _have_internal_generator = false;
1533 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1534 set_processor_positions ();
1536 reset_instrument_info ();
1538 if (!already_deleting) {
1539 _session.clear_deletion_in_progress();
1544 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1546 // TODO once the export point can be configured properly, do something smarter here
1547 if (processor == _capturing_processor) {
1548 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1549 if (need_process_lock) {
1553 _capturing_processor.reset();
1555 if (need_process_lock) {
1560 /* these can never be removed */
1562 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1566 if (!_session.engine().connected()) {
1570 processor_max_streams.reset();
1573 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1574 if (need_process_lock) {
1578 /* Caller must hold process lock */
1579 assert (!AudioEngine::instance()->process_lock().trylock());
1581 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1583 ProcessorState pstate (this);
1585 ProcessorList::iterator i;
1586 bool removed = false;
1588 for (i = _processors.begin(); i != _processors.end(); ) {
1589 if (*i == processor) {
1591 /* move along, see failure case for configure_processors()
1592 where we may need to reconfigure the processor.
1595 /* stop redirects that send signals to JACK ports
1596 from causing noise as a result of no longer being
1600 boost::shared_ptr<IOProcessor> iop;
1602 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1606 i = _processors.erase (i);
1614 _output->set_user_latency (0);
1622 if (configure_processors_unlocked (err)) {
1624 /* we know this will work, because it worked before :) */
1625 configure_processors_unlocked (0);
1629 _have_internal_generator = false;
1631 for (i = _processors.begin(); i != _processors.end(); ++i) {
1632 boost::shared_ptr<PluginInsert> pi;
1634 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1635 if (pi->has_no_inputs ()) {
1636 _have_internal_generator = true;
1641 if (need_process_lock) {
1646 reset_instrument_info ();
1647 processor->drop_references ();
1648 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1649 set_processor_positions ();
1655 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1657 ProcessorList deleted;
1659 if (!_session.engine().connected()) {
1663 processor_max_streams.reset();
1666 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1667 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1668 ProcessorState pstate (this);
1670 ProcessorList::iterator i;
1671 boost::shared_ptr<Processor> processor;
1673 for (i = _processors.begin(); i != _processors.end(); ) {
1677 /* these can never be removed */
1679 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1684 /* see if its in the list of processors to delete */
1686 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1691 /* stop IOProcessors that send to JACK ports
1692 from causing noise as a result of no longer being
1696 boost::shared_ptr<IOProcessor> iop;
1698 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1702 deleted.push_back (processor);
1703 i = _processors.erase (i);
1706 if (deleted.empty()) {
1707 /* none of those in the requested list were found */
1711 _output->set_user_latency (0);
1713 if (configure_processors_unlocked (err)) {
1715 /* we know this will work, because it worked before :) */
1716 configure_processors_unlocked (0);
1721 _have_internal_generator = false;
1723 for (i = _processors.begin(); i != _processors.end(); ++i) {
1724 boost::shared_ptr<PluginInsert> pi;
1726 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1727 if (pi->has_no_inputs ()) {
1728 _have_internal_generator = true;
1735 /* now try to do what we need to so that those that were removed will be deleted */
1737 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1738 (*i)->drop_references ();
1741 reset_instrument_info ();
1742 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1743 set_processor_positions ();
1749 Route::reset_instrument_info ()
1751 boost::shared_ptr<Processor> instr = the_instrument();
1753 _instrument_info.set_internal_instrument (instr);
1757 /** Caller must hold process lock */
1759 Route::configure_processors (ProcessorStreams* err)
1761 #ifndef PLATFORM_WINDOWS
1762 assert (!AudioEngine::instance()->process_lock().trylock());
1765 if (!_in_configure_processors) {
1766 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1767 return configure_processors_unlocked (err);
1774 Route::input_streams () const
1776 return _input->n_ports ();
1779 list<pair<ChanCount, ChanCount> >
1780 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1782 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1784 return try_configure_processors_unlocked (in, err);
1787 list<pair<ChanCount, ChanCount> >
1788 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1790 // Check each processor in order to see if we can configure as requested
1792 list<pair<ChanCount, ChanCount> > configuration;
1795 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1796 DEBUG_TRACE (DEBUG::Processors, "{\n");
1798 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1800 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1801 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1802 DEBUG_TRACE (DEBUG::Processors, "}\n");
1803 return list<pair<ChanCount, ChanCount> > ();
1806 if ((*p)->can_support_io_configuration(in, out)) {
1807 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1808 configuration.push_back(make_pair(in, out));
1815 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1816 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1817 DEBUG_TRACE (DEBUG::Processors, "}\n");
1818 return list<pair<ChanCount, ChanCount> > ();
1822 DEBUG_TRACE (DEBUG::Processors, "}\n");
1824 return configuration;
1827 /** Set the input/output configuration of each processor in the processors list.
1828 * Caller must hold process lock.
1829 * Return 0 on success, otherwise configuration is impossible.
1832 Route::configure_processors_unlocked (ProcessorStreams* err)
1834 #ifndef PLATFORM_WINDOWS
1835 assert (!AudioEngine::instance()->process_lock().trylock());
1838 if (_in_configure_processors) {
1842 /* put invisible processors where they should be */
1843 setup_invisible_processors ();
1845 _in_configure_processors = true;
1847 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1849 if (configuration.empty ()) {
1850 _in_configure_processors = false;
1855 bool seen_mains_out = false;
1856 processor_out_streams = _input->n_ports();
1857 processor_max_streams.reset();
1859 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1860 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1862 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1866 (*p)->configure_io(c->first, c->second);
1867 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1868 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1871 if (boost::dynamic_pointer_cast<Delivery> (*p)
1872 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1873 /* main delivery will increase port count to match input.
1874 * the Delivery::Main is usually the last processor - followed only by
1877 seen_mains_out = true;
1879 if (!seen_mains_out) {
1880 processor_out_streams = out;
1886 _meter->reset_max_channels (processor_max_streams);
1889 /* make sure we have sufficient scratch buffers to cope with the new processor
1892 _session.ensure_buffers (n_process_buffers ());
1894 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1896 _in_configure_processors = false;
1900 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1901 * @param state New active state for those processors.
1904 Route::all_visible_processors_active (bool state)
1906 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1908 if (_processors.empty()) {
1912 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1913 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1920 (*i)->deactivate ();
1924 _session.set_dirty ();
1928 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1930 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1931 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1932 processors in the current actual processor list that are hidden. Any visible processors
1933 in the current list but not in "new_order" will be assumed to be deleted.
1937 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1938 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1939 ProcessorState pstate (this);
1941 ProcessorList::iterator oiter;
1942 ProcessorList::const_iterator niter;
1943 ProcessorList as_it_will_be;
1945 oiter = _processors.begin();
1946 niter = new_order.begin();
1948 while (niter != new_order.end()) {
1950 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1951 then append it to the temp list.
1953 Otherwise, see if the next processor in the old list is in the new list. if not,
1954 its been deleted. If its there, append it to the temp list.
1957 if (oiter == _processors.end()) {
1959 /* no more elements in the old list, so just stick the rest of
1960 the new order onto the temp list.
1963 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1964 while (niter != new_order.end()) {
1971 if (!(*oiter)->display_to_user()) {
1973 as_it_will_be.push_back (*oiter);
1977 /* visible processor: check that its in the new order */
1979 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1980 /* deleted: do nothing, shared_ptr<> will clean up */
1982 /* ignore this one, and add the next item from the new order instead */
1983 as_it_will_be.push_back (*niter);
1988 /* now remove from old order - its taken care of no matter what */
1989 oiter = _processors.erase (oiter);
1994 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1996 /* If the meter is in a custom position, find it and make a rough note of its position */
1997 maybe_note_meter_position ();
1999 if (configure_processors_unlocked (err)) {
2005 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2006 set_processor_positions ();
2018 Route::get_template()
2020 return state(false);
2024 Route::state(bool full_state)
2026 XMLNode *node = new XMLNode("Route");
2027 ProcessorList::iterator i;
2030 id().print (buf, sizeof (buf));
2031 node->add_property("id", buf);
2032 node->add_property ("name", _name);
2033 node->add_property("default-type", _default_type.to_string());
2036 node->add_property("flags", enum_2_string (_flags));
2039 node->add_property("active", _active?"yes":"no");
2041 boost::to_string (_phase_invert, p);
2042 node->add_property("phase-invert", p);
2043 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2044 node->add_property("meter-point", enum_2_string (_meter_point));
2046 node->add_property("meter-type", enum_2_string (_meter_type));
2049 node->add_property("route-group", _route_group->name());
2052 snprintf (buf, sizeof (buf), "%d", _order_key);
2053 node->add_property ("order-key", buf);
2054 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2055 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2056 node->add_property ("soloed-by-upstream", buf);
2057 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2058 node->add_property ("soloed-by-downstream", buf);
2059 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2060 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2062 node->add_child_nocopy (_input->state (full_state));
2063 node->add_child_nocopy (_output->state (full_state));
2064 node->add_child_nocopy (_solo_control->get_state ());
2065 node->add_child_nocopy (_mute_control->get_state ());
2066 node->add_child_nocopy (_mute_master->get_state ());
2069 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2072 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2073 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2074 remote_control_node->add_property (X_("id"), buf);
2075 node->add_child_nocopy (*remote_control_node);
2077 if (_comment.length()) {
2078 XMLNode *cmt = node->add_child ("Comment");
2079 cmt->add_content (_comment);
2083 node->add_child_nocopy (_pannable->state (full_state));
2086 for (i = _processors.begin(); i != _processors.end(); ++i) {
2088 /* template save: do not include internal sends functioning as
2089 aux sends because the chance of the target ID
2090 in the session where this template is used
2093 similarly, do not save listen sends which connect to
2094 the monitor section, because these will always be
2097 boost::shared_ptr<InternalSend> is;
2099 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2100 if (is->role() == Delivery::Listen) {
2105 node->add_child_nocopy((*i)->state (full_state));
2109 node->add_child_copy (*_extra_xml);
2112 if (_custom_meter_position_noted) {
2113 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2115 after->id().print (buf, sizeof (buf));
2116 node->add_property (X_("processor-after-last-custom-meter"), buf);
2119 node->add_property (X_("last-custom-meter-was-at-end"), _last_custom_meter_was_at_end ? "yes" : "no");
2126 Route::set_state (const XMLNode& node, int version)
2128 if (version < 3000) {
2129 return set_state_2X (node, version);
2133 XMLNodeConstIterator niter;
2135 const XMLProperty *prop;
2137 if (node.name() != "Route"){
2138 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2142 if ((prop = node.property (X_("name"))) != 0) {
2143 Route::set_name (prop->value());
2147 _initial_io_setup = true;
2149 if ((prop = node.property (X_("flags"))) != 0) {
2150 _flags = Flag (string_2_enum (prop->value(), _flags));
2155 if (is_master() || is_monitor() || is_auditioner()) {
2156 _mute_master->set_solo_ignore (true);
2160 /* monitor bus does not get a panner, but if (re)created
2161 via XML, it will already have one by the time we
2162 call ::set_state(). so ... remove it.
2167 /* add all processors (except amp, which is always present) */
2169 nlist = node.children();
2170 XMLNode processor_state (X_("processor_state"));
2172 Stateful::save_extra_xml (node);
2174 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2178 if (child->name() == IO::state_node_name) {
2179 if ((prop = child->property (X_("direction"))) == 0) {
2183 if (prop->value() == "Input") {
2184 _input->set_state (*child, version);
2185 } else if (prop->value() == "Output") {
2186 _output->set_state (*child, version);
2190 if (child->name() == X_("Processor")) {
2191 processor_state.add_child_copy (*child);
2194 if (child->name() == X_("Pannable")) {
2196 _pannable->set_state (*child, version);
2198 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2203 if ((prop = node.property (X_("meter-point"))) != 0) {
2204 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2205 set_meter_point (mp, true);
2207 _meter->set_display_to_user (_meter_point == MeterCustom);
2211 if ((prop = node.property (X_("meter-type"))) != 0) {
2212 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2215 _initial_io_setup = false;
2217 set_processor_state (processor_state);
2219 // this looks up the internal instrument in processors
2220 reset_instrument_info();
2222 if ((prop = node.property ("self-solo")) != 0) {
2223 set_self_solo (string_is_affirmative (prop->value()));
2226 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2227 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2228 mod_solo_by_others_upstream (atoi (prop->value()));
2231 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2232 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2233 mod_solo_by_others_downstream (atoi (prop->value()));
2236 if ((prop = node.property ("solo-isolated")) != 0) {
2237 set_solo_isolated (string_is_affirmative (prop->value()), this);
2240 if ((prop = node.property ("solo-safe")) != 0) {
2241 set_solo_safe (string_is_affirmative (prop->value()), this);
2244 if ((prop = node.property (X_("phase-invert"))) != 0) {
2245 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2248 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2249 set_denormal_protection (string_is_affirmative (prop->value()));
2252 if ((prop = node.property (X_("active"))) != 0) {
2253 bool yn = string_is_affirmative (prop->value());
2254 _active = !yn; // force switch
2255 set_active (yn, this);
2258 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2259 set_order_key (atoi(prop->value()));
2262 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2266 string::size_type colon, equal;
2267 string remaining = prop->value();
2269 while (remaining.length()) {
2271 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2272 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2275 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2276 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2279 string keyname = remaining.substr (0, equal);
2281 if ((keyname == "EditorSort") || (keyname == "editor")) {
2282 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2288 colon = remaining.find_first_of (':');
2290 if (colon != string::npos) {
2291 remaining = remaining.substr (colon+1);
2298 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2299 PBD::ID id (prop->value ());
2300 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2301 ProcessorList::const_iterator i = _processors.begin ();
2302 while (i != _processors.end() && (*i)->id() != id) {
2306 if (i != _processors.end ()) {
2307 _processor_after_last_custom_meter = *i;
2308 _custom_meter_position_noted = true;
2312 if ((prop = node.property (X_("last-custom-meter-was-at-end"))) != 0) {
2313 _last_custom_meter_was_at_end = string_is_affirmative (prop->value ());
2316 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2319 if (child->name() == X_("Comment")) {
2321 /* XXX this is a terrible API design in libxml++ */
2323 XMLNode *cmt = *(child->children().begin());
2324 _comment = cmt->content();
2326 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2327 if (prop->value() == "solo") {
2328 _solo_control->set_state (*child, version);
2329 } else if (prop->value() == "mute") {
2330 _mute_control->set_state (*child, version);
2333 } else if (child->name() == X_("RemoteControl")) {
2334 if ((prop = child->property (X_("id"))) != 0) {
2336 sscanf (prop->value().c_str(), "%d", &x);
2337 set_remote_control_id_internal (x);
2340 } else if (child->name() == X_("MuteMaster")) {
2341 _mute_master->set_state (*child, version);
2343 } else if (child->name() == Automatable::xml_node_name) {
2344 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2352 Route::set_state_2X (const XMLNode& node, int version)
2354 LocaleGuard lg (X_("C"));
2356 XMLNodeConstIterator niter;
2358 const XMLProperty *prop;
2360 /* 2X things which still remain to be handled:
2366 if (node.name() != "Route") {
2367 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2371 if ((prop = node.property (X_("flags"))) != 0) {
2372 string f = prop->value ();
2373 boost::replace_all (f, "ControlOut", "MonitorOut");
2374 _flags = Flag (string_2_enum (f, _flags));
2379 if (is_master() || is_monitor() || is_auditioner()) {
2380 _mute_master->set_solo_ignore (true);
2383 if ((prop = node.property (X_("phase-invert"))) != 0) {
2384 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2385 if (string_is_affirmative (prop->value ())) {
2388 set_phase_invert (p);
2391 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2392 set_denormal_protection (string_is_affirmative (prop->value()));
2395 if ((prop = node.property (X_("soloed"))) != 0) {
2396 bool yn = string_is_affirmative (prop->value());
2398 /* XXX force reset of solo status */
2400 set_solo (yn, this);
2403 if ((prop = node.property (X_("muted"))) != 0) {
2406 bool muted = string_is_affirmative (prop->value());
2412 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2414 if (string_is_affirmative (prop->value())){
2415 mute_point = mute_point + "PreFader";
2420 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2422 if (string_is_affirmative (prop->value())){
2425 mute_point = mute_point + ",";
2428 mute_point = mute_point + "PostFader";
2433 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2435 if (string_is_affirmative (prop->value())){
2438 mute_point = mute_point + ",";
2441 mute_point = mute_point + "Listen";
2446 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2448 if (string_is_affirmative (prop->value())){
2451 mute_point = mute_point + ",";
2454 mute_point = mute_point + "Main";
2458 _mute_master->set_mute_points (mute_point);
2459 _mute_master->set_muted_by_self (true);
2463 if ((prop = node.property (X_("meter-point"))) != 0) {
2464 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2467 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2468 don't mean the same thing.
2471 if ((prop = node.property (X_("order-keys"))) != 0) {
2475 string::size_type colon, equal;
2476 string remaining = prop->value();
2478 while (remaining.length()) {
2480 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2481 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2484 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2485 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2488 string keyname = remaining.substr (0, equal);
2490 if (keyname == "EditorSort" || keyname == "editor") {
2491 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2497 colon = remaining.find_first_of (':');
2499 if (colon != string::npos) {
2500 remaining = remaining.substr (colon+1);
2509 nlist = node.children ();
2510 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2514 if (child->name() == IO::state_node_name) {
2516 /* there is a note in IO::set_state_2X() about why we have to call
2520 _input->set_state_2X (*child, version, true);
2521 _output->set_state_2X (*child, version, false);
2523 if ((prop = child->property (X_("name"))) != 0) {
2524 Route::set_name (prop->value ());
2529 if ((prop = child->property (X_("active"))) != 0) {
2530 bool yn = string_is_affirmative (prop->value());
2531 _active = !yn; // force switch
2532 set_active (yn, this);
2535 if ((prop = child->property (X_("gain"))) != 0) {
2538 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2539 _amp->gain_control()->set_value (val);
2543 /* Set up Panners in the IO */
2544 XMLNodeList io_nlist = child->children ();
2546 XMLNodeConstIterator io_niter;
2549 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2551 io_child = *io_niter;
2553 if (io_child->name() == X_("Panner")) {
2554 _main_outs->panner_shell()->set_state(*io_child, version);
2555 } else if (io_child->name() == X_("Automation")) {
2556 /* IO's automation is for the fader */
2557 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2563 XMLNodeList redirect_nodes;
2565 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2569 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2570 redirect_nodes.push_back(child);
2575 set_processor_state_2X (redirect_nodes, version);
2577 Stateful::save_extra_xml (node);
2579 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2582 if (child->name() == X_("Comment")) {
2584 /* XXX this is a terrible API design in libxml++ */
2586 XMLNode *cmt = *(child->children().begin());
2587 _comment = cmt->content();
2589 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2590 if (prop->value() == X_("solo")) {
2591 _solo_control->set_state (*child, version);
2592 } else if (prop->value() == X_("mute")) {
2593 _mute_control->set_state (*child, version);
2596 } else if (child->name() == X_("RemoteControl")) {
2597 if ((prop = child->property (X_("id"))) != 0) {
2599 sscanf (prop->value().c_str(), "%d", &x);
2600 set_remote_control_id_internal (x);
2610 Route::get_processor_state ()
2612 XMLNode* root = new XMLNode (X_("redirects"));
2613 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2614 root->add_child_nocopy ((*i)->state (true));
2621 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2623 /* We don't bother removing existing processors not in nList, as this
2624 method will only be called when creating a Route from scratch, not
2625 for undo purposes. Just put processors in at the appropriate place
2629 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2630 add_processor_from_xml_2X (**i, version);
2635 Route::set_processor_state (const XMLNode& node)
2637 const XMLNodeList &nlist = node.children();
2638 XMLNodeConstIterator niter;
2639 ProcessorList new_order;
2640 bool must_configure = false;
2642 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2644 XMLProperty* prop = (*niter)->property ("type");
2646 if (prop->value() == "amp") {
2647 _amp->set_state (**niter, Stateful::current_state_version);
2648 new_order.push_back (_amp);
2649 } else if (prop->value() == "meter") {
2650 _meter->set_state (**niter, Stateful::current_state_version);
2651 new_order.push_back (_meter);
2652 } else if (prop->value() == "delay") {
2654 _delayline->set_state (**niter, Stateful::current_state_version);
2655 new_order.push_back (_delayline);
2657 } else if (prop->value() == "main-outs") {
2658 _main_outs->set_state (**niter, Stateful::current_state_version);
2659 } else if (prop->value() == "intreturn") {
2661 _intreturn.reset (new InternalReturn (_session));
2662 must_configure = true;
2664 _intreturn->set_state (**niter, Stateful::current_state_version);
2665 } else if (is_monitor() && prop->value() == "monitor") {
2666 if (!_monitor_control) {
2667 _monitor_control.reset (new MonitorProcessor (_session));
2668 must_configure = true;
2670 _monitor_control->set_state (**niter, Stateful::current_state_version);
2671 } else if (prop->value() == "capture") {
2672 /* CapturingProcessor should never be restored, it's always
2673 added explicitly when needed */
2675 ProcessorList::iterator o;
2677 for (o = _processors.begin(); o != _processors.end(); ++o) {
2678 XMLProperty* id_prop = (*niter)->property(X_("id"));
2679 if (id_prop && (*o)->id() == id_prop->value()) {
2680 (*o)->set_state (**niter, Stateful::current_state_version);
2681 new_order.push_back (*o);
2686 // If the processor (*niter) is not on the route then create it
2688 if (o == _processors.end()) {
2690 boost::shared_ptr<Processor> processor;
2692 if (prop->value() == "intsend") {
2694 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2696 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2697 prop->value() == "lv2" ||
2698 prop->value() == "windows-vst" ||
2699 prop->value() == "lxvst" ||
2700 prop->value() == "audiounit") {
2702 processor.reset (new PluginInsert(_session));
2704 } else if (prop->value() == "port") {
2706 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2708 } else if (prop->value() == "send") {
2710 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2713 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2717 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2718 /* This processor could not be configured. Turn it into a UnknownProcessor */
2719 processor.reset (new UnknownProcessor (_session, **niter));
2722 /* we have to note the monitor send here, otherwise a new one will be created
2723 and the state of this one will be lost.
2725 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2726 if (isend && isend->role() == Delivery::Listen) {
2727 _monitor_send = isend;
2730 /* it doesn't matter if invisible processors are added here, as they
2731 will be sorted out by setup_invisible_processors () shortly.
2734 new_order.push_back (processor);
2735 must_configure = true;
2741 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2742 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2743 _processors = new_order;
2745 if (must_configure) {
2746 configure_processors_unlocked (0);
2749 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2751 (*i)->set_owner (this);
2752 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2754 boost::shared_ptr<PluginInsert> pi;
2756 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2757 if (pi->has_no_inputs ()) {
2758 _have_internal_generator = true;
2765 reset_instrument_info ();
2766 processors_changed (RouteProcessorChange ());
2767 set_processor_positions ();
2771 Route::curve_reallocate ()
2773 // _gain_automation_curve.finish_resize ();
2774 // _pan_automation_curve.finish_resize ();
2778 Route::silence (framecnt_t nframes)
2780 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2785 silence_unlocked (nframes);
2789 Route::silence_unlocked (framecnt_t nframes)
2791 /* Must be called with the processor lock held */
2795 _output->silence (nframes);
2797 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2798 boost::shared_ptr<PluginInsert> pi;
2800 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2801 // skip plugins, they don't need anything when we're not active
2805 (*i)->silence (nframes);
2808 if (nframes == _session.get_block_size()) {
2815 Route::add_internal_return ()
2818 _intreturn.reset (new InternalReturn (_session));
2819 add_processor (_intreturn, PreFader);
2824 Route::add_send_to_internal_return (InternalSend* send)
2826 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2828 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2829 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2832 return d->add_send (send);
2838 Route::remove_send_from_internal_return (InternalSend* send)
2840 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2842 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2843 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2846 return d->remove_send (send);
2852 Route::enable_monitor_send ()
2854 /* Caller must hold process lock */
2855 assert (!AudioEngine::instance()->process_lock().trylock());
2857 /* master never sends to monitor section via the normal mechanism */
2858 assert (!is_master ());
2859 assert (!is_monitor ());
2861 /* make sure we have one */
2862 if (!_monitor_send) {
2863 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
2864 _monitor_send->set_display_to_user (false);
2868 configure_processors (0);
2871 /** Add an aux send to a route.
2872 * @param route route to send to.
2873 * @param before Processor to insert before, or 0 to insert at the end.
2876 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2878 assert (route != _session.monitor_out ());
2881 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2883 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2885 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2887 if (d && d->target_route() == route) {
2888 /* already listening via the specified IO: do nothing */
2896 boost::shared_ptr<InternalSend> listener;
2899 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2900 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
2901 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
2904 add_processor (listener, before);
2906 } catch (failed_constructor& err) {
2914 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
2916 ProcessorStreams err;
2917 ProcessorList::iterator tmp;
2920 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
2922 /* have to do this early because otherwise processor reconfig
2923 * will put _monitor_send back in the list
2926 if (route == _session.monitor_out()) {
2927 _monitor_send.reset ();
2931 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2933 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2935 if (d && d->target_route() == route) {
2937 remove_processor (*x, &err, false);
2940 /* list could have been demolished while we dropped the lock
2951 Route::set_comment (string cmt, void *src)
2954 comment_changed (src);
2955 _session.set_dirty ();
2959 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2961 FeedRecord fr (other, via_sends_only);
2963 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2965 if (!result.second) {
2967 /* already a record for "other" - make sure sends-only information is correct */
2968 if (!via_sends_only && result.first->sends_only) {
2969 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2970 frp->sends_only = false;
2974 return result.second;
2978 Route::clear_fed_by ()
2984 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2986 const FedBy& fed_by (other->fed_by());
2988 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2989 boost::shared_ptr<Route> sr = f->r.lock();
2991 if (sr && (sr.get() == this)) {
2993 if (via_sends_only) {
2994 *via_sends_only = f->sends_only;
3005 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3007 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3009 if (_output->connected_to (other->input())) {
3010 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3011 if (via_send_only) {
3012 *via_send_only = false;
3019 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3021 boost::shared_ptr<IOProcessor> iop;
3023 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3024 if (iop->feeds (other)) {
3025 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3026 if (via_send_only) {
3027 *via_send_only = true;
3031 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3034 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3039 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3044 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3046 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3049 /** Called from the (non-realtime) butler thread when the transport is stopped */
3051 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3053 framepos_t now = _session.transport_frame();
3056 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3058 Automatable::transport_stopped (now);
3060 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3062 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3066 (*i)->transport_stopped (now);
3070 _roll_delay = _initial_delay;
3074 Route::input_change_handler (IOChange change, void * /*src*/)
3076 bool need_to_queue_solo_change = true;
3078 if ((change.type & IOChange::ConfigurationChanged)) {
3079 /* This is called with the process lock held if change
3080 contains ConfigurationChanged
3082 need_to_queue_solo_change = false;
3083 configure_processors (0);
3084 _phase_invert.resize (_input->n_ports().n_audio ());
3085 io_changed (); /* EMIT SIGNAL */
3088 if (!_input->connected() && _soloed_by_others_upstream) {
3089 if (need_to_queue_solo_change) {
3090 _session.cancel_solo_after_disconnect (shared_from_this(), true);
3092 cancel_solo_after_disconnect (true);
3098 Route::output_change_handler (IOChange change, void * /*src*/)
3100 bool need_to_queue_solo_change = true;
3101 if (_initial_io_setup) {
3105 if ((change.type & IOChange::ConfigurationChanged)) {
3106 /* This is called with the process lock held if change
3107 contains ConfigurationChanged
3109 need_to_queue_solo_change = false;
3110 configure_processors (0);
3111 io_changed (); /* EMIT SIGNAL */
3114 if (!_output->connected() && _soloed_by_others_downstream) {
3115 if (need_to_queue_solo_change) {
3116 _session.cancel_solo_after_disconnect (shared_from_this(), false);
3118 cancel_solo_after_disconnect (false);
3124 Route::cancel_solo_after_disconnect (bool upstream)
3127 _soloed_by_others_upstream = 0;
3129 _soloed_by_others_downstream = 0;
3131 set_mute_master_solo ();
3132 solo_changed (false, this);
3136 Route::pans_required () const
3138 if (n_outputs().n_audio() < 2) {
3142 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3146 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3148 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3154 if (n_outputs().n_total() == 0) {
3158 if (!_active || n_inputs() == ChanCount::ZERO) {
3159 silence_unlocked (nframes);
3163 if (session_state_changing) {
3164 if (_session.transport_speed() != 0.0f) {
3165 /* we're rolling but some state is changing (e.g. our diskstream contents)
3166 so we cannot use them. Be silent till this is over.
3168 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3170 silence_unlocked (nframes);
3173 /* we're really not rolling, so we're either delivery silence or actually
3174 monitoring, both of which are safe to do while session_state_changing is true.
3178 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3180 fill_buffers_with_input (bufs, _input, nframes);
3182 if (_meter_point == MeterInput) {
3183 _meter->run (bufs, start_frame, end_frame, nframes, true);
3186 _amp->apply_gain_automation (false);
3187 passthru (bufs, start_frame, end_frame, nframes, 0);
3193 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3195 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3200 if (n_outputs().n_total() == 0) {
3204 if (!_active || n_inputs().n_total() == 0) {
3205 silence_unlocked (nframes);
3209 framepos_t unused = 0;
3211 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3217 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3219 fill_buffers_with_input (bufs, _input, nframes);
3221 if (_meter_point == MeterInput) {
3222 _meter->run (bufs, start_frame, end_frame, nframes, true);
3225 passthru (bufs, start_frame, end_frame, nframes, declick);
3231 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3238 Route::flush_processors ()
3240 /* XXX shouldn't really try to take this lock, since
3241 this is called from the RT audio thread.
3244 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3246 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3252 Route::set_meter_point (MeterPoint p, bool force)
3254 if (_meter_point == p && !force) {
3258 bool meter_was_visible_to_user = _meter->display_to_user ();
3261 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3262 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3264 maybe_note_meter_position ();
3268 if (_meter_point != MeterCustom) {
3270 _meter->set_display_to_user (false);
3272 setup_invisible_processors ();
3276 _meter->set_display_to_user (true);
3278 /* If we have a previous position for the custom meter, try to put it there */
3279 if (_custom_meter_position_noted) {
3280 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3283 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3284 if (i != _processors.end ()) {
3285 _processors.remove (_meter);
3286 _processors.insert (i, _meter);
3288 } else if (_last_custom_meter_was_at_end) {
3289 _processors.remove (_meter);
3290 _processors.push_back (_meter);
3295 /* Set up the meter for its new position */
3297 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3301 if (loc == _processors.begin()) {
3302 m_in = _input->n_ports();
3304 ProcessorList::iterator before = loc;
3306 m_in = (*before)->output_streams ();
3309 _meter->reflect_inputs (m_in);
3311 /* we do not need to reconfigure the processors, because the meter
3312 (a) is always ready to handle processor_max_streams
3313 (b) is always an N-in/N-out processor, and thus moving
3314 it doesn't require any changes to the other processors.
3318 meter_change (); /* EMIT SIGNAL */
3320 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3322 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3326 Route::listen_position_changed ()
3329 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3330 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3331 ProcessorState pstate (this);
3333 if (configure_processors_unlocked (0)) {
3335 configure_processors_unlocked (0); // it worked before we tried to add it ...
3340 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3341 _session.set_dirty ();
3344 boost::shared_ptr<CapturingProcessor>
3345 Route::add_export_point()
3347 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3348 if (!_capturing_processor) {
3350 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3351 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3353 _capturing_processor.reset (new CapturingProcessor (_session));
3354 _capturing_processor->activate ();
3356 configure_processors_unlocked (0);
3360 return _capturing_processor;
3364 Route::update_signal_latency ()
3366 framecnt_t l = _output->user_latency();
3367 framecnt_t lamp = 0;
3368 bool before_amp = true;
3370 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3371 if ((*i)->active ()) {
3372 l += (*i)->signal_latency ();
3382 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3384 _signal_latency_at_amp_position = lamp;
3385 if (_signal_latency != l) {
3386 _signal_latency = l;
3387 signal_latency_changed (); /* EMIT SIGNAL */
3390 return _signal_latency;
3394 Route::set_user_latency (framecnt_t nframes)
3396 _output->set_user_latency (nframes);
3397 _session.update_latency_compensation ();
3401 Route::set_latency_compensation (framecnt_t longest_session_latency)
3403 framecnt_t old = _initial_delay;
3405 if (_signal_latency < longest_session_latency) {
3406 _initial_delay = longest_session_latency - _signal_latency;
3411 DEBUG_TRACE (DEBUG::Latency, string_compose (
3412 "%1: compensate for maximum latency of %2,"
3413 "given own latency of %3, using initial delay of %4\n",
3414 name(), longest_session_latency, _signal_latency, _initial_delay));
3416 if (_initial_delay != old) {
3417 initial_delay_changed (); /* EMIT SIGNAL */
3420 if (_session.transport_stopped()) {
3421 _roll_delay = _initial_delay;
3425 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3426 : AutomationControl (r->session(),
3427 Evoral::Parameter (SoloAutomation),
3428 ParameterDescriptor(Evoral::Parameter (SoloAutomation)),
3429 boost::shared_ptr<AutomationList>(), name)
3432 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3433 gl->set_interpolation(Evoral::ControlList::Discrete);
3438 Route::SoloControllable::set_value (double val)
3440 const bool bval = ((val >= 0.5) ? true : false);
3442 boost::shared_ptr<RouteList> rl (new RouteList);
3444 boost::shared_ptr<Route> r = _route.lock ();
3451 if (Config->get_solo_control_is_listen_control()) {
3452 _session.set_listen (rl, bval);
3454 _session.set_solo (rl, bval);
3459 Route::SoloControllable::get_value () const
3461 boost::shared_ptr<Route> r = _route.lock ();
3466 if (Config->get_solo_control_is_listen_control()) {
3467 return r->listening_via_monitor() ? 1.0f : 0.0f;
3469 return r->self_soloed() ? 1.0f : 0.0f;
3473 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3474 : AutomationControl (r->session(),
3475 Evoral::Parameter (MuteAutomation),
3476 ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
3477 boost::shared_ptr<AutomationList>(),
3481 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3482 gl->set_interpolation(Evoral::ControlList::Discrete);
3487 Route::MuteControllable::set_superficial_value(bool muted)
3489 /* Note we can not use AutomationControl::set_value here since it will emit
3490 Changed(), but the value will not be correct to the observer. */
3492 bool to_list = _list && ((AutomationList*)_list.get())->automation_write();
3494 Control::set_double (muted, _session.transport_frame(), to_list);
3498 Route::MuteControllable::set_value (double val)
3500 const bool bval = ((val >= 0.5) ? true : false);
3502 boost::shared_ptr<Route> r = _route.lock ();
3507 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3508 // Playing back automation, set route mute directly
3509 r->set_mute (bval, this);
3511 // Set from user, queue mute event
3512 boost::shared_ptr<RouteList> rl (new RouteList);
3514 _session.set_mute (rl, bval, Session::rt_cleanup);
3517 // Set superficial/automation value to drive controller (and possibly record)
3518 set_superficial_value(bval);
3522 Route::MuteControllable::get_value () const
3524 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3525 // Playing back automation, get the value from the list
3526 return AutomationControl::get_value();
3529 // Not playing back automation, get the actual route mute value
3530 boost::shared_ptr<Route> r = _route.lock ();
3531 return (r && r->muted()) ? 1.0 : 0.0;
3535 Route::set_block_size (pframes_t nframes)
3537 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3538 (*i)->set_block_size (nframes);
3541 _session.ensure_buffers (n_process_buffers ());
3545 Route::protect_automation ()
3547 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3548 (*i)->protect_automation();
3551 /** @param declick 1 to set a pending declick fade-in,
3552 * -1 to set a pending declick fade-out
3555 Route::set_pending_declick (int declick)
3558 /* this call is not allowed to turn off a pending declick */
3560 _pending_declick = declick;
3563 _pending_declick = 0;
3567 /** Shift automation forwards from a particular place, thereby inserting time.
3568 * Adds undo commands for any shifts that are performed.
3570 * @param pos Position to start shifting from.
3571 * @param frames Amount to shift forwards by.
3575 Route::shift (framepos_t pos, framecnt_t frames)
3577 /* gain automation */
3579 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3581 XMLNode &before = gc->alist()->get_state ();
3582 gc->alist()->shift (pos, frames);
3583 XMLNode &after = gc->alist()->get_state ();
3584 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3587 /* pan automation */
3589 ControlSet::Controls& c (_pannable->controls());
3591 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3592 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3594 boost::shared_ptr<AutomationList> al = pc->alist();
3595 XMLNode& before = al->get_state ();
3596 al->shift (pos, frames);
3597 XMLNode& after = al->get_state ();
3598 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3603 /* redirect automation */
3605 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3606 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3608 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3610 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3611 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3613 boost::shared_ptr<AutomationList> al = ac->alist();
3614 XMLNode &before = al->get_state ();
3615 al->shift (pos, frames);
3616 XMLNode &after = al->get_state ();
3617 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3626 Route::save_as_template (const string& path, const string& name)
3628 XMLNode& node (state (false));
3631 IO::set_name_in_state (*node.children().front(), name);
3633 tree.set_root (&node);
3634 return tree.write (path.c_str());
3639 Route::set_name (const string& str)
3641 if (str == name()) {
3645 string name = Route::ensure_track_or_route_name (str, _session);
3646 SessionObject::set_name (name);
3648 bool ret = (_input->set_name(name) && _output->set_name(name));
3651 /* rename the main outs. Leave other IO processors
3652 * with whatever name they already have, because its
3653 * just fine as it is (it will not contain the route
3654 * name if its a port insert, port send or port return).
3658 if (_main_outs->set_name (name)) {
3659 /* XXX returning false here is stupid because
3660 we already changed the route name.
3670 /** Set the name of a route in an XML description.
3671 * @param node XML <Route> node to set the name in.
3672 * @param name New name.
3675 Route::set_name_in_state (XMLNode& node, string const & name)
3677 node.add_property (X_("name"), name);
3679 XMLNodeList children = node.children();
3680 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3682 if ((*i)->name() == X_("IO")) {
3684 IO::set_name_in_state (**i, name);
3686 } else if ((*i)->name() == X_("Processor")) {
3688 XMLProperty* role = (*i)->property (X_("role"));
3689 if (role && role->value() == X_("Main")) {
3690 (*i)->add_property (X_("name"), name);
3693 } else if ((*i)->name() == X_("Diskstream")) {
3695 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3696 (*i)->add_property (X_("name"), name);
3702 boost::shared_ptr<Send>
3703 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3705 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3707 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3708 boost::shared_ptr<InternalSend> send;
3710 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3711 if (send->target_route() == target) {
3717 return boost::shared_ptr<Send>();
3720 /** @param c Audio channel index.
3721 * @param yn true to invert phase, otherwise false.
3724 Route::set_phase_invert (uint32_t c, bool yn)
3726 if (_phase_invert[c] != yn) {
3727 _phase_invert[c] = yn;
3728 phase_invert_changed (); /* EMIT SIGNAL */
3729 _session.set_dirty ();
3734 Route::set_phase_invert (boost::dynamic_bitset<> p)
3736 if (_phase_invert != p) {
3738 phase_invert_changed (); /* EMIT SIGNAL */
3739 _session.set_dirty ();
3744 Route::phase_invert (uint32_t c) const
3746 return _phase_invert[c];
3749 boost::dynamic_bitset<>
3750 Route::phase_invert () const
3752 return _phase_invert;
3756 Route::set_denormal_protection (bool yn)
3758 if (_denormal_protection != yn) {
3759 _denormal_protection = yn;
3760 denormal_protection_changed (); /* EMIT SIGNAL */
3765 Route::denormal_protection () const
3767 return _denormal_protection;
3771 Route::set_active (bool yn, void* src)
3773 if (_session.transport_rolling()) {
3777 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3778 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3782 if (_active != yn) {
3784 _input->set_active (yn);
3785 _output->set_active (yn);
3786 active_changed (); // EMIT SIGNAL
3787 _session.set_dirty ();
3794 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3800 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3802 boost::shared_ptr<Send> s;
3803 boost::shared_ptr<Return> r;
3805 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3806 s->meter()->meter();
3807 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3808 r->meter()->meter ();
3813 boost::shared_ptr<Pannable>
3814 Route::pannable() const
3819 boost::shared_ptr<Panner>
3820 Route::panner() const
3823 return _main_outs->panner_shell()->panner();
3826 boost::shared_ptr<PannerShell>
3827 Route::panner_shell() const
3829 return _main_outs->panner_shell();
3832 boost::shared_ptr<AutomationControl>
3833 Route::gain_control() const
3835 return _amp->gain_control();
3838 boost::shared_ptr<AutomationControl>
3839 Route::get_control (const Evoral::Parameter& param)
3841 /* either we own the control or .... */
3843 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3847 /* maybe one of our processors does or ... */
3849 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3850 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3851 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3859 /* nobody does so we'll make a new one */
3861 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3868 boost::shared_ptr<Processor>
3869 Route::nth_plugin (uint32_t n)
3871 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3872 ProcessorList::iterator i;
3874 for (i = _processors.begin(); i != _processors.end(); ++i) {
3875 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3882 return boost::shared_ptr<Processor> ();
3885 boost::shared_ptr<Processor>
3886 Route::nth_send (uint32_t n)
3888 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3889 ProcessorList::iterator i;
3891 for (i = _processors.begin(); i != _processors.end(); ++i) {
3892 if (boost::dynamic_pointer_cast<Send> (*i)) {
3899 return boost::shared_ptr<Processor> ();
3903 Route::has_io_processor_named (const string& name)
3905 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3906 ProcessorList::iterator i;
3908 for (i = _processors.begin(); i != _processors.end(); ++i) {
3909 if (boost::dynamic_pointer_cast<Send> (*i) ||
3910 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3911 if ((*i)->name() == name) {
3920 MuteMaster::MutePoint
3921 Route::mute_points () const
3923 return _mute_master->mute_points ();
3927 Route::set_processor_positions ()
3929 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3931 bool had_amp = false;
3932 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3933 (*i)->set_pre_fader (!had_amp);
3934 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3940 /** Called when there is a proposed change to the input port count */
3942 Route::input_port_count_changing (ChanCount to)
3944 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3946 /* The processors cannot be configured with the new input arrangement, so
3952 /* The change is ok */
3956 /** Called when there is a proposed change to the output port count */
3958 Route::output_port_count_changing (ChanCount to)
3960 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
3961 if (processor_out_streams.get(*t) > to.get(*t)) {
3965 /* The change is ok */
3970 Route::unknown_processors () const
3974 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3975 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3976 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3977 p.push_back ((*i)->name ());
3986 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
3988 /* we assume that all our input ports feed all our output ports. its not
3989 universally true, but the alternative is way too corner-case to worry about.
3992 LatencyRange all_connections;
3995 all_connections.min = 0;
3996 all_connections.max = 0;
3998 all_connections.min = ~((pframes_t) 0);
3999 all_connections.max = 0;
4001 /* iterate over all "from" ports and determine the latency range for all of their
4002 connections to the "outside" (outside of this Route).
4005 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4009 p->get_connected_latency_range (range, playback);
4011 all_connections.min = min (all_connections.min, range.min);
4012 all_connections.max = max (all_connections.max, range.max);
4016 /* set the "from" port latencies to the max/min range of all their connections */
4018 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4019 p->set_private_latency_range (all_connections, playback);
4022 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4024 all_connections.min += our_latency;
4025 all_connections.max += our_latency;
4027 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4028 p->set_private_latency_range (all_connections, playback);
4031 return all_connections.max;
4035 Route::set_private_port_latencies (bool playback) const
4037 framecnt_t own_latency = 0;
4039 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4040 OR LATENCY CALLBACK.
4042 This is called (early) from the latency callback. It computes the REAL
4043 latency associated with each port and stores the result as the "private"
4044 latency of the port. A later call to Route::set_public_port_latencies()
4045 sets all ports to the same value to reflect the fact that we do latency
4046 compensation and so all signals are delayed by the same amount as they
4047 flow through ardour.
4050 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4051 if ((*i)->active ()) {
4052 own_latency += (*i)->signal_latency ();
4057 /* playback: propagate latency from "outside the route" to outputs to inputs */
4058 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4060 /* capture: propagate latency from "outside the route" to inputs to outputs */
4061 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4066 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4068 /* this is called to set the JACK-visible port latencies, which take
4069 latency compensation into account.
4078 const PortSet& ports (_input->ports());
4079 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4080 p->set_public_latency_range (range, playback);
4085 const PortSet& ports (_output->ports());
4086 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4087 p->set_public_latency_range (range, playback);
4092 /** Put the invisible processors in the right place in _processors.
4093 * Must be called with a writer lock on _processor_lock held.
4096 Route::setup_invisible_processors ()
4099 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4100 assert (!lm.locked ());
4104 /* too early to be doing this stuff */
4108 /* we'll build this new list here and then use it */
4110 ProcessorList new_processors;
4112 /* find visible processors */
4114 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4115 if ((*i)->display_to_user ()) {
4116 new_processors.push_back (*i);
4122 ProcessorList::iterator amp = new_processors.begin ();
4123 while (amp != new_processors.end() && boost::dynamic_pointer_cast<Amp> (*amp) == 0) {
4127 assert (amp != new_processors.end ());
4129 /* and the processor after the amp */
4131 ProcessorList::iterator after_amp = amp;
4137 switch (_meter_point) {
4139 assert (!_meter->display_to_user ());
4140 new_processors.push_front (_meter);
4143 assert (!_meter->display_to_user ());
4144 new_processors.insert (amp, _meter);
4146 case MeterPostFader:
4147 /* do nothing here */
4150 /* do nothing here */
4153 /* the meter is visible, so we don't touch it here */
4160 assert (_main_outs);
4161 assert (!_main_outs->display_to_user ());
4162 new_processors.push_back (_main_outs);
4164 /* iterator for the main outs */
4166 ProcessorList::iterator main = new_processors.end();
4169 /* OUTPUT METERING */
4171 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4172 assert (!_meter->display_to_user ());
4174 /* add the processor just before or just after the main outs */
4176 ProcessorList::iterator meter_point = main;
4178 if (_meter_point == MeterOutput) {
4181 new_processors.insert (meter_point, _meter);
4186 if (_monitor_send && !is_monitor ()) {
4187 assert (!_monitor_send->display_to_user ());
4188 if (Config->get_solo_control_is_listen_control()) {
4189 switch (Config->get_listen_position ()) {
4190 case PreFaderListen:
4191 switch (Config->get_pfl_position ()) {
4192 case PFLFromBeforeProcessors:
4193 new_processors.push_front (_monitor_send);
4195 case PFLFromAfterProcessors:
4196 new_processors.insert (amp, _monitor_send);
4199 _monitor_send->set_can_pan (false);
4201 case AfterFaderListen:
4202 switch (Config->get_afl_position ()) {
4203 case AFLFromBeforeProcessors:
4204 new_processors.insert (after_amp, _monitor_send);
4206 case AFLFromAfterProcessors:
4207 new_processors.insert (new_processors.end(), _monitor_send);
4210 _monitor_send->set_can_pan (true);
4214 new_processors.insert (new_processors.end(), _monitor_send);
4215 _monitor_send->set_can_pan (false);
4219 #if 0 // not used - just yet
4220 if (!is_master() && !is_monitor() && !is_auditioner()) {
4221 new_processors.push_front (_delayline);
4225 /* MONITOR CONTROL */
4227 if (_monitor_control && is_monitor ()) {
4228 assert (!_monitor_control->display_to_user ());
4229 new_processors.push_front (_monitor_control);
4232 /* INTERNAL RETURN */
4234 /* doing this here means that any monitor control will come just after
4239 assert (!_intreturn->display_to_user ());
4240 new_processors.push_front (_intreturn);
4243 /* EXPORT PROCESSOR */
4245 if (_capturing_processor) {
4246 assert (!_capturing_processor->display_to_user ());
4247 new_processors.push_front (_capturing_processor);
4250 _processors = new_processors;
4252 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4253 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4254 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4261 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4262 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4266 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4267 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4274 /** If the meter point is `Custom', make a note of where the meter is.
4275 * This is so that if the meter point is subsequently set to something else,
4276 * and then back to custom, we can put the meter back where it was last time
4277 * custom was enabled.
4279 * Must be called with the _processor_lock held.
4282 Route::maybe_note_meter_position ()
4284 if (_meter_point != MeterCustom) {
4288 _custom_meter_position_noted = true;
4289 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4290 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4291 ProcessorList::iterator j = i;
4293 if (j != _processors.end ()) {
4294 _processor_after_last_custom_meter = *j;
4295 _last_custom_meter_was_at_end = false;
4297 _last_custom_meter_was_at_end = true;
4303 boost::shared_ptr<Processor>
4304 Route::processor_by_id (PBD::ID id) const
4306 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4307 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4308 if ((*i)->id() == id) {
4313 return boost::shared_ptr<Processor> ();
4316 /** @return the monitoring state, or in other words what data we are pushing
4317 * into the route (data from the inputs, data from disk or silence)
4320 Route::monitoring_state () const
4322 return MonitoringInput;
4325 /** @return what we should be metering; either the data coming from the input
4326 * IO or the data that is flowing through the route.
4329 Route::metering_state () const
4331 return MeteringRoute;
4335 Route::has_external_redirects () const
4337 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4339 /* ignore inactive processors and obviously ignore the main
4340 * outs since everything has them and we don't care.
4343 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4351 boost::shared_ptr<Processor>
4352 Route::the_instrument () const
4354 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4355 return the_instrument_unlocked ();
4358 boost::shared_ptr<Processor>
4359 Route::the_instrument_unlocked () const
4361 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4362 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4363 if ((*i)->input_streams().n_midi() > 0 &&
4364 (*i)->output_streams().n_audio() > 0) {
4369 return boost::shared_ptr<Processor>();
4375 Route::non_realtime_locate (framepos_t pos)
4378 _pannable->transport_located (pos);
4381 if (_delayline.get()) {
4382 _delayline.get()->flush();
4386 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4387 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4389 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4390 (*i)->transport_located (pos);
4396 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4403 * We don't currently mix MIDI input together, so we don't need the
4404 * complex logic of the audio case.
4407 n_buffers = bufs.count().n_midi ();
4409 for (i = 0; i < n_buffers; ++i) {
4411 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4412 MidiBuffer& buf (bufs.get_midi (i));
4415 buf.copy (source_port->get_midi_buffer(nframes));
4417 buf.silence (nframes);
4423 n_buffers = bufs.count().n_audio();
4425 size_t n_ports = io->n_ports().n_audio();
4426 float scaling = 1.0f;
4428 if (n_ports > n_buffers) {
4429 scaling = ((float) n_buffers) / n_ports;
4432 for (i = 0; i < n_ports; ++i) {
4434 /* if there are more ports than buffers, map them onto buffers
4435 * in a round-robin fashion
4438 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4439 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4442 if (i < n_buffers) {
4444 /* first time through just copy a channel into
4448 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4450 if (scaling != 1.0f) {
4451 buf.apply_gain (scaling, nframes);
4456 /* on subsequent times around, merge data from
4457 * the port with what is already there
4460 if (scaling != 1.0f) {
4461 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4463 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4468 /* silence any remaining buffers */
4470 for (; i < n_buffers; ++i) {
4471 AudioBuffer& buf (bufs.get_audio (i));
4472 buf.silence (nframes);
4475 /* establish the initial setup of the buffer set, reflecting what was
4476 copied into it. unless, of course, we are the auditioner, in which
4477 case nothing was fed into it from the inputs at all.
4480 if (!is_auditioner()) {
4481 bufs.set_count (io->n_ports());