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"
65 using namespace ARDOUR;
68 uint32_t Route::order_key_cnt = 0;
69 PBD::Signal1<void,string const&> Route::SyncOrderKeys;
70 PBD::Signal0<void> Route::RemoteControlIDChange;
72 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
73 : SessionObject (sess, name)
74 , AutomatableControls (sess)
79 , _pending_declick (true)
80 , _meter_point (MeterPostFader)
83 , _soloed_by_others_upstream (0)
84 , _soloed_by_others_downstream (0)
86 , _denormal_protection (false)
89 , _declickable (false)
90 , _solo_control (new SoloControllable (X_("solo"), *this))
91 , _mute_control (new MuteControllable (X_("mute"), *this))
92 , _mute_master (new MuteMaster (sess, name))
93 , _have_internal_generator (false)
95 , _default_type (default_type)
96 , _remote_control_id (0)
97 , _in_configure_processors (false)
99 processor_max_streams.reset();
100 order_keys[N_("signal")] = order_key_cnt++;
106 /* add standard controls */
108 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
109 _mute_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
111 add_control (_solo_control);
112 add_control (_mute_control);
114 /* input and output objects */
116 _input.reset (new IO (_session, _name, IO::Input, _default_type));
117 _output.reset (new IO (_session, _name, IO::Output, _default_type));
119 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
120 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
122 /* add amp processor */
124 _amp.reset (new Amp (_session));
125 add_processor (_amp, PostFader);
127 /* add standard processors: meter, main outs, monitor out */
129 _meter.reset (new PeakMeter (_session));
130 _meter->set_display_to_user (false);
132 add_processor (_meter, PostFader);
134 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
136 add_processor (_main_outs, PostFader);
139 /* where we listen to tracks */
140 _intreturn.reset (new InternalReturn (_session));
141 add_processor (_intreturn, PreFader);
143 ProcessorList::iterator i;
145 for (i = _processors.begin(); i != _processors.end(); ++i) {
146 if (*i == _intreturn) {
152 /* the thing that provides proper control over a control/monitor/listen bus
153 (such as per-channel cut, dim, solo, invert, etc).
154 It always goes right after the internal return;
156 _monitor_control.reset (new MonitorProcessor (_session));
157 add_processor (_monitor_control, i);
159 /* no panning on the monitor main outs */
161 _main_outs->panner()->set_bypassed (true);
164 if (is_master() || is_monitor() || is_hidden()) {
165 _mute_master->set_solo_ignore (true);
168 /* now that we have _meter, its safe to connect to this */
170 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
177 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
179 /* do this early so that we don't get incoming signals as we are going through destruction
184 /* don't use clear_processors here, as it depends on the session which may
185 be half-destroyed by now
188 Glib::RWLock::WriterLock lm (_processor_lock);
189 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
190 (*i)->drop_references ();
193 _processors.clear ();
197 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
199 if (id != _remote_control_id) {
200 _remote_control_id = id;
201 RemoteControlIDChanged ();
202 if (notify_class_listeners) {
203 RemoteControlIDChange ();
209 Route::remote_control_id() const
211 return _remote_control_id;
215 Route::order_key (std::string const & name) const
217 OrderKeys::const_iterator i = order_keys.find (name);
218 if (i == order_keys.end()) {
226 Route::set_order_key (std::string const & name, long n)
228 order_keys[name] = n;
230 if (Config->get_sync_all_route_ordering()) {
231 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
236 _session.set_dirty ();
239 /** Set all order keys to be the same as that for `base', if such a key
240 * exists in this route.
241 * @param base Base key.
244 Route::sync_order_keys (std::string const & base)
246 if (order_keys.empty()) {
250 OrderKeys::iterator i;
253 if ((i = order_keys.find (base)) == order_keys.end()) {
254 /* key doesn't exist, use the first existing key (during session initialization) */
255 i = order_keys.begin();
259 /* key exists - use it and reset all others (actually, itself included) */
261 i = order_keys.begin();
264 for (; i != order_keys.end(); ++i) {
270 Route::ensure_track_or_route_name(string name, Session &session)
272 string newname = name;
274 while (!session.io_name_is_legal (newname)) {
275 newname = bump_name_once (newname, '.');
283 Route::inc_gain (gain_t fraction, void *src)
285 _amp->inc_gain (fraction, src);
289 Route::set_gain (gain_t val, void *src)
291 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
293 if (_route_group->is_relative()) {
295 gain_t usable_gain = _amp->gain();
296 if (usable_gain < 0.000001f) {
297 usable_gain = 0.000001f;
301 if (delta < 0.000001f) {
305 delta -= usable_gain;
310 gain_t factor = delta / usable_gain;
313 factor = _route_group->get_max_factor(factor);
314 if (factor == 0.0f) {
315 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
319 factor = _route_group->get_min_factor(factor);
320 if (factor == 0.0f) {
321 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
326 _route_group->apply (&Route::inc_gain, factor, _route_group);
330 _route_group->apply (&Route::set_gain, val, _route_group);
336 if (val == _amp->gain()) {
340 _amp->set_gain (val, src);
343 /** Process this route for one (sub) cycle (process thread)
345 * @param bufs Scratch buffers to use for the signal path
346 * @param start_frame Initial transport frame
347 * @param end_frame Final transport frame
348 * @param nframes Number of frames to output (to ports)
350 * Note that (end_frame - start_frame) may not be equal to nframes when the
351 * transport speed isn't 1.0 (eg varispeed).
354 Route::process_output_buffers (BufferSet& bufs,
355 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
356 bool /*with_processors*/, int declick)
360 bufs.is_silent (false);
362 switch (Config->get_monitoring_model()) {
363 case HardwareMonitoring:
364 case ExternalMonitoring:
365 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
372 declick = _pending_declick;
375 /* figure out if we're going to use gain automation */
376 _amp->setup_gain_automation (start_frame, end_frame, nframes);
379 /* tell main outs what to do about monitoring */
380 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
383 /* -------------------------------------------------------------------------------------------
384 GLOBAL DECLICK (for transport changes etc.)
385 ----------------------------------------------------------------------------------------- */
388 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
389 } else if (declick < 0) {
390 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
393 _pending_declick = 0;
395 /* -------------------------------------------------------------------------------------------
396 DENORMAL CONTROL/PHASE INVERT
397 ----------------------------------------------------------------------------------------- */
403 if (_denormal_protection || Config->get_denormal_protection()) {
405 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
406 Sample* const sp = i->data();
408 if (_phase_invert & chn) {
409 for (nframes_t nx = 0; nx < nframes; ++nx) {
414 for (nframes_t nx = 0; nx < nframes; ++nx) {
422 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
423 Sample* const sp = i->data();
425 if (_phase_invert & (1<<chn)) {
426 for (nframes_t nx = 0; nx < nframes; ++nx) {
435 if (_denormal_protection || Config->get_denormal_protection()) {
437 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
438 Sample* const sp = i->data();
439 for (nframes_t nx = 0; nx < nframes; ++nx) {
447 /* -------------------------------------------------------------------------------------------
449 ----------------------------------------------------------------------------------------- */
451 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
453 if (bufs.count() != (*i)->input_streams()) {
454 cerr << _name << " bufs = " << bufs.count()
455 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
458 assert (bufs.count() == (*i)->input_streams());
460 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
461 bufs.set_count ((*i)->output_streams());
466 Route::n_process_buffers ()
468 return max (_input->n_ports(), processor_max_streams);
472 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
474 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
478 assert (bufs.available() >= input_streams());
480 if (_input->n_ports() == ChanCount::ZERO) {
481 silence_unlocked (nframes);
484 bufs.set_count (input_streams());
486 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
488 /* control/monitor bus ignores input ports when something is
489 feeding the listen "stream". data will "arrive" into the
490 route from the intreturn processor element.
492 bufs.silence (nframes, 0);
496 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
498 BufferSet::iterator o = bufs.begin(*t);
499 PortSet& ports (_input->ports());
501 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
502 o->read_from (i->get_buffer(nframes), nframes);
507 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
508 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
512 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
514 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
515 bufs.set_count (_input->n_ports());
516 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
517 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
521 Route::set_listen (bool yn, void* src)
528 if (yn != _monitor_send->active()) {
530 _monitor_send->activate ();
531 _mute_master->set_soloed (true);
533 _monitor_send->deactivate ();
534 _mute_master->set_soloed (false);
537 listen_changed (src); /* EMIT SIGNAL */
543 Route::listening () const
546 return _monitor_send->active ();
553 Route::set_solo_safe (bool yn, void *src)
555 if (_solo_safe != yn) {
557 solo_safe_changed (src);
562 Route::solo_safe() const
568 Route::set_solo (bool yn, void *src)
574 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
575 _route_group->apply (&Route::set_solo, yn, _route_group);
579 if (self_soloed() != yn) {
581 set_mute_master_solo ();
582 solo_changed (true, src); /* EMIT SIGNAL */
583 _solo_control->Changed (); /* EMIT SIGNAL */
588 Route::set_self_solo (bool yn)
594 Route::mod_solo_by_others_upstream (int32_t delta)
600 uint32_t old_sbu = _soloed_by_others_upstream;
603 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
604 _soloed_by_others_upstream += delta;
606 _soloed_by_others_upstream = 0;
609 _soloed_by_others_upstream += delta;
612 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
613 name(), delta, _soloed_by_others_upstream, old_sbu,
614 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
616 /* push the inverse solo change to everything that feeds us.
618 This is important for solo-within-group. When we solo 1 track out of N that
619 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
620 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
621 tracks that feed it. This will silence them if they were audible because
622 of a bus solo, but the newly soloed track will still be audible (because
625 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
629 if ((_self_solo || _soloed_by_others_downstream) &&
630 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
631 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
633 if (delta > 0 || !Config->get_exclusive_solo()) {
634 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
635 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
636 boost::shared_ptr<Route> sr = i->r.lock();
638 sr->mod_solo_by_others_downstream (-delta);
644 set_mute_master_solo ();
645 solo_changed (false, this);
649 Route::mod_solo_by_others_downstream (int32_t delta)
656 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
657 _soloed_by_others_downstream += delta;
659 _soloed_by_others_downstream = 0;
662 _soloed_by_others_downstream += delta;
665 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
667 set_mute_master_solo ();
668 solo_changed (false, this);
672 Route::set_mute_master_solo ()
674 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
678 Route::set_solo_isolated (bool yn, void *src)
680 if (is_master() || is_monitor() || is_hidden()) {
684 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
685 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
689 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
691 boost::shared_ptr<RouteList> routes = _session.get_routes ();
692 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
694 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
699 bool does_feed = direct_feeds (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
701 if (does_feed && !sends_only) {
702 (*i)->set_solo_isolated (yn, (*i)->route_group());
706 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
708 bool changed = false;
711 if (_solo_isolated == 0) {
712 _mute_master->set_solo_ignore (true);
717 if (_solo_isolated > 0) {
719 if (_solo_isolated == 0) {
720 _mute_master->set_solo_ignore (false);
727 solo_isolated_changed (src);
732 Route::solo_isolated () const
734 return _solo_isolated > 0;
738 Route::set_mute_points (MuteMaster::MutePoint mp)
740 _mute_master->set_mute_points (mp);
741 mute_points_changed (); /* EMIT SIGNAL */
743 if (_mute_master->muted_by_self()) {
744 mute_changed (this); /* EMIT SIGNAL */
749 Route::set_mute (bool yn, void *src)
751 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
752 _route_group->apply (&Route::set_mute, yn, _route_group);
757 _mute_master->set_muted_by_self (yn);
758 mute_changed (src); /* EMIT SIGNAL */
763 Route::muted () const
765 return _mute_master->muted_by_self();
770 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
772 cerr << name << " {" << endl;
773 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
774 p != procs.end(); ++p) {
775 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
782 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
784 ProcessorList::iterator loc;
786 /* XXX this is not thread safe - we don't hold the lock across determining the iter
787 to add before and actually doing the insertion. dammit.
790 if (placement == PreFader) {
791 /* generic pre-fader: insert immediately before the amp */
792 loc = find (_processors.begin(), _processors.end(), _amp);
794 /* generic post-fader: insert right before the main outs */
795 loc = find (_processors.begin(), _processors.end(), _main_outs);
798 return add_processor (processor, loc, err);
802 /** Add a processor to the route.
803 * @a iter must point to an iterator in _processors and the new
804 * processor will be inserted immediately before this location. Otherwise,
805 * @a position is used.
808 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
810 ChanCount old_pms = processor_max_streams;
812 if (!_session.engine().connected() || !processor) {
817 Glib::RWLock::WriterLock lm (_processor_lock);
819 boost::shared_ptr<PluginInsert> pi;
820 boost::shared_ptr<PortInsert> porti;
822 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
824 if (processor == _amp || processor == _meter || processor == _main_outs) {
825 // Ensure only one of these are in the list at any time
826 if (loc != _processors.end()) {
827 if (iter == loc) { // Already in place, do nothing
829 } else { // New position given, relocate
830 _processors.erase (loc);
835 if (loc != _processors.end()) {
836 cerr << "ERROR: Processor added to route twice!" << endl;
843 _processors.insert (loc, processor);
845 // Set up processor list channels. This will set processor->[input|output]_streams(),
846 // configure redirect ports properly, etc.
848 if (configure_processors_unlocked (err)) {
849 ProcessorList::iterator ploc = loc;
851 _processors.erase(ploc);
852 configure_processors_unlocked (0); // it worked before we tried to add it ...
853 cerr << "configure failed\n";
857 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
859 if (pi->natural_input_streams() == ChanCount::ZERO) {
860 /* generator plugin */
861 _have_internal_generator = true;
866 /* is this the monitor send ? if so, make sure we keep track of it */
868 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
870 if (isend && _session.monitor_out() && (isend->target_id() == _session.monitor_out()->id())) {
871 _monitor_send = isend;
874 if (activation_allowed && (processor != _monitor_send)) {
875 processor->activate ();
878 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
880 _output->set_user_latency (0);
883 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
884 set_processor_positions ();
890 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
892 const XMLProperty *prop;
895 boost::shared_ptr<Processor> processor;
897 if (node.name() == "Insert") {
899 if ((prop = node.property ("type")) != 0) {
901 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
902 prop->value() == "lv2" ||
903 prop->value() == "vst" ||
904 prop->value() == "audiounit") {
906 processor.reset (new PluginInsert (_session));
910 processor.reset (new PortInsert (_session, _mute_master));
915 } else if (node.name() == "Send") {
917 processor.reset (new Send (_session, _mute_master));
921 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
925 if (processor->set_state (node, version)) {
929 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
930 /* check for invisible processors stacked at the end and leave them there */
931 ProcessorList::iterator p;
932 p = _processors.end();
934 while (!(*p)->display_to_user() && p != _processors.begin()) {
941 return (add_processor (processor, iter) == 0);
944 catch (failed_constructor &err) {
945 warning << _("processor could not be created. Ignored.") << endmsg;
951 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
953 ProcessorList::iterator loc;
956 loc = find(_processors.begin(), _processors.end(), before);
958 /* nothing specified - at end but before main outs */
959 loc = find (_processors.begin(), _processors.end(), _main_outs);
962 return add_processors (others, loc, err);
966 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
968 /* NOTE: this is intended to be used ONLY when copying
969 processors from another Route. Hence the subtle
970 differences between this and ::add_processor()
973 ChanCount old_pms = processor_max_streams;
975 if (!_session.engine().connected()) {
979 if (others.empty()) {
984 Glib::RWLock::WriterLock lm (_processor_lock);
986 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
988 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
990 // Ensure meter only appears in the list once
992 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
993 if (m != _processors.end()) {
994 _processors.erase(m);
998 boost::shared_ptr<PluginInsert> pi;
1000 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1003 ChanCount m = max (pi->input_streams(), pi->output_streams());
1005 if (m > potential_max_streams) {
1006 potential_max_streams = m;
1010 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1012 if ((*i)->active()) {
1016 if (configure_processors_unlocked (err)) {
1017 _processors.erase (inserted);
1018 configure_processors_unlocked (0); // it worked before we tried to add it ...
1022 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
1025 _output->set_user_latency (0);
1028 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1029 set_processor_positions ();
1035 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1037 if (p == PreFader) {
1038 start = _processors.begin();
1039 end = find(_processors.begin(), _processors.end(), _amp);
1041 start = find(_processors.begin(), _processors.end(), _amp);
1043 end = _processors.end();
1047 /** Turn off all processors with a given placement
1048 * @param p Placement of processors to disable
1051 Route::disable_processors (Placement p)
1053 Glib::RWLock::ReaderLock lm (_processor_lock);
1055 ProcessorList::iterator start, end;
1056 placement_range(p, start, end);
1058 for (ProcessorList::iterator i = start; i != end; ++i) {
1059 (*i)->deactivate ();
1062 _session.set_dirty ();
1065 /** Turn off all redirects
1068 Route::disable_processors ()
1070 Glib::RWLock::ReaderLock lm (_processor_lock);
1072 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1073 (*i)->deactivate ();
1076 _session.set_dirty ();
1079 /** Turn off all redirects with a given placement
1080 * @param p Placement of redirects to disable
1083 Route::disable_plugins (Placement p)
1085 Glib::RWLock::ReaderLock lm (_processor_lock);
1087 ProcessorList::iterator start, end;
1088 placement_range(p, start, end);
1090 for (ProcessorList::iterator i = start; i != end; ++i) {
1091 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1092 (*i)->deactivate ();
1096 _session.set_dirty ();
1099 /** Turn off all plugins
1102 Route::disable_plugins ()
1104 Glib::RWLock::ReaderLock lm (_processor_lock);
1106 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1107 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1108 (*i)->deactivate ();
1112 _session.set_dirty ();
1117 Route::ab_plugins (bool forward)
1119 Glib::RWLock::ReaderLock lm (_processor_lock);
1123 /* forward = turn off all active redirects, and mark them so that the next time
1124 we go the other way, we will revert them
1127 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1128 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1132 if ((*i)->active()) {
1133 (*i)->deactivate ();
1134 (*i)->set_next_ab_is_active (true);
1136 (*i)->set_next_ab_is_active (false);
1142 /* backward = if the redirect was marked to go active on the next ab, do so */
1144 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1146 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1150 if ((*i)->get_next_ab_is_active()) {
1153 (*i)->deactivate ();
1158 _session.set_dirty ();
1162 /** Remove processors with a given placement.
1163 * @param p Placement of processors to remove.
1166 Route::clear_processors (Placement p)
1168 const ChanCount old_pms = processor_max_streams;
1170 if (!_session.engine().connected()) {
1174 bool already_deleting = _session.deletion_in_progress();
1175 if (!already_deleting) {
1176 _session.set_deletion_in_progress();
1180 Glib::RWLock::WriterLock lm (_processor_lock);
1181 ProcessorList new_list;
1182 ProcessorStreams err;
1183 bool seen_amp = false;
1185 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1191 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1193 /* you can't remove these */
1195 new_list.push_back (*i);
1202 new_list.push_back (*i);
1205 (*i)->drop_references ();
1213 (*i)->drop_references ();
1216 new_list.push_back (*i);
1223 _processors = new_list;
1224 configure_processors_unlocked (&err); // this can't fail
1227 processor_max_streams.reset();
1228 _have_internal_generator = false;
1229 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1230 set_processor_positions ();
1232 if (!already_deleting) {
1233 _session.clear_deletion_in_progress();
1238 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1240 /* these can never be removed */
1242 if (processor == _amp || processor == _meter || processor == _main_outs) {
1246 ChanCount old_pms = processor_max_streams;
1248 if (!_session.engine().connected()) {
1252 processor_max_streams.reset();
1255 Glib::RWLock::WriterLock lm (_processor_lock);
1256 ProcessorList::iterator i;
1257 bool removed = false;
1259 for (i = _processors.begin(); i != _processors.end(); ) {
1260 if (*i == processor) {
1262 /* move along, see failure case for configure_processors()
1263 where we may need to reconfigure the processor.
1266 /* stop redirects that send signals to JACK ports
1267 from causing noise as a result of no longer being
1271 boost::shared_ptr<IOProcessor> iop;
1273 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1275 iop->input()->disconnect (this);
1277 if (iop->output()) {
1278 iop->output()->disconnect (this);
1282 i = _processors.erase (i);
1290 _output->set_user_latency (0);
1298 if (configure_processors_unlocked (err)) {
1299 /* get back to where we where */
1300 _processors.insert (i, processor);
1301 /* we know this will work, because it worked before :) */
1302 configure_processors_unlocked (0);
1306 _have_internal_generator = false;
1308 for (i = _processors.begin(); i != _processors.end(); ++i) {
1309 boost::shared_ptr<PluginInsert> pi;
1311 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1312 if (pi->is_generator()) {
1313 _have_internal_generator = true;
1320 processor->drop_references ();
1321 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1322 set_processor_positions ();
1328 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1330 ProcessorList deleted;
1332 if (!_session.engine().connected()) {
1336 processor_max_streams.reset();
1339 Glib::RWLock::WriterLock lm (_processor_lock);
1340 ProcessorList::iterator i;
1341 boost::shared_ptr<Processor> processor;
1343 ProcessorList as_we_were = _processors;
1345 for (i = _processors.begin(); i != _processors.end(); ) {
1349 /* these can never be removed */
1351 if (processor == _amp || processor == _meter || processor == _main_outs) {
1356 /* see if its in the list of processors to delete */
1358 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1363 /* stop IOProcessors that send to JACK ports
1364 from causing noise as a result of no longer being
1368 boost::shared_ptr<IOProcessor> iop;
1370 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1374 deleted.push_back (processor);
1375 i = _processors.erase (i);
1378 if (deleted.empty()) {
1379 /* none of those in the requested list were found */
1383 _output->set_user_latency (0);
1385 if (configure_processors_unlocked (err)) {
1386 /* get back to where we where */
1387 _processors = as_we_were;
1388 /* we know this will work, because it worked before :) */
1389 configure_processors_unlocked (0);
1393 _have_internal_generator = false;
1395 for (i = _processors.begin(); i != _processors.end(); ++i) {
1396 boost::shared_ptr<PluginInsert> pi;
1398 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1399 if (pi->is_generator()) {
1400 _have_internal_generator = true;
1407 /* now try to do what we need to so that those that were removed will be deleted */
1409 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1410 (*i)->drop_references ();
1413 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1414 set_processor_positions ();
1421 Route::configure_processors (ProcessorStreams* err)
1423 if (!_in_configure_processors) {
1424 Glib::RWLock::WriterLock lm (_processor_lock);
1425 return configure_processors_unlocked (err);
1431 Route::input_streams () const
1433 return _input->n_ports ();
1436 /** Configure the input/output configuration of each processor in the processors list.
1437 * Return 0 on success, otherwise configuration is impossible.
1440 Route::configure_processors_unlocked (ProcessorStreams* err)
1442 if (_in_configure_processors) {
1446 _in_configure_processors = true;
1448 // Check each processor in order to see if we can configure as requested
1449 ChanCount in = input_streams ();
1451 list< pair<ChanCount,ChanCount> > configuration;
1454 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1455 DEBUG_TRACE (DEBUG::Processors, "{\n");
1456 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1457 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1459 DEBUG_TRACE (DEBUG::Processors, "}\n");
1461 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1463 if ((*p)->can_support_io_configuration(in, out)) {
1464 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 in = %2 out = %3\n",(*p)->name(), in, out));
1465 configuration.push_back(make_pair(in, out));
1472 _in_configure_processors = false;
1477 // We can, so configure everything
1478 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1479 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1480 (*p)->configure_io(c->first, c->second);
1481 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1482 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1487 _meter->reset_max_channels (processor_max_streams);
1490 /* make sure we have sufficient scratch buffers to cope with the new processor
1493 Glib::Mutex::Lock em (_session.engine().process_lock ());
1494 _session.ensure_buffers (n_process_buffers ());
1497 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1499 _in_configure_processors = false;
1504 Route::all_processors_flip ()
1506 Glib::RWLock::ReaderLock lm (_processor_lock);
1508 if (_processors.empty()) {
1512 bool first_is_on = _processors.front()->active();
1514 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1516 (*i)->deactivate ();
1522 _session.set_dirty ();
1525 /** Set all processors with a given placement to a given active state.
1526 * @param p Placement of processors to change.
1527 * @param state New active state for those processors.
1530 Route::all_processors_active (Placement p, bool state)
1532 Glib::RWLock::ReaderLock lm (_processor_lock);
1534 if (_processors.empty()) {
1537 ProcessorList::iterator start, end;
1538 placement_range(p, start, end);
1540 bool before_amp = true;
1541 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1546 if (p == PreFader && before_amp) {
1550 (*i)->deactivate ();
1555 _session.set_dirty ();
1559 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1561 bool pre_fader = true;
1562 Glib::RWLock::ReaderLock lm (_processor_lock);
1564 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1566 /* semantic note: if p == amp, we want to return true, so test
1567 for equality before checking if this is the amp
1584 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1586 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1587 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1588 processors in the current actual processor list that are hidden. Any visible processors
1589 in the current list but not in "new_order" will be assumed to be deleted.
1593 Glib::RWLock::WriterLock lm (_processor_lock);
1594 ChanCount old_pms = processor_max_streams;
1595 ProcessorList::iterator oiter;
1596 ProcessorList::const_iterator niter;
1597 ProcessorList as_it_was_before = _processors;
1598 ProcessorList as_it_will_be;
1600 oiter = _processors.begin();
1601 niter = new_order.begin();
1603 while (niter != new_order.end()) {
1605 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1606 then append it to the temp list.
1608 Otherwise, see if the next processor in the old list is in the new list. if not,
1609 its been deleted. If its there, append it to the temp list.
1612 if (oiter == _processors.end()) {
1614 /* no more elements in the old list, so just stick the rest of
1615 the new order onto the temp list.
1618 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1619 while (niter != new_order.end()) {
1626 if (!(*oiter)->display_to_user()) {
1628 as_it_will_be.push_back (*oiter);
1632 /* visible processor: check that its in the new order */
1634 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1635 /* deleted: do nothing, shared_ptr<> will clean up */
1637 /* ignore this one, and add the next item from the new order instead */
1638 as_it_will_be.push_back (*niter);
1643 /* now remove from old order - its taken care of no matter what */
1644 oiter = _processors.erase (oiter);
1649 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1651 if (configure_processors_unlocked (err)) {
1652 _processors = as_it_was_before;
1653 processor_max_streams = old_pms;
1659 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1660 set_processor_positions ();
1673 Route::get_template()
1675 return state(false);
1679 Route::state(bool full_state)
1681 XMLNode *node = new XMLNode("Route");
1682 ProcessorList::iterator i;
1685 id().print (buf, sizeof (buf));
1686 node->add_property("id", buf);
1687 node->add_property ("name", _name);
1688 node->add_property("default-type", _default_type.to_string());
1691 node->add_property("flags", enum_2_string (_flags));
1694 node->add_property("active", _active?"yes":"no");
1695 node->add_property("phase-invert", _phase_invert?"yes":"no");
1696 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1697 node->add_property("meter-point", enum_2_string (_meter_point));
1700 node->add_property("route-group", _route_group->name());
1703 string order_string;
1704 OrderKeys::iterator x = order_keys.begin();
1706 while (x != order_keys.end()) {
1707 order_string += string ((*x).first);
1708 order_string += '=';
1709 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1710 order_string += buf;
1714 if (x == order_keys.end()) {
1718 order_string += ':';
1720 node->add_property ("order-keys", order_string);
1721 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1722 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1723 node->add_property ("soloed-by-upstream", buf);
1724 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1725 node->add_property ("soloed-by-downstream", buf);
1727 node->add_child_nocopy (_input->state (full_state));
1728 node->add_child_nocopy (_output->state (full_state));
1729 node->add_child_nocopy (_solo_control->get_state ());
1730 node->add_child_nocopy (_mute_master->get_state ());
1732 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1733 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1734 remote_control_node->add_property (X_("id"), buf);
1735 node->add_child_nocopy (*remote_control_node);
1737 if (_comment.length()) {
1738 XMLNode *cmt = node->add_child ("Comment");
1739 cmt->add_content (_comment);
1742 for (i = _processors.begin(); i != _processors.end(); ++i) {
1743 node->add_child_nocopy((*i)->state (full_state));
1747 node->add_child_copy (*_extra_xml);
1754 Route::set_state (const XMLNode& node, int version)
1756 return _set_state (node, version, true);
1760 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1762 if (version < 3000) {
1763 return _set_state_2X (node, version);
1767 XMLNodeConstIterator niter;
1769 XMLPropertyList plist;
1770 const XMLProperty *prop;
1772 if (node.name() != "Route"){
1773 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1777 if ((prop = node.property (X_("name"))) != 0) {
1778 Route::set_name (prop->value());
1781 if ((prop = node.property ("id")) != 0) {
1782 _id = prop->value ();
1785 if ((prop = node.property (X_("flags"))) != 0) {
1786 _flags = Flag (string_2_enum (prop->value(), _flags));
1791 if (is_master() || is_monitor() || is_hidden()) {
1792 _mute_master->set_solo_ignore (true);
1795 /* add all processors (except amp, which is always present) */
1797 nlist = node.children();
1798 XMLNode processor_state (X_("processor_state"));
1800 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1804 if (child->name() == IO::state_node_name) {
1805 if ((prop = child->property (X_("direction"))) == 0) {
1809 if (prop->value() == "Input") {
1810 _input->set_state (*child, version);
1811 } else if (prop->value() == "Output") {
1812 _output->set_state (*child, version);
1816 if (child->name() == X_("Processor")) {
1817 processor_state.add_child_copy (*child);
1821 set_processor_state (processor_state);
1823 if ((prop = node.property ("self-solo")) != 0) {
1824 set_self_solo (string_is_affirmative (prop->value()));
1827 if ((prop = node.property ("soloed-by-upstream")) != 0) {
1828 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
1829 mod_solo_by_others_upstream (atoi (prop->value()));
1832 if ((prop = node.property ("soloed-by-downstream")) != 0) {
1833 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
1834 mod_solo_by_others_downstream (atoi (prop->value()));
1837 if ((prop = node.property ("solo-isolated")) != 0) {
1838 set_solo_isolated (string_is_affirmative (prop->value()), this);
1841 if ((prop = node.property (X_("phase-invert"))) != 0) {
1842 set_phase_invert (string_is_affirmative (prop->value()));
1845 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1846 set_denormal_protection (string_is_affirmative (prop->value()));
1849 if ((prop = node.property (X_("active"))) != 0) {
1850 bool yn = string_is_affirmative (prop->value());
1851 _active = !yn; // force switch
1855 if ((prop = node.property (X_("meter-point"))) != 0) {
1856 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
1857 set_meter_point (mp);
1859 _meter->set_display_to_user (_meter_point == MeterCustom);
1863 if ((prop = node.property (X_("order-keys"))) != 0) {
1867 string::size_type colon, equal;
1868 string remaining = prop->value();
1870 while (remaining.length()) {
1872 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1873 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1876 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1877 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1880 set_order_key (remaining.substr (0, equal), n);
1884 colon = remaining.find_first_of (':');
1886 if (colon != string::npos) {
1887 remaining = remaining.substr (colon+1);
1894 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1897 if (child->name() == X_("Comment")) {
1899 /* XXX this is a terrible API design in libxml++ */
1901 XMLNode *cmt = *(child->children().begin());
1902 _comment = cmt->content();
1904 } else if (child->name() == X_("Extra")) {
1906 _extra_xml = new XMLNode (*child);
1908 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1910 if (prop->value() == "solo") {
1911 _solo_control->set_state (*child, version);
1912 _session.add_controllable (_solo_control);
1915 } else if (child->name() == X_("RemoteControl")) {
1916 if ((prop = child->property (X_("id"))) != 0) {
1918 sscanf (prop->value().c_str(), "%d", &x);
1919 set_remote_control_id (x);
1922 } else if (child->name() == X_("MuteMaster")) {
1923 _mute_master->set_state (*child, version);
1931 Route::_set_state_2X (const XMLNode& node, int version)
1934 XMLNodeConstIterator niter;
1936 XMLPropertyList plist;
1937 const XMLProperty *prop;
1939 /* 2X things which still remain to be handled:
1945 if (node.name() != "Route") {
1946 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1950 if ((prop = node.property (X_("flags"))) != 0) {
1951 _flags = Flag (string_2_enum (prop->value(), _flags));
1956 if ((prop = node.property (X_("phase-invert"))) != 0) {
1957 set_phase_invert (string_is_affirmative (prop->value()));
1960 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1961 set_denormal_protection (string_is_affirmative (prop->value()));
1964 if ((prop = node.property (X_("soloed"))) != 0) {
1965 bool yn = string_is_affirmative (prop->value());
1967 /* XXX force reset of solo status */
1969 set_solo (yn, this);
1972 if ((prop = node.property (X_("muted"))) != 0) {
1975 bool muted = string_is_affirmative (prop->value());
1981 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1983 if (string_is_affirmative (prop->value())){
1984 mute_point = mute_point + "PreFader";
1989 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1991 if (string_is_affirmative (prop->value())){
1994 mute_point = mute_point + ",";
1997 mute_point = mute_point + "PostFader";
2002 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2004 if (string_is_affirmative (prop->value())){
2007 mute_point = mute_point + ",";
2010 mute_point = mute_point + "Listen";
2015 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2017 if (string_is_affirmative (prop->value())){
2020 mute_point = mute_point + ",";
2023 mute_point = mute_point + "Main";
2027 _mute_master->set_mute_points (mute_point);
2031 if ((prop = node.property (X_("meter-point"))) != 0) {
2032 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2035 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2036 don't mean the same thing.
2039 if ((prop = node.property (X_("order-keys"))) != 0) {
2043 string::size_type colon, equal;
2044 string remaining = prop->value();
2046 while (remaining.length()) {
2048 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2049 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2052 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2053 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2056 set_order_key (remaining.substr (0, equal), n);
2060 colon = remaining.find_first_of (':');
2062 if (colon != string::npos) {
2063 remaining = remaining.substr (colon+1);
2070 /* add standard processors */
2072 //_meter.reset (new PeakMeter (_session));
2073 //add_processor (_meter, PreFader);
2076 /* where we listen to tracks */
2077 _intreturn.reset (new InternalReturn (_session));
2078 add_processor (_intreturn, PreFader);
2080 _monitor_control.reset (new MonitorProcessor (_session));
2081 add_processor (_monitor_control, PostFader);
2084 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
2085 add_processor (_main_outs, PostFader);
2089 nlist = node.children ();
2090 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2094 if (child->name() == IO::state_node_name) {
2096 /* there is a note in IO::set_state_2X() about why we have to call
2100 _input->set_state_2X (*child, version, true);
2101 _output->set_state_2X (*child, version, false);
2103 if ((prop = child->property (X_("name"))) != 0) {
2104 Route::set_name (prop->value ());
2107 if ((prop = child->property (X_("id"))) != 0) {
2108 _id = prop->value ();
2111 if ((prop = child->property (X_("active"))) != 0) {
2112 bool yn = string_is_affirmative (prop->value());
2113 _active = !yn; // force switch
2117 if ((prop = child->property (X_("gain"))) != 0) {
2120 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2121 _amp->gain_control()->set_value (val);
2125 /* Set up Panners in the IO */
2126 XMLNodeList io_nlist = child->children ();
2128 XMLNodeConstIterator io_niter;
2131 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2133 io_child = *io_niter;
2135 if (io_child->name() == X_("Panner")) {
2136 _main_outs->panner()->set_state(*io_child, version);
2142 XMLNodeList redirect_nodes;
2144 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2148 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2149 redirect_nodes.push_back(child);
2154 set_processor_state_2X (redirect_nodes, version);
2156 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2159 if (child->name() == X_("Comment")) {
2161 /* XXX this is a terrible API design in libxml++ */
2163 XMLNode *cmt = *(child->children().begin());
2164 _comment = cmt->content();
2166 } else if (child->name() == X_("Extra")) {
2168 _extra_xml = new XMLNode (*child);
2170 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2172 if (prop->value() == "solo") {
2173 _solo_control->set_state (*child, version);
2174 _session.add_controllable (_solo_control);
2177 } else if (child->name() == X_("RemoteControl")) {
2178 if ((prop = child->property (X_("id"))) != 0) {
2180 sscanf (prop->value().c_str(), "%d", &x);
2181 set_remote_control_id (x);
2191 Route::get_processor_state ()
2193 XMLNode* root = new XMLNode (X_("redirects"));
2194 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2195 root->add_child_nocopy ((*i)->state (true));
2202 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2204 /* We don't bother removing existing processors not in nList, as this
2205 method will only be called when creating a Route from scratch, not
2206 for undo purposes. Just put processors in at the appropriate place
2210 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2211 add_processor_from_xml_2X (**i, version, _processors.begin ());
2216 Route::set_processor_state (const XMLNode& node)
2218 const XMLNodeList &nlist = node.children();
2219 XMLNodeConstIterator niter;
2220 ProcessorList new_order;
2221 bool must_configure = false;
2223 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2225 XMLProperty* prop = (*niter)->property ("type");
2227 if (prop->value() == "amp") {
2228 _amp->set_state (**niter, Stateful::current_state_version);
2229 new_order.push_back (_amp);
2230 } else if (prop->value() == "meter") {
2231 _meter->set_state (**niter, Stateful::current_state_version);
2232 new_order.push_back (_meter);
2233 } else if (prop->value() == "main-outs") {
2234 _main_outs->set_state (**niter, Stateful::current_state_version);
2235 new_order.push_back (_main_outs);
2236 } else if (prop->value() == "intreturn") {
2238 _intreturn.reset (new InternalReturn (_session));
2239 must_configure = true;
2241 _intreturn->set_state (**niter, Stateful::current_state_version);
2242 new_order.push_back (_intreturn);
2243 } else if (is_monitor() && prop->value() == "monitor") {
2244 if (!_monitor_control) {
2245 _monitor_control.reset (new MonitorProcessor (_session));
2246 must_configure = true;
2248 _monitor_control->set_state (**niter, Stateful::current_state_version);
2249 new_order.push_back (_monitor_control);
2251 ProcessorList::iterator o;
2253 for (o = _processors.begin(); o != _processors.end(); ++o) {
2254 XMLProperty* id_prop = (*niter)->property(X_("id"));
2255 if (id_prop && (*o)->id() == id_prop->value()) {
2256 (*o)->set_state (**niter, Stateful::current_state_version);
2257 new_order.push_back (*o);
2262 // If the processor (*niter) is not on the route then create it
2264 if (o == _processors.end()) {
2266 boost::shared_ptr<Processor> processor;
2268 if (prop->value() == "intsend") {
2270 processor.reset (new InternalSend (_session, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2272 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2273 prop->value() == "lv2" ||
2274 prop->value() == "vst" ||
2275 prop->value() == "audiounit") {
2277 processor.reset (new PluginInsert(_session));
2279 } else if (prop->value() == "port") {
2281 processor.reset (new PortInsert (_session, _mute_master));
2283 } else if (prop->value() == "send") {
2285 processor.reset (new Send (_session, _mute_master));
2288 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2292 processor->set_state (**niter, Stateful::current_state_version);
2293 new_order.push_back (processor);
2294 must_configure = true;
2300 Glib::RWLock::WriterLock lm (_processor_lock);
2301 _processors = new_order;
2302 if (must_configure) {
2303 configure_processors_unlocked (0);
2307 processors_changed (RouteProcessorChange ());
2308 set_processor_positions ();
2312 Route::curve_reallocate ()
2314 // _gain_automation_curve.finish_resize ();
2315 // _pan_automation_curve.finish_resize ();
2319 Route::silence (nframes_t nframes)
2321 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2326 silence_unlocked (nframes);
2330 Route::silence_unlocked (nframes_t nframes)
2332 /* Must be called with the processor lock held */
2336 _output->silence (nframes);
2338 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2339 boost::shared_ptr<PluginInsert> pi;
2341 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2342 // skip plugins, they don't need anything when we're not active
2346 (*i)->silence (nframes);
2349 if (nframes == _session.get_block_size()) {
2356 Route::add_internal_return ()
2359 _intreturn.reset (new InternalReturn (_session));
2360 add_processor (_intreturn, PreFader);
2365 Route::get_return_buffer () const
2367 Glib::RWLock::ReaderLock rm (_processor_lock);
2369 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2370 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2373 BufferSet* bs = d->get_buffers ();
2382 Route::release_return_buffer () const
2384 Glib::RWLock::ReaderLock rm (_processor_lock);
2386 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2387 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2390 return d->release_buffers ();
2396 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2398 vector<string> ports;
2399 vector<string>::const_iterator i;
2402 Glib::RWLock::ReaderLock rm (_processor_lock);
2404 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2406 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2408 if (d && d->target_route() == route) {
2410 /* if the target is the control outs, then make sure
2411 we take note of which i-send is doing that.
2414 if (route == _session.monitor_out()) {
2415 _monitor_send = boost::dynamic_pointer_cast<Delivery>(d);
2418 /* already listening via the specified IO: do nothing */
2425 boost::shared_ptr<InternalSend> listener;
2431 if (route == _session.monitor_out()) {
2432 /* master never sends to control outs */
2435 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2439 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2442 } catch (failed_constructor& err) {
2446 if (route == _session.monitor_out()) {
2447 _monitor_send = listener;
2450 if (placement == PostFader) {
2451 /* put it *really* at the end, not just after the panner (main outs)
2453 add_processor (listener, _processors.end());
2455 add_processor (listener, PreFader);
2462 Route::drop_listen (boost::shared_ptr<Route> route)
2464 ProcessorStreams err;
2465 ProcessorList::iterator tmp;
2467 Glib::RWLock::ReaderLock rl(_processor_lock);
2471 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2473 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2475 if (d && d->target_route() == route) {
2477 remove_processor (*x, &err);
2480 /* list could have been demolished while we dropped the lock
2490 if (route == _session.monitor_out()) {
2491 _monitor_send.reset ();
2496 Route::set_comment (string cmt, void *src)
2499 comment_changed (src);
2500 _session.set_dirty ();
2504 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2506 FeedRecord fr (other, via_sends_only);
2508 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2510 if (!result.second) {
2512 /* already a record for "other" - make sure sends-only information is correct */
2513 if (!via_sends_only && result.first->sends_only) {
2514 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2515 frp->sends_only = false;
2519 return result.second;
2523 Route::clear_fed_by ()
2529 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2531 const FedBy& fed_by (other->fed_by());
2533 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2534 boost::shared_ptr<Route> sr = f->r.lock();
2536 if (sr && (sr.get() == this)) {
2538 if (via_sends_only) {
2539 *via_sends_only = f->sends_only;
2550 Route::direct_feeds (boost::shared_ptr<Route> other, bool* only_send)
2552 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2554 if (_output->connected_to (other->input())) {
2555 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2564 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2566 boost::shared_ptr<IOProcessor> iop;
2568 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2569 if (iop->feeds (other)) {
2570 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2576 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2579 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2584 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2589 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2591 nframes_t now = _session.transport_frame();
2594 Glib::RWLock::ReaderLock lm (_processor_lock);
2597 automation_snapshot (now, true);
2600 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2602 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2603 (*i)->deactivate ();
2607 (*i)->transport_stopped (now);
2611 _roll_delay = _initial_delay;
2615 Route::input_change_handler (IOChange change, void * /*src*/)
2617 if ((change & ConfigurationChanged)) {
2618 configure_processors (0);
2623 Route::output_change_handler (IOChange change, void * /*src*/)
2625 if ((change & ConfigurationChanged)) {
2627 /* XXX resize all listeners to match _main_outs? */
2629 // configure_processors (0);
2634 Route::pans_required () const
2636 if (n_outputs().n_audio() < 2) {
2640 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2644 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2645 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2647 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2652 if (n_outputs().n_total() == 0) {
2656 if (!_active || n_inputs() == ChanCount::ZERO) {
2657 silence_unlocked (nframes);
2660 if (session_state_changing) {
2661 if (_session.transport_speed() != 0.0f) {
2662 /* we're rolling but some state is changing (e.g. our diskstream contents)
2663 so we cannot use them. Be silent till this is over.
2665 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2667 silence_unlocked (nframes);
2670 /* we're really not rolling, so we're either delivery silence or actually
2671 monitoring, both of which are safe to do while session_state_changing is true.
2675 _amp->apply_gain_automation (false);
2676 passthru (start_frame, end_frame, nframes, 0);
2682 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2684 if (_roll_delay > nframes) {
2686 _roll_delay -= nframes;
2687 silence_unlocked (nframes);
2688 /* transport frame is not legal for caller to use */
2691 } else if (_roll_delay > 0) {
2693 nframes -= _roll_delay;
2694 silence_unlocked (_roll_delay);
2695 /* we've written _roll_delay of samples into the
2696 output ports, so make a note of that for
2699 _main_outs->increment_output_offset (_roll_delay);
2700 transport_frame += _roll_delay;
2709 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2710 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2712 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2717 automation_snapshot (_session.transport_frame(), false);
2719 if (n_outputs().n_total() == 0) {
2723 if (!_active || n_inputs().n_total() == 0) {
2724 silence_unlocked (nframes);
2728 nframes_t unused = 0;
2730 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2736 passthru (start_frame, end_frame, nframes, declick);
2742 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2743 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2750 Route::toggle_monitor_input ()
2752 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2753 i->ensure_monitor_input( ! i->monitoring_input());
2758 Route::has_external_redirects () const
2760 // FIXME: what about sends? - they don't return a signal back to ardour?
2762 boost::shared_ptr<const PortInsert> pi;
2764 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2766 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2768 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2770 string port_name = port->name();
2771 string client_name = port_name.substr (0, port_name.find(':'));
2773 /* only say "yes" if the redirect is actually in use */
2775 if (client_name != "ardour" && pi->active()) {
2786 Route::flush_processors ()
2788 /* XXX shouldn't really try to take this lock, since
2789 this is called from the RT audio thread.
2792 Glib::RWLock::ReaderLock lm (_processor_lock);
2794 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2795 (*i)->deactivate ();
2801 Route::set_meter_point (MeterPoint p)
2803 /* CAN BE CALLED FROM PROCESS CONTEXT */
2805 if (_meter_point == p) {
2809 bool meter_was_visible_to_user = _meter->display_to_user ();
2812 Glib::RWLock::WriterLock lm (_processor_lock);
2814 if (p != MeterCustom) {
2815 // Move meter in the processors list to reflect the new position
2816 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2817 _processors.erase(loc);
2820 loc = _processors.begin();
2823 loc = find (_processors.begin(), _processors.end(), _amp);
2825 case MeterPostFader:
2826 loc = _processors.end();
2834 if (loc == _processors.begin()) {
2835 m_in = _input->n_ports();
2837 ProcessorList::iterator before = loc;
2839 m_in = (*before)->output_streams ();
2842 _meter->reflect_inputs (m_in);
2844 _processors.insert (loc, _meter);
2846 /* we do not need to reconfigure the processors, because the meter
2847 (a) is always ready to handle processor_max_streams
2848 (b) is always an N-in/N-out processor, and thus moving
2849 it doesn't require any changes to the other processors.
2852 _meter->set_display_to_user (false);
2856 // just make it visible and let the user move it
2858 _meter->set_display_to_user (true);
2863 meter_change (); /* EMIT SIGNAL */
2865 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
2867 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
2871 Route::put_monitor_send_at (Placement p)
2873 if (!_monitor_send) {
2878 Glib::RWLock::WriterLock lm (_processor_lock);
2879 ProcessorList as_it_was (_processors);
2880 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _monitor_send);
2881 _processors.erase(loc);
2885 loc = find(_processors.begin(), _processors.end(), _amp);
2886 if (loc != _processors.begin()) {
2891 loc = _processors.end();
2895 _processors.insert (loc, _monitor_send);
2897 if (configure_processors_unlocked (0)) {
2898 _processors = as_it_was;
2899 configure_processors_unlocked (0); // it worked before we tried to add it ...
2904 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2905 _session.set_dirty ();
2909 Route::update_total_latency ()
2911 nframes_t old = _output->effective_latency();
2912 nframes_t own_latency = _output->user_latency();
2914 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2915 if ((*i)->active ()) {
2916 own_latency += (*i)->signal_latency ();
2920 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2922 _output->set_port_latency (own_latency);
2924 if (_output->user_latency() == 0) {
2926 /* this (virtual) function is used for pure Routes,
2927 not derived classes like AudioTrack. this means
2928 that the data processed here comes from an input
2929 port, not prerecorded material, and therefore we
2930 have to take into account any input latency.
2933 own_latency += _input->signal_latency ();
2936 if (old != own_latency) {
2937 _output->set_latency_delay (own_latency);
2938 signal_latency_changed (); /* EMIT SIGNAL */
2941 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2943 return _output->effective_latency ();
2947 Route::set_user_latency (nframes_t nframes)
2949 _output->set_user_latency (nframes);
2950 _session.update_latency_compensation (false, false);
2954 Route::set_latency_delay (nframes_t longest_session_latency)
2956 nframes_t old = _initial_delay;
2958 if (_output->effective_latency() < longest_session_latency) {
2959 _initial_delay = longest_session_latency - _output->effective_latency();
2964 if (_initial_delay != old) {
2965 initial_delay_changed (); /* EMIT SIGNAL */
2968 if (_session.transport_stopped()) {
2969 _roll_delay = _initial_delay;
2974 Route::automation_snapshot (nframes_t now, bool force)
2976 panner()->automation_snapshot (now, force);
2978 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2979 (*i)->automation_snapshot (now, force);
2983 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2984 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2985 boost::shared_ptr<AutomationList>(), name)
2988 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2993 Route::SoloControllable::set_value (float val)
2995 bool bval = ((val >= 0.5f) ? true: false);
2997 this is how it should be done
2999 boost::shared_ptr<RouteList> rl (new RouteList);
3000 rl->push_back (route);
3002 if (Config->get_solo_control_is_listen_control()) {
3003 _session.set_listen (rl, bval);
3005 _session.set_solo (rl, bval);
3008 route.set_solo (bval, this);
3013 Route::SoloControllable::get_value (void) const
3015 if (Config->get_solo_control_is_listen_control()) {
3016 return route.listening() ? 1.0f : 0.0f;
3018 return route.self_soloed() ? 1.0f : 0.0f;
3022 Route::MuteControllable::MuteControllable (std::string name, Route& r)
3023 : AutomationControl (r.session(), Evoral::Parameter (MuteAutomation),
3024 boost::shared_ptr<AutomationList>(), name)
3027 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3032 Route::MuteControllable::set_value (float val)
3034 bool bval = ((val >= 0.5f) ? true: false);
3036 this is how it should be done
3038 boost::shared_ptr<RouteList> rl (new RouteList);
3039 rl->push_back (route);
3040 _session.set_mute (rl, bval);
3042 route.set_mute (bval, this);
3047 Route::MuteControllable::get_value (void) const
3049 return route.muted() ? 1.0f : 0.0f;
3053 Route::set_block_size (nframes_t nframes)
3055 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3056 (*i)->set_block_size (nframes);
3059 _session.ensure_buffers (n_process_buffers ());
3063 Route::protect_automation ()
3065 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3066 (*i)->protect_automation();
3070 Route::set_pending_declick (int declick)
3073 /* this call is not allowed to turn off a pending declick unless "force" is true */
3075 _pending_declick = declick;
3077 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3079 _pending_declick = 0;
3084 /** Shift automation forwards from a particular place, thereby inserting time.
3085 * Adds undo commands for any shifts that are performed.
3087 * @param pos Position to start shifting from.
3088 * @param frames Amount to shift forwards by.
3092 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
3094 #ifdef THIS_NEEDS_FIXING_FOR_V3
3096 /* gain automation */
3097 XMLNode &before = _gain_control->get_state ();
3098 _gain_control->shift (pos, frames);
3099 XMLNode &after = _gain_control->get_state ();
3100 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3102 /* pan automation */
3103 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3104 Curve & c = (*i)->automation ();
3105 XMLNode &before = c.get_state ();
3106 c.shift (pos, frames);
3107 XMLNode &after = c.get_state ();
3108 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3111 /* redirect automation */
3113 Glib::RWLock::ReaderLock lm (redirect_lock);
3114 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3117 (*i)->what_has_automation (a);
3119 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3120 AutomationList & al = (*i)->automation_list (*j);
3121 XMLNode &before = al.get_state ();
3122 al.shift (pos, frames);
3123 XMLNode &after = al.get_state ();
3124 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
3134 Route::save_as_template (const string& path, const string& name)
3136 XMLNode& node (state (false));
3139 IO::set_name_in_state (*node.children().front(), name);
3141 tree.set_root (&node);
3142 return tree.write (path.c_str());
3147 Route::set_name (const string& str)
3153 name = Route::ensure_track_or_route_name (str, _session);
3154 SessionObject::set_name (name);
3156 ret = (_input->set_name(name) && _output->set_name(name));
3160 Glib::RWLock::ReaderLock lm (_processor_lock);
3162 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3164 /* rename all I/O processors that have inputs or outputs */
3166 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3168 if (iop && (iop->output() || iop->input())) {
3169 if (!iop->set_name (name)) {
3180 boost::shared_ptr<Send>
3181 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3183 Glib::RWLock::ReaderLock lm (_processor_lock);
3185 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3186 boost::shared_ptr<InternalSend> send;
3188 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3189 if (send->target_route() == target) {
3195 return boost::shared_ptr<Send>();
3199 Route::set_phase_invert (bool yn)
3201 if (_phase_invert != yn) {
3203 _phase_invert = 0xffff; // XXX all channels
3205 _phase_invert = 0; // XXX no channels
3208 phase_invert_changed (); /* EMIT SIGNAL */
3209 _session.set_dirty ();
3214 Route::phase_invert () const
3216 return _phase_invert != 0;
3220 Route::set_denormal_protection (bool yn)
3222 if (_denormal_protection != yn) {
3223 _denormal_protection = yn;
3224 denormal_protection_changed (); /* EMIT SIGNAL */
3229 Route::denormal_protection () const
3231 return _denormal_protection;
3235 Route::set_active (bool yn)
3237 if (_active != yn) {
3239 _input->set_active (yn);
3240 _output->set_active (yn);
3241 active_changed (); // EMIT SIGNAL
3248 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3254 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3256 boost::shared_ptr<Send> s;
3257 boost::shared_ptr<Return> r;
3259 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3260 s->meter()->meter();
3261 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3262 r->meter()->meter ();
3267 boost::shared_ptr<Panner>
3268 Route::panner() const
3270 return _main_outs->panner();
3273 boost::shared_ptr<AutomationControl>
3274 Route::gain_control() const
3276 return _amp->gain_control();
3279 boost::shared_ptr<AutomationControl>
3280 Route::get_control (const Evoral::Parameter& param)
3282 /* either we own the control or .... */
3284 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3288 /* maybe one of our processors does or ... */
3290 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3291 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3292 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3300 /* nobody does so we'll make a new one */
3302 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3309 boost::shared_ptr<Processor>
3310 Route::nth_plugin (uint32_t n)
3312 Glib::RWLock::ReaderLock lm (_processor_lock);
3313 ProcessorList::iterator i;
3315 for (i = _processors.begin(); i != _processors.end(); ++i) {
3316 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3323 return boost::shared_ptr<Processor> ();
3326 boost::shared_ptr<Processor>
3327 Route::nth_send (uint32_t n)
3329 Glib::RWLock::ReaderLock lm (_processor_lock);
3330 ProcessorList::iterator i;
3332 for (i = _processors.begin(); i != _processors.end(); ++i) {
3333 if (boost::dynamic_pointer_cast<Send> (*i)) {
3340 return boost::shared_ptr<Processor> ();
3344 Route::has_io_processor_named (const string& name)
3346 Glib::RWLock::ReaderLock lm (_processor_lock);
3347 ProcessorList::iterator i;
3349 for (i = _processors.begin(); i != _processors.end(); ++i) {
3350 if (boost::dynamic_pointer_cast<Send> (*i) ||
3351 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3352 if ((*i)->name() == name) {
3361 MuteMaster::MutePoint
3362 Route::mute_points () const
3364 return _mute_master->mute_points ();
3368 Route::set_processor_positions ()
3370 Glib::RWLock::ReaderLock lm (_processor_lock);
3372 bool had_amp = false;
3373 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3374 (*i)->set_pre_fader (!had_amp);
3375 if (boost::dynamic_pointer_cast<Amp> (*i)) {