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/dB.h"
41 #include "ardour/ladspa_plugin.h"
42 #include "ardour/meter.h"
43 #include "ardour/mix.h"
44 #include "ardour/panner.h"
45 #include "ardour/plugin_insert.h"
46 #include "ardour/port.h"
47 #include "ardour/port_insert.h"
48 #include "ardour/processor.h"
49 #include "ardour/profile.h"
50 #include "ardour/route.h"
51 #include "ardour/route_group.h"
52 #include "ardour/send.h"
53 #include "ardour/session.h"
54 #include "ardour/timestamps.h"
55 #include "ardour/utils.h"
60 using namespace ARDOUR;
63 uint32_t Route::order_key_cnt = 0;
64 sigc::signal<void,const char*> Route::SyncOrderKeys;
66 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
67 : SessionObject (sess, name)
68 , AutomatableControls (sess)
70 , _solo_control (new SoloControllable (X_("solo"), *this))
71 , _mute_master (new MuteMaster (sess, name))
72 , _default_type (default_type)
78 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
79 : SessionObject (sess, "toBeReset")
80 , AutomatableControls (sess)
81 , _solo_control (new SoloControllable (X_("solo"), *this))
82 , _mute_master (new MuteMaster (sess, "toBeReset"))
83 , _default_type (default_type)
86 _set_state (node, false);
93 processor_max_streams.reset();
96 order_keys[strdup (N_("signal"))] = order_key_cnt++;
98 _meter_point = MeterPostFader;
101 _have_internal_generator = false;
102 _declickable = false;
103 _pending_declick = true;
104 _remote_control_id = 0;
105 _in_configure_processors = false;
111 _denormal_protection = false;
113 /* add standard controls */
115 add_control (_solo_control);
116 add_control (_mute_master);
118 /* input and output objects */
120 _input.reset (new IO (_session, _name, IO::Input, _default_type));
121 _output.reset (new IO (_session, _name, IO::Output, _default_type));
123 _input->changed.connect (mem_fun (this, &Route::input_change_handler));
124 _output->changed.connect (mem_fun (this, &Route::output_change_handler));
126 /* add standard processors */
128 _amp.reset (new Amp (_session, _mute_master));
129 add_processor (_amp, PostFader);
131 _meter.reset (new PeakMeter (_session));
132 add_processor (_meter, PreFader);
134 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
135 add_processor (_main_outs, PostFader);
137 /* now we can meter */
139 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
144 Metering::disconnect (_meter_connection);
146 clear_processors (PreFader);
147 clear_processors (PostFader);
149 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
150 free ((void*)(i->first));
155 Route::set_remote_control_id (uint32_t id)
157 if (id != _remote_control_id) {
158 _remote_control_id = id;
159 RemoteControlIDChanged ();
164 Route::remote_control_id() const
166 return _remote_control_id;
170 Route::order_key (const char* name) const
172 OrderKeys::const_iterator i;
174 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
175 if (!strcmp (name, i->first)) {
184 Route::set_order_key (const char* name, long n)
186 order_keys[strdup(name)] = n;
188 if (Config->get_sync_all_route_ordering()) {
189 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
194 _session.set_dirty ();
198 Route::sync_order_keys (const char* base)
200 if (order_keys.empty()) {
204 OrderKeys::iterator i;
207 if ((i = order_keys.find (base)) == order_keys.end()) {
208 /* key doesn't exist, use the first existing key (during session initialization) */
209 i = order_keys.begin();
213 /* key exists - use it and reset all others (actually, itself included) */
215 i = order_keys.begin();
218 for (; i != order_keys.end(); ++i) {
224 Route::ensure_track_or_route_name(string name, Session &session)
226 string newname = name;
228 while (session.route_by_name (newname) != NULL) {
229 newname = bump_name_once (newname);
237 Route::inc_gain (gain_t fraction, void *src)
239 _amp->inc_gain (fraction, src);
243 Route::set_gain (gain_t val, void *src)
245 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
247 if (_mix_group->is_relative()) {
249 gain_t usable_gain = _amp->gain();
250 if (usable_gain < 0.000001f) {
251 usable_gain = 0.000001f;
255 if (delta < 0.000001f) {
259 delta -= usable_gain;
264 gain_t factor = delta / usable_gain;
267 factor = _mix_group->get_max_factor(factor);
268 if (factor == 0.0f) {
269 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
273 factor = _mix_group->get_min_factor(factor);
274 if (factor == 0.0f) {
275 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
280 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
284 _mix_group->apply (&Route::set_gain, val, _mix_group);
290 if (val == _amp->gain()) {
294 _amp->set_gain (val, src);
297 /** Process this route for one (sub) cycle (process thread)
299 * @param bufs Scratch buffers to use for the signal path
300 * @param start_frame Initial transport frame
301 * @param end_frame Final transport frame
302 * @param nframes Number of frames to output (to ports)
304 * Note that (end_frame - start_frame) may not be equal to nframes when the
305 * transport speed isn't 1.0 (eg varispeed).
308 Route::process_output_buffers (BufferSet& bufs,
309 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
310 bool with_processors, int declick)
314 bufs.is_silent (false);
316 switch (Config->get_monitoring_model()) {
317 case HardwareMonitoring:
318 case ExternalMonitoring:
319 monitor = record_enabled() && (_session.config.get_auto_input() || _session.actively_recording());
326 declick = _pending_declick;
329 /* figure out if we're going to use gain automation */
331 _amp->setup_gain_automation (start_frame, end_frame, nframes);
333 /* tell main outs what to do about monitoring */
335 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
337 /* -------------------------------------------------------------------------------------------
338 GLOBAL DECLICK (for transport changes etc.)
339 ----------------------------------------------------------------------------------------- */
342 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
343 } else if (declick < 0) {
344 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
347 _pending_declick = 0;
349 /* -------------------------------------------------------------------------------------------
350 DENORMAL CONTROL/PHASE INVERT
351 ----------------------------------------------------------------------------------------- */
357 if (_denormal_protection || Config->get_denormal_protection()) {
359 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
360 Sample* const sp = i->data();
362 if (_phase_invert & chn) {
363 for (nframes_t nx = 0; nx < nframes; ++nx) {
368 for (nframes_t nx = 0; nx < nframes; ++nx) {
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) {
388 /* -------------------------------------------------------------------------------------------
390 ----------------------------------------------------------------------------------------- */
392 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
395 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
396 bufs.set_count (ChanCount::max(bufs.count(), (*i)->input_streams()));
397 (*i)->run_in_place (bufs, start_frame, end_frame, nframes);
398 bufs.set_count (ChanCount::max(bufs.count(), (*i)->output_streams()));
401 if (!_processors.empty()) {
402 bufs.set_count (ChanCount::max (bufs.count(), _processors.back()->output_streams()));
408 Route::n_process_buffers ()
410 return max (_input->n_ports(), processor_max_streams);
414 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
416 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
420 assert (bufs.available() >= _input->n_ports());
422 if (_input->n_ports() == ChanCount::ZERO) {
426 bufs.set_count (_input->n_ports());
428 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
430 BufferSet::iterator o = bufs.begin(*t);
431 PortSet& ports (_input->ports());
433 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
434 o->read_from (i->get_buffer(nframes), nframes);
438 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
442 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
444 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, true, declick);
448 Route::set_solo (bool yn, void *src)
454 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
455 _mix_group->apply (&Route::set_solo, yn, _mix_group);
459 if (_main_outs->soloed() != yn) {
460 _main_outs->mod_solo_level (yn ? 1 : -1);
461 solo_changed (src); /* EMIT SIGNAL */
462 _solo_control->Changed (); /* EMIT SIGNAL */
467 Route::soloed() const
469 return _main_outs->soloed ();
473 Route::set_solo_isolated (bool yn, void *src)
475 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
476 _mix_group->apply (&Route::set_solo_isolated, yn, _mix_group);
480 _main_outs->set_solo_isolated (yn);
481 solo_isolated_changed (src);
485 Route::solo_isolated () const
487 return _main_outs->solo_isolated();
491 Route::set_mute (bool yn, void *src)
493 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
494 _mix_group->apply (&Route::set_mute, yn, _mix_group);
499 _mute_master->mute (yn);
507 return _mute_master->muted ();
510 #if DEFINE_IF_YOU_NEED_THIS
512 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
514 cerr << name << " {" << endl;
515 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
516 p != procs.end(); ++p) {
517 cerr << "\t" << (*p)->name() << endl;
523 Route::ProcessorList::iterator
524 Route::prefader_iterator()
526 Glib::RWLock::ReaderLock lm (_processor_lock);
527 return find (_processors.begin(), _processors.end(), _amp);
531 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
533 ProcessorList::iterator loc;
535 /* XXX this is not thread safe - we don't hold the lock across determining the iter
536 to add before and actually doing the insertion. dammit.
539 if (placement == PreFader) {
540 /* generic pre-fader: insert immediately before the amp */
541 loc = find(_processors.begin(), _processors.end(), _amp);
543 /* generic post-fader: insert at end */
544 loc = _processors.end();
546 if (processor->visible() && !_processors.empty()) {
547 /* check for invisible processors stacked at the end and leave them there */
548 ProcessorList::iterator p;
549 p = _processors.end();
551 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
552 while (!(*p)->visible() && p != _processors.begin()) {
560 return add_processor (processor, loc, err);
564 /** Add a processor to the route.
565 * If @a iter is not NULL, it must point to an iterator in _processors and the new
566 * processor will be inserted immediately before this location. Otherwise,
567 * @a position is used.
570 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
572 ChanCount old_pms = processor_max_streams;
574 if (!_session.engine().connected() || !processor) {
579 Glib::RWLock::WriterLock lm (_processor_lock);
581 boost::shared_ptr<PluginInsert> pi;
582 boost::shared_ptr<PortInsert> porti;
584 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
586 if (processor == _amp || processor == _meter || processor == _main_outs) {
587 // Ensure only one of these are in the list at any time
588 if (loc != _processors.end()) {
589 if (iter == loc) { // Already in place, do nothing
591 } else { // New position given, relocate
592 _processors.erase (loc);
597 if (loc != _processors.end()) {
598 cerr << "ERROR: Processor added to route twice!" << endl;
605 _processors.insert (loc, processor);
607 // Set up processor list channels. This will set processor->[input|output]_streams(),
608 // configure redirect ports properly, etc.
611 if (configure_processors_unlocked (err)) {
612 ProcessorList::iterator ploc = loc;
614 _processors.erase(ploc);
615 configure_processors_unlocked (0); // it worked before we tried to add it ...
619 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
621 if (pi->natural_input_streams() == ChanCount::ZERO) {
622 /* generator plugin */
623 _have_internal_generator = true;
629 // Ensure peak vector sizes before the plugin is activated
630 ChanCount potential_max_streams = ChanCount::max (processor->input_streams(), processor->output_streams());
631 _meter->configure_io (potential_max_streams, potential_max_streams);
634 // XXX: do we want to emit the signal here ? change call order.
635 processor->activate ();
636 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
638 _output->set_user_latency (0);
641 processors_changed (); /* EMIT SIGNAL */
647 Route::add_processor_from_xml (const XMLNode& node, Placement placement)
649 ProcessorList::iterator loc;
650 if (placement == PreFader) {
651 /* generic pre-fader: insert immediately before the amp */
652 loc = find(_processors.begin(), _processors.end(), _amp);
654 /* generic post-fader: insert at end */
655 loc = _processors.end();
658 return add_processor_from_xml (node, loc);
662 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
664 const XMLProperty *prop;
666 // legacy sessions use a different node name for sends
667 if (node.name() == "Send") {
670 boost::shared_ptr<Send> send (new Send (_session, _mute_master, node));
671 add_processor (send, iter);
675 catch (failed_constructor &err) {
676 error << _("Send construction failed") << endmsg;
680 } else if (node.name() == "Processor") {
683 if ((prop = node.property ("type")) != 0) {
686 cerr << _name << " : got processor type " << prop->value() << endl;
688 boost::shared_ptr<Processor> processor;
689 bool have_insert = false;
691 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
692 prop->value() == "lv2" ||
693 prop->value() == "vst" ||
694 prop->value() == "audiounit") {
696 processor.reset (new PluginInsert(_session, node));
699 } else if (prop->value() == "port") {
701 processor.reset (new PortInsert (_session, _mute_master, node));
703 } else if (prop->value() == "send") {
705 processor.reset (new Send (_session, _mute_master, node));
708 } else if (prop->value() == "meter") {
711 processor->set_state (node);
713 } else if (prop->value() == "amp") {
716 processor->set_state (node);
718 } else if (prop->value() == "listen" || prop->value() == "deliver") {
720 /* XXX need to generalize */
722 processor = _control_outs;
723 processor->set_state (node);
725 } else if (prop->value() == "main-outs") {
727 processor = _main_outs;
728 processor->set_state (node);
732 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
735 if (iter == _processors.end() && processor->visible() && !_processors.empty()) {
736 /* check for invisible processors stacked at the end and leave them there */
737 ProcessorList::iterator p;
738 p = _processors.end();
740 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
741 while (!(*p)->visible() && p != _processors.begin()) {
748 return (add_processor (processor, iter) == 0);
751 error << _("Processor XML node has no type property") << endmsg;
755 catch (failed_constructor &err) {
756 warning << _("processor could not be created. Ignored.") << endmsg;
764 Route::add_processors (const ProcessorList& others, Placement placement, ProcessorStreams* err)
766 ProcessorList::iterator loc;
767 if (placement == PreFader) {
768 /* generic pre-fader: insert immediately before the amp */
769 loc = find(_processors.begin(), _processors.end(), _amp);
771 /* generic post-fader: insert at end */
772 loc = _processors.end();
774 if (!_processors.empty()) {
775 /* check for invisible processors stacked at the end and leave them there */
776 ProcessorList::iterator p;
777 p = _processors.end();
779 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
780 while (!(*p)->visible() && p != _processors.begin()) {
788 return add_processors (others, loc, err);
792 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
794 /* NOTE: this is intended to be used ONLY when copying
795 processors from another Route. Hence the subtle
796 differences between this and ::add_processor()
799 ChanCount old_pms = processor_max_streams;
801 if (!_session.engine().connected()) {
805 if (others.empty()) {
810 Glib::RWLock::WriterLock lm (_processor_lock);
811 ProcessorList::iterator existing_end = _processors.end();
814 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
816 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
818 // Ensure meter only appears in the list once
820 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
821 if (m != _processors.end()) {
822 _processors.erase(m);
826 boost::shared_ptr<PluginInsert> pi;
828 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
831 ChanCount m = max(pi->input_streams(), pi->output_streams());
832 if (m > potential_max_streams)
833 potential_max_streams = m;
836 // Ensure peak vector sizes before the plugin is activated
837 _meter->configure_io (potential_max_streams, potential_max_streams);
839 _processors.insert (iter, *i);
841 if (configure_processors_unlocked (err)) {
843 _processors.erase (existing_end, _processors.end());
844 configure_processors_unlocked (0); // it worked before we tried to add it ...
848 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
851 _output->set_user_latency (0);
854 processors_changed (); /* EMIT SIGNAL */
860 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
863 start = _processors.begin();
864 end = find(_processors.begin(), _processors.end(), _amp);
866 start = find(_processors.begin(), _processors.end(), _amp);
868 end = _processors.end();
872 /** Turn off all processors with a given placement
873 * @param p Placement of processors to disable
876 Route::disable_processors (Placement p)
878 Glib::RWLock::ReaderLock lm (_processor_lock);
880 ProcessorList::iterator start, end;
881 placement_range(p, start, end);
883 for (ProcessorList::iterator i = start; i != end; ++i) {
887 _session.set_dirty ();
890 /** Turn off all redirects
893 Route::disable_processors ()
895 Glib::RWLock::ReaderLock lm (_processor_lock);
897 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
901 _session.set_dirty ();
904 /** Turn off all redirects with a given placement
905 * @param p Placement of redirects to disable
908 Route::disable_plugins (Placement p)
910 Glib::RWLock::ReaderLock lm (_processor_lock);
912 ProcessorList::iterator start, end;
913 placement_range(p, start, end);
915 for (ProcessorList::iterator i = start; i != end; ++i) {
916 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
921 _session.set_dirty ();
924 /** Turn off all plugins
927 Route::disable_plugins ()
929 Glib::RWLock::ReaderLock lm (_processor_lock);
931 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
932 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
937 _session.set_dirty ();
942 Route::ab_plugins (bool forward)
944 Glib::RWLock::ReaderLock lm (_processor_lock);
948 /* forward = turn off all active redirects, and mark them so that the next time
949 we go the other way, we will revert them
952 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
953 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
957 if ((*i)->active()) {
959 (*i)->set_next_ab_is_active (true);
961 (*i)->set_next_ab_is_active (false);
967 /* backward = if the redirect was marked to go active on the next ab, do so */
969 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
971 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
975 if ((*i)->get_next_ab_is_active()) {
983 _session.set_dirty ();
987 /* Figure out the streams that will feed into PreFader */
989 Route::pre_fader_streams() const
991 boost::shared_ptr<Processor> processor;
993 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
995 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
999 if (boost::dynamic_pointer_cast<Send> (*i) == 0) {
1005 return processor->output_streams();
1007 return _input->n_ports ();
1012 /** Remove processors with a given placement.
1013 * @param p Placement of processors to remove.
1016 Route::clear_processors (Placement p)
1018 const ChanCount old_pms = processor_max_streams;
1020 if (!_session.engine().connected()) {
1024 bool already_deleting = _session.deletion_in_progress();
1025 if (!already_deleting) {
1026 _session.set_deletion_in_progress();
1030 Glib::RWLock::WriterLock lm (_processor_lock);
1031 ProcessorList new_list;
1032 ProcessorStreams err;
1034 ProcessorList::iterator amp_loc = find(_processors.begin(), _processors.end(), _amp);
1035 if (p == PreFader) {
1036 // Get rid of PreFader processors
1037 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1038 (*i)->drop_references ();
1041 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1042 new_list.push_back (*i);
1045 // Keep PreFader processors
1046 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1047 new_list.push_back (*i);
1049 new_list.push_back (_amp);
1050 // Get rid of PostFader processors
1051 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1052 (*i)->drop_references ();
1056 _processors = new_list;
1057 configure_processors_unlocked (&err); // this can't fail
1060 processor_max_streams.reset();
1061 _have_internal_generator = false;
1062 processors_changed (); /* EMIT SIGNAL */
1064 if (!already_deleting) {
1065 _session.clear_deletion_in_progress();
1070 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1072 /* these can never be removed */
1074 if (processor == _amp || processor == _meter || processor == _main_outs) {
1078 ChanCount old_pms = processor_max_streams;
1080 if (!_session.engine().connected()) {
1084 processor_max_streams.reset();
1087 Glib::RWLock::WriterLock lm (_processor_lock);
1088 ProcessorList::iterator i;
1089 bool removed = false;
1091 for (i = _processors.begin(); i != _processors.end(); ) {
1092 if (*i == processor) {
1094 /* move along, see failure case for configure_processors()
1095 where we may need to reconfigure the processor.
1098 /* stop redirects that send signals to JACK ports
1099 from causing noise as a result of no longer being
1103 boost::shared_ptr<IOProcessor> iop;
1105 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1107 iop->input()->disconnect (this);
1109 if (iop->output()) {
1110 iop->output()->disconnect (this);
1114 i = _processors.erase (i);
1122 _output->set_user_latency (0);
1130 if (configure_processors_unlocked (err)) {
1131 /* get back to where we where */
1132 _processors.insert (i, processor);
1133 /* we know this will work, because it worked before :) */
1134 configure_processors_unlocked (0);
1138 _have_internal_generator = false;
1140 for (i = _processors.begin(); i != _processors.end(); ++i) {
1141 boost::shared_ptr<PluginInsert> pi;
1143 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1144 if (pi->is_generator()) {
1145 _have_internal_generator = true;
1152 processor->drop_references ();
1153 processors_changed (); /* EMIT SIGNAL */
1159 Route::configure_processors (ProcessorStreams* err)
1161 if (!_in_configure_processors) {
1162 Glib::RWLock::WriterLock lm (_processor_lock);
1163 return configure_processors_unlocked (err);
1168 /** Configure the input/output configuration of each processor in the processors list.
1169 * Return 0 on success, otherwise configuration is impossible.
1172 Route::configure_processors_unlocked (ProcessorStreams* err)
1174 if (_in_configure_processors) {
1178 _in_configure_processors = true;
1180 // Check each processor in order to see if we can configure as requested
1181 ChanCount in = _input->n_ports ();
1183 list< pair<ChanCount,ChanCount> > configuration;
1185 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1186 if ((*p)->can_support_io_configuration(in, out)) {
1187 configuration.push_back(make_pair(in, out));
1194 _in_configure_processors = false;
1199 // We can, so configure everything
1200 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1201 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1202 (*p)->configure_io(c->first, c->second);
1204 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1205 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1209 // Ensure route outputs match last processor's outputs
1210 if (out != _output->n_ports ()) {
1211 _output->ensure_io (out, false, this);
1214 _in_configure_processors = false;
1219 Route::all_processors_flip ()
1221 Glib::RWLock::ReaderLock lm (_processor_lock);
1223 if (_processors.empty()) {
1227 bool first_is_on = _processors.front()->active();
1229 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1231 (*i)->deactivate ();
1237 _session.set_dirty ();
1240 /** Set all processors with a given placement to a given active state.
1241 * @param p Placement of processors to change.
1242 * @param state New active state for those processors.
1245 Route::all_processors_active (Placement p, bool state)
1247 Glib::RWLock::ReaderLock lm (_processor_lock);
1249 if (_processors.empty()) {
1252 ProcessorList::iterator start, end;
1253 placement_range(p, start, end);
1255 bool before_amp = true;
1256 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1261 if (p == PreFader && before_amp) {
1265 (*i)->deactivate ();
1270 _session.set_dirty ();
1274 Route::reorder_processors (const ProcessorList& new_order, Placement placement, ProcessorStreams* err)
1276 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1277 NOTE: all processors in "new_order" MUST be marked as visible. There maybe additional
1278 processors in the current actual processor list that are hidden. Any visible processors
1279 in the current list but not in "new_order" will be assumed to be deleted.
1283 Glib::RWLock::WriterLock lm (_processor_lock);
1284 ChanCount old_pms = processor_max_streams;
1285 ProcessorList::iterator oiter;
1286 ProcessorList::const_iterator niter;
1287 ProcessorList as_it_was_before = _processors;
1288 ProcessorList as_it_will_be;
1289 ProcessorList::iterator start, end;
1291 placement_range (placement, start, end);
1294 niter = new_order.begin();
1296 while (niter != new_order.end()) {
1298 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1299 then append it to the temp list.
1301 Otherwise, see if the next processor in the old list is in the new list. if not,
1302 its been deleted. If its there, append it to the temp list.
1307 /* no more elements in the old list, so just stick the rest of
1308 the new order onto the temp list.
1311 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1312 while (niter != new_order.end()) {
1313 (*niter)->set_placement (placement);
1320 if (!(*oiter)->visible()) {
1322 as_it_will_be.push_back (*oiter);
1323 (*oiter)->set_placement (placement);
1327 /* visible processor: check that its in the new order */
1329 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1330 /* deleted: do nothing, shared_ptr<> will clean up */
1332 /* ignore this one, and add the next item from the new order instead */
1333 as_it_will_be.push_back (*niter);
1334 (*niter)->set_placement (placement);
1339 /* now remove from old order - its taken care of no matter what */
1340 oiter = _processors.erase (oiter);
1345 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1347 if (configure_processors_unlocked (err)) {
1348 _processors = as_it_was_before;
1349 processor_max_streams = old_pms;
1354 processors_changed (); /* EMIT SIGNAL */
1366 Route::get_template()
1368 return state(false);
1372 Route::state(bool full_state)
1374 XMLNode *node = new XMLNode("Route");
1375 ProcessorList::iterator i;
1378 node->add_property ("name", _name);
1379 node->add_property("default-type", _default_type.to_string());
1382 node->add_property("flags", enum_2_string (_flags));
1385 node->add_property("active", _active?"yes":"no");
1386 node->add_property("phase-invert", _phase_invert?"yes":"no");
1387 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1388 node->add_property("meter-point", enum_2_string (_meter_point));
1391 node->add_property("edit-group", _edit_group->name());
1394 node->add_property("mix-group", _mix_group->name());
1397 string order_string;
1398 OrderKeys::iterator x = order_keys.begin();
1400 while (x != order_keys.end()) {
1401 order_string += string ((*x).first);
1402 order_string += '=';
1403 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1404 order_string += buf;
1408 if (x == order_keys.end()) {
1412 order_string += ':';
1414 node->add_property ("order-keys", order_string);
1416 node->add_child_nocopy (_input->state (full_state));
1417 node->add_child_nocopy (_output->state (full_state));
1418 node->add_child_nocopy (_solo_control->get_state ());
1419 node->add_child_nocopy (_mute_master->get_state ());
1421 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1422 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1423 remote_control_node->add_property (X_("id"), buf);
1424 node->add_child_nocopy (*remote_control_node);
1426 if (_comment.length()) {
1427 XMLNode *cmt = node->add_child ("Comment");
1428 cmt->add_content (_comment);
1431 for (i = _processors.begin(); i != _processors.end(); ++i) {
1432 node->add_child_nocopy((*i)->state (full_state));
1436 node->add_child_copy (*_extra_xml);
1443 Route::set_state (const XMLNode& node)
1445 return _set_state (node, true);
1449 Route::_set_state (const XMLNode& node, bool call_base)
1453 XMLNodeConstIterator niter;
1455 XMLPropertyList plist;
1456 const XMLProperty *prop;
1458 if (node.name() != "Route"){
1459 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1463 if ((prop = node.property (X_("name"))) != 0) {
1464 Route::set_name (prop->value());
1467 if ((prop = node.property (X_("flags"))) != 0) {
1468 _flags = Flag (string_2_enum (prop->value(), _flags));
1473 if ((prop = node.property (X_("phase-invert"))) != 0) {
1474 set_phase_invert (prop->value()=="yes"?true:false, this);
1477 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1478 set_denormal_protection (prop->value()=="yes"?true:false, this);
1481 if ((prop = node.property (X_("active"))) != 0) {
1482 bool yn = (prop->value() == "yes");
1483 _active = !yn; // force switch
1487 if ((prop = node.property (X_("soloed"))) != 0) {
1488 bool yn = (prop->value()=="yes");
1490 /* XXX force reset of solo status */
1492 set_solo (yn, this);
1495 if ((prop = node.property (X_("meter-point"))) != 0) {
1496 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1499 if ((prop = node.property (X_("edit-group"))) != 0) {
1500 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1501 if(edit_group == 0) {
1502 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1504 set_edit_group(edit_group, this);
1508 if ((prop = node.property (X_("order-keys"))) != 0) {
1512 string::size_type colon, equal;
1513 string remaining = prop->value();
1515 while (remaining.length()) {
1517 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1518 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1521 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1522 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1525 set_order_key (remaining.substr (0, equal).c_str(), n);
1529 colon = remaining.find_first_of (':');
1531 if (colon != string::npos) {
1532 remaining = remaining.substr (colon+1);
1539 nlist = node.children();
1540 XMLNode processor_state (X_("processor_state"));
1542 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1546 if (child->name() == IO::state_node_name) {
1547 if ((prop = child->property (X_("direction"))) == 0) {
1551 if (prop->value() == "Input") {
1552 _input->set_state (*child);
1553 } else if (prop->value() == "Output") {
1554 _output->set_state (*child);
1558 if (child->name() == X_("Processor")) {
1559 processor_state.add_child_copy (*child);
1563 set_processor_state (processor_state);
1565 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1568 if (child->name() == X_("Comment")) {
1570 /* XXX this is a terrible API design in libxml++ */
1572 XMLNode *cmt = *(child->children().begin());
1573 _comment = cmt->content();
1575 } else if (child->name() == X_("Extra")) {
1577 _extra_xml = new XMLNode (*child);
1579 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1581 if (prop->value() == "solo") {
1582 _solo_control->set_state (*child);
1583 _session.add_controllable (_solo_control);
1586 } else if (child->name() == X_("RemoteControl")) {
1587 if ((prop = child->property (X_("id"))) != 0) {
1589 sscanf (prop->value().c_str(), "%d", &x);
1590 set_remote_control_id (x);
1595 if ((prop = node.property (X_("mix-group"))) != 0) {
1596 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1597 if (mix_group == 0) {
1598 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1600 set_mix_group(mix_group, this);
1608 Route::get_processor_state ()
1610 XMLNode* root = new XMLNode (X_("redirects"));
1611 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1612 root->add_child_nocopy ((*i)->state (true));
1619 Route::set_processor_state (const XMLNode& node)
1621 const XMLNodeList &nlist = node.children();
1622 XMLNodeConstIterator niter;
1623 bool has_meter_processor = false; // legacy sessions don't
1624 ProcessorList::iterator i, o;
1626 cerr << _name << " _set_processor_states\n";
1628 // Iterate through existing processors, remove those which are not in the state list
1629 for (i = _processors.begin(); i != _processors.end(); ) {
1630 ProcessorList::iterator tmp = i;
1633 bool processorInStateList = false;
1635 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1637 XMLProperty* id_prop = (*niter)->property(X_("id"));
1638 if (id_prop && (*i)->id() == id_prop->value()) {
1639 processorInStateList = true;
1644 if (!processorInStateList) {
1645 remove_processor (*i);
1651 // Iterate through state list and make sure all processors are on the track and in the correct order,
1652 // set the state of existing processors according to the new state on the same go
1653 i = _processors.begin();
1655 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1657 XMLProperty* prop = (*niter)->property ("type");
1659 if (prop && prop->value() == "meter") {
1660 has_meter_processor = true;
1663 cerr << _name << " setting up proc state for " << prop->value() << endl;
1667 if (prop->value() != "meter" && prop->value() != "amp" && prop->value() != "main-outs") {
1669 // Check whether the next processor in the list
1671 while (o != _processors.end()) {
1672 XMLProperty* id_prop = (*niter)->property(X_("id"));
1673 if (id_prop && (*o)->id() == id_prop->value()) {
1681 // If the processor (*niter) is not on the route,
1682 // create it and move it to the correct location
1683 if (o == _processors.end()) {
1685 cerr << "\tproc not in list\n";
1687 if (add_processor_from_xml (**niter, i)) {
1688 --i; // move iterator to the newly inserted processor
1690 cerr << "Error restoring route: unable to restore processor" << endl;
1693 // Otherwise, the processor already exists; just
1694 // ensure it is at the location provided in the XML state
1697 cerr << "\tproc in wrong place in list\n";
1700 boost::shared_ptr<Processor> tmp = (*o);
1701 _processors.erase (o); // remove the old copy
1702 _processors.insert (i, tmp); // insert the processor at the correct location
1703 --i; // move iterator to the correct processor
1706 cerr << "\tnow reset proc " << (*i)->name() << endl;
1707 (*i)->set_state (**niter);
1711 /* note: there is no configure_processors() call because we figure that
1712 the XML state represents a working signal route.
1715 if (!has_meter_processor) {
1716 set_meter_point (_meter_point, NULL);
1719 processors_changed ();
1723 Route::curve_reallocate ()
1725 // _gain_automation_curve.finish_resize ();
1726 // _pan_automation_curve.finish_resize ();
1730 Route::silence (nframes_t nframes)
1734 _output->silence (nframes);
1737 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
1740 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1741 boost::shared_ptr<PluginInsert> pi;
1743 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1744 // skip plugins, they don't need anything when we're not active
1748 (*i)->silence (nframes);
1751 if (nframes == _session.get_block_size()) {
1760 boost::shared_ptr<Delivery>
1761 Route::add_listener (boost::shared_ptr<IO> io, const string& listen_name)
1763 string name = _name;
1765 name += listen_name;
1768 boost::shared_ptr<Delivery> listener (new Delivery (_session, _mute_master, name, Delivery::Listen));
1770 /* As an IO, our control outs need as many IO outputs as we have outputs
1771 * (we track the changes in ::output_change_handler()).
1772 * As a processor, the listener is an identity processor
1773 * (i.e. it does not modify its input buffers whatsoever)
1776 if (listener->output()->ensure_io (n_outputs(), true, this)) {
1777 return boost::shared_ptr<Delivery>();
1780 add_processor (listener, PostFader);
1786 Route::listen_via (boost::shared_ptr<IO> io, const string& listen_name)
1788 vector<string> ports;
1789 vector<string>::const_iterator i;
1792 Glib::RWLock::ReaderLock rm (_processor_lock);
1794 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1795 boost::shared_ptr<const Delivery> d = boost::dynamic_pointer_cast<const Delivery>(*x);
1797 if (d && d->output() == io) {
1798 /* already listening via the specified IO: do nothing */
1804 uint32_t ni = io->n_ports().n_total();
1806 for (uint32_t n = 0; n < ni; ++n) {
1807 ports.push_back (io->nth (n)->name());
1810 if (ports.empty()) {
1814 boost::shared_ptr<Delivery> listen_point = add_listener (io, listen_name);
1816 /* XXX hack for now .... until we can generalize listen points */
1818 _control_outs = listen_point;
1820 /* now connect to the named ports */
1822 ni = listen_point->output()->n_ports().n_total();
1823 size_t psize = ports.size();
1825 for (size_t n = 0; n < ni; ++n) {
1826 if (listen_point->output()->connect (listen_point->output()->nth (n), ports[n % psize], this)) {
1827 error << string_compose (_("could not connect %1 to %2"),
1828 listen_point->output()->nth (n)->name(), ports[n % psize]) << endmsg;
1838 Route::drop_listen (boost::shared_ptr<IO> io)
1840 ProcessorStreams err;
1841 ProcessorList::iterator tmp;
1843 Glib::RWLock::ReaderLock rm (_processor_lock);
1845 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
1850 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*x);
1852 if (d && d->output() == io) {
1853 /* already listening via the specified IO: do nothing */
1854 remove_processor (*x, &err);
1863 Route::set_edit_group (RouteGroup *eg, void *src)
1866 if (eg == _edit_group) {
1871 _edit_group->remove (this);
1874 if ((_edit_group = eg) != 0) {
1875 _edit_group->add (this);
1878 _session.set_dirty ();
1879 edit_group_changed (src); /* EMIT SIGNAL */
1883 Route::drop_edit_group (void *src)
1886 _session.set_dirty ();
1887 edit_group_changed (src); /* EMIT SIGNAL */
1891 Route::set_mix_group (RouteGroup *mg, void *src)
1894 if (mg == _mix_group) {
1899 _mix_group->remove (this);
1902 if ((_mix_group = mg) != 0) {
1903 _mix_group->add (this);
1906 _session.set_dirty ();
1907 mix_group_changed (src); /* EMIT SIGNAL */
1911 Route::drop_mix_group (void *src)
1914 _session.set_dirty ();
1915 mix_group_changed (src); /* EMIT SIGNAL */
1919 Route::set_comment (string cmt, void *src)
1922 comment_changed (src);
1923 _session.set_dirty ();
1927 Route::feeds (boost::shared_ptr<IO> other)
1929 if (_output->connected_to (other)) {
1933 /* check IOProcessors which may also interconnect Routes */
1935 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
1937 boost::shared_ptr<IOProcessor> iop;
1939 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
1940 if (iop->output() && iop->output()->connected_to (other)) {
1950 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
1952 nframes_t now = _session.transport_frame();
1955 Glib::RWLock::ReaderLock lm (_processor_lock);
1958 automation_snapshot (now, true);
1961 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1963 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
1964 (*i)->deactivate ();
1968 (*i)->transport_stopped (now);
1972 _roll_delay = _initial_delay;
1976 Route::input_change_handler (IOChange change, void *src)
1978 if ((change & ConfigurationChanged)) {
1979 configure_processors (0);
1984 Route::output_change_handler (IOChange change, void *src)
1986 if ((change & ConfigurationChanged)) {
1988 /* XXX resize all listeners to match _main_outs? */
1990 // configure_processors (0);
1995 Route::pans_required () const
1997 if (n_outputs().n_audio() < 2) {
2001 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2005 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2006 bool session_state_changing, bool can_record, bool rec_monitors_input)
2008 if (n_outputs().n_total() == 0) {
2012 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2017 _amp->apply_gain_automation (false);
2018 passthru (start_frame, end_frame, nframes, 0);
2024 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2026 if (_roll_delay > nframes) {
2028 _roll_delay -= nframes;
2030 /* transport frame is not legal for caller to use */
2033 } else if (_roll_delay > 0) {
2035 nframes -= _roll_delay;
2036 silence (_roll_delay);
2037 /* we've written _roll_delay of samples into the
2038 output ports, so make a note of that for
2041 _main_outs->increment_output_offset (_roll_delay);
2042 transport_frame += _roll_delay;
2051 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2052 bool can_record, bool rec_monitors_input)
2055 // automation snapshot can also be called from the non-rt context
2056 // and it uses the processor list, so we try to acquire the lock here
2057 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2060 automation_snapshot (_session.transport_frame(), false);
2064 if (n_outputs().n_total() == 0) {
2068 if (!_active || n_inputs().n_total() == 0) {
2073 nframes_t unused = 0;
2075 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2081 passthru (start_frame, end_frame, nframes, declick);
2087 Route::silent_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2088 bool can_record, bool rec_monitors_input)
2095 Route::toggle_monitor_input ()
2097 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2098 i->ensure_monitor_input( ! i->monitoring_input());
2103 Route::has_external_redirects () const
2105 // FIXME: what about sends? - they don't return a signal back to ardour?
2107 boost::shared_ptr<const PortInsert> pi;
2109 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2111 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2113 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2115 string port_name = port->name();
2116 string client_name = port_name.substr (0, port_name.find(':'));
2118 /* only say "yes" if the redirect is actually in use */
2120 if (client_name != "ardour" && pi->active()) {
2131 Route::flush_processors ()
2133 /* XXX shouldn't really try to take this lock, since
2134 this is called from the RT audio thread.
2137 Glib::RWLock::ReaderLock lm (_processor_lock);
2139 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2140 (*i)->deactivate ();
2146 Route::set_meter_point (MeterPoint p, void *src)
2148 if (_meter_point != p) {
2151 // Move meter in the processors list
2152 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2153 _processors.erase(loc);
2156 loc = _processors.begin();
2159 loc = find(_processors.begin(), _processors.end(), _amp);
2161 case MeterPostFader:
2162 loc = _processors.end();
2165 _processors.insert(loc, _meter);
2167 meter_change (src); /* EMIT SIGNAL */
2168 processors_changed (); /* EMIT SIGNAL */
2169 _session.set_dirty ();
2174 Route::update_total_latency ()
2176 nframes_t old = _output->effective_latency();
2177 nframes_t own_latency = _output->user_latency();
2179 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2180 if ((*i)->active ()) {
2181 own_latency += (*i)->signal_latency ();
2185 #undef DEBUG_LATENCY
2186 #ifdef DEBUG_LATENCY
2187 cerr << _name << ": internal redirect latency = " << own_latency << endl;
2190 _output->set_port_latency (own_latency);
2192 if (_output->user_latency() == 0) {
2194 /* this (virtual) function is used for pure Routes,
2195 not derived classes like AudioTrack. this means
2196 that the data processed here comes from an input
2197 port, not prerecorded material, and therefore we
2198 have to take into account any input latency.
2201 own_latency += _input->signal_latency ();
2204 if (old != own_latency) {
2205 _output->set_latency_delay (own_latency);
2206 signal_latency_changed (); /* EMIT SIGNAL */
2209 #ifdef DEBUG_LATENCY
2210 cerr << _name << ": input latency = " << _input->signal_latency() << " total = "
2211 << own_latency << endl;
2214 return _output->effective_latency ();
2218 Route::set_user_latency (nframes_t nframes)
2220 _output->set_user_latency (nframes);
2221 _session.update_latency_compensation (false, false);
2225 Route::set_latency_delay (nframes_t longest_session_latency)
2227 nframes_t old = _initial_delay;
2229 if (_output->effective_latency() < longest_session_latency) {
2230 _initial_delay = longest_session_latency - _output->effective_latency();
2235 if (_initial_delay != old) {
2236 initial_delay_changed (); /* EMIT SIGNAL */
2239 if (_session.transport_stopped()) {
2240 _roll_delay = _initial_delay;
2245 Route::automation_snapshot (nframes_t now, bool force)
2247 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2248 (*i)->automation_snapshot (now, force);
2252 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2253 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2254 boost::shared_ptr<AutomationList>(), name)
2257 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2262 Route::SoloControllable::set_value (float val)
2264 bool bval = ((val >= 0.5f) ? true: false);
2266 route.set_solo (bval, this);
2270 Route::SoloControllable::get_value (void) const
2272 return route.soloed() ? 1.0f : 0.0f;
2276 Route::set_block_size (nframes_t nframes)
2278 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2279 (*i)->set_block_size (nframes);
2281 _session.ensure_buffers(processor_max_streams);
2285 Route::protect_automation ()
2287 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2288 (*i)->protect_automation();
2292 Route::set_pending_declick (int declick)
2295 /* this call is not allowed to turn off a pending declick unless "force" is true */
2297 _pending_declick = declick;
2299 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2301 _pending_declick = 0;
2306 /** Shift automation forwards from a particular place, thereby inserting time.
2307 * Adds undo commands for any shifts that are performed.
2309 * @param pos Position to start shifting from.
2310 * @param frames Amount to shift forwards by.
2314 Route::shift (nframes64_t pos, nframes64_t frames)
2316 #ifdef THIS_NEEDS_FIXING_FOR_V3
2318 /* gain automation */
2319 XMLNode &before = _gain_control->get_state ();
2320 _gain_control->shift (pos, frames);
2321 XMLNode &after = _gain_control->get_state ();
2322 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2324 /* pan automation */
2325 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2326 Curve & c = (*i)->automation ();
2327 XMLNode &before = c.get_state ();
2328 c.shift (pos, frames);
2329 XMLNode &after = c.get_state ();
2330 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2333 /* redirect automation */
2335 Glib::RWLock::ReaderLock lm (redirect_lock);
2336 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2339 (*i)->what_has_automation (a);
2341 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2342 AutomationList & al = (*i)->automation_list (*j);
2343 XMLNode &before = al.get_state ();
2344 al.shift (pos, frames);
2345 XMLNode &after = al.get_state ();
2346 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2356 Route::save_as_template (const string& path, const string& name)
2358 XMLNode& node (state (false));
2361 IO::set_name_in_state (*node.children().front(), name);
2363 tree.set_root (&node);
2364 return tree.write (path.c_str());
2369 Route::set_name (const string& str)
2374 SessionObject::set_name (str);
2376 ret = (_input->set_name(str) && _output->set_name(str));
2380 Glib::RWLock::ReaderLock lm (_processor_lock);
2382 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2384 /* rename all processors with outputs to reflect our new name */
2386 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2389 string iop_name = str;
2391 iop_name += "XXX FIX ME XXX";
2394 if (!iop->set_name (iop_name)) {
2405 boost::shared_ptr<Send>
2406 Route::send_for (boost::shared_ptr<const IO> target) const
2408 Glib::RWLock::ReaderLock lm (_processor_lock);
2410 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2411 boost::shared_ptr<Send> send;
2413 if ((send = boost::dynamic_pointer_cast<Send>(*i)) != 0) {
2414 if (send->output()->connected_to (target)) {
2420 return boost::shared_ptr<Send>();
2424 Route::set_phase_invert (bool yn, void *src)
2426 if (_phase_invert != yn) {
2428 // phase_invert_changed (src); /* EMIT SIGNAL */
2433 Route::phase_invert () const
2435 return _phase_invert != 0;
2439 Route::set_denormal_protection (bool yn, void *src)
2441 if (_denormal_protection != yn) {
2442 _denormal_protection = yn;
2443 // denormal_protection_changed (src); /* EMIT SIGNAL */
2448 Route::denormal_protection () const
2450 return _denormal_protection;
2454 Route::set_active (bool yn)
2456 if (_active != yn) {
2458 _input->set_active (yn);
2459 _output->set_active (yn);
2460 active_changed (); // EMIT SIGNAL
2467 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2471 boost::shared_ptr<Panner>
2472 Route::panner() const
2475 return _main_outs->panner();
2478 boost::shared_ptr<AutomationControl>
2479 Route::gain_control() const
2482 return _amp->gain_control();
2485 boost::shared_ptr<AutomationControl>
2486 Route::get_control (const Evoral::Parameter& param)
2488 /* either we own the control or .... */
2490 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
2494 /* maybe one of our processors does or ... */
2496 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2497 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2498 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
2506 /* nobody does so we'll make a new one */
2508 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));