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::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
85 /** Base class for all routable/mixable objects (tracks and busses) */
86 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
87 : Stripable (sess, name, PresentationInfo (flag))
88 , GraphNode (sess._process_graph)
89 , Muteable (sess, name)
93 , _signal_latency_at_amp_position (0)
94 , _signal_latency_at_trim_position (0)
97 , _pending_process_reorder (0)
98 , _pending_signals (0)
99 , _pending_declick (true)
100 , _meter_point (MeterPostFader)
101 , _pending_meter_point (MeterPostFader)
102 , _meter_type (MeterPeak)
103 , _denormal_protection (false)
106 , _declickable (false)
107 , _have_internal_generator (false)
108 , _default_type (default_type)
110 , _in_configure_processors (false)
111 , _initial_io_setup (false)
112 , _in_sidechain_setup (false)
114 , _custom_meter_position_noted (false)
117 processor_max_streams.reset();
123 /* set default meter type */
125 _meter_type = Config->get_meter_type_master ();
127 else if (dynamic_cast<Track*>(this)) {
128 _meter_type = Config->get_meter_type_track ();
130 _meter_type = Config->get_meter_type_bus ();
133 /* add standard controls */
135 _gain_control.reset (new GainControl (_session, GainAutomation));
136 add_control (_gain_control);
138 _trim_control.reset (new GainControl (_session, TrimAutomation));
139 add_control (_trim_control);
141 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
142 add_control (_solo_control);
143 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
145 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
146 add_control (_mute_control);
148 _phase_control.reset (new PhaseControl (_session, X_("phase")));
149 add_control (_phase_control);
151 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
152 add_control (_solo_isolate_control);
154 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
155 add_control (_solo_safe_control);
159 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
160 _pannable.reset (new Pannable (_session));
163 /* input and output objects */
165 _input.reset (new IO (_session, _name, IO::Input, _default_type));
166 _output.reset (new IO (_session, _name, IO::Output, _default_type));
168 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
169 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
171 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
172 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
174 /* add the amp/fader processor.
175 * it should be the first processor to be added on every route.
178 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
179 add_processor (_amp, PostFader);
182 _amp->set_display_name (_("Monitor"));
185 #if 0 // not used - just yet
186 if (!is_master() && !is_monitor() && !is_auditioner()) {
187 _delayline.reset (new DelayLine (_session, _name));
188 add_processor (_delayline, PreFader);
194 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
195 _trim->set_display_to_user (false);
197 if (dynamic_cast<AudioTrack*>(this)) {
198 /* we can't do this in the AudioTrack's constructor
199 * because _trim does not exit then
203 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
208 /* create standard processors: meter, main outs, monitor out;
209 they will be added to _processors by setup_invisible_processors ()
212 _meter.reset (new PeakMeter (_session, _name));
213 _meter->set_owner (this);
214 _meter->set_display_to_user (false);
217 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
218 _main_outs->activate ();
221 /* where we listen to tracks */
222 _intreturn.reset (new InternalReturn (_session));
223 _intreturn->activate ();
225 /* the thing that provides proper control over a control/monitor/listen bus
226 (such as per-channel cut, dim, solo, invert, etc).
228 _monitor_control.reset (new MonitorProcessor (_session));
229 _monitor_control->activate ();
232 if (is_master() || is_monitor() || is_auditioner()) {
233 _mute_master->set_solo_ignore (true);
236 /* now that we have _meter, its safe to connect to this */
239 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
240 configure_processors (0);
248 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
250 /* do this early so that we don't get incoming signals as we are going through destruction
255 /* don't use clear_processors here, as it depends on the session which may
256 be half-destroyed by now
259 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
260 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
261 (*i)->drop_references ();
264 _processors.clear ();
268 Route::ensure_track_or_route_name(string name, Session &session)
270 string newname = name;
272 while (!session.io_name_is_legal (newname)) {
273 newname = bump_name_once (newname, ' ');
280 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
282 // TODO route group, see set_gain()
283 // _trim_control->route_set_value (val);
287 Route::maybe_declick (BufferSet&, framecnt_t, int)
289 /* this is the "bus" implementation and they never declick.
294 /** Process this route for one (sub) cycle (process thread)
296 * @param bufs Scratch buffers to use for the signal path
297 * @param start_frame Initial transport frame
298 * @param end_frame Final transport frame
299 * @param nframes Number of frames to output (to ports)
301 * Note that (end_frame - start_frame) may not be equal to nframes when the
302 * transport speed isn't 1.0 (eg varispeed).
305 Route::process_output_buffers (BufferSet& bufs,
306 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
307 int declick, bool gain_automation_ok)
309 /* Caller must hold process lock */
310 assert (!AudioEngine::instance()->process_lock().trylock());
312 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
314 // can this actually happen? functions calling process_output_buffers()
315 // already take a reader-lock.
316 bufs.silence (nframes, 0);
320 _mute_control->automation_run (start_frame, nframes);
322 /* figure out if we're going to use gain automation */
323 if (gain_automation_ok) {
324 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
325 _amp->setup_gain_automation (
326 start_frame + _signal_latency_at_amp_position,
327 end_frame + _signal_latency_at_amp_position,
330 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
331 _trim->setup_gain_automation (
332 start_frame + _signal_latency_at_trim_position,
333 end_frame + _signal_latency_at_trim_position,
336 _amp->apply_gain_automation (false);
337 _trim->apply_gain_automation (false);
340 /* Tell main outs what to do about monitoring. We do this so that
341 on a transition between monitoring states we get a de-clicking gain
342 change in the _main_outs delivery, if config.get_use_monitor_fades()
345 We override this in the case where we have an internal generator.
347 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
349 _main_outs->no_outs_cuz_we_no_monitor (silence);
351 /* -------------------------------------------------------------------------------------------
352 GLOBAL DECLICK (for transport changes etc.)
353 ----------------------------------------------------------------------------------------- */
355 maybe_declick (bufs, nframes, declick);
356 _pending_declick = 0;
358 /* -------------------------------------------------------------------------------------------
359 DENORMAL CONTROL/PHASE INVERT
360 ----------------------------------------------------------------------------------------- */
362 if (!_phase_control->none()) {
366 if (_denormal_protection || Config->get_denormal_protection()) {
368 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
369 Sample* const sp = i->data();
371 if (_phase_control->inverted (chn)) {
372 for (pframes_t nx = 0; nx < nframes; ++nx) {
377 for (pframes_t nx = 0; nx < nframes; ++nx) {
385 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
386 Sample* const sp = i->data();
388 if (_phase_control->inverted (chn)) {
389 for (pframes_t nx = 0; nx < nframes; ++nx) {
398 if (_denormal_protection || Config->get_denormal_protection()) {
400 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
401 Sample* const sp = i->data();
402 for (pframes_t nx = 0; nx < nframes; ++nx) {
410 /* -------------------------------------------------------------------------------------------
412 ----------------------------------------------------------------------------------------- */
414 /* set this to be true if the meter will already have been ::run() earlier */
415 bool const meter_already_run = metering_state() == MeteringInput;
417 framecnt_t latency = 0;
418 const double speed = _session.transport_speed ();
420 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
422 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
423 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
428 /* if it has any inputs, make sure they match */
429 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
430 if (bufs.count() != (*i)->input_streams()) {
432 DEBUG::Processors, string_compose (
433 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
434 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
441 /* should we NOT run plugins here if the route is inactive?
442 do we catch route != active somewhere higher?
445 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
446 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
448 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
449 const framecnt_t longest_session_latency = _initial_delay + _signal_latency;
450 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
451 _initial_delay + latency, longest_session_latency - latency);
454 (*i)->run (bufs, start_frame - latency, end_frame - latency, speed, nframes, *i != _processors.back());
455 bufs.set_count ((*i)->output_streams());
457 if ((*i)->active ()) {
458 latency += (*i)->signal_latency ();
464 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
465 boost::shared_ptr<Processor> endpoint,
466 bool include_endpoint, bool for_export, bool for_freeze)
468 /* If no processing is required, there's no need to go any further. */
469 if (!endpoint && !include_endpoint) {
473 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
474 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
475 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
477 /* trim is always at the top, for bounce no latency compensation is needed */
478 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
479 _trim->setup_gain_automation (start, start + nframes, nframes);
482 const double speed = _session.transport_speed ();
483 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
485 if (!include_endpoint && (*i) == endpoint) {
489 /* if we're *not* exporting, stop processing if we come across a routing processor. */
490 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
493 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
497 /* special case the panner (export outputs)
498 * Ideally we'd only run the panner, not the delivery itself...
499 * but panners need separate input/output buffers and some context
500 * (panshell, panner type, etc). AFAICT there is no ill side effect
501 * of re-using the main delivery when freewheeling/exporting a region.
503 if ((*i) == _main_outs) {
504 assert ((*i)->does_routing());
505 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
506 buffers.set_count ((*i)->output_streams());
509 /* don't run any processors that do routing.
510 * Also don't bother with metering.
512 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
513 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
514 buffers.set_count ((*i)->output_streams());
515 latency += (*i)->signal_latency ();
518 if ((*i) == endpoint) {
525 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
526 bool include_endpoint, bool for_export, bool for_freeze) const
528 framecnt_t latency = 0;
529 if (!endpoint && !include_endpoint) {
533 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
534 if (!include_endpoint && (*i) == endpoint) {
537 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
540 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
543 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
544 latency += (*i)->signal_latency ();
546 if ((*i) == endpoint) {
554 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
555 bool include_endpoint, bool for_export, bool for_freeze) const
557 if (!endpoint && !include_endpoint) {
561 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
562 if (!include_endpoint && (*i) == endpoint) {
565 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
568 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
571 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
572 cc = (*i)->output_streams();
574 if ((*i) == endpoint) {
582 Route::n_process_buffers ()
584 return max (_input->n_ports(), processor_max_streams);
588 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
590 assert (is_monitor());
591 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
592 fill_buffers_with_input (bufs, _input, nframes);
593 passthru (bufs, start_frame, end_frame, nframes, declick);
597 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
601 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
603 /* control/monitor bus ignores input ports when something is
604 feeding the listen "stream". data will "arrive" into the
605 route from the intreturn processor element.
608 bufs.silence (nframes, 0);
611 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
612 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
616 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
618 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
620 bufs.set_count (_input->n_ports());
621 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
622 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
626 Route::set_listen (bool yn)
630 _monitor_send->activate ();
632 _monitor_send->deactivate ();
638 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
640 /* nothing to do if we're not using AFL/PFL. But if we are, we need
641 to alter the active state of the monitor send.
644 if (Config->get_solo_control_is_listen_control ()) {
645 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
650 Route::push_solo_isolate_upstream (int32_t delta)
652 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
654 boost::shared_ptr<RouteList> routes = _session.get_routes ();
655 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
657 if ((*i).get() == this || !(*i)->can_solo()) {
662 bool does_feed = feeds (*i, &sends_only);
664 if (does_feed && !sends_only) {
665 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
671 Route::push_solo_upstream (int delta)
673 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
674 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
678 boost::shared_ptr<Route> sr (i->r.lock());
680 sr->solo_control()->mod_solo_by_others_downstream (-delta);
687 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
689 cerr << name << " {" << endl;
690 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
691 p != procs.end(); ++p) {
692 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
698 /** Supposing that we want to insert a Processor at a given Placement, return
699 * the processor to add the new one before (or 0 to add at the end).
701 boost::shared_ptr<Processor>
702 Route::before_processor_for_placement (Placement p)
704 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
706 ProcessorList::iterator loc;
709 /* generic pre-fader: insert immediately before the amp */
710 loc = find (_processors.begin(), _processors.end(), _amp);
712 /* generic post-fader: insert right before the main outs */
713 loc = find (_processors.begin(), _processors.end(), _main_outs);
716 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
719 /** Supposing that we want to insert a Processor at a given index, return
720 * the processor to add the new one before (or 0 to add at the end).
722 boost::shared_ptr<Processor>
723 Route::before_processor_for_index (int index)
726 return boost::shared_ptr<Processor> ();
729 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
731 ProcessorList::iterator i = _processors.begin ();
733 while (i != _processors.end() && j < index) {
734 if ((*i)->display_to_user()) {
741 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
744 /** Add a processor either pre- or post-fader
745 * @return 0 on success, non-0 on failure.
748 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
750 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
754 /** Add a processor to a route such that it ends up with a given index into the visible processors.
755 * @param index Index to add the processor at, or -1 to add at the end of the list.
756 * @return 0 on success, non-0 on failure.
759 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
761 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
764 /** Add a processor to the route.
765 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
766 * @return 0 on success, non-0 on failure.
769 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
771 assert (processor != _meter);
772 assert (processor != _main_outs);
774 DEBUG_TRACE (DEBUG::Processors, string_compose (
775 "%1 adding processor %2\n", name(), processor->name()));
779 pl.push_back (processor);
780 int rv = add_processors (pl, before, err);
786 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
787 processor->activate ();
794 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
796 /* We cannot destruct the processor here (usually RT-thread
797 * with various locks held - in case of sends also io_locks).
798 * Queue for deletion in low-priority thread.
800 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
801 selfdestruct_sequence.push_back (wp);
805 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
807 XMLProperty const * prop;
810 boost::shared_ptr<Processor> processor;
812 /* bit of a hack: get the `placement' property from the <Redirect> tag here
813 so that we can add the processor in the right place (pre/post-fader)
816 XMLNodeList const & children = node.children ();
817 XMLNodeList::const_iterator i = children.begin ();
819 while (i != children.end() && (*i)->name() != X_("Redirect")) {
823 Placement placement = PreFader;
825 if (i != children.end()) {
826 if ((prop = (*i)->property (X_("placement"))) != 0) {
827 placement = Placement (string_2_enum (prop->value(), placement));
831 if (node.name() == "Insert") {
833 if ((prop = node.property ("type")) != 0) {
835 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
836 prop->value() == "lv2" ||
837 prop->value() == "windows-vst" ||
838 prop->value() == "lxvst" ||
839 prop->value() == "audiounit") {
841 if (_session.get_disable_all_loaded_plugins ()) {
842 processor.reset (new UnknownProcessor (_session, node));
844 processor.reset (new PluginInsert (_session));
845 processor->set_owner (this);
850 processor.reset (new PortInsert (_session, _pannable, _mute_master));
855 } else if (node.name() == "Send") {
857 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
858 processor.reset (new Send (_session, sendpan, _mute_master));
862 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
866 if (processor->set_state (node, version)) {
870 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
871 if (i != children.end()) {
872 if ((prop = (*i)->property (X_("active"))) != 0) {
873 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
874 processor->activate();
876 processor->deactivate();
880 return (add_processor (processor, placement, 0, false) == 0);
883 catch (failed_constructor &err) {
884 warning << _("processor could not be created. Ignored.") << endmsg;
890 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
891 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
894 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
895 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
899 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
901 ProcessorList::iterator loc;
904 loc = find(_processors.begin(), _processors.end(), before);
905 if (loc == _processors.end ()) {
909 /* nothing specified - at end */
910 loc = _processors.end ();
913 if (!AudioEngine::instance()->connected()) {
917 if (others.empty()) {
921 ProcessorList to_skip;
923 // check if there's an instrument to replace or configure
924 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
925 boost::shared_ptr<PluginInsert> pi;
926 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
929 if (!pi->plugin ()->get_info ()->is_instrument ()) {
932 boost::shared_ptr<Processor> instrument = the_instrument ();
933 ChanCount in (DataType::MIDI, 1);
934 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
936 PluginSetupOptions flags = None;
939 in = instrument->input_streams ();
940 out = instrument->output_streams ();
942 if (pi->has_output_presets (in, out)) {
946 pi->set_strict_io (_strict_io);
948 PluginSetupOptions mask = None;
949 if (Config->get_ask_replace_instrument ()) {
952 if (Config->get_ask_setup_instrument ()) {
959 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
960 switch (rv.get_value_or (0)) {
962 to_skip.push_back (*i); // don't add this one;
965 replace_processor (instrument, *i, err);
966 to_skip.push_back (*i);
975 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
976 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
977 ProcessorState pstate (this);
979 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
984 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
985 if (check != to_skip.end()) {
989 boost::shared_ptr<PluginInsert> pi;
991 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
992 pi->set_strict_io (_strict_io);
996 /* Ensure that only one amp is in the list at any time */
997 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
998 if (check != _processors.end()) {
999 if (before == _amp) {
1000 /* Already in position; all is well */
1003 _processors.erase (check);
1008 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1010 _processors.insert (loc, *i);
1011 (*i)->set_owner (this);
1014 if (configure_processors_unlocked (err, &lm)) {
1016 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1021 if ((*i)->active()) {
1022 // why? emit ActiveChanged() ??
1026 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1028 boost::shared_ptr<Send> send;
1029 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1030 send->SelfDestruct.connect_same_thread (*this,
1031 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1035 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1036 boost::shared_ptr<PluginInsert> pi;
1038 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1039 if (pi->has_no_inputs ()) {
1040 _have_internal_generator = true;
1046 _output->set_user_latency (0);
1049 reset_instrument_info ();
1050 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1051 set_processor_positions ();
1057 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1059 if (p == PreFader) {
1060 start = _processors.begin();
1061 end = find(_processors.begin(), _processors.end(), _amp);
1063 start = find(_processors.begin(), _processors.end(), _amp);
1065 end = _processors.end();
1069 /** Turn off all processors with a given placement
1070 * @param p Placement of processors to disable
1073 Route::disable_processors (Placement p)
1075 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1077 ProcessorList::iterator start, end;
1078 placement_range(p, start, end);
1080 for (ProcessorList::iterator i = start; i != end; ++i) {
1081 (*i)->enable (false);
1084 _session.set_dirty ();
1087 /** Turn off all redirects
1090 Route::disable_processors ()
1092 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1094 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1095 (*i)->enable (false);
1098 _session.set_dirty ();
1101 /** Turn off all redirects with a given placement
1102 * @param p Placement of redirects to disable
1105 Route::disable_plugins (Placement p)
1107 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1109 ProcessorList::iterator start, end;
1110 placement_range(p, start, end);
1112 for (ProcessorList::iterator i = start; i != end; ++i) {
1113 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1114 (*i)->enable (false);
1118 _session.set_dirty ();
1121 /** Turn off all plugins
1124 Route::disable_plugins ()
1126 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1128 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1129 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1130 (*i)->enable (false);
1134 _session.set_dirty ();
1139 Route::ab_plugins (bool forward)
1141 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1145 /* forward = turn off all active redirects, and mark them so that the next time
1146 we go the other way, we will revert them
1149 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1150 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1154 if ((*i)->enabled ()) {
1155 (*i)->enable (false);
1156 (*i)->set_next_ab_is_active (true);
1158 (*i)->set_next_ab_is_active (false);
1164 /* backward = if the redirect was marked to go active on the next ab, do so */
1166 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1168 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1172 (*i)->enable ((*i)->get_next_ab_is_active ());
1176 _session.set_dirty ();
1180 /** Remove processors with a given placement.
1181 * @param p Placement of processors to remove.
1184 Route::clear_processors (Placement p)
1186 if (!_session.engine().connected()) {
1190 bool already_deleting = _session.deletion_in_progress();
1191 if (!already_deleting) {
1192 _session.set_deletion_in_progress();
1196 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1197 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1198 ProcessorList new_list;
1199 ProcessorStreams err;
1200 bool seen_amp = false;
1202 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1208 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1210 /* you can't remove these */
1212 new_list.push_back (*i);
1219 new_list.push_back (*i);
1222 (*i)->drop_references ();
1230 (*i)->drop_references ();
1233 new_list.push_back (*i);
1240 _processors = new_list;
1241 configure_processors_unlocked (&err, &lm); // this can't fail
1244 processor_max_streams.reset();
1245 _have_internal_generator = false;
1246 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1247 set_processor_positions ();
1249 reset_instrument_info ();
1251 if (!already_deleting) {
1252 _session.clear_deletion_in_progress();
1257 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1259 // TODO once the export point can be configured properly, do something smarter here
1260 if (processor == _capturing_processor) {
1261 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1262 if (need_process_lock) {
1266 _capturing_processor.reset();
1268 if (need_process_lock) {
1273 /* these can never be removed */
1275 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1279 if (!_session.engine().connected()) {
1283 processor_max_streams.reset();
1286 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1287 if (need_process_lock) {
1291 /* Caller must hold process lock */
1292 assert (!AudioEngine::instance()->process_lock().trylock());
1294 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1296 ProcessorState pstate (this);
1298 ProcessorList::iterator i;
1299 bool removed = false;
1301 for (i = _processors.begin(); i != _processors.end(); ) {
1302 if (*i == processor) {
1304 /* move along, see failure case for configure_processors()
1305 where we may need to reconfigure the processor.
1308 /* stop redirects that send signals to JACK ports
1309 from causing noise as a result of no longer being
1313 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1314 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1318 iop = pi->sidechain();
1325 i = _processors.erase (i);
1333 _output->set_user_latency (0);
1341 if (configure_processors_unlocked (err, &lm)) {
1343 /* we know this will work, because it worked before :) */
1344 configure_processors_unlocked (0, &lm);
1348 _have_internal_generator = false;
1350 for (i = _processors.begin(); i != _processors.end(); ++i) {
1351 boost::shared_ptr<PluginInsert> pi;
1353 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1354 if (pi->has_no_inputs ()) {
1355 _have_internal_generator = true;
1360 if (need_process_lock) {
1365 reset_instrument_info ();
1366 processor->drop_references ();
1367 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1368 set_processor_positions ();
1374 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1376 /* these can never be removed */
1377 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1380 /* and can't be used as substitute, either */
1381 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1385 /* I/Os are out, too */
1386 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1390 /* this function cannot be used to swap/reorder processors */
1391 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1395 if (!AudioEngine::instance()->connected() || !old || !sub) {
1399 /* ensure that sub is not owned by another route */
1400 if (sub->owner ()) {
1405 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1406 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1407 ProcessorState pstate (this);
1409 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1411 ProcessorList::iterator i;
1412 bool replaced = false;
1413 bool enable = old->enabled ();
1415 for (i = _processors.begin(); i != _processors.end(); ) {
1417 i = _processors.erase (i);
1418 _processors.insert (i, sub);
1419 sub->set_owner (this);
1432 boost::shared_ptr<PluginInsert> pi;
1433 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1434 pi->set_strict_io (true);
1438 if (configure_processors_unlocked (err, &lm)) {
1440 configure_processors_unlocked (0, &lm);
1444 _have_internal_generator = false;
1446 for (i = _processors.begin(); i != _processors.end(); ++i) {
1447 boost::shared_ptr<PluginInsert> pi;
1448 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1449 if (pi->has_no_inputs ()) {
1450 _have_internal_generator = true;
1460 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1461 _output->set_user_latency (0);
1464 reset_instrument_info ();
1465 old->drop_references ();
1466 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1467 set_processor_positions ();
1472 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1474 ProcessorList deleted;
1476 if (!_session.engine().connected()) {
1480 processor_max_streams.reset();
1483 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1484 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1485 ProcessorState pstate (this);
1487 ProcessorList::iterator i;
1488 boost::shared_ptr<Processor> processor;
1490 for (i = _processors.begin(); i != _processors.end(); ) {
1494 /* these can never be removed */
1496 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1501 /* see if its in the list of processors to delete */
1503 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1508 /* stop IOProcessors that send to JACK ports
1509 from causing noise as a result of no longer being
1513 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1514 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1517 iop = pi->sidechain();
1524 deleted.push_back (processor);
1525 i = _processors.erase (i);
1528 if (deleted.empty()) {
1529 /* none of those in the requested list were found */
1533 _output->set_user_latency (0);
1535 if (configure_processors_unlocked (err, &lm)) {
1537 /* we know this will work, because it worked before :) */
1538 configure_processors_unlocked (0, &lm);
1543 _have_internal_generator = false;
1545 for (i = _processors.begin(); i != _processors.end(); ++i) {
1546 boost::shared_ptr<PluginInsert> pi;
1548 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1549 if (pi->has_no_inputs ()) {
1550 _have_internal_generator = true;
1557 /* now try to do what we need to so that those that were removed will be deleted */
1559 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1560 (*i)->drop_references ();
1563 reset_instrument_info ();
1564 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1565 set_processor_positions ();
1571 Route::reset_instrument_info ()
1573 boost::shared_ptr<Processor> instr = the_instrument();
1575 _instrument_info.set_internal_instrument (instr);
1579 /** Caller must hold process lock */
1581 Route::configure_processors (ProcessorStreams* err)
1583 #ifndef PLATFORM_WINDOWS
1584 assert (!AudioEngine::instance()->process_lock().trylock());
1587 if (!_in_configure_processors) {
1588 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1589 return configure_processors_unlocked (err, &lm);
1596 Route::input_streams () const
1598 return _input->n_ports ();
1601 list<pair<ChanCount, ChanCount> >
1602 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1604 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1606 return try_configure_processors_unlocked (in, err);
1609 list<pair<ChanCount, ChanCount> >
1610 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1612 // Check each processor in order to see if we can configure as requested
1614 list<pair<ChanCount, ChanCount> > configuration;
1617 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1618 DEBUG_TRACE (DEBUG::Processors, "{\n");
1620 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1622 if ((*p)->can_support_io_configuration(in, out)) {
1624 if (boost::dynamic_pointer_cast<Delivery> (*p)
1625 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1627 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1628 /* with strict I/O the panner + output are forced to
1629 * follow the last processor's output.
1631 * Delivery::can_support_io_configuration() will only add ports,
1632 * but not remove excess ports.
1634 * This works because the delivery only requires
1635 * as many outputs as there are inputs.
1636 * Delivery::configure_io() will do the actual removal
1637 * by calling _output->ensure_io()
1639 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1640 /* ..but at least as many as there are master-inputs, if
1641 * the delivery is dealing with audio */
1642 // XXX this may need special-casing for mixbus (master-outputs)
1643 // and should maybe be a preference anyway ?!
1644 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1650 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1651 configuration.push_back(make_pair(in, out));
1654 // restriction for Monitor Section Processors
1655 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1656 /* do not allow to add/remove channels (for now)
1657 * The Monitor follows the master-bus and has no panner (unpan)
1658 * but do allow processors with midi-in to be added (e.g VSTs with control that
1659 * will remain unconnected)
1661 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1662 return list<pair<ChanCount, ChanCount> > ();
1664 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1665 // internal sends make no sense, only feedback
1666 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1667 return list<pair<ChanCount, ChanCount> > ();
1669 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1670 /* External Sends can be problematic. one can add/remove ports
1671 * there signal leaves the DAW to external monitors anyway, so there's
1672 * no real use for allowing them here anyway.
1674 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1675 return list<pair<ChanCount, ChanCount> > ();
1677 if (boost::dynamic_pointer_cast<Send> (*p)) {
1679 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1680 return list<pair<ChanCount, ChanCount> > ();
1689 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1690 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1691 DEBUG_TRACE (DEBUG::Processors, "}\n");
1692 return list<pair<ChanCount, ChanCount> > ();
1696 DEBUG_TRACE (DEBUG::Processors, "}\n");
1698 return configuration;
1701 /** Set the input/output configuration of each processor in the processors list.
1702 * Caller must hold process lock.
1703 * Return 0 on success, otherwise configuration is impossible.
1706 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1708 #ifndef PLATFORM_WINDOWS
1709 assert (!AudioEngine::instance()->process_lock().trylock());
1712 if (_in_configure_processors) {
1716 /* put invisible processors where they should be */
1717 setup_invisible_processors ();
1719 _in_configure_processors = true;
1721 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1723 if (configuration.empty ()) {
1724 _in_configure_processors = false;
1729 bool seen_mains_out = false;
1730 processor_out_streams = _input->n_ports();
1731 processor_max_streams.reset();
1733 /* processor configure_io() may result in adding ports
1734 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1736 * with jack2 adding ports results in a graph-order callback,
1737 * which calls Session::resort_routes() and eventually
1738 * Route::direct_feeds_according_to_reality()
1739 * which takes a ReaderLock (_processor_lock).
1741 * so we can't hold a WriterLock here until jack2 threading
1744 * NB. we still hold the process lock
1746 * (ardour's own engines do call graph-order from the
1747 * process-thread and hence do not have this issue; besides
1748 * merely adding ports won't trigger a graph-order, only
1749 * making connections does)
1753 // TODO check for a potential ReaderLock after ReaderLock ??
1754 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1756 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1757 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1759 if (!(*p)->configure_io(c->first, c->second)) {
1760 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1761 _in_configure_processors = false;
1766 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1767 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1769 boost::shared_ptr<IOProcessor> iop;
1770 boost::shared_ptr<PluginInsert> pi;
1771 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1772 /* plugins connected via Split or Hide Match may have more channels.
1773 * route/scratch buffers are needed for all of them
1774 * The configuration may only be a subset (both input and output)
1776 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1778 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1779 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1780 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1784 if (boost::dynamic_pointer_cast<Delivery> (*p)
1785 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1786 /* main delivery will increase port count to match input.
1787 * the Delivery::Main is usually the last processor - followed only by
1790 seen_mains_out = true;
1792 if (!seen_mains_out) {
1793 processor_out_streams = out;
1802 _meter->set_max_channels (processor_max_streams);
1805 /* make sure we have sufficient scratch buffers to cope with the new processor
1808 _session.ensure_buffers (n_process_buffers ());
1810 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1812 _in_configure_processors = false;
1816 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1817 * @param state New active state for those processors.
1820 Route::all_visible_processors_active (bool state)
1822 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1824 if (_processors.empty()) {
1828 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1829 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1832 (*i)->enable (state);
1835 _session.set_dirty ();
1839 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1841 /* check if re-order requires re-configuration of any processors
1842 * -> compare channel configuration for all processors
1844 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1845 ChanCount c = input_streams ();
1847 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1849 if (c != (*j)->input_streams()) {
1852 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1855 if ((*i)->input_streams() != c) {
1858 c = (*i)->output_streams();
1870 __attribute__((annotate("realtime")))
1873 Route::apply_processor_order (const ProcessorList& new_order)
1875 /* need to hold processor_lock; either read or write lock
1876 * and the engine process_lock.
1877 * Due to r/w lock ambiguity we can only assert the latter
1879 assert (!AudioEngine::instance()->process_lock().trylock());
1882 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1883 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1884 * processors in the current actual processor list that are hidden. Any visible processors
1885 * in the current list but not in "new_order" will be assumed to be deleted.
1888 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1889 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1890 * (note though that ::processors_reorder_needs_configure() ensured that
1891 * this function will only ever be called from the rt-thread if no processor were removed)
1893 * either way, I can't proove it, but an x-run due to re-order here is less likley
1894 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1897 ProcessorList as_it_will_be;
1898 ProcessorList::iterator oiter;
1899 ProcessorList::const_iterator niter;
1901 oiter = _processors.begin();
1902 niter = new_order.begin();
1904 while (niter != new_order.end()) {
1906 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1907 then append it to the temp list.
1909 Otherwise, see if the next processor in the old list is in the new list. if not,
1910 its been deleted. If its there, append it to the temp list.
1913 if (oiter == _processors.end()) {
1915 /* no more elements in the old list, so just stick the rest of
1916 the new order onto the temp list.
1919 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1920 while (niter != new_order.end()) {
1927 if (!(*oiter)->display_to_user()) {
1929 as_it_will_be.push_back (*oiter);
1933 /* visible processor: check that its in the new order */
1935 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1936 /* deleted: do nothing, shared_ptr<> will clean up */
1938 /* ignore this one, and add the next item from the new order instead */
1939 as_it_will_be.push_back (*niter);
1944 /* now remove from old order - its taken care of no matter what */
1945 oiter = _processors.erase (oiter);
1949 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1951 /* If the meter is in a custom position, find it and make a rough note of its position */
1952 maybe_note_meter_position ();
1956 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1958 // it a change is already queued, wait for it
1959 // (unless engine is stopped. apply immediately and proceed
1960 while (g_atomic_int_get (&_pending_process_reorder)) {
1961 if (!AudioEngine::instance()->running()) {
1962 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
1963 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1965 apply_processor_order(_pending_processor_order);
1966 setup_invisible_processors ();
1968 g_atomic_int_set (&_pending_process_reorder, 0);
1970 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1971 set_processor_positions ();
1973 // TODO rather use a semaphore or something.
1974 // but since ::reorder_processors() is called
1975 // from the GUI thread, this is fine..
1980 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
1982 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1983 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1984 ProcessorState pstate (this);
1986 apply_processor_order (new_order);
1988 if (configure_processors_unlocked (err, &lm)) {
1996 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1997 set_processor_positions ();
2000 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2001 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2003 // _pending_processor_order is protected by _processor_lock
2004 _pending_processor_order = new_order;
2005 g_atomic_int_set (&_pending_process_reorder, 1);
2012 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2014 boost::shared_ptr<PluginInsert> pi;
2015 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2019 if (pi->has_sidechain () == add) {
2020 return true; // ?? call failed, but result is as expected.
2024 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2025 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2026 if (i == _processors.end ()) {
2032 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2033 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2034 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2036 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2038 if (!pi->add_sidechain ()) {
2042 if (!pi->del_sidechain ()) {
2048 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2053 pi->del_sidechain ();
2055 pi->add_sidechain ();
2056 // TODO restore side-chain's state.
2061 configure_processors_unlocked (0, &lm);
2064 if (pi->has_sidechain ()) {
2065 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2068 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2069 _session.set_dirty ();
2074 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2076 boost::shared_ptr<PluginInsert> pi;
2077 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2082 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2083 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2084 if (i == _processors.end ()) {
2090 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2091 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2093 const ChanCount& old (pi->preset_out ());
2094 if (!pi->set_preset_out (outs)) {
2095 return true; // no change, OK
2098 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2101 pi->set_preset_out (old);
2104 configure_processors_unlocked (0, &lm);
2107 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2108 _session.set_dirty ();
2113 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2116 return customize_plugin_insert (proc, 0, unused, unused);
2120 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2122 boost::shared_ptr<PluginInsert> pi;
2123 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2128 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2129 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2130 if (i == _processors.end ()) {
2136 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2137 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2139 bool old_cust = pi->custom_cfg ();
2140 uint32_t old_cnt = pi->get_count ();
2141 ChanCount old_chan = pi->output_streams ();
2142 ChanCount old_sinks = pi->natural_input_streams ();
2145 pi->set_custom_cfg (false);
2147 pi->set_custom_cfg (true);
2148 pi->set_count (count);
2149 pi->set_outputs (outs);
2150 pi->set_sinks (sinks);
2153 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2157 pi->set_count (old_cnt);
2158 pi->set_sinks (old_sinks);
2159 pi->set_outputs (old_chan);
2160 pi->set_custom_cfg (old_cust);
2164 configure_processors_unlocked (0, &lm);
2167 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2168 _session.set_dirty ();
2173 Route::set_strict_io (const bool enable)
2175 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2177 if (_strict_io != enable) {
2178 _strict_io = enable;
2179 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2180 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2181 boost::shared_ptr<PluginInsert> pi;
2182 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2183 pi->set_strict_io (_strict_io);
2187 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2191 _strict_io = !enable; // restore old value
2192 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2193 boost::shared_ptr<PluginInsert> pi;
2194 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2195 pi->set_strict_io (_strict_io);
2202 configure_processors (0);
2205 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2206 _session.set_dirty ();
2218 Route::get_template()
2220 return state(false);
2224 Route::state(bool full_state)
2227 if (!_session._template_state_dir.empty()) {
2228 assert (!full_state); // only for templates
2229 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2232 XMLNode *node = new XMLNode("Route");
2233 ProcessorList::iterator i;
2236 id().print (buf, sizeof (buf));
2237 node->add_property("id", buf);
2238 node->add_property ("name", _name);
2239 node->add_property("default-type", _default_type.to_string());
2240 node->add_property ("strict-io", _strict_io);
2242 node->add_child_nocopy (_presentation_info.get_state());
2244 node->add_property("active", _active?"yes":"no");
2246 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2247 node->add_property("meter-point", enum_2_string (_meter_point));
2249 node->add_property("meter-type", enum_2_string (_meter_type));
2252 node->add_property("route-group", _route_group->name());
2255 node->add_child_nocopy (_solo_control->get_state ());
2256 node->add_child_nocopy (_solo_isolate_control->get_state ());
2257 node->add_child_nocopy (_solo_safe_control->get_state ());
2259 node->add_child_nocopy (_input->state (full_state));
2260 node->add_child_nocopy (_output->state (full_state));
2261 node->add_child_nocopy (_mute_master->get_state ());
2263 node->add_child_nocopy (_mute_control->get_state ());
2264 node->add_child_nocopy (_phase_control->get_state ());
2267 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2270 if (_comment.length()) {
2271 XMLNode *cmt = node->add_child ("Comment");
2272 cmt->add_content (_comment);
2276 node->add_child_nocopy (_pannable->state (full_state));
2280 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2281 for (i = _processors.begin(); i != _processors.end(); ++i) {
2283 /* template save: do not include internal sends functioning as
2284 aux sends because the chance of the target ID
2285 in the session where this template is used
2288 similarly, do not save listen sends which connect to
2289 the monitor section, because these will always be
2292 boost::shared_ptr<InternalSend> is;
2294 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2295 if (is->role() == Delivery::Listen) {
2300 node->add_child_nocopy((*i)->state (full_state));
2305 node->add_child_copy (*_extra_xml);
2308 if (_custom_meter_position_noted) {
2309 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2311 after->id().print (buf, sizeof (buf));
2312 node->add_property (X_("processor-after-last-custom-meter"), buf);
2316 if (!_session._template_state_dir.empty()) {
2317 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2320 node->add_child_copy (Slavable::get_state());
2326 Route::set_state (const XMLNode& node, int version)
2328 if (version < 3000) {
2329 return set_state_2X (node, version);
2333 XMLNodeConstIterator niter;
2335 XMLProperty const * prop;
2337 if (node.name() != "Route"){
2338 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2342 if ((prop = node.property (X_("name"))) != 0) {
2343 Route::set_name (prop->value());
2347 _initial_io_setup = true;
2349 Stripable::set_state (node, version);
2351 if ((prop = node.property (X_("strict-io"))) != 0) {
2352 _strict_io = string_is_affirmative (prop->value());
2356 _mute_master->set_solo_ignore (true);
2360 /* monitor bus does not get a panner, but if (re)created
2361 via XML, it will already have one by the time we
2362 call ::set_state(). so ... remove it.
2367 /* add all processors (except amp, which is always present) */
2369 nlist = node.children();
2370 XMLNode processor_state (X_("processor_state"));
2372 Stateful::save_extra_xml (node);
2374 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2378 if (child->name() == IO::state_node_name) {
2379 if ((prop = child->property (X_("direction"))) == 0) {
2383 if (prop->value() == "Input") {
2384 _input->set_state (*child, version);
2385 } else if (prop->value() == "Output") {
2386 _output->set_state (*child, version);
2389 } else if (child->name() == X_("Processor")) {
2390 processor_state.add_child_copy (*child);
2391 } else if (child->name() == X_("Pannable")) {
2393 _pannable->set_state (*child, version);
2395 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2397 } else if (child->name() == Controllable::xml_node_name) {
2398 if ((prop = child->property (X_("name"))) == 0) {
2402 if (prop->value() == _gain_control->name()) {
2403 _gain_control->set_state (*child, version);
2404 } else if (prop->value() == _solo_control->name()) {
2405 _solo_control->set_state (*child, version);
2406 } else if (prop->value() == _solo_safe_control->name()) {
2407 _solo_safe_control->set_state (*child, version);
2408 } else if (prop->value() == _solo_isolate_control->name()) {
2409 _solo_isolate_control->set_state (*child, version);
2410 } else if (prop->value() == _solo_control->name()) {
2411 _mute_control->set_state (*child, version);
2413 } else if (child->name() == Slavable::xml_node_name) {
2414 Slavable::set_state (*child, version);
2418 if ((prop = node.property (X_("meter-point"))) != 0) {
2419 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2420 set_meter_point (mp, true);
2422 _meter->set_display_to_user (_meter_point == MeterCustom);
2426 if ((prop = node.property (X_("meter-type"))) != 0) {
2427 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2430 _initial_io_setup = false;
2432 set_processor_state (processor_state);
2434 // this looks up the internal instrument in processors
2435 reset_instrument_info();
2437 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2438 set_denormal_protection (string_is_affirmative (prop->value()));
2441 if ((prop = node.property (X_("active"))) != 0) {
2442 bool yn = string_is_affirmative (prop->value());
2443 set_active (yn, this);
2446 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2447 PBD::ID id (prop->value ());
2448 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2449 ProcessorList::const_iterator i = _processors.begin ();
2450 while (i != _processors.end() && (*i)->id() != id) {
2454 if (i != _processors.end ()) {
2455 _processor_after_last_custom_meter = *i;
2456 _custom_meter_position_noted = true;
2460 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2463 if (child->name() == X_("Comment")) {
2465 /* XXX this is a terrible API design in libxml++ */
2467 XMLNode *cmt = *(child->children().begin());
2468 _comment = cmt->content();
2470 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2471 if (prop->value() == "solo") {
2472 _solo_control->set_state (*child, version);
2473 } else if (prop->value() == "mute") {
2474 _mute_control->set_state (*child, version);
2477 } else if (child->name() == MuteMaster::xml_node_name) {
2478 _mute_master->set_state (*child, version);
2480 } else if (child->name() == Automatable::xml_node_name) {
2481 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2489 Route::set_state_2X (const XMLNode& node, int version)
2493 XMLNodeConstIterator niter;
2495 XMLProperty const * prop;
2497 /* 2X things which still remain to be handled:
2503 if (node.name() != "Route") {
2504 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2508 Stripable::set_state (node, version);
2510 if (is_master() || is_monitor() || is_auditioner()) {
2511 _mute_master->set_solo_ignore (true);
2514 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2515 set_denormal_protection (string_is_affirmative (prop->value()));
2518 if ((prop = node.property (X_("muted"))) != 0) {
2521 bool muted = string_is_affirmative (prop->value());
2527 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2529 if (string_is_affirmative (prop->value())){
2530 mute_point = mute_point + "PreFader";
2535 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2537 if (string_is_affirmative (prop->value())){
2540 mute_point = mute_point + ",";
2543 mute_point = mute_point + "PostFader";
2548 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2550 if (string_is_affirmative (prop->value())){
2553 mute_point = mute_point + ",";
2556 mute_point = mute_point + "Listen";
2561 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2563 if (string_is_affirmative (prop->value())){
2566 mute_point = mute_point + ",";
2569 mute_point = mute_point + "Main";
2573 _mute_master->set_mute_points (mute_point);
2574 _mute_master->set_muted_by_self (true);
2578 if ((prop = node.property (X_("meter-point"))) != 0) {
2579 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2584 nlist = node.children ();
2585 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2589 if (child->name() == IO::state_node_name) {
2591 /* there is a note in IO::set_state_2X() about why we have to call
2595 _input->set_state_2X (*child, version, true);
2596 _output->set_state_2X (*child, version, false);
2598 if ((prop = child->property (X_("name"))) != 0) {
2599 Route::set_name (prop->value ());
2604 if ((prop = child->property (X_("active"))) != 0) {
2605 bool yn = string_is_affirmative (prop->value());
2606 _active = !yn; // force switch
2607 set_active (yn, this);
2610 if ((prop = child->property (X_("gain"))) != 0) {
2613 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2614 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2618 /* Set up Panners in the IO */
2619 XMLNodeList io_nlist = child->children ();
2621 XMLNodeConstIterator io_niter;
2624 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2626 io_child = *io_niter;
2628 if (io_child->name() == X_("Panner")) {
2629 _main_outs->panner_shell()->set_state(*io_child, version);
2630 } else if (io_child->name() == X_("Automation")) {
2631 /* IO's automation is for the fader */
2632 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2638 XMLNodeList redirect_nodes;
2640 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2644 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2645 redirect_nodes.push_back(child);
2650 set_processor_state_2X (redirect_nodes, version);
2652 Stateful::save_extra_xml (node);
2654 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2657 if (child->name() == X_("Comment")) {
2659 /* XXX this is a terrible API design in libxml++ */
2661 XMLNode *cmt = *(child->children().begin());
2662 _comment = cmt->content();
2664 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2665 if (prop->value() == X_("solo")) {
2666 _solo_control->set_state (*child, version);
2667 } else if (prop->value() == X_("mute")) {
2668 _mute_control->set_state (*child, version);
2678 Route::get_processor_state ()
2680 XMLNode* root = new XMLNode (X_("redirects"));
2681 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2682 root->add_child_nocopy ((*i)->state (true));
2689 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2691 /* We don't bother removing existing processors not in nList, as this
2692 method will only be called when creating a Route from scratch, not
2693 for undo purposes. Just put processors in at the appropriate place
2697 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2698 add_processor_from_xml_2X (**i, version);
2703 Route::set_processor_state (const XMLNode& node)
2705 const XMLNodeList &nlist = node.children();
2706 XMLNodeConstIterator niter;
2707 ProcessorList new_order;
2708 bool must_configure = false;
2710 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2712 XMLProperty* prop = (*niter)->property ("type");
2714 if (prop->value() == "amp") {
2715 _amp->set_state (**niter, Stateful::current_state_version);
2716 new_order.push_back (_amp);
2717 } else if (prop->value() == "trim") {
2718 _trim->set_state (**niter, Stateful::current_state_version);
2719 new_order.push_back (_trim);
2720 } else if (prop->value() == "meter") {
2721 _meter->set_state (**niter, Stateful::current_state_version);
2722 new_order.push_back (_meter);
2723 } else if (prop->value() == "delay") {
2725 _delayline->set_state (**niter, Stateful::current_state_version);
2726 new_order.push_back (_delayline);
2728 } else if (prop->value() == "main-outs") {
2729 _main_outs->set_state (**niter, Stateful::current_state_version);
2730 } else if (prop->value() == "intreturn") {
2732 _intreturn.reset (new InternalReturn (_session));
2733 must_configure = true;
2735 _intreturn->set_state (**niter, Stateful::current_state_version);
2736 } else if (is_monitor() && prop->value() == "monitor") {
2737 if (!_monitor_control) {
2738 _monitor_control.reset (new MonitorProcessor (_session));
2739 must_configure = true;
2741 _monitor_control->set_state (**niter, Stateful::current_state_version);
2742 } else if (prop->value() == "capture") {
2743 /* CapturingProcessor should never be restored, it's always
2744 added explicitly when needed */
2746 ProcessorList::iterator o;
2748 for (o = _processors.begin(); o != _processors.end(); ++o) {
2749 XMLProperty const * id_prop = (*niter)->property(X_("id"));
2750 if (id_prop && (*o)->id() == id_prop->value()) {
2751 (*o)->set_state (**niter, Stateful::current_state_version);
2752 new_order.push_back (*o);
2757 // If the processor (*niter) is not on the route then create it
2759 if (o == _processors.end()) {
2761 boost::shared_ptr<Processor> processor;
2763 if (prop->value() == "intsend") {
2765 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2767 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2768 prop->value() == "lv2" ||
2769 prop->value() == "windows-vst" ||
2770 prop->value() == "lxvst" ||
2771 prop->value() == "luaproc" ||
2772 prop->value() == "audiounit") {
2774 if (_session.get_disable_all_loaded_plugins ()) {
2775 processor.reset (new UnknownProcessor (_session, **niter));
2777 processor.reset (new PluginInsert (_session));
2778 processor->set_owner (this);
2780 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2781 pi->set_strict_io (true);
2785 } else if (prop->value() == "port") {
2787 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2789 } else if (prop->value() == "send") {
2791 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2792 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2793 send->SelfDestruct.connect_same_thread (*this,
2794 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2797 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2801 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2802 /* This processor could not be configured. Turn it into a UnknownProcessor */
2803 processor.reset (new UnknownProcessor (_session, **niter));
2806 /* subscribe to Sidechain IO changes */
2807 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2808 if (pi && pi->has_sidechain ()) {
2809 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2812 /* we have to note the monitor send here, otherwise a new one will be created
2813 and the state of this one will be lost.
2815 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2816 if (isend && isend->role() == Delivery::Listen) {
2817 _monitor_send = isend;
2820 /* it doesn't matter if invisible processors are added here, as they
2821 will be sorted out by setup_invisible_processors () shortly.
2824 new_order.push_back (processor);
2825 must_configure = true;
2831 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2832 /* re-assign _processors w/o process-lock.
2833 * if there's an IO-processor present in _processors but
2834 * not in new_order, it will be deleted and ~IO takes
2837 _processors = new_order;
2838 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2840 if (must_configure) {
2841 configure_processors_unlocked (0, &lm);
2844 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2846 (*i)->set_owner (this);
2847 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2849 boost::shared_ptr<PluginInsert> pi;
2851 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2852 if (pi->has_no_inputs ()) {
2853 _have_internal_generator = true;
2860 reset_instrument_info ();
2861 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2862 set_processor_positions ();
2866 Route::curve_reallocate ()
2868 // _gain_automation_curve.finish_resize ();
2869 // _pan_automation_curve.finish_resize ();
2873 Route::silence (framecnt_t nframes)
2875 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2880 silence_unlocked (nframes);
2884 Route::silence_unlocked (framecnt_t nframes)
2886 /* Must be called with the processor lock held */
2888 const framepos_t now = _session.transport_frame ();
2892 _output->silence (nframes);
2894 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2895 boost::shared_ptr<PluginInsert> pi;
2897 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2898 // skip plugins, they don't need anything when we're not active
2902 (*i)->silence (nframes, now);
2905 if (nframes == _session.get_block_size()) {
2912 Route::add_internal_return ()
2915 _intreturn.reset (new InternalReturn (_session));
2916 add_processor (_intreturn, PreFader);
2921 Route::add_send_to_internal_return (InternalSend* send)
2923 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2925 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2926 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2929 return d->add_send (send);
2935 Route::remove_send_from_internal_return (InternalSend* send)
2937 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2939 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2940 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2943 return d->remove_send (send);
2949 Route::enable_monitor_send ()
2951 /* Caller must hold process lock */
2952 assert (!AudioEngine::instance()->process_lock().trylock());
2954 /* master never sends to monitor section via the normal mechanism */
2955 assert (!is_master ());
2956 assert (!is_monitor ());
2958 /* make sure we have one */
2959 if (!_monitor_send) {
2960 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
2961 _monitor_send->set_display_to_user (false);
2965 configure_processors (0);
2968 /** Add an aux send to a route.
2969 * @param route route to send to.
2970 * @param before Processor to insert before, or 0 to insert at the end.
2973 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2975 assert (route != _session.monitor_out ());
2978 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2980 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2982 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2984 if (d && d->target_route() == route) {
2985 /* already listening via the specified IO: do nothing */
2993 boost::shared_ptr<InternalSend> listener;
2996 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2997 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
2998 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3001 add_processor (listener, before);
3003 } catch (failed_constructor& err) {
3011 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3013 ProcessorStreams err;
3014 ProcessorList::iterator tmp;
3017 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3019 /* have to do this early because otherwise processor reconfig
3020 * will put _monitor_send back in the list
3023 if (route == _session.monitor_out()) {
3024 _monitor_send.reset ();
3028 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3030 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3032 if (d && d->target_route() == route) {
3034 if (remove_processor (*x, &err, false) > 0) {
3040 /* list could have been demolished while we dropped the lock
3043 if (_session.engine().connected()) {
3044 /* i/o processors cannot be removed if the engine is not running
3045 * so don't live-loop in case the engine is N/A or dies
3055 Route::set_comment (string cmt, void *src)
3059 _session.set_dirty ();
3063 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3065 FeedRecord fr (other, via_sends_only);
3067 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3069 if (!result.second) {
3071 /* already a record for "other" - make sure sends-only information is correct */
3072 if (!via_sends_only && result.first->sends_only) {
3073 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3074 frp->sends_only = false;
3078 return result.second;
3082 Route::clear_fed_by ()
3088 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3090 const FedBy& fed_by (other->fed_by());
3092 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3093 boost::shared_ptr<Route> sr = f->r.lock();
3095 if (sr && (sr.get() == this)) {
3097 if (via_sends_only) {
3098 *via_sends_only = f->sends_only;
3109 Route::all_inputs () const
3111 /* TODO, if this works as expected,
3112 * cache the IOVector and maintain it via
3113 * input_change_handler(), sidechain_change_handler() etc
3116 ios.push_back (_input);
3118 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3119 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3121 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3122 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3125 iop = pi->sidechain();
3128 if (iop != 0 && iop->input()) {
3129 ios.push_back (iop->input());
3136 Route::all_outputs () const
3139 // _output is included via Delivery
3140 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3141 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3142 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3143 if (iop != 0 && iop->output()) {
3144 ios.push_back (iop->output());
3151 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3153 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3154 if (other->all_inputs().fed_by (_output)) {
3155 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3156 if (via_send_only) {
3157 *via_send_only = false;
3163 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3165 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3167 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3168 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3171 iop = pi->sidechain();
3175 boost::shared_ptr<const IO> iop_out = iop->output();
3176 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3177 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3180 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3181 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3182 if (via_send_only) {
3183 *via_send_only = true;
3187 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3190 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3195 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3200 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3202 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3206 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3208 return _session._current_route_graph.feeds (shared_from_this (), other);
3211 /** Called from the (non-realtime) butler thread when the transport is stopped */
3213 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3215 framepos_t now = _session.transport_frame();
3218 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3220 Automatable::transport_stopped (now);
3222 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3224 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3228 (*i)->transport_stopped (now);
3232 _roll_delay = _initial_delay;
3236 Route::input_change_handler (IOChange change, void * /*src*/)
3238 if ((change.type & IOChange::ConfigurationChanged)) {
3239 /* This is called with the process lock held if change
3240 contains ConfigurationChanged
3242 configure_processors (0);
3243 _phase_control->resize (_input->n_ports().n_audio ());
3244 io_changed (); /* EMIT SIGNAL */
3247 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3250 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3251 if (_input->connected()) {
3252 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3253 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3257 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3258 if (does_feed && !sends_only) {
3259 if ((*i)->soloed()) {
3262 if ((*i)->solo_isolate_control()->solo_isolated()) {
3269 int delta = sbou - _solo_control->soloed_by_others_upstream();
3270 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3273 PBD::warning << string_compose (
3274 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3275 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3280 if (_solo_control->soloed_by_others_upstream()) {
3281 // ignore new connections (they're not propagated)
3283 _solo_control->mod_solo_by_others_upstream (delta);
3287 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3288 // solo-isolate currently only propagates downstream
3290 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3292 //_solo_isolated_by_upstream = ibou;
3295 // Session::route_solo_changed does not propagate indirect solo-changes
3296 // propagate downstream to tracks
3297 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3298 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3302 bool does_feed = feeds (*i, &sends_only);
3303 if (delta <= 0 && does_feed && !sends_only) {
3304 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3307 if (idelta < 0 && does_feed && !sends_only) {
3308 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3315 Route::output_change_handler (IOChange change, void * /*src*/)
3317 if (_initial_io_setup) {
3321 if ((change.type & IOChange::ConfigurationChanged)) {
3322 /* This is called with the process lock held if change
3323 contains ConfigurationChanged
3325 configure_processors (0);
3328 _session.reset_monitor_section();
3331 io_changed (); /* EMIT SIGNAL */
3334 if (_solo_control->soloed_by_others_downstream()) {
3336 /* checking all all downstream routes for
3337 * explicit of implict solo is a rather drastic measure,
3338 * ideally the input_change_handler() of the other route
3339 * would propagate the change to us.
3341 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3342 if (_output->connected()) {
3343 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3344 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3348 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3349 if (does_feed && !sends_only) {
3350 if ((*i)->soloed()) {
3357 int delta = sbod - _solo_control->soloed_by_others_downstream();
3359 // do not allow new connections to change implicit solo (no propagation)
3360 _solo_control->mod_solo_by_others_downstream (delta);
3361 // Session::route_solo_changed() does not propagate indirect solo-changes
3362 // propagate upstream to tracks
3363 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3364 if ((*i).get() == this || !can_solo()) {
3368 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3369 if (delta != 0 && does_feed && !sends_only) {
3370 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3379 Route::sidechain_change_handler (IOChange change, void* src)
3381 if (_initial_io_setup || _in_sidechain_setup) {
3385 input_change_handler (change, src);
3389 Route::pans_required () const
3391 if (n_outputs().n_audio() < 2) {
3395 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3399 Route::flush_processor_buffers_locked (framecnt_t nframes)
3401 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3402 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3404 d->flush_buffers (nframes);
3406 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3408 p->flush_buffers (nframes);
3415 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3417 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3423 if (n_outputs().n_total() == 0) {
3427 if (!_active || n_inputs() == ChanCount::ZERO) {
3428 silence_unlocked (nframes);
3432 if (session_state_changing) {
3433 if (_session.transport_speed() != 0.0f) {
3434 /* we're rolling but some state is changing (e.g. our diskstream contents)
3435 so we cannot use them. Be silent till this is over.
3437 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3439 silence_unlocked (nframes);
3442 /* we're really not rolling, so we're either delivery silence or actually
3443 monitoring, both of which are safe to do while session_state_changing is true.
3447 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3449 fill_buffers_with_input (bufs, _input, nframes);
3451 if (_meter_point == MeterInput) {
3452 _meter->run (bufs, start_frame, end_frame, 0.0, nframes, true);
3455 _amp->apply_gain_automation (false);
3456 _trim->apply_gain_automation (false);
3457 passthru (bufs, start_frame, end_frame, nframes, 0);
3459 flush_processor_buffers_locked (nframes);
3465 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3467 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3472 if (n_outputs().n_total() == 0) {
3476 if (!_active || n_inputs().n_total() == 0) {
3477 silence_unlocked (nframes);
3481 framepos_t unused = 0;
3483 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3489 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3491 fill_buffers_with_input (bufs, _input, nframes);
3493 if (_meter_point == MeterInput) {
3494 _meter->run (bufs, start_frame, end_frame, 1.0, nframes, true);
3497 passthru (bufs, start_frame, end_frame, nframes, declick);
3499 flush_processor_buffers_locked (nframes);
3505 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3508 flush_processor_buffers_locked (nframes);
3513 Route::flush_processors ()
3515 /* XXX shouldn't really try to take this lock, since
3516 this is called from the RT audio thread.
3519 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3521 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3527 __attribute__((annotate("realtime")))
3530 Route::apply_processor_changes_rt ()
3532 int emissions = EmitNone;
3534 if (_pending_meter_point != _meter_point) {
3535 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3537 /* meters always have buffers for 'processor_max_streams'
3538 * they can be re-positioned without re-allocation */
3539 if (set_meter_point_unlocked()) {
3540 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3542 emissions |= EmitMeterChanged;
3547 bool changed = false;
3549 if (g_atomic_int_get (&_pending_process_reorder)) {
3550 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3552 apply_processor_order (_pending_processor_order);
3553 setup_invisible_processors ();
3555 g_atomic_int_set (&_pending_process_reorder, 0);
3556 emissions |= EmitRtProcessorChange;
3560 set_processor_positions ();
3562 if (emissions != 0) {
3563 g_atomic_int_set (&_pending_signals, emissions);
3566 return (!selfdestruct_sequence.empty ());
3570 Route::emit_pending_signals ()
3572 int sig = g_atomic_int_and (&_pending_signals, 0);
3573 if (sig & EmitMeterChanged) {
3574 _meter->emit_configuration_changed();
3575 meter_change (); /* EMIT SIGNAL */
3576 if (sig & EmitMeterVisibilityChange) {
3577 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3579 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3582 if (sig & EmitRtProcessorChange) {
3583 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3586 /* this would be a job for the butler.
3587 * Conceptually we should not take processe/processor locks here.
3588 * OTOH its more efficient (less overhead for summoning the butler and
3589 * telling her what do do) and signal emission is called
3590 * directly after the process callback, which decreases the chance
3591 * of x-runs when taking the locks.
3593 while (!selfdestruct_sequence.empty ()) {
3594 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3595 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3596 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3597 selfdestruct_sequence.pop_back ();
3600 remove_processor (proc);
3606 Route::set_meter_point (MeterPoint p, bool force)
3608 if (_pending_meter_point == p && !force) {
3612 if (force || !AudioEngine::instance()->running()) {
3613 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3614 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3615 _pending_meter_point = p;
3616 _meter->emit_configuration_changed();
3617 meter_change (); /* EMIT SIGNAL */
3618 if (set_meter_point_unlocked()) {
3619 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3621 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3624 _pending_meter_point = p;
3630 __attribute__((annotate("realtime")))
3633 Route::set_meter_point_unlocked ()
3636 /* Caller must hold process and processor write lock */
3637 assert (!AudioEngine::instance()->process_lock().trylock());
3638 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3639 assert (!lm.locked ());
3642 _meter_point = _pending_meter_point;
3644 bool meter_was_visible_to_user = _meter->display_to_user ();
3646 if (!_custom_meter_position_noted) {
3647 maybe_note_meter_position ();
3650 if (_meter_point != MeterCustom) {
3652 _meter->set_display_to_user (false);
3654 setup_invisible_processors ();
3657 _meter->set_display_to_user (true);
3659 /* If we have a previous position for the custom meter, try to put it there */
3660 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3662 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3663 if (i != _processors.end ()) {
3664 _processors.remove (_meter);
3665 _processors.insert (i, _meter);
3667 } else {// at end, right before the mains_out/panner
3668 _processors.remove (_meter);
3669 ProcessorList::iterator main = _processors.end();
3670 _processors.insert (--main, _meter);
3674 /* Set up the meter for its new position */
3676 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3680 if (loc == _processors.begin()) {
3681 m_in = _input->n_ports();
3683 ProcessorList::iterator before = loc;
3685 m_in = (*before)->output_streams ();
3688 _meter->reflect_inputs (m_in);
3690 /* we do not need to reconfigure the processors, because the meter
3691 (a) is always ready to handle processor_max_streams
3692 (b) is always an N-in/N-out processor, and thus moving
3693 it doesn't require any changes to the other processors.
3696 /* these should really be done after releasing the lock
3697 * but all those signals are subscribed to with gui_thread()
3700 return (_meter->display_to_user() != meter_was_visible_to_user);
3704 Route::listen_position_changed ()
3707 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3708 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3709 ProcessorState pstate (this);
3711 if (configure_processors_unlocked (0, &lm)) {
3712 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3714 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3719 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3720 _session.set_dirty ();
3723 boost::shared_ptr<CapturingProcessor>
3724 Route::add_export_point()
3726 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3727 if (!_capturing_processor) {
3729 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3730 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3732 // this aligns all tracks; but not tracks + busses
3733 assert (_session.worst_track_latency () >= _initial_delay);
3734 _capturing_processor.reset (new CapturingProcessor (_session, _session.worst_track_latency () - _initial_delay));
3735 _capturing_processor->activate ();
3737 configure_processors_unlocked (0, &lw);
3741 return _capturing_processor;
3745 Route::update_signal_latency ()
3747 framecnt_t l = _output->user_latency();
3748 framecnt_t lamp = 0;
3749 bool before_amp = true;
3750 framecnt_t ltrim = 0;
3751 bool before_trim = true;
3753 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3754 if ((*i)->active ()) {
3755 l += (*i)->signal_latency ();
3760 if ((*i) == _trim) {
3771 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3773 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3774 _signal_latency_at_amp_position = lamp;
3775 _signal_latency_at_trim_position = ltrim;
3777 if (_signal_latency != l) {
3778 _signal_latency = l;
3779 signal_latency_changed (); /* EMIT SIGNAL */
3782 return _signal_latency;
3786 Route::set_user_latency (framecnt_t nframes)
3788 _output->set_user_latency (nframes);
3789 _session.update_latency_compensation ();
3793 Route::set_latency_compensation (framecnt_t longest_session_latency)
3795 framecnt_t old = _initial_delay;
3797 if (_signal_latency < longest_session_latency) {
3798 _initial_delay = longest_session_latency - _signal_latency;
3803 DEBUG_TRACE (DEBUG::Latency, string_compose (
3804 "%1: compensate for maximum latency of %2,"
3805 "given own latency of %3, using initial delay of %4\n",
3806 name(), longest_session_latency, _signal_latency, _initial_delay));
3808 if (_initial_delay != old) {
3809 initial_delay_changed (); /* EMIT SIGNAL */
3812 if (_session.transport_stopped()) {
3813 _roll_delay = _initial_delay;
3818 Route::set_block_size (pframes_t nframes)
3820 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3821 (*i)->set_block_size (nframes);
3824 _session.ensure_buffers (n_process_buffers ());
3828 Route::protect_automation ()
3830 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3831 (*i)->protect_automation();
3834 /** @param declick 1 to set a pending declick fade-in,
3835 * -1 to set a pending declick fade-out
3838 Route::set_pending_declick (int declick)
3841 /* this call is not allowed to turn off a pending declick */
3843 _pending_declick = declick;
3846 _pending_declick = 0;
3850 /** Shift automation forwards from a particular place, thereby inserting time.
3851 * Adds undo commands for any shifts that are performed.
3853 * @param pos Position to start shifting from.
3854 * @param frames Amount to shift forwards by.
3858 Route::shift (framepos_t pos, framecnt_t frames)
3860 /* gain automation */
3862 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3864 XMLNode &before = gc->alist()->get_state ();
3865 gc->alist()->shift (pos, frames);
3866 XMLNode &after = gc->alist()->get_state ();
3867 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3870 /* gain automation */
3872 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3874 XMLNode &before = gc->alist()->get_state ();
3875 gc->alist()->shift (pos, frames);
3876 XMLNode &after = gc->alist()->get_state ();
3877 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3880 // TODO mute automation ??
3882 /* pan automation */
3884 ControlSet::Controls& c (_pannable->controls());
3886 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3887 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3889 boost::shared_ptr<AutomationList> al = pc->alist();
3890 XMLNode& before = al->get_state ();
3891 al->shift (pos, frames);
3892 XMLNode& after = al->get_state ();
3893 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3898 /* redirect automation */
3900 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3901 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3903 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3905 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3906 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3908 boost::shared_ptr<AutomationList> al = ac->alist();
3909 XMLNode &before = al->get_state ();
3910 al->shift (pos, frames);
3911 XMLNode &after = al->get_state ();
3912 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3920 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
3922 boost::shared_ptr<Processor> processor (p.lock ());
3923 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3927 pi->set_state_dir (d);
3931 Route::save_as_template (const string& path, const string& name)
3933 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
3934 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
3936 XMLNode& node (state (false));
3940 IO::set_name_in_state (*node.children().front(), name);
3942 tree.set_root (&node);
3944 /* return zero on success, non-zero otherwise */
3945 return !tree.write (path.c_str());
3950 Route::set_name (const string& str)
3952 if (str == name()) {
3956 string name = Route::ensure_track_or_route_name (str, _session);
3957 SessionObject::set_name (name);
3959 bool ret = (_input->set_name(name) && _output->set_name(name));
3962 /* rename the main outs. Leave other IO processors
3963 * with whatever name they already have, because its
3964 * just fine as it is (it will not contain the route
3965 * name if its a port insert, port send or port return).
3969 if (_main_outs->set_name (name)) {
3970 /* XXX returning false here is stupid because
3971 we already changed the route name.
3981 /** Set the name of a route in an XML description.
3982 * @param node XML <Route> node to set the name in.
3983 * @param name New name.
3986 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
3988 node.add_property (X_("name"), name);
3990 XMLNodeList children = node.children();
3991 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3993 if ((*i)->name() == X_("IO")) {
3995 IO::set_name_in_state (**i, name);
3997 } else if ((*i)->name() == X_("Processor")) {
3999 XMLProperty const * role = (*i)->property (X_("role"));
4000 if (role && role->value() == X_("Main")) {
4001 (*i)->add_property (X_("name"), name);
4004 } else if ((*i)->name() == X_("Diskstream")) {
4006 if (rename_playlist) {
4007 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4009 (*i)->add_property (X_("name"), name);
4015 boost::shared_ptr<Send>
4016 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4018 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4020 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4021 boost::shared_ptr<InternalSend> send;
4023 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4024 if (send->target_route() == target) {
4030 return boost::shared_ptr<Send>();
4034 Route::set_denormal_protection (bool yn)
4036 if (_denormal_protection != yn) {
4037 _denormal_protection = yn;
4038 denormal_protection_changed (); /* EMIT SIGNAL */
4043 Route::denormal_protection () const
4045 return _denormal_protection;
4049 Route::set_active (bool yn, void* src)
4051 if (_session.transport_rolling()) {
4055 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4056 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4060 if (_active != yn) {
4062 _input->set_active (yn);
4063 _output->set_active (yn);
4064 active_changed (); // EMIT SIGNAL
4065 _session.set_dirty ();
4069 boost::shared_ptr<Pannable>
4070 Route::pannable() const
4075 boost::shared_ptr<Panner>
4076 Route::panner() const
4079 return _main_outs->panner_shell()->panner();
4082 boost::shared_ptr<PannerShell>
4083 Route::panner_shell() const
4085 return _main_outs->panner_shell();
4088 boost::shared_ptr<GainControl>
4089 Route::gain_control() const
4091 return _gain_control;
4094 boost::shared_ptr<GainControl>
4095 Route::trim_control() const
4097 return _trim_control;
4100 boost::shared_ptr<PhaseControl>
4101 Route::phase_control() const
4103 return _phase_control;
4106 boost::shared_ptr<AutomationControl>
4107 Route::get_control (const Evoral::Parameter& param)
4109 /* either we own the control or .... */
4111 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4115 /* maybe one of our processors does or ... */
4117 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4118 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4119 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4127 /* nobody does so we'll make a new one */
4129 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4136 boost::shared_ptr<Processor>
4137 Route::nth_plugin (uint32_t n) const
4139 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4140 ProcessorList::const_iterator i;
4142 for (i = _processors.begin(); i != _processors.end(); ++i) {
4143 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4150 return boost::shared_ptr<Processor> ();
4153 boost::shared_ptr<Processor>
4154 Route::nth_send (uint32_t n) const
4156 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4157 ProcessorList::const_iterator i;
4159 for (i = _processors.begin(); i != _processors.end(); ++i) {
4160 if (boost::dynamic_pointer_cast<Send> (*i)) {
4162 if ((*i)->name().find (_("Monitor")) == 0) {
4163 /* send to monitor section is not considered
4164 to be an accessible send.
4175 return boost::shared_ptr<Processor> ();
4179 Route::has_io_processor_named (const string& name)
4181 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4182 ProcessorList::iterator i;
4184 for (i = _processors.begin(); i != _processors.end(); ++i) {
4185 if (boost::dynamic_pointer_cast<Send> (*i) ||
4186 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4187 if ((*i)->name() == name) {
4197 Route::set_processor_positions ()
4199 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4201 bool had_amp = false;
4202 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4203 (*i)->set_pre_fader (!had_amp);
4210 /** Called when there is a proposed change to the input port count */
4212 Route::input_port_count_changing (ChanCount to)
4214 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4216 /* The processors cannot be configured with the new input arrangement, so
4222 /* The change is ok */
4226 /** Called when there is a proposed change to the output port count */
4228 Route::output_port_count_changing (ChanCount to)
4230 if (_strict_io && !_in_configure_processors) {
4233 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4234 if (processor_out_streams.get(*t) > to.get(*t)) {
4238 /* The change is ok */
4243 Route::unknown_processors () const
4247 if (_session.get_disable_all_loaded_plugins ()) {
4248 // Do not list "missing plugins" if they are explicitly disabled
4252 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4253 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4254 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4255 p.push_back ((*i)->name ());
4264 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4266 /* we assume that all our input ports feed all our output ports. its not
4267 universally true, but the alternative is way too corner-case to worry about.
4270 LatencyRange all_connections;
4273 all_connections.min = 0;
4274 all_connections.max = 0;
4276 all_connections.min = ~((pframes_t) 0);
4277 all_connections.max = 0;
4279 /* iterate over all "from" ports and determine the latency range for all of their
4280 connections to the "outside" (outside of this Route).
4283 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4287 p->get_connected_latency_range (range, playback);
4289 all_connections.min = min (all_connections.min, range.min);
4290 all_connections.max = max (all_connections.max, range.max);
4294 /* set the "from" port latencies to the max/min range of all their connections */
4296 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4297 p->set_private_latency_range (all_connections, playback);
4300 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4302 all_connections.min += our_latency;
4303 all_connections.max += our_latency;
4305 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4306 p->set_private_latency_range (all_connections, playback);
4309 return all_connections.max;
4313 Route::set_private_port_latencies (bool playback) const
4315 framecnt_t own_latency = 0;
4317 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4318 OR LATENCY CALLBACK.
4320 This is called (early) from the latency callback. It computes the REAL
4321 latency associated with each port and stores the result as the "private"
4322 latency of the port. A later call to Route::set_public_port_latencies()
4323 sets all ports to the same value to reflect the fact that we do latency
4324 compensation and so all signals are delayed by the same amount as they
4325 flow through ardour.
4328 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4329 if ((*i)->active ()) {
4330 own_latency += (*i)->signal_latency ();
4335 /* playback: propagate latency from "outside the route" to outputs to inputs */
4336 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4338 /* capture: propagate latency from "outside the route" to inputs to outputs */
4339 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4344 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4346 /* this is called to set the JACK-visible port latencies, which take
4347 latency compensation into account.
4356 const PortSet& ports (_input->ports());
4357 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4358 p->set_public_latency_range (range, playback);
4363 const PortSet& ports (_output->ports());
4364 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4365 p->set_public_latency_range (range, playback);
4370 /** Put the invisible processors in the right place in _processors.
4371 * Must be called with a writer lock on _processor_lock held.
4374 __attribute__((annotate("realtime")))
4377 Route::setup_invisible_processors ()
4380 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4381 assert (!lm.locked ());
4385 /* too early to be doing this stuff */
4389 /* we'll build this new list here and then use it
4391 * TODO put the ProcessorList is on the stack for RT-safety.
4394 ProcessorList new_processors;
4396 /* find visible processors */
4398 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4399 if ((*i)->display_to_user ()) {
4400 new_processors.push_back (*i);
4406 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4408 if (amp == new_processors.end ()) {
4409 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4410 new_processors.push_front (_amp);
4411 amp = find (new_processors.begin(), new_processors.end(), _amp);
4414 /* and the processor after the amp */
4416 ProcessorList::iterator after_amp = amp;
4422 switch (_meter_point) {
4424 assert (!_meter->display_to_user ());
4425 new_processors.push_front (_meter);
4428 assert (!_meter->display_to_user ());
4429 new_processors.insert (amp, _meter);
4431 case MeterPostFader:
4432 /* do nothing here */
4435 /* do nothing here */
4438 /* the meter is visible, so we don't touch it here */
4445 assert (_main_outs);
4446 assert (!_main_outs->display_to_user ());
4447 new_processors.push_back (_main_outs);
4449 /* iterator for the main outs */
4451 ProcessorList::iterator main = new_processors.end();
4454 /* OUTPUT METERING */
4456 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4457 assert (!_meter->display_to_user ());
4459 /* add the processor just before or just after the main outs */
4461 ProcessorList::iterator meter_point = main;
4463 if (_meter_point == MeterOutput) {
4466 new_processors.insert (meter_point, _meter);
4471 if (_monitor_send && !is_monitor ()) {
4472 assert (!_monitor_send->display_to_user ());
4473 switch (Config->get_listen_position ()) {
4474 case PreFaderListen:
4475 switch (Config->get_pfl_position ()) {
4476 case PFLFromBeforeProcessors:
4477 new_processors.push_front (_monitor_send);
4479 case PFLFromAfterProcessors:
4480 new_processors.insert (amp, _monitor_send);
4483 _monitor_send->set_can_pan (false);
4485 case AfterFaderListen:
4486 switch (Config->get_afl_position ()) {
4487 case AFLFromBeforeProcessors:
4488 new_processors.insert (after_amp, _monitor_send);
4490 case AFLFromAfterProcessors:
4491 new_processors.insert (new_processors.end(), _monitor_send);
4494 _monitor_send->set_can_pan (true);
4499 #if 0 // not used - just yet
4500 if (!is_master() && !is_monitor() && !is_auditioner()) {
4501 new_processors.push_front (_delayline);
4505 /* MONITOR CONTROL */
4507 if (_monitor_control && is_monitor ()) {
4508 assert (!_monitor_control->display_to_user ());
4509 new_processors.insert (amp, _monitor_control);
4512 /* INTERNAL RETURN */
4514 /* doing this here means that any monitor control will come just after
4519 assert (!_intreturn->display_to_user ());
4520 new_processors.push_front (_intreturn);
4523 if (_trim && _trim->active()) {
4524 assert (!_trim->display_to_user ());
4525 new_processors.push_front (_trim);
4527 /* EXPORT PROCESSOR */
4529 if (_capturing_processor) {
4530 assert (!_capturing_processor->display_to_user ());
4531 new_processors.push_front (_capturing_processor);
4534 _processors = new_processors;
4536 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4537 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4538 (*i)->enable (true);
4542 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4543 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4544 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4551 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4552 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4556 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4557 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4564 /** If the meter point is `Custom', make a note of where the meter is.
4565 * This is so that if the meter point is subsequently set to something else,
4566 * and then back to custom, we can put the meter back where it was last time
4567 * custom was enabled.
4569 * Must be called with the _processor_lock held.
4572 Route::maybe_note_meter_position ()
4574 if (_meter_point != MeterCustom) {
4578 _custom_meter_position_noted = true;
4579 /* custom meter points range from after trim to before panner/main_outs
4580 * this is a limitation by the current processor UI
4582 bool seen_trim = false;
4583 _processor_after_last_custom_meter.reset();
4584 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4585 if ((*i) == _trim) {
4588 if ((*i) == _main_outs) {
4589 _processor_after_last_custom_meter = *i;
4592 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4594 _processor_after_last_custom_meter = _trim;
4596 ProcessorList::iterator j = i;
4598 assert(j != _processors.end ()); // main_outs should be before
4599 _processor_after_last_custom_meter = *j;
4604 assert(_processor_after_last_custom_meter.lock());
4607 boost::shared_ptr<Processor>
4608 Route::processor_by_id (PBD::ID id) const
4610 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4611 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4612 if ((*i)->id() == id) {
4617 return boost::shared_ptr<Processor> ();
4620 /** @return the monitoring state, or in other words what data we are pushing
4621 * into the route (data from the inputs, data from disk or silence)
4624 Route::monitoring_state () const
4626 return MonitoringInput;
4629 /** @return what we should be metering; either the data coming from the input
4630 * IO or the data that is flowing through the route.
4633 Route::metering_state () const
4635 return MeteringRoute;
4639 Route::has_external_redirects () const
4641 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4643 /* ignore inactive processors and obviously ignore the main
4644 * outs since everything has them and we don't care.
4647 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4655 boost::shared_ptr<Processor>
4656 Route::the_instrument () const
4658 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4659 return the_instrument_unlocked ();
4662 boost::shared_ptr<Processor>
4663 Route::the_instrument_unlocked () const
4665 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4666 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4667 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4671 return boost::shared_ptr<Processor>();
4677 Route::non_realtime_locate (framepos_t pos)
4680 _pannable->transport_located (pos);
4683 if (_delayline.get()) {
4684 _delayline.get()->flush();
4688 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4689 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4691 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4692 (*i)->transport_located (pos);
4695 _roll_delay = _initial_delay;
4699 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4706 * We don't currently mix MIDI input together, so we don't need the
4707 * complex logic of the audio case.
4710 n_buffers = bufs.count().n_midi ();
4712 for (i = 0; i < n_buffers; ++i) {
4714 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4715 MidiBuffer& buf (bufs.get_midi (i));
4718 buf.copy (source_port->get_midi_buffer(nframes));
4720 buf.silence (nframes);
4726 n_buffers = bufs.count().n_audio();
4728 size_t n_ports = io->n_ports().n_audio();
4729 float scaling = 1.0f;
4731 if (n_ports > n_buffers) {
4732 scaling = ((float) n_buffers) / n_ports;
4735 for (i = 0; i < n_ports; ++i) {
4737 /* if there are more ports than buffers, map them onto buffers
4738 * in a round-robin fashion
4741 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4742 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4745 if (i < n_buffers) {
4747 /* first time through just copy a channel into
4751 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4753 if (scaling != 1.0f) {
4754 buf.apply_gain (scaling, nframes);
4759 /* on subsequent times around, merge data from
4760 * the port with what is already there
4763 if (scaling != 1.0f) {
4764 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4766 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4771 /* silence any remaining buffers */
4773 for (; i < n_buffers; ++i) {
4774 AudioBuffer& buf (bufs.get_audio (i));
4775 buf.silence (nframes);
4778 /* establish the initial setup of the buffer set, reflecting what was
4779 copied into it. unless, of course, we are the auditioner, in which
4780 case nothing was fed into it from the inputs at all.
4783 if (!is_auditioner()) {
4784 bufs.set_count (io->n_ports());
4788 boost::shared_ptr<AutomationControl>
4789 Route::pan_azimuth_control() const
4792 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4794 return boost::shared_ptr<AutomationControl>();
4796 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
4797 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4799 if (!_pannable || !panner()) {
4800 return boost::shared_ptr<AutomationControl>();
4802 return _pannable->pan_azimuth_control;
4806 boost::shared_ptr<AutomationControl>
4807 Route::pan_elevation_control() const
4809 if (Profile->get_mixbus() || !_pannable || !panner()) {
4810 return boost::shared_ptr<AutomationControl>();
4813 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4815 if (c.find (PanElevationAutomation) != c.end()) {
4816 return _pannable->pan_elevation_control;
4818 return boost::shared_ptr<AutomationControl>();
4821 boost::shared_ptr<AutomationControl>
4822 Route::pan_width_control() const
4824 if (Profile->get_mixbus() || !_pannable || !panner()) {
4825 return boost::shared_ptr<AutomationControl>();
4828 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4830 if (c.find (PanWidthAutomation) != c.end()) {
4831 return _pannable->pan_width_control;
4833 return boost::shared_ptr<AutomationControl>();
4836 boost::shared_ptr<AutomationControl>
4837 Route::pan_frontback_control() const
4839 if (Profile->get_mixbus() || !_pannable || !panner()) {
4840 return boost::shared_ptr<AutomationControl>();
4843 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4845 if (c.find (PanFrontBackAutomation) != c.end()) {
4846 return _pannable->pan_frontback_control;
4848 return boost::shared_ptr<AutomationControl>();
4851 boost::shared_ptr<AutomationControl>
4852 Route::pan_lfe_control() const
4854 if (Profile->get_mixbus() || !_pannable || !panner()) {
4855 return boost::shared_ptr<AutomationControl>();
4858 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4860 if (c.find (PanLFEAutomation) != c.end()) {
4861 return _pannable->pan_lfe_control;
4863 return boost::shared_ptr<AutomationControl>();
4868 Route::eq_band_cnt () const
4870 if (Profile->get_mixbus()) {
4873 /* Ardour has no well-known EQ object */
4878 boost::shared_ptr<AutomationControl>
4879 Route::eq_gain_controllable (uint32_t band) const
4882 boost::shared_ptr<PluginInsert> eq = ch_eq();
4885 return boost::shared_ptr<AutomationControl>();
4888 uint32_t port_number;
4891 if (is_master() || mixbus()) {
4898 if (is_master() || mixbus()) {
4905 if (is_master() || mixbus()) {
4912 return boost::shared_ptr<AutomationControl>();
4915 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
4917 return boost::shared_ptr<AutomationControl>();
4920 boost::shared_ptr<AutomationControl>
4921 Route::eq_freq_controllable (uint32_t band) const
4925 if (mixbus() || is_master()) {
4926 /* no frequency controls for mixbusses or master */
4927 return boost::shared_ptr<AutomationControl>();
4930 boost::shared_ptr<PluginInsert> eq = ch_eq();
4933 return boost::shared_ptr<AutomationControl>();
4936 uint32_t port_number;
4948 return boost::shared_ptr<AutomationControl>();
4951 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
4953 return boost::shared_ptr<AutomationControl>();
4957 boost::shared_ptr<AutomationControl>
4958 Route::eq_q_controllable (uint32_t band) const
4960 return boost::shared_ptr<AutomationControl>();
4963 boost::shared_ptr<AutomationControl>
4964 Route::eq_shape_controllable (uint32_t band) const
4966 return boost::shared_ptr<AutomationControl>();
4969 boost::shared_ptr<AutomationControl>
4970 Route::eq_enable_controllable () const
4973 boost::shared_ptr<PluginInsert> eq = ch_eq();
4976 return boost::shared_ptr<AutomationControl>();
4979 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
4981 return boost::shared_ptr<AutomationControl>();
4985 boost::shared_ptr<AutomationControl>
4986 Route::eq_hpf_controllable () const
4989 boost::shared_ptr<PluginInsert> eq = ch_eq();
4992 return boost::shared_ptr<AutomationControl>();
4995 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
4997 return boost::shared_ptr<AutomationControl>();
5002 Route::eq_band_name (uint32_t band) const
5004 if (Profile->get_mixbus()) {
5020 boost::shared_ptr<AutomationControl>
5021 Route::comp_enable_controllable () const
5024 boost::shared_ptr<PluginInsert> comp = ch_comp();
5027 return boost::shared_ptr<AutomationControl>();
5030 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5032 return boost::shared_ptr<AutomationControl>();
5035 boost::shared_ptr<AutomationControl>
5036 Route::comp_threshold_controllable () const
5039 boost::shared_ptr<PluginInsert> comp = ch_comp();
5042 return boost::shared_ptr<AutomationControl>();
5045 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5048 return boost::shared_ptr<AutomationControl>();
5051 boost::shared_ptr<AutomationControl>
5052 Route::comp_speed_controllable () const
5055 boost::shared_ptr<PluginInsert> comp = ch_comp();
5058 return boost::shared_ptr<AutomationControl>();
5061 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5063 return boost::shared_ptr<AutomationControl>();
5066 boost::shared_ptr<AutomationControl>
5067 Route::comp_mode_controllable () const
5070 boost::shared_ptr<PluginInsert> comp = ch_comp();
5073 return boost::shared_ptr<AutomationControl>();
5076 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5078 return boost::shared_ptr<AutomationControl>();
5081 boost::shared_ptr<AutomationControl>
5082 Route::comp_makeup_controllable () const
5085 boost::shared_ptr<PluginInsert> comp = ch_comp();
5088 return boost::shared_ptr<AutomationControl>();
5091 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5093 return boost::shared_ptr<AutomationControl>();
5096 boost::shared_ptr<AutomationControl>
5097 Route::comp_redux_controllable () const
5100 boost::shared_ptr<PluginInsert> comp = ch_comp();
5103 return boost::shared_ptr<AutomationControl>();
5106 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5108 return boost::shared_ptr<AutomationControl>();
5113 Route::comp_mode_name (uint32_t mode) const
5118 return _("Leveler");
5120 return _("Compressor");
5122 return _("Limiter");
5124 return mixbus() ? _("Sidechain") : _("Limiter");
5134 Route::comp_speed_name (uint32_t mode) const
5152 boost::shared_ptr<AutomationControl>
5153 Route::send_level_controllable (uint32_t n) const
5156 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5158 return boost::shared_ptr<AutomationControl>();
5163 return boost::shared_ptr<AutomationControl>();
5166 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5167 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5169 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5171 return boost::shared_ptr<AutomationControl>();
5173 return s->gain_control ();
5177 boost::shared_ptr<AutomationControl>
5178 Route::send_enable_controllable (uint32_t n) const
5181 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5183 return boost::shared_ptr<AutomationControl>();
5188 return boost::shared_ptr<AutomationControl>();
5191 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5192 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5194 /* although Ardour sends have enable/disable as part of the Processor
5195 API, it is not exposed as a controllable.
5197 XXX: we should fix this.
5199 return boost::shared_ptr<AutomationControl>();
5204 Route::send_name (uint32_t n) const
5210 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5214 boost::shared_ptr<Processor> p = nth_send (n);
5223 boost::shared_ptr<AutomationControl>
5224 Route::master_send_enable_controllable () const
5227 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5229 return boost::shared_ptr<AutomationControl>();
5231 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5233 return boost::shared_ptr<AutomationControl>();
5238 Route::slaved () const
5240 if (!_gain_control) {
5243 /* just test one particular control, not all of them */
5244 return _gain_control->slaved ();
5248 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5250 if (!vca || !_gain_control) {
5254 /* just test one particular control, not all of them */
5256 return _gain_control->slaved_to (vca->gain_control());
5260 Route::muted_by_others_soloing () const
5262 if (!can_be_muted_by_others ()) {
5266 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5270 Route::clear_all_solo_state ()
5272 double v = _solo_safe_control->get_value ();
5274 _solo_control->clear_all_solo_state ();
5277 _solo_safe_control->set_value (v, Controllable::NoGroup);