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.
25 #include "pbd/xml++.h"
26 #include "pbd/enumwriter.h"
27 #include "pbd/memento_command.h"
28 #include "pbd/stacktrace.h"
29 #include "pbd/convert.h"
31 #include "evoral/Curve.hpp"
33 #include "ardour/amp.h"
34 #include "ardour/audio_port.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/buffer.h"
37 #include "ardour/buffer_set.h"
38 #include "ardour/configuration.h"
39 #include "ardour/cycle_timer.h"
40 #include "ardour/debug.h"
41 #include "ardour/delivery.h"
42 #include "ardour/dB.h"
43 #include "ardour/internal_send.h"
44 #include "ardour/internal_return.h"
45 #include "ardour/ladspa_plugin.h"
46 #include "ardour/meter.h"
47 #include "ardour/mix.h"
48 #include "ardour/monitor_processor.h"
49 #include "ardour/panner.h"
50 #include "ardour/plugin_insert.h"
51 #include "ardour/port.h"
52 #include "ardour/port_insert.h"
53 #include "ardour/processor.h"
54 #include "ardour/profile.h"
55 #include "ardour/route.h"
56 #include "ardour/route_group.h"
57 #include "ardour/send.h"
58 #include "ardour/session.h"
59 #include "ardour/timestamps.h"
60 #include "ardour/utils.h"
61 #include "ardour/graph.h"
62 #include "ardour/unknown_processor.h"
67 using namespace ARDOUR;
70 uint32_t Route::order_key_cnt = 0;
71 PBD::Signal1<void,string const&> Route::SyncOrderKeys;
72 PBD::Signal0<void> Route::RemoteControlIDChange;
74 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
75 : SessionObject (sess, name)
77 , GraphNode( sess.route_graph )
82 , _pending_declick (true)
83 , _meter_point (MeterPostFader)
85 , _soloed_by_others_upstream (0)
86 , _soloed_by_others_downstream (0)
88 , _denormal_protection (false)
91 , _declickable (false)
92 , _solo_control (new SoloControllable (X_("solo"), *this))
93 , _mute_control (new MuteControllable (X_("mute"), *this))
94 , _mute_master (new MuteMaster (sess, name))
95 , _have_internal_generator (false)
97 , _default_type (default_type)
98 , _remote_control_id (0)
99 , _in_configure_processors (false)
101 processor_max_streams.reset();
102 order_keys[N_("signal")] = order_key_cnt++;
108 /* add standard controls */
110 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
111 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
113 add_control (_solo_control);
114 add_control (_mute_control);
116 /* input and output objects */
118 _input.reset (new IO (_session, _name, IO::Input, _default_type));
119 _output.reset (new IO (_session, _name, IO::Output, _default_type));
121 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
122 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
124 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
126 /* add amp processor */
128 _amp.reset (new Amp (_session));
129 add_processor (_amp, PostFader);
131 /* add standard processors: meter, main outs, monitor out */
133 _meter.reset (new PeakMeter (_session));
134 _meter->set_display_to_user (false);
136 add_processor (_meter, PostFader);
138 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
140 add_processor (_main_outs, PostFader);
143 /* where we listen to tracks */
144 _intreturn.reset (new InternalReturn (_session));
145 add_processor (_intreturn, PreFader);
147 ProcessorList::iterator i;
149 for (i = _processors.begin(); i != _processors.end(); ++i) {
150 if (*i == _intreturn) {
156 /* the thing that provides proper control over a control/monitor/listen bus
157 (such as per-channel cut, dim, solo, invert, etc).
158 It always goes right after the internal return;
160 _monitor_control.reset (new MonitorProcessor (_session));
161 add_processor (_monitor_control, i);
163 /* no panning on the monitor main outs */
165 _main_outs->panner()->set_bypassed (true);
168 if (is_master() || is_monitor() || is_hidden()) {
169 _mute_master->set_solo_ignore (true);
172 /* now that we have _meter, its safe to connect to this */
174 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
181 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
183 /* do this early so that we don't get incoming signals as we are going through destruction
188 /* don't use clear_processors here, as it depends on the session which may
189 be half-destroyed by now
192 Glib::RWLock::WriterLock lm (_processor_lock);
193 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
194 (*i)->drop_references ();
197 _processors.clear ();
201 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
203 if (id != _remote_control_id) {
204 _remote_control_id = id;
205 RemoteControlIDChanged ();
206 if (notify_class_listeners) {
207 RemoteControlIDChange ();
213 Route::remote_control_id() const
215 return _remote_control_id;
219 Route::order_key (std::string const & name) const
221 OrderKeys::const_iterator i = order_keys.find (name);
222 if (i == order_keys.end()) {
230 Route::set_order_key (std::string const & name, int32_t n)
232 bool changed = false;
234 /* This method looks more complicated than it should, but
235 it's important that we don't emit order_key_changed unless
236 it actually has, as expensive things happen on receipt of that
240 if (order_keys.find(name) == order_keys.end() || order_keys[name] != n) {
241 order_keys[name] = n;
245 if (Config->get_sync_all_route_ordering()) {
246 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
247 if (x->second != n) {
255 order_key_changed (); /* EMIT SIGNAL */
256 _session.set_dirty ();
260 /** Set all order keys to be the same as that for `base', if such a key
261 * exists in this route.
262 * @param base Base key.
265 Route::sync_order_keys (std::string const & base)
267 if (order_keys.empty()) {
271 OrderKeys::iterator i;
274 if ((i = order_keys.find (base)) == order_keys.end()) {
275 /* key doesn't exist, use the first existing key (during session initialization) */
276 i = order_keys.begin();
280 /* key exists - use it and reset all others (actually, itself included) */
282 i = order_keys.begin();
285 bool changed = false;
287 for (; i != order_keys.end(); ++i) {
288 if (i->second != key) {
295 order_key_changed (); /* EMIT SIGNAL */
300 Route::ensure_track_or_route_name(string name, Session &session)
302 string newname = name;
304 while (!session.io_name_is_legal (newname)) {
305 newname = bump_name_once (newname, '.');
313 Route::inc_gain (gain_t fraction, void *src)
315 _amp->inc_gain (fraction, src);
319 Route::set_gain (gain_t val, void *src)
321 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
323 if (_route_group->is_relative()) {
325 gain_t usable_gain = _amp->gain();
326 if (usable_gain < 0.000001f) {
327 usable_gain = 0.000001f;
331 if (delta < 0.000001f) {
335 delta -= usable_gain;
340 gain_t factor = delta / usable_gain;
343 factor = _route_group->get_max_factor(factor);
344 if (factor == 0.0f) {
345 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
349 factor = _route_group->get_min_factor(factor);
350 if (factor == 0.0f) {
351 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
356 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
360 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
366 if (val == _amp->gain()) {
370 _amp->set_gain (val, src);
373 /** Process this route for one (sub) cycle (process thread)
375 * @param bufs Scratch buffers to use for the signal path
376 * @param start_frame Initial transport frame
377 * @param end_frame Final transport frame
378 * @param nframes Number of frames to output (to ports)
380 * Note that (end_frame - start_frame) may not be equal to nframes when the
381 * transport speed isn't 1.0 (eg varispeed).
384 Route::process_output_buffers (BufferSet& bufs,
385 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
386 bool /*with_processors*/, int declick,
387 bool gain_automation_ok)
391 bufs.is_silent (false);
393 switch (Config->get_monitoring_model()) {
394 case HardwareMonitoring:
395 case ExternalMonitoring:
396 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
403 declick = _pending_declick;
406 /* figure out if we're going to use gain automation */
407 if (gain_automation_ok) {
408 _amp->setup_gain_automation (start_frame, end_frame, nframes);
410 _amp->apply_gain_automation (false);
413 /* tell main outs what to do about monitoring */
414 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
417 /* -------------------------------------------------------------------------------------------
418 GLOBAL DECLICK (for transport changes etc.)
419 ----------------------------------------------------------------------------------------- */
422 Amp::declick (bufs, nframes, 1);
423 } else if (declick < 0) {
424 Amp::declick (bufs, nframes, -1);
427 _pending_declick = 0;
429 /* -------------------------------------------------------------------------------------------
430 DENORMAL CONTROL/PHASE INVERT
431 ----------------------------------------------------------------------------------------- */
433 if (_phase_invert.any ()) {
437 if (_denormal_protection || Config->get_denormal_protection()) {
439 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
440 Sample* const sp = i->data();
442 if (_phase_invert[chn]) {
443 for (pframes_t nx = 0; nx < nframes; ++nx) {
448 for (pframes_t nx = 0; nx < nframes; ++nx) {
456 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
457 Sample* const sp = i->data();
459 if (_phase_invert[chn]) {
460 for (pframes_t nx = 0; nx < nframes; ++nx) {
469 if (_denormal_protection || Config->get_denormal_protection()) {
471 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
472 Sample* const sp = i->data();
473 for (pframes_t nx = 0; nx < nframes; ++nx) {
481 /* -------------------------------------------------------------------------------------------
483 ----------------------------------------------------------------------------------------- */
485 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
487 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i)) {
491 if (bufs.count() != (*i)->input_streams()) {
492 cerr << _name << " bufs = " << bufs.count()
493 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
496 assert (bufs.count() == (*i)->input_streams());
498 /* should we NOT run plugins here if the route is inactive?
499 do we catch route != active somewhere higher?
502 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
503 bufs.set_count ((*i)->output_streams());
508 Route::n_process_buffers ()
510 return max (_input->n_ports(), processor_max_streams);
514 Route::passthru (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
516 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
520 assert (bufs.available() >= input_streams());
522 if (_input->n_ports() == ChanCount::ZERO) {
523 silence_unlocked (nframes);
526 bufs.set_count (input_streams());
528 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
530 /* control/monitor bus ignores input ports when something is
531 feeding the listen "stream". data will "arrive" into the
532 route from the intreturn processor element.
534 bufs.silence (nframes, 0);
538 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
540 BufferSet::iterator o = bufs.begin(*t);
541 PortSet& ports (_input->ports());
543 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
544 o->read_from (i->get_buffer(nframes), nframes);
549 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
550 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick, true);
554 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
556 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
557 bufs.set_count (_input->n_ports());
558 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
559 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick, false);
563 Route::set_listen (bool yn, void* src)
570 if (yn != _monitor_send->active()) {
572 _monitor_send->activate ();
573 _mute_master->set_soloed (true);
575 _monitor_send->deactivate ();
576 _mute_master->set_soloed (false);
579 listen_changed (src); /* EMIT SIGNAL */
585 Route::listening () const
588 return _monitor_send->active ();
595 Route::set_solo_safe (bool yn, void *src)
597 if (_solo_safe != yn) {
599 solo_safe_changed (src);
604 Route::solo_safe() const
610 Route::set_solo (bool yn, void *src)
616 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
617 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
621 if (self_soloed() != yn) {
623 set_mute_master_solo ();
624 solo_changed (true, src); /* EMIT SIGNAL */
625 _solo_control->Changed (); /* EMIT SIGNAL */
630 Route::set_self_solo (bool yn)
636 Route::mod_solo_by_others_upstream (int32_t delta)
642 uint32_t old_sbu = _soloed_by_others_upstream;
645 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
646 _soloed_by_others_upstream += delta;
648 _soloed_by_others_upstream = 0;
651 _soloed_by_others_upstream += delta;
654 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
655 name(), delta, _soloed_by_others_upstream, old_sbu,
656 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
658 /* push the inverse solo change to everything that feeds us.
660 This is important for solo-within-group. When we solo 1 track out of N that
661 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
662 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
663 tracks that feed it. This will silence them if they were audible because
664 of a bus solo, but the newly soloed track will still be audible (because
667 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
671 if ((_self_solo || _soloed_by_others_downstream) &&
672 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
673 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
675 if (delta > 0 || !Config->get_exclusive_solo()) {
676 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
677 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
678 boost::shared_ptr<Route> sr = i->r.lock();
680 sr->mod_solo_by_others_downstream (-delta);
686 set_mute_master_solo ();
687 solo_changed (false, this);
691 Route::mod_solo_by_others_downstream (int32_t delta)
698 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
699 _soloed_by_others_downstream += delta;
701 _soloed_by_others_downstream = 0;
704 _soloed_by_others_downstream += delta;
707 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
709 set_mute_master_solo ();
710 solo_changed (false, this);
714 Route::set_mute_master_solo ()
716 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
720 Route::set_solo_isolated (bool yn, void *src)
722 if (is_master() || is_monitor() || is_hidden()) {
726 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
727 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
731 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
733 boost::shared_ptr<RouteList> routes = _session.get_routes ();
734 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
736 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
741 bool does_feed = direct_feeds (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
743 if (does_feed && !sends_only) {
744 (*i)->set_solo_isolated (yn, (*i)->route_group());
748 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
750 bool changed = false;
753 if (_solo_isolated == 0) {
754 _mute_master->set_solo_ignore (true);
759 if (_solo_isolated > 0) {
761 if (_solo_isolated == 0) {
762 _mute_master->set_solo_ignore (false);
769 solo_isolated_changed (src);
774 Route::solo_isolated () const
776 return _solo_isolated > 0;
780 Route::set_mute_points (MuteMaster::MutePoint mp)
782 _mute_master->set_mute_points (mp);
783 mute_points_changed (); /* EMIT SIGNAL */
785 if (_mute_master->muted_by_self()) {
786 mute_changed (this); /* EMIT SIGNAL */
787 _mute_control->Changed (); /* EMIT SIGNAL */
792 Route::set_mute (bool yn, void *src)
794 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
795 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
800 _mute_master->set_muted_by_self (yn);
801 mute_changed (src); /* EMIT SIGNAL */
802 _mute_control->Changed (); /* EMIT SIGNAL */
807 Route::muted () const
809 return _mute_master->muted_by_self();
814 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
816 cerr << name << " {" << endl;
817 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
818 p != procs.end(); ++p) {
819 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
826 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
828 ProcessorList::iterator loc;
830 /* XXX this is not thread safe - we don't hold the lock across determining the iter
831 to add before and actually doing the insertion. dammit.
834 if (placement == PreFader) {
835 /* generic pre-fader: insert immediately before the amp */
836 loc = find (_processors.begin(), _processors.end(), _amp);
838 /* generic post-fader: insert right before the main outs */
839 loc = find (_processors.begin(), _processors.end(), _main_outs);
842 return add_processor (processor, loc, err);
846 /** Add a processor to the route.
847 * @a iter must point to an iterator in _processors and the new
848 * processor will be inserted immediately before this location. Otherwise,
849 * @a position is used.
852 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
854 ChanCount old_pms = processor_max_streams;
856 if (!_session.engine().connected() || !processor) {
861 Glib::RWLock::WriterLock lm (_processor_lock);
863 boost::shared_ptr<PluginInsert> pi;
864 boost::shared_ptr<PortInsert> porti;
866 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
868 if (processor == _amp || processor == _meter || processor == _main_outs) {
869 // Ensure only one of these are in the list at any time
870 if (loc != _processors.end()) {
871 if (iter == loc) { // Already in place, do nothing
873 } else { // New position given, relocate
874 _processors.erase (loc);
879 if (loc != _processors.end()) {
880 cerr << "ERROR: Processor added to route twice!" << endl;
887 _processors.insert (loc, processor);
889 // Set up processor list channels. This will set processor->[input|output]_streams(),
890 // configure redirect ports properly, etc.
893 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
895 if (configure_processors_unlocked (err)) {
896 ProcessorList::iterator ploc = loc;
898 _processors.erase(ploc);
899 configure_processors_unlocked (0); // it worked before we tried to add it ...
900 cerr << "configure failed\n";
905 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
907 if (pi->natural_input_streams() == ChanCount::ZERO) {
908 /* generator plugin */
909 _have_internal_generator = true;
914 /* is this the monitor send ? if so, make sure we keep track of it */
916 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
918 if (isend && _session.monitor_out() && (isend->target_id() == _session.monitor_out()->id())) {
919 _monitor_send = isend;
922 if (activation_allowed && (processor != _monitor_send)) {
923 processor->activate ();
926 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
928 _output->set_user_latency (0);
931 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
932 set_processor_positions ();
938 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
940 const XMLProperty *prop;
943 boost::shared_ptr<Processor> processor;
945 /* bit of a hack: get the `placement' property from the <Redirect> tag here
946 so that we can add the processor in the right place (pre/post-fader)
949 XMLNodeList const & children = node.children ();
950 XMLNodeList::const_iterator i = children.begin ();
952 while (i != children.end() && (*i)->name() != X_("Redirect")) {
956 Placement placement = PreFader;
958 if (i != children.end()) {
959 if ((prop = (*i)->property (X_("placement"))) != 0) {
960 placement = Placement (string_2_enum (prop->value(), placement));
964 if (node.name() == "Insert") {
966 if ((prop = node.property ("type")) != 0) {
968 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
969 prop->value() == "lv2" ||
970 prop->value() == "vst" ||
971 prop->value() == "audiounit") {
973 processor.reset (new PluginInsert (_session));
977 processor.reset (new PortInsert (_session, _mute_master));
982 } else if (node.name() == "Send") {
984 processor.reset (new Send (_session, _mute_master));
988 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
992 if (processor->set_state (node, version)) {
996 return (add_processor (processor, placement) == 0);
999 catch (failed_constructor &err) {
1000 warning << _("processor could not be created. Ignored.") << endmsg;
1006 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1008 ProcessorList::iterator loc;
1011 loc = find(_processors.begin(), _processors.end(), before);
1013 /* nothing specified - at end but before main outs */
1014 loc = find (_processors.begin(), _processors.end(), _main_outs);
1017 return add_processors (others, loc, err);
1021 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
1023 /* NOTE: this is intended to be used ONLY when copying
1024 processors from another Route. Hence the subtle
1025 differences between this and ::add_processor()
1028 ChanCount old_pms = processor_max_streams;
1030 if (!_session.engine().connected()) {
1034 if (others.empty()) {
1039 Glib::RWLock::WriterLock lm (_processor_lock);
1041 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
1043 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1045 // Ensure meter only appears in the list once
1047 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
1048 if (m != _processors.end()) {
1049 _processors.erase(m);
1053 boost::shared_ptr<PluginInsert> pi;
1055 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1058 ChanCount m = max (pi->input_streams(), pi->output_streams());
1060 if (m > potential_max_streams) {
1061 potential_max_streams = m;
1065 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1067 if ((*i)->active()) {
1072 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1073 if (configure_processors_unlocked (err)) {
1074 _processors.erase (inserted);
1075 configure_processors_unlocked (0); // it worked before we tried to add it ...
1080 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
1083 _output->set_user_latency (0);
1086 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1087 set_processor_positions ();
1093 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1095 if (p == PreFader) {
1096 start = _processors.begin();
1097 end = find(_processors.begin(), _processors.end(), _amp);
1099 start = find(_processors.begin(), _processors.end(), _amp);
1101 end = _processors.end();
1105 /** Turn off all processors with a given placement
1106 * @param p Placement of processors to disable
1109 Route::disable_processors (Placement p)
1111 Glib::RWLock::ReaderLock lm (_processor_lock);
1113 ProcessorList::iterator start, end;
1114 placement_range(p, start, end);
1116 for (ProcessorList::iterator i = start; i != end; ++i) {
1117 (*i)->deactivate ();
1120 _session.set_dirty ();
1123 /** Turn off all redirects
1126 Route::disable_processors ()
1128 Glib::RWLock::ReaderLock lm (_processor_lock);
1130 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1131 (*i)->deactivate ();
1134 _session.set_dirty ();
1137 /** Turn off all redirects with a given placement
1138 * @param p Placement of redirects to disable
1141 Route::disable_plugins (Placement p)
1143 Glib::RWLock::ReaderLock lm (_processor_lock);
1145 ProcessorList::iterator start, end;
1146 placement_range(p, start, end);
1148 for (ProcessorList::iterator i = start; i != end; ++i) {
1149 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1150 (*i)->deactivate ();
1154 _session.set_dirty ();
1157 /** Turn off all plugins
1160 Route::disable_plugins ()
1162 Glib::RWLock::ReaderLock lm (_processor_lock);
1164 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1165 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1166 (*i)->deactivate ();
1170 _session.set_dirty ();
1175 Route::ab_plugins (bool forward)
1177 Glib::RWLock::ReaderLock lm (_processor_lock);
1181 /* forward = turn off all active redirects, and mark them so that the next time
1182 we go the other way, we will revert them
1185 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1186 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1190 if ((*i)->active()) {
1191 (*i)->deactivate ();
1192 (*i)->set_next_ab_is_active (true);
1194 (*i)->set_next_ab_is_active (false);
1200 /* backward = if the redirect was marked to go active on the next ab, do so */
1202 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1204 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1208 if ((*i)->get_next_ab_is_active()) {
1211 (*i)->deactivate ();
1216 _session.set_dirty ();
1220 /** Remove processors with a given placement.
1221 * @param p Placement of processors to remove.
1224 Route::clear_processors (Placement p)
1226 const ChanCount old_pms = processor_max_streams;
1228 if (!_session.engine().connected()) {
1232 bool already_deleting = _session.deletion_in_progress();
1233 if (!already_deleting) {
1234 _session.set_deletion_in_progress();
1238 Glib::RWLock::WriterLock lm (_processor_lock);
1239 ProcessorList new_list;
1240 ProcessorStreams err;
1241 bool seen_amp = false;
1243 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1249 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1251 /* you can't remove these */
1253 new_list.push_back (*i);
1260 new_list.push_back (*i);
1263 (*i)->drop_references ();
1271 (*i)->drop_references ();
1274 new_list.push_back (*i);
1281 _processors = new_list;
1284 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1285 configure_processors_unlocked (&err); // this can't fail
1289 processor_max_streams.reset();
1290 _have_internal_generator = false;
1291 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1292 set_processor_positions ();
1294 if (!already_deleting) {
1295 _session.clear_deletion_in_progress();
1300 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1302 /* these can never be removed */
1304 if (processor == _amp || processor == _meter || processor == _main_outs) {
1308 ChanCount old_pms = processor_max_streams;
1310 if (!_session.engine().connected()) {
1314 processor_max_streams.reset();
1317 Glib::RWLock::WriterLock lm (_processor_lock);
1318 ProcessorList::iterator i;
1319 bool removed = false;
1321 for (i = _processors.begin(); i != _processors.end(); ) {
1322 if (*i == processor) {
1324 /* move along, see failure case for configure_processors()
1325 where we may need to reconfigure the processor.
1328 /* stop redirects that send signals to JACK ports
1329 from causing noise as a result of no longer being
1333 boost::shared_ptr<IOProcessor> iop;
1335 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1337 iop->input()->disconnect (this);
1339 if (iop->output()) {
1340 iop->output()->disconnect (this);
1344 i = _processors.erase (i);
1352 _output->set_user_latency (0);
1361 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1363 if (configure_processors_unlocked (err)) {
1364 /* get back to where we where */
1365 _processors.insert (i, processor);
1366 /* we know this will work, because it worked before :) */
1367 configure_processors_unlocked (0);
1372 _have_internal_generator = false;
1374 for (i = _processors.begin(); i != _processors.end(); ++i) {
1375 boost::shared_ptr<PluginInsert> pi;
1377 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1378 if (pi->is_generator()) {
1379 _have_internal_generator = true;
1386 processor->drop_references ();
1387 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1388 set_processor_positions ();
1394 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1396 ProcessorList deleted;
1398 if (!_session.engine().connected()) {
1402 processor_max_streams.reset();
1405 Glib::RWLock::WriterLock lm (_processor_lock);
1406 ProcessorList::iterator i;
1407 boost::shared_ptr<Processor> processor;
1409 ProcessorList as_we_were = _processors;
1411 for (i = _processors.begin(); i != _processors.end(); ) {
1415 /* these can never be removed */
1417 if (processor == _amp || processor == _meter || processor == _main_outs) {
1422 /* see if its in the list of processors to delete */
1424 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1429 /* stop IOProcessors that send to JACK ports
1430 from causing noise as a result of no longer being
1434 boost::shared_ptr<IOProcessor> iop;
1436 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1440 deleted.push_back (processor);
1441 i = _processors.erase (i);
1444 if (deleted.empty()) {
1445 /* none of those in the requested list were found */
1449 _output->set_user_latency (0);
1452 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1454 if (configure_processors_unlocked (err)) {
1455 /* get back to where we where */
1456 _processors = as_we_were;
1457 /* we know this will work, because it worked before :) */
1458 configure_processors_unlocked (0);
1463 _have_internal_generator = false;
1465 for (i = _processors.begin(); i != _processors.end(); ++i) {
1466 boost::shared_ptr<PluginInsert> pi;
1468 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1469 if (pi->is_generator()) {
1470 _have_internal_generator = true;
1477 /* now try to do what we need to so that those that were removed will be deleted */
1479 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1480 (*i)->drop_references ();
1483 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1484 set_processor_positions ();
1489 /** Caller must hold process lock */
1491 Route::configure_processors (ProcessorStreams* err)
1493 assert (!AudioEngine::instance()->process_lock().trylock());
1495 if (!_in_configure_processors) {
1496 Glib::RWLock::WriterLock lm (_processor_lock);
1497 return configure_processors_unlocked (err);
1503 Route::input_streams () const
1505 return _input->n_ports ();
1508 list<pair<ChanCount, ChanCount> >
1509 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1511 Glib::RWLock::ReaderLock lm (_processor_lock);
1513 return try_configure_processors_unlocked (in, err);
1516 list<pair<ChanCount, ChanCount> >
1517 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1519 // Check each processor in order to see if we can configure as requested
1521 list<pair<ChanCount, ChanCount> > configuration;
1524 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1525 DEBUG_TRACE (DEBUG::Processors, "{\n");
1527 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1529 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1530 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1534 if ((*p)->can_support_io_configuration(in, out)) {
1535 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1536 configuration.push_back(make_pair(in, out));
1543 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1544 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1545 DEBUG_TRACE (DEBUG::Processors, "}\n");
1546 return list<pair<ChanCount, ChanCount> > ();
1550 DEBUG_TRACE (DEBUG::Processors, "}\n");
1552 return configuration;
1555 /** Set the input/output configuration of each processor in the processors list.
1556 * Caller must hold process lock.
1557 * Return 0 on success, otherwise configuration is impossible.
1560 Route::configure_processors_unlocked (ProcessorStreams* err)
1562 assert (!AudioEngine::instance()->process_lock().trylock());
1564 if (_in_configure_processors) {
1568 _in_configure_processors = true;
1570 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1572 if (configuration.empty ()) {
1573 _in_configure_processors = false;
1579 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1580 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1582 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1586 (*p)->configure_io(c->first, c->second);
1587 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1588 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1593 _meter->reset_max_channels (processor_max_streams);
1596 /* make sure we have sufficient scratch buffers to cope with the new processor
1598 _session.ensure_buffers (n_process_buffers ());
1600 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1602 _in_configure_processors = false;
1607 Route::all_processors_flip ()
1609 Glib::RWLock::ReaderLock lm (_processor_lock);
1611 if (_processors.empty()) {
1615 bool first_is_on = _processors.front()->active();
1617 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1619 (*i)->deactivate ();
1625 _session.set_dirty ();
1628 /** Set all processors with a given placement to a given active state.
1629 * @param p Placement of processors to change.
1630 * @param state New active state for those processors.
1633 Route::all_processors_active (Placement p, bool state)
1635 Glib::RWLock::ReaderLock lm (_processor_lock);
1637 if (_processors.empty()) {
1640 ProcessorList::iterator start, end;
1641 placement_range(p, start, end);
1643 bool before_amp = true;
1644 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1649 if (p == PreFader && before_amp) {
1653 (*i)->deactivate ();
1658 _session.set_dirty ();
1662 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1664 bool pre_fader = true;
1665 Glib::RWLock::ReaderLock lm (_processor_lock);
1667 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1669 /* semantic note: if p == amp, we want to return true, so test
1670 for equality before checking if this is the amp
1687 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1689 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1690 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1691 processors in the current actual processor list that are hidden. Any visible processors
1692 in the current list but not in "new_order" will be assumed to be deleted.
1696 Glib::RWLock::WriterLock lm (_processor_lock);
1697 ChanCount old_pms = processor_max_streams;
1698 ProcessorList::iterator oiter;
1699 ProcessorList::const_iterator niter;
1700 ProcessorList as_it_was_before = _processors;
1701 ProcessorList as_it_will_be;
1703 oiter = _processors.begin();
1704 niter = new_order.begin();
1706 while (niter != new_order.end()) {
1708 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1709 then append it to the temp list.
1711 Otherwise, see if the next processor in the old list is in the new list. if not,
1712 its been deleted. If its there, append it to the temp list.
1715 if (oiter == _processors.end()) {
1717 /* no more elements in the old list, so just stick the rest of
1718 the new order onto the temp list.
1721 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1722 while (niter != new_order.end()) {
1729 if (!(*oiter)->display_to_user()) {
1731 as_it_will_be.push_back (*oiter);
1735 /* visible processor: check that its in the new order */
1737 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1738 /* deleted: do nothing, shared_ptr<> will clean up */
1740 /* ignore this one, and add the next item from the new order instead */
1741 as_it_will_be.push_back (*niter);
1746 /* now remove from old order - its taken care of no matter what */
1747 oiter = _processors.erase (oiter);
1752 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1755 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1757 if (configure_processors_unlocked (err)) {
1758 _processors = as_it_was_before;
1759 processor_max_streams = old_pms;
1766 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1767 set_processor_positions ();
1780 Route::get_template()
1782 return state(false);
1786 Route::state(bool full_state)
1788 XMLNode *node = new XMLNode("Route");
1789 ProcessorList::iterator i;
1792 id().print (buf, sizeof (buf));
1793 node->add_property("id", buf);
1794 node->add_property ("name", _name);
1795 node->add_property("default-type", _default_type.to_string());
1798 node->add_property("flags", enum_2_string (_flags));
1801 node->add_property("active", _active?"yes":"no");
1803 boost::to_string (_phase_invert, p);
1804 node->add_property("phase-invert", p);
1805 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1806 node->add_property("meter-point", enum_2_string (_meter_point));
1809 node->add_property("route-group", _route_group->name());
1812 string order_string;
1813 OrderKeys::iterator x = order_keys.begin();
1815 while (x != order_keys.end()) {
1816 order_string += string ((*x).first);
1817 order_string += '=';
1818 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1819 order_string += buf;
1823 if (x == order_keys.end()) {
1827 order_string += ':';
1829 node->add_property ("order-keys", order_string);
1830 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1831 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1832 node->add_property ("soloed-by-upstream", buf);
1833 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1834 node->add_property ("soloed-by-downstream", buf);
1835 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
1836 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
1838 node->add_child_nocopy (_input->state (full_state));
1839 node->add_child_nocopy (_output->state (full_state));
1840 node->add_child_nocopy (_solo_control->get_state ());
1841 node->add_child_nocopy (_mute_control->get_state ());
1842 node->add_child_nocopy (_mute_master->get_state ());
1844 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1845 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1846 remote_control_node->add_property (X_("id"), buf);
1847 node->add_child_nocopy (*remote_control_node);
1849 if (_comment.length()) {
1850 XMLNode *cmt = node->add_child ("Comment");
1851 cmt->add_content (_comment);
1854 for (i = _processors.begin(); i != _processors.end(); ++i) {
1855 node->add_child_nocopy((*i)->state (full_state));
1859 node->add_child_copy (*_extra_xml);
1866 Route::set_state (const XMLNode& node, int version)
1868 return _set_state (node, version, true);
1872 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1874 if (version < 3000) {
1875 return _set_state_2X (node, version);
1879 XMLNodeConstIterator niter;
1881 const XMLProperty *prop;
1883 if (node.name() != "Route"){
1884 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1888 if ((prop = node.property (X_("name"))) != 0) {
1889 Route::set_name (prop->value());
1892 if ((prop = node.property ("id")) != 0) {
1893 _id = prop->value ();
1896 if ((prop = node.property (X_("flags"))) != 0) {
1897 _flags = Flag (string_2_enum (prop->value(), _flags));
1902 if (is_master() || is_monitor() || is_hidden()) {
1903 _mute_master->set_solo_ignore (true);
1906 /* add all processors (except amp, which is always present) */
1908 nlist = node.children();
1909 XMLNode processor_state (X_("processor_state"));
1911 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1915 if (child->name() == IO::state_node_name) {
1916 if ((prop = child->property (X_("direction"))) == 0) {
1920 if (prop->value() == "Input") {
1921 _input->set_state (*child, version);
1922 } else if (prop->value() == "Output") {
1923 _output->set_state (*child, version);
1927 if (child->name() == X_("Processor")) {
1928 processor_state.add_child_copy (*child);
1932 set_processor_state (processor_state);
1934 if ((prop = node.property ("self-solo")) != 0) {
1935 set_self_solo (string_is_affirmative (prop->value()));
1938 if ((prop = node.property ("soloed-by-upstream")) != 0) {
1939 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
1940 mod_solo_by_others_upstream (atoi (prop->value()));
1943 if ((prop = node.property ("soloed-by-downstream")) != 0) {
1944 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
1945 mod_solo_by_others_downstream (atoi (prop->value()));
1948 if ((prop = node.property ("solo-isolated")) != 0) {
1949 set_solo_isolated (string_is_affirmative (prop->value()), this);
1952 if ((prop = node.property ("solo-safe")) != 0) {
1953 set_solo_safe (string_is_affirmative (prop->value()), this);
1956 if ((prop = node.property (X_("phase-invert"))) != 0) {
1957 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
1960 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1961 set_denormal_protection (string_is_affirmative (prop->value()));
1964 if ((prop = node.property (X_("active"))) != 0) {
1965 bool yn = string_is_affirmative (prop->value());
1966 _active = !yn; // force switch
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 if ((prop = node.property (X_("order-keys"))) != 0) {
1982 string::size_type colon, equal;
1983 string remaining = prop->value();
1985 while (remaining.length()) {
1987 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1988 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1991 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
1992 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1995 set_order_key (remaining.substr (0, equal), n);
1999 colon = remaining.find_first_of (':');
2001 if (colon != string::npos) {
2002 remaining = remaining.substr (colon+1);
2009 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2012 if (child->name() == X_("Comment")) {
2014 /* XXX this is a terrible API design in libxml++ */
2016 XMLNode *cmt = *(child->children().begin());
2017 _comment = cmt->content();
2019 } else if (child->name() == X_("Extra")) {
2021 _extra_xml = new XMLNode (*child);
2023 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2024 if (prop->value() == "solo") {
2025 _solo_control->set_state (*child, version);
2028 } else if (child->name() == X_("RemoteControl")) {
2029 if ((prop = child->property (X_("id"))) != 0) {
2031 sscanf (prop->value().c_str(), "%d", &x);
2032 set_remote_control_id (x);
2035 } else if (child->name() == X_("MuteMaster")) {
2036 _mute_master->set_state (*child, version);
2044 Route::_set_state_2X (const XMLNode& node, int version)
2047 XMLNodeConstIterator niter;
2049 const XMLProperty *prop;
2051 /* 2X things which still remain to be handled:
2057 if (node.name() != "Route") {
2058 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2062 if ((prop = node.property (X_("flags"))) != 0) {
2063 _flags = Flag (string_2_enum (prop->value(), _flags));
2068 if ((prop = node.property (X_("phase-invert"))) != 0) {
2069 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2070 if (string_is_affirmative (prop->value ())) {
2073 set_phase_invert (p);
2076 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2077 set_denormal_protection (string_is_affirmative (prop->value()));
2080 if ((prop = node.property (X_("soloed"))) != 0) {
2081 bool yn = string_is_affirmative (prop->value());
2083 /* XXX force reset of solo status */
2085 set_solo (yn, this);
2088 if ((prop = node.property (X_("muted"))) != 0) {
2091 bool muted = string_is_affirmative (prop->value());
2097 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2099 if (string_is_affirmative (prop->value())){
2100 mute_point = mute_point + "PreFader";
2105 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2107 if (string_is_affirmative (prop->value())){
2110 mute_point = mute_point + ",";
2113 mute_point = mute_point + "PostFader";
2118 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2120 if (string_is_affirmative (prop->value())){
2123 mute_point = mute_point + ",";
2126 mute_point = mute_point + "Listen";
2131 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2133 if (string_is_affirmative (prop->value())){
2136 mute_point = mute_point + ",";
2139 mute_point = mute_point + "Main";
2143 _mute_master->set_mute_points (mute_point);
2147 if ((prop = node.property (X_("meter-point"))) != 0) {
2148 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2151 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2152 don't mean the same thing.
2155 if ((prop = node.property (X_("order-keys"))) != 0) {
2159 string::size_type colon, equal;
2160 string remaining = prop->value();
2162 while (remaining.length()) {
2164 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2165 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2168 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2169 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2172 set_order_key (remaining.substr (0, equal), n);
2176 colon = remaining.find_first_of (':');
2178 if (colon != string::npos) {
2179 remaining = remaining.substr (colon+1);
2188 nlist = node.children ();
2189 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2193 if (child->name() == IO::state_node_name) {
2195 /* there is a note in IO::set_state_2X() about why we have to call
2199 _input->set_state_2X (*child, version, true);
2200 _output->set_state_2X (*child, version, false);
2202 if ((prop = child->property (X_("name"))) != 0) {
2203 Route::set_name (prop->value ());
2206 if ((prop = child->property (X_("id"))) != 0) {
2207 _id = prop->value ();
2210 if ((prop = child->property (X_("active"))) != 0) {
2211 bool yn = string_is_affirmative (prop->value());
2212 _active = !yn; // force switch
2216 if ((prop = child->property (X_("gain"))) != 0) {
2219 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2220 _amp->gain_control()->set_value (val);
2224 /* Set up Panners in the IO */
2225 XMLNodeList io_nlist = child->children ();
2227 XMLNodeConstIterator io_niter;
2230 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2232 io_child = *io_niter;
2234 if (io_child->name() == X_("Panner")) {
2235 _main_outs->panner()->set_state(*io_child, version);
2236 } else if (io_child->name() == X_("Automation")) {
2237 /* IO's automation is for the fader */
2238 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2244 XMLNodeList redirect_nodes;
2246 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2250 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2251 redirect_nodes.push_back(child);
2256 set_processor_state_2X (redirect_nodes, version);
2258 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2261 if (child->name() == X_("Comment")) {
2263 /* XXX this is a terrible API design in libxml++ */
2265 XMLNode *cmt = *(child->children().begin());
2266 _comment = cmt->content();
2268 } else if (child->name() == X_("extra")) {
2270 _extra_xml = new XMLNode (*child);
2272 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2273 if (prop->value() == X_("solo")) {
2274 _solo_control->set_state (*child, version);
2275 } else if (prop->value() == X_("mute")) {
2276 _mute_control->set_state (*child, version);
2279 } else if (child->name() == X_("RemoteControl")) {
2280 if ((prop = child->property (X_("id"))) != 0) {
2282 sscanf (prop->value().c_str(), "%d", &x);
2283 set_remote_control_id (x);
2293 Route::get_processor_state ()
2295 XMLNode* root = new XMLNode (X_("redirects"));
2296 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2297 root->add_child_nocopy ((*i)->state (true));
2304 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2306 /* We don't bother removing existing processors not in nList, as this
2307 method will only be called when creating a Route from scratch, not
2308 for undo purposes. Just put processors in at the appropriate place
2312 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2313 add_processor_from_xml_2X (**i, version);
2318 Route::set_processor_state (const XMLNode& node)
2320 const XMLNodeList &nlist = node.children();
2321 XMLNodeConstIterator niter;
2322 ProcessorList new_order;
2323 bool must_configure = false;
2325 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2327 XMLProperty* prop = (*niter)->property ("type");
2329 if (prop->value() == "amp") {
2330 _amp->set_state (**niter, Stateful::current_state_version);
2331 new_order.push_back (_amp);
2332 } else if (prop->value() == "meter") {
2333 _meter->set_state (**niter, Stateful::current_state_version);
2334 new_order.push_back (_meter);
2335 } else if (prop->value() == "main-outs") {
2336 _main_outs->set_state (**niter, Stateful::current_state_version);
2337 new_order.push_back (_main_outs);
2338 } else if (prop->value() == "intreturn") {
2340 _intreturn.reset (new InternalReturn (_session));
2341 must_configure = true;
2343 _intreturn->set_state (**niter, Stateful::current_state_version);
2344 new_order.push_back (_intreturn);
2345 } else if (is_monitor() && prop->value() == "monitor") {
2346 if (!_monitor_control) {
2347 _monitor_control.reset (new MonitorProcessor (_session));
2348 must_configure = true;
2350 _monitor_control->set_state (**niter, Stateful::current_state_version);
2351 new_order.push_back (_monitor_control);
2353 ProcessorList::iterator o;
2355 for (o = _processors.begin(); o != _processors.end(); ++o) {
2356 XMLProperty* id_prop = (*niter)->property(X_("id"));
2357 if (id_prop && (*o)->id() == id_prop->value()) {
2358 (*o)->set_state (**niter, Stateful::current_state_version);
2359 new_order.push_back (*o);
2364 // If the processor (*niter) is not on the route then create it
2366 if (o == _processors.end()) {
2368 boost::shared_ptr<Processor> processor;
2370 if (prop->value() == "intsend") {
2372 processor.reset (new InternalSend (_session, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2374 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2375 prop->value() == "lv2" ||
2376 prop->value() == "vst" ||
2377 prop->value() == "audiounit") {
2379 processor.reset (new PluginInsert(_session));
2381 } else if (prop->value() == "port") {
2383 processor.reset (new PortInsert (_session, _mute_master));
2385 } else if (prop->value() == "send") {
2387 processor.reset (new Send (_session, _mute_master));
2390 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2394 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2395 /* This processor could not be configured. Turn it into a UnknownProcessor */
2396 processor.reset (new UnknownProcessor (_session, **niter));
2399 new_order.push_back (processor);
2400 must_configure = true;
2406 Glib::RWLock::WriterLock lm (_processor_lock);
2407 _processors = new_order;
2408 if (must_configure) {
2409 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2410 configure_processors_unlocked (0);
2414 processors_changed (RouteProcessorChange ());
2415 set_processor_positions ();
2419 Route::curve_reallocate ()
2421 // _gain_automation_curve.finish_resize ();
2422 // _pan_automation_curve.finish_resize ();
2426 Route::silence (framecnt_t nframes)
2428 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2433 silence_unlocked (nframes);
2437 Route::silence_unlocked (framecnt_t nframes)
2439 /* Must be called with the processor lock held */
2443 _output->silence (nframes);
2445 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2446 boost::shared_ptr<PluginInsert> pi;
2448 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2449 // skip plugins, they don't need anything when we're not active
2453 (*i)->silence (nframes);
2456 if (nframes == _session.get_block_size()) {
2463 Route::add_internal_return ()
2466 _intreturn.reset (new InternalReturn (_session));
2467 add_processor (_intreturn, PreFader);
2472 Route::get_return_buffer () const
2474 Glib::RWLock::ReaderLock rm (_processor_lock);
2476 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2477 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2480 BufferSet* bs = d->get_buffers ();
2489 Route::release_return_buffer () const
2491 Glib::RWLock::ReaderLock rm (_processor_lock);
2493 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2494 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2497 return d->release_buffers ();
2503 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2505 vector<string> ports;
2506 vector<string>::const_iterator i;
2509 Glib::RWLock::ReaderLock rm (_processor_lock);
2511 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2513 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2515 if (d && d->target_route() == route) {
2517 /* if the target is the control outs, then make sure
2518 we take note of which i-send is doing that.
2521 if (route == _session.monitor_out()) {
2522 _monitor_send = boost::dynamic_pointer_cast<Delivery>(d);
2525 /* already listening via the specified IO: do nothing */
2532 boost::shared_ptr<InternalSend> listener;
2538 if (route == _session.monitor_out()) {
2539 /* master never sends to control outs */
2542 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2546 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2549 } catch (failed_constructor& err) {
2553 if (route == _session.monitor_out()) {
2554 _monitor_send = listener;
2557 if (placement == PostFader) {
2558 /* put it *really* at the end, not just after the panner (main outs)
2560 add_processor (listener, _processors.end());
2562 add_processor (listener, PreFader);
2569 Route::drop_listen (boost::shared_ptr<Route> route)
2571 ProcessorStreams err;
2572 ProcessorList::iterator tmp;
2574 Glib::RWLock::ReaderLock rl(_processor_lock);
2578 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2580 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2582 if (d && d->target_route() == route) {
2584 remove_processor (*x, &err);
2587 /* list could have been demolished while we dropped the lock
2597 if (route == _session.monitor_out()) {
2598 _monitor_send.reset ();
2603 Route::set_comment (string cmt, void *src)
2606 comment_changed (src);
2607 _session.set_dirty ();
2611 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2613 FeedRecord fr (other, via_sends_only);
2615 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2617 if (!result.second) {
2619 /* already a record for "other" - make sure sends-only information is correct */
2620 if (!via_sends_only && result.first->sends_only) {
2621 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2622 frp->sends_only = false;
2626 return result.second;
2630 Route::clear_fed_by ()
2636 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2638 const FedBy& fed_by (other->fed_by());
2640 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2641 boost::shared_ptr<Route> sr = f->r.lock();
2643 if (sr && (sr.get() == this)) {
2645 if (via_sends_only) {
2646 *via_sends_only = f->sends_only;
2657 Route::direct_feeds (boost::shared_ptr<Route> other, bool* only_send)
2659 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2661 if (_output->connected_to (other->input())) {
2662 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2671 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2673 boost::shared_ptr<IOProcessor> iop;
2675 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2676 if (iop->feeds (other)) {
2677 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2683 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2686 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2691 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2695 /** Called from the (non-realtime) butler thread when the transport is stopped */
2697 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2699 framepos_t now = _session.transport_frame();
2702 Glib::RWLock::ReaderLock lm (_processor_lock);
2705 automation_snapshot (now, true);
2708 Automatable::transport_stopped (now);
2710 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2712 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2716 (*i)->transport_stopped (now);
2720 _roll_delay = _initial_delay;
2723 /** Called with the process lock held if change contains ConfigurationChanged */
2725 Route::input_change_handler (IOChange change, void * /*src*/)
2727 if ((change.type & IOChange::ConfigurationChanged)) {
2728 configure_processors (0);
2729 _phase_invert.resize (_input->n_ports().n_audio ());
2730 io_changed (); /* EMIT SIGNAL */
2734 /** Called with the process lock held if change contains ConfigurationChanged */
2736 Route::output_change_handler (IOChange change, void * /*src*/)
2738 if ((change.type & IOChange::ConfigurationChanged)) {
2740 /* XXX resize all listeners to match _main_outs? */
2742 /* Auto-connect newly-created outputs, unless we're auto-connecting to master
2743 and we are master (as an auto-connect in this situation would cause a
2746 AutoConnectOption ac = Config->get_output_auto_connect ();
2747 if (ac == AutoConnectPhysical || (ac == AutoConnectMaster && !is_master ())) {
2749 ChanCount start = change.before;
2751 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
2752 if (change.before.get(*i) < change.after.get(*i)) {
2753 /* the existing ChanCounts don't matter for this call as they are only
2754 to do with matching input and output indices, and we are only changing
2759 /* only auto-connect the newly-created outputs, not the ones that were
2762 start.set (*i, start.get (*i) + 1);
2764 _session.auto_connect_route (this, dummy, dummy, false, ChanCount(), change.before);
2769 // configure_processors (0);
2774 Route::pans_required () const
2776 if (n_outputs().n_audio() < 2) {
2780 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2784 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
2785 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2787 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2792 if (n_outputs().n_total() == 0) {
2796 if (!_active || n_inputs() == ChanCount::ZERO) {
2797 silence_unlocked (nframes);
2800 if (session_state_changing) {
2801 if (_session.transport_speed() != 0.0f) {
2802 /* we're rolling but some state is changing (e.g. our diskstream contents)
2803 so we cannot use them. Be silent till this is over.
2805 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2807 silence_unlocked (nframes);
2810 /* we're really not rolling, so we're either delivery silence or actually
2811 monitoring, both of which are safe to do while session_state_changing is true.
2815 _amp->apply_gain_automation (false);
2816 passthru (start_frame, end_frame, nframes, 0);
2822 Route::check_initial_delay (framecnt_t nframes, framecnt_t& transport_frame)
2824 if (_roll_delay > nframes) {
2826 _roll_delay -= nframes;
2827 silence_unlocked (nframes);
2828 /* transport frame is not legal for caller to use */
2831 } else if (_roll_delay > 0) {
2833 nframes -= _roll_delay;
2834 silence_unlocked (_roll_delay);
2835 /* we've written _roll_delay of samples into the
2836 output ports, so make a note of that for
2839 _main_outs->increment_output_offset (_roll_delay);
2840 transport_frame += _roll_delay;
2849 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick,
2850 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2852 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2857 automation_snapshot (_session.transport_frame(), false);
2859 if (n_outputs().n_total() == 0) {
2863 if (!_active || n_inputs().n_total() == 0) {
2864 silence_unlocked (nframes);
2868 framecnt_t unused = 0;
2870 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2876 passthru (start_frame, end_frame, nframes, declick);
2882 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/,
2883 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2890 Route::toggle_monitor_input ()
2892 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2893 i->ensure_monitor_input( ! i->monitoring_input());
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 if (p != MeterCustom) {
2954 // Move meter in the processors list to reflect the new position
2955 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2956 _processors.erase(loc);
2959 loc = _processors.begin();
2962 loc = find (_processors.begin(), _processors.end(), _amp);
2964 case MeterPostFader:
2965 loc = _processors.end();
2973 if (loc == _processors.begin()) {
2974 m_in = _input->n_ports();
2976 ProcessorList::iterator before = loc;
2978 m_in = (*before)->output_streams ();
2981 _meter->reflect_inputs (m_in);
2983 _processors.insert (loc, _meter);
2985 /* we do not need to reconfigure the processors, because the meter
2986 (a) is always ready to handle processor_max_streams
2987 (b) is always an N-in/N-out processor, and thus moving
2988 it doesn't require any changes to the other processors.
2991 _meter->set_display_to_user (false);
2995 // just make it visible and let the user move it
2997 _meter->set_display_to_user (true);
3002 meter_change (); /* EMIT SIGNAL */
3004 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3006 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3010 Route::put_monitor_send_at (Placement p)
3012 if (!_monitor_send) {
3017 Glib::RWLock::WriterLock lm (_processor_lock);
3018 ProcessorList as_it_was (_processors);
3019 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _monitor_send);
3020 _processors.erase(loc);
3024 loc = find(_processors.begin(), _processors.end(), _amp);
3025 if (loc != _processors.begin()) {
3030 loc = _processors.end();
3034 _processors.insert (loc, _monitor_send);
3037 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3039 if (configure_processors_unlocked (0)) {
3040 _processors = as_it_was;
3041 configure_processors_unlocked (0); // it worked before we tried to add it ...
3047 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3048 _session.set_dirty ();
3052 Route::update_total_latency ()
3054 framecnt_t old = _output->effective_latency();
3055 framecnt_t own_latency = _output->user_latency();
3057 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3058 if ((*i)->active ()) {
3059 own_latency += (*i)->signal_latency ();
3063 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
3065 _output->set_port_latency (own_latency);
3067 if (_output->user_latency() == 0) {
3069 /* this (virtual) function is used for pure Routes,
3070 not derived classes like AudioTrack. this means
3071 that the data processed here comes from an input
3072 port, not prerecorded material, and therefore we
3073 have to take into account any input latency.
3076 own_latency += _input->signal_latency ();
3079 if (old != own_latency) {
3080 _output->set_latency_delay (own_latency);
3081 signal_latency_changed (); /* EMIT SIGNAL */
3084 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
3086 return _output->effective_latency ();
3090 Route::set_user_latency (framecnt_t nframes)
3092 _output->set_user_latency (nframes);
3093 _session.update_latency_compensation (false, false);
3097 Route::set_latency_delay (framecnt_t longest_session_latency)
3099 framecnt_t old = _initial_delay;
3101 if (_output->effective_latency() < longest_session_latency) {
3102 _initial_delay = longest_session_latency - _output->effective_latency();
3107 if (_initial_delay != old) {
3108 initial_delay_changed (); /* EMIT SIGNAL */
3111 if (_session.transport_stopped()) {
3112 _roll_delay = _initial_delay;
3117 Route::automation_snapshot (framepos_t now, bool force)
3119 panner()->automation_snapshot (now, force);
3121 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3122 (*i)->automation_snapshot (now, force);
3126 Route::SoloControllable::SoloControllable (std::string name, Route& r)
3127 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
3128 boost::shared_ptr<AutomationList>(), name)
3131 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3136 Route::SoloControllable::set_value (double val)
3138 bool bval = ((val >= 0.5f) ? true: false);
3140 this is how it should be done
3142 boost::shared_ptr<RouteList> rl (new RouteList);
3143 rl->push_back (route);
3145 if (Config->get_solo_control_is_listen_control()) {
3146 _session.set_listen (rl, bval);
3148 _session.set_solo (rl, bval);
3151 route.set_solo (bval, this);
3156 Route::SoloControllable::get_value (void) const
3158 if (Config->get_solo_control_is_listen_control()) {
3159 return route.listening() ? 1.0f : 0.0f;
3161 return route.self_soloed() ? 1.0f : 0.0f;
3165 Route::MuteControllable::MuteControllable (std::string name, Route& r)
3166 : AutomationControl (r.session(), Evoral::Parameter (MuteAutomation),
3167 boost::shared_ptr<AutomationList>(), name)
3170 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3175 Route::MuteControllable::set_value (double val)
3177 bool bval = ((val >= 0.5f) ? true: false);
3179 this is how it should be done
3181 boost::shared_ptr<RouteList> rl (new RouteList);
3182 rl->push_back (route);
3183 _session.set_mute (rl, bval);
3185 route.set_mute (bval, this);
3190 Route::MuteControllable::get_value (void) const
3192 return route.muted() ? 1.0f : 0.0f;
3196 Route::set_block_size (pframes_t nframes)
3198 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3199 (*i)->set_block_size (nframes);
3202 _session.ensure_buffers (n_process_buffers ());
3206 Route::protect_automation ()
3208 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3209 (*i)->protect_automation();
3213 Route::set_pending_declick (int declick)
3216 /* this call is not allowed to turn off a pending declick unless "force" is true */
3218 _pending_declick = declick;
3220 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3222 _pending_declick = 0;
3227 /** Shift automation forwards from a particular place, thereby inserting time.
3228 * Adds undo commands for any shifts that are performed.
3230 * @param pos Position to start shifting from.
3231 * @param frames Amount to shift forwards by.
3235 Route::shift (framepos_t pos, framecnt_t frames)
3237 /* gain automation */
3239 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3241 XMLNode &before = gc->alist()->get_state ();
3242 gc->alist()->shift (pos, frames);
3243 XMLNode &after = gc->alist()->get_state ();
3244 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3247 /* pan automation */
3249 boost::shared_ptr<AutomationControl> pc;
3250 uint32_t npans = _main_outs->panner()->npanners();
3252 for (uint32_t p = 0; p < npans; ++p) {
3253 pc = _main_outs->panner()->pan_control (0, p);
3255 boost::shared_ptr<AutomationList> al = pc->alist();
3256 XMLNode& before = al->get_state ();
3257 al->shift (pos, frames);
3258 XMLNode& after = al->get_state ();
3259 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3264 /* redirect automation */
3266 Glib::RWLock::ReaderLock lm (_processor_lock);
3267 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3269 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3271 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3272 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3274 boost::shared_ptr<AutomationList> al = ac->alist();
3275 XMLNode &before = al->get_state ();
3276 al->shift (pos, frames);
3277 XMLNode &after = al->get_state ();
3278 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3287 Route::save_as_template (const string& path, const string& name)
3289 XMLNode& node (state (false));
3292 IO::set_name_in_state (*node.children().front(), name);
3294 tree.set_root (&node);
3295 return tree.write (path.c_str());
3300 Route::set_name (const string& str)
3306 name = Route::ensure_track_or_route_name (str, _session);
3307 SessionObject::set_name (name);
3309 ret = (_input->set_name(name) && _output->set_name(name));
3313 Glib::RWLock::ReaderLock lm (_processor_lock);
3315 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3317 /* rename all I/O processors that have inputs or outputs */
3319 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3321 if (iop && (iop->output() || iop->input())) {
3322 if (!iop->set_name (name)) {
3333 boost::shared_ptr<Send>
3334 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3336 Glib::RWLock::ReaderLock lm (_processor_lock);
3338 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3339 boost::shared_ptr<InternalSend> send;
3341 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3342 if (send->target_route() == target) {
3348 return boost::shared_ptr<Send>();
3351 /** @param c Audio channel index.
3352 * @param yn true to invert phase, otherwise false.
3355 Route::set_phase_invert (uint32_t c, bool yn)
3357 if (_phase_invert[c] != yn) {
3358 _phase_invert[c] = yn;
3359 phase_invert_changed (); /* EMIT SIGNAL */
3360 _session.set_dirty ();
3365 Route::set_phase_invert (boost::dynamic_bitset<> p)
3367 if (_phase_invert != p) {
3369 phase_invert_changed (); /* EMIT SIGNAL */
3370 _session.set_dirty ();
3375 Route::phase_invert (uint32_t c) const
3377 return _phase_invert[c];
3380 boost::dynamic_bitset<>
3381 Route::phase_invert () const
3383 return _phase_invert;
3387 Route::set_denormal_protection (bool yn)
3389 if (_denormal_protection != yn) {
3390 _denormal_protection = yn;
3391 denormal_protection_changed (); /* EMIT SIGNAL */
3396 Route::denormal_protection () const
3398 return _denormal_protection;
3402 Route::set_active (bool yn)
3404 if (_active != yn) {
3406 _input->set_active (yn);
3407 _output->set_active (yn);
3408 active_changed (); // EMIT SIGNAL
3415 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3421 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3423 boost::shared_ptr<Send> s;
3424 boost::shared_ptr<Return> r;
3426 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3427 s->meter()->meter();
3428 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3429 r->meter()->meter ();
3434 boost::shared_ptr<Panner>
3435 Route::panner() const
3437 return _main_outs->panner();
3440 boost::shared_ptr<AutomationControl>
3441 Route::gain_control() const
3443 return _amp->gain_control();
3446 boost::shared_ptr<AutomationControl>
3447 Route::get_control (const Evoral::Parameter& param)
3449 /* either we own the control or .... */
3451 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3455 /* maybe one of our processors does or ... */
3457 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3458 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3459 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3467 /* nobody does so we'll make a new one */
3469 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3476 boost::shared_ptr<Processor>
3477 Route::nth_plugin (uint32_t n)
3479 Glib::RWLock::ReaderLock lm (_processor_lock);
3480 ProcessorList::iterator i;
3482 for (i = _processors.begin(); i != _processors.end(); ++i) {
3483 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3490 return boost::shared_ptr<Processor> ();
3493 boost::shared_ptr<Processor>
3494 Route::nth_send (uint32_t n)
3496 Glib::RWLock::ReaderLock lm (_processor_lock);
3497 ProcessorList::iterator i;
3499 for (i = _processors.begin(); i != _processors.end(); ++i) {
3500 if (boost::dynamic_pointer_cast<Send> (*i)) {
3507 return boost::shared_ptr<Processor> ();
3511 Route::has_io_processor_named (const string& name)
3513 Glib::RWLock::ReaderLock lm (_processor_lock);
3514 ProcessorList::iterator i;
3516 for (i = _processors.begin(); i != _processors.end(); ++i) {
3517 if (boost::dynamic_pointer_cast<Send> (*i) ||
3518 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3519 if ((*i)->name() == name) {
3528 MuteMaster::MutePoint
3529 Route::mute_points () const
3531 return _mute_master->mute_points ();
3535 Route::set_processor_positions ()
3537 Glib::RWLock::ReaderLock lm (_processor_lock);
3539 bool had_amp = false;
3540 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3541 (*i)->set_pre_fader (!had_amp);
3542 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3548 /** Called when there is a proposed change to the input port count */
3550 Route::input_port_count_changing (ChanCount to)
3552 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3554 /* The processors cannot be configured with the new input arrangement, so
3560 /* The change is ok */
3565 Route::unknown_processors () const
3569 Glib::RWLock::ReaderLock lm (_processor_lock);
3570 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3571 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3572 p.push_back ((*i)->name ());