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/stacktrace.h"
29 #include "pbd/memento_command.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/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 add_processor (_meter, PreFader);
85 if (_flags & ControlOut) {
86 /* where we listen to tracks */
87 _intreturn.reset (new InternalReturn (_session));
88 add_processor (_intreturn, PreFader);
91 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
92 add_processor (_main_outs, PostFader);
94 /* now that we have _meter, its safe to connect to this */
96 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
99 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
100 : SessionObject (sess, "toBeReset")
101 , AutomatableControls (sess)
102 , _solo_control (new SoloControllable (X_("solo"), *this))
103 , _mute_master (new MuteMaster (sess, "toBeReset"))
104 , _default_type (default_type)
108 _set_state (node, false);
110 /* now that we have _meter, its safe to connect to this */
112 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
119 _solo_isolated = false;
121 processor_max_streams.reset();
124 order_keys[N_("signal")] = order_key_cnt++;
126 _meter_point = MeterPostFader;
129 _have_internal_generator = false;
130 _declickable = false;
131 _pending_declick = true;
132 _remote_control_id = 0;
133 _in_configure_processors = false;
138 _denormal_protection = false;
140 /* add standard controls */
142 add_control (_solo_control);
143 add_control (_mute_master);
145 /* input and output objects */
147 _input.reset (new IO (_session, _name, IO::Input, _default_type));
148 _output.reset (new IO (_session, _name, IO::Output, _default_type));
150 _input->changed.connect (mem_fun (this, &Route::input_change_handler));
151 _output->changed.connect (mem_fun (this, &Route::output_change_handler));
153 /* add amp processor */
155 _amp.reset (new Amp (_session, _mute_master));
156 add_processor (_amp, PostFader);
161 Metering::disconnect (_meter_connection);
163 clear_processors (PreFader);
164 clear_processors (PostFader);
168 Route::set_remote_control_id (uint32_t id)
170 if (id != _remote_control_id) {
171 _remote_control_id = id;
172 RemoteControlIDChanged ();
177 Route::remote_control_id() const
179 return _remote_control_id;
183 Route::order_key (std::string const & name) const
185 OrderKeys::const_iterator i = order_keys.find (name);
186 if (i == order_keys.end()) {
194 Route::set_order_key (std::string const & name, long n)
196 order_keys[name] = n;
198 if (Config->get_sync_all_route_ordering()) {
199 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
204 _session.set_dirty ();
207 /** Set all order keys to be the same as that for `base', if such a key
208 * exists in this route.
209 * @param base Base key.
212 Route::sync_order_keys (std::string const & base)
214 if (order_keys.empty()) {
218 OrderKeys::iterator i;
221 if ((i = order_keys.find (base)) == order_keys.end()) {
222 /* key doesn't exist, use the first existing key (during session initialization) */
223 i = order_keys.begin();
227 /* key exists - use it and reset all others (actually, itself included) */
229 i = order_keys.begin();
232 for (; i != order_keys.end(); ++i) {
238 Route::ensure_track_or_route_name(string name, Session &session)
240 string newname = name;
242 while (session.route_by_name (newname) != NULL) {
243 newname = bump_name_once (newname);
251 Route::inc_gain (gain_t fraction, void *src)
253 _amp->inc_gain (fraction, src);
257 Route::set_gain (gain_t val, void *src)
259 if (src != 0 && _route_group && src != _route_group && _route_group->active_property (RouteGroup::Gain)) {
261 if (_route_group->is_relative()) {
263 gain_t usable_gain = _amp->gain();
264 if (usable_gain < 0.000001f) {
265 usable_gain = 0.000001f;
269 if (delta < 0.000001f) {
273 delta -= usable_gain;
278 gain_t factor = delta / usable_gain;
281 factor = _route_group->get_max_factor(factor);
282 if (factor == 0.0f) {
283 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
287 factor = _route_group->get_min_factor(factor);
288 if (factor == 0.0f) {
289 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
294 _route_group->apply (&Route::inc_gain, factor, _route_group);
298 _route_group->apply (&Route::set_gain, val, _route_group);
304 if (val == _amp->gain()) {
308 _amp->set_gain (val, src);
311 /** Process this route for one (sub) cycle (process thread)
313 * @param bufs Scratch buffers to use for the signal path
314 * @param start_frame Initial transport frame
315 * @param end_frame Final transport frame
316 * @param nframes Number of frames to output (to ports)
318 * Note that (end_frame - start_frame) may not be equal to nframes when the
319 * transport speed isn't 1.0 (eg varispeed).
322 Route::process_output_buffers (BufferSet& bufs,
323 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
324 bool /*with_processors*/, int declick)
328 bufs.is_silent (false);
330 switch (Config->get_monitoring_model()) {
331 case HardwareMonitoring:
332 case ExternalMonitoring:
333 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
340 declick = _pending_declick;
343 /* figure out if we're going to use gain automation */
344 _amp->setup_gain_automation (start_frame, end_frame, nframes);
347 /* tell main outs what to do about monitoring */
348 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
351 /* -------------------------------------------------------------------------------------------
352 GLOBAL DECLICK (for transport changes etc.)
353 ----------------------------------------------------------------------------------------- */
356 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
357 } else if (declick < 0) {
358 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
361 _pending_declick = 0;
363 /* -------------------------------------------------------------------------------------------
364 DENORMAL CONTROL/PHASE INVERT
365 ----------------------------------------------------------------------------------------- */
371 if (_denormal_protection || Config->get_denormal_protection()) {
373 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
374 Sample* const sp = i->data();
376 if (_phase_invert & chn) {
377 for (nframes_t nx = 0; nx < nframes; ++nx) {
382 for (nframes_t nx = 0; nx < nframes; ++nx) {
390 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
391 Sample* const sp = i->data();
393 if (_phase_invert & chn) {
394 for (nframes_t nx = 0; nx < nframes; ++nx) {
403 if (_denormal_protection || Config->get_denormal_protection()) {
405 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
406 Sample* const sp = i->data();
407 for (nframes_t nx = 0; nx < nframes; ++nx) {
415 /* -------------------------------------------------------------------------------------------
417 ----------------------------------------------------------------------------------------- */
419 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
422 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
423 bufs.set_count (ChanCount::max(bufs.count(), (*i)->input_streams()));
424 (*i)->run (bufs, start_frame, end_frame, nframes);
425 bufs.set_count (ChanCount::max(bufs.count(), (*i)->output_streams()));
428 if (!_processors.empty()) {
429 bufs.set_count (ChanCount::max (bufs.count(), _processors.back()->output_streams()));
435 Route::n_process_buffers ()
437 return max (_input->n_ports(), processor_max_streams);
441 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
443 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
447 assert (bufs.available() >= _input->n_ports());
449 if (_input->n_ports() == ChanCount::ZERO) {
453 bufs.set_count (_input->n_ports());
455 if (is_control() && _session.listening()) {
457 /* control/monitor bus ignores input ports when something is
458 feeding the listen "stream". data will "arrive" into the
459 route from the intreturn processor element.
462 bufs.silence (nframes, 0);
466 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
468 BufferSet::iterator o = bufs.begin(*t);
469 PortSet& ports (_input->ports());
471 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
472 o->read_from (i->get_buffer(nframes), nframes);
477 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
481 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
483 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, true, declick);
487 Route::set_listen (bool yn, void* src)
490 if (yn != _control_outs->active()) {
492 _control_outs->activate ();
494 _control_outs->deactivate ();
497 listen_changed (src); /* EMIT SIGNAL */
503 Route::listening () const
506 return _control_outs->active ();
513 Route::set_solo (bool yn, void *src)
515 if (_solo_safe || _solo_isolated) {
519 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
520 _route_group->apply (&Route::set_solo, yn, _route_group);
524 if (soloed() != yn) {
525 mod_solo_level (yn ? 1 : -1);
526 solo_changed (src); /* EMIT SIGNAL */
527 _solo_control->Changed (); /* EMIT SIGNAL */
532 Route::mod_solo_level (int32_t delta)
535 if (_solo_level >= (uint32_t) delta) {
536 _solo_level += delta;
541 _solo_level += delta;
544 /* tell main outs what the solo situation is
547 _main_outs->set_solo_level (_solo_level);
548 _main_outs->set_solo_isolated (_solo_isolated);
552 Route::set_solo_isolated (bool yn, void *src)
554 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
555 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
559 if (yn != _solo_isolated) {
562 /* tell main outs what the solo situation is
565 _main_outs->set_solo_level (_solo_level);
566 _main_outs->set_solo_isolated (_solo_isolated);
568 solo_isolated_changed (src);
573 Route::solo_isolated () const
575 return _solo_isolated;
579 Route::set_mute (bool yn, void *src)
581 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Mute)) {
582 _route_group->apply (&Route::set_mute, yn, _route_group);
587 _mute_master->mute (yn);
595 return _mute_master->muted ();
600 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
602 cerr << name << " {" << endl;
603 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
604 p != procs.end(); ++p) {
605 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
612 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
614 ProcessorList::iterator loc;
616 /* XXX this is not thread safe - we don't hold the lock across determining the iter
617 to add before and actually doing the insertion. dammit.
620 if (placement == PreFader) {
621 /* generic pre-fader: insert immediately before the amp */
622 loc = find (_processors.begin(), _processors.end(), _amp);
624 /* generic post-fader: insert right before the main outs */
625 loc = find (_processors.begin(), _processors.end(), _main_outs);
628 return add_processor (processor, loc, err);
632 /** Add a processor to the route.
633 * If @a iter is not NULL, it must point to an iterator in _processors and the new
634 * processor will be inserted immediately before this location. Otherwise,
635 * @a position is used.
638 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
640 ChanCount old_pms = processor_max_streams;
642 if (!_session.engine().connected() || !processor) {
647 Glib::RWLock::WriterLock lm (_processor_lock);
649 boost::shared_ptr<PluginInsert> pi;
650 boost::shared_ptr<PortInsert> porti;
652 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
654 if (processor == _amp || processor == _meter || processor == _main_outs) {
655 // Ensure only one of these are in the list at any time
656 if (loc != _processors.end()) {
657 if (iter == loc) { // Already in place, do nothing
659 } else { // New position given, relocate
660 _processors.erase (loc);
665 if (loc != _processors.end()) {
666 cerr << "ERROR: Processor added to route twice!" << endl;
673 _processors.insert (loc, processor);
675 // Set up processor list channels. This will set processor->[input|output]_streams(),
676 // configure redirect ports properly, etc.
679 if (configure_processors_unlocked (err)) {
680 ProcessorList::iterator ploc = loc;
682 _processors.erase(ploc);
683 configure_processors_unlocked (0); // it worked before we tried to add it ...
684 cerr << "configure failed\n";
688 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
690 if (pi->natural_input_streams() == ChanCount::ZERO) {
691 /* generator plugin */
692 _have_internal_generator = true;
697 if (_control_outs != processor) {
698 // XXX: do we want to emit the signal here ? change call order.
699 processor->activate ();
701 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
703 _output->set_user_latency (0);
706 processors_changed (); /* EMIT SIGNAL */
712 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
714 const XMLProperty *prop;
716 if (node.name() != "Processor") {
721 if ((prop = node.property ("type")) != 0) {
723 boost::shared_ptr<Processor> processor;
725 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
726 prop->value() == "lv2" ||
727 prop->value() == "vst" ||
728 prop->value() == "audiounit") {
730 processor.reset (new PluginInsert(_session, node));
732 } else if (prop->value() == "port") {
734 processor.reset (new PortInsert (_session, _mute_master, node));
736 } else if (prop->value() == "send") {
738 processor.reset (new Send (_session, _mute_master, node));
740 } else if (prop->value() == "meter") {
743 if (_meter->set_state (node)) {
750 _meter.reset (new PeakMeter (_session, node));
753 } else if (prop->value() == "amp") {
755 /* amp always exists */
758 if (processor->set_state (node)) {
761 /* never any reason to add it */
765 } else if (prop->value() == "intsend") {
767 processor.reset (new InternalSend (_session, _mute_master, node));
769 } else if (prop->value() == "intreturn") {
772 if (_intreturn->set_state (node)) {
778 _intreturn.reset (new InternalReturn (_session, node));
779 processor = _intreturn;
781 } else if (prop->value() == "main-outs") {
784 if (_main_outs->set_state (node)) {
791 _main_outs.reset (new Delivery (_session, _output, _mute_master, node));
792 processor = _main_outs;
795 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
799 if (iter == _processors.end() && processor->visible() && !_processors.empty()) {
800 /* check for invisible processors stacked at the end and leave them there */
801 ProcessorList::iterator p;
802 p = _processors.end();
804 while (!(*p)->visible() && p != _processors.begin()) {
811 return (add_processor (processor, iter) == 0);
814 error << _("Processor XML node has no type property") << endmsg;
819 catch (failed_constructor &err) {
820 warning << _("processor could not be created. Ignored.") << endmsg;
826 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
828 ProcessorList::iterator loc;
831 loc = find(_processors.begin(), _processors.end(), before);
833 /* nothing specified - at end but before main outs */
834 loc = find (_processors.begin(), _processors.end(), _main_outs);
837 return add_processors (others, loc, err);
841 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
843 /* NOTE: this is intended to be used ONLY when copying
844 processors from another Route. Hence the subtle
845 differences between this and ::add_processor()
848 ChanCount old_pms = processor_max_streams;
850 if (!_session.engine().connected()) {
854 if (others.empty()) {
859 Glib::RWLock::WriterLock lm (_processor_lock);
860 ProcessorList::iterator existing_end = _processors.end();
863 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
865 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
867 // Ensure meter only appears in the list once
869 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
870 if (m != _processors.end()) {
871 _processors.erase(m);
875 boost::shared_ptr<PluginInsert> pi;
877 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
880 ChanCount m = max (pi->input_streams(), pi->output_streams());
882 if (m > potential_max_streams) {
883 potential_max_streams = m;
887 _processors.insert (iter, *i);
889 if (configure_processors_unlocked (err)) {
891 _processors.erase (existing_end, _processors.end());
892 configure_processors_unlocked (0); // it worked before we tried to add it ...
896 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
899 _output->set_user_latency (0);
902 processors_changed (); /* EMIT SIGNAL */
908 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
911 start = _processors.begin();
912 end = find(_processors.begin(), _processors.end(), _amp);
914 start = find(_processors.begin(), _processors.end(), _amp);
916 end = _processors.end();
920 /** Turn off all processors with a given placement
921 * @param p Placement of processors to disable
924 Route::disable_processors (Placement p)
926 Glib::RWLock::ReaderLock lm (_processor_lock);
928 ProcessorList::iterator start, end;
929 placement_range(p, start, end);
931 for (ProcessorList::iterator i = start; i != end; ++i) {
935 _session.set_dirty ();
938 /** Turn off all redirects
941 Route::disable_processors ()
943 Glib::RWLock::ReaderLock lm (_processor_lock);
945 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
949 _session.set_dirty ();
952 /** Turn off all redirects with a given placement
953 * @param p Placement of redirects to disable
956 Route::disable_plugins (Placement p)
958 Glib::RWLock::ReaderLock lm (_processor_lock);
960 ProcessorList::iterator start, end;
961 placement_range(p, start, end);
963 for (ProcessorList::iterator i = start; i != end; ++i) {
964 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
969 _session.set_dirty ();
972 /** Turn off all plugins
975 Route::disable_plugins ()
977 Glib::RWLock::ReaderLock lm (_processor_lock);
979 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
980 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
985 _session.set_dirty ();
990 Route::ab_plugins (bool forward)
992 Glib::RWLock::ReaderLock lm (_processor_lock);
996 /* forward = turn off all active redirects, and mark them so that the next time
997 we go the other way, we will revert them
1000 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1001 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1005 if ((*i)->active()) {
1006 (*i)->deactivate ();
1007 (*i)->set_next_ab_is_active (true);
1009 (*i)->set_next_ab_is_active (false);
1015 /* backward = if the redirect was marked to go active on the next ab, do so */
1017 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1019 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1023 if ((*i)->get_next_ab_is_active()) {
1026 (*i)->deactivate ();
1031 _session.set_dirty ();
1035 /** Remove processors with a given placement.
1036 * @param p Placement of processors to remove.
1039 Route::clear_processors (Placement p)
1041 const ChanCount old_pms = processor_max_streams;
1043 if (!_session.engine().connected()) {
1047 bool already_deleting = _session.deletion_in_progress();
1048 if (!already_deleting) {
1049 _session.set_deletion_in_progress();
1053 Glib::RWLock::WriterLock lm (_processor_lock);
1054 ProcessorList new_list;
1055 ProcessorStreams err;
1056 bool seen_amp = false;
1058 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1064 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1066 /* you can't remove these */
1068 new_list.push_back (*i);
1075 new_list.push_back (*i);
1078 (*i)->drop_references ();
1086 (*i)->drop_references ();
1089 new_list.push_back (*i);
1096 _processors = new_list;
1097 configure_processors_unlocked (&err); // this can't fail
1100 processor_max_streams.reset();
1101 _have_internal_generator = false;
1102 processors_changed (); /* EMIT SIGNAL */
1104 if (!already_deleting) {
1105 _session.clear_deletion_in_progress();
1110 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1112 /* these can never be removed */
1114 if (processor == _amp || processor == _meter || processor == _main_outs) {
1118 ChanCount old_pms = processor_max_streams;
1120 if (!_session.engine().connected()) {
1124 processor_max_streams.reset();
1127 Glib::RWLock::WriterLock lm (_processor_lock);
1128 ProcessorList::iterator i;
1129 bool removed = false;
1131 for (i = _processors.begin(); i != _processors.end(); ) {
1132 if (*i == processor) {
1134 /* move along, see failure case for configure_processors()
1135 where we may need to reconfigure the processor.
1138 /* stop redirects that send signals to JACK ports
1139 from causing noise as a result of no longer being
1143 boost::shared_ptr<IOProcessor> iop;
1145 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1147 iop->input()->disconnect (this);
1149 if (iop->output()) {
1150 iop->output()->disconnect (this);
1154 i = _processors.erase (i);
1162 _output->set_user_latency (0);
1170 if (configure_processors_unlocked (err)) {
1171 /* get back to where we where */
1172 _processors.insert (i, processor);
1173 /* we know this will work, because it worked before :) */
1174 configure_processors_unlocked (0);
1178 _have_internal_generator = false;
1180 for (i = _processors.begin(); i != _processors.end(); ++i) {
1181 boost::shared_ptr<PluginInsert> pi;
1183 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1184 if (pi->is_generator()) {
1185 _have_internal_generator = true;
1192 processor->drop_references ();
1193 processors_changed (); /* EMIT SIGNAL */
1199 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1201 ProcessorList deleted;
1202 ProcessorList as_we_were;
1204 if (!_session.engine().connected()) {
1208 processor_max_streams.reset();
1211 Glib::RWLock::WriterLock lm (_processor_lock);
1212 ProcessorList::iterator i;
1213 boost::shared_ptr<Processor> processor;
1215 as_we_were = _processors;
1217 for (i = _processors.begin(); i != _processors.end(); ) {
1221 /* these can never be removed */
1223 if (processor == _amp || processor == _meter || processor == _main_outs) {
1228 /* see if its in the list of processors to delete */
1230 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1235 /* stop IOProcessors that send to JACK ports
1236 from causing noise as a result of no longer being
1240 boost::shared_ptr<IOProcessor> iop;
1242 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1246 deleted.push_back (processor);
1247 i = _processors.erase (i);
1250 if (deleted.empty()) {
1251 /* none of those in the requested list were found */
1255 _output->set_user_latency (0);
1257 if (configure_processors_unlocked (err)) {
1258 /* get back to where we where */
1259 _processors = as_we_were;
1260 /* we know this will work, because it worked before :) */
1261 configure_processors_unlocked (0);
1265 _have_internal_generator = false;
1267 for (i = _processors.begin(); i != _processors.end(); ++i) {
1268 boost::shared_ptr<PluginInsert> pi;
1270 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1271 if (pi->is_generator()) {
1272 _have_internal_generator = true;
1279 /* now try to do what we need to so that those that were removed will be deleted */
1281 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1282 (*i)->drop_references ();
1285 processors_changed (); /* EMIT SIGNAL */
1292 Route::configure_processors (ProcessorStreams* err)
1294 if (!_in_configure_processors) {
1295 Glib::RWLock::WriterLock lm (_processor_lock);
1296 return configure_processors_unlocked (err);
1301 /** Configure the input/output configuration of each processor in the processors list.
1302 * Return 0 on success, otherwise configuration is impossible.
1305 Route::configure_processors_unlocked (ProcessorStreams* err)
1307 if (_in_configure_processors) {
1311 _in_configure_processors = true;
1313 // Check each processor in order to see if we can configure as requested
1314 ChanCount in = _input->n_ports ();
1316 list< pair<ChanCount,ChanCount> > configuration;
1319 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1320 if ((*p)->can_support_io_configuration(in, out)) {
1321 configuration.push_back(make_pair(in, out));
1328 _in_configure_processors = false;
1333 // We can, so configure everything
1334 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1335 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1336 (*p)->configure_io(c->first, c->second);
1337 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1338 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1342 // Ensure route outputs match last processor's outputs
1343 if (out != _output->n_ports ()) {
1344 cerr << "For " << _name << " out/last mismatch - out = " << out << " vs. " << _output->n_ports() << endl;
1345 _output->ensure_io (out, false, this);
1348 _in_configure_processors = false;
1353 Route::all_processors_flip ()
1355 Glib::RWLock::ReaderLock lm (_processor_lock);
1357 if (_processors.empty()) {
1361 bool first_is_on = _processors.front()->active();
1363 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1365 (*i)->deactivate ();
1371 _session.set_dirty ();
1374 /** Set all processors with a given placement to a given active state.
1375 * @param p Placement of processors to change.
1376 * @param state New active state for those processors.
1379 Route::all_processors_active (Placement p, bool state)
1381 Glib::RWLock::ReaderLock lm (_processor_lock);
1383 if (_processors.empty()) {
1386 ProcessorList::iterator start, end;
1387 placement_range(p, start, end);
1389 bool before_amp = true;
1390 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1395 if (p == PreFader && before_amp) {
1399 (*i)->deactivate ();
1404 _session.set_dirty ();
1408 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1410 bool pre_fader = true;
1411 Glib::RWLock::ReaderLock lm (_processor_lock);
1413 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1415 /* semantic note: if p == amp, we want to return true, so test
1416 for equality before checking if this is the amp
1433 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1435 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1436 NOTE: all processors in "new_order" MUST be marked as visible. There maybe additional
1437 processors in the current actual processor list that are hidden. Any visible processors
1438 in the current list but not in "new_order" will be assumed to be deleted.
1442 Glib::RWLock::WriterLock lm (_processor_lock);
1443 ChanCount old_pms = processor_max_streams;
1444 ProcessorList::iterator oiter;
1445 ProcessorList::const_iterator niter;
1446 ProcessorList as_it_was_before = _processors;
1447 ProcessorList as_it_will_be;
1449 oiter = _processors.begin();
1450 niter = new_order.begin();
1452 while (niter != new_order.end()) {
1454 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1455 then append it to the temp list.
1457 Otherwise, see if the next processor in the old list is in the new list. if not,
1458 its been deleted. If its there, append it to the temp list.
1461 if (oiter == _processors.end()) {
1463 /* no more elements in the old list, so just stick the rest of
1464 the new order onto the temp list.
1467 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1468 while (niter != new_order.end()) {
1475 if (!(*oiter)->visible()) {
1477 as_it_will_be.push_back (*oiter);
1481 /* visible processor: check that its in the new order */
1483 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1484 /* deleted: do nothing, shared_ptr<> will clean up */
1486 /* ignore this one, and add the next item from the new order instead */
1487 as_it_will_be.push_back (*niter);
1492 /* now remove from old order - its taken care of no matter what */
1493 oiter = _processors.erase (oiter);
1498 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1500 if (configure_processors_unlocked (err)) {
1501 _processors = as_it_was_before;
1502 processor_max_streams = old_pms;
1507 processors_changed (); /* EMIT SIGNAL */
1519 Route::get_template()
1521 return state(false);
1525 Route::state(bool full_state)
1527 XMLNode *node = new XMLNode("Route");
1528 ProcessorList::iterator i;
1531 id().print (buf, sizeof (buf));
1532 node->add_property("id", buf);
1533 node->add_property ("name", _name);
1534 node->add_property("default-type", _default_type.to_string());
1537 node->add_property("flags", enum_2_string (_flags));
1540 node->add_property("active", _active?"yes":"no");
1541 node->add_property("phase-invert", _phase_invert?"yes":"no");
1542 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1543 node->add_property("meter-point", enum_2_string (_meter_point));
1546 node->add_property("route-group", _route_group->name());
1549 string order_string;
1550 OrderKeys::iterator x = order_keys.begin();
1552 while (x != order_keys.end()) {
1553 order_string += string ((*x).first);
1554 order_string += '=';
1555 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1556 order_string += buf;
1560 if (x == order_keys.end()) {
1564 order_string += ':';
1566 node->add_property ("order-keys", order_string);
1568 node->add_child_nocopy (_input->state (full_state));
1569 node->add_child_nocopy (_output->state (full_state));
1570 node->add_child_nocopy (_solo_control->get_state ());
1571 node->add_child_nocopy (_mute_master->get_state ());
1573 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1574 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1575 remote_control_node->add_property (X_("id"), buf);
1576 node->add_child_nocopy (*remote_control_node);
1578 if (_comment.length()) {
1579 XMLNode *cmt = node->add_child ("Comment");
1580 cmt->add_content (_comment);
1583 for (i = _processors.begin(); i != _processors.end(); ++i) {
1584 node->add_child_nocopy((*i)->state (full_state));
1588 node->add_child_copy (*_extra_xml);
1595 Route::set_state (const XMLNode& node)
1597 return _set_state (node, true);
1601 Route::_set_state (const XMLNode& node, bool /*call_base*/)
1605 XMLNodeConstIterator niter;
1607 XMLPropertyList plist;
1608 const XMLProperty *prop;
1610 if (node.name() != "Route"){
1611 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1615 if ((prop = node.property (X_("name"))) != 0) {
1616 Route::set_name (prop->value());
1619 if ((prop = node.property ("id")) != 0) {
1620 _id = prop->value ();
1623 if ((prop = node.property (X_("flags"))) != 0) {
1624 _flags = Flag (string_2_enum (prop->value(), _flags));
1629 /* add all processors (except amp, which is always present) */
1631 nlist = node.children();
1632 XMLNode processor_state (X_("processor_state"));
1634 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1638 if (child->name() == IO::state_node_name) {
1639 if ((prop = child->property (X_("direction"))) == 0) {
1643 if (prop->value() == "Input") {
1644 _input->set_state (*child);
1645 } else if (prop->value() == "Output") {
1646 _output->set_state (*child);
1650 if (child->name() == X_("Processor")) {
1651 processor_state.add_child_copy (*child);
1655 set_processor_state (processor_state);
1657 if ((prop = node.property ("solo_level")) != 0) {
1658 _solo_level = 0; // needed for mod_solo_level() to work
1659 mod_solo_level (atoi (prop->value()));
1662 if ((prop = node.property ("solo-isolated")) != 0) {
1663 set_solo_isolated (prop->value() == "yes", this);
1666 if ((prop = node.property (X_("phase-invert"))) != 0) {
1667 set_phase_invert (prop->value()=="yes"?true:false);
1670 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1671 set_denormal_protection (prop->value()=="yes"?true:false);
1674 if ((prop = node.property (X_("active"))) != 0) {
1675 bool yn = (prop->value() == "yes");
1676 _active = !yn; // force switch
1680 if ((prop = node.property (X_("soloed"))) != 0) {
1681 bool yn = (prop->value()=="yes");
1683 /* XXX force reset of solo status */
1685 set_solo (yn, this);
1688 if ((prop = node.property (X_("meter-point"))) != 0) {
1689 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1692 if ((prop = node.property (X_("route-group"))) != 0) {
1693 RouteGroup* route_group = _session.route_group_by_name(prop->value());
1694 if (route_group == 0) {
1695 error << string_compose(_("Route %1: unknown route group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1697 set_route_group (route_group, this);
1701 if ((prop = node.property (X_("order-keys"))) != 0) {
1705 string::size_type colon, equal;
1706 string remaining = prop->value();
1708 while (remaining.length()) {
1710 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1711 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1714 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1715 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1718 set_order_key (remaining.substr (0, equal), n);
1722 colon = remaining.find_first_of (':');
1724 if (colon != string::npos) {
1725 remaining = remaining.substr (colon+1);
1732 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1735 if (child->name() == X_("Comment")) {
1737 /* XXX this is a terrible API design in libxml++ */
1739 XMLNode *cmt = *(child->children().begin());
1740 _comment = cmt->content();
1742 } else if (child->name() == X_("Extra")) {
1744 _extra_xml = new XMLNode (*child);
1746 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1748 if (prop->value() == "solo") {
1749 _solo_control->set_state (*child);
1750 _session.add_controllable (_solo_control);
1753 } else if (child->name() == X_("RemoteControl")) {
1754 if ((prop = child->property (X_("id"))) != 0) {
1756 sscanf (prop->value().c_str(), "%d", &x);
1757 set_remote_control_id (x);
1760 } else if (child->name() == X_("MuteMaster")) {
1761 _mute_master->set_state (*child);
1769 Route::get_processor_state ()
1771 XMLNode* root = new XMLNode (X_("redirects"));
1772 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1773 root->add_child_nocopy ((*i)->state (true));
1780 Route::set_processor_state (const XMLNode& node)
1782 const XMLNodeList &nlist = node.children();
1783 XMLNodeConstIterator niter;
1784 ProcessorList::iterator i, o;
1786 // Iterate through existing processors, remove those which are not in the state list
1788 for (i = _processors.begin(); i != _processors.end(); ) {
1790 /* leave amp alone, always */
1797 ProcessorList::iterator tmp = i;
1800 bool processorInStateList = false;
1802 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1804 XMLProperty* id_prop = (*niter)->property(X_("id"));
1806 if (id_prop && (*i)->id() == id_prop->value()) {
1807 processorInStateList = true;
1812 if (!processorInStateList) {
1813 remove_processor (*i);
1819 // Iterate through state list and make sure all processors are on the track and in the correct order,
1820 // set the state of existing processors according to the new state on the same go
1822 i = _processors.begin();
1824 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1826 XMLProperty* prop = (*niter)->property ("type");
1830 // Check whether the next processor in the list is the right one,
1831 // except for "amp" which is always there and may not have the
1832 // old ID since it is always created anew in every Route
1834 if (prop->value() != "amp") {
1835 while (o != _processors.end()) {
1836 XMLProperty* id_prop = (*niter)->property(X_("id"));
1837 if (id_prop && (*o)->id() == id_prop->value()) {
1845 // If the processor (*niter) is not on the route,
1846 // create it and move it to the correct location
1848 if (o == _processors.end()) {
1850 if (add_processor_from_xml (**niter, i)) {
1851 --i; // move iterator to the newly inserted processor
1853 cerr << "Error restoring route: unable to restore processor" << endl;
1858 // Otherwise, the processor already exists; just
1859 // ensure it is at the location provided in the XML state
1862 boost::shared_ptr<Processor> tmp = (*o);
1863 _processors.erase (o); // remove the old copy
1864 _processors.insert (i, tmp); // insert the processor at the correct location
1865 --i; // move iterator to the correct processor
1868 // and make it (just) so
1870 (*i)->set_state (**niter);
1874 /* note: there is no configure_processors() call because we figure that
1875 the XML state represents a working signal route.
1878 processors_changed ();
1882 Route::curve_reallocate ()
1884 // _gain_automation_curve.finish_resize ();
1885 // _pan_automation_curve.finish_resize ();
1889 Route::silence (nframes_t nframes)
1893 _output->silence (nframes);
1896 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
1899 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1900 boost::shared_ptr<PluginInsert> pi;
1902 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1903 // skip plugins, they don't need anything when we're not active
1907 (*i)->silence (nframes);
1910 if (nframes == _session.get_block_size()) {
1920 Route::add_internal_return ()
1923 _intreturn.reset (new InternalReturn (_session));
1924 add_processor (_intreturn, PreFader);
1929 Route::get_return_buffer () const
1931 Glib::RWLock::ReaderLock rm (_processor_lock);
1933 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1934 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
1937 BufferSet* bs = d->get_buffers ();
1946 Route::release_return_buffer () const
1948 Glib::RWLock::ReaderLock rm (_processor_lock);
1950 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1951 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
1954 return d->release_buffers ();
1960 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
1962 vector<string> ports;
1963 vector<string>::const_iterator i;
1966 Glib::RWLock::ReaderLock rm (_processor_lock);
1968 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
1970 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
1972 if (d && d->target_route() == route) {
1974 /* if the target is the control outs, then make sure
1975 we take note of which i-send is doing that.
1978 if (route == _session.control_out()) {
1979 _control_outs = boost::dynamic_pointer_cast<Delivery>(d);
1982 /* already listening via the specified IO: do nothing */
1989 boost::shared_ptr<InternalSend> listener;
1992 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
1994 } catch (failed_constructor& err) {
1998 if (route == _session.control_out()) {
1999 _control_outs = listener;
2002 add_processor (listener, placement);
2008 Route::drop_listen (boost::shared_ptr<Route> route)
2010 ProcessorStreams err;
2011 ProcessorList::iterator tmp;
2013 Glib::RWLock::ReaderLock rl(_processor_lock);
2017 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2019 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2021 if (d && d->target_route() == route) {
2023 remove_processor (*x, &err);
2026 /* list could have been demolished while we dropped the lock
2036 if (route == _session.control_out()) {
2037 _control_outs.reset ();
2042 Route::set_route_group (RouteGroup *rg, void *src)
2044 if (rg == _route_group) {
2049 _route_group->remove (this);
2052 if ((_route_group = rg) != 0) {
2053 _route_group->add (this);
2056 _session.set_dirty ();
2057 route_group_changed (src); /* EMIT SIGNAL */
2061 Route::drop_route_group (void *src)
2064 _session.set_dirty ();
2065 route_group_changed (src); /* EMIT SIGNAL */
2069 Route::set_comment (string cmt, void *src)
2072 comment_changed (src);
2073 _session.set_dirty ();
2077 Route::feeds (boost::shared_ptr<Route> other)
2079 // cerr << _name << endl;
2081 if (_output->connected_to (other->input())) {
2082 // cerr << "\tdirect FEEDS " << other->name() << endl;
2086 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2088 boost::shared_ptr<IOProcessor> iop;
2090 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2091 if (iop->feeds (other)) {
2092 // cerr << "\tIOP " << iop->name() << " feeds " << other->name() << endl;
2095 // cerr << "\tIOP " << iop->name() << " does NOT feeds " << other->name() << endl;
2100 // cerr << "\tdoes NOT FEED " << other->name() << endl;
2105 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2107 nframes_t now = _session.transport_frame();
2110 Glib::RWLock::ReaderLock lm (_processor_lock);
2113 automation_snapshot (now, true);
2116 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2118 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2119 (*i)->deactivate ();
2123 (*i)->transport_stopped (now);
2127 _roll_delay = _initial_delay;
2131 Route::input_change_handler (IOChange change, void * /*src*/)
2133 if ((change & ConfigurationChanged)) {
2134 configure_processors (0);
2139 Route::output_change_handler (IOChange change, void * /*src*/)
2141 if ((change & ConfigurationChanged)) {
2143 /* XXX resize all listeners to match _main_outs? */
2145 // configure_processors (0);
2150 Route::pans_required () const
2152 if (n_outputs().n_audio() < 2) {
2156 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2160 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2161 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2163 if (n_outputs().n_total() == 0) {
2167 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2172 _amp->apply_gain_automation (false);
2173 passthru (start_frame, end_frame, nframes, 0);
2179 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2181 if (_roll_delay > nframes) {
2183 _roll_delay -= nframes;
2185 /* transport frame is not legal for caller to use */
2188 } else if (_roll_delay > 0) {
2190 nframes -= _roll_delay;
2191 silence (_roll_delay);
2192 /* we've written _roll_delay of samples into the
2193 output ports, so make a note of that for
2196 _main_outs->increment_output_offset (_roll_delay);
2197 transport_frame += _roll_delay;
2206 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2207 bool /*can_record*/, bool /*rec_monitors_input*/)
2210 // automation snapshot can also be called from the non-rt context
2211 // and it uses the processor list, so we try to acquire the lock here
2212 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2215 automation_snapshot (_session.transport_frame(), false);
2219 if (n_outputs().n_total() == 0) {
2223 if (!_active || n_inputs().n_total() == 0) {
2228 nframes_t unused = 0;
2230 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2236 passthru (start_frame, end_frame, nframes, declick);
2242 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2243 bool /*can_record*/, bool /*rec_monitors_input*/)
2250 Route::toggle_monitor_input ()
2252 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2253 i->ensure_monitor_input( ! i->monitoring_input());
2258 Route::has_external_redirects () const
2260 // FIXME: what about sends? - they don't return a signal back to ardour?
2262 boost::shared_ptr<const PortInsert> pi;
2264 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2266 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2268 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2270 string port_name = port->name();
2271 string client_name = port_name.substr (0, port_name.find(':'));
2273 /* only say "yes" if the redirect is actually in use */
2275 if (client_name != "ardour" && pi->active()) {
2286 Route::flush_processors ()
2288 /* XXX shouldn't really try to take this lock, since
2289 this is called from the RT audio thread.
2292 Glib::RWLock::ReaderLock lm (_processor_lock);
2294 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2295 (*i)->deactivate ();
2301 Route::set_meter_point (MeterPoint p, void *src)
2303 if (_meter_point != p) {
2306 // Move meter in the processors list
2307 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2308 _processors.erase(loc);
2311 loc = _processors.begin();
2314 loc = find(_processors.begin(), _processors.end(), _amp);
2316 case MeterPostFader:
2317 loc = _processors.end();
2320 _processors.insert(loc, _meter);
2322 meter_change (src); /* EMIT SIGNAL */
2323 processors_changed (); /* EMIT SIGNAL */
2324 _session.set_dirty ();
2328 Route::put_control_outs_at (Placement p)
2330 if (!_control_outs) {
2334 // Move meter in the processors list
2335 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _control_outs);
2336 _processors.erase(loc);
2340 loc = find(_processors.begin(), _processors.end(), _amp);
2341 if (loc != _processors.begin()) {
2346 loc = find(_processors.begin(), _processors.end(), _amp);
2347 assert (loc != _processors.end());
2352 _processors.insert(loc, _control_outs);
2354 processors_changed (); /* EMIT SIGNAL */
2355 _session.set_dirty ();
2359 Route::update_total_latency ()
2361 nframes_t old = _output->effective_latency();
2362 nframes_t own_latency = _output->user_latency();
2364 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2365 if ((*i)->active ()) {
2366 own_latency += (*i)->signal_latency ();
2370 #undef DEBUG_LATENCY
2371 #ifdef DEBUG_LATENCY
2372 cerr << _name << ": internal redirect latency = " << own_latency << endl;
2375 _output->set_port_latency (own_latency);
2377 if (_output->user_latency() == 0) {
2379 /* this (virtual) function is used for pure Routes,
2380 not derived classes like AudioTrack. this means
2381 that the data processed here comes from an input
2382 port, not prerecorded material, and therefore we
2383 have to take into account any input latency.
2386 own_latency += _input->signal_latency ();
2389 if (old != own_latency) {
2390 _output->set_latency_delay (own_latency);
2391 signal_latency_changed (); /* EMIT SIGNAL */
2394 #ifdef DEBUG_LATENCY
2395 cerr << _name << ": input latency = " << _input->signal_latency() << " total = "
2396 << own_latency << endl;
2399 return _output->effective_latency ();
2403 Route::set_user_latency (nframes_t nframes)
2405 _output->set_user_latency (nframes);
2406 _session.update_latency_compensation (false, false);
2410 Route::set_latency_delay (nframes_t longest_session_latency)
2412 nframes_t old = _initial_delay;
2414 if (_output->effective_latency() < longest_session_latency) {
2415 _initial_delay = longest_session_latency - _output->effective_latency();
2420 if (_initial_delay != old) {
2421 initial_delay_changed (); /* EMIT SIGNAL */
2424 if (_session.transport_stopped()) {
2425 _roll_delay = _initial_delay;
2430 Route::automation_snapshot (nframes_t now, bool force)
2432 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2433 (*i)->automation_snapshot (now, force);
2437 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2438 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2439 boost::shared_ptr<AutomationList>(), name)
2442 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2447 Route::SoloControllable::set_value (float val)
2449 bool bval = ((val >= 0.5f) ? true: false);
2451 route.set_solo (bval, this);
2455 Route::SoloControllable::get_value (void) const
2457 return route.soloed() ? 1.0f : 0.0f;
2461 Route::set_block_size (nframes_t nframes)
2463 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2464 (*i)->set_block_size (nframes);
2466 _session.ensure_buffers(processor_max_streams);
2470 Route::protect_automation ()
2472 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2473 (*i)->protect_automation();
2477 Route::set_pending_declick (int declick)
2480 /* this call is not allowed to turn off a pending declick unless "force" is true */
2482 _pending_declick = declick;
2484 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2486 _pending_declick = 0;
2491 /** Shift automation forwards from a particular place, thereby inserting time.
2492 * Adds undo commands for any shifts that are performed.
2494 * @param pos Position to start shifting from.
2495 * @param frames Amount to shift forwards by.
2499 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
2501 #ifdef THIS_NEEDS_FIXING_FOR_V3
2503 /* gain automation */
2504 XMLNode &before = _gain_control->get_state ();
2505 _gain_control->shift (pos, frames);
2506 XMLNode &after = _gain_control->get_state ();
2507 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2509 /* pan automation */
2510 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2511 Curve & c = (*i)->automation ();
2512 XMLNode &before = c.get_state ();
2513 c.shift (pos, frames);
2514 XMLNode &after = c.get_state ();
2515 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2518 /* redirect automation */
2520 Glib::RWLock::ReaderLock lm (redirect_lock);
2521 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2524 (*i)->what_has_automation (a);
2526 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2527 AutomationList & al = (*i)->automation_list (*j);
2528 XMLNode &before = al.get_state ();
2529 al.shift (pos, frames);
2530 XMLNode &after = al.get_state ();
2531 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2541 Route::save_as_template (const string& path, const string& name)
2543 XMLNode& node (state (false));
2546 IO::set_name_in_state (*node.children().front(), name);
2548 tree.set_root (&node);
2549 return tree.write (path.c_str());
2554 Route::set_name (const string& str)
2560 name = Route::ensure_track_or_route_name (str, _session);
2561 SessionObject::set_name (name);
2563 ret = (_input->set_name(name) && _output->set_name(name));
2567 Glib::RWLock::ReaderLock lm (_processor_lock);
2569 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2571 /* rename all I/O processors that have inputs or outputs */
2573 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2575 if (iop && (iop->output() || iop->input())) {
2576 if (!iop->set_name (name)) {
2587 boost::shared_ptr<Send>
2588 Route::internal_send_for (boost::shared_ptr<const Route> target) const
2590 Glib::RWLock::ReaderLock lm (_processor_lock);
2592 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2593 boost::shared_ptr<InternalSend> send;
2595 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
2596 if (send->target_route() == target) {
2602 return boost::shared_ptr<Send>();
2606 Route::set_phase_invert (bool yn)
2608 if (_phase_invert != yn) {
2609 _phase_invert = 0xffff; // XXX all channels
2610 phase_invert_changed (); /* EMIT SIGNAL */
2615 Route::phase_invert () const
2617 return _phase_invert != 0;
2621 Route::set_denormal_protection (bool yn)
2623 if (_denormal_protection != yn) {
2624 _denormal_protection = yn;
2625 denormal_protection_changed (); /* EMIT SIGNAL */
2630 Route::denormal_protection () const
2632 return _denormal_protection;
2636 Route::set_active (bool yn)
2638 if (_active != yn) {
2640 _input->set_active (yn);
2641 _output->set_active (yn);
2642 active_changed (); // EMIT SIGNAL
2649 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2655 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2657 boost::shared_ptr<Send> s;
2658 boost::shared_ptr<Return> r;
2660 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
2661 s->meter()->meter();
2662 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
2663 r->meter()->meter ();
2668 boost::shared_ptr<Panner>
2669 Route::panner() const
2672 return _main_outs->panner();
2675 boost::shared_ptr<AutomationControl>
2676 Route::gain_control() const
2679 return _amp->gain_control();
2682 boost::shared_ptr<AutomationControl>
2683 Route::get_control (const Evoral::Parameter& param)
2685 /* either we own the control or .... */
2687 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
2691 /* maybe one of our processors does or ... */
2693 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2694 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2695 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
2703 /* nobody does so we'll make a new one */
2705 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));