2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/unwind.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_track.h"
41 #include "ardour/audio_port.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/boost_debug.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/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/phase_control.h"
62 #include "ardour/plugin_insert.h"
63 #include "ardour/port.h"
64 #include "ardour/port_insert.h"
65 #include "ardour/processor.h"
66 #include "ardour/profile.h"
67 #include "ardour/route.h"
68 #include "ardour/route_group.h"
69 #include "ardour/send.h"
70 #include "ardour/session.h"
71 #include "ardour/solo_control.h"
72 #include "ardour/solo_isolate_control.h"
73 #include "ardour/unknown_processor.h"
74 #include "ardour/utils.h"
75 #include "ardour/vca.h"
80 using namespace ARDOUR;
83 PBD::Signal0<void> Route::SyncOrderKeys;
84 PBD::Signal0<void> Route::RemoteControlIDChange;
85 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
87 /** Base class for all routable/mixable objects (tracks and busses) */
88 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
89 : Stripable (sess, name)
90 , Muteable (sess, name)
92 , GraphNode (sess._process_graph)
95 , _signal_latency_at_amp_position (0)
96 , _signal_latency_at_trim_position (0)
99 , _pending_process_reorder (0)
100 , _pending_signals (0)
102 , _pending_declick (true)
103 , _meter_point (MeterPostFader)
104 , _pending_meter_point (MeterPostFader)
105 , _meter_type (MeterPeak)
106 , _denormal_protection (false)
109 , _declickable (false)
110 , _have_internal_generator (false)
111 , _default_type (default_type)
113 , _has_order_key (false)
114 , _remote_control_id (0)
116 , _in_configure_processors (false)
117 , _initial_io_setup (false)
118 , _in_sidechain_setup (false)
120 , _custom_meter_position_noted (false)
123 processor_max_streams.reset();
129 /* set default meter type */
131 _meter_type = Config->get_meter_type_master ();
133 else if (dynamic_cast<Track*>(this)) {
134 _meter_type = Config->get_meter_type_track ();
136 _meter_type = Config->get_meter_type_bus ();
139 /* add standard controls */
141 _gain_control.reset (new GainControl (_session, GainAutomation));
142 add_control (_gain_control);
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 add_control (_trim_control);
147 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
148 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
149 add_control (_solo_control);
150 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
152 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
153 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
154 add_control (_mute_control);
156 _phase_control.reset (new PhaseControl (_session, X_("phase")));
157 add_control (_phase_control);
159 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
160 add_control (_solo_isolate_control);
162 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
163 add_control (_solo_safe_control);
167 if (!(_flags & Route::MonitorOut)) {
168 _pannable.reset (new Pannable (_session));
171 /* input and output objects */
173 _input.reset (new IO (_session, _name, IO::Input, _default_type));
174 _output.reset (new IO (_session, _name, IO::Output, _default_type));
176 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
177 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
179 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
180 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
182 /* add the amp/fader processor.
183 * it should be the first processor to be added on every route.
186 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
187 add_processor (_amp, PostFader);
190 _amp->set_display_name (_("Monitor"));
193 #if 0 // not used - just yet
194 if (!is_master() && !is_monitor() && !is_auditioner()) {
195 _delayline.reset (new DelayLine (_session, _name));
196 add_processor (_delayline, PreFader);
202 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
203 _trim->set_display_to_user (false);
205 if (dynamic_cast<AudioTrack*>(this)) {
206 /* we can't do this in the AudioTrack's constructor
207 * because _trim does not exit then
211 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
216 /* create standard processors: meter, main outs, monitor out;
217 they will be added to _processors by setup_invisible_processors ()
220 _meter.reset (new PeakMeter (_session, _name));
221 _meter->set_owner (this);
222 _meter->set_display_to_user (false);
225 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
226 _main_outs->activate ();
229 /* where we listen to tracks */
230 _intreturn.reset (new InternalReturn (_session));
231 _intreturn->activate ();
233 /* the thing that provides proper control over a control/monitor/listen bus
234 (such as per-channel cut, dim, solo, invert, etc).
236 _monitor_control.reset (new MonitorProcessor (_session));
237 _monitor_control->activate ();
240 if (is_master() || is_monitor() || is_auditioner()) {
241 _mute_master->set_solo_ignore (true);
244 /* now that we have _meter, its safe to connect to this */
247 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
248 configure_processors (0);
256 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
258 /* do this early so that we don't get incoming signals as we are going through destruction
263 /* don't use clear_processors here, as it depends on the session which may
264 be half-destroyed by now
267 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
269 (*i)->drop_references ();
272 _processors.clear ();
276 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
278 if (Config->get_remote_model() != UserOrdered) {
282 set_remote_control_id_internal (id, notify_class_listeners);
286 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
288 /* force IDs for master/monitor busses and prevent
289 any other route from accidentally getting these IDs
290 (i.e. legacy sessions)
293 if (is_master() && id != MasterBusRemoteControlID) {
294 id = MasterBusRemoteControlID;
297 if (is_monitor() && id != MonitorBusRemoteControlID) {
298 id = MonitorBusRemoteControlID;
305 /* don't allow it to collide */
307 if (!is_master () && !is_monitor() &&
308 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
309 id += MonitorBusRemoteControlID;
312 if (id != remote_control_id()) {
313 _remote_control_id = id;
314 RemoteControlIDChanged ();
316 if (notify_class_listeners) {
317 RemoteControlIDChange ();
323 Route::remote_control_id() const
326 return MasterBusRemoteControlID;
330 return MonitorBusRemoteControlID;
333 return _remote_control_id;
337 Route::has_order_key () const
339 return _has_order_key;
343 Route::order_key () const
349 Route::set_remote_control_id_explicit (uint32_t rid)
351 if (is_master() || is_monitor() || is_auditioner()) {
352 /* hard-coded remote IDs, or no remote ID */
356 if (_remote_control_id != rid) {
357 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
358 _remote_control_id = rid;
359 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
362 /* don't emit the class-level RID signal RemoteControlIDChange here,
363 leave that to the entity that changed the order key, so that we
364 don't get lots of emissions for no good reasons (e.g. when changing
365 all route order keys).
367 See Session::sync_remote_id_from_order_keys() for the (primary|only)
368 spot where that is emitted.
373 Route::set_order_key (uint32_t n)
375 _has_order_key = true;
377 if (_order_key == n) {
383 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
384 name(), order_key ()));
386 _session.set_dirty ();
390 Route::ensure_track_or_route_name(string name, Session &session)
392 string newname = name;
394 while (!session.io_name_is_legal (newname)) {
395 newname = bump_name_once (newname, ' ');
402 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
404 // TODO route group, see set_gain()
405 // _trim_control->route_set_value (val);
409 Route::maybe_declick (BufferSet&, framecnt_t, int)
411 /* this is the "bus" implementation and they never declick.
416 /** Process this route for one (sub) cycle (process thread)
418 * @param bufs Scratch buffers to use for the signal path
419 * @param start_frame Initial transport frame
420 * @param end_frame Final transport frame
421 * @param nframes Number of frames to output (to ports)
423 * Note that (end_frame - start_frame) may not be equal to nframes when the
424 * transport speed isn't 1.0 (eg varispeed).
427 Route::process_output_buffers (BufferSet& bufs,
428 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
429 int declick, bool gain_automation_ok)
431 /* Caller must hold process lock */
432 assert (!AudioEngine::instance()->process_lock().trylock());
434 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
436 // can this actually happen? functions calling process_output_buffers()
437 // already take a reader-lock.
438 bufs.silence (nframes, 0);
442 /* figure out if we're going to use gain automation */
443 if (gain_automation_ok) {
444 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
445 _amp->setup_gain_automation (
446 start_frame + _signal_latency_at_amp_position,
447 end_frame + _signal_latency_at_amp_position,
450 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
451 _trim->setup_gain_automation (
452 start_frame + _signal_latency_at_trim_position,
453 end_frame + _signal_latency_at_trim_position,
456 _amp->apply_gain_automation (false);
457 _trim->apply_gain_automation (false);
460 /* Tell main outs what to do about monitoring. We do this so that
461 on a transition between monitoring states we get a de-clicking gain
462 change in the _main_outs delivery, if config.get_use_monitor_fades()
465 We override this in the case where we have an internal generator.
467 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
469 _main_outs->no_outs_cuz_we_no_monitor (silence);
471 /* -------------------------------------------------------------------------------------------
472 GLOBAL DECLICK (for transport changes etc.)
473 ----------------------------------------------------------------------------------------- */
475 maybe_declick (bufs, nframes, declick);
476 _pending_declick = 0;
478 /* -------------------------------------------------------------------------------------------
479 DENORMAL CONTROL/PHASE INVERT
480 ----------------------------------------------------------------------------------------- */
482 if (!_phase_control->none()) {
486 if (_denormal_protection || Config->get_denormal_protection()) {
488 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
489 Sample* const sp = i->data();
491 if (_phase_control->inverted (chn)) {
492 for (pframes_t nx = 0; nx < nframes; ++nx) {
497 for (pframes_t nx = 0; nx < nframes; ++nx) {
505 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
506 Sample* const sp = i->data();
508 if (_phase_control->inverted (chn)) {
509 for (pframes_t nx = 0; nx < nframes; ++nx) {
518 if (_denormal_protection || Config->get_denormal_protection()) {
520 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
521 Sample* const sp = i->data();
522 for (pframes_t nx = 0; nx < nframes; ++nx) {
530 /* -------------------------------------------------------------------------------------------
532 ----------------------------------------------------------------------------------------- */
534 /* set this to be true if the meter will already have been ::run() earlier */
535 bool const meter_already_run = metering_state() == MeteringInput;
537 framecnt_t latency = 0;
539 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
541 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
542 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
547 /* if it has any inputs, make sure they match */
548 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
549 if (bufs.count() != (*i)->input_streams()) {
551 DEBUG::Processors, string_compose (
552 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
553 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
560 /* should we NOT run plugins here if the route is inactive?
561 do we catch route != active somewhere higher?
564 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
565 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
568 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
569 bufs.set_count ((*i)->output_streams());
571 if ((*i)->active ()) {
572 latency += (*i)->signal_latency ();
578 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
579 boost::shared_ptr<Processor> endpoint,
580 bool include_endpoint, bool for_export, bool for_freeze)
582 /* If no processing is required, there's no need to go any further. */
583 if (!endpoint && !include_endpoint) {
587 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
588 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
589 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
591 /* trim is always at the top, for bounce no latency compensation is needed */
592 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
593 _trim->setup_gain_automation (start, start + nframes, nframes);
596 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
598 if (!include_endpoint && (*i) == endpoint) {
602 /* if we're *not* exporting, stop processing if we come across a routing processor. */
603 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
606 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
610 /* special case the panner (export outputs)
611 * Ideally we'd only run the panner, not the delivery itself...
612 * but panners need separate input/output buffers and some context
613 * (panshell, panner type, etc). AFAICT there is no ill side effect
614 * of re-using the main delivery when freewheeling/exporting a region.
616 if ((*i) == _main_outs) {
617 assert ((*i)->does_routing());
618 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
619 buffers.set_count ((*i)->output_streams());
622 /* don't run any processors that do routing.
623 * Also don't bother with metering.
625 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
626 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
627 buffers.set_count ((*i)->output_streams());
628 latency += (*i)->signal_latency ();
631 if ((*i) == endpoint) {
638 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
639 bool include_endpoint, bool for_export, bool for_freeze) const
641 framecnt_t latency = 0;
642 if (!endpoint && !include_endpoint) {
646 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
647 if (!include_endpoint && (*i) == endpoint) {
650 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
653 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
656 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
657 latency += (*i)->signal_latency ();
659 if ((*i) == endpoint) {
667 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
668 bool include_endpoint, bool for_export, bool for_freeze) const
670 if (!endpoint && !include_endpoint) {
674 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
675 if (!include_endpoint && (*i) == endpoint) {
678 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
681 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
684 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
685 cc = (*i)->output_streams();
687 if ((*i) == endpoint) {
695 Route::n_process_buffers ()
697 return max (_input->n_ports(), processor_max_streams);
701 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
703 assert (is_monitor());
704 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
705 fill_buffers_with_input (bufs, _input, nframes);
706 passthru (bufs, start_frame, end_frame, nframes, declick);
710 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
714 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
716 /* control/monitor bus ignores input ports when something is
717 feeding the listen "stream". data will "arrive" into the
718 route from the intreturn processor element.
721 bufs.silence (nframes, 0);
724 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
725 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
729 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
731 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
733 bufs.set_count (_input->n_ports());
734 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
735 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
739 Route::set_listen (bool yn)
743 _monitor_send->activate ();
745 _monitor_send->deactivate ();
751 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
753 /* nothing to do if we're not using AFL/PFL. But if we are, we need
754 to alter the active state of the monitor send.
757 if (Config->get_solo_control_is_listen_control ()) {
758 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
763 Route::push_solo_isolate_upstream (int32_t delta)
765 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
767 boost::shared_ptr<RouteList> routes = _session.get_routes ();
768 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
770 if ((*i).get() == this || !(*i)->can_solo()) {
775 bool does_feed = feeds (*i, &sends_only);
777 if (does_feed && !sends_only) {
778 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
784 Route::push_solo_upstream (int delta)
786 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
787 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
791 boost::shared_ptr<Route> sr (i->r.lock());
793 sr->solo_control()->mod_solo_by_others_downstream (-delta);
800 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
802 cerr << name << " {" << endl;
803 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
804 p != procs.end(); ++p) {
805 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
811 /** Supposing that we want to insert a Processor at a given Placement, return
812 * the processor to add the new one before (or 0 to add at the end).
814 boost::shared_ptr<Processor>
815 Route::before_processor_for_placement (Placement p)
817 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
819 ProcessorList::iterator loc;
822 /* generic pre-fader: insert immediately before the amp */
823 loc = find (_processors.begin(), _processors.end(), _amp);
825 /* generic post-fader: insert right before the main outs */
826 loc = find (_processors.begin(), _processors.end(), _main_outs);
829 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
832 /** Supposing that we want to insert a Processor at a given index, return
833 * the processor to add the new one before (or 0 to add at the end).
835 boost::shared_ptr<Processor>
836 Route::before_processor_for_index (int index)
839 return boost::shared_ptr<Processor> ();
842 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
844 ProcessorList::iterator i = _processors.begin ();
846 while (i != _processors.end() && j < index) {
847 if ((*i)->display_to_user()) {
854 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
857 /** Add a processor either pre- or post-fader
858 * @return 0 on success, non-0 on failure.
861 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
863 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
867 /** Add a processor to a route such that it ends up with a given index into the visible processors.
868 * @param index Index to add the processor at, or -1 to add at the end of the list.
869 * @return 0 on success, non-0 on failure.
872 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
874 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
877 /** Add a processor to the route.
878 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
879 * @return 0 on success, non-0 on failure.
882 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
884 assert (processor != _meter);
885 assert (processor != _main_outs);
887 DEBUG_TRACE (DEBUG::Processors, string_compose (
888 "%1 adding processor %2\n", name(), processor->name()));
892 pl.push_back (processor);
893 int rv = add_processors (pl, before, err);
899 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
900 processor->activate ();
907 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
909 /* We cannot destruct the processor here (usually RT-thread
910 * with various locks held - in case of sends also io_locks).
911 * Queue for deletion in low-priority thread.
913 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
914 selfdestruct_sequence.push_back (wp);
918 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
920 XMLProperty const * prop;
923 boost::shared_ptr<Processor> processor;
925 /* bit of a hack: get the `placement' property from the <Redirect> tag here
926 so that we can add the processor in the right place (pre/post-fader)
929 XMLNodeList const & children = node.children ();
930 XMLNodeList::const_iterator i = children.begin ();
932 while (i != children.end() && (*i)->name() != X_("Redirect")) {
936 Placement placement = PreFader;
938 if (i != children.end()) {
939 if ((prop = (*i)->property (X_("placement"))) != 0) {
940 placement = Placement (string_2_enum (prop->value(), placement));
944 if (node.name() == "Insert") {
946 if ((prop = node.property ("type")) != 0) {
948 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
949 prop->value() == "lv2" ||
950 prop->value() == "windows-vst" ||
951 prop->value() == "lxvst" ||
952 prop->value() == "audiounit") {
954 if (_session.get_disable_all_loaded_plugins ()) {
955 processor.reset (new UnknownProcessor (_session, node));
957 processor.reset (new PluginInsert (_session));
958 processor->set_owner (this);
963 processor.reset (new PortInsert (_session, _pannable, _mute_master));
968 } else if (node.name() == "Send") {
970 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
971 processor.reset (new Send (_session, sendpan, _mute_master));
975 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
979 if (processor->set_state (node, version)) {
983 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
984 if (i != children.end()) {
985 if ((prop = (*i)->property (X_("active"))) != 0) {
986 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
987 processor->activate();
989 processor->deactivate();
993 return (add_processor (processor, placement, 0, false) == 0);
996 catch (failed_constructor &err) {
997 warning << _("processor could not be created. Ignored.") << endmsg;
1003 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1004 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
1007 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1008 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
1012 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1014 ProcessorList::iterator loc;
1017 loc = find(_processors.begin(), _processors.end(), before);
1018 if (loc == _processors.end ()) {
1022 /* nothing specified - at end */
1023 loc = _processors.end ();
1026 if (!AudioEngine::instance()->connected()) {
1030 if (others.empty()) {
1034 ProcessorList to_skip;
1036 // check if there's an instrument to replace or configure
1037 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1038 boost::shared_ptr<PluginInsert> pi;
1039 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1042 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1045 boost::shared_ptr<Processor> instrument = the_instrument ();
1046 ChanCount in (DataType::MIDI, 1);
1047 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1049 PluginSetupOptions flags = None;
1051 flags |= CanReplace;
1052 in = instrument->input_streams ();
1053 out = instrument->output_streams ();
1055 if (pi->has_output_presets (in, out)) {
1059 pi->set_strict_io (_strict_io);
1061 PluginSetupOptions mask = None;
1062 if (Config->get_ask_replace_instrument ()) {
1065 if (Config->get_ask_setup_instrument ()) {
1071 if (flags != None) {
1072 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
1073 switch (rv.get_value_or (0)) {
1075 to_skip.push_back (*i); // don't add this one;
1078 replace_processor (instrument, *i, err);
1079 to_skip.push_back (*i);
1088 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1089 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1090 ProcessorState pstate (this);
1092 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1097 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1098 if (check != to_skip.end()) {
1102 boost::shared_ptr<PluginInsert> pi;
1104 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1105 pi->set_strict_io (_strict_io);
1109 /* Ensure that only one amp is in the list at any time */
1110 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1111 if (check != _processors.end()) {
1112 if (before == _amp) {
1113 /* Already in position; all is well */
1116 _processors.erase (check);
1121 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1123 _processors.insert (loc, *i);
1124 (*i)->set_owner (this);
1127 if (configure_processors_unlocked (err, &lm)) {
1129 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1134 if ((*i)->active()) {
1138 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1140 boost::shared_ptr<Send> send;
1141 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1142 send->SelfDestruct.connect_same_thread (*this,
1143 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1147 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1148 boost::shared_ptr<PluginInsert> pi;
1150 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1151 if (pi->has_no_inputs ()) {
1152 _have_internal_generator = true;
1158 _output->set_user_latency (0);
1161 reset_instrument_info ();
1162 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1163 set_processor_positions ();
1169 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1171 if (p == PreFader) {
1172 start = _processors.begin();
1173 end = find(_processors.begin(), _processors.end(), _amp);
1175 start = find(_processors.begin(), _processors.end(), _amp);
1177 end = _processors.end();
1181 /** Turn off all processors with a given placement
1182 * @param p Placement of processors to disable
1185 Route::disable_processors (Placement p)
1187 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1189 ProcessorList::iterator start, end;
1190 placement_range(p, start, end);
1192 for (ProcessorList::iterator i = start; i != end; ++i) {
1193 (*i)->deactivate ();
1196 _session.set_dirty ();
1199 /** Turn off all redirects
1202 Route::disable_processors ()
1204 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1206 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1207 (*i)->deactivate ();
1210 _session.set_dirty ();
1213 /** Turn off all redirects with a given placement
1214 * @param p Placement of redirects to disable
1217 Route::disable_plugins (Placement p)
1219 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1221 ProcessorList::iterator start, end;
1222 placement_range(p, start, end);
1224 for (ProcessorList::iterator i = start; i != end; ++i) {
1225 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1226 (*i)->deactivate ();
1230 _session.set_dirty ();
1233 /** Turn off all plugins
1236 Route::disable_plugins ()
1238 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1240 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1241 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1242 (*i)->deactivate ();
1246 _session.set_dirty ();
1251 Route::ab_plugins (bool forward)
1253 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1257 /* forward = turn off all active redirects, and mark them so that the next time
1258 we go the other way, we will revert them
1261 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1262 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1266 if ((*i)->active()) {
1267 (*i)->deactivate ();
1268 (*i)->set_next_ab_is_active (true);
1270 (*i)->set_next_ab_is_active (false);
1276 /* backward = if the redirect was marked to go active on the next ab, do so */
1278 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1280 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1284 if ((*i)->get_next_ab_is_active()) {
1287 (*i)->deactivate ();
1292 _session.set_dirty ();
1296 /** Remove processors with a given placement.
1297 * @param p Placement of processors to remove.
1300 Route::clear_processors (Placement p)
1302 if (!_session.engine().connected()) {
1306 bool already_deleting = _session.deletion_in_progress();
1307 if (!already_deleting) {
1308 _session.set_deletion_in_progress();
1312 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1313 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1314 ProcessorList new_list;
1315 ProcessorStreams err;
1316 bool seen_amp = false;
1318 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1324 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1326 /* you can't remove these */
1328 new_list.push_back (*i);
1335 new_list.push_back (*i);
1338 (*i)->drop_references ();
1346 (*i)->drop_references ();
1349 new_list.push_back (*i);
1356 _processors = new_list;
1357 configure_processors_unlocked (&err, &lm); // this can't fail
1360 processor_max_streams.reset();
1361 _have_internal_generator = false;
1362 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1363 set_processor_positions ();
1365 reset_instrument_info ();
1367 if (!already_deleting) {
1368 _session.clear_deletion_in_progress();
1373 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1375 // TODO once the export point can be configured properly, do something smarter here
1376 if (processor == _capturing_processor) {
1377 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1378 if (need_process_lock) {
1382 _capturing_processor.reset();
1384 if (need_process_lock) {
1389 /* these can never be removed */
1391 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1395 if (!_session.engine().connected()) {
1399 processor_max_streams.reset();
1402 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1403 if (need_process_lock) {
1407 /* Caller must hold process lock */
1408 assert (!AudioEngine::instance()->process_lock().trylock());
1410 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1412 ProcessorState pstate (this);
1414 ProcessorList::iterator i;
1415 bool removed = false;
1417 for (i = _processors.begin(); i != _processors.end(); ) {
1418 if (*i == processor) {
1420 /* move along, see failure case for configure_processors()
1421 where we may need to reconfigure the processor.
1424 /* stop redirects that send signals to JACK ports
1425 from causing noise as a result of no longer being
1429 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1430 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1434 iop = pi->sidechain();
1441 i = _processors.erase (i);
1449 _output->set_user_latency (0);
1457 if (configure_processors_unlocked (err, &lm)) {
1459 /* we know this will work, because it worked before :) */
1460 configure_processors_unlocked (0, &lm);
1464 _have_internal_generator = false;
1466 for (i = _processors.begin(); i != _processors.end(); ++i) {
1467 boost::shared_ptr<PluginInsert> pi;
1469 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1470 if (pi->has_no_inputs ()) {
1471 _have_internal_generator = true;
1476 if (need_process_lock) {
1481 reset_instrument_info ();
1482 processor->drop_references ();
1483 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1484 set_processor_positions ();
1490 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1492 /* these can never be removed */
1493 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1496 /* and can't be used as substitute, either */
1497 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1501 /* I/Os are out, too */
1502 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1506 /* this function cannot be used to swap/reorder processors */
1507 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1511 if (!AudioEngine::instance()->connected() || !old || !sub) {
1515 /* ensure that sub is not owned by another route */
1516 if (sub->owner ()) {
1521 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1522 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1523 ProcessorState pstate (this);
1525 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1527 ProcessorList::iterator i;
1528 bool replaced = false;
1529 bool enable = old->active ();
1531 for (i = _processors.begin(); i != _processors.end(); ) {
1533 i = _processors.erase (i);
1534 _processors.insert (i, sub);
1535 sub->set_owner (this);
1548 boost::shared_ptr<PluginInsert> pi;
1549 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1550 pi->set_strict_io (true);
1554 if (configure_processors_unlocked (err, &lm)) {
1556 configure_processors_unlocked (0, &lm);
1560 _have_internal_generator = false;
1562 for (i = _processors.begin(); i != _processors.end(); ++i) {
1563 boost::shared_ptr<PluginInsert> pi;
1564 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1565 if (pi->has_no_inputs ()) {
1566 _have_internal_generator = true;
1576 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1577 _output->set_user_latency (0);
1580 reset_instrument_info ();
1581 old->drop_references ();
1582 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1583 set_processor_positions ();
1588 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1590 ProcessorList deleted;
1592 if (!_session.engine().connected()) {
1596 processor_max_streams.reset();
1599 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1600 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1601 ProcessorState pstate (this);
1603 ProcessorList::iterator i;
1604 boost::shared_ptr<Processor> processor;
1606 for (i = _processors.begin(); i != _processors.end(); ) {
1610 /* these can never be removed */
1612 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1617 /* see if its in the list of processors to delete */
1619 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1624 /* stop IOProcessors that send to JACK ports
1625 from causing noise as a result of no longer being
1629 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1630 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1633 iop = pi->sidechain();
1640 deleted.push_back (processor);
1641 i = _processors.erase (i);
1644 if (deleted.empty()) {
1645 /* none of those in the requested list were found */
1649 _output->set_user_latency (0);
1651 if (configure_processors_unlocked (err, &lm)) {
1653 /* we know this will work, because it worked before :) */
1654 configure_processors_unlocked (0, &lm);
1659 _have_internal_generator = false;
1661 for (i = _processors.begin(); i != _processors.end(); ++i) {
1662 boost::shared_ptr<PluginInsert> pi;
1664 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1665 if (pi->has_no_inputs ()) {
1666 _have_internal_generator = true;
1673 /* now try to do what we need to so that those that were removed will be deleted */
1675 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1676 (*i)->drop_references ();
1679 reset_instrument_info ();
1680 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1681 set_processor_positions ();
1687 Route::reset_instrument_info ()
1689 boost::shared_ptr<Processor> instr = the_instrument();
1691 _instrument_info.set_internal_instrument (instr);
1695 /** Caller must hold process lock */
1697 Route::configure_processors (ProcessorStreams* err)
1699 #ifndef PLATFORM_WINDOWS
1700 assert (!AudioEngine::instance()->process_lock().trylock());
1703 if (!_in_configure_processors) {
1704 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1705 return configure_processors_unlocked (err, &lm);
1712 Route::input_streams () const
1714 return _input->n_ports ();
1717 list<pair<ChanCount, ChanCount> >
1718 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1720 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1722 return try_configure_processors_unlocked (in, err);
1725 list<pair<ChanCount, ChanCount> >
1726 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1728 // Check each processor in order to see if we can configure as requested
1730 list<pair<ChanCount, ChanCount> > configuration;
1733 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1734 DEBUG_TRACE (DEBUG::Processors, "{\n");
1736 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1738 if ((*p)->can_support_io_configuration(in, out)) {
1740 if (boost::dynamic_pointer_cast<Delivery> (*p)
1741 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1742 && !(is_monitor() || is_auditioner())
1743 && ( _strict_io || Profile->get_mixbus ())) {
1744 /* with strict I/O the panner + output are forced to
1745 * follow the last processor's output.
1747 * Delivery::can_support_io_configuration() will only add ports,
1748 * but not remove excess ports.
1750 * This works because the delivery only requires
1751 * as many outputs as there are inputs.
1752 * Delivery::configure_io() will do the actual removal
1753 * by calling _output->ensure_io()
1755 if (!is_master() && _session.master_out ()) {
1756 /* ..but at least as many as there are master-inputs */
1757 // XXX this may need special-casing for mixbus (master-outputs)
1758 // and should maybe be a preference anyway ?!
1759 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1765 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1766 configuration.push_back(make_pair(in, out));
1769 // restriction for Monitor Section Processors
1770 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1771 /* do not allow to add/remove channels (for now)
1772 * The Monitor follows the master-bus and has no panner (unpan)
1773 * but do allow processors with midi-in to be added (e.g VSTs with control that
1774 * will remain unconnected)
1776 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1777 return list<pair<ChanCount, ChanCount> > ();
1779 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1780 // internal sends make no sense, only feedback
1781 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1782 return list<pair<ChanCount, ChanCount> > ();
1784 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1785 /* External Sends can be problematic. one can add/remove ports
1786 * there signal leaves the DAW to external monitors anyway, so there's
1787 * no real use for allowing them here anyway.
1789 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1790 return list<pair<ChanCount, ChanCount> > ();
1792 if (boost::dynamic_pointer_cast<Send> (*p)) {
1794 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1795 return list<pair<ChanCount, ChanCount> > ();
1804 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1805 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1806 DEBUG_TRACE (DEBUG::Processors, "}\n");
1807 return list<pair<ChanCount, ChanCount> > ();
1811 DEBUG_TRACE (DEBUG::Processors, "}\n");
1813 return configuration;
1816 /** Set the input/output configuration of each processor in the processors list.
1817 * Caller must hold process lock.
1818 * Return 0 on success, otherwise configuration is impossible.
1821 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1823 #ifndef PLATFORM_WINDOWS
1824 assert (!AudioEngine::instance()->process_lock().trylock());
1827 if (_in_configure_processors) {
1831 /* put invisible processors where they should be */
1832 setup_invisible_processors ();
1834 _in_configure_processors = true;
1836 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1838 if (configuration.empty ()) {
1839 _in_configure_processors = false;
1844 bool seen_mains_out = false;
1845 processor_out_streams = _input->n_ports();
1846 processor_max_streams.reset();
1848 /* processor configure_io() may result in adding ports
1849 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1851 * with jack2 adding ports results in a graph-order callback,
1852 * which calls Session::resort_routes() and eventually
1853 * Route::direct_feeds_according_to_reality()
1854 * which takes a ReaderLock (_processor_lock).
1856 * so we can't hold a WriterLock here until jack2 threading
1859 * NB. we still hold the process lock
1861 * (ardour's own engines do call graph-order from the
1862 * process-thread and hence do not have this issue; besides
1863 * merely adding ports won't trigger a graph-order, only
1864 * making connections does)
1868 // TODO check for a potential ReaderLock after ReaderLock ??
1869 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1871 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1872 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1874 if (!(*p)->configure_io(c->first, c->second)) {
1875 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1876 _in_configure_processors = false;
1881 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1882 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1884 boost::shared_ptr<IOProcessor> iop;
1885 boost::shared_ptr<PluginInsert> pi;
1886 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1887 /* plugins connected via Split or Hide Match may have more channels.
1888 * route/scratch buffers are needed for all of them
1889 * The configuration may only be a subset (both input and output)
1891 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1893 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1894 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1895 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1899 if (boost::dynamic_pointer_cast<Delivery> (*p)
1900 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1901 /* main delivery will increase port count to match input.
1902 * the Delivery::Main is usually the last processor - followed only by
1905 seen_mains_out = true;
1907 if (!seen_mains_out) {
1908 processor_out_streams = out;
1917 _meter->set_max_channels (processor_max_streams);
1920 /* make sure we have sufficient scratch buffers to cope with the new processor
1923 _session.ensure_buffers (n_process_buffers ());
1925 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1927 _in_configure_processors = false;
1931 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1932 * @param state New active state for those processors.
1935 Route::all_visible_processors_active (bool state)
1937 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1939 if (_processors.empty()) {
1943 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1944 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1951 (*i)->deactivate ();
1955 _session.set_dirty ();
1959 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1961 /* check if re-order requires re-configuration of any processors
1962 * -> compare channel configuration for all processors
1964 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1965 ChanCount c = input_streams ();
1967 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1969 if (c != (*j)->input_streams()) {
1972 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1975 if ((*i)->input_streams() != c) {
1978 c = (*i)->output_streams();
1990 __attribute__((annotate("realtime")))
1993 Route::apply_processor_order (const ProcessorList& new_order)
1995 /* need to hold processor_lock; either read or write lock
1996 * and the engine process_lock.
1997 * Due to r/w lock ambiguity we can only assert the latter
1999 assert (!AudioEngine::instance()->process_lock().trylock());
2002 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2003 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2004 * processors in the current actual processor list that are hidden. Any visible processors
2005 * in the current list but not in "new_order" will be assumed to be deleted.
2008 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2009 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2010 * (note though that ::processors_reorder_needs_configure() ensured that
2011 * this function will only ever be called from the rt-thread if no processor were removed)
2013 * either way, I can't proove it, but an x-run due to re-order here is less likley
2014 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2017 ProcessorList as_it_will_be;
2018 ProcessorList::iterator oiter;
2019 ProcessorList::const_iterator niter;
2021 oiter = _processors.begin();
2022 niter = new_order.begin();
2024 while (niter != new_order.end()) {
2026 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2027 then append it to the temp list.
2029 Otherwise, see if the next processor in the old list is in the new list. if not,
2030 its been deleted. If its there, append it to the temp list.
2033 if (oiter == _processors.end()) {
2035 /* no more elements in the old list, so just stick the rest of
2036 the new order onto the temp list.
2039 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2040 while (niter != new_order.end()) {
2047 if (!(*oiter)->display_to_user()) {
2049 as_it_will_be.push_back (*oiter);
2053 /* visible processor: check that its in the new order */
2055 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2056 /* deleted: do nothing, shared_ptr<> will clean up */
2058 /* ignore this one, and add the next item from the new order instead */
2059 as_it_will_be.push_back (*niter);
2064 /* now remove from old order - its taken care of no matter what */
2065 oiter = _processors.erase (oiter);
2069 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2071 /* If the meter is in a custom position, find it and make a rough note of its position */
2072 maybe_note_meter_position ();
2076 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2078 // it a change is already queued, wait for it
2079 // (unless engine is stopped. apply immediately and proceed
2080 while (g_atomic_int_get (&_pending_process_reorder)) {
2081 if (!AudioEngine::instance()->running()) {
2082 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2083 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2085 apply_processor_order(_pending_processor_order);
2086 setup_invisible_processors ();
2088 g_atomic_int_set (&_pending_process_reorder, 0);
2090 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2091 set_processor_positions ();
2093 // TODO rather use a semaphore or something.
2094 // but since ::reorder_processors() is called
2095 // from the GUI thread, this is fine..
2100 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2102 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2103 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2104 ProcessorState pstate (this);
2106 apply_processor_order (new_order);
2108 if (configure_processors_unlocked (err, &lm)) {
2116 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2117 set_processor_positions ();
2120 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2121 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2123 // _pending_processor_order is protected by _processor_lock
2124 _pending_processor_order = new_order;
2125 g_atomic_int_set (&_pending_process_reorder, 1);
2132 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2134 boost::shared_ptr<PluginInsert> pi;
2135 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2139 if (pi->has_sidechain () == add) {
2140 return true; // ?? call failed, but result is as expected.
2144 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2145 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2146 if (i == _processors.end ()) {
2152 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2153 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2154 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2156 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2158 if (!pi->add_sidechain ()) {
2162 if (!pi->del_sidechain ()) {
2168 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2173 pi->del_sidechain ();
2175 pi->add_sidechain ();
2176 // TODO restore side-chain's state.
2181 configure_processors_unlocked (0, &lm);
2184 if (pi->has_sidechain ()) {
2185 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2188 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2189 _session.set_dirty ();
2194 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2196 boost::shared_ptr<PluginInsert> pi;
2197 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2202 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2203 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2204 if (i == _processors.end ()) {
2210 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2211 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2213 const ChanCount& old (pi->preset_out ());
2214 if (!pi->set_preset_out (outs)) {
2215 return true; // no change, OK
2218 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2221 pi->set_preset_out (old);
2224 configure_processors_unlocked (0, &lm);
2227 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2228 _session.set_dirty ();
2233 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2236 return customize_plugin_insert (proc, 0, unused, unused);
2240 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2242 boost::shared_ptr<PluginInsert> pi;
2243 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2248 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2249 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2250 if (i == _processors.end ()) {
2256 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2257 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2259 bool old_cust = pi->custom_cfg ();
2260 uint32_t old_cnt = pi->get_count ();
2261 ChanCount old_chan = pi->output_streams ();
2262 ChanCount old_sinks = pi->natural_input_streams ();
2265 pi->set_custom_cfg (false);
2267 pi->set_custom_cfg (true);
2268 pi->set_count (count);
2269 pi->set_outputs (outs);
2270 pi->set_sinks (sinks);
2273 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2277 pi->set_count (old_cnt);
2278 pi->set_sinks (old_sinks);
2279 pi->set_outputs (old_chan);
2280 pi->set_custom_cfg (old_cust);
2284 configure_processors_unlocked (0, &lm);
2287 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2288 _session.set_dirty ();
2293 Route::set_strict_io (const bool enable)
2295 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2297 if (_strict_io != enable) {
2298 _strict_io = enable;
2299 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2300 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2301 boost::shared_ptr<PluginInsert> pi;
2302 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2303 pi->set_strict_io (_strict_io);
2307 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2311 _strict_io = !enable; // restore old value
2312 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2313 boost::shared_ptr<PluginInsert> pi;
2314 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2315 pi->set_strict_io (_strict_io);
2322 configure_processors (0);
2325 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2326 _session.set_dirty ();
2338 Route::get_template()
2340 return state(false);
2344 Route::state(bool full_state)
2347 if (!_session._template_state_dir.empty()) {
2348 assert (!full_state); // only for templates
2349 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2352 XMLNode *node = new XMLNode("Route");
2353 ProcessorList::iterator i;
2356 id().print (buf, sizeof (buf));
2357 node->add_property("id", buf);
2358 node->add_property ("name", _name);
2359 node->add_property("default-type", _default_type.to_string());
2360 node->add_property ("strict-io", _strict_io);
2363 node->add_property("flags", enum_2_string (_flags));
2366 node->add_property("active", _active?"yes":"no");
2368 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2369 node->add_property("meter-point", enum_2_string (_meter_point));
2371 node->add_property("meter-type", enum_2_string (_meter_type));
2374 node->add_property("route-group", _route_group->name());
2377 snprintf (buf, sizeof (buf), "%d", _order_key);
2378 node->add_property ("order-key", buf);
2380 node->add_child_nocopy (_solo_control->get_state ());
2381 node->add_child_nocopy (_solo_isolate_control->get_state ());
2382 node->add_child_nocopy (_solo_safe_control->get_state ());
2384 node->add_child_nocopy (_input->state (full_state));
2385 node->add_child_nocopy (_output->state (full_state));
2386 node->add_child_nocopy (_mute_master->get_state ());
2388 node->add_child_nocopy (_mute_control->get_state ());
2389 node->add_child_nocopy (_phase_control->get_state ());
2392 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2395 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2396 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2397 remote_control_node->add_property (X_("id"), buf);
2398 node->add_child_nocopy (*remote_control_node);
2400 if (_comment.length()) {
2401 XMLNode *cmt = node->add_child ("Comment");
2402 cmt->add_content (_comment);
2406 node->add_child_nocopy (_pannable->state (full_state));
2410 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2411 for (i = _processors.begin(); i != _processors.end(); ++i) {
2413 /* template save: do not include internal sends functioning as
2414 aux sends because the chance of the target ID
2415 in the session where this template is used
2418 similarly, do not save listen sends which connect to
2419 the monitor section, because these will always be
2422 boost::shared_ptr<InternalSend> is;
2424 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2425 if (is->role() == Delivery::Listen) {
2430 node->add_child_nocopy((*i)->state (full_state));
2435 node->add_child_copy (*_extra_xml);
2438 if (_custom_meter_position_noted) {
2439 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2441 after->id().print (buf, sizeof (buf));
2442 node->add_property (X_("processor-after-last-custom-meter"), buf);
2446 if (!_session._template_state_dir.empty()) {
2447 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2454 Route::set_state (const XMLNode& node, int version)
2456 if (version < 3000) {
2457 return set_state_2X (node, version);
2461 XMLNodeConstIterator niter;
2463 XMLProperty const * prop;
2465 if (node.name() != "Route"){
2466 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2470 if ((prop = node.property (X_("name"))) != 0) {
2471 Route::set_name (prop->value());
2475 _initial_io_setup = true;
2477 if ((prop = node.property (X_("flags"))) != 0) {
2478 _flags = Flag (string_2_enum (prop->value(), _flags));
2483 if ((prop = node.property (X_("strict-io"))) != 0) {
2484 _strict_io = string_is_affirmative (prop->value());
2488 _mute_master->set_solo_ignore (true);
2492 /* monitor bus does not get a panner, but if (re)created
2493 via XML, it will already have one by the time we
2494 call ::set_state(). so ... remove it.
2499 /* add all processors (except amp, which is always present) */
2501 nlist = node.children();
2502 XMLNode processor_state (X_("processor_state"));
2504 Stateful::save_extra_xml (node);
2506 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2510 if (child->name() == IO::state_node_name) {
2511 if ((prop = child->property (X_("direction"))) == 0) {
2515 if (prop->value() == "Input") {
2516 _input->set_state (*child, version);
2517 } else if (prop->value() == "Output") {
2518 _output->set_state (*child, version);
2522 if (child->name() == X_("Processor")) {
2523 processor_state.add_child_copy (*child);
2526 if (child->name() == X_("Pannable")) {
2528 _pannable->set_state (*child, version);
2530 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2534 if (child->name() == Controllable::xml_node_name) {
2535 if ((prop = child->property (X_("name"))) == 0) {
2539 if (prop->value() == _gain_control->name()) {
2540 _gain_control->set_state (*child, version);
2541 } else if (prop->value() == _solo_control->name()) {
2542 _solo_control->set_state (*child, version);
2543 } else if (prop->value() == _solo_safe_control->name()) {
2544 _solo_safe_control->set_state (*child, version);
2545 } else if (prop->value() == _solo_isolate_control->name()) {
2546 _solo_isolate_control->set_state (*child, version);
2547 } else if (prop->value() == _solo_control->name()) {
2548 _mute_control->set_state (*child, version);
2553 if ((prop = node.property (X_("meter-point"))) != 0) {
2554 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2555 set_meter_point (mp, true);
2557 _meter->set_display_to_user (_meter_point == MeterCustom);
2561 if ((prop = node.property (X_("meter-type"))) != 0) {
2562 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2565 _initial_io_setup = false;
2567 set_processor_state (processor_state);
2569 // this looks up the internal instrument in processors
2570 reset_instrument_info();
2572 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2573 set_denormal_protection (string_is_affirmative (prop->value()));
2576 if ((prop = node.property (X_("active"))) != 0) {
2577 bool yn = string_is_affirmative (prop->value());
2578 set_active (yn, this);
2581 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2582 set_order_key (atoi(prop->value()));
2585 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2589 string::size_type colon, equal;
2590 string remaining = prop->value();
2592 while (remaining.length()) {
2594 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2595 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2598 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2599 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2602 string keyname = remaining.substr (0, equal);
2604 if ((keyname == "EditorSort") || (keyname == "editor")) {
2605 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2611 colon = remaining.find_first_of (':');
2613 if (colon != string::npos) {
2614 remaining = remaining.substr (colon+1);
2621 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2622 PBD::ID id (prop->value ());
2623 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2624 ProcessorList::const_iterator i = _processors.begin ();
2625 while (i != _processors.end() && (*i)->id() != id) {
2629 if (i != _processors.end ()) {
2630 _processor_after_last_custom_meter = *i;
2631 _custom_meter_position_noted = true;
2635 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2638 if (child->name() == X_("Comment")) {
2640 /* XXX this is a terrible API design in libxml++ */
2642 XMLNode *cmt = *(child->children().begin());
2643 _comment = cmt->content();
2645 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2646 if (prop->value() == "solo") {
2647 _solo_control->set_state (*child, version);
2648 } else if (prop->value() == "mute") {
2649 _mute_control->set_state (*child, version);
2652 } else if (child->name() == X_("RemoteControl")) {
2653 if ((prop = child->property (X_("id"))) != 0) {
2655 sscanf (prop->value().c_str(), "%d", &x);
2656 set_remote_control_id_internal (x);
2659 } else if (child->name() == MuteMaster::xml_node_name) {
2660 _mute_master->set_state (*child, version);
2662 } else if (child->name() == Automatable::xml_node_name) {
2663 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2671 Route::set_state_2X (const XMLNode& node, int version)
2675 XMLNodeConstIterator niter;
2677 XMLProperty const * prop;
2679 /* 2X things which still remain to be handled:
2685 if (node.name() != "Route") {
2686 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2690 if ((prop = node.property (X_("flags"))) != 0) {
2691 string f = prop->value ();
2692 boost::replace_all (f, "ControlOut", "MonitorOut");
2693 _flags = Flag (string_2_enum (f, _flags));
2698 if (is_master() || is_monitor() || is_auditioner()) {
2699 _mute_master->set_solo_ignore (true);
2702 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2703 set_denormal_protection (string_is_affirmative (prop->value()));
2706 if ((prop = node.property (X_("muted"))) != 0) {
2709 bool muted = string_is_affirmative (prop->value());
2715 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2717 if (string_is_affirmative (prop->value())){
2718 mute_point = mute_point + "PreFader";
2723 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2725 if (string_is_affirmative (prop->value())){
2728 mute_point = mute_point + ",";
2731 mute_point = mute_point + "PostFader";
2736 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2738 if (string_is_affirmative (prop->value())){
2741 mute_point = mute_point + ",";
2744 mute_point = mute_point + "Listen";
2749 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2751 if (string_is_affirmative (prop->value())){
2754 mute_point = mute_point + ",";
2757 mute_point = mute_point + "Main";
2761 _mute_master->set_mute_points (mute_point);
2762 _mute_master->set_muted_by_self (true);
2766 if ((prop = node.property (X_("meter-point"))) != 0) {
2767 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2770 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2771 don't mean the same thing.
2774 if ((prop = node.property (X_("order-keys"))) != 0) {
2778 string::size_type colon, equal;
2779 string remaining = prop->value();
2781 while (remaining.length()) {
2783 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2784 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2787 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2788 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2791 string keyname = remaining.substr (0, equal);
2793 if (keyname == "EditorSort" || keyname == "editor") {
2794 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2800 colon = remaining.find_first_of (':');
2802 if (colon != string::npos) {
2803 remaining = remaining.substr (colon+1);
2812 nlist = node.children ();
2813 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2817 if (child->name() == IO::state_node_name) {
2819 /* there is a note in IO::set_state_2X() about why we have to call
2823 _input->set_state_2X (*child, version, true);
2824 _output->set_state_2X (*child, version, false);
2826 if ((prop = child->property (X_("name"))) != 0) {
2827 Route::set_name (prop->value ());
2832 if ((prop = child->property (X_("active"))) != 0) {
2833 bool yn = string_is_affirmative (prop->value());
2834 _active = !yn; // force switch
2835 set_active (yn, this);
2838 if ((prop = child->property (X_("gain"))) != 0) {
2841 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2842 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2846 /* Set up Panners in the IO */
2847 XMLNodeList io_nlist = child->children ();
2849 XMLNodeConstIterator io_niter;
2852 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2854 io_child = *io_niter;
2856 if (io_child->name() == X_("Panner")) {
2857 _main_outs->panner_shell()->set_state(*io_child, version);
2858 } else if (io_child->name() == X_("Automation")) {
2859 /* IO's automation is for the fader */
2860 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2866 XMLNodeList redirect_nodes;
2868 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2872 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2873 redirect_nodes.push_back(child);
2878 set_processor_state_2X (redirect_nodes, version);
2880 Stateful::save_extra_xml (node);
2882 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2885 if (child->name() == X_("Comment")) {
2887 /* XXX this is a terrible API design in libxml++ */
2889 XMLNode *cmt = *(child->children().begin());
2890 _comment = cmt->content();
2892 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2893 if (prop->value() == X_("solo")) {
2894 _solo_control->set_state (*child, version);
2895 } else if (prop->value() == X_("mute")) {
2896 _mute_control->set_state (*child, version);
2899 } else if (child->name() == X_("RemoteControl")) {
2900 if ((prop = child->property (X_("id"))) != 0) {
2902 sscanf (prop->value().c_str(), "%d", &x);
2903 set_remote_control_id_internal (x);
2913 Route::get_processor_state ()
2915 XMLNode* root = new XMLNode (X_("redirects"));
2916 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2917 root->add_child_nocopy ((*i)->state (true));
2924 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2926 /* We don't bother removing existing processors not in nList, as this
2927 method will only be called when creating a Route from scratch, not
2928 for undo purposes. Just put processors in at the appropriate place
2932 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2933 add_processor_from_xml_2X (**i, version);
2938 Route::set_processor_state (const XMLNode& node)
2940 const XMLNodeList &nlist = node.children();
2941 XMLNodeConstIterator niter;
2942 ProcessorList new_order;
2943 bool must_configure = false;
2945 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2947 XMLProperty* prop = (*niter)->property ("type");
2949 if (prop->value() == "amp") {
2950 _amp->set_state (**niter, Stateful::current_state_version);
2951 new_order.push_back (_amp);
2952 } else if (prop->value() == "trim") {
2953 _trim->set_state (**niter, Stateful::current_state_version);
2954 new_order.push_back (_trim);
2955 } else if (prop->value() == "meter") {
2956 _meter->set_state (**niter, Stateful::current_state_version);
2957 new_order.push_back (_meter);
2958 } else if (prop->value() == "delay") {
2960 _delayline->set_state (**niter, Stateful::current_state_version);
2961 new_order.push_back (_delayline);
2963 } else if (prop->value() == "main-outs") {
2964 _main_outs->set_state (**niter, Stateful::current_state_version);
2965 } else if (prop->value() == "intreturn") {
2967 _intreturn.reset (new InternalReturn (_session));
2968 must_configure = true;
2970 _intreturn->set_state (**niter, Stateful::current_state_version);
2971 } else if (is_monitor() && prop->value() == "monitor") {
2972 if (!_monitor_control) {
2973 _monitor_control.reset (new MonitorProcessor (_session));
2974 must_configure = true;
2976 _monitor_control->set_state (**niter, Stateful::current_state_version);
2977 } else if (prop->value() == "capture") {
2978 /* CapturingProcessor should never be restored, it's always
2979 added explicitly when needed */
2981 ProcessorList::iterator o;
2983 for (o = _processors.begin(); o != _processors.end(); ++o) {
2984 XMLProperty const * id_prop = (*niter)->property(X_("id"));
2985 if (id_prop && (*o)->id() == id_prop->value()) {
2986 (*o)->set_state (**niter, Stateful::current_state_version);
2987 new_order.push_back (*o);
2992 // If the processor (*niter) is not on the route then create it
2994 if (o == _processors.end()) {
2996 boost::shared_ptr<Processor> processor;
2998 if (prop->value() == "intsend") {
3000 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3002 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3003 prop->value() == "lv2" ||
3004 prop->value() == "windows-vst" ||
3005 prop->value() == "lxvst" ||
3006 prop->value() == "luaproc" ||
3007 prop->value() == "audiounit") {
3009 if (_session.get_disable_all_loaded_plugins ()) {
3010 processor.reset (new UnknownProcessor (_session, **niter));
3012 processor.reset (new PluginInsert (_session));
3013 processor->set_owner (this);
3015 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3016 pi->set_strict_io (true);
3020 } else if (prop->value() == "port") {
3022 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3024 } else if (prop->value() == "send") {
3026 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3027 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3028 send->SelfDestruct.connect_same_thread (*this,
3029 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3032 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3036 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3037 /* This processor could not be configured. Turn it into a UnknownProcessor */
3038 processor.reset (new UnknownProcessor (_session, **niter));
3041 /* subscribe to Sidechain IO changes */
3042 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3043 if (pi && pi->has_sidechain ()) {
3044 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3047 /* we have to note the monitor send here, otherwise a new one will be created
3048 and the state of this one will be lost.
3050 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3051 if (isend && isend->role() == Delivery::Listen) {
3052 _monitor_send = isend;
3055 /* it doesn't matter if invisible processors are added here, as they
3056 will be sorted out by setup_invisible_processors () shortly.
3059 new_order.push_back (processor);
3060 must_configure = true;
3066 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3067 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3068 _processors = new_order;
3070 if (must_configure) {
3071 configure_processors_unlocked (0, &lm);
3074 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3076 (*i)->set_owner (this);
3077 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3079 boost::shared_ptr<PluginInsert> pi;
3081 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3082 if (pi->has_no_inputs ()) {
3083 _have_internal_generator = true;
3090 reset_instrument_info ();
3091 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3092 set_processor_positions ();
3096 Route::curve_reallocate ()
3098 // _gain_automation_curve.finish_resize ();
3099 // _pan_automation_curve.finish_resize ();
3103 Route::silence (framecnt_t nframes)
3105 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3110 silence_unlocked (nframes);
3114 Route::silence_unlocked (framecnt_t nframes)
3116 /* Must be called with the processor lock held */
3120 _output->silence (nframes);
3122 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3123 boost::shared_ptr<PluginInsert> pi;
3125 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3126 // skip plugins, they don't need anything when we're not active
3130 (*i)->silence (nframes);
3133 if (nframes == _session.get_block_size()) {
3140 Route::add_internal_return ()
3143 _intreturn.reset (new InternalReturn (_session));
3144 add_processor (_intreturn, PreFader);
3149 Route::add_send_to_internal_return (InternalSend* send)
3151 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3153 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3154 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3157 return d->add_send (send);
3163 Route::remove_send_from_internal_return (InternalSend* send)
3165 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3167 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3168 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3171 return d->remove_send (send);
3177 Route::enable_monitor_send ()
3179 /* Caller must hold process lock */
3180 assert (!AudioEngine::instance()->process_lock().trylock());
3182 /* master never sends to monitor section via the normal mechanism */
3183 assert (!is_master ());
3184 assert (!is_monitor ());
3186 /* make sure we have one */
3187 if (!_monitor_send) {
3188 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3189 _monitor_send->set_display_to_user (false);
3193 configure_processors (0);
3196 /** Add an aux send to a route.
3197 * @param route route to send to.
3198 * @param before Processor to insert before, or 0 to insert at the end.
3201 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3203 assert (route != _session.monitor_out ());
3206 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3208 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3210 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3212 if (d && d->target_route() == route) {
3213 /* already listening via the specified IO: do nothing */
3221 boost::shared_ptr<InternalSend> listener;
3224 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3225 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3226 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3229 add_processor (listener, before);
3231 } catch (failed_constructor& err) {
3239 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3241 ProcessorStreams err;
3242 ProcessorList::iterator tmp;
3245 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3247 /* have to do this early because otherwise processor reconfig
3248 * will put _monitor_send back in the list
3251 if (route == _session.monitor_out()) {
3252 _monitor_send.reset ();
3256 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3258 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3260 if (d && d->target_route() == route) {
3262 if (remove_processor (*x, &err, false) > 0) {
3268 /* list could have been demolished while we dropped the lock
3271 if (_session.engine().connected()) {
3272 /* i/o processors cannot be removed if the engine is not running
3273 * so don't live-loop in case the engine is N/A or dies
3283 Route::set_comment (string cmt, void *src)
3287 _session.set_dirty ();
3291 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3293 FeedRecord fr (other, via_sends_only);
3295 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3297 if (!result.second) {
3299 /* already a record for "other" - make sure sends-only information is correct */
3300 if (!via_sends_only && result.first->sends_only) {
3301 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3302 frp->sends_only = false;
3306 return result.second;
3310 Route::clear_fed_by ()
3316 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3318 const FedBy& fed_by (other->fed_by());
3320 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3321 boost::shared_ptr<Route> sr = f->r.lock();
3323 if (sr && (sr.get() == this)) {
3325 if (via_sends_only) {
3326 *via_sends_only = f->sends_only;
3337 Route::all_inputs () const
3339 /* TODO, if this works as expected,
3340 * cache the IOVector and maintain it via
3341 * input_change_handler(), sidechain_change_handler() etc
3344 ios.push_back (_input);
3346 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3347 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3349 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3350 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3353 iop = pi->sidechain();
3356 if (iop != 0 && iop->input()) {
3357 ios.push_back (iop->input());
3364 Route::all_outputs () const
3367 // _output is included via Delivery
3368 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3369 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3370 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3371 if (iop != 0 && iop->output()) {
3372 ios.push_back (iop->output());
3379 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3381 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3382 if (other->all_inputs().fed_by (_output)) {
3383 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3384 if (via_send_only) {
3385 *via_send_only = false;
3391 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3393 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3395 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3396 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3399 iop = pi->sidechain();
3403 boost::shared_ptr<const IO> iop_out = iop->output();
3404 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3405 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3406 if (via_send_only) {
3407 *via_send_only = true;
3411 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3414 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3419 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3424 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3426 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3430 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3432 return _session._current_route_graph.feeds (shared_from_this (), other);
3435 /** Called from the (non-realtime) butler thread when the transport is stopped */
3437 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3439 framepos_t now = _session.transport_frame();
3442 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3444 Automatable::transport_stopped (now);
3446 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3448 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3452 (*i)->transport_stopped (now);
3456 _roll_delay = _initial_delay;
3460 Route::input_change_handler (IOChange change, void * /*src*/)
3462 if ((change.type & IOChange::ConfigurationChanged)) {
3463 /* This is called with the process lock held if change
3464 contains ConfigurationChanged
3466 configure_processors (0);
3467 _phase_control->resize (_input->n_ports().n_audio ());
3468 io_changed (); /* EMIT SIGNAL */
3471 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3474 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3475 if (_input->connected()) {
3476 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3477 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3481 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3482 if (does_feed && !sends_only) {
3483 if ((*i)->soloed()) {
3486 if ((*i)->solo_isolate_control()->solo_isolated()) {
3493 int delta = sbou - _solo_control->soloed_by_others_upstream();
3494 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3497 PBD::warning << string_compose (
3498 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3499 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3504 if (_solo_control->soloed_by_others_upstream()) {
3505 // ignore new connections (they're not propagated)
3507 _solo_control->mod_solo_by_others_upstream (delta);
3511 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3512 // solo-isolate currently only propagates downstream
3514 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3516 //_solo_isolated_by_upstream = ibou;
3519 // Session::route_solo_changed does not propagate indirect solo-changes
3520 // propagate downstream to tracks
3521 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3522 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3526 bool does_feed = feeds (*i, &sends_only);
3527 if (delta <= 0 && does_feed && !sends_only) {
3528 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3531 if (idelta < 0 && does_feed && !sends_only) {
3532 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3539 Route::output_change_handler (IOChange change, void * /*src*/)
3541 if (_initial_io_setup) {
3545 if ((change.type & IOChange::ConfigurationChanged)) {
3546 /* This is called with the process lock held if change
3547 contains ConfigurationChanged
3549 configure_processors (0);
3552 _session.reset_monitor_section();
3555 io_changed (); /* EMIT SIGNAL */
3558 if (_solo_control->soloed_by_others_downstream()) {
3560 /* checking all all downstream routes for
3561 * explicit of implict solo is a rather drastic measure,
3562 * ideally the input_change_handler() of the other route
3563 * would propagate the change to us.
3565 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3566 if (_output->connected()) {
3567 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3568 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3572 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3573 if (does_feed && !sends_only) {
3574 if ((*i)->soloed()) {
3581 int delta = sbod - _solo_control->soloed_by_others_downstream();
3583 // do not allow new connections to change implicit solo (no propagation)
3584 _solo_control->mod_solo_by_others_downstream (delta);
3585 // Session::route_solo_changed() does not propagate indirect solo-changes
3586 // propagate upstream to tracks
3587 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3588 if ((*i).get() == this || !can_solo()) {
3592 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3593 if (delta != 0 && does_feed && !sends_only) {
3594 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3603 Route::sidechain_change_handler (IOChange change, void* src)
3605 if (_initial_io_setup || _in_sidechain_setup) {
3609 input_change_handler (change, src);
3613 Route::pans_required () const
3615 if (n_outputs().n_audio() < 2) {
3619 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3623 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3625 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3631 if (n_outputs().n_total() == 0) {
3635 if (!_active || n_inputs() == ChanCount::ZERO) {
3636 silence_unlocked (nframes);
3640 if (session_state_changing) {
3641 if (_session.transport_speed() != 0.0f) {
3642 /* we're rolling but some state is changing (e.g. our diskstream contents)
3643 so we cannot use them. Be silent till this is over.
3645 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3647 silence_unlocked (nframes);
3650 /* we're really not rolling, so we're either delivery silence or actually
3651 monitoring, both of which are safe to do while session_state_changing is true.
3655 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3657 fill_buffers_with_input (bufs, _input, nframes);
3659 if (_meter_point == MeterInput) {
3660 _meter->run (bufs, start_frame, end_frame, nframes, true);
3663 _amp->apply_gain_automation (false);
3664 _trim->apply_gain_automation (false);
3665 passthru (bufs, start_frame, end_frame, nframes, 0);
3671 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3673 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3678 if (n_outputs().n_total() == 0) {
3682 if (!_active || n_inputs().n_total() == 0) {
3683 silence_unlocked (nframes);
3687 framepos_t unused = 0;
3689 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3695 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3697 fill_buffers_with_input (bufs, _input, nframes);
3699 if (_meter_point == MeterInput) {
3700 _meter->run (bufs, start_frame, end_frame, nframes, true);
3703 passthru (bufs, start_frame, end_frame, nframes, declick);
3709 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3716 Route::flush_processors ()
3718 /* XXX shouldn't really try to take this lock, since
3719 this is called from the RT audio thread.
3722 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3724 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3730 __attribute__((annotate("realtime")))
3733 Route::apply_processor_changes_rt ()
3735 int emissions = EmitNone;
3737 if (_pending_meter_point != _meter_point) {
3738 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3740 /* meters always have buffers for 'processor_max_streams'
3741 * they can be re-positioned without re-allocation */
3742 if (set_meter_point_unlocked()) {
3743 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3745 emissions |= EmitMeterChanged;
3750 bool changed = false;
3752 if (g_atomic_int_get (&_pending_process_reorder)) {
3753 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3755 apply_processor_order (_pending_processor_order);
3756 setup_invisible_processors ();
3758 g_atomic_int_set (&_pending_process_reorder, 0);
3759 emissions |= EmitRtProcessorChange;
3763 set_processor_positions ();
3765 if (emissions != 0) {
3766 g_atomic_int_set (&_pending_signals, emissions);
3769 return (!selfdestruct_sequence.empty ());
3773 Route::emit_pending_signals ()
3775 int sig = g_atomic_int_and (&_pending_signals, 0);
3776 if (sig & EmitMeterChanged) {
3777 _meter->emit_configuration_changed();
3778 meter_change (); /* EMIT SIGNAL */
3779 if (sig & EmitMeterVisibilityChange) {
3780 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3782 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3785 if (sig & EmitRtProcessorChange) {
3786 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3789 /* this would be a job for the butler.
3790 * Conceptually we should not take processe/processor locks here.
3791 * OTOH its more efficient (less overhead for summoning the butler and
3792 * telling her what do do) and signal emission is called
3793 * directly after the process callback, which decreases the chance
3794 * of x-runs when taking the locks.
3796 while (!selfdestruct_sequence.empty ()) {
3797 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3798 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3799 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3800 selfdestruct_sequence.pop_back ();
3803 remove_processor (proc);
3809 Route::set_meter_point (MeterPoint p, bool force)
3811 if (_pending_meter_point == p && !force) {
3815 if (force || !AudioEngine::instance()->running()) {
3816 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3817 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3818 _pending_meter_point = p;
3819 _meter->emit_configuration_changed();
3820 meter_change (); /* EMIT SIGNAL */
3821 if (set_meter_point_unlocked()) {
3822 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3824 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3827 _pending_meter_point = p;
3833 __attribute__((annotate("realtime")))
3836 Route::set_meter_point_unlocked ()
3839 /* Caller must hold process and processor write lock */
3840 assert (!AudioEngine::instance()->process_lock().trylock());
3841 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3842 assert (!lm.locked ());
3845 _meter_point = _pending_meter_point;
3847 bool meter_was_visible_to_user = _meter->display_to_user ();
3849 if (!_custom_meter_position_noted) {
3850 maybe_note_meter_position ();
3853 if (_meter_point != MeterCustom) {
3855 _meter->set_display_to_user (false);
3857 setup_invisible_processors ();
3860 _meter->set_display_to_user (true);
3862 /* If we have a previous position for the custom meter, try to put it there */
3863 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3865 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3866 if (i != _processors.end ()) {
3867 _processors.remove (_meter);
3868 _processors.insert (i, _meter);
3870 } else {// at end, right before the mains_out/panner
3871 _processors.remove (_meter);
3872 ProcessorList::iterator main = _processors.end();
3873 _processors.insert (--main, _meter);
3877 /* Set up the meter for its new position */
3879 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3883 if (loc == _processors.begin()) {
3884 m_in = _input->n_ports();
3886 ProcessorList::iterator before = loc;
3888 m_in = (*before)->output_streams ();
3891 _meter->reflect_inputs (m_in);
3893 /* we do not need to reconfigure the processors, because the meter
3894 (a) is always ready to handle processor_max_streams
3895 (b) is always an N-in/N-out processor, and thus moving
3896 it doesn't require any changes to the other processors.
3899 /* these should really be done after releasing the lock
3900 * but all those signals are subscribed to with gui_thread()
3903 return (_meter->display_to_user() != meter_was_visible_to_user);
3907 Route::listen_position_changed ()
3910 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3911 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3912 ProcessorState pstate (this);
3914 if (configure_processors_unlocked (0, &lm)) {
3915 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3917 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3922 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3923 _session.set_dirty ();
3926 boost::shared_ptr<CapturingProcessor>
3927 Route::add_export_point()
3929 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3930 if (!_capturing_processor) {
3932 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3933 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3935 _capturing_processor.reset (new CapturingProcessor (_session));
3936 _capturing_processor->activate ();
3938 configure_processors_unlocked (0, &lw);
3942 return _capturing_processor;
3946 Route::update_signal_latency ()
3948 framecnt_t l = _output->user_latency();
3949 framecnt_t lamp = 0;
3950 bool before_amp = true;
3951 framecnt_t ltrim = 0;
3952 bool before_trim = true;
3954 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3955 if ((*i)->active ()) {
3956 l += (*i)->signal_latency ();
3961 if ((*i) == _trim) {
3972 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3974 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3975 _signal_latency_at_amp_position = lamp;
3976 _signal_latency_at_trim_position = ltrim;
3978 if (_signal_latency != l) {
3979 _signal_latency = l;
3980 signal_latency_changed (); /* EMIT SIGNAL */
3983 return _signal_latency;
3987 Route::set_user_latency (framecnt_t nframes)
3989 _output->set_user_latency (nframes);
3990 _session.update_latency_compensation ();
3994 Route::set_latency_compensation (framecnt_t longest_session_latency)
3996 framecnt_t old = _initial_delay;
3998 if (_signal_latency < longest_session_latency) {
3999 _initial_delay = longest_session_latency - _signal_latency;
4004 DEBUG_TRACE (DEBUG::Latency, string_compose (
4005 "%1: compensate for maximum latency of %2,"
4006 "given own latency of %3, using initial delay of %4\n",
4007 name(), longest_session_latency, _signal_latency, _initial_delay));
4009 if (_initial_delay != old) {
4010 initial_delay_changed (); /* EMIT SIGNAL */
4013 if (_session.transport_stopped()) {
4014 _roll_delay = _initial_delay;
4019 Route::set_block_size (pframes_t nframes)
4021 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4022 (*i)->set_block_size (nframes);
4025 _session.ensure_buffers (n_process_buffers ());
4029 Route::protect_automation ()
4031 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4032 (*i)->protect_automation();
4035 /** @param declick 1 to set a pending declick fade-in,
4036 * -1 to set a pending declick fade-out
4039 Route::set_pending_declick (int declick)
4042 /* this call is not allowed to turn off a pending declick */
4044 _pending_declick = declick;
4047 _pending_declick = 0;
4051 /** Shift automation forwards from a particular place, thereby inserting time.
4052 * Adds undo commands for any shifts that are performed.
4054 * @param pos Position to start shifting from.
4055 * @param frames Amount to shift forwards by.
4059 Route::shift (framepos_t pos, framecnt_t frames)
4061 /* gain automation */
4063 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4065 XMLNode &before = gc->alist()->get_state ();
4066 gc->alist()->shift (pos, frames);
4067 XMLNode &after = gc->alist()->get_state ();
4068 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4071 /* gain automation */
4073 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4075 XMLNode &before = gc->alist()->get_state ();
4076 gc->alist()->shift (pos, frames);
4077 XMLNode &after = gc->alist()->get_state ();
4078 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4081 // TODO mute automation ??
4083 /* pan automation */
4085 ControlSet::Controls& c (_pannable->controls());
4087 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4088 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4090 boost::shared_ptr<AutomationList> al = pc->alist();
4091 XMLNode& before = al->get_state ();
4092 al->shift (pos, frames);
4093 XMLNode& after = al->get_state ();
4094 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4099 /* redirect automation */
4101 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4102 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4104 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4106 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4107 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4109 boost::shared_ptr<AutomationList> al = ac->alist();
4110 XMLNode &before = al->get_state ();
4111 al->shift (pos, frames);
4112 XMLNode &after = al->get_state ();
4113 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4121 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4123 boost::shared_ptr<Processor> processor (p.lock ());
4124 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4128 pi->set_state_dir (d);
4132 Route::save_as_template (const string& path, const string& name)
4134 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4135 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4137 XMLNode& node (state (false));
4141 IO::set_name_in_state (*node.children().front(), name);
4143 tree.set_root (&node);
4145 /* return zero on success, non-zero otherwise */
4146 return !tree.write (path.c_str());
4151 Route::set_name (const string& str)
4153 if (str == name()) {
4157 string name = Route::ensure_track_or_route_name (str, _session);
4158 SessionObject::set_name (name);
4160 bool ret = (_input->set_name(name) && _output->set_name(name));
4163 /* rename the main outs. Leave other IO processors
4164 * with whatever name they already have, because its
4165 * just fine as it is (it will not contain the route
4166 * name if its a port insert, port send or port return).
4170 if (_main_outs->set_name (name)) {
4171 /* XXX returning false here is stupid because
4172 we already changed the route name.
4182 /** Set the name of a route in an XML description.
4183 * @param node XML <Route> node to set the name in.
4184 * @param name New name.
4187 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4189 node.add_property (X_("name"), name);
4191 XMLNodeList children = node.children();
4192 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4194 if ((*i)->name() == X_("IO")) {
4196 IO::set_name_in_state (**i, name);
4198 } else if ((*i)->name() == X_("Processor")) {
4200 XMLProperty const * role = (*i)->property (X_("role"));
4201 if (role && role->value() == X_("Main")) {
4202 (*i)->add_property (X_("name"), name);
4205 } else if ((*i)->name() == X_("Diskstream")) {
4207 if (rename_playlist) {
4208 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4210 (*i)->add_property (X_("name"), name);
4216 boost::shared_ptr<Send>
4217 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4219 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4221 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4222 boost::shared_ptr<InternalSend> send;
4224 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4225 if (send->target_route() == target) {
4231 return boost::shared_ptr<Send>();
4235 Route::set_denormal_protection (bool yn)
4237 if (_denormal_protection != yn) {
4238 _denormal_protection = yn;
4239 denormal_protection_changed (); /* EMIT SIGNAL */
4244 Route::denormal_protection () const
4246 return _denormal_protection;
4250 Route::set_active (bool yn, void* src)
4252 if (_session.transport_rolling()) {
4256 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4257 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4261 if (_active != yn) {
4263 _input->set_active (yn);
4264 _output->set_active (yn);
4265 active_changed (); // EMIT SIGNAL
4266 _session.set_dirty ();
4270 boost::shared_ptr<Pannable>
4271 Route::pannable() const
4276 boost::shared_ptr<Panner>
4277 Route::panner() const
4280 return _main_outs->panner_shell()->panner();
4283 boost::shared_ptr<PannerShell>
4284 Route::panner_shell() const
4286 return _main_outs->panner_shell();
4289 boost::shared_ptr<GainControl>
4290 Route::gain_control() const
4292 return _gain_control;
4295 boost::shared_ptr<GainControl>
4296 Route::trim_control() const
4298 return _trim_control;
4301 boost::shared_ptr<PhaseControl>
4302 Route::phase_control() const
4304 return _phase_control;
4307 boost::shared_ptr<AutomationControl>
4308 Route::get_control (const Evoral::Parameter& param)
4310 /* either we own the control or .... */
4312 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4316 /* maybe one of our processors does or ... */
4318 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4319 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4320 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4328 /* nobody does so we'll make a new one */
4330 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4337 boost::shared_ptr<Processor>
4338 Route::nth_plugin (uint32_t n) const
4340 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4341 ProcessorList::const_iterator i;
4343 for (i = _processors.begin(); i != _processors.end(); ++i) {
4344 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4351 return boost::shared_ptr<Processor> ();
4354 boost::shared_ptr<Processor>
4355 Route::nth_send (uint32_t n) const
4357 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4358 ProcessorList::const_iterator i;
4360 for (i = _processors.begin(); i != _processors.end(); ++i) {
4361 if (boost::dynamic_pointer_cast<Send> (*i)) {
4363 if ((*i)->name().find (_("Monitor")) == 0) {
4364 /* send to monitor section is not considered
4365 to be an accessible send.
4376 return boost::shared_ptr<Processor> ();
4380 Route::has_io_processor_named (const string& name)
4382 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4383 ProcessorList::iterator i;
4385 for (i = _processors.begin(); i != _processors.end(); ++i) {
4386 if (boost::dynamic_pointer_cast<Send> (*i) ||
4387 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4388 if ((*i)->name() == name) {
4398 Route::set_processor_positions ()
4400 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4402 bool had_amp = false;
4403 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4404 (*i)->set_pre_fader (!had_amp);
4411 /** Called when there is a proposed change to the input port count */
4413 Route::input_port_count_changing (ChanCount to)
4415 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4417 /* The processors cannot be configured with the new input arrangement, so
4423 /* The change is ok */
4427 /** Called when there is a proposed change to the output port count */
4429 Route::output_port_count_changing (ChanCount to)
4431 if (_strict_io && !_in_configure_processors) {
4434 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4435 if (processor_out_streams.get(*t) > to.get(*t)) {
4439 /* The change is ok */
4444 Route::unknown_processors () const
4448 if (_session.get_disable_all_loaded_plugins ()) {
4449 // Do not list "missing plugins" if they are explicitly disabled
4453 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4454 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4455 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4456 p.push_back ((*i)->name ());
4465 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4467 /* we assume that all our input ports feed all our output ports. its not
4468 universally true, but the alternative is way too corner-case to worry about.
4471 LatencyRange all_connections;
4474 all_connections.min = 0;
4475 all_connections.max = 0;
4477 all_connections.min = ~((pframes_t) 0);
4478 all_connections.max = 0;
4480 /* iterate over all "from" ports and determine the latency range for all of their
4481 connections to the "outside" (outside of this Route).
4484 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4488 p->get_connected_latency_range (range, playback);
4490 all_connections.min = min (all_connections.min, range.min);
4491 all_connections.max = max (all_connections.max, range.max);
4495 /* set the "from" port latencies to the max/min range of all their connections */
4497 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4498 p->set_private_latency_range (all_connections, playback);
4501 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4503 all_connections.min += our_latency;
4504 all_connections.max += our_latency;
4506 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4507 p->set_private_latency_range (all_connections, playback);
4510 return all_connections.max;
4514 Route::set_private_port_latencies (bool playback) const
4516 framecnt_t own_latency = 0;
4518 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4519 OR LATENCY CALLBACK.
4521 This is called (early) from the latency callback. It computes the REAL
4522 latency associated with each port and stores the result as the "private"
4523 latency of the port. A later call to Route::set_public_port_latencies()
4524 sets all ports to the same value to reflect the fact that we do latency
4525 compensation and so all signals are delayed by the same amount as they
4526 flow through ardour.
4529 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4530 if ((*i)->active ()) {
4531 own_latency += (*i)->signal_latency ();
4536 /* playback: propagate latency from "outside the route" to outputs to inputs */
4537 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4539 /* capture: propagate latency from "outside the route" to inputs to outputs */
4540 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4545 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4547 /* this is called to set the JACK-visible port latencies, which take
4548 latency compensation into account.
4557 const PortSet& ports (_input->ports());
4558 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4559 p->set_public_latency_range (range, playback);
4564 const PortSet& ports (_output->ports());
4565 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4566 p->set_public_latency_range (range, playback);
4571 /** Put the invisible processors in the right place in _processors.
4572 * Must be called with a writer lock on _processor_lock held.
4575 __attribute__((annotate("realtime")))
4578 Route::setup_invisible_processors ()
4581 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4582 assert (!lm.locked ());
4586 /* too early to be doing this stuff */
4590 /* we'll build this new list here and then use it
4592 * TODO put the ProcessorList is on the stack for RT-safety.
4595 ProcessorList new_processors;
4597 /* find visible processors */
4599 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4600 if ((*i)->display_to_user ()) {
4601 new_processors.push_back (*i);
4607 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4609 if (amp == new_processors.end ()) {
4610 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4611 new_processors.push_front (_amp);
4612 amp = find (new_processors.begin(), new_processors.end(), _amp);
4615 /* and the processor after the amp */
4617 ProcessorList::iterator after_amp = amp;
4623 switch (_meter_point) {
4625 assert (!_meter->display_to_user ());
4626 new_processors.push_front (_meter);
4629 assert (!_meter->display_to_user ());
4630 new_processors.insert (amp, _meter);
4632 case MeterPostFader:
4633 /* do nothing here */
4636 /* do nothing here */
4639 /* the meter is visible, so we don't touch it here */
4646 assert (_main_outs);
4647 assert (!_main_outs->display_to_user ());
4648 new_processors.push_back (_main_outs);
4650 /* iterator for the main outs */
4652 ProcessorList::iterator main = new_processors.end();
4655 /* OUTPUT METERING */
4657 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4658 assert (!_meter->display_to_user ());
4660 /* add the processor just before or just after the main outs */
4662 ProcessorList::iterator meter_point = main;
4664 if (_meter_point == MeterOutput) {
4667 new_processors.insert (meter_point, _meter);
4672 if (_monitor_send && !is_monitor ()) {
4673 assert (!_monitor_send->display_to_user ());
4674 switch (Config->get_listen_position ()) {
4675 case PreFaderListen:
4676 switch (Config->get_pfl_position ()) {
4677 case PFLFromBeforeProcessors:
4678 new_processors.push_front (_monitor_send);
4680 case PFLFromAfterProcessors:
4681 new_processors.insert (amp, _monitor_send);
4684 _monitor_send->set_can_pan (false);
4686 case AfterFaderListen:
4687 switch (Config->get_afl_position ()) {
4688 case AFLFromBeforeProcessors:
4689 new_processors.insert (after_amp, _monitor_send);
4691 case AFLFromAfterProcessors:
4692 new_processors.insert (new_processors.end(), _monitor_send);
4695 _monitor_send->set_can_pan (true);
4700 #if 0 // not used - just yet
4701 if (!is_master() && !is_monitor() && !is_auditioner()) {
4702 new_processors.push_front (_delayline);
4706 /* MONITOR CONTROL */
4708 if (_monitor_control && is_monitor ()) {
4709 assert (!_monitor_control->display_to_user ());
4710 new_processors.insert (amp, _monitor_control);
4713 /* INTERNAL RETURN */
4715 /* doing this here means that any monitor control will come just after
4720 assert (!_intreturn->display_to_user ());
4721 new_processors.push_front (_intreturn);
4724 if (_trim && _trim->active()) {
4725 assert (!_trim->display_to_user ());
4726 new_processors.push_front (_trim);
4728 /* EXPORT PROCESSOR */
4730 if (_capturing_processor) {
4731 assert (!_capturing_processor->display_to_user ());
4732 new_processors.push_front (_capturing_processor);
4735 _processors = new_processors;
4737 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4738 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4743 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4744 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4745 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4752 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4753 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4757 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4758 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4765 /** If the meter point is `Custom', make a note of where the meter is.
4766 * This is so that if the meter point is subsequently set to something else,
4767 * and then back to custom, we can put the meter back where it was last time
4768 * custom was enabled.
4770 * Must be called with the _processor_lock held.
4773 Route::maybe_note_meter_position ()
4775 if (_meter_point != MeterCustom) {
4779 _custom_meter_position_noted = true;
4780 /* custom meter points range from after trim to before panner/main_outs
4781 * this is a limitation by the current processor UI
4783 bool seen_trim = false;
4784 _processor_after_last_custom_meter.reset();
4785 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4786 if ((*i) == _trim) {
4789 if ((*i) == _main_outs) {
4790 _processor_after_last_custom_meter = *i;
4793 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4795 _processor_after_last_custom_meter = _trim;
4797 ProcessorList::iterator j = i;
4799 assert(j != _processors.end ()); // main_outs should be before
4800 _processor_after_last_custom_meter = *j;
4805 assert(_processor_after_last_custom_meter.lock());
4808 boost::shared_ptr<Processor>
4809 Route::processor_by_id (PBD::ID id) const
4811 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4812 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4813 if ((*i)->id() == id) {
4818 return boost::shared_ptr<Processor> ();
4821 /** @return the monitoring state, or in other words what data we are pushing
4822 * into the route (data from the inputs, data from disk or silence)
4825 Route::monitoring_state () const
4827 return MonitoringInput;
4830 /** @return what we should be metering; either the data coming from the input
4831 * IO or the data that is flowing through the route.
4834 Route::metering_state () const
4836 return MeteringRoute;
4840 Route::has_external_redirects () const
4842 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4844 /* ignore inactive processors and obviously ignore the main
4845 * outs since everything has them and we don't care.
4848 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4856 boost::shared_ptr<Processor>
4857 Route::the_instrument () const
4859 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4860 return the_instrument_unlocked ();
4863 boost::shared_ptr<Processor>
4864 Route::the_instrument_unlocked () const
4866 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4867 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4868 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4872 return boost::shared_ptr<Processor>();
4878 Route::non_realtime_locate (framepos_t pos)
4881 _pannable->transport_located (pos);
4884 if (_delayline.get()) {
4885 _delayline.get()->flush();
4889 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4890 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4892 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4893 (*i)->transport_located (pos);
4896 _roll_delay = _initial_delay;
4900 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4907 * We don't currently mix MIDI input together, so we don't need the
4908 * complex logic of the audio case.
4911 n_buffers = bufs.count().n_midi ();
4913 for (i = 0; i < n_buffers; ++i) {
4915 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4916 MidiBuffer& buf (bufs.get_midi (i));
4919 buf.copy (source_port->get_midi_buffer(nframes));
4921 buf.silence (nframes);
4927 n_buffers = bufs.count().n_audio();
4929 size_t n_ports = io->n_ports().n_audio();
4930 float scaling = 1.0f;
4932 if (n_ports > n_buffers) {
4933 scaling = ((float) n_buffers) / n_ports;
4936 for (i = 0; i < n_ports; ++i) {
4938 /* if there are more ports than buffers, map them onto buffers
4939 * in a round-robin fashion
4942 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4943 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4946 if (i < n_buffers) {
4948 /* first time through just copy a channel into
4952 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4954 if (scaling != 1.0f) {
4955 buf.apply_gain (scaling, nframes);
4960 /* on subsequent times around, merge data from
4961 * the port with what is already there
4964 if (scaling != 1.0f) {
4965 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4967 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4972 /* silence any remaining buffers */
4974 for (; i < n_buffers; ++i) {
4975 AudioBuffer& buf (bufs.get_audio (i));
4976 buf.silence (nframes);
4979 /* establish the initial setup of the buffer set, reflecting what was
4980 copied into it. unless, of course, we are the auditioner, in which
4981 case nothing was fed into it from the inputs at all.
4984 if (!is_auditioner()) {
4985 bufs.set_count (io->n_ports());
4989 boost::shared_ptr<AutomationControl>
4990 Route::pan_azimuth_control() const
4993 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4995 return boost::shared_ptr<AutomationControl>();
4997 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
4998 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5000 if (!_pannable || !panner()) {
5001 return boost::shared_ptr<AutomationControl>();
5003 return _pannable->pan_azimuth_control;
5007 boost::shared_ptr<AutomationControl>
5008 Route::pan_elevation_control() const
5010 if (Profile->get_mixbus() || !_pannable || !panner()) {
5011 return boost::shared_ptr<AutomationControl>();
5014 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5016 if (c.find (PanElevationAutomation) != c.end()) {
5017 return _pannable->pan_elevation_control;
5019 return boost::shared_ptr<AutomationControl>();
5022 boost::shared_ptr<AutomationControl>
5023 Route::pan_width_control() const
5025 if (Profile->get_mixbus() || !_pannable || !panner()) {
5026 return boost::shared_ptr<AutomationControl>();
5029 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5031 if (c.find (PanWidthAutomation) != c.end()) {
5032 return _pannable->pan_width_control;
5034 return boost::shared_ptr<AutomationControl>();
5037 boost::shared_ptr<AutomationControl>
5038 Route::pan_frontback_control() const
5040 if (Profile->get_mixbus() || !_pannable || !panner()) {
5041 return boost::shared_ptr<AutomationControl>();
5044 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5046 if (c.find (PanFrontBackAutomation) != c.end()) {
5047 return _pannable->pan_frontback_control;
5049 return boost::shared_ptr<AutomationControl>();
5052 boost::shared_ptr<AutomationControl>
5053 Route::pan_lfe_control() const
5055 if (Profile->get_mixbus() || !_pannable || !panner()) {
5056 return boost::shared_ptr<AutomationControl>();
5059 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5061 if (c.find (PanLFEAutomation) != c.end()) {
5062 return _pannable->pan_lfe_control;
5064 return boost::shared_ptr<AutomationControl>();
5069 Route::eq_band_cnt () const
5071 if (Profile->get_mixbus()) {
5074 /* Ardour has no well-known EQ object */
5079 boost::shared_ptr<AutomationControl>
5080 Route::eq_gain_controllable (uint32_t band) const
5083 boost::shared_ptr<PluginInsert> eq = ch_eq();
5086 return boost::shared_ptr<AutomationControl>();
5089 uint32_t port_number;
5092 if (is_master() || mixbus()) {
5099 if (is_master() || mixbus()) {
5106 if (is_master() || mixbus()) {
5113 return boost::shared_ptr<AutomationControl>();
5116 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5118 return boost::shared_ptr<AutomationControl>();
5121 boost::shared_ptr<AutomationControl>
5122 Route::eq_freq_controllable (uint32_t band) const
5126 if (mixbus() || is_master()) {
5127 /* no frequency controls for mixbusses or master */
5128 return boost::shared_ptr<AutomationControl>();
5131 boost::shared_ptr<PluginInsert> eq = ch_eq();
5134 return boost::shared_ptr<AutomationControl>();
5137 uint32_t port_number;
5149 return boost::shared_ptr<AutomationControl>();
5152 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5154 return boost::shared_ptr<AutomationControl>();
5158 boost::shared_ptr<AutomationControl>
5159 Route::eq_q_controllable (uint32_t band) const
5161 return boost::shared_ptr<AutomationControl>();
5164 boost::shared_ptr<AutomationControl>
5165 Route::eq_shape_controllable (uint32_t band) const
5167 return boost::shared_ptr<AutomationControl>();
5170 boost::shared_ptr<AutomationControl>
5171 Route::eq_enable_controllable () const
5174 boost::shared_ptr<PluginInsert> eq = ch_eq();
5177 return boost::shared_ptr<AutomationControl>();
5180 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5182 return boost::shared_ptr<AutomationControl>();
5186 boost::shared_ptr<AutomationControl>
5187 Route::eq_hpf_controllable () const
5190 boost::shared_ptr<PluginInsert> eq = ch_eq();
5193 return boost::shared_ptr<AutomationControl>();
5196 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5198 return boost::shared_ptr<AutomationControl>();
5203 Route::eq_band_name (uint32_t band) const
5205 if (Profile->get_mixbus()) {
5221 boost::shared_ptr<AutomationControl>
5222 Route::comp_enable_controllable () const
5225 boost::shared_ptr<PluginInsert> comp = ch_comp();
5228 return boost::shared_ptr<AutomationControl>();
5231 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5233 return boost::shared_ptr<AutomationControl>();
5236 boost::shared_ptr<AutomationControl>
5237 Route::comp_threshold_controllable () const
5240 boost::shared_ptr<PluginInsert> comp = ch_comp();
5243 return boost::shared_ptr<AutomationControl>();
5246 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5249 return boost::shared_ptr<AutomationControl>();
5252 boost::shared_ptr<AutomationControl>
5253 Route::comp_speed_controllable () const
5256 boost::shared_ptr<PluginInsert> comp = ch_comp();
5259 return boost::shared_ptr<AutomationControl>();
5262 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5264 return boost::shared_ptr<AutomationControl>();
5267 boost::shared_ptr<AutomationControl>
5268 Route::comp_mode_controllable () const
5271 boost::shared_ptr<PluginInsert> comp = ch_comp();
5274 return boost::shared_ptr<AutomationControl>();
5277 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5279 return boost::shared_ptr<AutomationControl>();
5282 boost::shared_ptr<AutomationControl>
5283 Route::comp_makeup_controllable () const
5286 boost::shared_ptr<PluginInsert> comp = ch_comp();
5289 return boost::shared_ptr<AutomationControl>();
5292 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5294 return boost::shared_ptr<AutomationControl>();
5297 boost::shared_ptr<AutomationControl>
5298 Route::comp_redux_controllable () const
5301 boost::shared_ptr<PluginInsert> comp = ch_comp();
5304 return boost::shared_ptr<AutomationControl>();
5307 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5309 return boost::shared_ptr<AutomationControl>();
5314 Route::comp_mode_name (uint32_t mode) const
5319 return _("Leveler");
5321 return _("Compressor");
5323 return _("Limiter");
5325 return mixbus() ? _("Sidechain") : _("Limiter");
5335 Route::comp_speed_name (uint32_t mode) const
5353 boost::shared_ptr<AutomationControl>
5354 Route::send_level_controllable (uint32_t n) const
5357 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5359 return boost::shared_ptr<AutomationControl>();
5364 return boost::shared_ptr<AutomationControl>();
5367 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5368 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5370 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5372 return boost::shared_ptr<AutomationControl>();
5374 return s->gain_control ();
5378 boost::shared_ptr<AutomationControl>
5379 Route::send_enable_controllable (uint32_t n) const
5382 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5384 return boost::shared_ptr<AutomationControl>();
5389 return boost::shared_ptr<AutomationControl>();
5392 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5393 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5395 /* although Ardour sends have enable/disable as part of the Processor
5396 API, it is not exposed as a controllable.
5398 XXX: we should fix this.
5400 return boost::shared_ptr<AutomationControl>();
5405 Route::send_name (uint32_t n) const
5411 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5415 boost::shared_ptr<Processor> p = nth_send (n);
5424 boost::shared_ptr<AutomationControl>
5425 Route::master_send_enable_controllable () const
5428 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5430 return boost::shared_ptr<AutomationControl>();
5432 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5434 return boost::shared_ptr<AutomationControl>();
5439 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5441 if (!vca || !_gain_control) {
5445 return _gain_control->slaved_to (vca->gain_control());
5449 Route::vca_assign (boost::shared_ptr<VCA> vca)
5451 _gain_control->add_master (vca->gain_control());
5452 _solo_control->add_master (vca->solo_control());
5453 _mute_control->add_master (vca->mute_control());
5457 Route::vca_unassign (boost::shared_ptr<VCA> vca)
5460 /* unassign from all */
5461 _gain_control->clear_masters ();
5462 _solo_control->clear_masters ();
5463 _mute_control->clear_masters ();
5465 _gain_control->remove_master (vca->gain_control());
5466 _solo_control->remove_master (vca->solo_control());
5467 _mute_control->remove_master (vca->mute_control());
5472 Route::muted_by_others_soloing () const
5474 if (!can_be_muted_by_others ()) {
5478 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5482 Route::clear_all_solo_state ()
5484 double v = _solo_safe_control->get_value ();
5486 _solo_control->clear_all_solo_state ();
5489 _solo_safe_control->set_value (v, Controllable::NoGroup);