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/graph.h"
69 #include "ardour/unknown_processor.h"
70 #include "ardour/capturing_processor.h"
75 using namespace ARDOUR;
78 uint32_t Route::order_key_cnt = 0;
79 PBD::Signal1<void,string const&> Route::SyncOrderKeys;
80 PBD::Signal0<void> Route::RemoteControlIDChange;
82 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
83 : SessionObject (sess, name)
85 , GraphNode( sess.route_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 , _solo_control (new SoloControllable (X_("solo"), *this))
101 , _mute_control (new MuteControllable (X_("mute"), *this))
102 , _mute_master (new MuteMaster (sess, name))
103 , _have_internal_generator (false)
105 , _default_type (default_type)
106 , _remote_control_id (0)
107 , _in_configure_processors (false)
109 processor_max_streams.reset();
110 order_keys[N_("signal")] = order_key_cnt++;
116 /* add standard controls */
118 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
119 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
121 add_control (_solo_control);
122 add_control (_mute_control);
126 Pannable* p = new Pannable (_session);
127 #ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
128 boost_debug_shared_ptr_mark_interesting (p, "Pannable");
132 /* input and output objects */
134 _input.reset (new IO (_session, _name, IO::Input, _default_type));
135 _output.reset (new IO (_session, _name, IO::Output, _default_type));
137 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
138 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
140 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
142 /* add amp processor */
144 _amp.reset (new Amp (_session));
145 add_processor (_amp, PostFader);
147 /* add standard processors: meter, main outs, monitor out */
149 _meter.reset (new PeakMeter (_session));
150 _meter->set_display_to_user (false);
152 add_processor (_meter, PostFader);
154 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
156 add_processor (_main_outs, PostFader);
159 /* where we listen to tracks */
160 _intreturn.reset (new InternalReturn (_session));
161 add_processor (_intreturn, PreFader);
163 ProcessorList::iterator i;
165 for (i = _processors.begin(); i != _processors.end(); ++i) {
166 if (*i == _intreturn) {
172 /* the thing that provides proper control over a control/monitor/listen bus
173 (such as per-channel cut, dim, solo, invert, etc).
174 It always goes right after the internal return;
176 _monitor_control.reset (new MonitorProcessor (_session));
177 add_processor (_monitor_control, i);
179 /* no panning on the monitor main outs */
182 _main_outs->panner()->set_bypassed (true);
186 if (is_master() || is_monitor() || is_hidden()) {
187 _mute_master->set_solo_ignore (true);
190 /* now that we have _meter, its safe to connect to this */
192 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
199 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
201 /* do this early so that we don't get incoming signals as we are going through destruction
206 /* don't use clear_processors here, as it depends on the session which may
207 be half-destroyed by now
210 Glib::RWLock::WriterLock lm (_processor_lock);
211 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
212 (*i)->drop_references ();
215 _processors.clear ();
219 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
221 if (id != _remote_control_id) {
222 _remote_control_id = id;
223 RemoteControlIDChanged ();
224 if (notify_class_listeners) {
225 RemoteControlIDChange ();
231 Route::remote_control_id() const
233 return _remote_control_id;
237 Route::order_key (std::string const & name) const
239 OrderKeys::const_iterator i = order_keys.find (name);
240 if (i == order_keys.end()) {
248 Route::set_order_key (std::string const & name, int32_t n)
250 bool changed = false;
252 /* This method looks more complicated than it should, but
253 it's important that we don't emit order_key_changed unless
254 it actually has, as expensive things happen on receipt of that
258 if (order_keys.find(name) == order_keys.end() || order_keys[name] != n) {
259 order_keys[name] = n;
263 if (Config->get_sync_all_route_ordering()) {
264 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
265 if (x->second != n) {
273 order_key_changed (); /* EMIT SIGNAL */
274 _session.set_dirty ();
278 /** Set all order keys to be the same as that for `base', if such a key
279 * exists in this route.
280 * @param base Base key.
283 Route::sync_order_keys (std::string const & base)
285 if (order_keys.empty()) {
289 OrderKeys::iterator i;
292 if ((i = order_keys.find (base)) == order_keys.end()) {
293 /* key doesn't exist, use the first existing key (during session initialization) */
294 i = order_keys.begin();
298 /* key exists - use it and reset all others (actually, itself included) */
300 i = order_keys.begin();
303 bool changed = false;
305 for (; i != order_keys.end(); ++i) {
306 if (i->second != key) {
313 order_key_changed (); /* EMIT SIGNAL */
318 Route::ensure_track_or_route_name(string name, Session &session)
320 string newname = name;
322 while (!session.io_name_is_legal (newname)) {
323 newname = bump_name_once (newname, '.');
331 Route::inc_gain (gain_t fraction, void *src)
333 _amp->inc_gain (fraction, src);
337 Route::set_gain (gain_t val, void *src)
339 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
341 if (_route_group->is_relative()) {
343 gain_t usable_gain = _amp->gain();
344 if (usable_gain < 0.000001f) {
345 usable_gain = 0.000001f;
349 if (delta < 0.000001f) {
353 delta -= usable_gain;
358 gain_t factor = delta / usable_gain;
361 factor = _route_group->get_max_factor(factor);
362 if (factor == 0.0f) {
363 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
367 factor = _route_group->get_min_factor(factor);
368 if (factor == 0.0f) {
369 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
374 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
378 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
384 if (val == _amp->gain()) {
388 _amp->set_gain (val, src);
391 /** Process this route for one (sub) cycle (process thread)
393 * @param bufs Scratch buffers to use for the signal path
394 * @param start_frame Initial transport frame
395 * @param end_frame Final transport frame
396 * @param nframes Number of frames to output (to ports)
398 * Note that (end_frame - start_frame) may not be equal to nframes when the
399 * transport speed isn't 1.0 (eg varispeed).
402 Route::process_output_buffers (BufferSet& bufs,
403 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
404 bool /*with_processors*/, int declick,
405 bool gain_automation_ok)
409 bufs.is_silent (false);
411 switch (Config->get_monitoring_model()) {
412 case HardwareMonitoring:
413 case ExternalMonitoring:
414 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
421 declick = _pending_declick;
424 /* figure out if we're going to use gain automation */
425 if (gain_automation_ok) {
426 _amp->setup_gain_automation (start_frame, end_frame, nframes);
428 _amp->apply_gain_automation (false);
431 /* tell main outs what to do about monitoring */
432 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
435 /* -------------------------------------------------------------------------------------------
436 GLOBAL DECLICK (for transport changes etc.)
437 ----------------------------------------------------------------------------------------- */
440 Amp::declick (bufs, nframes, 1);
441 } else if (declick < 0) {
442 Amp::declick (bufs, nframes, -1);
445 _pending_declick = 0;
447 /* -------------------------------------------------------------------------------------------
448 DENORMAL CONTROL/PHASE INVERT
449 ----------------------------------------------------------------------------------------- */
451 if (_phase_invert.any ()) {
455 if (_denormal_protection || Config->get_denormal_protection()) {
457 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
458 Sample* const sp = i->data();
460 if (_phase_invert[chn]) {
461 for (pframes_t nx = 0; nx < nframes; ++nx) {
466 for (pframes_t nx = 0; nx < nframes; ++nx) {
474 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
475 Sample* const sp = i->data();
477 if (_phase_invert[chn]) {
478 for (pframes_t nx = 0; nx < nframes; ++nx) {
487 if (_denormal_protection || Config->get_denormal_protection()) {
489 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
490 Sample* const sp = i->data();
491 for (pframes_t nx = 0; nx < nframes; ++nx) {
499 /* -------------------------------------------------------------------------------------------
501 ----------------------------------------------------------------------------------------- */
503 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
505 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i)) {
509 if (bufs.count() != (*i)->input_streams()) {
510 cerr << _name << " bufs = " << bufs.count()
511 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
514 assert (bufs.count() == (*i)->input_streams());
516 /* should we NOT run plugins here if the route is inactive?
517 do we catch route != active somewhere higher?
520 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
521 bufs.set_count ((*i)->output_streams());
526 Route::n_process_buffers ()
528 return max (_input->n_ports(), processor_max_streams);
532 Route::passthru (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
534 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
538 assert (bufs.available() >= input_streams());
540 if (_input->n_ports() == ChanCount::ZERO) {
541 silence_unlocked (nframes);
544 bufs.set_count (input_streams());
546 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
548 /* control/monitor bus ignores input ports when something is
549 feeding the listen "stream". data will "arrive" into the
550 route from the intreturn processor element.
552 bufs.silence (nframes, 0);
556 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
558 BufferSet::iterator o = bufs.begin(*t);
559 PortSet& ports (_input->ports());
561 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
562 o->read_from (i->get_buffer(nframes), nframes);
567 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
568 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick, true);
572 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
574 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
575 bufs.set_count (_input->n_ports());
576 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
577 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick, false);
581 Route::set_listen (bool yn, void* src)
588 if (yn != _monitor_send->active()) {
590 _monitor_send->activate ();
591 _mute_master->set_soloed (true);
593 _monitor_send->deactivate ();
594 _mute_master->set_soloed (false);
597 listen_changed (src); /* EMIT SIGNAL */
603 Route::listening () const
606 return _monitor_send->active ();
613 Route::set_solo_safe (bool yn, void *src)
615 if (_solo_safe != yn) {
617 solo_safe_changed (src);
622 Route::solo_safe() const
628 Route::set_solo (bool yn, void *src)
634 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
635 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
639 if (self_soloed() != yn) {
641 set_mute_master_solo ();
642 solo_changed (true, src); /* EMIT SIGNAL */
643 _solo_control->Changed (); /* EMIT SIGNAL */
648 Route::set_self_solo (bool yn)
654 Route::mod_solo_by_others_upstream (int32_t delta)
660 uint32_t old_sbu = _soloed_by_others_upstream;
663 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
664 _soloed_by_others_upstream += delta;
666 _soloed_by_others_upstream = 0;
669 _soloed_by_others_upstream += delta;
672 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
673 name(), delta, _soloed_by_others_upstream, old_sbu,
674 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
676 /* push the inverse solo change to everything that feeds us.
678 This is important for solo-within-group. When we solo 1 track out of N that
679 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
680 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
681 tracks that feed it. This will silence them if they were audible because
682 of a bus solo, but the newly soloed track will still be audible (because
685 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
689 if ((_self_solo || _soloed_by_others_downstream) &&
690 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
691 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
693 if (delta > 0 || !Config->get_exclusive_solo()) {
694 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
695 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
696 boost::shared_ptr<Route> sr = i->r.lock();
698 sr->mod_solo_by_others_downstream (-delta);
704 set_mute_master_solo ();
705 solo_changed (false, this);
709 Route::mod_solo_by_others_downstream (int32_t delta)
716 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
717 _soloed_by_others_downstream += delta;
719 _soloed_by_others_downstream = 0;
722 _soloed_by_others_downstream += delta;
725 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
727 set_mute_master_solo ();
728 solo_changed (false, this);
732 Route::set_mute_master_solo ()
734 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
738 Route::set_solo_isolated (bool yn, void *src)
740 if (is_master() || is_monitor() || is_hidden()) {
744 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
745 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
749 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
751 boost::shared_ptr<RouteList> routes = _session.get_routes ();
752 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
754 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
759 bool does_feed = direct_feeds (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
761 if (does_feed && !sends_only) {
762 (*i)->set_solo_isolated (yn, (*i)->route_group());
766 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
768 bool changed = false;
771 if (_solo_isolated == 0) {
772 _mute_master->set_solo_ignore (true);
777 if (_solo_isolated > 0) {
779 if (_solo_isolated == 0) {
780 _mute_master->set_solo_ignore (false);
787 solo_isolated_changed (src);
792 Route::solo_isolated () const
794 return _solo_isolated > 0;
798 Route::set_mute_points (MuteMaster::MutePoint mp)
800 _mute_master->set_mute_points (mp);
801 mute_points_changed (); /* EMIT SIGNAL */
803 if (_mute_master->muted_by_self()) {
804 mute_changed (this); /* EMIT SIGNAL */
805 _mute_control->Changed (); /* EMIT SIGNAL */
810 Route::set_mute (bool yn, void *src)
812 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
813 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
818 _mute_master->set_muted_by_self (yn);
819 mute_changed (src); /* EMIT SIGNAL */
820 _mute_control->Changed (); /* EMIT SIGNAL */
825 Route::muted () const
827 return _mute_master->muted_by_self();
832 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
834 cerr << name << " {" << endl;
835 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
836 p != procs.end(); ++p) {
837 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
844 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
846 ProcessorList::iterator loc;
848 /* XXX this is not thread safe - we don't hold the lock across determining the iter
849 to add before and actually doing the insertion. dammit.
852 if (placement == PreFader) {
853 /* generic pre-fader: insert immediately before the amp */
854 loc = find (_processors.begin(), _processors.end(), _amp);
856 /* generic post-fader: insert right before the main outs */
857 loc = find (_processors.begin(), _processors.end(), _main_outs);
860 return add_processor (processor, loc, err);
864 /** Add a processor to the route.
865 * @a iter must point to an iterator in _processors and the new
866 * processor will be inserted immediately before this location. Otherwise,
867 * @a position is used.
870 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
872 ChanCount old_pms = processor_max_streams;
874 if (!_session.engine().connected() || !processor) {
879 Glib::RWLock::WriterLock lm (_processor_lock);
881 boost::shared_ptr<PluginInsert> pi;
882 boost::shared_ptr<PortInsert> porti;
884 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
886 if (processor == _amp || processor == _meter || processor == _main_outs) {
887 // Ensure only one of these are in the list at any time
888 if (loc != _processors.end()) {
889 if (iter == loc) { // Already in place, do nothing
891 } else { // New position given, relocate
892 _processors.erase (loc);
897 if (loc != _processors.end()) {
898 cerr << "ERROR: Processor added to route twice!" << endl;
905 _processors.insert (loc, processor);
907 // Set up processor list channels. This will set processor->[input|output]_streams(),
908 // configure redirect ports properly, etc.
911 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
913 if (configure_processors_unlocked (err)) {
914 ProcessorList::iterator ploc = loc;
916 _processors.erase(ploc);
917 configure_processors_unlocked (0); // it worked before we tried to add it ...
918 cerr << "configure failed\n";
923 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
925 if (pi->natural_input_streams() == ChanCount::ZERO) {
926 /* generator plugin */
927 _have_internal_generator = true;
932 /* is this the monitor send ? if so, make sure we keep track of it */
934 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
936 if (isend && _session.monitor_out() && (isend->target_id() == _session.monitor_out()->id())) {
937 _monitor_send = isend;
940 if (activation_allowed && (processor != _monitor_send)) {
941 processor->activate ();
944 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
946 _output->set_user_latency (0);
949 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
950 set_processor_positions ();
956 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
958 const XMLProperty *prop;
961 boost::shared_ptr<Processor> processor;
963 /* bit of a hack: get the `placement' property from the <Redirect> tag here
964 so that we can add the processor in the right place (pre/post-fader)
967 XMLNodeList const & children = node.children ();
968 XMLNodeList::const_iterator i = children.begin ();
970 while (i != children.end() && (*i)->name() != X_("Redirect")) {
974 Placement placement = PreFader;
976 if (i != children.end()) {
977 if ((prop = (*i)->property (X_("placement"))) != 0) {
978 placement = Placement (string_2_enum (prop->value(), placement));
982 if (node.name() == "Insert") {
984 if ((prop = node.property ("type")) != 0) {
986 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
987 prop->value() == "lv2" ||
988 prop->value() == "vst" ||
989 prop->value() == "audiounit") {
991 processor.reset (new PluginInsert (_session));
995 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1000 } else if (node.name() == "Send") {
1002 processor.reset (new Send (_session, _pannable, _mute_master));
1006 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1010 if (processor->set_state (node, version)) {
1014 return (add_processor (processor, placement) == 0);
1017 catch (failed_constructor &err) {
1018 warning << _("processor could not be created. Ignored.") << endmsg;
1024 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1026 /* NOTE: this is intended to be used ONLY when copying
1027 processors from another Route. Hence the subtle
1028 differences between this and ::add_processor()
1031 ProcessorList::iterator loc;
1034 loc = find(_processors.begin(), _processors.end(), before);
1036 /* nothing specified - at end but before main outs */
1037 loc = find (_processors.begin(), _processors.end(), _main_outs);
1040 ChanCount old_pms = processor_max_streams;
1042 if (!_session.engine().connected()) {
1046 if (others.empty()) {
1051 Glib::RWLock::WriterLock lm (_processor_lock);
1053 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
1055 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1057 // Ensure meter only appears in the list once
1059 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
1060 if (m != _processors.end()) {
1061 _processors.erase(m);
1065 boost::shared_ptr<PluginInsert> pi;
1067 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1070 ChanCount m = max (pi->input_streams(), pi->output_streams());
1072 if (m > potential_max_streams) {
1073 potential_max_streams = m;
1077 ProcessorList::iterator inserted = _processors.insert (loc, *i);
1079 if ((*i)->active()) {
1084 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1085 if (configure_processors_unlocked (err)) {
1086 _processors.erase (inserted);
1087 configure_processors_unlocked (0); // it worked before we tried to add it ...
1092 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
1095 _output->set_user_latency (0);
1098 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1099 set_processor_positions ();
1105 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1107 if (p == PreFader) {
1108 start = _processors.begin();
1109 end = find(_processors.begin(), _processors.end(), _amp);
1111 start = find(_processors.begin(), _processors.end(), _amp);
1113 end = _processors.end();
1117 /** Turn off all processors with a given placement
1118 * @param p Placement of processors to disable
1121 Route::disable_processors (Placement p)
1123 Glib::RWLock::ReaderLock lm (_processor_lock);
1125 ProcessorList::iterator start, end;
1126 placement_range(p, start, end);
1128 for (ProcessorList::iterator i = start; i != end; ++i) {
1129 (*i)->deactivate ();
1132 _session.set_dirty ();
1135 /** Turn off all redirects
1138 Route::disable_processors ()
1140 Glib::RWLock::ReaderLock lm (_processor_lock);
1142 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1143 (*i)->deactivate ();
1146 _session.set_dirty ();
1149 /** Turn off all redirects with a given placement
1150 * @param p Placement of redirects to disable
1153 Route::disable_plugins (Placement p)
1155 Glib::RWLock::ReaderLock lm (_processor_lock);
1157 ProcessorList::iterator start, end;
1158 placement_range(p, start, end);
1160 for (ProcessorList::iterator i = start; i != end; ++i) {
1161 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1162 (*i)->deactivate ();
1166 _session.set_dirty ();
1169 /** Turn off all plugins
1172 Route::disable_plugins ()
1174 Glib::RWLock::ReaderLock lm (_processor_lock);
1176 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1177 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1178 (*i)->deactivate ();
1182 _session.set_dirty ();
1187 Route::ab_plugins (bool forward)
1189 Glib::RWLock::ReaderLock lm (_processor_lock);
1193 /* forward = turn off all active redirects, and mark them so that the next time
1194 we go the other way, we will revert them
1197 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1198 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1202 if ((*i)->active()) {
1203 (*i)->deactivate ();
1204 (*i)->set_next_ab_is_active (true);
1206 (*i)->set_next_ab_is_active (false);
1212 /* backward = if the redirect was marked to go active on the next ab, do so */
1214 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1216 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1220 if ((*i)->get_next_ab_is_active()) {
1223 (*i)->deactivate ();
1228 _session.set_dirty ();
1232 /** Remove processors with a given placement.
1233 * @param p Placement of processors to remove.
1236 Route::clear_processors (Placement p)
1238 const ChanCount old_pms = processor_max_streams;
1240 if (!_session.engine().connected()) {
1244 bool already_deleting = _session.deletion_in_progress();
1245 if (!already_deleting) {
1246 _session.set_deletion_in_progress();
1250 Glib::RWLock::WriterLock lm (_processor_lock);
1251 ProcessorList new_list;
1252 ProcessorStreams err;
1253 bool seen_amp = false;
1255 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1261 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1263 /* you can't remove these */
1265 new_list.push_back (*i);
1272 new_list.push_back (*i);
1275 (*i)->drop_references ();
1283 (*i)->drop_references ();
1286 new_list.push_back (*i);
1293 _processors = new_list;
1296 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1297 configure_processors_unlocked (&err); // this can't fail
1301 processor_max_streams.reset();
1302 _have_internal_generator = false;
1303 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1304 set_processor_positions ();
1306 if (!already_deleting) {
1307 _session.clear_deletion_in_progress();
1312 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1314 /* these can never be removed */
1316 if (processor == _amp || processor == _meter || processor == _main_outs) {
1320 ChanCount old_pms = processor_max_streams;
1322 if (!_session.engine().connected()) {
1326 processor_max_streams.reset();
1329 Glib::RWLock::WriterLock lm (_processor_lock);
1330 ProcessorList::iterator i;
1331 bool removed = false;
1333 for (i = _processors.begin(); i != _processors.end(); ) {
1334 if (*i == processor) {
1336 /* move along, see failure case for configure_processors()
1337 where we may need to reconfigure the processor.
1340 /* stop redirects that send signals to JACK ports
1341 from causing noise as a result of no longer being
1345 boost::shared_ptr<IOProcessor> iop;
1347 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1349 iop->input()->disconnect (this);
1351 if (iop->output()) {
1352 iop->output()->disconnect (this);
1356 i = _processors.erase (i);
1364 _output->set_user_latency (0);
1373 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1375 if (configure_processors_unlocked (err)) {
1376 /* get back to where we where */
1377 _processors.insert (i, processor);
1378 /* we know this will work, because it worked before :) */
1379 configure_processors_unlocked (0);
1384 _have_internal_generator = false;
1386 for (i = _processors.begin(); i != _processors.end(); ++i) {
1387 boost::shared_ptr<PluginInsert> pi;
1389 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1390 if (pi->is_generator()) {
1391 _have_internal_generator = true;
1398 processor->drop_references ();
1399 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1400 set_processor_positions ();
1406 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1408 ProcessorList deleted;
1410 if (!_session.engine().connected()) {
1414 processor_max_streams.reset();
1417 Glib::RWLock::WriterLock lm (_processor_lock);
1418 ProcessorList::iterator i;
1419 boost::shared_ptr<Processor> processor;
1421 ProcessorList as_we_were = _processors;
1423 for (i = _processors.begin(); i != _processors.end(); ) {
1427 /* these can never be removed */
1429 if (processor == _amp || processor == _meter || processor == _main_outs) {
1434 /* see if its in the list of processors to delete */
1436 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1441 /* stop IOProcessors that send to JACK ports
1442 from causing noise as a result of no longer being
1446 boost::shared_ptr<IOProcessor> iop;
1448 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1452 deleted.push_back (processor);
1453 i = _processors.erase (i);
1456 if (deleted.empty()) {
1457 /* none of those in the requested list were found */
1461 _output->set_user_latency (0);
1464 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1466 if (configure_processors_unlocked (err)) {
1467 /* get back to where we where */
1468 _processors = as_we_were;
1469 /* we know this will work, because it worked before :) */
1470 configure_processors_unlocked (0);
1475 _have_internal_generator = false;
1477 for (i = _processors.begin(); i != _processors.end(); ++i) {
1478 boost::shared_ptr<PluginInsert> pi;
1480 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1481 if (pi->is_generator()) {
1482 _have_internal_generator = true;
1489 /* now try to do what we need to so that those that were removed will be deleted */
1491 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1492 (*i)->drop_references ();
1495 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1496 set_processor_positions ();
1501 /** Caller must hold process lock */
1503 Route::configure_processors (ProcessorStreams* err)
1505 assert (!AudioEngine::instance()->process_lock().trylock());
1507 if (!_in_configure_processors) {
1508 Glib::RWLock::WriterLock lm (_processor_lock);
1509 return configure_processors_unlocked (err);
1515 Route::input_streams () const
1517 return _input->n_ports ();
1520 list<pair<ChanCount, ChanCount> >
1521 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1523 Glib::RWLock::ReaderLock lm (_processor_lock);
1525 return try_configure_processors_unlocked (in, err);
1528 list<pair<ChanCount, ChanCount> >
1529 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1531 // Check each processor in order to see if we can configure as requested
1533 list<pair<ChanCount, ChanCount> > configuration;
1536 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1537 DEBUG_TRACE (DEBUG::Processors, "{\n");
1539 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1541 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1542 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1546 if ((*p)->can_support_io_configuration(in, out)) {
1547 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1548 configuration.push_back(make_pair(in, out));
1555 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1556 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1557 DEBUG_TRACE (DEBUG::Processors, "}\n");
1558 return list<pair<ChanCount, ChanCount> > ();
1562 DEBUG_TRACE (DEBUG::Processors, "}\n");
1564 return configuration;
1567 /** Set the input/output configuration of each processor in the processors list.
1568 * Caller must hold process lock.
1569 * Return 0 on success, otherwise configuration is impossible.
1572 Route::configure_processors_unlocked (ProcessorStreams* err)
1574 assert (!AudioEngine::instance()->process_lock().trylock());
1576 if (_in_configure_processors) {
1580 _in_configure_processors = true;
1582 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1584 if (configuration.empty ()) {
1585 _in_configure_processors = false;
1591 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1592 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1594 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1598 (*p)->configure_io(c->first, c->second);
1599 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1600 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1605 _meter->reset_max_channels (processor_max_streams);
1608 /* make sure we have sufficient scratch buffers to cope with the new processor
1610 _session.ensure_buffers (n_process_buffers ());
1612 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1614 _in_configure_processors = false;
1619 Route::all_processors_flip ()
1621 Glib::RWLock::ReaderLock lm (_processor_lock);
1623 if (_processors.empty()) {
1627 bool first_is_on = _processors.front()->active();
1629 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1631 (*i)->deactivate ();
1637 _session.set_dirty ();
1640 /** Set all processors with a given placement to a given active state.
1641 * @param p Placement of processors to change.
1642 * @param state New active state for those processors.
1645 Route::all_processors_active (Placement p, bool state)
1647 Glib::RWLock::ReaderLock lm (_processor_lock);
1649 if (_processors.empty()) {
1652 ProcessorList::iterator start, end;
1653 placement_range(p, start, end);
1655 bool before_amp = true;
1656 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1661 if (p == PreFader && before_amp) {
1665 (*i)->deactivate ();
1670 _session.set_dirty ();
1674 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1676 bool pre_fader = true;
1677 Glib::RWLock::ReaderLock lm (_processor_lock);
1679 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1681 /* semantic note: if p == amp, we want to return true, so test
1682 for equality before checking if this is the amp
1699 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1701 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1702 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1703 processors in the current actual processor list that are hidden. Any visible processors
1704 in the current list but not in "new_order" will be assumed to be deleted.
1708 Glib::RWLock::WriterLock lm (_processor_lock);
1709 ChanCount old_pms = processor_max_streams;
1710 ProcessorList::iterator oiter;
1711 ProcessorList::const_iterator niter;
1712 ProcessorList as_it_was_before = _processors;
1713 ProcessorList as_it_will_be;
1715 oiter = _processors.begin();
1716 niter = new_order.begin();
1718 while (niter != new_order.end()) {
1720 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1721 then append it to the temp list.
1723 Otherwise, see if the next processor in the old list is in the new list. if not,
1724 its been deleted. If its there, append it to the temp list.
1727 if (oiter == _processors.end()) {
1729 /* no more elements in the old list, so just stick the rest of
1730 the new order onto the temp list.
1733 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1734 while (niter != new_order.end()) {
1741 if (!(*oiter)->display_to_user()) {
1743 as_it_will_be.push_back (*oiter);
1747 /* visible processor: check that its in the new order */
1749 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1750 /* deleted: do nothing, shared_ptr<> will clean up */
1752 /* ignore this one, and add the next item from the new order instead */
1753 as_it_will_be.push_back (*niter);
1758 /* now remove from old order - its taken care of no matter what */
1759 oiter = _processors.erase (oiter);
1764 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1767 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1769 if (configure_processors_unlocked (err)) {
1770 _processors = as_it_was_before;
1771 processor_max_streams = old_pms;
1777 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1778 set_processor_positions ();
1790 Route::get_template()
1792 return state(false);
1796 Route::state(bool full_state)
1798 XMLNode *node = new XMLNode("Route");
1799 ProcessorList::iterator i;
1802 id().print (buf, sizeof (buf));
1803 node->add_property("id", buf);
1804 node->add_property ("name", _name);
1805 node->add_property("default-type", _default_type.to_string());
1808 node->add_property("flags", enum_2_string (_flags));
1811 node->add_property("active", _active?"yes":"no");
1813 boost::to_string (_phase_invert, p);
1814 node->add_property("phase-invert", p);
1815 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1816 node->add_property("meter-point", enum_2_string (_meter_point));
1819 node->add_property("route-group", _route_group->name());
1822 string order_string;
1823 OrderKeys::iterator x = order_keys.begin();
1825 while (x != order_keys.end()) {
1826 order_string += string ((*x).first);
1827 order_string += '=';
1828 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1829 order_string += buf;
1833 if (x == order_keys.end()) {
1837 order_string += ':';
1839 node->add_property ("order-keys", order_string);
1840 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1841 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1842 node->add_property ("soloed-by-upstream", buf);
1843 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1844 node->add_property ("soloed-by-downstream", buf);
1845 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
1846 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
1848 node->add_child_nocopy (_input->state (full_state));
1849 node->add_child_nocopy (_output->state (full_state));
1850 node->add_child_nocopy (_solo_control->get_state ());
1851 node->add_child_nocopy (_mute_control->get_state ());
1852 node->add_child_nocopy (_mute_master->get_state ());
1854 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1855 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1856 remote_control_node->add_property (X_("id"), buf);
1857 node->add_child_nocopy (*remote_control_node);
1859 if (_comment.length()) {
1860 XMLNode *cmt = node->add_child ("Comment");
1861 cmt->add_content (_comment);
1864 node->add_child_nocopy (_pannable->state (full_state));
1866 for (i = _processors.begin(); i != _processors.end(); ++i) {
1867 node->add_child_nocopy((*i)->state (full_state));
1871 node->add_child_copy (*_extra_xml);
1878 Route::set_state (const XMLNode& node, int version)
1880 return _set_state (node, version, true);
1884 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1886 if (version < 3000) {
1887 return _set_state_2X (node, version);
1891 XMLNodeConstIterator niter;
1893 const XMLProperty *prop;
1895 if (node.name() != "Route"){
1896 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1900 if ((prop = node.property (X_("name"))) != 0) {
1901 Route::set_name (prop->value());
1904 if ((prop = node.property ("id")) != 0) {
1905 _id = prop->value ();
1908 if ((prop = node.property (X_("flags"))) != 0) {
1909 _flags = Flag (string_2_enum (prop->value(), _flags));
1914 if (is_master() || is_monitor() || is_hidden()) {
1915 _mute_master->set_solo_ignore (true);
1918 /* add all processors (except amp, which is always present) */
1920 nlist = node.children();
1921 XMLNode processor_state (X_("processor_state"));
1923 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1927 if (child->name() == IO::state_node_name) {
1928 if ((prop = child->property (X_("direction"))) == 0) {
1932 if (prop->value() == "Input") {
1933 _input->set_state (*child, version);
1934 } else if (prop->value() == "Output") {
1935 _output->set_state (*child, version);
1939 if (child->name() == X_("Processor")) {
1940 processor_state.add_child_copy (*child);
1944 if (child->name() == X_("Pannable")) {
1945 _pannable->set_state (*child, version);
1949 set_processor_state (processor_state);
1951 if ((prop = node.property ("self-solo")) != 0) {
1952 set_self_solo (string_is_affirmative (prop->value()));
1955 if ((prop = node.property ("soloed-by-upstream")) != 0) {
1956 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
1957 mod_solo_by_others_upstream (atoi (prop->value()));
1960 if ((prop = node.property ("soloed-by-downstream")) != 0) {
1961 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
1962 mod_solo_by_others_downstream (atoi (prop->value()));
1965 if ((prop = node.property ("solo-isolated")) != 0) {
1966 set_solo_isolated (string_is_affirmative (prop->value()), this);
1969 if ((prop = node.property ("solo-safe")) != 0) {
1970 set_solo_safe (string_is_affirmative (prop->value()), this);
1973 if ((prop = node.property (X_("phase-invert"))) != 0) {
1974 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
1977 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1978 set_denormal_protection (string_is_affirmative (prop->value()));
1981 if ((prop = node.property (X_("active"))) != 0) {
1982 bool yn = string_is_affirmative (prop->value());
1983 _active = !yn; // force switch
1984 set_active (yn, this);
1987 if ((prop = node.property (X_("meter-point"))) != 0) {
1988 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
1989 set_meter_point (mp, true);
1991 _meter->set_display_to_user (_meter_point == MeterCustom);
1995 if ((prop = node.property (X_("order-keys"))) != 0) {
1999 string::size_type colon, equal;
2000 string remaining = prop->value();
2002 while (remaining.length()) {
2004 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2005 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2008 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2009 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2012 set_order_key (remaining.substr (0, equal), n);
2016 colon = remaining.find_first_of (':');
2018 if (colon != string::npos) {
2019 remaining = remaining.substr (colon+1);
2026 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2029 if (child->name() == X_("Comment")) {
2031 /* XXX this is a terrible API design in libxml++ */
2033 XMLNode *cmt = *(child->children().begin());
2034 _comment = cmt->content();
2036 } else if (child->name() == X_("Extra")) {
2038 _extra_xml = new XMLNode (*child);
2040 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2041 if (prop->value() == "solo") {
2042 _solo_control->set_state (*child, version);
2045 } else if (child->name() == X_("RemoteControl")) {
2046 if ((prop = child->property (X_("id"))) != 0) {
2048 sscanf (prop->value().c_str(), "%d", &x);
2049 set_remote_control_id (x);
2052 } else if (child->name() == X_("MuteMaster")) {
2053 _mute_master->set_state (*child, version);
2061 Route::_set_state_2X (const XMLNode& node, int version)
2064 XMLNodeConstIterator niter;
2066 const XMLProperty *prop;
2068 /* 2X things which still remain to be handled:
2074 if (node.name() != "Route") {
2075 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2079 if ((prop = node.property (X_("flags"))) != 0) {
2080 _flags = Flag (string_2_enum (prop->value(), _flags));
2085 if ((prop = node.property (X_("phase-invert"))) != 0) {
2086 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2087 if (string_is_affirmative (prop->value ())) {
2090 set_phase_invert (p);
2093 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2094 set_denormal_protection (string_is_affirmative (prop->value()));
2097 if ((prop = node.property (X_("soloed"))) != 0) {
2098 bool yn = string_is_affirmative (prop->value());
2100 /* XXX force reset of solo status */
2102 set_solo (yn, this);
2105 if ((prop = node.property (X_("muted"))) != 0) {
2108 bool muted = string_is_affirmative (prop->value());
2114 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2116 if (string_is_affirmative (prop->value())){
2117 mute_point = mute_point + "PreFader";
2122 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2124 if (string_is_affirmative (prop->value())){
2127 mute_point = mute_point + ",";
2130 mute_point = mute_point + "PostFader";
2135 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2137 if (string_is_affirmative (prop->value())){
2140 mute_point = mute_point + ",";
2143 mute_point = mute_point + "Listen";
2148 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2150 if (string_is_affirmative (prop->value())){
2153 mute_point = mute_point + ",";
2156 mute_point = mute_point + "Main";
2160 _mute_master->set_mute_points (mute_point);
2164 if ((prop = node.property (X_("meter-point"))) != 0) {
2165 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2168 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2169 don't mean the same thing.
2172 if ((prop = node.property (X_("order-keys"))) != 0) {
2176 string::size_type colon, equal;
2177 string remaining = prop->value();
2179 while (remaining.length()) {
2181 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2182 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2185 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2186 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2189 set_order_key (remaining.substr (0, equal), n);
2193 colon = remaining.find_first_of (':');
2195 if (colon != string::npos) {
2196 remaining = remaining.substr (colon+1);
2205 nlist = node.children ();
2206 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2210 if (child->name() == IO::state_node_name) {
2212 /* there is a note in IO::set_state_2X() about why we have to call
2216 _input->set_state_2X (*child, version, true);
2217 _output->set_state_2X (*child, version, false);
2219 if ((prop = child->property (X_("name"))) != 0) {
2220 Route::set_name (prop->value ());
2223 if ((prop = child->property (X_("id"))) != 0) {
2224 _id = prop->value ();
2227 if ((prop = child->property (X_("active"))) != 0) {
2228 bool yn = string_is_affirmative (prop->value());
2229 _active = !yn; // force switch
2230 set_active (yn, this);
2233 if ((prop = child->property (X_("gain"))) != 0) {
2236 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2237 _amp->gain_control()->set_value (val);
2241 /* Set up Panners in the IO */
2242 XMLNodeList io_nlist = child->children ();
2244 XMLNodeConstIterator io_niter;
2247 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2249 io_child = *io_niter;
2251 if (io_child->name() == X_("Panner")) {
2252 _main_outs->panner_shell()->set_state(*io_child, version);
2253 } else if (io_child->name() == X_("Automation")) {
2254 /* IO's automation is for the fader */
2255 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2261 XMLNodeList redirect_nodes;
2263 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2267 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2268 redirect_nodes.push_back(child);
2273 set_processor_state_2X (redirect_nodes, version);
2275 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2278 if (child->name() == X_("Comment")) {
2280 /* XXX this is a terrible API design in libxml++ */
2282 XMLNode *cmt = *(child->children().begin());
2283 _comment = cmt->content();
2285 } else if (child->name() == X_("extra")) {
2287 _extra_xml = new XMLNode (*child);
2289 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2290 if (prop->value() == X_("solo")) {
2291 _solo_control->set_state (*child, version);
2292 } else if (prop->value() == X_("mute")) {
2293 _mute_control->set_state (*child, version);
2296 } else if (child->name() == X_("RemoteControl")) {
2297 if ((prop = child->property (X_("id"))) != 0) {
2299 sscanf (prop->value().c_str(), "%d", &x);
2300 set_remote_control_id (x);
2310 Route::get_processor_state ()
2312 XMLNode* root = new XMLNode (X_("redirects"));
2313 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2314 root->add_child_nocopy ((*i)->state (true));
2321 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2323 /* We don't bother removing existing processors not in nList, as this
2324 method will only be called when creating a Route from scratch, not
2325 for undo purposes. Just put processors in at the appropriate place
2329 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2330 add_processor_from_xml_2X (**i, version);
2335 Route::set_processor_state (const XMLNode& node)
2337 const XMLNodeList &nlist = node.children();
2338 XMLNodeConstIterator niter;
2339 ProcessorList new_order;
2340 bool must_configure = false;
2342 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2344 XMLProperty* prop = (*niter)->property ("type");
2346 if (prop->value() == "amp") {
2347 _amp->set_state (**niter, Stateful::current_state_version);
2348 new_order.push_back (_amp);
2349 } else if (prop->value() == "meter") {
2350 _meter->set_state (**niter, Stateful::current_state_version);
2351 new_order.push_back (_meter);
2352 } else if (prop->value() == "main-outs") {
2353 _main_outs->set_state (**niter, Stateful::current_state_version);
2354 new_order.push_back (_main_outs);
2355 } else if (prop->value() == "intreturn") {
2357 _intreturn.reset (new InternalReturn (_session));
2358 must_configure = true;
2360 _intreturn->set_state (**niter, Stateful::current_state_version);
2361 new_order.push_back (_intreturn);
2362 } else if (is_monitor() && prop->value() == "monitor") {
2363 if (!_monitor_control) {
2364 _monitor_control.reset (new MonitorProcessor (_session));
2365 must_configure = true;
2367 _monitor_control->set_state (**niter, Stateful::current_state_version);
2368 new_order.push_back (_monitor_control);
2370 ProcessorList::iterator o;
2372 for (o = _processors.begin(); o != _processors.end(); ++o) {
2373 XMLProperty* id_prop = (*niter)->property(X_("id"));
2374 if (id_prop && (*o)->id() == id_prop->value()) {
2375 (*o)->set_state (**niter, Stateful::current_state_version);
2376 new_order.push_back (*o);
2381 // If the processor (*niter) is not on the route then create it
2383 if (o == _processors.end()) {
2385 boost::shared_ptr<Processor> processor;
2387 if (prop->value() == "intsend") {
2389 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2391 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2392 prop->value() == "lv2" ||
2393 prop->value() == "vst" ||
2394 prop->value() == "audiounit") {
2396 processor.reset (new PluginInsert(_session));
2398 } else if (prop->value() == "port") {
2400 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2402 } else if (prop->value() == "send") {
2404 processor.reset (new Send (_session, _pannable, _mute_master));
2407 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2411 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2412 /* This processor could not be configured. Turn it into a UnknownProcessor */
2413 processor.reset (new UnknownProcessor (_session, **niter));
2416 new_order.push_back (processor);
2417 must_configure = true;
2423 Glib::RWLock::WriterLock lm (_processor_lock);
2424 _processors = new_order;
2425 if (must_configure) {
2426 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2427 configure_processors_unlocked (0);
2431 processors_changed (RouteProcessorChange ());
2432 set_processor_positions ();
2436 Route::curve_reallocate ()
2438 // _gain_automation_curve.finish_resize ();
2439 // _pan_automation_curve.finish_resize ();
2443 Route::silence (framecnt_t nframes)
2445 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2450 silence_unlocked (nframes);
2454 Route::silence_unlocked (framecnt_t nframes)
2456 /* Must be called with the processor lock held */
2460 _output->silence (nframes);
2462 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2463 boost::shared_ptr<PluginInsert> pi;
2465 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2466 // skip plugins, they don't need anything when we're not active
2470 (*i)->silence (nframes);
2473 if (nframes == _session.get_block_size()) {
2480 Route::add_internal_return ()
2483 _intreturn.reset (new InternalReturn (_session));
2484 add_processor (_intreturn, PreFader);
2489 Route::get_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 BufferSet* bs = d->get_buffers ();
2506 Route::release_return_buffer () const
2508 Glib::RWLock::ReaderLock rm (_processor_lock);
2510 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2511 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2514 return d->release_buffers ();
2520 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2522 vector<string> ports;
2523 vector<string>::const_iterator i;
2526 Glib::RWLock::ReaderLock rm (_processor_lock);
2528 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2530 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2532 if (d && d->target_route() == route) {
2534 /* if the target is the control outs, then make sure
2535 we take note of which i-send is doing that.
2538 if (route == _session.monitor_out()) {
2539 _monitor_send = boost::dynamic_pointer_cast<Delivery>(d);
2542 /* already listening via the specified IO: do nothing */
2549 boost::shared_ptr<InternalSend> listener;
2555 if (route == _session.monitor_out()) {
2556 /* master never sends to control outs */
2559 listener.reset (new InternalSend (_session, _pannable, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2563 listener.reset (new InternalSend (_session, _pannable, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2566 } catch (failed_constructor& err) {
2570 if (route == _session.monitor_out()) {
2571 _monitor_send = listener;
2577 add_processor (listener, placement);
2581 if (placement == PostFader) {
2582 /* put it *really* at the end, not just after the panner (main outs)
2584 add_processor (listener, _processors.end());
2586 add_processor (listener, PreFader);
2595 Route::drop_listen (boost::shared_ptr<Route> route)
2597 ProcessorStreams err;
2598 ProcessorList::iterator tmp;
2600 Glib::RWLock::ReaderLock rl(_processor_lock);
2604 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2606 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2608 if (d && d->target_route() == route) {
2610 remove_processor (*x, &err);
2613 /* list could have been demolished while we dropped the lock
2623 if (route == _session.monitor_out()) {
2624 _monitor_send.reset ();
2629 Route::set_comment (string cmt, void *src)
2632 comment_changed (src);
2633 _session.set_dirty ();
2637 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2639 FeedRecord fr (other, via_sends_only);
2641 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2643 if (!result.second) {
2645 /* already a record for "other" - make sure sends-only information is correct */
2646 if (!via_sends_only && result.first->sends_only) {
2647 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2648 frp->sends_only = false;
2652 return result.second;
2656 Route::clear_fed_by ()
2662 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2664 const FedBy& fed_by (other->fed_by());
2666 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2667 boost::shared_ptr<Route> sr = f->r.lock();
2669 if (sr && (sr.get() == this)) {
2671 if (via_sends_only) {
2672 *via_sends_only = f->sends_only;
2683 Route::direct_feeds (boost::shared_ptr<Route> other, bool* only_send)
2685 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2687 if (_output->connected_to (other->input())) {
2688 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2697 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2699 boost::shared_ptr<IOProcessor> iop;
2701 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2702 if (iop->feeds (other)) {
2703 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2709 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2712 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2717 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2721 /** Called from the (non-realtime) butler thread when the transport is stopped */
2723 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2725 framepos_t now = _session.transport_frame();
2728 Glib::RWLock::ReaderLock lm (_processor_lock);
2731 automation_snapshot (now, true);
2734 Automatable::transport_stopped (now);
2736 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2738 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2742 (*i)->transport_stopped (now);
2746 _roll_delay = _initial_delay;
2749 /** Called with the process lock held if change contains ConfigurationChanged */
2751 Route::input_change_handler (IOChange change, void * /*src*/)
2753 if ((change.type & IOChange::ConfigurationChanged)) {
2754 configure_processors (0);
2755 _phase_invert.resize (_input->n_ports().n_audio ());
2756 io_changed (); /* EMIT SIGNAL */
2760 /** Called with the process lock held if change contains ConfigurationChanged */
2762 Route::output_change_handler (IOChange change, void * /*src*/)
2764 if ((change.type & IOChange::ConfigurationChanged)) {
2766 /* XXX resize all listeners to match _main_outs? */
2768 /* Auto-connect newly-created outputs, unless we're auto-connecting to master
2769 and we are master (as an auto-connect in this situation would cause a
2772 AutoConnectOption ac = Config->get_output_auto_connect ();
2773 if (ac == AutoConnectPhysical || (ac == AutoConnectMaster && !is_master ())) {
2775 ChanCount start = change.before;
2777 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
2778 if (change.before.get(*i) < change.after.get(*i)) {
2779 /* the existing ChanCounts don't matter for this call as they are only
2780 to do with matching input and output indices, and we are only changing
2785 /* only auto-connect the newly-created outputs, not the ones that were
2788 start.set (*i, start.get (*i) + 1);
2790 _session.auto_connect_route (this, dummy, dummy, false, ChanCount(), change.before);
2795 // configure_processors (0);
2800 Route::pans_required () const
2802 if (n_outputs().n_audio() < 2) {
2806 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2810 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
2811 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2813 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2818 if (n_outputs().n_total() == 0) {
2822 if (!_active || n_inputs() == ChanCount::ZERO) {
2823 silence_unlocked (nframes);
2826 if (session_state_changing) {
2827 if (_session.transport_speed() != 0.0f) {
2828 /* we're rolling but some state is changing (e.g. our diskstream contents)
2829 so we cannot use them. Be silent till this is over.
2831 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2833 silence_unlocked (nframes);
2836 /* we're really not rolling, so we're either delivery silence or actually
2837 monitoring, both of which are safe to do while session_state_changing is true.
2841 _amp->apply_gain_automation (false);
2842 passthru (start_frame, end_frame, nframes, 0);
2848 Route::check_initial_delay (framecnt_t nframes, framecnt_t& transport_frame)
2850 if (_roll_delay > nframes) {
2852 _roll_delay -= nframes;
2853 silence_unlocked (nframes);
2854 /* transport frame is not legal for caller to use */
2857 } else if (_roll_delay > 0) {
2859 nframes -= _roll_delay;
2860 silence_unlocked (_roll_delay);
2861 /* we've written _roll_delay of samples into the
2862 output ports, so make a note of that for
2865 _main_outs->increment_output_offset (_roll_delay);
2866 transport_frame += _roll_delay;
2875 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick,
2876 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2878 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2883 automation_snapshot (_session.transport_frame(), false);
2885 if (n_outputs().n_total() == 0) {
2889 if (!_active || n_inputs().n_total() == 0) {
2890 silence_unlocked (nframes);
2894 framecnt_t unused = 0;
2896 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2902 passthru (start_frame, end_frame, nframes, declick);
2908 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/,
2909 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2916 Route::toggle_monitor_input ()
2918 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2919 i->ensure_monitor_input( ! i->monitoring_input());
2924 Route::has_external_redirects () const
2926 // FIXME: what about sends? - they don't return a signal back to ardour?
2928 boost::shared_ptr<const PortInsert> pi;
2930 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2932 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2934 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2936 string port_name = port->name();
2937 string client_name = port_name.substr (0, port_name.find(':'));
2939 /* only say "yes" if the redirect is actually in use */
2941 if (client_name != "ardour" && pi->active()) {
2952 Route::flush_processors ()
2954 /* XXX shouldn't really try to take this lock, since
2955 this is called from the RT audio thread.
2958 Glib::RWLock::ReaderLock lm (_processor_lock);
2960 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2966 Route::set_meter_point (MeterPoint p, bool force)
2968 /* CAN BE CALLED FROM PROCESS CONTEXT */
2970 if (_meter_point == p && !force) {
2974 bool meter_was_visible_to_user = _meter->display_to_user ();
2977 Glib::RWLock::WriterLock lm (_processor_lock);
2979 if (p != MeterCustom) {
2980 // Move meter in the processors list to reflect the new position
2981 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2982 _processors.erase(loc);
2985 loc = _processors.begin();
2988 loc = find (_processors.begin(), _processors.end(), _amp);
2990 case MeterPostFader:
2991 loc = _processors.end();
2999 if (loc == _processors.begin()) {
3000 m_in = _input->n_ports();
3002 ProcessorList::iterator before = loc;
3004 m_in = (*before)->output_streams ();
3007 _meter->reflect_inputs (m_in);
3009 _processors.insert (loc, _meter);
3011 /* we do not need to reconfigure the processors, because the meter
3012 (a) is always ready to handle processor_max_streams
3013 (b) is always an N-in/N-out processor, and thus moving
3014 it doesn't require any changes to the other processors.
3017 _meter->set_display_to_user (false);
3021 // just make it visible and let the user move it
3023 _meter->set_display_to_user (true);
3028 meter_change (); /* EMIT SIGNAL */
3030 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3032 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3036 Route::put_monitor_send_at (Placement p)
3038 if (!_monitor_send) {
3043 Glib::RWLock::WriterLock lm (_processor_lock);
3044 ProcessorList as_it_was (_processors);
3045 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _monitor_send);
3046 _processors.erase(loc);
3050 loc = find(_processors.begin(), _processors.end(), _amp);
3051 if (loc != _processors.begin()) {
3056 loc = _processors.end();
3060 _processors.insert (loc, _monitor_send);
3063 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3065 if (configure_processors_unlocked (0)) {
3066 _processors = as_it_was;
3067 configure_processors_unlocked (0); // it worked before we tried to add it ...
3073 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3074 _session.set_dirty ();
3077 boost::shared_ptr<CapturingProcessor>
3078 Route::add_export_point()
3080 // Check if it exists already
3081 boost::shared_ptr<CapturingProcessor> processor;
3082 if ((processor = boost::dynamic_pointer_cast<CapturingProcessor> (*_processors.begin()))) {
3087 processor.reset (new CapturingProcessor (_session));
3088 add_processor (processor, _processors.begin());
3093 Route::update_total_latency ()
3095 framecnt_t old = _output->effective_latency();
3096 framecnt_t own_latency = _output->user_latency();
3098 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3099 if ((*i)->active ()) {
3100 own_latency += (*i)->signal_latency ();
3104 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
3106 _output->set_port_latency (own_latency);
3108 if (_output->user_latency() == 0) {
3110 /* this (virtual) function is used for pure Routes,
3111 not derived classes like AudioTrack. this means
3112 that the data processed here comes from an input
3113 port, not prerecorded material, and therefore we
3114 have to take into account any input latency.
3117 own_latency += _input->signal_latency ();
3120 if (old != own_latency) {
3121 _output->set_latency_delay (own_latency);
3122 signal_latency_changed (); /* EMIT SIGNAL */
3125 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
3127 return _output->effective_latency ();
3131 Route::set_user_latency (framecnt_t nframes)
3133 _output->set_user_latency (nframes);
3134 _session.update_latency_compensation (false, false);
3138 Route::set_latency_delay (framecnt_t longest_session_latency)
3140 framecnt_t old = _initial_delay;
3142 if (_output->effective_latency() < longest_session_latency) {
3143 _initial_delay = longest_session_latency - _output->effective_latency();
3148 if (_initial_delay != old) {
3149 initial_delay_changed (); /* EMIT SIGNAL */
3152 if (_session.transport_stopped()) {
3153 _roll_delay = _initial_delay;
3158 Route::automation_snapshot (framepos_t now, bool force)
3160 _pannable->automation_snapshot (now, force);
3161 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3162 (*i)->automation_snapshot (now, force);
3166 Route::SoloControllable::SoloControllable (std::string name, Route& r)
3167 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
3168 boost::shared_ptr<AutomationList>(), name)
3171 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3176 Route::SoloControllable::set_value (double val)
3178 bool bval = ((val >= 0.5f) ? true: false);
3180 this is how it should be done
3182 boost::shared_ptr<RouteList> rl (new RouteList);
3183 rl->push_back (route);
3185 if (Config->get_solo_control_is_listen_control()) {
3186 _session.set_listen (rl, bval);
3188 _session.set_solo (rl, bval);
3191 route.set_solo (bval, this);
3196 Route::SoloControllable::get_value (void) const
3198 if (Config->get_solo_control_is_listen_control()) {
3199 return route.listening() ? 1.0f : 0.0f;
3201 return route.self_soloed() ? 1.0f : 0.0f;
3205 Route::MuteControllable::MuteControllable (std::string name, Route& r)
3206 : AutomationControl (r.session(), Evoral::Parameter (MuteAutomation),
3207 boost::shared_ptr<AutomationList>(), name)
3210 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3215 Route::MuteControllable::set_value (double val)
3217 bool bval = ((val >= 0.5f) ? true: false);
3219 this is how it should be done
3221 boost::shared_ptr<RouteList> rl (new RouteList);
3222 rl->push_back (route);
3223 _session.set_mute (rl, bval);
3225 route.set_mute (bval, this);
3230 Route::MuteControllable::get_value (void) const
3232 return route.muted() ? 1.0f : 0.0f;
3236 Route::set_block_size (pframes_t nframes)
3238 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3239 (*i)->set_block_size (nframes);
3242 _session.ensure_buffers (n_process_buffers ());
3246 Route::protect_automation ()
3248 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3249 (*i)->protect_automation();
3253 Route::set_pending_declick (int declick)
3256 /* this call is not allowed to turn off a pending declick unless "force" is true */
3258 _pending_declick = declick;
3260 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3262 _pending_declick = 0;
3267 /** Shift automation forwards from a particular place, thereby inserting time.
3268 * Adds undo commands for any shifts that are performed.
3270 * @param pos Position to start shifting from.
3271 * @param frames Amount to shift forwards by.
3275 Route::shift (framepos_t pos, framecnt_t frames)
3277 /* gain automation */
3279 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3281 XMLNode &before = gc->alist()->get_state ();
3282 gc->alist()->shift (pos, frames);
3283 XMLNode &after = gc->alist()->get_state ();
3284 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3287 /* pan automation */
3289 ControlSet::Controls& c (_pannable->controls());
3291 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3292 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3294 boost::shared_ptr<AutomationList> al = pc->alist();
3295 XMLNode& before = al->get_state ();
3296 al->shift (pos, frames);
3297 XMLNode& after = al->get_state ();
3298 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3303 /* redirect automation */
3305 Glib::RWLock::ReaderLock lm (_processor_lock);
3306 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3308 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3310 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3311 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3313 boost::shared_ptr<AutomationList> al = ac->alist();
3314 XMLNode &before = al->get_state ();
3315 al->shift (pos, frames);
3316 XMLNode &after = al->get_state ();
3317 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3326 Route::save_as_template (const string& path, const string& name)
3328 XMLNode& node (state (false));
3331 IO::set_name_in_state (*node.children().front(), name);
3333 tree.set_root (&node);
3334 return tree.write (path.c_str());
3339 Route::set_name (const string& str)
3345 name = Route::ensure_track_or_route_name (str, _session);
3346 SessionObject::set_name (name);
3348 ret = (_input->set_name(name) && _output->set_name(name));
3352 Glib::RWLock::ReaderLock lm (_processor_lock);
3354 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3356 /* rename all I/O processors that have inputs or outputs */
3358 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3360 if (iop && (iop->output() || iop->input())) {
3361 if (!iop->set_name (name)) {
3372 boost::shared_ptr<Send>
3373 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3375 Glib::RWLock::ReaderLock lm (_processor_lock);
3377 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3378 boost::shared_ptr<InternalSend> send;
3380 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3381 if (send->target_route() == target) {
3387 return boost::shared_ptr<Send>();
3390 /** @param c Audio channel index.
3391 * @param yn true to invert phase, otherwise false.
3394 Route::set_phase_invert (uint32_t c, bool yn)
3396 if (_phase_invert[c] != yn) {
3397 _phase_invert[c] = yn;
3398 phase_invert_changed (); /* EMIT SIGNAL */
3399 _session.set_dirty ();
3404 Route::set_phase_invert (boost::dynamic_bitset<> p)
3406 if (_phase_invert != p) {
3408 phase_invert_changed (); /* EMIT SIGNAL */
3409 _session.set_dirty ();
3414 Route::phase_invert (uint32_t c) const
3416 return _phase_invert[c];
3419 boost::dynamic_bitset<>
3420 Route::phase_invert () const
3422 return _phase_invert;
3426 Route::set_denormal_protection (bool yn)
3428 if (_denormal_protection != yn) {
3429 _denormal_protection = yn;
3430 denormal_protection_changed (); /* EMIT SIGNAL */
3435 Route::denormal_protection () const
3437 return _denormal_protection;
3441 Route::set_active (bool yn, void* src)
3443 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3444 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3448 if (_active != yn) {
3450 _input->set_active (yn);
3451 _output->set_active (yn);
3452 active_changed (); // EMIT SIGNAL
3459 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3465 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3467 boost::shared_ptr<Send> s;
3468 boost::shared_ptr<Return> r;
3470 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3471 s->meter()->meter();
3472 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3473 r->meter()->meter ();
3478 boost::shared_ptr<Pannable>
3479 Route::pannable() const
3484 boost::shared_ptr<Panner>
3485 Route::panner() const
3488 return _main_outs->panner_shell()->panner();
3491 boost::shared_ptr<PannerShell>
3492 Route::panner_shell() const
3494 return _main_outs->panner_shell();
3497 boost::shared_ptr<AutomationControl>
3498 Route::gain_control() const
3500 return _amp->gain_control();
3503 boost::shared_ptr<AutomationControl>
3504 Route::get_control (const Evoral::Parameter& param)
3506 /* either we own the control or .... */
3508 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3512 /* maybe one of our processors does or ... */
3514 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3515 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3516 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3524 /* nobody does so we'll make a new one */
3526 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3533 boost::shared_ptr<Processor>
3534 Route::nth_plugin (uint32_t n)
3536 Glib::RWLock::ReaderLock lm (_processor_lock);
3537 ProcessorList::iterator i;
3539 for (i = _processors.begin(); i != _processors.end(); ++i) {
3540 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3547 return boost::shared_ptr<Processor> ();
3550 boost::shared_ptr<Processor>
3551 Route::nth_send (uint32_t n)
3553 Glib::RWLock::ReaderLock lm (_processor_lock);
3554 ProcessorList::iterator i;
3556 for (i = _processors.begin(); i != _processors.end(); ++i) {
3557 if (boost::dynamic_pointer_cast<Send> (*i)) {
3564 return boost::shared_ptr<Processor> ();
3568 Route::has_io_processor_named (const string& name)
3570 Glib::RWLock::ReaderLock lm (_processor_lock);
3571 ProcessorList::iterator i;
3573 for (i = _processors.begin(); i != _processors.end(); ++i) {
3574 if (boost::dynamic_pointer_cast<Send> (*i) ||
3575 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3576 if ((*i)->name() == name) {
3585 MuteMaster::MutePoint
3586 Route::mute_points () const
3588 return _mute_master->mute_points ();
3592 Route::set_processor_positions ()
3594 Glib::RWLock::ReaderLock lm (_processor_lock);
3596 bool had_amp = false;
3597 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3598 (*i)->set_pre_fader (!had_amp);
3599 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3605 /** Called when there is a proposed change to the input port count */
3607 Route::input_port_count_changing (ChanCount to)
3609 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3611 /* The processors cannot be configured with the new input arrangement, so
3617 /* The change is ok */
3622 Route::unknown_processors () const
3626 Glib::RWLock::ReaderLock lm (_processor_lock);
3627 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3628 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3629 p.push_back ((*i)->name ());
3637 Route::set_latency_ranges (bool playback) const
3639 framecnt_t own_latency = 0;
3641 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD OR
3645 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3646 if ((*i)->active ()) {
3647 own_latency += (*i)->signal_latency ();
3652 update_port_latencies (_input->ports (), _output->ports (), true, own_latency);
3654 update_port_latencies (_output->ports (), _input->ports (), false, own_latency);
3659 Route::update_port_latencies (const PortSet& operands, const PortSet& feeders, bool playback, framecnt_t our_latency) const
3661 #ifdef HAVE_JACK_NEW_LATENCY
3663 /* we assume that all our input ports feed all our output ports. its not
3664 universally true, but the alternative is way too corner-case to worry about.
3667 jack_latency_range_t all_connections;
3669 all_connections.min = ~((jack_nframes_t) 0);
3670 all_connections.max = 0;
3672 /* iterate over all feeder ports and determine their relevant latency, taking
3673 the maximum and minimum across all of them.
3676 for (PortSet::const_iterator p = feeders.begin(); p != feeders.end(); ++p) {
3678 jack_latency_range_t range;
3680 p->get_connected_latency_range (range, playback);
3682 all_connections.min = min (all_connections.min, range.min);
3683 all_connections.max = max (all_connections.max, range.max);
3686 all_connections.min += our_latency;
3687 all_connections.max += our_latency;
3689 for (PortSet::const_iterator p = operands.begin(); p != operands.end(); ++p) {
3691 p->set_latency_range (all_connections, playback);
3693 DEBUG_TRACE (DEBUG::Latency, string_compose ("Port %1 %5 latency range %2 .. %3 + %4\n",
3695 all_connections.min,
3696 all_connections.max,
3698 (playback ? "PLAYBACK" : "CAPTURE")));