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) {
2227 IO::set_state (*child);
2232 XMLNodeList processor_nodes;
2234 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2238 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
2239 processor_nodes.push_back(child);
2244 _set_processor_states(processor_nodes);
2247 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2249 // All processors have been applied already
2251 if (child->name() == X_("Automation")) {
2253 if ((prop = child->property (X_("path"))) != 0) {
2254 load_automation (prop->value());
2257 } else if (child->name() == X_("ControlOuts")) {
2259 string coutname = _name;
2260 coutname += _("[control]");
2262 delete _control_outs;
2263 _control_outs = new IO (_session, coutname);
2265 /* fix up the control out name in the XML before setting it.
2266 Otherwise track templates don't work because the control
2267 outs end up with the stored template name, rather than
2268 the new name of the track based on the template.
2271 XMLProperty* prop = (*child->children().begin())->property ("name");
2273 prop->set_value (coutname);
2276 _control_outs->set_state (**(child->children().begin()));
2278 } else if (child->name() == X_("Comment")) {
2280 /* XXX this is a terrible API design in libxml++ */
2282 XMLNode *cmt = *(child->children().begin());
2283 _comment = cmt->content();
2285 } else if (child->name() == X_("Extra")) {
2287 _extra_xml = new XMLNode (*child);
2289 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2291 if (prop->value() == "solo") {
2292 _solo_control->set_state (*child);
2293 _session.add_controllable (_solo_control);
2294 } else if (prop->value() == "mute") {
2295 _mute_control->set_state (*child);
2296 _session.add_controllable (_mute_control);
2299 else if (child->name() == X_("RemoteControl")) {
2300 if ((prop = child->property (X_("id"))) != 0) {
2302 sscanf (prop->value().c_str(), "%d", &x);
2303 set_remote_control_id (x);
2308 if ((prop = node.property (X_("mix-group"))) != 0) {
2309 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2310 if (mix_group == 0) {
2311 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2313 set_mix_group(mix_group, this);
2321 Route::_set_processor_states(const XMLNodeList &nlist)
2323 XMLNodeConstIterator niter;
2326 ProcessorList::iterator i, o;
2328 // Iterate through existing processors, remove those which are not in the state list
2329 for (i = _processors.begin(); i != _processors.end(); ) {
2330 ProcessorList::iterator tmp = i;
2333 bool processorInStateList = false;
2335 (*i)->id().print (buf, sizeof (buf));
2338 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2340 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2341 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2342 processorInStateList = true;
2344 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2345 processorInStateList = true;
2350 if (!processorInStateList) {
2351 remove_processor (*i);
2359 // Iterate through state list and make sure all processors are on the track and in the correct order,
2360 // set the state of existing processors according to the new state on the same go
2361 i = _processors.begin();
2362 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2364 // Check whether the next processor in the list
2367 while (o != _processors.end()) {
2368 (*o)->id().print (buf, sizeof (buf));
2369 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2371 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2377 if (o == _processors.end()) {
2378 // If the processor (*niter) is not on the route, we need to create it
2379 // and move it to the correct location
2381 ProcessorList::iterator prev_last = _processors.end();
2382 --prev_last; // We need this to check whether adding succeeded
2384 add_processor_from_xml (**niter);
2386 ProcessorList::iterator last = _processors.end();
2389 if (prev_last == last) {
2390 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2395 boost::shared_ptr<Processor> tmp = (*last);
2396 // remove the processor from the wrong location
2397 _processors.erase(last);
2398 // processor the new processor at the current location
2399 _processors.insert(i, tmp);
2401 --i; // move pointer to the newly processored processor
2405 // We found the processor (*niter) on the route, first we must make sure the processor
2406 // is at the location provided in the XML state
2408 boost::shared_ptr<Processor> tmp = (*o);
2409 // remove the old copy
2410 _processors.erase(o);
2411 // processor the processor at the correct location
2412 _processors.insert(i, tmp);
2414 --i; // move pointer so it points to the right processor
2417 (*i)->set_state( (**niter) );
2420 processors_changed ();
2424 Route::curve_reallocate ()
2426 // _gain_automation_curve.finish_resize ();
2427 // _pan_automation_curve.finish_resize ();
2431 Route::silence (nframes_t nframes, nframes_t offset)
2435 IO::silence (nframes, offset);
2437 if (_control_outs) {
2438 _control_outs->silence (nframes, offset);
2442 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2445 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2446 boost::shared_ptr<PluginInsert> pi;
2447 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2448 // skip plugins, they don't need anything when we're not active
2452 (*i)->silence (nframes, offset);
2455 if (nframes == _session.get_block_size() && offset == 0) {
2465 Route::set_control_outs (const vector<string>& ports)
2467 Glib::Mutex::Lock lm (_control_outs_lock);
2468 vector<string>::const_iterator i;
2471 delete _control_outs;
2474 if (is_control() || is_master()) {
2475 /* no control outs for these two special busses */
2479 if (ports.empty()) {
2483 string coutname = _name;
2484 coutname += _("[control]");
2486 _control_outs = new IO (_session, coutname);
2488 /* our control outs need as many outputs as we
2489 have audio outputs. we track the changes in ::output_change_handler().
2492 // XXX its stupid that we have to get this value twice
2494 limit = n_outputs().n_audio();
2496 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2500 /* now connect to the named ports */
2502 for (size_t n = 0; n < limit; ++n) {
2503 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2504 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2513 Route::set_edit_group (RouteGroup *eg, void *src)
2516 if (eg == _edit_group) {
2521 _edit_group->remove (this);
2524 if ((_edit_group = eg) != 0) {
2525 _edit_group->add (this);
2528 _session.set_dirty ();
2529 edit_group_changed (src); /* EMIT SIGNAL */
2533 Route::drop_edit_group (void *src)
2536 _session.set_dirty ();
2537 edit_group_changed (src); /* EMIT SIGNAL */
2541 Route::set_mix_group (RouteGroup *mg, void *src)
2544 if (mg == _mix_group) {
2549 _mix_group->remove (this);
2552 if ((_mix_group = mg) != 0) {
2553 _mix_group->add (this);
2556 _session.set_dirty ();
2557 mix_group_changed (src); /* EMIT SIGNAL */
2561 Route::drop_mix_group (void *src)
2564 _session.set_dirty ();
2565 mix_group_changed (src); /* EMIT SIGNAL */
2569 Route::set_comment (string cmt, void *src)
2572 comment_changed (src);
2573 _session.set_dirty ();
2577 Route::feeds (boost::shared_ptr<Route> other)
2582 uint32_t no = self.n_outputs().n_total();
2583 uint32_t ni = other->n_inputs ().n_total();
2585 for (i = 0; i < no; ++i) {
2586 for (j = 0; j < ni; ++j) {
2587 if (self.output(i)->connected_to (other->input(j)->name())) {
2593 /* check IOProcessors which may also interconnect Routes */
2595 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2597 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2602 // TODO: support internal redirects here
2604 no = redirect->io()->n_outputs().n_total();
2606 for (i = 0; i < no; ++i) {
2607 for (j = 0; j < ni; ++j) {
2608 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2615 /* check for control room outputs which may also interconnect Routes */
2617 if (_control_outs) {
2619 no = _control_outs->n_outputs().n_total();
2621 for (i = 0; i < no; ++i) {
2622 for (j = 0; j < ni; ++j) {
2623 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2634 Route::set_mute_config (mute_type t, bool onoff, void *src)
2638 _mute_affects_pre_fader = onoff;
2639 pre_fader_changed(src); /* EMIT SIGNAL */
2643 _mute_affects_post_fader = onoff;
2644 post_fader_changed(src); /* EMIT SIGNAL */
2648 _mute_affects_control_outs = onoff;
2649 control_outs_changed(src); /* EMIT SIGNAL */
2653 _mute_affects_main_outs = onoff;
2654 main_outs_changed(src); /* EMIT SIGNAL */
2660 Route::get_mute_config (mute_type t)
2666 onoff = _mute_affects_pre_fader;
2669 onoff = _mute_affects_post_fader;
2672 onoff = _mute_affects_control_outs;
2675 onoff = _mute_affects_main_outs;
2683 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2685 nframes_t now = _session.transport_frame();
2688 Glib::RWLock::ReaderLock lm (_processor_lock);
2691 automation_snapshot (now, true);
2694 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2696 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2697 (*i)->deactivate ();
2701 (*i)->transport_stopped (now);
2705 IO::transport_stopped (now);
2707 _roll_delay = _initial_delay;
2711 Route::input_change_handler (IOChange change, void *ignored)
2713 if (change & ConfigurationChanged) {
2714 reset_processor_counts (0);
2719 Route::output_change_handler (IOChange change, void *ignored)
2721 if (change & ConfigurationChanged) {
2722 if (_control_outs) {
2723 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2726 reset_processor_counts (0);
2731 Route::pans_required () const
2733 if (n_outputs().n_audio() < 2) {
2737 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2741 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2742 bool session_state_changing, bool can_record, bool rec_monitors_input)
2744 if (n_outputs().n_total() == 0) {
2748 if (session_state_changing || !_active) {
2749 silence (nframes, offset);
2753 apply_gain_automation = false;
2755 if (n_inputs().n_total()) {
2756 passthru (start_frame, end_frame, nframes, offset, 0, false);
2758 silence (nframes, offset);
2765 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2767 if (_roll_delay > nframes) {
2769 _roll_delay -= nframes;
2770 silence (nframes, offset);
2771 /* transport frame is not legal for caller to use */
2774 } else if (_roll_delay > 0) {
2776 nframes -= _roll_delay;
2778 silence (_roll_delay, offset);
2780 offset += _roll_delay;
2781 transport_frame += _roll_delay;
2790 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2791 bool can_record, bool rec_monitors_input)
2794 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2796 // automation snapshot can also be called from the non-rt context
2797 // and it uses the processor list, so we take the lock out here
2798 automation_snapshot (_session.transport_frame(), false);
2802 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2803 silence (nframes, offset);
2807 nframes_t unused = 0;
2809 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2815 apply_gain_automation = false;
2818 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2820 if (am.locked() && _session.transport_rolling()) {
2822 if (_gain_control->automation_playback()) {
2823 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2824 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2829 passthru (start_frame, end_frame, nframes, offset, declick, false);
2835 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2836 bool can_record, bool rec_monitors_input)
2838 silence (nframes, offset);
2843 Route::toggle_monitor_input ()
2845 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2846 i->ensure_monitor_input( ! i->monitoring_input());
2851 Route::has_external_redirects () const
2853 // FIXME: what about sends?
2855 boost::shared_ptr<const PortInsert> pi;
2857 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2858 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2860 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2861 port != pi->io()->outputs().end(); ++port) {
2863 string port_name = port->name();
2864 string client_name = port_name.substr (0, port_name.find(':'));
2866 /* only say "yes" if the redirect is actually in use */
2868 if (client_name != "ardour" && pi->active()) {
2879 Route::flush_processors ()
2881 /* XXX shouldn't really try to take this lock, since
2882 this is called from the RT audio thread.
2885 Glib::RWLock::ReaderLock lm (_processor_lock);
2887 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2888 (*i)->deactivate ();
2894 Route::set_meter_point (MeterPoint p, void *src)
2896 if (_meter_point != p) {
2898 meter_change (src); /* EMIT SIGNAL */
2899 _session.set_dirty ();
2904 Route::update_total_latency ()
2906 nframes_t old = _own_latency;
2908 if (_user_latency) {
2909 _own_latency = _user_latency;
2913 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2914 if ((*i)->active ()) {
2915 _own_latency += (*i)->signal_latency ();
2920 #undef DEBUG_LATENCY
2921 #ifdef DEBUG_LATENCY
2922 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2925 set_port_latency (_own_latency);
2927 if (!_user_latency) {
2928 /* this (virtual) function is used for pure Routes,
2929 not derived classes like AudioTrack. this means
2930 that the data processed here comes from an input
2931 port, not prerecorded material, and therefore we
2932 have to take into account any input latency.
2936 _own_latency += input_latency ();
2939 if (old != _own_latency) {
2940 signal_latency_changed (); /* EMIT SIGNAL */
2943 #ifdef DEBUG_LATENCY
2944 cerr << _name << ": input latency = " << input_latency() << " total = "
2945 << _own_latency << endl;
2948 return _own_latency;
2952 Route::set_user_latency (nframes_t nframes)
2954 Latent::set_user_latency (nframes);
2955 _session.update_latency_compensation (false, false);
2959 Route::set_latency_delay (nframes_t longest_session_latency)
2961 nframes_t old = _initial_delay;
2963 if (_own_latency < longest_session_latency) {
2964 _initial_delay = longest_session_latency - _own_latency;
2969 if (_initial_delay != old) {
2970 initial_delay_changed (); /* EMIT SIGNAL */
2973 if (_session.transport_stopped()) {
2974 _roll_delay = _initial_delay;
2979 Route::automation_snapshot (nframes_t now, bool force)
2981 if (!force && !should_snapshot(now)) {
2985 IO::automation_snapshot (now, force);
2987 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2988 (*i)->automation_snapshot (now, force);
2992 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2993 : Controllable (name), route (s), type(tp)
2999 Route::ToggleControllable::set_value (float val)
3001 bool bval = ((val >= 0.5f) ? true: false);
3005 route.set_mute (bval, this);
3008 route.set_solo (bval, this);
3016 Route::ToggleControllable::get_value (void) const
3022 val = route.muted() ? 1.0f : 0.0f;
3025 val = route.soloed() ? 1.0f : 0.0f;
3035 Route::set_block_size (nframes_t nframes)
3037 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3038 (*i)->set_block_size (nframes);
3043 Route::protect_automation ()
3045 Automatable::protect_automation();
3047 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3048 (*i)->protect_automation();
3052 Route::set_pending_declick (int declick)
3055 /* this call is not allowed to turn off a pending declick unless "force" is true */
3057 _pending_declick = declick;
3059 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3061 _pending_declick = 0;
3066 /** Shift automation forwards from a particular place, thereby inserting time.
3067 * Adds undo commands for any shifts that are performed.
3069 * @param pos Position to start shifting from.
3070 * @param frames Amount to shift forwards by.
3074 Route::shift (nframes64_t pos, nframes64_t frames)
3076 #ifdef THIS_NEEDS_FIXING_FOR_V3
3078 /* gain automation */
3079 XMLNode &before = _gain_control->get_state ();
3080 _gain_control->shift (pos, frames);
3081 XMLNode &after = _gain_control->get_state ();
3082 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3084 /* pan automation */
3085 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3086 Curve & c = (*i)->automation ();
3087 XMLNode &before = c.get_state ();
3088 c.shift (pos, frames);
3089 XMLNode &after = c.get_state ();
3090 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3093 /* redirect automation */
3095 Glib::RWLock::ReaderLock lm (redirect_lock);
3096 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3099 (*i)->what_has_automation (a);
3101 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3102 AutomationList & al = (*i)->automation_list (*j);
3103 XMLNode &before = al.get_state ();
3104 al.shift (pos, frames);
3105 XMLNode &after = al.get_state ();
3106 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
3116 Route::save_as_template (const string& path, const string& name)
3118 XMLNode& node (state (false));
3121 IO::set_name_in_state (*node.children().front(), name);
3123 tree.set_root (&node);
3124 return tree.write (path.c_str());