2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/boost_debug.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_port.h"
41 #include "ardour/audioengine.h"
42 #include "ardour/buffer.h"
43 #include "ardour/buffer_set.h"
44 #include "ardour/capturing_processor.h"
45 #include "ardour/debug.h"
46 #include "ardour/delivery.h"
47 #include "ardour/internal_return.h"
48 #include "ardour/internal_send.h"
49 #include "ardour/meter.h"
50 #include "ardour/delayline.h"
51 #include "ardour/midi_buffer.h"
52 #include "ardour/midi_port.h"
53 #include "ardour/monitor_processor.h"
54 #include "ardour/pannable.h"
55 #include "ardour/panner.h"
56 #include "ardour/panner_shell.h"
57 #include "ardour/plugin_insert.h"
58 #include "ardour/port.h"
59 #include "ardour/port_insert.h"
60 #include "ardour/processor.h"
61 #include "ardour/route.h"
62 #include "ardour/route_group.h"
63 #include "ardour/send.h"
64 #include "ardour/session.h"
65 #include "ardour/unknown_processor.h"
66 #include "ardour/utils.h"
71 using namespace ARDOUR;
74 PBD::Signal0<void> Route::SyncOrderKeys;
75 PBD::Signal0<void> Route::RemoteControlIDChange;
77 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
78 : SessionObject (sess, name)
80 , GraphNode (sess._process_graph)
83 , _signal_latency_at_amp_position (0)
87 , _pending_declick (true)
88 , _meter_point (MeterPostFader)
89 , _meter_type (MeterPeak)
91 , _soloed_by_others_upstream (0)
92 , _soloed_by_others_downstream (0)
94 , _denormal_protection (false)
97 , _declickable (false)
98 , _mute_master (new MuteMaster (sess, name))
99 , _have_internal_generator (false)
101 , _default_type (default_type)
103 , _has_order_key (false)
104 , _remote_control_id (0)
106 , _in_configure_processors (false)
107 , _initial_io_setup (false)
108 , _custom_meter_position_noted (false)
109 , _last_custom_meter_was_at_end (false)
112 _meter_type = MeterK20;
114 processor_max_streams.reset();
120 /* add standard controls */
122 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
123 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
125 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
126 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
128 add_control (_solo_control);
129 add_control (_mute_control);
133 if (!(_flags & Route::MonitorOut)) {
134 _pannable.reset (new Pannable (_session));
137 /* input and output objects */
139 _input.reset (new IO (_session, _name, IO::Input, _default_type));
140 _output.reset (new IO (_session, _name, IO::Output, _default_type));
142 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
143 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
145 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
146 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
148 #if 0 // not used - just yet
149 if (!is_master() && !is_monitor() && !is_auditioner()) {
150 _delayline.reset (new DelayLine (_session, _name));
151 add_processor (_delayline, PreFader);
155 /* add amp processor */
157 _amp.reset (new Amp (_session));
158 add_processor (_amp, PostFader);
160 /* create standard processors: meter, main outs, monitor out;
161 they will be added to _processors by setup_invisible_processors ()
164 _meter.reset (new PeakMeter (_session, _name));
165 _meter->set_owner (this);
166 _meter->set_display_to_user (false);
169 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
170 _main_outs->activate ();
173 /* where we listen to tracks */
174 _intreturn.reset (new InternalReturn (_session));
175 _intreturn->activate ();
177 /* the thing that provides proper control over a control/monitor/listen bus
178 (such as per-channel cut, dim, solo, invert, etc).
180 _monitor_control.reset (new MonitorProcessor (_session));
181 _monitor_control->activate ();
184 if (is_master() || is_monitor() || is_auditioner()) {
185 _mute_master->set_solo_ignore (true);
188 /* now that we have _meter, its safe to connect to this */
190 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
193 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
194 configure_processors (0);
202 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
204 /* do this early so that we don't get incoming signals as we are going through destruction
209 /* don't use clear_processors here, as it depends on the session which may
210 be half-destroyed by now
213 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
214 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
215 (*i)->drop_references ();
218 _processors.clear ();
222 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
224 if (Config->get_remote_model() != UserOrdered) {
228 set_remote_control_id_internal (id, notify_class_listeners);
232 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
234 /* force IDs for master/monitor busses and prevent
235 any other route from accidentally getting these IDs
236 (i.e. legacy sessions)
239 if (is_master() && id != MasterBusRemoteControlID) {
240 id = MasterBusRemoteControlID;
243 if (is_monitor() && id != MonitorBusRemoteControlID) {
244 id = MonitorBusRemoteControlID;
251 /* don't allow it to collide */
253 if (!is_master () && !is_monitor() &&
254 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
255 id += MonitorBusRemoteControlID;
258 if (id != remote_control_id()) {
259 _remote_control_id = id;
260 RemoteControlIDChanged ();
262 if (notify_class_listeners) {
263 RemoteControlIDChange ();
269 Route::remote_control_id() const
272 return MasterBusRemoteControlID;
276 return MonitorBusRemoteControlID;
279 return _remote_control_id;
283 Route::has_order_key () const
285 return _has_order_key;
289 Route::order_key () const
295 Route::set_remote_control_id_explicit (uint32_t rid)
297 if (is_master() || is_monitor() || is_auditioner()) {
298 /* hard-coded remote IDs, or no remote ID */
302 if (_remote_control_id != rid) {
303 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
304 _remote_control_id = rid;
305 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
308 /* don't emit the class-level RID signal RemoteControlIDChange here,
309 leave that to the entity that changed the order key, so that we
310 don't get lots of emissions for no good reasons (e.g. when changing
311 all route order keys).
313 See Session::sync_remote_id_from_order_keys() for the (primary|only)
314 spot where that is emitted.
319 Route::set_order_key (uint32_t n)
321 _has_order_key = true;
323 if (_order_key == n) {
329 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
330 name(), order_key ()));
332 _session.set_dirty ();
336 Route::ensure_track_or_route_name(string name, Session &session)
338 string newname = name;
340 while (!session.io_name_is_legal (newname)) {
341 newname = bump_name_once (newname, '.');
349 Route::inc_gain (gain_t fraction, void *src)
351 _amp->inc_gain (fraction, src);
355 Route::set_gain (gain_t val, void *src)
357 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
359 if (_route_group->is_relative()) {
361 gain_t usable_gain = _amp->gain();
362 if (usable_gain < 0.000001f) {
363 usable_gain = 0.000001f;
367 if (delta < 0.000001f) {
371 delta -= usable_gain;
376 gain_t factor = delta / usable_gain;
379 factor = _route_group->get_max_factor(factor);
380 if (factor == 0.0f) {
381 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
385 factor = _route_group->get_min_factor(factor);
386 if (factor == 0.0f) {
387 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
392 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
396 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
402 if (val == _amp->gain()) {
406 _amp->set_gain (val, src);
410 Route::maybe_declick (BufferSet&, framecnt_t, int)
412 /* this is the "bus" implementation and they never declick.
417 /** Process this route for one (sub) cycle (process thread)
419 * @param bufs Scratch buffers to use for the signal path
420 * @param start_frame Initial transport frame
421 * @param end_frame Final transport frame
422 * @param nframes Number of frames to output (to ports)
424 * Note that (end_frame - start_frame) may not be equal to nframes when the
425 * transport speed isn't 1.0 (eg varispeed).
428 Route::process_output_buffers (BufferSet& bufs,
429 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
430 int declick, bool gain_automation_ok)
432 /* Caller must hold process lock */
433 assert (!AudioEngine::instance()->process_lock().trylock());
435 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
438 /* figure out if we're going to use gain automation */
439 if (gain_automation_ok) {
440 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
441 _amp->setup_gain_automation (
442 start_frame + _signal_latency_at_amp_position,
443 end_frame + _signal_latency_at_amp_position,
446 _amp->apply_gain_automation (false);
449 /* Tell main outs what to do about monitoring. We do this so that
450 on a transition between monitoring states we get a de-clicking gain
451 change in the _main_outs delivery.
453 bool silence = monitoring_state () == MonitoringSilence;
455 //but we override this in the case where we have an internal generator
456 if ( _have_internal_generator )
459 _main_outs->no_outs_cuz_we_no_monitor (silence);
461 /* -------------------------------------------------------------------------------------------
462 GLOBAL DECLICK (for transport changes etc.)
463 ----------------------------------------------------------------------------------------- */
465 maybe_declick (bufs, nframes, declick);
466 _pending_declick = 0;
468 /* -------------------------------------------------------------------------------------------
469 DENORMAL CONTROL/PHASE INVERT
470 ----------------------------------------------------------------------------------------- */
472 if (_phase_invert.any ()) {
476 if (_denormal_protection || Config->get_denormal_protection()) {
478 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
479 Sample* const sp = i->data();
481 if (_phase_invert[chn]) {
482 for (pframes_t nx = 0; nx < nframes; ++nx) {
487 for (pframes_t nx = 0; nx < nframes; ++nx) {
495 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
496 Sample* const sp = i->data();
498 if (_phase_invert[chn]) {
499 for (pframes_t nx = 0; nx < nframes; ++nx) {
508 if (_denormal_protection || Config->get_denormal_protection()) {
510 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
511 Sample* const sp = i->data();
512 for (pframes_t nx = 0; nx < nframes; ++nx) {
520 /* -------------------------------------------------------------------------------------------
522 ----------------------------------------------------------------------------------------- */
524 /* set this to be true if the meter will already have been ::run() earlier */
525 bool const meter_already_run = metering_state() == MeteringInput;
527 framecnt_t latency = 0;
529 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
531 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
532 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
537 /* if it has any inputs, make sure they match */
538 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
539 if (bufs.count() != (*i)->input_streams()) {
541 DEBUG::Processors, string_compose (
542 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
543 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
550 /* should we NOT run plugins here if the route is inactive?
551 do we catch route != active somewhere higher?
554 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
555 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
558 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
559 bufs.set_count ((*i)->output_streams());
561 if ((*i)->active ()) {
562 latency += (*i)->signal_latency ();
568 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
569 boost::shared_ptr<Processor> endpoint,
570 bool include_endpoint, bool for_export, bool for_freeze)
572 /* If no processing is required, there's no need to go any further. */
573 if (!endpoint && !include_endpoint) {
577 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
578 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
579 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
582 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
584 if (!include_endpoint && (*i) == endpoint) {
588 /* if we're not exporting, stop processing if we come across a routing processor. */
589 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
592 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
596 /* don't run any processors that does routing.
597 * oh, and don't bother with the peak meter either.
599 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
600 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
601 buffers.set_count ((*i)->output_streams());
602 latency += (*i)->signal_latency ();
605 if ((*i) == endpoint) {
612 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
613 bool include_endpoint, bool for_export, bool for_freeze) const
615 framecnt_t latency = 0;
616 if (!endpoint && !include_endpoint) {
620 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
621 if (!include_endpoint && (*i) == endpoint) {
624 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
627 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
630 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
631 latency += (*i)->signal_latency ();
633 if ((*i) == endpoint) {
641 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
642 bool include_endpoint, bool for_export, bool for_freeze) const
644 if (!endpoint && !include_endpoint) {
648 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
649 if (!include_endpoint && (*i) == endpoint) {
652 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
655 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
658 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
659 cc = (*i)->output_streams();
661 if ((*i) == endpoint) {
669 Route::n_process_buffers ()
671 return max (_input->n_ports(), processor_max_streams);
675 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
677 assert (is_monitor());
678 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
679 fill_buffers_with_input (bufs, _input, nframes);
680 passthru (bufs, start_frame, end_frame, nframes, declick);
684 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
688 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
690 /* control/monitor bus ignores input ports when something is
691 feeding the listen "stream". data will "arrive" into the
692 route from the intreturn processor element.
695 bufs.silence (nframes, 0);
698 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
699 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
703 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
705 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
707 bufs.set_count (_input->n_ports());
708 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
709 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
713 Route::set_listen (bool yn, void* src)
719 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
720 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
725 if (yn != _monitor_send->active()) {
727 _monitor_send->activate ();
728 _mute_master->set_soloed (true);
730 _monitor_send->deactivate ();
731 _mute_master->set_soloed (false);
734 listen_changed (src); /* EMIT SIGNAL */
740 Route::listening_via_monitor () const
743 return _monitor_send->active ();
750 Route::set_solo_safe (bool yn, void *src)
752 if (_solo_safe != yn) {
754 solo_safe_changed (src);
759 Route::solo_safe() const
765 Route::set_solo (bool yn, void *src)
768 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
772 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
773 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
777 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
778 name(), yn, src, (src == _route_group), self_soloed()));
780 if (self_soloed() != yn) {
782 set_mute_master_solo ();
783 solo_changed (true, src); /* EMIT SIGNAL */
784 _solo_control->Changed (); /* EMIT SIGNAL */
789 Route::set_self_solo (bool yn)
791 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
796 Route::mod_solo_by_others_upstream (int32_t delta)
799 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-upstream due to solo-safe\n", name()));
803 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
804 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
806 uint32_t old_sbu = _soloed_by_others_upstream;
809 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
810 _soloed_by_others_upstream += delta;
812 _soloed_by_others_upstream = 0;
815 _soloed_by_others_upstream += delta;
818 DEBUG_TRACE (DEBUG::Solo, string_compose (
819 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
820 name(), delta, _soloed_by_others_upstream, old_sbu,
821 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
823 /* push the inverse solo change to everything that feeds us.
825 This is important for solo-within-group. When we solo 1 track out of N that
826 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
827 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
828 tracks that feed it. This will silence them if they were audible because
829 of a bus solo, but the newly soloed track will still be audible (because
832 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
836 if ((_self_solo || _soloed_by_others_downstream) &&
837 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
838 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
840 if (delta > 0 || !Config->get_exclusive_solo()) {
841 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
842 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
843 boost::shared_ptr<Route> sr = i->r.lock();
845 sr->mod_solo_by_others_downstream (-delta);
851 set_mute_master_solo ();
852 solo_changed (false, this);
856 Route::mod_solo_by_others_downstream (int32_t delta)
859 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-downstream due to solo safe\n", name()));
863 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
864 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
867 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
868 _soloed_by_others_downstream += delta;
870 _soloed_by_others_downstream = 0;
873 _soloed_by_others_downstream += delta;
876 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
878 set_mute_master_solo ();
879 solo_changed (false, this);
883 Route::set_mute_master_solo ()
885 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
889 Route::set_solo_isolated (bool yn, void *src)
891 if (is_master() || is_monitor() || is_auditioner()) {
895 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
896 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
900 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
902 boost::shared_ptr<RouteList> routes = _session.get_routes ();
903 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
905 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
910 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
912 if (does_feed && !sends_only) {
913 (*i)->set_solo_isolated (yn, (*i)->route_group());
917 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
919 bool changed = false;
922 if (_solo_isolated == 0) {
923 _mute_master->set_solo_ignore (true);
928 if (_solo_isolated > 0) {
930 if (_solo_isolated == 0) {
931 _mute_master->set_solo_ignore (false);
938 solo_isolated_changed (src);
943 Route::solo_isolated () const
945 return _solo_isolated > 0;
949 Route::set_mute_points (MuteMaster::MutePoint mp)
951 _mute_master->set_mute_points (mp);
952 mute_points_changed (); /* EMIT SIGNAL */
954 if (_mute_master->muted_by_self()) {
955 mute_changed (this); /* EMIT SIGNAL */
956 _mute_control->Changed (); /* EMIT SIGNAL */
961 Route::set_mute (bool yn, void *src)
963 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
964 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
969 _mute_master->set_muted_by_self (yn);
970 /* allow any derived classes to respond to the mute change
971 before anybody else knows about it.
974 /* tell everyone else */
975 mute_changed (src); /* EMIT SIGNAL */
976 _mute_control->Changed (); /* EMIT SIGNAL */
981 Route::muted () const
983 return _mute_master->muted_by_self();
988 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
990 cerr << name << " {" << endl;
991 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
992 p != procs.end(); ++p) {
993 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
999 /** Supposing that we want to insert a Processor at a given Placement, return
1000 * the processor to add the new one before (or 0 to add at the end).
1002 boost::shared_ptr<Processor>
1003 Route::before_processor_for_placement (Placement p)
1005 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1007 ProcessorList::iterator loc;
1009 if (p == PreFader) {
1010 /* generic pre-fader: insert immediately before the amp */
1011 loc = find (_processors.begin(), _processors.end(), _amp);
1013 /* generic post-fader: insert right before the main outs */
1014 loc = find (_processors.begin(), _processors.end(), _main_outs);
1017 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1020 /** Supposing that we want to insert a Processor at a given index, return
1021 * the processor to add the new one before (or 0 to add at the end).
1023 boost::shared_ptr<Processor>
1024 Route::before_processor_for_index (int index)
1027 return boost::shared_ptr<Processor> ();
1030 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1032 ProcessorList::iterator i = _processors.begin ();
1034 while (i != _processors.end() && j < index) {
1035 if ((*i)->display_to_user()) {
1042 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1045 /** Add a processor either pre- or post-fader
1046 * @return 0 on success, non-0 on failure.
1049 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1051 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1055 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1056 * @param index Index to add the processor at, or -1 to add at the end of the list.
1057 * @return 0 on success, non-0 on failure.
1060 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1062 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1065 /** Add a processor to the route.
1066 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1067 * @return 0 on success, non-0 on failure.
1070 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1072 assert (processor != _meter);
1073 assert (processor != _main_outs);
1075 DEBUG_TRACE (DEBUG::Processors, string_compose (
1076 "%1 adding processor %2\n", name(), processor->name()));
1078 if (!AudioEngine::instance()->connected() || !processor) {
1083 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1084 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1085 ProcessorState pstate (this);
1087 boost::shared_ptr<PluginInsert> pi;
1088 boost::shared_ptr<PortInsert> porti;
1090 if (processor == _amp) {
1091 /* Ensure that only one amp is in the list at any time */
1092 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1093 if (check != _processors.end()) {
1094 if (before == _amp) {
1095 /* Already in position; all is well */
1098 _processors.erase (check);
1103 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1105 ProcessorList::iterator loc;
1107 /* inserting before a processor; find it */
1108 loc = find (_processors.begin(), _processors.end(), before);
1109 if (loc == _processors.end ()) {
1114 /* inserting at end */
1115 loc = _processors.end ();
1118 _processors.insert (loc, processor);
1119 processor->set_owner (this);
1121 // Set up processor list channels. This will set processor->[input|output]_streams(),
1122 // configure redirect ports properly, etc.
1125 if (configure_processors_unlocked (err)) {
1127 configure_processors_unlocked (0); // it worked before we tried to add it ...
1132 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1134 if (pi->has_no_inputs ()) {
1135 /* generator plugin */
1136 _have_internal_generator = true;
1141 if (activation_allowed && !_session.get_disable_all_loaded_plugins()) {
1142 processor->activate ();
1145 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1147 _output->set_user_latency (0);
1150 reset_instrument_info ();
1151 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1152 set_processor_positions ();
1158 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1160 const XMLProperty *prop;
1163 boost::shared_ptr<Processor> processor;
1165 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1166 so that we can add the processor in the right place (pre/post-fader)
1169 XMLNodeList const & children = node.children ();
1170 XMLNodeList::const_iterator i = children.begin ();
1172 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1176 Placement placement = PreFader;
1178 if (i != children.end()) {
1179 if ((prop = (*i)->property (X_("placement"))) != 0) {
1180 placement = Placement (string_2_enum (prop->value(), placement));
1184 if (node.name() == "Insert") {
1186 if ((prop = node.property ("type")) != 0) {
1188 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1189 prop->value() == "lv2" ||
1190 prop->value() == "windows-vst" ||
1191 prop->value() == "lxvst" ||
1192 prop->value() == "audiounit") {
1194 processor.reset (new PluginInsert (_session));
1198 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1203 } else if (node.name() == "Send") {
1205 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1206 processor.reset (new Send (_session, sendpan, _mute_master));
1210 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1214 if (processor->set_state (node, version)) {
1218 return (add_processor (processor, placement) == 0);
1221 catch (failed_constructor &err) {
1222 warning << _("processor could not be created. Ignored.") << endmsg;
1228 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1230 /* NOTE: this is intended to be used ONLY when copying
1231 processors from another Route. Hence the subtle
1232 differences between this and ::add_processor()
1235 ProcessorList::iterator loc;
1238 loc = find(_processors.begin(), _processors.end(), before);
1240 /* nothing specified - at end */
1241 loc = _processors.end ();
1244 if (!_session.engine().connected()) {
1248 if (others.empty()) {
1253 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1254 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1255 ProcessorState pstate (this);
1257 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1263 boost::shared_ptr<PluginInsert> pi;
1265 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1269 _processors.insert (loc, *i);
1270 (*i)->set_owner (this);
1272 if ((*i)->active()) {
1276 /* Think: does this really need to be called for every processor in the loop? */
1278 if (configure_processors_unlocked (err)) {
1280 configure_processors_unlocked (0); // it worked before we tried to add it ...
1285 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1288 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1289 boost::shared_ptr<PluginInsert> pi;
1291 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1292 if (pi->has_no_inputs ()) {
1293 _have_internal_generator = true;
1299 _output->set_user_latency (0);
1302 reset_instrument_info ();
1303 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1304 set_processor_positions ();
1310 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1312 if (p == PreFader) {
1313 start = _processors.begin();
1314 end = find(_processors.begin(), _processors.end(), _amp);
1316 start = find(_processors.begin(), _processors.end(), _amp);
1318 end = _processors.end();
1322 /** Turn off all processors with a given placement
1323 * @param p Placement of processors to disable
1326 Route::disable_processors (Placement p)
1328 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1330 ProcessorList::iterator start, end;
1331 placement_range(p, start, end);
1333 for (ProcessorList::iterator i = start; i != end; ++i) {
1334 (*i)->deactivate ();
1337 _session.set_dirty ();
1340 /** Turn off all redirects
1343 Route::disable_processors ()
1345 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1347 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1348 (*i)->deactivate ();
1351 _session.set_dirty ();
1354 /** Turn off all redirects with a given placement
1355 * @param p Placement of redirects to disable
1358 Route::disable_plugins (Placement p)
1360 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1362 ProcessorList::iterator start, end;
1363 placement_range(p, start, end);
1365 for (ProcessorList::iterator i = start; i != end; ++i) {
1366 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1367 (*i)->deactivate ();
1371 _session.set_dirty ();
1374 /** Turn off all plugins
1377 Route::disable_plugins ()
1379 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1381 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1382 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1383 (*i)->deactivate ();
1387 _session.set_dirty ();
1392 Route::ab_plugins (bool forward)
1394 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1398 /* forward = turn off all active redirects, and mark them so that the next time
1399 we go the other way, we will revert them
1402 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1403 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1407 if ((*i)->active()) {
1408 (*i)->deactivate ();
1409 (*i)->set_next_ab_is_active (true);
1411 (*i)->set_next_ab_is_active (false);
1417 /* backward = if the redirect was marked to go active on the next ab, do so */
1419 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1421 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1425 if ((*i)->get_next_ab_is_active()) {
1428 (*i)->deactivate ();
1433 _session.set_dirty ();
1437 /** Remove processors with a given placement.
1438 * @param p Placement of processors to remove.
1441 Route::clear_processors (Placement p)
1443 if (!_session.engine().connected()) {
1447 bool already_deleting = _session.deletion_in_progress();
1448 if (!already_deleting) {
1449 _session.set_deletion_in_progress();
1453 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1454 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1455 ProcessorList new_list;
1456 ProcessorStreams err;
1457 bool seen_amp = false;
1459 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1465 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline) {
1467 /* you can't remove these */
1469 new_list.push_back (*i);
1476 new_list.push_back (*i);
1479 (*i)->drop_references ();
1487 (*i)->drop_references ();
1490 new_list.push_back (*i);
1497 _processors = new_list;
1498 configure_processors_unlocked (&err); // this can't fail
1501 processor_max_streams.reset();
1502 _have_internal_generator = false;
1503 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1504 set_processor_positions ();
1506 reset_instrument_info ();
1508 if (!already_deleting) {
1509 _session.clear_deletion_in_progress();
1514 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1516 // TODO once the export point can be configured properly, do something smarter here
1517 if (processor == _capturing_processor) {
1518 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1519 if (need_process_lock) {
1523 _capturing_processor.reset();
1525 if (need_process_lock) {
1530 /* these can never be removed */
1532 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1536 if (!_session.engine().connected()) {
1540 processor_max_streams.reset();
1543 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1544 if (need_process_lock) {
1548 /* Caller must hold process lock */
1549 assert (!AudioEngine::instance()->process_lock().trylock());
1551 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1553 ProcessorState pstate (this);
1555 ProcessorList::iterator i;
1556 bool removed = false;
1558 for (i = _processors.begin(); i != _processors.end(); ) {
1559 if (*i == processor) {
1561 /* move along, see failure case for configure_processors()
1562 where we may need to reconfigure the processor.
1565 /* stop redirects that send signals to JACK ports
1566 from causing noise as a result of no longer being
1570 boost::shared_ptr<IOProcessor> iop;
1572 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1576 i = _processors.erase (i);
1584 _output->set_user_latency (0);
1592 if (configure_processors_unlocked (err)) {
1594 /* we know this will work, because it worked before :) */
1595 configure_processors_unlocked (0);
1599 _have_internal_generator = false;
1601 for (i = _processors.begin(); i != _processors.end(); ++i) {
1602 boost::shared_ptr<PluginInsert> pi;
1604 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1605 if (pi->has_no_inputs ()) {
1606 _have_internal_generator = true;
1611 if (need_process_lock) {
1616 reset_instrument_info ();
1617 processor->drop_references ();
1618 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1619 set_processor_positions ();
1625 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1627 ProcessorList deleted;
1629 if (!_session.engine().connected()) {
1633 processor_max_streams.reset();
1636 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1637 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1638 ProcessorState pstate (this);
1640 ProcessorList::iterator i;
1641 boost::shared_ptr<Processor> processor;
1643 for (i = _processors.begin(); i != _processors.end(); ) {
1647 /* these can never be removed */
1649 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline) {
1654 /* see if its in the list of processors to delete */
1656 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1661 /* stop IOProcessors that send to JACK ports
1662 from causing noise as a result of no longer being
1666 boost::shared_ptr<IOProcessor> iop;
1668 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1672 deleted.push_back (processor);
1673 i = _processors.erase (i);
1676 if (deleted.empty()) {
1677 /* none of those in the requested list were found */
1681 _output->set_user_latency (0);
1683 if (configure_processors_unlocked (err)) {
1685 /* we know this will work, because it worked before :) */
1686 configure_processors_unlocked (0);
1691 _have_internal_generator = false;
1693 for (i = _processors.begin(); i != _processors.end(); ++i) {
1694 boost::shared_ptr<PluginInsert> pi;
1696 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1697 if (pi->has_no_inputs ()) {
1698 _have_internal_generator = true;
1705 /* now try to do what we need to so that those that were removed will be deleted */
1707 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1708 (*i)->drop_references ();
1711 reset_instrument_info ();
1712 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1713 set_processor_positions ();
1719 Route::reset_instrument_info ()
1721 boost::shared_ptr<Processor> instr = the_instrument();
1723 _instrument_info.set_internal_instrument (instr);
1727 /** Caller must hold process lock */
1729 Route::configure_processors (ProcessorStreams* err)
1731 #ifndef PLATFORM_WINDOWS
1732 assert (!AudioEngine::instance()->process_lock().trylock());
1735 if (!_in_configure_processors) {
1736 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1737 return configure_processors_unlocked (err);
1744 Route::input_streams () const
1746 return _input->n_ports ();
1749 list<pair<ChanCount, ChanCount> >
1750 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1752 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1754 return try_configure_processors_unlocked (in, err);
1757 list<pair<ChanCount, ChanCount> >
1758 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1760 // Check each processor in order to see if we can configure as requested
1762 list<pair<ChanCount, ChanCount> > configuration;
1765 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1766 DEBUG_TRACE (DEBUG::Processors, "{\n");
1768 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1770 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1771 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1772 DEBUG_TRACE (DEBUG::Processors, "}\n");
1773 return list<pair<ChanCount, ChanCount> > ();
1776 if ((*p)->can_support_io_configuration(in, out)) {
1777 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1778 configuration.push_back(make_pair(in, out));
1785 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1786 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1787 DEBUG_TRACE (DEBUG::Processors, "}\n");
1788 return list<pair<ChanCount, ChanCount> > ();
1792 DEBUG_TRACE (DEBUG::Processors, "}\n");
1794 return configuration;
1797 /** Set the input/output configuration of each processor in the processors list.
1798 * Caller must hold process lock.
1799 * Return 0 on success, otherwise configuration is impossible.
1802 Route::configure_processors_unlocked (ProcessorStreams* err)
1804 #ifndef PLATFORM_WINDOWS
1805 assert (!AudioEngine::instance()->process_lock().trylock());
1808 if (_in_configure_processors) {
1812 /* put invisible processors where they should be */
1813 setup_invisible_processors ();
1815 _in_configure_processors = true;
1817 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1819 if (configuration.empty ()) {
1820 _in_configure_processors = false;
1825 bool seen_mains_out = false;
1826 processor_out_streams = _input->n_ports();
1827 processor_max_streams.reset();
1829 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1830 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1832 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1836 (*p)->configure_io(c->first, c->second);
1837 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1838 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1841 if (boost::dynamic_pointer_cast<Delivery> (*p)
1842 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1843 /* main delivery will increase port count to match input.
1844 * the Delivery::Main is usually the last processor - followed only by
1847 seen_mains_out = true;
1849 if (!seen_mains_out) {
1850 processor_out_streams = out;
1856 _meter->reset_max_channels (processor_max_streams);
1859 /* make sure we have sufficient scratch buffers to cope with the new processor
1862 _session.ensure_buffers (n_process_buffers ());
1864 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1866 _in_configure_processors = false;
1870 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1871 * @param state New active state for those processors.
1874 Route::all_visible_processors_active (bool state)
1876 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1878 if (_processors.empty()) {
1882 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1883 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1890 (*i)->deactivate ();
1894 _session.set_dirty ();
1898 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1900 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1901 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1902 processors in the current actual processor list that are hidden. Any visible processors
1903 in the current list but not in "new_order" will be assumed to be deleted.
1907 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1908 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1909 ProcessorState pstate (this);
1911 ProcessorList::iterator oiter;
1912 ProcessorList::const_iterator niter;
1913 ProcessorList as_it_will_be;
1915 oiter = _processors.begin();
1916 niter = new_order.begin();
1918 while (niter != new_order.end()) {
1920 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1921 then append it to the temp list.
1923 Otherwise, see if the next processor in the old list is in the new list. if not,
1924 its been deleted. If its there, append it to the temp list.
1927 if (oiter == _processors.end()) {
1929 /* no more elements in the old list, so just stick the rest of
1930 the new order onto the temp list.
1933 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1934 while (niter != new_order.end()) {
1941 if (!(*oiter)->display_to_user()) {
1943 as_it_will_be.push_back (*oiter);
1947 /* visible processor: check that its in the new order */
1949 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1950 /* deleted: do nothing, shared_ptr<> will clean up */
1952 /* ignore this one, and add the next item from the new order instead */
1953 as_it_will_be.push_back (*niter);
1958 /* now remove from old order - its taken care of no matter what */
1959 oiter = _processors.erase (oiter);
1964 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1966 /* If the meter is in a custom position, find it and make a rough note of its position */
1967 maybe_note_meter_position ();
1969 if (configure_processors_unlocked (err)) {
1975 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1976 set_processor_positions ();
1988 Route::get_template()
1990 return state(false);
1994 Route::state(bool full_state)
1996 XMLNode *node = new XMLNode("Route");
1997 ProcessorList::iterator i;
2000 id().print (buf, sizeof (buf));
2001 node->add_property("id", buf);
2002 node->add_property ("name", _name);
2003 node->add_property("default-type", _default_type.to_string());
2006 node->add_property("flags", enum_2_string (_flags));
2009 node->add_property("active", _active?"yes":"no");
2011 boost::to_string (_phase_invert, p);
2012 node->add_property("phase-invert", p);
2013 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2014 node->add_property("meter-point", enum_2_string (_meter_point));
2016 node->add_property("meter-type", enum_2_string (_meter_type));
2019 node->add_property("route-group", _route_group->name());
2022 snprintf (buf, sizeof (buf), "%d", _order_key);
2023 node->add_property ("order-key", buf);
2024 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2025 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2026 node->add_property ("soloed-by-upstream", buf);
2027 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2028 node->add_property ("soloed-by-downstream", buf);
2029 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2030 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2032 node->add_child_nocopy (_input->state (full_state));
2033 node->add_child_nocopy (_output->state (full_state));
2034 node->add_child_nocopy (_solo_control->get_state ());
2035 node->add_child_nocopy (_mute_control->get_state ());
2036 node->add_child_nocopy (_mute_master->get_state ());
2038 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2039 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2040 remote_control_node->add_property (X_("id"), buf);
2041 node->add_child_nocopy (*remote_control_node);
2043 if (_comment.length()) {
2044 XMLNode *cmt = node->add_child ("Comment");
2045 cmt->add_content (_comment);
2049 node->add_child_nocopy (_pannable->state (full_state));
2052 for (i = _processors.begin(); i != _processors.end(); ++i) {
2054 /* template save: do not include internal sends functioning as
2055 aux sends because the chance of the target ID
2056 in the session where this template is used
2059 similarly, do not save listen sends which connect to
2060 the monitor section, because these will always be
2063 boost::shared_ptr<InternalSend> is;
2065 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2066 if (is->role() == Delivery::Listen) {
2071 node->add_child_nocopy((*i)->state (full_state));
2075 node->add_child_copy (*_extra_xml);
2078 if (_custom_meter_position_noted) {
2079 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2081 after->id().print (buf, sizeof (buf));
2082 node->add_property (X_("processor-after-last-custom-meter"), buf);
2085 node->add_property (X_("last-custom-meter-was-at-end"), _last_custom_meter_was_at_end ? "yes" : "no");
2092 Route::set_state (const XMLNode& node, int version)
2094 if (version < 3000) {
2095 return set_state_2X (node, version);
2099 XMLNodeConstIterator niter;
2101 const XMLProperty *prop;
2103 if (node.name() != "Route"){
2104 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2108 if ((prop = node.property (X_("name"))) != 0) {
2109 Route::set_name (prop->value());
2113 _initial_io_setup = true;
2115 if ((prop = node.property (X_("flags"))) != 0) {
2116 _flags = Flag (string_2_enum (prop->value(), _flags));
2121 if (is_master() || is_monitor() || is_auditioner()) {
2122 _mute_master->set_solo_ignore (true);
2126 /* monitor bus does not get a panner, but if (re)created
2127 via XML, it will already have one by the time we
2128 call ::set_state(). so ... remove it.
2133 /* add all processors (except amp, which is always present) */
2135 nlist = node.children();
2136 XMLNode processor_state (X_("processor_state"));
2138 Stateful::save_extra_xml (node);
2140 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2144 if (child->name() == IO::state_node_name) {
2145 if ((prop = child->property (X_("direction"))) == 0) {
2149 if (prop->value() == "Input") {
2150 _input->set_state (*child, version);
2151 } else if (prop->value() == "Output") {
2152 _output->set_state (*child, version);
2156 if (child->name() == X_("Processor")) {
2157 processor_state.add_child_copy (*child);
2160 if (child->name() == X_("Pannable")) {
2162 _pannable->set_state (*child, version);
2164 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2169 if ((prop = node.property (X_("meter-point"))) != 0) {
2170 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2171 set_meter_point (mp, true);
2173 _meter->set_display_to_user (_meter_point == MeterCustom);
2177 if ((prop = node.property (X_("meter-type"))) != 0) {
2178 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2181 _initial_io_setup = false;
2183 set_processor_state (processor_state);
2185 // this looks up the internal instrument in processors
2186 reset_instrument_info();
2188 if ((prop = node.property ("self-solo")) != 0) {
2189 set_self_solo (string_is_affirmative (prop->value()));
2192 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2193 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2194 mod_solo_by_others_upstream (atoi (prop->value()));
2197 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2198 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2199 mod_solo_by_others_downstream (atoi (prop->value()));
2202 if ((prop = node.property ("solo-isolated")) != 0) {
2203 set_solo_isolated (string_is_affirmative (prop->value()), this);
2206 if ((prop = node.property ("solo-safe")) != 0) {
2207 set_solo_safe (string_is_affirmative (prop->value()), this);
2210 if ((prop = node.property (X_("phase-invert"))) != 0) {
2211 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2214 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2215 set_denormal_protection (string_is_affirmative (prop->value()));
2218 if ((prop = node.property (X_("active"))) != 0) {
2219 bool yn = string_is_affirmative (prop->value());
2220 _active = !yn; // force switch
2221 set_active (yn, this);
2224 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2225 set_order_key (atoi(prop->value()));
2228 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2232 string::size_type colon, equal;
2233 string remaining = prop->value();
2235 while (remaining.length()) {
2237 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2238 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2241 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2242 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2245 string keyname = remaining.substr (0, equal);
2247 if ((keyname == "EditorSort") || (keyname == "editor")) {
2248 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2254 colon = remaining.find_first_of (':');
2256 if (colon != string::npos) {
2257 remaining = remaining.substr (colon+1);
2264 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2265 PBD::ID id (prop->value ());
2266 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2267 ProcessorList::const_iterator i = _processors.begin ();
2268 while (i != _processors.end() && (*i)->id() != id) {
2272 if (i != _processors.end ()) {
2273 _processor_after_last_custom_meter = *i;
2274 _custom_meter_position_noted = true;
2278 if ((prop = node.property (X_("last-custom-meter-was-at-end"))) != 0) {
2279 _last_custom_meter_was_at_end = string_is_affirmative (prop->value ());
2282 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2285 if (child->name() == X_("Comment")) {
2287 /* XXX this is a terrible API design in libxml++ */
2289 XMLNode *cmt = *(child->children().begin());
2290 _comment = cmt->content();
2292 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2293 if (prop->value() == "solo") {
2294 _solo_control->set_state (*child, version);
2295 } else if (prop->value() == "mute") {
2296 _mute_control->set_state (*child, version);
2299 } else if (child->name() == X_("RemoteControl")) {
2300 if ((prop = child->property (X_("id"))) != 0) {
2302 sscanf (prop->value().c_str(), "%d", &x);
2303 set_remote_control_id_internal (x);
2306 } else if (child->name() == X_("MuteMaster")) {
2307 _mute_master->set_state (*child, version);
2315 Route::set_state_2X (const XMLNode& node, int version)
2318 XMLNodeConstIterator niter;
2320 const XMLProperty *prop;
2322 /* 2X things which still remain to be handled:
2328 if (node.name() != "Route") {
2329 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2333 if ((prop = node.property (X_("flags"))) != 0) {
2334 string f = prop->value ();
2335 boost::replace_all (f, "ControlOut", "MonitorOut");
2336 _flags = Flag (string_2_enum (f, _flags));
2341 if (is_master() || is_monitor() || is_auditioner()) {
2342 _mute_master->set_solo_ignore (true);
2345 if ((prop = node.property (X_("phase-invert"))) != 0) {
2346 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2347 if (string_is_affirmative (prop->value ())) {
2350 set_phase_invert (p);
2353 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2354 set_denormal_protection (string_is_affirmative (prop->value()));
2357 if ((prop = node.property (X_("soloed"))) != 0) {
2358 bool yn = string_is_affirmative (prop->value());
2360 /* XXX force reset of solo status */
2362 set_solo (yn, this);
2365 if ((prop = node.property (X_("muted"))) != 0) {
2368 bool muted = string_is_affirmative (prop->value());
2374 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2376 if (string_is_affirmative (prop->value())){
2377 mute_point = mute_point + "PreFader";
2382 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2384 if (string_is_affirmative (prop->value())){
2387 mute_point = mute_point + ",";
2390 mute_point = mute_point + "PostFader";
2395 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2397 if (string_is_affirmative (prop->value())){
2400 mute_point = mute_point + ",";
2403 mute_point = mute_point + "Listen";
2408 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2410 if (string_is_affirmative (prop->value())){
2413 mute_point = mute_point + ",";
2416 mute_point = mute_point + "Main";
2420 _mute_master->set_mute_points (mute_point);
2421 _mute_master->set_muted_by_self (true);
2425 if ((prop = node.property (X_("meter-point"))) != 0) {
2426 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2429 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2430 don't mean the same thing.
2433 if ((prop = node.property (X_("order-keys"))) != 0) {
2437 string::size_type colon, equal;
2438 string remaining = prop->value();
2440 while (remaining.length()) {
2442 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2443 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2446 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2447 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2450 string keyname = remaining.substr (0, equal);
2452 if (keyname == "EditorSort" || keyname == "editor") {
2453 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2459 colon = remaining.find_first_of (':');
2461 if (colon != string::npos) {
2462 remaining = remaining.substr (colon+1);
2471 nlist = node.children ();
2472 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2476 if (child->name() == IO::state_node_name) {
2478 /* there is a note in IO::set_state_2X() about why we have to call
2482 _input->set_state_2X (*child, version, true);
2483 _output->set_state_2X (*child, version, false);
2485 if ((prop = child->property (X_("name"))) != 0) {
2486 Route::set_name (prop->value ());
2491 if ((prop = child->property (X_("active"))) != 0) {
2492 bool yn = string_is_affirmative (prop->value());
2493 _active = !yn; // force switch
2494 set_active (yn, this);
2497 if ((prop = child->property (X_("gain"))) != 0) {
2500 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2501 _amp->gain_control()->set_value (val);
2505 /* Set up Panners in the IO */
2506 XMLNodeList io_nlist = child->children ();
2508 XMLNodeConstIterator io_niter;
2511 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2513 io_child = *io_niter;
2515 if (io_child->name() == X_("Panner")) {
2516 _main_outs->panner_shell()->set_state(*io_child, version);
2517 } else if (io_child->name() == X_("Automation")) {
2518 /* IO's automation is for the fader */
2519 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2525 XMLNodeList redirect_nodes;
2527 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2531 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2532 redirect_nodes.push_back(child);
2537 set_processor_state_2X (redirect_nodes, version);
2539 Stateful::save_extra_xml (node);
2541 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2544 if (child->name() == X_("Comment")) {
2546 /* XXX this is a terrible API design in libxml++ */
2548 XMLNode *cmt = *(child->children().begin());
2549 _comment = cmt->content();
2551 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2552 if (prop->value() == X_("solo")) {
2553 _solo_control->set_state (*child, version);
2554 } else if (prop->value() == X_("mute")) {
2555 _mute_control->set_state (*child, version);
2558 } else if (child->name() == X_("RemoteControl")) {
2559 if ((prop = child->property (X_("id"))) != 0) {
2561 sscanf (prop->value().c_str(), "%d", &x);
2562 set_remote_control_id_internal (x);
2572 Route::get_processor_state ()
2574 XMLNode* root = new XMLNode (X_("redirects"));
2575 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2576 root->add_child_nocopy ((*i)->state (true));
2583 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2585 /* We don't bother removing existing processors not in nList, as this
2586 method will only be called when creating a Route from scratch, not
2587 for undo purposes. Just put processors in at the appropriate place
2591 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2592 add_processor_from_xml_2X (**i, version);
2597 Route::set_processor_state (const XMLNode& node)
2599 const XMLNodeList &nlist = node.children();
2600 XMLNodeConstIterator niter;
2601 ProcessorList new_order;
2602 bool must_configure = false;
2604 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2606 XMLProperty* prop = (*niter)->property ("type");
2608 if (prop->value() == "amp") {
2609 _amp->set_state (**niter, Stateful::current_state_version);
2610 new_order.push_back (_amp);
2611 } else if (prop->value() == "meter") {
2612 _meter->set_state (**niter, Stateful::current_state_version);
2613 new_order.push_back (_meter);
2614 } else if (prop->value() == "delay") {
2616 _delayline->set_state (**niter, Stateful::current_state_version);
2617 new_order.push_back (_delayline);
2619 } else if (prop->value() == "main-outs") {
2620 _main_outs->set_state (**niter, Stateful::current_state_version);
2621 } else if (prop->value() == "intreturn") {
2623 _intreturn.reset (new InternalReturn (_session));
2624 must_configure = true;
2626 _intreturn->set_state (**niter, Stateful::current_state_version);
2627 } else if (is_monitor() && prop->value() == "monitor") {
2628 if (!_monitor_control) {
2629 _monitor_control.reset (new MonitorProcessor (_session));
2630 must_configure = true;
2632 _monitor_control->set_state (**niter, Stateful::current_state_version);
2633 } else if (prop->value() == "capture") {
2634 /* CapturingProcessor should never be restored, it's always
2635 added explicitly when needed */
2637 ProcessorList::iterator o;
2639 for (o = _processors.begin(); o != _processors.end(); ++o) {
2640 XMLProperty* id_prop = (*niter)->property(X_("id"));
2641 if (id_prop && (*o)->id() == id_prop->value()) {
2642 (*o)->set_state (**niter, Stateful::current_state_version);
2643 new_order.push_back (*o);
2648 // If the processor (*niter) is not on the route then create it
2650 if (o == _processors.end()) {
2652 boost::shared_ptr<Processor> processor;
2654 if (prop->value() == "intsend") {
2656 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2658 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2659 prop->value() == "lv2" ||
2660 prop->value() == "windows-vst" ||
2661 prop->value() == "lxvst" ||
2662 prop->value() == "audiounit") {
2664 processor.reset (new PluginInsert(_session));
2666 } else if (prop->value() == "port") {
2668 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2670 } else if (prop->value() == "send") {
2672 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2675 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2679 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2680 /* This processor could not be configured. Turn it into a UnknownProcessor */
2681 processor.reset (new UnknownProcessor (_session, **niter));
2684 /* we have to note the monitor send here, otherwise a new one will be created
2685 and the state of this one will be lost.
2687 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2688 if (isend && isend->role() == Delivery::Listen) {
2689 _monitor_send = isend;
2692 /* it doesn't matter if invisible processors are added here, as they
2693 will be sorted out by setup_invisible_processors () shortly.
2696 new_order.push_back (processor);
2697 must_configure = true;
2703 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2704 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2705 _processors = new_order;
2707 if (must_configure) {
2708 configure_processors_unlocked (0);
2711 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2713 (*i)->set_owner (this);
2714 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2716 boost::shared_ptr<PluginInsert> pi;
2718 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2719 if (pi->has_no_inputs ()) {
2720 _have_internal_generator = true;
2727 reset_instrument_info ();
2728 processors_changed (RouteProcessorChange ());
2729 set_processor_positions ();
2733 Route::curve_reallocate ()
2735 // _gain_automation_curve.finish_resize ();
2736 // _pan_automation_curve.finish_resize ();
2740 Route::silence (framecnt_t nframes)
2742 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2747 silence_unlocked (nframes);
2751 Route::silence_unlocked (framecnt_t nframes)
2753 /* Must be called with the processor lock held */
2757 _output->silence (nframes);
2759 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2760 boost::shared_ptr<PluginInsert> pi;
2762 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2763 // skip plugins, they don't need anything when we're not active
2767 (*i)->silence (nframes);
2770 if (nframes == _session.get_block_size()) {
2777 Route::add_internal_return ()
2780 _intreturn.reset (new InternalReturn (_session));
2781 add_processor (_intreturn, PreFader);
2786 Route::add_send_to_internal_return (InternalSend* send)
2788 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2790 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2791 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2794 return d->add_send (send);
2800 Route::remove_send_from_internal_return (InternalSend* send)
2802 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2804 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2805 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2808 return d->remove_send (send);
2814 Route::enable_monitor_send ()
2816 /* Caller must hold process lock */
2817 assert (!AudioEngine::instance()->process_lock().trylock());
2819 /* master never sends to monitor section via the normal mechanism */
2820 assert (!is_master ());
2821 assert (!is_monitor ());
2823 /* make sure we have one */
2824 if (!_monitor_send) {
2825 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
2826 _monitor_send->set_display_to_user (false);
2830 configure_processors (0);
2833 /** Add an aux send to a route.
2834 * @param route route to send to.
2835 * @param before Processor to insert before, or 0 to insert at the end.
2838 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2840 assert (route != _session.monitor_out ());
2843 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2845 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2847 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2849 if (d && d->target_route() == route) {
2850 /* already listening via the specified IO: do nothing */
2858 boost::shared_ptr<InternalSend> listener;
2861 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2862 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
2863 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
2866 add_processor (listener, before);
2868 } catch (failed_constructor& err) {
2876 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
2878 ProcessorStreams err;
2879 ProcessorList::iterator tmp;
2882 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
2884 /* have to do this early because otherwise processor reconfig
2885 * will put _monitor_send back in the list
2888 if (route == _session.monitor_out()) {
2889 _monitor_send.reset ();
2893 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2895 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2897 if (d && d->target_route() == route) {
2899 remove_processor (*x, &err, false);
2902 /* list could have been demolished while we dropped the lock
2913 Route::set_comment (string cmt, void *src)
2916 comment_changed (src);
2917 _session.set_dirty ();
2921 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2923 FeedRecord fr (other, via_sends_only);
2925 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2927 if (!result.second) {
2929 /* already a record for "other" - make sure sends-only information is correct */
2930 if (!via_sends_only && result.first->sends_only) {
2931 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2932 frp->sends_only = false;
2936 return result.second;
2940 Route::clear_fed_by ()
2946 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2948 const FedBy& fed_by (other->fed_by());
2950 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2951 boost::shared_ptr<Route> sr = f->r.lock();
2953 if (sr && (sr.get() == this)) {
2955 if (via_sends_only) {
2956 *via_sends_only = f->sends_only;
2967 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
2969 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2971 if (_output->connected_to (other->input())) {
2972 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2973 if (via_send_only) {
2974 *via_send_only = false;
2981 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2983 boost::shared_ptr<IOProcessor> iop;
2985 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2986 if (iop->feeds (other)) {
2987 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2988 if (via_send_only) {
2989 *via_send_only = true;
2993 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2996 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3001 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3006 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3008 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3011 /** Called from the (non-realtime) butler thread when the transport is stopped */
3013 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3015 framepos_t now = _session.transport_frame();
3018 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3020 Automatable::transport_stopped (now);
3022 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3024 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3028 (*i)->transport_stopped (now);
3032 _roll_delay = _initial_delay;
3036 Route::input_change_handler (IOChange change, void * /*src*/)
3038 bool need_to_queue_solo_change = true;
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 _phase_invert.resize (_input->n_ports().n_audio ());
3047 io_changed (); /* EMIT SIGNAL */
3050 if (!_input->connected() && _soloed_by_others_upstream) {
3051 if (need_to_queue_solo_change) {
3052 _session.cancel_solo_after_disconnect (shared_from_this(), true);
3054 cancel_solo_after_disconnect (true);
3060 Route::output_change_handler (IOChange change, void * /*src*/)
3062 bool need_to_queue_solo_change = true;
3063 if (_initial_io_setup) {
3067 if ((change.type & IOChange::ConfigurationChanged)) {
3068 /* This is called with the process lock held if change
3069 contains ConfigurationChanged
3071 need_to_queue_solo_change = false;
3072 configure_processors (0);
3073 io_changed (); /* EMIT SIGNAL */
3076 if (!_output->connected() && _soloed_by_others_downstream) {
3077 if (need_to_queue_solo_change) {
3078 _session.cancel_solo_after_disconnect (shared_from_this(), false);
3080 cancel_solo_after_disconnect (false);
3086 Route::cancel_solo_after_disconnect (bool upstream)
3089 _soloed_by_others_upstream = 0;
3091 _soloed_by_others_downstream = 0;
3093 set_mute_master_solo ();
3094 solo_changed (false, this);
3098 Route::pans_required () const
3100 if (n_outputs().n_audio() < 2) {
3104 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3108 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3110 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3116 if (n_outputs().n_total() == 0) {
3120 if (!_active || n_inputs() == ChanCount::ZERO) {
3121 silence_unlocked (nframes);
3125 if (session_state_changing) {
3126 if (_session.transport_speed() != 0.0f) {
3127 /* we're rolling but some state is changing (e.g. our diskstream contents)
3128 so we cannot use them. Be silent till this is over.
3130 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3132 silence_unlocked (nframes);
3135 /* we're really not rolling, so we're either delivery silence or actually
3136 monitoring, both of which are safe to do while session_state_changing is true.
3140 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3142 fill_buffers_with_input (bufs, _input, nframes);
3144 if (_meter_point == MeterInput) {
3145 _meter->run (bufs, start_frame, end_frame, nframes, true);
3148 _amp->apply_gain_automation (false);
3149 passthru (bufs, start_frame, end_frame, nframes, 0);
3155 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3157 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3162 if (n_outputs().n_total() == 0) {
3166 if (!_active || n_inputs().n_total() == 0) {
3167 silence_unlocked (nframes);
3171 framepos_t unused = 0;
3173 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3179 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3181 fill_buffers_with_input (bufs, _input, nframes);
3183 if (_meter_point == MeterInput) {
3184 _meter->run (bufs, start_frame, end_frame, nframes, true);
3187 passthru (bufs, start_frame, end_frame, nframes, declick);
3193 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3200 Route::flush_processors ()
3202 /* XXX shouldn't really try to take this lock, since
3203 this is called from the RT audio thread.
3206 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3208 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3214 Route::set_meter_point (MeterPoint p, bool force)
3216 if (_meter_point == p && !force) {
3220 bool meter_was_visible_to_user = _meter->display_to_user ();
3223 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3224 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3226 maybe_note_meter_position ();
3230 if (_meter_point != MeterCustom) {
3232 _meter->set_display_to_user (false);
3234 setup_invisible_processors ();
3238 _meter->set_display_to_user (true);
3240 /* If we have a previous position for the custom meter, try to put it there */
3241 if (_custom_meter_position_noted) {
3242 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3245 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3246 if (i != _processors.end ()) {
3247 _processors.remove (_meter);
3248 _processors.insert (i, _meter);
3250 } else if (_last_custom_meter_was_at_end) {
3251 _processors.remove (_meter);
3252 _processors.push_back (_meter);
3257 /* Set up the meter for its new position */
3259 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3263 if (loc == _processors.begin()) {
3264 m_in = _input->n_ports();
3266 ProcessorList::iterator before = loc;
3268 m_in = (*before)->output_streams ();
3271 _meter->reflect_inputs (m_in);
3273 /* we do not need to reconfigure the processors, because the meter
3274 (a) is always ready to handle processor_max_streams
3275 (b) is always an N-in/N-out processor, and thus moving
3276 it doesn't require any changes to the other processors.
3280 meter_change (); /* EMIT SIGNAL */
3282 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3284 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3288 Route::listen_position_changed ()
3291 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3292 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3293 ProcessorState pstate (this);
3295 if (configure_processors_unlocked (0)) {
3297 configure_processors_unlocked (0); // it worked before we tried to add it ...
3302 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3303 _session.set_dirty ();
3306 boost::shared_ptr<CapturingProcessor>
3307 Route::add_export_point()
3309 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3310 if (!_capturing_processor) {
3312 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3313 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3315 _capturing_processor.reset (new CapturingProcessor (_session));
3316 _capturing_processor->activate ();
3318 configure_processors_unlocked (0);
3322 return _capturing_processor;
3326 Route::update_signal_latency ()
3328 framecnt_t l = _output->user_latency();
3329 framecnt_t lamp = 0;
3330 bool before_amp = true;
3332 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3333 if ((*i)->active ()) {
3334 l += (*i)->signal_latency ();
3344 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3346 _signal_latency_at_amp_position = lamp;
3347 if (_signal_latency != l) {
3348 _signal_latency = l;
3349 signal_latency_changed (); /* EMIT SIGNAL */
3352 return _signal_latency;
3356 Route::set_user_latency (framecnt_t nframes)
3358 _output->set_user_latency (nframes);
3359 _session.update_latency_compensation ();
3363 Route::set_latency_compensation (framecnt_t longest_session_latency)
3365 framecnt_t old = _initial_delay;
3367 if (_signal_latency < longest_session_latency) {
3368 _initial_delay = longest_session_latency - _signal_latency;
3373 DEBUG_TRACE (DEBUG::Latency, string_compose (
3374 "%1: compensate for maximum latency of %2,"
3375 "given own latency of %3, using initial delay of %4\n",
3376 name(), longest_session_latency, _signal_latency, _initial_delay));
3378 if (_initial_delay != old) {
3379 initial_delay_changed (); /* EMIT SIGNAL */
3382 if (_session.transport_stopped()) {
3383 _roll_delay = _initial_delay;
3387 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3388 : AutomationControl (r->session(),
3389 Evoral::Parameter (SoloAutomation),
3390 ParameterDescriptor(Evoral::Parameter (SoloAutomation)),
3391 boost::shared_ptr<AutomationList>(), name)
3394 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3399 Route::SoloControllable::set_value (double val)
3401 bool bval = ((val >= 0.5f) ? true: false);
3403 boost::shared_ptr<RouteList> rl (new RouteList);
3405 boost::shared_ptr<Route> r = _route.lock ();
3412 if (Config->get_solo_control_is_listen_control()) {
3413 _session.set_listen (rl, bval);
3415 _session.set_solo (rl, bval);
3420 Route::SoloControllable::get_value () const
3422 boost::shared_ptr<Route> r = _route.lock ();
3427 if (Config->get_solo_control_is_listen_control()) {
3428 return r->listening_via_monitor() ? 1.0f : 0.0f;
3430 return r->self_soloed() ? 1.0f : 0.0f;
3434 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3435 : AutomationControl (r->session(),
3436 Evoral::Parameter (MuteAutomation),
3437 ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
3438 boost::shared_ptr<AutomationList>(),
3442 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3447 Route::MuteControllable::set_value (double val)
3449 bool bval = ((val >= 0.5f) ? true: false);
3451 boost::shared_ptr<RouteList> rl (new RouteList);
3453 boost::shared_ptr<Route> r = _route.lock ();
3459 _session.set_mute (rl, bval);
3463 Route::MuteControllable::get_value () const
3465 boost::shared_ptr<Route> r = _route.lock ();
3470 return r->muted() ? 1.0f : 0.0f;
3474 Route::set_block_size (pframes_t nframes)
3476 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3477 (*i)->set_block_size (nframes);
3480 _session.ensure_buffers (n_process_buffers ());
3484 Route::protect_automation ()
3486 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3487 (*i)->protect_automation();
3490 /** @param declick 1 to set a pending declick fade-in,
3491 * -1 to set a pending declick fade-out
3494 Route::set_pending_declick (int declick)
3497 /* this call is not allowed to turn off a pending declick */
3499 _pending_declick = declick;
3502 _pending_declick = 0;
3506 /** Shift automation forwards from a particular place, thereby inserting time.
3507 * Adds undo commands for any shifts that are performed.
3509 * @param pos Position to start shifting from.
3510 * @param frames Amount to shift forwards by.
3514 Route::shift (framepos_t pos, framecnt_t frames)
3516 /* gain automation */
3518 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3520 XMLNode &before = gc->alist()->get_state ();
3521 gc->alist()->shift (pos, frames);
3522 XMLNode &after = gc->alist()->get_state ();
3523 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3526 /* pan automation */
3528 ControlSet::Controls& c (_pannable->controls());
3530 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3531 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3533 boost::shared_ptr<AutomationList> al = pc->alist();
3534 XMLNode& before = al->get_state ();
3535 al->shift (pos, frames);
3536 XMLNode& after = al->get_state ();
3537 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3542 /* redirect automation */
3544 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3545 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3547 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3549 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3550 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3552 boost::shared_ptr<AutomationList> al = ac->alist();
3553 XMLNode &before = al->get_state ();
3554 al->shift (pos, frames);
3555 XMLNode &after = al->get_state ();
3556 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3565 Route::save_as_template (const string& path, const string& name)
3567 XMLNode& node (state (false));
3570 IO::set_name_in_state (*node.children().front(), name);
3572 tree.set_root (&node);
3573 return tree.write (path.c_str());
3578 Route::set_name (const string& str)
3580 if (str == name()) {
3584 string name = Route::ensure_track_or_route_name (str, _session);
3585 SessionObject::set_name (name);
3587 bool ret = (_input->set_name(name) && _output->set_name(name));
3590 /* rename the main outs. Leave other IO processors
3591 * with whatever name they already have, because its
3592 * just fine as it is (it will not contain the route
3593 * name if its a port insert, port send or port return).
3597 if (_main_outs->set_name (name)) {
3598 /* XXX returning false here is stupid because
3599 we already changed the route name.
3609 /** Set the name of a route in an XML description.
3610 * @param node XML <Route> node to set the name in.
3611 * @param name New name.
3614 Route::set_name_in_state (XMLNode& node, string const & name)
3616 node.add_property (X_("name"), name);
3618 XMLNodeList children = node.children();
3619 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3621 if ((*i)->name() == X_("IO")) {
3623 IO::set_name_in_state (**i, name);
3625 } else if ((*i)->name() == X_("Processor")) {
3627 XMLProperty* role = (*i)->property (X_("role"));
3628 if (role && role->value() == X_("Main")) {
3629 (*i)->add_property (X_("name"), name);
3632 } else if ((*i)->name() == X_("Diskstream")) {
3634 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3635 (*i)->add_property (X_("name"), name);
3641 boost::shared_ptr<Send>
3642 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3644 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3646 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3647 boost::shared_ptr<InternalSend> send;
3649 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3650 if (send->target_route() == target) {
3656 return boost::shared_ptr<Send>();
3659 /** @param c Audio channel index.
3660 * @param yn true to invert phase, otherwise false.
3663 Route::set_phase_invert (uint32_t c, bool yn)
3665 if (_phase_invert[c] != yn) {
3666 _phase_invert[c] = yn;
3667 phase_invert_changed (); /* EMIT SIGNAL */
3668 _session.set_dirty ();
3673 Route::set_phase_invert (boost::dynamic_bitset<> p)
3675 if (_phase_invert != p) {
3677 phase_invert_changed (); /* EMIT SIGNAL */
3678 _session.set_dirty ();
3683 Route::phase_invert (uint32_t c) const
3685 return _phase_invert[c];
3688 boost::dynamic_bitset<>
3689 Route::phase_invert () const
3691 return _phase_invert;
3695 Route::set_denormal_protection (bool yn)
3697 if (_denormal_protection != yn) {
3698 _denormal_protection = yn;
3699 denormal_protection_changed (); /* EMIT SIGNAL */
3704 Route::denormal_protection () const
3706 return _denormal_protection;
3710 Route::set_active (bool yn, void* src)
3712 if (_session.transport_rolling()) {
3716 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3717 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3721 if (_active != yn) {
3723 _input->set_active (yn);
3724 _output->set_active (yn);
3725 active_changed (); // EMIT SIGNAL
3726 _session.set_dirty ();
3733 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3739 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3741 boost::shared_ptr<Send> s;
3742 boost::shared_ptr<Return> r;
3744 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3745 s->meter()->meter();
3746 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3747 r->meter()->meter ();
3752 boost::shared_ptr<Pannable>
3753 Route::pannable() const
3758 boost::shared_ptr<Panner>
3759 Route::panner() const
3762 return _main_outs->panner_shell()->panner();
3765 boost::shared_ptr<PannerShell>
3766 Route::panner_shell() const
3768 return _main_outs->panner_shell();
3771 boost::shared_ptr<AutomationControl>
3772 Route::gain_control() const
3774 return _amp->gain_control();
3777 boost::shared_ptr<AutomationControl>
3778 Route::get_control (const Evoral::Parameter& param)
3780 /* either we own the control or .... */
3782 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3786 /* maybe one of our processors does or ... */
3788 Glib::Threads::RWLock::ReaderLock rm (_processor_lock, Glib::Threads::TRY_LOCK);
3789 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3790 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3798 /* nobody does so we'll make a new one */
3800 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3807 boost::shared_ptr<Processor>
3808 Route::nth_plugin (uint32_t n)
3810 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3811 ProcessorList::iterator i;
3813 for (i = _processors.begin(); i != _processors.end(); ++i) {
3814 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3821 return boost::shared_ptr<Processor> ();
3824 boost::shared_ptr<Processor>
3825 Route::nth_send (uint32_t n)
3827 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3828 ProcessorList::iterator i;
3830 for (i = _processors.begin(); i != _processors.end(); ++i) {
3831 if (boost::dynamic_pointer_cast<Send> (*i)) {
3838 return boost::shared_ptr<Processor> ();
3842 Route::has_io_processor_named (const string& name)
3844 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3845 ProcessorList::iterator i;
3847 for (i = _processors.begin(); i != _processors.end(); ++i) {
3848 if (boost::dynamic_pointer_cast<Send> (*i) ||
3849 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3850 if ((*i)->name() == name) {
3859 MuteMaster::MutePoint
3860 Route::mute_points () const
3862 return _mute_master->mute_points ();
3866 Route::set_processor_positions ()
3868 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3870 bool had_amp = false;
3871 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3872 (*i)->set_pre_fader (!had_amp);
3873 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3879 /** Called when there is a proposed change to the input port count */
3881 Route::input_port_count_changing (ChanCount to)
3883 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3885 /* The processors cannot be configured with the new input arrangement, so
3891 /* The change is ok */
3895 /** Called when there is a proposed change to the output port count */
3897 Route::output_port_count_changing (ChanCount to)
3899 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
3900 if (processor_out_streams.get(*t) > to.get(*t)) {
3904 /* The change is ok */
3909 Route::unknown_processors () const
3913 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3914 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3915 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3916 p.push_back ((*i)->name ());
3925 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
3927 /* we assume that all our input ports feed all our output ports. its not
3928 universally true, but the alternative is way too corner-case to worry about.
3931 LatencyRange all_connections;
3934 all_connections.min = 0;
3935 all_connections.max = 0;
3937 all_connections.min = ~((pframes_t) 0);
3938 all_connections.max = 0;
3940 /* iterate over all "from" ports and determine the latency range for all of their
3941 connections to the "outside" (outside of this Route).
3944 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3948 p->get_connected_latency_range (range, playback);
3950 all_connections.min = min (all_connections.min, range.min);
3951 all_connections.max = max (all_connections.max, range.max);
3955 /* set the "from" port latencies to the max/min range of all their connections */
3957 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3958 p->set_private_latency_range (all_connections, playback);
3961 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
3963 all_connections.min += our_latency;
3964 all_connections.max += our_latency;
3966 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
3967 p->set_private_latency_range (all_connections, playback);
3970 return all_connections.max;
3974 Route::set_private_port_latencies (bool playback) const
3976 framecnt_t own_latency = 0;
3978 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
3979 OR LATENCY CALLBACK.
3981 This is called (early) from the latency callback. It computes the REAL
3982 latency associated with each port and stores the result as the "private"
3983 latency of the port. A later call to Route::set_public_port_latencies()
3984 sets all ports to the same value to reflect the fact that we do latency
3985 compensation and so all signals are delayed by the same amount as they
3986 flow through ardour.
3989 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3990 if ((*i)->active ()) {
3991 own_latency += (*i)->signal_latency ();
3996 /* playback: propagate latency from "outside the route" to outputs to inputs */
3997 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
3999 /* capture: propagate latency from "outside the route" to inputs to outputs */
4000 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4005 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4007 /* this is called to set the JACK-visible port latencies, which take
4008 latency compensation into account.
4017 const PortSet& ports (_input->ports());
4018 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4019 p->set_public_latency_range (range, playback);
4024 const PortSet& ports (_output->ports());
4025 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4026 p->set_public_latency_range (range, playback);
4031 /** Put the invisible processors in the right place in _processors.
4032 * Must be called with a writer lock on _processor_lock held.
4035 Route::setup_invisible_processors ()
4038 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4039 assert (!lm.locked ());
4043 /* too early to be doing this stuff */
4047 /* we'll build this new list here and then use it */
4049 ProcessorList new_processors;
4051 /* find visible processors */
4053 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4054 if ((*i)->display_to_user ()) {
4055 new_processors.push_back (*i);
4061 ProcessorList::iterator amp = new_processors.begin ();
4062 while (amp != new_processors.end() && boost::dynamic_pointer_cast<Amp> (*amp) == 0) {
4066 assert (amp != new_processors.end ());
4068 /* and the processor after the amp */
4070 ProcessorList::iterator after_amp = amp;
4076 switch (_meter_point) {
4078 assert (!_meter->display_to_user ());
4079 new_processors.push_front (_meter);
4082 assert (!_meter->display_to_user ());
4083 new_processors.insert (amp, _meter);
4085 case MeterPostFader:
4086 /* do nothing here */
4089 /* do nothing here */
4092 /* the meter is visible, so we don't touch it here */
4099 assert (_main_outs);
4100 assert (!_main_outs->display_to_user ());
4101 new_processors.push_back (_main_outs);
4103 /* iterator for the main outs */
4105 ProcessorList::iterator main = new_processors.end();
4108 /* OUTPUT METERING */
4110 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4111 assert (!_meter->display_to_user ());
4113 /* add the processor just before or just after the main outs */
4115 ProcessorList::iterator meter_point = main;
4117 if (_meter_point == MeterOutput) {
4120 new_processors.insert (meter_point, _meter);
4125 if (_monitor_send && !is_monitor ()) {
4126 assert (!_monitor_send->display_to_user ());
4127 if (Config->get_solo_control_is_listen_control()) {
4128 switch (Config->get_listen_position ()) {
4129 case PreFaderListen:
4130 switch (Config->get_pfl_position ()) {
4131 case PFLFromBeforeProcessors:
4132 new_processors.push_front (_monitor_send);
4134 case PFLFromAfterProcessors:
4135 new_processors.insert (amp, _monitor_send);
4138 _monitor_send->set_can_pan (false);
4140 case AfterFaderListen:
4141 switch (Config->get_afl_position ()) {
4142 case AFLFromBeforeProcessors:
4143 new_processors.insert (after_amp, _monitor_send);
4145 case AFLFromAfterProcessors:
4146 new_processors.insert (new_processors.end(), _monitor_send);
4149 _monitor_send->set_can_pan (true);
4153 new_processors.insert (new_processors.end(), _monitor_send);
4154 _monitor_send->set_can_pan (false);
4158 #if 0 // not used - just yet
4159 if (!is_master() && !is_monitor() && !is_auditioner()) {
4160 new_processors.push_front (_delayline);
4164 /* MONITOR CONTROL */
4166 if (_monitor_control && is_monitor ()) {
4167 assert (!_monitor_control->display_to_user ());
4168 new_processors.push_front (_monitor_control);
4171 /* INTERNAL RETURN */
4173 /* doing this here means that any monitor control will come just after
4178 assert (!_intreturn->display_to_user ());
4179 new_processors.push_front (_intreturn);
4182 /* EXPORT PROCESSOR */
4184 if (_capturing_processor) {
4185 assert (!_capturing_processor->display_to_user ());
4186 new_processors.push_front (_capturing_processor);
4189 _processors = new_processors;
4191 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4192 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4193 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4200 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4201 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4205 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4206 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4213 /** If the meter point is `Custom', make a note of where the meter is.
4214 * This is so that if the meter point is subsequently set to something else,
4215 * and then back to custom, we can put the meter back where it was last time
4216 * custom was enabled.
4218 * Must be called with the _processor_lock held.
4221 Route::maybe_note_meter_position ()
4223 if (_meter_point != MeterCustom) {
4227 _custom_meter_position_noted = true;
4228 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4229 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4230 ProcessorList::iterator j = i;
4232 if (j != _processors.end ()) {
4233 _processor_after_last_custom_meter = *j;
4234 _last_custom_meter_was_at_end = false;
4236 _last_custom_meter_was_at_end = true;
4242 boost::shared_ptr<Processor>
4243 Route::processor_by_id (PBD::ID id) const
4245 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4246 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4247 if ((*i)->id() == id) {
4252 return boost::shared_ptr<Processor> ();
4255 /** @return the monitoring state, or in other words what data we are pushing
4256 * into the route (data from the inputs, data from disk or silence)
4259 Route::monitoring_state () const
4261 return MonitoringInput;
4264 /** @return what we should be metering; either the data coming from the input
4265 * IO or the data that is flowing through the route.
4268 Route::metering_state () const
4270 return MeteringRoute;
4274 Route::has_external_redirects () const
4276 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4278 /* ignore inactive processors and obviously ignore the main
4279 * outs since everything has them and we don't care.
4282 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4290 boost::shared_ptr<Processor>
4291 Route::the_instrument () const
4293 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4294 return the_instrument_unlocked ();
4297 boost::shared_ptr<Processor>
4298 Route::the_instrument_unlocked () const
4300 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4301 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4302 if ((*i)->input_streams().n_midi() > 0 &&
4303 (*i)->output_streams().n_audio() > 0) {
4308 return boost::shared_ptr<Processor>();
4314 Route::non_realtime_locate (framepos_t pos)
4317 _pannable->transport_located (pos);
4320 if (_delayline.get()) {
4321 _delayline.get()->flush();
4325 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4326 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4328 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4329 (*i)->transport_located (pos);
4335 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4342 * We don't currently mix MIDI input together, so we don't need the
4343 * complex logic of the audio case.
4346 n_buffers = bufs.count().n_midi ();
4348 for (i = 0; i < n_buffers; ++i) {
4350 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4351 MidiBuffer& buf (bufs.get_midi (i));
4354 buf.copy (source_port->get_midi_buffer(nframes));
4356 buf.silence (nframes);
4362 n_buffers = bufs.count().n_audio();
4364 size_t n_ports = io->n_ports().n_audio();
4365 float scaling = 1.0f;
4367 if (n_ports > n_buffers) {
4368 scaling = ((float) n_buffers) / n_ports;
4371 for (i = 0; i < n_ports; ++i) {
4373 /* if there are more ports than buffers, map them onto buffers
4374 * in a round-robin fashion
4377 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4378 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4381 if (i < n_buffers) {
4383 /* first time through just copy a channel into
4387 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4389 if (scaling != 1.0f) {
4390 buf.apply_gain (scaling, nframes);
4395 /* on subsequent times around, merge data from
4396 * the port with what is already there
4399 if (scaling != 1.0f) {
4400 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4402 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4407 /* silence any remaining buffers */
4409 for (; i < n_buffers; ++i) {
4410 AudioBuffer& buf (bufs.get_audio (i));
4411 buf.silence (nframes);
4414 /* establish the initial setup of the buffer set, reflecting what was
4415 copied into it. unless, of course, we are the auditioner, in which
4416 case nothing was fed into it from the inputs at all.
4419 if (!is_auditioner()) {
4420 bufs.set_count (io->n_ports());