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 "pbd/xml++.h"
30 #include "pbd/enumwriter.h"
31 #include "pbd/memento_command.h"
32 #include "pbd/stacktrace.h"
33 #include "pbd/convert.h"
34 #include "pbd/boost_debug.h"
36 #include "evoral/Curve.hpp"
38 #include "ardour/amp.h"
39 #include "ardour/audio_port.h"
40 #include "ardour/audioengine.h"
41 #include "ardour/buffer.h"
42 #include "ardour/buffer_set.h"
43 #include "ardour/configuration.h"
44 #include "ardour/cycle_timer.h"
45 #include "ardour/debug.h"
46 #include "ardour/delivery.h"
47 #include "ardour/dB.h"
48 #include "ardour/internal_send.h"
49 #include "ardour/internal_return.h"
50 #include "ardour/ladspa_plugin.h"
51 #include "ardour/meter.h"
52 #include "ardour/mix.h"
53 #include "ardour/monitor_processor.h"
54 #include "ardour/pannable.h"
55 #include "ardour/panner.h"
56 #include "ardour/panner_shell.h"
57 #include "ardour/plugin_insert.h"
58 #include "ardour/port.h"
59 #include "ardour/port_insert.h"
60 #include "ardour/processor.h"
61 #include "ardour/profile.h"
62 #include "ardour/route.h"
63 #include "ardour/route_group.h"
64 #include "ardour/send.h"
65 #include "ardour/session.h"
66 #include "ardour/timestamps.h"
67 #include "ardour/utils.h"
68 #include "ardour/unknown_processor.h"
69 #include "ardour/capturing_processor.h"
74 using namespace ARDOUR;
77 uint32_t Route::order_key_cnt = 0;
78 PBD::Signal1<void,string const&> Route::SyncOrderKeys;
79 PBD::Signal0<void> Route::RemoteControlIDChange;
81 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
82 : SessionObject (sess, name)
84 , GraphNode (sess._process_graph)
90 , _pending_declick (true)
91 , _meter_point (MeterPostFader)
93 , _soloed_by_others_upstream (0)
94 , _soloed_by_others_downstream (0)
96 , _denormal_protection (false)
99 , _declickable (false)
100 , _mute_master (new MuteMaster (sess, name))
101 , _have_internal_generator (false)
103 , _default_type (default_type)
104 , _remote_control_id (0)
105 , _in_configure_processors (false)
106 , _custom_meter_position_noted (false)
107 , _last_custom_meter_was_at_end (false)
109 processor_max_streams.reset();
110 order_keys[N_("signal")] = order_key_cnt++;
113 set_remote_control_id (MasterBusRemoteControlID);
114 } else if (is_monitor()) {
115 set_remote_control_id (MonitorBusRemoteControlID);
123 /* add standard controls */
125 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
126 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
128 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
129 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
131 add_control (_solo_control);
132 add_control (_mute_control);
136 if (!(_flags & Route::MonitorOut)) {
137 _pannable.reset (new Pannable (_session));
140 /* input and output objects */
142 _input.reset (new IO (_session, _name, IO::Input, _default_type));
143 _output.reset (new IO (_session, _name, IO::Output, _default_type));
145 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
146 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
148 /* add amp processor */
150 _amp.reset (new Amp (_session));
151 add_processor (_amp, PostFader);
153 /* create standard processors: meter, main outs, monitor out;
154 they will be added to _processors by setup_invisible_processors ()
157 _meter.reset (new PeakMeter (_session));
158 _meter->set_display_to_user (false);
161 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
162 _main_outs->activate ();
165 /* where we listen to tracks */
166 _intreturn.reset (new InternalReturn (_session));
167 _intreturn->activate ();
169 /* the thing that provides proper control over a control/monitor/listen bus
170 (such as per-channel cut, dim, solo, invert, etc).
172 _monitor_control.reset (new MonitorProcessor (_session));
173 _monitor_control->activate ();
176 if (is_master() || is_monitor() || is_hidden()) {
177 _mute_master->set_solo_ignore (true);
180 /* now that we have _meter, its safe to connect to this */
182 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
185 /* run a configure so that the invisible processors get set up */
186 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
187 configure_processors (0);
195 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
197 /* do this early so that we don't get incoming signals as we are going through destruction
202 /* don't use clear_processors here, as it depends on the session which may
203 be half-destroyed by now
206 Glib::RWLock::WriterLock lm (_processor_lock);
207 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
208 (*i)->drop_references ();
211 _processors.clear ();
215 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
217 /* force IDs for master/monitor busses and prevent
218 any other route from accidentally getting these IDs
219 (i.e. legacy sessions)
222 if (is_master() && id != MasterBusRemoteControlID) {
223 id = MasterBusRemoteControlID;
226 if (is_monitor() && id != MonitorBusRemoteControlID) {
227 id = MonitorBusRemoteControlID;
230 /* don't allow it to collide */
232 if (!is_master () && !is_monitor() &&
233 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
234 id += MonitorBusRemoteControlID;
237 if (id != _remote_control_id) {
238 _remote_control_id = id;
239 RemoteControlIDChanged ();
240 if (notify_class_listeners) {
241 RemoteControlIDChange ();
247 Route::remote_control_id() const
249 return _remote_control_id;
253 Route::order_key (std::string const & name) const
255 OrderKeys::const_iterator i = order_keys.find (name);
256 if (i == order_keys.end()) {
264 Route::set_order_key (std::string const & name, int32_t n)
266 bool changed = false;
268 /* This method looks more complicated than it should, but
269 it's important that we don't emit order_key_changed unless
270 it actually has, as expensive things happen on receipt of that
274 if (order_keys.find(name) == order_keys.end() || order_keys[name] != n) {
275 order_keys[name] = n;
279 if (Config->get_sync_all_route_ordering()) {
280 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
281 if (x->second != n) {
289 order_key_changed (); /* EMIT SIGNAL */
290 _session.set_dirty ();
294 /** Set all order keys to be the same as that for `base', if such a key
295 * exists in this route.
296 * @param base Base key.
299 Route::sync_order_keys (std::string const & base)
301 if (order_keys.empty()) {
305 OrderKeys::iterator i;
308 if ((i = order_keys.find (base)) == order_keys.end()) {
309 /* key doesn't exist, use the first existing key (during session initialization) */
310 i = order_keys.begin();
314 /* key exists - use it and reset all others (actually, itself included) */
316 i = order_keys.begin();
319 bool changed = false;
321 for (; i != order_keys.end(); ++i) {
322 if (i->second != key) {
329 order_key_changed (); /* EMIT SIGNAL */
334 Route::ensure_track_or_route_name(string name, Session &session)
336 string newname = name;
338 while (!session.io_name_is_legal (newname)) {
339 newname = bump_name_once (newname, '.');
347 Route::inc_gain (gain_t fraction, void *src)
349 _amp->inc_gain (fraction, src);
353 Route::set_gain (gain_t val, void *src)
355 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
357 if (_route_group->is_relative()) {
359 gain_t usable_gain = _amp->gain();
360 if (usable_gain < 0.000001f) {
361 usable_gain = 0.000001f;
365 if (delta < 0.000001f) {
369 delta -= usable_gain;
374 gain_t factor = delta / usable_gain;
377 factor = _route_group->get_max_factor(factor);
378 if (factor == 0.0f) {
379 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
383 factor = _route_group->get_min_factor(factor);
384 if (factor == 0.0f) {
385 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
390 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
394 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
400 if (val == _amp->gain()) {
404 _amp->set_gain (val, src);
408 Route::maybe_declick (BufferSet&, framecnt_t, int)
410 /* this is the "bus" implementation and they never declick.
415 /** Process this route for one (sub) cycle (process thread)
417 * @param bufs Scratch buffers to use for the signal path
418 * @param start_frame Initial transport frame
419 * @param end_frame Final transport frame
420 * @param nframes Number of frames to output (to ports)
422 * Note that (end_frame - start_frame) may not be equal to nframes when the
423 * transport speed isn't 1.0 (eg varispeed).
426 Route::process_output_buffers (BufferSet& bufs,
427 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
428 int declick, bool gain_automation_ok)
430 bufs.set_is_silent (false);
432 /* figure out if we're going to use gain automation */
433 if (gain_automation_ok) {
434 _amp->setup_gain_automation (start_frame, end_frame, nframes);
436 _amp->apply_gain_automation (false);
439 /* Tell main outs what to do about monitoring. We do this so that
440 on a transition between monitoring states we get a de-clicking gain
441 change in the _main_outs delivery.
443 _main_outs->no_outs_cuz_we_no_monitor (monitoring_state () == MonitoringSilence);
446 /* -------------------------------------------------------------------------------------------
447 GLOBAL DECLICK (for transport changes etc.)
448 ----------------------------------------------------------------------------------------- */
450 maybe_declick (bufs, nframes, declick);
451 _pending_declick = 0;
453 /* -------------------------------------------------------------------------------------------
454 DENORMAL CONTROL/PHASE INVERT
455 ----------------------------------------------------------------------------------------- */
457 if (_phase_invert.any ()) {
461 if (_denormal_protection || Config->get_denormal_protection()) {
463 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
464 Sample* const sp = i->data();
466 if (_phase_invert[chn]) {
467 for (pframes_t nx = 0; nx < nframes; ++nx) {
472 for (pframes_t nx = 0; nx < nframes; ++nx) {
480 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
481 Sample* const sp = i->data();
483 if (_phase_invert[chn]) {
484 for (pframes_t nx = 0; nx < nframes; ++nx) {
493 if (_denormal_protection || Config->get_denormal_protection()) {
495 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
496 Sample* const sp = i->data();
497 for (pframes_t nx = 0; nx < nframes; ++nx) {
505 /* -------------------------------------------------------------------------------------------
507 ----------------------------------------------------------------------------------------- */
509 /* set this to be true if the meter will already have been ::run() earlier */
510 bool const meter_already_run = metering_state() == MeteringInput;
512 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
514 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
515 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
520 /* if it has any inputs, make sure they match */
521 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
522 if (bufs.count() != (*i)->input_streams()) {
523 cerr << _name << " bufs = " << bufs.count()
524 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
531 /* should we NOT run plugins here if the route is inactive?
532 do we catch route != active somewhere higher?
535 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
536 bufs.set_count ((*i)->output_streams());
541 Route::n_process_buffers ()
543 return max (_input->n_ports(), processor_max_streams);
547 Route::passthru (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
549 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
553 assert (bufs.available() >= input_streams());
555 if (_input->n_ports() == ChanCount::ZERO) {
556 silence_unlocked (nframes);
559 bufs.set_count (input_streams());
561 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
563 /* control/monitor bus ignores input ports when something is
564 feeding the listen "stream". data will "arrive" into the
565 route from the intreturn processor element.
567 bufs.silence (nframes, 0);
571 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
573 BufferSet::iterator o = bufs.begin(*t);
574 PortSet& ports (_input->ports());
576 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
577 o->read_from (i->get_buffer(nframes), nframes);
582 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
583 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
587 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
589 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
591 bufs.set_count (_input->n_ports());
592 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
593 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
597 Route::set_listen (bool yn, void* src)
603 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
604 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
609 if (yn != _monitor_send->active()) {
611 _monitor_send->activate ();
612 _mute_master->set_soloed (true);
614 _monitor_send->deactivate ();
615 _mute_master->set_soloed (false);
618 listen_changed (src); /* EMIT SIGNAL */
624 Route::listening_via_monitor () const
627 return _monitor_send->active ();
634 Route::set_solo_safe (bool yn, void *src)
636 if (_solo_safe != yn) {
638 solo_safe_changed (src);
643 Route::solo_safe() const
649 Route::set_solo (bool yn, void *src)
655 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
656 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
660 if (self_soloed() != yn) {
662 set_mute_master_solo ();
663 solo_changed (true, src); /* EMIT SIGNAL */
664 _solo_control->Changed (); /* EMIT SIGNAL */
669 Route::set_self_solo (bool yn)
675 Route::mod_solo_by_others_upstream (int32_t delta)
681 uint32_t old_sbu = _soloed_by_others_upstream;
684 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
685 _soloed_by_others_upstream += delta;
687 _soloed_by_others_upstream = 0;
690 _soloed_by_others_upstream += delta;
693 DEBUG_TRACE (DEBUG::Solo, string_compose (
694 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
695 name(), delta, _soloed_by_others_upstream, old_sbu,
696 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
698 /* push the inverse solo change to everything that feeds us.
700 This is important for solo-within-group. When we solo 1 track out of N that
701 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
702 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
703 tracks that feed it. This will silence them if they were audible because
704 of a bus solo, but the newly soloed track will still be audible (because
707 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
711 if ((_self_solo || _soloed_by_others_downstream) &&
712 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
713 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
715 if (delta > 0 || !Config->get_exclusive_solo()) {
716 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
717 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
718 boost::shared_ptr<Route> sr = i->r.lock();
720 sr->mod_solo_by_others_downstream (-delta);
726 set_mute_master_solo ();
727 solo_changed (false, this);
731 Route::mod_solo_by_others_downstream (int32_t delta)
738 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
739 _soloed_by_others_downstream += delta;
741 _soloed_by_others_downstream = 0;
744 _soloed_by_others_downstream += delta;
747 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
749 set_mute_master_solo ();
750 solo_changed (false, this);
754 Route::set_mute_master_solo ()
756 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
760 Route::set_solo_isolated (bool yn, void *src)
762 if (is_master() || is_monitor() || is_hidden()) {
766 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
767 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
771 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
773 boost::shared_ptr<RouteList> routes = _session.get_routes ();
774 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
776 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
781 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
783 if (does_feed && !sends_only) {
784 (*i)->set_solo_isolated (yn, (*i)->route_group());
788 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
790 bool changed = false;
793 if (_solo_isolated == 0) {
794 _mute_master->set_solo_ignore (true);
799 if (_solo_isolated > 0) {
801 if (_solo_isolated == 0) {
802 _mute_master->set_solo_ignore (false);
809 solo_isolated_changed (src);
814 Route::solo_isolated () const
816 return _solo_isolated > 0;
820 Route::set_mute_points (MuteMaster::MutePoint mp)
822 _mute_master->set_mute_points (mp);
823 mute_points_changed (); /* EMIT SIGNAL */
825 if (_mute_master->muted_by_self()) {
826 mute_changed (this); /* EMIT SIGNAL */
827 _mute_control->Changed (); /* EMIT SIGNAL */
832 Route::set_mute (bool yn, void *src)
834 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
835 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
840 _mute_master->set_muted_by_self (yn);
841 /* allow any derived classes to respond to the mute change
842 before anybody else knows about it.
845 /* tell everyone else */
846 mute_changed (src); /* EMIT SIGNAL */
847 _mute_control->Changed (); /* EMIT SIGNAL */
852 Route::muted () const
854 return _mute_master->muted_by_self();
859 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
861 cerr << name << " {" << endl;
862 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
863 p != procs.end(); ++p) {
864 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
871 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
873 ProcessorList::iterator loc;
875 /* XXX this is not thread safe - we don't hold the lock across determining the iter
876 to add before and actually doing the insertion. dammit.
879 if (placement == PreFader) {
880 /* generic pre-fader: insert immediately before the amp */
881 loc = find (_processors.begin(), _processors.end(), _amp);
883 /* generic post-fader: insert right before the main outs */
884 loc = find (_processors.begin(), _processors.end(), _main_outs);
887 return add_processor (processor, loc, err, activation_allowed);
891 /** Add a processor to a route such that it ends up with a given index into the visible processors.
892 * @param index Index to add the processor at, or -1 to add at the end of the list.
896 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
898 /* XXX this is not thread safe - we don't hold the lock across determining the iter
899 to add before and actually doing the insertion. dammit.
903 return add_processor (processor, _processors.end(), err, activation_allowed);
906 ProcessorList::iterator i = _processors.begin ();
908 while (i != _processors.end() && j < index) {
909 if ((*i)->display_to_user()) {
916 return add_processor (processor, i, err, activation_allowed);
919 /** Add a processor to the route.
920 * @param iter an iterator in _processors; the new processor will be inserted immediately before this location.
923 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
925 assert (processor != _meter);
926 assert (processor != _main_outs);
928 DEBUG_TRACE (DEBUG::Processors, string_compose (
929 "%1 adding processor %2\n", name(), processor->name()));
931 if (!_session.engine().connected() || !processor) {
936 Glib::RWLock::WriterLock lm (_processor_lock);
937 ProcessorState pstate (this);
939 boost::shared_ptr<PluginInsert> pi;
940 boost::shared_ptr<PortInsert> porti;
942 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
944 if (processor == _amp) {
945 // Ensure only one amp is in the list at any time
946 if (loc != _processors.end()) {
947 if (iter == loc) { // Already in place, do nothing
949 } else { // New position given, relocate
950 _processors.erase (loc);
955 if (loc != _processors.end()) {
956 cerr << "ERROR: Processor added to route twice!" << endl;
963 _processors.insert (loc, processor);
965 // Set up processor list channels. This will set processor->[input|output]_streams(),
966 // configure redirect ports properly, etc.
969 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
971 if (configure_processors_unlocked (err)) {
973 configure_processors_unlocked (0); // it worked before we tried to add it ...
978 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
980 if (pi->has_no_inputs ()) {
981 /* generator plugin */
982 _have_internal_generator = true;
987 if (activation_allowed) {
988 processor->activate ();
991 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
993 _output->set_user_latency (0);
996 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
997 set_processor_positions ();
1003 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1005 const XMLProperty *prop;
1008 boost::shared_ptr<Processor> processor;
1010 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1011 so that we can add the processor in the right place (pre/post-fader)
1014 XMLNodeList const & children = node.children ();
1015 XMLNodeList::const_iterator i = children.begin ();
1017 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1021 Placement placement = PreFader;
1023 if (i != children.end()) {
1024 if ((prop = (*i)->property (X_("placement"))) != 0) {
1025 placement = Placement (string_2_enum (prop->value(), placement));
1029 if (node.name() == "Insert") {
1031 if ((prop = node.property ("type")) != 0) {
1033 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1034 prop->value() == "lv2" ||
1035 prop->value() == "vst" ||
1036 prop->value() == "lxvst" ||
1037 prop->value() == "audiounit") {
1039 processor.reset (new PluginInsert (_session));
1043 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1048 } else if (node.name() == "Send") {
1050 processor.reset (new Send (_session, _pannable, _mute_master));
1054 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1058 if (processor->set_state (node, version)) {
1062 return (add_processor (processor, placement) == 0);
1065 catch (failed_constructor &err) {
1066 warning << _("processor could not be created. Ignored.") << endmsg;
1072 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1074 /* NOTE: this is intended to be used ONLY when copying
1075 processors from another Route. Hence the subtle
1076 differences between this and ::add_processor()
1079 ProcessorList::iterator loc;
1082 loc = find(_processors.begin(), _processors.end(), before);
1084 /* nothing specified - at end */
1085 loc = _processors.end ();
1088 if (!_session.engine().connected()) {
1092 if (others.empty()) {
1097 Glib::RWLock::WriterLock lm (_processor_lock);
1098 ProcessorState pstate (this);
1100 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1106 boost::shared_ptr<PluginInsert> pi;
1108 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1112 _processors.insert (loc, *i);
1114 if ((*i)->active()) {
1119 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1120 if (configure_processors_unlocked (err)) {
1122 configure_processors_unlocked (0); // it worked before we tried to add it ...
1127 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1130 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1131 boost::shared_ptr<PluginInsert> pi;
1133 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1134 if (pi->has_no_inputs ()) {
1135 _have_internal_generator = true;
1141 _output->set_user_latency (0);
1144 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1145 set_processor_positions ();
1151 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1153 if (p == PreFader) {
1154 start = _processors.begin();
1155 end = find(_processors.begin(), _processors.end(), _amp);
1157 start = find(_processors.begin(), _processors.end(), _amp);
1159 end = _processors.end();
1163 /** Turn off all processors with a given placement
1164 * @param p Placement of processors to disable
1167 Route::disable_processors (Placement p)
1169 Glib::RWLock::ReaderLock lm (_processor_lock);
1171 ProcessorList::iterator start, end;
1172 placement_range(p, start, end);
1174 for (ProcessorList::iterator i = start; i != end; ++i) {
1175 (*i)->deactivate ();
1178 _session.set_dirty ();
1181 /** Turn off all redirects
1184 Route::disable_processors ()
1186 Glib::RWLock::ReaderLock lm (_processor_lock);
1188 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1189 (*i)->deactivate ();
1192 _session.set_dirty ();
1195 /** Turn off all redirects with a given placement
1196 * @param p Placement of redirects to disable
1199 Route::disable_plugins (Placement p)
1201 Glib::RWLock::ReaderLock lm (_processor_lock);
1203 ProcessorList::iterator start, end;
1204 placement_range(p, start, end);
1206 for (ProcessorList::iterator i = start; i != end; ++i) {
1207 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1208 (*i)->deactivate ();
1212 _session.set_dirty ();
1215 /** Turn off all plugins
1218 Route::disable_plugins ()
1220 Glib::RWLock::ReaderLock lm (_processor_lock);
1222 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1223 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1224 (*i)->deactivate ();
1228 _session.set_dirty ();
1233 Route::ab_plugins (bool forward)
1235 Glib::RWLock::ReaderLock lm (_processor_lock);
1239 /* forward = turn off all active redirects, and mark them so that the next time
1240 we go the other way, we will revert them
1243 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1244 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1248 if ((*i)->active()) {
1249 (*i)->deactivate ();
1250 (*i)->set_next_ab_is_active (true);
1252 (*i)->set_next_ab_is_active (false);
1258 /* backward = if the redirect was marked to go active on the next ab, do so */
1260 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1262 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1266 if ((*i)->get_next_ab_is_active()) {
1269 (*i)->deactivate ();
1274 _session.set_dirty ();
1278 /** Remove processors with a given placement.
1279 * @param p Placement of processors to remove.
1282 Route::clear_processors (Placement p)
1284 if (!_session.engine().connected()) {
1288 bool already_deleting = _session.deletion_in_progress();
1289 if (!already_deleting) {
1290 _session.set_deletion_in_progress();
1294 Glib::RWLock::WriterLock lm (_processor_lock);
1295 ProcessorList new_list;
1296 ProcessorStreams err;
1297 bool seen_amp = false;
1299 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1305 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1307 /* you can't remove these */
1309 new_list.push_back (*i);
1316 new_list.push_back (*i);
1319 (*i)->drop_references ();
1327 (*i)->drop_references ();
1330 new_list.push_back (*i);
1337 _processors = new_list;
1340 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1341 configure_processors_unlocked (&err); // this can't fail
1345 processor_max_streams.reset();
1346 _have_internal_generator = false;
1347 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1348 set_processor_positions ();
1350 if (!already_deleting) {
1351 _session.clear_deletion_in_progress();
1356 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1358 /* these can never be removed */
1360 if (processor == _amp || processor == _meter || processor == _main_outs) {
1364 if (!_session.engine().connected()) {
1368 processor_max_streams.reset();
1371 Glib::RWLock::WriterLock lm (_processor_lock);
1372 ProcessorState pstate (this);
1374 ProcessorList::iterator i;
1375 bool removed = false;
1377 for (i = _processors.begin(); i != _processors.end(); ) {
1378 if (*i == processor) {
1380 /* move along, see failure case for configure_processors()
1381 where we may need to reconfigure the processor.
1384 /* stop redirects that send signals to JACK ports
1385 from causing noise as a result of no longer being
1389 boost::shared_ptr<IOProcessor> iop;
1391 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1393 iop->input()->disconnect (this);
1395 if (iop->output()) {
1396 iop->output()->disconnect (this);
1400 i = _processors.erase (i);
1408 _output->set_user_latency (0);
1416 if (need_process_lock) {
1417 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1419 if (configure_processors_unlocked (err)) {
1421 /* we know this will work, because it worked before :) */
1422 configure_processors_unlocked (0);
1426 if (configure_processors_unlocked (err)) {
1428 /* we know this will work, because it worked before :) */
1429 configure_processors_unlocked (0);
1434 _have_internal_generator = false;
1436 for (i = _processors.begin(); i != _processors.end(); ++i) {
1437 boost::shared_ptr<PluginInsert> pi;
1439 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1440 if (pi->has_no_inputs ()) {
1441 _have_internal_generator = true;
1448 processor->drop_references ();
1449 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1450 set_processor_positions ();
1456 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1458 ProcessorList deleted;
1460 if (!_session.engine().connected()) {
1464 processor_max_streams.reset();
1467 Glib::RWLock::WriterLock lm (_processor_lock);
1468 ProcessorState pstate (this);
1470 ProcessorList::iterator i;
1471 boost::shared_ptr<Processor> processor;
1473 for (i = _processors.begin(); i != _processors.end(); ) {
1477 /* these can never be removed */
1479 if (processor == _amp || processor == _meter || processor == _main_outs) {
1484 /* see if its in the list of processors to delete */
1486 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1491 /* stop IOProcessors that send to JACK ports
1492 from causing noise as a result of no longer being
1496 boost::shared_ptr<IOProcessor> iop;
1498 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1502 deleted.push_back (processor);
1503 i = _processors.erase (i);
1506 if (deleted.empty()) {
1507 /* none of those in the requested list were found */
1511 _output->set_user_latency (0);
1514 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1516 if (configure_processors_unlocked (err)) {
1518 /* we know this will work, because it worked before :) */
1519 configure_processors_unlocked (0);
1524 _have_internal_generator = false;
1526 for (i = _processors.begin(); i != _processors.end(); ++i) {
1527 boost::shared_ptr<PluginInsert> pi;
1529 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1530 if (pi->has_no_inputs ()) {
1531 _have_internal_generator = true;
1538 /* now try to do what we need to so that those that were removed will be deleted */
1540 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1541 (*i)->drop_references ();
1544 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1545 set_processor_positions ();
1550 /** Caller must hold process lock */
1552 Route::configure_processors (ProcessorStreams* err)
1554 assert (!AudioEngine::instance()->process_lock().trylock());
1556 if (!_in_configure_processors) {
1557 Glib::RWLock::WriterLock lm (_processor_lock);
1558 return configure_processors_unlocked (err);
1565 Route::input_streams () const
1567 return _input->n_ports ();
1570 list<pair<ChanCount, ChanCount> >
1571 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1573 Glib::RWLock::ReaderLock lm (_processor_lock);
1575 return try_configure_processors_unlocked (in, err);
1578 list<pair<ChanCount, ChanCount> >
1579 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1581 // Check each processor in order to see if we can configure as requested
1583 list<pair<ChanCount, ChanCount> > configuration;
1586 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1587 DEBUG_TRACE (DEBUG::Processors, "{\n");
1589 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1591 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1592 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1596 if ((*p)->can_support_io_configuration(in, out)) {
1597 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1598 configuration.push_back(make_pair(in, out));
1605 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1606 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1607 DEBUG_TRACE (DEBUG::Processors, "}\n");
1608 return list<pair<ChanCount, ChanCount> > ();
1612 DEBUG_TRACE (DEBUG::Processors, "}\n");
1614 return configuration;
1617 /** Set the input/output configuration of each processor in the processors list.
1618 * Caller must hold process lock.
1619 * Return 0 on success, otherwise configuration is impossible.
1622 Route::configure_processors_unlocked (ProcessorStreams* err)
1624 assert (!AudioEngine::instance()->process_lock().trylock());
1626 if (_in_configure_processors) {
1630 /* put invisible processors where they should be */
1631 setup_invisible_processors ();
1633 _in_configure_processors = true;
1635 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1637 if (configuration.empty ()) {
1638 _in_configure_processors = false;
1644 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1645 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1647 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1651 (*p)->configure_io(c->first, c->second);
1652 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1653 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1658 _meter->reset_max_channels (processor_max_streams);
1661 /* make sure we have sufficient scratch buffers to cope with the new processor
1664 _session.ensure_buffers (n_process_buffers ());
1666 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1668 _in_configure_processors = false;
1672 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1673 * @param state New active state for those processors.
1676 Route::all_visible_processors_active (bool state)
1678 Glib::RWLock::ReaderLock lm (_processor_lock);
1680 if (_processors.empty()) {
1684 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1685 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1692 (*i)->deactivate ();
1696 _session.set_dirty ();
1700 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1702 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1703 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1704 processors in the current actual processor list that are hidden. Any visible processors
1705 in the current list but not in "new_order" will be assumed to be deleted.
1709 Glib::RWLock::WriterLock lm (_processor_lock);
1710 ProcessorState pstate (this);
1712 ProcessorList::iterator oiter;
1713 ProcessorList::const_iterator niter;
1714 ProcessorList as_it_will_be;
1716 oiter = _processors.begin();
1717 niter = new_order.begin();
1719 while (niter != new_order.end()) {
1721 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1722 then append it to the temp list.
1724 Otherwise, see if the next processor in the old list is in the new list. if not,
1725 its been deleted. If its there, append it to the temp list.
1728 if (oiter == _processors.end()) {
1730 /* no more elements in the old list, so just stick the rest of
1731 the new order onto the temp list.
1734 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1735 while (niter != new_order.end()) {
1742 if (!(*oiter)->display_to_user()) {
1744 as_it_will_be.push_back (*oiter);
1748 /* visible processor: check that its in the new order */
1750 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1751 /* deleted: do nothing, shared_ptr<> will clean up */
1753 /* ignore this one, and add the next item from the new order instead */
1754 as_it_will_be.push_back (*niter);
1759 /* now remove from old order - its taken care of no matter what */
1760 oiter = _processors.erase (oiter);
1765 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1767 /* If the meter is in a custom position, find it and make a rough note of its position */
1768 maybe_note_meter_position ();
1771 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1773 if (configure_processors_unlocked (err)) {
1780 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1781 set_processor_positions ();
1793 Route::get_template()
1795 return state(false);
1799 Route::state(bool full_state)
1801 XMLNode *node = new XMLNode("Route");
1802 ProcessorList::iterator i;
1805 id().print (buf, sizeof (buf));
1806 node->add_property("id", buf);
1807 node->add_property ("name", _name);
1808 node->add_property("default-type", _default_type.to_string());
1811 node->add_property("flags", enum_2_string (_flags));
1814 node->add_property("active", _active?"yes":"no");
1816 boost::to_string (_phase_invert, p);
1817 node->add_property("phase-invert", p);
1818 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1819 node->add_property("meter-point", enum_2_string (_meter_point));
1822 node->add_property("route-group", _route_group->name());
1825 string order_string;
1826 OrderKeys::iterator x = order_keys.begin();
1828 while (x != order_keys.end()) {
1829 order_string += string ((*x).first);
1830 order_string += '=';
1831 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1832 order_string += buf;
1836 if (x == order_keys.end()) {
1840 order_string += ':';
1842 node->add_property ("order-keys", order_string);
1843 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1844 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1845 node->add_property ("soloed-by-upstream", buf);
1846 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1847 node->add_property ("soloed-by-downstream", buf);
1848 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
1849 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
1851 node->add_child_nocopy (_input->state (full_state));
1852 node->add_child_nocopy (_output->state (full_state));
1853 node->add_child_nocopy (_solo_control->get_state ());
1854 node->add_child_nocopy (_mute_control->get_state ());
1855 node->add_child_nocopy (_mute_master->get_state ());
1857 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1858 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1859 remote_control_node->add_property (X_("id"), buf);
1860 node->add_child_nocopy (*remote_control_node);
1862 if (_comment.length()) {
1863 XMLNode *cmt = node->add_child ("Comment");
1864 cmt->add_content (_comment);
1868 node->add_child_nocopy (_pannable->state (full_state));
1871 for (i = _processors.begin(); i != _processors.end(); ++i) {
1872 node->add_child_nocopy((*i)->state (full_state));
1876 node->add_child_copy (*_extra_xml);
1879 if (_custom_meter_position_noted) {
1880 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
1882 after->id().print (buf, sizeof (buf));
1883 node->add_property (X_("processor-after-last-custom-meter"), buf);
1886 node->add_property (X_("last-custom-meter-was-at-end"), _last_custom_meter_was_at_end ? "yes" : "no");
1893 Route::set_state (const XMLNode& node, int version)
1895 if (version < 3000) {
1896 return set_state_2X (node, version);
1900 XMLNodeConstIterator niter;
1902 const XMLProperty *prop;
1904 if (node.name() != "Route"){
1905 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1909 if ((prop = node.property (X_("name"))) != 0) {
1910 Route::set_name (prop->value());
1915 if ((prop = node.property (X_("flags"))) != 0) {
1916 _flags = Flag (string_2_enum (prop->value(), _flags));
1921 if (is_master() || is_monitor() || is_hidden()) {
1922 _mute_master->set_solo_ignore (true);
1926 /* monitor bus does not get a panner, but if (re)created
1927 via XML, it will already have one by the time we
1928 call ::set_state(). so ... remove it.
1933 /* add all processors (except amp, which is always present) */
1935 nlist = node.children();
1936 XMLNode processor_state (X_("processor_state"));
1938 Stateful::save_extra_xml (node);
1940 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1944 if (child->name() == IO::state_node_name) {
1945 if ((prop = child->property (X_("direction"))) == 0) {
1949 if (prop->value() == "Input") {
1950 _input->set_state (*child, version);
1951 } else if (prop->value() == "Output") {
1952 _output->set_state (*child, version);
1956 if (child->name() == X_("Processor")) {
1957 processor_state.add_child_copy (*child);
1961 if (child->name() == X_("Pannable")) {
1963 _pannable->set_state (*child, version);
1965 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
1970 if ((prop = node.property (X_("meter-point"))) != 0) {
1971 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
1972 set_meter_point (mp, true);
1974 _meter->set_display_to_user (_meter_point == MeterCustom);
1978 set_processor_state (processor_state);
1980 if ((prop = node.property ("self-solo")) != 0) {
1981 set_self_solo (string_is_affirmative (prop->value()));
1984 if ((prop = node.property ("soloed-by-upstream")) != 0) {
1985 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
1986 mod_solo_by_others_upstream (atoi (prop->value()));
1989 if ((prop = node.property ("soloed-by-downstream")) != 0) {
1990 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
1991 mod_solo_by_others_downstream (atoi (prop->value()));
1994 if ((prop = node.property ("solo-isolated")) != 0) {
1995 set_solo_isolated (string_is_affirmative (prop->value()), this);
1998 if ((prop = node.property ("solo-safe")) != 0) {
1999 set_solo_safe (string_is_affirmative (prop->value()), this);
2002 if ((prop = node.property (X_("phase-invert"))) != 0) {
2003 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2006 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2007 set_denormal_protection (string_is_affirmative (prop->value()));
2010 if ((prop = node.property (X_("active"))) != 0) {
2011 bool yn = string_is_affirmative (prop->value());
2012 _active = !yn; // force switch
2013 set_active (yn, this);
2016 if ((prop = node.property (X_("order-keys"))) != 0) {
2020 string::size_type colon, equal;
2021 string remaining = prop->value();
2023 while (remaining.length()) {
2025 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2026 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2029 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2030 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2033 set_order_key (remaining.substr (0, equal), n);
2037 colon = remaining.find_first_of (':');
2039 if (colon != string::npos) {
2040 remaining = remaining.substr (colon+1);
2047 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2048 PBD::ID id (prop->value ());
2049 Glib::RWLock::ReaderLock lm (_processor_lock);
2050 ProcessorList::const_iterator i = _processors.begin ();
2051 while (i != _processors.end() && (*i)->id() != id) {
2055 if (i != _processors.end ()) {
2056 _processor_after_last_custom_meter = *i;
2057 _custom_meter_position_noted = true;
2061 if ((prop = node.property (X_("last-custom-meter-was-at-end"))) != 0) {
2062 _last_custom_meter_was_at_end = string_is_affirmative (prop->value ());
2065 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2068 if (child->name() == X_("Comment")) {
2070 /* XXX this is a terrible API design in libxml++ */
2072 XMLNode *cmt = *(child->children().begin());
2073 _comment = cmt->content();
2075 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2076 if (prop->value() == "solo") {
2077 _solo_control->set_state (*child, version);
2080 } else if (child->name() == X_("RemoteControl")) {
2081 if ((prop = child->property (X_("id"))) != 0) {
2083 sscanf (prop->value().c_str(), "%d", &x);
2084 set_remote_control_id (x);
2087 } else if (child->name() == X_("MuteMaster")) {
2088 _mute_master->set_state (*child, version);
2096 Route::set_state_2X (const XMLNode& node, int version)
2099 XMLNodeConstIterator niter;
2101 const XMLProperty *prop;
2103 /* 2X things which still remain to be handled:
2109 if (node.name() != "Route") {
2110 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2114 if ((prop = node.property (X_("flags"))) != 0) {
2115 _flags = Flag (string_2_enum (prop->value(), _flags));
2120 if ((prop = node.property (X_("phase-invert"))) != 0) {
2121 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2122 if (string_is_affirmative (prop->value ())) {
2125 set_phase_invert (p);
2128 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2129 set_denormal_protection (string_is_affirmative (prop->value()));
2132 if ((prop = node.property (X_("soloed"))) != 0) {
2133 bool yn = string_is_affirmative (prop->value());
2135 /* XXX force reset of solo status */
2137 set_solo (yn, this);
2140 if ((prop = node.property (X_("muted"))) != 0) {
2143 bool muted = string_is_affirmative (prop->value());
2149 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2151 if (string_is_affirmative (prop->value())){
2152 mute_point = mute_point + "PreFader";
2157 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2159 if (string_is_affirmative (prop->value())){
2162 mute_point = mute_point + ",";
2165 mute_point = mute_point + "PostFader";
2170 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2172 if (string_is_affirmative (prop->value())){
2175 mute_point = mute_point + ",";
2178 mute_point = mute_point + "Listen";
2183 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2185 if (string_is_affirmative (prop->value())){
2188 mute_point = mute_point + ",";
2191 mute_point = mute_point + "Main";
2195 _mute_master->set_mute_points (mute_point);
2196 _mute_master->set_muted_by_self (true);
2200 if ((prop = node.property (X_("meter-point"))) != 0) {
2201 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2204 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2205 don't mean the same thing.
2208 if ((prop = node.property (X_("order-keys"))) != 0) {
2212 string::size_type colon, equal;
2213 string remaining = prop->value();
2215 while (remaining.length()) {
2217 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2218 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2221 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2222 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2225 set_order_key (remaining.substr (0, equal), n);
2229 colon = remaining.find_first_of (':');
2231 if (colon != string::npos) {
2232 remaining = remaining.substr (colon+1);
2241 nlist = node.children ();
2242 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2246 if (child->name() == IO::state_node_name) {
2248 /* there is a note in IO::set_state_2X() about why we have to call
2252 _input->set_state_2X (*child, version, true);
2253 _output->set_state_2X (*child, version, false);
2255 if ((prop = child->property (X_("name"))) != 0) {
2256 Route::set_name (prop->value ());
2261 if ((prop = child->property (X_("active"))) != 0) {
2262 bool yn = string_is_affirmative (prop->value());
2263 _active = !yn; // force switch
2264 set_active (yn, this);
2267 if ((prop = child->property (X_("gain"))) != 0) {
2270 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2271 _amp->gain_control()->set_value (val);
2275 /* Set up Panners in the IO */
2276 XMLNodeList io_nlist = child->children ();
2278 XMLNodeConstIterator io_niter;
2281 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2283 io_child = *io_niter;
2285 if (io_child->name() == X_("Panner")) {
2286 _main_outs->panner_shell()->set_state(*io_child, version);
2287 } else if (io_child->name() == X_("Automation")) {
2288 /* IO's automation is for the fader */
2289 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2295 XMLNodeList redirect_nodes;
2297 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2301 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2302 redirect_nodes.push_back(child);
2307 set_processor_state_2X (redirect_nodes, version);
2309 Stateful::save_extra_xml (node);
2311 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2314 if (child->name() == X_("Comment")) {
2316 /* XXX this is a terrible API design in libxml++ */
2318 XMLNode *cmt = *(child->children().begin());
2319 _comment = cmt->content();
2321 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2322 if (prop->value() == X_("solo")) {
2323 _solo_control->set_state (*child, version);
2324 } else if (prop->value() == X_("mute")) {
2325 _mute_control->set_state (*child, version);
2328 } else if (child->name() == X_("RemoteControl")) {
2329 if ((prop = child->property (X_("id"))) != 0) {
2331 sscanf (prop->value().c_str(), "%d", &x);
2332 set_remote_control_id (x);
2342 Route::get_processor_state ()
2344 XMLNode* root = new XMLNode (X_("redirects"));
2345 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2346 root->add_child_nocopy ((*i)->state (true));
2353 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2355 /* We don't bother removing existing processors not in nList, as this
2356 method will only be called when creating a Route from scratch, not
2357 for undo purposes. Just put processors in at the appropriate place
2361 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2362 add_processor_from_xml_2X (**i, version);
2367 Route::set_processor_state (const XMLNode& node)
2369 const XMLNodeList &nlist = node.children();
2370 XMLNodeConstIterator niter;
2371 ProcessorList new_order;
2372 bool must_configure = false;
2374 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2376 XMLProperty* prop = (*niter)->property ("type");
2378 if (prop->value() == "amp") {
2379 _amp->set_state (**niter, Stateful::current_state_version);
2380 new_order.push_back (_amp);
2381 } else if (prop->value() == "meter") {
2382 _meter->set_state (**niter, Stateful::current_state_version);
2383 new_order.push_back (_meter);
2384 } else if (prop->value() == "main-outs") {
2385 _main_outs->set_state (**niter, Stateful::current_state_version);
2386 } else if (prop->value() == "intreturn") {
2388 _intreturn.reset (new InternalReturn (_session));
2389 must_configure = true;
2391 _intreturn->set_state (**niter, Stateful::current_state_version);
2392 } else if (is_monitor() && prop->value() == "monitor") {
2393 if (!_monitor_control) {
2394 _monitor_control.reset (new MonitorProcessor (_session));
2395 must_configure = true;
2397 _monitor_control->set_state (**niter, Stateful::current_state_version);
2398 } else if (prop->value() == "capture") {
2399 _capturing_processor.reset (new CapturingProcessor (_session));
2401 ProcessorList::iterator o;
2403 for (o = _processors.begin(); o != _processors.end(); ++o) {
2404 XMLProperty* id_prop = (*niter)->property(X_("id"));
2405 if (id_prop && (*o)->id() == id_prop->value()) {
2406 (*o)->set_state (**niter, Stateful::current_state_version);
2407 new_order.push_back (*o);
2412 // If the processor (*niter) is not on the route then create it
2414 if (o == _processors.end()) {
2416 boost::shared_ptr<Processor> processor;
2418 if (prop->value() == "intsend") {
2420 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2422 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2423 prop->value() == "lv2" ||
2424 prop->value() == "vst" ||
2425 prop->value() == "lxvst" ||
2426 prop->value() == "audiounit") {
2428 processor.reset (new PluginInsert(_session));
2430 } else if (prop->value() == "port") {
2432 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2434 } else if (prop->value() == "send") {
2436 processor.reset (new Send (_session, _pannable, _mute_master));
2439 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2443 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2444 /* This processor could not be configured. Turn it into a UnknownProcessor */
2445 processor.reset (new UnknownProcessor (_session, **niter));
2448 /* we have to note the monitor send here, otherwise a new one will be created
2449 and the state of this one will be lost.
2451 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2452 if (isend && isend->role() == Delivery::Listen) {
2453 _monitor_send = isend;
2456 /* it doesn't matter if invisible processors are added here, as they
2457 will be sorted out by setup_invisible_processors () shortly.
2460 new_order.push_back (processor);
2461 must_configure = true;
2467 Glib::RWLock::WriterLock lm (_processor_lock);
2468 _processors = new_order;
2470 if (must_configure) {
2471 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2472 configure_processors_unlocked (0);
2475 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2477 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2479 boost::shared_ptr<PluginInsert> pi;
2481 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2482 if (pi->has_no_inputs ()) {
2483 _have_internal_generator = true;
2490 processors_changed (RouteProcessorChange ());
2491 set_processor_positions ();
2495 Route::curve_reallocate ()
2497 // _gain_automation_curve.finish_resize ();
2498 // _pan_automation_curve.finish_resize ();
2502 Route::silence (framecnt_t nframes)
2504 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2509 silence_unlocked (nframes);
2513 Route::silence_unlocked (framecnt_t nframes)
2515 /* Must be called with the processor lock held */
2519 _output->silence (nframes);
2521 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2522 boost::shared_ptr<PluginInsert> pi;
2524 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2525 // skip plugins, they don't need anything when we're not active
2529 (*i)->silence (nframes);
2532 if (nframes == _session.get_block_size()) {
2539 Route::add_internal_return ()
2542 _intreturn.reset (new InternalReturn (_session));
2543 add_processor (_intreturn, PreFader);
2548 Route::add_send_to_internal_return (InternalSend* send)
2550 Glib::RWLock::ReaderLock rm (_processor_lock);
2552 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2553 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2556 return d->add_send (send);
2562 Route::remove_send_from_internal_return (InternalSend* send)
2564 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2565 Glib::RWLock::ReaderLock rm (_processor_lock);
2567 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2568 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2571 return d->remove_send (send);
2577 Route::enable_monitor_send ()
2579 /* Caller must hold process lock */
2580 assert (!AudioEngine::instance()->process_lock().trylock());
2582 /* master never sends to monitor section via the normal mechanism */
2583 assert (!is_master ());
2585 /* make sure we have one */
2586 if (!_monitor_send) {
2587 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, _session.monitor_out(), Delivery::Listen));
2588 _monitor_send->set_display_to_user (false);
2592 configure_processors (0);
2595 /** Add an aux send to a route.
2596 * @param route route to send to.
2597 * @param placement placement for the send.
2600 Route::add_aux_send (boost::shared_ptr<Route> route, Placement placement)
2602 assert (route != _session.monitor_out ());
2605 Glib::RWLock::ReaderLock rm (_processor_lock);
2607 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2609 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2611 if (d && d->target_route() == route) {
2612 /* already listening via the specified IO: do nothing */
2620 boost::shared_ptr<InternalSend> listener;
2623 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2624 listener.reset (new InternalSend (_session, _pannable, _mute_master, route, Delivery::Aux));
2627 add_processor (listener, placement);
2629 } catch (failed_constructor& err) {
2637 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
2639 ProcessorStreams err;
2640 ProcessorList::iterator tmp;
2643 Glib::RWLock::ReaderLock rl(_processor_lock);
2645 /* have to do this early because otherwise processor reconfig
2646 * will put _monitor_send back in the list
2649 if (route == _session.monitor_out()) {
2650 _monitor_send.reset ();
2654 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2656 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2658 if (d && d->target_route() == route) {
2660 remove_processor (*x, &err, false);
2663 /* list could have been demolished while we dropped the lock
2674 Route::set_comment (string cmt, void *src)
2677 comment_changed (src);
2678 _session.set_dirty ();
2682 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2684 FeedRecord fr (other, via_sends_only);
2686 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2688 if (!result.second) {
2690 /* already a record for "other" - make sure sends-only information is correct */
2691 if (!via_sends_only && result.first->sends_only) {
2692 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2693 frp->sends_only = false;
2697 return result.second;
2701 Route::clear_fed_by ()
2707 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2709 const FedBy& fed_by (other->fed_by());
2711 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2712 boost::shared_ptr<Route> sr = f->r.lock();
2714 if (sr && (sr.get() == this)) {
2716 if (via_sends_only) {
2717 *via_sends_only = f->sends_only;
2728 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
2730 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2732 if (_output->connected_to (other->input())) {
2733 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2734 if (via_send_only) {
2735 *via_send_only = false;
2742 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2744 boost::shared_ptr<IOProcessor> iop;
2746 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2747 if (iop->feeds (other)) {
2748 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2749 if (via_send_only) {
2750 *via_send_only = true;
2754 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2757 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2762 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2767 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
2769 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
2772 /** Called from the (non-realtime) butler thread when the transport is stopped */
2774 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2776 framepos_t now = _session.transport_frame();
2779 Glib::RWLock::ReaderLock lm (_processor_lock);
2782 automation_snapshot (now, true);
2785 Automatable::transport_stopped (now);
2787 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2789 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
2793 (*i)->transport_stopped (now);
2797 _roll_delay = _initial_delay;
2800 /** Called with the process lock held if change contains ConfigurationChanged */
2802 Route::input_change_handler (IOChange change, void * /*src*/)
2804 if ((change.type & IOChange::ConfigurationChanged)) {
2805 configure_processors (0);
2806 _phase_invert.resize (_input->n_ports().n_audio ());
2807 io_changed (); /* EMIT SIGNAL */
2812 Route::pans_required () const
2814 if (n_outputs().n_audio() < 2) {
2818 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2822 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
2824 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2829 if (n_outputs().n_total() == 0) {
2833 if (!_active || n_inputs() == ChanCount::ZERO) {
2834 silence_unlocked (nframes);
2837 if (session_state_changing) {
2838 if (_session.transport_speed() != 0.0f) {
2839 /* we're rolling but some state is changing (e.g. our diskstream contents)
2840 so we cannot use them. Be silent till this is over.
2842 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2844 silence_unlocked (nframes);
2847 /* we're really not rolling, so we're either delivery silence or actually
2848 monitoring, both of which are safe to do while session_state_changing is true.
2852 _amp->apply_gain_automation (false);
2853 passthru (start_frame, end_frame, nframes, 0);
2859 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
2861 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2866 automation_snapshot (_session.transport_frame(), false);
2868 if (n_outputs().n_total() == 0) {
2872 if (!_active || n_inputs().n_total() == 0) {
2873 silence_unlocked (nframes);
2877 framecnt_t unused = 0;
2879 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2885 passthru (start_frame, end_frame, nframes, declick);
2891 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
2898 Route::has_external_redirects () const
2900 // FIXME: what about sends? - they don't return a signal back to ardour?
2902 boost::shared_ptr<const PortInsert> pi;
2904 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2906 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2908 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2910 string port_name = port->name();
2911 string client_name = port_name.substr (0, port_name.find(':'));
2913 /* only say "yes" if the redirect is actually in use */
2915 if (client_name != "ardour" && pi->active()) {
2926 Route::flush_processors ()
2928 /* XXX shouldn't really try to take this lock, since
2929 this is called from the RT audio thread.
2932 Glib::RWLock::ReaderLock lm (_processor_lock);
2934 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2940 Route::set_meter_point (MeterPoint p, bool force)
2942 /* CAN BE CALLED FROM PROCESS CONTEXT */
2944 if (_meter_point == p && !force) {
2948 bool meter_was_visible_to_user = _meter->display_to_user ();
2951 Glib::RWLock::WriterLock lm (_processor_lock);
2953 maybe_note_meter_position ();
2957 if (_meter_point != MeterCustom) {
2959 _meter->set_display_to_user (false);
2961 setup_invisible_processors ();
2965 _meter->set_display_to_user (true);
2967 /* If we have a previous position for the custom meter, try to put it there */
2968 if (_custom_meter_position_noted) {
2969 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2972 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
2973 if (i != _processors.end ()) {
2974 _processors.remove (_meter);
2975 _processors.insert (i, _meter);
2977 } else if (_last_custom_meter_was_at_end) {
2978 _processors.remove (_meter);
2979 _processors.push_back (_meter);
2984 /* Set up the meter for its new position */
2986 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2990 if (loc == _processors.begin()) {
2991 m_in = _input->n_ports();
2993 ProcessorList::iterator before = loc;
2995 m_in = (*before)->output_streams ();
2998 _meter->reflect_inputs (m_in);
3000 /* we do not need to reconfigure the processors, because the meter
3001 (a) is always ready to handle processor_max_streams
3002 (b) is always an N-in/N-out processor, and thus moving
3003 it doesn't require any changes to the other processors.
3007 meter_change (); /* EMIT SIGNAL */
3009 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3011 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3015 Route::listen_position_changed ()
3018 Glib::RWLock::WriterLock lm (_processor_lock);
3019 ProcessorState pstate (this);
3022 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3024 if (configure_processors_unlocked (0)) {
3026 configure_processors_unlocked (0); // it worked before we tried to add it ...
3032 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3033 _session.set_dirty ();
3036 boost::shared_ptr<CapturingProcessor>
3037 Route::add_export_point()
3039 if (!_capturing_processor) {
3041 _capturing_processor.reset (new CapturingProcessor (_session));
3042 _capturing_processor->activate ();
3045 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3046 configure_processors (0);
3051 return _capturing_processor;
3055 Route::update_signal_latency ()
3057 framecnt_t l = _output->user_latency();
3059 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3060 if ((*i)->active ()) {
3061 l += (*i)->signal_latency ();
3065 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3067 if (_signal_latency != l) {
3068 _signal_latency = l;
3069 signal_latency_changed (); /* EMIT SIGNAL */
3072 return _signal_latency;
3076 Route::set_user_latency (framecnt_t nframes)
3078 _output->set_user_latency (nframes);
3079 _session.update_latency_compensation ();
3083 Route::set_latency_compensation (framecnt_t longest_session_latency)
3085 framecnt_t old = _initial_delay;
3087 if (_signal_latency < longest_session_latency) {
3088 _initial_delay = longest_session_latency - _signal_latency;
3093 DEBUG_TRACE (DEBUG::Latency, string_compose (
3094 "%1: compensate for maximum latency of %2,"
3095 "given own latency of %3, using initial delay of %4\n",
3096 name(), longest_session_latency, _signal_latency, _initial_delay));
3098 if (_initial_delay != old) {
3099 initial_delay_changed (); /* EMIT SIGNAL */
3102 if (_session.transport_stopped()) {
3103 _roll_delay = _initial_delay;
3108 Route::automation_snapshot (framepos_t now, bool force)
3111 _pannable->automation_snapshot (now, force);
3114 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3115 (*i)->automation_snapshot (now, force);
3119 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3120 : AutomationControl (r->session(), Evoral::Parameter (SoloAutomation),
3121 boost::shared_ptr<AutomationList>(), name)
3124 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3129 Route::SoloControllable::set_value (double val)
3131 bool bval = ((val >= 0.5f) ? true: false);
3133 boost::shared_ptr<RouteList> rl (new RouteList);
3135 boost::shared_ptr<Route> r = _route.lock ();
3142 if (Config->get_solo_control_is_listen_control()) {
3143 _session.set_listen (rl, bval);
3145 _session.set_solo (rl, bval);
3150 Route::SoloControllable::get_value () const
3152 boost::shared_ptr<Route> r = _route.lock ();
3157 if (Config->get_solo_control_is_listen_control()) {
3158 return r->listening_via_monitor() ? 1.0f : 0.0f;
3160 return r->self_soloed() ? 1.0f : 0.0f;
3164 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3165 : AutomationControl (r->session(), Evoral::Parameter (MuteAutomation),
3166 boost::shared_ptr<AutomationList>(), name)
3169 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3174 Route::MuteControllable::set_value (double val)
3176 bool bval = ((val >= 0.5f) ? true: false);
3178 boost::shared_ptr<RouteList> rl (new RouteList);
3180 boost::shared_ptr<Route> r = _route.lock ();
3186 _session.set_mute (rl, bval);
3190 Route::MuteControllable::get_value () const
3192 boost::shared_ptr<Route> r = _route.lock ();
3197 return r->muted() ? 1.0f : 0.0f;
3201 Route::set_block_size (pframes_t nframes)
3203 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3204 (*i)->set_block_size (nframes);
3207 _session.ensure_buffers (n_process_buffers ());
3211 Route::protect_automation ()
3213 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3214 (*i)->protect_automation();
3218 Route::set_pending_declick (int declick)
3221 /* this call is not allowed to turn off a pending declick unless "force" is true */
3223 _pending_declick = declick;
3225 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3227 _pending_declick = 0;
3232 /** Shift automation forwards from a particular place, thereby inserting time.
3233 * Adds undo commands for any shifts that are performed.
3235 * @param pos Position to start shifting from.
3236 * @param frames Amount to shift forwards by.
3240 Route::shift (framepos_t pos, framecnt_t frames)
3242 /* gain automation */
3244 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3246 XMLNode &before = gc->alist()->get_state ();
3247 gc->alist()->shift (pos, frames);
3248 XMLNode &after = gc->alist()->get_state ();
3249 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3252 /* pan automation */
3254 ControlSet::Controls& c (_pannable->controls());
3256 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3257 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3259 boost::shared_ptr<AutomationList> al = pc->alist();
3260 XMLNode& before = al->get_state ();
3261 al->shift (pos, frames);
3262 XMLNode& after = al->get_state ();
3263 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3268 /* redirect automation */
3270 Glib::RWLock::ReaderLock lm (_processor_lock);
3271 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3273 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3275 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3276 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3278 boost::shared_ptr<AutomationList> al = ac->alist();
3279 XMLNode &before = al->get_state ();
3280 al->shift (pos, frames);
3281 XMLNode &after = al->get_state ();
3282 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3291 Route::save_as_template (const string& path, const string& name)
3293 XMLNode& node (state (false));
3296 IO::set_name_in_state (*node.children().front(), name);
3298 tree.set_root (&node);
3299 return tree.write (path.c_str());
3304 Route::set_name (const string& str)
3310 name = Route::ensure_track_or_route_name (str, _session);
3311 SessionObject::set_name (name);
3313 ret = (_input->set_name(name) && _output->set_name(name));
3316 /* rename the main outs. Leave other IO processors
3317 * with whatever name they already have, because its
3318 * just fine as it is (it will not contain the route
3319 * name if its a port insert, port send or port return).
3323 if (_main_outs->set_name (name)) {
3324 /* XXX returning false here is stupid because
3325 we already changed the route name.
3335 /** Set the name of a route in an XML description.
3336 * @param node XML <Route> node to set the name in.
3337 * @param name New name.
3340 Route::set_name_in_state (XMLNode& node, string const & name)
3342 node.add_property (X_("name"), name);
3344 XMLNodeList children = node.children();
3345 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3347 if ((*i)->name() == X_("IO")) {
3349 IO::set_name_in_state (**i, name);
3351 } else if ((*i)->name() == X_("Processor")) {
3353 XMLProperty* role = (*i)->property (X_("role"));
3354 if (role && role->value() == X_("Main")) {
3355 (*i)->add_property (X_("name"), name);
3358 } else if ((*i)->name() == X_("Diskstream")) {
3360 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3361 (*i)->add_property (X_("name"), name);
3367 boost::shared_ptr<Send>
3368 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3370 Glib::RWLock::ReaderLock lm (_processor_lock);
3372 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3373 boost::shared_ptr<InternalSend> send;
3375 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3376 if (send->target_route() == target) {
3382 return boost::shared_ptr<Send>();
3385 /** @param c Audio channel index.
3386 * @param yn true to invert phase, otherwise false.
3389 Route::set_phase_invert (uint32_t c, bool yn)
3391 if (_phase_invert[c] != yn) {
3392 _phase_invert[c] = yn;
3393 phase_invert_changed (); /* EMIT SIGNAL */
3394 _session.set_dirty ();
3399 Route::set_phase_invert (boost::dynamic_bitset<> p)
3401 if (_phase_invert != p) {
3403 phase_invert_changed (); /* EMIT SIGNAL */
3404 _session.set_dirty ();
3409 Route::phase_invert (uint32_t c) const
3411 return _phase_invert[c];
3414 boost::dynamic_bitset<>
3415 Route::phase_invert () const
3417 return _phase_invert;
3421 Route::set_denormal_protection (bool yn)
3423 if (_denormal_protection != yn) {
3424 _denormal_protection = yn;
3425 denormal_protection_changed (); /* EMIT SIGNAL */
3430 Route::denormal_protection () const
3432 return _denormal_protection;
3436 Route::set_active (bool yn, void* src)
3438 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3439 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3443 if (_active != yn) {
3445 _input->set_active (yn);
3446 _output->set_active (yn);
3447 active_changed (); // EMIT SIGNAL
3454 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3460 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3462 boost::shared_ptr<Send> s;
3463 boost::shared_ptr<Return> r;
3465 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3466 s->meter()->meter();
3467 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3468 r->meter()->meter ();
3473 boost::shared_ptr<Pannable>
3474 Route::pannable() const
3479 boost::shared_ptr<Panner>
3480 Route::panner() const
3483 return _main_outs->panner_shell()->panner();
3486 boost::shared_ptr<PannerShell>
3487 Route::panner_shell() const
3489 return _main_outs->panner_shell();
3492 boost::shared_ptr<AutomationControl>
3493 Route::gain_control() const
3495 return _amp->gain_control();
3498 boost::shared_ptr<AutomationControl>
3499 Route::get_control (const Evoral::Parameter& param)
3501 /* either we own the control or .... */
3503 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3507 /* maybe one of our processors does or ... */
3509 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3510 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3511 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3519 /* nobody does so we'll make a new one */
3521 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3528 boost::shared_ptr<Processor>
3529 Route::nth_plugin (uint32_t n)
3531 Glib::RWLock::ReaderLock lm (_processor_lock);
3532 ProcessorList::iterator i;
3534 for (i = _processors.begin(); i != _processors.end(); ++i) {
3535 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3542 return boost::shared_ptr<Processor> ();
3545 boost::shared_ptr<Processor>
3546 Route::nth_send (uint32_t n)
3548 Glib::RWLock::ReaderLock lm (_processor_lock);
3549 ProcessorList::iterator i;
3551 for (i = _processors.begin(); i != _processors.end(); ++i) {
3552 if (boost::dynamic_pointer_cast<Send> (*i)) {
3559 return boost::shared_ptr<Processor> ();
3563 Route::has_io_processor_named (const string& name)
3565 Glib::RWLock::ReaderLock lm (_processor_lock);
3566 ProcessorList::iterator i;
3568 for (i = _processors.begin(); i != _processors.end(); ++i) {
3569 if (boost::dynamic_pointer_cast<Send> (*i) ||
3570 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3571 if ((*i)->name() == name) {
3580 MuteMaster::MutePoint
3581 Route::mute_points () const
3583 return _mute_master->mute_points ();
3587 Route::set_processor_positions ()
3589 Glib::RWLock::ReaderLock lm (_processor_lock);
3591 bool had_amp = false;
3592 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3593 (*i)->set_pre_fader (!had_amp);
3594 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3600 /** Called when there is a proposed change to the input port count */
3602 Route::input_port_count_changing (ChanCount to)
3604 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3606 /* The processors cannot be configured with the new input arrangement, so
3612 /* The change is ok */
3617 Route::unknown_processors () const
3621 Glib::RWLock::ReaderLock lm (_processor_lock);
3622 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3623 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3624 p.push_back ((*i)->name ());
3633 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
3635 /* we assume that all our input ports feed all our output ports. its not
3636 universally true, but the alternative is way too corner-case to worry about.
3639 jack_latency_range_t all_connections;
3642 all_connections.min = 0;
3643 all_connections.max = 0;
3645 all_connections.min = ~((jack_nframes_t) 0);
3646 all_connections.max = 0;
3648 /* iterate over all "from" ports and determine the latency range for all of their
3649 connections to the "outside" (outside of this Route).
3652 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3654 jack_latency_range_t range;
3656 p->get_connected_latency_range (range, playback);
3658 all_connections.min = min (all_connections.min, range.min);
3659 all_connections.max = max (all_connections.max, range.max);
3663 /* set the "from" port latencies to the max/min range of all their connections */
3665 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3666 p->set_private_latency_range (all_connections, playback);
3669 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
3671 all_connections.min += our_latency;
3672 all_connections.max += our_latency;
3674 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
3675 p->set_private_latency_range (all_connections, playback);
3678 return all_connections.max;
3682 Route::set_private_port_latencies (bool playback) const
3684 framecnt_t own_latency = 0;
3686 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
3687 OR LATENCY CALLBACK.
3689 This is called (early) from the latency callback. It computes the REAL
3690 latency associated with each port and stores the result as the "private"
3691 latency of the port. A later call to Route::set_public_port_latencies()
3692 sets all ports to the same value to reflect the fact that we do latency
3693 compensation and so all signals are delayed by the same amount as they
3694 flow through ardour.
3697 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3698 if ((*i)->active ()) {
3699 own_latency += (*i)->signal_latency ();
3704 /* playback: propagate latency from "outside the route" to outputs to inputs */
3705 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
3707 /* capture: propagate latency from "outside the route" to inputs to outputs */
3708 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
3713 Route::set_public_port_latencies (framecnt_t value, bool playback) const
3715 /* this is called to set the JACK-visible port latencies, which take
3716 latency compensation into account.
3719 jack_latency_range_t range;
3725 const PortSet& ports (_input->ports());
3726 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
3727 p->set_public_latency_range (range, playback);
3732 const PortSet& ports (_output->ports());
3733 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
3734 p->set_public_latency_range (range, playback);
3739 /** Put the invisible processors in the right place in _processors.
3740 * Must be called with a writer lock on _processor_lock held.
3743 Route::setup_invisible_processors ()
3746 Glib::RWLock::WriterLock lm (_processor_lock, Glib::TRY_LOCK);
3747 assert (!lm.locked ());
3751 /* too early to be doing this stuff */
3755 /* we'll build this new list here and then use it */
3757 ProcessorList new_processors;
3759 /* find visible processors */
3761 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3762 if ((*i)->display_to_user ()) {
3763 new_processors.push_back (*i);
3769 ProcessorList::iterator amp = new_processors.begin ();
3770 while (amp != new_processors.end() && boost::dynamic_pointer_cast<Amp> (*amp) == 0) {
3774 assert (amp != _processors.end ());
3776 /* and the processor after the amp */
3778 ProcessorList::iterator after_amp = amp;
3784 switch (_meter_point) {
3786 assert (!_meter->display_to_user ());
3787 new_processors.push_front (_meter);
3790 assert (!_meter->display_to_user ());
3791 new_processors.insert (amp, _meter);
3793 case MeterPostFader:
3794 /* do nothing here */
3797 /* do nothing here */
3800 /* the meter is visible, so we don't touch it here */
3807 assert (_main_outs);
3808 assert (!_main_outs->display_to_user ());
3809 new_processors.push_back (_main_outs);
3811 /* iterator for the main outs */
3813 ProcessorList::iterator main = new_processors.end();
3816 /* OUTPUT METERING */
3818 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
3819 assert (!_meter->display_to_user ());
3821 /* add the processor just before or just after the main outs */
3823 ProcessorList::iterator meter_point = main;
3825 if (_meter_point == MeterOutput) {
3828 new_processors.insert (meter_point, _meter);
3833 if (_monitor_send && !is_monitor ()) {
3834 assert (!_monitor_send->display_to_user ());
3835 if (Config->get_solo_control_is_listen_control()) {
3836 switch (Config->get_listen_position ()) {
3837 case PreFaderListen:
3838 switch (Config->get_pfl_position ()) {
3839 case PFLFromBeforeProcessors:
3840 new_processors.push_front (_monitor_send);
3842 case PFLFromAfterProcessors:
3843 new_processors.insert (amp, _monitor_send);
3846 _monitor_send->set_can_pan (false);
3848 case AfterFaderListen:
3849 switch (Config->get_afl_position ()) {
3850 case AFLFromBeforeProcessors:
3851 new_processors.insert (after_amp, _monitor_send);
3853 case AFLFromAfterProcessors:
3854 new_processors.insert (new_processors.end(), _monitor_send);
3857 _monitor_send->set_can_pan (true);
3861 new_processors.insert (new_processors.end(), _monitor_send);
3862 _monitor_send->set_can_pan (false);
3866 /* MONITOR CONTROL */
3868 if (_monitor_control && is_monitor ()) {
3869 assert (!_monitor_control->display_to_user ());
3870 new_processors.push_front (_monitor_control);
3873 /* INTERNAL RETURN */
3875 /* doing this here means that any monitor control will come just after
3880 assert (!_intreturn->display_to_user ());
3881 new_processors.push_front (_intreturn);
3884 /* EXPORT PROCESSOR */
3886 if (_capturing_processor) {
3887 assert (!_capturing_processor->display_to_user ());
3888 new_processors.push_front (_capturing_processor);
3891 _processors = new_processors;
3893 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
3894 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3895 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
3902 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3903 Glib::RWLock::ReaderLock lp (_processor_lock);
3907 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3908 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
3915 /** If the meter point is `Custom', make a note of where the meter is.
3916 * This is so that if the meter point is subsequently set to something else,
3917 * and then back to custom, we can put the meter back where it was last time
3918 * custom was enabled.
3920 * Must be called with the _processor_lock held.
3923 Route::maybe_note_meter_position ()
3925 if (_meter_point != MeterCustom) {
3929 _custom_meter_position_noted = true;
3930 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3931 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
3932 ProcessorList::iterator j = i;
3934 if (j != _processors.end ()) {
3935 _processor_after_last_custom_meter = *j;
3936 _last_custom_meter_was_at_end = false;
3938 _last_custom_meter_was_at_end = true;
3944 boost::shared_ptr<Processor>
3945 Route::processor_by_id (PBD::ID id) const
3947 Glib::RWLock::ReaderLock lm (_processor_lock);
3948 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3949 if ((*i)->id() == id) {
3954 return boost::shared_ptr<Processor> ();
3957 /** @return the monitoring state, or in other words what data we are pushing
3958 * into the route (data from the inputs, data from disk or silence)
3961 Route::monitoring_state () const
3963 return MonitoringInput;
3966 /** @return what we should be metering; either the data coming from the input
3967 * IO or the data that is flowing through the route.
3970 Route::metering_state () const
3972 return MeteringRoute;