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"
30 #include <boost/algorithm/string.hpp>
32 #include "pbd/xml++.h"
33 #include "pbd/enumwriter.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/convert.h"
37 #include "pbd/boost_debug.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/internal_return.h"
50 #include "ardour/internal_send.h"
51 #include "ardour/meter.h"
52 #include "ardour/delayline.h"
53 #include "ardour/midi_buffer.h"
54 #include "ardour/midi_port.h"
55 #include "ardour/monitor_processor.h"
56 #include "ardour/pannable.h"
57 #include "ardour/panner.h"
58 #include "ardour/panner_shell.h"
59 #include "ardour/plugin_insert.h"
60 #include "ardour/port.h"
61 #include "ardour/port_insert.h"
62 #include "ardour/processor.h"
63 #include "ardour/profile.h"
64 #include "ardour/route.h"
65 #include "ardour/route_group.h"
66 #include "ardour/send.h"
67 #include "ardour/session.h"
68 #include "ardour/unknown_processor.h"
69 #include "ardour/utils.h"
74 using namespace ARDOUR;
77 PBD::Signal0<void> Route::SyncOrderKeys;
78 PBD::Signal0<void> Route::RemoteControlIDChange;
80 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
81 : SessionObject (sess, name)
83 , GraphNode (sess._process_graph)
86 , _signal_latency_at_amp_position (0)
87 , _signal_latency_at_trim_position (0)
90 , _pending_process_reorder (0)
92 , _pending_declick (true)
93 , _meter_point (MeterPostFader)
94 , _pending_meter_point (MeterPostFader)
95 , _meter_type (MeterPeak)
97 , _soloed_by_others_upstream (0)
98 , _soloed_by_others_downstream (0)
100 , _denormal_protection (false)
103 , _declickable (false)
104 , _mute_master (new MuteMaster (sess, name))
105 , _have_internal_generator (false)
107 , _default_type (default_type)
109 , _has_order_key (false)
110 , _remote_control_id (0)
112 , _in_configure_processors (false)
113 , _initial_io_setup (false)
114 , _custom_meter_position_noted (false)
117 _meter_type = MeterK20;
119 processor_max_streams.reset();
125 /* add standard controls */
127 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
128 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
130 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
131 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
133 add_control (_solo_control);
134 add_control (_mute_control);
138 if (!(_flags & Route::MonitorOut)) {
139 _pannable.reset (new Pannable (_session));
142 /* input and output objects */
144 _input.reset (new IO (_session, _name, IO::Input, _default_type));
145 _output.reset (new IO (_session, _name, IO::Output, _default_type));
147 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
148 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
150 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
151 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
153 #if 0 // not used - just yet
154 if (!is_master() && !is_monitor() && !is_auditioner()) {
155 _delayline.reset (new DelayLine (_session, _name));
156 add_processor (_delayline, PreFader);
160 /* add amp processor */
162 _amp.reset (new Amp (_session));
163 add_processor (_amp, PostFader);
166 _trim.reset (new Amp (_session, "trim"));
167 _trim->set_display_to_user (false);
169 if (dynamic_cast<AudioTrack*>(this)) {
170 /* we can't do this in the AudioTrack's constructor
171 * because _trim does not exit then
175 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
180 /* create standard processors: meter, main outs, monitor out;
181 they will be added to _processors by setup_invisible_processors ()
184 _meter.reset (new PeakMeter (_session, _name));
185 _meter->set_owner (this);
186 _meter->set_display_to_user (false);
189 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
190 _main_outs->activate ();
193 /* where we listen to tracks */
194 _intreturn.reset (new InternalReturn (_session));
195 _intreturn->activate ();
197 /* the thing that provides proper control over a control/monitor/listen bus
198 (such as per-channel cut, dim, solo, invert, etc).
200 _monitor_control.reset (new MonitorProcessor (_session));
201 _monitor_control->activate ();
204 if (is_master() || is_monitor() || is_auditioner()) {
205 _mute_master->set_solo_ignore (true);
208 /* now that we have _meter, its safe to connect to this */
211 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
212 configure_processors (0);
220 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
222 /* do this early so that we don't get incoming signals as we are going through destruction
227 /* don't use clear_processors here, as it depends on the session which may
228 be half-destroyed by now
231 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
232 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
233 (*i)->drop_references ();
236 _processors.clear ();
240 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
242 if (Config->get_remote_model() != UserOrdered) {
246 set_remote_control_id_internal (id, notify_class_listeners);
250 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
252 /* force IDs for master/monitor busses and prevent
253 any other route from accidentally getting these IDs
254 (i.e. legacy sessions)
257 if (is_master() && id != MasterBusRemoteControlID) {
258 id = MasterBusRemoteControlID;
261 if (is_monitor() && id != MonitorBusRemoteControlID) {
262 id = MonitorBusRemoteControlID;
269 /* don't allow it to collide */
271 if (!is_master () && !is_monitor() &&
272 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
273 id += MonitorBusRemoteControlID;
276 if (id != remote_control_id()) {
277 _remote_control_id = id;
278 RemoteControlIDChanged ();
280 if (notify_class_listeners) {
281 RemoteControlIDChange ();
287 Route::remote_control_id() const
290 return MasterBusRemoteControlID;
294 return MonitorBusRemoteControlID;
297 return _remote_control_id;
301 Route::has_order_key () const
303 return _has_order_key;
307 Route::order_key () const
313 Route::set_remote_control_id_explicit (uint32_t rid)
315 if (is_master() || is_monitor() || is_auditioner()) {
316 /* hard-coded remote IDs, or no remote ID */
320 if (_remote_control_id != rid) {
321 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
322 _remote_control_id = rid;
323 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
326 /* don't emit the class-level RID signal RemoteControlIDChange here,
327 leave that to the entity that changed the order key, so that we
328 don't get lots of emissions for no good reasons (e.g. when changing
329 all route order keys).
331 See Session::sync_remote_id_from_order_keys() for the (primary|only)
332 spot where that is emitted.
337 Route::set_order_key (uint32_t n)
339 _has_order_key = true;
341 if (_order_key == n) {
347 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
348 name(), order_key ()));
350 _session.set_dirty ();
354 Route::ensure_track_or_route_name(string name, Session &session)
356 string newname = name;
358 while (!session.io_name_is_legal (newname)) {
359 newname = bump_name_once (newname, '.');
366 Route::inc_gain (gain_t fraction, void *src)
368 _amp->inc_gain (fraction, src);
372 Route::set_gain (gain_t val, void *src)
374 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
376 if (_route_group->is_relative()) {
378 gain_t usable_gain = _amp->gain();
379 if (usable_gain < 0.000001f) {
380 usable_gain = 0.000001f;
384 if (delta < 0.000001f) {
388 delta -= usable_gain;
393 gain_t factor = delta / usable_gain;
396 factor = _route_group->get_max_factor(factor);
397 if (factor == 0.0f) {
398 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
402 factor = _route_group->get_min_factor(factor);
403 if (factor == 0.0f) {
404 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
409 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
413 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
419 if (val == _amp->gain()) {
423 _amp->set_gain (val, src);
427 Route::inc_trim (gain_t fraction, void *src)
429 _trim->inc_gain (fraction, src);
433 Route::set_trim (gain_t val, void * /* src */)
435 // TODO route group, see set_gain()
436 _trim->set_gain (val, 0);
440 Route::maybe_declick (BufferSet&, framecnt_t, int)
442 /* this is the "bus" implementation and they never declick.
447 /** Process this route for one (sub) cycle (process thread)
449 * @param bufs Scratch buffers to use for the signal path
450 * @param start_frame Initial transport frame
451 * @param end_frame Final transport frame
452 * @param nframes Number of frames to output (to ports)
454 * Note that (end_frame - start_frame) may not be equal to nframes when the
455 * transport speed isn't 1.0 (eg varispeed).
458 Route::process_output_buffers (BufferSet& bufs,
459 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
460 int declick, bool gain_automation_ok)
462 /* Caller must hold process lock */
463 assert (!AudioEngine::instance()->process_lock().trylock());
465 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
467 // can this actually happen? functions calling process_output_buffers()
468 // already take a reader-lock.
469 bufs.silence (nframes, 0);
473 /* figure out if we're going to use gain automation */
474 if (gain_automation_ok) {
475 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
476 _amp->setup_gain_automation (
477 start_frame + _signal_latency_at_amp_position,
478 end_frame + _signal_latency_at_amp_position,
481 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
482 _trim->setup_gain_automation (
483 start_frame + _signal_latency_at_trim_position,
484 end_frame + _signal_latency_at_trim_position,
487 _amp->apply_gain_automation (false);
488 _trim->apply_gain_automation (false);
491 /* Tell main outs what to do about monitoring. We do this so that
492 on a transition between monitoring states we get a de-clicking gain
493 change in the _main_outs delivery.
495 bool silence = monitoring_state () == MonitoringSilence;
497 //but we override this in the case where we have an internal generator
498 if ( _have_internal_generator )
501 _main_outs->no_outs_cuz_we_no_monitor (silence);
503 /* -------------------------------------------------------------------------------------------
504 GLOBAL DECLICK (for transport changes etc.)
505 ----------------------------------------------------------------------------------------- */
507 maybe_declick (bufs, nframes, declick);
508 _pending_declick = 0;
510 /* -------------------------------------------------------------------------------------------
511 DENORMAL CONTROL/PHASE INVERT
512 ----------------------------------------------------------------------------------------- */
514 if (_phase_invert.any ()) {
518 if (_denormal_protection || Config->get_denormal_protection()) {
520 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
521 Sample* const sp = i->data();
523 if (_phase_invert[chn]) {
524 for (pframes_t nx = 0; nx < nframes; ++nx) {
529 for (pframes_t nx = 0; nx < nframes; ++nx) {
537 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
538 Sample* const sp = i->data();
540 if (_phase_invert[chn]) {
541 for (pframes_t nx = 0; nx < nframes; ++nx) {
550 if (_denormal_protection || Config->get_denormal_protection()) {
552 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
553 Sample* const sp = i->data();
554 for (pframes_t nx = 0; nx < nframes; ++nx) {
562 /* -------------------------------------------------------------------------------------------
564 ----------------------------------------------------------------------------------------- */
566 /* set this to be true if the meter will already have been ::run() earlier */
567 bool const meter_already_run = metering_state() == MeteringInput;
569 framecnt_t latency = 0;
571 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
573 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
574 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
579 /* if it has any inputs, make sure they match */
580 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
581 if (bufs.count() != (*i)->input_streams()) {
583 DEBUG::Processors, string_compose (
584 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
585 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
592 /* should we NOT run plugins here if the route is inactive?
593 do we catch route != active somewhere higher?
596 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
597 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
600 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
601 bufs.set_count ((*i)->output_streams());
603 if ((*i)->active ()) {
604 latency += (*i)->signal_latency ();
610 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
611 boost::shared_ptr<Processor> endpoint,
612 bool include_endpoint, bool for_export, bool for_freeze)
614 /* If no processing is required, there's no need to go any further. */
615 if (!endpoint && !include_endpoint) {
619 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
620 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
621 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
623 /* trim is always at the top, for bounce no latency compensation is needed */
624 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
625 _trim->setup_gain_automation (start, start + nframes, nframes);
628 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
630 if (!include_endpoint && (*i) == endpoint) {
634 /* if we're not exporting, stop processing if we come across a routing processor. */
635 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
638 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
642 /* don't run any processors that does routing.
643 * oh, and don't bother with the peak meter either.
645 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
646 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
647 buffers.set_count ((*i)->output_streams());
648 latency += (*i)->signal_latency ();
651 if ((*i) == endpoint) {
658 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
659 bool include_endpoint, bool for_export, bool for_freeze) const
661 framecnt_t latency = 0;
662 if (!endpoint && !include_endpoint) {
666 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
667 if (!include_endpoint && (*i) == endpoint) {
670 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
673 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
676 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
677 latency += (*i)->signal_latency ();
679 if ((*i) == endpoint) {
687 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
688 bool include_endpoint, bool for_export, bool for_freeze) const
690 if (!endpoint && !include_endpoint) {
694 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
695 if (!include_endpoint && (*i) == endpoint) {
698 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
701 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
704 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
705 cc = (*i)->output_streams();
707 if ((*i) == endpoint) {
715 Route::n_process_buffers ()
717 return max (_input->n_ports(), processor_max_streams);
721 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
723 assert (is_monitor());
724 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
725 fill_buffers_with_input (bufs, _input, nframes);
726 passthru (bufs, start_frame, end_frame, nframes, declick);
730 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
734 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
736 /* control/monitor bus ignores input ports when something is
737 feeding the listen "stream". data will "arrive" into the
738 route from the intreturn processor element.
741 bufs.silence (nframes, 0);
744 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
745 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
749 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
751 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
753 bufs.set_count (_input->n_ports());
754 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
755 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
759 Route::set_listen (bool yn, void* src)
765 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
766 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
771 if (yn != _monitor_send->active()) {
773 _monitor_send->activate ();
774 _mute_master->set_soloed (true);
776 _monitor_send->deactivate ();
777 _mute_master->set_soloed (false);
780 listen_changed (src); /* EMIT SIGNAL */
786 Route::listening_via_monitor () const
789 return _monitor_send->active ();
796 Route::set_solo_safe (bool yn, void *src)
798 if (_solo_safe != yn) {
800 solo_safe_changed (src);
805 Route::solo_safe() const
811 Route::set_solo (bool yn, void *src)
814 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change due to solo-safe\n", name()));
818 if (is_master() || is_monitor() || is_auditioner()) {
819 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo change (master, monitor or auditioner)\n", name()));
823 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
824 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
828 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set solo => %2, src: %3 grp ? %4 currently self-soloed ? %5\n",
829 name(), yn, src, (src == _route_group), self_soloed()));
831 if (self_soloed() != yn) {
833 set_mute_master_solo ();
834 solo_changed (true, src); /* EMIT SIGNAL */
835 _solo_control->Changed (); /* EMIT SIGNAL */
838 /* XXX TRACKS DEVELOPERS: THIS LOGIC SUGGESTS THAT YOU ARE NOT AWARE OF
839 Config->get_solo_mute_overrride().
842 if (yn && Profile->get_trx()) {
843 set_mute (false, src);
848 Route::set_self_solo (bool yn)
850 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1: set SELF solo => %2\n", name(), yn));
855 Route::mod_solo_by_others_upstream (int32_t delta)
858 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-upstream due to solo-safe\n", name()));
862 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-upstream by %2, current up = %3 down = %4\n",
863 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
865 uint32_t old_sbu = _soloed_by_others_upstream;
868 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
869 _soloed_by_others_upstream += delta;
871 _soloed_by_others_upstream = 0;
874 _soloed_by_others_upstream += delta;
877 DEBUG_TRACE (DEBUG::Solo, string_compose (
878 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
879 name(), delta, _soloed_by_others_upstream, old_sbu,
880 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
882 /* push the inverse solo change to everything that feeds us.
884 This is important for solo-within-group. When we solo 1 track out of N that
885 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
886 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
887 tracks that feed it. This will silence them if they were audible because
888 of a bus solo, but the newly soloed track will still be audible (because
891 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
895 if ((_self_solo || _soloed_by_others_downstream) &&
896 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
897 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
899 if (delta > 0 || !Config->get_exclusive_solo()) {
900 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
901 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
902 boost::shared_ptr<Route> sr = i->r.lock();
904 sr->mod_solo_by_others_downstream (-delta);
910 set_mute_master_solo ();
911 solo_changed (false, this);
915 Route::mod_solo_by_others_downstream (int32_t delta)
918 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 ignore solo-by-downstream due to solo safe\n", name()));
922 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 mod solo-by-downstream by %2, current up = %3 down = %4\n",
923 name(), delta, _soloed_by_others_upstream, _soloed_by_others_downstream));
926 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
927 _soloed_by_others_downstream += delta;
929 _soloed_by_others_downstream = 0;
932 _soloed_by_others_downstream += delta;
935 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
937 set_mute_master_solo ();
938 solo_changed (false, this);
942 Route::set_mute_master_solo ()
944 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
948 Route::set_solo_isolated (bool yn, void *src)
950 if (is_master() || is_monitor() || is_auditioner()) {
954 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
955 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
959 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
961 boost::shared_ptr<RouteList> routes = _session.get_routes ();
962 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
964 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
969 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
971 if (does_feed && !sends_only) {
972 (*i)->set_solo_isolated (yn, (*i)->route_group());
976 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
978 bool changed = false;
981 if (_solo_isolated == 0) {
982 _mute_master->set_solo_ignore (true);
987 if (_solo_isolated > 0) {
989 if (_solo_isolated == 0) {
990 _mute_master->set_solo_ignore (false);
997 solo_isolated_changed (src);
1002 Route::solo_isolated () const
1004 return _solo_isolated > 0;
1008 Route::set_mute_points (MuteMaster::MutePoint mp)
1010 _mute_master->set_mute_points (mp);
1011 mute_points_changed (); /* EMIT SIGNAL */
1013 if (_mute_master->muted_by_self()) {
1014 mute_changed (this); /* EMIT SIGNAL */
1015 _mute_control->Changed (); /* EMIT SIGNAL */
1020 Route::set_mute (bool yn, void *src)
1022 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
1023 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
1027 if (muted() != yn) {
1028 _mute_master->set_muted_by_self (yn);
1029 /* allow any derived classes to respond to the mute change
1030 before anybody else knows about it.
1033 /* tell everyone else */
1034 mute_changed (src); /* EMIT SIGNAL */
1035 _mute_control->Changed (); /* EMIT SIGNAL */
1040 Route::muted () const
1042 return _mute_master->muted_by_self();
1046 Route::muted_by_others () const
1048 //master is never muted by others
1052 //now check to see if something is soloed (and I am not)
1053 return (_session.soloing() && !self_soloed() && !solo_isolated());
1058 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
1060 cerr << name << " {" << endl;
1061 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
1062 p != procs.end(); ++p) {
1063 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
1065 cerr << "}" << endl;
1069 /** Supposing that we want to insert a Processor at a given Placement, return
1070 * the processor to add the new one before (or 0 to add at the end).
1072 boost::shared_ptr<Processor>
1073 Route::before_processor_for_placement (Placement p)
1075 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1077 ProcessorList::iterator loc;
1079 if (p == PreFader) {
1080 /* generic pre-fader: insert immediately before the amp */
1081 loc = find (_processors.begin(), _processors.end(), _amp);
1083 /* generic post-fader: insert right before the main outs */
1084 loc = find (_processors.begin(), _processors.end(), _main_outs);
1087 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
1090 /** Supposing that we want to insert a Processor at a given index, return
1091 * the processor to add the new one before (or 0 to add at the end).
1093 boost::shared_ptr<Processor>
1094 Route::before_processor_for_index (int index)
1097 return boost::shared_ptr<Processor> ();
1100 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1102 ProcessorList::iterator i = _processors.begin ();
1104 while (i != _processors.end() && j < index) {
1105 if ((*i)->display_to_user()) {
1112 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
1115 /** Add a processor either pre- or post-fader
1116 * @return 0 on success, non-0 on failure.
1119 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
1121 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
1125 /** Add a processor to a route such that it ends up with a given index into the visible processors.
1126 * @param index Index to add the processor at, or -1 to add at the end of the list.
1127 * @return 0 on success, non-0 on failure.
1130 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
1132 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
1135 /** Add a processor to the route.
1136 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
1137 * @return 0 on success, non-0 on failure.
1140 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
1142 assert (processor != _meter);
1143 assert (processor != _main_outs);
1145 DEBUG_TRACE (DEBUG::Processors, string_compose (
1146 "%1 adding processor %2\n", name(), processor->name()));
1148 if (!AudioEngine::instance()->connected() || !processor) {
1153 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1154 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1155 ProcessorState pstate (this);
1157 boost::shared_ptr<PluginInsert> pi;
1158 boost::shared_ptr<PortInsert> porti;
1160 if (processor == _amp) {
1161 /* Ensure that only one amp is in the list at any time */
1162 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
1163 if (check != _processors.end()) {
1164 if (before == _amp) {
1165 /* Already in position; all is well */
1168 _processors.erase (check);
1173 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
1175 ProcessorList::iterator loc;
1177 /* inserting before a processor; find it */
1178 loc = find (_processors.begin(), _processors.end(), before);
1179 if (loc == _processors.end ()) {
1184 /* inserting at end */
1185 loc = _processors.end ();
1188 _processors.insert (loc, processor);
1189 processor->set_owner (this);
1191 // Set up processor list channels. This will set processor->[input|output]_streams(),
1192 // configure redirect ports properly, etc.
1195 if (configure_processors_unlocked (err)) {
1197 configure_processors_unlocked (0); // it worked before we tried to add it ...
1202 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1204 if (pi->has_no_inputs ()) {
1205 /* generator plugin */
1206 _have_internal_generator = true;
1211 if (activation_allowed && !_session.get_disable_all_loaded_plugins()) {
1212 processor->activate ();
1215 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1217 _output->set_user_latency (0);
1220 reset_instrument_info ();
1221 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1222 set_processor_positions ();
1228 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1230 const XMLProperty *prop;
1233 boost::shared_ptr<Processor> processor;
1235 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1236 so that we can add the processor in the right place (pre/post-fader)
1239 XMLNodeList const & children = node.children ();
1240 XMLNodeList::const_iterator i = children.begin ();
1242 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1246 Placement placement = PreFader;
1248 if (i != children.end()) {
1249 if ((prop = (*i)->property (X_("placement"))) != 0) {
1250 placement = Placement (string_2_enum (prop->value(), placement));
1254 if (node.name() == "Insert") {
1256 if ((prop = node.property ("type")) != 0) {
1258 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1259 prop->value() == "lv2" ||
1260 prop->value() == "windows-vst" ||
1261 prop->value() == "lxvst" ||
1262 prop->value() == "audiounit") {
1264 processor.reset (new PluginInsert (_session));
1268 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1273 } else if (node.name() == "Send") {
1275 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
1276 processor.reset (new Send (_session, sendpan, _mute_master));
1280 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1284 if (processor->set_state (node, version)) {
1288 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
1289 if (i != children.end()) {
1290 if ((prop = (*i)->property (X_("active"))) != 0) {
1291 if ( string_is_affirmative (prop->value()) && !_session.get_disable_all_loaded_plugins() )
1292 processor->activate();
1294 processor->deactivate();
1298 return (add_processor (processor, placement, 0, false) == 0);
1301 catch (failed_constructor &err) {
1302 warning << _("processor could not be created. Ignored.") << endmsg;
1308 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1310 /* NOTE: this is intended to be used ONLY when copying
1311 processors from another Route. Hence the subtle
1312 differences between this and ::add_processor()
1315 ProcessorList::iterator loc;
1318 loc = find(_processors.begin(), _processors.end(), before);
1320 /* nothing specified - at end */
1321 loc = _processors.end ();
1324 if (!_session.engine().connected()) {
1328 if (others.empty()) {
1333 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1334 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1335 ProcessorState pstate (this);
1337 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1343 boost::shared_ptr<PluginInsert> pi;
1345 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1349 _processors.insert (loc, *i);
1350 (*i)->set_owner (this);
1352 if ((*i)->active()) {
1356 /* Think: does this really need to be called for every processor in the loop? */
1358 if (configure_processors_unlocked (err)) {
1360 configure_processors_unlocked (0); // it worked before we tried to add it ...
1365 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1368 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1369 boost::shared_ptr<PluginInsert> pi;
1371 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1372 if (pi->has_no_inputs ()) {
1373 _have_internal_generator = true;
1379 _output->set_user_latency (0);
1382 reset_instrument_info ();
1383 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1384 set_processor_positions ();
1390 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1392 if (p == PreFader) {
1393 start = _processors.begin();
1394 end = find(_processors.begin(), _processors.end(), _amp);
1396 start = find(_processors.begin(), _processors.end(), _amp);
1398 end = _processors.end();
1402 /** Turn off all processors with a given placement
1403 * @param p Placement of processors to disable
1406 Route::disable_processors (Placement p)
1408 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1410 ProcessorList::iterator start, end;
1411 placement_range(p, start, end);
1413 for (ProcessorList::iterator i = start; i != end; ++i) {
1414 (*i)->deactivate ();
1417 _session.set_dirty ();
1420 /** Turn off all redirects
1423 Route::disable_processors ()
1425 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1427 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1428 (*i)->deactivate ();
1431 _session.set_dirty ();
1434 /** Turn off all redirects with a given placement
1435 * @param p Placement of redirects to disable
1438 Route::disable_plugins (Placement p)
1440 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1442 ProcessorList::iterator start, end;
1443 placement_range(p, start, end);
1445 for (ProcessorList::iterator i = start; i != end; ++i) {
1446 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1447 (*i)->deactivate ();
1451 _session.set_dirty ();
1454 /** Turn off all plugins
1457 Route::disable_plugins ()
1459 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1461 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1462 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1463 (*i)->deactivate ();
1467 _session.set_dirty ();
1472 Route::ab_plugins (bool forward)
1474 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1478 /* forward = turn off all active redirects, and mark them so that the next time
1479 we go the other way, we will revert them
1482 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1483 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1487 if ((*i)->active()) {
1488 (*i)->deactivate ();
1489 (*i)->set_next_ab_is_active (true);
1491 (*i)->set_next_ab_is_active (false);
1497 /* backward = if the redirect was marked to go active on the next ab, do so */
1499 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1501 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1505 if ((*i)->get_next_ab_is_active()) {
1508 (*i)->deactivate ();
1513 _session.set_dirty ();
1517 /** Remove processors with a given placement.
1518 * @param p Placement of processors to remove.
1521 Route::clear_processors (Placement p)
1523 if (!_session.engine().connected()) {
1527 bool already_deleting = _session.deletion_in_progress();
1528 if (!already_deleting) {
1529 _session.set_deletion_in_progress();
1533 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1534 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1535 ProcessorList new_list;
1536 ProcessorStreams err;
1537 bool seen_amp = false;
1539 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1545 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1547 /* you can't remove these */
1549 new_list.push_back (*i);
1556 new_list.push_back (*i);
1559 (*i)->drop_references ();
1567 (*i)->drop_references ();
1570 new_list.push_back (*i);
1577 _processors = new_list;
1578 configure_processors_unlocked (&err); // this can't fail
1581 processor_max_streams.reset();
1582 _have_internal_generator = false;
1583 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1584 set_processor_positions ();
1586 reset_instrument_info ();
1588 if (!already_deleting) {
1589 _session.clear_deletion_in_progress();
1594 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1596 // TODO once the export point can be configured properly, do something smarter here
1597 if (processor == _capturing_processor) {
1598 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1599 if (need_process_lock) {
1603 _capturing_processor.reset();
1605 if (need_process_lock) {
1610 /* these can never be removed */
1612 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1616 if (!_session.engine().connected()) {
1620 processor_max_streams.reset();
1623 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1624 if (need_process_lock) {
1628 /* Caller must hold process lock */
1629 assert (!AudioEngine::instance()->process_lock().trylock());
1631 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1633 ProcessorState pstate (this);
1635 ProcessorList::iterator i;
1636 bool removed = false;
1638 for (i = _processors.begin(); i != _processors.end(); ) {
1639 if (*i == processor) {
1641 /* move along, see failure case for configure_processors()
1642 where we may need to reconfigure the processor.
1645 /* stop redirects that send signals to JACK ports
1646 from causing noise as a result of no longer being
1650 boost::shared_ptr<IOProcessor> iop;
1652 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1656 i = _processors.erase (i);
1664 _output->set_user_latency (0);
1672 if (configure_processors_unlocked (err)) {
1674 /* we know this will work, because it worked before :) */
1675 configure_processors_unlocked (0);
1679 _have_internal_generator = false;
1681 for (i = _processors.begin(); i != _processors.end(); ++i) {
1682 boost::shared_ptr<PluginInsert> pi;
1684 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1685 if (pi->has_no_inputs ()) {
1686 _have_internal_generator = true;
1691 if (need_process_lock) {
1696 reset_instrument_info ();
1697 processor->drop_references ();
1698 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1699 set_processor_positions ();
1705 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1707 ProcessorList deleted;
1709 if (!_session.engine().connected()) {
1713 processor_max_streams.reset();
1716 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1717 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1718 ProcessorState pstate (this);
1720 ProcessorList::iterator i;
1721 boost::shared_ptr<Processor> processor;
1723 for (i = _processors.begin(); i != _processors.end(); ) {
1727 /* these can never be removed */
1729 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1734 /* see if its in the list of processors to delete */
1736 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1741 /* stop IOProcessors that send to JACK ports
1742 from causing noise as a result of no longer being
1746 boost::shared_ptr<IOProcessor> iop;
1748 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1752 deleted.push_back (processor);
1753 i = _processors.erase (i);
1756 if (deleted.empty()) {
1757 /* none of those in the requested list were found */
1761 _output->set_user_latency (0);
1763 if (configure_processors_unlocked (err)) {
1765 /* we know this will work, because it worked before :) */
1766 configure_processors_unlocked (0);
1771 _have_internal_generator = false;
1773 for (i = _processors.begin(); i != _processors.end(); ++i) {
1774 boost::shared_ptr<PluginInsert> pi;
1776 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1777 if (pi->has_no_inputs ()) {
1778 _have_internal_generator = true;
1785 /* now try to do what we need to so that those that were removed will be deleted */
1787 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1788 (*i)->drop_references ();
1791 reset_instrument_info ();
1792 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1793 set_processor_positions ();
1799 Route::reset_instrument_info ()
1801 boost::shared_ptr<Processor> instr = the_instrument();
1803 _instrument_info.set_internal_instrument (instr);
1807 /** Caller must hold process lock */
1809 Route::configure_processors (ProcessorStreams* err)
1811 #ifndef PLATFORM_WINDOWS
1812 assert (!AudioEngine::instance()->process_lock().trylock());
1815 if (!_in_configure_processors) {
1816 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1817 return configure_processors_unlocked (err);
1824 Route::input_streams () const
1826 return _input->n_ports ();
1829 list<pair<ChanCount, ChanCount> >
1830 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1832 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1834 return try_configure_processors_unlocked (in, err);
1837 list<pair<ChanCount, ChanCount> >
1838 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1840 // Check each processor in order to see if we can configure as requested
1842 list<pair<ChanCount, ChanCount> > configuration;
1845 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1846 DEBUG_TRACE (DEBUG::Processors, "{\n");
1848 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1850 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1851 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1852 DEBUG_TRACE (DEBUG::Processors, "}\n");
1853 return list<pair<ChanCount, ChanCount> > ();
1856 if ((*p)->can_support_io_configuration(in, out)) {
1857 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1858 configuration.push_back(make_pair(in, out));
1865 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1866 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1867 DEBUG_TRACE (DEBUG::Processors, "}\n");
1868 return list<pair<ChanCount, ChanCount> > ();
1872 DEBUG_TRACE (DEBUG::Processors, "}\n");
1874 return configuration;
1877 /** Set the input/output configuration of each processor in the processors list.
1878 * Caller must hold process lock.
1879 * Return 0 on success, otherwise configuration is impossible.
1882 Route::configure_processors_unlocked (ProcessorStreams* err)
1884 #ifndef PLATFORM_WINDOWS
1885 assert (!AudioEngine::instance()->process_lock().trylock());
1888 if (_in_configure_processors) {
1892 /* put invisible processors where they should be */
1893 setup_invisible_processors ();
1895 _in_configure_processors = true;
1897 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1899 if (configuration.empty ()) {
1900 _in_configure_processors = false;
1905 bool seen_mains_out = false;
1906 processor_out_streams = _input->n_ports();
1907 processor_max_streams.reset();
1909 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1910 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1912 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1916 (*p)->configure_io(c->first, c->second);
1917 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1918 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1920 boost::shared_ptr<PluginInsert> pi;
1921 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1922 /* plugins connected via Split Match may have more channels.
1923 * route/scratch buffers are needed for all of them*/
1924 processor_max_streams = ChanCount::max(processor_max_streams, pi->input_streams());
1925 processor_max_streams = ChanCount::max(processor_max_streams, pi->natural_input_streams());
1929 if (boost::dynamic_pointer_cast<Delivery> (*p)
1930 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1931 /* main delivery will increase port count to match input.
1932 * the Delivery::Main is usually the last processor - followed only by
1935 seen_mains_out = true;
1937 if (!seen_mains_out) {
1938 processor_out_streams = out;
1944 _meter->set_max_channels (processor_max_streams);
1947 /* make sure we have sufficient scratch buffers to cope with the new processor
1950 _session.ensure_buffers (n_process_buffers ());
1952 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1954 _in_configure_processors = false;
1958 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1959 * @param state New active state for those processors.
1962 Route::all_visible_processors_active (bool state)
1964 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1966 if (_processors.empty()) {
1970 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1971 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1978 (*i)->deactivate ();
1982 _session.set_dirty ();
1986 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1988 /* check if re-order requires re-configuration of any processors
1989 * -> compare channel configuration for all processors
1991 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1992 ChanCount c = input_streams ();
1994 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1996 if (c != (*j)->input_streams()) {
1999 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2002 if ((*i)->input_streams() != c) {
2005 c = (*i)->output_streams();
2017 __attribute__((annotate("realtime")))
2020 Route::apply_processor_order (const ProcessorList& new_order)
2022 /* need to hold processor_lock; either read or write lock
2023 * and the engine process_lock.
2024 * Due to r/w lock ambiguity we can only assert the latter
2026 assert (!AudioEngine::instance()->process_lock().trylock());
2029 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2030 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2031 * processors in the current actual processor list that are hidden. Any visible processors
2032 * in the current list but not in "new_order" will be assumed to be deleted.
2035 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2036 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2037 * (note though that ::processors_reorder_needs_configure() ensured that
2038 * this function will only ever be called from the rt-thread if no processor were removed)
2040 * either way, I can't proove it, but an x-run due to re-order here is less likley
2041 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2044 ProcessorList as_it_will_be;
2045 ProcessorList::iterator oiter;
2046 ProcessorList::const_iterator niter;
2048 oiter = _processors.begin();
2049 niter = new_order.begin();
2051 while (niter != new_order.end()) {
2053 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2054 then append it to the temp list.
2056 Otherwise, see if the next processor in the old list is in the new list. if not,
2057 its been deleted. If its there, append it to the temp list.
2060 if (oiter == _processors.end()) {
2062 /* no more elements in the old list, so just stick the rest of
2063 the new order onto the temp list.
2066 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2067 while (niter != new_order.end()) {
2074 if (!(*oiter)->display_to_user()) {
2076 as_it_will_be.push_back (*oiter);
2080 /* visible processor: check that its in the new order */
2082 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2083 /* deleted: do nothing, shared_ptr<> will clean up */
2085 /* ignore this one, and add the next item from the new order instead */
2086 as_it_will_be.push_back (*niter);
2091 /* now remove from old order - its taken care of no matter what */
2092 oiter = _processors.erase (oiter);
2096 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2098 /* If the meter is in a custom position, find it and make a rough note of its position */
2099 maybe_note_meter_position ();
2103 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2105 // it a change is already queued, wait for it
2106 // (unless engine is stopped. apply immediately and proceed
2107 while (g_atomic_int_get (&_pending_process_reorder)) {
2108 if (!AudioEngine::instance()->running()) {
2109 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2110 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2112 apply_processor_order(_pending_processor_order);
2113 setup_invisible_processors ();
2115 g_atomic_int_set (&_pending_process_reorder, 0);
2117 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2118 set_processor_positions ();
2120 // TODO rather use a semaphore or something.
2121 // but since ::reorder_processors() is called
2122 // from the GUI thread, this is fine..
2127 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2129 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2130 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2131 ProcessorState pstate (this);
2133 apply_processor_order (new_order);
2135 if (configure_processors_unlocked (err)) {
2143 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2144 set_processor_positions ();
2147 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2148 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2150 // _pending_processor_order is protected by _processor_lock
2151 _pending_processor_order = new_order;
2152 g_atomic_int_set (&_pending_process_reorder, 1);
2165 Route::get_template()
2167 return state(false);
2171 Route::state(bool full_state)
2173 XMLNode *node = new XMLNode("Route");
2174 ProcessorList::iterator i;
2177 id().print (buf, sizeof (buf));
2178 node->add_property("id", buf);
2179 node->add_property ("name", _name);
2180 node->add_property("default-type", _default_type.to_string());
2183 node->add_property("flags", enum_2_string (_flags));
2186 node->add_property("active", _active?"yes":"no");
2188 boost::to_string (_phase_invert, p);
2189 node->add_property("phase-invert", p);
2190 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2191 node->add_property("meter-point", enum_2_string (_meter_point));
2193 node->add_property("meter-type", enum_2_string (_meter_type));
2196 node->add_property("route-group", _route_group->name());
2199 snprintf (buf, sizeof (buf), "%d", _order_key);
2200 node->add_property ("order-key", buf);
2201 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
2202 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
2203 node->add_property ("soloed-by-upstream", buf);
2204 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
2205 node->add_property ("soloed-by-downstream", buf);
2206 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
2207 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
2209 node->add_child_nocopy (_input->state (full_state));
2210 node->add_child_nocopy (_output->state (full_state));
2211 node->add_child_nocopy (_solo_control->get_state ());
2212 node->add_child_nocopy (_mute_control->get_state ());
2213 node->add_child_nocopy (_mute_master->get_state ());
2216 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2219 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2220 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2221 remote_control_node->add_property (X_("id"), buf);
2222 node->add_child_nocopy (*remote_control_node);
2224 if (_comment.length()) {
2225 XMLNode *cmt = node->add_child ("Comment");
2226 cmt->add_content (_comment);
2230 node->add_child_nocopy (_pannable->state (full_state));
2233 for (i = _processors.begin(); i != _processors.end(); ++i) {
2235 /* template save: do not include internal sends functioning as
2236 aux sends because the chance of the target ID
2237 in the session where this template is used
2240 similarly, do not save listen sends which connect to
2241 the monitor section, because these will always be
2244 boost::shared_ptr<InternalSend> is;
2246 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2247 if (is->role() == Delivery::Listen) {
2252 node->add_child_nocopy((*i)->state (full_state));
2256 node->add_child_copy (*_extra_xml);
2259 if (_custom_meter_position_noted) {
2260 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2262 after->id().print (buf, sizeof (buf));
2263 node->add_property (X_("processor-after-last-custom-meter"), buf);
2271 Route::set_state (const XMLNode& node, int version)
2273 if (version < 3000) {
2274 return set_state_2X (node, version);
2278 XMLNodeConstIterator niter;
2280 const XMLProperty *prop;
2282 if (node.name() != "Route"){
2283 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2287 if ((prop = node.property (X_("name"))) != 0) {
2288 Route::set_name (prop->value());
2292 _initial_io_setup = true;
2294 if ((prop = node.property (X_("flags"))) != 0) {
2295 _flags = Flag (string_2_enum (prop->value(), _flags));
2300 if (is_master() || is_monitor() || is_auditioner()) {
2301 _mute_master->set_solo_ignore (true);
2305 /* monitor bus does not get a panner, but if (re)created
2306 via XML, it will already have one by the time we
2307 call ::set_state(). so ... remove it.
2312 /* add all processors (except amp, which is always present) */
2314 nlist = node.children();
2315 XMLNode processor_state (X_("processor_state"));
2317 Stateful::save_extra_xml (node);
2319 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2323 if (child->name() == IO::state_node_name) {
2324 if ((prop = child->property (X_("direction"))) == 0) {
2328 if (prop->value() == "Input") {
2329 _input->set_state (*child, version);
2330 } else if (prop->value() == "Output") {
2331 _output->set_state (*child, version);
2335 if (child->name() == X_("Processor")) {
2336 processor_state.add_child_copy (*child);
2339 if (child->name() == X_("Pannable")) {
2341 _pannable->set_state (*child, version);
2343 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2348 if ((prop = node.property (X_("meter-point"))) != 0) {
2349 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2350 set_meter_point (mp, true);
2352 _meter->set_display_to_user (_meter_point == MeterCustom);
2356 if ((prop = node.property (X_("meter-type"))) != 0) {
2357 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2360 _initial_io_setup = false;
2362 set_processor_state (processor_state);
2364 // this looks up the internal instrument in processors
2365 reset_instrument_info();
2367 if ((prop = node.property ("self-solo")) != 0) {
2368 set_self_solo (string_is_affirmative (prop->value()));
2371 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2372 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2373 mod_solo_by_others_upstream (atoi (prop->value()));
2376 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2377 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2378 mod_solo_by_others_downstream (atoi (prop->value()));
2381 if ((prop = node.property ("solo-isolated")) != 0) {
2382 set_solo_isolated (string_is_affirmative (prop->value()), this);
2385 if ((prop = node.property ("solo-safe")) != 0) {
2386 set_solo_safe (string_is_affirmative (prop->value()), this);
2389 if ((prop = node.property (X_("phase-invert"))) != 0) {
2390 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2393 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2394 set_denormal_protection (string_is_affirmative (prop->value()));
2397 if ((prop = node.property (X_("active"))) != 0) {
2398 bool yn = string_is_affirmative (prop->value());
2399 _active = !yn; // force switch
2400 set_active (yn, this);
2403 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2404 set_order_key (atoi(prop->value()));
2407 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2411 string::size_type colon, equal;
2412 string remaining = prop->value();
2414 while (remaining.length()) {
2416 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2417 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2420 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2421 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2424 string keyname = remaining.substr (0, equal);
2426 if ((keyname == "EditorSort") || (keyname == "editor")) {
2427 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2433 colon = remaining.find_first_of (':');
2435 if (colon != string::npos) {
2436 remaining = remaining.substr (colon+1);
2443 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2444 PBD::ID id (prop->value ());
2445 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2446 ProcessorList::const_iterator i = _processors.begin ();
2447 while (i != _processors.end() && (*i)->id() != id) {
2451 if (i != _processors.end ()) {
2452 _processor_after_last_custom_meter = *i;
2453 _custom_meter_position_noted = true;
2457 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2460 if (child->name() == X_("Comment")) {
2462 /* XXX this is a terrible API design in libxml++ */
2464 XMLNode *cmt = *(child->children().begin());
2465 _comment = cmt->content();
2467 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2468 if (prop->value() == "solo") {
2469 _solo_control->set_state (*child, version);
2470 } else if (prop->value() == "mute") {
2471 _mute_control->set_state (*child, version);
2474 } else if (child->name() == X_("RemoteControl")) {
2475 if ((prop = child->property (X_("id"))) != 0) {
2477 sscanf (prop->value().c_str(), "%d", &x);
2478 set_remote_control_id_internal (x);
2481 } else if (child->name() == X_("MuteMaster")) {
2482 _mute_master->set_state (*child, version);
2484 } else if (child->name() == Automatable::xml_node_name) {
2485 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2493 Route::set_state_2X (const XMLNode& node, int version)
2495 LocaleGuard lg (X_("C"));
2497 XMLNodeConstIterator niter;
2499 const XMLProperty *prop;
2501 /* 2X things which still remain to be handled:
2507 if (node.name() != "Route") {
2508 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2512 if ((prop = node.property (X_("flags"))) != 0) {
2513 string f = prop->value ();
2514 boost::replace_all (f, "ControlOut", "MonitorOut");
2515 _flags = Flag (string_2_enum (f, _flags));
2520 if (is_master() || is_monitor() || is_auditioner()) {
2521 _mute_master->set_solo_ignore (true);
2524 if ((prop = node.property (X_("phase-invert"))) != 0) {
2525 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2526 if (string_is_affirmative (prop->value ())) {
2529 set_phase_invert (p);
2532 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2533 set_denormal_protection (string_is_affirmative (prop->value()));
2536 if ((prop = node.property (X_("soloed"))) != 0) {
2537 bool yn = string_is_affirmative (prop->value());
2539 /* XXX force reset of solo status */
2541 set_solo (yn, this);
2544 if ((prop = node.property (X_("muted"))) != 0) {
2547 bool muted = string_is_affirmative (prop->value());
2553 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2555 if (string_is_affirmative (prop->value())){
2556 mute_point = mute_point + "PreFader";
2561 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2563 if (string_is_affirmative (prop->value())){
2566 mute_point = mute_point + ",";
2569 mute_point = mute_point + "PostFader";
2574 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2576 if (string_is_affirmative (prop->value())){
2579 mute_point = mute_point + ",";
2582 mute_point = mute_point + "Listen";
2587 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2589 if (string_is_affirmative (prop->value())){
2592 mute_point = mute_point + ",";
2595 mute_point = mute_point + "Main";
2599 _mute_master->set_mute_points (mute_point);
2600 _mute_master->set_muted_by_self (true);
2604 if ((prop = node.property (X_("meter-point"))) != 0) {
2605 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2608 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2609 don't mean the same thing.
2612 if ((prop = node.property (X_("order-keys"))) != 0) {
2616 string::size_type colon, equal;
2617 string remaining = prop->value();
2619 while (remaining.length()) {
2621 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2622 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2625 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2626 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2629 string keyname = remaining.substr (0, equal);
2631 if (keyname == "EditorSort" || keyname == "editor") {
2632 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2638 colon = remaining.find_first_of (':');
2640 if (colon != string::npos) {
2641 remaining = remaining.substr (colon+1);
2650 nlist = node.children ();
2651 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2655 if (child->name() == IO::state_node_name) {
2657 /* there is a note in IO::set_state_2X() about why we have to call
2661 _input->set_state_2X (*child, version, true);
2662 _output->set_state_2X (*child, version, false);
2664 if ((prop = child->property (X_("name"))) != 0) {
2665 Route::set_name (prop->value ());
2670 if ((prop = child->property (X_("active"))) != 0) {
2671 bool yn = string_is_affirmative (prop->value());
2672 _active = !yn; // force switch
2673 set_active (yn, this);
2676 if ((prop = child->property (X_("gain"))) != 0) {
2679 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2680 _amp->gain_control()->set_value (val);
2684 /* Set up Panners in the IO */
2685 XMLNodeList io_nlist = child->children ();
2687 XMLNodeConstIterator io_niter;
2690 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2692 io_child = *io_niter;
2694 if (io_child->name() == X_("Panner")) {
2695 _main_outs->panner_shell()->set_state(*io_child, version);
2696 } else if (io_child->name() == X_("Automation")) {
2697 /* IO's automation is for the fader */
2698 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2704 XMLNodeList redirect_nodes;
2706 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2710 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2711 redirect_nodes.push_back(child);
2716 set_processor_state_2X (redirect_nodes, version);
2718 Stateful::save_extra_xml (node);
2720 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2723 if (child->name() == X_("Comment")) {
2725 /* XXX this is a terrible API design in libxml++ */
2727 XMLNode *cmt = *(child->children().begin());
2728 _comment = cmt->content();
2730 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2731 if (prop->value() == X_("solo")) {
2732 _solo_control->set_state (*child, version);
2733 } else if (prop->value() == X_("mute")) {
2734 _mute_control->set_state (*child, version);
2737 } else if (child->name() == X_("RemoteControl")) {
2738 if ((prop = child->property (X_("id"))) != 0) {
2740 sscanf (prop->value().c_str(), "%d", &x);
2741 set_remote_control_id_internal (x);
2751 Route::get_processor_state ()
2753 XMLNode* root = new XMLNode (X_("redirects"));
2754 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2755 root->add_child_nocopy ((*i)->state (true));
2762 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2764 /* We don't bother removing existing processors not in nList, as this
2765 method will only be called when creating a Route from scratch, not
2766 for undo purposes. Just put processors in at the appropriate place
2770 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2771 add_processor_from_xml_2X (**i, version);
2776 Route::set_processor_state (const XMLNode& node)
2778 const XMLNodeList &nlist = node.children();
2779 XMLNodeConstIterator niter;
2780 ProcessorList new_order;
2781 bool must_configure = false;
2783 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2785 XMLProperty* prop = (*niter)->property ("type");
2787 if (prop->value() == "amp") {
2788 _amp->set_state (**niter, Stateful::current_state_version);
2789 new_order.push_back (_amp);
2790 } else if (prop->value() == "trim") {
2791 _trim->set_state (**niter, Stateful::current_state_version);
2792 new_order.push_back (_trim);
2793 } else if (prop->value() == "meter") {
2794 _meter->set_state (**niter, Stateful::current_state_version);
2795 new_order.push_back (_meter);
2796 } else if (prop->value() == "delay") {
2798 _delayline->set_state (**niter, Stateful::current_state_version);
2799 new_order.push_back (_delayline);
2801 } else if (prop->value() == "main-outs") {
2802 _main_outs->set_state (**niter, Stateful::current_state_version);
2803 } else if (prop->value() == "intreturn") {
2805 _intreturn.reset (new InternalReturn (_session));
2806 must_configure = true;
2808 _intreturn->set_state (**niter, Stateful::current_state_version);
2809 } else if (is_monitor() && prop->value() == "monitor") {
2810 if (!_monitor_control) {
2811 _monitor_control.reset (new MonitorProcessor (_session));
2812 must_configure = true;
2814 _monitor_control->set_state (**niter, Stateful::current_state_version);
2815 } else if (prop->value() == "capture") {
2816 /* CapturingProcessor should never be restored, it's always
2817 added explicitly when needed */
2819 ProcessorList::iterator o;
2821 for (o = _processors.begin(); o != _processors.end(); ++o) {
2822 XMLProperty* id_prop = (*niter)->property(X_("id"));
2823 if (id_prop && (*o)->id() == id_prop->value()) {
2824 (*o)->set_state (**niter, Stateful::current_state_version);
2825 new_order.push_back (*o);
2830 // If the processor (*niter) is not on the route then create it
2832 if (o == _processors.end()) {
2834 boost::shared_ptr<Processor> processor;
2836 if (prop->value() == "intsend") {
2838 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2840 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2841 prop->value() == "lv2" ||
2842 prop->value() == "windows-vst" ||
2843 prop->value() == "lxvst" ||
2844 prop->value() == "audiounit") {
2846 processor.reset (new PluginInsert(_session));
2848 } else if (prop->value() == "port") {
2850 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2852 } else if (prop->value() == "send") {
2854 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2857 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2861 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2862 /* This processor could not be configured. Turn it into a UnknownProcessor */
2863 processor.reset (new UnknownProcessor (_session, **niter));
2866 /* we have to note the monitor send here, otherwise a new one will be created
2867 and the state of this one will be lost.
2869 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2870 if (isend && isend->role() == Delivery::Listen) {
2871 _monitor_send = isend;
2874 /* it doesn't matter if invisible processors are added here, as they
2875 will be sorted out by setup_invisible_processors () shortly.
2878 new_order.push_back (processor);
2879 must_configure = true;
2885 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2886 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2887 _processors = new_order;
2889 if (must_configure) {
2890 configure_processors_unlocked (0);
2893 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2895 (*i)->set_owner (this);
2896 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2898 boost::shared_ptr<PluginInsert> pi;
2900 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2901 if (pi->has_no_inputs ()) {
2902 _have_internal_generator = true;
2909 reset_instrument_info ();
2910 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2911 set_processor_positions ();
2915 Route::curve_reallocate ()
2917 // _gain_automation_curve.finish_resize ();
2918 // _pan_automation_curve.finish_resize ();
2922 Route::silence (framecnt_t nframes)
2924 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2929 silence_unlocked (nframes);
2933 Route::silence_unlocked (framecnt_t nframes)
2935 /* Must be called with the processor lock held */
2939 _output->silence (nframes);
2941 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2942 boost::shared_ptr<PluginInsert> pi;
2944 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2945 // skip plugins, they don't need anything when we're not active
2949 (*i)->silence (nframes);
2952 if (nframes == _session.get_block_size()) {
2959 Route::add_internal_return ()
2962 _intreturn.reset (new InternalReturn (_session));
2963 add_processor (_intreturn, PreFader);
2968 Route::add_send_to_internal_return (InternalSend* send)
2970 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2972 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2973 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2976 return d->add_send (send);
2982 Route::remove_send_from_internal_return (InternalSend* send)
2984 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2986 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2987 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2990 return d->remove_send (send);
2996 Route::enable_monitor_send ()
2998 /* Caller must hold process lock */
2999 assert (!AudioEngine::instance()->process_lock().trylock());
3001 /* master never sends to monitor section via the normal mechanism */
3002 assert (!is_master ());
3003 assert (!is_monitor ());
3005 /* make sure we have one */
3006 if (!_monitor_send) {
3007 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3008 _monitor_send->set_display_to_user (false);
3012 configure_processors (0);
3015 /** Add an aux send to a route.
3016 * @param route route to send to.
3017 * @param before Processor to insert before, or 0 to insert at the end.
3020 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3022 assert (route != _session.monitor_out ());
3025 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3027 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3029 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3031 if (d && d->target_route() == route) {
3032 /* already listening via the specified IO: do nothing */
3040 boost::shared_ptr<InternalSend> listener;
3043 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3044 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3045 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3048 add_processor (listener, before);
3050 } catch (failed_constructor& err) {
3058 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3060 ProcessorStreams err;
3061 ProcessorList::iterator tmp;
3064 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3066 /* have to do this early because otherwise processor reconfig
3067 * will put _monitor_send back in the list
3070 if (route == _session.monitor_out()) {
3071 _monitor_send.reset ();
3075 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3077 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3079 if (d && d->target_route() == route) {
3081 remove_processor (*x, &err, false);
3084 /* list could have been demolished while we dropped the lock
3095 Route::set_comment (string cmt, void *src)
3098 comment_changed (src);
3099 _session.set_dirty ();
3103 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3105 FeedRecord fr (other, via_sends_only);
3107 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3109 if (!result.second) {
3111 /* already a record for "other" - make sure sends-only information is correct */
3112 if (!via_sends_only && result.first->sends_only) {
3113 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3114 frp->sends_only = false;
3118 return result.second;
3122 Route::clear_fed_by ()
3128 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3130 const FedBy& fed_by (other->fed_by());
3132 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3133 boost::shared_ptr<Route> sr = f->r.lock();
3135 if (sr && (sr.get() == this)) {
3137 if (via_sends_only) {
3138 *via_sends_only = f->sends_only;
3149 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3151 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3153 if (_output->connected_to (other->input())) {
3154 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3155 if (via_send_only) {
3156 *via_send_only = false;
3163 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3165 boost::shared_ptr<IOProcessor> iop;
3167 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
3168 if (iop->feeds (other)) {
3169 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3170 if (via_send_only) {
3171 *via_send_only = true;
3175 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3178 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3183 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3188 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3190 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3193 /** Called from the (non-realtime) butler thread when the transport is stopped */
3195 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3197 framepos_t now = _session.transport_frame();
3200 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3202 Automatable::transport_stopped (now);
3204 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3206 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3210 (*i)->transport_stopped (now);
3214 _roll_delay = _initial_delay;
3218 Route::input_change_handler (IOChange change, void * /*src*/)
3220 bool need_to_queue_solo_change = true;
3222 if ((change.type & IOChange::ConfigurationChanged)) {
3223 /* This is called with the process lock held if change
3224 contains ConfigurationChanged
3226 need_to_queue_solo_change = false;
3227 configure_processors (0);
3228 _phase_invert.resize (_input->n_ports().n_audio ());
3229 io_changed (); /* EMIT SIGNAL */
3232 if (!_input->connected() && _soloed_by_others_upstream) {
3233 if (need_to_queue_solo_change) {
3234 _session.cancel_solo_after_disconnect (shared_from_this(), true);
3236 cancel_solo_after_disconnect (true);
3242 Route::output_change_handler (IOChange change, void * /*src*/)
3244 bool need_to_queue_solo_change = true;
3245 if (_initial_io_setup) {
3249 if ((change.type & IOChange::ConfigurationChanged)) {
3250 /* This is called with the process lock held if change
3251 contains ConfigurationChanged
3253 need_to_queue_solo_change = false;
3254 configure_processors (0);
3257 _session.reset_monitor_section();
3260 io_changed (); /* EMIT SIGNAL */
3263 if (!_output->connected() && _soloed_by_others_downstream) {
3264 if (need_to_queue_solo_change) {
3265 _session.cancel_solo_after_disconnect (shared_from_this(), false);
3267 cancel_solo_after_disconnect (false);
3273 Route::cancel_solo_after_disconnect (bool upstream)
3276 _soloed_by_others_upstream = 0;
3278 _soloed_by_others_downstream = 0;
3280 set_mute_master_solo ();
3281 solo_changed (false, this);
3285 Route::pans_required () const
3287 if (n_outputs().n_audio() < 2) {
3291 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3295 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3297 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3303 if (n_outputs().n_total() == 0) {
3307 if (!_active || n_inputs() == ChanCount::ZERO) {
3308 silence_unlocked (nframes);
3312 if (session_state_changing) {
3313 if (_session.transport_speed() != 0.0f) {
3314 /* we're rolling but some state is changing (e.g. our diskstream contents)
3315 so we cannot use them. Be silent till this is over.
3317 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3319 silence_unlocked (nframes);
3322 /* we're really not rolling, so we're either delivery silence or actually
3323 monitoring, both of which are safe to do while session_state_changing is true.
3327 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3329 fill_buffers_with_input (bufs, _input, nframes);
3331 if (_meter_point == MeterInput) {
3332 _meter->run (bufs, start_frame, end_frame, nframes, true);
3335 _amp->apply_gain_automation (false);
3336 _trim->apply_gain_automation (false);
3337 passthru (bufs, start_frame, end_frame, nframes, 0);
3343 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3345 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3350 if (n_outputs().n_total() == 0) {
3354 if (!_active || n_inputs().n_total() == 0) {
3355 silence_unlocked (nframes);
3359 framepos_t unused = 0;
3361 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3367 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3369 fill_buffers_with_input (bufs, _input, nframes);
3371 if (_meter_point == MeterInput) {
3372 _meter->run (bufs, start_frame, end_frame, nframes, true);
3375 passthru (bufs, start_frame, end_frame, nframes, declick);
3381 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3388 Route::flush_processors ()
3390 /* XXX shouldn't really try to take this lock, since
3391 this is called from the RT audio thread.
3394 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3396 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3402 __attribute__((annotate("realtime")))
3405 Route::apply_processor_changes_rt ()
3407 int emissions = EmitNone;
3409 if (_pending_meter_point != _meter_point) {
3410 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3412 /* meters always have buffers for 'processor_max_streams'
3413 * they can be re-positioned without re-allocation */
3414 if (set_meter_point_unlocked()) {
3415 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3417 emissions |= EmitMeterChanged;
3422 bool changed = false;
3424 if (g_atomic_int_get (&_pending_process_reorder)) {
3425 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3427 apply_processor_order (_pending_processor_order);
3428 setup_invisible_processors ();
3430 g_atomic_int_set (&_pending_process_reorder, 0);
3431 emissions |= EmitRtProcessorChange;
3435 set_processor_positions ();
3437 if (emissions != 0) {
3438 g_atomic_int_set (&_pending_signals, emissions);
3445 Route::emit_pending_signals ()
3448 int sig = g_atomic_int_and (&_pending_signals, 0);
3449 if (sig & EmitMeterChanged) {
3450 _meter->emit_configuration_changed();
3451 meter_change (); /* EMIT SIGNAL */
3452 if (sig & EmitMeterVisibilityChange) {
3453 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3455 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3458 if (sig & EmitRtProcessorChange) {
3459 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3464 Route::set_meter_point (MeterPoint p, bool force)
3466 if (_pending_meter_point == p && !force) {
3470 if (force || !AudioEngine::instance()->running()) {
3471 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3472 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3473 _pending_meter_point = p;
3474 _meter->emit_configuration_changed();
3475 meter_change (); /* EMIT SIGNAL */
3476 if (set_meter_point_unlocked()) {
3477 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3479 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3482 _pending_meter_point = p;
3488 __attribute__((annotate("realtime")))
3491 Route::set_meter_point_unlocked ()
3494 /* Caller must hold process and processor write lock */
3495 assert (!AudioEngine::instance()->process_lock().trylock());
3496 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3497 assert (!lm.locked ());
3500 _meter_point = _pending_meter_point;
3502 bool meter_was_visible_to_user = _meter->display_to_user ();
3504 if (!_custom_meter_position_noted) {
3505 maybe_note_meter_position ();
3508 if (_meter_point != MeterCustom) {
3510 _meter->set_display_to_user (false);
3512 setup_invisible_processors ();
3515 _meter->set_display_to_user (true);
3517 /* If we have a previous position for the custom meter, try to put it there */
3518 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3520 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3521 if (i != _processors.end ()) {
3522 _processors.remove (_meter);
3523 _processors.insert (i, _meter);
3525 } else {// at end, right before the mains_out/panner
3526 _processors.remove (_meter);
3527 ProcessorList::iterator main = _processors.end();
3528 _processors.insert (--main, _meter);
3532 /* Set up the meter for its new position */
3534 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3538 if (loc == _processors.begin()) {
3539 m_in = _input->n_ports();
3541 ProcessorList::iterator before = loc;
3543 m_in = (*before)->output_streams ();
3546 _meter->reflect_inputs (m_in);
3548 /* we do not need to reconfigure the processors, because the meter
3549 (a) is always ready to handle processor_max_streams
3550 (b) is always an N-in/N-out processor, and thus moving
3551 it doesn't require any changes to the other processors.
3554 /* these should really be done after releasing the lock
3555 * but all those signals are subscribed to with gui_thread()
3558 return (_meter->display_to_user() != meter_was_visible_to_user);
3562 Route::listen_position_changed ()
3565 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3566 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3567 ProcessorState pstate (this);
3569 if (configure_processors_unlocked (0)) {
3571 configure_processors_unlocked (0); // it worked before we tried to add it ...
3576 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3577 _session.set_dirty ();
3580 boost::shared_ptr<CapturingProcessor>
3581 Route::add_export_point()
3583 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3584 if (!_capturing_processor) {
3586 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3587 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3589 _capturing_processor.reset (new CapturingProcessor (_session));
3590 _capturing_processor->activate ();
3592 configure_processors_unlocked (0);
3596 return _capturing_processor;
3600 Route::update_signal_latency ()
3602 framecnt_t l = _output->user_latency();
3603 framecnt_t lamp = 0;
3604 bool before_amp = true;
3605 framecnt_t ltrim = 0;
3606 bool before_trim = true;
3608 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3609 if ((*i)->active ()) {
3610 l += (*i)->signal_latency ();
3615 if ((*i) == _trim) {
3626 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3628 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3629 _signal_latency_at_amp_position = lamp;
3630 _signal_latency_at_trim_position = ltrim;
3632 if (_signal_latency != l) {
3633 _signal_latency = l;
3634 signal_latency_changed (); /* EMIT SIGNAL */
3637 return _signal_latency;
3641 Route::set_user_latency (framecnt_t nframes)
3643 _output->set_user_latency (nframes);
3644 _session.update_latency_compensation ();
3648 Route::set_latency_compensation (framecnt_t longest_session_latency)
3650 framecnt_t old = _initial_delay;
3652 if (_signal_latency < longest_session_latency) {
3653 _initial_delay = longest_session_latency - _signal_latency;
3658 DEBUG_TRACE (DEBUG::Latency, string_compose (
3659 "%1: compensate for maximum latency of %2,"
3660 "given own latency of %3, using initial delay of %4\n",
3661 name(), longest_session_latency, _signal_latency, _initial_delay));
3663 if (_initial_delay != old) {
3664 initial_delay_changed (); /* EMIT SIGNAL */
3667 if (_session.transport_stopped()) {
3668 _roll_delay = _initial_delay;
3672 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3673 : AutomationControl (r->session(),
3674 Evoral::Parameter (SoloAutomation),
3675 ParameterDescriptor(Evoral::Parameter (SoloAutomation)),
3676 boost::shared_ptr<AutomationList>(), name)
3679 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3680 gl->set_interpolation(Evoral::ControlList::Discrete);
3685 Route::SoloControllable::set_value (double val)
3687 const bool bval = ((val >= 0.5) ? true : false);
3689 boost::shared_ptr<RouteList> rl (new RouteList);
3691 boost::shared_ptr<Route> r = _route.lock ();
3698 if (Config->get_solo_control_is_listen_control()) {
3699 _session.set_listen (rl, bval);
3701 _session.set_solo (rl, bval);
3706 Route::SoloControllable::get_value () const
3708 boost::shared_ptr<Route> r = _route.lock ();
3713 if (Config->get_solo_control_is_listen_control()) {
3714 return r->listening_via_monitor() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3716 return r->self_soloed() ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3720 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3721 : AutomationControl (r->session(),
3722 Evoral::Parameter (MuteAutomation),
3723 ParameterDescriptor (Evoral::Parameter (MuteAutomation)),
3724 boost::shared_ptr<AutomationList>(),
3728 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3729 gl->set_interpolation(Evoral::ControlList::Discrete);
3734 Route::MuteControllable::set_superficial_value(bool muted)
3736 /* Note we can not use AutomationControl::set_value here since it will emit
3737 Changed(), but the value will not be correct to the observer. */
3739 bool to_list = _list && ((AutomationList*)_list.get())->automation_write();
3741 Control::set_double (muted, _session.transport_frame(), to_list);
3745 Route::MuteControllable::set_value (double val)
3747 const bool bval = ((val >= 0.5) ? true : false);
3749 boost::shared_ptr<Route> r = _route.lock ();
3754 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3755 // Playing back automation, set route mute directly
3756 r->set_mute (bval, this);
3758 // Set from user, queue mute event
3759 boost::shared_ptr<RouteList> rl (new RouteList);
3761 _session.set_mute (rl, bval, Session::rt_cleanup);
3764 // Set superficial/automation value to drive controller (and possibly record)
3765 set_superficial_value(bval);
3769 Route::MuteControllable::get_value () const
3771 if (_list && ((AutomationList*)_list.get())->automation_playback()) {
3772 // Playing back automation, get the value from the list
3773 return AutomationControl::get_value();
3776 // Not playing back automation, get the actual route mute value
3777 boost::shared_ptr<Route> r = _route.lock ();
3778 return (r && r->muted()) ? GAIN_COEFF_UNITY : GAIN_COEFF_ZERO;
3782 Route::set_block_size (pframes_t nframes)
3784 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3785 (*i)->set_block_size (nframes);
3788 _session.ensure_buffers (n_process_buffers ());
3792 Route::protect_automation ()
3794 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3795 (*i)->protect_automation();
3798 /** @param declick 1 to set a pending declick fade-in,
3799 * -1 to set a pending declick fade-out
3802 Route::set_pending_declick (int declick)
3805 /* this call is not allowed to turn off a pending declick */
3807 _pending_declick = declick;
3810 _pending_declick = 0;
3814 /** Shift automation forwards from a particular place, thereby inserting time.
3815 * Adds undo commands for any shifts that are performed.
3817 * @param pos Position to start shifting from.
3818 * @param frames Amount to shift forwards by.
3822 Route::shift (framepos_t pos, framecnt_t frames)
3824 /* gain automation */
3826 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3828 XMLNode &before = gc->alist()->get_state ();
3829 gc->alist()->shift (pos, frames);
3830 XMLNode &after = gc->alist()->get_state ();
3831 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3834 /* gain automation */
3836 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3838 XMLNode &before = gc->alist()->get_state ();
3839 gc->alist()->shift (pos, frames);
3840 XMLNode &after = gc->alist()->get_state ();
3841 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3844 // TODO mute automation ??
3846 /* pan automation */
3848 ControlSet::Controls& c (_pannable->controls());
3850 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3851 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3853 boost::shared_ptr<AutomationList> al = pc->alist();
3854 XMLNode& before = al->get_state ();
3855 al->shift (pos, frames);
3856 XMLNode& after = al->get_state ();
3857 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3862 /* redirect automation */
3864 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3865 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3867 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3869 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3870 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3872 boost::shared_ptr<AutomationList> al = ac->alist();
3873 XMLNode &before = al->get_state ();
3874 al->shift (pos, frames);
3875 XMLNode &after = al->get_state ();
3876 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3885 Route::save_as_template (const string& path, const string& name)
3887 XMLNode& node (state (false));
3890 IO::set_name_in_state (*node.children().front(), name);
3892 tree.set_root (&node);
3893 return tree.write (path.c_str());
3898 Route::set_name (const string& str)
3900 if (str == name()) {
3904 string name = Route::ensure_track_or_route_name (str, _session);
3905 SessionObject::set_name (name);
3907 bool ret = (_input->set_name(name) && _output->set_name(name));
3910 /* rename the main outs. Leave other IO processors
3911 * with whatever name they already have, because its
3912 * just fine as it is (it will not contain the route
3913 * name if its a port insert, port send or port return).
3917 if (_main_outs->set_name (name)) {
3918 /* XXX returning false here is stupid because
3919 we already changed the route name.
3929 /** Set the name of a route in an XML description.
3930 * @param node XML <Route> node to set the name in.
3931 * @param name New name.
3934 Route::set_name_in_state (XMLNode& node, string const & name)
3936 node.add_property (X_("name"), name);
3938 XMLNodeList children = node.children();
3939 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3941 if ((*i)->name() == X_("IO")) {
3943 IO::set_name_in_state (**i, name);
3945 } else if ((*i)->name() == X_("Processor")) {
3947 XMLProperty* role = (*i)->property (X_("role"));
3948 if (role && role->value() == X_("Main")) {
3949 (*i)->add_property (X_("name"), name);
3952 } else if ((*i)->name() == X_("Diskstream")) {
3954 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3955 (*i)->add_property (X_("name"), name);
3961 boost::shared_ptr<Send>
3962 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3964 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3966 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3967 boost::shared_ptr<InternalSend> send;
3969 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3970 if (send->target_route() == target) {
3976 return boost::shared_ptr<Send>();
3979 /** @param c Audio channel index.
3980 * @param yn true to invert phase, otherwise false.
3983 Route::set_phase_invert (uint32_t c, bool yn)
3985 if (_phase_invert[c] != yn) {
3986 _phase_invert[c] = yn;
3987 phase_invert_changed (); /* EMIT SIGNAL */
3988 _session.set_dirty ();
3993 Route::set_phase_invert (boost::dynamic_bitset<> p)
3995 if (_phase_invert != p) {
3997 phase_invert_changed (); /* EMIT SIGNAL */
3998 _session.set_dirty ();
4003 Route::phase_invert (uint32_t c) const
4005 return _phase_invert[c];
4008 boost::dynamic_bitset<>
4009 Route::phase_invert () const
4011 return _phase_invert;
4015 Route::set_denormal_protection (bool yn)
4017 if (_denormal_protection != yn) {
4018 _denormal_protection = yn;
4019 denormal_protection_changed (); /* EMIT SIGNAL */
4024 Route::denormal_protection () const
4026 return _denormal_protection;
4030 Route::set_active (bool yn, void* src)
4032 if (_session.transport_rolling()) {
4036 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4037 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4041 if (_active != yn) {
4043 _input->set_active (yn);
4044 _output->set_active (yn);
4045 active_changed (); // EMIT SIGNAL
4046 _session.set_dirty ();
4050 boost::shared_ptr<Pannable>
4051 Route::pannable() const
4056 boost::shared_ptr<Panner>
4057 Route::panner() const
4060 return _main_outs->panner_shell()->panner();
4063 boost::shared_ptr<PannerShell>
4064 Route::panner_shell() const
4066 return _main_outs->panner_shell();
4069 boost::shared_ptr<AutomationControl>
4070 Route::gain_control() const
4072 return _amp->gain_control();
4075 boost::shared_ptr<AutomationControl>
4076 Route::get_control (const Evoral::Parameter& param)
4078 /* either we own the control or .... */
4080 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4084 /* maybe one of our processors does or ... */
4086 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4087 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4088 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4096 /* nobody does so we'll make a new one */
4098 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4105 boost::shared_ptr<Processor>
4106 Route::nth_plugin (uint32_t n)
4108 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4109 ProcessorList::iterator i;
4111 for (i = _processors.begin(); i != _processors.end(); ++i) {
4112 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4119 return boost::shared_ptr<Processor> ();
4122 boost::shared_ptr<Processor>
4123 Route::nth_send (uint32_t n)
4125 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4126 ProcessorList::iterator i;
4128 for (i = _processors.begin(); i != _processors.end(); ++i) {
4129 if (boost::dynamic_pointer_cast<Send> (*i)) {
4136 return boost::shared_ptr<Processor> ();
4140 Route::has_io_processor_named (const string& name)
4142 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4143 ProcessorList::iterator i;
4145 for (i = _processors.begin(); i != _processors.end(); ++i) {
4146 if (boost::dynamic_pointer_cast<Send> (*i) ||
4147 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4148 if ((*i)->name() == name) {
4157 MuteMaster::MutePoint
4158 Route::mute_points () const
4160 return _mute_master->mute_points ();
4164 Route::set_processor_positions ()
4166 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4168 bool had_amp = false;
4169 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4170 (*i)->set_pre_fader (!had_amp);
4177 /** Called when there is a proposed change to the input port count */
4179 Route::input_port_count_changing (ChanCount to)
4181 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4183 /* The processors cannot be configured with the new input arrangement, so
4189 /* The change is ok */
4193 /** Called when there is a proposed change to the output port count */
4195 Route::output_port_count_changing (ChanCount to)
4197 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4198 if (processor_out_streams.get(*t) > to.get(*t)) {
4202 /* The change is ok */
4207 Route::unknown_processors () const
4211 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4212 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4213 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4214 p.push_back ((*i)->name ());
4223 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4225 /* we assume that all our input ports feed all our output ports. its not
4226 universally true, but the alternative is way too corner-case to worry about.
4229 LatencyRange all_connections;
4232 all_connections.min = 0;
4233 all_connections.max = 0;
4235 all_connections.min = ~((pframes_t) 0);
4236 all_connections.max = 0;
4238 /* iterate over all "from" ports and determine the latency range for all of their
4239 connections to the "outside" (outside of this Route).
4242 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4246 p->get_connected_latency_range (range, playback);
4248 all_connections.min = min (all_connections.min, range.min);
4249 all_connections.max = max (all_connections.max, range.max);
4253 /* set the "from" port latencies to the max/min range of all their connections */
4255 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4256 p->set_private_latency_range (all_connections, playback);
4259 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4261 all_connections.min += our_latency;
4262 all_connections.max += our_latency;
4264 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4265 p->set_private_latency_range (all_connections, playback);
4268 return all_connections.max;
4272 Route::set_private_port_latencies (bool playback) const
4274 framecnt_t own_latency = 0;
4276 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4277 OR LATENCY CALLBACK.
4279 This is called (early) from the latency callback. It computes the REAL
4280 latency associated with each port and stores the result as the "private"
4281 latency of the port. A later call to Route::set_public_port_latencies()
4282 sets all ports to the same value to reflect the fact that we do latency
4283 compensation and so all signals are delayed by the same amount as they
4284 flow through ardour.
4287 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4288 if ((*i)->active ()) {
4289 own_latency += (*i)->signal_latency ();
4294 /* playback: propagate latency from "outside the route" to outputs to inputs */
4295 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4297 /* capture: propagate latency from "outside the route" to inputs to outputs */
4298 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4303 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4305 /* this is called to set the JACK-visible port latencies, which take
4306 latency compensation into account.
4315 const PortSet& ports (_input->ports());
4316 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4317 p->set_public_latency_range (range, playback);
4322 const PortSet& ports (_output->ports());
4323 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4324 p->set_public_latency_range (range, playback);
4329 /** Put the invisible processors in the right place in _processors.
4330 * Must be called with a writer lock on _processor_lock held.
4333 __attribute__((annotate("realtime")))
4336 Route::setup_invisible_processors ()
4339 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4340 assert (!lm.locked ());
4344 /* too early to be doing this stuff */
4348 /* we'll build this new list here and then use it
4350 * TODO put the ProcessorList is on the stack for RT-safety.
4353 ProcessorList new_processors;
4355 /* find visible processors */
4357 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4358 if ((*i)->display_to_user ()) {
4359 new_processors.push_back (*i);
4365 ProcessorList::iterator amp = new_processors.begin ();
4366 while (amp != new_processors.end() && *amp != _amp) {
4370 assert (amp != new_processors.end ());
4372 /* and the processor after the amp */
4374 ProcessorList::iterator after_amp = amp;
4380 switch (_meter_point) {
4382 assert (!_meter->display_to_user ());
4383 new_processors.push_front (_meter);
4386 assert (!_meter->display_to_user ());
4387 new_processors.insert (amp, _meter);
4389 case MeterPostFader:
4390 /* do nothing here */
4393 /* do nothing here */
4396 /* the meter is visible, so we don't touch it here */
4403 assert (_main_outs);
4404 assert (!_main_outs->display_to_user ());
4405 new_processors.push_back (_main_outs);
4407 /* iterator for the main outs */
4409 ProcessorList::iterator main = new_processors.end();
4412 /* OUTPUT METERING */
4414 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4415 assert (!_meter->display_to_user ());
4417 /* add the processor just before or just after the main outs */
4419 ProcessorList::iterator meter_point = main;
4421 if (_meter_point == MeterOutput) {
4424 new_processors.insert (meter_point, _meter);
4429 if (_monitor_send && !is_monitor ()) {
4430 assert (!_monitor_send->display_to_user ());
4431 if (Config->get_solo_control_is_listen_control()) {
4432 switch (Config->get_listen_position ()) {
4433 case PreFaderListen:
4434 switch (Config->get_pfl_position ()) {
4435 case PFLFromBeforeProcessors:
4436 new_processors.push_front (_monitor_send);
4438 case PFLFromAfterProcessors:
4439 new_processors.insert (amp, _monitor_send);
4442 _monitor_send->set_can_pan (false);
4444 case AfterFaderListen:
4445 switch (Config->get_afl_position ()) {
4446 case AFLFromBeforeProcessors:
4447 new_processors.insert (after_amp, _monitor_send);
4449 case AFLFromAfterProcessors:
4450 new_processors.insert (new_processors.end(), _monitor_send);
4453 _monitor_send->set_can_pan (true);
4457 new_processors.insert (new_processors.end(), _monitor_send);
4458 _monitor_send->set_can_pan (false);
4462 #if 0 // not used - just yet
4463 if (!is_master() && !is_monitor() && !is_auditioner()) {
4464 new_processors.push_front (_delayline);
4468 /* MONITOR CONTROL */
4470 if (_monitor_control && is_monitor ()) {
4471 assert (!_monitor_control->display_to_user ());
4472 new_processors.push_front (_monitor_control);
4475 /* INTERNAL RETURN */
4477 /* doing this here means that any monitor control will come just after
4482 assert (!_intreturn->display_to_user ());
4483 new_processors.push_front (_intreturn);
4486 if (_trim && _trim->active()) {
4487 assert (!_trim->display_to_user ());
4488 new_processors.push_front (_trim);
4490 /* EXPORT PROCESSOR */
4492 if (_capturing_processor) {
4493 assert (!_capturing_processor->display_to_user ());
4494 new_processors.push_front (_capturing_processor);
4497 _processors = new_processors;
4499 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4500 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4501 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4508 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4509 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4513 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4514 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4521 /** If the meter point is `Custom', make a note of where the meter is.
4522 * This is so that if the meter point is subsequently set to something else,
4523 * and then back to custom, we can put the meter back where it was last time
4524 * custom was enabled.
4526 * Must be called with the _processor_lock held.
4529 Route::maybe_note_meter_position ()
4531 if (_meter_point != MeterCustom) {
4535 _custom_meter_position_noted = true;
4536 /* custom meter points range from after trim to before panner/main_outs
4537 * this is a limitation by the current processor UI
4539 bool seen_trim = false;
4540 _processor_after_last_custom_meter.reset();
4541 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4542 if ((*i) == _trim) {
4545 if ((*i) == _main_outs) {
4546 _processor_after_last_custom_meter = *i;
4549 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4551 _processor_after_last_custom_meter = _trim;
4553 ProcessorList::iterator j = i;
4555 assert(j != _processors.end ()); // main_outs should be before
4556 _processor_after_last_custom_meter = *j;
4561 assert(_processor_after_last_custom_meter.lock());
4564 boost::shared_ptr<Processor>
4565 Route::processor_by_id (PBD::ID id) const
4567 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4568 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4569 if ((*i)->id() == id) {
4574 return boost::shared_ptr<Processor> ();
4577 /** @return the monitoring state, or in other words what data we are pushing
4578 * into the route (data from the inputs, data from disk or silence)
4581 Route::monitoring_state () const
4583 return MonitoringInput;
4586 /** @return what we should be metering; either the data coming from the input
4587 * IO or the data that is flowing through the route.
4590 Route::metering_state () const
4592 return MeteringRoute;
4596 Route::has_external_redirects () const
4598 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4600 /* ignore inactive processors and obviously ignore the main
4601 * outs since everything has them and we don't care.
4604 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4612 boost::shared_ptr<Processor>
4613 Route::the_instrument () const
4615 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4616 return the_instrument_unlocked ();
4619 boost::shared_ptr<Processor>
4620 Route::the_instrument_unlocked () const
4622 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4623 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4624 if ((*i)->input_streams().n_midi() > 0 &&
4625 (*i)->output_streams().n_audio() > 0) {
4630 return boost::shared_ptr<Processor>();
4636 Route::non_realtime_locate (framepos_t pos)
4639 _pannable->transport_located (pos);
4642 if (_delayline.get()) {
4643 _delayline.get()->flush();
4647 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4648 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4650 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4651 (*i)->transport_located (pos);
4657 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4664 * We don't currently mix MIDI input together, so we don't need the
4665 * complex logic of the audio case.
4668 n_buffers = bufs.count().n_midi ();
4670 for (i = 0; i < n_buffers; ++i) {
4672 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4673 MidiBuffer& buf (bufs.get_midi (i));
4676 buf.copy (source_port->get_midi_buffer(nframes));
4678 buf.silence (nframes);
4684 n_buffers = bufs.count().n_audio();
4686 size_t n_ports = io->n_ports().n_audio();
4687 float scaling = 1.0f;
4689 if (n_ports > n_buffers) {
4690 scaling = ((float) n_buffers) / n_ports;
4693 for (i = 0; i < n_ports; ++i) {
4695 /* if there are more ports than buffers, map them onto buffers
4696 * in a round-robin fashion
4699 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4700 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4703 if (i < n_buffers) {
4705 /* first time through just copy a channel into
4709 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4711 if (scaling != 1.0f) {
4712 buf.apply_gain (scaling, nframes);
4717 /* on subsequent times around, merge data from
4718 * the port with what is already there
4721 if (scaling != 1.0f) {
4722 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4724 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4729 /* silence any remaining buffers */
4731 for (; i < n_buffers; ++i) {
4732 AudioBuffer& buf (bufs.get_audio (i));
4733 buf.silence (nframes);
4736 /* establish the initial setup of the buffer set, reflecting what was
4737 copied into it. unless, of course, we are the auditioner, in which
4738 case nothing was fed into it from the inputs at all.
4741 if (!is_auditioner()) {
4742 bufs.set_count (io->n_ports());