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)
99 , _disk_io_point (DiskIOPreFader)
100 , _pending_process_reorder (0)
101 , _pending_signals (0)
102 , _pending_declick (true)
103 , _meter_point (MeterPostFader)
104 , _pending_meter_point (MeterPostFader)
105 , _meter_type (MeterPeak)
106 , _denormal_protection (false)
109 , _declickable (false)
110 , _have_internal_generator (false)
111 , _default_type (default_type)
113 , _in_configure_processors (false)
114 , _initial_io_setup (false)
115 , _in_sidechain_setup (false)
117 , _custom_meter_position_noted (false)
119 , _patch_selector_dialog (0)
121 processor_max_streams.reset();
124 boost::weak_ptr<Route>
125 Route::weakroute () {
126 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
132 /* set default meter type */
134 _meter_type = Config->get_meter_type_master ();
136 else if (dynamic_cast<Track*>(this)) {
137 _meter_type = Config->get_meter_type_track ();
139 _meter_type = Config->get_meter_type_bus ();
142 /* add standard controls */
144 _gain_control.reset (new GainControl (_session, GainAutomation));
145 _trim_control.reset (new GainControl (_session, TrimAutomation));
146 /* While the route has-a gain-control for consistency with Stripable and VCA
147 * ownership is handed over to the Amp Processor which manages the
148 * state of the Control and AutomationList as part of its
149 * Automatable API. -- Don't call add_control () here.
152 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
153 add_control (_solo_control);
154 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
156 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
157 add_control (_mute_control);
159 _phase_control.reset (new PhaseControl (_session, X_("phase")));
160 add_control (_phase_control);
162 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
163 add_control (_solo_isolate_control);
165 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
166 add_control (_solo_safe_control);
170 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
171 _pannable.reset (new Pannable (_session));
174 /* input and output objects */
176 _input.reset (new IO (_session, _name, IO::Input, _default_type));
177 _output.reset (new IO (_session, _name, IO::Output, _default_type));
179 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
180 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
182 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
183 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
185 /* add the amp/fader processor.
186 * it should be the first processor to be added on every route.
189 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
190 add_processor (_amp, PostFader);
193 _amp->set_display_name (_("Monitor"));
196 #if 0 // not used - just yet
197 if (!is_master() && !is_monitor() && !is_auditioner()) {
198 _delayline.reset (new DelayLine (_session, _name));
199 add_processor (_delayline, PreFader);
205 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
206 _trim->set_display_to_user (false);
208 if (dynamic_cast<AudioTrack*>(this)) {
209 /* we can't do this in the AudioTrack's constructor
210 * because _trim does not exit then
214 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
219 /* create standard processors: meter, main outs, monitor out;
220 they will be added to _processors by setup_invisible_processors ()
223 _meter.reset (new PeakMeter (_session, _name));
224 _meter->set_owner (this);
225 _meter->set_display_to_user (false);
228 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
229 _main_outs->activate ();
232 /* where we listen to tracks */
233 _intreturn.reset (new InternalReturn (_session));
234 _intreturn->activate ();
236 /* the thing that provides proper control over a control/monitor/listen bus
237 (such as per-channel cut, dim, solo, invert, etc).
239 _monitor_control.reset (new MonitorProcessor (_session));
240 _monitor_control->activate ();
243 /* now that we have _meter, its safe to connect to this */
246 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
247 configure_processors (0);
255 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
257 /* do this early so that we don't get incoming signals as we are going through destruction
262 /* don't use clear_processors here, as it depends on the session which may
263 be half-destroyed by now
266 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
267 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
268 (*i)->drop_references ();
271 _processors.clear ();
275 Route::ensure_track_or_route_name(string name, Session &session)
277 string newname = name;
279 while (!session.io_name_is_legal (newname)) {
280 newname = bump_name_once (newname, ' ');
287 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
289 // TODO route group, see set_gain()
290 // _trim_control->route_set_value (val);
294 Route::maybe_declick (BufferSet&, samplecnt_t, int)
296 /* this is the "bus" implementation and they never declick.
301 /** Process this route for one (sub) cycle (process thread)
303 * @param bufs Scratch buffers to use for the signal path
304 * @param start_sample Initial transport sample
305 * @param end_sample Final transport sample
306 * @param nframes Number of samples to output (to ports)
308 * Note that (end_sample - start_sample) may not be equal to nframes when the
309 * transport speed isn't 1.0 (eg varispeed).
312 Route::process_output_buffers (BufferSet& bufs,
313 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
314 int declick, bool gain_automation_ok)
316 /* Caller must hold process lock */
317 assert (!AudioEngine::instance()->process_lock().trylock());
319 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
321 // can this actually happen? functions calling process_output_buffers()
322 // already take a reader-lock.
323 bufs.silence (nframes, 0);
327 automation_run (start_sample, nframes);
329 /* figure out if we're going to use gain automation */
330 if (gain_automation_ok) {
331 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
332 _amp->setup_gain_automation (
333 start_sample + _amp->output_latency (),
334 end_sample + _amp->output_latency (),
337 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
338 _trim->setup_gain_automation (
339 start_sample + _trim->output_latency (),
340 end_sample + _trim->output_latency (),
344 /* Tell main outs what to do about monitoring. We do this so that
345 on a transition between monitoring states we get a de-clicking gain
346 change in the _main_outs delivery, if config.get_use_monitor_fades()
349 We override this in the case where we have an internal generator.
351 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
353 _main_outs->no_outs_cuz_we_no_monitor (silence);
355 /* -------------------------------------------------------------------------------------------
356 GLOBAL DECLICK (for transport changes etc.)
357 ----------------------------------------------------------------------------------------- */
359 maybe_declick (bufs, nframes, declick);
360 _pending_declick = 0;
362 /* -------------------------------------------------------------------------------------------
363 DENORMAL CONTROL/PHASE INVERT
364 ----------------------------------------------------------------------------------------- */
366 if (!_phase_control->none()) {
370 if (_denormal_protection || Config->get_denormal_protection()) {
372 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
373 Sample* const sp = i->data();
375 if (_phase_control->inverted (chn)) {
376 for (pframes_t nx = 0; nx < nframes; ++nx) {
381 for (pframes_t nx = 0; nx < nframes; ++nx) {
389 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
390 Sample* const sp = i->data();
392 if (_phase_control->inverted (chn)) {
393 for (pframes_t nx = 0; nx < nframes; ++nx) {
402 if (_denormal_protection || Config->get_denormal_protection()) {
404 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
405 Sample* const sp = i->data();
406 for (pframes_t nx = 0; nx < nframes; ++nx) {
414 /* -------------------------------------------------------------------------------------------
416 ----------------------------------------------------------------------------------------- */
418 /* set this to be true if the meter will already have been ::run() earlier */
419 bool const meter_already_run = metering_state() == MeteringInput;
421 samplecnt_t latency = 0;
422 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
424 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
426 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
427 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
432 /* if it has any inputs, make sure they match */
433 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
434 if (bufs.count() != (*i)->input_streams()) {
436 DEBUG::Processors, string_compose (
437 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
438 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
445 /* should we NOT run plugins here if the route is inactive?
446 do we catch route != active somewhere higher?
449 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
450 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
452 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
453 const samplecnt_t longest_session_latency = _initial_delay + _signal_latency;
454 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
455 _initial_delay + latency, longest_session_latency - latency);
458 //cerr << name() << " run " << (*i)->name() << endl;
459 (*i)->run (bufs, start_sample - latency, end_sample - latency, speed, nframes, *i != _processors.back());
460 bufs.set_count ((*i)->output_streams());
462 if ((*i)->active ()) {
463 latency += (*i)->signal_latency ();
469 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
470 boost::shared_ptr<Processor> endpoint,
471 bool include_endpoint, bool for_export, bool for_freeze)
473 /* If no processing is required, there's no need to go any further. */
474 if (!endpoint && !include_endpoint) {
478 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
479 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
480 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
482 /* trim is always at the top, for bounce no latency compensation is needed */
483 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
484 _trim->setup_gain_automation (start, start + nframes, nframes);
487 const double speed = _session.transport_speed ();
488 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
490 if (!include_endpoint && (*i) == endpoint) {
494 /* if we're *not* exporting, stop processing if we come across a routing processor. */
495 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
498 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
502 /* special case the panner (export outputs)
503 * Ideally we'd only run the panner, not the delivery itself...
504 * but panners need separate input/output buffers and some context
505 * (panshell, panner type, etc). AFAICT there is no ill side effect
506 * of re-using the main delivery when freewheeling/exporting a region.
508 if ((*i) == _main_outs) {
509 assert ((*i)->does_routing());
510 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
511 buffers.set_count ((*i)->output_streams());
514 /* don't run any processors that do routing.
515 * Also don't bother with metering.
517 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
518 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
519 buffers.set_count ((*i)->output_streams());
520 latency += (*i)->signal_latency ();
523 if ((*i) == endpoint) {
530 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
531 bool include_endpoint, bool for_export, bool for_freeze) const
533 samplecnt_t latency = 0;
534 if (!endpoint && !include_endpoint) {
538 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
539 if (!include_endpoint && (*i) == endpoint) {
542 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
545 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
548 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
549 latency += (*i)->signal_latency ();
551 if ((*i) == endpoint) {
559 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
560 bool include_endpoint, bool for_export, bool for_freeze) const
562 if (!endpoint && !include_endpoint) {
566 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
567 if (!include_endpoint && (*i) == endpoint) {
570 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
573 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
576 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
577 cc = (*i)->output_streams();
579 if ((*i) == endpoint) {
587 Route::n_process_buffers ()
589 return max (_input->n_ports(), processor_max_streams);
593 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
595 assert (is_monitor());
596 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
597 fill_buffers_with_input (bufs, _input, nframes);
598 passthru (bufs, start_sample, end_sample, nframes, declick, true);
602 Route::passthru (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok)
606 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
608 /* control/monitor bus ignores input ports when something is
609 feeding the listen "stream". data will "arrive" into the
610 route from the intreturn processor element.
613 bufs.silence (nframes, 0);
616 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
618 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
620 /* run processor chain */
622 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok);
626 Route::passthru_silence (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
628 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
630 bufs.set_count (_input->n_ports());
631 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
632 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, false);
636 Route::set_listen (bool yn)
639 if (_monitor_send->active() == yn) {
643 _monitor_send->activate ();
645 _monitor_send->deactivate ();
651 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
653 /* nothing to do if we're not using AFL/PFL. But if we are, we need
654 to alter the active state of the monitor send.
657 if (Config->get_solo_control_is_listen_control ()) {
658 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
663 Route::push_solo_isolate_upstream (int32_t delta)
665 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
667 boost::shared_ptr<RouteList> routes = _session.get_routes ();
668 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
670 if ((*i).get() == this || !(*i)->can_solo()) {
675 bool does_feed = feeds (*i, &sends_only);
677 if (does_feed && !sends_only) {
678 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
684 Route::push_solo_upstream (int delta)
686 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
687 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
691 boost::shared_ptr<Route> sr (i->r.lock());
693 sr->solo_control()->mod_solo_by_others_downstream (-delta);
700 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
702 cerr << name << " {" << endl;
703 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
704 p != procs.end(); ++p) {
705 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
711 /** Supposing that we want to insert a Processor at a given Placement, return
712 * the processor to add the new one before (or 0 to add at the end).
714 boost::shared_ptr<Processor>
715 Route::before_processor_for_placement (Placement p)
717 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
719 ProcessorList::iterator loc;
722 /* generic pre-fader: insert immediately before the amp */
723 loc = find (_processors.begin(), _processors.end(), _amp);
725 /* generic post-fader: insert right before the main outs */
726 loc = find (_processors.begin(), _processors.end(), _main_outs);
729 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
732 /** Supposing that we want to insert a Processor at a given index, return
733 * the processor to add the new one before (or 0 to add at the end).
735 boost::shared_ptr<Processor>
736 Route::before_processor_for_index (int index)
739 return boost::shared_ptr<Processor> ();
742 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
744 ProcessorList::iterator i = _processors.begin ();
746 while (i != _processors.end() && j < index) {
747 if ((*i)->display_to_user()) {
754 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
757 /** Add a processor either pre- or post-fader
758 * @return 0 on success, non-0 on failure.
761 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
763 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
767 /** Add a processor to a route such that it ends up with a given index into the visible processors.
768 * @param index Index to add the processor at, or -1 to add at the end of the list.
769 * @return 0 on success, non-0 on failure.
772 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
774 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
777 /** Add a processor to the route.
778 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
779 * @return 0 on success, non-0 on failure.
782 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
784 assert (processor != _meter);
785 assert (processor != _main_outs);
787 DEBUG_TRACE (DEBUG::Processors, string_compose (
788 "%1 adding processor %2\n", name(), processor->name()));
792 pl.push_back (processor);
793 int rv = add_processors (pl, before, err);
799 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
800 processor->activate ();
807 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
809 /* We cannot destruct the processor here (usually RT-thread
810 * with various locks held - in case of sends also io_locks).
811 * Queue for deletion in low-priority thread.
813 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
814 selfdestruct_sequence.push_back (wp);
818 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
820 XMLProperty const * prop;
823 boost::shared_ptr<Processor> processor;
825 /* bit of a hack: get the `placement' property from the <Redirect> tag here
826 so that we can add the processor in the right place (pre/post-fader)
829 XMLNodeList const & children = node.children ();
830 XMLNodeList::const_iterator i = children.begin ();
832 while (i != children.end() && (*i)->name() != X_("Redirect")) {
836 Placement placement = PreFader;
838 if (i != children.end()) {
839 if ((prop = (*i)->property (X_("placement"))) != 0) {
840 placement = Placement (string_2_enum (prop->value(), placement));
844 if (node.name() == "Insert") {
846 if ((prop = node.property ("type")) != 0) {
848 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
849 prop->value() == "lv2" ||
850 prop->value() == "windows-vst" ||
851 prop->value() == "mac-vst" ||
852 prop->value() == "lxvst" ||
853 prop->value() == "audiounit") {
855 if (_session.get_disable_all_loaded_plugins ()) {
856 processor.reset (new UnknownProcessor (_session, node));
858 processor.reset (new PluginInsert (_session));
859 processor->set_owner (this);
864 processor.reset (new PortInsert (_session, _pannable, _mute_master));
869 } else if (node.name() == "Send") {
871 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
872 processor.reset (new Send (_session, sendpan, _mute_master));
876 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
880 if (processor->set_state (node, version)) {
884 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
885 if (i != children.end()) {
886 if ((prop = (*i)->property (X_("active"))) != 0) {
887 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
888 processor->activate();
890 processor->deactivate();
894 return (add_processor (processor, placement, 0, false) == 0);
897 catch (failed_constructor &err) {
898 warning << _("processor could not be created. Ignored.") << endmsg;
904 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
905 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
908 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
909 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
913 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
915 ProcessorList::iterator loc;
916 boost::shared_ptr <PluginInsert> fanout;
918 if (g_atomic_int_get (&_pending_process_reorder)) {
919 /* we need to flush any pending re-order changes */
920 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
921 apply_processor_changes_rt ();
925 loc = find(_processors.begin(), _processors.end(), before);
926 if (loc == _processors.end ()) {
930 /* nothing specified - at end */
931 loc = _processors.end ();
934 if (others.empty()) {
938 ProcessorList to_skip;
940 // check if there's an instrument to replace or configure
941 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
942 boost::shared_ptr<PluginInsert> pi;
943 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
946 if (!pi->plugin ()->get_info ()->is_instrument ()) {
949 boost::shared_ptr<Processor> instrument = the_instrument ();
950 ChanCount in (DataType::MIDI, 1);
951 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
953 PluginSetupOptions flags = None;
956 in = instrument->input_streams ();
957 out = instrument->output_streams ();
959 if (pi->has_output_presets (in, out)) {
963 pi->set_strict_io (_strict_io);
965 PluginSetupOptions mask = None;
966 if (Config->get_ask_replace_instrument ()) {
969 if (Config->get_ask_setup_instrument ()) {
976 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
977 int mode = rv.get_value_or (0);
980 to_skip.push_back (*i); // don't add this one;
983 replace_processor (instrument, *i, err);
984 to_skip.push_back (*i);
989 if ((mode & 5) == 4) {
996 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
997 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
998 ProcessorState pstate (this);
1000 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1005 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1006 if (check != to_skip.end()) {
1010 boost::shared_ptr<PluginInsert> pi;
1012 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1013 pi->set_strict_io (_strict_io);
1017 /* Ensure that only one amp is in the list at any time */
1018 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1019 if (check != _processors.end()) {
1020 if (before == _amp) {
1021 /* Already in position; all is well */
1024 _processors.erase (check);
1029 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1031 _processors.insert (loc, *i);
1032 (*i)->set_owner (this);
1035 if (configure_processors_unlocked (err, &lm)) {
1037 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1042 if (pi && pi->has_sidechain ()) {
1043 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1046 if ((*i)->active()) {
1047 // emit ActiveChanged() and latency_changed() if needed
1051 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1053 boost::shared_ptr<Send> send;
1054 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1055 send->SelfDestruct.connect_same_thread (*this,
1056 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1060 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1061 boost::shared_ptr<PluginInsert> pi;
1063 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1064 if (pi->has_no_inputs ()) {
1065 _have_internal_generator = true;
1071 _output->set_user_latency (0);
1074 reset_instrument_info ();
1075 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1076 set_processor_positions ();
1078 if (fanout && fanout->configured ()
1079 && fanout->output_streams().n_audio() > 2
1080 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1081 fan_out (); /* EMIT SIGNAL */
1087 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1089 if (p == PreFader) {
1090 start = _processors.begin();
1091 end = find(_processors.begin(), _processors.end(), _amp);
1093 start = find(_processors.begin(), _processors.end(), _amp);
1095 end = _processors.end();
1099 /** Turn off all processors with a given placement
1100 * @param p Placement of processors to disable
1103 Route::disable_processors (Placement p)
1105 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1107 ProcessorList::iterator start, end;
1108 placement_range(p, start, end);
1110 for (ProcessorList::iterator i = start; i != end; ++i) {
1111 (*i)->enable (false);
1114 _session.set_dirty ();
1117 /** Turn off all redirects
1120 Route::disable_processors ()
1122 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1124 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1125 (*i)->enable (false);
1128 _session.set_dirty ();
1131 /** Turn off all redirects with a given placement
1132 * @param p Placement of redirects to disable
1135 Route::disable_plugins (Placement p)
1137 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1139 ProcessorList::iterator start, end;
1140 placement_range(p, start, end);
1142 for (ProcessorList::iterator i = start; i != end; ++i) {
1143 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1144 (*i)->enable (false);
1148 _session.set_dirty ();
1151 /** Turn off all plugins
1154 Route::disable_plugins ()
1156 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1158 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1159 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1160 (*i)->enable (false);
1164 _session.set_dirty ();
1169 Route::ab_plugins (bool forward)
1171 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1175 /* forward = turn off all active redirects, and mark them so that the next time
1176 we go the other way, we will revert them
1179 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1180 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1183 if (!(*i)->display_to_user ()) {
1187 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1192 if ((*i)->enabled ()) {
1193 (*i)->enable (false);
1194 (*i)->set_next_ab_is_active (true);
1196 (*i)->set_next_ab_is_active (false);
1202 /* backward = if the redirect was marked to go active on the next ab, do so */
1204 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1205 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1208 if (!(*i)->display_to_user ()) {
1212 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1217 (*i)->enable ((*i)->get_next_ab_is_active ());
1221 _session.set_dirty ();
1225 /** Remove processors with a given placement.
1226 * @param p Placement of processors to remove.
1229 Route::clear_processors (Placement p)
1231 if (!_session.engine().connected()) {
1235 bool already_deleting = _session.deletion_in_progress();
1236 if (!already_deleting) {
1237 _session.set_deletion_in_progress();
1240 ProcessorList old_list = _processors;
1242 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1243 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1244 ProcessorList new_list;
1245 ProcessorStreams err;
1246 bool seen_amp = false;
1248 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1254 if (is_internal_processor (*i)) {
1256 /* you can't remove these */
1258 new_list.push_back (*i);
1265 new_list.push_back (*i);
1268 (*i)->drop_references ();
1276 (*i)->drop_references ();
1279 new_list.push_back (*i);
1286 _processors = new_list;
1287 configure_processors_unlocked (&err, &lm); // this can't fail
1289 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1292 processor_max_streams.reset();
1293 _have_internal_generator = false;
1294 reset_instrument_info ();
1295 set_processor_positions ();
1297 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1299 if (!already_deleting) {
1300 _session.clear_deletion_in_progress();
1305 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1307 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim) {
1314 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1316 // TODO once the export point can be configured properly, do something smarter here
1317 if (processor == _capturing_processor) {
1318 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1319 if (need_process_lock) {
1323 _capturing_processor.reset();
1325 if (need_process_lock) {
1330 /* these can never be removed */
1332 if (is_internal_processor (processor)) {
1336 if (!_session.engine().connected()) {
1340 processor_max_streams.reset();
1343 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1344 if (need_process_lock) {
1348 /* Caller must hold process lock */
1349 assert (!AudioEngine::instance()->process_lock().trylock());
1351 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1353 ProcessorState pstate (this);
1355 ProcessorList::iterator i;
1356 bool removed = false;
1358 for (i = _processors.begin(); i != _processors.end(); ) {
1359 if (*i == processor) {
1361 /* move along, see failure case for configure_processors()
1362 where we may need to reconfigure the processor.
1365 /* stop redirects that send signals to JACK ports
1366 from causing noise as a result of no longer being
1370 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1371 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1375 iop = pi->sidechain();
1382 i = _processors.erase (i);
1390 _output->set_user_latency (0);
1398 if (configure_processors_unlocked (err, &lm)) {
1400 /* we know this will work, because it worked before :) */
1401 configure_processors_unlocked (0, &lm);
1405 _have_internal_generator = false;
1407 for (i = _processors.begin(); i != _processors.end(); ++i) {
1408 boost::shared_ptr<PluginInsert> pi;
1410 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1411 if (pi->has_no_inputs ()) {
1412 _have_internal_generator = true;
1417 if (need_process_lock) {
1422 reset_instrument_info ();
1423 processor->drop_references ();
1424 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1425 set_processor_positions ();
1431 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1433 /* these can never be removed */
1434 if (is_internal_processor (old)) {
1437 /* and can't be used as substitute, either */
1438 if (is_internal_processor (sub)) {
1442 /* I/Os are out, too */
1443 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1447 /* this function cannot be used to swap/reorder processors */
1448 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1452 if (!AudioEngine::instance()->connected() || !old || !sub) {
1456 /* ensure that sub is not owned by another route */
1457 if (sub->owner ()) {
1462 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1463 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1464 ProcessorState pstate (this);
1466 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1468 ProcessorList::iterator i;
1469 bool replaced = false;
1470 bool enable = old->enabled ();
1472 for (i = _processors.begin(); i != _processors.end(); ) {
1474 i = _processors.erase (i);
1475 _processors.insert (i, sub);
1476 sub->set_owner (this);
1489 boost::shared_ptr<PluginInsert> pi;
1490 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1491 pi->set_strict_io (true);
1495 if (configure_processors_unlocked (err, &lm)) {
1497 configure_processors_unlocked (0, &lm);
1501 _have_internal_generator = false;
1503 for (i = _processors.begin(); i != _processors.end(); ++i) {
1504 boost::shared_ptr<PluginInsert> pi;
1505 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1506 if (pi->has_no_inputs ()) {
1507 _have_internal_generator = true;
1517 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1518 _output->set_user_latency (0);
1521 reset_instrument_info ();
1522 old->drop_references ();
1523 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1524 set_processor_positions ();
1529 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1531 ProcessorList deleted;
1533 if (!_session.engine().connected()) {
1537 processor_max_streams.reset();
1540 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1541 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1542 ProcessorState pstate (this);
1544 ProcessorList::iterator i;
1545 boost::shared_ptr<Processor> processor;
1547 for (i = _processors.begin(); i != _processors.end(); ) {
1551 /* these can never be removed */
1553 if (is_internal_processor (processor)) {
1558 /* see if its in the list of processors to delete */
1560 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1565 /* stop IOProcessors that send to JACK ports
1566 from causing noise as a result of no longer being
1570 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1571 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1574 iop = pi->sidechain();
1581 deleted.push_back (processor);
1582 i = _processors.erase (i);
1585 if (deleted.empty()) {
1586 /* none of those in the requested list were found */
1590 _output->set_user_latency (0);
1592 if (configure_processors_unlocked (err, &lm)) {
1594 /* we know this will work, because it worked before :) */
1595 configure_processors_unlocked (0, &lm);
1600 _have_internal_generator = false;
1602 for (i = _processors.begin(); i != _processors.end(); ++i) {
1603 boost::shared_ptr<PluginInsert> pi;
1605 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1606 if (pi->has_no_inputs ()) {
1607 _have_internal_generator = true;
1614 /* now try to do what we need to so that those that were removed will be deleted */
1616 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1617 (*i)->drop_references ();
1620 reset_instrument_info ();
1621 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1622 set_processor_positions ();
1628 Route::reset_instrument_info ()
1630 boost::shared_ptr<Processor> instr = the_instrument();
1632 _instrument_info.set_internal_instrument (instr);
1636 /** Caller must hold process lock */
1638 Route::configure_processors (ProcessorStreams* err)
1640 #ifndef PLATFORM_WINDOWS
1641 assert (!AudioEngine::instance()->process_lock().trylock());
1644 if (!_in_configure_processors) {
1645 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1646 return configure_processors_unlocked (err, &lm);
1653 Route::input_streams () const
1655 return _input->n_ports ();
1658 list<pair<ChanCount, ChanCount> >
1659 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1661 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1663 return try_configure_processors_unlocked (in, err);
1666 list<pair<ChanCount, ChanCount> >
1667 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1669 // Check each processor in order to see if we can configure as requested
1671 list<pair<ChanCount, ChanCount> > configuration;
1674 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1675 DEBUG_TRACE (DEBUG::Processors, "{\n");
1677 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1679 if ((*p)->can_support_io_configuration(in, out)) {
1681 if (boost::dynamic_pointer_cast<Delivery> (*p)
1682 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1684 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1685 /* with strict I/O the panner + output are forced to
1686 * follow the last processor's output.
1688 * Delivery::can_support_io_configuration() will only add ports,
1689 * but not remove excess ports.
1691 * This works because the delivery only requires
1692 * as many outputs as there are inputs.
1693 * Delivery::configure_io() will do the actual removal
1694 * by calling _output->ensure_io()
1696 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1697 /* ..but at least as many as there are master-inputs, if
1698 * the delivery is dealing with audio */
1699 // XXX this may need special-casing for mixbus (master-outputs)
1700 // and should maybe be a preference anyway ?!
1701 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1707 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1708 configuration.push_back(make_pair(in, out));
1711 // restriction for Monitor Section Processors
1712 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1713 /* Note: The Monitor follows the master-bus and has no panner.
1715 * The general idea is to only allow plugins that retain the channel-count
1716 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1717 * Then again 5.1 in, monitor stereo is a valid use-case.
1719 * and worse: we only refuse adding plugins *here*.
1721 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1722 * 2) change master-bus, add a channel
1723 * 2a) monitor-secion follows
1724 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1725 * 4) re-load session, monitor-processor remains unconfigured, crash.
1727 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1729 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1730 // internal sends make no sense, only feedback
1731 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1732 return list<pair<ChanCount, ChanCount> > ();
1734 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1735 /* External Sends can be problematic. one can add/remove ports
1736 * there signal leaves the DAW to external monitors anyway, so there's
1737 * no real use for allowing them here anyway.
1739 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1740 return list<pair<ChanCount, ChanCount> > ();
1742 if (boost::dynamic_pointer_cast<Send> (*p)) {
1744 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1745 return list<pair<ChanCount, ChanCount> > ();
1754 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1755 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1756 DEBUG_TRACE (DEBUG::Processors, "}\n");
1757 return list<pair<ChanCount, ChanCount> > ();
1761 DEBUG_TRACE (DEBUG::Processors, "}\n");
1763 return configuration;
1766 /** Set the input/output configuration of each processor in the processors list.
1767 * Caller must hold process lock.
1768 * Return 0 on success, otherwise configuration is impossible.
1771 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1773 #ifndef PLATFORM_WINDOWS
1774 assert (!AudioEngine::instance()->process_lock().trylock());
1777 if (_in_configure_processors) {
1781 /* put invisible processors where they should be */
1782 setup_invisible_processors ();
1784 _in_configure_processors = true;
1786 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1788 if (configuration.empty ()) {
1789 _in_configure_processors = false;
1794 bool seen_mains_out = false;
1795 processor_out_streams = _input->n_ports();
1796 processor_max_streams.reset();
1798 /* processor configure_io() may result in adding ports
1799 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1801 * with jack2 adding ports results in a graph-order callback,
1802 * which calls Session::resort_routes() and eventually
1803 * Route::direct_feeds_according_to_reality()
1804 * which takes a ReaderLock (_processor_lock).
1806 * so we can't hold a WriterLock here until jack2 threading
1809 * NB. we still hold the process lock
1811 * (ardour's own engines do call graph-order from the
1812 * process-thread and hence do not have this issue; besides
1813 * merely adding ports won't trigger a graph-order, only
1814 * making connections does)
1818 // TODO check for a potential ReaderLock after ReaderLock ??
1819 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1821 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1822 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1824 if (!(*p)->configure_io(c->first, c->second)) {
1825 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1826 _in_configure_processors = false;
1832 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1833 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1835 boost::shared_ptr<IOProcessor> iop;
1836 boost::shared_ptr<PluginInsert> pi;
1837 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1838 /* plugins connected via Split or Hide Match may have more channels.
1839 * route/scratch buffers are needed for all of them
1840 * The configuration may only be a subset (both input and output)
1842 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1844 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1845 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1846 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1850 if (boost::dynamic_pointer_cast<Delivery> (*p)
1851 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1852 /* main delivery will increase port count to match input.
1853 * the Delivery::Main is usually the last processor - followed only by
1856 seen_mains_out = true;
1858 if (!seen_mains_out) {
1859 processor_out_streams = out;
1868 _meter->set_max_channels (processor_max_streams);
1871 /* make sure we have sufficient scratch buffers to cope with the new processor
1874 _session.ensure_buffers (n_process_buffers ());
1876 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1878 _in_configure_processors = false;
1882 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1883 * @param state New active state for those processors.
1886 Route::all_visible_processors_active (bool state)
1888 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1890 if (_processors.empty()) {
1894 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1895 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1899 boost::shared_ptr<PluginInsert> pi;
1900 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1901 if (pi->is_channelstrip ()) {
1906 (*i)->enable (state);
1909 _session.set_dirty ();
1913 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1915 /* check if re-order requires re-configuration of any processors
1916 * -> compare channel configuration for all processors
1918 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1919 ChanCount c = input_streams ();
1921 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1923 if (c != (*j)->input_streams()) {
1926 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1929 if ((*i)->input_streams() != c) {
1932 c = (*i)->output_streams();
1944 __attribute__((annotate("realtime")))
1947 Route::apply_processor_order (const ProcessorList& new_order)
1949 /* need to hold processor_lock; either read or write lock
1950 * and the engine process_lock.
1951 * Due to r/w lock ambiguity we can only assert the latter
1953 assert (!AudioEngine::instance()->process_lock().trylock());
1956 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1957 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1958 * processors in the current actual processor list that are hidden. Any visible processors
1959 * in the current list but not in "new_order" will be assumed to be deleted.
1962 /* "as_it_will_be" and "_processors" are lists of shared pointers.
1963 * actual memory usage is small, but insert/erase is not actually rt-safe :(
1964 * (note though that ::processors_reorder_needs_configure() ensured that
1965 * this function will only ever be called from the rt-thread if no processor were removed)
1967 * either way, I can't proove it, but an x-run due to re-order here is less likley
1968 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
1971 ProcessorList as_it_will_be;
1972 ProcessorList::iterator oiter;
1973 ProcessorList::const_iterator niter;
1975 oiter = _processors.begin();
1976 niter = new_order.begin();
1978 while (niter != new_order.end()) {
1980 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1981 then append it to the temp list.
1983 Otherwise, see if the next processor in the old list is in the new list. if not,
1984 its been deleted. If its there, append it to the temp list.
1987 if (oiter == _processors.end()) {
1989 /* no more elements in the old list, so just stick the rest of
1990 the new order onto the temp list.
1993 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1994 while (niter != new_order.end()) {
2001 if (!(*oiter)->display_to_user()) {
2003 as_it_will_be.push_back (*oiter);
2007 /* visible processor: check that its in the new order */
2009 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2010 /* deleted: do nothing, shared_ptr<> will clean up */
2012 /* ignore this one, and add the next item from the new order instead */
2013 as_it_will_be.push_back (*niter);
2018 /* now remove from old order - its taken care of no matter what */
2019 oiter = _processors.erase (oiter);
2023 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2025 /* If the meter is in a custom position, find it and make a rough note of its position */
2026 maybe_note_meter_position ();
2030 Route::move_instrument_down (bool postfader)
2032 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2033 ProcessorList new_order;
2034 boost::shared_ptr<Processor> instrument;
2035 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2036 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2037 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2039 } else if (instrument && *i == _amp) {
2041 new_order.push_back (*i);
2042 new_order.push_back (instrument);
2044 new_order.push_back (instrument);
2045 new_order.push_back (*i);
2048 new_order.push_back (*i);
2055 reorder_processors (new_order, 0);
2059 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2061 // it a change is already queued, wait for it
2062 // (unless engine is stopped. apply immediately and proceed
2063 while (g_atomic_int_get (&_pending_process_reorder)) {
2064 if (!AudioEngine::instance()->running()) {
2065 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2066 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2068 apply_processor_order(_pending_processor_order);
2069 setup_invisible_processors ();
2071 g_atomic_int_set (&_pending_process_reorder, 0);
2073 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2074 set_processor_positions ();
2076 // TODO rather use a semaphore or something.
2077 // but since ::reorder_processors() is called
2078 // from the GUI thread, this is fine..
2083 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2085 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2086 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2087 ProcessorState pstate (this);
2089 apply_processor_order (new_order);
2091 if (configure_processors_unlocked (err, &lm)) {
2099 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2100 set_processor_positions ();
2103 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2104 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2106 // _pending_processor_order is protected by _processor_lock
2107 _pending_processor_order = new_order;
2108 g_atomic_int_set (&_pending_process_reorder, 1);
2111 /* update processor input/output latency
2112 * (total signal_latency does not change)
2114 update_signal_latency (true);
2120 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2122 boost::shared_ptr<PluginInsert> pi;
2123 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2127 if (pi->has_sidechain () == add) {
2128 return true; // ?? call failed, but result is as expected.
2132 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2133 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2134 if (i == _processors.end ()) {
2140 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2141 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2142 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2144 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2146 if (!pi->add_sidechain ()) {
2150 if (!pi->del_sidechain ()) {
2156 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2161 pi->del_sidechain ();
2163 pi->add_sidechain ();
2164 // TODO restore side-chain's state.
2169 configure_processors_unlocked (0, &lm);
2172 if (pi->has_sidechain ()) {
2173 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2176 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2177 _session.set_dirty ();
2182 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2184 boost::shared_ptr<PluginInsert> pi;
2185 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2190 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2191 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2192 if (i == _processors.end ()) {
2198 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2199 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2201 const ChanCount& old (pi->preset_out ());
2202 if (!pi->set_preset_out (outs)) {
2203 return true; // no change, OK
2206 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2209 pi->set_preset_out (old);
2212 configure_processors_unlocked (0, &lm);
2215 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2216 _session.set_dirty ();
2221 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2224 return customize_plugin_insert (proc, 0, unused, unused);
2228 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2230 boost::shared_ptr<PluginInsert> pi;
2231 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2236 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2237 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2238 if (i == _processors.end ()) {
2244 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2245 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2247 bool old_cust = pi->custom_cfg ();
2248 uint32_t old_cnt = pi->get_count ();
2249 ChanCount old_chan = pi->output_streams ();
2250 ChanCount old_sinks = pi->natural_input_streams ();
2253 pi->set_custom_cfg (false);
2255 pi->set_custom_cfg (true);
2256 pi->set_count (count);
2257 pi->set_outputs (outs);
2258 pi->set_sinks (sinks);
2261 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2265 pi->set_count (old_cnt);
2266 pi->set_sinks (old_sinks);
2267 pi->set_outputs (old_chan);
2268 pi->set_custom_cfg (old_cust);
2272 configure_processors_unlocked (0, &lm);
2275 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2276 _session.set_dirty ();
2281 Route::set_strict_io (const bool enable)
2283 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2285 if (_strict_io != enable) {
2286 _strict_io = enable;
2287 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2288 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2289 boost::shared_ptr<PluginInsert> pi;
2290 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2291 pi->set_strict_io (_strict_io);
2295 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2299 _strict_io = !enable; // restore old value
2300 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2301 boost::shared_ptr<PluginInsert> pi;
2302 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2303 pi->set_strict_io (_strict_io);
2310 configure_processors (0);
2313 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2314 _session.set_dirty ();
2326 Route::get_template()
2328 return state(false);
2332 Route::state(bool full_state)
2334 if (!_session._template_state_dir.empty()) {
2335 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2338 XMLNode *node = new XMLNode("Route");
2339 ProcessorList::iterator i;
2341 node->set_property (X_("id"), id ());
2342 node->set_property (X_("name"), name());
2343 node->set_property (X_("default-type"), _default_type);
2344 node->set_property (X_("strict-io"), _strict_io);
2346 node->add_child_nocopy (_presentation_info.get_state());
2348 node->set_property (X_("active"), _active);
2349 node->set_property (X_("denormal-protection"), _denormal_protection);
2350 node->set_property (X_("meter-point"), _meter_point);
2351 node->set_property (X_("disk-io-point"), _disk_io_point);
2353 node->set_property (X_("meter-type"), _meter_type);
2356 node->set_property (X_("route-group"), _route_group->name());
2359 node->add_child_nocopy (_solo_control->get_state ());
2360 node->add_child_nocopy (_solo_isolate_control->get_state ());
2361 node->add_child_nocopy (_solo_safe_control->get_state ());
2363 node->add_child_nocopy (_input->state (full_state));
2364 node->add_child_nocopy (_output->state (full_state));
2365 node->add_child_nocopy (_mute_master->get_state ());
2367 node->add_child_nocopy (_mute_control->get_state ());
2368 node->add_child_nocopy (_phase_control->get_state ());
2371 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2374 if (_comment.length()) {
2375 XMLNode *cmt = node->add_child ("Comment");
2376 cmt->add_content (_comment);
2380 node->add_child_nocopy (_pannable->state (full_state));
2384 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2385 for (i = _processors.begin(); i != _processors.end(); ++i) {
2387 /* template save: do not include internal sends functioning as
2388 aux sends because the chance of the target ID
2389 in the session where this template is used
2392 similarly, do not save listen sends which connect to
2393 the monitor section, because these will always be
2396 boost::shared_ptr<InternalSend> is;
2398 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2399 if (is->role() == Delivery::Listen) {
2404 node->add_child_nocopy((*i)->state (full_state));
2409 node->add_child_copy (*_extra_xml);
2412 if (_custom_meter_position_noted) {
2413 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2415 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2419 if (!_session._template_state_dir.empty()) {
2420 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2423 node->add_child_copy (Slavable::get_state());
2429 Route::set_state (const XMLNode& node, int version)
2431 if (version < 3000) {
2432 return set_state_2X (node, version);
2436 XMLNodeConstIterator niter;
2439 if (node.name() != "Route"){
2440 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2444 std::string route_name;
2445 if (node.get_property (X_("name"), route_name)) {
2446 Route::set_name (route_name);
2450 _initial_io_setup = true;
2452 Stripable::set_state (node, version);
2454 node.get_property (X_("strict-io"), _strict_io);
2457 /* monitor bus does not get a panner, but if (re)created
2458 via XML, it will already have one by the time we
2459 call ::set_state(). so ... remove it.
2464 /* add all processors (except amp, which is always present) */
2466 nlist = node.children();
2467 XMLNode processor_state (X_("processor_state"));
2469 Stateful::save_extra_xml (node);
2471 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2475 if (child->name() == IO::state_node_name) {
2476 std::string direction;
2477 if (!child->get_property (X_("direction"), direction)) {
2481 if (direction == "Input") {
2482 _input->set_state (*child, version);
2483 } else if (direction == "Output") {
2484 _output->set_state (*child, version);
2487 } else if (child->name() == X_("Processor")) {
2488 processor_state.add_child_copy (*child);
2489 } else if (child->name() == X_("Pannable")) {
2491 _pannable->set_state (*child, version);
2493 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2495 } else if (child->name() == Slavable::xml_node_name) {
2496 Slavable::set_state (*child, version);
2501 if (node.get_property (X_("meter-point"), mp)) {
2502 set_meter_point (mp, true);
2504 _meter->set_display_to_user (_meter_point == MeterCustom);
2509 if (node.get_property (X_("disk-io-point"), diop)) {
2511 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2514 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2516 set_disk_io_point (diop);
2519 node.get_property (X_("meter-type"), _meter_type);
2521 _initial_io_setup = false;
2523 set_processor_state (processor_state);
2525 // this looks up the internal instrument in processors
2526 reset_instrument_info();
2528 bool denormal_protection;
2529 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2530 set_denormal_protection (denormal_protection);
2533 /* convert old 3001 state */
2534 std::string phase_invert_str;
2535 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2536 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2540 if (node.get_property (X_("active"), is_active)) {
2541 set_active (is_active, this);
2544 std::string id_string;
2545 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2546 PBD::ID id (id_string);
2547 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2548 ProcessorList::const_iterator i = _processors.begin ();
2549 while (i != _processors.end() && (*i)->id() != id) {
2553 if (i != _processors.end ()) {
2554 _processor_after_last_custom_meter = *i;
2555 _custom_meter_position_noted = true;
2559 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2562 if (child->name() == X_("Comment")) {
2564 /* XXX this is a terrible API design in libxml++ */
2566 XMLNode *cmt = *(child->children().begin());
2567 _comment = cmt->content();
2569 } else if (child->name() == Controllable::xml_node_name) {
2570 std::string control_name;
2571 if (!child->get_property (X_("name"), control_name)) {
2575 if (control_name == _solo_control->name()) {
2576 _solo_control->set_state (*child, version);
2577 } else if (control_name == _solo_safe_control->name()) {
2578 _solo_safe_control->set_state (*child, version);
2579 } else if (control_name == _solo_isolate_control->name()) {
2580 _solo_isolate_control->set_state (*child, version);
2581 } else if (control_name == _mute_control->name()) {
2582 _mute_control->set_state (*child, version);
2583 } else if (control_name == _phase_control->name()) {
2584 _phase_control->set_state (*child, version);
2586 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2587 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2588 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2590 ac->set_state (*child, version);
2594 } else if (child->name() == MuteMaster::xml_node_name) {
2595 _mute_master->set_state (*child, version);
2597 } else if (child->name() == Automatable::xml_node_name) {
2598 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2606 Route::set_state_2X (const XMLNode& node, int version)
2610 XMLNodeConstIterator niter;
2612 XMLProperty const * prop;
2614 /* 2X things which still remain to be handled:
2620 if (node.name() != "Route") {
2621 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2625 Stripable::set_state (node, version);
2627 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2628 set_denormal_protection (string_to<bool> (prop->value()));
2631 if ((prop = node.property (X_("muted"))) != 0) {
2634 bool muted = string_to<bool> (prop->value());
2640 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2642 if (string_to<bool> (prop->value())){
2643 mute_point = mute_point + "PreFader";
2648 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2650 if (string_to<bool> (prop->value())){
2653 mute_point = mute_point + ",";
2656 mute_point = mute_point + "PostFader";
2661 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2663 if (string_to<bool> (prop->value())){
2666 mute_point = mute_point + ",";
2669 mute_point = mute_point + "Listen";
2674 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2676 if (string_to<bool> (prop->value())){
2679 mute_point = mute_point + ",";
2682 mute_point = mute_point + "Main";
2686 _mute_master->set_mute_points (mute_point);
2687 _mute_master->set_muted_by_self (true);
2691 if ((prop = node.property (X_("meter-point"))) != 0) {
2692 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2697 nlist = node.children ();
2698 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2702 if (child->name() == IO::state_node_name) {
2704 /* there is a note in IO::set_state_2X() about why we have to call
2708 _input->set_state_2X (*child, version, true);
2709 _output->set_state_2X (*child, version, false);
2711 if ((prop = child->property (X_("name"))) != 0) {
2712 Route::set_name (prop->value ());
2717 if ((prop = child->property (X_("active"))) != 0) {
2718 bool yn = string_to<bool> (prop->value());
2719 _active = !yn; // force switch
2720 set_active (yn, this);
2723 if ((prop = child->property (X_("gain"))) != 0) {
2726 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2727 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2731 /* Set up Panners in the IO */
2732 XMLNodeList io_nlist = child->children ();
2734 XMLNodeConstIterator io_niter;
2737 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2739 io_child = *io_niter;
2741 if (io_child->name() == X_("Panner")) {
2742 _main_outs->panner_shell()->set_state(*io_child, version);
2743 } else if (io_child->name() == X_("Automation")) {
2744 /* IO's automation is for the fader */
2745 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2751 XMLNodeList redirect_nodes;
2753 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2757 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2758 redirect_nodes.push_back(child);
2763 set_processor_state_2X (redirect_nodes, version);
2765 Stateful::save_extra_xml (node);
2767 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2770 if (child->name() == X_("Comment")) {
2772 /* XXX this is a terrible API design in libxml++ */
2774 XMLNode *cmt = *(child->children().begin());
2775 _comment = cmt->content();
2777 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2778 if (prop->value() == X_("solo")) {
2779 _solo_control->set_state (*child, version);
2780 } else if (prop->value() == X_("mute")) {
2781 _mute_control->set_state (*child, version);
2791 Route::get_processor_state ()
2793 XMLNode* root = new XMLNode (X_("redirects"));
2794 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2795 root->add_child_nocopy ((*i)->state (true));
2802 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2804 /* We don't bother removing existing processors not in nList, as this
2805 method will only be called when creating a Route from scratch, not
2806 for undo purposes. Just put processors in at the appropriate place
2810 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2811 add_processor_from_xml_2X (**i, version);
2816 Route::set_processor_state (const XMLNode& node)
2818 const XMLNodeList &nlist = node.children();
2819 XMLNodeConstIterator niter;
2820 ProcessorList new_order;
2821 bool must_configure = false;
2823 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2825 XMLProperty* prop = (*niter)->property ("type");
2827 if (prop->value() == "amp") {
2828 _amp->set_state (**niter, Stateful::current_state_version);
2829 new_order.push_back (_amp);
2830 } else if (prop->value() == "trim") {
2831 _trim->set_state (**niter, Stateful::current_state_version);
2832 new_order.push_back (_trim);
2833 } else if (prop->value() == "meter") {
2834 _meter->set_state (**niter, Stateful::current_state_version);
2835 new_order.push_back (_meter);
2836 } else if (prop->value() == "delay") {
2838 _delayline->set_state (**niter, Stateful::current_state_version);
2839 new_order.push_back (_delayline);
2841 } else if (prop->value() == "main-outs") {
2842 _main_outs->set_state (**niter, Stateful::current_state_version);
2843 } else if (prop->value() == "intreturn") {
2845 _intreturn.reset (new InternalReturn (_session));
2846 must_configure = true;
2848 _intreturn->set_state (**niter, Stateful::current_state_version);
2849 } else if (is_monitor() && prop->value() == "monitor") {
2850 if (!_monitor_control) {
2851 _monitor_control.reset (new MonitorProcessor (_session));
2852 must_configure = true;
2854 _monitor_control->set_state (**niter, Stateful::current_state_version);
2855 } else if (prop->value() == "capture") {
2856 /* CapturingProcessor should never be restored, it's always
2857 added explicitly when needed */
2858 } else if (prop->value() == "diskreader" && _disk_reader) {
2859 _disk_reader->set_state (**niter, Stateful::current_state_version);
2860 new_order.push_back (_disk_reader);
2861 } else if (prop->value() == "diskwriter" && _disk_writer) {
2862 _disk_writer->set_state (**niter, Stateful::current_state_version);
2863 new_order.push_back (_disk_writer);
2865 set_processor_state (**niter, prop, new_order, must_configure);
2869 ProcessorList old_list = _processors; // keep a copy
2871 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2872 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2873 /* re-assign _processors w/o process-lock.
2874 * if there's an IO-processor present in _processors but
2875 * not in new_order, it will be deleted and ~IO takes
2878 _processors = new_order;
2880 if (must_configure) {
2881 configure_processors_unlocked (0, &lm);
2884 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2886 (*i)->set_owner (this);
2887 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2889 boost::shared_ptr<PluginInsert> pi;
2891 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2892 if (pi->has_no_inputs ()) {
2893 _have_internal_generator = true;
2899 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2902 reset_instrument_info ();
2903 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2904 set_processor_positions ();
2908 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2910 ProcessorList::iterator o;
2912 for (o = _processors.begin(); o != _processors.end(); ++o) {
2913 XMLProperty const * id_prop = node.property(X_("id"));
2914 if (id_prop && (*o)->id() == id_prop->value()) {
2915 (*o)->set_state (node, Stateful::current_state_version);
2916 new_order.push_back (*o);
2921 // If the processor (node) is not on the route then create it
2923 if (o == _processors.end()) {
2925 boost::shared_ptr<Processor> processor;
2927 if (prop->value() == "intsend") {
2929 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2931 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2932 prop->value() == "lv2" ||
2933 prop->value() == "windows-vst" ||
2934 prop->value() == "mac-vst" ||
2935 prop->value() == "lxvst" ||
2936 prop->value() == "luaproc" ||
2937 prop->value() == "audiounit") {
2939 if (_session.get_disable_all_loaded_plugins ()) {
2940 processor.reset (new UnknownProcessor (_session, node));
2942 processor.reset (new PluginInsert (_session));
2943 processor->set_owner (this);
2945 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
2946 pi->set_strict_io (true);
2950 } else if (prop->value() == "port") {
2952 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2954 } else if (prop->value() == "send") {
2956 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
2957 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
2958 send->SelfDestruct.connect_same_thread (*this,
2959 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
2965 if (processor->set_state (node, Stateful::current_state_version) != 0) {
2966 /* This processor could not be configured. Turn it into a UnknownProcessor */
2967 processor.reset (new UnknownProcessor (_session, node));
2970 /* subscribe to Sidechain IO changes */
2971 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
2972 if (pi && pi->has_sidechain ()) {
2973 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2976 /* we have to note the monitor send here, otherwise a new one will be created
2977 and the state of this one will be lost.
2979 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2980 if (isend && isend->role() == Delivery::Listen) {
2981 _monitor_send = isend;
2984 /* it doesn't matter if invisible processors are added here, as they
2985 will be sorted out by setup_invisible_processors () shortly.
2988 new_order.push_back (processor);
2989 must_configure = true;
2995 Route::curve_reallocate ()
2997 // _gain_automation_curve.finish_resize ();
2998 // _pan_automation_curve.finish_resize ();
3002 Route::silence (samplecnt_t nframes)
3004 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3009 silence_unlocked (nframes);
3013 Route::silence_unlocked (samplecnt_t nframes)
3015 /* Must be called with the processor lock held */
3017 const samplepos_t now = _session.transport_sample ();
3021 _output->silence (nframes);
3023 // update owned automated controllables
3024 automation_run (now, nframes);
3026 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3027 boost::shared_ptr<PluginInsert> pi;
3029 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3030 /* evaluate automated automation controls */
3031 pi->automation_run (now, nframes);
3032 /* skip plugins, they don't need anything when we're not active */
3036 (*i)->silence (nframes, now);
3039 if (nframes == _session.get_block_size()) {
3046 Route::add_internal_return ()
3049 _intreturn.reset (new InternalReturn (_session));
3050 add_processor (_intreturn, PreFader);
3055 Route::add_send_to_internal_return (InternalSend* send)
3057 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3059 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3060 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3063 return d->add_send (send);
3069 Route::remove_send_from_internal_return (InternalSend* send)
3071 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3073 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3074 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3077 return d->remove_send (send);
3083 Route::enable_monitor_send ()
3085 /* Caller must hold process lock */
3086 assert (!AudioEngine::instance()->process_lock().trylock());
3088 /* master never sends to monitor section via the normal mechanism */
3089 assert (!is_master ());
3090 assert (!is_monitor ());
3092 /* make sure we have one */
3093 if (!_monitor_send) {
3094 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3095 _monitor_send->set_display_to_user (false);
3099 configure_processors (0);
3102 /** Add an aux send to a route.
3103 * @param route route to send to.
3104 * @param before Processor to insert before, or 0 to insert at the end.
3107 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3109 assert (route != _session.monitor_out ());
3112 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3114 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3116 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3118 if (d && d->target_route() == route) {
3119 /* already listening via the specified IO: do nothing */
3127 boost::shared_ptr<InternalSend> listener;
3130 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3131 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3134 add_processor (listener, before);
3136 } catch (failed_constructor& err) {
3144 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3146 ProcessorStreams err;
3147 ProcessorList::iterator tmp;
3150 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3152 /* have to do this early because otherwise processor reconfig
3153 * will put _monitor_send back in the list
3156 if (route == _session.monitor_out()) {
3157 _monitor_send.reset ();
3161 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3163 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3165 if (d && d->target_route() == route) {
3167 if (remove_processor (*x, &err, false) > 0) {
3173 /* list could have been demolished while we dropped the lock
3176 if (_session.engine().connected()) {
3177 /* i/o processors cannot be removed if the engine is not running
3178 * so don't live-loop in case the engine is N/A or dies
3188 Route::set_comment (string cmt, void *src)
3192 _session.set_dirty ();
3196 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3198 FeedRecord fr (other, via_sends_only);
3200 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3202 if (!result.second) {
3204 /* already a record for "other" - make sure sends-only information is correct */
3205 if (!via_sends_only && result.first->sends_only) {
3206 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3207 frp->sends_only = false;
3211 return result.second;
3215 Route::clear_fed_by ()
3221 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3223 const FedBy& fed_by (other->fed_by());
3225 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3226 boost::shared_ptr<Route> sr = f->r.lock();
3228 if (sr && (sr.get() == this)) {
3230 if (via_sends_only) {
3231 *via_sends_only = f->sends_only;
3242 Route::all_inputs () const
3244 /* TODO, if this works as expected,
3245 * cache the IOVector and maintain it via
3246 * input_change_handler(), sidechain_change_handler() etc
3249 ios.push_back (_input);
3251 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3252 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3254 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3255 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3258 iop = pi->sidechain();
3261 if (iop != 0 && iop->input()) {
3262 ios.push_back (iop->input());
3269 Route::all_outputs () const
3272 // _output is included via Delivery
3273 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3274 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3275 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3276 if (iop != 0 && iop->output()) {
3277 ios.push_back (iop->output());
3284 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3286 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3287 if (other->all_inputs().fed_by (_output)) {
3288 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3289 if (via_send_only) {
3290 *via_send_only = false;
3296 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3298 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3300 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3301 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3304 iop = pi->sidechain();
3308 boost::shared_ptr<const IO> iop_out = iop->output();
3309 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3310 // TODO this needs a delaylines in the Insert to align connections (!)
3311 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3314 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3315 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3316 if (via_send_only) {
3317 *via_send_only = true;
3321 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3324 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3329 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3334 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3336 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3340 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3342 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3345 /** Called from the (non-realtime) butler thread when the transport is stopped */
3347 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3350 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3352 Automatable::non_realtime_transport_stop (now, flush);
3354 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3356 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3360 (*i)->non_realtime_transport_stop (now, flush);
3366 Route::input_change_handler (IOChange change, void * /*src*/)
3368 if ((change.type & IOChange::ConfigurationChanged)) {
3369 /* This is called with the process lock held if change
3370 contains ConfigurationChanged
3372 configure_processors (0);
3373 _phase_control->resize (_input->n_ports().n_audio ());
3374 io_changed (); /* EMIT SIGNAL */
3377 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3380 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3381 if (_input->connected()) {
3382 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3383 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3387 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3388 if (does_feed && !sends_only) {
3389 if ((*i)->soloed()) {
3392 if ((*i)->solo_isolate_control()->solo_isolated()) {
3399 int delta = sbou - _solo_control->soloed_by_others_upstream();
3400 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3403 PBD::warning << string_compose (
3404 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3405 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3410 if (_solo_control->soloed_by_others_upstream()) {
3411 // ignore new connections (they're not propagated)
3413 _solo_control->mod_solo_by_others_upstream (delta);
3417 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3418 // solo-isolate currently only propagates downstream
3420 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3422 //_solo_isolated_by_upstream = ibou;
3425 // Session::route_solo_changed does not propagate indirect solo-changes
3426 // propagate downstream to tracks
3427 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3428 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3432 bool does_feed = feeds (*i, &sends_only);
3433 if (delta <= 0 && does_feed && !sends_only) {
3434 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3437 if (idelta < 0 && does_feed && !sends_only) {
3438 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3445 Route::output_change_handler (IOChange change, void * /*src*/)
3447 if (_initial_io_setup) {
3451 if ((change.type & IOChange::ConfigurationChanged)) {
3452 /* This is called with the process lock held if change
3453 contains ConfigurationChanged
3455 configure_processors (0);
3458 _session.reset_monitor_section();
3461 io_changed (); /* EMIT SIGNAL */
3464 if ((change.type & IOChange::ConnectionsChanged)) {
3466 /* do this ONLY if connections have changed. Configuration
3467 * changes do not, by themselves alter solo upstream or
3468 * downstream status.
3471 if (_solo_control->soloed_by_others_downstream()) {
3473 /* checking all all downstream routes for
3474 * explicit of implict solo is a rather drastic measure,
3475 * ideally the input_change_handler() of the other route
3476 * would propagate the change to us.
3478 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3479 if (_output->connected()) {
3480 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3481 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3485 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3486 if (does_feed && !sends_only) {
3487 if ((*i)->soloed()) {
3495 int delta = sbod - _solo_control->soloed_by_others_downstream();
3497 // do not allow new connections to change implicit solo (no propagation)
3498 _solo_control->mod_solo_by_others_downstream (delta);
3499 // Session::route_solo_changed() does not propagate indirect solo-changes
3500 // propagate upstream to tracks
3501 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3502 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3503 if ((*i).get() == this || !can_solo()) {
3507 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3508 if (delta != 0 && does_feed && !sends_only) {
3509 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3519 Route::sidechain_change_handler (IOChange change, void* src)
3521 if (_initial_io_setup || _in_sidechain_setup) {
3525 input_change_handler (change, src);
3529 Route::pans_required () const
3531 if (n_outputs().n_audio() < 2) {
3535 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3539 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3541 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3542 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3544 d->flush_buffers (nframes);
3546 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3548 p->flush_buffers (nframes);
3555 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3557 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3564 silence_unlocked (nframes);
3568 if (session_state_changing) {
3569 if (_session.transport_speed() != 0.0f) {
3570 /* we're rolling but some state is changing (e.g. our diskstream contents)
3571 so we cannot use them. Be silent till this is over.
3573 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3575 silence_unlocked (nframes);
3578 /* we're really not rolling, so we're either delivery silence or actually
3579 monitoring, both of which are safe to do while session_state_changing is true.
3583 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3585 fill_buffers_with_input (bufs, _input, nframes);
3587 if (_meter_point == MeterInput) {
3588 _meter->run (bufs, start_sample, end_sample, 0.0, nframes, true);
3591 passthru (bufs, start_sample, end_sample, nframes, 0, true);
3593 flush_processor_buffers_locked (nframes);
3599 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3601 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3608 silence_unlocked (nframes);
3609 if (_meter_point == MeterInput && ((_monitoring_control->monitoring_choice() & MonitorInput) || (!_disk_writer || _disk_writer->record_enabled()))) {
3617 BufferSet& bufs = _session.get_route_buffers (n_process_buffers ());
3619 fill_buffers_with_input (bufs, _input, nframes);
3621 /* filter captured data before meter sees it */
3622 filter_input (bufs);
3624 if (_meter_point == MeterInput &&
3625 ((_monitoring_control->monitoring_choice() & MonitorInput) || (_disk_writer && _disk_writer->record_enabled()))) {
3626 _meter->run (bufs, start_sample, end_sample, 1.0 /*speed()*/, nframes, true);
3629 passthru (bufs, start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling());
3631 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3635 flush_processor_buffers_locked (nframes);
3641 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3644 flush_processor_buffers_locked (nframes);
3649 Route::flush_processors ()
3651 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3653 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3659 __attribute__((annotate("realtime")))
3662 Route::apply_processor_changes_rt ()
3664 int emissions = EmitNone;
3666 if (_pending_meter_point != _meter_point) {
3667 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3669 /* meters always have buffers for 'processor_max_streams'
3670 * they can be re-positioned without re-allocation */
3671 if (set_meter_point_unlocked()) {
3672 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3674 emissions |= EmitMeterChanged;
3679 bool changed = false;
3681 if (g_atomic_int_get (&_pending_process_reorder)) {
3682 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3684 apply_processor_order (_pending_processor_order);
3685 setup_invisible_processors ();
3687 g_atomic_int_set (&_pending_process_reorder, 0);
3688 emissions |= EmitRtProcessorChange;
3692 set_processor_positions ();
3693 /* update processor input/output latency
3694 * (total signal_latency does not change)
3696 update_signal_latency (true);
3698 if (emissions != 0) {
3699 g_atomic_int_set (&_pending_signals, emissions);
3702 return (!selfdestruct_sequence.empty ());
3706 Route::emit_pending_signals ()
3708 int sig = g_atomic_int_and (&_pending_signals, 0);
3709 if (sig & EmitMeterChanged) {
3710 _meter->emit_configuration_changed();
3711 meter_change (); /* EMIT SIGNAL */
3712 if (sig & EmitMeterVisibilityChange) {
3713 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3715 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3718 if (sig & EmitRtProcessorChange) {
3719 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3722 /* this would be a job for the butler.
3723 * Conceptually we should not take processe/processor locks here.
3724 * OTOH its more efficient (less overhead for summoning the butler and
3725 * telling her what do do) and signal emission is called
3726 * directly after the process callback, which decreases the chance
3727 * of x-runs when taking the locks.
3729 while (!selfdestruct_sequence.empty ()) {
3730 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3731 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3732 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3733 selfdestruct_sequence.pop_back ();
3736 remove_processor (proc);
3742 Route::set_meter_point (MeterPoint p, bool force)
3744 if (_pending_meter_point == p && !force) {
3748 if (force || !AudioEngine::instance()->running()) {
3749 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3750 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3751 _pending_meter_point = p;
3752 _meter->emit_configuration_changed();
3753 meter_change (); /* EMIT SIGNAL */
3754 if (set_meter_point_unlocked()) {
3755 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3757 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3760 _pending_meter_point = p;
3766 __attribute__((annotate("realtime")))
3769 Route::set_meter_point_unlocked ()
3772 /* Caller must hold process and processor write lock */
3773 assert (!AudioEngine::instance()->process_lock().trylock());
3774 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3775 assert (!lm.locked ());
3778 _meter_point = _pending_meter_point;
3780 bool meter_was_visible_to_user = _meter->display_to_user ();
3782 if (!_custom_meter_position_noted) {
3783 maybe_note_meter_position ();
3786 if (_meter_point != MeterCustom) {
3788 _meter->set_display_to_user (false);
3790 setup_invisible_processors ();
3793 _meter->set_display_to_user (true);
3795 /* If we have a previous position for the custom meter, try to put it there */
3796 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3798 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3799 if (i != _processors.end ()) {
3800 _processors.remove (_meter);
3801 _processors.insert (i, _meter);
3803 } else {// at end, right before the mains_out/panner
3804 _processors.remove (_meter);
3805 ProcessorList::iterator main = _processors.end();
3806 _processors.insert (--main, _meter);
3810 /* Set up the meter for its new position */
3812 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3816 if (loc == _processors.begin()) {
3817 m_in = _input->n_ports();
3819 ProcessorList::iterator before = loc;
3821 m_in = (*before)->output_streams ();
3824 _meter->reflect_inputs (m_in);
3826 /* we do not need to reconfigure the processors, because the meter
3827 (a) is always ready to handle processor_max_streams
3828 (b) is always an N-in/N-out processor, and thus moving
3829 it doesn't require any changes to the other processors.
3832 /* these should really be done after releasing the lock
3833 * but all those signals are subscribed to with gui_thread()
3836 return (_meter->display_to_user() != meter_was_visible_to_user);
3840 Route::listen_position_changed ()
3843 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3844 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3845 ProcessorState pstate (this);
3847 if (configure_processors_unlocked (0, &lm)) {
3848 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3850 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3855 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3856 _session.set_dirty ();
3859 boost::shared_ptr<CapturingProcessor>
3860 Route::add_export_point()
3862 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3863 if (!_capturing_processor) {
3865 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3866 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3868 // this aligns all tracks; but not tracks + busses
3869 samplecnt_t latency = _session.worst_track_out_latency (); // FIXME
3870 assert (latency >= _initial_delay);
3871 _capturing_processor.reset (new CapturingProcessor (_session, latency - _initial_delay));
3872 _capturing_processor->activate ();
3874 configure_processors_unlocked (0, &lw);
3878 return _capturing_processor;
3882 Route::update_signal_latency (bool set_initial_delay)
3884 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3886 samplecnt_t l_in = _input->latency ();
3887 samplecnt_t l_out = _output->user_latency();
3889 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3890 if ((*i)->active ()) {
3891 l_in += (*i)->signal_latency ();
3893 (*i)->set_input_latency (l_in);
3896 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
3897 (*i)->set_output_latency (l_out);
3898 if ((*i)->active ()) {
3899 l_out += (*i)->signal_latency ();
3903 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
3905 _signal_latency = l_out;
3909 if (set_initial_delay) {
3910 /* see also Session::post_playback_latency() */
3911 set_latency_compensation (_session.worst_track_latency () + _session.worst_track_out_latency () - output ()->latency ());
3914 if (_signal_latency != l_out) {
3915 signal_latency_changed (); /* EMIT SIGNAL */
3918 return _signal_latency;
3922 Route::set_user_latency (samplecnt_t nframes)
3924 _output->set_user_latency (nframes);
3925 _session.update_latency_compensation ();
3929 Route::set_latency_compensation (samplecnt_t longest_session_latency)
3931 samplecnt_t old = _initial_delay;
3932 assert (!_disk_reader || _disk_reader->output_latency () <= _signal_latency);
3934 if (_disk_reader && _disk_reader->output_latency () < longest_session_latency) {
3935 _initial_delay = longest_session_latency - _disk_reader->output_latency ();
3940 DEBUG_TRACE (DEBUG::Latency, string_compose (
3941 "%1: compensate for maximum latency of %2,"
3942 "given own latency of %3, using initial delay of %4\n",
3943 name(), longest_session_latency, _signal_latency, _initial_delay));
3945 if (_initial_delay != old) {
3946 initial_delay_changed (); /* EMIT SIGNAL */
3952 Route::set_block_size (pframes_t nframes)
3954 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3955 (*i)->set_block_size (nframes);
3958 _session.ensure_buffers (n_process_buffers ());
3962 Route::protect_automation ()
3964 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3965 (*i)->protect_automation();
3968 /** @param declick 1 to set a pending declick fade-in,
3969 * -1 to set a pending declick fade-out
3972 Route::set_pending_declick (int declick)
3975 /* this call is not allowed to turn off a pending declick */
3977 _pending_declick = declick;
3980 _pending_declick = 0;
3984 /** Shift automation forwards from a particular place, thereby inserting time.
3985 * Adds undo commands for any shifts that are performed.
3987 * @param pos Position to start shifting from.
3988 * @param samples Amount to shift forwards by.
3992 Route::shift (samplepos_t pos, samplecnt_t samples)
3994 /* gain automation */
3996 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3998 XMLNode &before = gc->alist()->get_state ();
3999 gc->alist()->shift (pos, samples);
4000 XMLNode &after = gc->alist()->get_state ();
4001 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4004 /* gain automation */
4006 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4008 XMLNode &before = gc->alist()->get_state ();
4009 gc->alist()->shift (pos, samples);
4010 XMLNode &after = gc->alist()->get_state ();
4011 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4014 // TODO mute automation ??
4016 /* pan automation */
4018 ControlSet::Controls& c (_pannable->controls());
4020 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4021 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4023 boost::shared_ptr<AutomationList> al = pc->alist();
4024 XMLNode& before = al->get_state ();
4025 al->shift (pos, samples);
4026 XMLNode& after = al->get_state ();
4027 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4032 /* redirect automation */
4034 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4035 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4037 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4039 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4040 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4042 boost::shared_ptr<AutomationList> al = ac->alist();
4043 XMLNode &before = al->get_state ();
4044 al->shift (pos, samples);
4045 XMLNode &after = al->get_state ();
4046 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4054 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4056 boost::shared_ptr<Processor> processor (p.lock ());
4057 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4061 pi->set_state_dir (d);
4065 Route::save_as_template (const string& path, const string& name, const string& description)
4067 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4068 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4070 XMLNode& node (state (false));
4071 node.set_property (X_("name"), name);
4073 node.remove_nodes (X_("description"));
4074 if (!description.empty()) {
4075 XMLNode* desc = new XMLNode(X_("description"));
4076 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4077 desc->add_child_nocopy (*desc_cont);
4079 node.add_child_nocopy (*desc);
4084 IO::set_name_in_state (*node.children().front(), name);
4086 tree.set_root (&node);
4088 /* return zero on success, non-zero otherwise */
4089 return !tree.write (path.c_str());
4094 Route::set_name (const string& str)
4100 if (str == name()) {
4104 string name = Route::ensure_track_or_route_name (str, _session);
4105 SessionObject::set_name (name);
4107 bool ret = (_input->set_name(name) && _output->set_name(name));
4110 /* rename the main outs. Leave other IO processors
4111 * with whatever name they already have, because its
4112 * just fine as it is (it will not contain the route
4113 * name if its a port insert, port send or port return).
4117 if (_main_outs->set_name (name)) {
4118 /* XXX returning false here is stupid because
4119 we already changed the route name.
4129 /** Set the name of a route in an XML description.
4130 * @param node XML <Route> node to set the name in.
4131 * @param name New name.
4134 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4136 node.set_property (X_("name"), name);
4138 XMLNodeList children = node.children();
4139 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4141 if ((*i)->name() == X_("IO")) {
4143 IO::set_name_in_state (**i, name);
4145 } else if ((*i)->name() == X_("Processor")) {
4148 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4149 (*i)->set_property (X_("name"), name);
4152 } else if ((*i)->name() == X_("Diskstream")) {
4154 if (rename_playlist) {
4155 (*i)->set_property (X_("playlist"), name + ".1");
4157 (*i)->set_property (X_("name"), name);
4163 boost::shared_ptr<Send>
4164 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4166 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4168 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4169 boost::shared_ptr<InternalSend> send;
4171 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4172 if (send->target_route() == target) {
4178 return boost::shared_ptr<Send>();
4182 Route::set_denormal_protection (bool yn)
4184 if (_denormal_protection != yn) {
4185 _denormal_protection = yn;
4186 denormal_protection_changed (); /* EMIT SIGNAL */
4191 Route::denormal_protection () const
4193 return _denormal_protection;
4197 Route::set_active (bool yn, void* src)
4199 if (_session.transport_rolling()) {
4203 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4204 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4208 if (_active != yn) {
4210 _input->set_active (yn);
4211 _output->set_active (yn);
4212 flush_processors ();
4213 active_changed (); // EMIT SIGNAL
4214 _session.set_dirty ();
4218 boost::shared_ptr<Pannable>
4219 Route::pannable() const
4224 boost::shared_ptr<Panner>
4225 Route::panner() const
4228 return _main_outs->panner_shell()->panner();
4231 boost::shared_ptr<PannerShell>
4232 Route::panner_shell() const
4234 return _main_outs->panner_shell();
4237 boost::shared_ptr<GainControl>
4238 Route::gain_control() const
4240 return _gain_control;
4243 boost::shared_ptr<GainControl>
4244 Route::trim_control() const
4246 return _trim_control;
4249 boost::shared_ptr<PhaseControl>
4250 Route::phase_control() const
4252 return _phase_control;
4255 boost::shared_ptr<AutomationControl>
4256 Route::get_control (const Evoral::Parameter& param)
4258 /* either we own the control or .... */
4260 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4264 /* maybe one of our processors does or ... */
4266 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4267 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4268 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4276 /* nobody does so we'll make a new one */
4278 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4285 boost::shared_ptr<Processor>
4286 Route::nth_plugin (uint32_t n) const
4288 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4289 ProcessorList::const_iterator i;
4291 for (i = _processors.begin(); i != _processors.end(); ++i) {
4292 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4299 return boost::shared_ptr<Processor> ();
4302 boost::shared_ptr<Processor>
4303 Route::nth_send (uint32_t n) const
4305 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4306 ProcessorList::const_iterator i;
4308 for (i = _processors.begin(); i != _processors.end(); ++i) {
4309 if (boost::dynamic_pointer_cast<Send> (*i)) {
4311 if ((*i)->name().find (_("Monitor")) == 0) {
4312 /* send to monitor section is not considered
4313 to be an accessible send.
4324 return boost::shared_ptr<Processor> ();
4328 Route::has_io_processor_named (const string& name)
4330 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4331 ProcessorList::iterator i;
4333 for (i = _processors.begin(); i != _processors.end(); ++i) {
4334 if (boost::dynamic_pointer_cast<Send> (*i) ||
4335 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4336 if ((*i)->name() == name) {
4346 Route::set_processor_positions ()
4348 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4350 bool had_amp = false;
4351 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4352 (*i)->set_pre_fader (!had_amp);
4359 /** Called when there is a proposed change to the input port count */
4361 Route::input_port_count_changing (ChanCount to)
4363 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4365 /* The processors cannot be configured with the new input arrangement, so
4371 /* The change is ok */
4375 /** Called when there is a proposed change to the output port count */
4377 Route::output_port_count_changing (ChanCount to)
4379 if (_strict_io && !_in_configure_processors) {
4382 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4383 if (processor_out_streams.get(*t) > to.get(*t)) {
4387 /* The change is ok */
4392 Route::unknown_processors () const
4396 if (_session.get_disable_all_loaded_plugins ()) {
4397 // Do not list "missing plugins" if they are explicitly disabled
4401 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4402 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4403 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4404 p.push_back ((*i)->name ());
4413 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4415 /* we assume that all our input ports feed all our output ports. its not
4416 universally true, but the alternative is way too corner-case to worry about.
4419 LatencyRange all_connections;
4422 all_connections.min = 0;
4423 all_connections.max = 0;
4425 all_connections.min = ~((pframes_t) 0);
4426 all_connections.max = 0;
4428 /* iterate over all "from" ports and determine the latency range for all of their
4429 connections to the "outside" (outside of this Route).
4432 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4436 p->get_connected_latency_range (range, playback);
4438 all_connections.min = min (all_connections.min, range.min);
4439 all_connections.max = max (all_connections.max, range.max);
4443 /* set the "from" port latencies to the max/min range of all their connections */
4445 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4446 p->set_private_latency_range (all_connections, playback);
4449 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4451 all_connections.min += our_latency;
4452 all_connections.max += our_latency;
4454 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4455 p->set_private_latency_range (all_connections, playback);
4458 return all_connections.max;
4462 Route::set_private_port_latencies (bool playback) const
4464 samplecnt_t own_latency = 0;
4466 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4467 OR LATENCY CALLBACK.
4469 This is called (early) from the latency callback. It computes the REAL
4470 latency associated with each port and stores the result as the "private"
4471 latency of the port. A later call to Route::set_public_port_latencies()
4472 sets all ports to the same value to reflect the fact that we do latency
4473 compensation and so all signals are delayed by the same amount as they
4474 flow through ardour.
4477 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4478 if ((*i)->active ()) {
4479 own_latency += (*i)->signal_latency ();
4484 /* playback: propagate latency from "outside the route" to outputs to inputs */
4485 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4487 /* capture: propagate latency from "outside the route" to inputs to outputs */
4488 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4493 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4495 /* this is called to set the JACK-visible port latencies, which take
4496 latency compensation into account.
4505 const PortSet& ports (_input->ports());
4506 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4507 p->set_public_latency_range (range, playback);
4512 const PortSet& ports (_output->ports());
4513 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4514 p->set_public_latency_range (range, playback);
4519 /** Put the invisible processors in the right place in _processors.
4520 * Must be called with a writer lock on _processor_lock held.
4523 __attribute__((annotate("realtime")))
4526 Route::setup_invisible_processors ()
4529 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4530 assert (!lm.locked ());
4534 /* too early to be doing this stuff */
4538 /* we'll build this new list here and then use it
4540 * TODO put the ProcessorList is on the stack for RT-safety.
4543 ProcessorList new_processors;
4544 ProcessorList::iterator dr;
4545 ProcessorList::iterator dw;
4547 /* find visible processors */
4549 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4550 if ((*i)->display_to_user ()) {
4551 new_processors.push_back (*i);
4557 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4559 if (amp == new_processors.end ()) {
4560 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4561 new_processors.push_front (_amp);
4562 amp = find (new_processors.begin(), new_processors.end(), _amp);
4565 /* and the processor after the amp */
4567 ProcessorList::iterator after_amp = amp;
4573 switch (_meter_point) {
4575 assert (!_meter->display_to_user ());
4576 new_processors.push_front (_meter);
4579 assert (!_meter->display_to_user ());
4580 new_processors.insert (amp, _meter);
4582 case MeterPostFader:
4583 /* do nothing here */
4586 /* do nothing here */
4589 /* the meter is visible, so we don't touch it here */
4596 assert (_main_outs);
4597 assert (!_main_outs->display_to_user ());
4598 new_processors.push_back (_main_outs);
4600 /* iterator for the main outs */
4602 ProcessorList::iterator main = new_processors.end();
4605 /* OUTPUT METERING */
4607 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4608 assert (!_meter->display_to_user ());
4610 /* add the processor just before or just after the main outs */
4612 ProcessorList::iterator meter_point = main;
4614 if (_meter_point == MeterOutput) {
4617 new_processors.insert (meter_point, _meter);
4622 if (_monitor_send && !is_monitor ()) {
4623 assert (!_monitor_send->display_to_user ());
4624 switch (Config->get_listen_position ()) {
4625 case PreFaderListen:
4626 switch (Config->get_pfl_position ()) {
4627 case PFLFromBeforeProcessors:
4628 new_processors.push_front (_monitor_send);
4630 case PFLFromAfterProcessors:
4631 new_processors.insert (amp, _monitor_send);
4634 _monitor_send->set_can_pan (false);
4636 case AfterFaderListen:
4637 switch (Config->get_afl_position ()) {
4638 case AFLFromBeforeProcessors:
4639 new_processors.insert (after_amp, _monitor_send);
4641 case AFLFromAfterProcessors:
4642 new_processors.insert (new_processors.end(), _monitor_send);
4645 _monitor_send->set_can_pan (true);
4650 #if 0 // not used - just yet
4651 if (!is_master() && !is_monitor() && !is_auditioner()) {
4652 new_processors.push_front (_delayline);
4656 /* MONITOR CONTROL */
4658 if (_monitor_control && is_monitor ()) {
4659 assert (!_monitor_control->display_to_user ());
4660 new_processors.insert (amp, _monitor_control);
4665 ProcessorList::iterator trim = new_processors.end();
4667 if (_trim->active()) {
4668 assert (!_trim->display_to_user ());
4669 new_processors.push_front (_trim);
4670 trim = new_processors.begin();
4673 /* INTERNAL RETURN */
4675 /* doing this here means that any monitor control will come after
4676 the return and trim.
4680 assert (!_intreturn->display_to_user ());
4681 new_processors.push_front (_intreturn);
4684 /* DISK READER & WRITER (for Track objects) */
4686 if (_disk_reader || _disk_writer) {
4687 switch (_disk_io_point) {
4688 case DiskIOPreFader:
4689 if (trim != new_processors.end()) {
4690 /* insert BEFORE TRIM */
4692 new_processors.insert (trim, _disk_writer);
4695 new_processors.insert (trim, _disk_reader);
4699 new_processors.push_front (_disk_writer);
4702 new_processors.push_front (_disk_reader);
4706 case DiskIOPostFader:
4707 /* insert BEFORE main outs */
4709 new_processors.insert (main, _disk_writer);
4712 new_processors.insert (main, _disk_reader);
4716 /* reader and writer are visible under this condition, so they
4717 * are not invisible and thus not handled here.
4723 /* ensure dist-writer is before disk-reader */
4724 if (_disk_reader && _disk_writer) {
4725 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4726 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4727 assert (reader_pos != new_processors.end ());
4728 assert (writer_pos != new_processors.end ());
4729 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4730 new_processors.erase (reader_pos);
4731 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4732 new_processors.insert (++writer_pos, _disk_reader);
4737 /* EXPORT PROCESSOR */
4738 if (_capturing_processor) {
4739 assert (!_capturing_processor->display_to_user ());
4740 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4741 if (reader_pos != new_processors.end()) {
4742 /* insert after disk-reader */
4743 new_processors.insert (++reader_pos, _capturing_processor);
4745 new_processors.push_front (_capturing_processor);
4750 _processors = new_processors;
4752 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4753 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4754 (*i)->enable (true);
4758 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4759 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4760 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4767 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4768 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4772 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4773 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4780 /** If the meter point is `Custom', make a note of where the meter is.
4781 * This is so that if the meter point is subsequently set to something else,
4782 * and then back to custom, we can put the meter back where it was last time
4783 * custom was enabled.
4785 * Must be called with the _processor_lock held.
4788 Route::maybe_note_meter_position ()
4790 if (_meter_point != MeterCustom) {
4794 _custom_meter_position_noted = true;
4795 /* custom meter points range from after trim to before panner/main_outs
4796 * this is a limitation by the current processor UI
4798 bool seen_trim = false;
4799 _processor_after_last_custom_meter.reset();
4800 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4801 if ((*i) == _trim) {
4804 if ((*i) == _main_outs) {
4805 _processor_after_last_custom_meter = *i;
4808 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4810 _processor_after_last_custom_meter = _trim;
4812 ProcessorList::iterator j = i;
4814 assert(j != _processors.end ()); // main_outs should be before
4815 _processor_after_last_custom_meter = *j;
4820 assert(_processor_after_last_custom_meter.lock());
4823 boost::shared_ptr<Processor>
4824 Route::processor_by_id (PBD::ID id) const
4826 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4827 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4828 if ((*i)->id() == id) {
4833 return boost::shared_ptr<Processor> ();
4836 /** @return what we should be metering; either the data coming from the input
4837 * IO or the data that is flowing through the route.
4840 Route::metering_state () const
4842 return MeteringRoute;
4846 Route::has_external_redirects () const
4848 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4850 /* ignore inactive processors and obviously ignore the main
4851 * outs since everything has them and we don't care.
4854 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4862 boost::shared_ptr<Processor>
4863 Route::the_instrument () const
4865 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4866 return the_instrument_unlocked ();
4869 boost::shared_ptr<Processor>
4870 Route::the_instrument_unlocked () const
4872 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4873 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4874 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4878 return boost::shared_ptr<Processor>();
4884 Route::non_realtime_locate (samplepos_t pos)
4886 Automatable::non_realtime_locate (pos);
4889 _pannable->non_realtime_locate (pos);
4892 if (_delayline.get()) {
4893 _delayline.get()->flush();
4897 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4898 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4900 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4901 (*i)->non_realtime_locate (pos);
4907 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4914 * We don't currently mix MIDI input together, so we don't need the
4915 * complex logic of the audio case.
4918 n_buffers = bufs.count().n_midi ();
4920 for (i = 0; i < n_buffers; ++i) {
4922 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4923 MidiBuffer& buf (bufs.get_midi (i));
4926 buf.copy (source_port->get_midi_buffer(nframes));
4928 buf.silence (nframes);
4934 n_buffers = bufs.count().n_audio();
4936 size_t n_ports = io->n_ports().n_audio();
4937 float scaling = 1.0f;
4939 if (n_ports > n_buffers) {
4940 scaling = ((float) n_buffers) / n_ports;
4943 for (i = 0; i < n_ports; ++i) {
4945 /* if there are more ports than buffers, map them onto buffers
4946 * in a round-robin fashion
4949 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4950 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4952 if (i < n_buffers) {
4954 /* first time through just copy a channel into
4958 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4960 if (scaling != 1.0f) {
4961 buf.apply_gain (scaling, nframes);
4966 /* on subsequent times around, merge data from
4967 * the port with what is already there
4970 if (scaling != 1.0f) {
4971 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4973 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4978 /* silence any remaining buffers */
4980 for (; i < n_buffers; ++i) {
4981 AudioBuffer& buf (bufs.get_audio (i));
4982 buf.silence (nframes);
4985 /* establish the initial setup of the buffer set, reflecting what was
4986 copied into it. unless, of course, we are the auditioner, in which
4987 case nothing was fed into it from the inputs at all.
4990 if (!is_auditioner()) {
4991 bufs.set_count (io->n_ports());
4995 boost::shared_ptr<AutomationControl>
4996 Route::pan_azimuth_control() const
4999 # undef MIXBUS_PORTS_H
5000 # include "../../gtk2_ardour/mixbus_ports.h"
5001 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5003 return boost::shared_ptr<AutomationControl>();
5005 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5007 if (!_pannable || !panner()) {
5008 return boost::shared_ptr<AutomationControl>();
5010 return _pannable->pan_azimuth_control;
5014 boost::shared_ptr<AutomationControl>
5015 Route::pan_elevation_control() const
5017 if (Profile->get_mixbus() || !_pannable || !panner()) {
5018 return boost::shared_ptr<AutomationControl>();
5021 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5023 if (c.find (PanElevationAutomation) != c.end()) {
5024 return _pannable->pan_elevation_control;
5026 return boost::shared_ptr<AutomationControl>();
5029 boost::shared_ptr<AutomationControl>
5030 Route::pan_width_control() const
5033 if (mixbus() && _ch_pre) {
5035 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
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 (PanWidthAutomation) != c.end()) {
5045 return _pannable->pan_width_control;
5047 return boost::shared_ptr<AutomationControl>();
5050 boost::shared_ptr<AutomationControl>
5051 Route::pan_frontback_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 (PanFrontBackAutomation) != c.end()) {
5060 return _pannable->pan_frontback_control;
5062 return boost::shared_ptr<AutomationControl>();
5065 boost::shared_ptr<AutomationControl>
5066 Route::pan_lfe_control() const
5068 if (Profile->get_mixbus() || !_pannable || !panner()) {
5069 return boost::shared_ptr<AutomationControl>();
5072 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5074 if (c.find (PanLFEAutomation) != c.end()) {
5075 return _pannable->pan_lfe_control;
5077 return boost::shared_ptr<AutomationControl>();
5082 Route::eq_band_cnt () const
5084 if (Profile->get_mixbus()) {
5086 if (is_master() || mixbus()) {
5095 /* Ardour has no well-known EQ object */
5100 boost::shared_ptr<AutomationControl>
5101 Route::eq_gain_controllable (uint32_t band) const
5104 boost::shared_ptr<PluginInsert> eq = ch_eq();
5107 return boost::shared_ptr<AutomationControl>();
5110 uint32_t port_number;
5111 if (is_master() || mixbus()) {
5113 case 0: port_number = 4; break;
5114 case 1: port_number = 3; break;
5115 case 2: port_number = 2; break;
5117 return boost::shared_ptr<AutomationControl>();
5122 case 0: port_number = 14; break;
5123 case 1: port_number = 12; break;
5124 case 2: port_number = 10; break;
5125 case 3: port_number = 8; break;
5127 return boost::shared_ptr<AutomationControl>();
5131 case 0: port_number = 8; break;
5132 case 1: port_number = 6; break;
5133 case 2: port_number = 4; break;
5135 return boost::shared_ptr<AutomationControl>();
5140 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5142 return boost::shared_ptr<AutomationControl>();
5145 boost::shared_ptr<AutomationControl>
5146 Route::eq_freq_controllable (uint32_t band) const
5149 if (mixbus() || is_master()) {
5150 /* no frequency controls for mixbusses or master */
5151 return boost::shared_ptr<AutomationControl>();
5154 boost::shared_ptr<PluginInsert> eq = ch_eq();
5157 return boost::shared_ptr<AutomationControl>();
5160 uint32_t port_number;
5163 case 0: port_number = 13; break; // lo
5164 case 1: port_number = 11; break; // lo mid
5165 case 2: port_number = 9; break; // hi mid
5166 case 3: port_number = 7; break; // hi
5168 return boost::shared_ptr<AutomationControl>();
5172 case 0: port_number = 7; break;
5173 case 1: port_number = 5; break;
5174 case 2: port_number = 3; break;
5176 return boost::shared_ptr<AutomationControl>();
5180 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5182 return boost::shared_ptr<AutomationControl>();
5186 boost::shared_ptr<AutomationControl>
5187 Route::eq_q_controllable (uint32_t band) const
5189 return boost::shared_ptr<AutomationControl>();
5192 boost::shared_ptr<AutomationControl>
5193 Route::eq_shape_controllable (uint32_t band) const
5196 boost::shared_ptr<PluginInsert> eq = ch_eq();
5197 if (is_master() || mixbus() || !eq) {
5198 return boost::shared_ptr<AutomationControl>();
5202 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5205 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5211 return boost::shared_ptr<AutomationControl>();
5214 boost::shared_ptr<AutomationControl>
5215 Route::eq_enable_controllable () const
5218 boost::shared_ptr<PluginInsert> eq = ch_eq();
5221 return boost::shared_ptr<AutomationControl>();
5224 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5226 return boost::shared_ptr<AutomationControl>();
5230 boost::shared_ptr<AutomationControl>
5231 Route::filter_freq_controllable (bool hpf) const
5234 boost::shared_ptr<PluginInsert> eq = ch_eq();
5236 if (is_master() || mixbus() || !eq) {
5237 return boost::shared_ptr<AutomationControl>();
5241 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5243 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5247 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5249 return boost::shared_ptr<AutomationControl>();
5254 return boost::shared_ptr<AutomationControl>();
5258 boost::shared_ptr<AutomationControl>
5259 Route::filter_slope_controllable (bool) const
5261 return boost::shared_ptr<AutomationControl>();
5264 boost::shared_ptr<AutomationControl>
5265 Route::filter_enable_controllable (bool) const
5268 boost::shared_ptr<PluginInsert> eq = ch_eq();
5270 if (is_master() || mixbus() || !eq) {
5271 return boost::shared_ptr<AutomationControl>();
5274 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5276 return boost::shared_ptr<AutomationControl>();
5281 Route::eq_band_name (uint32_t band) const
5284 if (is_master() || mixbus()) {
5286 if (Profile->get_mixbus()) {
5288 case 0: return _("lo");
5289 case 1: return _("mid");
5290 case 2: return _("hi");
5291 default: return string();
5299 case 0: return _("lo");
5300 case 1: return _("lo mid");
5301 case 2: return _("hi mid");
5302 case 3: return _("hi");
5303 default: return string();
5309 boost::shared_ptr<AutomationControl>
5310 Route::comp_enable_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, 1)));
5321 return boost::shared_ptr<AutomationControl>();
5324 boost::shared_ptr<AutomationControl>
5325 Route::comp_threshold_controllable () const
5328 boost::shared_ptr<PluginInsert> comp = ch_comp();
5331 return boost::shared_ptr<AutomationControl>();
5334 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5337 return boost::shared_ptr<AutomationControl>();
5340 boost::shared_ptr<AutomationControl>
5341 Route::comp_speed_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, 3)));
5352 return boost::shared_ptr<AutomationControl>();
5355 boost::shared_ptr<AutomationControl>
5356 Route::comp_mode_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, 4)));
5367 return boost::shared_ptr<AutomationControl>();
5370 boost::shared_ptr<AutomationControl>
5371 Route::comp_makeup_controllable () const
5374 boost::shared_ptr<PluginInsert> comp = ch_comp();
5377 return boost::shared_ptr<AutomationControl>();
5380 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5382 return boost::shared_ptr<AutomationControl>();
5385 boost::shared_ptr<ReadOnlyControl>
5386 Route::comp_redux_controllable () const
5389 boost::shared_ptr<PluginInsert> comp = ch_comp();
5392 return boost::shared_ptr<ReadOnlyControl>();
5395 return comp->control_output (2);
5397 return comp->control_output (6);
5401 return boost::shared_ptr<ReadOnlyControl>();
5406 Route::comp_mode_name (uint32_t mode) const
5411 return _("Leveler");
5413 return _("Compressor");
5415 return _("Limiter");
5417 return mixbus() ? _("Sidechain") : _("Limiter");
5427 Route::comp_speed_name (uint32_t mode) const
5445 boost::shared_ptr<AutomationControl>
5446 Route::send_level_controllable (uint32_t n) const
5449 # undef MIXBUS_PORTS_H
5450 # include "../../gtk2_ardour/mixbus_ports.h"
5451 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5452 if (plug && !mixbus()) {
5453 uint32_t port_id = 0;
5455 case 0: port_id = port_channel_post_aux1_level; break;
5456 case 1: port_id = port_channel_post_aux2_level; break;
5457 case 2: port_id = port_channel_post_aux3_level; break;
5458 case 3: port_id = port_channel_post_aux4_level; break;
5459 case 4: port_id = port_channel_post_aux5_level; break;
5460 case 5: port_id = port_channel_post_aux6_level; break;
5461 case 6: port_id = port_channel_post_aux7_level; break;
5462 case 7: port_id = port_channel_post_aux8_level; break;
5464 case 8: port_id = port_channel_post_aux9_level; break;
5465 case 9: port_id = port_channel_post_aux10_level; break;
5466 case 10: port_id = port_channel_post_aux11_level; break;
5467 case 11: port_id = port_channel_post_aux12_level; break;
5474 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5485 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5487 return boost::shared_ptr<AutomationControl>();
5489 return s->gain_control ();
5492 boost::shared_ptr<AutomationControl>
5493 Route::send_enable_controllable (uint32_t n) const
5496 # undef MIXBUS_PORTS_H
5497 # include "../../gtk2_ardour/mixbus_ports.h"
5498 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5499 if (plug && !mixbus()) {
5500 uint32_t port_id = 0;
5502 case 0: port_id = port_channel_post_aux1_asgn; break;
5503 case 1: port_id = port_channel_post_aux2_asgn; break;
5504 case 2: port_id = port_channel_post_aux3_asgn; break;
5505 case 3: port_id = port_channel_post_aux4_asgn; break;
5506 case 4: port_id = port_channel_post_aux5_asgn; break;
5507 case 5: port_id = port_channel_post_aux6_asgn; break;
5508 case 6: port_id = port_channel_post_aux7_asgn; break;
5509 case 7: port_id = port_channel_post_aux8_asgn; break;
5511 case 8: port_id = port_channel_post_aux9_asgn; break;
5512 case 9: port_id = port_channel_post_aux10_asgn; break;
5513 case 10: port_id = port_channel_post_aux11_asgn; break;
5514 case 11: port_id = port_channel_post_aux12_asgn; break;
5521 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5532 /* although Ardour sends have enable/disable as part of the Processor
5533 * API, it is not exposed as a controllable.
5535 * XXX: we should fix this (make it click-free, automatable enable-control)
5537 return boost::shared_ptr<AutomationControl>();
5541 Route::send_name (uint32_t n) const
5544 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5545 if (plug && !mixbus()) {
5548 return _session.get_mixbus (n)->name();
5553 return _session.get_mixbus (n)->name();
5559 boost::shared_ptr<Processor> p = nth_send (n);
5567 boost::shared_ptr<AutomationControl>
5568 Route::master_send_enable_controllable () const
5571 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5573 return boost::shared_ptr<AutomationControl>();
5575 # undef MIXBUS_PORTS_H
5576 # include "../../gtk2_ardour/mixbus_ports.h"
5577 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5579 return boost::shared_ptr<AutomationControl>();
5584 Route::slaved () const
5586 if (!_gain_control) {
5589 /* just test one particular control, not all of them */
5590 return _gain_control->slaved ();
5594 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5596 if (!vca || !_gain_control) {
5600 /* just test one particular control, not all of them */
5602 return _gain_control->slaved_to (vca->gain_control());
5606 Route::muted_by_others_soloing () const
5608 if (!can_be_muted_by_others ()) {
5612 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5616 Route::clear_all_solo_state ()
5618 _solo_control->clear_all_solo_state ();
5621 boost::shared_ptr<AutomationControl>
5622 Route::automation_control_recurse (PBD::ID const & id) const
5624 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5630 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5632 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5633 if ((ac = (*i)->automation_control (id))) {
5638 return boost::shared_ptr<AutomationControl> ();
5642 Route::slavables () const
5644 SlavableControlList rv;
5645 rv.push_back (_gain_control);
5646 rv.push_back (_mute_control);
5647 rv.push_back (_solo_control);
5652 Route::set_disk_io_point (DiskIOPoint diop)
5654 bool display = false;
5656 cerr << "set disk io to " << enum_2_string (diop) << endl;
5667 _disk_writer->set_display_to_user (display);
5671 _disk_reader->set_display_to_user (display);
5674 const bool changed = (diop != _disk_io_point);
5676 _disk_io_point = diop;
5679 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5680 configure_processors (0);
5683 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5686 #ifdef USE_TRACKS_CODE_FEATURES
5688 /* This is the Tracks version of Track::monitoring_state().
5690 * Ardour developers: try to flag or fix issues if parts of the libardour API
5691 * change in ways that invalidate this
5695 Route::monitoring_state () const
5697 /* Explicit requests */
5699 if (_monitoring != MonitorInput) {
5700 return MonitoringInput;
5703 if (_monitoring & MonitorDisk) {
5704 return MonitoringDisk;
5707 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5708 I don't think it's ever going to be too pretty too look at.
5711 // GZ: NOT USED IN TRACKS
5712 //bool const auto_input = _session.config.get_auto_input ();
5713 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5714 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5716 bool const roll = _session.transport_rolling ();
5717 bool const track_rec = _diskstream->record_enabled ();
5718 bool session_rec = _session.actively_recording ();
5722 if (!session_rec && roll) {
5723 return MonitoringDisk;
5725 return MonitoringInput;
5731 return MonitoringDisk;
5735 return MonitoringSilence;
5740 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5742 * Tracks developers: do NOT modify this method under any circumstances.
5746 Route::monitoring_state () const
5748 if (!_disk_reader) {
5749 return MonitoringInput;
5752 /* Explicit requests */
5753 MonitorChoice m (_monitoring_control->monitoring_choice());
5755 if (m != MonitorAuto) {
5757 MonitorState ms ((MonitorState) 0);
5759 if (m & MonitorInput) {
5760 ms = MonitoringInput;
5763 if (m & MonitorDisk) {
5764 ms = MonitorState (ms | MonitoringDisk);
5770 switch (_session.config.get_session_monitoring ()) {
5772 return MonitoringDisk;
5775 return MonitoringInput;
5781 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5782 I don't think it's ever going to be too pretty too look at.
5785 bool const roll = _session.transport_rolling ();
5786 bool const track_rec = _disk_writer->record_enabled ();
5787 bool const auto_input = _session.config.get_auto_input ();
5788 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5789 bool const tape_machine_mode = Config->get_tape_machine_mode ();
5792 /* I suspect that just use actively_recording() is good enough all the
5793 * time, but just to keep the semantics the same as they were before
5794 * sept 26th 2012, we differentiate between the cases where punch is
5795 * enabled and those where it is not.
5797 * rg: I suspect this is not the case: monitoring may differ
5800 if (_session.config.get_punch_in() || _session.config.get_punch_out() || _session.preroll_record_punch_enabled ()) {
5801 session_rec = _session.actively_recording ();
5803 session_rec = _session.get_record_enabled();
5808 if (!session_rec && roll && auto_input) {
5809 return MonitoringDisk;
5811 return software_monitor ? MonitoringInput : MonitoringSilence;
5816 if (tape_machine_mode) {
5818 return MonitoringDisk;
5822 if (!roll && auto_input) {
5823 return software_monitor ? MonitoringInput : MonitoringSilence;
5825 return MonitoringDisk;
5831 abort(); /* NOTREACHED */
5832 return MonitoringSilence;