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)
86 , _pending_declick (true)
87 , _meter_point (MeterPostFader)
88 , _meter_type (MeterPeak)
90 , _soloed_by_others_upstream (0)
91 , _soloed_by_others_downstream (0)
93 , _denormal_protection (false)
96 , _declickable (false)
97 , _mute_master (new MuteMaster (sess, name))
98 , _have_internal_generator (false)
100 , _default_type (default_type)
102 , _has_order_key (false)
103 , _remote_control_id (0)
104 , _in_configure_processors (false)
105 , _initial_io_setup (false)
106 , _custom_meter_position_noted (false)
107 , _last_custom_meter_was_at_end (false)
110 _meter_type = MeterK20;
112 processor_max_streams.reset();
118 /* add standard controls */
120 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
121 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
123 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
124 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
126 add_control (_solo_control);
127 add_control (_mute_control);
131 if (!(_flags & Route::MonitorOut)) {
132 _pannable.reset (new Pannable (_session));
135 /* input and output objects */
137 _input.reset (new IO (_session, _name, IO::Input, _default_type));
138 _output.reset (new IO (_session, _name, IO::Output, _default_type));
140 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
141 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
143 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
144 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
146 if (!is_master() && !is_monitor() && !is_auditioner()) {
147 _delayline.reset (new DelayLine (_session, _name));
148 add_processor (_delayline, PreFader);
151 /* add amp processor */
153 _amp.reset (new Amp (_session));
154 add_processor (_amp, PostFader);
156 /* create standard processors: meter, main outs, monitor out;
157 they will be added to _processors by setup_invisible_processors ()
160 _meter.reset (new PeakMeter (_session, _name));
161 _meter->set_owner (this);
162 _meter->set_display_to_user (false);
165 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
166 _main_outs->activate ();
169 /* where we listen to tracks */
170 _intreturn.reset (new InternalReturn (_session));
171 _intreturn->activate ();
173 /* the thing that provides proper control over a control/monitor/listen bus
174 (such as per-channel cut, dim, solo, invert, etc).
176 _monitor_control.reset (new MonitorProcessor (_session));
177 _monitor_control->activate ();
180 if (is_master() || is_monitor() || is_auditioner()) {
181 _mute_master->set_solo_ignore (true);
184 /* now that we have _meter, its safe to connect to this */
186 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
189 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
190 configure_processors (0);
198 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
200 /* do this early so that we don't get incoming signals as we are going through destruction
205 /* don't use clear_processors here, as it depends on the session which may
206 be half-destroyed by now
209 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
210 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
211 (*i)->drop_references ();
214 _processors.clear ();
218 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
220 if (Config->get_remote_model() != UserOrdered) {
224 set_remote_control_id_internal (id, notify_class_listeners);
228 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
230 /* force IDs for master/monitor busses and prevent
231 any other route from accidentally getting these IDs
232 (i.e. legacy sessions)
235 if (is_master() && id != MasterBusRemoteControlID) {
236 id = MasterBusRemoteControlID;
239 if (is_monitor() && id != MonitorBusRemoteControlID) {
240 id = MonitorBusRemoteControlID;
247 /* don't allow it to collide */
249 if (!is_master () && !is_monitor() &&
250 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
251 id += MonitorBusRemoteControlID;
254 if (id != remote_control_id()) {
255 _remote_control_id = id;
256 RemoteControlIDChanged ();
258 if (notify_class_listeners) {
259 RemoteControlIDChange ();
265 Route::remote_control_id() const
268 return MasterBusRemoteControlID;
272 return MonitorBusRemoteControlID;
275 return _remote_control_id;
279 Route::has_order_key () const
281 return _has_order_key;
285 Route::order_key () const
291 Route::set_remote_control_id_explicit (uint32_t rid)
293 if (is_master() || is_monitor() || is_auditioner()) {
294 /* hard-coded remote IDs, or no remote ID */
298 if (_remote_control_id != rid) {
299 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
300 _remote_control_id = rid;
301 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
304 /* don't emit the class-level RID signal RemoteControlIDChange here,
305 leave that to the entity that changed the order key, so that we
306 don't get lots of emissions for no good reasons (e.g. when changing
307 all route order keys).
309 See Session::sync_remote_id_from_order_keys() for the (primary|only)
310 spot where that is emitted.
315 Route::set_order_key (uint32_t n)
317 _has_order_key = true;
319 if (_order_key == n) {
325 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
326 name(), order_key ()));
328 _session.set_dirty ();
332 Route::ensure_track_or_route_name(string name, Session &session)
334 string newname = name;
336 while (!session.io_name_is_legal (newname)) {
337 newname = bump_name_once (newname, '.');
345 Route::inc_gain (gain_t fraction, void *src)
347 _amp->inc_gain (fraction, src);
351 Route::set_gain (gain_t val, void *src)
353 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
355 if (_route_group->is_relative()) {
357 gain_t usable_gain = _amp->gain();
358 if (usable_gain < 0.000001f) {
359 usable_gain = 0.000001f;
363 if (delta < 0.000001f) {
367 delta -= usable_gain;
372 gain_t factor = delta / usable_gain;
375 factor = _route_group->get_max_factor(factor);
376 if (factor == 0.0f) {
377 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
381 factor = _route_group->get_min_factor(factor);
382 if (factor == 0.0f) {
383 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
388 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
392 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
398 if (val == _amp->gain()) {
402 _amp->set_gain (val, src);
406 Route::maybe_declick (BufferSet&, framecnt_t, int)
408 /* this is the "bus" implementation and they never declick.
413 /** Process this route for one (sub) cycle (process thread)
415 * @param bufs Scratch buffers to use for the signal path
416 * @param start_frame Initial transport frame
417 * @param end_frame Final transport frame
418 * @param nframes Number of frames to output (to ports)
420 * Note that (end_frame - start_frame) may not be equal to nframes when the
421 * transport speed isn't 1.0 (eg varispeed).
424 Route::process_output_buffers (BufferSet& bufs,
425 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
426 int declick, bool gain_automation_ok)
428 /* Caller must hold process lock */
429 assert (!AudioEngine::instance()->process_lock().trylock());
431 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
434 /* figure out if we're going to use gain automation */
435 if (gain_automation_ok) {
436 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
437 _amp->setup_gain_automation (start_frame, end_frame, nframes);
439 _amp->apply_gain_automation (false);
442 /* Tell main outs what to do about monitoring. We do this so that
443 on a transition between monitoring states we get a de-clicking gain
444 change in the _main_outs delivery.
447 _main_outs->no_outs_cuz_we_no_monitor (monitoring_state () == MonitoringSilence);
449 /* -------------------------------------------------------------------------------------------
450 GLOBAL DECLICK (for transport changes etc.)
451 ----------------------------------------------------------------------------------------- */
453 maybe_declick (bufs, nframes, declick);
454 _pending_declick = 0;
456 /* -------------------------------------------------------------------------------------------
457 DENORMAL CONTROL/PHASE INVERT
458 ----------------------------------------------------------------------------------------- */
460 if (_phase_invert.any ()) {
464 if (_denormal_protection || Config->get_denormal_protection()) {
466 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
467 Sample* const sp = i->data();
469 if (_phase_invert[chn]) {
470 for (pframes_t nx = 0; nx < nframes; ++nx) {
475 for (pframes_t nx = 0; nx < nframes; ++nx) {
483 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
484 Sample* const sp = i->data();
486 if (_phase_invert[chn]) {
487 for (pframes_t nx = 0; nx < nframes; ++nx) {
496 if (_denormal_protection || Config->get_denormal_protection()) {
498 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
499 Sample* const sp = i->data();
500 for (pframes_t nx = 0; nx < nframes; ++nx) {
508 /* -------------------------------------------------------------------------------------------
510 ----------------------------------------------------------------------------------------- */
512 /* set this to be true if the meter will already have been ::run() earlier */
513 bool const meter_already_run = metering_state() == MeteringInput;
515 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
517 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
518 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
523 /* if it has any inputs, make sure they match */
524 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
525 if (bufs.count() != (*i)->input_streams()) {
527 DEBUG::Processors, string_compose (
528 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
529 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
536 /* should we NOT run plugins here if the route is inactive?
537 do we catch route != active somewhere higher?
540 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
541 bufs.set_count ((*i)->output_streams());
546 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
547 boost::shared_ptr<Processor> endpoint,
548 bool include_endpoint, bool for_export, bool for_freeze)
550 /* If no processing is required, there's no need to go any further. */
551 if (!endpoint && !include_endpoint) {
555 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
556 _amp->setup_gain_automation (start, start + nframes, nframes);
558 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
560 if (!include_endpoint && (*i) == endpoint) {
564 /* if we're not exporting, stop processing if we come across a routing processor. */
565 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
568 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
572 /* don't run any processors that does routing.
573 * oh, and don't bother with the peak meter either.
575 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
576 (*i)->run (buffers, start, start+nframes, nframes, true);
577 buffers.set_count ((*i)->output_streams());
580 if ((*i) == endpoint) {
587 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
588 bool include_endpoint, bool for_export, bool for_freeze) const
590 framecnt_t latency = 0;
591 if (!endpoint && !include_endpoint) {
595 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
596 if (!include_endpoint && (*i) == endpoint) {
599 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
602 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
605 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
606 latency += (*i)->signal_latency ();
608 if ((*i) == endpoint) {
616 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
617 bool include_endpoint, bool for_export, bool for_freeze) const
619 if (!endpoint && !include_endpoint) {
623 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
624 if (!include_endpoint && (*i) == endpoint) {
627 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
630 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
633 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
634 cc = (*i)->output_streams();
636 if ((*i) == endpoint) {
644 Route::n_process_buffers ()
646 return max (_input->n_ports(), processor_max_streams);
650 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
652 assert (is_monitor());
653 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
654 fill_buffers_with_input (bufs, _input, nframes);
655 passthru (bufs, start_frame, end_frame, nframes, declick);
659 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
663 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
665 /* control/monitor bus ignores input ports when something is
666 feeding the listen "stream". data will "arrive" into the
667 route from the intreturn processor element.
670 bufs.silence (nframes, 0);
673 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
674 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
678 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
680 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
682 bufs.set_count (_input->n_ports());
683 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
684 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
688 Route::set_listen (bool yn, void* src)
694 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
695 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
700 if (yn != _monitor_send->active()) {
702 _monitor_send->activate ();
703 _mute_master->set_soloed (true);
705 _monitor_send->deactivate ();
706 _mute_master->set_soloed (false);
709 listen_changed (src); /* EMIT SIGNAL */
715 Route::listening_via_monitor () const
718 return _monitor_send->active ();
725 Route::set_solo_safe (bool yn, void *src)
727 if (_solo_safe != yn) {
729 solo_safe_changed (src);
734 Route::solo_safe() const
740 Route::set_solo (bool yn, void *src)
743 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
747 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
748 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
752 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
753 name(), yn, src, (src == _route_group), self_soloed()));
755 if (self_soloed() != yn) {
757 set_mute_master_solo ();
758 solo_changed (true, src); /* EMIT SIGNAL */
759 _solo_control->Changed (); /* EMIT SIGNAL */
764 Route::set_self_solo (bool yn)
766 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
771 Route::mod_solo_by_others_upstream (int32_t delta)
774 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-upstream due to solo-safe\n", name()));
778 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
779 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
781 uint32_t old_sbu = _soloed_by_others_upstream;
784 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
785 _soloed_by_others_upstream += delta;
787 _soloed_by_others_upstream = 0;
790 _soloed_by_others_upstream += delta;
793 DEBUG_TRACE (DEBUG::Solo, string_compose (
794 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
795 name(), delta, _soloed_by_others_upstream, old_sbu,
796 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
798 /* push the inverse solo change to everything that feeds us.
800 This is important for solo-within-group. When we solo 1 track out of N that
801 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
802 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
803 tracks that feed it. This will silence them if they were audible because
804 of a bus solo, but the newly soloed track will still be audible (because
807 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
811 if ((_self_solo || _soloed_by_others_downstream) &&
812 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
813 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
815 if (delta > 0 || !Config->get_exclusive_solo()) {
816 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
817 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
818 boost::shared_ptr<Route> sr = i->r.lock();
820 sr->mod_solo_by_others_downstream (-delta);
826 set_mute_master_solo ();
827 solo_changed (false, this);
831 Route::mod_solo_by_others_downstream (int32_t delta)
834 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-downstream due to solo safe\n", name()));
838 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
839 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
842 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
843 _soloed_by_others_downstream += delta;
845 _soloed_by_others_downstream = 0;
848 _soloed_by_others_downstream += delta;
851 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
853 set_mute_master_solo ();
854 solo_changed (false, this);
858 Route::set_mute_master_solo ()
860 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
864 Route::set_solo_isolated (bool yn, void *src)
866 if (is_master() || is_monitor() || is_auditioner()) {
870 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
871 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
875 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
877 boost::shared_ptr<RouteList> routes = _session.get_routes ();
878 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
880 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
885 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
887 if (does_feed && !sends_only) {
888 (*i)->set_solo_isolated (yn, (*i)->route_group());
892 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
894 bool changed = false;
897 if (_solo_isolated == 0) {
898 _mute_master->set_solo_ignore (true);
903 if (_solo_isolated > 0) {
905 if (_solo_isolated == 0) {
906 _mute_master->set_solo_ignore (false);
913 solo_isolated_changed (src);
918 Route::solo_isolated () const
920 return _solo_isolated > 0;
924 Route::set_mute_points (MuteMaster::MutePoint mp)
926 _mute_master->set_mute_points (mp);
927 mute_points_changed (); /* EMIT SIGNAL */
929 if (_mute_master->muted_by_self()) {
930 mute_changed (this); /* EMIT SIGNAL */
931 _mute_control->Changed (); /* EMIT SIGNAL */
936 Route::set_mute (bool yn, void *src)
938 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
939 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
944 _mute_master->set_muted_by_self (yn);
945 /* allow any derived classes to respond to the mute change
946 before anybody else knows about it.
949 /* tell everyone else */
950 mute_changed (src); /* EMIT SIGNAL */
951 _mute_control->Changed (); /* EMIT SIGNAL */
956 Route::muted () const
958 return _mute_master->muted_by_self();
963 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
965 cerr << name << " {" << endl;
966 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
967 p != procs.end(); ++p) {
968 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
974 /** Supposing that we want to insert a Processor at a given Placement, return
975 * the processor to add the new one before (or 0 to add at the end).
977 boost::shared_ptr<Processor>
978 Route::before_processor_for_placement (Placement p)
980 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
982 ProcessorList::iterator loc;
985 /* generic pre-fader: insert immediately before the amp */
986 loc = find (_processors.begin(), _processors.end(), _amp);
988 /* generic post-fader: insert right before the main outs */
989 loc = find (_processors.begin(), _processors.end(), _main_outs);
992 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
995 /** Supposing that we want to insert a Processor at a given index, return
996 * the processor to add the new one before (or 0 to add at the end).
998 boost::shared_ptr<Processor>
999 Route::before_processor_for_index (int index)
1002 return boost::shared_ptr<Processor> ();
1005 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1007 ProcessorList::iterator i = _processors.begin ();
1009 while (i != _processors.end() && j < index) {
1010 if ((*i)->display_to_user()) {
1017 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1020 /** Add a processor either pre- or post-fader
1021 * @return 0 on success, non-0 on failure.
1024 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1026 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1030 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1031 * @param index Index to add the processor at, or -1 to add at the end of the list.
1032 * @return 0 on success, non-0 on failure.
1035 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1037 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1040 /** Add a processor to the route.
1041 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1042 * @return 0 on success, non-0 on failure.
1045 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1047 assert (processor != _meter);
1048 assert (processor != _main_outs);
1050 DEBUG_TRACE (DEBUG::Processors, string_compose (
1051 "%1 adding processor %2\n", name(), processor->name()));
1053 if (!AudioEngine::instance()->connected() || !processor) {
1058 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1059 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1060 ProcessorState pstate (this);
1062 boost::shared_ptr<PluginInsert> pi;
1063 boost::shared_ptr<PortInsert> porti;
1065 if (processor == _amp) {
1066 /* Ensure that only one amp is in the list at any time */
1067 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1068 if (check != _processors.end()) {
1069 if (before == _amp) {
1070 /* Already in position; all is well */
1073 _processors.erase (check);
1078 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1080 ProcessorList::iterator loc;
1082 /* inserting before a processor; find it */
1083 loc = find (_processors.begin(), _processors.end(), before);
1084 if (loc == _processors.end ()) {
1089 /* inserting at end */
1090 loc = _processors.end ();
1093 _processors.insert (loc, processor);
1094 processor->set_owner (this);
1096 // Set up processor list channels. This will set processor->[input|output]_streams(),
1097 // configure redirect ports properly, etc.
1100 if (configure_processors_unlocked (err)) {
1102 configure_processors_unlocked (0); // it worked before we tried to add it ...
1107 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1109 if (pi->has_no_inputs ()) {
1110 /* generator plugin */
1111 _have_internal_generator = true;
1116 if (activation_allowed && !_session.get_disable_all_loaded_plugins()) {
1117 processor->activate ();
1120 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1122 _output->set_user_latency (0);
1125 reset_instrument_info ();
1126 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1127 set_processor_positions ();
1133 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1135 const XMLProperty *prop;
1138 boost::shared_ptr<Processor> processor;
1140 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1141 so that we can add the processor in the right place (pre/post-fader)
1144 XMLNodeList const & children = node.children ();
1145 XMLNodeList::const_iterator i = children.begin ();
1147 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1151 Placement placement = PreFader;
1153 if (i != children.end()) {
1154 if ((prop = (*i)->property (X_("placement"))) != 0) {
1155 placement = Placement (string_2_enum (prop->value(), placement));
1159 if (node.name() == "Insert") {
1161 if ((prop = node.property ("type")) != 0) {
1163 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1164 prop->value() == "lv2" ||
1165 prop->value() == "windows-vst" ||
1166 prop->value() == "lxvst" ||
1167 prop->value() == "audiounit") {
1169 processor.reset (new PluginInsert (_session));
1173 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1178 } else if (node.name() == "Send") {
1180 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1181 processor.reset (new Send (_session, sendpan, _mute_master));
1185 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1189 if (processor->set_state (node, version)) {
1193 return (add_processor (processor, placement) == 0);
1196 catch (failed_constructor &err) {
1197 warning << _("processor could not be created. Ignored.") << endmsg;
1203 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1205 /* NOTE: this is intended to be used ONLY when copying
1206 processors from another Route. Hence the subtle
1207 differences between this and ::add_processor()
1210 ProcessorList::iterator loc;
1213 loc = find(_processors.begin(), _processors.end(), before);
1215 /* nothing specified - at end */
1216 loc = _processors.end ();
1219 if (!_session.engine().connected()) {
1223 if (others.empty()) {
1228 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1229 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1230 ProcessorState pstate (this);
1232 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1238 boost::shared_ptr<PluginInsert> pi;
1240 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1244 _processors.insert (loc, *i);
1245 (*i)->set_owner (this);
1247 if ((*i)->active()) {
1251 /* Think: does this really need to be called for every processor in the loop? */
1253 if (configure_processors_unlocked (err)) {
1255 configure_processors_unlocked (0); // it worked before we tried to add it ...
1260 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1263 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1264 boost::shared_ptr<PluginInsert> pi;
1266 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1267 if (pi->has_no_inputs ()) {
1268 _have_internal_generator = true;
1274 _output->set_user_latency (0);
1277 reset_instrument_info ();
1278 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1279 set_processor_positions ();
1285 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1287 if (p == PreFader) {
1288 start = _processors.begin();
1289 end = find(_processors.begin(), _processors.end(), _amp);
1291 start = find(_processors.begin(), _processors.end(), _amp);
1293 end = _processors.end();
1297 /** Turn off all processors with a given placement
1298 * @param p Placement of processors to disable
1301 Route::disable_processors (Placement p)
1303 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1305 ProcessorList::iterator start, end;
1306 placement_range(p, start, end);
1308 for (ProcessorList::iterator i = start; i != end; ++i) {
1309 (*i)->deactivate ();
1312 _session.set_dirty ();
1315 /** Turn off all redirects
1318 Route::disable_processors ()
1320 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1322 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1323 (*i)->deactivate ();
1326 _session.set_dirty ();
1329 /** Turn off all redirects with a given placement
1330 * @param p Placement of redirects to disable
1333 Route::disable_plugins (Placement p)
1335 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1337 ProcessorList::iterator start, end;
1338 placement_range(p, start, end);
1340 for (ProcessorList::iterator i = start; i != end; ++i) {
1341 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1342 (*i)->deactivate ();
1346 _session.set_dirty ();
1349 /** Turn off all plugins
1352 Route::disable_plugins ()
1354 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1356 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1357 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1358 (*i)->deactivate ();
1362 _session.set_dirty ();
1367 Route::ab_plugins (bool forward)
1369 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1373 /* forward = turn off all active redirects, and mark them so that the next time
1374 we go the other way, we will revert them
1377 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1378 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1382 if ((*i)->active()) {
1383 (*i)->deactivate ();
1384 (*i)->set_next_ab_is_active (true);
1386 (*i)->set_next_ab_is_active (false);
1392 /* backward = if the redirect was marked to go active on the next ab, do so */
1394 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1396 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1400 if ((*i)->get_next_ab_is_active()) {
1403 (*i)->deactivate ();
1408 _session.set_dirty ();
1412 /** Remove processors with a given placement.
1413 * @param p Placement of processors to remove.
1416 Route::clear_processors (Placement p)
1418 if (!_session.engine().connected()) {
1422 bool already_deleting = _session.deletion_in_progress();
1423 if (!already_deleting) {
1424 _session.set_deletion_in_progress();
1428 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1429 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1430 ProcessorList new_list;
1431 ProcessorStreams err;
1432 bool seen_amp = false;
1434 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1440 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline) {
1442 /* you can't remove these */
1444 new_list.push_back (*i);
1451 new_list.push_back (*i);
1454 (*i)->drop_references ();
1462 (*i)->drop_references ();
1465 new_list.push_back (*i);
1472 _processors = new_list;
1473 configure_processors_unlocked (&err); // this can't fail
1476 processor_max_streams.reset();
1477 _have_internal_generator = false;
1478 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1479 set_processor_positions ();
1481 reset_instrument_info ();
1483 if (!already_deleting) {
1484 _session.clear_deletion_in_progress();
1489 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1491 // TODO once the export point can be configured properly, do something smarter here
1492 if (processor == _capturing_processor) {
1493 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1494 if (need_process_lock) {
1498 _capturing_processor.reset();
1500 if (need_process_lock) {
1505 /* these can never be removed */
1507 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1511 if (!_session.engine().connected()) {
1515 processor_max_streams.reset();
1518 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1519 if (need_process_lock) {
1523 /* Caller must hold process lock */
1524 assert (!AudioEngine::instance()->process_lock().trylock());
1526 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1528 ProcessorState pstate (this);
1530 ProcessorList::iterator i;
1531 bool removed = false;
1533 for (i = _processors.begin(); i != _processors.end(); ) {
1534 if (*i == processor) {
1536 /* move along, see failure case for configure_processors()
1537 where we may need to reconfigure the processor.
1540 /* stop redirects that send signals to JACK ports
1541 from causing noise as a result of no longer being
1545 boost::shared_ptr<IOProcessor> iop;
1547 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1551 i = _processors.erase (i);
1559 _output->set_user_latency (0);
1567 if (configure_processors_unlocked (err)) {
1569 /* we know this will work, because it worked before :) */
1570 configure_processors_unlocked (0);
1574 _have_internal_generator = false;
1576 for (i = _processors.begin(); i != _processors.end(); ++i) {
1577 boost::shared_ptr<PluginInsert> pi;
1579 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1580 if (pi->has_no_inputs ()) {
1581 _have_internal_generator = true;
1586 if (need_process_lock) {
1591 reset_instrument_info ();
1592 processor->drop_references ();
1593 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1594 set_processor_positions ();
1600 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1602 ProcessorList deleted;
1604 if (!_session.engine().connected()) {
1608 processor_max_streams.reset();
1611 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1612 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1613 ProcessorState pstate (this);
1615 ProcessorList::iterator i;
1616 boost::shared_ptr<Processor> processor;
1618 for (i = _processors.begin(); i != _processors.end(); ) {
1622 /* these can never be removed */
1624 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1629 /* see if its in the list of processors to delete */
1631 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1636 /* stop IOProcessors that send to JACK ports
1637 from causing noise as a result of no longer being
1641 boost::shared_ptr<IOProcessor> iop;
1643 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1647 deleted.push_back (processor);
1648 i = _processors.erase (i);
1651 if (deleted.empty()) {
1652 /* none of those in the requested list were found */
1656 _output->set_user_latency (0);
1658 if (configure_processors_unlocked (err)) {
1660 /* we know this will work, because it worked before :) */
1661 configure_processors_unlocked (0);
1666 _have_internal_generator = false;
1668 for (i = _processors.begin(); i != _processors.end(); ++i) {
1669 boost::shared_ptr<PluginInsert> pi;
1671 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1672 if (pi->has_no_inputs ()) {
1673 _have_internal_generator = true;
1680 /* now try to do what we need to so that those that were removed will be deleted */
1682 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1683 (*i)->drop_references ();
1686 reset_instrument_info ();
1687 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1688 set_processor_positions ();
1694 Route::reset_instrument_info ()
1696 boost::shared_ptr<Processor> instr = the_instrument();
1698 _instrument_info.set_internal_instrument (instr);
1702 /** Caller must hold process lock */
1704 Route::configure_processors (ProcessorStreams* err)
1706 #ifndef PLATFORM_WINDOWS
1707 assert (!AudioEngine::instance()->process_lock().trylock());
1710 if (!_in_configure_processors) {
1711 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1712 return configure_processors_unlocked (err);
1719 Route::input_streams () const
1721 return _input->n_ports ();
1724 list<pair<ChanCount, ChanCount> >
1725 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1727 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1729 return try_configure_processors_unlocked (in, err);
1732 list<pair<ChanCount, ChanCount> >
1733 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1735 // Check each processor in order to see if we can configure as requested
1737 list<pair<ChanCount, ChanCount> > configuration;
1740 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1741 DEBUG_TRACE (DEBUG::Processors, "{\n");
1743 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1745 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1746 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1747 DEBUG_TRACE (DEBUG::Processors, "}\n");
1748 return list<pair<ChanCount, ChanCount> > ();
1751 if ((*p)->can_support_io_configuration(in, out)) {
1752 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1753 configuration.push_back(make_pair(in, out));
1760 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1761 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1762 DEBUG_TRACE (DEBUG::Processors, "}\n");
1763 return list<pair<ChanCount, ChanCount> > ();
1767 DEBUG_TRACE (DEBUG::Processors, "}\n");
1769 return configuration;
1772 /** Set the input/output configuration of each processor in the processors list.
1773 * Caller must hold process lock.
1774 * Return 0 on success, otherwise configuration is impossible.
1777 Route::configure_processors_unlocked (ProcessorStreams* err)
1779 #ifndef PLATFORM_WINDOWS
1780 assert (!AudioEngine::instance()->process_lock().trylock());
1783 if (_in_configure_processors) {
1787 /* put invisible processors where they should be */
1788 setup_invisible_processors ();
1790 _in_configure_processors = true;
1792 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1794 if (configuration.empty ()) {
1795 _in_configure_processors = false;
1800 bool seen_mains_out = false;
1801 processor_out_streams = _input->n_ports();
1802 processor_max_streams.reset();
1804 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1805 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1807 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1811 (*p)->configure_io(c->first, c->second);
1812 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1813 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1816 if (boost::dynamic_pointer_cast<Delivery> (*p)
1817 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1818 /* main delivery will increase port count to match input.
1819 * the Delivery::Main is usually the last processor - followed only by
1822 seen_mains_out = true;
1824 if (!seen_mains_out) {
1825 processor_out_streams = out;
1831 _meter->reset_max_channels (processor_max_streams);
1834 /* make sure we have sufficient scratch buffers to cope with the new processor
1837 _session.ensure_buffers (n_process_buffers ());
1839 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1841 _in_configure_processors = false;
1845 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1846 * @param state New active state for those processors.
1849 Route::all_visible_processors_active (bool state)
1851 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1853 if (_processors.empty()) {
1857 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1858 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1865 (*i)->deactivate ();
1869 _session.set_dirty ();
1873 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1875 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1876 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1877 processors in the current actual processor list that are hidden. Any visible processors
1878 in the current list but not in "new_order" will be assumed to be deleted.
1882 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1883 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1884 ProcessorState pstate (this);
1886 ProcessorList::iterator oiter;
1887 ProcessorList::const_iterator niter;
1888 ProcessorList as_it_will_be;
1890 oiter = _processors.begin();
1891 niter = new_order.begin();
1893 while (niter != new_order.end()) {
1895 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1896 then append it to the temp list.
1898 Otherwise, see if the next processor in the old list is in the new list. if not,
1899 its been deleted. If its there, append it to the temp list.
1902 if (oiter == _processors.end()) {
1904 /* no more elements in the old list, so just stick the rest of
1905 the new order onto the temp list.
1908 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1909 while (niter != new_order.end()) {
1916 if (!(*oiter)->display_to_user()) {
1918 as_it_will_be.push_back (*oiter);
1922 /* visible processor: check that its in the new order */
1924 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1925 /* deleted: do nothing, shared_ptr<> will clean up */
1927 /* ignore this one, and add the next item from the new order instead */
1928 as_it_will_be.push_back (*niter);
1933 /* now remove from old order - its taken care of no matter what */
1934 oiter = _processors.erase (oiter);
1939 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1941 /* If the meter is in a custom position, find it and make a rough note of its position */
1942 maybe_note_meter_position ();
1944 if (configure_processors_unlocked (err)) {
1950 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1951 set_processor_positions ();
1963 Route::get_template()
1965 return state(false);
1969 Route::state(bool full_state)
1971 XMLNode *node = new XMLNode("Route");
1972 ProcessorList::iterator i;
1975 id().print (buf, sizeof (buf));
1976 node->add_property("id", buf);
1977 node->add_property ("name", _name);
1978 node->add_property("default-type", _default_type.to_string());
1981 node->add_property("flags", enum_2_string (_flags));
1984 node->add_property("active", _active?"yes":"no");
1986 boost::to_string (_phase_invert, p);
1987 node->add_property("phase-invert", p);
1988 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1989 node->add_property("meter-point", enum_2_string (_meter_point));
1991 node->add_property("meter-type", enum_2_string (_meter_type));
1994 node->add_property("route-group", _route_group->name());
1997 snprintf (buf, sizeof (buf), "%d", _order_key);
1998 node->add_property ("order-key", buf);
1999 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2000 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2001 node->add_property ("soloed-by-upstream", buf);
2002 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2003 node->add_property ("soloed-by-downstream", buf);
2004 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2005 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2007 node->add_child_nocopy (_input->state (full_state));
2008 node->add_child_nocopy (_output->state (full_state));
2009 node->add_child_nocopy (_solo_control->get_state ());
2010 node->add_child_nocopy (_mute_control->get_state ());
2011 node->add_child_nocopy (_mute_master->get_state ());
2013 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2014 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2015 remote_control_node->add_property (X_("id"), buf);
2016 node->add_child_nocopy (*remote_control_node);
2018 if (_comment.length()) {
2019 XMLNode *cmt = node->add_child ("Comment");
2020 cmt->add_content (_comment);
2024 node->add_child_nocopy (_pannable->state (full_state));
2027 for (i = _processors.begin(); i != _processors.end(); ++i) {
2029 /* template save: do not include internal sends functioning as
2030 aux sends because the chance of the target ID
2031 in the session where this template is used
2034 similarly, do not save listen sends which connect to
2035 the monitor section, because these will always be
2038 boost::shared_ptr<InternalSend> is;
2040 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2041 if (is->role() == Delivery::Listen) {
2046 node->add_child_nocopy((*i)->state (full_state));
2050 node->add_child_copy (*_extra_xml);
2053 if (_custom_meter_position_noted) {
2054 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2056 after->id().print (buf, sizeof (buf));
2057 node->add_property (X_("processor-after-last-custom-meter"), buf);
2060 node->add_property (X_("last-custom-meter-was-at-end"), _last_custom_meter_was_at_end ? "yes" : "no");
2067 Route::set_state (const XMLNode& node, int version)
2069 if (version < 3000) {
2070 return set_state_2X (node, version);
2074 XMLNodeConstIterator niter;
2076 const XMLProperty *prop;
2078 if (node.name() != "Route"){
2079 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2083 if ((prop = node.property (X_("name"))) != 0) {
2084 Route::set_name (prop->value());
2088 _initial_io_setup = true;
2090 if ((prop = node.property (X_("flags"))) != 0) {
2091 _flags = Flag (string_2_enum (prop->value(), _flags));
2096 if (is_master() || is_monitor() || is_auditioner()) {
2097 _mute_master->set_solo_ignore (true);
2101 /* monitor bus does not get a panner, but if (re)created
2102 via XML, it will already have one by the time we
2103 call ::set_state(). so ... remove it.
2108 /* add all processors (except amp, which is always present) */
2110 nlist = node.children();
2111 XMLNode processor_state (X_("processor_state"));
2113 Stateful::save_extra_xml (node);
2115 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2119 if (child->name() == IO::state_node_name) {
2120 if ((prop = child->property (X_("direction"))) == 0) {
2124 if (prop->value() == "Input") {
2125 _input->set_state (*child, version);
2126 } else if (prop->value() == "Output") {
2127 _output->set_state (*child, version);
2131 if (child->name() == X_("Processor")) {
2132 processor_state.add_child_copy (*child);
2135 if (child->name() == X_("Pannable")) {
2137 _pannable->set_state (*child, version);
2139 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2144 if ((prop = node.property (X_("meter-point"))) != 0) {
2145 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2146 set_meter_point (mp, true);
2148 _meter->set_display_to_user (_meter_point == MeterCustom);
2152 if ((prop = node.property (X_("meter-type"))) != 0) {
2153 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2156 _initial_io_setup = false;
2158 set_processor_state (processor_state);
2160 // this looks up the internal instrument in processors
2161 reset_instrument_info();
2163 if ((prop = node.property ("self-solo")) != 0) {
2164 set_self_solo (string_is_affirmative (prop->value()));
2167 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2168 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2169 mod_solo_by_others_upstream (atoi (prop->value()));
2172 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2173 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2174 mod_solo_by_others_downstream (atoi (prop->value()));
2177 if ((prop = node.property ("solo-isolated")) != 0) {
2178 set_solo_isolated (string_is_affirmative (prop->value()), this);
2181 if ((prop = node.property ("solo-safe")) != 0) {
2182 set_solo_safe (string_is_affirmative (prop->value()), this);
2185 if ((prop = node.property (X_("phase-invert"))) != 0) {
2186 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2189 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2190 set_denormal_protection (string_is_affirmative (prop->value()));
2193 if ((prop = node.property (X_("active"))) != 0) {
2194 bool yn = string_is_affirmative (prop->value());
2195 _active = !yn; // force switch
2196 set_active (yn, this);
2199 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2200 set_order_key (atoi(prop->value()));
2203 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2207 string::size_type colon, equal;
2208 string remaining = prop->value();
2210 while (remaining.length()) {
2212 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2213 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2216 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2217 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2220 string keyname = remaining.substr (0, equal);
2222 if ((keyname == "EditorSort") || (keyname == "editor")) {
2223 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2229 colon = remaining.find_first_of (':');
2231 if (colon != string::npos) {
2232 remaining = remaining.substr (colon+1);
2239 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2240 PBD::ID id (prop->value ());
2241 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2242 ProcessorList::const_iterator i = _processors.begin ();
2243 while (i != _processors.end() && (*i)->id() != id) {
2247 if (i != _processors.end ()) {
2248 _processor_after_last_custom_meter = *i;
2249 _custom_meter_position_noted = true;
2253 if ((prop = node.property (X_("last-custom-meter-was-at-end"))) != 0) {
2254 _last_custom_meter_was_at_end = string_is_affirmative (prop->value ());
2257 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2260 if (child->name() == X_("Comment")) {
2262 /* XXX this is a terrible API design in libxml++ */
2264 XMLNode *cmt = *(child->children().begin());
2265 _comment = cmt->content();
2267 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2268 if (prop->value() == "solo") {
2269 _solo_control->set_state (*child, version);
2270 } else if (prop->value() == "mute") {
2271 _mute_control->set_state (*child, version);
2274 } else if (child->name() == X_("RemoteControl")) {
2275 if ((prop = child->property (X_("id"))) != 0) {
2277 sscanf (prop->value().c_str(), "%d", &x);
2278 set_remote_control_id_internal (x);
2281 } else if (child->name() == X_("MuteMaster")) {
2282 _mute_master->set_state (*child, version);
2290 Route::set_state_2X (const XMLNode& node, int version)
2293 XMLNodeConstIterator niter;
2295 const XMLProperty *prop;
2297 /* 2X things which still remain to be handled:
2303 if (node.name() != "Route") {
2304 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2308 if ((prop = node.property (X_("flags"))) != 0) {
2309 string f = prop->value ();
2310 boost::replace_all (f, "ControlOut", "MonitorOut");
2311 _flags = Flag (string_2_enum (f, _flags));
2316 if (is_master() || is_monitor() || is_auditioner()) {
2317 _mute_master->set_solo_ignore (true);
2320 if ((prop = node.property (X_("phase-invert"))) != 0) {
2321 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2322 if (string_is_affirmative (prop->value ())) {
2325 set_phase_invert (p);
2328 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2329 set_denormal_protection (string_is_affirmative (prop->value()));
2332 if ((prop = node.property (X_("soloed"))) != 0) {
2333 bool yn = string_is_affirmative (prop->value());
2335 /* XXX force reset of solo status */
2337 set_solo (yn, this);
2340 if ((prop = node.property (X_("muted"))) != 0) {
2343 bool muted = string_is_affirmative (prop->value());
2349 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2351 if (string_is_affirmative (prop->value())){
2352 mute_point = mute_point + "PreFader";
2357 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2359 if (string_is_affirmative (prop->value())){
2362 mute_point = mute_point + ",";
2365 mute_point = mute_point + "PostFader";
2370 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2372 if (string_is_affirmative (prop->value())){
2375 mute_point = mute_point + ",";
2378 mute_point = mute_point + "Listen";
2383 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2385 if (string_is_affirmative (prop->value())){
2388 mute_point = mute_point + ",";
2391 mute_point = mute_point + "Main";
2395 _mute_master->set_mute_points (mute_point);
2396 _mute_master->set_muted_by_self (true);
2400 if ((prop = node.property (X_("meter-point"))) != 0) {
2401 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2404 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2405 don't mean the same thing.
2408 if ((prop = node.property (X_("order-keys"))) != 0) {
2412 string::size_type colon, equal;
2413 string remaining = prop->value();
2415 while (remaining.length()) {
2417 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2418 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2421 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2422 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2425 string keyname = remaining.substr (0, equal);
2427 if (keyname == "EditorSort" || keyname == "editor") {
2428 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2434 colon = remaining.find_first_of (':');
2436 if (colon != string::npos) {
2437 remaining = remaining.substr (colon+1);
2446 nlist = node.children ();
2447 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2451 if (child->name() == IO::state_node_name) {
2453 /* there is a note in IO::set_state_2X() about why we have to call
2457 _input->set_state_2X (*child, version, true);
2458 _output->set_state_2X (*child, version, false);
2460 if ((prop = child->property (X_("name"))) != 0) {
2461 Route::set_name (prop->value ());
2466 if ((prop = child->property (X_("active"))) != 0) {
2467 bool yn = string_is_affirmative (prop->value());
2468 _active = !yn; // force switch
2469 set_active (yn, this);
2472 if ((prop = child->property (X_("gain"))) != 0) {
2475 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2476 _amp->gain_control()->set_value (val);
2480 /* Set up Panners in the IO */
2481 XMLNodeList io_nlist = child->children ();
2483 XMLNodeConstIterator io_niter;
2486 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2488 io_child = *io_niter;
2490 if (io_child->name() == X_("Panner")) {
2491 _main_outs->panner_shell()->set_state(*io_child, version);
2492 } else if (io_child->name() == X_("Automation")) {
2493 /* IO's automation is for the fader */
2494 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2500 XMLNodeList redirect_nodes;
2502 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2506 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2507 redirect_nodes.push_back(child);
2512 set_processor_state_2X (redirect_nodes, version);
2514 Stateful::save_extra_xml (node);
2516 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2519 if (child->name() == X_("Comment")) {
2521 /* XXX this is a terrible API design in libxml++ */
2523 XMLNode *cmt = *(child->children().begin());
2524 _comment = cmt->content();
2526 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2527 if (prop->value() == X_("solo")) {
2528 _solo_control->set_state (*child, version);
2529 } else if (prop->value() == X_("mute")) {
2530 _mute_control->set_state (*child, version);
2533 } else if (child->name() == X_("RemoteControl")) {
2534 if ((prop = child->property (X_("id"))) != 0) {
2536 sscanf (prop->value().c_str(), "%d", &x);
2537 set_remote_control_id_internal (x);
2547 Route::get_processor_state ()
2549 XMLNode* root = new XMLNode (X_("redirects"));
2550 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2551 root->add_child_nocopy ((*i)->state (true));
2558 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2560 /* We don't bother removing existing processors not in nList, as this
2561 method will only be called when creating a Route from scratch, not
2562 for undo purposes. Just put processors in at the appropriate place
2566 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2567 add_processor_from_xml_2X (**i, version);
2572 Route::set_processor_state (const XMLNode& node)
2574 const XMLNodeList &nlist = node.children();
2575 XMLNodeConstIterator niter;
2576 ProcessorList new_order;
2577 bool must_configure = false;
2579 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2581 XMLProperty* prop = (*niter)->property ("type");
2583 if (prop->value() == "amp") {
2584 _amp->set_state (**niter, Stateful::current_state_version);
2585 new_order.push_back (_amp);
2586 } else if (prop->value() == "meter") {
2587 _meter->set_state (**niter, Stateful::current_state_version);
2588 new_order.push_back (_meter);
2589 } else if (prop->value() == "delay") {
2590 _delayline->set_state (**niter, Stateful::current_state_version);
2591 new_order.push_back (_delayline);
2592 } else if (prop->value() == "main-outs") {
2593 _main_outs->set_state (**niter, Stateful::current_state_version);
2594 } else if (prop->value() == "intreturn") {
2596 _intreturn.reset (new InternalReturn (_session));
2597 must_configure = true;
2599 _intreturn->set_state (**niter, Stateful::current_state_version);
2600 } else if (is_monitor() && prop->value() == "monitor") {
2601 if (!_monitor_control) {
2602 _monitor_control.reset (new MonitorProcessor (_session));
2603 must_configure = true;
2605 _monitor_control->set_state (**niter, Stateful::current_state_version);
2606 } else if (prop->value() == "capture") {
2607 /* CapturingProcessor should never be restored, it's always
2608 added explicitly when needed */
2610 ProcessorList::iterator o;
2612 for (o = _processors.begin(); o != _processors.end(); ++o) {
2613 XMLProperty* id_prop = (*niter)->property(X_("id"));
2614 if (id_prop && (*o)->id() == id_prop->value()) {
2615 (*o)->set_state (**niter, Stateful::current_state_version);
2616 new_order.push_back (*o);
2621 // If the processor (*niter) is not on the route then create it
2623 if (o == _processors.end()) {
2625 boost::shared_ptr<Processor> processor;
2627 if (prop->value() == "intsend") {
2629 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::shared_ptr<Route>(), Delivery::Aux, true));
2631 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2632 prop->value() == "lv2" ||
2633 prop->value() == "windows-vst" ||
2634 prop->value() == "lxvst" ||
2635 prop->value() == "audiounit") {
2637 processor.reset (new PluginInsert(_session));
2639 } else if (prop->value() == "port") {
2641 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2643 } else if (prop->value() == "send") {
2645 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2648 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2652 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2653 /* This processor could not be configured. Turn it into a UnknownProcessor */
2654 processor.reset (new UnknownProcessor (_session, **niter));
2657 /* we have to note the monitor send here, otherwise a new one will be created
2658 and the state of this one will be lost.
2660 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2661 if (isend && isend->role() == Delivery::Listen) {
2662 _monitor_send = isend;
2665 /* it doesn't matter if invisible processors are added here, as they
2666 will be sorted out by setup_invisible_processors () shortly.
2669 new_order.push_back (processor);
2670 must_configure = true;
2676 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2677 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2678 _processors = new_order;
2680 if (must_configure) {
2681 configure_processors_unlocked (0);
2684 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2686 (*i)->set_owner (this);
2687 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2689 boost::shared_ptr<PluginInsert> pi;
2691 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2692 if (pi->has_no_inputs ()) {
2693 _have_internal_generator = true;
2700 reset_instrument_info ();
2701 processors_changed (RouteProcessorChange ());
2702 set_processor_positions ();
2706 Route::curve_reallocate ()
2708 // _gain_automation_curve.finish_resize ();
2709 // _pan_automation_curve.finish_resize ();
2713 Route::silence (framecnt_t nframes)
2715 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2720 silence_unlocked (nframes);
2724 Route::silence_unlocked (framecnt_t nframes)
2726 /* Must be called with the processor lock held */
2730 _output->silence (nframes);
2732 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2733 boost::shared_ptr<PluginInsert> pi;
2735 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2736 // skip plugins, they don't need anything when we're not active
2740 (*i)->silence (nframes);
2743 if (nframes == _session.get_block_size()) {
2750 Route::add_internal_return ()
2753 _intreturn.reset (new InternalReturn (_session));
2754 add_processor (_intreturn, PreFader);
2759 Route::add_send_to_internal_return (InternalSend* send)
2761 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2763 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2764 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2767 return d->add_send (send);
2773 Route::remove_send_from_internal_return (InternalSend* send)
2775 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2777 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2778 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2781 return d->remove_send (send);
2787 Route::enable_monitor_send ()
2789 /* Caller must hold process lock */
2790 assert (!AudioEngine::instance()->process_lock().trylock());
2792 /* master never sends to monitor section via the normal mechanism */
2793 assert (!is_master ());
2794 assert (!is_monitor ());
2796 /* make sure we have one */
2797 if (!_monitor_send) {
2798 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, _session.monitor_out(), Delivery::Listen));
2799 _monitor_send->set_display_to_user (false);
2803 configure_processors (0);
2806 /** Add an aux send to a route.
2807 * @param route route to send to.
2808 * @param before Processor to insert before, or 0 to insert at the end.
2811 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2813 assert (route != _session.monitor_out ());
2816 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2818 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2820 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2822 if (d && d->target_route() == route) {
2823 /* already listening via the specified IO: do nothing */
2831 boost::shared_ptr<InternalSend> listener;
2834 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2835 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
2836 listener.reset (new InternalSend (_session, sendpan, _mute_master, route, Delivery::Aux));
2839 add_processor (listener, before);
2841 } catch (failed_constructor& err) {
2849 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
2851 ProcessorStreams err;
2852 ProcessorList::iterator tmp;
2855 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
2857 /* have to do this early because otherwise processor reconfig
2858 * will put _monitor_send back in the list
2861 if (route == _session.monitor_out()) {
2862 _monitor_send.reset ();
2866 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2868 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2870 if (d && d->target_route() == route) {
2872 remove_processor (*x, &err, false);
2875 /* list could have been demolished while we dropped the lock
2886 Route::set_comment (string cmt, void *src)
2889 comment_changed (src);
2890 _session.set_dirty ();
2894 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2896 FeedRecord fr (other, via_sends_only);
2898 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2900 if (!result.second) {
2902 /* already a record for "other" - make sure sends-only information is correct */
2903 if (!via_sends_only && result.first->sends_only) {
2904 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2905 frp->sends_only = false;
2909 return result.second;
2913 Route::clear_fed_by ()
2919 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2921 const FedBy& fed_by (other->fed_by());
2923 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2924 boost::shared_ptr<Route> sr = f->r.lock();
2926 if (sr && (sr.get() == this)) {
2928 if (via_sends_only) {
2929 *via_sends_only = f->sends_only;
2940 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
2942 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2944 if (_output->connected_to (other->input())) {
2945 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2946 if (via_send_only) {
2947 *via_send_only = false;
2954 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2956 boost::shared_ptr<IOProcessor> iop;
2958 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2959 if (iop->feeds (other)) {
2960 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2961 if (via_send_only) {
2962 *via_send_only = true;
2966 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2969 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2974 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2979 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
2981 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
2984 /** Called from the (non-realtime) butler thread when the transport is stopped */
2986 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
2988 framepos_t now = _session.transport_frame();
2991 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2993 Automatable::transport_stopped (now);
2995 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2997 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3001 (*i)->transport_stopped (now);
3005 _roll_delay = _initial_delay;
3009 Route::input_change_handler (IOChange change, void * /*src*/)
3011 bool need_to_queue_solo_change = true;
3013 if ((change.type & IOChange::ConfigurationChanged)) {
3014 /* This is called with the process lock held if change
3015 contains ConfigurationChanged
3017 need_to_queue_solo_change = false;
3018 configure_processors (0);
3019 _phase_invert.resize (_input->n_ports().n_audio ());
3020 io_changed (); /* EMIT SIGNAL */
3023 if (!_input->connected() && _soloed_by_others_upstream) {
3024 if (need_to_queue_solo_change) {
3025 _session.cancel_solo_after_disconnect (shared_from_this(), true);
3027 cancel_solo_after_disconnect (true);
3033 Route::output_change_handler (IOChange change, void * /*src*/)
3035 bool need_to_queue_solo_change = true;
3036 if (_initial_io_setup) {
3040 if ((change.type & IOChange::ConfigurationChanged)) {
3041 /* This is called with the process lock held if change
3042 contains ConfigurationChanged
3044 need_to_queue_solo_change = false;
3045 configure_processors (0);
3046 io_changed (); /* EMIT SIGNAL */
3049 if (!_output->connected() && _soloed_by_others_downstream) {
3050 if (need_to_queue_solo_change) {
3051 _session.cancel_solo_after_disconnect (shared_from_this(), false);
3053 cancel_solo_after_disconnect (false);
3059 Route::cancel_solo_after_disconnect (bool upstream)
3062 _soloed_by_others_upstream = 0;
3064 _soloed_by_others_downstream = 0;
3066 set_mute_master_solo ();
3067 solo_changed (false, this);
3071 Route::pans_required () const
3073 if (n_outputs().n_audio() < 2) {
3077 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3081 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3083 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3089 if (n_outputs().n_total() == 0) {
3093 if (!_active || n_inputs() == ChanCount::ZERO) {
3094 silence_unlocked (nframes);
3098 if (session_state_changing) {
3099 if (_session.transport_speed() != 0.0f) {
3100 /* we're rolling but some state is changing (e.g. our diskstream contents)
3101 so we cannot use them. Be silent till this is over.
3103 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3105 silence_unlocked (nframes);
3108 /* we're really not rolling, so we're either delivery silence or actually
3109 monitoring, both of which are safe to do while session_state_changing is true.
3113 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3115 fill_buffers_with_input (bufs, _input, nframes);
3117 if (_meter_point == MeterInput) {
3118 _meter->run (bufs, start_frame, end_frame, nframes, true);
3121 _amp->apply_gain_automation (false);
3122 passthru (bufs, start_frame, end_frame, nframes, 0);
3128 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3130 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3135 if (n_outputs().n_total() == 0) {
3139 if (!_active || n_inputs().n_total() == 0) {
3140 silence_unlocked (nframes);
3144 framepos_t unused = 0;
3146 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3152 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3154 fill_buffers_with_input (bufs, _input, nframes);
3156 if (_meter_point == MeterInput) {
3157 _meter->run (bufs, start_frame, end_frame, nframes, true);
3160 passthru (bufs, start_frame, end_frame, nframes, declick);
3166 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3173 Route::flush_processors ()
3175 /* XXX shouldn't really try to take this lock, since
3176 this is called from the RT audio thread.
3179 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3181 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3187 Route::set_meter_point (MeterPoint p, bool force)
3189 if (_meter_point == p && !force) {
3193 bool meter_was_visible_to_user = _meter->display_to_user ();
3196 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3197 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3199 maybe_note_meter_position ();
3203 if (_meter_point != MeterCustom) {
3205 _meter->set_display_to_user (false);
3207 setup_invisible_processors ();
3211 _meter->set_display_to_user (true);
3213 /* If we have a previous position for the custom meter, try to put it there */
3214 if (_custom_meter_position_noted) {
3215 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3218 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3219 if (i != _processors.end ()) {
3220 _processors.remove (_meter);
3221 _processors.insert (i, _meter);
3223 } else if (_last_custom_meter_was_at_end) {
3224 _processors.remove (_meter);
3225 _processors.push_back (_meter);
3230 /* Set up the meter for its new position */
3232 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3236 if (loc == _processors.begin()) {
3237 m_in = _input->n_ports();
3239 ProcessorList::iterator before = loc;
3241 m_in = (*before)->output_streams ();
3244 _meter->reflect_inputs (m_in);
3246 /* we do not need to reconfigure the processors, because the meter
3247 (a) is always ready to handle processor_max_streams
3248 (b) is always an N-in/N-out processor, and thus moving
3249 it doesn't require any changes to the other processors.
3253 meter_change (); /* EMIT SIGNAL */
3255 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3257 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3261 Route::listen_position_changed ()
3264 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3265 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3266 ProcessorState pstate (this);
3268 if (configure_processors_unlocked (0)) {
3270 configure_processors_unlocked (0); // it worked before we tried to add it ...
3275 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3276 _session.set_dirty ();
3279 boost::shared_ptr<CapturingProcessor>
3280 Route::add_export_point()
3282 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3283 if (!_capturing_processor) {
3285 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3286 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3288 _capturing_processor.reset (new CapturingProcessor (_session));
3289 _capturing_processor->activate ();
3291 configure_processors_unlocked (0);
3295 return _capturing_processor;
3299 Route::update_signal_latency ()
3301 framecnt_t l = _output->user_latency();
3303 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3304 if ((*i)->active ()) {
3305 l += (*i)->signal_latency ();
3309 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3311 if (_signal_latency != l) {
3312 _signal_latency = l;
3313 signal_latency_changed (); /* EMIT SIGNAL */
3316 return _signal_latency;
3320 Route::set_user_latency (framecnt_t nframes)
3322 _output->set_user_latency (nframes);
3323 _session.update_latency_compensation ();
3327 Route::set_latency_compensation (framecnt_t longest_session_latency)
3329 framecnt_t old = _initial_delay;
3331 if (_signal_latency < longest_session_latency) {
3332 _initial_delay = longest_session_latency - _signal_latency;
3337 DEBUG_TRACE (DEBUG::Latency, string_compose (
3338 "%1: compensate for maximum latency of %2,"
3339 "given own latency of %3, using initial delay of %4\n",
3340 name(), longest_session_latency, _signal_latency, _initial_delay));
3342 if (_initial_delay != old) {
3343 initial_delay_changed (); /* EMIT SIGNAL */
3346 if (_session.transport_stopped()) {
3347 _roll_delay = _initial_delay;
3351 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3352 : AutomationControl (r->session(), Evoral::Parameter (SoloAutomation),
3353 boost::shared_ptr<AutomationList>(), name)
3356 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3361 Route::SoloControllable::set_value (double val)
3363 bool bval = ((val >= 0.5f) ? true: false);
3365 boost::shared_ptr<RouteList> rl (new RouteList);
3367 boost::shared_ptr<Route> r = _route.lock ();
3374 if (Config->get_solo_control_is_listen_control()) {
3375 _session.set_listen (rl, bval);
3377 _session.set_solo (rl, bval);
3382 Route::SoloControllable::get_value () const
3384 boost::shared_ptr<Route> r = _route.lock ();
3389 if (Config->get_solo_control_is_listen_control()) {
3390 return r->listening_via_monitor() ? 1.0f : 0.0f;
3392 return r->self_soloed() ? 1.0f : 0.0f;
3396 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3397 : AutomationControl (r->session(), Evoral::Parameter (MuteAutomation),
3398 boost::shared_ptr<AutomationList>(), name)
3401 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3406 Route::MuteControllable::set_value (double val)
3408 bool bval = ((val >= 0.5f) ? true: false);
3410 boost::shared_ptr<RouteList> rl (new RouteList);
3412 boost::shared_ptr<Route> r = _route.lock ();
3418 _session.set_mute (rl, bval);
3422 Route::MuteControllable::get_value () const
3424 boost::shared_ptr<Route> r = _route.lock ();
3429 return r->muted() ? 1.0f : 0.0f;
3433 Route::set_block_size (pframes_t nframes)
3435 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3436 (*i)->set_block_size (nframes);
3439 _session.ensure_buffers (n_process_buffers ());
3443 Route::protect_automation ()
3445 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3446 (*i)->protect_automation();
3449 /** @param declick 1 to set a pending declick fade-in,
3450 * -1 to set a pending declick fade-out
3453 Route::set_pending_declick (int declick)
3456 /* this call is not allowed to turn off a pending declick */
3458 _pending_declick = declick;
3461 _pending_declick = 0;
3465 /** Shift automation forwards from a particular place, thereby inserting time.
3466 * Adds undo commands for any shifts that are performed.
3468 * @param pos Position to start shifting from.
3469 * @param frames Amount to shift forwards by.
3473 Route::shift (framepos_t pos, framecnt_t frames)
3475 /* gain automation */
3477 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3479 XMLNode &before = gc->alist()->get_state ();
3480 gc->alist()->shift (pos, frames);
3481 XMLNode &after = gc->alist()->get_state ();
3482 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3485 /* pan automation */
3487 ControlSet::Controls& c (_pannable->controls());
3489 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3490 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3492 boost::shared_ptr<AutomationList> al = pc->alist();
3493 XMLNode& before = al->get_state ();
3494 al->shift (pos, frames);
3495 XMLNode& after = al->get_state ();
3496 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3501 /* redirect automation */
3503 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3504 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3506 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3508 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3509 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3511 boost::shared_ptr<AutomationList> al = ac->alist();
3512 XMLNode &before = al->get_state ();
3513 al->shift (pos, frames);
3514 XMLNode &after = al->get_state ();
3515 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3524 Route::save_as_template (const string& path, const string& name)
3526 XMLNode& node (state (false));
3529 IO::set_name_in_state (*node.children().front(), name);
3531 tree.set_root (&node);
3532 return tree.write (path.c_str());
3537 Route::set_name (const string& str)
3543 name = Route::ensure_track_or_route_name (str, _session);
3544 SessionObject::set_name (name);
3546 ret = (_input->set_name(name) && _output->set_name(name));
3549 /* rename the main outs. Leave other IO processors
3550 * with whatever name they already have, because its
3551 * just fine as it is (it will not contain the route
3552 * name if its a port insert, port send or port return).
3556 if (_main_outs->set_name (name)) {
3557 /* XXX returning false here is stupid because
3558 we already changed the route name.
3568 /** Set the name of a route in an XML description.
3569 * @param node XML <Route> node to set the name in.
3570 * @param name New name.
3573 Route::set_name_in_state (XMLNode& node, string const & name)
3575 node.add_property (X_("name"), name);
3577 XMLNodeList children = node.children();
3578 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3580 if ((*i)->name() == X_("IO")) {
3582 IO::set_name_in_state (**i, name);
3584 } else if ((*i)->name() == X_("Processor")) {
3586 XMLProperty* role = (*i)->property (X_("role"));
3587 if (role && role->value() == X_("Main")) {
3588 (*i)->add_property (X_("name"), name);
3591 } else if ((*i)->name() == X_("Diskstream")) {
3593 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3594 (*i)->add_property (X_("name"), name);
3600 boost::shared_ptr<Send>
3601 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3603 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3605 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3606 boost::shared_ptr<InternalSend> send;
3608 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3609 if (send->target_route() == target) {
3615 return boost::shared_ptr<Send>();
3618 /** @param c Audio channel index.
3619 * @param yn true to invert phase, otherwise false.
3622 Route::set_phase_invert (uint32_t c, bool yn)
3624 if (_phase_invert[c] != yn) {
3625 _phase_invert[c] = yn;
3626 phase_invert_changed (); /* EMIT SIGNAL */
3627 _session.set_dirty ();
3632 Route::set_phase_invert (boost::dynamic_bitset<> p)
3634 if (_phase_invert != p) {
3636 phase_invert_changed (); /* EMIT SIGNAL */
3637 _session.set_dirty ();
3642 Route::phase_invert (uint32_t c) const
3644 return _phase_invert[c];
3647 boost::dynamic_bitset<>
3648 Route::phase_invert () const
3650 return _phase_invert;
3654 Route::set_denormal_protection (bool yn)
3656 if (_denormal_protection != yn) {
3657 _denormal_protection = yn;
3658 denormal_protection_changed (); /* EMIT SIGNAL */
3663 Route::denormal_protection () const
3665 return _denormal_protection;
3669 Route::set_active (bool yn, void* src)
3671 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3672 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3676 if (_active != yn) {
3678 _input->set_active (yn);
3679 _output->set_active (yn);
3680 active_changed (); // EMIT SIGNAL
3681 _session.set_dirty ();
3688 Glib::Threads::RWLock::ReaderLock rm (_processor_lock, Glib::Threads::TRY_LOCK);
3694 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3696 boost::shared_ptr<Send> s;
3697 boost::shared_ptr<Return> r;
3699 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3700 s->meter()->meter();
3701 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3702 r->meter()->meter ();
3707 boost::shared_ptr<Pannable>
3708 Route::pannable() const
3713 boost::shared_ptr<Panner>
3714 Route::panner() const
3717 return _main_outs->panner_shell()->panner();
3720 boost::shared_ptr<PannerShell>
3721 Route::panner_shell() const
3723 return _main_outs->panner_shell();
3726 boost::shared_ptr<AutomationControl>
3727 Route::gain_control() const
3729 return _amp->gain_control();
3732 boost::shared_ptr<AutomationControl>
3733 Route::get_control (const Evoral::Parameter& param)
3735 /* either we own the control or .... */
3737 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3741 /* maybe one of our processors does or ... */
3743 Glib::Threads::RWLock::ReaderLock rm (_processor_lock, Glib::Threads::TRY_LOCK);
3744 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3745 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3753 /* nobody does so we'll make a new one */
3755 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3762 boost::shared_ptr<Processor>
3763 Route::nth_plugin (uint32_t n)
3765 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3766 ProcessorList::iterator i;
3768 for (i = _processors.begin(); i != _processors.end(); ++i) {
3769 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3776 return boost::shared_ptr<Processor> ();
3779 boost::shared_ptr<Processor>
3780 Route::nth_send (uint32_t n)
3782 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3783 ProcessorList::iterator i;
3785 for (i = _processors.begin(); i != _processors.end(); ++i) {
3786 if (boost::dynamic_pointer_cast<Send> (*i)) {
3793 return boost::shared_ptr<Processor> ();
3797 Route::has_io_processor_named (const string& name)
3799 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3800 ProcessorList::iterator i;
3802 for (i = _processors.begin(); i != _processors.end(); ++i) {
3803 if (boost::dynamic_pointer_cast<Send> (*i) ||
3804 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3805 if ((*i)->name() == name) {
3814 MuteMaster::MutePoint
3815 Route::mute_points () const
3817 return _mute_master->mute_points ();
3821 Route::set_processor_positions ()
3823 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3825 bool had_amp = false;
3826 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3827 (*i)->set_pre_fader (!had_amp);
3828 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3834 /** Called when there is a proposed change to the input port count */
3836 Route::input_port_count_changing (ChanCount to)
3838 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3840 /* The processors cannot be configured with the new input arrangement, so
3846 /* The change is ok */
3850 /** Called when there is a proposed change to the output port count */
3852 Route::output_port_count_changing (ChanCount to)
3854 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
3855 if (processor_out_streams.get(*t) > to.get(*t)) {
3859 /* The change is ok */
3864 Route::unknown_processors () const
3868 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3869 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3870 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3871 p.push_back ((*i)->name ());
3880 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
3882 /* we assume that all our input ports feed all our output ports. its not
3883 universally true, but the alternative is way too corner-case to worry about.
3886 LatencyRange all_connections;
3889 all_connections.min = 0;
3890 all_connections.max = 0;
3892 all_connections.min = ~((pframes_t) 0);
3893 all_connections.max = 0;
3895 /* iterate over all "from" ports and determine the latency range for all of their
3896 connections to the "outside" (outside of this Route).
3899 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3903 p->get_connected_latency_range (range, playback);
3905 all_connections.min = min (all_connections.min, range.min);
3906 all_connections.max = max (all_connections.max, range.max);
3910 /* set the "from" port latencies to the max/min range of all their connections */
3912 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3913 p->set_private_latency_range (all_connections, playback);
3916 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
3918 all_connections.min += our_latency;
3919 all_connections.max += our_latency;
3921 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
3922 p->set_private_latency_range (all_connections, playback);
3925 return all_connections.max;
3929 Route::set_private_port_latencies (bool playback) const
3931 framecnt_t own_latency = 0;
3933 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
3934 OR LATENCY CALLBACK.
3936 This is called (early) from the latency callback. It computes the REAL
3937 latency associated with each port and stores the result as the "private"
3938 latency of the port. A later call to Route::set_public_port_latencies()
3939 sets all ports to the same value to reflect the fact that we do latency
3940 compensation and so all signals are delayed by the same amount as they
3941 flow through ardour.
3944 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3945 if ((*i)->active ()) {
3946 own_latency += (*i)->signal_latency ();
3951 /* playback: propagate latency from "outside the route" to outputs to inputs */
3952 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
3954 /* capture: propagate latency from "outside the route" to inputs to outputs */
3955 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
3960 Route::set_public_port_latencies (framecnt_t value, bool playback) const
3962 /* this is called to set the JACK-visible port latencies, which take
3963 latency compensation into account.
3972 const PortSet& ports (_input->ports());
3973 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
3974 p->set_public_latency_range (range, playback);
3979 const PortSet& ports (_output->ports());
3980 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
3981 p->set_public_latency_range (range, playback);
3986 /** Put the invisible processors in the right place in _processors.
3987 * Must be called with a writer lock on _processor_lock held.
3990 Route::setup_invisible_processors ()
3993 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3994 assert (!lm.locked ());
3998 /* too early to be doing this stuff */
4002 /* we'll build this new list here and then use it */
4004 ProcessorList new_processors;
4006 /* find visible processors */
4008 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4009 if ((*i)->display_to_user ()) {
4010 new_processors.push_back (*i);
4016 ProcessorList::iterator amp = new_processors.begin ();
4017 while (amp != new_processors.end() && boost::dynamic_pointer_cast<Amp> (*amp) == 0) {
4021 assert (amp != new_processors.end ());
4023 /* and the processor after the amp */
4025 ProcessorList::iterator after_amp = amp;
4031 switch (_meter_point) {
4033 assert (!_meter->display_to_user ());
4034 new_processors.push_front (_meter);
4037 assert (!_meter->display_to_user ());
4038 new_processors.insert (amp, _meter);
4040 case MeterPostFader:
4041 /* do nothing here */
4044 /* do nothing here */
4047 /* the meter is visible, so we don't touch it here */
4054 assert (_main_outs);
4055 assert (!_main_outs->display_to_user ());
4056 new_processors.push_back (_main_outs);
4058 /* iterator for the main outs */
4060 ProcessorList::iterator main = new_processors.end();
4063 /* OUTPUT METERING */
4065 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4066 assert (!_meter->display_to_user ());
4068 /* add the processor just before or just after the main outs */
4070 ProcessorList::iterator meter_point = main;
4072 if (_meter_point == MeterOutput) {
4075 new_processors.insert (meter_point, _meter);
4080 if (_monitor_send && !is_monitor ()) {
4081 assert (!_monitor_send->display_to_user ());
4082 if (Config->get_solo_control_is_listen_control()) {
4083 switch (Config->get_listen_position ()) {
4084 case PreFaderListen:
4085 switch (Config->get_pfl_position ()) {
4086 case PFLFromBeforeProcessors:
4087 new_processors.push_front (_monitor_send);
4089 case PFLFromAfterProcessors:
4090 new_processors.insert (amp, _monitor_send);
4093 _monitor_send->set_can_pan (false);
4095 case AfterFaderListen:
4096 switch (Config->get_afl_position ()) {
4097 case AFLFromBeforeProcessors:
4098 new_processors.insert (after_amp, _monitor_send);
4100 case AFLFromAfterProcessors:
4101 new_processors.insert (new_processors.end(), _monitor_send);
4104 _monitor_send->set_can_pan (true);
4108 new_processors.insert (new_processors.end(), _monitor_send);
4109 _monitor_send->set_can_pan (false);
4113 if (!is_master() && !is_monitor() && !is_auditioner()) {
4114 new_processors.push_front (_delayline);
4117 /* MONITOR CONTROL */
4119 if (_monitor_control && is_monitor ()) {
4120 assert (!_monitor_control->display_to_user ());
4121 new_processors.push_front (_monitor_control);
4124 /* INTERNAL RETURN */
4126 /* doing this here means that any monitor control will come just after
4131 assert (!_intreturn->display_to_user ());
4132 new_processors.push_front (_intreturn);
4135 /* EXPORT PROCESSOR */
4137 if (_capturing_processor) {
4138 assert (!_capturing_processor->display_to_user ());
4139 new_processors.push_front (_capturing_processor);
4142 _processors = new_processors;
4144 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4145 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4146 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4153 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4154 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4158 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4159 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4166 /** If the meter point is `Custom', make a note of where the meter is.
4167 * This is so that if the meter point is subsequently set to something else,
4168 * and then back to custom, we can put the meter back where it was last time
4169 * custom was enabled.
4171 * Must be called with the _processor_lock held.
4174 Route::maybe_note_meter_position ()
4176 if (_meter_point != MeterCustom) {
4180 _custom_meter_position_noted = true;
4181 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4182 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4183 ProcessorList::iterator j = i;
4185 if (j != _processors.end ()) {
4186 _processor_after_last_custom_meter = *j;
4187 _last_custom_meter_was_at_end = false;
4189 _last_custom_meter_was_at_end = true;
4195 boost::shared_ptr<Processor>
4196 Route::processor_by_id (PBD::ID id) const
4198 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4199 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4200 if ((*i)->id() == id) {
4205 return boost::shared_ptr<Processor> ();
4208 /** @return the monitoring state, or in other words what data we are pushing
4209 * into the route (data from the inputs, data from disk or silence)
4212 Route::monitoring_state () const
4214 return MonitoringInput;
4217 /** @return what we should be metering; either the data coming from the input
4218 * IO or the data that is flowing through the route.
4221 Route::metering_state () const
4223 return MeteringRoute;
4227 Route::has_external_redirects () const
4229 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4231 /* ignore inactive processors and obviously ignore the main
4232 * outs since everything has them and we don't care.
4235 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4243 boost::shared_ptr<Processor>
4244 Route::the_instrument () const
4246 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4247 return the_instrument_unlocked ();
4250 boost::shared_ptr<Processor>
4251 Route::the_instrument_unlocked () const
4253 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4254 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4255 if ((*i)->input_streams().n_midi() > 0 &&
4256 (*i)->output_streams().n_audio() > 0) {
4261 return boost::shared_ptr<Processor>();
4267 Route::non_realtime_locate (framepos_t pos)
4270 _pannable->transport_located (pos);
4273 if (_delayline.get()) {
4274 _delayline.get()->flush();
4278 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4279 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4281 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4282 (*i)->transport_located (pos);
4288 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4295 * We don't currently mix MIDI input together, so we don't need the
4296 * complex logic of the audio case.
4299 n_buffers = bufs.count().n_midi ();
4301 for (i = 0; i < n_buffers; ++i) {
4303 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4304 MidiBuffer& buf (bufs.get_midi (i));
4307 buf.copy (source_port->get_midi_buffer(nframes));
4309 buf.silence (nframes);
4315 n_buffers = bufs.count().n_audio();
4317 size_t n_ports = io->n_ports().n_audio();
4318 float scaling = 1.0f;
4320 if (n_ports > n_buffers) {
4321 scaling = ((float) n_buffers) / n_ports;
4324 for (i = 0; i < n_ports; ++i) {
4326 /* if there are more ports than buffers, map them onto buffers
4327 * in a round-robin fashion
4330 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4331 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4334 if (i < n_buffers) {
4336 /* first time through just copy a channel into
4340 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4342 if (scaling != 1.0f) {
4343 buf.apply_gain (scaling, nframes);
4348 /* on subsequent times around, merge data from
4349 * the port with what is already there
4352 if (scaling != 1.0f) {
4353 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4355 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4360 /* silence any remaining buffers */
4362 for (; i < n_buffers; ++i) {
4363 AudioBuffer& buf (bufs.get_audio (i));
4364 buf.silence (nframes);
4367 /* establish the initial setup of the buffer set, reflecting what was
4368 copied into it. unless, of course, we are the auditioner, in which
4369 case nothing was fed into it from the inputs at all.
4372 if (!is_auditioner()) {
4373 bufs.set_count (io->n_ports());