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.
24 #include <sigc++/bind.h>
25 #include "pbd/xml++.h"
26 #include "pbd/enumwriter.h"
27 #include "pbd/stacktrace.h"
28 #include "pbd/memento_command.h"
30 #include "evoral/Curve.hpp"
32 #include "ardour/timestamps.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/route.h"
35 #include "ardour/buffer.h"
36 #include "ardour/processor.h"
37 #include "ardour/plugin_insert.h"
38 #include "ardour/port_insert.h"
39 #include "ardour/send.h"
40 #include "ardour/session.h"
41 #include "ardour/utils.h"
42 #include "ardour/configuration.h"
43 #include "ardour/cycle_timer.h"
44 #include "ardour/route_group.h"
45 #include "ardour/port.h"
46 #include "ardour/audio_port.h"
47 #include "ardour/ladspa_plugin.h"
48 #include "ardour/panner.h"
49 #include "ardour/dB.h"
50 #include "ardour/amp.h"
51 #include "ardour/meter.h"
52 #include "ardour/buffer_set.h"
53 #include "ardour/mix.h"
54 #include "ardour/profile.h"
59 using namespace ARDOUR;
62 uint32_t Route::order_key_cnt = 0;
63 sigc::signal<void,const char*> Route::SyncOrderKeys;
65 Route::Route (Session& sess, string name,
66 int in_min, int in_max, int out_min, int out_max,
67 Flag flg, DataType default_type)
68 : IO (sess, name, in_min, in_max, out_min, out_max, default_type)
70 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
71 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
76 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
77 : IO (sess, *node.child ("IO"), default_type)
78 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
79 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
82 _set_state (node, false);
88 processor_max_outs.reset();
94 _phase_invert = false;
95 _denormal_protection = false;
96 order_keys[strdup (N_("signal"))] = order_key_cnt++;
98 _meter_point = MeterPostFader;
103 _have_internal_generator = false;
104 _declickable = false;
105 _pending_declick = true;
106 _remote_control_id = 0;
111 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
112 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
113 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
114 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
117 desired_solo_gain = 1.0;
119 desired_mute_gain = 1.0;
123 input_changed.connect (mem_fun (this, &Route::input_change_handler));
124 output_changed.connect (mem_fun (this, &Route::output_change_handler));
129 clear_processors (PreFader);
130 clear_processors (PostFader);
132 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
133 free ((void*)(i->first));
136 delete _control_outs;
140 Route::set_remote_control_id (uint32_t id)
142 if (id != _remote_control_id) {
143 _remote_control_id = id;
144 RemoteControlIDChanged ();
149 Route::remote_control_id() const
151 return _remote_control_id;
155 Route::order_key (const char* name) const
157 OrderKeys::const_iterator i;
159 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
160 if (!strcmp (name, i->first)) {
169 Route::set_order_key (const char* name, long n)
171 order_keys[strdup(name)] = n;
173 if (Config->get_sync_all_route_ordering()) {
174 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
179 _session.set_dirty ();
183 Route::sync_order_keys (const char* base)
185 if (order_keys.empty()) {
189 OrderKeys::iterator i;
192 if ((i = order_keys.find (base)) == order_keys.end()) {
193 /* key doesn't exist, use the first existing key (during session initialization) */
194 i = order_keys.begin();
198 /* key exists - use it and reset all others (actually, itself included) */
199 i = order_keys.begin();
203 for (; i != order_keys.end(); ++i) {
209 Route::ensure_track_or_route_name(string name, Session &session)
211 string newname = name;
213 while (session.route_by_name (newname) != NULL) {
214 newname = bump_name_once (newname);
222 Route::inc_gain (gain_t fraction, void *src)
224 IO::inc_gain (fraction, src);
228 Route::set_gain (gain_t val, void *src)
230 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
232 if (_mix_group->is_relative()) {
234 gain_t usable_gain = gain();
235 if (usable_gain < 0.000001f) {
236 usable_gain = 0.000001f;
240 if (delta < 0.000001f) {
244 delta -= usable_gain;
249 gain_t factor = delta / usable_gain;
252 factor = _mix_group->get_max_factor(factor);
253 if (factor == 0.0f) {
254 _gain_control->Changed(); /* EMIT SIGNAL */
258 factor = _mix_group->get_min_factor(factor);
259 if (factor == 0.0f) {
260 _gain_control->Changed(); /* EMIT SIGNAL */
265 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
269 _mix_group->apply (&Route::set_gain, val, _mix_group);
279 IO::set_gain (val, src);
282 /** Process this route for one (sub) cycle (process thread)
284 * @param bufs Scratch buffers to use for the signal path
285 * @param start_frame Initial transport frame
286 * @param end_frame Final transport frame
287 * @param nframes Number of frames to output (to ports)
288 * @param offset Output offset (of port buffers, for split cycles)
290 * Note that (end_frame - start_frame) may not be equal to nframes when the
291 * transport speed isn't 1.0 (eg varispeed).
294 Route::process_output_buffers (BufferSet& bufs,
295 nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset,
296 bool with_processors, int declick, bool meter)
298 // This is definitely very audio-only for now
299 assert(_default_type == DataType::AUDIO);
301 ProcessorList::iterator i;
302 bool post_fader_work = false;
303 bool mute_declick_applied = false;
309 gain_t* gab = _session.gain_automation_buffer();
311 switch (Config->get_monitoring_model()) {
312 case HardwareMonitoring:
313 case ExternalMonitoring:
320 declick = _pending_declick;
323 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
333 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
336 dmg = desired_mute_gain;
337 dsg = desired_solo_gain;
346 /* -------------------------------------------------------------------------------------------
347 GLOBAL DECLICK (for transport changes etc.)
348 ----------------------------------------------------------------------------------------- */
351 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
352 _pending_declick = 0;
353 } else if (declick < 0) {
354 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
355 _pending_declick = 0;
358 /* no global declick */
360 if (solo_gain != dsg) {
361 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
367 /* -------------------------------------------------------------------------------------------
368 INPUT METERING & MONITORING
369 ----------------------------------------------------------------------------------------- */
371 if (meter && (_meter_point == MeterInput)) {
372 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
375 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
376 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
378 mute_declick_applied = true;
381 if ((_meter_point == MeterInput) && co) {
383 solo_audible = dsg > 0;
384 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
386 if ( // muted by solo of another track
390 // muted by mute of this track
394 // rec-enabled but not s/w monitoring
396 // TODO: this is probably wrong
398 ( no_monitor && record_enabled()
399 && (!Config->get_auto_input() || _session.actively_recording()) )
403 co->silence (nframes, offset);
407 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
412 /* -------------------------------------------------------------------------------------------
414 ----------------------------------------------------------------------------------------- */
416 if (_denormal_protection || Config->get_denormal_protection()) {
418 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
419 Sample* const sp = i->data();
421 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
427 /* -------------------------------------------------------------------------------------------
429 ----------------------------------------------------------------------------------------- */
431 if (with_processors) {
432 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
434 if (mute_gain > 0 || !_mute_affects_pre_fader) {
435 for (i = _processors.begin(); i != _processors.end(); ++i) {
436 switch ((*i)->placement()) {
438 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
441 post_fader_work = true;
446 for (i = _processors.begin(); i != _processors.end(); ++i) {
447 switch ((*i)->placement()) {
449 (*i)->silence (nframes, offset);
452 post_fader_work = true;
460 /* When we entered this method, the number of bufs was set by n_process_buffers(), so
461 * it may be larger than required. Consider e.g a mono track with two redirects A and B.
462 * If A has one input and three outputs, and B three inputs and one output, n_process_buffers()
463 * will be 3. In this case, now we've done pre-fader redirects, we can reset the number of bufs.
465 bufs.set_count (pre_fader_streams());
467 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
468 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
470 mute_declick_applied = true;
473 /* -------------------------------------------------------------------------------------------
474 PRE-FADER METERING & MONITORING
475 ----------------------------------------------------------------------------------------- */
477 if (meter && (_meter_point == MeterPreFader)) {
478 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
482 if ((_meter_point == MeterPreFader) && co) {
484 solo_audible = dsg > 0;
485 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
487 if ( // muted by solo of another track
491 // muted by mute of this track
495 // rec-enabled but not s/w monitoring
497 ( no_monitor && record_enabled()
498 && (!Config->get_auto_input() || _session.actively_recording()) )
502 co->silence (nframes, offset);
506 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
510 /* -------------------------------------------------------------------------------------------
512 ----------------------------------------------------------------------------------------- */
514 /* if not recording or recording and requiring any monitor signal, then apply gain */
516 if ( // not recording
518 !(record_enabled() && _session.actively_recording()) ||
522 // AND software monitoring required
524 Config->get_monitoring_model() == SoftwareMonitoring) {
526 if (apply_gain_automation) {
529 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
530 Sample* const sp = i->data();
532 for (nframes_t nx = 0; nx < nframes; ++nx) {
537 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
538 Sample* const sp = i->data();
540 for (nframes_t nx = 0; nx < nframes; ++nx) {
546 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
547 _effective_gain = gab[nframes-1];
552 /* manual (scalar) gain */
556 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
559 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
561 /* no need to interpolate current gain value,
562 but its non-unity, so apply it. if the gain
563 is zero, do nothing because we'll ship silence
575 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
576 Sample* const sp = i->data();
577 apply_gain_to_buffer(sp,nframes,this_gain);
580 } else if (_gain == 0) {
581 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
589 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
593 /* -------------------------------------------------------------------------------------------
595 ----------------------------------------------------------------------------------------- */
597 /* note that post_fader_work cannot be true unless with_processors was also true,
601 if (post_fader_work) {
603 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
605 if (mute_gain > 0 || !_mute_affects_post_fader) {
606 for (i = _processors.begin(); i != _processors.end(); ++i) {
607 switch ((*i)->placement()) {
611 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
616 for (i = _processors.begin(); i != _processors.end(); ++i) {
617 switch ((*i)->placement()) {
621 (*i)->silence (nframes, offset);
629 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
630 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
632 mute_declick_applied = true;
635 /* -------------------------------------------------------------------------------------------
637 ----------------------------------------------------------------------------------------- */
639 if ((_meter_point == MeterPostFader) && co) {
641 solo_audible = solo_gain > 0;
642 mute_audible = dmg > 0 || !_mute_affects_control_outs;
644 if ( // silent anyway
646 (_gain == 0 && !apply_gain_automation) ||
648 // muted by solo of another track
652 // muted by mute of this track
656 // recording but not s/w monitoring
658 ( no_monitor && record_enabled()
659 && (!Config->get_auto_input() || _session.actively_recording()) )
663 co->silence (nframes, offset);
667 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
671 /* -------------------------------------------------------------------------------------------
673 ----------------------------------------------------------------------------------------- */
675 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
676 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
678 mute_declick_applied = true;
681 /* -------------------------------------------------------------------------------------------
683 ----------------------------------------------------------------------------------------- */
685 solo_audible = dsg > 0;
686 mute_audible = dmg > 0 || !_mute_affects_main_outs;
688 if (n_outputs().get(_default_type) == 0) {
692 } else if (no_monitor && record_enabled()
693 && (!Config->get_auto_input() || _session.actively_recording())) {
695 IO::silence (nframes, offset);
699 if ( // silent anyway
701 (_gain == 0 && !apply_gain_automation) ||
703 // muted by solo of another track, but not using control outs for solo
705 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
707 // muted by mute of this track
713 /* don't use Route::silence() here, because that causes
714 all outputs (sends, port processors, etc. to be silent).
717 if (_meter_point == MeterPostFader) {
718 peak_meter().reset();
721 IO::silence (nframes, offset);
725 deliver_output(bufs, start_frame, end_frame, nframes, offset);
731 /* -------------------------------------------------------------------------------------------
733 ----------------------------------------------------------------------------------------- */
735 if (meter && (_meter_point == MeterPostFader)) {
736 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
739 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
745 /** Process this route for one (sub) cycle (process thread)
747 * @param bufs Scratch buffers to use for the signal path
748 * @param start_frame Initial transport frame
749 * @param end_frame Final transport frame
750 * @param nframes Number of frames to output (to ports)
751 * @param offset Output offset (of port buffers, for split cycles)
753 * Note that (end_frame - start_frame) may not be equal to nframes when the
754 * transport speed isn't 1.0 (eg varispeed).
757 Route::process_output_buffers (BufferSet& bufs,
758 nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset,
759 bool with_processors, int declick, bool meter)
761 // This is definitely very audio-only for now
762 assert(_default_type == DataType::AUDIO);
764 ProcessorList::iterator i;
765 bool post_fader_work = false;
766 bool mute_declick_applied = false;
772 gain_t* gab = _session.gain_automation_buffer();
774 switch (Config->get_monitoring_model()) {
775 case HardwareMonitoring:
776 case ExternalMonitoring:
783 declick = _pending_declick;
786 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
796 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
799 dmg = desired_mute_gain;
800 dsg = desired_solo_gain;
809 /* -------------------------------------------------------------------------------------------
810 GLOBAL DECLICK (for transport changes etc.)
811 input metering & monitoring (control outs)
814 pre-fader metering & monitoring (control outs)
819 post-fader metering & monitoring (control outs)
820 ----------------------------------------------------------------------------------------- */
823 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
824 for (i = processors.begin(); i != processors.end(); ++i) {
825 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
830 /* -------------------------------------------------------------------------------------------
831 INPUT METERING & MONITORING
832 ----------------------------------------------------------------------------------------- */
834 if (meter && (_meter_point == MeterInput)) {
835 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
838 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
839 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
841 mute_declick_applied = true;
844 /* -------------------------------------------------------------------------------------------
846 ----------------------------------------------------------------------------------------- */
848 // This really should already be true...
849 bufs.set_count(pre_fader_streams());
852 if ((_meter_point == MeterPreFader) && co) {
854 solo_audible = dsg > 0;
855 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
857 if ( // muted by solo of another track
861 // muted by mute of this track
865 // rec-enabled but not s/w monitoring
867 ( no_monitor && record_enabled()
868 && (!Config->get_auto_input() || _session.actively_recording()) )
872 co->silence (nframes, offset);
876 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
880 /* -------------------------------------------------------------------------------------------
882 ----------------------------------------------------------------------------------------- */
884 /* if not recording or recording and requiring any monitor signal, then apply gain */
886 if ( // not recording
888 !(record_enabled() && _session.actively_recording()) ||
892 // AND software monitoring required
894 Config->get_monitoring_model() == SoftwareMonitoring) {
896 if (apply_gain_automation) {
899 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
900 Sample* const sp = i->data();
902 for (nframes_t nx = 0; nx < nframes; ++nx) {
907 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
908 Sample* const sp = i->data();
910 for (nframes_t nx = 0; nx < nframes; ++nx) {
916 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
917 _effective_gain = gab[nframes-1];
922 /* manual (scalar) gain */
926 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
929 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
931 /* no need to interpolate current gain value,
932 but its non-unity, so apply it. if the gain
933 is zero, do nothing because we'll ship silence
945 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
946 Sample* const sp = i->data();
947 apply_gain_to_buffer(sp,nframes,this_gain);
950 } else if (_gain == 0) {
951 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
959 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
963 /* -------------------------------------------------------------------------------------------
965 ----------------------------------------------------------------------------------------- */
967 if ((_meter_point == MeterPostFader) && co) {
969 solo_audible = solo_gain > 0;
970 mute_audible = dmg > 0 || !_mute_affects_control_outs;
972 if ( // silent anyway
974 (_gain == 0 && !apply_gain_automation) ||
976 // muted by solo of another track
980 // muted by mute of this track
984 // recording but not s/w monitoring
986 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
990 co->silence (nframes, offset);
994 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
998 /* -------------------------------------------------------------------------------------------
1000 ----------------------------------------------------------------------------------------- */
1002 solo_audible = dsg > 0;
1003 mute_audible = dmg > 0 || !_mute_affects_main_outs;
1005 if (n_outputs().get(_default_type) == 0) {
1009 } else if (no_monitor && record_enabled()
1010 && (!Config->get_auto_input() || _session.actively_recording())) {
1012 IO::silence (nframes, offset);
1016 if ( // silent anyway
1018 (_gain == 0 && !apply_gain_automation) ||
1020 // muted by solo of another track, but not using control outs for solo
1022 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
1024 // muted by mute of this track
1030 /* don't use Route::silence() here, because that causes
1031 all outputs (sends, port processors, etc. to be silent).
1034 if (_meter_point == MeterPostFader) {
1035 peak_meter().reset();
1038 IO::silence (nframes, offset);
1042 deliver_output(bufs, start_frame, end_frame, nframes, offset);
1049 #endif /* NEW_POB */
1052 Route::n_process_buffers ()
1054 return max (n_inputs(), processor_max_outs);
1058 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
1060 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
1064 collect_input (bufs, nframes, offset);
1067 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
1068 meter_first = false;
1073 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
1077 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
1079 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
1083 Route::set_solo (bool yn, void *src)
1089 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1090 _mix_group->apply (&Route::set_solo, yn, _mix_group);
1094 if (_soloed != yn) {
1096 solo_changed (src); /* EMIT SIGNAL */
1097 _solo_control->Changed (); /* EMIT SIGNAL */
1100 catch_up_on_solo_mute_override ();
1104 Route::catch_up_on_solo_mute_override ()
1106 if (Config->get_solo_model() != InverseMute) {
1112 Glib::Mutex::Lock lm (declick_lock);
1115 if (Config->get_solo_mute_override()) {
1116 desired_mute_gain = (_soloed?1.0:0.0);
1118 desired_mute_gain = 0.0;
1121 desired_mute_gain = 1.0;
1127 Route::set_solo_mute (bool yn)
1129 Glib::Mutex::Lock lm (declick_lock);
1131 /* Called by Session in response to another Route being soloed.
1134 desired_solo_gain = (yn?0.0:1.0);
1138 Route::set_solo_safe (bool yn, void *src)
1140 if (_solo_safe != yn) {
1142 solo_safe_changed (src); /* EMIT SIGNAL */
1147 Route::set_mute (bool yn, void *src)
1150 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1151 _mix_group->apply (&Route::set_mute, yn, _mix_group);
1157 mute_changed (src); /* EMIT SIGNAL */
1159 _mute_control->Changed (); /* EMIT SIGNAL */
1161 Glib::Mutex::Lock lm (declick_lock);
1163 if (_soloed && Config->get_solo_mute_override()){
1164 desired_mute_gain = 1.0f;
1166 desired_mute_gain = (yn?0.0f:1.0f);
1172 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1174 ChanCount old_pmo = processor_max_outs;
1176 if (!_session.engine().connected()) {
1181 Glib::RWLock::WriterLock lm (_processor_lock);
1183 boost::shared_ptr<PluginInsert> pi;
1184 boost::shared_ptr<PortInsert> porti;
1186 //processor->set_default_type(_default_type);
1188 _processors.push_back (processor);
1190 // Set up processor list channels. This will set processor->[input|output]_streams(),
1191 // configure redirect ports properly, etc.
1192 if (_reset_processor_counts (err)) {
1193 _processors.pop_back ();
1194 _reset_processor_counts (0); // it worked before we tried to add it ...
1198 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1200 if (pi->natural_input_streams() == ChanCount::ZERO) {
1201 /* generator plugin */
1202 _have_internal_generator = true;
1207 // Ensure peak vector sizes before the plugin is activated
1209 ChanCount potential_max_streams;
1211 potential_max_streams.set (DataType::AUDIO, max (processor->input_streams().n_audio(),
1212 processor->output_streams().n_audio()));
1213 potential_max_streams.set (DataType::MIDI, max (processor->input_streams().n_midi(),
1214 processor->output_streams().n_midi()));
1216 _meter->configure_io (potential_max_streams, potential_max_streams);
1218 // XXX: do we want to emit the signal here ? change call order.
1219 processor->activate ();
1220 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1225 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1229 processors_changed (); /* EMIT SIGNAL */
1235 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
1237 /* NOTE: this is intended to be used ONLY when copying
1238 processors from another Route. Hence the subtle
1239 differences between this and ::add_processor()
1242 ChanCount old_pmo = processor_max_outs;
1244 if (!_session.engine().connected()) {
1249 Glib::RWLock::WriterLock lm (_processor_lock);
1251 ProcessorList::iterator existing_end = _processors.end();
1254 ChanCount potential_max_streams;
1256 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1258 boost::shared_ptr<PluginInsert> pi;
1260 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1263 ChanCount m = max(pi->input_streams(), pi->output_streams());
1264 if (m > potential_max_streams)
1265 potential_max_streams = m;
1268 // Ensure peak vector sizes before the plugin is activated
1269 _meter->configure_io (potential_max_streams, potential_max_streams);
1271 _processors.push_back (*i);
1273 if (_reset_processor_counts (err)) {
1275 _processors.erase (existing_end, _processors.end());
1276 _reset_processor_counts (0); // it worked before we tried to add it ...
1280 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1286 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1290 processors_changed (); /* EMIT SIGNAL */
1294 /** Turn off all processors with a given placement
1295 * @param p Placement of processors to disable
1298 Route::disable_processors (Placement p)
1300 Glib::RWLock::ReaderLock lm (_processor_lock);
1302 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1303 if ((*i)->placement() == p) {
1304 (*i)->deactivate ();
1308 _session.set_dirty ();
1311 /** Turn off all redirects
1314 Route::disable_processors ()
1316 Glib::RWLock::ReaderLock lm (_processor_lock);
1318 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1319 (*i)->deactivate ();
1322 _session.set_dirty ();
1325 /** Turn off all redirects with a given placement
1326 * @param p Placement of redirects to disable
1329 Route::disable_plugins (Placement p)
1331 Glib::RWLock::ReaderLock lm (_processor_lock);
1333 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1334 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
1335 (*i)->deactivate ();
1339 _session.set_dirty ();
1342 /** Turn off all plugins
1345 Route::disable_plugins ()
1347 Glib::RWLock::ReaderLock lm (_processor_lock);
1349 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1350 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1351 (*i)->deactivate ();
1355 _session.set_dirty ();
1360 Route::ab_plugins (bool forward)
1362 Glib::RWLock::ReaderLock lm (_processor_lock);
1366 /* forward = turn off all active redirects, and mark them so that the next time
1367 we go the other way, we will revert them
1370 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1371 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1375 if ((*i)->active()) {
1376 (*i)->deactivate ();
1377 (*i)->set_next_ab_is_active (true);
1379 (*i)->set_next_ab_is_active (false);
1385 /* backward = if the redirect was marked to go active on the next ab, do so */
1387 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1389 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1393 if ((*i)->get_next_ab_is_active()) {
1396 (*i)->deactivate ();
1401 _session.set_dirty ();
1405 /* Figure out the streams that will feed into PreFader */
1407 Route::pre_fader_streams() const
1409 boost::shared_ptr<Processor> processor;
1411 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
1413 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1414 if ((*i)->placement() == PreFader && boost::dynamic_pointer_cast<Send> (*i) == 0) {
1420 return processor->output_streams();
1427 /** Remove processors with a given placement.
1428 * @param p Placement of processors to remove.
1431 Route::clear_processors (Placement p)
1433 const ChanCount old_pmo = processor_max_outs;
1435 if (!_session.engine().connected()) {
1440 Glib::RWLock::WriterLock lm (_processor_lock);
1441 ProcessorList new_list;
1443 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1444 if ((*i)->placement() == p) {
1445 /* it's the placement we want to get rid of */
1446 (*i)->drop_references ();
1448 /* it's a different placement, so keep it */
1449 new_list.push_back (*i);
1453 _processors = new_list;
1456 /* FIXME: can't see how this test can ever fire */
1457 if (processor_max_outs != old_pmo) {
1461 processor_max_outs.reset();
1462 _have_internal_generator = false;
1463 processors_changed (); /* EMIT SIGNAL */
1467 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1469 ChanCount old_pmo = processor_max_outs;
1471 if (!_session.engine().connected()) {
1475 processor_max_outs.reset();
1478 Glib::RWLock::WriterLock lm (_processor_lock);
1479 ProcessorList::iterator i;
1480 bool removed = false;
1482 for (i = _processors.begin(); i != _processors.end(); ++i) {
1483 if (*i == processor) {
1485 ProcessorList::iterator tmp;
1487 /* move along, see failure case for reset_processor_counts()
1488 where we may need to reprocessor the processor.
1494 /* stop redirects that send signals to JACK ports
1495 from causing noise as a result of no longer being
1499 boost::shared_ptr<IOProcessor> redirect;
1501 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1502 redirect->io()->disconnect_inputs (this);
1503 redirect->io()->disconnect_outputs (this);
1506 _processors.erase (i);
1521 if (_reset_processor_counts (err)) {
1522 /* get back to where we where */
1523 _processors.insert (i, processor);
1524 /* we know this will work, because it worked before :) */
1525 _reset_processor_counts (0);
1529 _have_internal_generator = false;
1531 for (i = _processors.begin(); i != _processors.end(); ++i) {
1532 boost::shared_ptr<PluginInsert> pi;
1534 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1535 if (pi->is_generator()) {
1536 _have_internal_generator = true;
1543 if (old_pmo != processor_max_outs) {
1547 processor->drop_references ();
1549 processors_changed (); /* EMIT SIGNAL */
1554 Route::reset_processor_counts (ProcessorStreams* err)
1556 Glib::RWLock::WriterLock lm (_processor_lock);
1557 return _reset_processor_counts (err);
1562 Route::_reset_processor_counts (ProcessorStreams* err)
1564 ProcessorList::iterator r;
1565 uint32_t insert_cnt = 0;
1566 uint32_t send_cnt = 0;
1567 map<Placement,list<ProcessorCount> > proc_map;
1568 ProcessorList::iterator prev;
1569 ChanCount initial_streams = n_inputs ();
1570 ChanCount previous_initial_streams = n_inputs ();
1572 uint32_t max_audio = 0;
1573 uint32_t max_midi = 0;
1575 processor_max_outs.reset ();
1577 /* Step 1: build a map that links each insert to an in/out channel count
1579 Divide inserts up by placement so we get the signal flow
1580 properly modelled. we need to do this because the _processors
1581 list is not sorted by placement, and because other reasons may
1582 exist now or in the future for this separate treatment.
1585 /* ... but it should/will be... */
1587 for (r = _processors.begin(); r != _processors.end(); ++r) {
1589 boost::shared_ptr<PluginInsert> plugin_insert;
1590 boost::shared_ptr<PortInsert> port_insert;
1592 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1595 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1597 /* reset plugin counts back to one for now so
1598 that we have a predictable, controlled
1599 state to try to configure.
1602 plugin_insert->set_count (1);
1604 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1607 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1609 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1614 if (insert_cnt == 0) {
1623 /* Now process each placement in order, checking to see if we
1624 can really do what has been requested.
1629 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1633 if (!proc_map[PreFader].empty()) {
1634 previous_initial_streams = n_inputs ();
1635 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1636 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) == false) {
1639 previous_initial_streams = initial_streams;
1645 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1649 if (!proc_map[PostFader].empty()) {
1650 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1651 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) == false) {
1654 previous_initial_streams = initial_streams;
1658 /* OK, everything can be set up correctly, so lets do it */
1660 apply_some_processor_counts (proc_map[PreFader]);
1661 apply_some_processor_counts (proc_map[PostFader]);
1663 /* recompute max outs of any processor */
1669 processor_max_outs.reset ();
1670 prev = _processors.end();
1672 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1673 boost::shared_ptr<Send> s;
1675 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1677 /* don't pay any attention to send output configuration, since it doesn't
1681 if (r == _processors.begin()) {
1682 s->expect_inputs (n_inputs());
1684 s->expect_inputs ((*prev)->output_streams());
1689 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1690 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1694 processor_max_outs.set (DataType::AUDIO, max_audio);
1695 processor_max_outs.set (DataType::MIDI, max_midi);
1701 for (r = _processors.begin(); r != _processors.end(); ++r) {
1702 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1703 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1706 processor_max_outs.set (DataType::AUDIO, max_audio);
1707 processor_max_outs.set (DataType::MIDI, max_midi);
1713 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1715 list<ProcessorCount>::iterator i;
1717 for (i = iclist.begin(); i != iclist.end(); ++i) {
1719 ProcessorCount& pc (*i);
1721 if (pc.processor->configure_io (pc.in, pc.out)) {
1725 /* make sure that however many we have, they are all active */
1727 pc.processor->activate ();
1733 /** Returns whether \a iclist can be configured and run starting with
1734 * \a required_inputs at the first processor's inputs.
1735 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1736 * Otherwise, \a err is set to the output of the list.
1739 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1741 list<ProcessorCount>::iterator i;
1746 err->count = required_inputs;
1749 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1751 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1754 err->count = required_inputs;
1759 (*i).in = required_inputs;
1760 required_inputs = (*i).out;
1767 Route::all_processors_flip ()
1769 Glib::RWLock::ReaderLock lm (_processor_lock);
1771 if (_processors.empty()) {
1775 bool first_is_on = _processors.front()->active();
1777 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1779 (*i)->deactivate ();
1785 _session.set_dirty ();
1788 /** Set all processors with a given placement to a given active state.
1789 * @param p Placement of processors to change.
1790 * @param state New active state for those processors.
1793 Route::all_processors_active (Placement p, bool state)
1795 Glib::RWLock::ReaderLock lm (_processor_lock);
1797 if (_processors.empty()) {
1801 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1802 if ((*i)->placement() == p) {
1806 (*i)->deactivate ();
1811 _session.set_dirty ();
1814 struct ProcessorSorter {
1815 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1816 return a->sort_key() < b->sort_key();
1821 Route::sort_processors (ProcessorStreams* err)
1824 ProcessorSorter comparator;
1825 Glib::RWLock::WriterLock lm (_processor_lock);
1826 ChanCount old_pmo = processor_max_outs;
1828 /* the sweet power of C++ ... */
1830 ProcessorList as_it_was_before = _processors;
1832 _processors.sort (comparator);
1834 if (_reset_processor_counts (err)) {
1835 _processors = as_it_was_before;
1836 processor_max_outs = old_pmo;
1842 processors_changed (); /* EMIT SIGNAL */
1854 Route::get_template()
1856 return state(false);
1860 Route::state(bool full_state)
1862 XMLNode *node = new XMLNode("Route");
1863 ProcessorList::iterator i;
1867 node->add_property("flags", enum_2_string (_flags));
1870 node->add_property("default-type", _default_type.to_string());
1872 node->add_property("active", _active?"yes":"no");
1873 node->add_property("muted", _muted?"yes":"no");
1874 node->add_property("soloed", _soloed?"yes":"no");
1875 node->add_property("phase-invert", _phase_invert?"yes":"no");
1876 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1877 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1878 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1879 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1880 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1881 node->add_property("meter-point", enum_2_string (_meter_point));
1884 node->add_property("edit-group", _edit_group->name());
1887 node->add_property("mix-group", _mix_group->name());
1890 string order_string;
1891 OrderKeys::iterator x = order_keys.begin();
1893 while (x != order_keys.end()) {
1894 order_string += string ((*x).first);
1895 order_string += '=';
1896 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1897 order_string += buf;
1901 if (x == order_keys.end()) {
1905 order_string += ':';
1907 node->add_property ("order-keys", order_string);
1909 node->add_child_nocopy (IO::state (full_state));
1910 node->add_child_nocopy (_solo_control->get_state ());
1911 node->add_child_nocopy (_mute_control->get_state ());
1913 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1914 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1915 remote_control_node->add_property (X_("id"), buf);
1916 node->add_child_nocopy (*remote_control_node);
1918 if (_control_outs) {
1919 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1920 cnode->add_child_nocopy (_control_outs->state (full_state));
1921 node->add_child_nocopy (*cnode);
1924 if (_comment.length()) {
1925 XMLNode *cmt = node->add_child ("Comment");
1926 cmt->add_content (_comment);
1929 for (i = _processors.begin(); i != _processors.end(); ++i) {
1930 node->add_child_nocopy((*i)->state (full_state));
1934 node->add_child_copy (*_extra_xml);
1941 Route::get_processor_state ()
1943 XMLNode* root = new XMLNode (X_("redirects"));
1944 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1945 root->add_child_nocopy ((*i)->state (true));
1952 Route::set_processor_state (const XMLNode& root)
1954 if (root.name() != X_("redirects")) {
1960 XMLNodeConstIterator iter;
1961 XMLNodeConstIterator niter;
1962 Glib::RWLock::ReaderLock lm (_processor_lock);
1964 nlist = root.children();
1966 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1968 /* iter now points to a IOProcessor state node */
1970 nnlist = (*iter)->children ();
1972 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1974 /* find the IO child node, since it contains the ID we need */
1976 /* XXX OOP encapsulation violation, ugh */
1978 if ((*niter)->name() == IO::state_node_name) {
1980 XMLProperty* prop = (*niter)->property (X_("id"));
1983 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1987 ID id = prop->value ();
1989 /* now look for a processor with that ID */
1991 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1992 if ((*i)->id() == id) {
1993 (*i)->set_state (**iter);
2009 Route::set_deferred_state ()
2012 XMLNodeConstIterator niter;
2014 if (!deferred_state) {
2018 nlist = deferred_state->children();
2020 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2021 add_processor_from_xml (**niter);
2024 delete deferred_state;
2029 Route::add_processor_from_xml (const XMLNode& node)
2031 const XMLProperty *prop;
2033 // legacy sessions use a different node name for sends
2034 if (node.name() == "Send") {
2037 boost::shared_ptr<Send> send (new Send (_session, node));
2038 add_processor (send);
2041 catch (failed_constructor &err) {
2042 error << _("Send construction failed") << endmsg;
2046 // use "Processor" in XML?
2047 } else if (node.name() == "Processor") {
2050 if ((prop = node.property ("type")) != 0) {
2052 boost::shared_ptr<Processor> processor;
2053 bool have_insert = false;
2055 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2056 prop->value() == "lv2" ||
2057 prop->value() == "vst" ||
2058 prop->value() == "audiounit") {
2060 processor.reset (new PluginInsert(_session, node));
2063 } else if (prop->value() == "port") {
2065 processor.reset (new PortInsert (_session, node));
2067 } else if (prop->value() == "send") {
2069 processor.reset (new Send (_session, node));
2074 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2077 add_processor (processor);
2080 error << _("Processor XML node has no type property") << endmsg;
2084 catch (failed_constructor &err) {
2085 warning << _("processor could not be created. Ignored.") << endmsg;
2092 Route::set_state (const XMLNode& node)
2094 return _set_state (node, true);
2098 Route::_set_state (const XMLNode& node, bool call_base)
2101 XMLNodeConstIterator niter;
2103 XMLPropertyList plist;
2104 const XMLProperty *prop;
2106 if (node.name() != "Route"){
2107 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2111 if ((prop = node.property (X_("flags"))) != 0) {
2112 _flags = Flag (string_2_enum (prop->value(), _flags));
2117 if ((prop = node.property (X_("default-type"))) != 0) {
2118 _default_type = DataType(prop->value());
2119 assert(_default_type != DataType::NIL);
2122 if ((prop = node.property (X_("phase-invert"))) != 0) {
2123 set_phase_invert (prop->value()=="yes"?true:false, this);
2126 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2127 set_denormal_protection (prop->value()=="yes"?true:false, this);
2131 if ((prop = node.property (X_("active"))) != 0) {
2132 set_active (prop->value() == "yes");
2135 if ((prop = node.property (X_("muted"))) != 0) {
2136 bool yn = prop->value()=="yes"?true:false;
2138 /* force reset of mute status */
2142 mute_gain = desired_mute_gain;
2145 if ((prop = node.property (X_("soloed"))) != 0) {
2146 bool yn = prop->value()=="yes"?true:false;
2148 /* force reset of solo status */
2151 set_solo (yn, this);
2152 solo_gain = desired_solo_gain;
2155 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2156 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2159 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2160 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2163 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2164 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2167 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2168 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2171 if ((prop = node.property (X_("meter-point"))) != 0) {
2172 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2175 if ((prop = node.property (X_("edit-group"))) != 0) {
2176 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2177 if(edit_group == 0) {
2178 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2180 set_edit_group(edit_group, this);
2184 if ((prop = node.property (X_("order-keys"))) != 0) {
2188 string::size_type colon, equal;
2189 string remaining = prop->value();
2191 while (remaining.length()) {
2193 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2194 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2197 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2198 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2201 set_order_key (remaining.substr (0, equal).c_str(), n);
2205 colon = remaining.find_first_of (':');
2207 if (colon != string::npos) {
2208 remaining = remaining.substr (colon+1);
2215 nlist = node.children();
2217 delete deferred_state;
2218 deferred_state = new XMLNode(X_("deferred state"));
2220 /* set parent class properties before anything else */
2222 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2226 if (child->name() == IO::state_node_name && call_base) {
2228 IO::set_state (*child);
2233 XMLNodeList processor_nodes;
2235 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2239 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
2240 processor_nodes.push_back(child);
2245 _set_processor_states(processor_nodes);
2248 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2250 // All processors have been applied already
2252 if (child->name() == X_("Automation")) {
2254 if ((prop = child->property (X_("path"))) != 0) {
2255 load_automation (prop->value());
2258 } else if (child->name() == X_("ControlOuts")) {
2260 string coutname = _name;
2261 coutname += _("[control]");
2263 delete _control_outs;
2264 _control_outs = new IO (_session, coutname);
2265 _control_outs->set_state (**(child->children().begin()));
2267 } else if (child->name() == X_("Comment")) {
2269 /* XXX this is a terrible API design in libxml++ */
2271 XMLNode *cmt = *(child->children().begin());
2272 _comment = cmt->content();
2274 } else if (child->name() == X_("Extra")) {
2276 _extra_xml = new XMLNode (*child);
2278 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2280 if (prop->value() == "solo") {
2281 _solo_control->set_state (*child);
2282 _session.add_controllable (_solo_control);
2283 } else if (prop->value() == "mute") {
2284 _mute_control->set_state (*child);
2285 _session.add_controllable (_mute_control);
2288 else if (child->name() == X_("RemoteControl")) {
2289 if ((prop = child->property (X_("id"))) != 0) {
2291 sscanf (prop->value().c_str(), "%d", &x);
2292 set_remote_control_id (x);
2297 if ((prop = node.property (X_("mix-group"))) != 0) {
2298 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2299 if (mix_group == 0) {
2300 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2302 set_mix_group(mix_group, this);
2310 Route::_set_processor_states(const XMLNodeList &nlist)
2312 XMLNodeConstIterator niter;
2315 ProcessorList::iterator i, o;
2317 // Iterate through existing processors, remove those which are not in the state list
2318 for (i = _processors.begin(); i != _processors.end(); ) {
2319 ProcessorList::iterator tmp = i;
2322 bool processorInStateList = false;
2324 (*i)->id().print (buf, sizeof (buf));
2327 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2329 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2330 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2331 processorInStateList = true;
2333 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2334 processorInStateList = true;
2339 if (!processorInStateList) {
2340 remove_processor (*i);
2348 // Iterate through state list and make sure all processors are on the track and in the correct order,
2349 // set the state of existing processors according to the new state on the same go
2350 i = _processors.begin();
2351 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2353 // Check whether the next processor in the list
2356 while (o != _processors.end()) {
2357 (*o)->id().print (buf, sizeof (buf));
2358 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2360 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2366 if (o == _processors.end()) {
2367 // If the processor (*niter) is not on the route, we need to create it
2368 // and move it to the correct location
2370 ProcessorList::iterator prev_last = _processors.end();
2371 --prev_last; // We need this to check whether adding succeeded
2373 add_processor_from_xml (**niter);
2375 ProcessorList::iterator last = _processors.end();
2378 if (prev_last == last) {
2379 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2384 boost::shared_ptr<Processor> tmp = (*last);
2385 // remove the processor from the wrong location
2386 _processors.erase(last);
2387 // processor the new processor at the current location
2388 _processors.insert(i, tmp);
2390 --i; // move pointer to the newly processored processor
2394 // We found the processor (*niter) on the route, first we must make sure the processor
2395 // is at the location provided in the XML state
2397 boost::shared_ptr<Processor> tmp = (*o);
2398 // remove the old copy
2399 _processors.erase(o);
2400 // processor the processor at the correct location
2401 _processors.insert(i, tmp);
2403 --i; // move pointer so it points to the right processor
2406 (*i)->set_state( (**niter) );
2409 processors_changed ();
2413 Route::curve_reallocate ()
2415 // _gain_automation_curve.finish_resize ();
2416 // _pan_automation_curve.finish_resize ();
2420 Route::silence (nframes_t nframes, nframes_t offset)
2424 IO::silence (nframes, offset);
2426 if (_control_outs) {
2427 _control_outs->silence (nframes, offset);
2431 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2434 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2435 boost::shared_ptr<PluginInsert> pi;
2436 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2437 // skip plugins, they don't need anything when we're not active
2441 (*i)->silence (nframes, offset);
2444 if (nframes == _session.get_block_size() && offset == 0) {
2454 Route::set_control_outs (const vector<string>& ports)
2456 Glib::Mutex::Lock lm (_control_outs_lock);
2457 vector<string>::const_iterator i;
2460 delete _control_outs;
2463 if (is_control() || is_master()) {
2464 /* no control outs for these two special busses */
2468 if (ports.empty()) {
2472 string coutname = _name;
2473 coutname += _("[control]");
2475 _control_outs = new IO (_session, coutname);
2477 /* our control outs need as many outputs as we
2478 have audio outputs. we track the changes in ::output_change_handler().
2481 // XXX its stupid that we have to get this value twice
2483 limit = n_outputs().n_audio();
2485 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2489 /* now connect to the named ports */
2491 for (size_t n = 0; n < limit; ++n) {
2492 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2493 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2502 Route::set_edit_group (RouteGroup *eg, void *src)
2505 if (eg == _edit_group) {
2510 _edit_group->remove (this);
2513 if ((_edit_group = eg) != 0) {
2514 _edit_group->add (this);
2517 _session.set_dirty ();
2518 edit_group_changed (src); /* EMIT SIGNAL */
2522 Route::drop_edit_group (void *src)
2525 _session.set_dirty ();
2526 edit_group_changed (src); /* EMIT SIGNAL */
2530 Route::set_mix_group (RouteGroup *mg, void *src)
2533 if (mg == _mix_group) {
2538 _mix_group->remove (this);
2541 if ((_mix_group = mg) != 0) {
2542 _mix_group->add (this);
2545 _session.set_dirty ();
2546 mix_group_changed (src); /* EMIT SIGNAL */
2550 Route::drop_mix_group (void *src)
2553 _session.set_dirty ();
2554 mix_group_changed (src); /* EMIT SIGNAL */
2558 Route::set_comment (string cmt, void *src)
2561 comment_changed (src);
2562 _session.set_dirty ();
2566 Route::feeds (boost::shared_ptr<Route> other)
2571 uint32_t no = self.n_outputs().n_total();
2572 uint32_t ni = other->n_inputs ().n_total();
2574 for (i = 0; i < no; ++i) {
2575 for (j = 0; j < ni; ++j) {
2576 if (self.output(i)->connected_to (other->input(j)->name())) {
2582 /* check IOProcessors which may also interconnect Routes */
2584 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2586 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2591 // TODO: support internal redirects here
2593 no = redirect->io()->n_outputs().n_total();
2595 for (i = 0; i < no; ++i) {
2596 for (j = 0; j < ni; ++j) {
2597 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2604 /* check for control room outputs which may also interconnect Routes */
2606 if (_control_outs) {
2608 no = _control_outs->n_outputs().n_total();
2610 for (i = 0; i < no; ++i) {
2611 for (j = 0; j < ni; ++j) {
2612 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2623 Route::set_mute_config (mute_type t, bool onoff, void *src)
2627 _mute_affects_pre_fader = onoff;
2628 pre_fader_changed(src); /* EMIT SIGNAL */
2632 _mute_affects_post_fader = onoff;
2633 post_fader_changed(src); /* EMIT SIGNAL */
2637 _mute_affects_control_outs = onoff;
2638 control_outs_changed(src); /* EMIT SIGNAL */
2642 _mute_affects_main_outs = onoff;
2643 main_outs_changed(src); /* EMIT SIGNAL */
2649 Route::get_mute_config (mute_type t)
2655 onoff = _mute_affects_pre_fader;
2658 onoff = _mute_affects_post_fader;
2661 onoff = _mute_affects_control_outs;
2664 onoff = _mute_affects_main_outs;
2672 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2674 nframes_t now = _session.transport_frame();
2677 Glib::RWLock::ReaderLock lm (_processor_lock);
2680 automation_snapshot (now, true);
2683 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2685 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2686 (*i)->deactivate ();
2690 (*i)->transport_stopped (now);
2694 IO::transport_stopped (now);
2696 _roll_delay = _initial_delay;
2700 Route::input_change_handler (IOChange change, void *ignored)
2702 if (change & ConfigurationChanged) {
2703 reset_processor_counts (0);
2708 Route::output_change_handler (IOChange change, void *ignored)
2710 if (change & ConfigurationChanged) {
2711 if (_control_outs) {
2712 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2715 reset_processor_counts (0);
2720 Route::pans_required () const
2722 if (n_outputs().n_audio() < 2) {
2726 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2730 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2731 bool session_state_changing, bool can_record, bool rec_monitors_input)
2733 if (n_outputs().n_total() == 0) {
2737 if (session_state_changing || !_active) {
2738 silence (nframes, offset);
2742 apply_gain_automation = false;
2744 if (n_inputs().n_total()) {
2745 passthru (start_frame, end_frame, nframes, offset, 0, false);
2747 silence (nframes, offset);
2754 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2756 if (_roll_delay > nframes) {
2758 _roll_delay -= nframes;
2759 silence (nframes, offset);
2760 /* transport frame is not legal for caller to use */
2763 } else if (_roll_delay > 0) {
2765 nframes -= _roll_delay;
2767 silence (_roll_delay, offset);
2769 offset += _roll_delay;
2770 transport_frame += _roll_delay;
2779 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2780 bool can_record, bool rec_monitors_input)
2783 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2785 // automation snapshot can also be called from the non-rt context
2786 // and it uses the processor list, so we take the lock out here
2787 automation_snapshot (_session.transport_frame(), false);
2791 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2792 silence (nframes, offset);
2796 nframes_t unused = 0;
2798 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2804 apply_gain_automation = false;
2807 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2809 if (am.locked() && _session.transport_rolling()) {
2811 if (_gain_control->automation_playback()) {
2812 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2813 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2818 passthru (start_frame, end_frame, nframes, offset, declick, false);
2824 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2825 bool can_record, bool rec_monitors_input)
2827 silence (nframes, offset);
2832 Route::toggle_monitor_input ()
2834 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2835 i->ensure_monitor_input( ! i->monitoring_input());
2840 Route::has_external_redirects () const
2842 // FIXME: what about sends?
2844 boost::shared_ptr<const PortInsert> pi;
2846 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2847 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2849 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2850 port != pi->io()->outputs().end(); ++port) {
2852 string port_name = port->name();
2853 string client_name = port_name.substr (0, port_name.find(':'));
2855 /* only say "yes" if the redirect is actually in use */
2857 if (client_name != "ardour" && pi->active()) {
2868 Route::flush_processors ()
2870 /* XXX shouldn't really try to take this lock, since
2871 this is called from the RT audio thread.
2874 Glib::RWLock::ReaderLock lm (_processor_lock);
2876 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2877 (*i)->deactivate ();
2883 Route::set_meter_point (MeterPoint p, void *src)
2885 if (_meter_point != p) {
2887 meter_change (src); /* EMIT SIGNAL */
2888 _session.set_dirty ();
2893 Route::update_total_latency ()
2895 nframes_t old = _own_latency;
2897 if (_user_latency) {
2898 _own_latency = _user_latency;
2902 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2903 if ((*i)->active ()) {
2904 _own_latency += (*i)->signal_latency ();
2909 #undef DEBUG_LATENCY
2910 #ifdef DEBUG_LATENCY
2911 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2914 set_port_latency (_own_latency);
2916 if (!_user_latency) {
2917 /* this (virtual) function is used for pure Routes,
2918 not derived classes like AudioTrack. this means
2919 that the data processed here comes from an input
2920 port, not prerecorded material, and therefore we
2921 have to take into account any input latency.
2925 _own_latency += input_latency ();
2928 if (old != _own_latency) {
2929 signal_latency_changed (); /* EMIT SIGNAL */
2932 #ifdef DEBUG_LATENCY
2933 cerr << _name << ": input latency = " << input_latency() << " total = "
2934 << _own_latency << endl;
2937 return _own_latency;
2941 Route::set_user_latency (nframes_t nframes)
2943 Latent::set_user_latency (nframes);
2944 _session.update_latency_compensation (false, false);
2948 Route::set_latency_delay (nframes_t longest_session_latency)
2950 nframes_t old = _initial_delay;
2952 if (_own_latency < longest_session_latency) {
2953 _initial_delay = longest_session_latency - _own_latency;
2958 if (_initial_delay != old) {
2959 initial_delay_changed (); /* EMIT SIGNAL */
2962 if (_session.transport_stopped()) {
2963 _roll_delay = _initial_delay;
2968 Route::automation_snapshot (nframes_t now, bool force)
2970 if (!force && !should_snapshot(now)) {
2974 IO::automation_snapshot (now, force);
2976 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2977 (*i)->automation_snapshot (now, force);
2981 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2982 : Controllable (name), route (s), type(tp)
2988 Route::ToggleControllable::set_value (float val)
2990 bool bval = ((val >= 0.5f) ? true: false);
2994 route.set_mute (bval, this);
2997 route.set_solo (bval, this);
3005 Route::ToggleControllable::get_value (void) const
3011 val = route.muted() ? 1.0f : 0.0f;
3014 val = route.soloed() ? 1.0f : 0.0f;
3024 Route::set_block_size (nframes_t nframes)
3026 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3027 (*i)->set_block_size (nframes);
3032 Route::protect_automation ()
3034 Automatable::protect_automation();
3036 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3037 (*i)->protect_automation();
3041 Route::set_pending_declick (int declick)
3044 /* this call is not allowed to turn off a pending declick unless "force" is true */
3046 _pending_declick = declick;
3048 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3050 _pending_declick = 0;
3055 /** Shift automation forwards from a particular place, thereby inserting time.
3056 * Adds undo commands for any shifts that are performed.
3058 * @param pos Position to start shifting from.
3059 * @param frames Amount to shift forwards by.
3063 Route::shift (nframes64_t pos, nframes64_t frames)
3065 #ifdef THIS_NEEDS_FIXING_FOR_V3
3067 /* gain automation */
3068 XMLNode &before = _gain_control->get_state ();
3069 _gain_control->shift (pos, frames);
3070 XMLNode &after = _gain_control->get_state ();
3071 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3073 /* pan automation */
3074 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3075 Curve & c = (*i)->automation ();
3076 XMLNode &before = c.get_state ();
3077 c.shift (pos, frames);
3078 XMLNode &after = c.get_state ();
3079 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3082 /* redirect automation */
3084 Glib::RWLock::ReaderLock lm (redirect_lock);
3085 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3088 (*i)->what_has_automation (a);
3090 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3091 AutomationList & al = (*i)->automation_list (*j);
3092 XMLNode &before = al.get_state ();
3093 al.shift (pos, frames);
3094 XMLNode &after = al.get_state ();
3095 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));