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,
67 DataType default_type, ChanCount in, ChanCount out)
68 : IO (sess, name, default_type, in, ChanCount::INFINITE, out, ChanCount::INFINITE)
70 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
71 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
73 _configured_inputs = in;
74 _configured_outputs = out;
79 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
80 : IO (sess, *node.child ("IO"), default_type)
81 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
82 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
85 _set_state (node, false);
91 processor_max_streams.reset();
97 _phase_invert = false;
98 _denormal_protection = false;
99 order_keys[strdup (N_("signal"))] = order_key_cnt++;
101 _meter_point = MeterPostFader;
106 _have_internal_generator = false;
107 _declickable = false;
108 _pending_declick = true;
109 _remote_control_id = 0;
110 _in_configure_processors = false;
115 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
116 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
117 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
118 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
121 desired_solo_gain = 1.0;
123 desired_mute_gain = 1.0;
125 input_changed.connect (mem_fun (this, &Route::input_change_handler));
126 output_changed.connect (mem_fun (this, &Route::output_change_handler));
128 /* add standard processors: amp, meter, main outs */
130 /* amp & meter belong to IO but need to be added to our processor list */
132 _amp->set_sort_key (0);
133 _meter->set_sort_key (1);
134 add_processor (_amp);
135 add_processor (_meter);
137 _main_outs.reset (new Delivery (_session, this, _name, Delivery::Main));
138 ProcessorList::iterator i = _processors.end();
139 add_processor (_main_outs, 0, &i);
144 clear_processors (PreFader);
145 clear_processors (PostFader);
147 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
148 free ((void*)(i->first));
153 Route::set_remote_control_id (uint32_t id)
155 if (id != _remote_control_id) {
156 _remote_control_id = id;
157 RemoteControlIDChanged ();
162 Route::remote_control_id() const
164 return _remote_control_id;
168 Route::order_key (const char* name) const
170 OrderKeys::const_iterator i;
172 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
173 if (!strcmp (name, i->first)) {
182 Route::set_order_key (const char* name, long n)
184 order_keys[strdup(name)] = n;
186 if (Config->get_sync_all_route_ordering()) {
187 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
192 _session.set_dirty ();
196 Route::sync_order_keys (const char* base)
198 if (order_keys.empty()) {
202 OrderKeys::iterator i;
205 if ((i = order_keys.find (base)) == order_keys.end()) {
206 /* key doesn't exist, use the first existing key (during session initialization) */
207 i = order_keys.begin();
211 /* key exists - use it and reset all others (actually, itself included) */
213 i = order_keys.begin();
216 for (; i != order_keys.end(); ++i) {
222 Route::ensure_track_or_route_name(string name, Session &session)
224 string newname = name;
226 while (session.route_by_name (newname) != NULL) {
227 newname = bump_name_once (newname);
234 Route::inc_gain (gain_t fraction, void *src)
236 IO::inc_gain (fraction, src);
240 Route::set_gain (gain_t val, void *src)
242 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
244 if (_mix_group->is_relative()) {
246 gain_t usable_gain = gain();
247 if (usable_gain < 0.000001f) {
248 usable_gain = 0.000001f;
252 if (delta < 0.000001f) {
256 delta -= usable_gain;
261 gain_t factor = delta / usable_gain;
264 factor = _mix_group->get_max_factor(factor);
265 if (factor == 0.0f) {
266 _gain_control->Changed(); /* EMIT SIGNAL */
270 factor = _mix_group->get_min_factor(factor);
271 if (factor == 0.0f) {
272 _gain_control->Changed(); /* EMIT SIGNAL */
277 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
281 _mix_group->apply (&Route::set_gain, val, _mix_group);
291 IO::set_gain (val, src);
294 /** Process this route for one (sub) cycle (process thread)
296 * @param bufs Scratch buffers to use for the signal path
297 * @param start_frame Initial transport frame
298 * @param end_frame Final transport frame
299 * @param nframes Number of frames to output (to ports)
301 * Note that (end_frame - start_frame) may not be equal to nframes when the
302 * transport speed isn't 1.0 (eg varispeed).
305 Route::process_output_buffers (BufferSet& bufs,
306 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
307 bool with_processors, int declick)
309 ProcessorList::iterator i;
310 bool mute_declick_applied = false;
314 bufs.is_silent(false);
316 switch (Config->get_monitoring_model()) {
317 case HardwareMonitoring:
318 case ExternalMonitoring:
325 declick = _pending_declick;
327 const bool recording_without_monitoring = no_monitor && record_enabled()
328 && (!Config->get_auto_input() || _session.actively_recording());
331 /* -------------------------------------------------------------------------------------------
333 ----------------------------------------------------------------------------------------- */
336 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
339 dmg = desired_mute_gain;
340 dsg = desired_solo_gain;
341 dg = _gain_control->user_float();
349 // apply gain at the amp if...
351 // we're not recording
352 !(record_enabled() && _session.actively_recording())
353 // or (we are recording, and) software monitoring is required
354 || Config->get_monitoring_model() == SoftwareMonitoring);
356 // mute at the amp if...
357 _amp->apply_mute (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader,
360 _amp->set_gain (_gain, dg);
363 /* -------------------------------------------------------------------------------------------
364 SET UP CONTROL OUTPUTS
365 ----------------------------------------------------------------------------------------- */
367 boost::shared_ptr<Delivery> co = _control_outs;
369 // deliver control outputs unless we're ...
370 bool self_mute = ((dmg == 0 && _mute_affects_control_outs) || // or muted by mute of this track
371 !recording_without_monitoring); // or rec-enabled w/o s/w monitoring
372 bool other_mute = (dsg == 0); // muted by solo of another track
374 co->set_self_mute (self_mute);
375 co->set_nonself_mute (other_mute);
378 /* -------------------------------------------------------------------------------------------
379 SET UP MAIN OUTPUT STAGE
380 ----------------------------------------------------------------------------------------- */
382 bool solo_audible = dsg > 0;
383 bool mute_audible = dmg > 0 || !_mute_affects_main_outs;
385 bool silent_anyway = (_gain == 0 && !_amp->apply_gain_automation());
386 bool muted_by_other_solo = (!solo_audible && (Config->get_solo_model() != SoloBus));
387 bool muted_by_self = !mute_audible;
389 _main_outs->set_nonself_mute (recording_without_monitoring || muted_by_other_solo || silent_anyway);
390 _main_outs->set_self_mute (muted_by_self);
392 /* -------------------------------------------------------------------------------------------
393 GLOBAL DECLICK (for transport changes etc.)
394 ----------------------------------------------------------------------------------------- */
397 Amp::apply_gain (bufs, nframes, 0.0, 1.0, false);
398 _pending_declick = 0;
399 } else if (declick < 0) {
400 Amp::apply_gain (bufs, nframes, 1.0, 0.0, false);
401 _pending_declick = 0;
402 } else { // no global declick
403 if (solo_gain != dsg) {
404 Amp::apply_gain (bufs, nframes, solo_gain, dsg, false);
410 /* -------------------------------------------------------------------------------------------
412 ----------------------------------------------------------------------------------------- */
414 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
415 Amp::apply_gain (bufs, nframes, mute_gain, dmg, false);
417 mute_declick_applied = true;
419 if (mute_gain == 0.0f && dmg == 0.0f) {
420 bufs.is_silent(true);
424 /* -------------------------------------------------------------------------------------------
426 ----------------------------------------------------------------------------------------- */
428 if (_denormal_protection || Config->get_denormal_protection()) {
430 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
431 Sample* const sp = i->data();
433 for (nframes_t nx = 0; nx < nframes; ++nx) {
439 /* -------------------------------------------------------------------------------------------
441 ----------------------------------------------------------------------------------------- */
443 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
446 for (i = _processors.begin(); i != _processors.end(); ++i) {
447 bufs.set_count(ChanCount::max(bufs.count(), (*i)->input_streams()));
448 (*i)->run_in_place (bufs, start_frame, end_frame, nframes);
449 bufs.set_count(ChanCount::max(bufs.count(), (*i)->output_streams()));
452 if (!_processors.empty()) {
453 bufs.set_count(ChanCount::max(bufs.count(), _processors.back()->output_streams()));
457 /* -------------------------------------------------------------------------------------------
459 ----------------------------------------------------------------------------------------- */
461 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
462 Amp::apply_gain (bufs, nframes, mute_gain, dmg, false);
464 mute_declick_applied = true;
467 if (mute_gain == 0.0f && dmg == 0.0f) {
468 bufs.is_silent(true);
471 // at this point we've reached the desired mute gain regardless
476 Route::n_process_buffers ()
478 return max (n_inputs(), processor_max_streams);
482 Route::setup_peak_meters()
484 ChanCount max_streams = std::max (_inputs.count(), _outputs.count());
485 max_streams = std::max (max_streams, processor_max_streams);
486 _meter->configure_io (max_streams, max_streams);
490 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
492 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
496 collect_input (bufs, nframes);
498 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
502 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
504 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, true, declick);
508 Route::set_solo (bool yn, void *src)
514 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
515 _mix_group->apply (&Route::set_solo, yn, _mix_group);
521 solo_changed (src); /* EMIT SIGNAL */
522 _solo_control->Changed (); /* EMIT SIGNAL */
525 catch_up_on_solo_mute_override ();
529 Route::catch_up_on_solo_mute_override ()
531 if (Config->get_solo_model() != InverseMute) {
536 Glib::Mutex::Lock lm (declick_lock);
539 if (Config->get_solo_mute_override()) {
540 desired_mute_gain = (_soloed?1.0:0.0);
542 desired_mute_gain = 0.0;
545 desired_mute_gain = 1.0;
551 Route::set_solo_mute (bool yn)
553 Glib::Mutex::Lock lm (declick_lock);
555 /* Called by Session in response to another Route being soloed.
558 desired_solo_gain = (yn?0.0:1.0);
562 Route::set_solo_safe (bool yn, void *src)
564 if (_solo_safe != yn) {
566 solo_safe_changed (src); /* EMIT SIGNAL */
571 Route::set_mute (bool yn, void *src)
574 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
575 _mix_group->apply (&Route::set_mute, yn, _mix_group);
581 mute_changed (src); /* EMIT SIGNAL */
583 _mute_control->Changed (); /* EMIT SIGNAL */
585 Glib::Mutex::Lock lm (declick_lock);
587 if (_soloed && Config->get_solo_mute_override()) {
588 desired_mute_gain = 1.0f;
590 desired_mute_gain = (yn?0.0f:1.0f);
596 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
598 cerr << name << " {" << endl;
599 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
600 p != procs.end(); ++p) {
601 cerr << "\t" << (*p)->sort_key() << ": " << (*p)->name() << endl;
607 struct ProcessorSortByKey {
608 bool operator() (boost::shared_ptr<Processor> a, boost::shared_ptr<Processor> b) {
609 return a->sort_key() < b->sort_key();
614 Route::fader_sort_key() const
616 return _amp->sort_key();
619 /** Add a processor to the route.
620 * If @a iter is not NULL, it must point to an iterator in _processors and the new
621 * processor will be inserted immediately before this location. Otherwise,
622 * @a position is used.
625 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, ProcessorList::iterator* iter)
627 ChanCount old_pms = processor_max_streams;
629 if (!_session.engine().connected() || !processor) {
633 cerr << "Adding a processor called " << processor->name() << " sk = " << processor->sort_key()
634 << ((iter == 0) ? " NO given position " : " with given position")
638 Glib::RWLock::WriterLock lm (_processor_lock);
640 boost::shared_ptr<PluginInsert> pi;
641 boost::shared_ptr<PortInsert> porti;
643 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
645 if (processor == _amp || processor == _meter || processor == _main_outs) {
646 // Ensure only one of these are in the list at any time
647 if (loc != _processors.end()) {
649 if (*iter == loc) { // Already in place, do nothing
651 } else { // New position given, relocate
652 _processors.erase(loc);
654 } else { // Insert at end
655 _processors.erase(loc);
656 loc = _processors.end();
661 if (loc != _processors.end()) {
662 cerr << "ERROR: Processor added to route twice!" << endl;
668 // Use position given by user
671 if (processor->sort_key() == 0) {
672 /* generic pre-fader: insert immediately before the amp */
673 loc = find(_processors.begin(), _processors.end(), _amp);
674 } else if (processor->sort_key() > _processors.size()) {
675 /* generic post-fader: insert at end */
676 loc = _processors.end();
678 /* find insert point */
679 ProcessorSortByKey cmp;
680 loc = upper_bound (_processors.begin(), _processors.end(), processor, cmp);
685 if (loc == _processors.end()) {
686 processor->set_sort_key(_processors.size());
688 processor->set_sort_key((*loc)->sort_key());
689 for (ProcessorList::iterator p = loc; p != _processors.end(); ++p) {
690 (*p)->set_sort_key((*p)->sort_key() + 1);
694 _processors.insert(loc, processor);
696 // Set up processor list channels. This will set processor->[input|output]_streams(),
697 // configure redirect ports properly, etc.
698 if (configure_processors_unlocked (err)) {
699 dump_processors(_name + "bad config", _processors);
700 ProcessorList::iterator ploc = loc;
702 _processors.erase(ploc);
703 configure_processors_unlocked (0); // it worked before we tried to add it ...
704 cerr << "Bad IO config\n";
708 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
710 if (pi->natural_input_streams() == ChanCount::ZERO) {
711 /* generator plugin */
712 _have_internal_generator = true;
717 // Ensure peak vector sizes before the plugin is activated
718 ChanCount potential_max_streams = ChanCount::max (processor->input_streams(), processor->output_streams());
720 _meter->configure_io (potential_max_streams, potential_max_streams);
722 // XXX: do we want to emit the signal here ? change call order.
723 processor->activate ();
724 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
729 if (processor_max_streams != old_pms || old_pms == ChanCount::ZERO) {
733 dump_processors (_name + " added one", _processors);
734 processors_changed (); /* EMIT SIGNAL */
740 Route::add_processors (const ProcessorList& others, ProcessorStreams* err, uint32_t first_sort_key)
742 /* NOTE: this is intended to be used ONLY when copying
743 processors from another Route. Hence the subtle
744 differences between this and ::add_processor()
747 ChanCount old_pms = processor_max_streams;
749 if (!_session.engine().connected()) {
754 Glib::RWLock::WriterLock lm (_processor_lock);
756 ProcessorList::iterator loc;
757 ProcessorList::iterator existing_end = _processors.end();
760 ChanCount potential_max_streams = ChanCount::max(input_minimum(), output_minimum());
762 if (first_sort_key == 0) {
763 /* generic pre-fader: insert immediately before the amp */
764 cerr << "Add new procs at amp, sk = " << first_sort_key << endl;
765 loc = find(_processors.begin(), _processors.end(), _amp);
766 } else if (first_sort_key > _processors.size()) {
767 /* generic post-fader: insert at end */
768 cerr << "Add new procs at end, sk = " << first_sort_key << endl;
769 loc = _processors.end();
771 /* find insert point */
772 ProcessorSortByKey cmp;
773 cerr << "Add new procs at sk = " << first_sort_key << endl;
774 loc = upper_bound (_processors.begin(), _processors.end(), others.front(), cmp);
777 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
779 // Ensure meter only appears in the list once
781 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
782 if (m != _processors.end()) {
783 _processors.erase(m);
787 boost::shared_ptr<PluginInsert> pi;
789 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
792 ChanCount m = max(pi->input_streams(), pi->output_streams());
793 if (m > potential_max_streams)
794 potential_max_streams = m;
797 // Ensure peak vector sizes before the plugin is activated
798 _meter->configure_io (potential_max_streams, potential_max_streams);
800 _processors.insert (loc, *i);
802 if (configure_processors_unlocked (err)) {
804 _processors.erase (existing_end, _processors.end());
805 configure_processors_unlocked (0); // it worked before we tried to add it ...
809 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
815 if (processor_max_streams != old_pms || old_pms == ChanCount::ZERO) {
819 dump_processors (_name + " added several", _processors);
820 processors_changed (); /* EMIT SIGNAL */
826 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
829 start = _processors.begin();
830 end = find(_processors.begin(), _processors.end(), _amp);
832 start = find(_processors.begin(), _processors.end(), _amp);
834 end = _processors.end();
838 /** Turn off all processors with a given placement
839 * @param p Placement of processors to disable
842 Route::disable_processors (Placement p)
844 Glib::RWLock::ReaderLock lm (_processor_lock);
846 ProcessorList::iterator start, end;
847 placement_range(p, start, end);
849 for (ProcessorList::iterator i = start; i != end; ++i) {
853 _session.set_dirty ();
856 /** Turn off all redirects
859 Route::disable_processors ()
861 Glib::RWLock::ReaderLock lm (_processor_lock);
863 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
867 _session.set_dirty ();
870 /** Turn off all redirects with a given placement
871 * @param p Placement of redirects to disable
874 Route::disable_plugins (Placement p)
876 Glib::RWLock::ReaderLock lm (_processor_lock);
878 ProcessorList::iterator start, end;
879 placement_range(p, start, end);
881 for (ProcessorList::iterator i = start; i != end; ++i) {
882 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
887 _session.set_dirty ();
890 /** Turn off all plugins
893 Route::disable_plugins ()
895 Glib::RWLock::ReaderLock lm (_processor_lock);
897 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
898 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
903 _session.set_dirty ();
908 Route::ab_plugins (bool forward)
910 Glib::RWLock::ReaderLock lm (_processor_lock);
914 /* forward = turn off all active redirects, and mark them so that the next time
915 we go the other way, we will revert them
918 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
919 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
923 if ((*i)->active()) {
925 (*i)->set_next_ab_is_active (true);
927 (*i)->set_next_ab_is_active (false);
933 /* backward = if the redirect was marked to go active on the next ab, do so */
935 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
937 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
941 if ((*i)->get_next_ab_is_active()) {
949 _session.set_dirty ();
953 /* Figure out the streams that will feed into PreFader */
955 Route::pre_fader_streams() const
957 boost::shared_ptr<Processor> processor;
959 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
961 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
965 if (boost::dynamic_pointer_cast<Send> (*i) == 0) {
971 return processor->output_streams();
978 /** Remove processors with a given placement.
979 * @param p Placement of processors to remove.
982 Route::clear_processors (Placement p)
984 const ChanCount old_pms = processor_max_streams;
986 if (!_session.engine().connected()) {
990 bool already_deleting = _session.deletion_in_progress();
991 if (!already_deleting) {
992 _session.set_deletion_in_progress();
996 Glib::RWLock::WriterLock lm (_processor_lock);
997 ProcessorList new_list;
998 ProcessorStreams err;
1000 ProcessorList::iterator amp_loc = find(_processors.begin(), _processors.end(), _amp);
1001 if (p == PreFader) {
1002 // Get rid of PreFader processors
1003 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1004 (*i)->drop_references ();
1007 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1008 new_list.push_back (*i);
1011 // Keep PreFader processors
1012 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1013 new_list.push_back (*i);
1015 new_list.push_back (_amp);
1016 // Get rid of PostFader processors
1017 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1018 (*i)->drop_references ();
1022 _processors = new_list;
1023 configure_processors_unlocked (&err); // this can't fail
1026 if (processor_max_streams != old_pms) {
1030 processor_max_streams.reset();
1031 _have_internal_generator = false;
1032 processors_changed (); /* EMIT SIGNAL */
1034 if (!already_deleting) {
1035 _session.clear_deletion_in_progress();
1040 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1042 /* these can never be removed */
1044 if (processor == _amp || processor == _meter || processor == _main_outs) {
1048 ChanCount old_pms = processor_max_streams;
1050 if (!_session.engine().connected()) {
1054 processor_max_streams.reset();
1057 Glib::RWLock::WriterLock lm (_processor_lock);
1058 ProcessorList::iterator i;
1059 bool removed = false;
1061 for (i = _processors.begin(); i != _processors.end(); ) {
1062 if (*i == processor) {
1064 /* move along, see failure case for configure_processors()
1065 where we may need to reprocessor the processor.
1068 /* stop redirects that send signals to JACK ports
1069 from causing noise as a result of no longer being
1073 boost::shared_ptr<IOProcessor> redirect;
1075 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1076 redirect->io()->disconnect_inputs (this);
1077 redirect->io()->disconnect_outputs (this);
1080 i = _processors.erase (i);
1096 if (configure_processors_unlocked (err)) {
1097 /* get back to where we where */
1098 _processors.insert (i, processor);
1099 /* we know this will work, because it worked before :) */
1100 configure_processors_unlocked (0);
1104 _have_internal_generator = false;
1106 for (i = _processors.begin(); i != _processors.end(); ++i) {
1107 boost::shared_ptr<PluginInsert> pi;
1109 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1110 if (pi->is_generator()) {
1111 _have_internal_generator = true;
1118 if (old_pms != processor_max_streams) {
1122 processor->drop_references ();
1124 dump_processors (_name + " removed one", _processors);
1125 processors_changed (); /* EMIT SIGNAL */
1131 Route::configure_processors (ProcessorStreams* err)
1133 if (!_in_configure_processors) {
1134 Glib::RWLock::WriterLock lm (_processor_lock);
1135 return configure_processors_unlocked (err);
1140 /** Configure the input/output configuration of each processor in the processors list.
1141 * Return 0 on success, otherwise configuration is impossible.
1144 Route::configure_processors_unlocked (ProcessorStreams* err)
1146 if (_in_configure_processors) {
1150 _in_configure_processors = true;
1152 // Check each processor in order to see if we can configure as requested
1153 ChanCount in = _configured_inputs;
1155 list< pair<ChanCount,ChanCount> > configuration;
1157 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1158 (*p)->set_sort_key(index);
1159 if ((*p)->can_support_io_configuration(in, out)) {
1160 configuration.push_back(make_pair(in, out));
1167 _in_configure_processors = false;
1172 // We can, so configure everything
1173 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1174 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1175 (*p)->configure_io(c->first, c->second);
1177 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1178 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1182 // Ensure route outputs match last processor's outputs
1183 if (out != n_outputs()) {
1184 ensure_io(_configured_inputs, out, false, this);
1187 _in_configure_processors = false;
1192 Route::all_processors_flip ()
1194 Glib::RWLock::ReaderLock lm (_processor_lock);
1196 if (_processors.empty()) {
1200 bool first_is_on = _processors.front()->active();
1202 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1204 (*i)->deactivate ();
1210 _session.set_dirty ();
1213 /** Set all processors with a given placement to a given active state.
1214 * @param p Placement of processors to change.
1215 * @param state New active state for those processors.
1218 Route::all_processors_active (Placement p, bool state)
1220 Glib::RWLock::ReaderLock lm (_processor_lock);
1222 if (_processors.empty()) {
1225 ProcessorList::iterator start, end;
1226 placement_range(p, start, end);
1228 bool before_amp = true;
1229 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1234 if (p == PreFader && before_amp) {
1238 (*i)->deactivate ();
1243 _session.set_dirty ();
1247 Route::sort_processors (ProcessorStreams* err)
1250 ProcessorSortByKey comparator;
1251 Glib::RWLock::WriterLock lm (_processor_lock);
1252 ChanCount old_pms = processor_max_streams;
1254 /* the sweet power of C++ ... */
1256 ProcessorList as_it_was_before = _processors;
1258 dump_processors (_name + " PRESORT", _processors);
1260 _processors.sort (comparator);
1262 if (configure_processors_unlocked (err)) {
1263 _processors = as_it_was_before;
1264 processor_max_streams = old_pms;
1269 dump_processors (_name + " sorted", _processors);
1271 processors_changed (); /* EMIT SIGNAL */
1283 Route::get_template()
1285 return state(false);
1289 Route::state(bool full_state)
1291 XMLNode *node = new XMLNode("Route");
1292 ProcessorList::iterator i;
1296 node->add_property("flags", enum_2_string (_flags));
1299 node->add_property("default-type", _default_type.to_string());
1301 node->add_property("active", _active?"yes":"no");
1302 node->add_property("muted", _muted?"yes":"no");
1303 node->add_property("soloed", _soloed?"yes":"no");
1304 node->add_property("phase-invert", _phase_invert?"yes":"no");
1305 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1306 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1307 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1308 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1309 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1310 node->add_property("meter-point", enum_2_string (_meter_point));
1313 node->add_property("edit-group", _edit_group->name());
1316 node->add_property("mix-group", _mix_group->name());
1319 string order_string;
1320 OrderKeys::iterator x = order_keys.begin();
1322 while (x != order_keys.end()) {
1323 order_string += string ((*x).first);
1324 order_string += '=';
1325 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1326 order_string += buf;
1330 if (x == order_keys.end()) {
1334 order_string += ':';
1336 node->add_property ("order-keys", order_string);
1338 node->add_child_nocopy (IO::state (full_state));
1339 node->add_child_nocopy (_solo_control->get_state ());
1340 node->add_child_nocopy (_mute_control->get_state ());
1342 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1343 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1344 remote_control_node->add_property (X_("id"), buf);
1345 node->add_child_nocopy (*remote_control_node);
1347 if (_comment.length()) {
1348 XMLNode *cmt = node->add_child ("Comment");
1349 cmt->add_content (_comment);
1352 for (i = _processors.begin(); i != _processors.end(); ++i) {
1353 node->add_child_nocopy((*i)->state (full_state));
1357 node->add_child_copy (*_extra_xml);
1364 Route::get_processor_state ()
1366 XMLNode* root = new XMLNode (X_("redirects"));
1367 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1368 root->add_child_nocopy ((*i)->state (true));
1375 Route::set_processor_state (const XMLNode& root)
1377 if (root.name() != X_("redirects")) {
1383 XMLNodeConstIterator iter;
1384 XMLNodeConstIterator niter;
1385 Glib::RWLock::ReaderLock lm (_processor_lock);
1387 nlist = root.children();
1389 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1391 /* iter now points to a IOProcessor state node */
1393 nnlist = (*iter)->children ();
1395 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1397 /* find the IO child node, since it contains the ID we need */
1399 /* XXX OOP encapsulation violation, ugh */
1401 if ((*niter)->name() == IO::state_node_name) {
1403 XMLProperty* prop = (*niter)->property (X_("id"));
1406 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1410 ID id = prop->value ();
1412 /* now look for a processor with that ID */
1414 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1415 if ((*i)->id() == id) {
1416 (*i)->set_state (**iter);
1432 Route::set_deferred_state ()
1435 XMLNodeConstIterator niter;
1437 if (!deferred_state) {
1441 nlist = deferred_state->children();
1443 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1444 add_processor_from_xml (**niter);
1447 delete deferred_state;
1452 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator* iter)
1454 const XMLProperty *prop;
1456 // legacy sessions use a different node name for sends
1457 if (node.name() == "Send") {
1460 boost::shared_ptr<Send> send (new Send (_session, node));
1461 add_processor (send, 0, iter);
1465 catch (failed_constructor &err) {
1466 error << _("Send construction failed") << endmsg;
1470 } else if (node.name() == "Processor") {
1473 if ((prop = node.property ("type")) != 0) {
1475 boost::shared_ptr<Processor> processor;
1476 bool have_insert = false;
1478 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1479 prop->value() == "lv2" ||
1480 prop->value() == "vst" ||
1481 prop->value() == "audiounit") {
1483 processor.reset (new PluginInsert(_session, node));
1486 } else if (prop->value() == "port") {
1488 processor.reset (new PortInsert (_session, node));
1490 } else if (prop->value() == "send") {
1492 processor.reset (new Send (_session, node));
1495 } else if (prop->value() == "meter") {
1499 } else if (prop->value() == "amp") {
1503 } else if (prop->value() == "listen" || prop->value() == "deliver") {
1505 /* XXX need to generalize */
1507 processor = _control_outs;
1509 } else if (prop->value() == "main-outs") {
1511 processor = _main_outs;
1515 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
1518 return (add_processor (processor, 0, iter) == 0);
1521 error << _("Processor XML node has no type property") << endmsg;
1525 catch (failed_constructor &err) {
1526 warning << _("processor could not be created. Ignored.") << endmsg;
1534 Route::set_state (const XMLNode& node)
1536 return _set_state (node, true);
1540 Route::_set_state (const XMLNode& node, bool call_base)
1543 XMLNodeConstIterator niter;
1545 XMLPropertyList plist;
1546 const XMLProperty *prop;
1548 if (node.name() != "Route"){
1549 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1553 if ((prop = node.property (X_("flags"))) != 0) {
1554 _flags = Flag (string_2_enum (prop->value(), _flags));
1559 if ((prop = node.property (X_("default-type"))) != 0) {
1560 _default_type = DataType(prop->value());
1561 assert(_default_type != DataType::NIL);
1564 if ((prop = node.property (X_("phase-invert"))) != 0) {
1565 set_phase_invert (prop->value()=="yes"?true:false, this);
1568 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1569 set_denormal_protection (prop->value()=="yes"?true:false, this);
1573 if ((prop = node.property (X_("active"))) != 0) {
1574 set_active (prop->value() == "yes");
1577 if ((prop = node.property (X_("muted"))) != 0) {
1578 bool yn = prop->value()=="yes"?true:false;
1580 /* force reset of mute status */
1584 mute_gain = desired_mute_gain;
1587 if ((prop = node.property (X_("soloed"))) != 0) {
1588 bool yn = prop->value()=="yes"?true:false;
1590 /* force reset of solo status */
1593 set_solo (yn, this);
1594 solo_gain = desired_solo_gain;
1597 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1598 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1601 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1602 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1605 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1606 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1609 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1610 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1613 if ((prop = node.property (X_("meter-point"))) != 0) {
1614 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1617 if ((prop = node.property (X_("edit-group"))) != 0) {
1618 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1619 if(edit_group == 0) {
1620 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1622 set_edit_group(edit_group, this);
1626 if ((prop = node.property (X_("order-keys"))) != 0) {
1630 string::size_type colon, equal;
1631 string remaining = prop->value();
1633 while (remaining.length()) {
1635 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1636 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1639 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1640 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1643 set_order_key (remaining.substr (0, equal).c_str(), n);
1647 colon = remaining.find_first_of (':');
1649 if (colon != string::npos) {
1650 remaining = remaining.substr (colon+1);
1657 nlist = node.children();
1659 delete deferred_state;
1660 deferred_state = new XMLNode(X_("deferred state"));
1662 /* set parent class properties before anything else */
1664 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1668 if (child->name() == IO::state_node_name && call_base) {
1669 IO::set_state (*child);
1674 XMLNodeList processor_nodes;
1675 bool has_meter_processor = false; // legacy sessions don't
1677 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1681 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
1682 processor_nodes.push_back(child);
1683 if ((prop = child->property (X_("type"))) != 0 && prop->value() == "meter") {
1684 has_meter_processor = true;
1690 _set_processor_states(processor_nodes);
1691 if (!has_meter_processor) {
1692 set_meter_point(_meter_point, NULL);
1694 processors_changed ();
1696 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1698 // All processors have been applied already
1700 if (child->name() == X_("Automation")) {
1702 if ((prop = child->property (X_("path"))) != 0) {
1703 load_automation (prop->value());
1706 } else if (child->name() == X_("ControlOuts")) {
1708 /* ignore this - deprecated */
1710 } else if (child->name() == X_("Comment")) {
1712 /* XXX this is a terrible API design in libxml++ */
1714 XMLNode *cmt = *(child->children().begin());
1715 _comment = cmt->content();
1717 } else if (child->name() == X_("Extra")) {
1719 _extra_xml = new XMLNode (*child);
1721 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1723 if (prop->value() == "solo") {
1724 _solo_control->set_state (*child);
1725 _session.add_controllable (_solo_control);
1726 } else if (prop->value() == "mute") {
1727 _mute_control->set_state (*child);
1728 _session.add_controllable (_mute_control);
1730 } else if (child->name() == X_("RemoteControl")) {
1731 if ((prop = child->property (X_("id"))) != 0) {
1733 sscanf (prop->value().c_str(), "%d", &x);
1734 set_remote_control_id (x);
1739 if ((prop = node.property (X_("mix-group"))) != 0) {
1740 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1741 if (mix_group == 0) {
1742 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1744 set_mix_group(mix_group, this);
1752 Route::_set_processor_states(const XMLNodeList &nlist)
1754 XMLNodeConstIterator niter;
1756 ProcessorList::iterator i, o;
1758 // Iterate through existing processors, remove those which are not in the state list
1759 for (i = _processors.begin(); i != _processors.end(); ) {
1760 ProcessorList::iterator tmp = i;
1763 bool processorInStateList = false;
1765 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1767 XMLProperty* id_prop = (*niter)->property(X_("id"));
1768 if (id_prop && (*i)->id() == id_prop->value()) {
1769 processorInStateList = true;
1774 if (!processorInStateList) {
1775 remove_processor (*i);
1781 // Iterate through state list and make sure all processors are on the track and in the correct order,
1782 // set the state of existing processors according to the new state on the same go
1783 i = _processors.begin();
1785 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1787 XMLProperty* prop = (*niter)->property ("type");
1791 if (prop->value() != "meter" && prop->value() != "amp" && prop->value() != "main-outs") {
1793 // Check whether the next processor in the list
1795 while (o != _processors.end()) {
1796 XMLProperty* id_prop = (*niter)->property(X_("id"));
1797 if (id_prop && (*o)->id() == id_prop->value()) {
1805 // If the processor (*niter) is not on the route,
1806 // create it and move it to the correct location
1807 if (o == _processors.end()) {
1809 if (add_processor_from_xml (**niter, &i)) {
1810 --i; // move iterator to the newly inserted processor
1812 cerr << "Error restoring route: unable to restore processor" << endl;
1815 // Otherwise, the processor already exists; just
1816 // ensure it is at the location provided in the XML state
1820 boost::shared_ptr<Processor> tmp = (*o);
1821 cerr << "move proc from state\n";
1822 _processors.erase (o); // remove the old copy
1823 _processors.insert (i, tmp); // insert the processor at the correct location
1824 --i; // move iterator to the correct processor
1827 (*i)->set_state (**niter);
1833 Route::curve_reallocate ()
1835 // _gain_automation_curve.finish_resize ();
1836 // _pan_automation_curve.finish_resize ();
1840 Route::silence (nframes_t nframes)
1844 IO::silence (nframes);
1847 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
1850 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1851 boost::shared_ptr<PluginInsert> pi;
1853 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1854 // skip plugins, they don't need anything when we're not active
1858 (*i)->silence (nframes);
1861 if (nframes == _session.get_block_size()) {
1870 boost::shared_ptr<Delivery>
1871 Route::add_listener (boost::shared_ptr<IO> io, const string& listen_name)
1873 string name = _name;
1875 name += listen_name;
1878 boost::shared_ptr<Delivery> listener (new Delivery (_session, name, Delivery::Listen));
1880 /* As an IO, our control outs need as many IO outputs as we have outputs
1881 * (we track the changes in ::output_change_handler()).
1882 * As a processor, the listener is an identity processor
1883 * (i.e. it does not modify its input buffers whatsoever)
1886 if (listener->io()->ensure_io (ChanCount::ZERO, n_outputs(), true, this)) {
1887 return boost::shared_ptr<Delivery>();
1890 listener->set_sort_key (_meter->sort_key() + 1);
1891 add_processor (listener, NULL);
1897 Route::listen_via (boost::shared_ptr<IO> io, const string& listen_name)
1899 vector<string> ports;
1900 vector<string>::const_iterator i;
1903 Glib::RWLock::ReaderLock rm (_processor_lock);
1905 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1906 boost::shared_ptr<const Delivery> d = boost::dynamic_pointer_cast<const Delivery>(*x);
1908 if (d && d->io() == io) {
1909 /* already listening via the specified IO: do nothing */
1915 uint32_t ni = io->n_inputs().n_total();
1917 for (uint32_t n = 0; n < ni; ++n) {
1918 ports.push_back (io->input(n)->name());
1921 if (ports.empty()) {
1925 boost::shared_ptr<Delivery> listen_point = add_listener (io, listen_name);
1927 /* XXX hack for now .... until we can generalize listen points */
1929 _control_outs = listen_point;
1931 /* now connect to the named ports */
1933 ni = listen_point->io()->n_outputs().n_total();
1934 size_t psize = ports.size();
1936 for (size_t n = 0; n < ni; ++n) {
1937 if (listen_point->io()->connect_output (listen_point->io()->output (n), ports[n % psize], this)) {
1938 error << string_compose (_("could not connect %1 to %2"),
1939 listen_point->io()->output(n)->name(), ports[n % psize]) << endmsg;
1949 Route::drop_listen (boost::shared_ptr<IO> io)
1951 ProcessorStreams err;
1952 ProcessorList::iterator tmp;
1954 Glib::RWLock::ReaderLock rm (_processor_lock);
1956 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
1961 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*x);
1963 if (d && d->io() == io) {
1964 /* already listening via the specified IO: do nothing */
1965 remove_processor (*x, &err);
1974 Route::set_edit_group (RouteGroup *eg, void *src)
1977 if (eg == _edit_group) {
1982 _edit_group->remove (this);
1985 if ((_edit_group = eg) != 0) {
1986 _edit_group->add (this);
1989 _session.set_dirty ();
1990 edit_group_changed (src); /* EMIT SIGNAL */
1994 Route::drop_edit_group (void *src)
1997 _session.set_dirty ();
1998 edit_group_changed (src); /* EMIT SIGNAL */
2002 Route::set_mix_group (RouteGroup *mg, void *src)
2005 if (mg == _mix_group) {
2010 _mix_group->remove (this);
2013 if ((_mix_group = mg) != 0) {
2014 _mix_group->add (this);
2017 _session.set_dirty ();
2018 mix_group_changed (src); /* EMIT SIGNAL */
2022 Route::drop_mix_group (void *src)
2025 _session.set_dirty ();
2026 mix_group_changed (src); /* EMIT SIGNAL */
2030 Route::set_comment (string cmt, void *src)
2033 comment_changed (src);
2034 _session.set_dirty ();
2038 Route::feeds (boost::shared_ptr<Route> other)
2043 uint32_t no = self.n_outputs().n_total();
2044 uint32_t ni = other->n_inputs ().n_total();
2046 for (i = 0; i < no; ++i) {
2047 for (j = 0; j < ni; ++j) {
2048 if (self.output(i)->connected_to (other->input(j)->name())) {
2054 /* check IOProcessors which may also interconnect Routes */
2056 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2058 boost::shared_ptr<IOProcessor> proc = boost::dynamic_pointer_cast<IOProcessor>(*r);
2064 no = proc->io()->n_outputs().n_total();
2066 for (i = 0; i < no; ++i) {
2067 for (j = 0; j < ni; ++j) {
2068 if (proc->io()->output(i)->connected_to (other->input (j)->name())) {
2079 Route::set_mute_config (mute_type t, bool onoff, void *src)
2083 _mute_affects_pre_fader = onoff;
2084 pre_fader_changed(src); /* EMIT SIGNAL */
2088 _mute_affects_post_fader = onoff;
2089 post_fader_changed(src); /* EMIT SIGNAL */
2093 _mute_affects_control_outs = onoff;
2094 control_outs_changed(src); /* EMIT SIGNAL */
2098 _mute_affects_main_outs = onoff;
2099 main_outs_changed(src); /* EMIT SIGNAL */
2105 Route::get_mute_config (mute_type t)
2111 onoff = _mute_affects_pre_fader;
2114 onoff = _mute_affects_post_fader;
2117 onoff = _mute_affects_control_outs;
2120 onoff = _mute_affects_main_outs;
2128 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2130 nframes_t now = _session.transport_frame();
2133 Glib::RWLock::ReaderLock lm (_processor_lock);
2136 automation_snapshot (now, true);
2139 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2141 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2142 (*i)->deactivate ();
2146 (*i)->transport_stopped (now);
2150 IO::transport_stopped (now);
2152 _roll_delay = _initial_delay;
2156 Route::input_change_handler (IOChange change, void *src)
2158 if ((change & ConfigurationChanged)) {
2159 configure_processors (0);
2164 Route::output_change_handler (IOChange change, void *src)
2166 if ((change & ConfigurationChanged)) {
2167 if (_control_outs) {
2168 _control_outs->io()->ensure_io (ChanCount::ZERO, n_outputs(), true, this);
2171 configure_processors (0);
2176 Route::pans_required () const
2178 if (n_outputs().n_audio() < 2) {
2182 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2186 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2187 bool session_state_changing, bool can_record, bool rec_monitors_input)
2189 if (n_outputs().n_total() == 0) {
2193 if (session_state_changing || !_active) {
2198 _amp->apply_gain_automation(false);
2200 if (n_inputs() != ChanCount::ZERO) {
2201 passthru (start_frame, end_frame, nframes, 0);
2210 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2212 if (_roll_delay > nframes) {
2214 _roll_delay -= nframes;
2216 /* transport frame is not legal for caller to use */
2219 } else if (_roll_delay > 0) {
2221 nframes -= _roll_delay;
2222 silence (_roll_delay);
2223 /* we've written _roll_delay of samples into the
2224 output ports, so make a note of that for
2227 increment_output_offset (_roll_delay);
2228 transport_frame += _roll_delay;
2237 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2238 bool can_record, bool rec_monitors_input)
2241 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2243 // automation snapshot can also be called from the non-rt context
2244 // and it uses the processor list, so we take the lock out here
2245 automation_snapshot (_session.transport_frame(), false);
2249 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2254 nframes_t unused = 0;
2256 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2262 _amp->apply_gain_automation(false);
2265 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2267 if (am.locked() && _session.transport_rolling()) {
2269 if (_gain_control->automation_playback()) {
2270 _amp->apply_gain_automation(
2271 _gain_control->list()->curve().rt_safe_get_vector (
2272 start_frame, end_frame, _session.gain_automation_buffer(), nframes));
2277 passthru (start_frame, end_frame, nframes, declick);
2283 Route::silent_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2284 bool can_record, bool rec_monitors_input)
2291 Route::toggle_monitor_input ()
2293 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2294 i->ensure_monitor_input( ! i->monitoring_input());
2299 Route::has_external_redirects () const
2301 // FIXME: what about sends?
2303 boost::shared_ptr<const PortInsert> pi;
2305 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2306 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2308 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2309 port != pi->io()->outputs().end(); ++port) {
2311 string port_name = port->name();
2312 string client_name = port_name.substr (0, port_name.find(':'));
2314 /* only say "yes" if the redirect is actually in use */
2316 if (client_name != "ardour" && pi->active()) {
2327 Route::flush_processors ()
2329 /* XXX shouldn't really try to take this lock, since
2330 this is called from the RT audio thread.
2333 Glib::RWLock::ReaderLock lm (_processor_lock);
2335 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2336 (*i)->deactivate ();
2342 Route::set_meter_point (MeterPoint p, void *src)
2344 if (_meter_point != p) {
2347 // Move meter in the processors list
2348 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2349 _processors.erase(loc);
2352 loc = _processors.begin();
2355 loc = find(_processors.begin(), _processors.end(), _amp);
2357 case MeterPostFader:
2358 loc = _processors.end();
2361 _processors.insert(loc, _meter);
2364 if (loc == _processors.end()) {
2365 _meter->set_sort_key(_processors.size());
2367 _meter->set_sort_key((*loc)->sort_key());
2368 for (ProcessorList::iterator p = loc; p != _processors.end(); ++p) {
2369 (*p)->set_sort_key((*p)->sort_key() + 1);
2373 meter_change (src); /* EMIT SIGNAL */
2374 processors_changed (); /* EMIT SIGNAL */
2375 _session.set_dirty ();
2380 Route::update_total_latency ()
2382 nframes_t old = _own_latency;
2384 if (_user_latency) {
2385 _own_latency = _user_latency;
2389 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2390 if ((*i)->active ()) {
2391 _own_latency += (*i)->signal_latency ();
2396 #undef DEBUG_LATENCY
2397 #ifdef DEBUG_LATENCY
2398 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2401 set_port_latency (_own_latency);
2403 if (!_user_latency) {
2404 /* this (virtual) function is used for pure Routes,
2405 not derived classes like AudioTrack. this means
2406 that the data processed here comes from an input
2407 port, not prerecorded material, and therefore we
2408 have to take into account any input latency.
2412 _own_latency += input_latency ();
2415 if (old != _own_latency) {
2416 signal_latency_changed (); /* EMIT SIGNAL */
2419 #ifdef DEBUG_LATENCY
2420 cerr << _name << ": input latency = " << input_latency() << " total = "
2421 << _own_latency << endl;
2424 return _own_latency;
2428 Route::set_user_latency (nframes_t nframes)
2430 Latent::set_user_latency (nframes);
2431 _session.update_latency_compensation (false, false);
2435 Route::set_latency_delay (nframes_t longest_session_latency)
2437 nframes_t old = _initial_delay;
2439 if (_own_latency < longest_session_latency) {
2440 _initial_delay = longest_session_latency - _own_latency;
2445 if (_initial_delay != old) {
2446 initial_delay_changed (); /* EMIT SIGNAL */
2449 if (_session.transport_stopped()) {
2450 _roll_delay = _initial_delay;
2455 Route::automation_snapshot (nframes_t now, bool force)
2457 if (!force && !should_snapshot(now)) {
2461 IO::automation_snapshot (now, force);
2463 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2464 (*i)->automation_snapshot (now, force);
2468 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2469 : Controllable (name), route (s), type(tp)
2475 Route::ToggleControllable::set_value (float val)
2477 bool bval = ((val >= 0.5f) ? true: false);
2481 route.set_mute (bval, this);
2484 route.set_solo (bval, this);
2492 Route::ToggleControllable::get_value (void) const
2498 val = route.muted() ? 1.0f : 0.0f;
2501 val = route.soloed() ? 1.0f : 0.0f;
2511 Route::set_block_size (nframes_t nframes)
2513 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2514 (*i)->set_block_size (nframes);
2516 _session.ensure_buffers(processor_max_streams);
2520 Route::protect_automation ()
2522 Automatable::protect_automation();
2524 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2525 (*i)->protect_automation();
2529 Route::set_pending_declick (int declick)
2532 /* this call is not allowed to turn off a pending declick unless "force" is true */
2534 _pending_declick = declick;
2536 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2538 _pending_declick = 0;
2543 /** Shift automation forwards from a particular place, thereby inserting time.
2544 * Adds undo commands for any shifts that are performed.
2546 * @param pos Position to start shifting from.
2547 * @param frames Amount to shift forwards by.
2551 Route::shift (nframes64_t pos, nframes64_t frames)
2553 #ifdef THIS_NEEDS_FIXING_FOR_V3
2555 /* gain automation */
2556 XMLNode &before = _gain_control->get_state ();
2557 _gain_control->shift (pos, frames);
2558 XMLNode &after = _gain_control->get_state ();
2559 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2561 /* pan automation */
2562 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2563 Curve & c = (*i)->automation ();
2564 XMLNode &before = c.get_state ();
2565 c.shift (pos, frames);
2566 XMLNode &after = c.get_state ();
2567 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2570 /* redirect automation */
2572 Glib::RWLock::ReaderLock lm (redirect_lock);
2573 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2576 (*i)->what_has_automation (a);
2578 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2579 AutomationList & al = (*i)->automation_list (*j);
2580 XMLNode &before = al.get_state ();
2581 al.shift (pos, frames);
2582 XMLNode &after = al.get_state ();
2583 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2593 Route::save_as_template (const string& path, const string& name)
2595 XMLNode& node (state (false));
2598 IO::set_name_in_state (*node.children().front(), name);
2600 tree.set_root (&node);
2601 return tree.write (path.c_str());
2606 Route::set_name (const string& str)
2611 if ((ret = IO::set_name (str)) == true) {
2612 Glib::RWLock::ReaderLock lm (_processor_lock);
2614 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2616 /* rename all delivery objects to reflect our new name */
2618 boost::shared_ptr<Delivery> dp = boost::dynamic_pointer_cast<Delivery> (*i);
2621 string dp_name = str;
2623 dp_name += "XXX FIX ME XXX";
2626 if (!dp->set_name (dp_name)) {