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 <sigc++/bind.h>
26 #include "pbd/xml++.h"
27 #include "pbd/enumwriter.h"
28 #include "pbd/memento_command.h"
30 #include "evoral/Curve.hpp"
32 #include "ardour/amp.h"
33 #include "ardour/audio_port.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/buffer.h"
36 #include "ardour/buffer_set.h"
37 #include "ardour/configuration.h"
38 #include "ardour/cycle_timer.h"
39 #include "ardour/debug.h"
40 #include "ardour/delivery.h"
41 #include "ardour/dB.h"
42 #include "ardour/internal_send.h"
43 #include "ardour/internal_return.h"
44 #include "ardour/ladspa_plugin.h"
45 #include "ardour/meter.h"
46 #include "ardour/mix.h"
47 #include "ardour/panner.h"
48 #include "ardour/plugin_insert.h"
49 #include "ardour/port.h"
50 #include "ardour/port_insert.h"
51 #include "ardour/processor.h"
52 #include "ardour/profile.h"
53 #include "ardour/route.h"
54 #include "ardour/route_group.h"
55 #include "ardour/send.h"
56 #include "ardour/session.h"
57 #include "ardour/timestamps.h"
58 #include "ardour/utils.h"
63 using namespace ARDOUR;
66 uint32_t Route::order_key_cnt = 0;
67 sigc::signal<void, string const &> Route::SyncOrderKeys;
69 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
70 : SessionObject (sess, name)
71 , AutomatableControls (sess)
73 , _solo_control (new SoloControllable (X_("solo"), *this))
74 , _mute_master (new MuteMaster (sess, name))
75 , _default_type (default_type)
80 /* add standard processors other than amp (added by ::init()) */
82 _meter.reset (new PeakMeter (_session));
83 _meter->set_display_to_user (_meter_point == MeterCustom);
84 add_processor (_meter, PreFader);
86 if (_flags & ControlOut) {
87 /* where we listen to tracks */
88 _intreturn.reset (new InternalReturn (_session));
89 add_processor (_intreturn, PreFader);
92 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
93 add_processor (_main_outs, PostFader);
95 /* now that we have _meter, its safe to connect to this */
97 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
100 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
101 : SessionObject (sess, "toBeReset")
102 , AutomatableControls (sess)
103 , _solo_control (new SoloControllable (X_("solo"), *this))
104 , _mute_master (new MuteMaster (sess, "toBeReset"))
105 , _default_type (default_type)
109 _set_state (node, Stateful::loading_state_version, false);
111 /* now that we have _meter, its safe to connect to this */
113 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
120 _soloed_by_others = 0;
121 _solo_isolated = false;
124 processor_max_streams.reset();
126 order_keys[N_("signal")] = order_key_cnt++;
128 _meter_point = MeterPostFader;
131 _have_internal_generator = false;
132 _declickable = false;
133 _pending_declick = true;
134 _remote_control_id = 0;
135 _in_configure_processors = false;
136 _mute_points = MuteMaster::AllPoints;
141 _denormal_protection = false;
143 /* add standard controls */
145 add_control (_solo_control);
146 add_control (_mute_master);
148 /* input and output objects */
150 _input.reset (new IO (_session, _name, IO::Input, _default_type));
151 _output.reset (new IO (_session, _name, IO::Output, _default_type));
153 _input->changed.connect (mem_fun (this, &Route::input_change_handler));
154 _output->changed.connect (mem_fun (this, &Route::output_change_handler));
156 /* add amp processor */
158 _amp.reset (new Amp (_session, _mute_master));
159 add_processor (_amp, PostFader);
164 Metering::disconnect (_meter_connection);
166 clear_processors (PreFader);
167 clear_processors (PostFader);
171 Route::set_remote_control_id (uint32_t id)
173 if (id != _remote_control_id) {
174 _remote_control_id = id;
175 RemoteControlIDChanged ();
180 Route::remote_control_id() const
182 return _remote_control_id;
186 Route::order_key (std::string const & name) const
188 OrderKeys::const_iterator i = order_keys.find (name);
189 if (i == order_keys.end()) {
197 Route::set_order_key (std::string const & name, long n)
199 order_keys[name] = n;
201 if (Config->get_sync_all_route_ordering()) {
202 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
207 _session.set_dirty ();
210 /** Set all order keys to be the same as that for `base', if such a key
211 * exists in this route.
212 * @param base Base key.
215 Route::sync_order_keys (std::string const & base)
217 if (order_keys.empty()) {
221 OrderKeys::iterator i;
224 if ((i = order_keys.find (base)) == order_keys.end()) {
225 /* key doesn't exist, use the first existing key (during session initialization) */
226 i = order_keys.begin();
230 /* key exists - use it and reset all others (actually, itself included) */
232 i = order_keys.begin();
235 for (; i != order_keys.end(); ++i) {
241 Route::ensure_track_or_route_name(string name, Session &session)
243 string newname = name;
245 while (session.route_by_name (newname) != NULL) {
246 newname = bump_name_once (newname);
254 Route::inc_gain (gain_t fraction, void *src)
256 _amp->inc_gain (fraction, src);
260 Route::set_gain (gain_t val, void *src)
262 if (src != 0 && _route_group && src != _route_group && _route_group->active_property (RouteGroup::Gain)) {
264 if (_route_group->is_relative()) {
266 gain_t usable_gain = _amp->gain();
267 if (usable_gain < 0.000001f) {
268 usable_gain = 0.000001f;
272 if (delta < 0.000001f) {
276 delta -= usable_gain;
281 gain_t factor = delta / usable_gain;
284 factor = _route_group->get_max_factor(factor);
285 if (factor == 0.0f) {
286 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
290 factor = _route_group->get_min_factor(factor);
291 if (factor == 0.0f) {
292 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
297 _route_group->apply (&Route::inc_gain, factor, _route_group);
301 _route_group->apply (&Route::set_gain, val, _route_group);
307 if (val == _amp->gain()) {
311 _amp->set_gain (val, src);
314 /** Process this route for one (sub) cycle (process thread)
316 * @param bufs Scratch buffers to use for the signal path
317 * @param start_frame Initial transport frame
318 * @param end_frame Final transport frame
319 * @param nframes Number of frames to output (to ports)
321 * Note that (end_frame - start_frame) may not be equal to nframes when the
322 * transport speed isn't 1.0 (eg varispeed).
325 Route::process_output_buffers (BufferSet& bufs,
326 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
327 bool /*with_processors*/, int declick)
331 bufs.is_silent (false);
333 switch (Config->get_monitoring_model()) {
334 case HardwareMonitoring:
335 case ExternalMonitoring:
336 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
343 declick = _pending_declick;
346 /* figure out if we're going to use gain automation */
347 _amp->setup_gain_automation (start_frame, end_frame, nframes);
350 /* tell main outs what to do about monitoring */
351 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
354 /* -------------------------------------------------------------------------------------------
355 GLOBAL DECLICK (for transport changes etc.)
356 ----------------------------------------------------------------------------------------- */
359 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
360 } else if (declick < 0) {
361 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
364 _pending_declick = 0;
366 /* -------------------------------------------------------------------------------------------
367 DENORMAL CONTROL/PHASE INVERT
368 ----------------------------------------------------------------------------------------- */
374 if (_denormal_protection || Config->get_denormal_protection()) {
376 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
377 Sample* const sp = i->data();
379 if (_phase_invert & chn) {
380 for (nframes_t nx = 0; nx < nframes; ++nx) {
385 for (nframes_t nx = 0; nx < nframes; ++nx) {
393 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
394 Sample* const sp = i->data();
396 if (_phase_invert & chn) {
397 for (nframes_t nx = 0; nx < nframes; ++nx) {
406 if (_denormal_protection || Config->get_denormal_protection()) {
408 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
409 Sample* const sp = i->data();
410 for (nframes_t nx = 0; nx < nframes; ++nx) {
418 /* -------------------------------------------------------------------------------------------
420 ----------------------------------------------------------------------------------------- */
422 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
425 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
426 if (bufs.count() != (*i)->input_streams()) {
427 cerr << _name << " bufs = " << bufs.count()
428 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
431 assert (bufs.count() == (*i)->input_streams());
432 (*i)->run (bufs, start_frame, end_frame, nframes);
433 bufs.set_count (ChanCount::max(bufs.count(), (*i)->output_streams()));
436 if (!_processors.empty()) {
437 bufs.set_count (ChanCount::max (bufs.count(), _processors.back()->output_streams()));
443 Route::n_process_buffers ()
445 return max (_input->n_ports(), processor_max_streams);
449 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
451 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
455 assert (bufs.available() >= _input->n_ports());
457 if (_input->n_ports() == ChanCount::ZERO) {
461 bufs.set_count (_input->n_ports());
463 if (is_control() && _session.listening()) {
465 /* control/monitor bus ignores input ports when something is
466 feeding the listen "stream". data will "arrive" into the
467 route from the intreturn processor element.
470 bufs.silence (nframes, 0);
474 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
476 BufferSet::iterator o = bufs.begin(*t);
477 PortSet& ports (_input->ports());
479 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
480 o->read_from (i->get_buffer(nframes), nframes);
485 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
486 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
490 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
492 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
493 bufs.set_count (_input->n_ports());
494 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
495 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
499 Route::set_listen (bool yn, void* src)
502 if (yn != _control_outs->active()) {
504 _control_outs->activate ();
506 _control_outs->deactivate ();
509 listen_changed (src); /* EMIT SIGNAL */
515 Route::listening () const
518 return _control_outs->active ();
525 Route::set_solo_safe (bool yn, void *src)
527 if (_solo_safe != yn) {
529 solo_safe_changed (src);
534 Route::solo_safe() const
540 Route::set_solo (bool yn, void *src)
546 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
547 _route_group->apply (&Route::set_solo, yn, _route_group);
551 if (self_soloed() != yn) {
553 set_delivery_solo ();
554 solo_changed (src); /* EMIT SIGNAL */
555 _solo_control->Changed (); /* EMIT SIGNAL */
560 Route::set_self_solo (bool yn)
566 Route::mod_solo_by_others (int32_t delta)
569 if (_soloed_by_others >= (uint32_t) delta) {
570 _soloed_by_others += delta;
572 _soloed_by_others = 0;
575 _soloed_by_others += delta;
578 set_delivery_solo ();
582 Route::set_delivery_solo ()
584 /* tell all delivery processors what the solo situation is, so that they keep
585 delivering even though Session::soloing() is true and they were not
589 Glib::RWLock::ReaderLock rm (_processor_lock);
590 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
591 boost::shared_ptr<Delivery> d;
593 if ((d = boost::dynamic_pointer_cast<Delivery> (*i)) != 0) {
594 d->set_solo_level (soloed ());
595 d->set_solo_isolated (solo_isolated());
601 Route::set_solo_isolated (bool yn, void *src)
603 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
604 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
608 if (yn != _solo_isolated) {
610 set_delivery_solo ();
611 solo_isolated_changed (src);
616 Route::solo_isolated () const
618 return _solo_isolated;
622 Route::set_mute_points (MuteMaster::MutePoint mp)
625 mute_points_changed (); /* EMIT SIGNAL */
627 if (_mute_master->muted()) {
628 _mute_master->mute_at (_mute_points);
629 mute_changed (this); /* EMIT SIGNAL */
634 Route::set_mute (bool yn, void *src)
636 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Mute)) {
637 _route_group->apply (&Route::set_mute, yn, _route_group);
643 _mute_master->mute_at (_mute_points);
645 _mute_master->clear_mute ();
648 mute_changed (src); /* EMIT SIGNAL */
655 return _mute_master->muted ();
660 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
662 cerr << name << " {" << endl;
663 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
664 p != procs.end(); ++p) {
665 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
672 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
674 ProcessorList::iterator loc;
676 /* XXX this is not thread safe - we don't hold the lock across determining the iter
677 to add before and actually doing the insertion. dammit.
680 if (placement == PreFader) {
681 /* generic pre-fader: insert immediately before the amp */
682 loc = find (_processors.begin(), _processors.end(), _amp);
684 /* generic post-fader: insert right before the main outs */
685 loc = find (_processors.begin(), _processors.end(), _main_outs);
688 return add_processor (processor, loc, err);
692 /** Add a processor to the route.
693 * If @a iter is not NULL, it must point to an iterator in _processors and the new
694 * processor will be inserted immediately before this location. Otherwise,
695 * @a position is used.
698 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
700 ChanCount old_pms = processor_max_streams;
702 if (!_session.engine().connected() || !processor) {
707 Glib::RWLock::WriterLock lm (_processor_lock);
709 boost::shared_ptr<PluginInsert> pi;
710 boost::shared_ptr<PortInsert> porti;
712 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
714 if (processor == _amp || processor == _meter || processor == _main_outs) {
715 // Ensure only one of these are in the list at any time
716 if (loc != _processors.end()) {
717 if (iter == loc) { // Already in place, do nothing
719 } else { // New position given, relocate
720 _processors.erase (loc);
725 if (loc != _processors.end()) {
726 cerr << "ERROR: Processor added to route twice!" << endl;
733 _processors.insert (loc, processor);
735 // Set up processor list channels. This will set processor->[input|output]_streams(),
736 // configure redirect ports properly, etc.
738 if (configure_processors_unlocked (err)) {
739 ProcessorList::iterator ploc = loc;
741 _processors.erase(ploc);
742 configure_processors_unlocked (0); // it worked before we tried to add it ...
743 cerr << "configure failed\n";
747 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
749 if (pi->natural_input_streams() == ChanCount::ZERO) {
750 /* generator plugin */
751 _have_internal_generator = true;
756 if (_control_outs != processor) {
757 // XXX: do we want to emit the signal here ? change call order.
758 processor->activate ();
760 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
762 _output->set_user_latency (0);
765 processors_changed (); /* EMIT SIGNAL */
771 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
773 const XMLProperty *prop;
775 if (node.name() != "Processor") {
780 if ((prop = node.property ("type")) != 0) {
782 boost::shared_ptr<Processor> processor;
784 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
785 prop->value() == "lv2" ||
786 prop->value() == "vst" ||
787 prop->value() == "audiounit") {
789 processor.reset (new PluginInsert(_session, node));
791 } else if (prop->value() == "port") {
793 processor.reset (new PortInsert (_session, _mute_master, node));
795 } else if (prop->value() == "send") {
797 processor.reset (new Send (_session, _mute_master, node));
799 } else if (prop->value() == "meter") {
802 if (_meter->set_state (node, Stateful::loading_state_version)) {
809 _meter.reset (new PeakMeter (_session, node));
810 _meter->set_display_to_user (_meter_point == MeterCustom);
813 } else if (prop->value() == "amp") {
815 /* amp always exists */
818 if (processor->set_state (node, Stateful::loading_state_version)) {
821 /* never any reason to add it */
825 } else if (prop->value() == "intsend") {
827 processor.reset (new InternalSend (_session, _mute_master, node));
829 } else if (prop->value() == "intreturn") {
832 if (_intreturn->set_state (node, Stateful::loading_state_version)) {
838 _intreturn.reset (new InternalReturn (_session, node));
839 processor = _intreturn;
841 } else if (prop->value() == "main-outs") {
844 if (_main_outs->set_state (node, Stateful::loading_state_version)) {
851 _main_outs.reset (new Delivery (_session, _output, _mute_master, node));
852 processor = _main_outs;
855 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
859 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
860 /* check for invisible processors stacked at the end and leave them there */
861 ProcessorList::iterator p;
862 p = _processors.end();
864 while (!(*p)->display_to_user() && p != _processors.begin()) {
871 return (add_processor (processor, iter) == 0);
874 error << _("Processor XML node has no type property") << endmsg;
879 catch (failed_constructor &err) {
880 warning << _("processor could not be created. Ignored.") << endmsg;
887 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
889 const XMLProperty *prop;
892 boost::shared_ptr<Processor> processor;
894 if (node.name() == "Insert") {
896 if ((prop = node.property ("type")) != 0) {
898 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
899 prop->value() == "lv2" ||
900 prop->value() == "vst" ||
901 prop->value() == "audiounit") {
903 processor.reset (new PluginInsert (_session, node));
907 processor.reset (new PortInsert (_session, _mute_master, node));
912 } else if (node.name() == "Send") {
914 processor.reset (new Send (_session, _mute_master, node, version));
918 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
922 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
923 /* check for invisible processors stacked at the end and leave them there */
924 ProcessorList::iterator p;
925 p = _processors.end();
927 while (!(*p)->display_to_user() && p != _processors.begin()) {
934 return (add_processor (processor, iter) == 0);
937 catch (failed_constructor &err) {
938 warning << _("processor could not be created. Ignored.") << endmsg;
944 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
946 ProcessorList::iterator loc;
949 loc = find(_processors.begin(), _processors.end(), before);
951 /* nothing specified - at end but before main outs */
952 loc = find (_processors.begin(), _processors.end(), _main_outs);
955 return add_processors (others, loc, err);
959 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
961 /* NOTE: this is intended to be used ONLY when copying
962 processors from another Route. Hence the subtle
963 differences between this and ::add_processor()
966 ChanCount old_pms = processor_max_streams;
968 if (!_session.engine().connected()) {
972 if (others.empty()) {
977 Glib::RWLock::WriterLock lm (_processor_lock);
978 ProcessorList::iterator existing_end = _processors.end();
981 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
983 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
985 // Ensure meter only appears in the list once
987 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
988 if (m != _processors.end()) {
989 _processors.erase(m);
993 boost::shared_ptr<PluginInsert> pi;
995 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
998 ChanCount m = max (pi->input_streams(), pi->output_streams());
1000 if (m > potential_max_streams) {
1001 potential_max_streams = m;
1005 _processors.insert (iter, *i);
1007 if (configure_processors_unlocked (err)) {
1009 _processors.erase (existing_end, _processors.end());
1010 configure_processors_unlocked (0); // it worked before we tried to add it ...
1014 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1017 _output->set_user_latency (0);
1020 processors_changed (); /* EMIT SIGNAL */
1026 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1028 if (p == PreFader) {
1029 start = _processors.begin();
1030 end = find(_processors.begin(), _processors.end(), _amp);
1032 start = find(_processors.begin(), _processors.end(), _amp);
1034 end = _processors.end();
1038 /** Turn off all processors with a given placement
1039 * @param p Placement of processors to disable
1042 Route::disable_processors (Placement p)
1044 Glib::RWLock::ReaderLock lm (_processor_lock);
1046 ProcessorList::iterator start, end;
1047 placement_range(p, start, end);
1049 for (ProcessorList::iterator i = start; i != end; ++i) {
1050 (*i)->deactivate ();
1053 _session.set_dirty ();
1056 /** Turn off all redirects
1059 Route::disable_processors ()
1061 Glib::RWLock::ReaderLock lm (_processor_lock);
1063 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1064 (*i)->deactivate ();
1067 _session.set_dirty ();
1070 /** Turn off all redirects with a given placement
1071 * @param p Placement of redirects to disable
1074 Route::disable_plugins (Placement p)
1076 Glib::RWLock::ReaderLock lm (_processor_lock);
1078 ProcessorList::iterator start, end;
1079 placement_range(p, start, end);
1081 for (ProcessorList::iterator i = start; i != end; ++i) {
1082 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1083 (*i)->deactivate ();
1087 _session.set_dirty ();
1090 /** Turn off all plugins
1093 Route::disable_plugins ()
1095 Glib::RWLock::ReaderLock lm (_processor_lock);
1097 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1098 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1099 (*i)->deactivate ();
1103 _session.set_dirty ();
1108 Route::ab_plugins (bool forward)
1110 Glib::RWLock::ReaderLock lm (_processor_lock);
1114 /* forward = turn off all active redirects, and mark them so that the next time
1115 we go the other way, we will revert them
1118 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1119 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1123 if ((*i)->active()) {
1124 (*i)->deactivate ();
1125 (*i)->set_next_ab_is_active (true);
1127 (*i)->set_next_ab_is_active (false);
1133 /* backward = if the redirect was marked to go active on the next ab, do so */
1135 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1137 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1141 if ((*i)->get_next_ab_is_active()) {
1144 (*i)->deactivate ();
1149 _session.set_dirty ();
1153 /** Remove processors with a given placement.
1154 * @param p Placement of processors to remove.
1157 Route::clear_processors (Placement p)
1159 const ChanCount old_pms = processor_max_streams;
1161 if (!_session.engine().connected()) {
1165 bool already_deleting = _session.deletion_in_progress();
1166 if (!already_deleting) {
1167 _session.set_deletion_in_progress();
1171 Glib::RWLock::WriterLock lm (_processor_lock);
1172 ProcessorList new_list;
1173 ProcessorStreams err;
1174 bool seen_amp = false;
1176 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1182 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1184 /* you can't remove these */
1186 new_list.push_back (*i);
1193 new_list.push_back (*i);
1196 (*i)->drop_references ();
1204 (*i)->drop_references ();
1207 new_list.push_back (*i);
1214 _processors = new_list;
1215 configure_processors_unlocked (&err); // this can't fail
1218 processor_max_streams.reset();
1219 _have_internal_generator = false;
1220 processors_changed (); /* EMIT SIGNAL */
1222 if (!already_deleting) {
1223 _session.clear_deletion_in_progress();
1228 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1230 /* these can never be removed */
1232 if (processor == _amp || processor == _meter || processor == _main_outs) {
1236 ChanCount old_pms = processor_max_streams;
1238 if (!_session.engine().connected()) {
1242 processor_max_streams.reset();
1245 Glib::RWLock::WriterLock lm (_processor_lock);
1246 ProcessorList::iterator i;
1247 bool removed = false;
1249 for (i = _processors.begin(); i != _processors.end(); ) {
1250 if (*i == processor) {
1252 /* move along, see failure case for configure_processors()
1253 where we may need to reconfigure the processor.
1256 /* stop redirects that send signals to JACK ports
1257 from causing noise as a result of no longer being
1261 boost::shared_ptr<IOProcessor> iop;
1263 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1265 iop->input()->disconnect (this);
1267 if (iop->output()) {
1268 iop->output()->disconnect (this);
1272 i = _processors.erase (i);
1280 _output->set_user_latency (0);
1288 if (configure_processors_unlocked (err)) {
1289 /* get back to where we where */
1290 _processors.insert (i, processor);
1291 /* we know this will work, because it worked before :) */
1292 configure_processors_unlocked (0);
1296 _have_internal_generator = false;
1298 for (i = _processors.begin(); i != _processors.end(); ++i) {
1299 boost::shared_ptr<PluginInsert> pi;
1301 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1302 if (pi->is_generator()) {
1303 _have_internal_generator = true;
1310 processor->drop_references ();
1311 processors_changed (); /* EMIT SIGNAL */
1317 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1319 ProcessorList deleted;
1320 ProcessorList as_we_were;
1322 if (!_session.engine().connected()) {
1326 processor_max_streams.reset();
1329 Glib::RWLock::WriterLock lm (_processor_lock);
1330 ProcessorList::iterator i;
1331 boost::shared_ptr<Processor> processor;
1333 as_we_were = _processors;
1335 for (i = _processors.begin(); i != _processors.end(); ) {
1339 /* these can never be removed */
1341 if (processor == _amp || processor == _meter || processor == _main_outs) {
1346 /* see if its in the list of processors to delete */
1348 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1353 /* stop IOProcessors that send to JACK ports
1354 from causing noise as a result of no longer being
1358 boost::shared_ptr<IOProcessor> iop;
1360 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1364 deleted.push_back (processor);
1365 i = _processors.erase (i);
1368 if (deleted.empty()) {
1369 /* none of those in the requested list were found */
1373 _output->set_user_latency (0);
1375 if (configure_processors_unlocked (err)) {
1376 /* get back to where we where */
1377 _processors = as_we_were;
1378 /* we know this will work, because it worked before :) */
1379 configure_processors_unlocked (0);
1383 _have_internal_generator = false;
1385 for (i = _processors.begin(); i != _processors.end(); ++i) {
1386 boost::shared_ptr<PluginInsert> pi;
1388 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1389 if (pi->is_generator()) {
1390 _have_internal_generator = true;
1397 /* now try to do what we need to so that those that were removed will be deleted */
1399 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1400 (*i)->drop_references ();
1403 processors_changed (); /* EMIT SIGNAL */
1410 Route::configure_processors (ProcessorStreams* err)
1412 if (!_in_configure_processors) {
1413 Glib::RWLock::WriterLock lm (_processor_lock);
1414 return configure_processors_unlocked (err);
1419 /** Configure the input/output configuration of each processor in the processors list.
1420 * Return 0 on success, otherwise configuration is impossible.
1423 Route::configure_processors_unlocked (ProcessorStreams* err)
1425 if (_in_configure_processors) {
1429 _in_configure_processors = true;
1431 // Check each processor in order to see if we can configure as requested
1432 ChanCount in = _input->n_ports ();
1434 list< pair<ChanCount,ChanCount> > configuration;
1437 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1439 DEBUG_TRACE (DEBUG::Processors, "{\n");
1440 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1441 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1443 DEBUG_TRACE (DEBUG::Processors, "}\n");
1446 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1448 if ((*p)->can_support_io_configuration(in, out)) {
1449 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1in = %2 out = %3\n",(*p)->name(), in, out));
1450 configuration.push_back(make_pair(in, out));
1457 _in_configure_processors = false;
1462 /* Take the process lock so that if we add a processor which increases the required
1463 number of scratch buffers, we create those scratch buffers before the process
1464 thread has a chance to ask for them.
1465 XXX: in an ideal world we'd perhaps use some RCU magic to avoid having to take
1469 Glib::Mutex::Lock pl (_session.engine().process_lock ());
1471 // We can, so configure everything
1472 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1473 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1474 (*p)->configure_io(c->first, c->second);
1475 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1476 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1480 /* make sure we have sufficient scratch buffers to cope with the new processor
1482 _session.ensure_buffers (n_process_buffers ());
1484 _in_configure_processors = false;
1489 Route::all_processors_flip ()
1491 Glib::RWLock::ReaderLock lm (_processor_lock);
1493 if (_processors.empty()) {
1497 bool first_is_on = _processors.front()->active();
1499 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1501 (*i)->deactivate ();
1507 _session.set_dirty ();
1510 /** Set all processors with a given placement to a given active state.
1511 * @param p Placement of processors to change.
1512 * @param state New active state for those processors.
1515 Route::all_processors_active (Placement p, bool state)
1517 Glib::RWLock::ReaderLock lm (_processor_lock);
1519 if (_processors.empty()) {
1522 ProcessorList::iterator start, end;
1523 placement_range(p, start, end);
1525 bool before_amp = true;
1526 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1531 if (p == PreFader && before_amp) {
1535 (*i)->deactivate ();
1540 _session.set_dirty ();
1544 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1546 bool pre_fader = true;
1547 Glib::RWLock::ReaderLock lm (_processor_lock);
1549 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1551 /* semantic note: if p == amp, we want to return true, so test
1552 for equality before checking if this is the amp
1569 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1571 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1572 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1573 processors in the current actual processor list that are hidden. Any visible processors
1574 in the current list but not in "new_order" will be assumed to be deleted.
1578 Glib::RWLock::WriterLock lm (_processor_lock);
1579 ChanCount old_pms = processor_max_streams;
1580 ProcessorList::iterator oiter;
1581 ProcessorList::const_iterator niter;
1582 ProcessorList as_it_was_before = _processors;
1583 ProcessorList as_it_will_be;
1585 oiter = _processors.begin();
1586 niter = new_order.begin();
1588 while (niter != new_order.end()) {
1590 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1591 then append it to the temp list.
1593 Otherwise, see if the next processor in the old list is in the new list. if not,
1594 its been deleted. If its there, append it to the temp list.
1597 if (oiter == _processors.end()) {
1599 /* no more elements in the old list, so just stick the rest of
1600 the new order onto the temp list.
1603 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1604 while (niter != new_order.end()) {
1611 if (!(*oiter)->display_to_user()) {
1613 as_it_will_be.push_back (*oiter);
1617 /* visible processor: check that its in the new order */
1619 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1620 /* deleted: do nothing, shared_ptr<> will clean up */
1622 /* ignore this one, and add the next item from the new order instead */
1623 as_it_will_be.push_back (*niter);
1628 /* now remove from old order - its taken care of no matter what */
1629 oiter = _processors.erase (oiter);
1634 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1636 if (configure_processors_unlocked (err)) {
1637 _processors = as_it_was_before;
1638 processor_max_streams = old_pms;
1643 processors_changed (); /* EMIT SIGNAL */
1655 Route::get_template()
1657 return state(false);
1661 Route::state(bool full_state)
1663 XMLNode *node = new XMLNode("Route");
1664 ProcessorList::iterator i;
1667 id().print (buf, sizeof (buf));
1668 node->add_property("id", buf);
1669 node->add_property ("name", _name);
1670 node->add_property("default-type", _default_type.to_string());
1673 node->add_property("flags", enum_2_string (_flags));
1676 node->add_property("active", _active?"yes":"no");
1677 node->add_property("phase-invert", _phase_invert?"yes":"no");
1678 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1679 node->add_property("meter-point", enum_2_string (_meter_point));
1682 node->add_property("route-group", _route_group->name());
1685 string order_string;
1686 OrderKeys::iterator x = order_keys.begin();
1688 while (x != order_keys.end()) {
1689 order_string += string ((*x).first);
1690 order_string += '=';
1691 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1692 order_string += buf;
1696 if (x == order_keys.end()) {
1700 order_string += ':';
1702 node->add_property ("order-keys", order_string);
1703 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1704 snprintf (buf, sizeof (buf), "%d", _soloed_by_others);
1705 node->add_property ("soloed-by-others", buf);
1707 node->add_child_nocopy (_input->state (full_state));
1708 node->add_child_nocopy (_output->state (full_state));
1709 node->add_child_nocopy (_solo_control->get_state ());
1710 node->add_child_nocopy (_mute_master->get_state ());
1712 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1713 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1714 remote_control_node->add_property (X_("id"), buf);
1715 node->add_child_nocopy (*remote_control_node);
1717 if (_comment.length()) {
1718 XMLNode *cmt = node->add_child ("Comment");
1719 cmt->add_content (_comment);
1722 for (i = _processors.begin(); i != _processors.end(); ++i) {
1723 node->add_child_nocopy((*i)->state (full_state));
1727 node->add_child_copy (*_extra_xml);
1734 Route::set_state (const XMLNode& node, int version)
1736 return _set_state (node, version, true);
1740 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1742 if (version < 3000) {
1743 return _set_state_2X (node, version);
1747 XMLNodeConstIterator niter;
1749 XMLPropertyList plist;
1750 const XMLProperty *prop;
1752 if (node.name() != "Route"){
1753 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1757 if ((prop = node.property (X_("name"))) != 0) {
1758 Route::set_name (prop->value());
1761 if ((prop = node.property ("id")) != 0) {
1762 _id = prop->value ();
1765 if ((prop = node.property (X_("flags"))) != 0) {
1766 _flags = Flag (string_2_enum (prop->value(), _flags));
1771 /* add all processors (except amp, which is always present) */
1773 nlist = node.children();
1774 XMLNode processor_state (X_("processor_state"));
1776 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1780 if (child->name() == IO::state_node_name) {
1781 if ((prop = child->property (X_("direction"))) == 0) {
1785 if (prop->value() == "Input") {
1786 _input->set_state (*child, version);
1787 } else if (prop->value() == "Output") {
1788 _output->set_state (*child, version);
1792 if (child->name() == X_("Processor")) {
1793 processor_state.add_child_copy (*child);
1797 set_processor_state (processor_state);
1799 if ((prop = node.property ("self-solo")) != 0) {
1800 set_self_solo (string_is_affirmative (prop->value()));
1803 if ((prop = node.property ("soloed-by-others")) != 0) {
1804 _soloed_by_others = 0; // needed for mod_solo_by_others () to work
1805 mod_solo_by_others (atoi (prop->value()));
1808 if ((prop = node.property ("solo-isolated")) != 0) {
1809 set_solo_isolated (string_is_affirmative (prop->value()), this);
1812 if ((prop = node.property (X_("phase-invert"))) != 0) {
1813 set_phase_invert (string_is_affirmative (prop->value()));
1816 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1817 set_denormal_protection (string_is_affirmative (prop->value()));
1820 if ((prop = node.property (X_("active"))) != 0) {
1821 bool yn = string_is_affirmative (prop->value());
1822 _active = !yn; // force switch
1826 if ((prop = node.property (X_("meter-point"))) != 0) {
1827 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1829 _meter->set_display_to_user (_meter_point == MeterCustom);
1833 if ((prop = node.property (X_("route-group"))) != 0) {
1834 RouteGroup* route_group = _session.route_group_by_name(prop->value());
1835 if (route_group == 0) {
1836 error << string_compose(_("Route %1: unknown route group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1838 set_route_group (route_group, this);
1842 if ((prop = node.property (X_("order-keys"))) != 0) {
1846 string::size_type colon, equal;
1847 string remaining = prop->value();
1849 while (remaining.length()) {
1851 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1852 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1855 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1856 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1859 set_order_key (remaining.substr (0, equal), n);
1863 colon = remaining.find_first_of (':');
1865 if (colon != string::npos) {
1866 remaining = remaining.substr (colon+1);
1873 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1876 if (child->name() == X_("Comment")) {
1878 /* XXX this is a terrible API design in libxml++ */
1880 XMLNode *cmt = *(child->children().begin());
1881 _comment = cmt->content();
1883 } else if (child->name() == X_("Extra")) {
1885 _extra_xml = new XMLNode (*child);
1887 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1889 if (prop->value() == "solo") {
1890 _solo_control->set_state (*child, version);
1891 _session.add_controllable (_solo_control);
1894 } else if (child->name() == X_("RemoteControl")) {
1895 if ((prop = child->property (X_("id"))) != 0) {
1897 sscanf (prop->value().c_str(), "%d", &x);
1898 set_remote_control_id (x);
1901 } else if (child->name() == X_("MuteMaster")) {
1902 _mute_master->set_state (*child, version);
1910 Route::_set_state_2X (const XMLNode& node, int version)
1913 XMLNodeConstIterator niter;
1915 XMLPropertyList plist;
1916 const XMLProperty *prop;
1918 /* 2X things which still remain to be handled:
1921 * mute-affects-pre-fader
1922 * mute-affects-post-fader
1923 * mute-affects-control-outs
1924 * mute-affects-main-outs
1929 if (node.name() != "Route") {
1930 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1934 if ((prop = node.property (X_("flags"))) != 0) {
1935 _flags = Flag (string_2_enum (prop->value(), _flags));
1940 /* add standard processors */
1942 _meter.reset (new PeakMeter (_session));
1943 add_processor (_meter, PreFader);
1945 if (_flags & ControlOut) {
1946 /* where we listen to tracks */
1947 _intreturn.reset (new InternalReturn (_session));
1948 add_processor (_intreturn, PreFader);
1951 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
1952 add_processor (_main_outs, PostFader);
1956 nlist = node.children ();
1957 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1961 if (child->name() == IO::state_node_name) {
1963 /* there is a note in IO::set_state_2X() about why we have to call
1967 _input->set_state_2X (*child, version, true);
1968 _output->set_state_2X (*child, version, false);
1970 if ((prop = child->property (X_("name"))) != 0) {
1971 set_name (prop->value ());
1974 if ((prop = child->property (X_("id"))) != 0) {
1975 _id = prop->value ();
1978 if ((prop = child->property (X_("active"))) != 0) {
1979 bool yn = string_is_affirmative (prop->value());
1980 _active = !yn; // force switch
1988 if ((prop = node.property (X_("phase-invert"))) != 0) {
1989 set_phase_invert (string_is_affirmative (prop->value()));
1992 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1993 set_denormal_protection (string_is_affirmative (prop->value()));
1996 if ((prop = node.property (X_("soloed"))) != 0) {
1997 bool yn = string_is_affirmative (prop->value());
1999 /* XXX force reset of solo status */
2001 set_solo (yn, this);
2004 if ((prop = node.property (X_("meter-point"))) != 0) {
2005 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2008 /* XXX: if the route was in both a mix group and an edit group, it'll end up
2009 just in the edit group. */
2011 if ((prop = node.property (X_("mix-group"))) != 0) {
2012 RouteGroup* route_group = _session.route_group_by_name(prop->value());
2013 if (route_group == 0) {
2014 error << string_compose(_("Route %1: unknown route group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2016 set_route_group (route_group, this);
2020 if ((prop = node.property (X_("edit-group"))) != 0) {
2021 RouteGroup* route_group = _session.route_group_by_name(prop->value());
2022 if (route_group == 0) {
2023 error << string_compose(_("Route %1: unknown route group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2025 set_route_group (route_group, this);
2029 if ((prop = node.property (X_("order-keys"))) != 0) {
2033 string::size_type colon, equal;
2034 string remaining = prop->value();
2036 while (remaining.length()) {
2038 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2039 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2042 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2043 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2046 set_order_key (remaining.substr (0, equal), n);
2050 colon = remaining.find_first_of (':');
2052 if (colon != string::npos) {
2053 remaining = remaining.substr (colon+1);
2060 XMLNodeList redirect_nodes;
2062 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2066 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2067 redirect_nodes.push_back(child);
2072 set_processor_state_2X (redirect_nodes, version);
2074 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2077 if (child->name() == X_("Comment")) {
2079 /* XXX this is a terrible API design in libxml++ */
2081 XMLNode *cmt = *(child->children().begin());
2082 _comment = cmt->content();
2084 } else if (child->name() == X_("Extra")) {
2086 _extra_xml = new XMLNode (*child);
2088 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2090 if (prop->value() == "solo") {
2091 _solo_control->set_state (*child, version);
2092 _session.add_controllable (_solo_control);
2095 } else if (child->name() == X_("RemoteControl")) {
2096 if ((prop = child->property (X_("id"))) != 0) {
2098 sscanf (prop->value().c_str(), "%d", &x);
2099 set_remote_control_id (x);
2109 Route::get_processor_state ()
2111 XMLNode* root = new XMLNode (X_("redirects"));
2112 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2113 root->add_child_nocopy ((*i)->state (true));
2120 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2122 /* We don't bother removing existing processors not in nList, as this
2123 method will only be called when creating a Route from scratch, not
2124 for undo purposes. Just put processors in at the appropriate place
2128 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2129 add_processor_from_xml_2X (**i, version, _processors.begin ());
2134 Route::set_processor_state (const XMLNode& node)
2136 const XMLNodeList &nlist = node.children();
2137 XMLNodeConstIterator niter;
2138 ProcessorList::iterator i, o;
2140 // Iterate through existing processors, remove those which are not in the state list
2142 for (i = _processors.begin(); i != _processors.end(); ) {
2144 /* leave amp alone, always */
2151 ProcessorList::iterator tmp = i;
2154 bool processorInStateList = false;
2156 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2158 XMLProperty* id_prop = (*niter)->property(X_("id"));
2160 if (id_prop && (*i)->id() == id_prop->value()) {
2161 processorInStateList = true;
2166 if (!processorInStateList) {
2167 remove_processor (*i);
2173 // Iterate through state list and make sure all processors are on the track and in the correct order,
2174 // set the state of existing processors according to the new state on the same go
2176 i = _processors.begin();
2178 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2180 XMLProperty* prop = (*niter)->property ("type");
2184 // Check whether the next processor in the list is the right one,
2185 // except for "amp" which is always there and may not have the
2186 // old ID since it is always created anew in every Route
2188 if (prop->value() != "amp") {
2189 while (o != _processors.end()) {
2190 XMLProperty* id_prop = (*niter)->property(X_("id"));
2191 if (id_prop && (*o)->id() == id_prop->value()) {
2199 // If the processor (*niter) is not on the route,
2200 // create it and move it to the correct location
2202 if (o == _processors.end()) {
2204 if (add_processor_from_xml (**niter, i)) {
2205 --i; // move iterator to the newly inserted processor
2207 cerr << "Error restoring route: unable to restore processor" << endl;
2212 // Otherwise, the processor already exists; just
2213 // ensure it is at the location provided in the XML state
2216 boost::shared_ptr<Processor> tmp = (*o);
2217 _processors.erase (o); // remove the old copy
2218 _processors.insert (i, tmp); // insert the processor at the correct location
2219 --i; // move iterator to the correct processor
2222 // and make it (just) so
2224 (*i)->set_state (**niter, Stateful::current_state_version);
2228 /* note: there is no configure_processors() call because we figure that
2229 the XML state represents a working signal route.
2232 processors_changed ();
2236 Route::curve_reallocate ()
2238 // _gain_automation_curve.finish_resize ();
2239 // _pan_automation_curve.finish_resize ();
2243 Route::silence (nframes_t nframes)
2247 _output->silence (nframes);
2250 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2253 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2254 boost::shared_ptr<PluginInsert> pi;
2256 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2257 // skip plugins, they don't need anything when we're not active
2261 (*i)->silence (nframes);
2264 if (nframes == _session.get_block_size()) {
2274 Route::add_internal_return ()
2277 _intreturn.reset (new InternalReturn (_session));
2278 add_processor (_intreturn, PreFader);
2283 Route::get_return_buffer () const
2285 Glib::RWLock::ReaderLock rm (_processor_lock);
2287 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2288 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2291 BufferSet* bs = d->get_buffers ();
2300 Route::release_return_buffer () const
2302 Glib::RWLock::ReaderLock rm (_processor_lock);
2304 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2305 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2308 return d->release_buffers ();
2314 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2316 vector<string> ports;
2317 vector<string>::const_iterator i;
2320 Glib::RWLock::ReaderLock rm (_processor_lock);
2322 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2324 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2326 if (d && d->target_route() == route) {
2328 /* if the target is the control outs, then make sure
2329 we take note of which i-send is doing that.
2332 if (route == _session.control_out()) {
2333 _control_outs = boost::dynamic_pointer_cast<Delivery>(d);
2336 /* already listening via the specified IO: do nothing */
2343 boost::shared_ptr<InternalSend> listener;
2346 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2348 } catch (failed_constructor& err) {
2352 if (route == _session.control_out()) {
2353 _control_outs = listener;
2356 add_processor (listener, placement);
2362 Route::drop_listen (boost::shared_ptr<Route> route)
2364 ProcessorStreams err;
2365 ProcessorList::iterator tmp;
2367 Glib::RWLock::ReaderLock rl(_processor_lock);
2371 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2373 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2375 if (d && d->target_route() == route) {
2377 remove_processor (*x, &err);
2380 /* list could have been demolished while we dropped the lock
2390 if (route == _session.control_out()) {
2391 _control_outs.reset ();
2396 Route::set_route_group (RouteGroup *rg, void *src)
2398 if (rg == _route_group) {
2403 _route_group->remove (this);
2406 if ((_route_group = rg) != 0) {
2407 _route_group->add (this);
2410 _session.set_dirty ();
2411 route_group_changed (src); /* EMIT SIGNAL */
2415 Route::drop_route_group (void *src)
2418 _session.set_dirty ();
2419 route_group_changed (src); /* EMIT SIGNAL */
2423 Route::set_comment (string cmt, void *src)
2426 comment_changed (src);
2427 _session.set_dirty ();
2431 Route::feeds (boost::shared_ptr<Route> other, bool* only_send)
2433 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2435 if (_output->connected_to (other->input())) {
2436 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2445 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2447 boost::shared_ptr<IOProcessor> iop;
2449 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2450 if (iop->feeds (other)) {
2451 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2457 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2460 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2465 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2470 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2472 nframes_t now = _session.transport_frame();
2475 Glib::RWLock::ReaderLock lm (_processor_lock);
2478 automation_snapshot (now, true);
2481 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2483 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2484 (*i)->deactivate ();
2488 (*i)->transport_stopped (now);
2492 _roll_delay = _initial_delay;
2496 Route::input_change_handler (IOChange change, void * /*src*/)
2498 if ((change & ConfigurationChanged)) {
2499 configure_processors (0);
2504 Route::output_change_handler (IOChange change, void * /*src*/)
2506 if ((change & ConfigurationChanged)) {
2508 /* XXX resize all listeners to match _main_outs? */
2510 // configure_processors (0);
2515 Route::pans_required () const
2517 if (n_outputs().n_audio() < 2) {
2521 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2525 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2526 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2528 if (n_outputs().n_total() == 0) {
2532 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2537 _amp->apply_gain_automation (false);
2538 passthru (start_frame, end_frame, nframes, 0);
2544 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2546 if (_roll_delay > nframes) {
2548 _roll_delay -= nframes;
2550 /* transport frame is not legal for caller to use */
2553 } else if (_roll_delay > 0) {
2555 nframes -= _roll_delay;
2556 silence (_roll_delay);
2557 /* we've written _roll_delay of samples into the
2558 output ports, so make a note of that for
2561 _main_outs->increment_output_offset (_roll_delay);
2562 transport_frame += _roll_delay;
2571 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2572 bool /*can_record*/, bool /*rec_monitors_input*/)
2575 // automation snapshot can also be called from the non-rt context
2576 // and it uses the processor list, so we try to acquire the lock here
2577 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2580 automation_snapshot (_session.transport_frame(), false);
2584 if (n_outputs().n_total() == 0) {
2588 if (!_active || n_inputs().n_total() == 0) {
2593 nframes_t unused = 0;
2595 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2601 passthru (start_frame, end_frame, nframes, declick);
2607 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2608 bool /*can_record*/, bool /*rec_monitors_input*/)
2615 Route::toggle_monitor_input ()
2617 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2618 i->ensure_monitor_input( ! i->monitoring_input());
2623 Route::has_external_redirects () const
2625 // FIXME: what about sends? - they don't return a signal back to ardour?
2627 boost::shared_ptr<const PortInsert> pi;
2629 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2631 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2633 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2635 string port_name = port->name();
2636 string client_name = port_name.substr (0, port_name.find(':'));
2638 /* only say "yes" if the redirect is actually in use */
2640 if (client_name != "ardour" && pi->active()) {
2651 Route::flush_processors ()
2653 /* XXX shouldn't really try to take this lock, since
2654 this is called from the RT audio thread.
2657 Glib::RWLock::ReaderLock lm (_processor_lock);
2659 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2660 (*i)->deactivate ();
2666 Route::set_meter_point (MeterPoint p, void *src)
2668 if (_meter_point == p) {
2673 Glib::RWLock::WriterLock lm (_processor_lock);
2674 ProcessorList as_it_was (_processors);
2676 if (p != MeterCustom) {
2677 // Move meter in the processors list to reflect the new position
2678 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2679 _processors.erase(loc);
2682 loc = _processors.begin();
2685 loc = find(_processors.begin(), _processors.end(), _amp);
2687 case MeterPostFader:
2688 loc = _processors.end();
2694 _processors.insert(loc, _meter);
2696 if (configure_processors_unlocked (0)) {
2697 _processors = as_it_was;
2698 configure_processors_unlocked (0); // it worked before we tried to add it ...
2702 _meter->set_display_to_user (false);
2706 // just make it visible and let the user move it
2708 _meter->set_display_to_user (true);
2714 meter_change (src); /* EMIT SIGNAL */
2715 processors_changed (); /* EMIT SIGNAL */
2716 _session.set_dirty ();
2720 Route::put_control_outs_at (Placement p)
2722 if (!_control_outs) {
2727 Glib::RWLock::WriterLock lm (_processor_lock);
2728 ProcessorList as_it_was (_processors);
2729 // Move meter in the processors list
2730 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _control_outs);
2731 _processors.erase(loc);
2735 loc = find(_processors.begin(), _processors.end(), _amp);
2736 if (loc != _processors.begin()) {
2741 loc = find(_processors.begin(), _processors.end(), _amp);
2742 assert (loc != _processors.end());
2747 _processors.insert(loc, _control_outs);
2749 if (configure_processors_unlocked (0)) {
2750 _processors = as_it_was;
2751 configure_processors_unlocked (0); // it worked before we tried to add it ...
2756 processors_changed (); /* EMIT SIGNAL */
2757 _session.set_dirty ();
2761 Route::update_total_latency ()
2763 nframes_t old = _output->effective_latency();
2764 nframes_t own_latency = _output->user_latency();
2766 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2767 if ((*i)->active ()) {
2768 own_latency += (*i)->signal_latency ();
2772 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2774 _output->set_port_latency (own_latency);
2776 if (_output->user_latency() == 0) {
2778 /* this (virtual) function is used for pure Routes,
2779 not derived classes like AudioTrack. this means
2780 that the data processed here comes from an input
2781 port, not prerecorded material, and therefore we
2782 have to take into account any input latency.
2785 own_latency += _input->signal_latency ();
2788 if (old != own_latency) {
2789 _output->set_latency_delay (own_latency);
2790 signal_latency_changed (); /* EMIT SIGNAL */
2793 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2795 return _output->effective_latency ();
2799 Route::set_user_latency (nframes_t nframes)
2801 _output->set_user_latency (nframes);
2802 _session.update_latency_compensation (false, false);
2806 Route::set_latency_delay (nframes_t longest_session_latency)
2808 nframes_t old = _initial_delay;
2810 if (_output->effective_latency() < longest_session_latency) {
2811 _initial_delay = longest_session_latency - _output->effective_latency();
2816 if (_initial_delay != old) {
2817 initial_delay_changed (); /* EMIT SIGNAL */
2820 if (_session.transport_stopped()) {
2821 _roll_delay = _initial_delay;
2826 Route::automation_snapshot (nframes_t now, bool force)
2828 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2829 (*i)->automation_snapshot (now, force);
2833 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2834 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2835 boost::shared_ptr<AutomationList>(), name)
2838 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2843 Route::SoloControllable::set_value (float val)
2845 bool bval = ((val >= 0.5f) ? true: false);
2847 route.set_solo (bval, this);
2851 Route::SoloControllable::get_value (void) const
2853 return route.self_soloed() ? 1.0f : 0.0f;
2857 Route::set_block_size (nframes_t nframes)
2859 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2860 (*i)->set_block_size (nframes);
2863 _session.ensure_buffers (n_process_buffers ());
2867 Route::protect_automation ()
2869 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2870 (*i)->protect_automation();
2874 Route::set_pending_declick (int declick)
2877 /* this call is not allowed to turn off a pending declick unless "force" is true */
2879 _pending_declick = declick;
2881 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2883 _pending_declick = 0;
2888 /** Shift automation forwards from a particular place, thereby inserting time.
2889 * Adds undo commands for any shifts that are performed.
2891 * @param pos Position to start shifting from.
2892 * @param frames Amount to shift forwards by.
2896 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
2898 #ifdef THIS_NEEDS_FIXING_FOR_V3
2900 /* gain automation */
2901 XMLNode &before = _gain_control->get_state ();
2902 _gain_control->shift (pos, frames);
2903 XMLNode &after = _gain_control->get_state ();
2904 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2906 /* pan automation */
2907 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2908 Curve & c = (*i)->automation ();
2909 XMLNode &before = c.get_state ();
2910 c.shift (pos, frames);
2911 XMLNode &after = c.get_state ();
2912 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2915 /* redirect automation */
2917 Glib::RWLock::ReaderLock lm (redirect_lock);
2918 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2921 (*i)->what_has_automation (a);
2923 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2924 AutomationList & al = (*i)->automation_list (*j);
2925 XMLNode &before = al.get_state ();
2926 al.shift (pos, frames);
2927 XMLNode &after = al.get_state ();
2928 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2938 Route::save_as_template (const string& path, const string& name)
2940 XMLNode& node (state (false));
2943 IO::set_name_in_state (*node.children().front(), name);
2945 tree.set_root (&node);
2946 return tree.write (path.c_str());
2951 Route::set_name (const string& str)
2957 name = Route::ensure_track_or_route_name (str, _session);
2958 SessionObject::set_name (name);
2960 ret = (_input->set_name(name) && _output->set_name(name));
2964 Glib::RWLock::ReaderLock lm (_processor_lock);
2966 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2968 /* rename all I/O processors that have inputs or outputs */
2970 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2972 if (iop && (iop->output() || iop->input())) {
2973 if (!iop->set_name (name)) {
2984 boost::shared_ptr<Send>
2985 Route::internal_send_for (boost::shared_ptr<const Route> target) const
2987 Glib::RWLock::ReaderLock lm (_processor_lock);
2989 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2990 boost::shared_ptr<InternalSend> send;
2992 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
2993 if (send->target_route() == target) {
2999 return boost::shared_ptr<Send>();
3003 Route::set_phase_invert (bool yn)
3005 if (_phase_invert != yn) {
3006 _phase_invert = 0xffff; // XXX all channels
3007 phase_invert_changed (); /* EMIT SIGNAL */
3012 Route::phase_invert () const
3014 return _phase_invert != 0;
3018 Route::set_denormal_protection (bool yn)
3020 if (_denormal_protection != yn) {
3021 _denormal_protection = yn;
3022 denormal_protection_changed (); /* EMIT SIGNAL */
3027 Route::denormal_protection () const
3029 return _denormal_protection;
3033 Route::set_active (bool yn)
3035 if (_active != yn) {
3037 _input->set_active (yn);
3038 _output->set_active (yn);
3039 active_changed (); // EMIT SIGNAL
3046 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3052 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3054 boost::shared_ptr<Send> s;
3055 boost::shared_ptr<Return> r;
3057 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3058 s->meter()->meter();
3059 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3060 r->meter()->meter ();
3065 boost::shared_ptr<Panner>
3066 Route::panner() const
3069 return _main_outs->panner();
3072 boost::shared_ptr<AutomationControl>
3073 Route::gain_control() const
3076 return _amp->gain_control();
3079 boost::shared_ptr<AutomationControl>
3080 Route::get_control (const Evoral::Parameter& param)
3082 /* either we own the control or .... */
3084 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
3088 /* maybe one of our processors does or ... */
3090 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3091 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3092 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
3100 /* nobody does so we'll make a new one */
3102 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));