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;
908 boost::shared_ptr <PluginInsert> fanout;
910 if (g_atomic_int_get (&_pending_process_reorder)) {
911 /* we need to flush any pending re-order changes */
912 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
913 apply_processor_changes_rt ();
917 loc = find(_processors.begin(), _processors.end(), before);
918 if (loc == _processors.end ()) {
922 /* nothing specified - at end */
923 loc = _processors.end ();
926 if (!AudioEngine::instance()->connected()) {
930 if (others.empty()) {
934 ProcessorList to_skip;
936 // check if there's an instrument to replace or configure
937 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
938 boost::shared_ptr<PluginInsert> pi;
939 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
942 if (!pi->plugin ()->get_info ()->is_instrument ()) {
945 boost::shared_ptr<Processor> instrument = the_instrument ();
946 ChanCount in (DataType::MIDI, 1);
947 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
949 PluginSetupOptions flags = None;
952 in = instrument->input_streams ();
953 out = instrument->output_streams ();
955 if (pi->has_output_presets (in, out)) {
959 pi->set_strict_io (_strict_io);
961 PluginSetupOptions mask = None;
962 if (Config->get_ask_replace_instrument ()) {
965 if (Config->get_ask_setup_instrument ()) {
972 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
973 int mode = rv.get_value_or (0);
976 to_skip.push_back (*i); // don't add this one;
979 replace_processor (instrument, *i, err);
980 to_skip.push_back (*i);
985 if ((mode & 5) == 4) {
992 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
993 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
994 ProcessorState pstate (this);
996 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1001 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1002 if (check != to_skip.end()) {
1006 boost::shared_ptr<PluginInsert> pi;
1008 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1009 pi->set_strict_io (_strict_io);
1013 /* Ensure that only one amp is in the list at any time */
1014 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1015 if (check != _processors.end()) {
1016 if (before == _amp) {
1017 /* Already in position; all is well */
1020 _processors.erase (check);
1025 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1027 _processors.insert (loc, *i);
1028 (*i)->set_owner (this);
1031 if (configure_processors_unlocked (err, &lm)) {
1033 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1038 if (pi && pi->has_sidechain ()) {
1039 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1042 if ((*i)->active()) {
1043 // emit ActiveChanged() and latency_changed() if needed
1047 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1049 boost::shared_ptr<Send> send;
1050 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1051 send->SelfDestruct.connect_same_thread (*this,
1052 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1056 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1057 boost::shared_ptr<PluginInsert> pi;
1059 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1060 if (pi->has_no_inputs ()) {
1061 _have_internal_generator = true;
1067 _output->set_user_latency (0);
1070 reset_instrument_info ();
1071 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1072 set_processor_positions ();
1074 if (fanout && fanout->configured ()
1075 && fanout->output_streams().n_audio() > 2
1076 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1077 fan_out (); /* EMIT SIGNAL */
1083 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1085 if (p == PreFader) {
1086 start = _processors.begin();
1087 end = find(_processors.begin(), _processors.end(), _amp);
1089 start = find(_processors.begin(), _processors.end(), _amp);
1091 end = _processors.end();
1095 /** Turn off all processors with a given placement
1096 * @param p Placement of processors to disable
1099 Route::disable_processors (Placement p)
1101 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1103 ProcessorList::iterator start, end;
1104 placement_range(p, start, end);
1106 for (ProcessorList::iterator i = start; i != end; ++i) {
1107 (*i)->enable (false);
1110 _session.set_dirty ();
1113 /** Turn off all redirects
1116 Route::disable_processors ()
1118 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1120 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1121 (*i)->enable (false);
1124 _session.set_dirty ();
1127 /** Turn off all redirects with a given placement
1128 * @param p Placement of redirects to disable
1131 Route::disable_plugins (Placement p)
1133 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1135 ProcessorList::iterator start, end;
1136 placement_range(p, start, end);
1138 for (ProcessorList::iterator i = start; i != end; ++i) {
1139 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1140 (*i)->enable (false);
1144 _session.set_dirty ();
1147 /** Turn off all plugins
1150 Route::disable_plugins ()
1152 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1154 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1155 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1156 (*i)->enable (false);
1160 _session.set_dirty ();
1165 Route::ab_plugins (bool forward)
1167 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1171 /* forward = turn off all active redirects, and mark them so that the next time
1172 we go the other way, we will revert them
1175 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1176 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1179 if (!(*i)->display_to_user ()) {
1183 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1188 if ((*i)->enabled ()) {
1189 (*i)->enable (false);
1190 (*i)->set_next_ab_is_active (true);
1192 (*i)->set_next_ab_is_active (false);
1198 /* backward = if the redirect was marked to go active on the next ab, do so */
1200 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1201 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1204 if (!(*i)->display_to_user ()) {
1208 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1213 (*i)->enable ((*i)->get_next_ab_is_active ());
1217 _session.set_dirty ();
1221 /** Remove processors with a given placement.
1222 * @param p Placement of processors to remove.
1225 Route::clear_processors (Placement p)
1227 if (!_session.engine().connected()) {
1231 bool already_deleting = _session.deletion_in_progress();
1232 if (!already_deleting) {
1233 _session.set_deletion_in_progress();
1237 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1238 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1239 ProcessorList new_list;
1240 ProcessorStreams err;
1241 bool seen_amp = false;
1243 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1249 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1251 /* you can't remove these */
1253 new_list.push_back (*i);
1260 new_list.push_back (*i);
1263 (*i)->drop_references ();
1271 (*i)->drop_references ();
1274 new_list.push_back (*i);
1281 _processors = new_list;
1282 configure_processors_unlocked (&err, &lm); // this can't fail
1285 processor_max_streams.reset();
1286 _have_internal_generator = false;
1287 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1288 set_processor_positions ();
1290 reset_instrument_info ();
1292 if (!already_deleting) {
1293 _session.clear_deletion_in_progress();
1298 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1300 // TODO once the export point can be configured properly, do something smarter here
1301 if (processor == _capturing_processor) {
1302 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1303 if (need_process_lock) {
1307 _capturing_processor.reset();
1309 if (need_process_lock) {
1314 /* these can never be removed */
1316 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1320 if (!_session.engine().connected()) {
1324 processor_max_streams.reset();
1327 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1328 if (need_process_lock) {
1332 /* Caller must hold process lock */
1333 assert (!AudioEngine::instance()->process_lock().trylock());
1335 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1337 ProcessorState pstate (this);
1339 ProcessorList::iterator i;
1340 bool removed = false;
1342 for (i = _processors.begin(); i != _processors.end(); ) {
1343 if (*i == processor) {
1345 /* move along, see failure case for configure_processors()
1346 where we may need to reconfigure the processor.
1349 /* stop redirects that send signals to JACK ports
1350 from causing noise as a result of no longer being
1354 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1355 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1359 iop = pi->sidechain();
1366 i = _processors.erase (i);
1374 _output->set_user_latency (0);
1382 if (configure_processors_unlocked (err, &lm)) {
1384 /* we know this will work, because it worked before :) */
1385 configure_processors_unlocked (0, &lm);
1389 _have_internal_generator = false;
1391 for (i = _processors.begin(); i != _processors.end(); ++i) {
1392 boost::shared_ptr<PluginInsert> pi;
1394 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1395 if (pi->has_no_inputs ()) {
1396 _have_internal_generator = true;
1401 if (need_process_lock) {
1406 reset_instrument_info ();
1407 processor->drop_references ();
1408 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1409 set_processor_positions ();
1415 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1417 /* these can never be removed */
1418 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1421 /* and can't be used as substitute, either */
1422 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1426 /* I/Os are out, too */
1427 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1431 /* this function cannot be used to swap/reorder processors */
1432 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1436 if (!AudioEngine::instance()->connected() || !old || !sub) {
1440 /* ensure that sub is not owned by another route */
1441 if (sub->owner ()) {
1446 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1447 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1448 ProcessorState pstate (this);
1450 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1452 ProcessorList::iterator i;
1453 bool replaced = false;
1454 bool enable = old->enabled ();
1456 for (i = _processors.begin(); i != _processors.end(); ) {
1458 i = _processors.erase (i);
1459 _processors.insert (i, sub);
1460 sub->set_owner (this);
1473 boost::shared_ptr<PluginInsert> pi;
1474 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1475 pi->set_strict_io (true);
1479 if (configure_processors_unlocked (err, &lm)) {
1481 configure_processors_unlocked (0, &lm);
1485 _have_internal_generator = false;
1487 for (i = _processors.begin(); i != _processors.end(); ++i) {
1488 boost::shared_ptr<PluginInsert> pi;
1489 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1490 if (pi->has_no_inputs ()) {
1491 _have_internal_generator = true;
1501 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1502 _output->set_user_latency (0);
1505 reset_instrument_info ();
1506 old->drop_references ();
1507 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1508 set_processor_positions ();
1513 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1515 ProcessorList deleted;
1517 if (!_session.engine().connected()) {
1521 processor_max_streams.reset();
1524 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1525 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1526 ProcessorState pstate (this);
1528 ProcessorList::iterator i;
1529 boost::shared_ptr<Processor> processor;
1531 for (i = _processors.begin(); i != _processors.end(); ) {
1535 /* these can never be removed */
1537 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1542 /* see if its in the list of processors to delete */
1544 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1549 /* stop IOProcessors that send to JACK ports
1550 from causing noise as a result of no longer being
1554 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1555 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1558 iop = pi->sidechain();
1565 deleted.push_back (processor);
1566 i = _processors.erase (i);
1569 if (deleted.empty()) {
1570 /* none of those in the requested list were found */
1574 _output->set_user_latency (0);
1576 if (configure_processors_unlocked (err, &lm)) {
1578 /* we know this will work, because it worked before :) */
1579 configure_processors_unlocked (0, &lm);
1584 _have_internal_generator = false;
1586 for (i = _processors.begin(); i != _processors.end(); ++i) {
1587 boost::shared_ptr<PluginInsert> pi;
1589 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1590 if (pi->has_no_inputs ()) {
1591 _have_internal_generator = true;
1598 /* now try to do what we need to so that those that were removed will be deleted */
1600 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1601 (*i)->drop_references ();
1604 reset_instrument_info ();
1605 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1606 set_processor_positions ();
1612 Route::reset_instrument_info ()
1614 boost::shared_ptr<Processor> instr = the_instrument();
1616 _instrument_info.set_internal_instrument (instr);
1620 /** Caller must hold process lock */
1622 Route::configure_processors (ProcessorStreams* err)
1624 #ifndef PLATFORM_WINDOWS
1625 assert (!AudioEngine::instance()->process_lock().trylock());
1628 if (!_in_configure_processors) {
1629 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1630 return configure_processors_unlocked (err, &lm);
1637 Route::input_streams () const
1639 return _input->n_ports ();
1642 list<pair<ChanCount, ChanCount> >
1643 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1645 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1647 return try_configure_processors_unlocked (in, err);
1650 list<pair<ChanCount, ChanCount> >
1651 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1653 // Check each processor in order to see if we can configure as requested
1655 list<pair<ChanCount, ChanCount> > configuration;
1658 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1659 DEBUG_TRACE (DEBUG::Processors, "{\n");
1661 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1663 if ((*p)->can_support_io_configuration(in, out)) {
1665 if (boost::dynamic_pointer_cast<Delivery> (*p)
1666 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1668 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1669 /* with strict I/O the panner + output are forced to
1670 * follow the last processor's output.
1672 * Delivery::can_support_io_configuration() will only add ports,
1673 * but not remove excess ports.
1675 * This works because the delivery only requires
1676 * as many outputs as there are inputs.
1677 * Delivery::configure_io() will do the actual removal
1678 * by calling _output->ensure_io()
1680 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1681 /* ..but at least as many as there are master-inputs, if
1682 * the delivery is dealing with audio */
1683 // XXX this may need special-casing for mixbus (master-outputs)
1684 // and should maybe be a preference anyway ?!
1685 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1691 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1692 configuration.push_back(make_pair(in, out));
1695 // restriction for Monitor Section Processors
1696 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1697 /* Note: The Monitor follows the master-bus and has no panner.
1699 * The general idea is to only allow plugins that retain the channel-count
1700 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1701 * Then again 5.1 in, monitor stereo is a valid use-case.
1703 * and worse: we only refuse adding plugins *here*.
1705 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1706 * 2) change master-bus, add a channel
1707 * 2a) monitor-secion follows
1708 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1709 * 4) re-load session, monitor-processor remains unconfigured, crash.
1711 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1713 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1714 // internal sends make no sense, only feedback
1715 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1716 return list<pair<ChanCount, ChanCount> > ();
1718 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1719 /* External Sends can be problematic. one can add/remove ports
1720 * there signal leaves the DAW to external monitors anyway, so there's
1721 * no real use for allowing them here anyway.
1723 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1724 return list<pair<ChanCount, ChanCount> > ();
1726 if (boost::dynamic_pointer_cast<Send> (*p)) {
1728 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1729 return list<pair<ChanCount, ChanCount> > ();
1738 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1739 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1740 DEBUG_TRACE (DEBUG::Processors, "}\n");
1741 return list<pair<ChanCount, ChanCount> > ();
1745 DEBUG_TRACE (DEBUG::Processors, "}\n");
1747 return configuration;
1750 /** Set the input/output configuration of each processor in the processors list.
1751 * Caller must hold process lock.
1752 * Return 0 on success, otherwise configuration is impossible.
1755 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1757 #ifndef PLATFORM_WINDOWS
1758 assert (!AudioEngine::instance()->process_lock().trylock());
1761 if (_in_configure_processors) {
1765 /* put invisible processors where they should be */
1766 setup_invisible_processors ();
1768 _in_configure_processors = true;
1770 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1772 if (configuration.empty ()) {
1773 _in_configure_processors = false;
1778 bool seen_mains_out = false;
1779 processor_out_streams = _input->n_ports();
1780 processor_max_streams.reset();
1782 /* processor configure_io() may result in adding ports
1783 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1785 * with jack2 adding ports results in a graph-order callback,
1786 * which calls Session::resort_routes() and eventually
1787 * Route::direct_feeds_according_to_reality()
1788 * which takes a ReaderLock (_processor_lock).
1790 * so we can't hold a WriterLock here until jack2 threading
1793 * NB. we still hold the process lock
1795 * (ardour's own engines do call graph-order from the
1796 * process-thread and hence do not have this issue; besides
1797 * merely adding ports won't trigger a graph-order, only
1798 * making connections does)
1802 // TODO check for a potential ReaderLock after ReaderLock ??
1803 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1805 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1806 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1808 if (!(*p)->configure_io(c->first, c->second)) {
1809 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1810 _in_configure_processors = false;
1815 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1816 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1818 boost::shared_ptr<IOProcessor> iop;
1819 boost::shared_ptr<PluginInsert> pi;
1820 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1821 /* plugins connected via Split or Hide Match may have more channels.
1822 * route/scratch buffers are needed for all of them
1823 * The configuration may only be a subset (both input and output)
1825 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1827 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1828 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1829 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1833 if (boost::dynamic_pointer_cast<Delivery> (*p)
1834 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1835 /* main delivery will increase port count to match input.
1836 * the Delivery::Main is usually the last processor - followed only by
1839 seen_mains_out = true;
1841 if (!seen_mains_out) {
1842 processor_out_streams = out;
1851 _meter->set_max_channels (processor_max_streams);
1854 /* make sure we have sufficient scratch buffers to cope with the new processor
1857 _session.ensure_buffers (n_process_buffers ());
1859 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1861 _in_configure_processors = false;
1865 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1866 * @param state New active state for those processors.
1869 Route::all_visible_processors_active (bool state)
1871 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1873 if (_processors.empty()) {
1877 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1878 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1882 boost::shared_ptr<PluginInsert> pi;
1883 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1884 if (pi->is_channelstrip ()) {
1889 (*i)->enable (state);
1892 _session.set_dirty ();
1896 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1898 /* check if re-order requires re-configuration of any processors
1899 * -> compare channel configuration for all processors
1901 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1902 ChanCount c = input_streams ();
1904 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1906 if (c != (*j)->input_streams()) {
1909 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1912 if ((*i)->input_streams() != c) {
1915 c = (*i)->output_streams();
1927 __attribute__((annotate("realtime")))
1930 Route::apply_processor_order (const ProcessorList& new_order)
1932 /* need to hold processor_lock; either read or write lock
1933 * and the engine process_lock.
1934 * Due to r/w lock ambiguity we can only assert the latter
1936 assert (!AudioEngine::instance()->process_lock().trylock());
1939 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1940 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1941 * processors in the current actual processor list that are hidden. Any visible processors
1942 * in the current list but not in "new_order" will be assumed to be deleted.
1945 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1946 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1947 * (note though that ::processors_reorder_needs_configure() ensured that
1948 * this function will only ever be called from the rt-thread if no processor were removed)
1950 * either way, I can't proove it, but an x-run due to re-order here is less likley
1951 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1954 ProcessorList as_it_will_be;
1955 ProcessorList::iterator oiter;
1956 ProcessorList::const_iterator niter;
1958 oiter = _processors.begin();
1959 niter = new_order.begin();
1961 while (niter != new_order.end()) {
1963 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1964 then append it to the temp list.
1966 Otherwise, see if the next processor in the old list is in the new list. if not,
1967 its been deleted. If its there, append it to the temp list.
1970 if (oiter == _processors.end()) {
1972 /* no more elements in the old list, so just stick the rest of
1973 the new order onto the temp list.
1976 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1977 while (niter != new_order.end()) {
1984 if (!(*oiter)->display_to_user()) {
1986 as_it_will_be.push_back (*oiter);
1990 /* visible processor: check that its in the new order */
1992 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1993 /* deleted: do nothing, shared_ptr<> will clean up */
1995 /* ignore this one, and add the next item from the new order instead */
1996 as_it_will_be.push_back (*niter);
2001 /* now remove from old order - its taken care of no matter what */
2002 oiter = _processors.erase (oiter);
2006 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2008 /* If the meter is in a custom position, find it and make a rough note of its position */
2009 maybe_note_meter_position ();
2013 Route::move_instrument_down (bool postfader)
2015 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2016 ProcessorList new_order;
2017 boost::shared_ptr<Processor> instrument;
2018 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2019 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2020 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2022 } else if (instrument && *i == _amp) {
2024 new_order.push_back (*i);
2025 new_order.push_back (instrument);
2027 new_order.push_back (instrument);
2028 new_order.push_back (*i);
2031 new_order.push_back (*i);
2038 reorder_processors (new_order, 0);
2042 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2044 // it a change is already queued, wait for it
2045 // (unless engine is stopped. apply immediately and proceed
2046 while (g_atomic_int_get (&_pending_process_reorder)) {
2047 if (!AudioEngine::instance()->running()) {
2048 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2049 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2051 apply_processor_order(_pending_processor_order);
2052 setup_invisible_processors ();
2054 g_atomic_int_set (&_pending_process_reorder, 0);
2056 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2057 set_processor_positions ();
2059 // TODO rather use a semaphore or something.
2060 // but since ::reorder_processors() is called
2061 // from the GUI thread, this is fine..
2066 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2068 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2069 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2070 ProcessorState pstate (this);
2072 apply_processor_order (new_order);
2074 if (configure_processors_unlocked (err, &lm)) {
2082 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2083 set_processor_positions ();
2086 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2087 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2089 // _pending_processor_order is protected by _processor_lock
2090 _pending_processor_order = new_order;
2091 g_atomic_int_set (&_pending_process_reorder, 1);
2098 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2100 boost::shared_ptr<PluginInsert> pi;
2101 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2105 if (pi->has_sidechain () == add) {
2106 return true; // ?? call failed, but result is as expected.
2110 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2111 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2112 if (i == _processors.end ()) {
2118 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2119 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2120 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2122 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2124 if (!pi->add_sidechain ()) {
2128 if (!pi->del_sidechain ()) {
2134 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2139 pi->del_sidechain ();
2141 pi->add_sidechain ();
2142 // TODO restore side-chain's state.
2147 configure_processors_unlocked (0, &lm);
2150 if (pi->has_sidechain ()) {
2151 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2154 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2155 _session.set_dirty ();
2160 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2162 boost::shared_ptr<PluginInsert> pi;
2163 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2168 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2169 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2170 if (i == _processors.end ()) {
2176 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2177 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2179 const ChanCount& old (pi->preset_out ());
2180 if (!pi->set_preset_out (outs)) {
2181 return true; // no change, OK
2184 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2187 pi->set_preset_out (old);
2190 configure_processors_unlocked (0, &lm);
2193 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2194 _session.set_dirty ();
2199 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2202 return customize_plugin_insert (proc, 0, unused, unused);
2206 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2208 boost::shared_ptr<PluginInsert> pi;
2209 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2214 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2215 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2216 if (i == _processors.end ()) {
2222 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2223 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2225 bool old_cust = pi->custom_cfg ();
2226 uint32_t old_cnt = pi->get_count ();
2227 ChanCount old_chan = pi->output_streams ();
2228 ChanCount old_sinks = pi->natural_input_streams ();
2231 pi->set_custom_cfg (false);
2233 pi->set_custom_cfg (true);
2234 pi->set_count (count);
2235 pi->set_outputs (outs);
2236 pi->set_sinks (sinks);
2239 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2243 pi->set_count (old_cnt);
2244 pi->set_sinks (old_sinks);
2245 pi->set_outputs (old_chan);
2246 pi->set_custom_cfg (old_cust);
2250 configure_processors_unlocked (0, &lm);
2253 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2254 _session.set_dirty ();
2259 Route::set_strict_io (const bool enable)
2261 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2263 if (_strict_io != enable) {
2264 _strict_io = enable;
2265 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2266 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2267 boost::shared_ptr<PluginInsert> pi;
2268 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2269 pi->set_strict_io (_strict_io);
2273 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2277 _strict_io = !enable; // restore old value
2278 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2279 boost::shared_ptr<PluginInsert> pi;
2280 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2281 pi->set_strict_io (_strict_io);
2288 configure_processors (0);
2291 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2292 _session.set_dirty ();
2304 Route::get_template()
2306 return state(false);
2310 Route::state(bool full_state)
2313 if (!_session._template_state_dir.empty()) {
2314 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2317 XMLNode *node = new XMLNode("Route");
2318 ProcessorList::iterator i;
2321 node->add_property ("id", id ().to_s ());
2322 node->add_property ("name", _name);
2323 node->add_property("default-type", _default_type.to_string());
2324 node->add_property ("strict-io", _strict_io);
2326 node->add_child_nocopy (_presentation_info.get_state());
2328 node->add_property("active", _active?"yes":"no");
2330 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2331 node->add_property("meter-point", enum_2_string (_meter_point));
2333 node->add_property("meter-type", enum_2_string (_meter_type));
2336 node->add_property("route-group", _route_group->name());
2339 node->add_child_nocopy (_solo_control->get_state ());
2340 node->add_child_nocopy (_solo_isolate_control->get_state ());
2341 node->add_child_nocopy (_solo_safe_control->get_state ());
2343 node->add_child_nocopy (_input->state (full_state));
2344 node->add_child_nocopy (_output->state (full_state));
2345 node->add_child_nocopy (_mute_master->get_state ());
2347 node->add_child_nocopy (_mute_control->get_state ());
2348 node->add_child_nocopy (_phase_control->get_state ());
2351 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2354 if (_comment.length()) {
2355 XMLNode *cmt = node->add_child ("Comment");
2356 cmt->add_content (_comment);
2360 node->add_child_nocopy (_pannable->state (full_state));
2364 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2365 for (i = _processors.begin(); i != _processors.end(); ++i) {
2367 /* template save: do not include internal sends functioning as
2368 aux sends because the chance of the target ID
2369 in the session where this template is used
2372 similarly, do not save listen sends which connect to
2373 the monitor section, because these will always be
2376 boost::shared_ptr<InternalSend> is;
2378 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2379 if (is->role() == Delivery::Listen) {
2384 node->add_child_nocopy((*i)->state (full_state));
2389 node->add_child_copy (*_extra_xml);
2392 if (_custom_meter_position_noted) {
2393 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2395 node->add_property (X_("processor-after-last-custom-meter"), after->id().to_s());
2399 if (!_session._template_state_dir.empty()) {
2400 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2403 node->add_child_copy (Slavable::get_state());
2409 Route::set_state (const XMLNode& node, int version)
2411 if (version < 3000) {
2412 return set_state_2X (node, version);
2416 XMLNodeConstIterator niter;
2418 XMLProperty const * prop;
2420 if (node.name() != "Route"){
2421 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2425 if ((prop = node.property (X_("name"))) != 0) {
2426 Route::set_name (prop->value());
2430 _initial_io_setup = true;
2432 Stripable::set_state (node, version);
2434 if ((prop = node.property (X_("strict-io"))) != 0) {
2435 _strict_io = string_is_affirmative (prop->value());
2439 /* monitor bus does not get a panner, but if (re)created
2440 via XML, it will already have one by the time we
2441 call ::set_state(). so ... remove it.
2446 /* add all processors (except amp, which is always present) */
2448 nlist = node.children();
2449 XMLNode processor_state (X_("processor_state"));
2451 Stateful::save_extra_xml (node);
2453 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2457 if (child->name() == IO::state_node_name) {
2458 if ((prop = child->property (X_("direction"))) == 0) {
2462 if (prop->value() == "Input") {
2463 _input->set_state (*child, version);
2464 } else if (prop->value() == "Output") {
2465 _output->set_state (*child, version);
2468 } else if (child->name() == X_("Processor")) {
2469 processor_state.add_child_copy (*child);
2470 } else if (child->name() == X_("Pannable")) {
2472 _pannable->set_state (*child, version);
2474 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2476 } else if (child->name() == Slavable::xml_node_name) {
2477 Slavable::set_state (*child, version);
2481 if ((prop = node.property (X_("meter-point"))) != 0) {
2482 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2483 set_meter_point (mp, true);
2485 _meter->set_display_to_user (_meter_point == MeterCustom);
2489 if ((prop = node.property (X_("meter-type"))) != 0) {
2490 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2493 _initial_io_setup = false;
2495 set_processor_state (processor_state);
2497 // this looks up the internal instrument in processors
2498 reset_instrument_info();
2500 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2501 set_denormal_protection (string_is_affirmative (prop->value()));
2504 /* convert old 3001 state */
2505 if ((prop = node.property (X_("phase-invert"))) != 0) {
2506 _phase_control->set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2509 if ((prop = node.property (X_("active"))) != 0) {
2510 bool yn = string_is_affirmative (prop->value());
2511 set_active (yn, this);
2514 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2515 PBD::ID id (prop->value ());
2516 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2517 ProcessorList::const_iterator i = _processors.begin ();
2518 while (i != _processors.end() && (*i)->id() != id) {
2522 if (i != _processors.end ()) {
2523 _processor_after_last_custom_meter = *i;
2524 _custom_meter_position_noted = true;
2528 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2531 if (child->name() == X_("Comment")) {
2533 /* XXX this is a terrible API design in libxml++ */
2535 XMLNode *cmt = *(child->children().begin());
2536 _comment = cmt->content();
2538 } else if (child->name() == Controllable::xml_node_name) {
2539 if ((prop = child->property (X_("name"))) == 0) {
2543 if (prop->value() == _gain_control->name()) {
2544 _gain_control->set_state (*child, version);
2545 } else if (prop->value() == _solo_control->name()) {
2546 _solo_control->set_state (*child, version);
2547 } else if (prop->value() == _solo_safe_control->name()) {
2548 _solo_safe_control->set_state (*child, version);
2549 } else if (prop->value() == _solo_isolate_control->name()) {
2550 _solo_isolate_control->set_state (*child, version);
2551 } else if (prop->value() == _mute_control->name()) {
2552 _mute_control->set_state (*child, version);
2553 } else if (prop->value() == _phase_control->name()) {
2554 _phase_control->set_state (*child, version);
2556 Evoral::Parameter p = EventTypeMap::instance().from_symbol (prop->value());
2557 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2558 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2560 ac->set_state (*child, version);
2564 } else if (child->name() == MuteMaster::xml_node_name) {
2565 _mute_master->set_state (*child, version);
2567 } else if (child->name() == Automatable::xml_node_name) {
2568 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2576 Route::set_state_2X (const XMLNode& node, int version)
2580 XMLNodeConstIterator niter;
2582 XMLProperty const * prop;
2584 /* 2X things which still remain to be handled:
2590 if (node.name() != "Route") {
2591 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2595 Stripable::set_state (node, version);
2597 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2598 set_denormal_protection (string_is_affirmative (prop->value()));
2601 if ((prop = node.property (X_("muted"))) != 0) {
2604 bool muted = string_is_affirmative (prop->value());
2610 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2612 if (string_is_affirmative (prop->value())){
2613 mute_point = mute_point + "PreFader";
2618 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2620 if (string_is_affirmative (prop->value())){
2623 mute_point = mute_point + ",";
2626 mute_point = mute_point + "PostFader";
2631 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2633 if (string_is_affirmative (prop->value())){
2636 mute_point = mute_point + ",";
2639 mute_point = mute_point + "Listen";
2644 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2646 if (string_is_affirmative (prop->value())){
2649 mute_point = mute_point + ",";
2652 mute_point = mute_point + "Main";
2656 _mute_master->set_mute_points (mute_point);
2657 _mute_master->set_muted_by_self (true);
2661 if ((prop = node.property (X_("meter-point"))) != 0) {
2662 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2667 nlist = node.children ();
2668 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2672 if (child->name() == IO::state_node_name) {
2674 /* there is a note in IO::set_state_2X() about why we have to call
2678 _input->set_state_2X (*child, version, true);
2679 _output->set_state_2X (*child, version, false);
2681 if ((prop = child->property (X_("name"))) != 0) {
2682 Route::set_name (prop->value ());
2687 if ((prop = child->property (X_("active"))) != 0) {
2688 bool yn = string_is_affirmative (prop->value());
2689 _active = !yn; // force switch
2690 set_active (yn, this);
2693 if ((prop = child->property (X_("gain"))) != 0) {
2696 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2697 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2701 /* Set up Panners in the IO */
2702 XMLNodeList io_nlist = child->children ();
2704 XMLNodeConstIterator io_niter;
2707 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2709 io_child = *io_niter;
2711 if (io_child->name() == X_("Panner")) {
2712 _main_outs->panner_shell()->set_state(*io_child, version);
2713 } else if (io_child->name() == X_("Automation")) {
2714 /* IO's automation is for the fader */
2715 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2721 XMLNodeList redirect_nodes;
2723 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2727 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2728 redirect_nodes.push_back(child);
2733 set_processor_state_2X (redirect_nodes, version);
2735 Stateful::save_extra_xml (node);
2737 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2740 if (child->name() == X_("Comment")) {
2742 /* XXX this is a terrible API design in libxml++ */
2744 XMLNode *cmt = *(child->children().begin());
2745 _comment = cmt->content();
2747 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2748 if (prop->value() == X_("solo")) {
2749 _solo_control->set_state (*child, version);
2750 } else if (prop->value() == X_("mute")) {
2751 _mute_control->set_state (*child, version);
2761 Route::get_processor_state ()
2763 XMLNode* root = new XMLNode (X_("redirects"));
2764 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2765 root->add_child_nocopy ((*i)->state (true));
2772 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2774 /* We don't bother removing existing processors not in nList, as this
2775 method will only be called when creating a Route from scratch, not
2776 for undo purposes. Just put processors in at the appropriate place
2780 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2781 add_processor_from_xml_2X (**i, version);
2786 Route::set_processor_state (const XMLNode& node)
2788 const XMLNodeList &nlist = node.children();
2789 XMLNodeConstIterator niter;
2790 ProcessorList new_order;
2791 bool must_configure = false;
2793 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2795 XMLProperty* prop = (*niter)->property ("type");
2797 if (prop->value() == "amp") {
2798 _amp->set_state (**niter, Stateful::current_state_version);
2799 new_order.push_back (_amp);
2800 } else if (prop->value() == "trim") {
2801 _trim->set_state (**niter, Stateful::current_state_version);
2802 new_order.push_back (_trim);
2803 } else if (prop->value() == "meter") {
2804 _meter->set_state (**niter, Stateful::current_state_version);
2805 new_order.push_back (_meter);
2806 } else if (prop->value() == "delay") {
2808 _delayline->set_state (**niter, Stateful::current_state_version);
2809 new_order.push_back (_delayline);
2811 } else if (prop->value() == "main-outs") {
2812 _main_outs->set_state (**niter, Stateful::current_state_version);
2813 } else if (prop->value() == "intreturn") {
2815 _intreturn.reset (new InternalReturn (_session));
2816 must_configure = true;
2818 _intreturn->set_state (**niter, Stateful::current_state_version);
2819 } else if (is_monitor() && prop->value() == "monitor") {
2820 if (!_monitor_control) {
2821 _monitor_control.reset (new MonitorProcessor (_session));
2822 must_configure = true;
2824 _monitor_control->set_state (**niter, Stateful::current_state_version);
2825 } else if (prop->value() == "capture") {
2826 /* CapturingProcessor should never be restored, it's always
2827 added explicitly when needed */
2829 ProcessorList::iterator o;
2831 for (o = _processors.begin(); o != _processors.end(); ++o) {
2832 XMLProperty const * id_prop = (*niter)->property(X_("id"));
2833 if (id_prop && (*o)->id() == id_prop->value()) {
2834 (*o)->set_state (**niter, Stateful::current_state_version);
2835 new_order.push_back (*o);
2840 // If the processor (*niter) is not on the route then create it
2842 if (o == _processors.end()) {
2844 boost::shared_ptr<Processor> processor;
2846 if (prop->value() == "intsend") {
2848 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2850 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2851 prop->value() == "lv2" ||
2852 prop->value() == "windows-vst" ||
2853 prop->value() == "mac-vst" ||
2854 prop->value() == "lxvst" ||
2855 prop->value() == "luaproc" ||
2856 prop->value() == "audiounit") {
2858 if (_session.get_disable_all_loaded_plugins ()) {
2859 processor.reset (new UnknownProcessor (_session, **niter));
2861 processor.reset (new PluginInsert (_session));
2862 processor->set_owner (this);
2864 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2865 pi->set_strict_io (true);
2869 } else if (prop->value() == "port") {
2871 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2873 } else if (prop->value() == "send") {
2875 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2876 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2877 send->SelfDestruct.connect_same_thread (*this,
2878 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2881 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2885 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2886 /* This processor could not be configured. Turn it into a UnknownProcessor */
2887 processor.reset (new UnknownProcessor (_session, **niter));
2890 /* subscribe to Sidechain IO changes */
2891 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2892 if (pi && pi->has_sidechain ()) {
2893 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2896 /* we have to note the monitor send here, otherwise a new one will be created
2897 and the state of this one will be lost.
2899 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2900 if (isend && isend->role() == Delivery::Listen) {
2901 _monitor_send = isend;
2904 /* it doesn't matter if invisible processors are added here, as they
2905 will be sorted out by setup_invisible_processors () shortly.
2908 new_order.push_back (processor);
2909 must_configure = true;
2915 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2916 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2917 /* re-assign _processors w/o process-lock.
2918 * if there's an IO-processor present in _processors but
2919 * not in new_order, it will be deleted and ~IO takes
2922 _processors = new_order;
2924 if (must_configure) {
2925 configure_processors_unlocked (0, &lm);
2928 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2930 (*i)->set_owner (this);
2931 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2933 boost::shared_ptr<PluginInsert> pi;
2935 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2936 if (pi->has_no_inputs ()) {
2937 _have_internal_generator = true;
2944 reset_instrument_info ();
2945 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2946 set_processor_positions ();
2950 Route::curve_reallocate ()
2952 // _gain_automation_curve.finish_resize ();
2953 // _pan_automation_curve.finish_resize ();
2957 Route::silence (framecnt_t nframes)
2959 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2964 silence_unlocked (nframes);
2968 Route::silence_unlocked (framecnt_t nframes)
2970 /* Must be called with the processor lock held */
2972 const framepos_t now = _session.transport_frame ();
2976 _output->silence (nframes);
2978 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2979 boost::shared_ptr<PluginInsert> pi;
2981 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2982 // skip plugins, they don't need anything when we're not active
2986 (*i)->silence (nframes, now);
2989 if (nframes == _session.get_block_size()) {
2996 Route::add_internal_return ()
2999 _intreturn.reset (new InternalReturn (_session));
3000 add_processor (_intreturn, PreFader);
3005 Route::add_send_to_internal_return (InternalSend* send)
3007 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3009 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3010 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3013 return d->add_send (send);
3019 Route::remove_send_from_internal_return (InternalSend* send)
3021 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3023 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3024 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3027 return d->remove_send (send);
3033 Route::enable_monitor_send ()
3035 /* Caller must hold process lock */
3036 assert (!AudioEngine::instance()->process_lock().trylock());
3038 /* master never sends to monitor section via the normal mechanism */
3039 assert (!is_master ());
3040 assert (!is_monitor ());
3042 /* make sure we have one */
3043 if (!_monitor_send) {
3044 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3045 _monitor_send->set_display_to_user (false);
3049 configure_processors (0);
3052 /** Add an aux send to a route.
3053 * @param route route to send to.
3054 * @param before Processor to insert before, or 0 to insert at the end.
3057 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3059 assert (route != _session.monitor_out ());
3062 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3064 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3066 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3068 if (d && d->target_route() == route) {
3069 /* already listening via the specified IO: do nothing */
3077 boost::shared_ptr<InternalSend> listener;
3080 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3081 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3084 add_processor (listener, before);
3086 } catch (failed_constructor& err) {
3094 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3096 ProcessorStreams err;
3097 ProcessorList::iterator tmp;
3100 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3102 /* have to do this early because otherwise processor reconfig
3103 * will put _monitor_send back in the list
3106 if (route == _session.monitor_out()) {
3107 _monitor_send.reset ();
3111 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3113 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3115 if (d && d->target_route() == route) {
3117 if (remove_processor (*x, &err, false) > 0) {
3123 /* list could have been demolished while we dropped the lock
3126 if (_session.engine().connected()) {
3127 /* i/o processors cannot be removed if the engine is not running
3128 * so don't live-loop in case the engine is N/A or dies
3138 Route::set_comment (string cmt, void *src)
3142 _session.set_dirty ();
3146 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3148 FeedRecord fr (other, via_sends_only);
3150 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3152 if (!result.second) {
3154 /* already a record for "other" - make sure sends-only information is correct */
3155 if (!via_sends_only && result.first->sends_only) {
3156 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3157 frp->sends_only = false;
3161 return result.second;
3165 Route::clear_fed_by ()
3171 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3173 const FedBy& fed_by (other->fed_by());
3175 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3176 boost::shared_ptr<Route> sr = f->r.lock();
3178 if (sr && (sr.get() == this)) {
3180 if (via_sends_only) {
3181 *via_sends_only = f->sends_only;
3192 Route::all_inputs () const
3194 /* TODO, if this works as expected,
3195 * cache the IOVector and maintain it via
3196 * input_change_handler(), sidechain_change_handler() etc
3199 ios.push_back (_input);
3201 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3202 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3204 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3205 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3208 iop = pi->sidechain();
3211 if (iop != 0 && iop->input()) {
3212 ios.push_back (iop->input());
3219 Route::all_outputs () const
3222 // _output is included via Delivery
3223 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3224 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3225 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3226 if (iop != 0 && iop->output()) {
3227 ios.push_back (iop->output());
3234 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3236 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3237 if (other->all_inputs().fed_by (_output)) {
3238 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3239 if (via_send_only) {
3240 *via_send_only = false;
3246 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3248 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3250 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3251 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3254 iop = pi->sidechain();
3258 boost::shared_ptr<const IO> iop_out = iop->output();
3259 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3260 // TODO this needs a delaylines in the Insert to align connections (!)
3261 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3264 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3265 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3266 if (via_send_only) {
3267 *via_send_only = true;
3271 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3274 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3279 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3284 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3286 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3290 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3292 return _session._current_route_graph.feeds (shared_from_this (), other);
3295 /** Called from the (non-realtime) butler thread when the transport is stopped */
3297 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3299 framepos_t now = _session.transport_frame();
3302 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3304 Automatable::transport_stopped (now);
3306 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3308 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3312 (*i)->transport_stopped (now);
3316 _roll_delay = _initial_delay;
3320 Route::input_change_handler (IOChange change, void * /*src*/)
3322 if ((change.type & IOChange::ConfigurationChanged)) {
3323 /* This is called with the process lock held if change
3324 contains ConfigurationChanged
3326 configure_processors (0);
3327 _phase_control->resize (_input->n_ports().n_audio ());
3328 io_changed (); /* EMIT SIGNAL */
3331 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3334 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3335 if (_input->connected()) {
3336 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3337 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3341 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3342 if (does_feed && !sends_only) {
3343 if ((*i)->soloed()) {
3346 if ((*i)->solo_isolate_control()->solo_isolated()) {
3353 int delta = sbou - _solo_control->soloed_by_others_upstream();
3354 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3357 PBD::warning << string_compose (
3358 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3359 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3364 if (_solo_control->soloed_by_others_upstream()) {
3365 // ignore new connections (they're not propagated)
3367 _solo_control->mod_solo_by_others_upstream (delta);
3371 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3372 // solo-isolate currently only propagates downstream
3374 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3376 //_solo_isolated_by_upstream = ibou;
3379 // Session::route_solo_changed does not propagate indirect solo-changes
3380 // propagate downstream to tracks
3381 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3382 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3386 bool does_feed = feeds (*i, &sends_only);
3387 if (delta <= 0 && does_feed && !sends_only) {
3388 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3391 if (idelta < 0 && does_feed && !sends_only) {
3392 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3399 Route::output_change_handler (IOChange change, void * /*src*/)
3401 if (_initial_io_setup) {
3405 if ((change.type & IOChange::ConfigurationChanged)) {
3406 /* This is called with the process lock held if change
3407 contains ConfigurationChanged
3409 configure_processors (0);
3412 _session.reset_monitor_section();
3415 io_changed (); /* EMIT SIGNAL */
3418 if ((change.type & IOChange::ConnectionsChanged)) {
3420 /* do this ONLY if connections have changed. Configuration
3421 * changes do not, by themselves alter solo upstream or
3422 * downstream status.
3425 if (_solo_control->soloed_by_others_downstream()) {
3427 /* checking all all downstream routes for
3428 * explicit of implict solo is a rather drastic measure,
3429 * ideally the input_change_handler() of the other route
3430 * would propagate the change to us.
3432 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3433 if (_output->connected()) {
3434 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3435 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3439 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3440 if (does_feed && !sends_only) {
3441 if ((*i)->soloed()) {
3449 int delta = sbod - _solo_control->soloed_by_others_downstream();
3451 // do not allow new connections to change implicit solo (no propagation)
3452 _solo_control->mod_solo_by_others_downstream (delta);
3453 // Session::route_solo_changed() does not propagate indirect solo-changes
3454 // propagate upstream to tracks
3455 boost::shared_ptr<Route> shared_this = shared_from_this();
3456 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3457 if ((*i).get() == this || !can_solo()) {
3461 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3462 if (delta != 0 && does_feed && !sends_only) {
3463 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3473 Route::sidechain_change_handler (IOChange change, void* src)
3475 if (_initial_io_setup || _in_sidechain_setup) {
3479 input_change_handler (change, src);
3483 Route::pans_required () const
3485 if (n_outputs().n_audio() < 2) {
3489 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3493 Route::flush_processor_buffers_locked (framecnt_t nframes)
3495 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3496 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3498 d->flush_buffers (nframes);
3500 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3502 p->flush_buffers (nframes);
3509 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3511 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3518 silence_unlocked (nframes);
3522 if (session_state_changing) {
3523 if (_session.transport_speed() != 0.0f) {
3524 /* we're rolling but some state is changing (e.g. our diskstream contents)
3525 so we cannot use them. Be silent till this is over.
3527 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3529 silence_unlocked (nframes);
3532 /* we're really not rolling, so we're either delivery silence or actually
3533 monitoring, both of which are safe to do while session_state_changing is true.
3537 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3539 fill_buffers_with_input (bufs, _input, nframes);
3541 if (_meter_point == MeterInput) {
3542 _meter->run (bufs, start_frame, end_frame, 0.0, nframes, true);
3545 _amp->apply_gain_automation (false);
3546 _trim->apply_gain_automation (false);
3547 passthru (bufs, start_frame, end_frame, nframes, 0);
3549 flush_processor_buffers_locked (nframes);
3555 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3557 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3563 silence_unlocked (nframes);
3567 framepos_t unused = 0;
3569 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3575 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3577 fill_buffers_with_input (bufs, _input, nframes);
3579 if (_meter_point == MeterInput) {
3580 _meter->run (bufs, start_frame, end_frame, 1.0, nframes, true);
3583 passthru (bufs, start_frame, end_frame, nframes, declick);
3585 flush_processor_buffers_locked (nframes);
3591 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3594 flush_processor_buffers_locked (nframes);
3599 Route::flush_processors ()
3601 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3603 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3609 __attribute__((annotate("realtime")))
3612 Route::apply_processor_changes_rt ()
3614 int emissions = EmitNone;
3616 if (_pending_meter_point != _meter_point) {
3617 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3619 /* meters always have buffers for 'processor_max_streams'
3620 * they can be re-positioned without re-allocation */
3621 if (set_meter_point_unlocked()) {
3622 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3624 emissions |= EmitMeterChanged;
3629 bool changed = false;
3631 if (g_atomic_int_get (&_pending_process_reorder)) {
3632 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3634 apply_processor_order (_pending_processor_order);
3635 setup_invisible_processors ();
3637 g_atomic_int_set (&_pending_process_reorder, 0);
3638 emissions |= EmitRtProcessorChange;
3642 set_processor_positions ();
3644 if (emissions != 0) {
3645 g_atomic_int_set (&_pending_signals, emissions);
3648 return (!selfdestruct_sequence.empty ());
3652 Route::emit_pending_signals ()
3654 int sig = g_atomic_int_and (&_pending_signals, 0);
3655 if (sig & EmitMeterChanged) {
3656 _meter->emit_configuration_changed();
3657 meter_change (); /* EMIT SIGNAL */
3658 if (sig & EmitMeterVisibilityChange) {
3659 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3661 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3664 if (sig & EmitRtProcessorChange) {
3665 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3668 /* this would be a job for the butler.
3669 * Conceptually we should not take processe/processor locks here.
3670 * OTOH its more efficient (less overhead for summoning the butler and
3671 * telling her what do do) and signal emission is called
3672 * directly after the process callback, which decreases the chance
3673 * of x-runs when taking the locks.
3675 while (!selfdestruct_sequence.empty ()) {
3676 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3677 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3678 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3679 selfdestruct_sequence.pop_back ();
3682 remove_processor (proc);
3688 Route::set_meter_point (MeterPoint p, bool force)
3690 if (_pending_meter_point == p && !force) {
3694 if (force || !AudioEngine::instance()->running()) {
3695 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3696 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3697 _pending_meter_point = p;
3698 _meter->emit_configuration_changed();
3699 meter_change (); /* EMIT SIGNAL */
3700 if (set_meter_point_unlocked()) {
3701 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3703 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3706 _pending_meter_point = p;
3712 __attribute__((annotate("realtime")))
3715 Route::set_meter_point_unlocked ()
3718 /* Caller must hold process and processor write lock */
3719 assert (!AudioEngine::instance()->process_lock().trylock());
3720 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3721 assert (!lm.locked ());
3724 _meter_point = _pending_meter_point;
3726 bool meter_was_visible_to_user = _meter->display_to_user ();
3728 if (!_custom_meter_position_noted) {
3729 maybe_note_meter_position ();
3732 if (_meter_point != MeterCustom) {
3734 _meter->set_display_to_user (false);
3736 setup_invisible_processors ();
3739 _meter->set_display_to_user (true);
3741 /* If we have a previous position for the custom meter, try to put it there */
3742 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3744 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3745 if (i != _processors.end ()) {
3746 _processors.remove (_meter);
3747 _processors.insert (i, _meter);
3749 } else {// at end, right before the mains_out/panner
3750 _processors.remove (_meter);
3751 ProcessorList::iterator main = _processors.end();
3752 _processors.insert (--main, _meter);
3756 /* Set up the meter for its new position */
3758 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3762 if (loc == _processors.begin()) {
3763 m_in = _input->n_ports();
3765 ProcessorList::iterator before = loc;
3767 m_in = (*before)->output_streams ();
3770 _meter->reflect_inputs (m_in);
3772 /* we do not need to reconfigure the processors, because the meter
3773 (a) is always ready to handle processor_max_streams
3774 (b) is always an N-in/N-out processor, and thus moving
3775 it doesn't require any changes to the other processors.
3778 /* these should really be done after releasing the lock
3779 * but all those signals are subscribed to with gui_thread()
3782 return (_meter->display_to_user() != meter_was_visible_to_user);
3786 Route::listen_position_changed ()
3789 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3790 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3791 ProcessorState pstate (this);
3793 if (configure_processors_unlocked (0, &lm)) {
3794 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3796 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3801 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3802 _session.set_dirty ();
3805 boost::shared_ptr<CapturingProcessor>
3806 Route::add_export_point()
3808 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3809 if (!_capturing_processor) {
3811 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3812 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3814 // this aligns all tracks; but not tracks + busses
3815 assert (_session.worst_track_latency () >= _initial_delay);
3816 _capturing_processor.reset (new CapturingProcessor (_session, _session.worst_track_latency () - _initial_delay));
3817 _capturing_processor->activate ();
3819 configure_processors_unlocked (0, &lw);
3823 return _capturing_processor;
3827 Route::update_signal_latency ()
3829 framecnt_t l = _output->user_latency();
3830 framecnt_t lamp = 0;
3831 bool before_amp = true;
3832 framecnt_t ltrim = 0;
3833 bool before_trim = true;
3835 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3836 if ((*i)->active ()) {
3837 l += (*i)->signal_latency ();
3842 if ((*i) == _trim) {
3853 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3855 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3856 _signal_latency_at_amp_position = lamp;
3857 _signal_latency_at_trim_position = ltrim;
3859 if (_signal_latency != l) {
3860 _signal_latency = l;
3861 signal_latency_changed (); /* EMIT SIGNAL */
3864 return _signal_latency;
3868 Route::set_user_latency (framecnt_t nframes)
3870 _output->set_user_latency (nframes);
3871 _session.update_latency_compensation ();
3875 Route::set_latency_compensation (framecnt_t longest_session_latency)
3877 framecnt_t old = _initial_delay;
3879 if (_signal_latency < longest_session_latency) {
3880 _initial_delay = longest_session_latency - _signal_latency;
3885 DEBUG_TRACE (DEBUG::Latency, string_compose (
3886 "%1: compensate for maximum latency of %2,"
3887 "given own latency of %3, using initial delay of %4\n",
3888 name(), longest_session_latency, _signal_latency, _initial_delay));
3890 if (_initial_delay != old) {
3891 initial_delay_changed (); /* EMIT SIGNAL */
3894 if (_session.transport_stopped()) {
3895 _roll_delay = _initial_delay;
3900 Route::set_block_size (pframes_t nframes)
3902 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3903 (*i)->set_block_size (nframes);
3906 _session.ensure_buffers (n_process_buffers ());
3910 Route::protect_automation ()
3912 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3913 (*i)->protect_automation();
3916 /** @param declick 1 to set a pending declick fade-in,
3917 * -1 to set a pending declick fade-out
3920 Route::set_pending_declick (int declick)
3923 /* this call is not allowed to turn off a pending declick */
3925 _pending_declick = declick;
3928 _pending_declick = 0;
3932 /** Shift automation forwards from a particular place, thereby inserting time.
3933 * Adds undo commands for any shifts that are performed.
3935 * @param pos Position to start shifting from.
3936 * @param frames Amount to shift forwards by.
3940 Route::shift (framepos_t pos, framecnt_t frames)
3942 /* gain automation */
3944 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3946 XMLNode &before = gc->alist()->get_state ();
3947 gc->alist()->shift (pos, frames);
3948 XMLNode &after = gc->alist()->get_state ();
3949 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3952 /* gain automation */
3954 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
3956 XMLNode &before = gc->alist()->get_state ();
3957 gc->alist()->shift (pos, frames);
3958 XMLNode &after = gc->alist()->get_state ();
3959 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3962 // TODO mute automation ??
3964 /* pan automation */
3966 ControlSet::Controls& c (_pannable->controls());
3968 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3969 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3971 boost::shared_ptr<AutomationList> al = pc->alist();
3972 XMLNode& before = al->get_state ();
3973 al->shift (pos, frames);
3974 XMLNode& after = al->get_state ();
3975 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3980 /* redirect automation */
3982 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3983 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3985 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3987 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3988 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3990 boost::shared_ptr<AutomationList> al = ac->alist();
3991 XMLNode &before = al->get_state ();
3992 al->shift (pos, frames);
3993 XMLNode &after = al->get_state ();
3994 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4002 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4004 boost::shared_ptr<Processor> processor (p.lock ());
4005 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4009 pi->set_state_dir (d);
4013 Route::save_as_template (const string& path, const string& name)
4015 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4016 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4018 XMLNode& node (state (false));
4022 IO::set_name_in_state (*node.children().front(), name);
4024 tree.set_root (&node);
4026 /* return zero on success, non-zero otherwise */
4027 return !tree.write (path.c_str());
4032 Route::set_name (const string& str)
4038 if (str == name()) {
4042 string name = Route::ensure_track_or_route_name (str, _session);
4043 SessionObject::set_name (name);
4045 bool ret = (_input->set_name(name) && _output->set_name(name));
4048 /* rename the main outs. Leave other IO processors
4049 * with whatever name they already have, because its
4050 * just fine as it is (it will not contain the route
4051 * name if its a port insert, port send or port return).
4055 if (_main_outs->set_name (name)) {
4056 /* XXX returning false here is stupid because
4057 we already changed the route name.
4067 /** Set the name of a route in an XML description.
4068 * @param node XML <Route> node to set the name in.
4069 * @param name New name.
4072 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4074 node.add_property (X_("name"), name);
4076 XMLNodeList children = node.children();
4077 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4079 if ((*i)->name() == X_("IO")) {
4081 IO::set_name_in_state (**i, name);
4083 } else if ((*i)->name() == X_("Processor")) {
4085 XMLProperty const * role = (*i)->property (X_("role"));
4086 if (role && role->value() == X_("Main")) {
4087 (*i)->add_property (X_("name"), name);
4090 } else if ((*i)->name() == X_("Diskstream")) {
4092 if (rename_playlist) {
4093 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4095 (*i)->add_property (X_("name"), name);
4101 boost::shared_ptr<Send>
4102 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4104 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4106 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4107 boost::shared_ptr<InternalSend> send;
4109 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4110 if (send->target_route() == target) {
4116 return boost::shared_ptr<Send>();
4120 Route::set_denormal_protection (bool yn)
4122 if (_denormal_protection != yn) {
4123 _denormal_protection = yn;
4124 denormal_protection_changed (); /* EMIT SIGNAL */
4129 Route::denormal_protection () const
4131 return _denormal_protection;
4135 Route::set_active (bool yn, void* src)
4137 if (_session.transport_rolling()) {
4141 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4142 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4146 if (_active != yn) {
4148 _input->set_active (yn);
4149 _output->set_active (yn);
4150 flush_processors ();
4151 active_changed (); // EMIT SIGNAL
4152 _session.set_dirty ();
4156 boost::shared_ptr<Pannable>
4157 Route::pannable() const
4162 boost::shared_ptr<Panner>
4163 Route::panner() const
4166 return _main_outs->panner_shell()->panner();
4169 boost::shared_ptr<PannerShell>
4170 Route::panner_shell() const
4172 return _main_outs->panner_shell();
4175 boost::shared_ptr<GainControl>
4176 Route::gain_control() const
4178 return _gain_control;
4181 boost::shared_ptr<GainControl>
4182 Route::trim_control() const
4184 return _trim_control;
4187 boost::shared_ptr<PhaseControl>
4188 Route::phase_control() const
4190 return _phase_control;
4193 boost::shared_ptr<AutomationControl>
4194 Route::get_control (const Evoral::Parameter& param)
4196 /* either we own the control or .... */
4198 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4202 /* maybe one of our processors does or ... */
4204 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4205 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4206 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4214 /* nobody does so we'll make a new one */
4216 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4223 boost::shared_ptr<Processor>
4224 Route::nth_plugin (uint32_t n) const
4226 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4227 ProcessorList::const_iterator i;
4229 for (i = _processors.begin(); i != _processors.end(); ++i) {
4230 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4237 return boost::shared_ptr<Processor> ();
4240 boost::shared_ptr<Processor>
4241 Route::nth_send (uint32_t n) const
4243 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4244 ProcessorList::const_iterator i;
4246 for (i = _processors.begin(); i != _processors.end(); ++i) {
4247 if (boost::dynamic_pointer_cast<Send> (*i)) {
4249 if ((*i)->name().find (_("Monitor")) == 0) {
4250 /* send to monitor section is not considered
4251 to be an accessible send.
4262 return boost::shared_ptr<Processor> ();
4266 Route::has_io_processor_named (const string& name)
4268 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4269 ProcessorList::iterator i;
4271 for (i = _processors.begin(); i != _processors.end(); ++i) {
4272 if (boost::dynamic_pointer_cast<Send> (*i) ||
4273 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4274 if ((*i)->name() == name) {
4284 Route::set_processor_positions ()
4286 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4288 bool had_amp = false;
4289 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4290 (*i)->set_pre_fader (!had_amp);
4297 /** Called when there is a proposed change to the input port count */
4299 Route::input_port_count_changing (ChanCount to)
4301 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4303 /* The processors cannot be configured with the new input arrangement, so
4309 /* The change is ok */
4313 /** Called when there is a proposed change to the output port count */
4315 Route::output_port_count_changing (ChanCount to)
4317 if (_strict_io && !_in_configure_processors) {
4320 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4321 if (processor_out_streams.get(*t) > to.get(*t)) {
4325 /* The change is ok */
4330 Route::unknown_processors () const
4334 if (_session.get_disable_all_loaded_plugins ()) {
4335 // Do not list "missing plugins" if they are explicitly disabled
4339 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4340 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4341 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4342 p.push_back ((*i)->name ());
4351 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4353 /* we assume that all our input ports feed all our output ports. its not
4354 universally true, but the alternative is way too corner-case to worry about.
4357 LatencyRange all_connections;
4360 all_connections.min = 0;
4361 all_connections.max = 0;
4363 all_connections.min = ~((pframes_t) 0);
4364 all_connections.max = 0;
4366 /* iterate over all "from" ports and determine the latency range for all of their
4367 connections to the "outside" (outside of this Route).
4370 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4374 p->get_connected_latency_range (range, playback);
4376 all_connections.min = min (all_connections.min, range.min);
4377 all_connections.max = max (all_connections.max, range.max);
4381 /* set the "from" port latencies to the max/min range of all their connections */
4383 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4384 p->set_private_latency_range (all_connections, playback);
4387 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4389 all_connections.min += our_latency;
4390 all_connections.max += our_latency;
4392 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4393 p->set_private_latency_range (all_connections, playback);
4396 return all_connections.max;
4400 Route::set_private_port_latencies (bool playback) const
4402 framecnt_t own_latency = 0;
4404 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4405 OR LATENCY CALLBACK.
4407 This is called (early) from the latency callback. It computes the REAL
4408 latency associated with each port and stores the result as the "private"
4409 latency of the port. A later call to Route::set_public_port_latencies()
4410 sets all ports to the same value to reflect the fact that we do latency
4411 compensation and so all signals are delayed by the same amount as they
4412 flow through ardour.
4415 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4416 if ((*i)->active ()) {
4417 own_latency += (*i)->signal_latency ();
4422 /* playback: propagate latency from "outside the route" to outputs to inputs */
4423 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4425 /* capture: propagate latency from "outside the route" to inputs to outputs */
4426 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4431 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4433 /* this is called to set the JACK-visible port latencies, which take
4434 latency compensation into account.
4443 const PortSet& ports (_input->ports());
4444 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4445 p->set_public_latency_range (range, playback);
4450 const PortSet& ports (_output->ports());
4451 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4452 p->set_public_latency_range (range, playback);
4457 /** Put the invisible processors in the right place in _processors.
4458 * Must be called with a writer lock on _processor_lock held.
4461 __attribute__((annotate("realtime")))
4464 Route::setup_invisible_processors ()
4467 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4468 assert (!lm.locked ());
4472 /* too early to be doing this stuff */
4476 /* we'll build this new list here and then use it
4478 * TODO put the ProcessorList is on the stack for RT-safety.
4481 ProcessorList new_processors;
4483 /* find visible processors */
4485 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4486 if ((*i)->display_to_user ()) {
4487 new_processors.push_back (*i);
4493 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4495 if (amp == new_processors.end ()) {
4496 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4497 new_processors.push_front (_amp);
4498 amp = find (new_processors.begin(), new_processors.end(), _amp);
4501 /* and the processor after the amp */
4503 ProcessorList::iterator after_amp = amp;
4509 switch (_meter_point) {
4511 assert (!_meter->display_to_user ());
4512 new_processors.push_front (_meter);
4515 assert (!_meter->display_to_user ());
4516 new_processors.insert (amp, _meter);
4518 case MeterPostFader:
4519 /* do nothing here */
4522 /* do nothing here */
4525 /* the meter is visible, so we don't touch it here */
4532 assert (_main_outs);
4533 assert (!_main_outs->display_to_user ());
4534 new_processors.push_back (_main_outs);
4536 /* iterator for the main outs */
4538 ProcessorList::iterator main = new_processors.end();
4541 /* OUTPUT METERING */
4543 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4544 assert (!_meter->display_to_user ());
4546 /* add the processor just before or just after the main outs */
4548 ProcessorList::iterator meter_point = main;
4550 if (_meter_point == MeterOutput) {
4553 new_processors.insert (meter_point, _meter);
4558 if (_monitor_send && !is_monitor ()) {
4559 assert (!_monitor_send->display_to_user ());
4560 switch (Config->get_listen_position ()) {
4561 case PreFaderListen:
4562 switch (Config->get_pfl_position ()) {
4563 case PFLFromBeforeProcessors:
4564 new_processors.push_front (_monitor_send);
4566 case PFLFromAfterProcessors:
4567 new_processors.insert (amp, _monitor_send);
4570 _monitor_send->set_can_pan (false);
4572 case AfterFaderListen:
4573 switch (Config->get_afl_position ()) {
4574 case AFLFromBeforeProcessors:
4575 new_processors.insert (after_amp, _monitor_send);
4577 case AFLFromAfterProcessors:
4578 new_processors.insert (new_processors.end(), _monitor_send);
4581 _monitor_send->set_can_pan (true);
4586 #if 0 // not used - just yet
4587 if (!is_master() && !is_monitor() && !is_auditioner()) {
4588 new_processors.push_front (_delayline);
4592 /* MONITOR CONTROL */
4594 if (_monitor_control && is_monitor ()) {
4595 assert (!_monitor_control->display_to_user ());
4596 new_processors.insert (amp, _monitor_control);
4601 if (_trim && _trim->active()) {
4602 assert (!_trim->display_to_user ());
4603 new_processors.push_front (_trim);
4606 /* INTERNAL RETURN */
4608 /* doing this here means that any monitor control will come after
4609 the return and trim.
4613 assert (!_intreturn->display_to_user ());
4614 new_processors.push_front (_intreturn);
4617 /* EXPORT PROCESSOR */
4619 if (_capturing_processor) {
4620 assert (!_capturing_processor->display_to_user ());
4621 new_processors.push_front (_capturing_processor);
4624 _processors = new_processors;
4626 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4627 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4628 (*i)->enable (true);
4632 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4633 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4634 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4641 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4642 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4646 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4647 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4654 /** If the meter point is `Custom', make a note of where the meter is.
4655 * This is so that if the meter point is subsequently set to something else,
4656 * and then back to custom, we can put the meter back where it was last time
4657 * custom was enabled.
4659 * Must be called with the _processor_lock held.
4662 Route::maybe_note_meter_position ()
4664 if (_meter_point != MeterCustom) {
4668 _custom_meter_position_noted = true;
4669 /* custom meter points range from after trim to before panner/main_outs
4670 * this is a limitation by the current processor UI
4672 bool seen_trim = false;
4673 _processor_after_last_custom_meter.reset();
4674 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4675 if ((*i) == _trim) {
4678 if ((*i) == _main_outs) {
4679 _processor_after_last_custom_meter = *i;
4682 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4684 _processor_after_last_custom_meter = _trim;
4686 ProcessorList::iterator j = i;
4688 assert(j != _processors.end ()); // main_outs should be before
4689 _processor_after_last_custom_meter = *j;
4694 assert(_processor_after_last_custom_meter.lock());
4697 boost::shared_ptr<Processor>
4698 Route::processor_by_id (PBD::ID id) const
4700 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4701 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4702 if ((*i)->id() == id) {
4707 return boost::shared_ptr<Processor> ();
4710 /** @return the monitoring state, or in other words what data we are pushing
4711 * into the route (data from the inputs, data from disk or silence)
4714 Route::monitoring_state () const
4716 return MonitoringInput;
4719 /** @return what we should be metering; either the data coming from the input
4720 * IO or the data that is flowing through the route.
4723 Route::metering_state () const
4725 return MeteringRoute;
4729 Route::has_external_redirects () const
4731 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4733 /* ignore inactive processors and obviously ignore the main
4734 * outs since everything has them and we don't care.
4737 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4745 boost::shared_ptr<Processor>
4746 Route::the_instrument () const
4748 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4749 return the_instrument_unlocked ();
4752 boost::shared_ptr<Processor>
4753 Route::the_instrument_unlocked () const
4755 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4756 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4757 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4761 return boost::shared_ptr<Processor>();
4767 Route::non_realtime_locate (framepos_t pos)
4770 _pannable->transport_located (pos);
4773 if (_delayline.get()) {
4774 _delayline.get()->flush();
4778 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4779 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4781 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4782 (*i)->transport_located (pos);
4785 _roll_delay = _initial_delay;
4789 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4796 * We don't currently mix MIDI input together, so we don't need the
4797 * complex logic of the audio case.
4800 n_buffers = bufs.count().n_midi ();
4802 for (i = 0; i < n_buffers; ++i) {
4804 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4805 MidiBuffer& buf (bufs.get_midi (i));
4808 buf.copy (source_port->get_midi_buffer(nframes));
4810 buf.silence (nframes);
4816 n_buffers = bufs.count().n_audio();
4818 size_t n_ports = io->n_ports().n_audio();
4819 float scaling = 1.0f;
4821 if (n_ports > n_buffers) {
4822 scaling = ((float) n_buffers) / n_ports;
4825 for (i = 0; i < n_ports; ++i) {
4827 /* if there are more ports than buffers, map them onto buffers
4828 * in a round-robin fashion
4831 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4832 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4835 if (i < n_buffers) {
4837 /* first time through just copy a channel into
4841 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4843 if (scaling != 1.0f) {
4844 buf.apply_gain (scaling, nframes);
4849 /* on subsequent times around, merge data from
4850 * the port with what is already there
4853 if (scaling != 1.0f) {
4854 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4856 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4861 /* silence any remaining buffers */
4863 for (; i < n_buffers; ++i) {
4864 AudioBuffer& buf (bufs.get_audio (i));
4865 buf.silence (nframes);
4868 /* establish the initial setup of the buffer set, reflecting what was
4869 copied into it. unless, of course, we are the auditioner, in which
4870 case nothing was fed into it from the inputs at all.
4873 if (!is_auditioner()) {
4874 bufs.set_count (io->n_ports());
4878 boost::shared_ptr<AutomationControl>
4879 Route::pan_azimuth_control() const
4882 # undef MIXBUS_PORTS_H
4883 # include "../../gtk2_ardour/mixbus_ports.h"
4884 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4886 return boost::shared_ptr<AutomationControl>();
4888 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4890 if (!_pannable || !panner()) {
4891 return boost::shared_ptr<AutomationControl>();
4893 return _pannable->pan_azimuth_control;
4897 boost::shared_ptr<AutomationControl>
4898 Route::pan_elevation_control() const
4900 if (Profile->get_mixbus() || !_pannable || !panner()) {
4901 return boost::shared_ptr<AutomationControl>();
4904 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4906 if (c.find (PanElevationAutomation) != c.end()) {
4907 return _pannable->pan_elevation_control;
4909 return boost::shared_ptr<AutomationControl>();
4912 boost::shared_ptr<AutomationControl>
4913 Route::pan_width_control() const
4916 if (mixbus() && _ch_pre) {
4918 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
4921 if (Profile->get_mixbus() || !_pannable || !panner()) {
4922 return boost::shared_ptr<AutomationControl>();
4925 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4927 if (c.find (PanWidthAutomation) != c.end()) {
4928 return _pannable->pan_width_control;
4930 return boost::shared_ptr<AutomationControl>();
4933 boost::shared_ptr<AutomationControl>
4934 Route::pan_frontback_control() const
4936 if (Profile->get_mixbus() || !_pannable || !panner()) {
4937 return boost::shared_ptr<AutomationControl>();
4940 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4942 if (c.find (PanFrontBackAutomation) != c.end()) {
4943 return _pannable->pan_frontback_control;
4945 return boost::shared_ptr<AutomationControl>();
4948 boost::shared_ptr<AutomationControl>
4949 Route::pan_lfe_control() const
4951 if (Profile->get_mixbus() || !_pannable || !panner()) {
4952 return boost::shared_ptr<AutomationControl>();
4955 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
4957 if (c.find (PanLFEAutomation) != c.end()) {
4958 return _pannable->pan_lfe_control;
4960 return boost::shared_ptr<AutomationControl>();
4965 Route::eq_band_cnt () const
4967 if (Profile->get_mixbus()) {
4969 if (is_master() || mixbus()) {
4978 /* Ardour has no well-known EQ object */
4983 boost::shared_ptr<AutomationControl>
4984 Route::eq_gain_controllable (uint32_t band) const
4987 boost::shared_ptr<PluginInsert> eq = ch_eq();
4990 return boost::shared_ptr<AutomationControl>();
4993 uint32_t port_number;
4994 if (is_master() || mixbus()) {
4996 case 0: port_number = 4; break;
4997 case 1: port_number = 3; break;
4998 case 2: port_number = 2; break;
5000 return boost::shared_ptr<AutomationControl>();
5005 case 0: port_number = 14; break;
5006 case 1: port_number = 12; break;
5007 case 2: port_number = 10; break;
5008 case 3: port_number = 8; break;
5010 return boost::shared_ptr<AutomationControl>();
5014 case 0: port_number = 8; break;
5015 case 1: port_number = 6; break;
5016 case 2: port_number = 4; break;
5018 return boost::shared_ptr<AutomationControl>();
5023 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5025 return boost::shared_ptr<AutomationControl>();
5028 boost::shared_ptr<AutomationControl>
5029 Route::eq_freq_controllable (uint32_t band) const
5032 if (mixbus() || is_master()) {
5033 /* no frequency controls for mixbusses or master */
5034 return boost::shared_ptr<AutomationControl>();
5037 boost::shared_ptr<PluginInsert> eq = ch_eq();
5040 return boost::shared_ptr<AutomationControl>();
5043 uint32_t port_number;
5046 case 0: port_number = 13; break;
5047 case 1: port_number = 11; break;
5048 case 2: port_number = 9; break;
5049 case 3: port_number = 7; break;
5051 return boost::shared_ptr<AutomationControl>();
5055 case 0: port_number = 7; break;
5056 case 1: port_number = 5; break;
5057 case 2: port_number = 3; break;
5059 return boost::shared_ptr<AutomationControl>();
5063 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5065 return boost::shared_ptr<AutomationControl>();
5069 boost::shared_ptr<AutomationControl>
5070 Route::eq_q_controllable (uint32_t band) const
5072 return boost::shared_ptr<AutomationControl>();
5075 boost::shared_ptr<AutomationControl>
5076 Route::eq_shape_controllable (uint32_t band) const
5078 return boost::shared_ptr<AutomationControl>();
5081 boost::shared_ptr<AutomationControl>
5082 Route::eq_enable_controllable () const
5085 boost::shared_ptr<PluginInsert> eq = ch_eq();
5088 return boost::shared_ptr<AutomationControl>();
5091 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5093 return boost::shared_ptr<AutomationControl>();
5097 boost::shared_ptr<AutomationControl>
5098 Route::eq_hpf_controllable () const
5101 boost::shared_ptr<PluginInsert> eq = ch_eq();
5103 if (is_master() || mixbus() || !eq) {
5104 return boost::shared_ptr<AutomationControl>();
5107 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5109 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5113 return boost::shared_ptr<AutomationControl>();
5118 Route::eq_band_name (uint32_t band) const
5121 if (is_master() || mixbus()) {
5123 if (Profile->get_mixbus()) {
5125 case 0: return _("lo");
5126 case 1: return _("mid");
5127 case 2: return _("hi");
5128 default: return string();
5136 case 0: return _("lo");
5137 case 1: return _("lo mid");
5138 case 2: return _("hi mid");
5139 case 3: return _("hi");
5140 default: return string();
5146 boost::shared_ptr<AutomationControl>
5147 Route::comp_enable_controllable () const
5150 boost::shared_ptr<PluginInsert> comp = ch_comp();
5153 return boost::shared_ptr<AutomationControl>();
5156 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5158 return boost::shared_ptr<AutomationControl>();
5161 boost::shared_ptr<AutomationControl>
5162 Route::comp_threshold_controllable () const
5165 boost::shared_ptr<PluginInsert> comp = ch_comp();
5168 return boost::shared_ptr<AutomationControl>();
5171 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5174 return boost::shared_ptr<AutomationControl>();
5177 boost::shared_ptr<AutomationControl>
5178 Route::comp_speed_controllable () const
5181 boost::shared_ptr<PluginInsert> comp = ch_comp();
5184 return boost::shared_ptr<AutomationControl>();
5187 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5189 return boost::shared_ptr<AutomationControl>();
5192 boost::shared_ptr<AutomationControl>
5193 Route::comp_mode_controllable () const
5196 boost::shared_ptr<PluginInsert> comp = ch_comp();
5199 return boost::shared_ptr<AutomationControl>();
5202 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5204 return boost::shared_ptr<AutomationControl>();
5207 boost::shared_ptr<AutomationControl>
5208 Route::comp_makeup_controllable () const
5211 boost::shared_ptr<PluginInsert> comp = ch_comp();
5214 return boost::shared_ptr<AutomationControl>();
5217 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5219 return boost::shared_ptr<AutomationControl>();
5222 boost::shared_ptr<ReadOnlyControl>
5223 Route::comp_redux_controllable () const
5226 boost::shared_ptr<PluginInsert> comp = ch_comp();
5229 return boost::shared_ptr<ReadOnlyControl>();
5232 return comp->control_output (2);
5234 return comp->control_output (6);
5238 return boost::shared_ptr<ReadOnlyControl>();
5243 Route::comp_mode_name (uint32_t mode) const
5248 return _("Leveler");
5250 return _("Compressor");
5252 return _("Limiter");
5254 return mixbus() ? _("Sidechain") : _("Limiter");
5264 Route::comp_speed_name (uint32_t mode) const
5282 boost::shared_ptr<AutomationControl>
5283 Route::send_level_controllable (uint32_t n) const
5286 # undef MIXBUS_PORTS_H
5287 # include "../../gtk2_ardour/mixbus_ports.h"
5288 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5290 uint32_t port_id = 0;
5292 case 0: port_id = port_channel_post_aux1_level; break;
5293 case 1: port_id = port_channel_post_aux2_level; break;
5294 case 2: port_id = port_channel_post_aux3_level; break;
5295 case 3: port_id = port_channel_post_aux4_level; break;
5296 case 4: port_id = port_channel_post_aux5_level; break;
5297 case 5: port_id = port_channel_post_aux6_level; break;
5298 case 6: port_id = port_channel_post_aux7_level; break;
5299 case 7: port_id = port_channel_post_aux8_level; break;
5301 case 8: port_id = port_channel_post_aux9_level; break;
5302 case 9: port_id = port_channel_post_aux10_level; break;
5303 case 10: port_id = port_channel_post_aux11_level; break;
5304 case 11: port_id = port_channel_post_aux12_level; break;
5311 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5322 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5324 return boost::shared_ptr<AutomationControl>();
5326 return s->gain_control ();
5329 boost::shared_ptr<AutomationControl>
5330 Route::send_enable_controllable (uint32_t n) const
5333 # undef MIXBUS_PORTS_H
5334 # include "../../gtk2_ardour/mixbus_ports.h"
5335 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5337 uint32_t port_id = 0;
5339 case 0: port_id = port_channel_post_aux1_asgn; break;
5340 case 1: port_id = port_channel_post_aux2_asgn; break;
5341 case 2: port_id = port_channel_post_aux3_asgn; break;
5342 case 3: port_id = port_channel_post_aux4_asgn; break;
5343 case 4: port_id = port_channel_post_aux5_asgn; break;
5344 case 5: port_id = port_channel_post_aux6_asgn; break;
5345 case 6: port_id = port_channel_post_aux7_asgn; break;
5346 case 7: port_id = port_channel_post_aux8_asgn; break;
5348 case 8: port_id = port_channel_post_aux9_asgn; break;
5349 case 9: port_id = port_channel_post_aux10_asgn; break;
5350 case 10: port_id = port_channel_post_aux11_asgn; break;
5351 case 11: port_id = port_channel_post_aux12_asgn; break;
5358 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5369 /* although Ardour sends have enable/disable as part of the Processor
5370 * API, it is not exposed as a controllable.
5372 * XXX: we should fix this (make it click-free, automatable enable-control)
5374 return boost::shared_ptr<AutomationControl>();
5378 Route::send_name (uint32_t n) const
5383 return _session.get_mixbus (n)->name();
5388 return _session.get_mixbus (n)->name();
5393 boost::shared_ptr<Processor> p = nth_send (n);
5401 boost::shared_ptr<AutomationControl>
5402 Route::master_send_enable_controllable () const
5405 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5407 return boost::shared_ptr<AutomationControl>();
5409 # undef MIXBUS_PORTS_H
5410 # include "../../gtk2_ardour/mixbus_ports.h"
5411 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5413 return boost::shared_ptr<AutomationControl>();
5418 Route::slaved () const
5420 if (!_gain_control) {
5423 /* just test one particular control, not all of them */
5424 return _gain_control->slaved ();
5428 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5430 if (!vca || !_gain_control) {
5434 /* just test one particular control, not all of them */
5436 return _gain_control->slaved_to (vca->gain_control());
5440 Route::muted_by_others_soloing () const
5442 if (!can_be_muted_by_others ()) {
5446 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5450 Route::clear_all_solo_state ()
5452 _solo_control->clear_all_solo_state ();