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"
66 using namespace ARDOUR;
69 uint32_t Route::order_key_cnt = 0;
70 PBD::Signal1<void,string const&> Route::SyncOrderKeys;
71 PBD::Signal0<void> Route::RemoteControlIDChange;
73 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
74 : SessionObject (sess, name)
76 , GraphNode( sess.route_graph )
81 , _pending_declick (true)
82 , _meter_point (MeterPostFader)
84 , _soloed_by_others_upstream (0)
85 , _soloed_by_others_downstream (0)
87 , _denormal_protection (false)
90 , _declickable (false)
91 , _solo_control (new SoloControllable (X_("solo"), *this))
92 , _mute_control (new MuteControllable (X_("mute"), *this))
93 , _mute_master (new MuteMaster (sess, name))
94 , _have_internal_generator (false)
96 , _default_type (default_type)
97 , _remote_control_id (0)
98 , _in_configure_processors (false)
100 processor_max_streams.reset();
101 order_keys[N_("signal")] = order_key_cnt++;
107 /* add standard controls */
109 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
110 _mute_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
112 add_control (_solo_control);
113 add_control (_mute_control);
115 /* input and output objects */
117 _input.reset (new IO (_session, _name, IO::Input, _default_type));
118 _output.reset (new IO (_session, _name, IO::Output, _default_type));
120 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
121 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
123 /* add amp processor */
125 _amp.reset (new Amp (_session));
126 add_processor (_amp, PostFader);
128 /* add standard processors: meter, main outs, monitor out */
130 _meter.reset (new PeakMeter (_session));
131 _meter->set_display_to_user (false);
133 add_processor (_meter, PostFader);
135 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
137 add_processor (_main_outs, PostFader);
140 /* where we listen to tracks */
141 _intreturn.reset (new InternalReturn (_session));
142 add_processor (_intreturn, PreFader);
144 ProcessorList::iterator i;
146 for (i = _processors.begin(); i != _processors.end(); ++i) {
147 if (*i == _intreturn) {
153 /* the thing that provides proper control over a control/monitor/listen bus
154 (such as per-channel cut, dim, solo, invert, etc).
155 It always goes right after the internal return;
157 _monitor_control.reset (new MonitorProcessor (_session));
158 add_processor (_monitor_control, i);
160 /* no panning on the monitor main outs */
162 _main_outs->panner()->set_bypassed (true);
165 if (is_master() || is_monitor() || is_hidden()) {
166 _mute_master->set_solo_ignore (true);
169 /* now that we have _meter, its safe to connect to this */
171 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
178 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
180 /* do this early so that we don't get incoming signals as we are going through destruction
185 /* don't use clear_processors here, as it depends on the session which may
186 be half-destroyed by now
189 Glib::RWLock::WriterLock lm (_processor_lock);
190 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
191 (*i)->drop_references ();
194 _processors.clear ();
198 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
200 if (id != _remote_control_id) {
201 _remote_control_id = id;
202 RemoteControlIDChanged ();
203 if (notify_class_listeners) {
204 RemoteControlIDChange ();
210 Route::remote_control_id() const
212 return _remote_control_id;
216 Route::order_key (std::string const & name) const
218 OrderKeys::const_iterator i = order_keys.find (name);
219 if (i == order_keys.end()) {
227 Route::set_order_key (std::string const & name, int32_t n)
229 bool changed = false;
231 /* This method looks more complicated than it should, but
232 it's important that we don't emit order_key_changed unless
233 it actually has, as expensive things happen on receipt of that
237 if (order_keys.find(name) == order_keys.end() || order_keys[name] != n) {
238 order_keys[name] = n;
242 if (Config->get_sync_all_route_ordering()) {
243 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
244 if (x->second != n) {
252 order_key_changed (); /* EMIT SIGNAL */
253 _session.set_dirty ();
257 /** Set all order keys to be the same as that for `base', if such a key
258 * exists in this route.
259 * @param base Base key.
262 Route::sync_order_keys (std::string const & base)
264 if (order_keys.empty()) {
268 OrderKeys::iterator i;
271 if ((i = order_keys.find (base)) == order_keys.end()) {
272 /* key doesn't exist, use the first existing key (during session initialization) */
273 i = order_keys.begin();
277 /* key exists - use it and reset all others (actually, itself included) */
279 i = order_keys.begin();
282 bool changed = false;
284 for (; i != order_keys.end(); ++i) {
285 if (i->second != key) {
292 order_key_changed (); /* EMIT SIGNAL */
297 Route::ensure_track_or_route_name(string name, Session &session)
299 string newname = name;
301 while (!session.io_name_is_legal (newname)) {
302 newname = bump_name_once (newname, '.');
310 Route::inc_gain (gain_t fraction, void *src)
312 _amp->inc_gain (fraction, src);
316 Route::set_gain (gain_t val, void *src)
318 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
320 if (_route_group->is_relative()) {
322 gain_t usable_gain = _amp->gain();
323 if (usable_gain < 0.000001f) {
324 usable_gain = 0.000001f;
328 if (delta < 0.000001f) {
332 delta -= usable_gain;
337 gain_t factor = delta / usable_gain;
340 factor = _route_group->get_max_factor(factor);
341 if (factor == 0.0f) {
342 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
346 factor = _route_group->get_min_factor(factor);
347 if (factor == 0.0f) {
348 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
353 _route_group->apply (&Route::inc_gain, factor, _route_group);
357 _route_group->apply (&Route::set_gain, val, _route_group);
363 if (val == _amp->gain()) {
367 _amp->set_gain (val, src);
370 /** Process this route for one (sub) cycle (process thread)
372 * @param bufs Scratch buffers to use for the signal path
373 * @param start_frame Initial transport frame
374 * @param end_frame Final transport frame
375 * @param nframes Number of frames to output (to ports)
377 * Note that (end_frame - start_frame) may not be equal to nframes when the
378 * transport speed isn't 1.0 (eg varispeed).
381 Route::process_output_buffers (BufferSet& bufs,
382 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
383 bool /*with_processors*/, int declick)
387 bufs.is_silent (false);
389 switch (Config->get_monitoring_model()) {
390 case HardwareMonitoring:
391 case ExternalMonitoring:
392 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
399 declick = _pending_declick;
402 /* figure out if we're going to use gain automation */
403 _amp->setup_gain_automation (start_frame, end_frame, nframes);
406 /* tell main outs what to do about monitoring */
407 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
410 /* -------------------------------------------------------------------------------------------
411 GLOBAL DECLICK (for transport changes etc.)
412 ----------------------------------------------------------------------------------------- */
415 Amp::declick (bufs, nframes, 1);
416 } else if (declick < 0) {
417 Amp::declick (bufs, nframes, -1);
420 _pending_declick = 0;
422 /* -------------------------------------------------------------------------------------------
423 DENORMAL CONTROL/PHASE INVERT
424 ----------------------------------------------------------------------------------------- */
426 if (_phase_invert.any ()) {
430 if (_denormal_protection || Config->get_denormal_protection()) {
432 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
433 Sample* const sp = i->data();
435 if (_phase_invert[chn]) {
436 for (nframes_t nx = 0; nx < nframes; ++nx) {
441 for (nframes_t nx = 0; nx < nframes; ++nx) {
449 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
450 Sample* const sp = i->data();
452 if (_phase_invert[chn]) {
453 for (nframes_t nx = 0; nx < nframes; ++nx) {
462 if (_denormal_protection || Config->get_denormal_protection()) {
464 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
465 Sample* const sp = i->data();
466 for (nframes_t nx = 0; nx < nframes; ++nx) {
474 /* -------------------------------------------------------------------------------------------
476 ----------------------------------------------------------------------------------------- */
478 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
480 if (bufs.count() != (*i)->input_streams()) {
481 cerr << _name << " bufs = " << bufs.count()
482 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
485 assert (bufs.count() == (*i)->input_streams());
487 /* should we NOT run plugins here if the route is inactive?
488 do we catch route != active somewhere higher?
491 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
492 bufs.set_count ((*i)->output_streams());
497 Route::n_process_buffers ()
499 return max (_input->n_ports(), processor_max_streams);
503 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
505 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
509 assert (bufs.available() >= input_streams());
511 if (_input->n_ports() == ChanCount::ZERO) {
512 silence_unlocked (nframes);
515 bufs.set_count (input_streams());
517 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
519 /* control/monitor bus ignores input ports when something is
520 feeding the listen "stream". data will "arrive" into the
521 route from the intreturn processor element.
523 bufs.silence (nframes, 0);
527 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
529 BufferSet::iterator o = bufs.begin(*t);
530 PortSet& ports (_input->ports());
532 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
533 o->read_from (i->get_buffer(nframes), nframes);
538 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
539 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
543 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
545 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
546 bufs.set_count (_input->n_ports());
547 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
548 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
552 Route::set_listen (bool yn, void* src)
559 if (yn != _monitor_send->active()) {
561 _monitor_send->activate ();
562 _mute_master->set_soloed (true);
564 _monitor_send->deactivate ();
565 _mute_master->set_soloed (false);
568 listen_changed (src); /* EMIT SIGNAL */
574 Route::listening () const
577 return _monitor_send->active ();
584 Route::set_solo_safe (bool yn, void *src)
586 if (_solo_safe != yn) {
588 solo_safe_changed (src);
593 Route::solo_safe() const
599 Route::set_solo (bool yn, void *src)
605 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
606 _route_group->apply (&Route::set_solo, yn, _route_group);
610 if (self_soloed() != yn) {
612 set_mute_master_solo ();
613 solo_changed (true, src); /* EMIT SIGNAL */
614 _solo_control->Changed (); /* EMIT SIGNAL */
619 Route::set_self_solo (bool yn)
625 Route::mod_solo_by_others_upstream (int32_t delta)
631 uint32_t old_sbu = _soloed_by_others_upstream;
634 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
635 _soloed_by_others_upstream += delta;
637 _soloed_by_others_upstream = 0;
640 _soloed_by_others_upstream += delta;
643 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
644 name(), delta, _soloed_by_others_upstream, old_sbu,
645 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
647 /* push the inverse solo change to everything that feeds us.
649 This is important for solo-within-group. When we solo 1 track out of N that
650 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
651 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
652 tracks that feed it. This will silence them if they were audible because
653 of a bus solo, but the newly soloed track will still be audible (because
656 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
660 if ((_self_solo || _soloed_by_others_downstream) &&
661 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
662 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
664 if (delta > 0 || !Config->get_exclusive_solo()) {
665 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
666 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
667 boost::shared_ptr<Route> sr = i->r.lock();
669 sr->mod_solo_by_others_downstream (-delta);
675 set_mute_master_solo ();
676 solo_changed (false, this);
680 Route::mod_solo_by_others_downstream (int32_t delta)
687 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
688 _soloed_by_others_downstream += delta;
690 _soloed_by_others_downstream = 0;
693 _soloed_by_others_downstream += delta;
696 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
698 set_mute_master_solo ();
699 solo_changed (false, this);
703 Route::set_mute_master_solo ()
705 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
709 Route::set_solo_isolated (bool yn, void *src)
711 if (is_master() || is_monitor() || is_hidden()) {
715 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
716 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
720 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
722 boost::shared_ptr<RouteList> routes = _session.get_routes ();
723 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
725 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
730 bool does_feed = direct_feeds (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
732 if (does_feed && !sends_only) {
733 (*i)->set_solo_isolated (yn, (*i)->route_group());
737 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
739 bool changed = false;
742 if (_solo_isolated == 0) {
743 _mute_master->set_solo_ignore (true);
748 if (_solo_isolated > 0) {
750 if (_solo_isolated == 0) {
751 _mute_master->set_solo_ignore (false);
758 solo_isolated_changed (src);
763 Route::solo_isolated () const
765 return _solo_isolated > 0;
769 Route::set_mute_points (MuteMaster::MutePoint mp)
771 _mute_master->set_mute_points (mp);
772 mute_points_changed (); /* EMIT SIGNAL */
774 if (_mute_master->muted_by_self()) {
775 mute_changed (this); /* EMIT SIGNAL */
780 Route::set_mute (bool yn, void *src)
782 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
783 _route_group->apply (&Route::set_mute, yn, _route_group);
788 _mute_master->set_muted_by_self (yn);
789 mute_changed (src); /* EMIT SIGNAL */
794 Route::muted () const
796 return _mute_master->muted_by_self();
801 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
803 cerr << name << " {" << endl;
804 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
805 p != procs.end(); ++p) {
806 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
813 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
815 ProcessorList::iterator loc;
817 /* XXX this is not thread safe - we don't hold the lock across determining the iter
818 to add before and actually doing the insertion. dammit.
821 if (placement == PreFader) {
822 /* generic pre-fader: insert immediately before the amp */
823 loc = find (_processors.begin(), _processors.end(), _amp);
825 /* generic post-fader: insert right before the main outs */
826 loc = find (_processors.begin(), _processors.end(), _main_outs);
829 return add_processor (processor, loc, err);
833 /** Add a processor to the route.
834 * @a iter must point to an iterator in _processors and the new
835 * processor will be inserted immediately before this location. Otherwise,
836 * @a position is used.
839 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
841 ChanCount old_pms = processor_max_streams;
843 if (!_session.engine().connected() || !processor) {
848 Glib::RWLock::WriterLock lm (_processor_lock);
850 boost::shared_ptr<PluginInsert> pi;
851 boost::shared_ptr<PortInsert> porti;
853 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
855 if (processor == _amp || processor == _meter || processor == _main_outs) {
856 // Ensure only one of these are in the list at any time
857 if (loc != _processors.end()) {
858 if (iter == loc) { // Already in place, do nothing
860 } else { // New position given, relocate
861 _processors.erase (loc);
866 if (loc != _processors.end()) {
867 cerr << "ERROR: Processor added to route twice!" << endl;
874 _processors.insert (loc, processor);
876 // Set up processor list channels. This will set processor->[input|output]_streams(),
877 // configure redirect ports properly, etc.
879 if (configure_processors_unlocked (err)) {
880 ProcessorList::iterator ploc = loc;
882 _processors.erase(ploc);
883 configure_processors_unlocked (0); // it worked before we tried to add it ...
884 cerr << "configure failed\n";
888 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
890 if (pi->natural_input_streams() == ChanCount::ZERO) {
891 /* generator plugin */
892 _have_internal_generator = true;
897 /* is this the monitor send ? if so, make sure we keep track of it */
899 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
901 if (isend && _session.monitor_out() && (isend->target_id() == _session.monitor_out()->id())) {
902 _monitor_send = isend;
905 if (activation_allowed && (processor != _monitor_send)) {
906 processor->activate ();
909 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
911 _output->set_user_latency (0);
914 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
915 set_processor_positions ();
921 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
923 const XMLProperty *prop;
926 boost::shared_ptr<Processor> processor;
928 if (node.name() == "Insert") {
930 if ((prop = node.property ("type")) != 0) {
932 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
933 prop->value() == "lv2" ||
934 prop->value() == "vst" ||
935 prop->value() == "audiounit") {
937 processor.reset (new PluginInsert (_session));
941 processor.reset (new PortInsert (_session, _mute_master));
946 } else if (node.name() == "Send") {
948 processor.reset (new Send (_session, _mute_master));
952 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
956 if (processor->set_state (node, version)) {
960 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
961 /* check for invisible processors stacked at the end and leave them there */
962 ProcessorList::iterator p;
963 p = _processors.end();
965 while (!(*p)->display_to_user() && p != _processors.begin()) {
972 return (add_processor (processor, iter) == 0);
975 catch (failed_constructor &err) {
976 warning << _("processor could not be created. Ignored.") << endmsg;
982 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
984 ProcessorList::iterator loc;
987 loc = find(_processors.begin(), _processors.end(), before);
989 /* nothing specified - at end but before main outs */
990 loc = find (_processors.begin(), _processors.end(), _main_outs);
993 return add_processors (others, loc, err);
997 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
999 /* NOTE: this is intended to be used ONLY when copying
1000 processors from another Route. Hence the subtle
1001 differences between this and ::add_processor()
1004 ChanCount old_pms = processor_max_streams;
1006 if (!_session.engine().connected()) {
1010 if (others.empty()) {
1015 Glib::RWLock::WriterLock lm (_processor_lock);
1017 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
1019 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1021 // Ensure meter only appears in the list once
1023 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
1024 if (m != _processors.end()) {
1025 _processors.erase(m);
1029 boost::shared_ptr<PluginInsert> pi;
1031 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1034 ChanCount m = max (pi->input_streams(), pi->output_streams());
1036 if (m > potential_max_streams) {
1037 potential_max_streams = m;
1041 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1043 if ((*i)->active()) {
1047 if (configure_processors_unlocked (err)) {
1048 _processors.erase (inserted);
1049 configure_processors_unlocked (0); // it worked before we tried to add it ...
1053 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
1056 _output->set_user_latency (0);
1059 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1060 set_processor_positions ();
1066 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1068 if (p == PreFader) {
1069 start = _processors.begin();
1070 end = find(_processors.begin(), _processors.end(), _amp);
1072 start = find(_processors.begin(), _processors.end(), _amp);
1074 end = _processors.end();
1078 /** Turn off all processors with a given placement
1079 * @param p Placement of processors to disable
1082 Route::disable_processors (Placement p)
1084 Glib::RWLock::ReaderLock lm (_processor_lock);
1086 ProcessorList::iterator start, end;
1087 placement_range(p, start, end);
1089 for (ProcessorList::iterator i = start; i != end; ++i) {
1090 (*i)->deactivate ();
1093 _session.set_dirty ();
1096 /** Turn off all redirects
1099 Route::disable_processors ()
1101 Glib::RWLock::ReaderLock lm (_processor_lock);
1103 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1104 (*i)->deactivate ();
1107 _session.set_dirty ();
1110 /** Turn off all redirects with a given placement
1111 * @param p Placement of redirects to disable
1114 Route::disable_plugins (Placement p)
1116 Glib::RWLock::ReaderLock lm (_processor_lock);
1118 ProcessorList::iterator start, end;
1119 placement_range(p, start, end);
1121 for (ProcessorList::iterator i = start; i != end; ++i) {
1122 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1123 (*i)->deactivate ();
1127 _session.set_dirty ();
1130 /** Turn off all plugins
1133 Route::disable_plugins ()
1135 Glib::RWLock::ReaderLock lm (_processor_lock);
1137 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1138 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1139 (*i)->deactivate ();
1143 _session.set_dirty ();
1148 Route::ab_plugins (bool forward)
1150 Glib::RWLock::ReaderLock lm (_processor_lock);
1154 /* forward = turn off all active redirects, and mark them so that the next time
1155 we go the other way, we will revert them
1158 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1159 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1163 if ((*i)->active()) {
1164 (*i)->deactivate ();
1165 (*i)->set_next_ab_is_active (true);
1167 (*i)->set_next_ab_is_active (false);
1173 /* backward = if the redirect was marked to go active on the next ab, do so */
1175 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1177 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1181 if ((*i)->get_next_ab_is_active()) {
1184 (*i)->deactivate ();
1189 _session.set_dirty ();
1193 /** Remove processors with a given placement.
1194 * @param p Placement of processors to remove.
1197 Route::clear_processors (Placement p)
1199 const ChanCount old_pms = processor_max_streams;
1201 if (!_session.engine().connected()) {
1205 bool already_deleting = _session.deletion_in_progress();
1206 if (!already_deleting) {
1207 _session.set_deletion_in_progress();
1211 Glib::RWLock::WriterLock lm (_processor_lock);
1212 ProcessorList new_list;
1213 ProcessorStreams err;
1214 bool seen_amp = false;
1216 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1222 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1224 /* you can't remove these */
1226 new_list.push_back (*i);
1233 new_list.push_back (*i);
1236 (*i)->drop_references ();
1244 (*i)->drop_references ();
1247 new_list.push_back (*i);
1254 _processors = new_list;
1255 configure_processors_unlocked (&err); // this can't fail
1258 processor_max_streams.reset();
1259 _have_internal_generator = false;
1260 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1261 set_processor_positions ();
1263 if (!already_deleting) {
1264 _session.clear_deletion_in_progress();
1269 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1271 /* these can never be removed */
1273 if (processor == _amp || processor == _meter || processor == _main_outs) {
1277 ChanCount old_pms = processor_max_streams;
1279 if (!_session.engine().connected()) {
1283 processor_max_streams.reset();
1286 Glib::RWLock::WriterLock lm (_processor_lock);
1287 ProcessorList::iterator i;
1288 bool removed = false;
1290 for (i = _processors.begin(); i != _processors.end(); ) {
1291 if (*i == processor) {
1293 /* move along, see failure case for configure_processors()
1294 where we may need to reconfigure the processor.
1297 /* stop redirects that send signals to JACK ports
1298 from causing noise as a result of no longer being
1302 boost::shared_ptr<IOProcessor> iop;
1304 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1306 iop->input()->disconnect (this);
1308 if (iop->output()) {
1309 iop->output()->disconnect (this);
1313 i = _processors.erase (i);
1321 _output->set_user_latency (0);
1329 if (configure_processors_unlocked (err)) {
1330 /* get back to where we where */
1331 _processors.insert (i, processor);
1332 /* we know this will work, because it worked before :) */
1333 configure_processors_unlocked (0);
1337 _have_internal_generator = false;
1339 for (i = _processors.begin(); i != _processors.end(); ++i) {
1340 boost::shared_ptr<PluginInsert> pi;
1342 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1343 if (pi->is_generator()) {
1344 _have_internal_generator = true;
1351 processor->drop_references ();
1352 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1353 set_processor_positions ();
1359 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1361 ProcessorList deleted;
1363 if (!_session.engine().connected()) {
1367 processor_max_streams.reset();
1370 Glib::RWLock::WriterLock lm (_processor_lock);
1371 ProcessorList::iterator i;
1372 boost::shared_ptr<Processor> processor;
1374 ProcessorList as_we_were = _processors;
1376 for (i = _processors.begin(); i != _processors.end(); ) {
1380 /* these can never be removed */
1382 if (processor == _amp || processor == _meter || processor == _main_outs) {
1387 /* see if its in the list of processors to delete */
1389 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1394 /* stop IOProcessors that send to JACK ports
1395 from causing noise as a result of no longer being
1399 boost::shared_ptr<IOProcessor> iop;
1401 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1405 deleted.push_back (processor);
1406 i = _processors.erase (i);
1409 if (deleted.empty()) {
1410 /* none of those in the requested list were found */
1414 _output->set_user_latency (0);
1416 if (configure_processors_unlocked (err)) {
1417 /* get back to where we where */
1418 _processors = as_we_were;
1419 /* we know this will work, because it worked before :) */
1420 configure_processors_unlocked (0);
1424 _have_internal_generator = false;
1426 for (i = _processors.begin(); i != _processors.end(); ++i) {
1427 boost::shared_ptr<PluginInsert> pi;
1429 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1430 if (pi->is_generator()) {
1431 _have_internal_generator = true;
1438 /* now try to do what we need to so that those that were removed will be deleted */
1440 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1441 (*i)->drop_references ();
1444 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1445 set_processor_positions ();
1452 Route::configure_processors (ProcessorStreams* err)
1454 if (!_in_configure_processors) {
1455 Glib::RWLock::WriterLock lm (_processor_lock);
1456 return configure_processors_unlocked (err);
1462 Route::input_streams () const
1464 return _input->n_ports ();
1467 /** Configure the input/output configuration of each processor in the processors list.
1468 * Return 0 on success, otherwise configuration is impossible.
1471 Route::configure_processors_unlocked (ProcessorStreams* err)
1473 if (_in_configure_processors) {
1477 _in_configure_processors = true;
1479 // Check each processor in order to see if we can configure as requested
1480 ChanCount in = input_streams ();
1482 list< pair<ChanCount,ChanCount> > configuration;
1485 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1486 DEBUG_TRACE (DEBUG::Processors, "{\n");
1487 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1488 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1490 DEBUG_TRACE (DEBUG::Processors, "}\n");
1492 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1494 if ((*p)->can_support_io_configuration(in, out)) {
1495 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 in = %2 out = %3\n",(*p)->name(), in, out));
1496 configuration.push_back(make_pair(in, out));
1503 _in_configure_processors = false;
1508 // We can, so configure everything
1509 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1510 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1511 (*p)->configure_io(c->first, c->second);
1512 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1513 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1518 _meter->reset_max_channels (processor_max_streams);
1521 /* make sure we have sufficient scratch buffers to cope with the new processor
1524 Glib::Mutex::Lock em (_session.engine().process_lock ());
1525 _session.ensure_buffers (n_process_buffers ());
1528 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1530 _in_configure_processors = false;
1535 Route::all_processors_flip ()
1537 Glib::RWLock::ReaderLock lm (_processor_lock);
1539 if (_processors.empty()) {
1543 bool first_is_on = _processors.front()->active();
1545 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1547 (*i)->deactivate ();
1553 _session.set_dirty ();
1556 /** Set all processors with a given placement to a given active state.
1557 * @param p Placement of processors to change.
1558 * @param state New active state for those processors.
1561 Route::all_processors_active (Placement p, bool state)
1563 Glib::RWLock::ReaderLock lm (_processor_lock);
1565 if (_processors.empty()) {
1568 ProcessorList::iterator start, end;
1569 placement_range(p, start, end);
1571 bool before_amp = true;
1572 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1577 if (p == PreFader && before_amp) {
1581 (*i)->deactivate ();
1586 _session.set_dirty ();
1590 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1592 bool pre_fader = true;
1593 Glib::RWLock::ReaderLock lm (_processor_lock);
1595 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1597 /* semantic note: if p == amp, we want to return true, so test
1598 for equality before checking if this is the amp
1615 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1617 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1618 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1619 processors in the current actual processor list that are hidden. Any visible processors
1620 in the current list but not in "new_order" will be assumed to be deleted.
1624 Glib::RWLock::WriterLock lm (_processor_lock);
1625 ChanCount old_pms = processor_max_streams;
1626 ProcessorList::iterator oiter;
1627 ProcessorList::const_iterator niter;
1628 ProcessorList as_it_was_before = _processors;
1629 ProcessorList as_it_will_be;
1631 oiter = _processors.begin();
1632 niter = new_order.begin();
1634 while (niter != new_order.end()) {
1636 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1637 then append it to the temp list.
1639 Otherwise, see if the next processor in the old list is in the new list. if not,
1640 its been deleted. If its there, append it to the temp list.
1643 if (oiter == _processors.end()) {
1645 /* no more elements in the old list, so just stick the rest of
1646 the new order onto the temp list.
1649 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1650 while (niter != new_order.end()) {
1657 if (!(*oiter)->display_to_user()) {
1659 as_it_will_be.push_back (*oiter);
1663 /* visible processor: check that its in the new order */
1665 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1666 /* deleted: do nothing, shared_ptr<> will clean up */
1668 /* ignore this one, and add the next item from the new order instead */
1669 as_it_will_be.push_back (*niter);
1674 /* now remove from old order - its taken care of no matter what */
1675 oiter = _processors.erase (oiter);
1680 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1682 if (configure_processors_unlocked (err)) {
1683 _processors = as_it_was_before;
1684 processor_max_streams = old_pms;
1690 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1691 set_processor_positions ();
1704 Route::get_template()
1706 return state(false);
1710 Route::state(bool full_state)
1712 XMLNode *node = new XMLNode("Route");
1713 ProcessorList::iterator i;
1716 id().print (buf, sizeof (buf));
1717 node->add_property("id", buf);
1718 node->add_property ("name", _name);
1719 node->add_property("default-type", _default_type.to_string());
1722 node->add_property("flags", enum_2_string (_flags));
1725 node->add_property("active", _active?"yes":"no");
1727 boost::to_string (_phase_invert, p);
1728 node->add_property("phase-invert", p);
1729 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1730 node->add_property("meter-point", enum_2_string (_meter_point));
1733 node->add_property("route-group", _route_group->name());
1736 string order_string;
1737 OrderKeys::iterator x = order_keys.begin();
1739 while (x != order_keys.end()) {
1740 order_string += string ((*x).first);
1741 order_string += '=';
1742 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1743 order_string += buf;
1747 if (x == order_keys.end()) {
1751 order_string += ':';
1753 node->add_property ("order-keys", order_string);
1754 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1755 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1756 node->add_property ("soloed-by-upstream", buf);
1757 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1758 node->add_property ("soloed-by-downstream", buf);
1760 node->add_child_nocopy (_input->state (full_state));
1761 node->add_child_nocopy (_output->state (full_state));
1762 node->add_child_nocopy (_solo_control->get_state ());
1763 node->add_child_nocopy (_mute_master->get_state ());
1765 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1766 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1767 remote_control_node->add_property (X_("id"), buf);
1768 node->add_child_nocopy (*remote_control_node);
1770 if (_comment.length()) {
1771 XMLNode *cmt = node->add_child ("Comment");
1772 cmt->add_content (_comment);
1775 for (i = _processors.begin(); i != _processors.end(); ++i) {
1776 node->add_child_nocopy((*i)->state (full_state));
1780 node->add_child_copy (*_extra_xml);
1787 Route::set_state (const XMLNode& node, int version)
1789 return _set_state (node, version, true);
1793 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1795 if (version < 3000) {
1796 return _set_state_2X (node, version);
1800 XMLNodeConstIterator niter;
1802 XMLPropertyList plist;
1803 const XMLProperty *prop;
1805 if (node.name() != "Route"){
1806 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1810 if ((prop = node.property (X_("name"))) != 0) {
1811 Route::set_name (prop->value());
1814 if ((prop = node.property ("id")) != 0) {
1815 _id = prop->value ();
1818 if ((prop = node.property (X_("flags"))) != 0) {
1819 _flags = Flag (string_2_enum (prop->value(), _flags));
1824 if (is_master() || is_monitor() || is_hidden()) {
1825 _mute_master->set_solo_ignore (true);
1828 /* add all processors (except amp, which is always present) */
1830 nlist = node.children();
1831 XMLNode processor_state (X_("processor_state"));
1833 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1837 if (child->name() == IO::state_node_name) {
1838 if ((prop = child->property (X_("direction"))) == 0) {
1842 if (prop->value() == "Input") {
1843 _input->set_state (*child, version);
1844 } else if (prop->value() == "Output") {
1845 _output->set_state (*child, version);
1849 if (child->name() == X_("Processor")) {
1850 processor_state.add_child_copy (*child);
1854 set_processor_state (processor_state);
1856 if ((prop = node.property ("self-solo")) != 0) {
1857 set_self_solo (string_is_affirmative (prop->value()));
1860 if ((prop = node.property ("soloed-by-upstream")) != 0) {
1861 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
1862 mod_solo_by_others_upstream (atoi (prop->value()));
1865 if ((prop = node.property ("soloed-by-downstream")) != 0) {
1866 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
1867 mod_solo_by_others_downstream (atoi (prop->value()));
1870 if ((prop = node.property ("solo-isolated")) != 0) {
1871 set_solo_isolated (string_is_affirmative (prop->value()), this);
1874 if ((prop = node.property (X_("phase-invert"))) != 0) {
1875 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
1878 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1879 set_denormal_protection (string_is_affirmative (prop->value()));
1882 if ((prop = node.property (X_("active"))) != 0) {
1883 bool yn = string_is_affirmative (prop->value());
1884 _active = !yn; // force switch
1888 if ((prop = node.property (X_("meter-point"))) != 0) {
1889 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
1890 set_meter_point (mp);
1892 _meter->set_display_to_user (_meter_point == MeterCustom);
1896 if ((prop = node.property (X_("order-keys"))) != 0) {
1900 string::size_type colon, equal;
1901 string remaining = prop->value();
1903 while (remaining.length()) {
1905 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1906 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1909 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
1910 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1913 set_order_key (remaining.substr (0, equal), n);
1917 colon = remaining.find_first_of (':');
1919 if (colon != string::npos) {
1920 remaining = remaining.substr (colon+1);
1927 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1930 if (child->name() == X_("Comment")) {
1932 /* XXX this is a terrible API design in libxml++ */
1934 XMLNode *cmt = *(child->children().begin());
1935 _comment = cmt->content();
1937 } else if (child->name() == X_("Extra")) {
1939 _extra_xml = new XMLNode (*child);
1941 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1943 if (prop->value() == "solo") {
1944 _solo_control->set_state (*child, version);
1945 _session.add_controllable (_solo_control);
1948 } else if (child->name() == X_("RemoteControl")) {
1949 if ((prop = child->property (X_("id"))) != 0) {
1951 sscanf (prop->value().c_str(), "%d", &x);
1952 set_remote_control_id (x);
1955 } else if (child->name() == X_("MuteMaster")) {
1956 _mute_master->set_state (*child, version);
1964 Route::_set_state_2X (const XMLNode& node, int version)
1967 XMLNodeConstIterator niter;
1969 XMLPropertyList plist;
1970 const XMLProperty *prop;
1972 /* 2X things which still remain to be handled:
1978 if (node.name() != "Route") {
1979 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1983 if ((prop = node.property (X_("flags"))) != 0) {
1984 _flags = Flag (string_2_enum (prop->value(), _flags));
1989 if ((prop = node.property (X_("phase-invert"))) != 0) {
1990 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
1991 if (string_is_affirmative (prop->value ())) {
1994 set_phase_invert (p);
1997 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1998 set_denormal_protection (string_is_affirmative (prop->value()));
2001 if ((prop = node.property (X_("soloed"))) != 0) {
2002 bool yn = string_is_affirmative (prop->value());
2004 /* XXX force reset of solo status */
2006 set_solo (yn, this);
2009 if ((prop = node.property (X_("muted"))) != 0) {
2012 bool muted = string_is_affirmative (prop->value());
2018 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2020 if (string_is_affirmative (prop->value())){
2021 mute_point = mute_point + "PreFader";
2026 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2028 if (string_is_affirmative (prop->value())){
2031 mute_point = mute_point + ",";
2034 mute_point = mute_point + "PostFader";
2039 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2041 if (string_is_affirmative (prop->value())){
2044 mute_point = mute_point + ",";
2047 mute_point = mute_point + "Listen";
2052 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2054 if (string_is_affirmative (prop->value())){
2057 mute_point = mute_point + ",";
2060 mute_point = mute_point + "Main";
2064 _mute_master->set_mute_points (mute_point);
2068 if ((prop = node.property (X_("meter-point"))) != 0) {
2069 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2072 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2073 don't mean the same thing.
2076 if ((prop = node.property (X_("order-keys"))) != 0) {
2080 string::size_type colon, equal;
2081 string remaining = prop->value();
2083 while (remaining.length()) {
2085 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2086 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2089 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2090 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2093 set_order_key (remaining.substr (0, equal), n);
2097 colon = remaining.find_first_of (':');
2099 if (colon != string::npos) {
2100 remaining = remaining.substr (colon+1);
2107 /* add standard processors */
2109 //_meter.reset (new PeakMeter (_session));
2110 //add_processor (_meter, PreFader);
2113 /* where we listen to tracks */
2114 _intreturn.reset (new InternalReturn (_session));
2115 add_processor (_intreturn, PreFader);
2117 _monitor_control.reset (new MonitorProcessor (_session));
2118 add_processor (_monitor_control, PostFader);
2121 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
2122 add_processor (_main_outs, PostFader);
2126 nlist = node.children ();
2127 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2131 if (child->name() == IO::state_node_name) {
2133 /* there is a note in IO::set_state_2X() about why we have to call
2137 _input->set_state_2X (*child, version, true);
2138 _output->set_state_2X (*child, version, false);
2140 if ((prop = child->property (X_("name"))) != 0) {
2141 Route::set_name (prop->value ());
2144 if ((prop = child->property (X_("id"))) != 0) {
2145 _id = prop->value ();
2148 if ((prop = child->property (X_("active"))) != 0) {
2149 bool yn = string_is_affirmative (prop->value());
2150 _active = !yn; // force switch
2154 if ((prop = child->property (X_("gain"))) != 0) {
2157 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2158 _amp->gain_control()->set_value (val);
2162 /* Set up Panners in the IO */
2163 XMLNodeList io_nlist = child->children ();
2165 XMLNodeConstIterator io_niter;
2168 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2170 io_child = *io_niter;
2172 if (io_child->name() == X_("Panner")) {
2173 _main_outs->panner()->set_state(*io_child, version);
2179 XMLNodeList redirect_nodes;
2181 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2185 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2186 redirect_nodes.push_back(child);
2191 set_processor_state_2X (redirect_nodes, version);
2193 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2196 if (child->name() == X_("Comment")) {
2198 /* XXX this is a terrible API design in libxml++ */
2200 XMLNode *cmt = *(child->children().begin());
2201 _comment = cmt->content();
2203 } else if (child->name() == X_("Extra")) {
2205 _extra_xml = new XMLNode (*child);
2207 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2209 if (prop->value() == "solo") {
2210 _solo_control->set_state (*child, version);
2211 _session.add_controllable (_solo_control);
2214 } else if (child->name() == X_("RemoteControl")) {
2215 if ((prop = child->property (X_("id"))) != 0) {
2217 sscanf (prop->value().c_str(), "%d", &x);
2218 set_remote_control_id (x);
2228 Route::get_processor_state ()
2230 XMLNode* root = new XMLNode (X_("redirects"));
2231 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2232 root->add_child_nocopy ((*i)->state (true));
2239 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2241 /* We don't bother removing existing processors not in nList, as this
2242 method will only be called when creating a Route from scratch, not
2243 for undo purposes. Just put processors in at the appropriate place
2247 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2248 add_processor_from_xml_2X (**i, version, _processors.begin ());
2253 Route::set_processor_state (const XMLNode& node)
2255 const XMLNodeList &nlist = node.children();
2256 XMLNodeConstIterator niter;
2257 ProcessorList new_order;
2258 bool must_configure = false;
2260 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2262 XMLProperty* prop = (*niter)->property ("type");
2264 if (prop->value() == "amp") {
2265 _amp->set_state (**niter, Stateful::current_state_version);
2266 new_order.push_back (_amp);
2267 } else if (prop->value() == "meter") {
2268 _meter->set_state (**niter, Stateful::current_state_version);
2269 new_order.push_back (_meter);
2270 } else if (prop->value() == "main-outs") {
2271 _main_outs->set_state (**niter, Stateful::current_state_version);
2272 new_order.push_back (_main_outs);
2273 } else if (prop->value() == "intreturn") {
2275 _intreturn.reset (new InternalReturn (_session));
2276 must_configure = true;
2278 _intreturn->set_state (**niter, Stateful::current_state_version);
2279 new_order.push_back (_intreturn);
2280 } else if (is_monitor() && prop->value() == "monitor") {
2281 if (!_monitor_control) {
2282 _monitor_control.reset (new MonitorProcessor (_session));
2283 must_configure = true;
2285 _monitor_control->set_state (**niter, Stateful::current_state_version);
2286 new_order.push_back (_monitor_control);
2288 ProcessorList::iterator o;
2290 for (o = _processors.begin(); o != _processors.end(); ++o) {
2291 XMLProperty* id_prop = (*niter)->property(X_("id"));
2292 if (id_prop && (*o)->id() == id_prop->value()) {
2293 (*o)->set_state (**niter, Stateful::current_state_version);
2294 new_order.push_back (*o);
2299 // If the processor (*niter) is not on the route then create it
2301 if (o == _processors.end()) {
2303 boost::shared_ptr<Processor> processor;
2305 if (prop->value() == "intsend") {
2307 processor.reset (new InternalSend (_session, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2309 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2310 prop->value() == "lv2" ||
2311 prop->value() == "vst" ||
2312 prop->value() == "audiounit") {
2314 processor.reset (new PluginInsert(_session));
2316 } else if (prop->value() == "port") {
2318 processor.reset (new PortInsert (_session, _mute_master));
2320 } else if (prop->value() == "send") {
2322 processor.reset (new Send (_session, _mute_master));
2325 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2329 processor->set_state (**niter, Stateful::current_state_version);
2330 new_order.push_back (processor);
2331 must_configure = true;
2337 Glib::RWLock::WriterLock lm (_processor_lock);
2338 _processors = new_order;
2339 if (must_configure) {
2340 configure_processors_unlocked (0);
2344 processors_changed (RouteProcessorChange ());
2345 set_processor_positions ();
2349 Route::curve_reallocate ()
2351 // _gain_automation_curve.finish_resize ();
2352 // _pan_automation_curve.finish_resize ();
2356 Route::silence (nframes_t nframes)
2358 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2363 silence_unlocked (nframes);
2367 Route::silence_unlocked (nframes_t nframes)
2369 /* Must be called with the processor lock held */
2373 _output->silence (nframes);
2375 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2376 boost::shared_ptr<PluginInsert> pi;
2378 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2379 // skip plugins, they don't need anything when we're not active
2383 (*i)->silence (nframes);
2386 if (nframes == _session.get_block_size()) {
2393 Route::add_internal_return ()
2396 _intreturn.reset (new InternalReturn (_session));
2397 add_processor (_intreturn, PreFader);
2402 Route::get_return_buffer () const
2404 Glib::RWLock::ReaderLock rm (_processor_lock);
2406 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2407 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2410 BufferSet* bs = d->get_buffers ();
2419 Route::release_return_buffer () const
2421 Glib::RWLock::ReaderLock rm (_processor_lock);
2423 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2424 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2427 return d->release_buffers ();
2433 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2435 vector<string> ports;
2436 vector<string>::const_iterator i;
2439 Glib::RWLock::ReaderLock rm (_processor_lock);
2441 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2443 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2445 if (d && d->target_route() == route) {
2447 /* if the target is the control outs, then make sure
2448 we take note of which i-send is doing that.
2451 if (route == _session.monitor_out()) {
2452 _monitor_send = boost::dynamic_pointer_cast<Delivery>(d);
2455 /* already listening via the specified IO: do nothing */
2462 boost::shared_ptr<InternalSend> listener;
2468 if (route == _session.monitor_out()) {
2469 /* master never sends to control outs */
2472 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2476 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2479 } catch (failed_constructor& err) {
2483 if (route == _session.monitor_out()) {
2484 _monitor_send = listener;
2487 if (placement == PostFader) {
2488 /* put it *really* at the end, not just after the panner (main outs)
2490 add_processor (listener, _processors.end());
2492 add_processor (listener, PreFader);
2499 Route::drop_listen (boost::shared_ptr<Route> route)
2501 ProcessorStreams err;
2502 ProcessorList::iterator tmp;
2504 Glib::RWLock::ReaderLock rl(_processor_lock);
2508 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2510 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2512 if (d && d->target_route() == route) {
2514 remove_processor (*x, &err);
2517 /* list could have been demolished while we dropped the lock
2527 if (route == _session.monitor_out()) {
2528 _monitor_send.reset ();
2533 Route::set_comment (string cmt, void *src)
2536 comment_changed (src);
2537 _session.set_dirty ();
2541 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2543 FeedRecord fr (other, via_sends_only);
2545 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2547 if (!result.second) {
2549 /* already a record for "other" - make sure sends-only information is correct */
2550 if (!via_sends_only && result.first->sends_only) {
2551 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2552 frp->sends_only = false;
2556 return result.second;
2560 Route::clear_fed_by ()
2566 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2568 const FedBy& fed_by (other->fed_by());
2570 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2571 boost::shared_ptr<Route> sr = f->r.lock();
2573 if (sr && (sr.get() == this)) {
2575 if (via_sends_only) {
2576 *via_sends_only = f->sends_only;
2587 Route::direct_feeds (boost::shared_ptr<Route> other, bool* only_send)
2589 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2591 if (_output->connected_to (other->input())) {
2592 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2601 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2603 boost::shared_ptr<IOProcessor> iop;
2605 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2606 if (iop->feeds (other)) {
2607 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2613 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2616 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2621 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2626 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2628 framepos_t now = _session.transport_frame();
2631 Glib::RWLock::ReaderLock lm (_processor_lock);
2634 automation_snapshot (now, true);
2637 Automatable::transport_stopped (now);
2639 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2641 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2642 (*i)->deactivate ();
2647 (*i)->transport_stopped (now);
2651 _roll_delay = _initial_delay;
2655 Route::input_change_handler (IOChange change, void * /*src*/)
2657 if ((change & ConfigurationChanged)) {
2658 configure_processors (0);
2659 _phase_invert.resize (_input->n_ports().n_audio ());
2660 io_changed (); /* EMIT SIGNAL */
2665 Route::output_change_handler (IOChange change, void * /*src*/)
2667 if ((change & ConfigurationChanged)) {
2669 /* XXX resize all listeners to match _main_outs? */
2671 // configure_processors (0);
2676 Route::pans_required () const
2678 if (n_outputs().n_audio() < 2) {
2682 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2686 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2687 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2689 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2694 if (n_outputs().n_total() == 0) {
2698 if (!_active || n_inputs() == ChanCount::ZERO) {
2699 silence_unlocked (nframes);
2702 if (session_state_changing) {
2703 if (_session.transport_speed() != 0.0f) {
2704 /* we're rolling but some state is changing (e.g. our diskstream contents)
2705 so we cannot use them. Be silent till this is over.
2707 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2709 silence_unlocked (nframes);
2712 /* we're really not rolling, so we're either delivery silence or actually
2713 monitoring, both of which are safe to do while session_state_changing is true.
2717 _amp->apply_gain_automation (false);
2718 passthru (start_frame, end_frame, nframes, 0);
2724 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2726 if (_roll_delay > nframes) {
2728 _roll_delay -= nframes;
2729 silence_unlocked (nframes);
2730 /* transport frame is not legal for caller to use */
2733 } else if (_roll_delay > 0) {
2735 nframes -= _roll_delay;
2736 silence_unlocked (_roll_delay);
2737 /* we've written _roll_delay of samples into the
2738 output ports, so make a note of that for
2741 _main_outs->increment_output_offset (_roll_delay);
2742 transport_frame += _roll_delay;
2751 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2752 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2754 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2759 automation_snapshot (_session.transport_frame(), false);
2761 if (n_outputs().n_total() == 0) {
2765 if (!_active || n_inputs().n_total() == 0) {
2766 silence_unlocked (nframes);
2770 nframes_t unused = 0;
2772 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2778 passthru (start_frame, end_frame, nframes, declick);
2784 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2785 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2792 Route::toggle_monitor_input ()
2794 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2795 i->ensure_monitor_input( ! i->monitoring_input());
2800 Route::has_external_redirects () const
2802 // FIXME: what about sends? - they don't return a signal back to ardour?
2804 boost::shared_ptr<const PortInsert> pi;
2806 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2808 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2810 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2812 string port_name = port->name();
2813 string client_name = port_name.substr (0, port_name.find(':'));
2815 /* only say "yes" if the redirect is actually in use */
2817 if (client_name != "ardour" && pi->active()) {
2828 Route::flush_processors ()
2830 /* XXX shouldn't really try to take this lock, since
2831 this is called from the RT audio thread.
2834 Glib::RWLock::ReaderLock lm (_processor_lock);
2836 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2842 Route::set_meter_point (MeterPoint p)
2844 /* CAN BE CALLED FROM PROCESS CONTEXT */
2846 if (_meter_point == p) {
2850 bool meter_was_visible_to_user = _meter->display_to_user ();
2853 Glib::RWLock::WriterLock lm (_processor_lock);
2855 if (p != MeterCustom) {
2856 // Move meter in the processors list to reflect the new position
2857 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2858 _processors.erase(loc);
2861 loc = _processors.begin();
2864 loc = find (_processors.begin(), _processors.end(), _amp);
2866 case MeterPostFader:
2867 loc = _processors.end();
2875 if (loc == _processors.begin()) {
2876 m_in = _input->n_ports();
2878 ProcessorList::iterator before = loc;
2880 m_in = (*before)->output_streams ();
2883 _meter->reflect_inputs (m_in);
2885 _processors.insert (loc, _meter);
2887 /* we do not need to reconfigure the processors, because the meter
2888 (a) is always ready to handle processor_max_streams
2889 (b) is always an N-in/N-out processor, and thus moving
2890 it doesn't require any changes to the other processors.
2893 _meter->set_display_to_user (false);
2897 // just make it visible and let the user move it
2899 _meter->set_display_to_user (true);
2904 meter_change (); /* EMIT SIGNAL */
2906 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
2908 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
2912 Route::put_monitor_send_at (Placement p)
2914 if (!_monitor_send) {
2919 Glib::RWLock::WriterLock lm (_processor_lock);
2920 ProcessorList as_it_was (_processors);
2921 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _monitor_send);
2922 _processors.erase(loc);
2926 loc = find(_processors.begin(), _processors.end(), _amp);
2927 if (loc != _processors.begin()) {
2932 loc = _processors.end();
2936 _processors.insert (loc, _monitor_send);
2938 if (configure_processors_unlocked (0)) {
2939 _processors = as_it_was;
2940 configure_processors_unlocked (0); // it worked before we tried to add it ...
2945 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2946 _session.set_dirty ();
2950 Route::update_total_latency ()
2952 nframes_t old = _output->effective_latency();
2953 nframes_t own_latency = _output->user_latency();
2955 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2956 if ((*i)->active ()) {
2957 own_latency += (*i)->signal_latency ();
2961 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2963 _output->set_port_latency (own_latency);
2965 if (_output->user_latency() == 0) {
2967 /* this (virtual) function is used for pure Routes,
2968 not derived classes like AudioTrack. this means
2969 that the data processed here comes from an input
2970 port, not prerecorded material, and therefore we
2971 have to take into account any input latency.
2974 own_latency += _input->signal_latency ();
2977 if (old != own_latency) {
2978 _output->set_latency_delay (own_latency);
2979 signal_latency_changed (); /* EMIT SIGNAL */
2982 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2984 return _output->effective_latency ();
2988 Route::set_user_latency (nframes_t nframes)
2990 _output->set_user_latency (nframes);
2991 _session.update_latency_compensation (false, false);
2995 Route::set_latency_delay (nframes_t longest_session_latency)
2997 nframes_t old = _initial_delay;
2999 if (_output->effective_latency() < longest_session_latency) {
3000 _initial_delay = longest_session_latency - _output->effective_latency();
3005 if (_initial_delay != old) {
3006 initial_delay_changed (); /* EMIT SIGNAL */
3009 if (_session.transport_stopped()) {
3010 _roll_delay = _initial_delay;
3015 Route::automation_snapshot (nframes_t now, bool force)
3017 panner()->automation_snapshot (now, force);
3019 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3020 (*i)->automation_snapshot (now, force);
3024 Route::SoloControllable::SoloControllable (std::string name, Route& r)
3025 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
3026 boost::shared_ptr<AutomationList>(), name)
3029 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3034 Route::SoloControllable::set_value (double val)
3036 bool bval = ((val >= 0.5f) ? true: false);
3038 this is how it should be done
3040 boost::shared_ptr<RouteList> rl (new RouteList);
3041 rl->push_back (route);
3043 if (Config->get_solo_control_is_listen_control()) {
3044 _session.set_listen (rl, bval);
3046 _session.set_solo (rl, bval);
3049 route.set_solo (bval, this);
3054 Route::SoloControllable::get_value (void) const
3056 if (Config->get_solo_control_is_listen_control()) {
3057 return route.listening() ? 1.0f : 0.0f;
3059 return route.self_soloed() ? 1.0f : 0.0f;
3063 Route::MuteControllable::MuteControllable (std::string name, Route& r)
3064 : AutomationControl (r.session(), Evoral::Parameter (MuteAutomation),
3065 boost::shared_ptr<AutomationList>(), name)
3068 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3073 Route::MuteControllable::set_value (double val)
3075 bool bval = ((val >= 0.5f) ? true: false);
3077 this is how it should be done
3079 boost::shared_ptr<RouteList> rl (new RouteList);
3080 rl->push_back (route);
3081 _session.set_mute (rl, bval);
3083 route.set_mute (bval, this);
3088 Route::MuteControllable::get_value (void) const
3090 return route.muted() ? 1.0f : 0.0f;
3094 Route::set_block_size (nframes_t nframes)
3096 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3097 (*i)->set_block_size (nframes);
3100 _session.ensure_buffers (n_process_buffers ());
3104 Route::protect_automation ()
3106 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3107 (*i)->protect_automation();
3111 Route::set_pending_declick (int declick)
3114 /* this call is not allowed to turn off a pending declick unless "force" is true */
3116 _pending_declick = declick;
3118 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3120 _pending_declick = 0;
3125 /** Shift automation forwards from a particular place, thereby inserting time.
3126 * Adds undo commands for any shifts that are performed.
3128 * @param pos Position to start shifting from.
3129 * @param frames Amount to shift forwards by.
3133 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
3135 #ifdef THIS_NEEDS_FIXING_FOR_V3
3137 /* gain automation */
3138 XMLNode &before = _gain_control->get_state ();
3139 _gain_control->shift (pos, frames);
3140 XMLNode &after = _gain_control->get_state ();
3141 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3143 /* pan automation */
3144 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3145 Curve & c = (*i)->automation ();
3146 XMLNode &before = c.get_state ();
3147 c.shift (pos, frames);
3148 XMLNode &after = c.get_state ();
3149 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3152 /* redirect automation */
3154 Glib::RWLock::ReaderLock lm (redirect_lock);
3155 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3158 (*i)->what_has_automation (a);
3160 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3161 AutomationList & al = (*i)->automation_list (*j);
3162 XMLNode &before = al.get_state ();
3163 al.shift (pos, frames);
3164 XMLNode &after = al.get_state ();
3165 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
3175 Route::save_as_template (const string& path, const string& name)
3177 XMLNode& node (state (false));
3180 IO::set_name_in_state (*node.children().front(), name);
3182 tree.set_root (&node);
3183 return tree.write (path.c_str());
3188 Route::set_name (const string& str)
3194 name = Route::ensure_track_or_route_name (str, _session);
3195 SessionObject::set_name (name);
3197 ret = (_input->set_name(name) && _output->set_name(name));
3201 Glib::RWLock::ReaderLock lm (_processor_lock);
3203 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3205 /* rename all I/O processors that have inputs or outputs */
3207 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3209 if (iop && (iop->output() || iop->input())) {
3210 if (!iop->set_name (name)) {
3221 boost::shared_ptr<Send>
3222 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3224 Glib::RWLock::ReaderLock lm (_processor_lock);
3226 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3227 boost::shared_ptr<InternalSend> send;
3229 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3230 if (send->target_route() == target) {
3236 return boost::shared_ptr<Send>();
3239 /** @param c Audio channel index.
3240 * @param yn true to invert phase, otherwise false.
3243 Route::set_phase_invert (uint32_t c, bool yn)
3245 if (_phase_invert[c] != yn) {
3246 _phase_invert[c] = yn;
3247 phase_invert_changed (); /* EMIT SIGNAL */
3248 _session.set_dirty ();
3253 Route::set_phase_invert (boost::dynamic_bitset<> p)
3255 if (_phase_invert != p) {
3257 phase_invert_changed (); /* EMIT SIGNAL */
3258 _session.set_dirty ();
3263 Route::phase_invert (uint32_t c) const
3265 return _phase_invert[c];
3268 boost::dynamic_bitset<>
3269 Route::phase_invert () const
3271 return _phase_invert;
3275 Route::set_denormal_protection (bool yn)
3277 if (_denormal_protection != yn) {
3278 _denormal_protection = yn;
3279 denormal_protection_changed (); /* EMIT SIGNAL */
3284 Route::denormal_protection () const
3286 return _denormal_protection;
3290 Route::set_active (bool yn)
3292 if (_active != yn) {
3294 _input->set_active (yn);
3295 _output->set_active (yn);
3296 active_changed (); // EMIT SIGNAL
3303 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3309 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3311 boost::shared_ptr<Send> s;
3312 boost::shared_ptr<Return> r;
3314 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3315 s->meter()->meter();
3316 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3317 r->meter()->meter ();
3322 boost::shared_ptr<Panner>
3323 Route::panner() const
3325 return _main_outs->panner();
3328 boost::shared_ptr<AutomationControl>
3329 Route::gain_control() const
3331 return _amp->gain_control();
3334 boost::shared_ptr<AutomationControl>
3335 Route::get_control (const Evoral::Parameter& param)
3337 /* either we own the control or .... */
3339 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3343 /* maybe one of our processors does or ... */
3345 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3346 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3347 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3355 /* nobody does so we'll make a new one */
3357 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3364 boost::shared_ptr<Processor>
3365 Route::nth_plugin (uint32_t n)
3367 Glib::RWLock::ReaderLock lm (_processor_lock);
3368 ProcessorList::iterator i;
3370 for (i = _processors.begin(); i != _processors.end(); ++i) {
3371 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3378 return boost::shared_ptr<Processor> ();
3381 boost::shared_ptr<Processor>
3382 Route::nth_send (uint32_t n)
3384 Glib::RWLock::ReaderLock lm (_processor_lock);
3385 ProcessorList::iterator i;
3387 for (i = _processors.begin(); i != _processors.end(); ++i) {
3388 if (boost::dynamic_pointer_cast<Send> (*i)) {
3395 return boost::shared_ptr<Processor> ();
3399 Route::has_io_processor_named (const string& name)
3401 Glib::RWLock::ReaderLock lm (_processor_lock);
3402 ProcessorList::iterator i;
3404 for (i = _processors.begin(); i != _processors.end(); ++i) {
3405 if (boost::dynamic_pointer_cast<Send> (*i) ||
3406 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3407 if ((*i)->name() == name) {
3416 MuteMaster::MutePoint
3417 Route::mute_points () const
3419 return _mute_master->mute_points ();
3423 Route::set_processor_positions ()
3425 Glib::RWLock::ReaderLock lm (_processor_lock);
3427 bool had_amp = false;
3428 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3429 (*i)->set_pre_fader (!had_amp);
3430 if (boost::dynamic_pointer_cast<Amp> (*i)) {