2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/unwind.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_track.h"
41 #include "ardour/audio_port.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/boost_debug.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/phase_control.h"
62 #include "ardour/plugin_insert.h"
63 #include "ardour/port.h"
64 #include "ardour/port_insert.h"
65 #include "ardour/processor.h"
66 #include "ardour/profile.h"
67 #include "ardour/route.h"
68 #include "ardour/route_group.h"
69 #include "ardour/send.h"
70 #include "ardour/session.h"
71 #include "ardour/solo_control.h"
72 #include "ardour/solo_isolate_control.h"
73 #include "ardour/unknown_processor.h"
74 #include "ardour/utils.h"
75 #include "ardour/vca.h"
80 using namespace ARDOUR;
83 PBD::Signal0<void> Route::SyncOrderKeys;
84 PBD::Signal0<void> Route::RemoteControlIDChange;
85 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
87 /** Base class for all routable/mixable objects (tracks and busses) */
88 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
89 : Stripable (sess, name)
90 , Muteable (sess, name)
92 , GraphNode (sess._process_graph)
95 , _signal_latency_at_amp_position (0)
96 , _signal_latency_at_trim_position (0)
99 , _pending_process_reorder (0)
100 , _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 , _has_order_key (false)
114 , _remote_control_id (0)
116 , _in_configure_processors (false)
117 , _initial_io_setup (false)
118 , _in_sidechain_setup (false)
120 , _custom_meter_position_noted (false)
123 processor_max_streams.reset();
129 /* set default meter type */
131 _meter_type = Config->get_meter_type_master ();
133 else if (dynamic_cast<Track*>(this)) {
134 _meter_type = Config->get_meter_type_track ();
136 _meter_type = Config->get_meter_type_bus ();
139 /* add standard controls */
141 _gain_control.reset (new GainControl (_session, GainAutomation));
142 add_control (_gain_control);
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 add_control (_trim_control);
147 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
148 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
149 add_control (_solo_control);
150 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
152 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
153 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
154 add_control (_mute_control);
156 _phase_control.reset (new PhaseControl (_session, X_("phase")));
157 add_control (_phase_control);
159 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
160 add_control (_solo_isolate_control);
162 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
163 add_control (_solo_safe_control);
167 if (!(_flags & Route::MonitorOut)) {
168 _pannable.reset (new Pannable (_session));
171 /* input and output objects */
173 _input.reset (new IO (_session, _name, IO::Input, _default_type));
174 _output.reset (new IO (_session, _name, IO::Output, _default_type));
176 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
177 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
179 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
180 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
182 /* add the amp/fader processor.
183 * it should be the first processor to be added on every route.
186 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
187 add_processor (_amp, PostFader);
190 _amp->set_display_name (_("Monitor"));
193 #if 0 // not used - just yet
194 if (!is_master() && !is_monitor() && !is_auditioner()) {
195 _delayline.reset (new DelayLine (_session, _name));
196 add_processor (_delayline, PreFader);
202 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
203 _trim->set_display_to_user (false);
205 if (dynamic_cast<AudioTrack*>(this)) {
206 /* we can't do this in the AudioTrack's constructor
207 * because _trim does not exit then
211 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
216 /* create standard processors: meter, main outs, monitor out;
217 they will be added to _processors by setup_invisible_processors ()
220 _meter.reset (new PeakMeter (_session, _name));
221 _meter->set_owner (this);
222 _meter->set_display_to_user (false);
225 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
226 _main_outs->activate ();
229 /* where we listen to tracks */
230 _intreturn.reset (new InternalReturn (_session));
231 _intreturn->activate ();
233 /* the thing that provides proper control over a control/monitor/listen bus
234 (such as per-channel cut, dim, solo, invert, etc).
236 _monitor_control.reset (new MonitorProcessor (_session));
237 _monitor_control->activate ();
240 if (is_master() || is_monitor() || is_auditioner()) {
241 _mute_master->set_solo_ignore (true);
244 /* now that we have _meter, its safe to connect to this */
247 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
248 configure_processors (0);
256 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
258 /* do this early so that we don't get incoming signals as we are going through destruction
263 /* don't use clear_processors here, as it depends on the session which may
264 be half-destroyed by now
267 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
269 (*i)->drop_references ();
272 _processors.clear ();
276 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
278 if (Config->get_remote_model() != UserOrdered) {
282 set_remote_control_id_internal (id, notify_class_listeners);
286 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
288 /* force IDs for master/monitor busses and prevent
289 any other route from accidentally getting these IDs
290 (i.e. legacy sessions)
293 if (is_master() && id != MasterBusRemoteControlID) {
294 id = MasterBusRemoteControlID;
297 if (is_monitor() && id != MonitorBusRemoteControlID) {
298 id = MonitorBusRemoteControlID;
305 /* don't allow it to collide */
307 if (!is_master () && !is_monitor() &&
308 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
309 id += MonitorBusRemoteControlID;
312 if (id != remote_control_id()) {
313 _remote_control_id = id;
314 RemoteControlIDChanged ();
316 if (notify_class_listeners) {
317 RemoteControlIDChange ();
323 Route::remote_control_id() const
326 return MasterBusRemoteControlID;
330 return MonitorBusRemoteControlID;
333 return _remote_control_id;
337 Route::has_order_key () const
339 return _has_order_key;
343 Route::order_key () const
349 Route::set_remote_control_id_explicit (uint32_t rid)
351 if (is_master() || is_monitor() || is_auditioner()) {
352 /* hard-coded remote IDs, or no remote ID */
356 if (_remote_control_id != rid) {
357 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
358 _remote_control_id = rid;
359 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
362 /* don't emit the class-level RID signal RemoteControlIDChange here,
363 leave that to the entity that changed the order key, so that we
364 don't get lots of emissions for no good reasons (e.g. when changing
365 all route order keys).
367 See Session::sync_remote_id_from_order_keys() for the (primary|only)
368 spot where that is emitted.
373 Route::set_order_key (uint32_t n)
375 _has_order_key = true;
377 if (_order_key == n) {
383 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
384 name(), order_key ()));
386 _session.set_dirty ();
390 Route::ensure_track_or_route_name(string name, Session &session)
392 string newname = name;
394 while (!session.io_name_is_legal (newname)) {
395 newname = bump_name_once (newname, ' ');
402 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
404 // TODO route group, see set_gain()
405 // _trim_control->route_set_value (val);
409 Route::maybe_declick (BufferSet&, framecnt_t, int)
411 /* this is the "bus" implementation and they never declick.
416 /** Process this route for one (sub) cycle (process thread)
418 * @param bufs Scratch buffers to use for the signal path
419 * @param start_frame Initial transport frame
420 * @param end_frame Final transport frame
421 * @param nframes Number of frames to output (to ports)
423 * Note that (end_frame - start_frame) may not be equal to nframes when the
424 * transport speed isn't 1.0 (eg varispeed).
427 Route::process_output_buffers (BufferSet& bufs,
428 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
429 int declick, bool gain_automation_ok)
431 /* Caller must hold process lock */
432 assert (!AudioEngine::instance()->process_lock().trylock());
434 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
436 // can this actually happen? functions calling process_output_buffers()
437 // already take a reader-lock.
438 bufs.silence (nframes, 0);
442 /* figure out if we're going to use gain automation */
443 if (gain_automation_ok) {
444 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
445 _amp->setup_gain_automation (
446 start_frame + _signal_latency_at_amp_position,
447 end_frame + _signal_latency_at_amp_position,
450 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
451 _trim->setup_gain_automation (
452 start_frame + _signal_latency_at_trim_position,
453 end_frame + _signal_latency_at_trim_position,
456 _amp->apply_gain_automation (false);
457 _trim->apply_gain_automation (false);
460 /* Tell main outs what to do about monitoring. We do this so that
461 on a transition between monitoring states we get a de-clicking gain
462 change in the _main_outs delivery, if config.get_use_monitor_fades()
465 We override this in the case where we have an internal generator.
467 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
469 _main_outs->no_outs_cuz_we_no_monitor (silence);
471 /* -------------------------------------------------------------------------------------------
472 GLOBAL DECLICK (for transport changes etc.)
473 ----------------------------------------------------------------------------------------- */
475 maybe_declick (bufs, nframes, declick);
476 _pending_declick = 0;
478 /* -------------------------------------------------------------------------------------------
479 DENORMAL CONTROL/PHASE INVERT
480 ----------------------------------------------------------------------------------------- */
482 if (!_phase_control->none()) {
486 if (_denormal_protection || Config->get_denormal_protection()) {
488 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
489 Sample* const sp = i->data();
491 if (_phase_control->inverted (chn)) {
492 for (pframes_t nx = 0; nx < nframes; ++nx) {
497 for (pframes_t nx = 0; nx < nframes; ++nx) {
505 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
506 Sample* const sp = i->data();
508 if (_phase_control->inverted (chn)) {
509 for (pframes_t nx = 0; nx < nframes; ++nx) {
518 if (_denormal_protection || Config->get_denormal_protection()) {
520 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
521 Sample* const sp = i->data();
522 for (pframes_t nx = 0; nx < nframes; ++nx) {
530 /* -------------------------------------------------------------------------------------------
532 ----------------------------------------------------------------------------------------- */
534 /* set this to be true if the meter will already have been ::run() earlier */
535 bool const meter_already_run = metering_state() == MeteringInput;
537 framecnt_t latency = 0;
539 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
541 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
542 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
547 /* if it has any inputs, make sure they match */
548 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
549 if (bufs.count() != (*i)->input_streams()) {
551 DEBUG::Processors, string_compose (
552 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
553 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
560 /* should we NOT run plugins here if the route is inactive?
561 do we catch route != active somewhere higher?
564 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
565 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
568 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
569 bufs.set_count ((*i)->output_streams());
571 if ((*i)->active ()) {
572 latency += (*i)->signal_latency ();
578 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
579 boost::shared_ptr<Processor> endpoint,
580 bool include_endpoint, bool for_export, bool for_freeze)
582 /* If no processing is required, there's no need to go any further. */
583 if (!endpoint && !include_endpoint) {
587 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
588 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
589 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
591 /* trim is always at the top, for bounce no latency compensation is needed */
592 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
593 _trim->setup_gain_automation (start, start + nframes, nframes);
596 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
598 if (!include_endpoint && (*i) == endpoint) {
602 /* if we're *not* exporting, stop processing if we come across a routing processor. */
603 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
606 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
610 /* special case the panner (export outputs)
611 * Ideally we'd only run the panner, not the delivery itself...
612 * but panners need separate input/output buffers and some context
613 * (panshell, panner type, etc). AFAICT there is no ill side effect
614 * of re-using the main delivery when freewheeling/exporting a region.
616 if ((*i) == _main_outs) {
617 assert ((*i)->does_routing());
618 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
619 buffers.set_count ((*i)->output_streams());
622 /* don't run any processors that do routing.
623 * Also don't bother with metering.
625 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
626 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
627 buffers.set_count ((*i)->output_streams());
628 latency += (*i)->signal_latency ();
631 if ((*i) == endpoint) {
638 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
639 bool include_endpoint, bool for_export, bool for_freeze) const
641 framecnt_t latency = 0;
642 if (!endpoint && !include_endpoint) {
646 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
647 if (!include_endpoint && (*i) == endpoint) {
650 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
653 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
656 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
657 latency += (*i)->signal_latency ();
659 if ((*i) == endpoint) {
667 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
668 bool include_endpoint, bool for_export, bool for_freeze) const
670 if (!endpoint && !include_endpoint) {
674 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
675 if (!include_endpoint && (*i) == endpoint) {
678 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
681 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
684 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
685 cc = (*i)->output_streams();
687 if ((*i) == endpoint) {
695 Route::n_process_buffers ()
697 return max (_input->n_ports(), processor_max_streams);
701 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
703 assert (is_monitor());
704 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
705 fill_buffers_with_input (bufs, _input, nframes);
706 passthru (bufs, start_frame, end_frame, nframes, declick);
710 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
714 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
716 /* control/monitor bus ignores input ports when something is
717 feeding the listen "stream". data will "arrive" into the
718 route from the intreturn processor element.
721 bufs.silence (nframes, 0);
724 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
725 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
729 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
731 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
733 bufs.set_count (_input->n_ports());
734 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
735 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
739 Route::set_listen (bool yn)
743 _monitor_send->activate ();
745 _monitor_send->deactivate ();
751 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
753 /* nothing to do if we're not using AFL/PFL. But if we are, we need
754 to alter the active state of the monitor send.
757 if (Config->get_solo_control_is_listen_control ()) {
758 set_listen (_solo_control->self_soloed());
763 Route::listening_via_monitor () const
766 return _monitor_send->active ();
773 Route::push_solo_isolate_upstream (int32_t delta)
775 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
777 boost::shared_ptr<RouteList> routes = _session.get_routes ();
778 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
780 if ((*i).get() == this || !(*i)->can_solo()) {
785 bool does_feed = feeds (*i, &sends_only);
787 if (does_feed && !sends_only) {
788 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
794 Route::push_solo_upstream (int delta)
796 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
797 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
801 boost::shared_ptr<Route> sr (i->r.lock());
803 sr->solo_control()->mod_solo_by_others_downstream (-delta);
810 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
812 cerr << name << " {" << endl;
813 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
814 p != procs.end(); ++p) {
815 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
821 /** Supposing that we want to insert a Processor at a given Placement, return
822 * the processor to add the new one before (or 0 to add at the end).
824 boost::shared_ptr<Processor>
825 Route::before_processor_for_placement (Placement p)
827 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
829 ProcessorList::iterator loc;
832 /* generic pre-fader: insert immediately before the amp */
833 loc = find (_processors.begin(), _processors.end(), _amp);
835 /* generic post-fader: insert right before the main outs */
836 loc = find (_processors.begin(), _processors.end(), _main_outs);
839 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
842 /** Supposing that we want to insert a Processor at a given index, return
843 * the processor to add the new one before (or 0 to add at the end).
845 boost::shared_ptr<Processor>
846 Route::before_processor_for_index (int index)
849 return boost::shared_ptr<Processor> ();
852 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
854 ProcessorList::iterator i = _processors.begin ();
856 while (i != _processors.end() && j < index) {
857 if ((*i)->display_to_user()) {
864 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
867 /** Add a processor either pre- or post-fader
868 * @return 0 on success, non-0 on failure.
871 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
873 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
877 /** Add a processor to a route such that it ends up with a given index into the visible processors.
878 * @param index Index to add the processor at, or -1 to add at the end of the list.
879 * @return 0 on success, non-0 on failure.
882 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
884 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
887 /** Add a processor to the route.
888 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
889 * @return 0 on success, non-0 on failure.
892 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
894 assert (processor != _meter);
895 assert (processor != _main_outs);
897 DEBUG_TRACE (DEBUG::Processors, string_compose (
898 "%1 adding processor %2\n", name(), processor->name()));
902 pl.push_back (processor);
903 int rv = add_processors (pl, before, err);
909 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
910 processor->activate ();
917 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
919 /* We cannot destruct the processor here (usually RT-thread
920 * with various locks held - in case of sends also io_locks).
921 * Queue for deletion in low-priority thread.
923 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
924 selfdestruct_sequence.push_back (wp);
928 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
930 XMLProperty const * prop;
933 boost::shared_ptr<Processor> processor;
935 /* bit of a hack: get the `placement' property from the <Redirect> tag here
936 so that we can add the processor in the right place (pre/post-fader)
939 XMLNodeList const & children = node.children ();
940 XMLNodeList::const_iterator i = children.begin ();
942 while (i != children.end() && (*i)->name() != X_("Redirect")) {
946 Placement placement = PreFader;
948 if (i != children.end()) {
949 if ((prop = (*i)->property (X_("placement"))) != 0) {
950 placement = Placement (string_2_enum (prop->value(), placement));
954 if (node.name() == "Insert") {
956 if ((prop = node.property ("type")) != 0) {
958 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
959 prop->value() == "lv2" ||
960 prop->value() == "windows-vst" ||
961 prop->value() == "lxvst" ||
962 prop->value() == "audiounit") {
964 if (_session.get_disable_all_loaded_plugins ()) {
965 processor.reset (new UnknownProcessor (_session, node));
967 processor.reset (new PluginInsert (_session));
968 processor->set_owner (this);
973 processor.reset (new PortInsert (_session, _pannable, _mute_master));
978 } else if (node.name() == "Send") {
980 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
981 processor.reset (new Send (_session, sendpan, _mute_master));
985 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
989 if (processor->set_state (node, version)) {
993 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
994 if (i != children.end()) {
995 if ((prop = (*i)->property (X_("active"))) != 0) {
996 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
997 processor->activate();
999 processor->deactivate();
1003 return (add_processor (processor, placement, 0, false) == 0);
1006 catch (failed_constructor &err) {
1007 warning << _("processor could not be created. Ignored.") << endmsg;
1013 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1014 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
1017 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1018 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
1022 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1024 ProcessorList::iterator loc;
1027 loc = find(_processors.begin(), _processors.end(), before);
1028 if (loc == _processors.end ()) {
1032 /* nothing specified - at end */
1033 loc = _processors.end ();
1036 if (!AudioEngine::instance()->connected()) {
1040 if (others.empty()) {
1044 ProcessorList to_skip;
1046 // check if there's an instrument to replace or configure
1047 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1048 boost::shared_ptr<PluginInsert> pi;
1049 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1052 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1055 boost::shared_ptr<Processor> instrument = the_instrument ();
1056 ChanCount in (DataType::MIDI, 1);
1057 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1059 PluginSetupOptions flags = None;
1061 flags |= CanReplace;
1062 in = instrument->input_streams ();
1063 out = instrument->output_streams ();
1065 if (pi->has_output_presets (in, out)) {
1069 pi->set_strict_io (_strict_io);
1071 PluginSetupOptions mask = None;
1072 if (Config->get_ask_replace_instrument ()) {
1075 if (Config->get_ask_setup_instrument ()) {
1081 if (flags != None) {
1082 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
1083 switch (rv.get_value_or (0)) {
1085 to_skip.push_back (*i); // don't add this one;
1088 replace_processor (instrument, *i, err);
1089 to_skip.push_back (*i);
1098 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1099 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1100 ProcessorState pstate (this);
1102 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1107 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1108 if (check != to_skip.end()) {
1112 boost::shared_ptr<PluginInsert> pi;
1114 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1115 pi->set_strict_io (_strict_io);
1119 /* Ensure that only one amp is in the list at any time */
1120 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1121 if (check != _processors.end()) {
1122 if (before == _amp) {
1123 /* Already in position; all is well */
1126 _processors.erase (check);
1131 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1133 _processors.insert (loc, *i);
1134 (*i)->set_owner (this);
1137 if (configure_processors_unlocked (err, &lm)) {
1139 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1144 if ((*i)->active()) {
1148 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1150 boost::shared_ptr<Send> send;
1151 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1152 send->SelfDestruct.connect_same_thread (*this,
1153 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1157 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1158 boost::shared_ptr<PluginInsert> pi;
1160 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1161 if (pi->has_no_inputs ()) {
1162 _have_internal_generator = true;
1168 _output->set_user_latency (0);
1171 reset_instrument_info ();
1172 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1173 set_processor_positions ();
1179 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1181 if (p == PreFader) {
1182 start = _processors.begin();
1183 end = find(_processors.begin(), _processors.end(), _amp);
1185 start = find(_processors.begin(), _processors.end(), _amp);
1187 end = _processors.end();
1191 /** Turn off all processors with a given placement
1192 * @param p Placement of processors to disable
1195 Route::disable_processors (Placement p)
1197 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1199 ProcessorList::iterator start, end;
1200 placement_range(p, start, end);
1202 for (ProcessorList::iterator i = start; i != end; ++i) {
1203 (*i)->deactivate ();
1206 _session.set_dirty ();
1209 /** Turn off all redirects
1212 Route::disable_processors ()
1214 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1216 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1217 (*i)->deactivate ();
1220 _session.set_dirty ();
1223 /** Turn off all redirects with a given placement
1224 * @param p Placement of redirects to disable
1227 Route::disable_plugins (Placement p)
1229 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1231 ProcessorList::iterator start, end;
1232 placement_range(p, start, end);
1234 for (ProcessorList::iterator i = start; i != end; ++i) {
1235 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1236 (*i)->deactivate ();
1240 _session.set_dirty ();
1243 /** Turn off all plugins
1246 Route::disable_plugins ()
1248 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1250 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1251 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1252 (*i)->deactivate ();
1256 _session.set_dirty ();
1261 Route::ab_plugins (bool forward)
1263 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1267 /* forward = turn off all active redirects, and mark them so that the next time
1268 we go the other way, we will revert them
1271 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1272 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1276 if ((*i)->active()) {
1277 (*i)->deactivate ();
1278 (*i)->set_next_ab_is_active (true);
1280 (*i)->set_next_ab_is_active (false);
1286 /* backward = if the redirect was marked to go active on the next ab, do so */
1288 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1290 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1294 if ((*i)->get_next_ab_is_active()) {
1297 (*i)->deactivate ();
1302 _session.set_dirty ();
1306 /** Remove processors with a given placement.
1307 * @param p Placement of processors to remove.
1310 Route::clear_processors (Placement p)
1312 if (!_session.engine().connected()) {
1316 bool already_deleting = _session.deletion_in_progress();
1317 if (!already_deleting) {
1318 _session.set_deletion_in_progress();
1322 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1323 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1324 ProcessorList new_list;
1325 ProcessorStreams err;
1326 bool seen_amp = false;
1328 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1334 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1336 /* you can't remove these */
1338 new_list.push_back (*i);
1345 new_list.push_back (*i);
1348 (*i)->drop_references ();
1356 (*i)->drop_references ();
1359 new_list.push_back (*i);
1366 _processors = new_list;
1367 configure_processors_unlocked (&err, &lm); // this can't fail
1370 processor_max_streams.reset();
1371 _have_internal_generator = false;
1372 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1373 set_processor_positions ();
1375 reset_instrument_info ();
1377 if (!already_deleting) {
1378 _session.clear_deletion_in_progress();
1383 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1385 // TODO once the export point can be configured properly, do something smarter here
1386 if (processor == _capturing_processor) {
1387 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1388 if (need_process_lock) {
1392 _capturing_processor.reset();
1394 if (need_process_lock) {
1399 /* these can never be removed */
1401 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1405 if (!_session.engine().connected()) {
1409 processor_max_streams.reset();
1412 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1413 if (need_process_lock) {
1417 /* Caller must hold process lock */
1418 assert (!AudioEngine::instance()->process_lock().trylock());
1420 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1422 ProcessorState pstate (this);
1424 ProcessorList::iterator i;
1425 bool removed = false;
1427 for (i = _processors.begin(); i != _processors.end(); ) {
1428 if (*i == processor) {
1430 /* move along, see failure case for configure_processors()
1431 where we may need to reconfigure the processor.
1434 /* stop redirects that send signals to JACK ports
1435 from causing noise as a result of no longer being
1439 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1440 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1444 iop = pi->sidechain();
1451 i = _processors.erase (i);
1459 _output->set_user_latency (0);
1467 if (configure_processors_unlocked (err, &lm)) {
1469 /* we know this will work, because it worked before :) */
1470 configure_processors_unlocked (0, &lm);
1474 _have_internal_generator = false;
1476 for (i = _processors.begin(); i != _processors.end(); ++i) {
1477 boost::shared_ptr<PluginInsert> pi;
1479 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1480 if (pi->has_no_inputs ()) {
1481 _have_internal_generator = true;
1486 if (need_process_lock) {
1491 reset_instrument_info ();
1492 processor->drop_references ();
1493 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1494 set_processor_positions ();
1500 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1502 /* these can never be removed */
1503 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1506 /* and can't be used as substitute, either */
1507 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1511 /* I/Os are out, too */
1512 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1516 /* this function cannot be used to swap/reorder processors */
1517 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1521 if (!AudioEngine::instance()->connected() || !old || !sub) {
1525 /* ensure that sub is not owned by another route */
1526 if (sub->owner ()) {
1531 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1532 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1533 ProcessorState pstate (this);
1535 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1537 ProcessorList::iterator i;
1538 bool replaced = false;
1539 bool enable = old->active ();
1541 for (i = _processors.begin(); i != _processors.end(); ) {
1543 i = _processors.erase (i);
1544 _processors.insert (i, sub);
1545 sub->set_owner (this);
1558 boost::shared_ptr<PluginInsert> pi;
1559 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1560 pi->set_strict_io (true);
1564 if (configure_processors_unlocked (err, &lm)) {
1566 configure_processors_unlocked (0, &lm);
1570 _have_internal_generator = false;
1572 for (i = _processors.begin(); i != _processors.end(); ++i) {
1573 boost::shared_ptr<PluginInsert> pi;
1574 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1575 if (pi->has_no_inputs ()) {
1576 _have_internal_generator = true;
1586 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1587 _output->set_user_latency (0);
1590 reset_instrument_info ();
1591 old->drop_references ();
1592 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1593 set_processor_positions ();
1598 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1600 ProcessorList deleted;
1602 if (!_session.engine().connected()) {
1606 processor_max_streams.reset();
1609 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1610 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1611 ProcessorState pstate (this);
1613 ProcessorList::iterator i;
1614 boost::shared_ptr<Processor> processor;
1616 for (i = _processors.begin(); i != _processors.end(); ) {
1620 /* these can never be removed */
1622 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1627 /* see if its in the list of processors to delete */
1629 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1634 /* stop IOProcessors that send to JACK ports
1635 from causing noise as a result of no longer being
1639 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1640 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1643 iop = pi->sidechain();
1650 deleted.push_back (processor);
1651 i = _processors.erase (i);
1654 if (deleted.empty()) {
1655 /* none of those in the requested list were found */
1659 _output->set_user_latency (0);
1661 if (configure_processors_unlocked (err, &lm)) {
1663 /* we know this will work, because it worked before :) */
1664 configure_processors_unlocked (0, &lm);
1669 _have_internal_generator = false;
1671 for (i = _processors.begin(); i != _processors.end(); ++i) {
1672 boost::shared_ptr<PluginInsert> pi;
1674 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1675 if (pi->has_no_inputs ()) {
1676 _have_internal_generator = true;
1683 /* now try to do what we need to so that those that were removed will be deleted */
1685 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1686 (*i)->drop_references ();
1689 reset_instrument_info ();
1690 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1691 set_processor_positions ();
1697 Route::reset_instrument_info ()
1699 boost::shared_ptr<Processor> instr = the_instrument();
1701 _instrument_info.set_internal_instrument (instr);
1705 /** Caller must hold process lock */
1707 Route::configure_processors (ProcessorStreams* err)
1709 #ifndef PLATFORM_WINDOWS
1710 assert (!AudioEngine::instance()->process_lock().trylock());
1713 if (!_in_configure_processors) {
1714 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1715 return configure_processors_unlocked (err, &lm);
1722 Route::input_streams () const
1724 return _input->n_ports ();
1727 list<pair<ChanCount, ChanCount> >
1728 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1730 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1732 return try_configure_processors_unlocked (in, err);
1735 list<pair<ChanCount, ChanCount> >
1736 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1738 // Check each processor in order to see if we can configure as requested
1740 list<pair<ChanCount, ChanCount> > configuration;
1743 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1744 DEBUG_TRACE (DEBUG::Processors, "{\n");
1746 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1748 if ((*p)->can_support_io_configuration(in, out)) {
1750 if (boost::dynamic_pointer_cast<Delivery> (*p)
1751 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1752 && !(is_monitor() || is_auditioner())
1753 && ( _strict_io || Profile->get_mixbus ())) {
1754 /* with strict I/O the panner + output are forced to
1755 * follow the last processor's output.
1757 * Delivery::can_support_io_configuration() will only add ports,
1758 * but not remove excess ports.
1760 * This works because the delivery only requires
1761 * as many outputs as there are inputs.
1762 * Delivery::configure_io() will do the actual removal
1763 * by calling _output->ensure_io()
1765 if (!is_master() && _session.master_out ()) {
1766 /* ..but at least as many as there are master-inputs */
1767 // XXX this may need special-casing for mixbus (master-outputs)
1768 // and should maybe be a preference anyway ?!
1769 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1775 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1776 configuration.push_back(make_pair(in, out));
1779 // restriction for Monitor Section Processors
1780 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1781 /* do not allow to add/remove channels (for now)
1782 * The Monitor follows the master-bus and has no panner (unpan)
1783 * but do allow processors with midi-in to be added (e.g VSTs with control that
1784 * will remain unconnected)
1786 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1787 return list<pair<ChanCount, ChanCount> > ();
1789 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1790 // internal sends make no sense, only feedback
1791 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1792 return list<pair<ChanCount, ChanCount> > ();
1794 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1795 /* External Sends can be problematic. one can add/remove ports
1796 * there signal leaves the DAW to external monitors anyway, so there's
1797 * no real use for allowing them here anyway.
1799 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1800 return list<pair<ChanCount, ChanCount> > ();
1802 if (boost::dynamic_pointer_cast<Send> (*p)) {
1804 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1805 return list<pair<ChanCount, ChanCount> > ();
1814 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1815 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1816 DEBUG_TRACE (DEBUG::Processors, "}\n");
1817 return list<pair<ChanCount, ChanCount> > ();
1821 DEBUG_TRACE (DEBUG::Processors, "}\n");
1823 return configuration;
1826 /** Set the input/output configuration of each processor in the processors list.
1827 * Caller must hold process lock.
1828 * Return 0 on success, otherwise configuration is impossible.
1831 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1833 #ifndef PLATFORM_WINDOWS
1834 assert (!AudioEngine::instance()->process_lock().trylock());
1837 if (_in_configure_processors) {
1841 /* put invisible processors where they should be */
1842 setup_invisible_processors ();
1844 _in_configure_processors = true;
1846 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1848 if (configuration.empty ()) {
1849 _in_configure_processors = false;
1854 bool seen_mains_out = false;
1855 processor_out_streams = _input->n_ports();
1856 processor_max_streams.reset();
1858 /* processor configure_io() may result in adding ports
1859 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1861 * with jack2 adding ports results in a graph-order callback,
1862 * which calls Session::resort_routes() and eventually
1863 * Route::direct_feeds_according_to_reality()
1864 * which takes a ReaderLock (_processor_lock).
1866 * so we can't hold a WriterLock here until jack2 threading
1869 * NB. we still hold the process lock
1871 * (ardour's own engines do call graph-order from the
1872 * process-thread and hence do not have this issue; besides
1873 * merely adding ports won't trigger a graph-order, only
1874 * making connections does)
1878 // TODO check for a potential ReaderLock after ReaderLock ??
1879 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1881 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1882 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1884 if (!(*p)->configure_io(c->first, c->second)) {
1885 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1886 _in_configure_processors = false;
1891 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1892 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1894 boost::shared_ptr<IOProcessor> iop;
1895 boost::shared_ptr<PluginInsert> pi;
1896 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1897 /* plugins connected via Split or Hide Match may have more channels.
1898 * route/scratch buffers are needed for all of them
1899 * The configuration may only be a subset (both input and output)
1901 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1903 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1904 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1905 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1909 if (boost::dynamic_pointer_cast<Delivery> (*p)
1910 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1911 /* main delivery will increase port count to match input.
1912 * the Delivery::Main is usually the last processor - followed only by
1915 seen_mains_out = true;
1917 if (!seen_mains_out) {
1918 processor_out_streams = out;
1927 _meter->set_max_channels (processor_max_streams);
1930 /* make sure we have sufficient scratch buffers to cope with the new processor
1933 _session.ensure_buffers (n_process_buffers ());
1935 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1937 _in_configure_processors = false;
1941 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1942 * @param state New active state for those processors.
1945 Route::all_visible_processors_active (bool state)
1947 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1949 if (_processors.empty()) {
1953 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1954 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1961 (*i)->deactivate ();
1965 _session.set_dirty ();
1969 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1971 /* check if re-order requires re-configuration of any processors
1972 * -> compare channel configuration for all processors
1974 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1975 ChanCount c = input_streams ();
1977 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1979 if (c != (*j)->input_streams()) {
1982 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1985 if ((*i)->input_streams() != c) {
1988 c = (*i)->output_streams();
2000 __attribute__((annotate("realtime")))
2003 Route::apply_processor_order (const ProcessorList& new_order)
2005 /* need to hold processor_lock; either read or write lock
2006 * and the engine process_lock.
2007 * Due to r/w lock ambiguity we can only assert the latter
2009 assert (!AudioEngine::instance()->process_lock().trylock());
2012 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2013 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2014 * processors in the current actual processor list that are hidden. Any visible processors
2015 * in the current list but not in "new_order" will be assumed to be deleted.
2018 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2019 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2020 * (note though that ::processors_reorder_needs_configure() ensured that
2021 * this function will only ever be called from the rt-thread if no processor were removed)
2023 * either way, I can't proove it, but an x-run due to re-order here is less likley
2024 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2027 ProcessorList as_it_will_be;
2028 ProcessorList::iterator oiter;
2029 ProcessorList::const_iterator niter;
2031 oiter = _processors.begin();
2032 niter = new_order.begin();
2034 while (niter != new_order.end()) {
2036 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2037 then append it to the temp list.
2039 Otherwise, see if the next processor in the old list is in the new list. if not,
2040 its been deleted. If its there, append it to the temp list.
2043 if (oiter == _processors.end()) {
2045 /* no more elements in the old list, so just stick the rest of
2046 the new order onto the temp list.
2049 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2050 while (niter != new_order.end()) {
2057 if (!(*oiter)->display_to_user()) {
2059 as_it_will_be.push_back (*oiter);
2063 /* visible processor: check that its in the new order */
2065 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2066 /* deleted: do nothing, shared_ptr<> will clean up */
2068 /* ignore this one, and add the next item from the new order instead */
2069 as_it_will_be.push_back (*niter);
2074 /* now remove from old order - its taken care of no matter what */
2075 oiter = _processors.erase (oiter);
2079 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2081 /* If the meter is in a custom position, find it and make a rough note of its position */
2082 maybe_note_meter_position ();
2086 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2088 // it a change is already queued, wait for it
2089 // (unless engine is stopped. apply immediately and proceed
2090 while (g_atomic_int_get (&_pending_process_reorder)) {
2091 if (!AudioEngine::instance()->running()) {
2092 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2093 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2095 apply_processor_order(_pending_processor_order);
2096 setup_invisible_processors ();
2098 g_atomic_int_set (&_pending_process_reorder, 0);
2100 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2101 set_processor_positions ();
2103 // TODO rather use a semaphore or something.
2104 // but since ::reorder_processors() is called
2105 // from the GUI thread, this is fine..
2110 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2112 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2113 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2114 ProcessorState pstate (this);
2116 apply_processor_order (new_order);
2118 if (configure_processors_unlocked (err, &lm)) {
2126 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2127 set_processor_positions ();
2130 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2131 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2133 // _pending_processor_order is protected by _processor_lock
2134 _pending_processor_order = new_order;
2135 g_atomic_int_set (&_pending_process_reorder, 1);
2142 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2144 boost::shared_ptr<PluginInsert> pi;
2145 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2149 if (pi->has_sidechain () == add) {
2150 return true; // ?? call failed, but result is as expected.
2154 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2155 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2156 if (i == _processors.end ()) {
2162 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2163 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2164 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2166 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2168 if (!pi->add_sidechain ()) {
2172 if (!pi->del_sidechain ()) {
2178 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2183 pi->del_sidechain ();
2185 pi->add_sidechain ();
2186 // TODO restore side-chain's state.
2191 configure_processors_unlocked (0, &lm);
2194 if (pi->has_sidechain ()) {
2195 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2198 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2199 _session.set_dirty ();
2204 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2206 boost::shared_ptr<PluginInsert> pi;
2207 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2212 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2213 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2214 if (i == _processors.end ()) {
2220 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2221 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2223 const ChanCount& old (pi->preset_out ());
2224 if (!pi->set_preset_out (outs)) {
2225 return true; // no change, OK
2228 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2231 pi->set_preset_out (old);
2234 configure_processors_unlocked (0, &lm);
2237 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2238 _session.set_dirty ();
2243 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2246 return customize_plugin_insert (proc, 0, unused, unused);
2250 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2252 boost::shared_ptr<PluginInsert> pi;
2253 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2258 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2259 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2260 if (i == _processors.end ()) {
2266 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2267 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2269 bool old_cust = pi->custom_cfg ();
2270 uint32_t old_cnt = pi->get_count ();
2271 ChanCount old_chan = pi->output_streams ();
2272 ChanCount old_sinks = pi->natural_input_streams ();
2275 pi->set_custom_cfg (false);
2277 pi->set_custom_cfg (true);
2278 pi->set_count (count);
2279 pi->set_outputs (outs);
2280 pi->set_sinks (sinks);
2283 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2287 pi->set_count (old_cnt);
2288 pi->set_sinks (old_sinks);
2289 pi->set_outputs (old_chan);
2290 pi->set_custom_cfg (old_cust);
2294 configure_processors_unlocked (0, &lm);
2297 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2298 _session.set_dirty ();
2303 Route::set_strict_io (const bool enable)
2305 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2307 if (_strict_io != enable) {
2308 _strict_io = enable;
2309 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2310 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2311 boost::shared_ptr<PluginInsert> pi;
2312 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2313 pi->set_strict_io (_strict_io);
2317 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2321 _strict_io = !enable; // restore old value
2322 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2323 boost::shared_ptr<PluginInsert> pi;
2324 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2325 pi->set_strict_io (_strict_io);
2332 configure_processors (0);
2335 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2336 _session.set_dirty ();
2348 Route::get_template()
2350 return state(false);
2354 Route::state(bool full_state)
2357 if (!_session._template_state_dir.empty()) {
2358 assert (!full_state); // only for templates
2359 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2362 XMLNode *node = new XMLNode("Route");
2363 ProcessorList::iterator i;
2366 id().print (buf, sizeof (buf));
2367 node->add_property("id", buf);
2368 node->add_property ("name", _name);
2369 node->add_property("default-type", _default_type.to_string());
2370 node->add_property ("strict-io", _strict_io);
2373 node->add_property("flags", enum_2_string (_flags));
2376 node->add_property("active", _active?"yes":"no");
2378 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2379 node->add_property("meter-point", enum_2_string (_meter_point));
2381 node->add_property("meter-type", enum_2_string (_meter_type));
2384 node->add_property("route-group", _route_group->name());
2387 snprintf (buf, sizeof (buf), "%d", _order_key);
2388 node->add_property ("order-key", buf);
2390 node->add_child_nocopy (_solo_control->get_state ());
2391 node->add_child_nocopy (_solo_isolate_control->get_state ());
2392 node->add_child_nocopy (_solo_safe_control->get_state ());
2394 node->add_child_nocopy (_input->state (full_state));
2395 node->add_child_nocopy (_output->state (full_state));
2396 node->add_child_nocopy (_mute_master->get_state ());
2398 node->add_child_nocopy (_mute_control->get_state ());
2399 node->add_child_nocopy (_phase_control->get_state ());
2402 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2405 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2406 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2407 remote_control_node->add_property (X_("id"), buf);
2408 node->add_child_nocopy (*remote_control_node);
2410 if (_comment.length()) {
2411 XMLNode *cmt = node->add_child ("Comment");
2412 cmt->add_content (_comment);
2416 node->add_child_nocopy (_pannable->state (full_state));
2420 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2421 for (i = _processors.begin(); i != _processors.end(); ++i) {
2423 /* template save: do not include internal sends functioning as
2424 aux sends because the chance of the target ID
2425 in the session where this template is used
2428 similarly, do not save listen sends which connect to
2429 the monitor section, because these will always be
2432 boost::shared_ptr<InternalSend> is;
2434 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2435 if (is->role() == Delivery::Listen) {
2440 node->add_child_nocopy((*i)->state (full_state));
2445 node->add_child_copy (*_extra_xml);
2448 if (_custom_meter_position_noted) {
2449 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2451 after->id().print (buf, sizeof (buf));
2452 node->add_property (X_("processor-after-last-custom-meter"), buf);
2456 if (!_session._template_state_dir.empty()) {
2457 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2464 Route::set_state (const XMLNode& node, int version)
2466 if (version < 3000) {
2467 return set_state_2X (node, version);
2471 XMLNodeConstIterator niter;
2473 XMLProperty const * prop;
2475 if (node.name() != "Route"){
2476 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2480 if ((prop = node.property (X_("name"))) != 0) {
2481 Route::set_name (prop->value());
2485 _initial_io_setup = true;
2487 if ((prop = node.property (X_("flags"))) != 0) {
2488 _flags = Flag (string_2_enum (prop->value(), _flags));
2493 if ((prop = node.property (X_("strict-io"))) != 0) {
2494 _strict_io = string_is_affirmative (prop->value());
2498 _mute_master->set_solo_ignore (true);
2502 /* monitor bus does not get a panner, but if (re)created
2503 via XML, it will already have one by the time we
2504 call ::set_state(). so ... remove it.
2509 /* add all processors (except amp, which is always present) */
2511 nlist = node.children();
2512 XMLNode processor_state (X_("processor_state"));
2514 Stateful::save_extra_xml (node);
2516 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2520 if (child->name() == IO::state_node_name) {
2521 if ((prop = child->property (X_("direction"))) == 0) {
2525 if (prop->value() == "Input") {
2526 _input->set_state (*child, version);
2527 } else if (prop->value() == "Output") {
2528 _output->set_state (*child, version);
2532 if (child->name() == X_("Processor")) {
2533 processor_state.add_child_copy (*child);
2536 if (child->name() == X_("Pannable")) {
2538 _pannable->set_state (*child, version);
2540 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2544 if (child->name() == Controllable::xml_node_name) {
2545 if ((prop = child->property (X_("name"))) == 0) {
2549 if (prop->value() == _gain_control->name()) {
2550 _gain_control->set_state (*child, version);
2551 } else if (prop->value() == _solo_control->name()) {
2552 _solo_control->set_state (*child, version);
2553 } else if (prop->value() == _solo_safe_control->name()) {
2554 _solo_safe_control->set_state (*child, version);
2555 } else if (prop->value() == _solo_isolate_control->name()) {
2556 _solo_isolate_control->set_state (*child, version);
2557 } else if (prop->value() == _solo_control->name()) {
2558 _mute_control->set_state (*child, version);
2563 if ((prop = node.property (X_("meter-point"))) != 0) {
2564 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2565 set_meter_point (mp, true);
2567 _meter->set_display_to_user (_meter_point == MeterCustom);
2571 if ((prop = node.property (X_("meter-type"))) != 0) {
2572 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2575 _initial_io_setup = false;
2577 set_processor_state (processor_state);
2579 // this looks up the internal instrument in processors
2580 reset_instrument_info();
2582 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2583 set_denormal_protection (string_is_affirmative (prop->value()));
2586 if ((prop = node.property (X_("active"))) != 0) {
2587 bool yn = string_is_affirmative (prop->value());
2588 set_active (yn, this);
2591 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2592 set_order_key (atoi(prop->value()));
2595 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2599 string::size_type colon, equal;
2600 string remaining = prop->value();
2602 while (remaining.length()) {
2604 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2605 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2608 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2609 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2612 string keyname = remaining.substr (0, equal);
2614 if ((keyname == "EditorSort") || (keyname == "editor")) {
2615 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2621 colon = remaining.find_first_of (':');
2623 if (colon != string::npos) {
2624 remaining = remaining.substr (colon+1);
2631 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2632 PBD::ID id (prop->value ());
2633 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2634 ProcessorList::const_iterator i = _processors.begin ();
2635 while (i != _processors.end() && (*i)->id() != id) {
2639 if (i != _processors.end ()) {
2640 _processor_after_last_custom_meter = *i;
2641 _custom_meter_position_noted = true;
2645 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2648 if (child->name() == X_("Comment")) {
2650 /* XXX this is a terrible API design in libxml++ */
2652 XMLNode *cmt = *(child->children().begin());
2653 _comment = cmt->content();
2655 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2656 if (prop->value() == "solo") {
2657 _solo_control->set_state (*child, version);
2658 } else if (prop->value() == "mute") {
2659 _mute_control->set_state (*child, version);
2662 } else if (child->name() == X_("RemoteControl")) {
2663 if ((prop = child->property (X_("id"))) != 0) {
2665 sscanf (prop->value().c_str(), "%d", &x);
2666 set_remote_control_id_internal (x);
2669 } else if (child->name() == MuteMaster::xml_node_name) {
2670 _mute_master->set_state (*child, version);
2672 } else if (child->name() == Automatable::xml_node_name) {
2673 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2681 Route::set_state_2X (const XMLNode& node, int version)
2685 XMLNodeConstIterator niter;
2687 XMLProperty const * prop;
2689 /* 2X things which still remain to be handled:
2695 if (node.name() != "Route") {
2696 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2700 if ((prop = node.property (X_("flags"))) != 0) {
2701 string f = prop->value ();
2702 boost::replace_all (f, "ControlOut", "MonitorOut");
2703 _flags = Flag (string_2_enum (f, _flags));
2708 if (is_master() || is_monitor() || is_auditioner()) {
2709 _mute_master->set_solo_ignore (true);
2712 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2713 set_denormal_protection (string_is_affirmative (prop->value()));
2716 if ((prop = node.property (X_("muted"))) != 0) {
2719 bool muted = string_is_affirmative (prop->value());
2725 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2727 if (string_is_affirmative (prop->value())){
2728 mute_point = mute_point + "PreFader";
2733 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2735 if (string_is_affirmative (prop->value())){
2738 mute_point = mute_point + ",";
2741 mute_point = mute_point + "PostFader";
2746 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2748 if (string_is_affirmative (prop->value())){
2751 mute_point = mute_point + ",";
2754 mute_point = mute_point + "Listen";
2759 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2761 if (string_is_affirmative (prop->value())){
2764 mute_point = mute_point + ",";
2767 mute_point = mute_point + "Main";
2771 _mute_master->set_mute_points (mute_point);
2772 _mute_master->set_muted_by_self (true);
2776 if ((prop = node.property (X_("meter-point"))) != 0) {
2777 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2780 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2781 don't mean the same thing.
2784 if ((prop = node.property (X_("order-keys"))) != 0) {
2788 string::size_type colon, equal;
2789 string remaining = prop->value();
2791 while (remaining.length()) {
2793 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2794 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2797 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2798 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2801 string keyname = remaining.substr (0, equal);
2803 if (keyname == "EditorSort" || keyname == "editor") {
2804 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2810 colon = remaining.find_first_of (':');
2812 if (colon != string::npos) {
2813 remaining = remaining.substr (colon+1);
2822 nlist = node.children ();
2823 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2827 if (child->name() == IO::state_node_name) {
2829 /* there is a note in IO::set_state_2X() about why we have to call
2833 _input->set_state_2X (*child, version, true);
2834 _output->set_state_2X (*child, version, false);
2836 if ((prop = child->property (X_("name"))) != 0) {
2837 Route::set_name (prop->value ());
2842 if ((prop = child->property (X_("active"))) != 0) {
2843 bool yn = string_is_affirmative (prop->value());
2844 _active = !yn; // force switch
2845 set_active (yn, this);
2848 if ((prop = child->property (X_("gain"))) != 0) {
2851 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2852 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2856 /* Set up Panners in the IO */
2857 XMLNodeList io_nlist = child->children ();
2859 XMLNodeConstIterator io_niter;
2862 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2864 io_child = *io_niter;
2866 if (io_child->name() == X_("Panner")) {
2867 _main_outs->panner_shell()->set_state(*io_child, version);
2868 } else if (io_child->name() == X_("Automation")) {
2869 /* IO's automation is for the fader */
2870 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2876 XMLNodeList redirect_nodes;
2878 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2882 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2883 redirect_nodes.push_back(child);
2888 set_processor_state_2X (redirect_nodes, version);
2890 Stateful::save_extra_xml (node);
2892 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2895 if (child->name() == X_("Comment")) {
2897 /* XXX this is a terrible API design in libxml++ */
2899 XMLNode *cmt = *(child->children().begin());
2900 _comment = cmt->content();
2902 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2903 if (prop->value() == X_("solo")) {
2904 _solo_control->set_state (*child, version);
2905 } else if (prop->value() == X_("mute")) {
2906 _mute_control->set_state (*child, version);
2909 } else if (child->name() == X_("RemoteControl")) {
2910 if ((prop = child->property (X_("id"))) != 0) {
2912 sscanf (prop->value().c_str(), "%d", &x);
2913 set_remote_control_id_internal (x);
2923 Route::get_processor_state ()
2925 XMLNode* root = new XMLNode (X_("redirects"));
2926 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2927 root->add_child_nocopy ((*i)->state (true));
2934 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2936 /* We don't bother removing existing processors not in nList, as this
2937 method will only be called when creating a Route from scratch, not
2938 for undo purposes. Just put processors in at the appropriate place
2942 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2943 add_processor_from_xml_2X (**i, version);
2948 Route::set_processor_state (const XMLNode& node)
2950 const XMLNodeList &nlist = node.children();
2951 XMLNodeConstIterator niter;
2952 ProcessorList new_order;
2953 bool must_configure = false;
2955 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2957 XMLProperty* prop = (*niter)->property ("type");
2959 if (prop->value() == "amp") {
2960 _amp->set_state (**niter, Stateful::current_state_version);
2961 new_order.push_back (_amp);
2962 } else if (prop->value() == "trim") {
2963 _trim->set_state (**niter, Stateful::current_state_version);
2964 new_order.push_back (_trim);
2965 } else if (prop->value() == "meter") {
2966 _meter->set_state (**niter, Stateful::current_state_version);
2967 new_order.push_back (_meter);
2968 } else if (prop->value() == "delay") {
2970 _delayline->set_state (**niter, Stateful::current_state_version);
2971 new_order.push_back (_delayline);
2973 } else if (prop->value() == "main-outs") {
2974 _main_outs->set_state (**niter, Stateful::current_state_version);
2975 } else if (prop->value() == "intreturn") {
2977 _intreturn.reset (new InternalReturn (_session));
2978 must_configure = true;
2980 _intreturn->set_state (**niter, Stateful::current_state_version);
2981 } else if (is_monitor() && prop->value() == "monitor") {
2982 if (!_monitor_control) {
2983 _monitor_control.reset (new MonitorProcessor (_session));
2984 must_configure = true;
2986 _monitor_control->set_state (**niter, Stateful::current_state_version);
2987 } else if (prop->value() == "capture") {
2988 /* CapturingProcessor should never be restored, it's always
2989 added explicitly when needed */
2991 ProcessorList::iterator o;
2993 for (o = _processors.begin(); o != _processors.end(); ++o) {
2994 XMLProperty const * id_prop = (*niter)->property(X_("id"));
2995 if (id_prop && (*o)->id() == id_prop->value()) {
2996 (*o)->set_state (**niter, Stateful::current_state_version);
2997 new_order.push_back (*o);
3002 // If the processor (*niter) is not on the route then create it
3004 if (o == _processors.end()) {
3006 boost::shared_ptr<Processor> processor;
3008 if (prop->value() == "intsend") {
3010 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3012 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3013 prop->value() == "lv2" ||
3014 prop->value() == "windows-vst" ||
3015 prop->value() == "lxvst" ||
3016 prop->value() == "luaproc" ||
3017 prop->value() == "audiounit") {
3019 if (_session.get_disable_all_loaded_plugins ()) {
3020 processor.reset (new UnknownProcessor (_session, **niter));
3022 processor.reset (new PluginInsert (_session));
3023 processor->set_owner (this);
3025 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3026 pi->set_strict_io (true);
3030 } else if (prop->value() == "port") {
3032 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3034 } else if (prop->value() == "send") {
3036 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3037 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3038 send->SelfDestruct.connect_same_thread (*this,
3039 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3042 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3046 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3047 /* This processor could not be configured. Turn it into a UnknownProcessor */
3048 processor.reset (new UnknownProcessor (_session, **niter));
3051 /* subscribe to Sidechain IO changes */
3052 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3053 if (pi && pi->has_sidechain ()) {
3054 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3057 /* we have to note the monitor send here, otherwise a new one will be created
3058 and the state of this one will be lost.
3060 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3061 if (isend && isend->role() == Delivery::Listen) {
3062 _monitor_send = isend;
3065 /* it doesn't matter if invisible processors are added here, as they
3066 will be sorted out by setup_invisible_processors () shortly.
3069 new_order.push_back (processor);
3070 must_configure = true;
3076 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3077 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3078 _processors = new_order;
3080 if (must_configure) {
3081 configure_processors_unlocked (0, &lm);
3084 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3086 (*i)->set_owner (this);
3087 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3089 boost::shared_ptr<PluginInsert> pi;
3091 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3092 if (pi->has_no_inputs ()) {
3093 _have_internal_generator = true;
3100 reset_instrument_info ();
3101 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3102 set_processor_positions ();
3106 Route::curve_reallocate ()
3108 // _gain_automation_curve.finish_resize ();
3109 // _pan_automation_curve.finish_resize ();
3113 Route::silence (framecnt_t nframes)
3115 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3120 silence_unlocked (nframes);
3124 Route::silence_unlocked (framecnt_t nframes)
3126 /* Must be called with the processor lock held */
3130 _output->silence (nframes);
3132 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3133 boost::shared_ptr<PluginInsert> pi;
3135 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3136 // skip plugins, they don't need anything when we're not active
3140 (*i)->silence (nframes);
3143 if (nframes == _session.get_block_size()) {
3150 Route::add_internal_return ()
3153 _intreturn.reset (new InternalReturn (_session));
3154 add_processor (_intreturn, PreFader);
3159 Route::add_send_to_internal_return (InternalSend* send)
3161 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3163 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3164 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3167 return d->add_send (send);
3173 Route::remove_send_from_internal_return (InternalSend* send)
3175 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3177 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3178 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3181 return d->remove_send (send);
3187 Route::enable_monitor_send ()
3189 /* Caller must hold process lock */
3190 assert (!AudioEngine::instance()->process_lock().trylock());
3192 /* master never sends to monitor section via the normal mechanism */
3193 assert (!is_master ());
3194 assert (!is_monitor ());
3196 /* make sure we have one */
3197 if (!_monitor_send) {
3198 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3199 _monitor_send->set_display_to_user (false);
3203 configure_processors (0);
3206 /** Add an aux send to a route.
3207 * @param route route to send to.
3208 * @param before Processor to insert before, or 0 to insert at the end.
3211 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3213 assert (route != _session.monitor_out ());
3216 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3218 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3220 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3222 if (d && d->target_route() == route) {
3223 /* already listening via the specified IO: do nothing */
3231 boost::shared_ptr<InternalSend> listener;
3234 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3235 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3236 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3239 add_processor (listener, before);
3241 } catch (failed_constructor& err) {
3249 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3251 ProcessorStreams err;
3252 ProcessorList::iterator tmp;
3255 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3257 /* have to do this early because otherwise processor reconfig
3258 * will put _monitor_send back in the list
3261 if (route == _session.monitor_out()) {
3262 _monitor_send.reset ();
3266 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3268 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3270 if (d && d->target_route() == route) {
3272 if (remove_processor (*x, &err, false) > 0) {
3278 /* list could have been demolished while we dropped the lock
3281 if (_session.engine().connected()) {
3282 /* i/o processors cannot be removed if the engine is not running
3283 * so don't live-loop in case the engine is N/A or dies
3293 Route::set_comment (string cmt, void *src)
3297 _session.set_dirty ();
3301 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3303 FeedRecord fr (other, via_sends_only);
3305 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3307 if (!result.second) {
3309 /* already a record for "other" - make sure sends-only information is correct */
3310 if (!via_sends_only && result.first->sends_only) {
3311 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3312 frp->sends_only = false;
3316 return result.second;
3320 Route::clear_fed_by ()
3326 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3328 const FedBy& fed_by (other->fed_by());
3330 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3331 boost::shared_ptr<Route> sr = f->r.lock();
3333 if (sr && (sr.get() == this)) {
3335 if (via_sends_only) {
3336 *via_sends_only = f->sends_only;
3347 Route::all_inputs () const
3349 /* TODO, if this works as expected,
3350 * cache the IOVector and maintain it via
3351 * input_change_handler(), sidechain_change_handler() etc
3354 ios.push_back (_input);
3356 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3357 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3359 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3360 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3363 iop = pi->sidechain();
3366 if (iop != 0 && iop->input()) {
3367 ios.push_back (iop->input());
3374 Route::all_outputs () const
3377 // _output is included via Delivery
3378 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3379 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3380 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3381 if (iop != 0 && iop->output()) {
3382 ios.push_back (iop->output());
3389 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3391 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3392 if (other->all_inputs().fed_by (_output)) {
3393 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3394 if (via_send_only) {
3395 *via_send_only = false;
3401 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3403 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3405 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3406 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3409 iop = pi->sidechain();
3413 boost::shared_ptr<const IO> iop_out = iop->output();
3414 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3415 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3416 if (via_send_only) {
3417 *via_send_only = true;
3421 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3424 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3429 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3434 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3436 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3440 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3442 return _session._current_route_graph.feeds (shared_from_this (), other);
3445 /** Called from the (non-realtime) butler thread when the transport is stopped */
3447 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3449 framepos_t now = _session.transport_frame();
3452 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3454 Automatable::transport_stopped (now);
3456 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3458 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3462 (*i)->transport_stopped (now);
3466 _roll_delay = _initial_delay;
3470 Route::input_change_handler (IOChange change, void * /*src*/)
3472 if ((change.type & IOChange::ConfigurationChanged)) {
3473 /* This is called with the process lock held if change
3474 contains ConfigurationChanged
3476 configure_processors (0);
3477 _phase_control->resize (_input->n_ports().n_audio ());
3478 io_changed (); /* EMIT SIGNAL */
3481 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3484 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3485 if (_input->connected()) {
3486 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3487 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3491 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3492 if (does_feed && !sends_only) {
3493 if ((*i)->soloed()) {
3496 if ((*i)->solo_isolate_control()->solo_isolated()) {
3503 int delta = sbou - _solo_control->soloed_by_others_upstream();
3504 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3507 PBD::warning << string_compose (
3508 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3509 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3514 if (_solo_control->soloed_by_others_upstream()) {
3515 // ignore new connections (they're not propagated)
3517 _solo_control->mod_solo_by_others_upstream (delta);
3521 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3522 // solo-isolate currently only propagates downstream
3524 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3526 //_solo_isolated_by_upstream = ibou;
3529 // Session::route_solo_changed does not propagate indirect solo-changes
3530 // propagate downstream to tracks
3531 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3532 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3536 bool does_feed = feeds (*i, &sends_only);
3537 if (delta <= 0 && does_feed && !sends_only) {
3538 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3541 if (idelta < 0 && does_feed && !sends_only) {
3542 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3549 Route::output_change_handler (IOChange change, void * /*src*/)
3551 if (_initial_io_setup) {
3555 if ((change.type & IOChange::ConfigurationChanged)) {
3556 /* This is called with the process lock held if change
3557 contains ConfigurationChanged
3559 configure_processors (0);
3562 _session.reset_monitor_section();
3565 io_changed (); /* EMIT SIGNAL */
3568 if (_solo_control->soloed_by_others_downstream()) {
3570 /* checking all all downstream routes for
3571 * explicit of implict solo is a rather drastic measure,
3572 * ideally the input_change_handler() of the other route
3573 * would propagate the change to us.
3575 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3576 if (_output->connected()) {
3577 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3578 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3582 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3583 if (does_feed && !sends_only) {
3584 if ((*i)->soloed()) {
3591 int delta = sbod - _solo_control->soloed_by_others_downstream();
3593 // do not allow new connections to change implicit solo (no propagation)
3594 _solo_control->mod_solo_by_others_downstream (delta);
3595 // Session::route_solo_changed() does not propagate indirect solo-changes
3596 // propagate upstream to tracks
3597 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3598 if ((*i).get() == this || !can_solo()) {
3602 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3603 if (delta != 0 && does_feed && !sends_only) {
3604 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3613 Route::sidechain_change_handler (IOChange change, void* src)
3615 if (_initial_io_setup || _in_sidechain_setup) {
3619 input_change_handler (change, src);
3623 Route::pans_required () const
3625 if (n_outputs().n_audio() < 2) {
3629 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3633 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3635 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3641 if (n_outputs().n_total() == 0) {
3645 if (!_active || n_inputs() == ChanCount::ZERO) {
3646 silence_unlocked (nframes);
3650 if (session_state_changing) {
3651 if (_session.transport_speed() != 0.0f) {
3652 /* we're rolling but some state is changing (e.g. our diskstream contents)
3653 so we cannot use them. Be silent till this is over.
3655 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3657 silence_unlocked (nframes);
3660 /* we're really not rolling, so we're either delivery silence or actually
3661 monitoring, both of which are safe to do while session_state_changing is true.
3665 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3667 fill_buffers_with_input (bufs, _input, nframes);
3669 if (_meter_point == MeterInput) {
3670 _meter->run (bufs, start_frame, end_frame, nframes, true);
3673 _amp->apply_gain_automation (false);
3674 _trim->apply_gain_automation (false);
3675 passthru (bufs, start_frame, end_frame, nframes, 0);
3681 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3683 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3688 if (n_outputs().n_total() == 0) {
3692 if (!_active || n_inputs().n_total() == 0) {
3693 silence_unlocked (nframes);
3697 framepos_t unused = 0;
3699 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3705 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3707 fill_buffers_with_input (bufs, _input, nframes);
3709 if (_meter_point == MeterInput) {
3710 _meter->run (bufs, start_frame, end_frame, nframes, true);
3713 passthru (bufs, start_frame, end_frame, nframes, declick);
3719 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3726 Route::flush_processors ()
3728 /* XXX shouldn't really try to take this lock, since
3729 this is called from the RT audio thread.
3732 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3734 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3740 __attribute__((annotate("realtime")))
3743 Route::apply_processor_changes_rt ()
3745 int emissions = EmitNone;
3747 if (_pending_meter_point != _meter_point) {
3748 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3750 /* meters always have buffers for 'processor_max_streams'
3751 * they can be re-positioned without re-allocation */
3752 if (set_meter_point_unlocked()) {
3753 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3755 emissions |= EmitMeterChanged;
3760 bool changed = false;
3762 if (g_atomic_int_get (&_pending_process_reorder)) {
3763 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3765 apply_processor_order (_pending_processor_order);
3766 setup_invisible_processors ();
3768 g_atomic_int_set (&_pending_process_reorder, 0);
3769 emissions |= EmitRtProcessorChange;
3773 set_processor_positions ();
3775 if (emissions != 0) {
3776 g_atomic_int_set (&_pending_signals, emissions);
3779 return (!selfdestruct_sequence.empty ());
3783 Route::emit_pending_signals ()
3785 int sig = g_atomic_int_and (&_pending_signals, 0);
3786 if (sig & EmitMeterChanged) {
3787 _meter->emit_configuration_changed();
3788 meter_change (); /* EMIT SIGNAL */
3789 if (sig & EmitMeterVisibilityChange) {
3790 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3792 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3795 if (sig & EmitRtProcessorChange) {
3796 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3799 /* this would be a job for the butler.
3800 * Conceptually we should not take processe/processor locks here.
3801 * OTOH its more efficient (less overhead for summoning the butler and
3802 * telling her what do do) and signal emission is called
3803 * directly after the process callback, which decreases the chance
3804 * of x-runs when taking the locks.
3806 while (!selfdestruct_sequence.empty ()) {
3807 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3808 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3809 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3810 selfdestruct_sequence.pop_back ();
3813 remove_processor (proc);
3819 Route::set_meter_point (MeterPoint p, bool force)
3821 if (_pending_meter_point == p && !force) {
3825 if (force || !AudioEngine::instance()->running()) {
3826 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3827 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3828 _pending_meter_point = p;
3829 _meter->emit_configuration_changed();
3830 meter_change (); /* EMIT SIGNAL */
3831 if (set_meter_point_unlocked()) {
3832 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3834 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3837 _pending_meter_point = p;
3843 __attribute__((annotate("realtime")))
3846 Route::set_meter_point_unlocked ()
3849 /* Caller must hold process and processor write lock */
3850 assert (!AudioEngine::instance()->process_lock().trylock());
3851 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3852 assert (!lm.locked ());
3855 _meter_point = _pending_meter_point;
3857 bool meter_was_visible_to_user = _meter->display_to_user ();
3859 if (!_custom_meter_position_noted) {
3860 maybe_note_meter_position ();
3863 if (_meter_point != MeterCustom) {
3865 _meter->set_display_to_user (false);
3867 setup_invisible_processors ();
3870 _meter->set_display_to_user (true);
3872 /* If we have a previous position for the custom meter, try to put it there */
3873 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3875 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3876 if (i != _processors.end ()) {
3877 _processors.remove (_meter);
3878 _processors.insert (i, _meter);
3880 } else {// at end, right before the mains_out/panner
3881 _processors.remove (_meter);
3882 ProcessorList::iterator main = _processors.end();
3883 _processors.insert (--main, _meter);
3887 /* Set up the meter for its new position */
3889 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3893 if (loc == _processors.begin()) {
3894 m_in = _input->n_ports();
3896 ProcessorList::iterator before = loc;
3898 m_in = (*before)->output_streams ();
3901 _meter->reflect_inputs (m_in);
3903 /* we do not need to reconfigure the processors, because the meter
3904 (a) is always ready to handle processor_max_streams
3905 (b) is always an N-in/N-out processor, and thus moving
3906 it doesn't require any changes to the other processors.
3909 /* these should really be done after releasing the lock
3910 * but all those signals are subscribed to with gui_thread()
3913 return (_meter->display_to_user() != meter_was_visible_to_user);
3917 Route::listen_position_changed ()
3920 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3921 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3922 ProcessorState pstate (this);
3924 if (configure_processors_unlocked (0, &lm)) {
3925 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3927 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3932 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3933 _session.set_dirty ();
3936 boost::shared_ptr<CapturingProcessor>
3937 Route::add_export_point()
3939 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3940 if (!_capturing_processor) {
3942 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3943 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3945 _capturing_processor.reset (new CapturingProcessor (_session));
3946 _capturing_processor->activate ();
3948 configure_processors_unlocked (0, &lw);
3952 return _capturing_processor;
3956 Route::update_signal_latency ()
3958 framecnt_t l = _output->user_latency();
3959 framecnt_t lamp = 0;
3960 bool before_amp = true;
3961 framecnt_t ltrim = 0;
3962 bool before_trim = true;
3964 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3965 if ((*i)->active ()) {
3966 l += (*i)->signal_latency ();
3971 if ((*i) == _trim) {
3982 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3984 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3985 _signal_latency_at_amp_position = lamp;
3986 _signal_latency_at_trim_position = ltrim;
3988 if (_signal_latency != l) {
3989 _signal_latency = l;
3990 signal_latency_changed (); /* EMIT SIGNAL */
3993 return _signal_latency;
3997 Route::set_user_latency (framecnt_t nframes)
3999 _output->set_user_latency (nframes);
4000 _session.update_latency_compensation ();
4004 Route::set_latency_compensation (framecnt_t longest_session_latency)
4006 framecnt_t old = _initial_delay;
4008 if (_signal_latency < longest_session_latency) {
4009 _initial_delay = longest_session_latency - _signal_latency;
4014 DEBUG_TRACE (DEBUG::Latency, string_compose (
4015 "%1: compensate for maximum latency of %2,"
4016 "given own latency of %3, using initial delay of %4\n",
4017 name(), longest_session_latency, _signal_latency, _initial_delay));
4019 if (_initial_delay != old) {
4020 initial_delay_changed (); /* EMIT SIGNAL */
4023 if (_session.transport_stopped()) {
4024 _roll_delay = _initial_delay;
4029 Route::set_block_size (pframes_t nframes)
4031 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4032 (*i)->set_block_size (nframes);
4035 _session.ensure_buffers (n_process_buffers ());
4039 Route::protect_automation ()
4041 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4042 (*i)->protect_automation();
4045 /** @param declick 1 to set a pending declick fade-in,
4046 * -1 to set a pending declick fade-out
4049 Route::set_pending_declick (int declick)
4052 /* this call is not allowed to turn off a pending declick */
4054 _pending_declick = declick;
4057 _pending_declick = 0;
4061 /** Shift automation forwards from a particular place, thereby inserting time.
4062 * Adds undo commands for any shifts that are performed.
4064 * @param pos Position to start shifting from.
4065 * @param frames Amount to shift forwards by.
4069 Route::shift (framepos_t pos, framecnt_t frames)
4071 /* gain automation */
4073 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4075 XMLNode &before = gc->alist()->get_state ();
4076 gc->alist()->shift (pos, frames);
4077 XMLNode &after = gc->alist()->get_state ();
4078 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4081 /* gain automation */
4083 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4085 XMLNode &before = gc->alist()->get_state ();
4086 gc->alist()->shift (pos, frames);
4087 XMLNode &after = gc->alist()->get_state ();
4088 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4091 // TODO mute automation ??
4093 /* pan automation */
4095 ControlSet::Controls& c (_pannable->controls());
4097 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4098 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4100 boost::shared_ptr<AutomationList> al = pc->alist();
4101 XMLNode& before = al->get_state ();
4102 al->shift (pos, frames);
4103 XMLNode& after = al->get_state ();
4104 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4109 /* redirect automation */
4111 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4112 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4114 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4116 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4117 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4119 boost::shared_ptr<AutomationList> al = ac->alist();
4120 XMLNode &before = al->get_state ();
4121 al->shift (pos, frames);
4122 XMLNode &after = al->get_state ();
4123 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4131 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4133 boost::shared_ptr<Processor> processor (p.lock ());
4134 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4138 pi->set_state_dir (d);
4142 Route::save_as_template (const string& path, const string& name)
4144 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4145 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4147 XMLNode& node (state (false));
4151 IO::set_name_in_state (*node.children().front(), name);
4153 tree.set_root (&node);
4155 /* return zero on success, non-zero otherwise */
4156 return !tree.write (path.c_str());
4161 Route::set_name (const string& str)
4163 if (str == name()) {
4167 string name = Route::ensure_track_or_route_name (str, _session);
4168 SessionObject::set_name (name);
4170 bool ret = (_input->set_name(name) && _output->set_name(name));
4173 /* rename the main outs. Leave other IO processors
4174 * with whatever name they already have, because its
4175 * just fine as it is (it will not contain the route
4176 * name if its a port insert, port send or port return).
4180 if (_main_outs->set_name (name)) {
4181 /* XXX returning false here is stupid because
4182 we already changed the route name.
4192 /** Set the name of a route in an XML description.
4193 * @param node XML <Route> node to set the name in.
4194 * @param name New name.
4197 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4199 node.add_property (X_("name"), name);
4201 XMLNodeList children = node.children();
4202 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4204 if ((*i)->name() == X_("IO")) {
4206 IO::set_name_in_state (**i, name);
4208 } else if ((*i)->name() == X_("Processor")) {
4210 XMLProperty const * role = (*i)->property (X_("role"));
4211 if (role && role->value() == X_("Main")) {
4212 (*i)->add_property (X_("name"), name);
4215 } else if ((*i)->name() == X_("Diskstream")) {
4217 if (rename_playlist) {
4218 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4220 (*i)->add_property (X_("name"), name);
4226 boost::shared_ptr<Send>
4227 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4229 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4231 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4232 boost::shared_ptr<InternalSend> send;
4234 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4235 if (send->target_route() == target) {
4241 return boost::shared_ptr<Send>();
4245 Route::set_denormal_protection (bool yn)
4247 if (_denormal_protection != yn) {
4248 _denormal_protection = yn;
4249 denormal_protection_changed (); /* EMIT SIGNAL */
4254 Route::denormal_protection () const
4256 return _denormal_protection;
4260 Route::set_active (bool yn, void* src)
4262 if (_session.transport_rolling()) {
4266 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4267 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4271 if (_active != yn) {
4273 _input->set_active (yn);
4274 _output->set_active (yn);
4275 active_changed (); // EMIT SIGNAL
4276 _session.set_dirty ();
4280 boost::shared_ptr<Pannable>
4281 Route::pannable() const
4286 boost::shared_ptr<Panner>
4287 Route::panner() const
4290 return _main_outs->panner_shell()->panner();
4293 boost::shared_ptr<PannerShell>
4294 Route::panner_shell() const
4296 return _main_outs->panner_shell();
4299 boost::shared_ptr<GainControl>
4300 Route::gain_control() const
4302 return _gain_control;
4305 boost::shared_ptr<GainControl>
4306 Route::trim_control() const
4308 return _trim_control;
4311 boost::shared_ptr<PhaseControl>
4312 Route::phase_control() const
4314 return _phase_control;
4317 boost::shared_ptr<AutomationControl>
4318 Route::get_control (const Evoral::Parameter& param)
4320 /* either we own the control or .... */
4322 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4326 /* maybe one of our processors does or ... */
4328 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4329 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4330 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4338 /* nobody does so we'll make a new one */
4340 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4347 boost::shared_ptr<Processor>
4348 Route::nth_plugin (uint32_t n) const
4350 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4351 ProcessorList::const_iterator i;
4353 for (i = _processors.begin(); i != _processors.end(); ++i) {
4354 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4361 return boost::shared_ptr<Processor> ();
4364 boost::shared_ptr<Processor>
4365 Route::nth_send (uint32_t n) const
4367 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4368 ProcessorList::const_iterator i;
4370 for (i = _processors.begin(); i != _processors.end(); ++i) {
4371 if (boost::dynamic_pointer_cast<Send> (*i)) {
4373 if ((*i)->name().find (_("Monitor")) == 0) {
4374 /* send to monitor section is not considered
4375 to be an accessible send.
4386 return boost::shared_ptr<Processor> ();
4390 Route::has_io_processor_named (const string& name)
4392 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4393 ProcessorList::iterator i;
4395 for (i = _processors.begin(); i != _processors.end(); ++i) {
4396 if (boost::dynamic_pointer_cast<Send> (*i) ||
4397 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4398 if ((*i)->name() == name) {
4408 Route::set_processor_positions ()
4410 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4412 bool had_amp = false;
4413 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4414 (*i)->set_pre_fader (!had_amp);
4421 /** Called when there is a proposed change to the input port count */
4423 Route::input_port_count_changing (ChanCount to)
4425 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4427 /* The processors cannot be configured with the new input arrangement, so
4433 /* The change is ok */
4437 /** Called when there is a proposed change to the output port count */
4439 Route::output_port_count_changing (ChanCount to)
4441 if (_strict_io && !_in_configure_processors) {
4444 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4445 if (processor_out_streams.get(*t) > to.get(*t)) {
4449 /* The change is ok */
4454 Route::unknown_processors () const
4458 if (_session.get_disable_all_loaded_plugins ()) {
4459 // Do not list "missing plugins" if they are explicitly disabled
4463 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4464 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4465 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4466 p.push_back ((*i)->name ());
4475 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4477 /* we assume that all our input ports feed all our output ports. its not
4478 universally true, but the alternative is way too corner-case to worry about.
4481 LatencyRange all_connections;
4484 all_connections.min = 0;
4485 all_connections.max = 0;
4487 all_connections.min = ~((pframes_t) 0);
4488 all_connections.max = 0;
4490 /* iterate over all "from" ports and determine the latency range for all of their
4491 connections to the "outside" (outside of this Route).
4494 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4498 p->get_connected_latency_range (range, playback);
4500 all_connections.min = min (all_connections.min, range.min);
4501 all_connections.max = max (all_connections.max, range.max);
4505 /* set the "from" port latencies to the max/min range of all their connections */
4507 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4508 p->set_private_latency_range (all_connections, playback);
4511 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4513 all_connections.min += our_latency;
4514 all_connections.max += our_latency;
4516 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4517 p->set_private_latency_range (all_connections, playback);
4520 return all_connections.max;
4524 Route::set_private_port_latencies (bool playback) const
4526 framecnt_t own_latency = 0;
4528 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4529 OR LATENCY CALLBACK.
4531 This is called (early) from the latency callback. It computes the REAL
4532 latency associated with each port and stores the result as the "private"
4533 latency of the port. A later call to Route::set_public_port_latencies()
4534 sets all ports to the same value to reflect the fact that we do latency
4535 compensation and so all signals are delayed by the same amount as they
4536 flow through ardour.
4539 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4540 if ((*i)->active ()) {
4541 own_latency += (*i)->signal_latency ();
4546 /* playback: propagate latency from "outside the route" to outputs to inputs */
4547 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4549 /* capture: propagate latency from "outside the route" to inputs to outputs */
4550 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4555 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4557 /* this is called to set the JACK-visible port latencies, which take
4558 latency compensation into account.
4567 const PortSet& ports (_input->ports());
4568 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4569 p->set_public_latency_range (range, playback);
4574 const PortSet& ports (_output->ports());
4575 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4576 p->set_public_latency_range (range, playback);
4581 /** Put the invisible processors in the right place in _processors.
4582 * Must be called with a writer lock on _processor_lock held.
4585 __attribute__((annotate("realtime")))
4588 Route::setup_invisible_processors ()
4591 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4592 assert (!lm.locked ());
4596 /* too early to be doing this stuff */
4600 /* we'll build this new list here and then use it
4602 * TODO put the ProcessorList is on the stack for RT-safety.
4605 ProcessorList new_processors;
4607 /* find visible processors */
4609 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4610 if ((*i)->display_to_user ()) {
4611 new_processors.push_back (*i);
4617 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4619 if (amp == new_processors.end ()) {
4620 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4621 new_processors.push_front (_amp);
4622 amp = find (new_processors.begin(), new_processors.end(), _amp);
4625 /* and the processor after the amp */
4627 ProcessorList::iterator after_amp = amp;
4633 switch (_meter_point) {
4635 assert (!_meter->display_to_user ());
4636 new_processors.push_front (_meter);
4639 assert (!_meter->display_to_user ());
4640 new_processors.insert (amp, _meter);
4642 case MeterPostFader:
4643 /* do nothing here */
4646 /* do nothing here */
4649 /* the meter is visible, so we don't touch it here */
4656 assert (_main_outs);
4657 assert (!_main_outs->display_to_user ());
4658 new_processors.push_back (_main_outs);
4660 /* iterator for the main outs */
4662 ProcessorList::iterator main = new_processors.end();
4665 /* OUTPUT METERING */
4667 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4668 assert (!_meter->display_to_user ());
4670 /* add the processor just before or just after the main outs */
4672 ProcessorList::iterator meter_point = main;
4674 if (_meter_point == MeterOutput) {
4677 new_processors.insert (meter_point, _meter);
4682 if (_monitor_send && !is_monitor ()) {
4683 assert (!_monitor_send->display_to_user ());
4684 switch (Config->get_listen_position ()) {
4685 case PreFaderListen:
4686 switch (Config->get_pfl_position ()) {
4687 case PFLFromBeforeProcessors:
4688 new_processors.push_front (_monitor_send);
4690 case PFLFromAfterProcessors:
4691 new_processors.insert (amp, _monitor_send);
4694 _monitor_send->set_can_pan (false);
4696 case AfterFaderListen:
4697 switch (Config->get_afl_position ()) {
4698 case AFLFromBeforeProcessors:
4699 new_processors.insert (after_amp, _monitor_send);
4701 case AFLFromAfterProcessors:
4702 new_processors.insert (new_processors.end(), _monitor_send);
4705 _monitor_send->set_can_pan (true);
4710 #if 0 // not used - just yet
4711 if (!is_master() && !is_monitor() && !is_auditioner()) {
4712 new_processors.push_front (_delayline);
4716 /* MONITOR CONTROL */
4718 if (_monitor_control && is_monitor ()) {
4719 assert (!_monitor_control->display_to_user ());
4720 new_processors.insert (amp, _monitor_control);
4723 /* INTERNAL RETURN */
4725 /* doing this here means that any monitor control will come just after
4730 assert (!_intreturn->display_to_user ());
4731 new_processors.push_front (_intreturn);
4734 if (_trim && _trim->active()) {
4735 assert (!_trim->display_to_user ());
4736 new_processors.push_front (_trim);
4738 /* EXPORT PROCESSOR */
4740 if (_capturing_processor) {
4741 assert (!_capturing_processor->display_to_user ());
4742 new_processors.push_front (_capturing_processor);
4745 _processors = new_processors;
4747 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4748 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4753 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4754 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4755 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4762 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4763 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4767 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4768 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4775 /** If the meter point is `Custom', make a note of where the meter is.
4776 * This is so that if the meter point is subsequently set to something else,
4777 * and then back to custom, we can put the meter back where it was last time
4778 * custom was enabled.
4780 * Must be called with the _processor_lock held.
4783 Route::maybe_note_meter_position ()
4785 if (_meter_point != MeterCustom) {
4789 _custom_meter_position_noted = true;
4790 /* custom meter points range from after trim to before panner/main_outs
4791 * this is a limitation by the current processor UI
4793 bool seen_trim = false;
4794 _processor_after_last_custom_meter.reset();
4795 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4796 if ((*i) == _trim) {
4799 if ((*i) == _main_outs) {
4800 _processor_after_last_custom_meter = *i;
4803 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4805 _processor_after_last_custom_meter = _trim;
4807 ProcessorList::iterator j = i;
4809 assert(j != _processors.end ()); // main_outs should be before
4810 _processor_after_last_custom_meter = *j;
4815 assert(_processor_after_last_custom_meter.lock());
4818 boost::shared_ptr<Processor>
4819 Route::processor_by_id (PBD::ID id) const
4821 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4822 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4823 if ((*i)->id() == id) {
4828 return boost::shared_ptr<Processor> ();
4831 /** @return the monitoring state, or in other words what data we are pushing
4832 * into the route (data from the inputs, data from disk or silence)
4835 Route::monitoring_state () const
4837 return MonitoringInput;
4840 /** @return what we should be metering; either the data coming from the input
4841 * IO or the data that is flowing through the route.
4844 Route::metering_state () const
4846 return MeteringRoute;
4850 Route::has_external_redirects () const
4852 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4854 /* ignore inactive processors and obviously ignore the main
4855 * outs since everything has them and we don't care.
4858 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4866 boost::shared_ptr<Processor>
4867 Route::the_instrument () const
4869 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4870 return the_instrument_unlocked ();
4873 boost::shared_ptr<Processor>
4874 Route::the_instrument_unlocked () const
4876 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4877 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4878 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4882 return boost::shared_ptr<Processor>();
4888 Route::non_realtime_locate (framepos_t pos)
4891 _pannable->transport_located (pos);
4894 if (_delayline.get()) {
4895 _delayline.get()->flush();
4899 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4900 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4902 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4903 (*i)->transport_located (pos);
4906 _roll_delay = _initial_delay;
4910 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4917 * We don't currently mix MIDI input together, so we don't need the
4918 * complex logic of the audio case.
4921 n_buffers = bufs.count().n_midi ();
4923 for (i = 0; i < n_buffers; ++i) {
4925 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4926 MidiBuffer& buf (bufs.get_midi (i));
4929 buf.copy (source_port->get_midi_buffer(nframes));
4931 buf.silence (nframes);
4937 n_buffers = bufs.count().n_audio();
4939 size_t n_ports = io->n_ports().n_audio();
4940 float scaling = 1.0f;
4942 if (n_ports > n_buffers) {
4943 scaling = ((float) n_buffers) / n_ports;
4946 for (i = 0; i < n_ports; ++i) {
4948 /* if there are more ports than buffers, map them onto buffers
4949 * in a round-robin fashion
4952 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4953 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4956 if (i < n_buffers) {
4958 /* first time through just copy a channel into
4962 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4964 if (scaling != 1.0f) {
4965 buf.apply_gain (scaling, nframes);
4970 /* on subsequent times around, merge data from
4971 * the port with what is already there
4974 if (scaling != 1.0f) {
4975 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4977 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4982 /* silence any remaining buffers */
4984 for (; i < n_buffers; ++i) {
4985 AudioBuffer& buf (bufs.get_audio (i));
4986 buf.silence (nframes);
4989 /* establish the initial setup of the buffer set, reflecting what was
4990 copied into it. unless, of course, we are the auditioner, in which
4991 case nothing was fed into it from the inputs at all.
4994 if (!is_auditioner()) {
4995 bufs.set_count (io->n_ports());
4999 boost::shared_ptr<AutomationControl>
5000 Route::pan_azimuth_control() const
5003 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5005 return boost::shared_ptr<AutomationControl>();
5007 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
5008 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5010 if (!_pannable || !panner()) {
5011 return boost::shared_ptr<AutomationControl>();
5013 return _pannable->pan_azimuth_control;
5017 boost::shared_ptr<AutomationControl>
5018 Route::pan_elevation_control() const
5020 if (Profile->get_mixbus() || !_pannable || !panner()) {
5021 return boost::shared_ptr<AutomationControl>();
5024 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5026 if (c.find (PanElevationAutomation) != c.end()) {
5027 return _pannable->pan_elevation_control;
5029 return boost::shared_ptr<AutomationControl>();
5032 boost::shared_ptr<AutomationControl>
5033 Route::pan_width_control() const
5035 if (Profile->get_mixbus() || !_pannable || !panner()) {
5036 return boost::shared_ptr<AutomationControl>();
5039 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5041 if (c.find (PanWidthAutomation) != c.end()) {
5042 return _pannable->pan_width_control;
5044 return boost::shared_ptr<AutomationControl>();
5047 boost::shared_ptr<AutomationControl>
5048 Route::pan_frontback_control() const
5050 if (Profile->get_mixbus() || !_pannable || !panner()) {
5051 return boost::shared_ptr<AutomationControl>();
5054 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5056 if (c.find (PanFrontBackAutomation) != c.end()) {
5057 return _pannable->pan_frontback_control;
5059 return boost::shared_ptr<AutomationControl>();
5062 boost::shared_ptr<AutomationControl>
5063 Route::pan_lfe_control() const
5065 if (Profile->get_mixbus() || !_pannable || !panner()) {
5066 return boost::shared_ptr<AutomationControl>();
5069 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5071 if (c.find (PanLFEAutomation) != c.end()) {
5072 return _pannable->pan_lfe_control;
5074 return boost::shared_ptr<AutomationControl>();
5079 Route::eq_band_cnt () const
5081 if (Profile->get_mixbus()) {
5084 /* Ardour has no well-known EQ object */
5089 boost::shared_ptr<AutomationControl>
5090 Route::eq_gain_controllable (uint32_t band) const
5093 boost::shared_ptr<PluginInsert> eq = ch_eq();
5096 return boost::shared_ptr<AutomationControl>();
5099 uint32_t port_number;
5102 if (is_master() || mixbus()) {
5109 if (is_master() || mixbus()) {
5116 if (is_master() || mixbus()) {
5123 return boost::shared_ptr<AutomationControl>();
5126 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5128 return boost::shared_ptr<AutomationControl>();
5131 boost::shared_ptr<AutomationControl>
5132 Route::eq_freq_controllable (uint32_t band) const
5136 if (mixbus() || is_master()) {
5137 /* no frequency controls for mixbusses or master */
5138 return boost::shared_ptr<AutomationControl>();
5141 boost::shared_ptr<PluginInsert> eq = ch_eq();
5144 return boost::shared_ptr<AutomationControl>();
5147 uint32_t port_number;
5159 return boost::shared_ptr<AutomationControl>();
5162 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5164 return boost::shared_ptr<AutomationControl>();
5168 boost::shared_ptr<AutomationControl>
5169 Route::eq_q_controllable (uint32_t band) const
5171 return boost::shared_ptr<AutomationControl>();
5174 boost::shared_ptr<AutomationControl>
5175 Route::eq_shape_controllable (uint32_t band) const
5177 return boost::shared_ptr<AutomationControl>();
5180 boost::shared_ptr<AutomationControl>
5181 Route::eq_enable_controllable () const
5184 boost::shared_ptr<PluginInsert> eq = ch_eq();
5187 return boost::shared_ptr<AutomationControl>();
5190 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5192 return boost::shared_ptr<AutomationControl>();
5196 boost::shared_ptr<AutomationControl>
5197 Route::eq_hpf_controllable () const
5200 boost::shared_ptr<PluginInsert> eq = ch_eq();
5203 return boost::shared_ptr<AutomationControl>();
5206 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5208 return boost::shared_ptr<AutomationControl>();
5213 Route::eq_band_name (uint32_t band) const
5215 if (Profile->get_mixbus()) {
5231 boost::shared_ptr<AutomationControl>
5232 Route::comp_enable_controllable () const
5235 boost::shared_ptr<PluginInsert> comp = ch_comp();
5238 return boost::shared_ptr<AutomationControl>();
5241 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5243 return boost::shared_ptr<AutomationControl>();
5246 boost::shared_ptr<AutomationControl>
5247 Route::comp_threshold_controllable () const
5250 boost::shared_ptr<PluginInsert> comp = ch_comp();
5253 return boost::shared_ptr<AutomationControl>();
5256 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5259 return boost::shared_ptr<AutomationControl>();
5262 boost::shared_ptr<AutomationControl>
5263 Route::comp_speed_controllable () const
5266 boost::shared_ptr<PluginInsert> comp = ch_comp();
5269 return boost::shared_ptr<AutomationControl>();
5272 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5274 return boost::shared_ptr<AutomationControl>();
5277 boost::shared_ptr<AutomationControl>
5278 Route::comp_mode_controllable () const
5281 boost::shared_ptr<PluginInsert> comp = ch_comp();
5284 return boost::shared_ptr<AutomationControl>();
5287 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5289 return boost::shared_ptr<AutomationControl>();
5292 boost::shared_ptr<AutomationControl>
5293 Route::comp_makeup_controllable () const
5296 boost::shared_ptr<PluginInsert> comp = ch_comp();
5299 return boost::shared_ptr<AutomationControl>();
5302 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5304 return boost::shared_ptr<AutomationControl>();
5307 boost::shared_ptr<AutomationControl>
5308 Route::comp_redux_controllable () const
5311 boost::shared_ptr<PluginInsert> comp = ch_comp();
5314 return boost::shared_ptr<AutomationControl>();
5317 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5319 return boost::shared_ptr<AutomationControl>();
5324 Route::comp_mode_name (uint32_t mode) const
5329 return _("Leveler");
5331 return _("Compressor");
5333 return _("Limiter");
5335 return mixbus() ? _("Sidechain") : _("Limiter");
5345 Route::comp_speed_name (uint32_t mode) const
5363 boost::shared_ptr<AutomationControl>
5364 Route::send_level_controllable (uint32_t n) const
5367 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5369 return boost::shared_ptr<AutomationControl>();
5374 return boost::shared_ptr<AutomationControl>();
5377 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5378 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5380 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5382 return boost::shared_ptr<AutomationControl>();
5384 return s->gain_control ();
5388 boost::shared_ptr<AutomationControl>
5389 Route::send_enable_controllable (uint32_t n) const
5392 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5394 return boost::shared_ptr<AutomationControl>();
5399 return boost::shared_ptr<AutomationControl>();
5402 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5403 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5405 /* although Ardour sends have enable/disable as part of the Processor
5406 API, it is not exposed as a controllable.
5408 XXX: we should fix this.
5410 return boost::shared_ptr<AutomationControl>();
5415 Route::send_name (uint32_t n) const
5421 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5425 boost::shared_ptr<Processor> p = nth_send (n);
5434 boost::shared_ptr<AutomationControl>
5435 Route::master_send_enable_controllable () const
5438 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5440 return boost::shared_ptr<AutomationControl>();
5442 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5444 return boost::shared_ptr<AutomationControl>();
5449 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5451 if (!vca || !_gain_control) {
5455 return _gain_control->slaved_to (vca->gain_control());
5459 Route::vca_assign (boost::shared_ptr<VCA> vca)
5461 _gain_control->add_master (vca->gain_control());
5462 _solo_control->add_master (vca->solo_control());
5463 _mute_control->add_master (vca->mute_control());
5467 Route::vca_unassign (boost::shared_ptr<VCA> vca)
5470 /* unassign from all */
5471 _gain_control->clear_masters ();
5472 _solo_control->clear_masters ();
5473 _mute_control->clear_masters ();
5475 _gain_control->remove_master (vca->gain_control());
5476 _solo_control->remove_master (vca->solo_control());
5477 _mute_control->remove_master (vca->mute_control());
5482 Route::muted_by_others_soloing () const
5484 // This method is only used by route_ui for display state.
5485 // The DSP version is MuteMaster::muted_by_others_at()
5487 if (!can_be_muted_by_others ()) {
5491 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5495 Route::muted_by_others () const
5497 // This method is only used by route_ui for display state.
5498 // The DSP version is MuteMaster::muted_by_others_at()
5500 if (!can_be_muted_by_others()) {
5504 return _mute_master->muted_by_others();
5508 Route::clear_all_solo_state ()
5510 double v = _solo_safe_control->get_value ();
5512 _solo_control->clear_all_solo_state ();
5515 _solo_safe_control->set_value (v, Controllable::NoGroup);