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/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/disk_reader.h"
51 #include "ardour/disk_writer.h"
52 #include "ardour/event_type_map.h"
53 #include "ardour/gain_control.h"
54 #include "ardour/internal_return.h"
55 #include "ardour/internal_send.h"
56 #include "ardour/meter.h"
57 #include "ardour/delayline.h"
58 #include "ardour/midi_buffer.h"
59 #include "ardour/midi_port.h"
60 #include "ardour/monitor_control.h"
61 #include "ardour/monitor_processor.h"
62 #include "ardour/pannable.h"
63 #include "ardour/panner.h"
64 #include "ardour/panner_shell.h"
65 #include "ardour/parameter_descriptor.h"
66 #include "ardour/phase_control.h"
67 #include "ardour/plugin_insert.h"
68 #include "ardour/port.h"
69 #include "ardour/port_insert.h"
70 #include "ardour/processor.h"
71 #include "ardour/profile.h"
72 #include "ardour/route.h"
73 #include "ardour/route_group.h"
74 #include "ardour/send.h"
75 #include "ardour/session.h"
76 #include "ardour/solo_control.h"
77 #include "ardour/solo_isolate_control.h"
78 #include "ardour/types_convert.h"
79 #include "ardour/unknown_processor.h"
80 #include "ardour/utils.h"
81 #include "ardour/vca.h"
86 using namespace ARDOUR;
89 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
91 /** Base class for all routable/mixable objects (tracks and busses) */
92 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
93 : Stripable (sess, name, PresentationInfo (flag))
94 , GraphNode (sess._process_graph)
95 , Muteable (sess, name)
100 , _disk_io_point (DiskIOPreFader)
101 , _pending_process_reorder (0)
102 , _pending_signals (0)
103 , _pending_declick (true)
104 , _meter_point (MeterPostFader)
105 , _pending_meter_point (MeterPostFader)
106 , _meter_type (MeterPeak)
107 , _denormal_protection (false)
110 , _declickable (false)
111 , _have_internal_generator (false)
112 , _default_type (default_type)
114 , _in_configure_processors (false)
115 , _initial_io_setup (false)
116 , _in_sidechain_setup (false)
118 , _custom_meter_position_noted (false)
120 , _patch_selector_dialog (0)
122 processor_max_streams.reset();
125 boost::weak_ptr<Route>
126 Route::weakroute () {
127 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
133 /* set default meter type */
135 _meter_type = Config->get_meter_type_master ();
137 else if (dynamic_cast<Track*>(this)) {
138 _meter_type = Config->get_meter_type_track ();
140 _meter_type = Config->get_meter_type_bus ();
143 /* add standard controls */
145 _gain_control.reset (new GainControl (_session, GainAutomation));
146 _trim_control.reset (new GainControl (_session, TrimAutomation));
147 /* While the route has-a gain-control for consistency with Stripable and VCA
148 * ownership is handed over to the Amp Processor which manages the
149 * state of the Control and AutomationList as part of its
150 * Automatable API. -- Don't call add_control () here.
153 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
154 add_control (_solo_control);
155 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
157 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
158 add_control (_mute_control);
160 _phase_control.reset (new PhaseControl (_session, X_("phase")));
161 add_control (_phase_control);
163 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
164 add_control (_solo_isolate_control);
166 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
167 add_control (_solo_safe_control);
171 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
172 _pannable.reset (new Pannable (_session));
175 /* input and output objects */
177 _input.reset (new IO (_session, _name, IO::Input, _default_type));
178 _output.reset (new IO (_session, _name, IO::Output, _default_type));
180 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
181 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
183 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
184 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
186 /* add the amp/fader processor.
187 * it should be the first processor to be added on every route.
190 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
191 add_processor (_amp, PostFader);
194 _amp->set_display_name (_("Monitor"));
197 #if 0 // not used - just yet
198 if (!is_master() && !is_monitor() && !is_auditioner()) {
199 _delayline.reset (new DelayLine (_session, _name));
200 add_processor (_delayline, PreFader);
206 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
207 _trim->set_display_to_user (false);
209 if (dynamic_cast<AudioTrack*>(this)) {
210 /* we can't do this in the AudioTrack's constructor
211 * because _trim does not exit then
215 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
220 /* create standard processors: meter, main outs, monitor out;
221 they will be added to _processors by setup_invisible_processors ()
224 _meter.reset (new PeakMeter (_session, _name));
225 _meter->set_owner (this);
226 _meter->set_display_to_user (false);
229 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
230 _main_outs->activate ();
233 /* where we listen to tracks */
234 _intreturn.reset (new InternalReturn (_session));
235 _intreturn->activate ();
237 /* the thing that provides proper control over a control/monitor/listen bus
238 (such as per-channel cut, dim, solo, invert, etc).
240 _monitor_control.reset (new MonitorProcessor (_session));
241 _monitor_control->activate ();
244 /* now that we have _meter, its safe to connect to this */
247 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
248 configure_processors (0);
256 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
258 /* do this early so that we don't get incoming signals as we are going through destruction
263 /* don't use clear_processors here, as it depends on the session which may
264 be half-destroyed by now
267 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
269 (*i)->drop_references ();
272 _processors.clear ();
276 Route::ensure_track_or_route_name(string name, Session &session)
278 string newname = name;
280 while (!session.io_name_is_legal (newname)) {
281 newname = bump_name_once (newname, ' ');
288 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
290 // TODO route group, see set_gain()
291 // _trim_control->route_set_value (val);
295 Route::maybe_declick (BufferSet&, samplecnt_t, int)
297 /* this is the "bus" implementation and they never declick.
302 /** Process this route for one (sub) cycle (process thread)
304 * @param bufs Scratch buffers to use for the signal path
305 * @param start_sample Initial transport sample
306 * @param end_sample Final transport sample
307 * @param nframes Number of samples to output (to ports)
309 * Note that (end_sample - start_sample) may not be equal to nframes when the
310 * transport speed isn't 1.0 (eg varispeed).
313 Route::process_output_buffers (BufferSet& bufs,
314 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
315 int declick, bool gain_automation_ok)
317 /* Caller must hold process lock */
318 assert (!AudioEngine::instance()->process_lock().trylock());
320 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
322 // can this actually happen? functions calling process_output_buffers()
323 // already take a reader-lock.
324 bufs.silence (nframes, 0);
328 automation_run (start_sample, nframes);
330 /* figure out if we're going to use gain automation */
331 if (gain_automation_ok) {
332 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
333 _amp->setup_gain_automation (
334 start_sample + _amp->output_latency (),
335 end_sample + _amp->output_latency (),
338 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
339 _trim->setup_gain_automation (
340 start_sample + _trim->output_latency (),
341 end_sample + _trim->output_latency (),
345 /* Tell main outs what to do about monitoring. We do this so that
346 on a transition between monitoring states we get a de-clicking gain
347 change in the _main_outs delivery, if config.get_use_monitor_fades()
350 We override this in the case where we have an internal generator.
352 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
354 _main_outs->no_outs_cuz_we_no_monitor (silence);
356 /* -------------------------------------------------------------------------------------------
357 GLOBAL DECLICK (for transport changes etc.)
358 ----------------------------------------------------------------------------------------- */
360 maybe_declick (bufs, nframes, declick);
361 _pending_declick = 0;
363 /* -------------------------------------------------------------------------------------------
364 DENORMAL CONTROL/PHASE INVERT
365 ----------------------------------------------------------------------------------------- */
367 if (!_phase_control->none()) {
371 if (_denormal_protection || Config->get_denormal_protection()) {
373 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
374 Sample* const sp = i->data();
376 if (_phase_control->inverted (chn)) {
377 for (pframes_t nx = 0; nx < nframes; ++nx) {
382 for (pframes_t nx = 0; nx < nframes; ++nx) {
390 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
391 Sample* const sp = i->data();
393 if (_phase_control->inverted (chn)) {
394 for (pframes_t nx = 0; nx < nframes; ++nx) {
403 if (_denormal_protection || Config->get_denormal_protection()) {
405 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
406 Sample* const sp = i->data();
407 for (pframes_t nx = 0; nx < nframes; ++nx) {
415 /* -------------------------------------------------------------------------------------------
417 ----------------------------------------------------------------------------------------- */
419 /* set this to be true if the meter will already have been ::run() earlier */
420 bool const meter_already_run = metering_state() == MeteringInput;
422 samplecnt_t latency = 0;
423 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
425 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
427 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
428 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
433 /* if it has any inputs, make sure they match */
434 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
435 if (bufs.count() != (*i)->input_streams()) {
437 DEBUG::Processors, string_compose (
438 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
439 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
446 /* should we NOT run plugins here if the route is inactive?
447 do we catch route != active somewhere higher?
450 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
451 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
453 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
454 const samplecnt_t longest_session_latency = _initial_delay + _signal_latency;
455 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
456 _initial_delay + latency, longest_session_latency - latency);
459 //cerr << name() << " run " << (*i)->name() << endl;
460 (*i)->run (bufs, start_sample - latency, end_sample - latency, speed, nframes, *i != _processors.back());
461 bufs.set_count ((*i)->output_streams());
463 if ((*i)->active ()) {
464 latency += (*i)->signal_latency ();
470 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
471 boost::shared_ptr<Processor> endpoint,
472 bool include_endpoint, bool for_export, bool for_freeze)
474 /* If no processing is required, there's no need to go any further. */
475 if (!endpoint && !include_endpoint) {
479 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
480 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
481 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
483 /* trim is always at the top, for bounce no latency compensation is needed */
484 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
485 _trim->setup_gain_automation (start, start + nframes, nframes);
488 const double speed = _session.transport_speed ();
489 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
491 if (!include_endpoint && (*i) == endpoint) {
495 /* if we're *not* exporting, stop processing if we come across a routing processor. */
496 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
499 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
503 /* special case the panner (export outputs)
504 * Ideally we'd only run the panner, not the delivery itself...
505 * but panners need separate input/output buffers and some context
506 * (panshell, panner type, etc). AFAICT there is no ill side effect
507 * of re-using the main delivery when freewheeling/exporting a region.
509 if ((*i) == _main_outs) {
510 assert ((*i)->does_routing());
511 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
512 buffers.set_count ((*i)->output_streams());
515 /* don't run any processors that do routing.
516 * Also don't bother with metering.
518 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
519 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
520 buffers.set_count ((*i)->output_streams());
521 latency += (*i)->signal_latency ();
524 if ((*i) == endpoint) {
531 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
532 bool include_endpoint, bool for_export, bool for_freeze) const
534 samplecnt_t latency = 0;
535 if (!endpoint && !include_endpoint) {
539 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
540 if (!include_endpoint && (*i) == endpoint) {
543 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
546 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
549 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
550 latency += (*i)->signal_latency ();
552 if ((*i) == endpoint) {
560 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
561 bool include_endpoint, bool for_export, bool for_freeze) const
563 if (!endpoint && !include_endpoint) {
567 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
568 if (!include_endpoint && (*i) == endpoint) {
571 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
574 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
577 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
578 cc = (*i)->output_streams();
580 if ((*i) == endpoint) {
588 Route::n_process_buffers ()
590 return max (_input->n_ports(), processor_max_streams);
594 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
596 assert (is_monitor());
597 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
598 fill_buffers_with_input (bufs, _input, nframes);
599 passthru (bufs, start_sample, end_sample, nframes, declick, true);
603 Route::passthru (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok)
607 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
609 /* control/monitor bus ignores input ports when something is
610 feeding the listen "stream". data will "arrive" into the
611 route from the intreturn processor element.
614 bufs.silence (nframes, 0);
617 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
619 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
621 /* run processor chain */
623 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok);
627 Route::passthru_silence (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
629 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
631 bufs.set_count (_input->n_ports());
632 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
633 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, false);
637 Route::set_listen (bool yn)
640 if (_monitor_send->active() == yn) {
644 _monitor_send->activate ();
646 _monitor_send->deactivate ();
652 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
654 /* nothing to do if we're not using AFL/PFL. But if we are, we need
655 to alter the active state of the monitor send.
658 if (Config->get_solo_control_is_listen_control ()) {
659 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
664 Route::push_solo_isolate_upstream (int32_t delta)
666 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
668 boost::shared_ptr<RouteList> routes = _session.get_routes ();
669 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
671 if ((*i).get() == this || !(*i)->can_solo()) {
676 bool does_feed = feeds (*i, &sends_only);
678 if (does_feed && !sends_only) {
679 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
685 Route::push_solo_upstream (int delta)
687 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
688 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
692 boost::shared_ptr<Route> sr (i->r.lock());
694 sr->solo_control()->mod_solo_by_others_downstream (-delta);
701 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
703 cerr << name << " {" << endl;
704 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
705 p != procs.end(); ++p) {
706 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
712 /** Supposing that we want to insert a Processor at a given Placement, return
713 * the processor to add the new one before (or 0 to add at the end).
715 boost::shared_ptr<Processor>
716 Route::before_processor_for_placement (Placement p)
718 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
720 ProcessorList::iterator loc;
723 /* generic pre-fader: insert immediately before the amp */
724 loc = find (_processors.begin(), _processors.end(), _amp);
726 /* generic post-fader: insert right before the main outs */
727 loc = find (_processors.begin(), _processors.end(), _main_outs);
730 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
733 /** Supposing that we want to insert a Processor at a given index, return
734 * the processor to add the new one before (or 0 to add at the end).
736 boost::shared_ptr<Processor>
737 Route::before_processor_for_index (int index)
740 return boost::shared_ptr<Processor> ();
743 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
745 ProcessorList::iterator i = _processors.begin ();
747 while (i != _processors.end() && j < index) {
748 if ((*i)->display_to_user()) {
755 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
758 /** Add a processor either pre- or post-fader
759 * @return 0 on success, non-0 on failure.
762 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
764 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
768 /** Add a processor to a route such that it ends up with a given index into the visible processors.
769 * @param index Index to add the processor at, or -1 to add at the end of the list.
770 * @return 0 on success, non-0 on failure.
773 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
775 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
778 /** Add a processor to the route.
779 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
780 * @return 0 on success, non-0 on failure.
783 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
785 assert (processor != _meter);
786 assert (processor != _main_outs);
788 DEBUG_TRACE (DEBUG::Processors, string_compose (
789 "%1 adding processor %2\n", name(), processor->name()));
793 pl.push_back (processor);
794 int rv = add_processors (pl, before, err);
800 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
801 processor->activate ();
808 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
810 /* We cannot destruct the processor here (usually RT-thread
811 * with various locks held - in case of sends also io_locks).
812 * Queue for deletion in low-priority thread.
814 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
815 selfdestruct_sequence.push_back (wp);
819 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
821 XMLProperty const * prop;
824 boost::shared_ptr<Processor> processor;
826 /* bit of a hack: get the `placement' property from the <Redirect> tag here
827 so that we can add the processor in the right place (pre/post-fader)
830 XMLNodeList const & children = node.children ();
831 XMLNodeList::const_iterator i = children.begin ();
833 while (i != children.end() && (*i)->name() != X_("Redirect")) {
837 Placement placement = PreFader;
839 if (i != children.end()) {
840 if ((prop = (*i)->property (X_("placement"))) != 0) {
841 placement = Placement (string_2_enum (prop->value(), placement));
845 if (node.name() == "Insert") {
847 if ((prop = node.property ("type")) != 0) {
849 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
850 prop->value() == "lv2" ||
851 prop->value() == "windows-vst" ||
852 prop->value() == "mac-vst" ||
853 prop->value() == "lxvst" ||
854 prop->value() == "audiounit") {
856 if (_session.get_disable_all_loaded_plugins ()) {
857 processor.reset (new UnknownProcessor (_session, node));
859 processor.reset (new PluginInsert (_session));
860 processor->set_owner (this);
865 processor.reset (new PortInsert (_session, _pannable, _mute_master));
870 } else if (node.name() == "Send") {
872 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
873 processor.reset (new Send (_session, sendpan, _mute_master));
877 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
881 if (processor->set_state (node, version)) {
885 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
886 if (i != children.end()) {
887 if ((prop = (*i)->property (X_("active"))) != 0) {
888 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
889 processor->activate();
891 processor->deactivate();
895 return (add_processor (processor, placement, 0, false) == 0);
898 catch (failed_constructor &err) {
899 warning << _("processor could not be created. Ignored.") << endmsg;
905 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
906 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
909 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
910 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
914 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
916 ProcessorList::iterator loc;
917 boost::shared_ptr <PluginInsert> fanout;
919 if (g_atomic_int_get (&_pending_process_reorder)) {
920 /* we need to flush any pending re-order changes */
921 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
922 apply_processor_changes_rt ();
926 loc = find(_processors.begin(), _processors.end(), before);
927 if (loc == _processors.end ()) {
931 /* nothing specified - at end */
932 loc = _processors.end ();
935 if (others.empty()) {
939 ProcessorList to_skip;
941 // check if there's an instrument to replace or configure
942 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
943 boost::shared_ptr<PluginInsert> pi;
944 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
947 if (!pi->plugin ()->get_info ()->is_instrument ()) {
950 boost::shared_ptr<Processor> instrument = the_instrument ();
951 ChanCount in (DataType::MIDI, 1);
952 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
954 PluginSetupOptions flags = None;
957 in = instrument->input_streams ();
958 out = instrument->output_streams ();
960 if (pi->has_output_presets (in, out)) {
964 pi->set_strict_io (_strict_io);
966 PluginSetupOptions mask = None;
967 if (Config->get_ask_replace_instrument ()) {
970 if (Config->get_ask_setup_instrument ()) {
977 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
978 int mode = rv.get_value_or (0);
981 to_skip.push_back (*i); // don't add this one;
984 replace_processor (instrument, *i, err);
985 to_skip.push_back (*i);
990 if ((mode & 5) == 4) {
997 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
998 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
999 ProcessorState pstate (this);
1001 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1006 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1007 if (check != to_skip.end()) {
1011 boost::shared_ptr<PluginInsert> pi;
1013 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1014 pi->set_strict_io (_strict_io);
1018 /* Ensure that only one amp is in the list at any time */
1019 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1020 if (check != _processors.end()) {
1021 if (before == _amp) {
1022 /* Already in position; all is well */
1025 _processors.erase (check);
1030 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1032 _processors.insert (loc, *i);
1033 (*i)->set_owner (this);
1036 if (configure_processors_unlocked (err, &lm)) {
1038 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1043 if (pi && pi->has_sidechain ()) {
1044 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1047 if ((*i)->active()) {
1048 // emit ActiveChanged() and latency_changed() if needed
1052 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1054 boost::shared_ptr<Send> send;
1055 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1056 send->SelfDestruct.connect_same_thread (*this,
1057 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1061 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1062 boost::shared_ptr<PluginInsert> pi;
1064 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1065 if (pi->has_no_inputs ()) {
1066 _have_internal_generator = true;
1072 _output->set_user_latency (0);
1075 reset_instrument_info ();
1076 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1077 set_processor_positions ();
1079 if (fanout && fanout->configured ()
1080 && fanout->output_streams().n_audio() > 2
1081 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1082 fan_out (); /* EMIT SIGNAL */
1088 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1090 if (p == PreFader) {
1091 start = _processors.begin();
1092 end = find(_processors.begin(), _processors.end(), _amp);
1094 start = find(_processors.begin(), _processors.end(), _amp);
1096 end = _processors.end();
1100 /** Turn off all processors with a given placement
1101 * @param p Placement of processors to disable
1104 Route::disable_processors (Placement p)
1106 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1108 ProcessorList::iterator start, end;
1109 placement_range(p, start, end);
1111 for (ProcessorList::iterator i = start; i != end; ++i) {
1112 (*i)->enable (false);
1115 _session.set_dirty ();
1118 /** Turn off all redirects
1121 Route::disable_processors ()
1123 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1125 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1126 (*i)->enable (false);
1129 _session.set_dirty ();
1132 /** Turn off all redirects with a given placement
1133 * @param p Placement of redirects to disable
1136 Route::disable_plugins (Placement p)
1138 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1140 ProcessorList::iterator start, end;
1141 placement_range(p, start, end);
1143 for (ProcessorList::iterator i = start; i != end; ++i) {
1144 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1145 (*i)->enable (false);
1149 _session.set_dirty ();
1152 /** Turn off all plugins
1155 Route::disable_plugins ()
1157 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1159 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1160 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1161 (*i)->enable (false);
1165 _session.set_dirty ();
1170 Route::ab_plugins (bool forward)
1172 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1176 /* forward = turn off all active redirects, and mark them so that the next time
1177 we go the other way, we will revert them
1180 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1181 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1184 if (!(*i)->display_to_user ()) {
1188 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1193 if ((*i)->enabled ()) {
1194 (*i)->enable (false);
1195 (*i)->set_next_ab_is_active (true);
1197 (*i)->set_next_ab_is_active (false);
1203 /* backward = if the redirect was marked to go active on the next ab, do so */
1205 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1206 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1209 if (!(*i)->display_to_user ()) {
1213 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1218 (*i)->enable ((*i)->get_next_ab_is_active ());
1222 _session.set_dirty ();
1226 /** Remove processors with a given placement.
1227 * @param p Placement of processors to remove.
1230 Route::clear_processors (Placement p)
1232 if (!_session.engine().connected()) {
1236 bool already_deleting = _session.deletion_in_progress();
1237 if (!already_deleting) {
1238 _session.set_deletion_in_progress();
1241 ProcessorList old_list = _processors;
1243 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1244 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1245 ProcessorList new_list;
1246 ProcessorStreams err;
1247 bool seen_amp = false;
1249 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1255 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1257 /* you can't remove these */
1259 new_list.push_back (*i);
1266 new_list.push_back (*i);
1269 (*i)->drop_references ();
1277 (*i)->drop_references ();
1280 new_list.push_back (*i);
1287 _processors = new_list;
1288 configure_processors_unlocked (&err, &lm); // this can't fail
1290 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1293 processor_max_streams.reset();
1294 _have_internal_generator = false;
1295 reset_instrument_info ();
1296 set_processor_positions ();
1298 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1300 if (!already_deleting) {
1301 _session.clear_deletion_in_progress();
1306 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1308 // TODO once the export point can be configured properly, do something smarter here
1309 if (processor == _capturing_processor) {
1310 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1311 if (need_process_lock) {
1315 _capturing_processor.reset();
1317 if (need_process_lock) {
1322 /* these can never be removed */
1324 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1328 if (!_session.engine().connected()) {
1332 processor_max_streams.reset();
1335 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1336 if (need_process_lock) {
1340 /* Caller must hold process lock */
1341 assert (!AudioEngine::instance()->process_lock().trylock());
1343 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1345 ProcessorState pstate (this);
1347 ProcessorList::iterator i;
1348 bool removed = false;
1350 for (i = _processors.begin(); i != _processors.end(); ) {
1351 if (*i == processor) {
1353 /* move along, see failure case for configure_processors()
1354 where we may need to reconfigure the processor.
1357 /* stop redirects that send signals to JACK ports
1358 from causing noise as a result of no longer being
1362 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1363 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1367 iop = pi->sidechain();
1374 i = _processors.erase (i);
1382 _output->set_user_latency (0);
1390 if (configure_processors_unlocked (err, &lm)) {
1392 /* we know this will work, because it worked before :) */
1393 configure_processors_unlocked (0, &lm);
1397 _have_internal_generator = false;
1399 for (i = _processors.begin(); i != _processors.end(); ++i) {
1400 boost::shared_ptr<PluginInsert> pi;
1402 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1403 if (pi->has_no_inputs ()) {
1404 _have_internal_generator = true;
1409 if (need_process_lock) {
1414 reset_instrument_info ();
1415 processor->drop_references ();
1416 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1417 set_processor_positions ();
1423 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1425 /* these can never be removed */
1426 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1429 /* and can't be used as substitute, either */
1430 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1434 /* I/Os are out, too */
1435 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1439 /* this function cannot be used to swap/reorder processors */
1440 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1444 if (!AudioEngine::instance()->connected() || !old || !sub) {
1448 /* ensure that sub is not owned by another route */
1449 if (sub->owner ()) {
1454 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1455 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1456 ProcessorState pstate (this);
1458 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1460 ProcessorList::iterator i;
1461 bool replaced = false;
1462 bool enable = old->enabled ();
1464 for (i = _processors.begin(); i != _processors.end(); ) {
1466 i = _processors.erase (i);
1467 _processors.insert (i, sub);
1468 sub->set_owner (this);
1481 boost::shared_ptr<PluginInsert> pi;
1482 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1483 pi->set_strict_io (true);
1487 if (configure_processors_unlocked (err, &lm)) {
1489 configure_processors_unlocked (0, &lm);
1493 _have_internal_generator = false;
1495 for (i = _processors.begin(); i != _processors.end(); ++i) {
1496 boost::shared_ptr<PluginInsert> pi;
1497 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1498 if (pi->has_no_inputs ()) {
1499 _have_internal_generator = true;
1509 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1510 _output->set_user_latency (0);
1513 reset_instrument_info ();
1514 old->drop_references ();
1515 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1516 set_processor_positions ();
1521 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1523 ProcessorList deleted;
1525 if (!_session.engine().connected()) {
1529 processor_max_streams.reset();
1532 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1533 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1534 ProcessorState pstate (this);
1536 ProcessorList::iterator i;
1537 boost::shared_ptr<Processor> processor;
1539 for (i = _processors.begin(); i != _processors.end(); ) {
1543 /* these can never be removed */
1545 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1550 /* see if its in the list of processors to delete */
1552 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1557 /* stop IOProcessors that send to JACK ports
1558 from causing noise as a result of no longer being
1562 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1563 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1566 iop = pi->sidechain();
1573 deleted.push_back (processor);
1574 i = _processors.erase (i);
1577 if (deleted.empty()) {
1578 /* none of those in the requested list were found */
1582 _output->set_user_latency (0);
1584 if (configure_processors_unlocked (err, &lm)) {
1586 /* we know this will work, because it worked before :) */
1587 configure_processors_unlocked (0, &lm);
1592 _have_internal_generator = false;
1594 for (i = _processors.begin(); i != _processors.end(); ++i) {
1595 boost::shared_ptr<PluginInsert> pi;
1597 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1598 if (pi->has_no_inputs ()) {
1599 _have_internal_generator = true;
1606 /* now try to do what we need to so that those that were removed will be deleted */
1608 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1609 (*i)->drop_references ();
1612 reset_instrument_info ();
1613 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1614 set_processor_positions ();
1620 Route::reset_instrument_info ()
1622 boost::shared_ptr<Processor> instr = the_instrument();
1624 _instrument_info.set_internal_instrument (instr);
1628 /** Caller must hold process lock */
1630 Route::configure_processors (ProcessorStreams* err)
1632 #ifndef PLATFORM_WINDOWS
1633 assert (!AudioEngine::instance()->process_lock().trylock());
1636 if (!_in_configure_processors) {
1637 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1638 return configure_processors_unlocked (err, &lm);
1645 Route::input_streams () const
1647 return _input->n_ports ();
1650 list<pair<ChanCount, ChanCount> >
1651 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1653 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1655 return try_configure_processors_unlocked (in, err);
1658 list<pair<ChanCount, ChanCount> >
1659 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1661 // Check each processor in order to see if we can configure as requested
1663 list<pair<ChanCount, ChanCount> > configuration;
1666 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1667 DEBUG_TRACE (DEBUG::Processors, "{\n");
1669 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1671 if ((*p)->can_support_io_configuration(in, out)) {
1673 if (boost::dynamic_pointer_cast<Delivery> (*p)
1674 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1676 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1677 /* with strict I/O the panner + output are forced to
1678 * follow the last processor's output.
1680 * Delivery::can_support_io_configuration() will only add ports,
1681 * but not remove excess ports.
1683 * This works because the delivery only requires
1684 * as many outputs as there are inputs.
1685 * Delivery::configure_io() will do the actual removal
1686 * by calling _output->ensure_io()
1688 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1689 /* ..but at least as many as there are master-inputs, if
1690 * the delivery is dealing with audio */
1691 // XXX this may need special-casing for mixbus (master-outputs)
1692 // and should maybe be a preference anyway ?!
1693 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1699 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1700 configuration.push_back(make_pair(in, out));
1703 // restriction for Monitor Section Processors
1704 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1705 /* Note: The Monitor follows the master-bus and has no panner.
1707 * The general idea is to only allow plugins that retain the channel-count
1708 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1709 * Then again 5.1 in, monitor stereo is a valid use-case.
1711 * and worse: we only refuse adding plugins *here*.
1713 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1714 * 2) change master-bus, add a channel
1715 * 2a) monitor-secion follows
1716 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1717 * 4) re-load session, monitor-processor remains unconfigured, crash.
1719 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1721 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1722 // internal sends make no sense, only feedback
1723 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1724 return list<pair<ChanCount, ChanCount> > ();
1726 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1727 /* External Sends can be problematic. one can add/remove ports
1728 * there signal leaves the DAW to external monitors anyway, so there's
1729 * no real use for allowing them here anyway.
1731 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1732 return list<pair<ChanCount, ChanCount> > ();
1734 if (boost::dynamic_pointer_cast<Send> (*p)) {
1736 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1737 return list<pair<ChanCount, ChanCount> > ();
1746 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1747 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1748 DEBUG_TRACE (DEBUG::Processors, "}\n");
1749 return list<pair<ChanCount, ChanCount> > ();
1753 DEBUG_TRACE (DEBUG::Processors, "}\n");
1755 return configuration;
1758 /** Set the input/output configuration of each processor in the processors list.
1759 * Caller must hold process lock.
1760 * Return 0 on success, otherwise configuration is impossible.
1763 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1765 #ifndef PLATFORM_WINDOWS
1766 assert (!AudioEngine::instance()->process_lock().trylock());
1769 if (_in_configure_processors) {
1773 /* put invisible processors where they should be */
1774 setup_invisible_processors ();
1776 _in_configure_processors = true;
1778 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1780 if (configuration.empty ()) {
1781 _in_configure_processors = false;
1786 bool seen_mains_out = false;
1787 processor_out_streams = _input->n_ports();
1788 processor_max_streams.reset();
1790 /* processor configure_io() may result in adding ports
1791 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1793 * with jack2 adding ports results in a graph-order callback,
1794 * which calls Session::resort_routes() and eventually
1795 * Route::direct_feeds_according_to_reality()
1796 * which takes a ReaderLock (_processor_lock).
1798 * so we can't hold a WriterLock here until jack2 threading
1801 * NB. we still hold the process lock
1803 * (ardour's own engines do call graph-order from the
1804 * process-thread and hence do not have this issue; besides
1805 * merely adding ports won't trigger a graph-order, only
1806 * making connections does)
1810 // TODO check for a potential ReaderLock after ReaderLock ??
1811 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1813 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1814 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1816 if (!(*p)->configure_io(c->first, c->second)) {
1817 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1818 _in_configure_processors = false;
1824 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1825 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1827 boost::shared_ptr<IOProcessor> iop;
1828 boost::shared_ptr<PluginInsert> pi;
1829 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1830 /* plugins connected via Split or Hide Match may have more channels.
1831 * route/scratch buffers are needed for all of them
1832 * The configuration may only be a subset (both input and output)
1834 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1836 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1837 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1838 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1842 if (boost::dynamic_pointer_cast<Delivery> (*p)
1843 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1844 /* main delivery will increase port count to match input.
1845 * the Delivery::Main is usually the last processor - followed only by
1848 seen_mains_out = true;
1850 if (!seen_mains_out) {
1851 processor_out_streams = out;
1860 _meter->set_max_channels (processor_max_streams);
1863 /* make sure we have sufficient scratch buffers to cope with the new processor
1866 _session.ensure_buffers (n_process_buffers ());
1868 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1870 _in_configure_processors = false;
1874 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1875 * @param state New active state for those processors.
1878 Route::all_visible_processors_active (bool state)
1880 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1882 if (_processors.empty()) {
1886 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1887 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1891 boost::shared_ptr<PluginInsert> pi;
1892 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1893 if (pi->is_channelstrip ()) {
1898 (*i)->enable (state);
1901 _session.set_dirty ();
1905 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1907 /* check if re-order requires re-configuration of any processors
1908 * -> compare channel configuration for all processors
1910 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1911 ChanCount c = input_streams ();
1913 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1915 if (c != (*j)->input_streams()) {
1918 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1921 if ((*i)->input_streams() != c) {
1924 c = (*i)->output_streams();
1936 __attribute__((annotate("realtime")))
1939 Route::apply_processor_order (const ProcessorList& new_order)
1941 /* need to hold processor_lock; either read or write lock
1942 * and the engine process_lock.
1943 * Due to r/w lock ambiguity we can only assert the latter
1945 assert (!AudioEngine::instance()->process_lock().trylock());
1948 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1949 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1950 * processors in the current actual processor list that are hidden. Any visible processors
1951 * in the current list but not in "new_order" will be assumed to be deleted.
1954 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1955 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1956 * (note though that ::processors_reorder_needs_configure() ensured that
1957 * this function will only ever be called from the rt-thread if no processor were removed)
1959 * either way, I can't proove it, but an x-run due to re-order here is less likley
1960 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1963 ProcessorList as_it_will_be;
1964 ProcessorList::iterator oiter;
1965 ProcessorList::const_iterator niter;
1967 oiter = _processors.begin();
1968 niter = new_order.begin();
1970 while (niter != new_order.end()) {
1972 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1973 then append it to the temp list.
1975 Otherwise, see if the next processor in the old list is in the new list. if not,
1976 its been deleted. If its there, append it to the temp list.
1979 if (oiter == _processors.end()) {
1981 /* no more elements in the old list, so just stick the rest of
1982 the new order onto the temp list.
1985 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1986 while (niter != new_order.end()) {
1993 if (!(*oiter)->display_to_user()) {
1995 as_it_will_be.push_back (*oiter);
1999 /* visible processor: check that its in the new order */
2001 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2002 /* deleted: do nothing, shared_ptr<> will clean up */
2004 /* ignore this one, and add the next item from the new order instead */
2005 as_it_will_be.push_back (*niter);
2010 /* now remove from old order - its taken care of no matter what */
2011 oiter = _processors.erase (oiter);
2015 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2017 /* If the meter is in a custom position, find it and make a rough note of its position */
2018 maybe_note_meter_position ();
2022 Route::move_instrument_down (bool postfader)
2024 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2025 ProcessorList new_order;
2026 boost::shared_ptr<Processor> instrument;
2027 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2028 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2029 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2031 } else if (instrument && *i == _amp) {
2033 new_order.push_back (*i);
2034 new_order.push_back (instrument);
2036 new_order.push_back (instrument);
2037 new_order.push_back (*i);
2040 new_order.push_back (*i);
2047 reorder_processors (new_order, 0);
2051 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2053 // it a change is already queued, wait for it
2054 // (unless engine is stopped. apply immediately and proceed
2055 while (g_atomic_int_get (&_pending_process_reorder)) {
2056 if (!AudioEngine::instance()->running()) {
2057 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2058 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2060 apply_processor_order(_pending_processor_order);
2061 setup_invisible_processors ();
2063 g_atomic_int_set (&_pending_process_reorder, 0);
2065 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2066 set_processor_positions ();
2068 // TODO rather use a semaphore or something.
2069 // but since ::reorder_processors() is called
2070 // from the GUI thread, this is fine..
2075 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2077 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2078 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2079 ProcessorState pstate (this);
2081 apply_processor_order (new_order);
2083 if (configure_processors_unlocked (err, &lm)) {
2091 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2092 set_processor_positions ();
2095 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2096 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2098 // _pending_processor_order is protected by _processor_lock
2099 _pending_processor_order = new_order;
2100 g_atomic_int_set (&_pending_process_reorder, 1);
2103 /* update processor input/output latency
2104 * (total signal_latency does not change)
2106 update_signal_latency (true);
2112 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2114 boost::shared_ptr<PluginInsert> pi;
2115 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2119 if (pi->has_sidechain () == add) {
2120 return true; // ?? call failed, but result is as expected.
2124 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2125 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2126 if (i == _processors.end ()) {
2132 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2133 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2134 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2136 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2138 if (!pi->add_sidechain ()) {
2142 if (!pi->del_sidechain ()) {
2148 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2153 pi->del_sidechain ();
2155 pi->add_sidechain ();
2156 // TODO restore side-chain's state.
2161 configure_processors_unlocked (0, &lm);
2164 if (pi->has_sidechain ()) {
2165 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2168 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2169 _session.set_dirty ();
2174 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2176 boost::shared_ptr<PluginInsert> pi;
2177 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2182 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2183 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2184 if (i == _processors.end ()) {
2190 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2191 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2193 const ChanCount& old (pi->preset_out ());
2194 if (!pi->set_preset_out (outs)) {
2195 return true; // no change, OK
2198 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2201 pi->set_preset_out (old);
2204 configure_processors_unlocked (0, &lm);
2207 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2208 _session.set_dirty ();
2213 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2216 return customize_plugin_insert (proc, 0, unused, unused);
2220 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2222 boost::shared_ptr<PluginInsert> pi;
2223 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2228 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2229 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2230 if (i == _processors.end ()) {
2236 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2237 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2239 bool old_cust = pi->custom_cfg ();
2240 uint32_t old_cnt = pi->get_count ();
2241 ChanCount old_chan = pi->output_streams ();
2242 ChanCount old_sinks = pi->natural_input_streams ();
2245 pi->set_custom_cfg (false);
2247 pi->set_custom_cfg (true);
2248 pi->set_count (count);
2249 pi->set_outputs (outs);
2250 pi->set_sinks (sinks);
2253 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2257 pi->set_count (old_cnt);
2258 pi->set_sinks (old_sinks);
2259 pi->set_outputs (old_chan);
2260 pi->set_custom_cfg (old_cust);
2264 configure_processors_unlocked (0, &lm);
2267 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2268 _session.set_dirty ();
2273 Route::set_strict_io (const bool enable)
2275 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2277 if (_strict_io != enable) {
2278 _strict_io = enable;
2279 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2280 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2281 boost::shared_ptr<PluginInsert> pi;
2282 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2283 pi->set_strict_io (_strict_io);
2287 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2291 _strict_io = !enable; // restore old value
2292 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2293 boost::shared_ptr<PluginInsert> pi;
2294 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2295 pi->set_strict_io (_strict_io);
2302 configure_processors (0);
2305 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2306 _session.set_dirty ();
2318 Route::get_template()
2320 return state(false);
2324 Route::state(bool full_state)
2326 if (!_session._template_state_dir.empty()) {
2327 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2330 XMLNode *node = new XMLNode("Route");
2331 ProcessorList::iterator i;
2333 node->set_property (X_("id"), id ());
2334 node->set_property (X_("name"), name());
2335 node->set_property (X_("default-type"), _default_type);
2336 node->set_property (X_("strict-io"), _strict_io);
2338 node->add_child_nocopy (_presentation_info.get_state());
2340 node->set_property (X_("active"), _active);
2341 node->set_property (X_("denormal-protection"), _denormal_protection);
2342 node->set_property (X_("meter-point"), _meter_point);
2343 node->set_property (X_("disk-io-point"), _disk_io_point);
2345 node->set_property (X_("meter-type"), _meter_type);
2348 node->set_property (X_("route-group"), _route_group->name());
2351 node->add_child_nocopy (_solo_control->get_state ());
2352 node->add_child_nocopy (_solo_isolate_control->get_state ());
2353 node->add_child_nocopy (_solo_safe_control->get_state ());
2355 node->add_child_nocopy (_input->state (full_state));
2356 node->add_child_nocopy (_output->state (full_state));
2357 node->add_child_nocopy (_mute_master->get_state ());
2359 node->add_child_nocopy (_mute_control->get_state ());
2360 node->add_child_nocopy (_phase_control->get_state ());
2363 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2366 if (_comment.length()) {
2367 XMLNode *cmt = node->add_child ("Comment");
2368 cmt->add_content (_comment);
2372 node->add_child_nocopy (_pannable->state (full_state));
2376 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2377 for (i = _processors.begin(); i != _processors.end(); ++i) {
2379 /* template save: do not include internal sends functioning as
2380 aux sends because the chance of the target ID
2381 in the session where this template is used
2384 similarly, do not save listen sends which connect to
2385 the monitor section, because these will always be
2388 boost::shared_ptr<InternalSend> is;
2390 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2391 if (is->role() == Delivery::Listen) {
2396 node->add_child_nocopy((*i)->state (full_state));
2401 node->add_child_copy (*_extra_xml);
2404 if (_custom_meter_position_noted) {
2405 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2407 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2411 if (!_session._template_state_dir.empty()) {
2412 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2415 node->add_child_copy (Slavable::get_state());
2421 Route::set_state (const XMLNode& node, int version)
2423 if (version < 3000) {
2424 return set_state_2X (node, version);
2428 XMLNodeConstIterator niter;
2431 if (node.name() != "Route"){
2432 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2436 std::string route_name;
2437 if (node.get_property (X_("name"), route_name)) {
2438 Route::set_name (route_name);
2442 _initial_io_setup = true;
2444 Stripable::set_state (node, version);
2446 node.get_property (X_("strict-io"), _strict_io);
2449 /* monitor bus does not get a panner, but if (re)created
2450 via XML, it will already have one by the time we
2451 call ::set_state(). so ... remove it.
2456 /* add all processors (except amp, which is always present) */
2458 nlist = node.children();
2459 XMLNode processor_state (X_("processor_state"));
2461 Stateful::save_extra_xml (node);
2463 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2467 if (child->name() == IO::state_node_name) {
2468 std::string direction;
2469 if (!child->get_property (X_("direction"), direction)) {
2473 if (direction == "Input") {
2474 _input->set_state (*child, version);
2475 } else if (direction == "Output") {
2476 _output->set_state (*child, version);
2479 } else if (child->name() == X_("Processor")) {
2480 processor_state.add_child_copy (*child);
2481 } else if (child->name() == X_("Pannable")) {
2483 _pannable->set_state (*child, version);
2485 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2487 } else if (child->name() == Slavable::xml_node_name) {
2488 Slavable::set_state (*child, version);
2493 if (node.get_property (X_("meter-point"), mp)) {
2494 set_meter_point (mp, true);
2496 _meter->set_display_to_user (_meter_point == MeterCustom);
2501 if (node.get_property (X_("disk-io-point"), diop)) {
2503 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2506 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2508 set_disk_io_point (diop);
2511 node.get_property (X_("meter-type"), _meter_type);
2513 _initial_io_setup = false;
2515 set_processor_state (processor_state);
2517 // this looks up the internal instrument in processors
2518 reset_instrument_info();
2520 bool denormal_protection;
2521 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2522 set_denormal_protection (denormal_protection);
2525 /* convert old 3001 state */
2526 std::string phase_invert_str;
2527 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2528 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2532 if (node.get_property (X_("active"), is_active)) {
2533 set_active (is_active, this);
2536 std::string id_string;
2537 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2538 PBD::ID id (id_string);
2539 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2540 ProcessorList::const_iterator i = _processors.begin ();
2541 while (i != _processors.end() && (*i)->id() != id) {
2545 if (i != _processors.end ()) {
2546 _processor_after_last_custom_meter = *i;
2547 _custom_meter_position_noted = true;
2551 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2554 if (child->name() == X_("Comment")) {
2556 /* XXX this is a terrible API design in libxml++ */
2558 XMLNode *cmt = *(child->children().begin());
2559 _comment = cmt->content();
2561 } else if (child->name() == Controllable::xml_node_name) {
2562 std::string control_name;
2563 if (!child->get_property (X_("name"), control_name)) {
2567 if (control_name == _solo_control->name()) {
2568 _solo_control->set_state (*child, version);
2569 } else if (control_name == _solo_safe_control->name()) {
2570 _solo_safe_control->set_state (*child, version);
2571 } else if (control_name == _solo_isolate_control->name()) {
2572 _solo_isolate_control->set_state (*child, version);
2573 } else if (control_name == _mute_control->name()) {
2574 _mute_control->set_state (*child, version);
2575 } else if (control_name == _phase_control->name()) {
2576 _phase_control->set_state (*child, version);
2578 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2579 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2580 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2582 ac->set_state (*child, version);
2586 } else if (child->name() == MuteMaster::xml_node_name) {
2587 _mute_master->set_state (*child, version);
2589 } else if (child->name() == Automatable::xml_node_name) {
2590 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2598 Route::set_state_2X (const XMLNode& node, int version)
2602 XMLNodeConstIterator niter;
2604 XMLProperty const * prop;
2606 /* 2X things which still remain to be handled:
2612 if (node.name() != "Route") {
2613 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2617 Stripable::set_state (node, version);
2619 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2620 set_denormal_protection (string_to<bool> (prop->value()));
2623 if ((prop = node.property (X_("muted"))) != 0) {
2626 bool muted = string_to<bool> (prop->value());
2632 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2634 if (string_to<bool> (prop->value())){
2635 mute_point = mute_point + "PreFader";
2640 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2642 if (string_to<bool> (prop->value())){
2645 mute_point = mute_point + ",";
2648 mute_point = mute_point + "PostFader";
2653 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2655 if (string_to<bool> (prop->value())){
2658 mute_point = mute_point + ",";
2661 mute_point = mute_point + "Listen";
2666 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2668 if (string_to<bool> (prop->value())){
2671 mute_point = mute_point + ",";
2674 mute_point = mute_point + "Main";
2678 _mute_master->set_mute_points (mute_point);
2679 _mute_master->set_muted_by_self (true);
2683 if ((prop = node.property (X_("meter-point"))) != 0) {
2684 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2689 nlist = node.children ();
2690 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2694 if (child->name() == IO::state_node_name) {
2696 /* there is a note in IO::set_state_2X() about why we have to call
2700 _input->set_state_2X (*child, version, true);
2701 _output->set_state_2X (*child, version, false);
2703 if ((prop = child->property (X_("name"))) != 0) {
2704 Route::set_name (prop->value ());
2709 if ((prop = child->property (X_("active"))) != 0) {
2710 bool yn = string_to<bool> (prop->value());
2711 _active = !yn; // force switch
2712 set_active (yn, this);
2715 if ((prop = child->property (X_("gain"))) != 0) {
2718 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2719 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2723 /* Set up Panners in the IO */
2724 XMLNodeList io_nlist = child->children ();
2726 XMLNodeConstIterator io_niter;
2729 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2731 io_child = *io_niter;
2733 if (io_child->name() == X_("Panner")) {
2734 _main_outs->panner_shell()->set_state(*io_child, version);
2735 } else if (io_child->name() == X_("Automation")) {
2736 /* IO's automation is for the fader */
2737 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2743 XMLNodeList redirect_nodes;
2745 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2749 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2750 redirect_nodes.push_back(child);
2755 set_processor_state_2X (redirect_nodes, version);
2757 Stateful::save_extra_xml (node);
2759 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2762 if (child->name() == X_("Comment")) {
2764 /* XXX this is a terrible API design in libxml++ */
2766 XMLNode *cmt = *(child->children().begin());
2767 _comment = cmt->content();
2769 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2770 if (prop->value() == X_("solo")) {
2771 _solo_control->set_state (*child, version);
2772 } else if (prop->value() == X_("mute")) {
2773 _mute_control->set_state (*child, version);
2783 Route::get_processor_state ()
2785 XMLNode* root = new XMLNode (X_("redirects"));
2786 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2787 root->add_child_nocopy ((*i)->state (true));
2794 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2796 /* We don't bother removing existing processors not in nList, as this
2797 method will only be called when creating a Route from scratch, not
2798 for undo purposes. Just put processors in at the appropriate place
2802 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2803 add_processor_from_xml_2X (**i, version);
2808 Route::set_processor_state (const XMLNode& node)
2810 const XMLNodeList &nlist = node.children();
2811 XMLNodeConstIterator niter;
2812 ProcessorList new_order;
2813 bool must_configure = false;
2815 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2817 XMLProperty* prop = (*niter)->property ("type");
2819 if (prop->value() == "amp") {
2820 _amp->set_state (**niter, Stateful::current_state_version);
2821 new_order.push_back (_amp);
2822 } else if (prop->value() == "trim") {
2823 _trim->set_state (**niter, Stateful::current_state_version);
2824 new_order.push_back (_trim);
2825 } else if (prop->value() == "meter") {
2826 _meter->set_state (**niter, Stateful::current_state_version);
2827 new_order.push_back (_meter);
2828 } else if (prop->value() == "delay") {
2830 _delayline->set_state (**niter, Stateful::current_state_version);
2831 new_order.push_back (_delayline);
2833 } else if (prop->value() == "main-outs") {
2834 _main_outs->set_state (**niter, Stateful::current_state_version);
2835 } else if (prop->value() == "intreturn") {
2837 _intreturn.reset (new InternalReturn (_session));
2838 must_configure = true;
2840 _intreturn->set_state (**niter, Stateful::current_state_version);
2841 } else if (is_monitor() && prop->value() == "monitor") {
2842 if (!_monitor_control) {
2843 _monitor_control.reset (new MonitorProcessor (_session));
2844 must_configure = true;
2846 _monitor_control->set_state (**niter, Stateful::current_state_version);
2847 } else if (prop->value() == "capture") {
2848 /* CapturingProcessor should never be restored, it's always
2849 added explicitly when needed */
2850 } else if (prop->value() == "diskreader" && _disk_reader) {
2851 _disk_reader->set_state (**niter, Stateful::current_state_version);
2852 new_order.push_back (_disk_reader);
2853 } else if (prop->value() == "diskwriter" && _disk_writer) {
2854 _disk_writer->set_state (**niter, Stateful::current_state_version);
2855 new_order.push_back (_disk_writer);
2857 set_processor_state (**niter, prop, new_order, must_configure);
2861 ProcessorList old_list = _processors; // keep a copy
2863 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2864 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2865 /* re-assign _processors w/o process-lock.
2866 * if there's an IO-processor present in _processors but
2867 * not in new_order, it will be deleted and ~IO takes
2870 _processors = new_order;
2872 if (must_configure) {
2873 configure_processors_unlocked (0, &lm);
2876 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2878 (*i)->set_owner (this);
2879 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2881 boost::shared_ptr<PluginInsert> pi;
2883 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2884 if (pi->has_no_inputs ()) {
2885 _have_internal_generator = true;
2891 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2894 reset_instrument_info ();
2895 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2896 set_processor_positions ();
2900 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2902 ProcessorList::iterator o;
2904 for (o = _processors.begin(); o != _processors.end(); ++o) {
2905 XMLProperty const * id_prop = node.property(X_("id"));
2906 if (id_prop && (*o)->id() == id_prop->value()) {
2907 (*o)->set_state (node, Stateful::current_state_version);
2908 new_order.push_back (*o);
2913 // If the processor (node) is not on the route then create it
2915 if (o == _processors.end()) {
2917 boost::shared_ptr<Processor> processor;
2919 if (prop->value() == "intsend") {
2921 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2923 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2924 prop->value() == "lv2" ||
2925 prop->value() == "windows-vst" ||
2926 prop->value() == "mac-vst" ||
2927 prop->value() == "lxvst" ||
2928 prop->value() == "luaproc" ||
2929 prop->value() == "audiounit") {
2931 if (_session.get_disable_all_loaded_plugins ()) {
2932 processor.reset (new UnknownProcessor (_session, node));
2934 processor.reset (new PluginInsert (_session));
2935 processor->set_owner (this);
2937 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2938 pi->set_strict_io (true);
2942 } else if (prop->value() == "port") {
2944 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2946 } else if (prop->value() == "send") {
2948 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2949 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2950 send->SelfDestruct.connect_same_thread (*this,
2951 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2957 if (processor->set_state (node, Stateful::current_state_version) != 0) {
2958 /* This processor could not be configured. Turn it into a UnknownProcessor */
2959 processor.reset (new UnknownProcessor (_session, node));
2962 /* subscribe to Sidechain IO changes */
2963 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2964 if (pi && pi->has_sidechain ()) {
2965 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2968 /* we have to note the monitor send here, otherwise a new one will be created
2969 and the state of this one will be lost.
2971 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2972 if (isend && isend->role() == Delivery::Listen) {
2973 _monitor_send = isend;
2976 /* it doesn't matter if invisible processors are added here, as they
2977 will be sorted out by setup_invisible_processors () shortly.
2980 new_order.push_back (processor);
2981 must_configure = true;
2987 Route::curve_reallocate ()
2989 // _gain_automation_curve.finish_resize ();
2990 // _pan_automation_curve.finish_resize ();
2994 Route::silence (samplecnt_t nframes)
2996 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3001 silence_unlocked (nframes);
3005 Route::silence_unlocked (samplecnt_t nframes)
3007 /* Must be called with the processor lock held */
3009 const samplepos_t now = _session.transport_sample ();
3013 _output->silence (nframes);
3015 // update owned automated controllables
3016 automation_run (now, nframes);
3018 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3019 boost::shared_ptr<PluginInsert> pi;
3021 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3022 /* evaluate automated automation controls */
3023 pi->automation_run (now, nframes);
3024 /* skip plugins, they don't need anything when we're not active */
3028 (*i)->silence (nframes, now);
3031 if (nframes == _session.get_block_size()) {
3038 Route::add_internal_return ()
3041 _intreturn.reset (new InternalReturn (_session));
3042 add_processor (_intreturn, PreFader);
3047 Route::add_send_to_internal_return (InternalSend* send)
3049 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3051 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3052 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3055 return d->add_send (send);
3061 Route::remove_send_from_internal_return (InternalSend* send)
3063 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3065 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3066 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3069 return d->remove_send (send);
3075 Route::enable_monitor_send ()
3077 /* Caller must hold process lock */
3078 assert (!AudioEngine::instance()->process_lock().trylock());
3080 /* master never sends to monitor section via the normal mechanism */
3081 assert (!is_master ());
3082 assert (!is_monitor ());
3084 /* make sure we have one */
3085 if (!_monitor_send) {
3086 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3087 _monitor_send->set_display_to_user (false);
3091 configure_processors (0);
3094 /** Add an aux send to a route.
3095 * @param route route to send to.
3096 * @param before Processor to insert before, or 0 to insert at the end.
3099 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3101 assert (route != _session.monitor_out ());
3104 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3106 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3108 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3110 if (d && d->target_route() == route) {
3111 /* already listening via the specified IO: do nothing */
3119 boost::shared_ptr<InternalSend> listener;
3122 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3123 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3126 add_processor (listener, before);
3128 } catch (failed_constructor& err) {
3136 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3138 ProcessorStreams err;
3139 ProcessorList::iterator tmp;
3142 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3144 /* have to do this early because otherwise processor reconfig
3145 * will put _monitor_send back in the list
3148 if (route == _session.monitor_out()) {
3149 _monitor_send.reset ();
3153 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3155 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3157 if (d && d->target_route() == route) {
3159 if (remove_processor (*x, &err, false) > 0) {
3165 /* list could have been demolished while we dropped the lock
3168 if (_session.engine().connected()) {
3169 /* i/o processors cannot be removed if the engine is not running
3170 * so don't live-loop in case the engine is N/A or dies
3180 Route::set_comment (string cmt, void *src)
3184 _session.set_dirty ();
3188 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3190 FeedRecord fr (other, via_sends_only);
3192 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3194 if (!result.second) {
3196 /* already a record for "other" - make sure sends-only information is correct */
3197 if (!via_sends_only && result.first->sends_only) {
3198 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3199 frp->sends_only = false;
3203 return result.second;
3207 Route::clear_fed_by ()
3213 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3215 const FedBy& fed_by (other->fed_by());
3217 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3218 boost::shared_ptr<Route> sr = f->r.lock();
3220 if (sr && (sr.get() == this)) {
3222 if (via_sends_only) {
3223 *via_sends_only = f->sends_only;
3234 Route::all_inputs () const
3236 /* TODO, if this works as expected,
3237 * cache the IOVector and maintain it via
3238 * input_change_handler(), sidechain_change_handler() etc
3241 ios.push_back (_input);
3243 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3244 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3246 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3247 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3250 iop = pi->sidechain();
3253 if (iop != 0 && iop->input()) {
3254 ios.push_back (iop->input());
3261 Route::all_outputs () const
3264 // _output is included via Delivery
3265 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3266 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3267 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3268 if (iop != 0 && iop->output()) {
3269 ios.push_back (iop->output());
3276 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3278 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3279 if (other->all_inputs().fed_by (_output)) {
3280 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3281 if (via_send_only) {
3282 *via_send_only = false;
3288 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3290 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3292 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3293 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3296 iop = pi->sidechain();
3300 boost::shared_ptr<const IO> iop_out = iop->output();
3301 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3302 // TODO this needs a delaylines in the Insert to align connections (!)
3303 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3306 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3307 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3308 if (via_send_only) {
3309 *via_send_only = true;
3313 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3316 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3321 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3326 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3328 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3332 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3334 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3337 /** Called from the (non-realtime) butler thread when the transport is stopped */
3339 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3342 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3344 Automatable::non_realtime_transport_stop (now, flush);
3346 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3348 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3352 (*i)->non_realtime_transport_stop (now, flush);
3356 _roll_delay = _initial_delay;
3360 Route::input_change_handler (IOChange change, void * /*src*/)
3362 if ((change.type & IOChange::ConfigurationChanged)) {
3363 /* This is called with the process lock held if change
3364 contains ConfigurationChanged
3366 configure_processors (0);
3367 _phase_control->resize (_input->n_ports().n_audio ());
3368 io_changed (); /* EMIT SIGNAL */
3371 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3374 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3375 if (_input->connected()) {
3376 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3377 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3381 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3382 if (does_feed && !sends_only) {
3383 if ((*i)->soloed()) {
3386 if ((*i)->solo_isolate_control()->solo_isolated()) {
3393 int delta = sbou - _solo_control->soloed_by_others_upstream();
3394 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3397 PBD::warning << string_compose (
3398 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3399 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3404 if (_solo_control->soloed_by_others_upstream()) {
3405 // ignore new connections (they're not propagated)
3407 _solo_control->mod_solo_by_others_upstream (delta);
3411 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3412 // solo-isolate currently only propagates downstream
3414 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3416 //_solo_isolated_by_upstream = ibou;
3419 // Session::route_solo_changed does not propagate indirect solo-changes
3420 // propagate downstream to tracks
3421 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3422 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3426 bool does_feed = feeds (*i, &sends_only);
3427 if (delta <= 0 && does_feed && !sends_only) {
3428 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3431 if (idelta < 0 && does_feed && !sends_only) {
3432 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3439 Route::output_change_handler (IOChange change, void * /*src*/)
3441 if (_initial_io_setup) {
3445 if ((change.type & IOChange::ConfigurationChanged)) {
3446 /* This is called with the process lock held if change
3447 contains ConfigurationChanged
3449 configure_processors (0);
3452 _session.reset_monitor_section();
3455 io_changed (); /* EMIT SIGNAL */
3458 if ((change.type & IOChange::ConnectionsChanged)) {
3460 /* do this ONLY if connections have changed. Configuration
3461 * changes do not, by themselves alter solo upstream or
3462 * downstream status.
3465 if (_solo_control->soloed_by_others_downstream()) {
3467 /* checking all all downstream routes for
3468 * explicit of implict solo is a rather drastic measure,
3469 * ideally the input_change_handler() of the other route
3470 * would propagate the change to us.
3472 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3473 if (_output->connected()) {
3474 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3475 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3479 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3480 if (does_feed && !sends_only) {
3481 if ((*i)->soloed()) {
3489 int delta = sbod - _solo_control->soloed_by_others_downstream();
3491 // do not allow new connections to change implicit solo (no propagation)
3492 _solo_control->mod_solo_by_others_downstream (delta);
3493 // Session::route_solo_changed() does not propagate indirect solo-changes
3494 // propagate upstream to tracks
3495 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3496 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3497 if ((*i).get() == this || !can_solo()) {
3501 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3502 if (delta != 0 && does_feed && !sends_only) {
3503 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3513 Route::sidechain_change_handler (IOChange change, void* src)
3515 if (_initial_io_setup || _in_sidechain_setup) {
3519 input_change_handler (change, src);
3523 Route::pans_required () const
3525 if (n_outputs().n_audio() < 2) {
3529 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3533 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3535 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3536 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3538 d->flush_buffers (nframes);
3540 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3542 p->flush_buffers (nframes);
3549 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3551 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3558 silence_unlocked (nframes);
3562 if (session_state_changing) {
3563 if (_session.transport_speed() != 0.0f) {
3564 /* we're rolling but some state is changing (e.g. our diskstream contents)
3565 so we cannot use them. Be silent till this is over.
3567 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3569 silence_unlocked (nframes);
3572 /* we're really not rolling, so we're either delivery silence or actually
3573 monitoring, both of which are safe to do while session_state_changing is true.
3577 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3579 fill_buffers_with_input (bufs, _input, nframes);
3581 if (_meter_point == MeterInput) {
3582 _meter->run (bufs, start_sample, end_sample, 0.0, nframes, true);
3585 passthru (bufs, start_sample, end_sample, nframes, 0, true);
3587 flush_processor_buffers_locked (nframes);
3593 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3595 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3602 silence_unlocked (nframes);
3603 if (_meter_point == MeterInput && ((_monitoring_control->monitoring_choice() & MonitorInput) || (!_disk_writer || _disk_writer->record_enabled()))) {
3611 BufferSet& bufs = _session.get_route_buffers (n_process_buffers ());
3613 fill_buffers_with_input (bufs, _input, nframes);
3615 /* filter captured data before meter sees it */
3616 filter_input (bufs);
3618 if (_meter_point == MeterInput &&
3619 ((_monitoring_control->monitoring_choice() & MonitorInput) || (_disk_writer && _disk_writer->record_enabled()))) {
3620 _meter->run (bufs, start_sample, end_sample, 1.0 /*speed()*/, nframes, true);
3623 passthru (bufs, start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling());
3625 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3629 flush_processor_buffers_locked (nframes);
3635 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3638 flush_processor_buffers_locked (nframes);
3643 Route::flush_processors ()
3645 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3647 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3653 __attribute__((annotate("realtime")))
3656 Route::apply_processor_changes_rt ()
3658 int emissions = EmitNone;
3660 if (_pending_meter_point != _meter_point) {
3661 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3663 /* meters always have buffers for 'processor_max_streams'
3664 * they can be re-positioned without re-allocation */
3665 if (set_meter_point_unlocked()) {
3666 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3668 emissions |= EmitMeterChanged;
3673 bool changed = false;
3675 if (g_atomic_int_get (&_pending_process_reorder)) {
3676 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3678 apply_processor_order (_pending_processor_order);
3679 setup_invisible_processors ();
3681 g_atomic_int_set (&_pending_process_reorder, 0);
3682 emissions |= EmitRtProcessorChange;
3686 set_processor_positions ();
3687 /* update processor input/output latency
3688 * (total signal_latency does not change)
3690 update_signal_latency (true);
3692 if (emissions != 0) {
3693 g_atomic_int_set (&_pending_signals, emissions);
3696 return (!selfdestruct_sequence.empty ());
3700 Route::emit_pending_signals ()
3702 int sig = g_atomic_int_and (&_pending_signals, 0);
3703 if (sig & EmitMeterChanged) {
3704 _meter->emit_configuration_changed();
3705 meter_change (); /* EMIT SIGNAL */
3706 if (sig & EmitMeterVisibilityChange) {
3707 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3709 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3712 if (sig & EmitRtProcessorChange) {
3713 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3716 /* this would be a job for the butler.
3717 * Conceptually we should not take processe/processor locks here.
3718 * OTOH its more efficient (less overhead for summoning the butler and
3719 * telling her what do do) and signal emission is called
3720 * directly after the process callback, which decreases the chance
3721 * of x-runs when taking the locks.
3723 while (!selfdestruct_sequence.empty ()) {
3724 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3725 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3726 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3727 selfdestruct_sequence.pop_back ();
3730 remove_processor (proc);
3736 Route::set_meter_point (MeterPoint p, bool force)
3738 if (_pending_meter_point == p && !force) {
3742 if (force || !AudioEngine::instance()->running()) {
3743 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3744 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3745 _pending_meter_point = p;
3746 _meter->emit_configuration_changed();
3747 meter_change (); /* EMIT SIGNAL */
3748 if (set_meter_point_unlocked()) {
3749 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3751 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3754 _pending_meter_point = p;
3760 __attribute__((annotate("realtime")))
3763 Route::set_meter_point_unlocked ()
3766 /* Caller must hold process and processor write lock */
3767 assert (!AudioEngine::instance()->process_lock().trylock());
3768 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3769 assert (!lm.locked ());
3772 _meter_point = _pending_meter_point;
3774 bool meter_was_visible_to_user = _meter->display_to_user ();
3776 if (!_custom_meter_position_noted) {
3777 maybe_note_meter_position ();
3780 if (_meter_point != MeterCustom) {
3782 _meter->set_display_to_user (false);
3784 setup_invisible_processors ();
3787 _meter->set_display_to_user (true);
3789 /* If we have a previous position for the custom meter, try to put it there */
3790 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3792 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3793 if (i != _processors.end ()) {
3794 _processors.remove (_meter);
3795 _processors.insert (i, _meter);
3797 } else {// at end, right before the mains_out/panner
3798 _processors.remove (_meter);
3799 ProcessorList::iterator main = _processors.end();
3800 _processors.insert (--main, _meter);
3804 /* Set up the meter for its new position */
3806 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3810 if (loc == _processors.begin()) {
3811 m_in = _input->n_ports();
3813 ProcessorList::iterator before = loc;
3815 m_in = (*before)->output_streams ();
3818 _meter->reflect_inputs (m_in);
3820 /* we do not need to reconfigure the processors, because the meter
3821 (a) is always ready to handle processor_max_streams
3822 (b) is always an N-in/N-out processor, and thus moving
3823 it doesn't require any changes to the other processors.
3826 /* these should really be done after releasing the lock
3827 * but all those signals are subscribed to with gui_thread()
3830 return (_meter->display_to_user() != meter_was_visible_to_user);
3834 Route::listen_position_changed ()
3837 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3838 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3839 ProcessorState pstate (this);
3841 if (configure_processors_unlocked (0, &lm)) {
3842 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3844 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3849 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3850 _session.set_dirty ();
3853 boost::shared_ptr<CapturingProcessor>
3854 Route::add_export_point()
3856 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3857 if (!_capturing_processor) {
3859 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3860 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3862 // this aligns all tracks; but not tracks + busses
3863 samplecnt_t latency = _session.worst_track_roll_delay ();
3864 assert (latency >= _initial_delay);
3865 _capturing_processor.reset (new CapturingProcessor (_session, latency - _initial_delay));
3866 _capturing_processor->activate ();
3868 configure_processors_unlocked (0, &lw);
3872 return _capturing_processor;
3876 Route::update_signal_latency (bool set_initial_delay)
3878 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3880 samplecnt_t l_in = _input->latency ();
3881 samplecnt_t l_out = _output->user_latency();
3883 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3884 if ((*i)->active ()) {
3885 l_in += (*i)->signal_latency ();
3887 (*i)->set_input_latency (l_in);
3890 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
3891 (*i)->set_output_latency (l_out);
3892 if ((*i)->active ()) {
3893 l_out += (*i)->signal_latency ();
3897 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
3899 _signal_latency = l_out;
3903 if (set_initial_delay) {
3904 /* see also Session::post_playback_latency() */
3905 set_latency_compensation (_session.worst_track_latency () + _session.worst_track_out_latency () - output ()->latency ());
3908 if (_signal_latency != l_out) {
3909 signal_latency_changed (); /* EMIT SIGNAL */
3912 return _signal_latency;
3916 Route::set_user_latency (samplecnt_t nframes)
3918 _output->set_user_latency (nframes);
3919 _session.update_latency_compensation ();
3923 Route::set_latency_compensation (samplecnt_t longest_session_latency)
3925 samplecnt_t old = _initial_delay;
3926 assert (!_disk_reader || _disk_reader->output_latency () <= _signal_latency);
3928 if (_disk_reader && _disk_reader->output_latency () < longest_session_latency) {
3929 _initial_delay = longest_session_latency - _disk_reader->output_latency ();
3934 DEBUG_TRACE (DEBUG::Latency, string_compose (
3935 "%1: compensate for maximum latency of %2,"
3936 "given own latency of %3, using initial delay of %4\n",
3937 name(), longest_session_latency, _signal_latency, _initial_delay));
3939 if (_initial_delay != old) {
3940 initial_delay_changed (); /* EMIT SIGNAL */
3943 if (_session.transport_stopped()) {
3944 _roll_delay = _initial_delay;
3949 Route::set_block_size (pframes_t nframes)
3951 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3952 (*i)->set_block_size (nframes);
3955 _session.ensure_buffers (n_process_buffers ());
3959 Route::protect_automation ()
3961 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3962 (*i)->protect_automation();
3965 /** @param declick 1 to set a pending declick fade-in,
3966 * -1 to set a pending declick fade-out
3969 Route::set_pending_declick (int declick)
3972 /* this call is not allowed to turn off a pending declick */
3974 _pending_declick = declick;
3977 _pending_declick = 0;
3981 /** Shift automation forwards from a particular place, thereby inserting time.
3982 * Adds undo commands for any shifts that are performed.
3984 * @param pos Position to start shifting from.
3985 * @param samples Amount to shift forwards by.
3989 Route::shift (samplepos_t pos, samplecnt_t samples)
3991 /* gain automation */
3993 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3995 XMLNode &before = gc->alist()->get_state ();
3996 gc->alist()->shift (pos, samples);
3997 XMLNode &after = gc->alist()->get_state ();
3998 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4001 /* gain automation */
4003 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4005 XMLNode &before = gc->alist()->get_state ();
4006 gc->alist()->shift (pos, samples);
4007 XMLNode &after = gc->alist()->get_state ();
4008 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4011 // TODO mute automation ??
4013 /* pan automation */
4015 ControlSet::Controls& c (_pannable->controls());
4017 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4018 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4020 boost::shared_ptr<AutomationList> al = pc->alist();
4021 XMLNode& before = al->get_state ();
4022 al->shift (pos, samples);
4023 XMLNode& after = al->get_state ();
4024 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4029 /* redirect automation */
4031 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4032 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4034 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4036 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4037 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4039 boost::shared_ptr<AutomationList> al = ac->alist();
4040 XMLNode &before = al->get_state ();
4041 al->shift (pos, samples);
4042 XMLNode &after = al->get_state ();
4043 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4051 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4053 boost::shared_ptr<Processor> processor (p.lock ());
4054 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4058 pi->set_state_dir (d);
4062 Route::save_as_template (const string& path, const string& name, const string& description)
4064 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4065 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4067 XMLNode& node (state (false));
4068 node.set_property (X_("name"), name);
4070 node.remove_nodes (X_("description"));
4071 if (!description.empty()) {
4072 XMLNode* desc = new XMLNode(X_("description"));
4073 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4074 desc->add_child_nocopy (*desc_cont);
4076 node.add_child_nocopy (*desc);
4081 IO::set_name_in_state (*node.children().front(), name);
4083 tree.set_root (&node);
4085 /* return zero on success, non-zero otherwise */
4086 return !tree.write (path.c_str());
4091 Route::set_name (const string& str)
4097 if (str == name()) {
4101 string name = Route::ensure_track_or_route_name (str, _session);
4102 SessionObject::set_name (name);
4104 bool ret = (_input->set_name(name) && _output->set_name(name));
4107 /* rename the main outs. Leave other IO processors
4108 * with whatever name they already have, because its
4109 * just fine as it is (it will not contain the route
4110 * name if its a port insert, port send or port return).
4114 if (_main_outs->set_name (name)) {
4115 /* XXX returning false here is stupid because
4116 we already changed the route name.
4126 /** Set the name of a route in an XML description.
4127 * @param node XML <Route> node to set the name in.
4128 * @param name New name.
4131 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4133 node.set_property (X_("name"), name);
4135 XMLNodeList children = node.children();
4136 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4138 if ((*i)->name() == X_("IO")) {
4140 IO::set_name_in_state (**i, name);
4142 } else if ((*i)->name() == X_("Processor")) {
4145 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4146 (*i)->set_property (X_("name"), name);
4149 } else if ((*i)->name() == X_("Diskstream")) {
4151 if (rename_playlist) {
4152 (*i)->set_property (X_("playlist"), name + ".1");
4154 (*i)->set_property (X_("name"), name);
4160 boost::shared_ptr<Send>
4161 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4163 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4165 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4166 boost::shared_ptr<InternalSend> send;
4168 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4169 if (send->target_route() == target) {
4175 return boost::shared_ptr<Send>();
4179 Route::set_denormal_protection (bool yn)
4181 if (_denormal_protection != yn) {
4182 _denormal_protection = yn;
4183 denormal_protection_changed (); /* EMIT SIGNAL */
4188 Route::denormal_protection () const
4190 return _denormal_protection;
4194 Route::set_active (bool yn, void* src)
4196 if (_session.transport_rolling()) {
4200 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4201 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4205 if (_active != yn) {
4207 _input->set_active (yn);
4208 _output->set_active (yn);
4209 flush_processors ();
4210 active_changed (); // EMIT SIGNAL
4211 _session.set_dirty ();
4215 boost::shared_ptr<Pannable>
4216 Route::pannable() const
4221 boost::shared_ptr<Panner>
4222 Route::panner() const
4225 return _main_outs->panner_shell()->panner();
4228 boost::shared_ptr<PannerShell>
4229 Route::panner_shell() const
4231 return _main_outs->panner_shell();
4234 boost::shared_ptr<GainControl>
4235 Route::gain_control() const
4237 return _gain_control;
4240 boost::shared_ptr<GainControl>
4241 Route::trim_control() const
4243 return _trim_control;
4246 boost::shared_ptr<PhaseControl>
4247 Route::phase_control() const
4249 return _phase_control;
4252 boost::shared_ptr<AutomationControl>
4253 Route::get_control (const Evoral::Parameter& param)
4255 /* either we own the control or .... */
4257 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4261 /* maybe one of our processors does or ... */
4263 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4264 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4265 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4273 /* nobody does so we'll make a new one */
4275 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4282 boost::shared_ptr<Processor>
4283 Route::nth_plugin (uint32_t n) const
4285 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4286 ProcessorList::const_iterator i;
4288 for (i = _processors.begin(); i != _processors.end(); ++i) {
4289 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4296 return boost::shared_ptr<Processor> ();
4299 boost::shared_ptr<Processor>
4300 Route::nth_send (uint32_t n) const
4302 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4303 ProcessorList::const_iterator i;
4305 for (i = _processors.begin(); i != _processors.end(); ++i) {
4306 if (boost::dynamic_pointer_cast<Send> (*i)) {
4308 if ((*i)->name().find (_("Monitor")) == 0) {
4309 /* send to monitor section is not considered
4310 to be an accessible send.
4321 return boost::shared_ptr<Processor> ();
4325 Route::has_io_processor_named (const string& name)
4327 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4328 ProcessorList::iterator i;
4330 for (i = _processors.begin(); i != _processors.end(); ++i) {
4331 if (boost::dynamic_pointer_cast<Send> (*i) ||
4332 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4333 if ((*i)->name() == name) {
4343 Route::set_processor_positions ()
4345 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4347 bool had_amp = false;
4348 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4349 (*i)->set_pre_fader (!had_amp);
4356 /** Called when there is a proposed change to the input port count */
4358 Route::input_port_count_changing (ChanCount to)
4360 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4362 /* The processors cannot be configured with the new input arrangement, so
4368 /* The change is ok */
4372 /** Called when there is a proposed change to the output port count */
4374 Route::output_port_count_changing (ChanCount to)
4376 if (_strict_io && !_in_configure_processors) {
4379 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4380 if (processor_out_streams.get(*t) > to.get(*t)) {
4384 /* The change is ok */
4389 Route::unknown_processors () const
4393 if (_session.get_disable_all_loaded_plugins ()) {
4394 // Do not list "missing plugins" if they are explicitly disabled
4398 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4399 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4400 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4401 p.push_back ((*i)->name ());
4410 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4412 /* we assume that all our input ports feed all our output ports. its not
4413 universally true, but the alternative is way too corner-case to worry about.
4416 LatencyRange all_connections;
4419 all_connections.min = 0;
4420 all_connections.max = 0;
4422 all_connections.min = ~((pframes_t) 0);
4423 all_connections.max = 0;
4425 /* iterate over all "from" ports and determine the latency range for all of their
4426 connections to the "outside" (outside of this Route).
4429 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4433 p->get_connected_latency_range (range, playback);
4435 all_connections.min = min (all_connections.min, range.min);
4436 all_connections.max = max (all_connections.max, range.max);
4440 /* set the "from" port latencies to the max/min range of all their connections */
4442 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4443 p->set_private_latency_range (all_connections, playback);
4446 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4448 all_connections.min += our_latency;
4449 all_connections.max += our_latency;
4451 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4452 p->set_private_latency_range (all_connections, playback);
4455 return all_connections.max;
4459 Route::set_private_port_latencies (bool playback) const
4461 samplecnt_t own_latency = 0;
4463 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4464 OR LATENCY CALLBACK.
4466 This is called (early) from the latency callback. It computes the REAL
4467 latency associated with each port and stores the result as the "private"
4468 latency of the port. A later call to Route::set_public_port_latencies()
4469 sets all ports to the same value to reflect the fact that we do latency
4470 compensation and so all signals are delayed by the same amount as they
4471 flow through ardour.
4474 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4475 if ((*i)->active ()) {
4476 own_latency += (*i)->signal_latency ();
4481 /* playback: propagate latency from "outside the route" to outputs to inputs */
4482 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4484 /* capture: propagate latency from "outside the route" to inputs to outputs */
4485 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4490 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4492 /* this is called to set the JACK-visible port latencies, which take
4493 latency compensation into account.
4502 const PortSet& ports (_input->ports());
4503 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4504 p->set_public_latency_range (range, playback);
4509 const PortSet& ports (_output->ports());
4510 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4511 p->set_public_latency_range (range, playback);
4516 /** Put the invisible processors in the right place in _processors.
4517 * Must be called with a writer lock on _processor_lock held.
4520 __attribute__((annotate("realtime")))
4523 Route::setup_invisible_processors ()
4526 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4527 assert (!lm.locked ());
4531 /* too early to be doing this stuff */
4535 /* we'll build this new list here and then use it
4537 * TODO put the ProcessorList is on the stack for RT-safety.
4540 ProcessorList new_processors;
4541 ProcessorList::iterator dr;
4542 ProcessorList::iterator dw;
4544 /* find visible processors */
4546 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4547 if ((*i)->display_to_user ()) {
4548 new_processors.push_back (*i);
4554 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4556 if (amp == new_processors.end ()) {
4557 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4558 new_processors.push_front (_amp);
4559 amp = find (new_processors.begin(), new_processors.end(), _amp);
4562 /* and the processor after the amp */
4564 ProcessorList::iterator after_amp = amp;
4570 switch (_meter_point) {
4572 assert (!_meter->display_to_user ());
4573 new_processors.push_front (_meter);
4576 assert (!_meter->display_to_user ());
4577 new_processors.insert (amp, _meter);
4579 case MeterPostFader:
4580 /* do nothing here */
4583 /* do nothing here */
4586 /* the meter is visible, so we don't touch it here */
4593 assert (_main_outs);
4594 assert (!_main_outs->display_to_user ());
4595 new_processors.push_back (_main_outs);
4597 /* iterator for the main outs */
4599 ProcessorList::iterator main = new_processors.end();
4602 /* OUTPUT METERING */
4604 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4605 assert (!_meter->display_to_user ());
4607 /* add the processor just before or just after the main outs */
4609 ProcessorList::iterator meter_point = main;
4611 if (_meter_point == MeterOutput) {
4614 new_processors.insert (meter_point, _meter);
4619 if (_monitor_send && !is_monitor ()) {
4620 assert (!_monitor_send->display_to_user ());
4621 switch (Config->get_listen_position ()) {
4622 case PreFaderListen:
4623 switch (Config->get_pfl_position ()) {
4624 case PFLFromBeforeProcessors:
4625 new_processors.push_front (_monitor_send);
4627 case PFLFromAfterProcessors:
4628 new_processors.insert (amp, _monitor_send);
4631 _monitor_send->set_can_pan (false);
4633 case AfterFaderListen:
4634 switch (Config->get_afl_position ()) {
4635 case AFLFromBeforeProcessors:
4636 new_processors.insert (after_amp, _monitor_send);
4638 case AFLFromAfterProcessors:
4639 new_processors.insert (new_processors.end(), _monitor_send);
4642 _monitor_send->set_can_pan (true);
4647 #if 0 // not used - just yet
4648 if (!is_master() && !is_monitor() && !is_auditioner()) {
4649 new_processors.push_front (_delayline);
4653 /* MONITOR CONTROL */
4655 if (_monitor_control && is_monitor ()) {
4656 assert (!_monitor_control->display_to_user ());
4657 new_processors.insert (amp, _monitor_control);
4662 ProcessorList::iterator trim = new_processors.end();
4664 if (_trim->active()) {
4665 assert (!_trim->display_to_user ());
4666 new_processors.push_front (_trim);
4667 trim = new_processors.begin();
4670 /* INTERNAL RETURN */
4672 /* doing this here means that any monitor control will come after
4673 the return and trim.
4677 assert (!_intreturn->display_to_user ());
4678 new_processors.push_front (_intreturn);
4681 /* EXPORT PROCESSOR */
4683 /* DISK READER & WRITER (for Track objects) */
4685 if (_disk_reader || _disk_writer) {
4686 switch (_disk_io_point) {
4687 case DiskIOPreFader:
4688 if (trim != new_processors.end()) {
4689 /* insert BEFORE TRIM */
4691 new_processors.insert (trim, _disk_writer);
4694 new_processors.insert (trim, _disk_reader);
4698 new_processors.push_front (_disk_writer);
4701 new_processors.push_front (_disk_reader);
4705 case DiskIOPostFader:
4706 /* insert BEFORE main outs */
4708 new_processors.insert (main, _disk_writer);
4711 new_processors.insert (main, _disk_reader);
4715 /* reader and writer are visible under this condition, so they
4716 * are not invisible and thus not handled here.
4722 if (_capturing_processor) {
4723 assert (!_capturing_processor->display_to_user ());
4724 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4725 if (reader_pos != new_processors.end()) {
4726 /* insert after disk-reader */
4727 new_processors.insert (++reader_pos, _capturing_processor);
4729 new_processors.push_front (_capturing_processor);
4734 _processors = new_processors;
4736 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4737 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4738 (*i)->enable (true);
4742 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4743 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4744 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4751 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4752 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4756 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4757 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4764 /** If the meter point is `Custom', make a note of where the meter is.
4765 * This is so that if the meter point is subsequently set to something else,
4766 * and then back to custom, we can put the meter back where it was last time
4767 * custom was enabled.
4769 * Must be called with the _processor_lock held.
4772 Route::maybe_note_meter_position ()
4774 if (_meter_point != MeterCustom) {
4778 _custom_meter_position_noted = true;
4779 /* custom meter points range from after trim to before panner/main_outs
4780 * this is a limitation by the current processor UI
4782 bool seen_trim = false;
4783 _processor_after_last_custom_meter.reset();
4784 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4785 if ((*i) == _trim) {
4788 if ((*i) == _main_outs) {
4789 _processor_after_last_custom_meter = *i;
4792 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4794 _processor_after_last_custom_meter = _trim;
4796 ProcessorList::iterator j = i;
4798 assert(j != _processors.end ()); // main_outs should be before
4799 _processor_after_last_custom_meter = *j;
4804 assert(_processor_after_last_custom_meter.lock());
4807 boost::shared_ptr<Processor>
4808 Route::processor_by_id (PBD::ID id) const
4810 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4811 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4812 if ((*i)->id() == id) {
4817 return boost::shared_ptr<Processor> ();
4820 /** @return what we should be metering; either the data coming from the input
4821 * IO or the data that is flowing through the route.
4824 Route::metering_state () const
4826 return MeteringRoute;
4830 Route::has_external_redirects () const
4832 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4834 /* ignore inactive processors and obviously ignore the main
4835 * outs since everything has them and we don't care.
4838 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4846 boost::shared_ptr<Processor>
4847 Route::the_instrument () const
4849 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4850 return the_instrument_unlocked ();
4853 boost::shared_ptr<Processor>
4854 Route::the_instrument_unlocked () const
4856 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4857 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4858 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4862 return boost::shared_ptr<Processor>();
4868 Route::non_realtime_locate (samplepos_t pos)
4870 Automatable::non_realtime_locate (pos);
4873 _pannable->non_realtime_locate (pos);
4876 if (_delayline.get()) {
4877 _delayline.get()->flush();
4881 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4882 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4884 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4885 (*i)->non_realtime_locate (pos);
4888 _roll_delay = _initial_delay;
4892 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4899 * We don't currently mix MIDI input together, so we don't need the
4900 * complex logic of the audio case.
4903 n_buffers = bufs.count().n_midi ();
4905 for (i = 0; i < n_buffers; ++i) {
4907 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4908 MidiBuffer& buf (bufs.get_midi (i));
4911 buf.copy (source_port->get_midi_buffer(nframes));
4913 buf.silence (nframes);
4919 n_buffers = bufs.count().n_audio();
4921 size_t n_ports = io->n_ports().n_audio();
4922 float scaling = 1.0f;
4924 if (n_ports > n_buffers) {
4925 scaling = ((float) n_buffers) / n_ports;
4928 for (i = 0; i < n_ports; ++i) {
4930 /* if there are more ports than buffers, map them onto buffers
4931 * in a round-robin fashion
4934 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4935 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4937 if (i < n_buffers) {
4939 /* first time through just copy a channel into
4943 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4945 if (scaling != 1.0f) {
4946 buf.apply_gain (scaling, nframes);
4951 /* on subsequent times around, merge data from
4952 * the port with what is already there
4955 if (scaling != 1.0f) {
4956 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4958 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4963 /* silence any remaining buffers */
4965 for (; i < n_buffers; ++i) {
4966 AudioBuffer& buf (bufs.get_audio (i));
4967 buf.silence (nframes);
4970 /* establish the initial setup of the buffer set, reflecting what was
4971 copied into it. unless, of course, we are the auditioner, in which
4972 case nothing was fed into it from the inputs at all.
4975 if (!is_auditioner()) {
4976 bufs.set_count (io->n_ports());
4980 boost::shared_ptr<AutomationControl>
4981 Route::pan_azimuth_control() const
4984 # undef MIXBUS_PORTS_H
4985 # include "../../gtk2_ardour/mixbus_ports.h"
4986 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4988 return boost::shared_ptr<AutomationControl>();
4990 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4992 if (!_pannable || !panner()) {
4993 return boost::shared_ptr<AutomationControl>();
4995 return _pannable->pan_azimuth_control;
4999 boost::shared_ptr<AutomationControl>
5000 Route::pan_elevation_control() const
5002 if (Profile->get_mixbus() || !_pannable || !panner()) {
5003 return boost::shared_ptr<AutomationControl>();
5006 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5008 if (c.find (PanElevationAutomation) != c.end()) {
5009 return _pannable->pan_elevation_control;
5011 return boost::shared_ptr<AutomationControl>();
5014 boost::shared_ptr<AutomationControl>
5015 Route::pan_width_control() const
5018 if (mixbus() && _ch_pre) {
5020 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5023 if (Profile->get_mixbus() || !_pannable || !panner()) {
5024 return boost::shared_ptr<AutomationControl>();
5027 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5029 if (c.find (PanWidthAutomation) != c.end()) {
5030 return _pannable->pan_width_control;
5032 return boost::shared_ptr<AutomationControl>();
5035 boost::shared_ptr<AutomationControl>
5036 Route::pan_frontback_control() const
5038 if (Profile->get_mixbus() || !_pannable || !panner()) {
5039 return boost::shared_ptr<AutomationControl>();
5042 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5044 if (c.find (PanFrontBackAutomation) != c.end()) {
5045 return _pannable->pan_frontback_control;
5047 return boost::shared_ptr<AutomationControl>();
5050 boost::shared_ptr<AutomationControl>
5051 Route::pan_lfe_control() const
5053 if (Profile->get_mixbus() || !_pannable || !panner()) {
5054 return boost::shared_ptr<AutomationControl>();
5057 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5059 if (c.find (PanLFEAutomation) != c.end()) {
5060 return _pannable->pan_lfe_control;
5062 return boost::shared_ptr<AutomationControl>();
5067 Route::eq_band_cnt () const
5069 if (Profile->get_mixbus()) {
5071 if (is_master() || mixbus()) {
5080 /* Ardour has no well-known EQ object */
5085 boost::shared_ptr<AutomationControl>
5086 Route::eq_gain_controllable (uint32_t band) const
5089 boost::shared_ptr<PluginInsert> eq = ch_eq();
5092 return boost::shared_ptr<AutomationControl>();
5095 uint32_t port_number;
5096 if (is_master() || mixbus()) {
5098 case 0: port_number = 4; break;
5099 case 1: port_number = 3; break;
5100 case 2: port_number = 2; break;
5102 return boost::shared_ptr<AutomationControl>();
5107 case 0: port_number = 14; break;
5108 case 1: port_number = 12; break;
5109 case 2: port_number = 10; break;
5110 case 3: port_number = 8; break;
5112 return boost::shared_ptr<AutomationControl>();
5116 case 0: port_number = 8; break;
5117 case 1: port_number = 6; break;
5118 case 2: port_number = 4; break;
5120 return boost::shared_ptr<AutomationControl>();
5125 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5127 return boost::shared_ptr<AutomationControl>();
5130 boost::shared_ptr<AutomationControl>
5131 Route::eq_freq_controllable (uint32_t band) const
5134 if (mixbus() || is_master()) {
5135 /* no frequency controls for mixbusses or master */
5136 return boost::shared_ptr<AutomationControl>();
5139 boost::shared_ptr<PluginInsert> eq = ch_eq();
5142 return boost::shared_ptr<AutomationControl>();
5145 uint32_t port_number;
5148 case 0: port_number = 13; break; // lo
5149 case 1: port_number = 11; break; // lo mid
5150 case 2: port_number = 9; break; // hi mid
5151 case 3: port_number = 7; break; // hi
5153 return boost::shared_ptr<AutomationControl>();
5157 case 0: port_number = 7; break;
5158 case 1: port_number = 5; break;
5159 case 2: port_number = 3; break;
5161 return boost::shared_ptr<AutomationControl>();
5165 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5167 return boost::shared_ptr<AutomationControl>();
5171 boost::shared_ptr<AutomationControl>
5172 Route::eq_q_controllable (uint32_t band) const
5174 return boost::shared_ptr<AutomationControl>();
5177 boost::shared_ptr<AutomationControl>
5178 Route::eq_shape_controllable (uint32_t band) const
5181 boost::shared_ptr<PluginInsert> eq = ch_eq();
5182 if (is_master() || mixbus() || !eq) {
5183 return boost::shared_ptr<AutomationControl>();
5187 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5190 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5196 return boost::shared_ptr<AutomationControl>();
5199 boost::shared_ptr<AutomationControl>
5200 Route::eq_enable_controllable () const
5203 boost::shared_ptr<PluginInsert> eq = ch_eq();
5206 return boost::shared_ptr<AutomationControl>();
5209 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5211 return boost::shared_ptr<AutomationControl>();
5215 boost::shared_ptr<AutomationControl>
5216 Route::filter_freq_controllable (bool hpf) const
5219 boost::shared_ptr<PluginInsert> eq = ch_eq();
5221 if (is_master() || mixbus() || !eq) {
5222 return boost::shared_ptr<AutomationControl>();
5226 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5228 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5232 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5234 return boost::shared_ptr<AutomationControl>();
5239 return boost::shared_ptr<AutomationControl>();
5243 boost::shared_ptr<AutomationControl>
5244 Route::filter_slope_controllable (bool) const
5246 return boost::shared_ptr<AutomationControl>();
5249 boost::shared_ptr<AutomationControl>
5250 Route::filter_enable_controllable (bool) const
5253 boost::shared_ptr<PluginInsert> eq = ch_eq();
5255 if (is_master() || mixbus() || !eq) {
5256 return boost::shared_ptr<AutomationControl>();
5259 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5261 return boost::shared_ptr<AutomationControl>();
5266 Route::eq_band_name (uint32_t band) const
5269 if (is_master() || mixbus()) {
5271 if (Profile->get_mixbus()) {
5273 case 0: return _("lo");
5274 case 1: return _("mid");
5275 case 2: return _("hi");
5276 default: return string();
5284 case 0: return _("lo");
5285 case 1: return _("lo mid");
5286 case 2: return _("hi mid");
5287 case 3: return _("hi");
5288 default: return string();
5294 boost::shared_ptr<AutomationControl>
5295 Route::comp_enable_controllable () const
5298 boost::shared_ptr<PluginInsert> comp = ch_comp();
5301 return boost::shared_ptr<AutomationControl>();
5304 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5306 return boost::shared_ptr<AutomationControl>();
5309 boost::shared_ptr<AutomationControl>
5310 Route::comp_threshold_controllable () const
5313 boost::shared_ptr<PluginInsert> comp = ch_comp();
5316 return boost::shared_ptr<AutomationControl>();
5319 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5322 return boost::shared_ptr<AutomationControl>();
5325 boost::shared_ptr<AutomationControl>
5326 Route::comp_speed_controllable () const
5329 boost::shared_ptr<PluginInsert> comp = ch_comp();
5332 return boost::shared_ptr<AutomationControl>();
5335 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5337 return boost::shared_ptr<AutomationControl>();
5340 boost::shared_ptr<AutomationControl>
5341 Route::comp_mode_controllable () const
5344 boost::shared_ptr<PluginInsert> comp = ch_comp();
5347 return boost::shared_ptr<AutomationControl>();
5350 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5352 return boost::shared_ptr<AutomationControl>();
5355 boost::shared_ptr<AutomationControl>
5356 Route::comp_makeup_controllable () const
5359 boost::shared_ptr<PluginInsert> comp = ch_comp();
5362 return boost::shared_ptr<AutomationControl>();
5365 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5367 return boost::shared_ptr<AutomationControl>();
5370 boost::shared_ptr<ReadOnlyControl>
5371 Route::comp_redux_controllable () const
5374 boost::shared_ptr<PluginInsert> comp = ch_comp();
5377 return boost::shared_ptr<ReadOnlyControl>();
5380 return comp->control_output (2);
5382 return comp->control_output (6);
5386 return boost::shared_ptr<ReadOnlyControl>();
5391 Route::comp_mode_name (uint32_t mode) const
5396 return _("Leveler");
5398 return _("Compressor");
5400 return _("Limiter");
5402 return mixbus() ? _("Sidechain") : _("Limiter");
5412 Route::comp_speed_name (uint32_t mode) const
5430 boost::shared_ptr<AutomationControl>
5431 Route::send_level_controllable (uint32_t n) const
5434 # undef MIXBUS_PORTS_H
5435 # include "../../gtk2_ardour/mixbus_ports.h"
5436 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5437 if (plug && !mixbus()) {
5438 uint32_t port_id = 0;
5440 case 0: port_id = port_channel_post_aux1_level; break;
5441 case 1: port_id = port_channel_post_aux2_level; break;
5442 case 2: port_id = port_channel_post_aux3_level; break;
5443 case 3: port_id = port_channel_post_aux4_level; break;
5444 case 4: port_id = port_channel_post_aux5_level; break;
5445 case 5: port_id = port_channel_post_aux6_level; break;
5446 case 6: port_id = port_channel_post_aux7_level; break;
5447 case 7: port_id = port_channel_post_aux8_level; break;
5449 case 8: port_id = port_channel_post_aux9_level; break;
5450 case 9: port_id = port_channel_post_aux10_level; break;
5451 case 10: port_id = port_channel_post_aux11_level; break;
5452 case 11: port_id = port_channel_post_aux12_level; break;
5459 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5470 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5472 return boost::shared_ptr<AutomationControl>();
5474 return s->gain_control ();
5477 boost::shared_ptr<AutomationControl>
5478 Route::send_enable_controllable (uint32_t n) const
5481 # undef MIXBUS_PORTS_H
5482 # include "../../gtk2_ardour/mixbus_ports.h"
5483 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5484 if (plug && !mixbus()) {
5485 uint32_t port_id = 0;
5487 case 0: port_id = port_channel_post_aux1_asgn; break;
5488 case 1: port_id = port_channel_post_aux2_asgn; break;
5489 case 2: port_id = port_channel_post_aux3_asgn; break;
5490 case 3: port_id = port_channel_post_aux4_asgn; break;
5491 case 4: port_id = port_channel_post_aux5_asgn; break;
5492 case 5: port_id = port_channel_post_aux6_asgn; break;
5493 case 6: port_id = port_channel_post_aux7_asgn; break;
5494 case 7: port_id = port_channel_post_aux8_asgn; break;
5496 case 8: port_id = port_channel_post_aux9_asgn; break;
5497 case 9: port_id = port_channel_post_aux10_asgn; break;
5498 case 10: port_id = port_channel_post_aux11_asgn; break;
5499 case 11: port_id = port_channel_post_aux12_asgn; break;
5506 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5517 /* although Ardour sends have enable/disable as part of the Processor
5518 * API, it is not exposed as a controllable.
5520 * XXX: we should fix this (make it click-free, automatable enable-control)
5522 return boost::shared_ptr<AutomationControl>();
5526 Route::send_name (uint32_t n) const
5529 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5530 if (plug && !mixbus()) {
5533 return _session.get_mixbus (n)->name();
5538 return _session.get_mixbus (n)->name();
5544 boost::shared_ptr<Processor> p = nth_send (n);
5552 boost::shared_ptr<AutomationControl>
5553 Route::master_send_enable_controllable () const
5556 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5558 return boost::shared_ptr<AutomationControl>();
5560 # undef MIXBUS_PORTS_H
5561 # include "../../gtk2_ardour/mixbus_ports.h"
5562 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5564 return boost::shared_ptr<AutomationControl>();
5569 Route::slaved () const
5571 if (!_gain_control) {
5574 /* just test one particular control, not all of them */
5575 return _gain_control->slaved ();
5579 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5581 if (!vca || !_gain_control) {
5585 /* just test one particular control, not all of them */
5587 return _gain_control->slaved_to (vca->gain_control());
5591 Route::muted_by_others_soloing () const
5593 if (!can_be_muted_by_others ()) {
5597 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5601 Route::clear_all_solo_state ()
5603 _solo_control->clear_all_solo_state ();
5606 boost::shared_ptr<AutomationControl>
5607 Route::automation_control_recurse (PBD::ID const & id) const
5609 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5615 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5617 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5618 if ((ac = (*i)->automation_control (id))) {
5623 return boost::shared_ptr<AutomationControl> ();
5627 Route::slavables () const
5629 SlavableControlList rv;
5630 rv.push_back (_gain_control);
5631 rv.push_back (_mute_control);
5632 rv.push_back (_solo_control);
5637 Route::set_disk_io_point (DiskIOPoint diop)
5639 bool display = false;
5641 cerr << "set disk io to " << enum_2_string (diop) << endl;
5652 _disk_writer->set_display_to_user (display);
5656 _disk_reader->set_display_to_user (display);
5659 const bool changed = (diop != _disk_io_point);
5661 _disk_io_point = diop;
5664 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5665 configure_processors (0);
5668 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5671 #ifdef USE_TRACKS_CODE_FEATURES
5673 /* This is the Tracks version of Track::monitoring_state().
5675 * Ardour developers: try to flag or fix issues if parts of the libardour API
5676 * change in ways that invalidate this
5680 Route::monitoring_state () const
5682 /* Explicit requests */
5684 if (_monitoring != MonitorInput) {
5685 return MonitoringInput;
5688 if (_monitoring & MonitorDisk) {
5689 return MonitoringDisk;
5692 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5693 I don't think it's ever going to be too pretty too look at.
5696 // GZ: NOT USED IN TRACKS
5697 //bool const auto_input = _session.config.get_auto_input ();
5698 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5699 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5701 bool const roll = _session.transport_rolling ();
5702 bool const track_rec = _diskstream->record_enabled ();
5703 bool session_rec = _session.actively_recording ();
5707 if (!session_rec && roll) {
5708 return MonitoringDisk;
5710 return MonitoringInput;
5716 return MonitoringDisk;
5720 return MonitoringSilence;
5725 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5727 * Tracks developers: do NOT modify this method under any circumstances.
5731 Route::monitoring_state () const
5733 if (!_disk_reader) {
5734 return MonitoringInput;
5737 /* Explicit requests */
5738 MonitorChoice m (_monitoring_control->monitoring_choice());
5740 if (m != MonitorAuto) {
5742 MonitorState ms ((MonitorState) 0);
5744 if (m & MonitorInput) {
5745 ms = MonitoringInput;
5748 if (m & MonitorDisk) {
5749 ms = MonitorState (ms | MonitoringDisk);
5755 switch (_session.config.get_session_monitoring ()) {
5757 return MonitoringDisk;
5760 return MonitoringInput;
5766 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5767 I don't think it's ever going to be too pretty too look at.
5770 bool const roll = _session.transport_rolling ();
5771 bool const track_rec = _disk_writer->record_enabled ();
5772 bool const auto_input = _session.config.get_auto_input ();
5773 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5774 bool const tape_machine_mode = Config->get_tape_machine_mode ();
5777 /* I suspect that just use actively_recording() is good enough all the
5778 * time, but just to keep the semantics the same as they were before
5779 * sept 26th 2012, we differentiate between the cases where punch is
5780 * enabled and those where it is not.
5782 * rg: I suspect this is not the case: monitoring may differ
5785 if (_session.config.get_punch_in() || _session.config.get_punch_out() || _session.preroll_record_punch_enabled ()) {
5786 session_rec = _session.actively_recording ();
5788 session_rec = _session.get_record_enabled();
5793 if (!session_rec && roll && auto_input) {
5794 return MonitoringDisk;
5796 return software_monitor ? MonitoringInput : MonitoringSilence;
5801 if (tape_machine_mode) {
5803 return MonitoringDisk;
5807 if (!roll && auto_input) {
5808 return software_monitor ? MonitoringInput : MonitoringSilence;
5810 return MonitoringDisk;
5816 abort(); /* NOTREACHED */
5817 return MonitoringSilence;