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 <ardour/timestamps.h>
31 #include <ardour/audioengine.h>
32 #include <ardour/route.h>
33 #include <ardour/buffer.h>
34 #include <ardour/processor.h>
35 #include <ardour/plugin_insert.h>
36 #include <ardour/port_insert.h>
37 #include <ardour/send.h>
38 #include <ardour/session.h>
39 #include <ardour/utils.h>
40 #include <ardour/configuration.h>
41 #include <ardour/cycle_timer.h>
42 #include <ardour/route_group.h>
43 #include <ardour/port.h>
44 #include <ardour/audio_port.h>
45 #include <ardour/ladspa_plugin.h>
46 #include <ardour/panner.h>
47 #include <ardour/dB.h>
48 #include <ardour/amp.h>
49 #include <ardour/meter.h>
50 #include <ardour/buffer_set.h>
51 #include <ardour/mix.h>
52 #include <ardour/profile.h>
57 using namespace ARDOUR;
60 uint32_t Route::order_key_cnt = 0;
61 sigc::signal<void,const char*> Route::SyncOrderKeys;
63 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
64 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
66 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
67 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
72 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
73 : IO (sess, *node.child ("IO"), default_type),
74 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
75 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
78 _set_state (node, false);
84 processor_max_outs.reset();
90 _phase_invert = false;
91 _denormal_protection = false;
92 order_keys[strdup (N_("signal"))] = order_key_cnt++;
94 _meter_point = MeterPostFader;
99 _have_internal_generator = false;
100 _declickable = false;
101 _pending_declick = true;
102 _remote_control_id = 0;
107 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
108 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
109 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
110 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
113 desired_solo_gain = 1.0;
115 desired_mute_gain = 1.0;
119 input_changed.connect (mem_fun (this, &Route::input_change_handler));
120 output_changed.connect (mem_fun (this, &Route::output_change_handler));
125 clear_processors (PreFader);
126 clear_processors (PostFader);
128 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
129 free ((void*)(i->first));
132 delete _control_outs;
136 Route::set_remote_control_id (uint32_t id)
138 if (id != _remote_control_id) {
139 _remote_control_id = id;
140 RemoteControlIDChanged ();
145 Route::remote_control_id() const
147 return _remote_control_id;
151 Route::order_key (const char* name) const
153 OrderKeys::const_iterator i;
155 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
156 if (!strcmp (name, i->first)) {
165 Route::set_order_key (const char* name, long n)
167 order_keys[strdup(name)] = n;
169 if (Config->get_sync_all_route_ordering()) {
170 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
175 _session.set_dirty ();
179 Route::sync_order_keys (const char* base)
181 if (order_keys.empty()) {
185 OrderKeys::iterator i;
188 if ((i = order_keys.find (base)) == order_keys.end()) {
189 /* key doesn't exist, use the first existing
190 key (this is done during session initialization)
192 i = order_keys.begin();
196 /* key exists - use it and reset all others
197 (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)
215 newname = bump_name_once (newname);
223 Route::inc_gain (gain_t fraction, void *src)
225 IO::inc_gain (fraction, src);
229 Route::set_gain (gain_t val, void *src)
231 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
233 if (_mix_group->is_relative()) {
235 gain_t usable_gain = gain();
236 if (usable_gain < 0.000001f) {
237 usable_gain = 0.000001f;
241 if (delta < 0.000001f) {
245 delta -= usable_gain;
250 gain_t factor = delta / usable_gain;
253 factor = _mix_group->get_max_factor(factor);
254 if (factor == 0.0f) {
255 _gain_control->Changed(); /* EMIT SIGNAL */
259 factor = _mix_group->get_min_factor(factor);
260 if (factor == 0.0f) {
261 _gain_control->Changed(); /* EMIT SIGNAL */
266 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
270 _mix_group->apply (&Route::set_gain, val, _mix_group);
280 IO::set_gain (val, src);
283 /** Process this route for one (sub) cycle (process thread)
285 * @param bufs Scratch buffers to use for the signal path
286 * @param start_frame Initial transport frame
287 * @param end_frame Final transport frame
288 * @param nframes Number of frames to output (to ports)
289 * @param offset Output offset (of port buffers, for split cycles)
291 * Note that (end_frame - start_frame) may not be equal to nframes when the
292 * transport speed isn't 1.0 (eg varispeed).
295 Route::process_output_buffers (BufferSet& bufs,
296 nframes_t start_frame, nframes_t end_frame,
297 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
300 // This is definitely very audio-only for now
301 assert(_default_type == DataType::AUDIO);
303 ProcessorList::iterator i;
304 bool post_fader_work = false;
305 bool mute_declick_applied = false;
311 gain_t* gab = _session.gain_automation_buffer();
313 switch (Config->get_monitoring_model()) {
314 case HardwareMonitoring:
315 case ExternalMonitoring:
322 declick = _pending_declick;
325 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
335 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
338 dmg = desired_mute_gain;
339 dsg = desired_solo_gain;
348 /* ----------------------------------------------------------------------------------------------------
349 GLOBAL DECLICK (for transport changes etc.)
350 -------------------------------------------------------------------------------------------------- */
353 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
354 _pending_declick = 0;
355 } else if (declick < 0) {
356 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
357 _pending_declick = 0;
360 /* no global declick */
362 if (solo_gain != dsg) {
363 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
369 /* ----------------------------------------------------------------------------------------------------
370 INPUT METERING & MONITORING
371 -------------------------------------------------------------------------------------------------- */
373 if (meter && (_meter_point == MeterInput)) {
374 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
377 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
378 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
380 mute_declick_applied = true;
383 if ((_meter_point == MeterInput) && co) {
385 solo_audible = dsg > 0;
386 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
388 if ( // muted by solo of another track
392 // muted by mute of this track
396 // rec-enabled but not s/w monitoring
398 // TODO: this is probably wrong
400 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
404 co->silence (nframes, offset);
408 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
413 /* -----------------------------------------------------------------------------------------------------
415 -------------------------------------------------------------------------------------------------- */
417 if (_denormal_protection || Config->get_denormal_protection()) {
419 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
420 Sample* const sp = i->data();
422 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
428 /* ----------------------------------------------------------------------------------------------------
430 -------------------------------------------------------------------------------------------------- */
432 if (with_processors) {
433 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
435 if (mute_gain > 0 || !_mute_affects_pre_fader) {
436 for (i = _processors.begin(); i != _processors.end(); ++i) {
437 switch ((*i)->placement()) {
439 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
442 post_fader_work = true;
447 for (i = _processors.begin(); i != _processors.end(); ++i) {
448 switch ((*i)->placement()) {
450 (*i)->silence (nframes, offset);
453 post_fader_work = true;
461 /* When we entered this method, the number of bufs was set by n_process_buffers(), so
462 * it may be larger than required. Consider, for example, a mono track with two redirects A and B.
463 * If A has one input and three outputs, and B three inputs and one output, n_process_buffers()
464 * will be 3. In this case, now we've done pre-fader redirects, we can reset the number of bufs.
466 bufs.set_count (pre_fader_streams());
468 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
469 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
471 mute_declick_applied = true;
474 /* ----------------------------------------------------------------------------------------------------
475 PRE-FADER METERING & MONITORING
476 -------------------------------------------------------------------------------------------------- */
478 if (meter && (_meter_point == MeterPreFader)) {
479 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
483 if ((_meter_point == MeterPreFader) && co) {
485 solo_audible = dsg > 0;
486 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
488 if ( // muted by solo of another track
492 // muted by mute of this track
496 // rec-enabled but not s/w monitoring
498 (no_monitor && record_enabled() && (!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, so don't test both */
599 if (post_fader_work) {
601 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
603 if (mute_gain > 0 || !_mute_affects_post_fader) {
604 for (i = _processors.begin(); i != _processors.end(); ++i) {
605 switch ((*i)->placement()) {
609 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
614 for (i = _processors.begin(); i != _processors.end(); ++i) {
615 switch ((*i)->placement()) {
619 (*i)->silence (nframes, offset);
627 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
628 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
630 mute_declick_applied = true;
633 /* ----------------------------------------------------------------------------------------------------
635 -------------------------------------------------------------------------------------------------- */
637 if ((_meter_point == MeterPostFader) && co) {
639 solo_audible = solo_gain > 0;
640 mute_audible = dmg > 0 || !_mute_affects_control_outs;
642 if ( // silent anyway
644 (_gain == 0 && !apply_gain_automation) ||
646 // muted by solo of another track
650 // muted by mute of this track
654 // recording but not s/w monitoring
656 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
660 co->silence (nframes, offset);
664 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
668 /* ----------------------------------------------------------------------
670 ----------------------------------------------------------------------*/
672 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
673 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
675 mute_declick_applied = true;
678 /* ----------------------------------------------------------------------------------------------------
680 -------------------------------------------------------------------------------------------------- */
682 solo_audible = dsg > 0;
683 mute_audible = dmg > 0 || !_mute_affects_main_outs;
685 if (n_outputs().get(_default_type) == 0) {
689 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
691 IO::silence (nframes, offset);
695 if ( // silent anyway
697 (_gain == 0 && !apply_gain_automation) ||
699 // muted by solo of another track, but not using control outs for solo
701 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
703 // muted by mute of this track
709 /* don't use Route::silence() here, because that causes
710 all outputs (sends, port processors, etc. to be silent).
713 if (_meter_point == MeterPostFader) {
714 peak_meter().reset();
717 IO::silence (nframes, offset);
721 deliver_output(bufs, start_frame, end_frame, nframes, offset);
727 /* ----------------------------------------------------------------------------------------------------
729 -------------------------------------------------------------------------------------------------- */
731 if (meter && (_meter_point == MeterPostFader)) {
732 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
735 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
741 /** Process this route for one (sub) cycle (process thread)
743 * @param bufs Scratch buffers to use for the signal path
744 * @param start_frame Initial transport frame
745 * @param end_frame Final transport frame
746 * @param nframes Number of frames to output (to ports)
747 * @param offset Output offset (of port buffers, for split cycles)
749 * Note that (end_frame - start_frame) may not be equal to nframes when the
750 * transport speed isn't 1.0 (eg varispeed).
753 Route::process_output_buffers (BufferSet& bufs,
754 nframes_t start_frame, nframes_t end_frame,
755 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
758 // This is definitely very audio-only for now
759 assert(_default_type == DataType::AUDIO);
761 ProcessorList::iterator i;
762 bool post_fader_work = false;
763 bool mute_declick_applied = false;
769 gain_t* gab = _session.gain_automation_buffer();
771 switch (Config->get_monitoring_model()) {
772 case HardwareMonitoring:
773 case ExternalMonitoring:
780 declick = _pending_declick;
783 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
793 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
796 dmg = desired_mute_gain;
797 dsg = desired_solo_gain;
806 /* ----------------------------------------------------------------------------------------------------
807 GLOBAL DECLICK (for transport changes etc.)
808 input metering & monitoring (control outs)
811 pre-fader metering & monitoring (control outs)
816 post-fader metering & monitoring (control outs)
820 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
821 for (i = processors.begin(); i != processors.end(); ++i) {
822 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
826 /* ----------------------------------------------------------------------------------------------------
827 INPUT METERING & MONITORING
828 -------------------------------------------------------------------------------------------------- */
830 if (meter && (_meter_point == MeterInput)) {
831 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
834 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
835 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
837 mute_declick_applied = true;
840 /* ----------------------------------------------------------------------------------------------------
842 -------------------------------------------------------------------------------------------------- */
844 // This really should already be true...
845 bufs.set_count(pre_fader_streams());
848 if ((_meter_point == MeterPreFader) && co) {
850 solo_audible = dsg > 0;
851 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
853 if ( // muted by solo of another track
857 // muted by mute of this track
861 // rec-enabled but not s/w monitoring
863 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
867 co->silence (nframes, offset);
871 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
875 /* ----------------------------------------------------------------------------------------------------
877 -------------------------------------------------------------------------------------------------- */
879 /* if not recording or recording and requiring any monitor signal, then apply gain */
881 if ( // not recording
883 !(record_enabled() && _session.actively_recording()) ||
887 // AND software monitoring required
889 Config->get_monitoring_model() == SoftwareMonitoring) {
891 if (apply_gain_automation) {
894 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
895 Sample* const sp = i->data();
897 for (nframes_t nx = 0; nx < nframes; ++nx) {
902 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
903 Sample* const sp = i->data();
905 for (nframes_t nx = 0; nx < nframes; ++nx) {
911 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
912 _effective_gain = gab[nframes-1];
917 /* manual (scalar) gain */
921 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
924 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
926 /* no need to interpolate current gain value,
927 but its non-unity, so apply it. if the gain
928 is zero, do nothing because we'll ship silence
940 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
941 Sample* const sp = i->data();
942 apply_gain_to_buffer(sp,nframes,this_gain);
945 } else if (_gain == 0) {
946 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
954 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
959 /* ----------------------------------------------------------------------------------------------------
961 -------------------------------------------------------------------------------------------------- */
963 if ((_meter_point == MeterPostFader) && co) {
965 solo_audible = solo_gain > 0;
966 mute_audible = dmg > 0 || !_mute_affects_control_outs;
968 if ( // silent anyway
970 (_gain == 0 && !apply_gain_automation) ||
972 // muted by solo of another track
976 // muted by mute of this track
980 // recording but not s/w monitoring
982 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
986 co->silence (nframes, offset);
990 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
994 /* ----------------------------------------------------------------------------------------------------
996 -------------------------------------------------------------------------------------------------- */
998 solo_audible = dsg > 0;
999 mute_audible = dmg > 0 || !_mute_affects_main_outs;
1001 if (n_outputs().get(_default_type) == 0) {
1005 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
1007 IO::silence (nframes, offset);
1011 if ( // silent anyway
1013 (_gain == 0 && !apply_gain_automation) ||
1015 // muted by solo of another track, but not using control outs for solo
1017 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
1019 // muted by mute of this track
1025 /* don't use Route::silence() here, because that causes
1026 all outputs (sends, port processors, etc. to be silent).
1029 if (_meter_point == MeterPostFader) {
1030 peak_meter().reset();
1033 IO::silence (nframes, offset);
1037 deliver_output(bufs, start_frame, end_frame, nframes, offset);
1044 #endif /* NEW_POB */
1047 Route::n_process_buffers ()
1049 return max (n_inputs(), processor_max_outs);
1053 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
1055 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
1059 collect_input (bufs, nframes, offset);
1062 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
1063 meter_first = false;
1068 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
1072 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
1074 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
1078 Route::set_solo (bool yn, void *src)
1084 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1085 _mix_group->apply (&Route::set_solo, yn, _mix_group);
1089 if (_soloed != yn) {
1091 solo_changed (src); /* EMIT SIGNAL */
1092 _solo_control->Changed (); /* EMIT SIGNAL */
1095 catch_up_on_solo_mute_override ();
1099 Route::catch_up_on_solo_mute_override ()
1101 if (Config->get_solo_model() != InverseMute) {
1107 Glib::Mutex::Lock lm (declick_lock);
1110 if (Config->get_solo_mute_override()) {
1111 desired_mute_gain = (_soloed?1.0:0.0);
1113 desired_mute_gain = 0.0;
1116 desired_mute_gain = 1.0;
1122 Route::set_solo_mute (bool yn)
1124 Glib::Mutex::Lock lm (declick_lock);
1126 /* Called by Session in response to another Route being soloed.
1129 desired_solo_gain = (yn?0.0:1.0);
1133 Route::set_solo_safe (bool yn, void *src)
1135 if (_solo_safe != yn) {
1137 solo_safe_changed (src); /* EMIT SIGNAL */
1142 Route::set_mute (bool yn, void *src)
1145 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1146 _mix_group->apply (&Route::set_mute, yn, _mix_group);
1152 mute_changed (src); /* EMIT SIGNAL */
1154 _mute_control->Changed (); /* EMIT SIGNAL */
1156 Glib::Mutex::Lock lm (declick_lock);
1158 if (_soloed && Config->get_solo_mute_override()){
1159 desired_mute_gain = 1.0f;
1161 desired_mute_gain = (yn?0.0f:1.0f);
1167 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1169 ChanCount old_pmo = processor_max_outs;
1171 if (!_session.engine().connected()) {
1176 Glib::RWLock::WriterLock lm (_processor_lock);
1178 boost::shared_ptr<PluginInsert> pi;
1179 boost::shared_ptr<PortInsert> porti;
1181 //processor->set_default_type(_default_type);
1183 _processors.push_back (processor);
1185 // Set up processor list channels. This will set processor->[input|output]_streams(),
1186 // configure redirect ports properly, etc.
1187 if (_reset_processor_counts (err)) {
1188 _processors.pop_back ();
1189 _reset_processor_counts (0); // it worked before we tried to add it ...
1193 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1195 if (pi->natural_input_streams() == ChanCount::ZERO) {
1196 /* generator plugin */
1197 _have_internal_generator = true;
1202 // Ensure peak vector sizes before the plugin is activated
1204 ChanCount potential_max_streams;
1206 potential_max_streams.set (DataType::AUDIO, max (processor->input_streams().n_audio(),
1207 processor->output_streams().n_audio()));
1208 potential_max_streams.set (DataType::MIDI, max (processor->input_streams().n_midi(),
1209 processor->output_streams().n_midi()));
1211 _meter->configure_io (potential_max_streams, potential_max_streams);
1213 // XXX: do we want to emit the signal here ? change call order.
1214 processor->activate ();
1215 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1220 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1224 processors_changed (); /* EMIT SIGNAL */
1230 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
1232 ChanCount old_pmo = processor_max_outs;
1234 if (!_session.engine().connected()) {
1239 Glib::RWLock::WriterLock lm (_processor_lock);
1241 ProcessorList::iterator existing_end = _processors.end();
1244 ChanCount potential_max_streams;
1246 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1248 boost::shared_ptr<PluginInsert> pi;
1250 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1253 ChanCount m = max(pi->input_streams(), pi->output_streams());
1254 if (m > potential_max_streams)
1255 potential_max_streams = m;
1258 // Ensure peak vector sizes before the plugin is activated
1259 _meter->configure_io (potential_max_streams, potential_max_streams);
1261 _processors.push_back (*i);
1263 if (_reset_processor_counts (err)) {
1265 _processors.erase (existing_end, _processors.end());
1266 _reset_processor_counts (0); // it worked before we tried to add it ...
1270 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1276 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1280 processors_changed (); /* EMIT SIGNAL */
1284 /** Turn off all processors with a given placement
1285 * @param p Placement of processors to disable
1289 Route::disable_processors (Placement p)
1291 Glib::RWLock::ReaderLock lm (_processor_lock);
1293 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1294 if ((*i)->placement() == p) {
1295 (*i)->set_active (false);
1299 _session.set_dirty ();
1302 /** Turn off all redirects
1306 Route::disable_processors ()
1308 Glib::RWLock::ReaderLock lm (_processor_lock);
1310 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1311 (*i)->set_active (false);
1314 _session.set_dirty ();
1317 /** Turn off all redirects with a given placement
1318 * @param p Placement of redirects to disable
1322 Route::disable_plugins (Placement p)
1324 Glib::RWLock::ReaderLock lm (_processor_lock);
1326 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1327 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
1328 (*i)->set_active (false);
1332 _session.set_dirty ();
1335 /** Turn off all plugins
1339 Route::disable_plugins ()
1341 Glib::RWLock::ReaderLock lm (_processor_lock);
1343 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1344 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1345 (*i)->set_active (false);
1349 _session.set_dirty ();
1354 Route::ab_plugins (bool forward)
1356 Glib::RWLock::ReaderLock lm (_processor_lock);
1360 /* forward = turn off all active redirects, and mark them so that the next time
1361 we go the other way, we will revert them
1364 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1365 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1369 if ((*i)->active()) {
1370 (*i)->set_active (false);
1371 (*i)->set_next_ab_is_active (true);
1373 (*i)->set_next_ab_is_active (false);
1379 /* backward = if the redirect was marked to go active on the next ab, do so */
1381 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1383 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1387 if ((*i)->get_next_ab_is_active()) {
1388 (*i)->set_active (true);
1390 (*i)->set_active (false);
1395 _session.set_dirty ();
1399 /* Figure out the streams that will feed into PreFader */
1401 Route::pre_fader_streams() const
1403 boost::shared_ptr<Processor> processor;
1405 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
1407 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1408 if ((*i)->placement() == PreFader && boost::dynamic_pointer_cast<Send> (*i) == 0) {
1414 return processor->output_streams();
1421 /** Remove processors with a given placement.
1422 * @param p Placement of processors to remove.
1425 Route::clear_processors (Placement p)
1427 const ChanCount old_pmo = processor_max_outs;
1429 if (!_session.engine().connected()) {
1434 Glib::RWLock::WriterLock lm (_processor_lock);
1435 ProcessorList new_list;
1437 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1438 if ((*i)->placement() == p) {
1439 /* it's the placement we want to get rid of */
1440 (*i)->drop_references ();
1442 /* it's a different placement, so keep it */
1443 new_list.push_back (*i);
1447 _processors = new_list;
1450 /* FIXME: can't see how this test can ever fire */
1451 if (processor_max_outs != old_pmo) {
1455 processor_max_outs.reset();
1456 _have_internal_generator = false;
1457 processors_changed (); /* EMIT SIGNAL */
1461 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1463 ChanCount old_pmo = processor_max_outs;
1465 if (!_session.engine().connected()) {
1469 processor_max_outs.reset();
1472 Glib::RWLock::WriterLock lm (_processor_lock);
1473 ProcessorList::iterator i;
1474 bool removed = false;
1476 for (i = _processors.begin(); i != _processors.end(); ++i) {
1477 if (*i == processor) {
1479 ProcessorList::iterator tmp;
1481 /* move along, see failure case for reset_processor_counts()
1482 where we may need to reprocessor the processor.
1488 /* stop redirects that send signals to JACK ports
1489 from causing noise as a result of no longer being
1493 boost::shared_ptr<IOProcessor> redirect;
1495 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1496 redirect->io()->disconnect_inputs (this);
1497 redirect->io()->disconnect_outputs (this);
1500 _processors.erase (i);
1515 if (_reset_processor_counts (err)) {
1516 /* get back to where we where */
1517 _processors.insert (i, processor);
1518 /* we know this will work, because it worked before :) */
1519 _reset_processor_counts (0);
1523 _have_internal_generator = false;
1525 for (i = _processors.begin(); i != _processors.end(); ++i) {
1526 boost::shared_ptr<PluginInsert> pi;
1528 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1529 if (pi->is_generator()) {
1530 _have_internal_generator = true;
1537 if (old_pmo != processor_max_outs) {
1541 processor->drop_references ();
1543 processors_changed (); /* EMIT SIGNAL */
1548 Route::reset_processor_counts (ProcessorStreams* err)
1550 Glib::RWLock::WriterLock lm (_processor_lock);
1551 return _reset_processor_counts (err);
1556 Route::_reset_processor_counts (ProcessorStreams* err)
1558 ProcessorList::iterator r;
1559 uint32_t insert_cnt = 0;
1560 uint32_t send_cnt = 0;
1561 map<Placement,list<ProcessorCount> > proc_map;
1562 ProcessorList::iterator prev;
1563 ChanCount initial_streams = n_inputs ();
1564 ChanCount previous_initial_streams = n_inputs ();
1566 uint32_t max_audio = 0;
1567 uint32_t max_midi = 0;
1569 processor_max_outs.reset ();
1571 /* Step 1: build a map that links each insert to an in/out channel count
1573 Divide inserts up by placement so we get the signal flow
1574 properly modelled. we need to do this because the _processors
1575 list is not sorted by placement, and because other reasons may
1576 exist now or in the future for this separate treatment.
1579 /* ... but it should/will be... */
1581 for (r = _processors.begin(); r != _processors.end(); ++r) {
1583 boost::shared_ptr<PluginInsert> plugin_insert;
1584 boost::shared_ptr<PortInsert> port_insert;
1586 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1589 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1591 /* reset plugin counts back to one for now so
1592 that we have a predictable, controlled
1593 state to try to configure.
1596 plugin_insert->set_count (1);
1598 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1601 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1603 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1608 if (insert_cnt == 0) {
1617 /* Now process each placement in order, checking to see if we
1618 can really do what has been requested.
1623 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1627 if (!proc_map[PreFader].empty()) {
1628 previous_initial_streams = n_inputs ();
1629 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1630 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1633 previous_initial_streams = initial_streams;
1639 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1643 if (!proc_map[PostFader].empty()) {
1644 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1645 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1648 previous_initial_streams = initial_streams;
1652 /* OK, everything can be set up correctly, so lets do it */
1654 apply_some_processor_counts (proc_map[PreFader]);
1655 apply_some_processor_counts (proc_map[PostFader]);
1657 /* recompute max outs of any processor */
1663 processor_max_outs.reset ();
1664 prev = _processors.end();
1666 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1667 boost::shared_ptr<Send> s;
1669 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1670 if (r == _processors.begin()) {
1671 s->expect_inputs (n_inputs());
1673 s->expect_inputs ((*prev)->output_streams());
1678 /* don't pay any attention to send output configuration, since it doesn't
1682 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1683 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1687 processor_max_outs.set (DataType::AUDIO, max_audio);
1688 processor_max_outs.set (DataType::MIDI, max_midi);
1694 for (r = _processors.begin(); r != _processors.end(); ++r) {
1695 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1696 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1699 processor_max_outs.set (DataType::AUDIO, max_audio);
1700 processor_max_outs.set (DataType::MIDI, max_midi);
1706 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1708 list<ProcessorCount>::iterator i;
1710 for (i = iclist.begin(); i != iclist.end(); ++i) {
1712 ProcessorCount& pc (*i);
1714 cerr << "now applying for " << (*i).processor->name() << " in = " << pc.in.n_audio() << " out = " << pc.out.n_audio() << endl;
1716 if (pc.processor->configure_io (pc.in, pc.out)) {
1720 /* make sure that however many we have, they are all active */
1722 pc.processor->activate ();
1728 /** Returns whether \a iclist can be configured and run starting with
1729 * \a required_inputs at the first processor's inputs.
1730 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1731 * Otherwise, \a err is set to the output of the list.
1734 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1736 list<ProcessorCount>::iterator i;
1741 err->count = required_inputs;
1744 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1746 cerr << "Checking whether " << (*i).processor->name() << " can support " << required_inputs.n_audio() << " inputs\n";
1748 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1751 err->count = required_inputs;
1756 (*i).in = required_inputs;
1757 required_inputs = (*i).out;
1764 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1766 ChanCount old_pmo = processor_max_outs;
1768 ProcessorList to_be_deleted;
1771 Glib::RWLock::WriterLock lm (_processor_lock);
1772 ProcessorList::iterator tmp;
1773 ProcessorList the_copy;
1775 the_copy = _processors;
1777 /* remove all relevant processors */
1779 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1783 if ((*i)->placement() == placement) {
1784 to_be_deleted.push_back (*i);
1785 _processors.erase (i);
1791 /* now copy the relevant ones from "other" */
1793 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1794 if ((*i)->placement() == placement) {
1795 _processors.push_back (IOProcessor::clone (*i));
1799 /* reset plugin stream handling */
1801 if (_reset_processor_counts (err)) {
1803 /* FAILED COPY ATTEMPT: we have to restore order */
1805 /* delete all cloned processors */
1807 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1812 if ((*i)->placement() == placement) {
1813 _processors.erase (i);
1819 /* restore the natural order */
1821 _processors = the_copy;
1822 processor_max_outs = old_pmo;
1824 /* we failed, even though things are OK again */
1830 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1831 to_be_deleted.clear ();
1836 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1840 processors_changed (); /* EMIT SIGNAL */
1845 Route::all_processors_flip ()
1847 Glib::RWLock::ReaderLock lm (_processor_lock);
1849 if (_processors.empty()) {
1853 bool first_is_on = _processors.front()->active();
1855 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1856 (*i)->set_active (!first_is_on);
1859 _session.set_dirty ();
1862 /** Set all processors with a given placement to a given active state.
1863 * @param p Placement of processors to change.
1864 * @param state New active state for those processors.
1867 Route::all_processors_active (Placement p, bool state)
1869 Glib::RWLock::ReaderLock lm (_processor_lock);
1871 if (_processors.empty()) {
1875 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1876 if ((*i)->placement() == p) {
1877 (*i)->set_active (state);
1881 _session.set_dirty ();
1884 struct ProcessorSorter {
1885 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1886 return a->sort_key() < b->sort_key();
1891 Route::sort_processors (ProcessorStreams* err)
1894 ProcessorSorter comparator;
1895 Glib::RWLock::WriterLock lm (_processor_lock);
1896 ChanCount old_pmo = processor_max_outs;
1898 /* the sweet power of C++ ... */
1900 ProcessorList as_it_was_before = _processors;
1902 _processors.sort (comparator);
1904 if (_reset_processor_counts (err)) {
1905 _processors = as_it_was_before;
1906 processor_max_outs = old_pmo;
1912 processors_changed (); /* EMIT SIGNAL */
1924 Route::get_template()
1926 return state(false);
1930 Route::state(bool full_state)
1932 XMLNode *node = new XMLNode("Route");
1933 ProcessorList::iterator i;
1937 node->add_property("flags", enum_2_string (_flags));
1940 node->add_property("default-type", _default_type.to_string());
1942 node->add_property("active", _active?"yes":"no");
1943 node->add_property("muted", _muted?"yes":"no");
1944 node->add_property("soloed", _soloed?"yes":"no");
1945 node->add_property("phase-invert", _phase_invert?"yes":"no");
1946 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1947 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1948 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1949 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1950 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1951 node->add_property("meter-point", enum_2_string (_meter_point));
1954 node->add_property("edit-group", _edit_group->name());
1957 node->add_property("mix-group", _mix_group->name());
1960 string order_string;
1961 OrderKeys::iterator x = order_keys.begin();
1963 while (x != order_keys.end()) {
1964 order_string += string ((*x).first);
1965 order_string += '=';
1966 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1967 order_string += buf;
1971 if (x == order_keys.end()) {
1975 order_string += ':';
1977 node->add_property ("order-keys", order_string);
1979 node->add_child_nocopy (IO::state (full_state));
1980 node->add_child_nocopy (_solo_control->get_state ());
1981 node->add_child_nocopy (_mute_control->get_state ());
1983 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1984 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1985 remote_control_node->add_property (X_("id"), buf);
1986 node->add_child_nocopy (*remote_control_node);
1988 if (_control_outs) {
1989 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1990 cnode->add_child_nocopy (_control_outs->state (full_state));
1991 node->add_child_nocopy (*cnode);
1994 if (_comment.length()) {
1995 XMLNode *cmt = node->add_child ("Comment");
1996 cmt->add_content (_comment);
1999 for (i = _processors.begin(); i != _processors.end(); ++i) {
2000 node->add_child_nocopy((*i)->state (full_state));
2004 node->add_child_copy (*_extra_xml);
2011 Route::get_processor_state ()
2013 XMLNode* root = new XMLNode (X_("redirects"));
2014 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2015 root->add_child_nocopy ((*i)->state (true));
2022 Route::set_processor_state (const XMLNode& root)
2024 if (root.name() != X_("redirects")) {
2030 XMLNodeConstIterator iter;
2031 XMLNodeConstIterator niter;
2032 Glib::RWLock::ReaderLock lm (_processor_lock);
2034 nlist = root.children();
2036 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
2038 /* iter now points to a IOProcessor state node */
2040 nnlist = (*iter)->children ();
2042 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
2044 /* find the IO child node, since it contains the ID we need */
2046 /* XXX OOP encapsulation violation, ugh */
2048 if ((*niter)->name() == IO::state_node_name) {
2050 XMLProperty* prop = (*niter)->property (X_("id"));
2053 warning << _("IOProcessor node has no ID, ignored") << endmsg;
2057 ID id = prop->value ();
2059 /* now look for a processor with that ID */
2061 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2062 if ((*i)->id() == id) {
2063 (*i)->set_state (**iter);
2079 Route::set_deferred_state ()
2082 XMLNodeConstIterator niter;
2084 if (!deferred_state) {
2088 nlist = deferred_state->children();
2090 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2091 add_processor_from_xml (**niter);
2094 delete deferred_state;
2099 Route::add_processor_from_xml (const XMLNode& node)
2101 const XMLProperty *prop;
2103 // legacy sessions use a different node name for sends
2104 if (node.name() == "Send") {
2107 boost::shared_ptr<Send> send (new Send (_session, node));
2108 add_processor (send);
2111 catch (failed_constructor &err) {
2112 error << _("Send construction failed") << endmsg;
2116 // use "Processor" in XML?
2117 } else if (node.name() == "Processor") {
2120 if ((prop = node.property ("type")) != 0) {
2122 boost::shared_ptr<Processor> processor;
2123 bool have_insert = false;
2125 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2126 prop->value() == "lv2" ||
2127 prop->value() == "vst" ||
2128 prop->value() == "audiounit") {
2130 processor.reset (new PluginInsert(_session, node));
2133 } else if (prop->value() == "port") {
2135 processor.reset (new PortInsert (_session, node));
2137 } else if (prop->value() == "send") {
2139 processor.reset (new Send (_session, node));
2144 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2147 add_processor (processor);
2150 error << _("Processor XML node has no type property") << endmsg;
2154 catch (failed_constructor &err) {
2155 warning << _("processor could not be created. Ignored.") << endmsg;
2162 Route::set_state (const XMLNode& node)
2164 return _set_state (node, true);
2168 Route::_set_state (const XMLNode& node, bool call_base)
2171 XMLNodeConstIterator niter;
2173 XMLPropertyList plist;
2174 const XMLProperty *prop;
2176 if (node.name() != "Route"){
2177 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2181 if ((prop = node.property (X_("flags"))) != 0) {
2182 _flags = Flag (string_2_enum (prop->value(), _flags));
2187 if ((prop = node.property (X_("default-type"))) != 0) {
2188 _default_type = DataType(prop->value());
2189 assert(_default_type != DataType::NIL);
2192 if ((prop = node.property (X_("phase-invert"))) != 0) {
2193 set_phase_invert (prop->value()=="yes"?true:false, this);
2196 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2197 set_denormal_protection (prop->value()=="yes"?true:false, this);
2201 if ((prop = node.property (X_("active"))) != 0) {
2202 set_active (prop->value() == "yes");
2205 if ((prop = node.property (X_("muted"))) != 0) {
2206 bool yn = prop->value()=="yes"?true:false;
2208 /* force reset of mute status */
2212 mute_gain = desired_mute_gain;
2215 if ((prop = node.property (X_("soloed"))) != 0) {
2216 bool yn = prop->value()=="yes"?true:false;
2218 /* force reset of solo status */
2221 set_solo (yn, this);
2222 solo_gain = desired_solo_gain;
2225 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2226 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2229 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2230 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2233 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2234 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2237 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2238 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2241 if ((prop = node.property (X_("meter-point"))) != 0) {
2242 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2245 if ((prop = node.property (X_("edit-group"))) != 0) {
2246 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2247 if(edit_group == 0) {
2248 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2250 set_edit_group(edit_group, this);
2254 if ((prop = node.property (X_("order-keys"))) != 0) {
2258 string::size_type colon, equal;
2259 string remaining = prop->value();
2261 while (remaining.length()) {
2263 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2264 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2267 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2268 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2271 set_order_key (remaining.substr (0, equal).c_str(), n);
2275 colon = remaining.find_first_of (':');
2277 if (colon != string::npos) {
2278 remaining = remaining.substr (colon+1);
2285 nlist = node.children();
2287 delete deferred_state;
2288 deferred_state = new XMLNode(X_("deferred state"));
2290 /* set parent class properties before anything else */
2292 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2296 if (child->name() == IO::state_node_name && call_base) {
2298 IO::set_state (*child);
2303 XMLNodeList processor_nodes;
2305 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2309 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
2310 processor_nodes.push_back(child);
2315 _set_processor_states(processor_nodes);
2318 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2320 // All processors have been applied already
2322 if (child->name() == X_("Automation")) {
2324 if ((prop = child->property (X_("path"))) != 0) {
2325 load_automation (prop->value());
2328 } else if (child->name() == X_("ControlOuts")) {
2330 string coutname = _name;
2331 coutname += _("[control]");
2333 delete _control_outs;
2334 _control_outs = new IO (_session, coutname);
2335 _control_outs->set_state (**(child->children().begin()));
2337 } else if (child->name() == X_("Comment")) {
2339 /* XXX this is a terrible API design in libxml++ */
2341 XMLNode *cmt = *(child->children().begin());
2342 _comment = cmt->content();
2344 } else if (child->name() == X_("extra")) {
2346 _extra_xml = new XMLNode (*child);
2348 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
2350 if (prop->value() == "solo") {
2351 _solo_control->set_state (*child);
2352 _session.add_controllable (_solo_control);
2354 else if (prop->value() == "mute") {
2355 _mute_control->set_state (*child);
2356 _session.add_controllable (_mute_control);
2359 else if (child->name() == X_("remote_control")) {
2360 if ((prop = child->property (X_("id"))) != 0) {
2362 sscanf (prop->value().c_str(), "%d", &x);
2363 set_remote_control_id (x);
2368 if ((prop = node.property (X_("mix-group"))) != 0) {
2369 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2370 if (mix_group == 0) {
2371 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2373 set_mix_group(mix_group, this);
2381 Route::_set_processor_states(const XMLNodeList &nlist)
2383 XMLNodeConstIterator niter;
2386 ProcessorList::iterator i, o;
2388 // Iterate through existing processors, remove those which are not in the state list
2389 for (i = _processors.begin(); i != _processors.end(); ) {
2390 ProcessorList::iterator tmp = i;
2393 bool processorInStateList = false;
2395 (*i)->id().print (buf, sizeof (buf));
2398 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2400 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2401 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2402 processorInStateList = true;
2404 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2405 processorInStateList = true;
2410 if (!processorInStateList) {
2411 remove_processor (*i);
2419 // Iterate through state list and make sure all processors are on the track and in the correct order,
2420 // set the state of existing processors according to the new state on the same go
2421 i = _processors.begin();
2422 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2424 // Check whether the next processor in the list
2427 while (o != _processors.end()) {
2428 (*o)->id().print (buf, sizeof (buf));
2429 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2431 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2437 if (o == _processors.end()) {
2438 // If the processor (*niter) is not on the route, we need to create it
2439 // and move it to the correct location
2441 ProcessorList::iterator prev_last = _processors.end();
2442 --prev_last; // We need this to check whether adding succeeded
2444 add_processor_from_xml (**niter);
2446 ProcessorList::iterator last = _processors.end();
2449 if (prev_last == last) {
2450 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2455 boost::shared_ptr<Processor> tmp = (*last);
2456 // remove the processor from the wrong location
2457 _processors.erase(last);
2458 // processor the new processor at the current location
2459 _processors.insert(i, tmp);
2461 --i; // move pointer to the newly processored processor
2465 // We found the processor (*niter) on the route, first we must make sure the processor
2466 // is at the location provided in the XML state
2468 boost::shared_ptr<Processor> tmp = (*o);
2469 // remove the old copy
2470 _processors.erase(o);
2471 // processor the processor at the correct location
2472 _processors.insert(i, tmp);
2474 --i; // move pointer so it points to the right processor
2477 (*i)->set_state( (**niter) );
2480 processors_changed ();
2484 Route::curve_reallocate ()
2486 // _gain_automation_curve.finish_resize ();
2487 // _pan_automation_curve.finish_resize ();
2491 Route::silence (nframes_t nframes, nframes_t offset)
2495 IO::silence (nframes, offset);
2497 if (_control_outs) {
2498 _control_outs->silence (nframes, offset);
2502 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2505 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2506 boost::shared_ptr<PluginInsert> pi;
2507 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2508 // skip plugins, they don't need anything when we're not active
2512 (*i)->silence (nframes, offset);
2515 if (nframes == _session.get_block_size() && offset == 0) {
2525 Route::set_control_outs (const vector<string>& ports)
2527 Glib::Mutex::Lock lm (_control_outs_lock);
2528 vector<string>::const_iterator i;
2531 delete _control_outs;
2534 if (is_control() || is_master()) {
2535 /* no control outs for these two special busses */
2539 if (ports.empty()) {
2543 string coutname = _name;
2544 coutname += _("[control]");
2546 _control_outs = new IO (_session, coutname);
2548 /* our control outs need as many outputs as we
2549 have audio outputs. we track the changes in ::output_change_handler().
2552 // XXX its stupid that we have to get this value twice
2554 limit = n_outputs().n_audio();
2556 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2560 /* now connect to the named ports */
2562 for (size_t n = 0; n < limit; ++n) {
2563 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2564 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2573 Route::set_edit_group (RouteGroup *eg, void *src)
2576 if (eg == _edit_group) {
2581 _edit_group->remove (this);
2584 if ((_edit_group = eg) != 0) {
2585 _edit_group->add (this);
2588 _session.set_dirty ();
2589 edit_group_changed (src); /* EMIT SIGNAL */
2593 Route::drop_edit_group (void *src)
2596 _session.set_dirty ();
2597 edit_group_changed (src); /* EMIT SIGNAL */
2601 Route::set_mix_group (RouteGroup *mg, void *src)
2604 if (mg == _mix_group) {
2609 _mix_group->remove (this);
2612 if ((_mix_group = mg) != 0) {
2613 _mix_group->add (this);
2616 _session.set_dirty ();
2617 mix_group_changed (src); /* EMIT SIGNAL */
2621 Route::drop_mix_group (void *src)
2624 _session.set_dirty ();
2625 mix_group_changed (src); /* EMIT SIGNAL */
2629 Route::set_comment (string cmt, void *src)
2632 comment_changed (src);
2633 _session.set_dirty ();
2637 Route::feeds (boost::shared_ptr<Route> other)
2642 uint32_t no = self.n_outputs().n_total();
2643 uint32_t ni = other->n_inputs ().n_total();
2645 for (i = 0; i < no; ++i) {
2646 for (j = 0; j < ni; ++j) {
2647 if (self.output(i)->connected_to (other->input(j)->name())) {
2653 /* check IOProcessors which may also interconnect Routes */
2655 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2657 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2662 // TODO: support internal redirects here
2664 no = redirect->io()->n_outputs().n_total();
2666 for (i = 0; i < no; ++i) {
2667 for (j = 0; j < ni; ++j) {
2668 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2675 /* check for control room outputs which may also interconnect Routes */
2677 if (_control_outs) {
2679 no = _control_outs->n_outputs().n_total();
2681 for (i = 0; i < no; ++i) {
2682 for (j = 0; j < ni; ++j) {
2683 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2694 Route::set_mute_config (mute_type t, bool onoff, void *src)
2698 _mute_affects_pre_fader = onoff;
2699 pre_fader_changed(src); /* EMIT SIGNAL */
2703 _mute_affects_post_fader = onoff;
2704 post_fader_changed(src); /* EMIT SIGNAL */
2708 _mute_affects_control_outs = onoff;
2709 control_outs_changed(src); /* EMIT SIGNAL */
2713 _mute_affects_main_outs = onoff;
2714 main_outs_changed(src); /* EMIT SIGNAL */
2720 Route::get_mute_config (mute_type t)
2726 onoff = _mute_affects_pre_fader;
2729 onoff = _mute_affects_post_fader;
2732 onoff = _mute_affects_control_outs;
2735 onoff = _mute_affects_main_outs;
2743 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2745 nframes_t now = _session.transport_frame();
2748 Glib::RWLock::ReaderLock lm (_processor_lock);
2751 automation_snapshot (now, true);
2754 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2756 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2757 (*i)->deactivate ();
2761 (*i)->transport_stopped (now);
2765 IO::transport_stopped (now);
2767 _roll_delay = _initial_delay;
2771 Route::input_change_handler (IOChange change, void *ignored)
2773 if (change & ConfigurationChanged) {
2774 reset_processor_counts (0);
2779 Route::output_change_handler (IOChange change, void *ignored)
2781 if (change & ConfigurationChanged) {
2782 if (_control_outs) {
2783 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2786 reset_processor_counts (0);
2791 Route::pans_required () const
2793 if (n_outputs().n_audio() < 2) {
2797 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2801 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2802 bool session_state_changing, bool can_record, bool rec_monitors_input)
2804 if (n_outputs().n_total() == 0) {
2808 if (session_state_changing || !_active) {
2809 silence (nframes, offset);
2813 apply_gain_automation = false;
2815 if (n_inputs().n_total()) {
2816 passthru (start_frame, end_frame, nframes, offset, 0, false);
2818 silence (nframes, offset);
2825 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2827 if (_roll_delay > nframes) {
2829 _roll_delay -= nframes;
2830 silence (nframes, offset);
2831 /* transport frame is not legal for caller to use */
2834 } else if (_roll_delay > 0) {
2836 nframes -= _roll_delay;
2838 silence (_roll_delay, offset);
2840 offset += _roll_delay;
2841 transport_frame += _roll_delay;
2850 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2851 bool can_record, bool rec_monitors_input)
2854 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2856 // automation snapshot can also be called from the non-rt context
2857 // and it uses the processor list, so we take the lock out here
2858 automation_snapshot (_session.transport_frame(), false);
2862 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2863 silence (nframes, offset);
2867 nframes_t unused = 0;
2869 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2875 apply_gain_automation = false;
2878 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2880 if (am.locked() && _session.transport_rolling()) {
2882 if (_gain_control->automation_playback()) {
2883 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2884 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2889 passthru (start_frame, end_frame, nframes, offset, declick, false);
2895 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2896 bool can_record, bool rec_monitors_input)
2898 silence (nframes, offset);
2903 Route::toggle_monitor_input ()
2905 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2906 i->ensure_monitor_input( ! i->monitoring_input());
2911 Route::has_external_redirects () const
2913 // FIXME: what about sends?
2915 boost::shared_ptr<const PortInsert> pi;
2917 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2918 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2920 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2921 port != pi->io()->outputs().end(); ++port) {
2923 string port_name = port->name();
2924 string client_name = port_name.substr (0, port_name.find(':'));
2926 /* only say "yes" if the redirect is actually in use */
2928 if (client_name != "ardour" && pi->active()) {
2939 Route::flush_processors ()
2941 /* XXX shouldn't really try to take this lock, since
2942 this is called from the RT audio thread.
2945 Glib::RWLock::ReaderLock lm (_processor_lock);
2947 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2948 (*i)->deactivate ();
2954 Route::set_meter_point (MeterPoint p, void *src)
2956 if (_meter_point != p) {
2958 meter_change (src); /* EMIT SIGNAL */
2959 _session.set_dirty ();
2964 Route::update_total_latency ()
2966 nframes_t old = _own_latency;
2968 if (_user_latency) {
2969 _own_latency = _user_latency;
2973 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2974 if ((*i)->active ()) {
2975 _own_latency += (*i)->signal_latency ();
2980 #undef DEBUG_LATENCY
2981 #ifdef DEBUG_LATENCY
2982 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2985 set_port_latency (_own_latency);
2987 if (!_user_latency) {
2988 /* this (virtual) function is used for pure Routes,
2989 not derived classes like AudioTrack. this means
2990 that the data processed here comes from an input
2991 port, not prerecorded material, and therefore we
2992 have to take into account any input latency.
2996 _own_latency += input_latency ();
2999 if (old != _own_latency) {
3000 signal_latency_changed (); /* EMIT SIGNAL */
3003 #ifdef DEBUG_LATENCY
3004 cerr << _name << ": input latency = " << input_latency() << " total = "
3005 << _own_latency << endl;
3008 return _own_latency;
3012 Route::set_user_latency (nframes_t nframes)
3014 Latent::set_user_latency (nframes);
3015 _session.update_latency_compensation (false, false);
3019 Route::set_latency_delay (nframes_t longest_session_latency)
3021 nframes_t old = _initial_delay;
3023 if (_own_latency < longest_session_latency) {
3024 _initial_delay = longest_session_latency - _own_latency;
3029 if (_initial_delay != old) {
3030 initial_delay_changed (); /* EMIT SIGNAL */
3033 if (_session.transport_stopped()) {
3034 _roll_delay = _initial_delay;
3039 Route::automation_snapshot (nframes_t now, bool force)
3041 if (!force && !should_snapshot(now)) {
3045 IO::automation_snapshot (now, force);
3047 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3048 (*i)->automation_snapshot (now, force);
3052 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
3053 : Controllable (name), route (s), type(tp)
3059 Route::ToggleControllable::set_value (float val)
3061 bool bval = ((val >= 0.5f) ? true: false);
3065 route.set_mute (bval, this);
3068 route.set_solo (bval, this);
3076 Route::ToggleControllable::get_value (void) const
3082 val = route.muted() ? 1.0f : 0.0f;
3085 val = route.soloed() ? 1.0f : 0.0f;
3095 Route::set_block_size (nframes_t nframes)
3097 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3098 (*i)->set_block_size (nframes);
3103 Route::protect_automation ()
3105 Automatable::protect_automation();
3107 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3108 (*i)->protect_automation();
3112 Route::set_pending_declick (int declick)
3115 /* this call is not allowed to turn off a pending declick unless "force" is true */
3117 _pending_declick = declick;
3119 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3121 _pending_declick = 0;
3126 /** Shift automation forwards from a particular place, thereby inserting time.
3127 * Adds undo commands for any shifts that are performed.
3129 * @param pos Position to start shifting from.
3130 * @param frames Amount to shift forwards by.
3134 Route::shift (nframes64_t pos, nframes64_t frames)
3136 #ifdef THIS_NEEDS_FIXING_FOR_V3
3138 /* gain automation */
3139 XMLNode &before = _gain_control->get_state ();
3140 _gain_control->shift (pos, frames);
3141 XMLNode &after = _gain_control->get_state ();
3142 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3144 /* pan automation */
3145 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3146 Curve & c = (*i)->automation ();
3147 XMLNode &before = c.get_state ();
3148 c.shift (pos, frames);
3149 XMLNode &after = c.get_state ();
3150 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3153 /* redirect automation */
3155 Glib::RWLock::ReaderLock lm (redirect_lock);
3156 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3159 (*i)->what_has_automation (a);
3161 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3162 AutomationList & al = (*i)->automation_list (*j);
3163 XMLNode &before = al.get_state ();
3164 al.shift (pos, frames);
3165 XMLNode &after = al.get_state ();
3166 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));