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,const char*> 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[strdup (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;
139 _denormal_protection = false;
141 /* add standard controls */
143 add_control (_solo_control);
144 add_control (_mute_master);
146 /* input and output objects */
148 _input.reset (new IO (_session, _name, IO::Input, _default_type));
149 _output.reset (new IO (_session, _name, IO::Output, _default_type));
151 _input->changed.connect (mem_fun (this, &Route::input_change_handler));
152 _output->changed.connect (mem_fun (this, &Route::output_change_handler));
154 /* add amp processor */
156 _amp.reset (new Amp (_session, _mute_master));
157 add_processor (_amp, PostFader);
162 Metering::disconnect (_meter_connection);
164 clear_processors (PreFader);
165 clear_processors (PostFader);
167 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
168 free ((void*)(i->first));
173 Route::set_remote_control_id (uint32_t id)
175 if (id != _remote_control_id) {
176 _remote_control_id = id;
177 RemoteControlIDChanged ();
182 Route::remote_control_id() const
184 return _remote_control_id;
188 Route::order_key (const char* name) const
190 OrderKeys::const_iterator i;
192 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
193 if (!strcmp (name, i->first)) {
202 Route::set_order_key (const char* name, long n)
204 order_keys[strdup(name)] = n;
206 if (Config->get_sync_all_route_ordering()) {
207 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
212 _session.set_dirty ();
216 Route::sync_order_keys (const char* base)
218 if (order_keys.empty()) {
222 OrderKeys::iterator i;
225 if ((i = order_keys.find (base)) == order_keys.end()) {
226 /* key doesn't exist, use the first existing key (during session initialization) */
227 i = order_keys.begin();
231 /* key exists - use it and reset all others (actually, itself included) */
233 i = order_keys.begin();
236 for (; i != order_keys.end(); ++i) {
242 Route::ensure_track_or_route_name(string name, Session &session)
244 string newname = name;
246 while (session.route_by_name (newname) != NULL) {
247 newname = bump_name_once (newname);
255 Route::inc_gain (gain_t fraction, void *src)
257 _amp->inc_gain (fraction, src);
261 Route::set_gain (gain_t val, void *src)
263 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
265 if (_mix_group->is_relative()) {
267 gain_t usable_gain = _amp->gain();
268 if (usable_gain < 0.000001f) {
269 usable_gain = 0.000001f;
273 if (delta < 0.000001f) {
277 delta -= usable_gain;
282 gain_t factor = delta / usable_gain;
285 factor = _mix_group->get_max_factor(factor);
286 if (factor == 0.0f) {
287 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
291 factor = _mix_group->get_min_factor(factor);
292 if (factor == 0.0f) {
293 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
298 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
302 _mix_group->apply (&Route::set_gain, val, _mix_group);
308 if (val == _amp->gain()) {
312 _amp->set_gain (val, src);
315 /** Process this route for one (sub) cycle (process thread)
317 * @param bufs Scratch buffers to use for the signal path
318 * @param start_frame Initial transport frame
319 * @param end_frame Final transport frame
320 * @param nframes Number of frames to output (to ports)
322 * Note that (end_frame - start_frame) may not be equal to nframes when the
323 * transport speed isn't 1.0 (eg varispeed).
326 Route::process_output_buffers (BufferSet& bufs,
327 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
328 bool with_processors, int declick)
332 bufs.is_silent (false);
334 switch (Config->get_monitoring_model()) {
335 case HardwareMonitoring:
336 case ExternalMonitoring:
337 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
344 declick = _pending_declick;
347 /* figure out if we're going to use gain automation */
348 _amp->setup_gain_automation (start_frame, end_frame, nframes);
351 /* tell main outs what to do about monitoring */
352 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
355 /* -------------------------------------------------------------------------------------------
356 GLOBAL DECLICK (for transport changes etc.)
357 ----------------------------------------------------------------------------------------- */
360 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
361 } else if (declick < 0) {
362 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
365 _pending_declick = 0;
367 /* -------------------------------------------------------------------------------------------
368 DENORMAL CONTROL/PHASE INVERT
369 ----------------------------------------------------------------------------------------- */
375 if (_denormal_protection || Config->get_denormal_protection()) {
377 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
378 Sample* const sp = i->data();
380 if (_phase_invert & chn) {
381 for (nframes_t nx = 0; nx < nframes; ++nx) {
386 for (nframes_t nx = 0; nx < nframes; ++nx) {
394 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
395 Sample* const sp = i->data();
397 if (_phase_invert & chn) {
398 for (nframes_t nx = 0; nx < nframes; ++nx) {
407 if (_denormal_protection || Config->get_denormal_protection()) {
409 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
410 Sample* const sp = i->data();
411 for (nframes_t nx = 0; nx < nframes; ++nx) {
419 /* -------------------------------------------------------------------------------------------
421 ----------------------------------------------------------------------------------------- */
423 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
426 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
427 bufs.set_count (ChanCount::max(bufs.count(), (*i)->input_streams()));
428 (*i)->run (bufs, start_frame, end_frame, nframes);
429 bufs.set_count (ChanCount::max(bufs.count(), (*i)->output_streams()));
432 if (!_processors.empty()) {
433 bufs.set_count (ChanCount::max (bufs.count(), _processors.back()->output_streams()));
439 Route::n_process_buffers ()
441 return max (_input->n_ports(), processor_max_streams);
445 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
447 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
451 assert (bufs.available() >= _input->n_ports());
453 if (_input->n_ports() == ChanCount::ZERO) {
457 bufs.set_count (_input->n_ports());
459 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
461 BufferSet::iterator o = bufs.begin(*t);
462 PortSet& ports (_input->ports());
464 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
465 o->read_from (i->get_buffer(nframes), nframes);
469 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
473 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
475 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, true, declick);
479 Route::set_solo (bool yn, void *src)
481 if (_solo_safe || _solo_isolated) {
485 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
486 _mix_group->apply (&Route::set_solo, yn, _mix_group);
490 if (soloed() != yn) {
491 mod_solo_level (yn ? 1 : -1);
492 solo_changed (src); /* EMIT SIGNAL */
493 _solo_control->Changed (); /* EMIT SIGNAL */
498 Route::mod_solo_level (int32_t delta)
501 if (_solo_level >= (uint32_t) delta) {
502 _solo_level += delta;
507 _solo_level += delta;
510 /* tell "special" delivery units what the solo situation is
513 switch (Config->get_solo_model()) {
515 /* main outs are used for soloing */
516 _main_outs->set_solo_level (_solo_level);
517 _main_outs->set_solo_isolated (_solo_isolated);
519 /* control outs just keep on playing */
520 _control_outs->set_solo_level (0);
521 _control_outs->set_solo_isolated (true);
527 /* control outs are used for soloing */
529 _control_outs->set_solo_level (_solo_level);
530 _control_outs->set_solo_isolated (_solo_isolated);
532 /* main outs just keep on playing */
533 _main_outs->set_solo_level (0);
534 _main_outs->set_solo_isolated (true);
540 Route::set_solo_isolated (bool yn, void *src)
542 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
543 _mix_group->apply (&Route::set_solo_isolated, yn, _mix_group);
547 if (yn != _solo_isolated) {
550 /* tell "special" delivery units what the solo situation is
553 switch (Config->get_solo_model()) {
555 _main_outs->set_solo_level (_solo_level);
556 _main_outs->set_solo_isolated (_solo_isolated);
558 _main_outs->set_solo_level (1);
559 _main_outs->set_solo_isolated (false);
565 _control_outs->set_solo_level (_solo_level);
566 _control_outs->set_solo_isolated (_solo_isolated);
568 _main_outs->set_solo_level (1);
569 _main_outs->set_solo_isolated (false);
573 solo_isolated_changed (src);
578 Route::solo_isolated () const
580 return _solo_isolated;
584 Route::set_mute (bool yn, void *src)
586 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
587 _mix_group->apply (&Route::set_mute, yn, _mix_group);
592 _mute_master->mute (yn);
600 return _mute_master->muted ();
605 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
607 cerr << name << " {" << endl;
608 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
609 p != procs.end(); ++p) {
610 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
617 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
619 ProcessorList::iterator loc;
621 /* XXX this is not thread safe - we don't hold the lock across determining the iter
622 to add before and actually doing the insertion. dammit.
625 if (placement == PreFader) {
626 /* generic pre-fader: insert immediately before the amp */
627 loc = find(_processors.begin(), _processors.end(), _amp);
629 /* generic post-fader: insert at end */
630 loc = _processors.end();
632 if (processor->visible() && !_processors.empty()) {
633 /* check for invisible processors stacked at the end and leave them there */
634 ProcessorList::iterator p;
635 p = _processors.end();
637 while (!(*p)->visible() && p != _processors.begin()) {
645 return add_processor (processor, loc, err);
649 /** Add a processor to the route.
650 * If @a iter is not NULL, it must point to an iterator in _processors and the new
651 * processor will be inserted immediately before this location. Otherwise,
652 * @a position is used.
655 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
657 ChanCount old_pms = processor_max_streams;
659 if (!_session.engine().connected() || !processor) {
664 Glib::RWLock::WriterLock lm (_processor_lock);
666 boost::shared_ptr<PluginInsert> pi;
667 boost::shared_ptr<PortInsert> porti;
669 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
671 if (processor == _amp || processor == _meter || processor == _main_outs) {
672 // Ensure only one of these are in the list at any time
673 if (loc != _processors.end()) {
674 if (iter == loc) { // Already in place, do nothing
676 } else { // New position given, relocate
677 _processors.erase (loc);
682 if (loc != _processors.end()) {
683 cerr << "ERROR: Processor added to route twice!" << endl;
690 _processors.insert (loc, processor);
692 // Set up processor list channels. This will set processor->[input|output]_streams(),
693 // configure redirect ports properly, etc.
696 if (configure_processors_unlocked (err)) {
697 ProcessorList::iterator ploc = loc;
699 _processors.erase(ploc);
700 configure_processors_unlocked (0); // it worked before we tried to add it ...
701 cerr << "configure failed\n";
705 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
707 if (pi->natural_input_streams() == ChanCount::ZERO) {
708 /* generator plugin */
709 _have_internal_generator = true;
715 // Ensure peak vector sizes before the plugin is activated
716 ChanCount potential_max_streams = ChanCount::max (processor->input_streams(), processor->output_streams());
717 _meter->configure_io (potential_max_streams, potential_max_streams);
720 // XXX: do we want to emit the signal here ? change call order.
721 processor->activate ();
722 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
724 _output->set_user_latency (0);
727 processors_changed (); /* EMIT SIGNAL */
733 Route::add_processor_from_xml (const XMLNode& node, Placement placement)
735 ProcessorList::iterator loc;
737 if (placement == PreFader) {
738 /* generic pre-fader: insert immediately before the amp */
739 loc = find(_processors.begin(), _processors.end(), _amp);
741 /* generic post-fader: insert at end */
742 loc = _processors.end();
745 return add_processor_from_xml (node, loc);
749 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
751 const XMLProperty *prop;
753 // legacy sessions use a different node name for sends
754 if (node.name() == "Send") {
757 boost::shared_ptr<Send> send (new Send (_session, _mute_master, node));
758 add_processor (send, iter);
762 catch (failed_constructor &err) {
763 error << _("Send construction failed") << endmsg;
767 } else if (node.name() == "Processor") {
770 if ((prop = node.property ("type")) != 0) {
772 boost::shared_ptr<Processor> processor;
774 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
775 prop->value() == "lv2" ||
776 prop->value() == "vst" ||
777 prop->value() == "audiounit") {
779 processor.reset (new PluginInsert(_session, node));
781 } else if (prop->value() == "port") {
783 processor.reset (new PortInsert (_session, _mute_master, node));
785 } else if (prop->value() == "send") {
787 processor.reset (new Send (_session, _mute_master, node));
789 } else if (prop->value() == "meter") {
792 if (_meter->set_state (node)) {
799 _meter.reset (new PeakMeter (_session, node));
802 } else if (prop->value() == "amp") {
804 /* amp always exists */
807 if (processor->set_state (node)) {
810 /* never any reason to add it */
814 } else if (prop->value() == "listen" || prop->value() == "deliver") {
816 /* XXX need to generalize */
818 } else if (prop->value() == "intsend") {
820 processor.reset (new InternalSend (_session, _mute_master, node));
822 } else if (prop->value() == "intreturn") {
825 if (_intreturn->set_state (node)) {
831 _intreturn.reset (new InternalReturn (_session, node));
832 processor = _intreturn;
834 } else if (prop->value() == "main-outs") {
837 if (_main_outs->set_state (node)) {
844 _main_outs.reset (new Delivery (_session, _output, _mute_master, node));
845 processor = _main_outs;
848 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
851 if (iter == _processors.end() && processor->visible() && !_processors.empty()) {
852 /* check for invisible processors stacked at the end and leave them there */
853 ProcessorList::iterator p;
854 p = _processors.end();
856 while (!(*p)->visible() && p != _processors.begin()) {
863 return (add_processor (processor, iter) == 0);
866 error << _("Processor XML node has no type property") << endmsg;
870 catch (failed_constructor &err) {
871 warning << _("processor could not be created. Ignored.") << endmsg;
879 Route::add_processors (const ProcessorList& others, Placement placement, ProcessorStreams* err)
881 ProcessorList::iterator loc;
882 if (placement == PreFader) {
883 /* generic pre-fader: insert immediately before the amp */
884 loc = find(_processors.begin(), _processors.end(), _amp);
886 /* generic post-fader: insert at end */
887 loc = _processors.end();
889 if (!_processors.empty()) {
890 /* check for invisible processors stacked at the end and leave them there */
891 ProcessorList::iterator p;
892 p = _processors.end();
894 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
895 while (!(*p)->visible() && p != _processors.begin()) {
903 return add_processors (others, loc, err);
907 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
909 /* NOTE: this is intended to be used ONLY when copying
910 processors from another Route. Hence the subtle
911 differences between this and ::add_processor()
914 ChanCount old_pms = processor_max_streams;
916 if (!_session.engine().connected()) {
920 if (others.empty()) {
925 Glib::RWLock::WriterLock lm (_processor_lock);
926 ProcessorList::iterator existing_end = _processors.end();
929 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
931 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
933 // Ensure meter only appears in the list once
935 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
936 if (m != _processors.end()) {
937 _processors.erase(m);
941 boost::shared_ptr<PluginInsert> pi;
943 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
946 ChanCount m = max(pi->input_streams(), pi->output_streams());
947 if (m > potential_max_streams)
948 potential_max_streams = m;
951 // Ensure peak vector sizes before the plugin is activated
952 _meter->configure_io (potential_max_streams, potential_max_streams);
954 _processors.insert (iter, *i);
956 if (configure_processors_unlocked (err)) {
958 _processors.erase (existing_end, _processors.end());
959 configure_processors_unlocked (0); // it worked before we tried to add it ...
963 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
966 _output->set_user_latency (0);
969 processors_changed (); /* EMIT SIGNAL */
975 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
978 start = _processors.begin();
979 end = find(_processors.begin(), _processors.end(), _amp);
981 start = find(_processors.begin(), _processors.end(), _amp);
983 end = _processors.end();
987 /** Turn off all processors with a given placement
988 * @param p Placement of processors to disable
991 Route::disable_processors (Placement p)
993 Glib::RWLock::ReaderLock lm (_processor_lock);
995 ProcessorList::iterator start, end;
996 placement_range(p, start, end);
998 for (ProcessorList::iterator i = start; i != end; ++i) {
1002 _session.set_dirty ();
1005 /** Turn off all redirects
1008 Route::disable_processors ()
1010 Glib::RWLock::ReaderLock lm (_processor_lock);
1012 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1013 (*i)->deactivate ();
1016 _session.set_dirty ();
1019 /** Turn off all redirects with a given placement
1020 * @param p Placement of redirects to disable
1023 Route::disable_plugins (Placement p)
1025 Glib::RWLock::ReaderLock lm (_processor_lock);
1027 ProcessorList::iterator start, end;
1028 placement_range(p, start, end);
1030 for (ProcessorList::iterator i = start; i != end; ++i) {
1031 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1032 (*i)->deactivate ();
1036 _session.set_dirty ();
1039 /** Turn off all plugins
1042 Route::disable_plugins ()
1044 Glib::RWLock::ReaderLock lm (_processor_lock);
1046 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1047 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1048 (*i)->deactivate ();
1052 _session.set_dirty ();
1057 Route::ab_plugins (bool forward)
1059 Glib::RWLock::ReaderLock lm (_processor_lock);
1063 /* forward = turn off all active redirects, and mark them so that the next time
1064 we go the other way, we will revert them
1067 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1068 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1072 if ((*i)->active()) {
1073 (*i)->deactivate ();
1074 (*i)->set_next_ab_is_active (true);
1076 (*i)->set_next_ab_is_active (false);
1082 /* backward = if the redirect was marked to go active on the next ab, do so */
1084 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1086 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1090 if ((*i)->get_next_ab_is_active()) {
1093 (*i)->deactivate ();
1098 _session.set_dirty ();
1102 /** Remove processors with a given placement.
1103 * @param p Placement of processors to remove.
1106 Route::clear_processors (Placement p)
1108 const ChanCount old_pms = processor_max_streams;
1110 if (!_session.engine().connected()) {
1114 bool already_deleting = _session.deletion_in_progress();
1115 if (!already_deleting) {
1116 _session.set_deletion_in_progress();
1120 Glib::RWLock::WriterLock lm (_processor_lock);
1121 ProcessorList new_list;
1122 ProcessorStreams err;
1124 ProcessorList::iterator amp_loc = find(_processors.begin(), _processors.end(), _amp);
1125 if (p == PreFader) {
1126 // Get rid of PreFader processors
1127 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1128 (*i)->drop_references ();
1131 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1132 new_list.push_back (*i);
1135 // Keep PreFader processors
1136 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1137 new_list.push_back (*i);
1139 new_list.push_back (_amp);
1140 // Get rid of PostFader processors
1141 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1142 (*i)->drop_references ();
1146 _processors = new_list;
1147 configure_processors_unlocked (&err); // this can't fail
1150 processor_max_streams.reset();
1151 _have_internal_generator = false;
1152 processors_changed (); /* EMIT SIGNAL */
1154 if (!already_deleting) {
1155 _session.clear_deletion_in_progress();
1160 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1162 /* these can never be removed */
1164 if (processor == _amp || processor == _meter || processor == _main_outs) {
1168 ChanCount old_pms = processor_max_streams;
1170 if (!_session.engine().connected()) {
1174 processor_max_streams.reset();
1177 Glib::RWLock::WriterLock lm (_processor_lock);
1178 ProcessorList::iterator i;
1179 bool removed = false;
1181 for (i = _processors.begin(); i != _processors.end(); ) {
1182 if (*i == processor) {
1184 /* move along, see failure case for configure_processors()
1185 where we may need to reconfigure the processor.
1188 /* stop redirects that send signals to JACK ports
1189 from causing noise as a result of no longer being
1193 boost::shared_ptr<IOProcessor> iop;
1195 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1197 iop->input()->disconnect (this);
1199 if (iop->output()) {
1200 iop->output()->disconnect (this);
1204 i = _processors.erase (i);
1212 _output->set_user_latency (0);
1220 if (configure_processors_unlocked (err)) {
1221 /* get back to where we where */
1222 _processors.insert (i, processor);
1223 /* we know this will work, because it worked before :) */
1224 configure_processors_unlocked (0);
1228 _have_internal_generator = false;
1230 for (i = _processors.begin(); i != _processors.end(); ++i) {
1231 boost::shared_ptr<PluginInsert> pi;
1233 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1234 if (pi->is_generator()) {
1235 _have_internal_generator = true;
1242 processor->drop_references ();
1243 processors_changed (); /* EMIT SIGNAL */
1249 Route::configure_processors (ProcessorStreams* err)
1251 if (!_in_configure_processors) {
1252 Glib::RWLock::WriterLock lm (_processor_lock);
1253 return configure_processors_unlocked (err);
1258 /** Configure the input/output configuration of each processor in the processors list.
1259 * Return 0 on success, otherwise configuration is impossible.
1262 Route::configure_processors_unlocked (ProcessorStreams* err)
1264 if (_in_configure_processors) {
1268 _in_configure_processors = true;
1270 // Check each processor in order to see if we can configure as requested
1271 ChanCount in = _input->n_ports ();
1273 list< pair<ChanCount,ChanCount> > configuration;
1276 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1277 if ((*p)->can_support_io_configuration(in, out)) {
1278 configuration.push_back(make_pair(in, out));
1285 _in_configure_processors = false;
1290 // We can, so configure everything
1291 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1292 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1293 (*p)->configure_io(c->first, c->second);
1295 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1296 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1300 // Ensure route outputs match last processor's outputs
1301 if (out != _output->n_ports ()) {
1302 _output->ensure_io (out, false, this);
1305 _in_configure_processors = false;
1310 Route::all_processors_flip ()
1312 Glib::RWLock::ReaderLock lm (_processor_lock);
1314 if (_processors.empty()) {
1318 bool first_is_on = _processors.front()->active();
1320 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1322 (*i)->deactivate ();
1328 _session.set_dirty ();
1331 /** Set all processors with a given placement to a given active state.
1332 * @param p Placement of processors to change.
1333 * @param state New active state for those processors.
1336 Route::all_processors_active (Placement p, bool state)
1338 Glib::RWLock::ReaderLock lm (_processor_lock);
1340 if (_processors.empty()) {
1343 ProcessorList::iterator start, end;
1344 placement_range(p, start, end);
1346 bool before_amp = true;
1347 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1352 if (p == PreFader && before_amp) {
1356 (*i)->deactivate ();
1361 _session.set_dirty ();
1365 Route::reorder_processors (const ProcessorList& new_order, Placement placement, ProcessorStreams* err)
1367 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1368 NOTE: all processors in "new_order" MUST be marked as visible. There maybe additional
1369 processors in the current actual processor list that are hidden. Any visible processors
1370 in the current list but not in "new_order" will be assumed to be deleted.
1374 Glib::RWLock::WriterLock lm (_processor_lock);
1375 ChanCount old_pms = processor_max_streams;
1376 ProcessorList::iterator oiter;
1377 ProcessorList::const_iterator niter;
1378 ProcessorList as_it_was_before = _processors;
1379 ProcessorList as_it_will_be;
1380 ProcessorList::iterator start, end;
1382 placement_range (placement, start, end);
1385 niter = new_order.begin();
1387 while (niter != new_order.end()) {
1389 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1390 then append it to the temp list.
1392 Otherwise, see if the next processor in the old list is in the new list. if not,
1393 its been deleted. If its there, append it to the temp list.
1398 /* no more elements in the old list, so just stick the rest of
1399 the new order onto the temp list.
1402 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1403 while (niter != new_order.end()) {
1404 (*niter)->set_placement (placement);
1411 if (!(*oiter)->visible()) {
1413 as_it_will_be.push_back (*oiter);
1414 (*oiter)->set_placement (placement);
1418 /* visible processor: check that its in the new order */
1420 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1421 /* deleted: do nothing, shared_ptr<> will clean up */
1423 /* ignore this one, and add the next item from the new order instead */
1424 as_it_will_be.push_back (*niter);
1425 (*niter)->set_placement (placement);
1430 /* now remove from old order - its taken care of no matter what */
1431 oiter = _processors.erase (oiter);
1436 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1438 if (configure_processors_unlocked (err)) {
1439 _processors = as_it_was_before;
1440 processor_max_streams = old_pms;
1445 processors_changed (); /* EMIT SIGNAL */
1457 Route::get_template()
1459 return state(false);
1463 Route::state(bool full_state)
1465 XMLNode *node = new XMLNode("Route");
1466 ProcessorList::iterator i;
1469 id().print (buf, sizeof (buf));
1470 node->add_property("id", buf);
1471 node->add_property ("name", _name);
1472 node->add_property("default-type", _default_type.to_string());
1475 node->add_property("flags", enum_2_string (_flags));
1478 node->add_property("active", _active?"yes":"no");
1479 node->add_property("phase-invert", _phase_invert?"yes":"no");
1480 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1481 node->add_property("meter-point", enum_2_string (_meter_point));
1484 node->add_property("edit-group", _edit_group->name());
1487 node->add_property("mix-group", _mix_group->name());
1490 string order_string;
1491 OrderKeys::iterator x = order_keys.begin();
1493 while (x != order_keys.end()) {
1494 order_string += string ((*x).first);
1495 order_string += '=';
1496 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1497 order_string += buf;
1501 if (x == order_keys.end()) {
1505 order_string += ':';
1507 node->add_property ("order-keys", order_string);
1509 node->add_child_nocopy (_input->state (full_state));
1510 node->add_child_nocopy (_output->state (full_state));
1511 node->add_child_nocopy (_solo_control->get_state ());
1512 node->add_child_nocopy (_mute_master->get_state ());
1514 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1515 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1516 remote_control_node->add_property (X_("id"), buf);
1517 node->add_child_nocopy (*remote_control_node);
1519 if (_comment.length()) {
1520 XMLNode *cmt = node->add_child ("Comment");
1521 cmt->add_content (_comment);
1524 for (i = _processors.begin(); i != _processors.end(); ++i) {
1525 node->add_child_nocopy((*i)->state (full_state));
1529 node->add_child_copy (*_extra_xml);
1536 Route::set_state (const XMLNode& node)
1538 return _set_state (node, true);
1542 Route::_set_state (const XMLNode& node, bool call_base)
1546 XMLNodeConstIterator niter;
1548 XMLPropertyList plist;
1549 const XMLProperty *prop;
1551 if (node.name() != "Route"){
1552 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1556 if ((prop = node.property (X_("name"))) != 0) {
1557 Route::set_name (prop->value());
1560 if ((prop = node.property ("id")) != 0) {
1561 _id = prop->value ();
1564 if ((prop = node.property (X_("flags"))) != 0) {
1565 _flags = Flag (string_2_enum (prop->value(), _flags));
1570 /* add all processors (except amp, which is always present) */
1572 nlist = node.children();
1573 XMLNode processor_state (X_("processor_state"));
1575 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1579 if (child->name() == IO::state_node_name) {
1580 if ((prop = child->property (X_("direction"))) == 0) {
1584 if (prop->value() == "Input") {
1585 _input->set_state (*child);
1586 } else if (prop->value() == "Output") {
1587 _output->set_state (*child);
1591 if (child->name() == X_("Processor")) {
1592 processor_state.add_child_copy (*child);
1596 set_processor_state (processor_state);
1598 if ((prop = node.property ("solo_level")) != 0) {
1599 _solo_level = 0; // needed for mod_solo_level() to work
1600 mod_solo_level (atoi (prop->value()));
1603 if ((prop = node.property ("solo-isolated")) != 0) {
1604 set_solo_isolated (prop->value() == "yes", this);
1607 if ((prop = node.property (X_("phase-invert"))) != 0) {
1608 set_phase_invert (prop->value()=="yes"?true:false);
1611 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1612 set_denormal_protection (prop->value()=="yes"?true:false);
1615 if ((prop = node.property (X_("active"))) != 0) {
1616 bool yn = (prop->value() == "yes");
1617 _active = !yn; // force switch
1621 if ((prop = node.property (X_("soloed"))) != 0) {
1622 bool yn = (prop->value()=="yes");
1624 /* XXX force reset of solo status */
1626 set_solo (yn, this);
1629 if ((prop = node.property (X_("meter-point"))) != 0) {
1630 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1633 if ((prop = node.property (X_("edit-group"))) != 0) {
1634 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1635 if(edit_group == 0) {
1636 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1638 set_edit_group(edit_group, this);
1642 if ((prop = node.property (X_("order-keys"))) != 0) {
1646 string::size_type colon, equal;
1647 string remaining = prop->value();
1649 while (remaining.length()) {
1651 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1652 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1655 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1656 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1659 set_order_key (remaining.substr (0, equal).c_str(), n);
1663 colon = remaining.find_first_of (':');
1665 if (colon != string::npos) {
1666 remaining = remaining.substr (colon+1);
1673 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1676 if (child->name() == X_("Comment")) {
1678 /* XXX this is a terrible API design in libxml++ */
1680 XMLNode *cmt = *(child->children().begin());
1681 _comment = cmt->content();
1683 } else if (child->name() == X_("Extra")) {
1685 _extra_xml = new XMLNode (*child);
1687 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1689 if (prop->value() == "solo") {
1690 _solo_control->set_state (*child);
1691 _session.add_controllable (_solo_control);
1694 } else if (child->name() == X_("RemoteControl")) {
1695 if ((prop = child->property (X_("id"))) != 0) {
1697 sscanf (prop->value().c_str(), "%d", &x);
1698 set_remote_control_id (x);
1701 } else if (child->name() == X_("MuteMaster")) {
1702 _mute_master->set_state (*child);
1706 if ((prop = node.property (X_("mix-group"))) != 0) {
1707 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1708 if (mix_group == 0) {
1709 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1711 set_mix_group(mix_group, this);
1719 Route::get_processor_state ()
1721 XMLNode* root = new XMLNode (X_("redirects"));
1722 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1723 root->add_child_nocopy ((*i)->state (true));
1730 Route::set_processor_state (const XMLNode& node)
1732 const XMLNodeList &nlist = node.children();
1733 XMLNodeConstIterator niter;
1734 ProcessorList::iterator i, o;
1736 // Iterate through existing processors, remove those which are not in the state list
1738 for (i = _processors.begin(); i != _processors.end(); ) {
1740 /* leave amp alone, always */
1747 ProcessorList::iterator tmp = i;
1750 bool processorInStateList = false;
1752 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1754 XMLProperty* id_prop = (*niter)->property(X_("id"));
1755 cerr << "\tchecking " << id_prop->value() << endl;
1756 if (id_prop && (*i)->id() == id_prop->value()) {
1757 processorInStateList = true;
1762 if (!processorInStateList) {
1763 remove_processor (*i);
1769 // Iterate through state list and make sure all processors are on the track and in the correct order,
1770 // set the state of existing processors according to the new state on the same go
1772 i = _processors.begin();
1774 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1776 XMLProperty* prop = (*niter)->property ("type");
1780 // Check whether the next processor in the list is the right one,
1781 // except for "amp" which is always there and may not have the
1782 // old ID since it is always created anew in every Route
1784 if (prop->value() != "amp") {
1785 while (o != _processors.end()) {
1786 XMLProperty* id_prop = (*niter)->property(X_("id"));
1787 if (id_prop && (*o)->id() == id_prop->value()) {
1795 // If the processor (*niter) is not on the route,
1796 // create it and move it to the correct location
1798 if (o == _processors.end()) {
1800 if (add_processor_from_xml (**niter, i)) {
1801 --i; // move iterator to the newly inserted processor
1803 cerr << "Error restoring route: unable to restore processor" << endl;
1808 // Otherwise, the processor already exists; just
1809 // ensure it is at the location provided in the XML state
1812 boost::shared_ptr<Processor> tmp = (*o);
1813 _processors.erase (o); // remove the old copy
1814 _processors.insert (i, tmp); // insert the processor at the correct location
1815 --i; // move iterator to the correct processor
1818 // and make it (just) so
1820 (*i)->set_state (**niter);
1824 /* note: there is no configure_processors() call because we figure that
1825 the XML state represents a working signal route.
1828 processors_changed ();
1832 Route::curve_reallocate ()
1834 // _gain_automation_curve.finish_resize ();
1835 // _pan_automation_curve.finish_resize ();
1839 Route::silence (nframes_t nframes)
1843 _output->silence (nframes);
1846 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
1849 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1850 boost::shared_ptr<PluginInsert> pi;
1852 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1853 // skip plugins, they don't need anything when we're not active
1857 (*i)->silence (nframes);
1860 if (nframes == _session.get_block_size()) {
1870 Route::get_return_buffer () const
1872 Glib::RWLock::ReaderLock rm (_processor_lock);
1874 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1875 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
1878 return d->get_buffers ();
1886 Route::release_return_buffer () const
1888 Glib::RWLock::ReaderLock rm (_processor_lock);
1890 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1891 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
1894 return d->release_buffers ();
1900 Route::listen_via (boost::shared_ptr<Route> route, const string& listen_name)
1902 vector<string> ports;
1903 vector<string>::const_iterator i;
1906 Glib::RWLock::ReaderLock rm (_processor_lock);
1908 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
1909 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
1911 if (d && d->target_route() == route) {
1913 /* if the target is the control outs, then make sure
1914 we take note of which i-send is doing that.
1917 if (route == _session.control_out()) {
1918 _control_outs = boost::dynamic_pointer_cast<Delivery>(d);
1921 /* already listening via the specified IO: do nothing */
1928 boost::shared_ptr<InternalSend> listener;
1931 listener.reset (new InternalSend (_session, _mute_master, route));
1933 } catch (failed_constructor& err) {
1938 add_processor (listener, PreFader);
1944 Route::drop_listen (boost::shared_ptr<Route> route)
1946 ProcessorStreams err;
1947 ProcessorList::iterator tmp;
1949 Glib::RWLock::ReaderLock rl(_processor_lock);
1953 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
1955 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
1957 if (d && d->target_route() == route) {
1959 remove_processor (*x, &err);
1962 /* list could have been demolished while we dropped the lock
1972 if (route == _session.control_out()) {
1973 _control_outs.reset ();
1978 Route::set_edit_group (RouteGroup *eg, void *src)
1981 if (eg == _edit_group) {
1986 _edit_group->remove (this);
1989 if ((_edit_group = eg) != 0) {
1990 _edit_group->add (this);
1993 _session.set_dirty ();
1994 edit_group_changed (src); /* EMIT SIGNAL */
1998 Route::drop_edit_group (void *src)
2001 _session.set_dirty ();
2002 edit_group_changed (src); /* EMIT SIGNAL */
2006 Route::set_mix_group (RouteGroup *mg, void *src)
2009 if (mg == _mix_group) {
2014 _mix_group->remove (this);
2017 if ((_mix_group = mg) != 0) {
2018 _mix_group->add (this);
2021 _session.set_dirty ();
2022 mix_group_changed (src); /* EMIT SIGNAL */
2026 Route::drop_mix_group (void *src)
2029 _session.set_dirty ();
2030 mix_group_changed (src); /* EMIT SIGNAL */
2034 Route::set_comment (string cmt, void *src)
2037 comment_changed (src);
2038 _session.set_dirty ();
2042 Route::feeds (boost::shared_ptr<Route> other)
2044 // cerr << _name << endl;
2046 if (_output->connected_to (other->input())) {
2047 // cerr << "\tdirect FEEDS " << other->name() << endl;
2051 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2053 boost::shared_ptr<IOProcessor> iop;
2055 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2056 if (iop->feeds (other)) {
2057 // cerr << "\tIOP " << iop->name() << " feeds " << other->name() << endl;
2060 // cerr << "\tIOP " << iop->name() << " does NOT feeds " << other->name() << endl;
2065 // cerr << "\tdoes NOT FEED " << other->name() << endl;
2070 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2072 nframes_t now = _session.transport_frame();
2075 Glib::RWLock::ReaderLock lm (_processor_lock);
2078 automation_snapshot (now, true);
2081 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2083 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2084 (*i)->deactivate ();
2088 (*i)->transport_stopped (now);
2092 _roll_delay = _initial_delay;
2096 Route::input_change_handler (IOChange change, void *src)
2098 if ((change & ConfigurationChanged)) {
2099 configure_processors (0);
2104 Route::output_change_handler (IOChange change, void *src)
2106 if ((change & ConfigurationChanged)) {
2108 /* XXX resize all listeners to match _main_outs? */
2110 // configure_processors (0);
2115 Route::pans_required () const
2117 if (n_outputs().n_audio() < 2) {
2121 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2125 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2126 bool session_state_changing, bool can_record, bool rec_monitors_input)
2128 if (n_outputs().n_total() == 0) {
2132 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2137 _amp->apply_gain_automation (false);
2138 passthru (start_frame, end_frame, nframes, 0);
2144 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2146 if (_roll_delay > nframes) {
2148 _roll_delay -= nframes;
2150 /* transport frame is not legal for caller to use */
2153 } else if (_roll_delay > 0) {
2155 nframes -= _roll_delay;
2156 silence (_roll_delay);
2157 /* we've written _roll_delay of samples into the
2158 output ports, so make a note of that for
2161 _main_outs->increment_output_offset (_roll_delay);
2162 transport_frame += _roll_delay;
2171 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2172 bool can_record, bool rec_monitors_input)
2175 // automation snapshot can also be called from the non-rt context
2176 // and it uses the processor list, so we try to acquire the lock here
2177 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2180 automation_snapshot (_session.transport_frame(), false);
2184 if (n_outputs().n_total() == 0) {
2188 if (!_active || n_inputs().n_total() == 0) {
2193 nframes_t unused = 0;
2195 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2201 passthru (start_frame, end_frame, nframes, declick);
2207 Route::silent_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2208 bool can_record, bool rec_monitors_input)
2215 Route::toggle_monitor_input ()
2217 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2218 i->ensure_monitor_input( ! i->monitoring_input());
2223 Route::has_external_redirects () const
2225 // FIXME: what about sends? - they don't return a signal back to ardour?
2227 boost::shared_ptr<const PortInsert> pi;
2229 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2231 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2233 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2235 string port_name = port->name();
2236 string client_name = port_name.substr (0, port_name.find(':'));
2238 /* only say "yes" if the redirect is actually in use */
2240 if (client_name != "ardour" && pi->active()) {
2251 Route::flush_processors ()
2253 /* XXX shouldn't really try to take this lock, since
2254 this is called from the RT audio thread.
2257 Glib::RWLock::ReaderLock lm (_processor_lock);
2259 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2260 (*i)->deactivate ();
2266 Route::set_meter_point (MeterPoint p, void *src)
2268 if (_meter_point != p) {
2271 // Move meter in the processors list
2272 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2273 _processors.erase(loc);
2276 loc = _processors.begin();
2279 loc = find(_processors.begin(), _processors.end(), _amp);
2281 case MeterPostFader:
2282 loc = _processors.end();
2285 _processors.insert(loc, _meter);
2287 meter_change (src); /* EMIT SIGNAL */
2288 processors_changed (); /* EMIT SIGNAL */
2289 _session.set_dirty ();
2293 Route::put_control_outs_at (Placement p)
2295 if (!_control_outs) {
2299 // Move meter in the processors list
2300 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _control_outs);
2301 _processors.erase(loc);
2305 loc = find(_processors.begin(), _processors.end(), _amp);
2306 if (loc != _processors.begin()) {
2311 loc = find(_processors.begin(), _processors.end(), _amp);
2312 assert (loc != _processors.end());
2317 _processors.insert(loc, _control_outs);
2319 cerr << _name << " moved control outs to " << enum_2_string (p) << endl;
2321 processors_changed (); /* EMIT SIGNAL */
2322 _session.set_dirty ();
2326 Route::update_total_latency ()
2328 nframes_t old = _output->effective_latency();
2329 nframes_t own_latency = _output->user_latency();
2331 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2332 if ((*i)->active ()) {
2333 own_latency += (*i)->signal_latency ();
2337 #undef DEBUG_LATENCY
2338 #ifdef DEBUG_LATENCY
2339 cerr << _name << ": internal redirect latency = " << own_latency << endl;
2342 _output->set_port_latency (own_latency);
2344 if (_output->user_latency() == 0) {
2346 /* this (virtual) function is used for pure Routes,
2347 not derived classes like AudioTrack. this means
2348 that the data processed here comes from an input
2349 port, not prerecorded material, and therefore we
2350 have to take into account any input latency.
2353 own_latency += _input->signal_latency ();
2356 if (old != own_latency) {
2357 _output->set_latency_delay (own_latency);
2358 signal_latency_changed (); /* EMIT SIGNAL */
2361 #ifdef DEBUG_LATENCY
2362 cerr << _name << ": input latency = " << _input->signal_latency() << " total = "
2363 << own_latency << endl;
2366 return _output->effective_latency ();
2370 Route::set_user_latency (nframes_t nframes)
2372 _output->set_user_latency (nframes);
2373 _session.update_latency_compensation (false, false);
2377 Route::set_latency_delay (nframes_t longest_session_latency)
2379 nframes_t old = _initial_delay;
2381 if (_output->effective_latency() < longest_session_latency) {
2382 _initial_delay = longest_session_latency - _output->effective_latency();
2387 if (_initial_delay != old) {
2388 initial_delay_changed (); /* EMIT SIGNAL */
2391 if (_session.transport_stopped()) {
2392 _roll_delay = _initial_delay;
2397 Route::automation_snapshot (nframes_t now, bool force)
2399 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2400 (*i)->automation_snapshot (now, force);
2404 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2405 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2406 boost::shared_ptr<AutomationList>(), name)
2409 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2414 Route::SoloControllable::set_value (float val)
2416 bool bval = ((val >= 0.5f) ? true: false);
2418 route.set_solo (bval, this);
2422 Route::SoloControllable::get_value (void) const
2424 return route.soloed() ? 1.0f : 0.0f;
2428 Route::set_block_size (nframes_t nframes)
2430 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2431 (*i)->set_block_size (nframes);
2433 _session.ensure_buffers(processor_max_streams);
2437 Route::protect_automation ()
2439 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2440 (*i)->protect_automation();
2444 Route::set_pending_declick (int declick)
2447 /* this call is not allowed to turn off a pending declick unless "force" is true */
2449 _pending_declick = declick;
2451 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2453 _pending_declick = 0;
2458 /** Shift automation forwards from a particular place, thereby inserting time.
2459 * Adds undo commands for any shifts that are performed.
2461 * @param pos Position to start shifting from.
2462 * @param frames Amount to shift forwards by.
2466 Route::shift (nframes64_t pos, nframes64_t frames)
2468 #ifdef THIS_NEEDS_FIXING_FOR_V3
2470 /* gain automation */
2471 XMLNode &before = _gain_control->get_state ();
2472 _gain_control->shift (pos, frames);
2473 XMLNode &after = _gain_control->get_state ();
2474 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2476 /* pan automation */
2477 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2478 Curve & c = (*i)->automation ();
2479 XMLNode &before = c.get_state ();
2480 c.shift (pos, frames);
2481 XMLNode &after = c.get_state ();
2482 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2485 /* redirect automation */
2487 Glib::RWLock::ReaderLock lm (redirect_lock);
2488 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2491 (*i)->what_has_automation (a);
2493 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2494 AutomationList & al = (*i)->automation_list (*j);
2495 XMLNode &before = al.get_state ();
2496 al.shift (pos, frames);
2497 XMLNode &after = al.get_state ();
2498 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2508 Route::save_as_template (const string& path, const string& name)
2510 XMLNode& node (state (false));
2513 IO::set_name_in_state (*node.children().front(), name);
2515 tree.set_root (&node);
2516 return tree.write (path.c_str());
2521 Route::set_name (const string& str)
2526 SessionObject::set_name (str);
2528 ret = (_input->set_name(str) && _output->set_name(str));
2532 Glib::RWLock::ReaderLock lm (_processor_lock);
2534 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2536 /* rename all processors with outputs to reflect our new name */
2538 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2541 string iop_name = str;
2543 iop_name += "XXX FIX ME XXX";
2546 if (!iop->set_name (iop_name)) {
2557 boost::shared_ptr<Send>
2558 Route::internal_send_for (boost::shared_ptr<const Route> target) const
2560 Glib::RWLock::ReaderLock lm (_processor_lock);
2562 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2563 boost::shared_ptr<InternalSend> send;
2565 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
2566 if (send->target_route() == target) {
2572 return boost::shared_ptr<Send>();
2576 Route::set_phase_invert (bool yn)
2578 if (_phase_invert != yn) {
2579 _phase_invert = 0xffff; // XXX all channels
2580 phase_invert_changed (); /* EMIT SIGNAL */
2585 Route::phase_invert () const
2587 return _phase_invert != 0;
2591 Route::set_denormal_protection (bool yn)
2593 if (_denormal_protection != yn) {
2594 _denormal_protection = yn;
2595 denormal_protection_changed (); /* EMIT SIGNAL */
2600 Route::denormal_protection () const
2602 return _denormal_protection;
2606 Route::set_active (bool yn)
2608 if (_active != yn) {
2610 _input->set_active (yn);
2611 _output->set_active (yn);
2612 active_changed (); // EMIT SIGNAL
2619 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2623 boost::shared_ptr<Panner>
2624 Route::panner() const
2627 return _main_outs->panner();
2630 boost::shared_ptr<AutomationControl>
2631 Route::gain_control() const
2634 return _amp->gain_control();
2637 boost::shared_ptr<AutomationControl>
2638 Route::get_control (const Evoral::Parameter& param)
2640 /* either we own the control or .... */
2642 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
2646 /* maybe one of our processors does or ... */
2648 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2649 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2650 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
2658 /* nobody does so we'll make a new one */
2660 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));