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/event_type_map.h"
50 #include "ardour/gain_control.h"
51 #include "ardour/internal_return.h"
52 #include "ardour/internal_send.h"
53 #include "ardour/meter.h"
54 #include "ardour/delayline.h"
55 #include "ardour/midi_buffer.h"
56 #include "ardour/midi_port.h"
57 #include "ardour/monitor_processor.h"
58 #include "ardour/pannable.h"
59 #include "ardour/panner.h"
60 #include "ardour/panner_shell.h"
61 #include "ardour/parameter_descriptor.h"
62 #include "ardour/phase_control.h"
63 #include "ardour/plugin_insert.h"
64 #include "ardour/port.h"
65 #include "ardour/port_insert.h"
66 #include "ardour/processor.h"
67 #include "ardour/profile.h"
68 #include "ardour/route.h"
69 #include "ardour/route_group.h"
70 #include "ardour/send.h"
71 #include "ardour/session.h"
72 #include "ardour/solo_control.h"
73 #include "ardour/solo_isolate_control.h"
74 #include "ardour/unknown_processor.h"
75 #include "ardour/utils.h"
76 #include "ardour/vca.h"
81 using namespace ARDOUR;
84 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
86 /** Base class for all routable/mixable objects (tracks and busses) */
87 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
88 : Stripable (sess, name, PresentationInfo (flag))
89 , GraphNode (sess._process_graph)
90 , Muteable (sess, name)
94 , _signal_latency_at_amp_position (0)
95 , _signal_latency_at_trim_position (0)
98 , _pending_process_reorder (0)
99 , _pending_signals (0)
100 , _pending_declick (true)
101 , _meter_point (MeterPostFader)
102 , _pending_meter_point (MeterPostFader)
103 , _meter_type (MeterPeak)
104 , _denormal_protection (false)
107 , _declickable (false)
108 , _have_internal_generator (false)
109 , _default_type (default_type)
111 , _in_configure_processors (false)
112 , _initial_io_setup (false)
113 , _in_sidechain_setup (false)
115 , _custom_meter_position_noted (false)
118 processor_max_streams.reset();
121 boost::weak_ptr<Route>
122 Route::weakroute () {
123 return boost::weak_ptr<Route> (shared_from_this ());
129 /* set default meter type */
131 _meter_type = Config->get_meter_type_master ();
133 else if (dynamic_cast<Track*>(this)) {
134 _meter_type = Config->get_meter_type_track ();
136 _meter_type = Config->get_meter_type_bus ();
139 /* add standard controls */
141 _gain_control.reset (new GainControl (_session, GainAutomation));
142 add_control (_gain_control);
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 add_control (_trim_control);
147 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
148 add_control (_solo_control);
149 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
151 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
152 add_control (_mute_control);
154 _phase_control.reset (new PhaseControl (_session, X_("phase")));
155 add_control (_phase_control);
157 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
158 add_control (_solo_isolate_control);
160 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
161 add_control (_solo_safe_control);
165 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
166 _pannable.reset (new Pannable (_session));
169 /* input and output objects */
171 _input.reset (new IO (_session, _name, IO::Input, _default_type));
172 _output.reset (new IO (_session, _name, IO::Output, _default_type));
174 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
175 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
177 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
178 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
180 /* add the amp/fader processor.
181 * it should be the first processor to be added on every route.
184 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
185 add_processor (_amp, PostFader);
188 _amp->set_display_name (_("Monitor"));
191 #if 0 // not used - just yet
192 if (!is_master() && !is_monitor() && !is_auditioner()) {
193 _delayline.reset (new DelayLine (_session, _name));
194 add_processor (_delayline, PreFader);
200 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
201 _trim->set_display_to_user (false);
203 if (dynamic_cast<AudioTrack*>(this)) {
204 /* we can't do this in the AudioTrack's constructor
205 * because _trim does not exit then
209 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
214 /* create standard processors: meter, main outs, monitor out;
215 they will be added to _processors by setup_invisible_processors ()
218 _meter.reset (new PeakMeter (_session, _name));
219 _meter->set_owner (this);
220 _meter->set_display_to_user (false);
223 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
224 _main_outs->activate ();
227 /* where we listen to tracks */
228 _intreturn.reset (new InternalReturn (_session));
229 _intreturn->activate ();
231 /* the thing that provides proper control over a control/monitor/listen bus
232 (such as per-channel cut, dim, solo, invert, etc).
234 _monitor_control.reset (new MonitorProcessor (_session));
235 _monitor_control->activate ();
238 /* now that we have _meter, its safe to connect to this */
241 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
242 configure_processors (0);
250 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
252 /* do this early so that we don't get incoming signals as we are going through destruction
257 /* don't use clear_processors here, as it depends on the session which may
258 be half-destroyed by now
261 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
262 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
263 (*i)->drop_references ();
266 _processors.clear ();
270 Route::ensure_track_or_route_name(string name, Session &session)
272 string newname = name;
274 while (!session.io_name_is_legal (newname)) {
275 newname = bump_name_once (newname, ' ');
282 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
284 // TODO route group, see set_gain()
285 // _trim_control->route_set_value (val);
289 Route::maybe_declick (BufferSet&, framecnt_t, int)
291 /* this is the "bus" implementation and they never declick.
296 /** Process this route for one (sub) cycle (process thread)
298 * @param bufs Scratch buffers to use for the signal path
299 * @param start_frame Initial transport frame
300 * @param end_frame Final transport frame
301 * @param nframes Number of frames to output (to ports)
303 * Note that (end_frame - start_frame) may not be equal to nframes when the
304 * transport speed isn't 1.0 (eg varispeed).
307 Route::process_output_buffers (BufferSet& bufs,
308 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
309 int declick, bool gain_automation_ok)
311 /* Caller must hold process lock */
312 assert (!AudioEngine::instance()->process_lock().trylock());
314 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
316 // can this actually happen? functions calling process_output_buffers()
317 // already take a reader-lock.
318 bufs.silence (nframes, 0);
322 _mute_control->automation_run (start_frame, nframes);
324 /* figure out if we're going to use gain automation */
325 if (gain_automation_ok) {
326 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
327 _amp->setup_gain_automation (
328 start_frame + _signal_latency_at_amp_position,
329 end_frame + _signal_latency_at_amp_position,
332 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
333 _trim->setup_gain_automation (
334 start_frame + _signal_latency_at_trim_position,
335 end_frame + _signal_latency_at_trim_position,
338 _amp->apply_gain_automation (false);
339 _trim->apply_gain_automation (false);
342 /* Tell main outs what to do about monitoring. We do this so that
343 on a transition between monitoring states we get a de-clicking gain
344 change in the _main_outs delivery, if config.get_use_monitor_fades()
347 We override this in the case where we have an internal generator.
349 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
351 _main_outs->no_outs_cuz_we_no_monitor (silence);
353 /* -------------------------------------------------------------------------------------------
354 GLOBAL DECLICK (for transport changes etc.)
355 ----------------------------------------------------------------------------------------- */
357 maybe_declick (bufs, nframes, declick);
358 _pending_declick = 0;
360 /* -------------------------------------------------------------------------------------------
361 DENORMAL CONTROL/PHASE INVERT
362 ----------------------------------------------------------------------------------------- */
364 if (!_phase_control->none()) {
368 if (_denormal_protection || Config->get_denormal_protection()) {
370 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
371 Sample* const sp = i->data();
373 if (_phase_control->inverted (chn)) {
374 for (pframes_t nx = 0; nx < nframes; ++nx) {
379 for (pframes_t nx = 0; nx < nframes; ++nx) {
387 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
388 Sample* const sp = i->data();
390 if (_phase_control->inverted (chn)) {
391 for (pframes_t nx = 0; nx < nframes; ++nx) {
400 if (_denormal_protection || Config->get_denormal_protection()) {
402 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
403 Sample* const sp = i->data();
404 for (pframes_t nx = 0; nx < nframes; ++nx) {
412 /* -------------------------------------------------------------------------------------------
414 ----------------------------------------------------------------------------------------- */
416 /* set this to be true if the meter will already have been ::run() earlier */
417 bool const meter_already_run = metering_state() == MeteringInput;
419 framecnt_t latency = 0;
420 const double speed = _session.transport_speed ();
422 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
424 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
425 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
430 /* if it has any inputs, make sure they match */
431 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
432 if (bufs.count() != (*i)->input_streams()) {
434 DEBUG::Processors, string_compose (
435 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
436 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
443 /* should we NOT run plugins here if the route is inactive?
444 do we catch route != active somewhere higher?
447 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
448 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
450 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
451 const framecnt_t longest_session_latency = _initial_delay + _signal_latency;
452 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
453 _initial_delay + latency, longest_session_latency - latency);
456 (*i)->run (bufs, start_frame - latency, end_frame - latency, speed, nframes, *i != _processors.back());
457 bufs.set_count ((*i)->output_streams());
459 if ((*i)->active ()) {
460 latency += (*i)->signal_latency ();
466 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
467 boost::shared_ptr<Processor> endpoint,
468 bool include_endpoint, bool for_export, bool for_freeze)
470 /* If no processing is required, there's no need to go any further. */
471 if (!endpoint && !include_endpoint) {
475 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
476 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
477 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
479 /* trim is always at the top, for bounce no latency compensation is needed */
480 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
481 _trim->setup_gain_automation (start, start + nframes, nframes);
484 const double speed = _session.transport_speed ();
485 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
487 if (!include_endpoint && (*i) == endpoint) {
491 /* if we're *not* exporting, stop processing if we come across a routing processor. */
492 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
495 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
499 /* special case the panner (export outputs)
500 * Ideally we'd only run the panner, not the delivery itself...
501 * but panners need separate input/output buffers and some context
502 * (panshell, panner type, etc). AFAICT there is no ill side effect
503 * of re-using the main delivery when freewheeling/exporting a region.
505 if ((*i) == _main_outs) {
506 assert ((*i)->does_routing());
507 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
508 buffers.set_count ((*i)->output_streams());
511 /* don't run any processors that do routing.
512 * Also don't bother with metering.
514 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
515 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
516 buffers.set_count ((*i)->output_streams());
517 latency += (*i)->signal_latency ();
520 if ((*i) == endpoint) {
527 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
528 bool include_endpoint, bool for_export, bool for_freeze) const
530 framecnt_t latency = 0;
531 if (!endpoint && !include_endpoint) {
535 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
536 if (!include_endpoint && (*i) == endpoint) {
539 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
542 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
545 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
546 latency += (*i)->signal_latency ();
548 if ((*i) == endpoint) {
556 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
557 bool include_endpoint, bool for_export, bool for_freeze) const
559 if (!endpoint && !include_endpoint) {
563 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
564 if (!include_endpoint && (*i) == endpoint) {
567 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
570 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
573 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
574 cc = (*i)->output_streams();
576 if ((*i) == endpoint) {
584 Route::n_process_buffers ()
586 return max (_input->n_ports(), processor_max_streams);
590 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
592 assert (is_monitor());
593 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
594 fill_buffers_with_input (bufs, _input, nframes);
595 passthru (bufs, start_frame, end_frame, nframes, declick);
599 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
603 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
605 /* control/monitor bus ignores input ports when something is
606 feeding the listen "stream". data will "arrive" into the
607 route from the intreturn processor element.
610 bufs.silence (nframes, 0);
613 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
614 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
618 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
620 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
622 bufs.set_count (_input->n_ports());
623 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
624 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
628 Route::set_listen (bool yn)
631 if (_monitor_send->active() == yn) {
635 _monitor_send->activate ();
637 _monitor_send->deactivate ();
643 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
645 /* nothing to do if we're not using AFL/PFL. But if we are, we need
646 to alter the active state of the monitor send.
649 if (Config->get_solo_control_is_listen_control ()) {
650 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
655 Route::push_solo_isolate_upstream (int32_t delta)
657 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
659 boost::shared_ptr<RouteList> routes = _session.get_routes ();
660 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
662 if ((*i).get() == this || !(*i)->can_solo()) {
667 bool does_feed = feeds (*i, &sends_only);
669 if (does_feed && !sends_only) {
670 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
676 Route::push_solo_upstream (int delta)
678 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
679 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
683 boost::shared_ptr<Route> sr (i->r.lock());
685 sr->solo_control()->mod_solo_by_others_downstream (-delta);
692 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
694 cerr << name << " {" << endl;
695 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
696 p != procs.end(); ++p) {
697 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
703 /** Supposing that we want to insert a Processor at a given Placement, return
704 * the processor to add the new one before (or 0 to add at the end).
706 boost::shared_ptr<Processor>
707 Route::before_processor_for_placement (Placement p)
709 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
711 ProcessorList::iterator loc;
714 /* generic pre-fader: insert immediately before the amp */
715 loc = find (_processors.begin(), _processors.end(), _amp);
717 /* generic post-fader: insert right before the main outs */
718 loc = find (_processors.begin(), _processors.end(), _main_outs);
721 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
724 /** Supposing that we want to insert a Processor at a given index, return
725 * the processor to add the new one before (or 0 to add at the end).
727 boost::shared_ptr<Processor>
728 Route::before_processor_for_index (int index)
731 return boost::shared_ptr<Processor> ();
734 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
736 ProcessorList::iterator i = _processors.begin ();
738 while (i != _processors.end() && j < index) {
739 if ((*i)->display_to_user()) {
746 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
749 /** Add a processor either pre- or post-fader
750 * @return 0 on success, non-0 on failure.
753 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
755 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
759 /** Add a processor to a route such that it ends up with a given index into the visible processors.
760 * @param index Index to add the processor at, or -1 to add at the end of the list.
761 * @return 0 on success, non-0 on failure.
764 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
766 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
769 /** Add a processor to the route.
770 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
771 * @return 0 on success, non-0 on failure.
774 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
776 assert (processor != _meter);
777 assert (processor != _main_outs);
779 DEBUG_TRACE (DEBUG::Processors, string_compose (
780 "%1 adding processor %2\n", name(), processor->name()));
784 pl.push_back (processor);
785 int rv = add_processors (pl, before, err);
791 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
792 processor->activate ();
799 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
801 /* We cannot destruct the processor here (usually RT-thread
802 * with various locks held - in case of sends also io_locks).
803 * Queue for deletion in low-priority thread.
805 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
806 selfdestruct_sequence.push_back (wp);
810 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
812 XMLProperty const * prop;
815 boost::shared_ptr<Processor> processor;
817 /* bit of a hack: get the `placement' property from the <Redirect> tag here
818 so that we can add the processor in the right place (pre/post-fader)
821 XMLNodeList const & children = node.children ();
822 XMLNodeList::const_iterator i = children.begin ();
824 while (i != children.end() && (*i)->name() != X_("Redirect")) {
828 Placement placement = PreFader;
830 if (i != children.end()) {
831 if ((prop = (*i)->property (X_("placement"))) != 0) {
832 placement = Placement (string_2_enum (prop->value(), placement));
836 if (node.name() == "Insert") {
838 if ((prop = node.property ("type")) != 0) {
840 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
841 prop->value() == "lv2" ||
842 prop->value() == "windows-vst" ||
843 prop->value() == "mac-vst" ||
844 prop->value() == "lxvst" ||
845 prop->value() == "audiounit") {
847 if (_session.get_disable_all_loaded_plugins ()) {
848 processor.reset (new UnknownProcessor (_session, node));
850 processor.reset (new PluginInsert (_session));
851 processor->set_owner (this);
856 processor.reset (new PortInsert (_session, _pannable, _mute_master));
861 } else if (node.name() == "Send") {
863 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
864 processor.reset (new Send (_session, sendpan, _mute_master));
868 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
872 if (processor->set_state (node, version)) {
876 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
877 if (i != children.end()) {
878 if ((prop = (*i)->property (X_("active"))) != 0) {
879 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
880 processor->activate();
882 processor->deactivate();
886 return (add_processor (processor, placement, 0, false) == 0);
889 catch (failed_constructor &err) {
890 warning << _("processor could not be created. Ignored.") << endmsg;
896 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
897 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
900 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
901 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
905 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
907 ProcessorList::iterator loc;
910 loc = find(_processors.begin(), _processors.end(), before);
911 if (loc == _processors.end ()) {
915 /* nothing specified - at end */
916 loc = _processors.end ();
919 if (!AudioEngine::instance()->connected()) {
923 if (others.empty()) {
927 ProcessorList to_skip;
929 // check if there's an instrument to replace or configure
930 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
931 boost::shared_ptr<PluginInsert> pi;
932 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
935 if (!pi->plugin ()->get_info ()->is_instrument ()) {
938 boost::shared_ptr<Processor> instrument = the_instrument ();
939 ChanCount in (DataType::MIDI, 1);
940 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
942 PluginSetupOptions flags = None;
945 in = instrument->input_streams ();
946 out = instrument->output_streams ();
948 if (pi->has_output_presets (in, out)) {
952 pi->set_strict_io (_strict_io);
954 PluginSetupOptions mask = None;
955 if (Config->get_ask_replace_instrument ()) {
958 if (Config->get_ask_setup_instrument ()) {
965 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
966 switch (rv.get_value_or (0)) {
968 to_skip.push_back (*i); // don't add this one;
971 replace_processor (instrument, *i, err);
972 to_skip.push_back (*i);
981 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
982 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
983 ProcessorState pstate (this);
985 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
990 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
991 if (check != to_skip.end()) {
995 boost::shared_ptr<PluginInsert> pi;
997 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
998 pi->set_strict_io (_strict_io);
1002 /* Ensure that only one amp is in the list at any time */
1003 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1004 if (check != _processors.end()) {
1005 if (before == _amp) {
1006 /* Already in position; all is well */
1009 _processors.erase (check);
1014 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1016 _processors.insert (loc, *i);
1017 (*i)->set_owner (this);
1020 if (configure_processors_unlocked (err, &lm)) {
1022 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1027 if (pi && pi->has_sidechain ()) {
1028 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1031 if ((*i)->active()) {
1032 // emit ActiveChanged() and latency_changed() if needed
1036 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1038 boost::shared_ptr<Send> send;
1039 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1040 send->SelfDestruct.connect_same_thread (*this,
1041 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1045 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1046 boost::shared_ptr<PluginInsert> pi;
1048 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1049 if (pi->has_no_inputs ()) {
1050 _have_internal_generator = true;
1056 _output->set_user_latency (0);
1059 reset_instrument_info ();
1060 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1061 set_processor_positions ();
1067 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1069 if (p == PreFader) {
1070 start = _processors.begin();
1071 end = find(_processors.begin(), _processors.end(), _amp);
1073 start = find(_processors.begin(), _processors.end(), _amp);
1075 end = _processors.end();
1079 /** Turn off all processors with a given placement
1080 * @param p Placement of processors to disable
1083 Route::disable_processors (Placement p)
1085 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1087 ProcessorList::iterator start, end;
1088 placement_range(p, start, end);
1090 for (ProcessorList::iterator i = start; i != end; ++i) {
1091 (*i)->enable (false);
1094 _session.set_dirty ();
1097 /** Turn off all redirects
1100 Route::disable_processors ()
1102 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1104 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1105 (*i)->enable (false);
1108 _session.set_dirty ();
1111 /** Turn off all redirects with a given placement
1112 * @param p Placement of redirects to disable
1115 Route::disable_plugins (Placement p)
1117 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1119 ProcessorList::iterator start, end;
1120 placement_range(p, start, end);
1122 for (ProcessorList::iterator i = start; i != end; ++i) {
1123 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1124 (*i)->enable (false);
1128 _session.set_dirty ();
1131 /** Turn off all plugins
1134 Route::disable_plugins ()
1136 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1138 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1139 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1140 (*i)->enable (false);
1144 _session.set_dirty ();
1149 Route::ab_plugins (bool forward)
1151 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1155 /* forward = turn off all active redirects, and mark them so that the next time
1156 we go the other way, we will revert them
1159 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1160 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1164 if ((*i)->enabled ()) {
1165 (*i)->enable (false);
1166 (*i)->set_next_ab_is_active (true);
1168 (*i)->set_next_ab_is_active (false);
1174 /* backward = if the redirect was marked to go active on the next ab, do so */
1176 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1178 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1182 (*i)->enable ((*i)->get_next_ab_is_active ());
1186 _session.set_dirty ();
1190 /** Remove processors with a given placement.
1191 * @param p Placement of processors to remove.
1194 Route::clear_processors (Placement p)
1196 if (!_session.engine().connected()) {
1200 bool already_deleting = _session.deletion_in_progress();
1201 if (!already_deleting) {
1202 _session.set_deletion_in_progress();
1206 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1207 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1208 ProcessorList new_list;
1209 ProcessorStreams err;
1210 bool seen_amp = false;
1212 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1218 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1220 /* you can't remove these */
1222 new_list.push_back (*i);
1229 new_list.push_back (*i);
1232 (*i)->drop_references ();
1240 (*i)->drop_references ();
1243 new_list.push_back (*i);
1250 _processors = new_list;
1251 configure_processors_unlocked (&err, &lm); // this can't fail
1254 processor_max_streams.reset();
1255 _have_internal_generator = false;
1256 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1257 set_processor_positions ();
1259 reset_instrument_info ();
1261 if (!already_deleting) {
1262 _session.clear_deletion_in_progress();
1267 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1269 // TODO once the export point can be configured properly, do something smarter here
1270 if (processor == _capturing_processor) {
1271 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1272 if (need_process_lock) {
1276 _capturing_processor.reset();
1278 if (need_process_lock) {
1283 /* these can never be removed */
1285 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1289 if (!_session.engine().connected()) {
1293 processor_max_streams.reset();
1296 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1297 if (need_process_lock) {
1301 /* Caller must hold process lock */
1302 assert (!AudioEngine::instance()->process_lock().trylock());
1304 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1306 ProcessorState pstate (this);
1308 ProcessorList::iterator i;
1309 bool removed = false;
1311 for (i = _processors.begin(); i != _processors.end(); ) {
1312 if (*i == processor) {
1314 /* move along, see failure case for configure_processors()
1315 where we may need to reconfigure the processor.
1318 /* stop redirects that send signals to JACK ports
1319 from causing noise as a result of no longer being
1323 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1324 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1328 iop = pi->sidechain();
1335 i = _processors.erase (i);
1343 _output->set_user_latency (0);
1351 if (configure_processors_unlocked (err, &lm)) {
1353 /* we know this will work, because it worked before :) */
1354 configure_processors_unlocked (0, &lm);
1358 _have_internal_generator = false;
1360 for (i = _processors.begin(); i != _processors.end(); ++i) {
1361 boost::shared_ptr<PluginInsert> pi;
1363 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1364 if (pi->has_no_inputs ()) {
1365 _have_internal_generator = true;
1370 if (need_process_lock) {
1375 reset_instrument_info ();
1376 processor->drop_references ();
1377 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1378 set_processor_positions ();
1384 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1386 /* these can never be removed */
1387 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1390 /* and can't be used as substitute, either */
1391 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1395 /* I/Os are out, too */
1396 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1400 /* this function cannot be used to swap/reorder processors */
1401 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1405 if (!AudioEngine::instance()->connected() || !old || !sub) {
1409 /* ensure that sub is not owned by another route */
1410 if (sub->owner ()) {
1415 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1416 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1417 ProcessorState pstate (this);
1419 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1421 ProcessorList::iterator i;
1422 bool replaced = false;
1423 bool enable = old->enabled ();
1425 for (i = _processors.begin(); i != _processors.end(); ) {
1427 i = _processors.erase (i);
1428 _processors.insert (i, sub);
1429 sub->set_owner (this);
1442 boost::shared_ptr<PluginInsert> pi;
1443 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1444 pi->set_strict_io (true);
1448 if (configure_processors_unlocked (err, &lm)) {
1450 configure_processors_unlocked (0, &lm);
1454 _have_internal_generator = false;
1456 for (i = _processors.begin(); i != _processors.end(); ++i) {
1457 boost::shared_ptr<PluginInsert> pi;
1458 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1459 if (pi->has_no_inputs ()) {
1460 _have_internal_generator = true;
1470 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1471 _output->set_user_latency (0);
1474 reset_instrument_info ();
1475 old->drop_references ();
1476 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1477 set_processor_positions ();
1482 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1484 ProcessorList deleted;
1486 if (!_session.engine().connected()) {
1490 processor_max_streams.reset();
1493 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1494 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1495 ProcessorState pstate (this);
1497 ProcessorList::iterator i;
1498 boost::shared_ptr<Processor> processor;
1500 for (i = _processors.begin(); i != _processors.end(); ) {
1504 /* these can never be removed */
1506 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1511 /* see if its in the list of processors to delete */
1513 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1518 /* stop IOProcessors that send to JACK ports
1519 from causing noise as a result of no longer being
1523 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1524 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1527 iop = pi->sidechain();
1534 deleted.push_back (processor);
1535 i = _processors.erase (i);
1538 if (deleted.empty()) {
1539 /* none of those in the requested list were found */
1543 _output->set_user_latency (0);
1545 if (configure_processors_unlocked (err, &lm)) {
1547 /* we know this will work, because it worked before :) */
1548 configure_processors_unlocked (0, &lm);
1553 _have_internal_generator = false;
1555 for (i = _processors.begin(); i != _processors.end(); ++i) {
1556 boost::shared_ptr<PluginInsert> pi;
1558 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1559 if (pi->has_no_inputs ()) {
1560 _have_internal_generator = true;
1567 /* now try to do what we need to so that those that were removed will be deleted */
1569 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1570 (*i)->drop_references ();
1573 reset_instrument_info ();
1574 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1575 set_processor_positions ();
1581 Route::reset_instrument_info ()
1583 boost::shared_ptr<Processor> instr = the_instrument();
1585 _instrument_info.set_internal_instrument (instr);
1589 /** Caller must hold process lock */
1591 Route::configure_processors (ProcessorStreams* err)
1593 #ifndef PLATFORM_WINDOWS
1594 assert (!AudioEngine::instance()->process_lock().trylock());
1597 if (!_in_configure_processors) {
1598 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1599 return configure_processors_unlocked (err, &lm);
1606 Route::input_streams () const
1608 return _input->n_ports ();
1611 list<pair<ChanCount, ChanCount> >
1612 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1614 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1616 return try_configure_processors_unlocked (in, err);
1619 list<pair<ChanCount, ChanCount> >
1620 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1622 // Check each processor in order to see if we can configure as requested
1624 list<pair<ChanCount, ChanCount> > configuration;
1627 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1628 DEBUG_TRACE (DEBUG::Processors, "{\n");
1630 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1632 if ((*p)->can_support_io_configuration(in, out)) {
1634 if (boost::dynamic_pointer_cast<Delivery> (*p)
1635 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1637 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1638 /* with strict I/O the panner + output are forced to
1639 * follow the last processor's output.
1641 * Delivery::can_support_io_configuration() will only add ports,
1642 * but not remove excess ports.
1644 * This works because the delivery only requires
1645 * as many outputs as there are inputs.
1646 * Delivery::configure_io() will do the actual removal
1647 * by calling _output->ensure_io()
1649 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1650 /* ..but at least as many as there are master-inputs, if
1651 * the delivery is dealing with audio */
1652 // XXX this may need special-casing for mixbus (master-outputs)
1653 // and should maybe be a preference anyway ?!
1654 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1660 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1661 configuration.push_back(make_pair(in, out));
1664 // restriction for Monitor Section Processors
1665 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1666 /* Note: The Monitor follows the master-bus and has no panner.
1668 * The general idea is to only allow plugins that retain the channel-count
1669 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1670 * Then again 5.1 in, monitor stereo is a valid use-case.
1672 * and worse: we only refuse adding plugins *here*.
1674 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1675 * 2) change master-bus, add a channel
1676 * 2a) monitor-secion follows
1677 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1678 * 4) re-load session, monitor-processor remains unconfigured, crash.
1680 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1682 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1683 // internal sends make no sense, only feedback
1684 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1685 return list<pair<ChanCount, ChanCount> > ();
1687 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1688 /* External Sends can be problematic. one can add/remove ports
1689 * there signal leaves the DAW to external monitors anyway, so there's
1690 * no real use for allowing them here anyway.
1692 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1693 return list<pair<ChanCount, ChanCount> > ();
1695 if (boost::dynamic_pointer_cast<Send> (*p)) {
1697 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1698 return list<pair<ChanCount, ChanCount> > ();
1707 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1708 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1709 DEBUG_TRACE (DEBUG::Processors, "}\n");
1710 return list<pair<ChanCount, ChanCount> > ();
1714 DEBUG_TRACE (DEBUG::Processors, "}\n");
1716 return configuration;
1719 /** Set the input/output configuration of each processor in the processors list.
1720 * Caller must hold process lock.
1721 * Return 0 on success, otherwise configuration is impossible.
1724 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1726 #ifndef PLATFORM_WINDOWS
1727 assert (!AudioEngine::instance()->process_lock().trylock());
1730 if (_in_configure_processors) {
1734 /* put invisible processors where they should be */
1735 setup_invisible_processors ();
1737 _in_configure_processors = true;
1739 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1741 if (configuration.empty ()) {
1742 _in_configure_processors = false;
1747 bool seen_mains_out = false;
1748 processor_out_streams = _input->n_ports();
1749 processor_max_streams.reset();
1751 /* processor configure_io() may result in adding ports
1752 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1754 * with jack2 adding ports results in a graph-order callback,
1755 * which calls Session::resort_routes() and eventually
1756 * Route::direct_feeds_according_to_reality()
1757 * which takes a ReaderLock (_processor_lock).
1759 * so we can't hold a WriterLock here until jack2 threading
1762 * NB. we still hold the process lock
1764 * (ardour's own engines do call graph-order from the
1765 * process-thread and hence do not have this issue; besides
1766 * merely adding ports won't trigger a graph-order, only
1767 * making connections does)
1771 // TODO check for a potential ReaderLock after ReaderLock ??
1772 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1774 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1775 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1777 if (!(*p)->configure_io(c->first, c->second)) {
1778 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1779 _in_configure_processors = false;
1784 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1785 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1787 boost::shared_ptr<IOProcessor> iop;
1788 boost::shared_ptr<PluginInsert> pi;
1789 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1790 /* plugins connected via Split or Hide Match may have more channels.
1791 * route/scratch buffers are needed for all of them
1792 * The configuration may only be a subset (both input and output)
1794 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1796 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1797 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1798 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1802 if (boost::dynamic_pointer_cast<Delivery> (*p)
1803 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1804 /* main delivery will increase port count to match input.
1805 * the Delivery::Main is usually the last processor - followed only by
1808 seen_mains_out = true;
1810 if (!seen_mains_out) {
1811 processor_out_streams = out;
1820 _meter->set_max_channels (processor_max_streams);
1823 /* make sure we have sufficient scratch buffers to cope with the new processor
1826 _session.ensure_buffers (n_process_buffers ());
1828 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1830 _in_configure_processors = false;
1834 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1835 * @param state New active state for those processors.
1838 Route::all_visible_processors_active (bool state)
1840 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1842 if (_processors.empty()) {
1846 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1847 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1850 (*i)->enable (state);
1853 _session.set_dirty ();
1857 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1859 /* check if re-order requires re-configuration of any processors
1860 * -> compare channel configuration for all processors
1862 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1863 ChanCount c = input_streams ();
1865 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1867 if (c != (*j)->input_streams()) {
1870 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1873 if ((*i)->input_streams() != c) {
1876 c = (*i)->output_streams();
1888 __attribute__((annotate("realtime")))
1891 Route::apply_processor_order (const ProcessorList& new_order)
1893 /* need to hold processor_lock; either read or write lock
1894 * and the engine process_lock.
1895 * Due to r/w lock ambiguity we can only assert the latter
1897 assert (!AudioEngine::instance()->process_lock().trylock());
1900 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1901 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1902 * processors in the current actual processor list that are hidden. Any visible processors
1903 * in the current list but not in "new_order" will be assumed to be deleted.
1906 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1907 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1908 * (note though that ::processors_reorder_needs_configure() ensured that
1909 * this function will only ever be called from the rt-thread if no processor were removed)
1911 * either way, I can't proove it, but an x-run due to re-order here is less likley
1912 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1915 ProcessorList as_it_will_be;
1916 ProcessorList::iterator oiter;
1917 ProcessorList::const_iterator niter;
1919 oiter = _processors.begin();
1920 niter = new_order.begin();
1922 while (niter != new_order.end()) {
1924 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1925 then append it to the temp list.
1927 Otherwise, see if the next processor in the old list is in the new list. if not,
1928 its been deleted. If its there, append it to the temp list.
1931 if (oiter == _processors.end()) {
1933 /* no more elements in the old list, so just stick the rest of
1934 the new order onto the temp list.
1937 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1938 while (niter != new_order.end()) {
1945 if (!(*oiter)->display_to_user()) {
1947 as_it_will_be.push_back (*oiter);
1951 /* visible processor: check that its in the new order */
1953 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1954 /* deleted: do nothing, shared_ptr<> will clean up */
1956 /* ignore this one, and add the next item from the new order instead */
1957 as_it_will_be.push_back (*niter);
1962 /* now remove from old order - its taken care of no matter what */
1963 oiter = _processors.erase (oiter);
1967 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1969 /* If the meter is in a custom position, find it and make a rough note of its position */
1970 maybe_note_meter_position ();
1974 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1976 // it a change is already queued, wait for it
1977 // (unless engine is stopped. apply immediately and proceed
1978 while (g_atomic_int_get (&_pending_process_reorder)) {
1979 if (!AudioEngine::instance()->running()) {
1980 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
1981 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1983 apply_processor_order(_pending_processor_order);
1984 setup_invisible_processors ();
1986 g_atomic_int_set (&_pending_process_reorder, 0);
1988 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1989 set_processor_positions ();
1991 // TODO rather use a semaphore or something.
1992 // but since ::reorder_processors() is called
1993 // from the GUI thread, this is fine..
1998 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2000 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2001 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2002 ProcessorState pstate (this);
2004 apply_processor_order (new_order);
2006 if (configure_processors_unlocked (err, &lm)) {
2014 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2015 set_processor_positions ();
2018 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2019 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2021 // _pending_processor_order is protected by _processor_lock
2022 _pending_processor_order = new_order;
2023 g_atomic_int_set (&_pending_process_reorder, 1);
2030 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2032 boost::shared_ptr<PluginInsert> pi;
2033 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2037 if (pi->has_sidechain () == add) {
2038 return true; // ?? call failed, but result is as expected.
2042 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2043 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2044 if (i == _processors.end ()) {
2050 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2051 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2052 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2054 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2056 if (!pi->add_sidechain ()) {
2060 if (!pi->del_sidechain ()) {
2066 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2071 pi->del_sidechain ();
2073 pi->add_sidechain ();
2074 // TODO restore side-chain's state.
2079 configure_processors_unlocked (0, &lm);
2082 if (pi->has_sidechain ()) {
2083 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2086 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2087 _session.set_dirty ();
2092 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2094 boost::shared_ptr<PluginInsert> pi;
2095 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2100 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2101 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2102 if (i == _processors.end ()) {
2108 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2109 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2111 const ChanCount& old (pi->preset_out ());
2112 if (!pi->set_preset_out (outs)) {
2113 return true; // no change, OK
2116 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2119 pi->set_preset_out (old);
2122 configure_processors_unlocked (0, &lm);
2125 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2126 _session.set_dirty ();
2131 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2134 return customize_plugin_insert (proc, 0, unused, unused);
2138 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2140 boost::shared_ptr<PluginInsert> pi;
2141 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2146 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2147 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2148 if (i == _processors.end ()) {
2154 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2155 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2157 bool old_cust = pi->custom_cfg ();
2158 uint32_t old_cnt = pi->get_count ();
2159 ChanCount old_chan = pi->output_streams ();
2160 ChanCount old_sinks = pi->natural_input_streams ();
2163 pi->set_custom_cfg (false);
2165 pi->set_custom_cfg (true);
2166 pi->set_count (count);
2167 pi->set_outputs (outs);
2168 pi->set_sinks (sinks);
2171 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2175 pi->set_count (old_cnt);
2176 pi->set_sinks (old_sinks);
2177 pi->set_outputs (old_chan);
2178 pi->set_custom_cfg (old_cust);
2182 configure_processors_unlocked (0, &lm);
2185 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2186 _session.set_dirty ();
2191 Route::set_strict_io (const bool enable)
2193 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2195 if (_strict_io != enable) {
2196 _strict_io = enable;
2197 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2198 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2199 boost::shared_ptr<PluginInsert> pi;
2200 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2201 pi->set_strict_io (_strict_io);
2205 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2209 _strict_io = !enable; // restore old value
2210 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2211 boost::shared_ptr<PluginInsert> pi;
2212 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2213 pi->set_strict_io (_strict_io);
2220 configure_processors (0);
2223 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2224 _session.set_dirty ();
2236 Route::get_template()
2238 return state(false);
2242 Route::state(bool full_state)
2245 if (!_session._template_state_dir.empty()) {
2246 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2249 XMLNode *node = new XMLNode("Route");
2250 ProcessorList::iterator i;
2253 id().print (buf, sizeof (buf));
2254 node->add_property("id", buf);
2255 node->add_property ("name", _name);
2256 node->add_property("default-type", _default_type.to_string());
2257 node->add_property ("strict-io", _strict_io);
2259 node->add_child_nocopy (_presentation_info.get_state());
2261 node->add_property("active", _active?"yes":"no");
2263 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2264 node->add_property("meter-point", enum_2_string (_meter_point));
2266 node->add_property("meter-type", enum_2_string (_meter_type));
2269 node->add_property("route-group", _route_group->name());
2272 node->add_child_nocopy (_solo_control->get_state ());
2273 node->add_child_nocopy (_solo_isolate_control->get_state ());
2274 node->add_child_nocopy (_solo_safe_control->get_state ());
2276 node->add_child_nocopy (_input->state (full_state));
2277 node->add_child_nocopy (_output->state (full_state));
2278 node->add_child_nocopy (_mute_master->get_state ());
2280 node->add_child_nocopy (_mute_control->get_state ());
2281 node->add_child_nocopy (_phase_control->get_state ());
2284 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2287 if (_comment.length()) {
2288 XMLNode *cmt = node->add_child ("Comment");
2289 cmt->add_content (_comment);
2293 node->add_child_nocopy (_pannable->state (full_state));
2297 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2298 for (i = _processors.begin(); i != _processors.end(); ++i) {
2300 /* template save: do not include internal sends functioning as
2301 aux sends because the chance of the target ID
2302 in the session where this template is used
2305 similarly, do not save listen sends which connect to
2306 the monitor section, because these will always be
2309 boost::shared_ptr<InternalSend> is;
2311 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2312 if (is->role() == Delivery::Listen) {
2317 node->add_child_nocopy((*i)->state (full_state));
2322 node->add_child_copy (*_extra_xml);
2325 if (_custom_meter_position_noted) {
2326 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2328 after->id().print (buf, sizeof (buf));
2329 node->add_property (X_("processor-after-last-custom-meter"), buf);
2333 if (!_session._template_state_dir.empty()) {
2334 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2337 node->add_child_copy (Slavable::get_state());
2343 Route::set_state (const XMLNode& node, int version)
2345 if (version < 3000) {
2346 return set_state_2X (node, version);
2350 XMLNodeConstIterator niter;
2352 XMLProperty const * prop;
2354 if (node.name() != "Route"){
2355 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2359 if ((prop = node.property (X_("name"))) != 0) {
2360 Route::set_name (prop->value());
2364 _initial_io_setup = true;
2366 Stripable::set_state (node, version);
2368 if ((prop = node.property (X_("strict-io"))) != 0) {
2369 _strict_io = string_is_affirmative (prop->value());
2373 /* monitor bus does not get a panner, but if (re)created
2374 via XML, it will already have one by the time we
2375 call ::set_state(). so ... remove it.
2380 /* add all processors (except amp, which is always present) */
2382 nlist = node.children();
2383 XMLNode processor_state (X_("processor_state"));
2385 Stateful::save_extra_xml (node);
2387 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2391 if (child->name() == IO::state_node_name) {
2392 if ((prop = child->property (X_("direction"))) == 0) {
2396 if (prop->value() == "Input") {
2397 _input->set_state (*child, version);
2398 } else if (prop->value() == "Output") {
2399 _output->set_state (*child, version);
2402 } else if (child->name() == X_("Processor")) {
2403 processor_state.add_child_copy (*child);
2404 } else if (child->name() == X_("Pannable")) {
2406 _pannable->set_state (*child, version);
2408 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2410 } else if (child->name() == Slavable::xml_node_name) {
2411 Slavable::set_state (*child, version);
2415 if ((prop = node.property (X_("meter-point"))) != 0) {
2416 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2417 set_meter_point (mp, true);
2419 _meter->set_display_to_user (_meter_point == MeterCustom);
2423 if ((prop = node.property (X_("meter-type"))) != 0) {
2424 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2427 _initial_io_setup = false;
2429 set_processor_state (processor_state);
2431 // this looks up the internal instrument in processors
2432 reset_instrument_info();
2434 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2435 set_denormal_protection (string_is_affirmative (prop->value()));
2438 if ((prop = node.property (X_("active"))) != 0) {
2439 bool yn = string_is_affirmative (prop->value());
2440 set_active (yn, this);
2443 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2444 PBD::ID id (prop->value ());
2445 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2446 ProcessorList::const_iterator i = _processors.begin ();
2447 while (i != _processors.end() && (*i)->id() != id) {
2451 if (i != _processors.end ()) {
2452 _processor_after_last_custom_meter = *i;
2453 _custom_meter_position_noted = true;
2457 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2460 if (child->name() == X_("Comment")) {
2462 /* XXX this is a terrible API design in libxml++ */
2464 XMLNode *cmt = *(child->children().begin());
2465 _comment = cmt->content();
2467 } else if (child->name() == Controllable::xml_node_name) {
2468 if ((prop = child->property (X_("name"))) == 0) {
2472 if (prop->value() == _gain_control->name()) {
2473 _gain_control->set_state (*child, version);
2474 } else if (prop->value() == _solo_control->name()) {
2475 _solo_control->set_state (*child, version);
2476 } else if (prop->value() == _solo_safe_control->name()) {
2477 _solo_safe_control->set_state (*child, version);
2478 } else if (prop->value() == _solo_isolate_control->name()) {
2479 _solo_isolate_control->set_state (*child, version);
2480 } else if (prop->value() == _mute_control->name()) {
2481 _mute_control->set_state (*child, version);
2482 } else if (prop->value() == _phase_control->name()) {
2483 _phase_control->set_state (*child, version);
2485 Evoral::Parameter p = EventTypeMap::instance().from_symbol (prop->value());
2486 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2487 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2489 ac->set_state (*child, version);
2493 } else if (child->name() == MuteMaster::xml_node_name) {
2494 _mute_master->set_state (*child, version);
2496 } else if (child->name() == Automatable::xml_node_name) {
2497 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2505 Route::set_state_2X (const XMLNode& node, int version)
2509 XMLNodeConstIterator niter;
2511 XMLProperty const * prop;
2513 /* 2X things which still remain to be handled:
2519 if (node.name() != "Route") {
2520 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2524 Stripable::set_state (node, version);
2526 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2527 set_denormal_protection (string_is_affirmative (prop->value()));
2530 if ((prop = node.property (X_("muted"))) != 0) {
2533 bool muted = string_is_affirmative (prop->value());
2539 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2541 if (string_is_affirmative (prop->value())){
2542 mute_point = mute_point + "PreFader";
2547 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2549 if (string_is_affirmative (prop->value())){
2552 mute_point = mute_point + ",";
2555 mute_point = mute_point + "PostFader";
2560 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2562 if (string_is_affirmative (prop->value())){
2565 mute_point = mute_point + ",";
2568 mute_point = mute_point + "Listen";
2573 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2575 if (string_is_affirmative (prop->value())){
2578 mute_point = mute_point + ",";
2581 mute_point = mute_point + "Main";
2585 _mute_master->set_mute_points (mute_point);
2586 _mute_master->set_muted_by_self (true);
2590 if ((prop = node.property (X_("meter-point"))) != 0) {
2591 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2596 nlist = node.children ();
2597 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2601 if (child->name() == IO::state_node_name) {
2603 /* there is a note in IO::set_state_2X() about why we have to call
2607 _input->set_state_2X (*child, version, true);
2608 _output->set_state_2X (*child, version, false);
2610 if ((prop = child->property (X_("name"))) != 0) {
2611 Route::set_name (prop->value ());
2616 if ((prop = child->property (X_("active"))) != 0) {
2617 bool yn = string_is_affirmative (prop->value());
2618 _active = !yn; // force switch
2619 set_active (yn, this);
2622 if ((prop = child->property (X_("gain"))) != 0) {
2625 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2626 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2630 /* Set up Panners in the IO */
2631 XMLNodeList io_nlist = child->children ();
2633 XMLNodeConstIterator io_niter;
2636 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2638 io_child = *io_niter;
2640 if (io_child->name() == X_("Panner")) {
2641 _main_outs->panner_shell()->set_state(*io_child, version);
2642 } else if (io_child->name() == X_("Automation")) {
2643 /* IO's automation is for the fader */
2644 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2650 XMLNodeList redirect_nodes;
2652 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2656 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2657 redirect_nodes.push_back(child);
2662 set_processor_state_2X (redirect_nodes, version);
2664 Stateful::save_extra_xml (node);
2666 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2669 if (child->name() == X_("Comment")) {
2671 /* XXX this is a terrible API design in libxml++ */
2673 XMLNode *cmt = *(child->children().begin());
2674 _comment = cmt->content();
2676 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2677 if (prop->value() == X_("solo")) {
2678 _solo_control->set_state (*child, version);
2679 } else if (prop->value() == X_("mute")) {
2680 _mute_control->set_state (*child, version);
2690 Route::get_processor_state ()
2692 XMLNode* root = new XMLNode (X_("redirects"));
2693 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2694 root->add_child_nocopy ((*i)->state (true));
2701 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2703 /* We don't bother removing existing processors not in nList, as this
2704 method will only be called when creating a Route from scratch, not
2705 for undo purposes. Just put processors in at the appropriate place
2709 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2710 add_processor_from_xml_2X (**i, version);
2715 Route::set_processor_state (const XMLNode& node)
2717 const XMLNodeList &nlist = node.children();
2718 XMLNodeConstIterator niter;
2719 ProcessorList new_order;
2720 bool must_configure = false;
2722 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2724 XMLProperty* prop = (*niter)->property ("type");
2726 if (prop->value() == "amp") {
2727 _amp->set_state (**niter, Stateful::current_state_version);
2728 new_order.push_back (_amp);
2729 } else if (prop->value() == "trim") {
2730 _trim->set_state (**niter, Stateful::current_state_version);
2731 new_order.push_back (_trim);
2732 } else if (prop->value() == "meter") {
2733 _meter->set_state (**niter, Stateful::current_state_version);
2734 new_order.push_back (_meter);
2735 } else if (prop->value() == "delay") {
2737 _delayline->set_state (**niter, Stateful::current_state_version);
2738 new_order.push_back (_delayline);
2740 } else if (prop->value() == "main-outs") {
2741 _main_outs->set_state (**niter, Stateful::current_state_version);
2742 } else if (prop->value() == "intreturn") {
2744 _intreturn.reset (new InternalReturn (_session));
2745 must_configure = true;
2747 _intreturn->set_state (**niter, Stateful::current_state_version);
2748 } else if (is_monitor() && prop->value() == "monitor") {
2749 if (!_monitor_control) {
2750 _monitor_control.reset (new MonitorProcessor (_session));
2751 must_configure = true;
2753 _monitor_control->set_state (**niter, Stateful::current_state_version);
2754 } else if (prop->value() == "capture") {
2755 /* CapturingProcessor should never be restored, it's always
2756 added explicitly when needed */
2758 ProcessorList::iterator o;
2760 for (o = _processors.begin(); o != _processors.end(); ++o) {
2761 XMLProperty const * id_prop = (*niter)->property(X_("id"));
2762 if (id_prop && (*o)->id() == id_prop->value()) {
2763 (*o)->set_state (**niter, Stateful::current_state_version);
2764 new_order.push_back (*o);
2769 // If the processor (*niter) is not on the route then create it
2771 if (o == _processors.end()) {
2773 boost::shared_ptr<Processor> processor;
2775 if (prop->value() == "intsend") {
2777 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2779 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2780 prop->value() == "lv2" ||
2781 prop->value() == "windows-vst" ||
2782 prop->value() == "mac-vst" ||
2783 prop->value() == "lxvst" ||
2784 prop->value() == "luaproc" ||
2785 prop->value() == "audiounit") {
2787 if (_session.get_disable_all_loaded_plugins ()) {
2788 processor.reset (new UnknownProcessor (_session, **niter));
2790 processor.reset (new PluginInsert (_session));
2791 processor->set_owner (this);
2793 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2794 pi->set_strict_io (true);
2798 } else if (prop->value() == "port") {
2800 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2802 } else if (prop->value() == "send") {
2804 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2805 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2806 send->SelfDestruct.connect_same_thread (*this,
2807 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2810 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2814 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2815 /* This processor could not be configured. Turn it into a UnknownProcessor */
2816 processor.reset (new UnknownProcessor (_session, **niter));
2819 /* subscribe to Sidechain IO changes */
2820 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2821 if (pi && pi->has_sidechain ()) {
2822 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2825 /* we have to note the monitor send here, otherwise a new one will be created
2826 and the state of this one will be lost.
2828 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2829 if (isend && isend->role() == Delivery::Listen) {
2830 _monitor_send = isend;
2833 /* it doesn't matter if invisible processors are added here, as they
2834 will be sorted out by setup_invisible_processors () shortly.
2837 new_order.push_back (processor);
2838 must_configure = true;
2844 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2845 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2846 /* re-assign _processors w/o process-lock.
2847 * if there's an IO-processor present in _processors but
2848 * not in new_order, it will be deleted and ~IO takes
2851 _processors = new_order;
2853 if (must_configure) {
2854 configure_processors_unlocked (0, &lm);
2857 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2859 (*i)->set_owner (this);
2860 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2862 boost::shared_ptr<PluginInsert> pi;
2864 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2865 if (pi->has_no_inputs ()) {
2866 _have_internal_generator = true;
2873 reset_instrument_info ();
2874 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2875 set_processor_positions ();
2879 Route::curve_reallocate ()
2881 // _gain_automation_curve.finish_resize ();
2882 // _pan_automation_curve.finish_resize ();
2886 Route::silence (framecnt_t nframes)
2888 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2893 silence_unlocked (nframes);
2897 Route::silence_unlocked (framecnt_t nframes)
2899 /* Must be called with the processor lock held */
2901 const framepos_t now = _session.transport_frame ();
2905 _output->silence (nframes);
2907 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2908 boost::shared_ptr<PluginInsert> pi;
2910 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2911 // skip plugins, they don't need anything when we're not active
2915 (*i)->silence (nframes, now);
2918 if (nframes == _session.get_block_size()) {
2925 Route::add_internal_return ()
2928 _intreturn.reset (new InternalReturn (_session));
2929 add_processor (_intreturn, PreFader);
2934 Route::add_send_to_internal_return (InternalSend* send)
2936 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2938 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2939 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2942 return d->add_send (send);
2948 Route::remove_send_from_internal_return (InternalSend* send)
2950 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2952 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2953 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2956 return d->remove_send (send);
2962 Route::enable_monitor_send ()
2964 /* Caller must hold process lock */
2965 assert (!AudioEngine::instance()->process_lock().trylock());
2967 /* master never sends to monitor section via the normal mechanism */
2968 assert (!is_master ());
2969 assert (!is_monitor ());
2971 /* make sure we have one */
2972 if (!_monitor_send) {
2973 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
2974 _monitor_send->set_display_to_user (false);
2978 configure_processors (0);
2981 /** Add an aux send to a route.
2982 * @param route route to send to.
2983 * @param before Processor to insert before, or 0 to insert at the end.
2986 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2988 assert (route != _session.monitor_out ());
2991 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2993 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2995 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2997 if (d && d->target_route() == route) {
2998 /* already listening via the specified IO: do nothing */
3006 boost::shared_ptr<InternalSend> listener;
3009 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3010 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3013 add_processor (listener, before);
3015 } catch (failed_constructor& err) {
3023 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3025 ProcessorStreams err;
3026 ProcessorList::iterator tmp;
3029 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3031 /* have to do this early because otherwise processor reconfig
3032 * will put _monitor_send back in the list
3035 if (route == _session.monitor_out()) {
3036 _monitor_send.reset ();
3040 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3042 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3044 if (d && d->target_route() == route) {
3046 if (remove_processor (*x, &err, false) > 0) {
3052 /* list could have been demolished while we dropped the lock
3055 if (_session.engine().connected()) {
3056 /* i/o processors cannot be removed if the engine is not running
3057 * so don't live-loop in case the engine is N/A or dies
3067 Route::set_comment (string cmt, void *src)
3071 _session.set_dirty ();
3075 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3077 FeedRecord fr (other, via_sends_only);
3079 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3081 if (!result.second) {
3083 /* already a record for "other" - make sure sends-only information is correct */
3084 if (!via_sends_only && result.first->sends_only) {
3085 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3086 frp->sends_only = false;
3090 return result.second;
3094 Route::clear_fed_by ()
3100 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3102 const FedBy& fed_by (other->fed_by());
3104 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3105 boost::shared_ptr<Route> sr = f->r.lock();
3107 if (sr && (sr.get() == this)) {
3109 if (via_sends_only) {
3110 *via_sends_only = f->sends_only;
3121 Route::all_inputs () const
3123 /* TODO, if this works as expected,
3124 * cache the IOVector and maintain it via
3125 * input_change_handler(), sidechain_change_handler() etc
3128 ios.push_back (_input);
3130 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3131 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3133 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3134 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3137 iop = pi->sidechain();
3140 if (iop != 0 && iop->input()) {
3141 ios.push_back (iop->input());
3148 Route::all_outputs () const
3151 // _output is included via Delivery
3152 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3153 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3154 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3155 if (iop != 0 && iop->output()) {
3156 ios.push_back (iop->output());
3163 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3165 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3166 if (other->all_inputs().fed_by (_output)) {
3167 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3168 if (via_send_only) {
3169 *via_send_only = false;
3175 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3177 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3179 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3180 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3183 iop = pi->sidechain();
3187 boost::shared_ptr<const IO> iop_out = iop->output();
3188 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3189 // TODO this needs a delaylines in the Insert to align connections (!)
3190 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3193 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3194 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3195 if (via_send_only) {
3196 *via_send_only = true;
3200 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3203 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3208 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3213 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3215 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3219 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3221 return _session._current_route_graph.feeds (shared_from_this (), other);
3224 /** Called from the (non-realtime) butler thread when the transport is stopped */
3226 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3228 framepos_t now = _session.transport_frame();
3231 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3233 Automatable::transport_stopped (now);
3235 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3237 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3241 (*i)->transport_stopped (now);
3245 _roll_delay = _initial_delay;
3249 Route::input_change_handler (IOChange change, void * /*src*/)
3251 if ((change.type & IOChange::ConfigurationChanged)) {
3252 /* This is called with the process lock held if change
3253 contains ConfigurationChanged
3255 configure_processors (0);
3256 _phase_control->resize (_input->n_ports().n_audio ());
3257 io_changed (); /* EMIT SIGNAL */
3260 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3263 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3264 if (_input->connected()) {
3265 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3266 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3270 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3271 if (does_feed && !sends_only) {
3272 if ((*i)->soloed()) {
3275 if ((*i)->solo_isolate_control()->solo_isolated()) {
3282 int delta = sbou - _solo_control->soloed_by_others_upstream();
3283 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3286 PBD::warning << string_compose (
3287 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3288 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3293 if (_solo_control->soloed_by_others_upstream()) {
3294 // ignore new connections (they're not propagated)
3296 _solo_control->mod_solo_by_others_upstream (delta);
3300 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3301 // solo-isolate currently only propagates downstream
3303 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3305 //_solo_isolated_by_upstream = ibou;
3308 // Session::route_solo_changed does not propagate indirect solo-changes
3309 // propagate downstream to tracks
3310 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3311 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3315 bool does_feed = feeds (*i, &sends_only);
3316 if (delta <= 0 && does_feed && !sends_only) {
3317 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3320 if (idelta < 0 && does_feed && !sends_only) {
3321 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3328 Route::output_change_handler (IOChange change, void * /*src*/)
3330 if (_initial_io_setup) {
3334 if ((change.type & IOChange::ConfigurationChanged)) {
3335 /* This is called with the process lock held if change
3336 contains ConfigurationChanged
3338 configure_processors (0);
3341 _session.reset_monitor_section();
3344 io_changed (); /* EMIT SIGNAL */
3347 if (_solo_control->soloed_by_others_downstream()) {
3349 /* checking all all downstream routes for
3350 * explicit of implict solo is a rather drastic measure,
3351 * ideally the input_change_handler() of the other route
3352 * would propagate the change to us.
3354 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3355 if (_output->connected()) {
3356 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3357 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3361 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3362 if (does_feed && !sends_only) {
3363 if ((*i)->soloed()) {
3370 int delta = sbod - _solo_control->soloed_by_others_downstream();
3372 // do not allow new connections to change implicit solo (no propagation)
3373 _solo_control->mod_solo_by_others_downstream (delta);
3374 // Session::route_solo_changed() does not propagate indirect solo-changes
3375 // propagate upstream to tracks
3376 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3377 if ((*i).get() == this || !can_solo()) {
3381 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3382 if (delta != 0 && does_feed && !sends_only) {
3383 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3392 Route::sidechain_change_handler (IOChange change, void* src)
3394 if (_initial_io_setup || _in_sidechain_setup) {
3398 input_change_handler (change, src);
3402 Route::pans_required () const
3404 if (n_outputs().n_audio() < 2) {
3408 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3412 Route::flush_processor_buffers_locked (framecnt_t nframes)
3414 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3415 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3417 d->flush_buffers (nframes);
3419 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3421 p->flush_buffers (nframes);
3428 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3430 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3436 if (n_outputs().n_total() == 0) {
3440 if (!_active || n_inputs() == ChanCount::ZERO) {
3441 silence_unlocked (nframes);
3445 if (session_state_changing) {
3446 if (_session.transport_speed() != 0.0f) {
3447 /* we're rolling but some state is changing (e.g. our diskstream contents)
3448 so we cannot use them. Be silent till this is over.
3450 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3452 silence_unlocked (nframes);
3455 /* we're really not rolling, so we're either delivery silence or actually
3456 monitoring, both of which are safe to do while session_state_changing is true.
3460 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3462 fill_buffers_with_input (bufs, _input, nframes);
3464 if (_meter_point == MeterInput) {
3465 _meter->run (bufs, start_frame, end_frame, 0.0, nframes, true);
3468 _amp->apply_gain_automation (false);
3469 _trim->apply_gain_automation (false);
3470 passthru (bufs, start_frame, end_frame, nframes, 0);
3472 flush_processor_buffers_locked (nframes);
3478 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3480 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3485 if (n_outputs().n_total() == 0) {
3489 if (!_active || n_inputs().n_total() == 0) {
3490 silence_unlocked (nframes);
3494 framepos_t unused = 0;
3496 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3502 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3504 fill_buffers_with_input (bufs, _input, nframes);
3506 if (_meter_point == MeterInput) {
3507 _meter->run (bufs, start_frame, end_frame, 1.0, nframes, true);
3510 passthru (bufs, start_frame, end_frame, nframes, declick);
3512 flush_processor_buffers_locked (nframes);
3518 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3521 flush_processor_buffers_locked (nframes);
3526 Route::flush_processors ()
3528 /* XXX shouldn't really try to take this lock, since
3529 this is called from the RT audio thread.
3532 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3534 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3540 __attribute__((annotate("realtime")))
3543 Route::apply_processor_changes_rt ()
3545 int emissions = EmitNone;
3547 if (_pending_meter_point != _meter_point) {
3548 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3550 /* meters always have buffers for 'processor_max_streams'
3551 * they can be re-positioned without re-allocation */
3552 if (set_meter_point_unlocked()) {
3553 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3555 emissions |= EmitMeterChanged;
3560 bool changed = false;
3562 if (g_atomic_int_get (&_pending_process_reorder)) {
3563 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3565 apply_processor_order (_pending_processor_order);
3566 setup_invisible_processors ();
3568 g_atomic_int_set (&_pending_process_reorder, 0);
3569 emissions |= EmitRtProcessorChange;
3573 set_processor_positions ();
3575 if (emissions != 0) {
3576 g_atomic_int_set (&_pending_signals, emissions);
3579 return (!selfdestruct_sequence.empty ());
3583 Route::emit_pending_signals ()
3585 int sig = g_atomic_int_and (&_pending_signals, 0);
3586 if (sig & EmitMeterChanged) {
3587 _meter->emit_configuration_changed();
3588 meter_change (); /* EMIT SIGNAL */
3589 if (sig & EmitMeterVisibilityChange) {
3590 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3592 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3595 if (sig & EmitRtProcessorChange) {
3596 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3599 /* this would be a job for the butler.
3600 * Conceptually we should not take processe/processor locks here.
3601 * OTOH its more efficient (less overhead for summoning the butler and
3602 * telling her what do do) and signal emission is called
3603 * directly after the process callback, which decreases the chance
3604 * of x-runs when taking the locks.
3606 while (!selfdestruct_sequence.empty ()) {
3607 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3608 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3609 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3610 selfdestruct_sequence.pop_back ();
3613 remove_processor (proc);
3619 Route::set_meter_point (MeterPoint p, bool force)
3621 if (_pending_meter_point == p && !force) {
3625 if (force || !AudioEngine::instance()->running()) {
3626 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3627 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3628 _pending_meter_point = p;
3629 _meter->emit_configuration_changed();
3630 meter_change (); /* EMIT SIGNAL */
3631 if (set_meter_point_unlocked()) {
3632 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3634 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3637 _pending_meter_point = p;
3643 __attribute__((annotate("realtime")))
3646 Route::set_meter_point_unlocked ()
3649 /* Caller must hold process and processor write lock */
3650 assert (!AudioEngine::instance()->process_lock().trylock());
3651 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3652 assert (!lm.locked ());
3655 _meter_point = _pending_meter_point;
3657 bool meter_was_visible_to_user = _meter->display_to_user ();
3659 if (!_custom_meter_position_noted) {
3660 maybe_note_meter_position ();
3663 if (_meter_point != MeterCustom) {
3665 _meter->set_display_to_user (false);
3667 setup_invisible_processors ();
3670 _meter->set_display_to_user (true);
3672 /* If we have a previous position for the custom meter, try to put it there */
3673 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3675 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3676 if (i != _processors.end ()) {
3677 _processors.remove (_meter);
3678 _processors.insert (i, _meter);
3680 } else {// at end, right before the mains_out/panner
3681 _processors.remove (_meter);
3682 ProcessorList::iterator main = _processors.end();
3683 _processors.insert (--main, _meter);
3687 /* Set up the meter for its new position */
3689 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3693 if (loc == _processors.begin()) {
3694 m_in = _input->n_ports();
3696 ProcessorList::iterator before = loc;
3698 m_in = (*before)->output_streams ();
3701 _meter->reflect_inputs (m_in);
3703 /* we do not need to reconfigure the processors, because the meter
3704 (a) is always ready to handle processor_max_streams
3705 (b) is always an N-in/N-out processor, and thus moving
3706 it doesn't require any changes to the other processors.
3709 /* these should really be done after releasing the lock
3710 * but all those signals are subscribed to with gui_thread()
3713 return (_meter->display_to_user() != meter_was_visible_to_user);
3717 Route::listen_position_changed ()
3720 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3721 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3722 ProcessorState pstate (this);
3724 if (configure_processors_unlocked (0, &lm)) {
3725 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3727 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3732 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3733 _session.set_dirty ();
3736 boost::shared_ptr<CapturingProcessor>
3737 Route::add_export_point()
3739 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3740 if (!_capturing_processor) {
3742 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3743 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3745 // this aligns all tracks; but not tracks + busses
3746 assert (_session.worst_track_latency () >= _initial_delay);
3747 _capturing_processor.reset (new CapturingProcessor (_session, _session.worst_track_latency () - _initial_delay));
3748 _capturing_processor->activate ();
3750 configure_processors_unlocked (0, &lw);
3754 return _capturing_processor;
3758 Route::update_signal_latency ()
3760 framecnt_t l = _output->user_latency();
3761 framecnt_t lamp = 0;
3762 bool before_amp = true;
3763 framecnt_t ltrim = 0;
3764 bool before_trim = true;
3766 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3767 if ((*i)->active ()) {
3768 l += (*i)->signal_latency ();
3773 if ((*i) == _trim) {
3784 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3786 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3787 _signal_latency_at_amp_position = lamp;
3788 _signal_latency_at_trim_position = ltrim;
3790 if (_signal_latency != l) {
3791 _signal_latency = l;
3792 signal_latency_changed (); /* EMIT SIGNAL */
3795 return _signal_latency;
3799 Route::set_user_latency (framecnt_t nframes)
3801 _output->set_user_latency (nframes);
3802 _session.update_latency_compensation ();
3806 Route::set_latency_compensation (framecnt_t longest_session_latency)
3808 framecnt_t old = _initial_delay;
3810 if (_signal_latency < longest_session_latency) {
3811 _initial_delay = longest_session_latency - _signal_latency;
3816 DEBUG_TRACE (DEBUG::Latency, string_compose (
3817 "%1: compensate for maximum latency of %2,"
3818 "given own latency of %3, using initial delay of %4\n",
3819 name(), longest_session_latency, _signal_latency, _initial_delay));
3821 if (_initial_delay != old) {
3822 initial_delay_changed (); /* EMIT SIGNAL */
3825 if (_session.transport_stopped()) {
3826 _roll_delay = _initial_delay;
3831 Route::set_block_size (pframes_t nframes)
3833 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3834 (*i)->set_block_size (nframes);
3837 _session.ensure_buffers (n_process_buffers ());
3841 Route::protect_automation ()
3843 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3844 (*i)->protect_automation();
3847 /** @param declick 1 to set a pending declick fade-in,
3848 * -1 to set a pending declick fade-out
3851 Route::set_pending_declick (int declick)
3854 /* this call is not allowed to turn off a pending declick */
3856 _pending_declick = declick;
3859 _pending_declick = 0;
3863 /** Shift automation forwards from a particular place, thereby inserting time.
3864 * Adds undo commands for any shifts that are performed.
3866 * @param pos Position to start shifting from.
3867 * @param frames Amount to shift forwards by.
3871 Route::shift (framepos_t pos, framecnt_t frames)
3873 /* gain automation */
3875 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3877 XMLNode &before = gc->alist()->get_state ();
3878 gc->alist()->shift (pos, frames);
3879 XMLNode &after = gc->alist()->get_state ();
3880 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3883 /* gain automation */
3885 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3887 XMLNode &before = gc->alist()->get_state ();
3888 gc->alist()->shift (pos, frames);
3889 XMLNode &after = gc->alist()->get_state ();
3890 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3893 // TODO mute automation ??
3895 /* pan automation */
3897 ControlSet::Controls& c (_pannable->controls());
3899 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3900 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3902 boost::shared_ptr<AutomationList> al = pc->alist();
3903 XMLNode& before = al->get_state ();
3904 al->shift (pos, frames);
3905 XMLNode& after = al->get_state ();
3906 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3911 /* redirect automation */
3913 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3914 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3916 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3918 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3919 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3921 boost::shared_ptr<AutomationList> al = ac->alist();
3922 XMLNode &before = al->get_state ();
3923 al->shift (pos, frames);
3924 XMLNode &after = al->get_state ();
3925 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3933 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
3935 boost::shared_ptr<Processor> processor (p.lock ());
3936 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3940 pi->set_state_dir (d);
3944 Route::save_as_template (const string& path, const string& name)
3946 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
3947 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
3949 XMLNode& node (state (false));
3953 IO::set_name_in_state (*node.children().front(), name);
3955 tree.set_root (&node);
3957 /* return zero on success, non-zero otherwise */
3958 return !tree.write (path.c_str());
3963 Route::set_name (const string& str)
3965 if (str == name()) {
3969 string name = Route::ensure_track_or_route_name (str, _session);
3970 SessionObject::set_name (name);
3972 bool ret = (_input->set_name(name) && _output->set_name(name));
3975 /* rename the main outs. Leave other IO processors
3976 * with whatever name they already have, because its
3977 * just fine as it is (it will not contain the route
3978 * name if its a port insert, port send or port return).
3982 if (_main_outs->set_name (name)) {
3983 /* XXX returning false here is stupid because
3984 we already changed the route name.
3994 /** Set the name of a route in an XML description.
3995 * @param node XML <Route> node to set the name in.
3996 * @param name New name.
3999 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4001 node.add_property (X_("name"), name);
4003 XMLNodeList children = node.children();
4004 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4006 if ((*i)->name() == X_("IO")) {
4008 IO::set_name_in_state (**i, name);
4010 } else if ((*i)->name() == X_("Processor")) {
4012 XMLProperty const * role = (*i)->property (X_("role"));
4013 if (role && role->value() == X_("Main")) {
4014 (*i)->add_property (X_("name"), name);
4017 } else if ((*i)->name() == X_("Diskstream")) {
4019 if (rename_playlist) {
4020 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4022 (*i)->add_property (X_("name"), name);
4028 boost::shared_ptr<Send>
4029 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4031 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4033 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4034 boost::shared_ptr<InternalSend> send;
4036 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4037 if (send->target_route() == target) {
4043 return boost::shared_ptr<Send>();
4047 Route::set_denormal_protection (bool yn)
4049 if (_denormal_protection != yn) {
4050 _denormal_protection = yn;
4051 denormal_protection_changed (); /* EMIT SIGNAL */
4056 Route::denormal_protection () const
4058 return _denormal_protection;
4062 Route::set_active (bool yn, void* src)
4064 if (_session.transport_rolling()) {
4068 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4069 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4073 if (_active != yn) {
4075 _input->set_active (yn);
4076 _output->set_active (yn);
4077 active_changed (); // EMIT SIGNAL
4078 _session.set_dirty ();
4082 boost::shared_ptr<Pannable>
4083 Route::pannable() const
4088 boost::shared_ptr<Panner>
4089 Route::panner() const
4092 return _main_outs->panner_shell()->panner();
4095 boost::shared_ptr<PannerShell>
4096 Route::panner_shell() const
4098 return _main_outs->panner_shell();
4101 boost::shared_ptr<GainControl>
4102 Route::gain_control() const
4104 return _gain_control;
4107 boost::shared_ptr<GainControl>
4108 Route::trim_control() const
4110 return _trim_control;
4113 boost::shared_ptr<PhaseControl>
4114 Route::phase_control() const
4116 return _phase_control;
4119 boost::shared_ptr<AutomationControl>
4120 Route::get_control (const Evoral::Parameter& param)
4122 /* either we own the control or .... */
4124 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4128 /* maybe one of our processors does or ... */
4130 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4131 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4132 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4140 /* nobody does so we'll make a new one */
4142 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4149 boost::shared_ptr<Processor>
4150 Route::nth_plugin (uint32_t n) const
4152 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4153 ProcessorList::const_iterator i;
4155 for (i = _processors.begin(); i != _processors.end(); ++i) {
4156 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4163 return boost::shared_ptr<Processor> ();
4166 boost::shared_ptr<Processor>
4167 Route::nth_send (uint32_t n) const
4169 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4170 ProcessorList::const_iterator i;
4172 for (i = _processors.begin(); i != _processors.end(); ++i) {
4173 if (boost::dynamic_pointer_cast<Send> (*i)) {
4175 if ((*i)->name().find (_("Monitor")) == 0) {
4176 /* send to monitor section is not considered
4177 to be an accessible send.
4188 return boost::shared_ptr<Processor> ();
4192 Route::has_io_processor_named (const string& name)
4194 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4195 ProcessorList::iterator i;
4197 for (i = _processors.begin(); i != _processors.end(); ++i) {
4198 if (boost::dynamic_pointer_cast<Send> (*i) ||
4199 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4200 if ((*i)->name() == name) {
4210 Route::set_processor_positions ()
4212 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4214 bool had_amp = false;
4215 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4216 (*i)->set_pre_fader (!had_amp);
4223 /** Called when there is a proposed change to the input port count */
4225 Route::input_port_count_changing (ChanCount to)
4227 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4229 /* The processors cannot be configured with the new input arrangement, so
4235 /* The change is ok */
4239 /** Called when there is a proposed change to the output port count */
4241 Route::output_port_count_changing (ChanCount to)
4243 if (_strict_io && !_in_configure_processors) {
4246 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4247 if (processor_out_streams.get(*t) > to.get(*t)) {
4251 /* The change is ok */
4256 Route::unknown_processors () const
4260 if (_session.get_disable_all_loaded_plugins ()) {
4261 // Do not list "missing plugins" if they are explicitly disabled
4265 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4266 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4267 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4268 p.push_back ((*i)->name ());
4277 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4279 /* we assume that all our input ports feed all our output ports. its not
4280 universally true, but the alternative is way too corner-case to worry about.
4283 LatencyRange all_connections;
4286 all_connections.min = 0;
4287 all_connections.max = 0;
4289 all_connections.min = ~((pframes_t) 0);
4290 all_connections.max = 0;
4292 /* iterate over all "from" ports and determine the latency range for all of their
4293 connections to the "outside" (outside of this Route).
4296 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4300 p->get_connected_latency_range (range, playback);
4302 all_connections.min = min (all_connections.min, range.min);
4303 all_connections.max = max (all_connections.max, range.max);
4307 /* set the "from" port latencies to the max/min range of all their connections */
4309 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4310 p->set_private_latency_range (all_connections, playback);
4313 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4315 all_connections.min += our_latency;
4316 all_connections.max += our_latency;
4318 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4319 p->set_private_latency_range (all_connections, playback);
4322 return all_connections.max;
4326 Route::set_private_port_latencies (bool playback) const
4328 framecnt_t own_latency = 0;
4330 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4331 OR LATENCY CALLBACK.
4333 This is called (early) from the latency callback. It computes the REAL
4334 latency associated with each port and stores the result as the "private"
4335 latency of the port. A later call to Route::set_public_port_latencies()
4336 sets all ports to the same value to reflect the fact that we do latency
4337 compensation and so all signals are delayed by the same amount as they
4338 flow through ardour.
4341 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4342 if ((*i)->active ()) {
4343 own_latency += (*i)->signal_latency ();
4348 /* playback: propagate latency from "outside the route" to outputs to inputs */
4349 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4351 /* capture: propagate latency from "outside the route" to inputs to outputs */
4352 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4357 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4359 /* this is called to set the JACK-visible port latencies, which take
4360 latency compensation into account.
4369 const PortSet& ports (_input->ports());
4370 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4371 p->set_public_latency_range (range, playback);
4376 const PortSet& ports (_output->ports());
4377 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4378 p->set_public_latency_range (range, playback);
4383 /** Put the invisible processors in the right place in _processors.
4384 * Must be called with a writer lock on _processor_lock held.
4387 __attribute__((annotate("realtime")))
4390 Route::setup_invisible_processors ()
4393 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4394 assert (!lm.locked ());
4398 /* too early to be doing this stuff */
4402 /* we'll build this new list here and then use it
4404 * TODO put the ProcessorList is on the stack for RT-safety.
4407 ProcessorList new_processors;
4409 /* find visible processors */
4411 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4412 if ((*i)->display_to_user ()) {
4413 new_processors.push_back (*i);
4419 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4421 if (amp == new_processors.end ()) {
4422 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4423 new_processors.push_front (_amp);
4424 amp = find (new_processors.begin(), new_processors.end(), _amp);
4427 /* and the processor after the amp */
4429 ProcessorList::iterator after_amp = amp;
4435 switch (_meter_point) {
4437 assert (!_meter->display_to_user ());
4438 new_processors.push_front (_meter);
4441 assert (!_meter->display_to_user ());
4442 new_processors.insert (amp, _meter);
4444 case MeterPostFader:
4445 /* do nothing here */
4448 /* do nothing here */
4451 /* the meter is visible, so we don't touch it here */
4458 assert (_main_outs);
4459 assert (!_main_outs->display_to_user ());
4460 new_processors.push_back (_main_outs);
4462 /* iterator for the main outs */
4464 ProcessorList::iterator main = new_processors.end();
4467 /* OUTPUT METERING */
4469 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4470 assert (!_meter->display_to_user ());
4472 /* add the processor just before or just after the main outs */
4474 ProcessorList::iterator meter_point = main;
4476 if (_meter_point == MeterOutput) {
4479 new_processors.insert (meter_point, _meter);
4484 if (_monitor_send && !is_monitor ()) {
4485 assert (!_monitor_send->display_to_user ());
4486 switch (Config->get_listen_position ()) {
4487 case PreFaderListen:
4488 switch (Config->get_pfl_position ()) {
4489 case PFLFromBeforeProcessors:
4490 new_processors.push_front (_monitor_send);
4492 case PFLFromAfterProcessors:
4493 new_processors.insert (amp, _monitor_send);
4496 _monitor_send->set_can_pan (false);
4498 case AfterFaderListen:
4499 switch (Config->get_afl_position ()) {
4500 case AFLFromBeforeProcessors:
4501 new_processors.insert (after_amp, _monitor_send);
4503 case AFLFromAfterProcessors:
4504 new_processors.insert (new_processors.end(), _monitor_send);
4507 _monitor_send->set_can_pan (true);
4512 #if 0 // not used - just yet
4513 if (!is_master() && !is_monitor() && !is_auditioner()) {
4514 new_processors.push_front (_delayline);
4518 /* MONITOR CONTROL */
4520 if (_monitor_control && is_monitor ()) {
4521 assert (!_monitor_control->display_to_user ());
4522 new_processors.insert (amp, _monitor_control);
4527 if (_trim && _trim->active()) {
4528 assert (!_trim->display_to_user ());
4529 new_processors.push_front (_trim);
4532 /* INTERNAL RETURN */
4534 /* doing this here means that any monitor control will come after
4535 the return and trim.
4539 assert (!_intreturn->display_to_user ());
4540 new_processors.push_front (_intreturn);
4543 /* EXPORT PROCESSOR */
4545 if (_capturing_processor) {
4546 assert (!_capturing_processor->display_to_user ());
4547 new_processors.push_front (_capturing_processor);
4550 _processors = new_processors;
4552 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4553 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4554 (*i)->enable (true);
4558 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4559 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4560 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4567 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4568 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4572 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4573 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4580 /** If the meter point is `Custom', make a note of where the meter is.
4581 * This is so that if the meter point is subsequently set to something else,
4582 * and then back to custom, we can put the meter back where it was last time
4583 * custom was enabled.
4585 * Must be called with the _processor_lock held.
4588 Route::maybe_note_meter_position ()
4590 if (_meter_point != MeterCustom) {
4594 _custom_meter_position_noted = true;
4595 /* custom meter points range from after trim to before panner/main_outs
4596 * this is a limitation by the current processor UI
4598 bool seen_trim = false;
4599 _processor_after_last_custom_meter.reset();
4600 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4601 if ((*i) == _trim) {
4604 if ((*i) == _main_outs) {
4605 _processor_after_last_custom_meter = *i;
4608 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4610 _processor_after_last_custom_meter = _trim;
4612 ProcessorList::iterator j = i;
4614 assert(j != _processors.end ()); // main_outs should be before
4615 _processor_after_last_custom_meter = *j;
4620 assert(_processor_after_last_custom_meter.lock());
4623 boost::shared_ptr<Processor>
4624 Route::processor_by_id (PBD::ID id) const
4626 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4627 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4628 if ((*i)->id() == id) {
4633 return boost::shared_ptr<Processor> ();
4636 /** @return the monitoring state, or in other words what data we are pushing
4637 * into the route (data from the inputs, data from disk or silence)
4640 Route::monitoring_state () const
4642 return MonitoringInput;
4645 /** @return what we should be metering; either the data coming from the input
4646 * IO or the data that is flowing through the route.
4649 Route::metering_state () const
4651 return MeteringRoute;
4655 Route::has_external_redirects () const
4657 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4659 /* ignore inactive processors and obviously ignore the main
4660 * outs since everything has them and we don't care.
4663 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4671 boost::shared_ptr<Processor>
4672 Route::the_instrument () const
4674 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4675 return the_instrument_unlocked ();
4678 boost::shared_ptr<Processor>
4679 Route::the_instrument_unlocked () const
4681 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4682 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4683 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4687 return boost::shared_ptr<Processor>();
4693 Route::non_realtime_locate (framepos_t pos)
4696 _pannable->transport_located (pos);
4699 if (_delayline.get()) {
4700 _delayline.get()->flush();
4704 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4705 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4707 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4708 (*i)->transport_located (pos);
4711 _roll_delay = _initial_delay;
4715 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4722 * We don't currently mix MIDI input together, so we don't need the
4723 * complex logic of the audio case.
4726 n_buffers = bufs.count().n_midi ();
4728 for (i = 0; i < n_buffers; ++i) {
4730 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4731 MidiBuffer& buf (bufs.get_midi (i));
4734 buf.copy (source_port->get_midi_buffer(nframes));
4736 buf.silence (nframes);
4742 n_buffers = bufs.count().n_audio();
4744 size_t n_ports = io->n_ports().n_audio();
4745 float scaling = 1.0f;
4747 if (n_ports > n_buffers) {
4748 scaling = ((float) n_buffers) / n_ports;
4751 for (i = 0; i < n_ports; ++i) {
4753 /* if there are more ports than buffers, map them onto buffers
4754 * in a round-robin fashion
4757 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4758 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4761 if (i < n_buffers) {
4763 /* first time through just copy a channel into
4767 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4769 if (scaling != 1.0f) {
4770 buf.apply_gain (scaling, nframes);
4775 /* on subsequent times around, merge data from
4776 * the port with what is already there
4779 if (scaling != 1.0f) {
4780 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4782 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4787 /* silence any remaining buffers */
4789 for (; i < n_buffers; ++i) {
4790 AudioBuffer& buf (bufs.get_audio (i));
4791 buf.silence (nframes);
4794 /* establish the initial setup of the buffer set, reflecting what was
4795 copied into it. unless, of course, we are the auditioner, in which
4796 case nothing was fed into it from the inputs at all.
4799 if (!is_auditioner()) {
4800 bufs.set_count (io->n_ports());
4804 boost::shared_ptr<AutomationControl>
4805 Route::pan_azimuth_control() const
4808 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4810 return boost::shared_ptr<AutomationControl>();
4812 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
4813 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4815 if (!_pannable || !panner()) {
4816 return boost::shared_ptr<AutomationControl>();
4818 return _pannable->pan_azimuth_control;
4822 boost::shared_ptr<AutomationControl>
4823 Route::pan_elevation_control() const
4825 if (Profile->get_mixbus() || !_pannable || !panner()) {
4826 return boost::shared_ptr<AutomationControl>();
4829 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4831 if (c.find (PanElevationAutomation) != c.end()) {
4832 return _pannable->pan_elevation_control;
4834 return boost::shared_ptr<AutomationControl>();
4837 boost::shared_ptr<AutomationControl>
4838 Route::pan_width_control() const
4840 if (Profile->get_mixbus() || !_pannable || !panner()) {
4841 return boost::shared_ptr<AutomationControl>();
4844 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4846 if (c.find (PanWidthAutomation) != c.end()) {
4847 return _pannable->pan_width_control;
4849 return boost::shared_ptr<AutomationControl>();
4852 boost::shared_ptr<AutomationControl>
4853 Route::pan_frontback_control() const
4855 if (Profile->get_mixbus() || !_pannable || !panner()) {
4856 return boost::shared_ptr<AutomationControl>();
4859 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4861 if (c.find (PanFrontBackAutomation) != c.end()) {
4862 return _pannable->pan_frontback_control;
4864 return boost::shared_ptr<AutomationControl>();
4867 boost::shared_ptr<AutomationControl>
4868 Route::pan_lfe_control() const
4870 if (Profile->get_mixbus() || !_pannable || !panner()) {
4871 return boost::shared_ptr<AutomationControl>();
4874 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4876 if (c.find (PanLFEAutomation) != c.end()) {
4877 return _pannable->pan_lfe_control;
4879 return boost::shared_ptr<AutomationControl>();
4884 Route::eq_band_cnt () const
4886 if (Profile->get_mixbus()) {
4889 /* Ardour has no well-known EQ object */
4894 boost::shared_ptr<AutomationControl>
4895 Route::eq_gain_controllable (uint32_t band) const
4898 boost::shared_ptr<PluginInsert> eq = ch_eq();
4901 return boost::shared_ptr<AutomationControl>();
4904 uint32_t port_number;
4907 if (is_master() || mixbus()) {
4914 if (is_master() || mixbus()) {
4921 if (is_master() || mixbus()) {
4928 return boost::shared_ptr<AutomationControl>();
4931 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
4933 return boost::shared_ptr<AutomationControl>();
4936 boost::shared_ptr<AutomationControl>
4937 Route::eq_freq_controllable (uint32_t band) const
4941 if (mixbus() || is_master()) {
4942 /* no frequency controls for mixbusses or master */
4943 return boost::shared_ptr<AutomationControl>();
4946 boost::shared_ptr<PluginInsert> eq = ch_eq();
4949 return boost::shared_ptr<AutomationControl>();
4952 uint32_t port_number;
4964 return boost::shared_ptr<AutomationControl>();
4967 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
4969 return boost::shared_ptr<AutomationControl>();
4973 boost::shared_ptr<AutomationControl>
4974 Route::eq_q_controllable (uint32_t band) const
4976 return boost::shared_ptr<AutomationControl>();
4979 boost::shared_ptr<AutomationControl>
4980 Route::eq_shape_controllable (uint32_t band) const
4982 return boost::shared_ptr<AutomationControl>();
4985 boost::shared_ptr<AutomationControl>
4986 Route::eq_enable_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, 1)));
4997 return boost::shared_ptr<AutomationControl>();
5001 boost::shared_ptr<AutomationControl>
5002 Route::eq_hpf_controllable () const
5005 boost::shared_ptr<PluginInsert> eq = ch_eq();
5008 return boost::shared_ptr<AutomationControl>();
5011 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5013 return boost::shared_ptr<AutomationControl>();
5018 Route::eq_band_name (uint32_t band) const
5020 if (Profile->get_mixbus()) {
5036 boost::shared_ptr<AutomationControl>
5037 Route::comp_enable_controllable () const
5040 boost::shared_ptr<PluginInsert> comp = ch_comp();
5043 return boost::shared_ptr<AutomationControl>();
5046 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5048 return boost::shared_ptr<AutomationControl>();
5051 boost::shared_ptr<AutomationControl>
5052 Route::comp_threshold_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, 2)));
5064 return boost::shared_ptr<AutomationControl>();
5067 boost::shared_ptr<AutomationControl>
5068 Route::comp_speed_controllable () const
5071 boost::shared_ptr<PluginInsert> comp = ch_comp();
5074 return boost::shared_ptr<AutomationControl>();
5077 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5079 return boost::shared_ptr<AutomationControl>();
5082 boost::shared_ptr<AutomationControl>
5083 Route::comp_mode_controllable () const
5086 boost::shared_ptr<PluginInsert> comp = ch_comp();
5089 return boost::shared_ptr<AutomationControl>();
5092 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5094 return boost::shared_ptr<AutomationControl>();
5097 boost::shared_ptr<AutomationControl>
5098 Route::comp_makeup_controllable () const
5101 boost::shared_ptr<PluginInsert> comp = ch_comp();
5104 return boost::shared_ptr<AutomationControl>();
5107 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5109 return boost::shared_ptr<AutomationControl>();
5112 boost::shared_ptr<AutomationControl>
5113 Route::comp_redux_controllable () const
5116 boost::shared_ptr<PluginInsert> comp = ch_comp();
5119 return boost::shared_ptr<AutomationControl>();
5122 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5124 return boost::shared_ptr<AutomationControl>();
5129 Route::comp_mode_name (uint32_t mode) const
5134 return _("Leveler");
5136 return _("Compressor");
5138 return _("Limiter");
5140 return mixbus() ? _("Sidechain") : _("Limiter");
5150 Route::comp_speed_name (uint32_t mode) const
5168 boost::shared_ptr<AutomationControl>
5169 Route::send_level_controllable (uint32_t n) const
5172 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5174 return boost::shared_ptr<AutomationControl>();
5179 return boost::shared_ptr<AutomationControl>();
5182 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5183 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5185 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5187 return boost::shared_ptr<AutomationControl>();
5189 return s->gain_control ();
5193 boost::shared_ptr<AutomationControl>
5194 Route::send_enable_controllable (uint32_t n) const
5197 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5199 return boost::shared_ptr<AutomationControl>();
5204 return boost::shared_ptr<AutomationControl>();
5207 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5208 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5210 /* although Ardour sends have enable/disable as part of the Processor
5211 API, it is not exposed as a controllable.
5213 XXX: we should fix this.
5215 return boost::shared_ptr<AutomationControl>();
5220 Route::send_name (uint32_t n) const
5226 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5230 boost::shared_ptr<Processor> p = nth_send (n);
5239 boost::shared_ptr<AutomationControl>
5240 Route::master_send_enable_controllable () const
5243 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5245 return boost::shared_ptr<AutomationControl>();
5247 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5249 return boost::shared_ptr<AutomationControl>();
5254 Route::slaved () const
5256 if (!_gain_control) {
5259 /* just test one particular control, not all of them */
5260 return _gain_control->slaved ();
5264 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5266 if (!vca || !_gain_control) {
5270 /* just test one particular control, not all of them */
5272 return _gain_control->slaved_to (vca->gain_control());
5276 Route::muted_by_others_soloing () const
5278 if (!can_be_muted_by_others ()) {
5282 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5286 Route::clear_all_solo_state ()
5288 _solo_control->clear_all_solo_state ();