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 /* NOTE: this is intended to be used ONLY when copying
1233 processors from another Route. Hence the subtle
1234 differences between this and ::add_processor()
1237 ChanCount old_pmo = processor_max_outs;
1239 if (!_session.engine().connected()) {
1244 Glib::RWLock::WriterLock lm (_processor_lock);
1246 ProcessorList::iterator existing_end = _processors.end();
1249 ChanCount potential_max_streams;
1251 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1253 boost::shared_ptr<PluginInsert> pi;
1255 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1258 ChanCount m = max(pi->input_streams(), pi->output_streams());
1259 if (m > potential_max_streams)
1260 potential_max_streams = m;
1263 // Ensure peak vector sizes before the plugin is activated
1264 _meter->configure_io (potential_max_streams, potential_max_streams);
1266 _processors.push_back (*i);
1268 if (_reset_processor_counts (err)) {
1270 _processors.erase (existing_end, _processors.end());
1271 _reset_processor_counts (0); // it worked before we tried to add it ...
1275 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1281 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1285 processors_changed (); /* EMIT SIGNAL */
1289 /** Turn off all processors with a given placement
1290 * @param p Placement of processors to disable
1294 Route::disable_processors (Placement p)
1296 Glib::RWLock::ReaderLock lm (_processor_lock);
1298 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1299 if ((*i)->placement() == p) {
1300 (*i)->deactivate ();
1304 _session.set_dirty ();
1307 /** Turn off all redirects
1311 Route::disable_processors ()
1313 Glib::RWLock::ReaderLock lm (_processor_lock);
1315 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1316 (*i)->deactivate ();
1319 _session.set_dirty ();
1322 /** Turn off all redirects with a given placement
1323 * @param p Placement of redirects to disable
1327 Route::disable_plugins (Placement p)
1329 Glib::RWLock::ReaderLock lm (_processor_lock);
1331 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1332 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
1333 (*i)->deactivate ();
1337 _session.set_dirty ();
1340 /** Turn off all plugins
1344 Route::disable_plugins ()
1346 Glib::RWLock::ReaderLock lm (_processor_lock);
1348 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1349 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1350 (*i)->deactivate ();
1354 _session.set_dirty ();
1359 Route::ab_plugins (bool forward)
1361 Glib::RWLock::ReaderLock lm (_processor_lock);
1365 /* forward = turn off all active redirects, and mark them so that the next time
1366 we go the other way, we will revert them
1369 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1370 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1374 if ((*i)->active()) {
1375 (*i)->deactivate ();
1376 (*i)->set_next_ab_is_active (true);
1378 (*i)->set_next_ab_is_active (false);
1384 /* backward = if the redirect was marked to go active on the next ab, do so */
1386 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1388 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1392 if ((*i)->get_next_ab_is_active()) {
1395 (*i)->deactivate ();
1400 _session.set_dirty ();
1404 /* Figure out the streams that will feed into PreFader */
1406 Route::pre_fader_streams() const
1408 boost::shared_ptr<Processor> processor;
1410 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
1412 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1413 if ((*i)->placement() == PreFader && boost::dynamic_pointer_cast<Send> (*i) == 0) {
1419 return processor->output_streams();
1426 /** Remove processors with a given placement.
1427 * @param p Placement of processors to remove.
1430 Route::clear_processors (Placement p)
1432 const ChanCount old_pmo = processor_max_outs;
1434 if (!_session.engine().connected()) {
1439 Glib::RWLock::WriterLock lm (_processor_lock);
1440 ProcessorList new_list;
1442 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1443 if ((*i)->placement() == p) {
1444 /* it's the placement we want to get rid of */
1445 (*i)->drop_references ();
1447 /* it's a different placement, so keep it */
1448 new_list.push_back (*i);
1452 _processors = new_list;
1455 /* FIXME: can't see how this test can ever fire */
1456 if (processor_max_outs != old_pmo) {
1460 processor_max_outs.reset();
1461 _have_internal_generator = false;
1462 processors_changed (); /* EMIT SIGNAL */
1466 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1468 ChanCount old_pmo = processor_max_outs;
1470 if (!_session.engine().connected()) {
1474 processor_max_outs.reset();
1477 Glib::RWLock::WriterLock lm (_processor_lock);
1478 ProcessorList::iterator i;
1479 bool removed = false;
1481 for (i = _processors.begin(); i != _processors.end(); ++i) {
1482 if (*i == processor) {
1484 ProcessorList::iterator tmp;
1486 /* move along, see failure case for reset_processor_counts()
1487 where we may need to reprocessor the processor.
1493 /* stop redirects that send signals to JACK ports
1494 from causing noise as a result of no longer being
1498 boost::shared_ptr<IOProcessor> redirect;
1500 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1501 redirect->io()->disconnect_inputs (this);
1502 redirect->io()->disconnect_outputs (this);
1505 _processors.erase (i);
1520 if (_reset_processor_counts (err)) {
1521 /* get back to where we where */
1522 _processors.insert (i, processor);
1523 /* we know this will work, because it worked before :) */
1524 _reset_processor_counts (0);
1528 _have_internal_generator = false;
1530 for (i = _processors.begin(); i != _processors.end(); ++i) {
1531 boost::shared_ptr<PluginInsert> pi;
1533 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1534 if (pi->is_generator()) {
1535 _have_internal_generator = true;
1542 if (old_pmo != processor_max_outs) {
1546 processor->drop_references ();
1548 processors_changed (); /* EMIT SIGNAL */
1553 Route::reset_processor_counts (ProcessorStreams* err)
1555 Glib::RWLock::WriterLock lm (_processor_lock);
1556 return _reset_processor_counts (err);
1561 Route::_reset_processor_counts (ProcessorStreams* err)
1563 ProcessorList::iterator r;
1564 uint32_t insert_cnt = 0;
1565 uint32_t send_cnt = 0;
1566 map<Placement,list<ProcessorCount> > proc_map;
1567 ProcessorList::iterator prev;
1568 ChanCount initial_streams = n_inputs ();
1569 ChanCount previous_initial_streams = n_inputs ();
1571 uint32_t max_audio = 0;
1572 uint32_t max_midi = 0;
1574 processor_max_outs.reset ();
1576 /* Step 1: build a map that links each insert to an in/out channel count
1578 Divide inserts up by placement so we get the signal flow
1579 properly modelled. we need to do this because the _processors
1580 list is not sorted by placement, and because other reasons may
1581 exist now or in the future for this separate treatment.
1584 /* ... but it should/will be... */
1586 for (r = _processors.begin(); r != _processors.end(); ++r) {
1588 boost::shared_ptr<PluginInsert> plugin_insert;
1589 boost::shared_ptr<PortInsert> port_insert;
1591 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1594 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1596 /* reset plugin counts back to one for now so
1597 that we have a predictable, controlled
1598 state to try to configure.
1601 plugin_insert->set_count (1);
1603 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1606 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1608 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1613 if (insert_cnt == 0) {
1622 /* Now process each placement in order, checking to see if we
1623 can really do what has been requested.
1628 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1632 if (!proc_map[PreFader].empty()) {
1633 previous_initial_streams = n_inputs ();
1634 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1635 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) == false) {
1638 previous_initial_streams = initial_streams;
1644 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1648 if (!proc_map[PostFader].empty()) {
1649 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1650 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) == false) {
1653 previous_initial_streams = initial_streams;
1657 /* OK, everything can be set up correctly, so lets do it */
1659 apply_some_processor_counts (proc_map[PreFader]);
1660 apply_some_processor_counts (proc_map[PostFader]);
1662 /* recompute max outs of any processor */
1668 processor_max_outs.reset ();
1669 prev = _processors.end();
1671 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1672 boost::shared_ptr<Send> s;
1674 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1676 /* don't pay any attention to send output configuration, since it doesn't
1680 if (r == _processors.begin()) {
1681 s->expect_inputs (n_inputs());
1683 s->expect_inputs ((*prev)->output_streams());
1688 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1689 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1693 processor_max_outs.set (DataType::AUDIO, max_audio);
1694 processor_max_outs.set (DataType::MIDI, max_midi);
1700 for (r = _processors.begin(); r != _processors.end(); ++r) {
1701 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1702 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1705 processor_max_outs.set (DataType::AUDIO, max_audio);
1706 processor_max_outs.set (DataType::MIDI, max_midi);
1712 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1714 list<ProcessorCount>::iterator i;
1716 for (i = iclist.begin(); i != iclist.end(); ++i) {
1718 ProcessorCount& pc (*i);
1720 if (pc.processor->configure_io (pc.in, pc.out)) {
1724 /* make sure that however many we have, they are all active */
1726 pc.processor->activate ();
1732 /** Returns whether \a iclist can be configured and run starting with
1733 * \a required_inputs at the first processor's inputs.
1734 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1735 * Otherwise, \a err is set to the output of the list.
1738 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1740 list<ProcessorCount>::iterator i;
1745 err->count = required_inputs;
1748 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1750 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1753 err->count = required_inputs;
1758 (*i).in = required_inputs;
1759 required_inputs = (*i).out;
1766 Route::all_processors_flip ()
1768 Glib::RWLock::ReaderLock lm (_processor_lock);
1770 if (_processors.empty()) {
1774 bool first_is_on = _processors.front()->active();
1776 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1778 (*i)->deactivate ();
1784 _session.set_dirty ();
1787 /** Set all processors with a given placement to a given active state.
1788 * @param p Placement of processors to change.
1789 * @param state New active state for those processors.
1792 Route::all_processors_active (Placement p, bool state)
1794 Glib::RWLock::ReaderLock lm (_processor_lock);
1796 if (_processors.empty()) {
1800 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1801 if ((*i)->placement() == p) {
1805 (*i)->deactivate ();
1810 _session.set_dirty ();
1813 struct ProcessorSorter {
1814 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1815 return a->sort_key() < b->sort_key();
1820 Route::sort_processors (ProcessorStreams* err)
1823 ProcessorSorter comparator;
1824 Glib::RWLock::WriterLock lm (_processor_lock);
1825 ChanCount old_pmo = processor_max_outs;
1827 /* the sweet power of C++ ... */
1829 ProcessorList as_it_was_before = _processors;
1831 _processors.sort (comparator);
1833 if (_reset_processor_counts (err)) {
1834 _processors = as_it_was_before;
1835 processor_max_outs = old_pmo;
1841 processors_changed (); /* EMIT SIGNAL */
1853 Route::get_template()
1855 return state(false);
1859 Route::state(bool full_state)
1861 XMLNode *node = new XMLNode("Route");
1862 ProcessorList::iterator i;
1866 node->add_property("flags", enum_2_string (_flags));
1869 node->add_property("default-type", _default_type.to_string());
1871 node->add_property("active", _active?"yes":"no");
1872 node->add_property("muted", _muted?"yes":"no");
1873 node->add_property("soloed", _soloed?"yes":"no");
1874 node->add_property("phase-invert", _phase_invert?"yes":"no");
1875 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1876 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1877 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1878 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1879 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1880 node->add_property("meter-point", enum_2_string (_meter_point));
1883 node->add_property("edit-group", _edit_group->name());
1886 node->add_property("mix-group", _mix_group->name());
1889 string order_string;
1890 OrderKeys::iterator x = order_keys.begin();
1892 while (x != order_keys.end()) {
1893 order_string += string ((*x).first);
1894 order_string += '=';
1895 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1896 order_string += buf;
1900 if (x == order_keys.end()) {
1904 order_string += ':';
1906 node->add_property ("order-keys", order_string);
1908 node->add_child_nocopy (IO::state (full_state));
1909 node->add_child_nocopy (_solo_control->get_state ());
1910 node->add_child_nocopy (_mute_control->get_state ());
1912 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1913 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1914 remote_control_node->add_property (X_("id"), buf);
1915 node->add_child_nocopy (*remote_control_node);
1917 if (_control_outs) {
1918 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1919 cnode->add_child_nocopy (_control_outs->state (full_state));
1920 node->add_child_nocopy (*cnode);
1923 if (_comment.length()) {
1924 XMLNode *cmt = node->add_child ("Comment");
1925 cmt->add_content (_comment);
1928 for (i = _processors.begin(); i != _processors.end(); ++i) {
1929 node->add_child_nocopy((*i)->state (full_state));
1933 node->add_child_copy (*_extra_xml);
1940 Route::get_processor_state ()
1942 XMLNode* root = new XMLNode (X_("redirects"));
1943 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1944 root->add_child_nocopy ((*i)->state (true));
1951 Route::set_processor_state (const XMLNode& root)
1953 if (root.name() != X_("redirects")) {
1959 XMLNodeConstIterator iter;
1960 XMLNodeConstIterator niter;
1961 Glib::RWLock::ReaderLock lm (_processor_lock);
1963 nlist = root.children();
1965 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1967 /* iter now points to a IOProcessor state node */
1969 nnlist = (*iter)->children ();
1971 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1973 /* find the IO child node, since it contains the ID we need */
1975 /* XXX OOP encapsulation violation, ugh */
1977 if ((*niter)->name() == IO::state_node_name) {
1979 XMLProperty* prop = (*niter)->property (X_("id"));
1982 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1986 ID id = prop->value ();
1988 /* now look for a processor with that ID */
1990 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1991 if ((*i)->id() == id) {
1992 (*i)->set_state (**iter);
2008 Route::set_deferred_state ()
2011 XMLNodeConstIterator niter;
2013 if (!deferred_state) {
2017 nlist = deferred_state->children();
2019 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2020 add_processor_from_xml (**niter);
2023 delete deferred_state;
2028 Route::add_processor_from_xml (const XMLNode& node)
2030 const XMLProperty *prop;
2032 // legacy sessions use a different node name for sends
2033 if (node.name() == "Send") {
2036 boost::shared_ptr<Send> send (new Send (_session, node));
2037 add_processor (send);
2040 catch (failed_constructor &err) {
2041 error << _("Send construction failed") << endmsg;
2045 // use "Processor" in XML?
2046 } else if (node.name() == "Processor") {
2049 if ((prop = node.property ("type")) != 0) {
2051 boost::shared_ptr<Processor> processor;
2052 bool have_insert = false;
2054 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2055 prop->value() == "lv2" ||
2056 prop->value() == "vst" ||
2057 prop->value() == "audiounit") {
2059 processor.reset (new PluginInsert(_session, node));
2062 } else if (prop->value() == "port") {
2064 processor.reset (new PortInsert (_session, node));
2066 } else if (prop->value() == "send") {
2068 processor.reset (new Send (_session, node));
2073 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2076 add_processor (processor);
2079 error << _("Processor XML node has no type property") << endmsg;
2083 catch (failed_constructor &err) {
2084 warning << _("processor could not be created. Ignored.") << endmsg;
2091 Route::set_state (const XMLNode& node)
2093 return _set_state (node, true);
2097 Route::_set_state (const XMLNode& node, bool call_base)
2100 XMLNodeConstIterator niter;
2102 XMLPropertyList plist;
2103 const XMLProperty *prop;
2105 if (node.name() != "Route"){
2106 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2110 if ((prop = node.property (X_("flags"))) != 0) {
2111 _flags = Flag (string_2_enum (prop->value(), _flags));
2116 if ((prop = node.property (X_("default-type"))) != 0) {
2117 _default_type = DataType(prop->value());
2118 assert(_default_type != DataType::NIL);
2121 if ((prop = node.property (X_("phase-invert"))) != 0) {
2122 set_phase_invert (prop->value()=="yes"?true:false, this);
2125 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2126 set_denormal_protection (prop->value()=="yes"?true:false, this);
2130 if ((prop = node.property (X_("active"))) != 0) {
2131 set_active (prop->value() == "yes");
2134 if ((prop = node.property (X_("muted"))) != 0) {
2135 bool yn = prop->value()=="yes"?true:false;
2137 /* force reset of mute status */
2141 mute_gain = desired_mute_gain;
2144 if ((prop = node.property (X_("soloed"))) != 0) {
2145 bool yn = prop->value()=="yes"?true:false;
2147 /* force reset of solo status */
2150 set_solo (yn, this);
2151 solo_gain = desired_solo_gain;
2154 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2155 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2158 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2159 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2162 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2163 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2166 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2167 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2170 if ((prop = node.property (X_("meter-point"))) != 0) {
2171 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2174 if ((prop = node.property (X_("edit-group"))) != 0) {
2175 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2176 if(edit_group == 0) {
2177 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2179 set_edit_group(edit_group, this);
2183 if ((prop = node.property (X_("order-keys"))) != 0) {
2187 string::size_type colon, equal;
2188 string remaining = prop->value();
2190 while (remaining.length()) {
2192 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2193 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2196 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2197 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2200 set_order_key (remaining.substr (0, equal).c_str(), n);
2204 colon = remaining.find_first_of (':');
2206 if (colon != string::npos) {
2207 remaining = remaining.substr (colon+1);
2214 nlist = node.children();
2216 delete deferred_state;
2217 deferred_state = new XMLNode(X_("deferred state"));
2219 /* set parent class properties before anything else */
2221 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2225 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);
2264 _control_outs->set_state (**(child->children().begin()));
2266 } else if (child->name() == X_("Comment")) {
2268 /* XXX this is a terrible API design in libxml++ */
2270 XMLNode *cmt = *(child->children().begin());
2271 _comment = cmt->content();
2273 } else if (child->name() == X_("Extra")) {
2275 _extra_xml = new XMLNode (*child);
2277 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2279 if (prop->value() == "solo") {
2280 _solo_control->set_state (*child);
2281 _session.add_controllable (_solo_control);
2282 } else if (prop->value() == "mute") {
2283 _mute_control->set_state (*child);
2284 _session.add_controllable (_mute_control);
2287 else if (child->name() == X_("RemoteControl")) {
2288 if ((prop = child->property (X_("id"))) != 0) {
2290 sscanf (prop->value().c_str(), "%d", &x);
2291 set_remote_control_id (x);
2296 if ((prop = node.property (X_("mix-group"))) != 0) {
2297 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2298 if (mix_group == 0) {
2299 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2301 set_mix_group(mix_group, this);
2309 Route::_set_processor_states(const XMLNodeList &nlist)
2311 XMLNodeConstIterator niter;
2314 ProcessorList::iterator i, o;
2316 // Iterate through existing processors, remove those which are not in the state list
2317 for (i = _processors.begin(); i != _processors.end(); ) {
2318 ProcessorList::iterator tmp = i;
2321 bool processorInStateList = false;
2323 (*i)->id().print (buf, sizeof (buf));
2326 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2328 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2329 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2330 processorInStateList = true;
2332 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2333 processorInStateList = true;
2338 if (!processorInStateList) {
2339 remove_processor (*i);
2347 // Iterate through state list and make sure all processors are on the track and in the correct order,
2348 // set the state of existing processors according to the new state on the same go
2349 i = _processors.begin();
2350 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2352 // Check whether the next processor in the list
2355 while (o != _processors.end()) {
2356 (*o)->id().print (buf, sizeof (buf));
2357 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2359 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2365 if (o == _processors.end()) {
2366 // If the processor (*niter) is not on the route, we need to create it
2367 // and move it to the correct location
2369 ProcessorList::iterator prev_last = _processors.end();
2370 --prev_last; // We need this to check whether adding succeeded
2372 add_processor_from_xml (**niter);
2374 ProcessorList::iterator last = _processors.end();
2377 if (prev_last == last) {
2378 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2383 boost::shared_ptr<Processor> tmp = (*last);
2384 // remove the processor from the wrong location
2385 _processors.erase(last);
2386 // processor the new processor at the current location
2387 _processors.insert(i, tmp);
2389 --i; // move pointer to the newly processored processor
2393 // We found the processor (*niter) on the route, first we must make sure the processor
2394 // is at the location provided in the XML state
2396 boost::shared_ptr<Processor> tmp = (*o);
2397 // remove the old copy
2398 _processors.erase(o);
2399 // processor the processor at the correct location
2400 _processors.insert(i, tmp);
2402 --i; // move pointer so it points to the right processor
2405 (*i)->set_state( (**niter) );
2408 processors_changed ();
2412 Route::curve_reallocate ()
2414 // _gain_automation_curve.finish_resize ();
2415 // _pan_automation_curve.finish_resize ();
2419 Route::silence (nframes_t nframes, nframes_t offset)
2423 IO::silence (nframes, offset);
2425 if (_control_outs) {
2426 _control_outs->silence (nframes, offset);
2430 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2433 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2434 boost::shared_ptr<PluginInsert> pi;
2435 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2436 // skip plugins, they don't need anything when we're not active
2440 (*i)->silence (nframes, offset);
2443 if (nframes == _session.get_block_size() && offset == 0) {
2453 Route::set_control_outs (const vector<string>& ports)
2455 Glib::Mutex::Lock lm (_control_outs_lock);
2456 vector<string>::const_iterator i;
2459 delete _control_outs;
2462 if (is_control() || is_master()) {
2463 /* no control outs for these two special busses */
2467 if (ports.empty()) {
2471 string coutname = _name;
2472 coutname += _("[control]");
2474 _control_outs = new IO (_session, coutname);
2476 /* our control outs need as many outputs as we
2477 have audio outputs. we track the changes in ::output_change_handler().
2480 // XXX its stupid that we have to get this value twice
2482 limit = n_outputs().n_audio();
2484 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2488 /* now connect to the named ports */
2490 for (size_t n = 0; n < limit; ++n) {
2491 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2492 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2501 Route::set_edit_group (RouteGroup *eg, void *src)
2504 if (eg == _edit_group) {
2509 _edit_group->remove (this);
2512 if ((_edit_group = eg) != 0) {
2513 _edit_group->add (this);
2516 _session.set_dirty ();
2517 edit_group_changed (src); /* EMIT SIGNAL */
2521 Route::drop_edit_group (void *src)
2524 _session.set_dirty ();
2525 edit_group_changed (src); /* EMIT SIGNAL */
2529 Route::set_mix_group (RouteGroup *mg, void *src)
2532 if (mg == _mix_group) {
2537 _mix_group->remove (this);
2540 if ((_mix_group = mg) != 0) {
2541 _mix_group->add (this);
2544 _session.set_dirty ();
2545 mix_group_changed (src); /* EMIT SIGNAL */
2549 Route::drop_mix_group (void *src)
2552 _session.set_dirty ();
2553 mix_group_changed (src); /* EMIT SIGNAL */
2557 Route::set_comment (string cmt, void *src)
2560 comment_changed (src);
2561 _session.set_dirty ();
2565 Route::feeds (boost::shared_ptr<Route> other)
2570 uint32_t no = self.n_outputs().n_total();
2571 uint32_t ni = other->n_inputs ().n_total();
2573 for (i = 0; i < no; ++i) {
2574 for (j = 0; j < ni; ++j) {
2575 if (self.output(i)->connected_to (other->input(j)->name())) {
2581 /* check IOProcessors which may also interconnect Routes */
2583 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2585 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2590 // TODO: support internal redirects here
2592 no = redirect->io()->n_outputs().n_total();
2594 for (i = 0; i < no; ++i) {
2595 for (j = 0; j < ni; ++j) {
2596 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2603 /* check for control room outputs which may also interconnect Routes */
2605 if (_control_outs) {
2607 no = _control_outs->n_outputs().n_total();
2609 for (i = 0; i < no; ++i) {
2610 for (j = 0; j < ni; ++j) {
2611 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2622 Route::set_mute_config (mute_type t, bool onoff, void *src)
2626 _mute_affects_pre_fader = onoff;
2627 pre_fader_changed(src); /* EMIT SIGNAL */
2631 _mute_affects_post_fader = onoff;
2632 post_fader_changed(src); /* EMIT SIGNAL */
2636 _mute_affects_control_outs = onoff;
2637 control_outs_changed(src); /* EMIT SIGNAL */
2641 _mute_affects_main_outs = onoff;
2642 main_outs_changed(src); /* EMIT SIGNAL */
2648 Route::get_mute_config (mute_type t)
2654 onoff = _mute_affects_pre_fader;
2657 onoff = _mute_affects_post_fader;
2660 onoff = _mute_affects_control_outs;
2663 onoff = _mute_affects_main_outs;
2671 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2673 nframes_t now = _session.transport_frame();
2676 Glib::RWLock::ReaderLock lm (_processor_lock);
2679 automation_snapshot (now, true);
2682 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2684 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2685 (*i)->deactivate ();
2689 (*i)->transport_stopped (now);
2693 IO::transport_stopped (now);
2695 _roll_delay = _initial_delay;
2699 Route::input_change_handler (IOChange change, void *ignored)
2701 if (change & ConfigurationChanged) {
2702 reset_processor_counts (0);
2707 Route::output_change_handler (IOChange change, void *ignored)
2709 if (change & ConfigurationChanged) {
2710 if (_control_outs) {
2711 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2714 reset_processor_counts (0);
2719 Route::pans_required () const
2721 if (n_outputs().n_audio() < 2) {
2725 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2729 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2730 bool session_state_changing, bool can_record, bool rec_monitors_input)
2732 if (n_outputs().n_total() == 0) {
2736 if (session_state_changing || !_active) {
2737 silence (nframes, offset);
2741 apply_gain_automation = false;
2743 if (n_inputs().n_total()) {
2744 passthru (start_frame, end_frame, nframes, offset, 0, false);
2746 silence (nframes, offset);
2753 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2755 if (_roll_delay > nframes) {
2757 _roll_delay -= nframes;
2758 silence (nframes, offset);
2759 /* transport frame is not legal for caller to use */
2762 } else if (_roll_delay > 0) {
2764 nframes -= _roll_delay;
2766 silence (_roll_delay, offset);
2768 offset += _roll_delay;
2769 transport_frame += _roll_delay;
2778 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2779 bool can_record, bool rec_monitors_input)
2782 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2784 // automation snapshot can also be called from the non-rt context
2785 // and it uses the processor list, so we take the lock out here
2786 automation_snapshot (_session.transport_frame(), false);
2790 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2791 silence (nframes, offset);
2795 nframes_t unused = 0;
2797 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2803 apply_gain_automation = false;
2806 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2808 if (am.locked() && _session.transport_rolling()) {
2810 if (_gain_control->automation_playback()) {
2811 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2812 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2817 passthru (start_frame, end_frame, nframes, offset, declick, false);
2823 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2824 bool can_record, bool rec_monitors_input)
2826 silence (nframes, offset);
2831 Route::toggle_monitor_input ()
2833 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2834 i->ensure_monitor_input( ! i->monitoring_input());
2839 Route::has_external_redirects () const
2841 // FIXME: what about sends?
2843 boost::shared_ptr<const PortInsert> pi;
2845 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2846 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2848 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2849 port != pi->io()->outputs().end(); ++port) {
2851 string port_name = port->name();
2852 string client_name = port_name.substr (0, port_name.find(':'));
2854 /* only say "yes" if the redirect is actually in use */
2856 if (client_name != "ardour" && pi->active()) {
2867 Route::flush_processors ()
2869 /* XXX shouldn't really try to take this lock, since
2870 this is called from the RT audio thread.
2873 Glib::RWLock::ReaderLock lm (_processor_lock);
2875 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2876 (*i)->deactivate ();
2882 Route::set_meter_point (MeterPoint p, void *src)
2884 if (_meter_point != p) {
2886 meter_change (src); /* EMIT SIGNAL */
2887 _session.set_dirty ();
2892 Route::update_total_latency ()
2894 nframes_t old = _own_latency;
2896 if (_user_latency) {
2897 _own_latency = _user_latency;
2901 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2902 if ((*i)->active ()) {
2903 _own_latency += (*i)->signal_latency ();
2908 #undef DEBUG_LATENCY
2909 #ifdef DEBUG_LATENCY
2910 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2913 set_port_latency (_own_latency);
2915 if (!_user_latency) {
2916 /* this (virtual) function is used for pure Routes,
2917 not derived classes like AudioTrack. this means
2918 that the data processed here comes from an input
2919 port, not prerecorded material, and therefore we
2920 have to take into account any input latency.
2924 _own_latency += input_latency ();
2927 if (old != _own_latency) {
2928 signal_latency_changed (); /* EMIT SIGNAL */
2931 #ifdef DEBUG_LATENCY
2932 cerr << _name << ": input latency = " << input_latency() << " total = "
2933 << _own_latency << endl;
2936 return _own_latency;
2940 Route::set_user_latency (nframes_t nframes)
2942 Latent::set_user_latency (nframes);
2943 _session.update_latency_compensation (false, false);
2947 Route::set_latency_delay (nframes_t longest_session_latency)
2949 nframes_t old = _initial_delay;
2951 if (_own_latency < longest_session_latency) {
2952 _initial_delay = longest_session_latency - _own_latency;
2957 if (_initial_delay != old) {
2958 initial_delay_changed (); /* EMIT SIGNAL */
2961 if (_session.transport_stopped()) {
2962 _roll_delay = _initial_delay;
2967 Route::automation_snapshot (nframes_t now, bool force)
2969 if (!force && !should_snapshot(now)) {
2973 IO::automation_snapshot (now, force);
2975 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2976 (*i)->automation_snapshot (now, force);
2980 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2981 : Controllable (name), route (s), type(tp)
2987 Route::ToggleControllable::set_value (float val)
2989 bool bval = ((val >= 0.5f) ? true: false);
2993 route.set_mute (bval, this);
2996 route.set_solo (bval, this);
3004 Route::ToggleControllable::get_value (void) const
3010 val = route.muted() ? 1.0f : 0.0f;
3013 val = route.soloed() ? 1.0f : 0.0f;
3023 Route::set_block_size (nframes_t nframes)
3025 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3026 (*i)->set_block_size (nframes);
3031 Route::protect_automation ()
3033 Automatable::protect_automation();
3035 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3036 (*i)->protect_automation();
3040 Route::set_pending_declick (int declick)
3043 /* this call is not allowed to turn off a pending declick unless "force" is true */
3045 _pending_declick = declick;
3047 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3049 _pending_declick = 0;
3054 /** Shift automation forwards from a particular place, thereby inserting time.
3055 * Adds undo commands for any shifts that are performed.
3057 * @param pos Position to start shifting from.
3058 * @param frames Amount to shift forwards by.
3062 Route::shift (nframes64_t pos, nframes64_t frames)
3064 #ifdef THIS_NEEDS_FIXING_FOR_V3
3066 /* gain automation */
3067 XMLNode &before = _gain_control->get_state ();
3068 _gain_control->shift (pos, frames);
3069 XMLNode &after = _gain_control->get_state ();
3070 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3072 /* pan automation */
3073 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3074 Curve & c = (*i)->automation ();
3075 XMLNode &before = c.get_state ();
3076 c.shift (pos, frames);
3077 XMLNode &after = c.get_state ();
3078 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3081 /* redirect automation */
3083 Glib::RWLock::ReaderLock lm (redirect_lock);
3084 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3087 (*i)->what_has_automation (a);
3089 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3090 AutomationList & al = (*i)->automation_list (*j);
3091 XMLNode &before = al.get_state ();
3092 al.shift (pos, frames);
3093 XMLNode &after = al.get_state ();
3094 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));