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>
28 #include <ardour/timestamps.h>
29 #include <ardour/audioengine.h>
30 #include <ardour/route.h>
31 #include <ardour/buffer.h>
32 #include <ardour/insert.h>
33 #include <ardour/send.h>
34 #include <ardour/session.h>
35 #include <ardour/utils.h>
36 #include <ardour/configuration.h>
37 #include <ardour/cycle_timer.h>
38 #include <ardour/route_group.h>
39 #include <ardour/port.h>
40 #include <ardour/audio_port.h>
41 #include <ardour/ladspa_plugin.h>
42 #include <ardour/panner.h>
43 #include <ardour/dB.h>
44 #include <ardour/amp.h>
45 #include <ardour/meter.h>
46 #include <ardour/buffer_set.h>
50 using namespace ARDOUR;
53 uint32_t Route::order_key_cnt = 0;
56 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
57 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
59 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
60 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
65 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
66 : IO (sess, *node.child ("IO"), default_type),
67 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
68 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
71 _set_state (node, false);
77 redirect_max_outs.reset();
81 _phase_invert = false;
82 _denormal_protection = false;
83 order_keys[strdup (N_("signal"))] = order_key_cnt++;
86 _meter_point = MeterPostFader;
90 _have_internal_generator = false;
92 _pending_declick = true;
93 _remote_control_id = 0;
98 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
99 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
100 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
101 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
104 desired_solo_gain = 1.0;
106 desired_mute_gain = 1.0;
110 input_changed.connect (mem_fun (this, &Route::input_change_handler));
111 output_changed.connect (mem_fun (this, &Route::output_change_handler));
116 clear_redirects (PreFader, this);
117 clear_redirects (PostFader, this);
119 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
120 free ((void*)(i->first));
124 delete _control_outs;
129 Route::set_remote_control_id (uint32_t id)
131 if (id != _remote_control_id) {
132 _remote_control_id = id;
133 RemoteControlIDChanged ();
138 Route::remote_control_id() const
140 return _remote_control_id;
144 Route::order_key (const char* name) const
146 OrderKeys::const_iterator i;
148 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
149 if (!strcmp (name, i->first)) {
158 Route::set_order_key (const char* name, long n)
160 order_keys[strdup(name)] = n;
161 _session.set_dirty ();
165 Route::inc_gain (gain_t fraction, void *src)
167 IO::inc_gain (fraction, src);
171 Route::set_gain (gain_t val, void *src)
173 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
175 if (_mix_group->is_relative()) {
178 gain_t usable_gain = gain();
179 if (usable_gain < 0.000001f) {
180 usable_gain=0.000001f;
184 if (delta < 0.000001f) {
188 delta -= usable_gain;
190 if (delta == 0.0f) return;
192 gain_t factor = delta / usable_gain;
195 factor = _mix_group->get_max_factor(factor);
196 if (factor == 0.0f) {
201 factor = _mix_group->get_min_factor(factor);
202 if (factor == 0.0f) {
208 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
212 _mix_group->apply (&Route::set_gain, val, _mix_group);
222 IO::set_gain (val, src);
225 /** Process this route for one (sub) cycle (process thread)
227 * @param bufs Scratch buffers to use for the signal path
228 * @param start_frame Initial transport frame
229 * @param end_frame Final transport frame
230 * @param nframes Number of frames to output (to ports)
231 * @param offset Output offset (of port buffers, for split cycles)
233 * Note that (end_frame - start_frame) may not be equal to nframes when the
234 * transport speed isn't 1.0 (eg varispeed).
237 Route::process_output_buffers (BufferSet& bufs,
238 nframes_t start_frame, nframes_t end_frame,
239 nframes_t nframes, nframes_t offset, bool with_redirects, int declick,
242 // This is definitely very audio-only for now
243 assert(_default_type == DataType::AUDIO);
245 RedirectList::iterator i;
246 bool post_fader_work = false;
247 bool mute_declick_applied = false;
253 gain_t* gab = _session.gain_automation_buffer();
255 switch (Config->get_monitoring_model()) {
256 case HardwareMonitoring:
257 case ExternalMonitoring:
264 declick = _pending_declick;
267 Glib::Mutex::Lock cm (control_outs_lock, Glib::TRY_LOCK);
277 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
280 dmg = desired_mute_gain;
281 dsg = desired_solo_gain;
290 /* ----------------------------------------------------------------------------------------------------
291 GLOBAL DECLICK (for transport changes etc.)
292 -------------------------------------------------------------------------------------------------- */
295 Amp::run (bufs, nframes, 0.0, 1.0, false);
296 _pending_declick = 0;
297 } else if (declick < 0) {
298 Amp::run (bufs, nframes, 1.0, 0.0, false);
299 _pending_declick = 0;
302 /* no global declick */
304 if (solo_gain != dsg) {
305 Amp::run (bufs, nframes, solo_gain, dsg, false);
311 /* ----------------------------------------------------------------------------------------------------
312 INPUT METERING & MONITORING
313 -------------------------------------------------------------------------------------------------- */
315 if (meter && (_meter_point == MeterInput)) {
316 _meter->run(bufs, nframes);
319 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
320 Amp::run (bufs, nframes, mute_gain, dmg, false);
322 mute_declick_applied = true;
325 if ((_meter_point == MeterInput) && co) {
327 solo_audible = dsg > 0;
328 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
330 if ( // muted by solo of another track
334 // muted by mute of this track
338 // rec-enabled but not s/w monitoring
340 // TODO: this is probably wrong
342 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
346 co->silence (nframes, offset);
350 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
355 /* -----------------------------------------------------------------------------------------------------
357 -------------------------------------------------------------------------------------------------- */
359 if (_denormal_protection || Config->get_denormal_protection()) {
361 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
362 Sample* const sp = i->data();
364 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
370 /* ----------------------------------------------------------------------------------------------------
372 -------------------------------------------------------------------------------------------------- */
374 /* FIXME: Somewhere in these loops is where bufs.count() should go from n_inputs() to redirect_max_outs()
375 * (if they differ). Something explicit needs to be done here to make sure the list of redirects will
376 * give us what we need (possibly by inserting transparent 'translators' into the list to make it work) */
378 if (with_redirects) {
379 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
381 if (mute_gain > 0 || !_mute_affects_pre_fader) {
382 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
383 switch ((*i)->placement()) {
385 (*i)->run (bufs, start_frame, end_frame, nframes, offset);
388 post_fader_work = true;
393 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
394 switch ((*i)->placement()) {
396 (*i)->silence (nframes, offset);
399 post_fader_work = true;
407 // FIXME: for now, just hope the redirects list did what it was supposed to
408 bufs.set_count(n_process_buffers());
411 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
412 Amp::run (bufs, nframes, mute_gain, dmg, false);
414 mute_declick_applied = true;
417 /* ----------------------------------------------------------------------------------------------------
418 PRE-FADER METERING & MONITORING
419 -------------------------------------------------------------------------------------------------- */
421 if (meter && (_meter_point == MeterPreFader)) {
422 _meter->run(bufs, nframes);
426 if ((_meter_point == MeterPreFader) && co) {
428 solo_audible = dsg > 0;
429 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
431 if ( // muted by solo of another track
435 // muted by mute of this track
439 // rec-enabled but not s/w monitoring
441 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
445 co->silence (nframes, offset);
449 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
453 /* ----------------------------------------------------------------------------------------------------
455 -------------------------------------------------------------------------------------------------- */
457 /* if not recording or recording and requiring any monitor signal, then apply gain */
459 if ( // not recording
461 !(record_enabled() && _session.actively_recording()) ||
465 // h/w monitoring not in use
467 (!Config->get_monitoring_model() == HardwareMonitoring &&
469 // AND software monitoring required
471 Config->get_monitoring_model() == SoftwareMonitoring)) {
473 if (apply_gain_automation) {
476 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
477 Sample* const sp = i->data();
479 for (nframes_t nx = 0; nx < nframes; ++nx) {
484 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
485 Sample* const sp = i->data();
487 for (nframes_t nx = 0; nx < nframes; ++nx) {
493 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
494 _effective_gain = gab[nframes-1];
499 /* manual (scalar) gain */
503 Amp::run (bufs, nframes, _gain, dg, _phase_invert);
506 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
508 /* no need to interpolate current gain value,
509 but its non-unity, so apply it. if the gain
510 is zero, do nothing because we'll ship silence
522 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
523 Sample* const sp = i->data();
524 apply_gain_to_buffer(sp,nframes,this_gain);
527 } else if (_gain == 0) {
528 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
536 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
540 /* ----------------------------------------------------------------------------------------------------
542 -------------------------------------------------------------------------------------------------- */
544 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
546 if (post_fader_work) {
548 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
550 if (mute_gain > 0 || !_mute_affects_post_fader) {
551 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
552 switch ((*i)->placement()) {
556 (*i)->run (bufs, start_frame, end_frame, nframes, offset);
561 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
562 switch ((*i)->placement()) {
566 (*i)->silence (nframes, offset);
574 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
575 Amp::run (bufs, nframes, mute_gain, dmg, false);
577 mute_declick_applied = true;
580 /* ----------------------------------------------------------------------------------------------------
582 -------------------------------------------------------------------------------------------------- */
584 if ((_meter_point == MeterPostFader) && co) {
586 solo_audible = solo_gain > 0;
587 mute_audible = dmg > 0 || !_mute_affects_control_outs;
589 if ( // silent anyway
591 (_gain == 0 && !apply_gain_automation) ||
593 // muted by solo of another track
597 // muted by mute of this track
601 // recording but not s/w monitoring
603 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
607 co->silence (nframes, offset);
611 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
615 /* ----------------------------------------------------------------------
617 ----------------------------------------------------------------------*/
619 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
620 Amp::run (bufs, nframes, mute_gain, dmg, false);
622 mute_declick_applied = true;
625 /* ----------------------------------------------------------------------------------------------------
627 -------------------------------------------------------------------------------------------------- */
629 solo_audible = dsg > 0;
630 mute_audible = dmg > 0 || !_mute_affects_main_outs;
632 if (n_outputs().get(_default_type) == 0) {
636 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
638 IO::silence (nframes, offset);
642 if ( // silent anyway
644 (_gain == 0 && !apply_gain_automation) ||
646 // muted by solo of another track, but not using control outs for solo
648 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
650 // muted by mute of this track
656 /* don't use Route::silence() here, because that causes
657 all outputs (sends, port inserts, etc. to be silent).
660 if (_meter_point == MeterPostFader) {
661 peak_meter().reset();
664 IO::silence (nframes, offset);
668 deliver_output(bufs, start_frame, end_frame, nframes, offset);
674 /* ----------------------------------------------------------------------------------------------------
676 -------------------------------------------------------------------------------------------------- */
678 if (meter && (_meter_point == MeterPostFader)) {
679 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
682 _meter->run(output_buffers(), nframes, offset);
688 Route::n_process_buffers ()
690 return max (n_inputs(), redirect_max_outs);
694 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
696 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
700 collect_input (bufs, nframes, offset);
702 #define meter_stream meter_first
705 _meter->run(bufs, nframes);
706 meter_stream = false;
711 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_stream);
717 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
719 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
723 Route::set_solo (bool yn, void *src)
729 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
730 _mix_group->apply (&Route::set_solo, yn, _mix_group);
736 solo_changed (src); /* EMIT SIGNAL */
737 _solo_control.Changed (); /* EMIT SIGNAL */
742 Route::set_solo_mute (bool yn)
744 Glib::Mutex::Lock lm (declick_lock);
746 /* Called by Session in response to another Route being soloed.
749 desired_solo_gain = (yn?0.0:1.0);
753 Route::set_solo_safe (bool yn, void *src)
755 if (_solo_safe != yn) {
757 solo_safe_changed (src); /* EMIT SIGNAL */
762 Route::set_mute (bool yn, void *src)
765 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
766 _mix_group->apply (&Route::set_mute, yn, _mix_group);
772 mute_changed (src); /* EMIT SIGNAL */
774 _mute_control.Changed (); /* EMIT SIGNAL */
776 Glib::Mutex::Lock lm (declick_lock);
777 desired_mute_gain = (yn?0.0f:1.0f);
782 Route::add_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
784 ChanCount old_rmo = redirect_max_outs;
786 if (!_session.engine().connected()) {
791 Glib::RWLock::WriterLock lm (redirect_lock);
793 boost::shared_ptr<PluginInsert> pi;
794 boost::shared_ptr<PortInsert> porti;
796 redirect->set_default_type(_default_type);
798 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redirect)) != 0) {
801 if (pi->input_streams() == ChanCount::ZERO) {
802 /* generator plugin */
803 _have_internal_generator = true;
806 } else if ((porti = boost::dynamic_pointer_cast<PortInsert>(redirect)) != 0) {
808 /* force new port inserts to start out with an i/o configuration
809 that matches this route's i/o configuration.
811 the "inputs" for the port are supposed to match the output
814 the "outputs" of the route should match the inputs of this
815 route. XXX shouldn't they match the number of active signal
816 streams at the point of insertion?
818 // FIXME: (yes, they should)
820 porti->ensure_io (n_outputs (), n_inputs(), false, this);
823 // Ensure peak vector sizes before the plugin is activated
824 ChanCount potential_max_streams = max(redirect->input_streams(), redirect->output_streams());
825 _meter->setup(potential_max_streams);
827 _redirects.push_back (redirect);
829 if (_reset_plugin_counts (err_streams)) {
830 _redirects.pop_back ();
831 _reset_plugin_counts (0); // it worked before we tried to add it ...
835 redirect->activate ();
836 redirect->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
839 if (redirect_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
844 redirects_changed (src); /* EMIT SIGNAL */
849 Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_streams)
851 ChanCount old_rmo = redirect_max_outs;
853 if (!_session.engine().connected()) {
858 Glib::RWLock::WriterLock lm (redirect_lock);
860 RedirectList::iterator existing_end = _redirects.end();
863 ChanCount potential_max_streams;
865 for (RedirectList::const_iterator i = others.begin(); i != others.end(); ++i) {
867 boost::shared_ptr<PluginInsert> pi;
869 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
872 ChanCount m = max(pi->input_streams(), pi->output_streams());
873 if (m > potential_max_streams)
874 potential_max_streams = m;
877 // Ensure peak vector sizes before the plugin is activated
878 _meter->setup(potential_max_streams);
880 _redirects.push_back (*i);
882 if (_reset_plugin_counts (err_streams)) {
884 _redirects.erase (existing_end, _redirects.end());
885 _reset_plugin_counts (0); // it worked before we tried to add it ...
890 (*i)->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
894 if (redirect_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
898 redirects_changed (src); /* EMIT SIGNAL */
902 /** Turn off all redirects with a given placement
903 * @param p Placement of redirects to disable
907 Route::disable_redirects (Placement p)
909 Glib::RWLock::ReaderLock lm (redirect_lock);
911 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
912 if ((*i)->placement() == p) {
913 (*i)->set_active (false, this);
918 /** Turn off all redirects
922 Route::disable_redirects ()
924 Glib::RWLock::ReaderLock lm (redirect_lock);
926 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
927 (*i)->set_active (false, this);
931 /** Turn off all redirects with a given placement
932 * @param p Placement of redirects to disable
936 Route::disable_plugins (Placement p)
938 Glib::RWLock::ReaderLock lm (redirect_lock);
940 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
941 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
942 (*i)->set_active (false, this);
947 /** Turn off all plugins
951 Route::disable_plugins ()
953 Glib::RWLock::ReaderLock lm (redirect_lock);
955 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
956 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
957 (*i)->set_active (false, this);
964 Route::ab_plugins (bool forward)
966 Glib::RWLock::ReaderLock lm (redirect_lock);
970 /* forward = turn off all active redirects, and mark them so that the next time
971 we go the other way, we will revert them
974 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
975 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
979 if ((*i)->active()) {
980 (*i)->set_active (false, this);
981 (*i)->set_next_ab_is_active (true);
983 (*i)->set_next_ab_is_active (false);
989 /* backward = if the redirect was marked to go active on the next ab, do so */
991 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
993 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
997 if ((*i)->get_next_ab_is_active()) {
998 (*i)->set_active (true, this);
1000 (*i)->set_active (false, this);
1006 /** Remove redirects with a given placement.
1007 * @param p Placement of redirects to remove.
1010 Route::clear_redirects (Placement p, void *src)
1012 const ChanCount old_rmo = redirect_max_outs;
1014 if (!_session.engine().connected()) {
1019 Glib::RWLock::WriterLock lm (redirect_lock);
1020 RedirectList new_list;
1022 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1023 if ((*i)->placement() == p) {
1024 /* it's the placement we want to get rid of */
1025 (*i)->drop_references ();
1027 /* it's a different placement, so keep it */
1028 new_list.push_back (*i);
1032 _redirects = new_list;
1035 /* FIXME: can't see how this test can ever fire */
1036 if (redirect_max_outs != old_rmo) {
1040 redirect_max_outs.reset();
1041 _have_internal_generator = false;
1042 redirects_changed (src); /* EMIT SIGNAL */
1046 Route::remove_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
1048 ChanCount old_rmo = redirect_max_outs;
1050 if (!_session.engine().connected()) {
1054 redirect_max_outs.reset();
1057 Glib::RWLock::WriterLock lm (redirect_lock);
1058 RedirectList::iterator i;
1059 bool removed = false;
1061 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1062 if (*i == redirect) {
1064 RedirectList::iterator tmp;
1066 /* move along, see failure case for reset_plugin_counts()
1067 where we may need to reinsert the redirect.
1073 /* stop redirects that send signals to JACK ports
1074 from causing noise as a result of no longer being
1078 boost::shared_ptr<Send> send;
1079 boost::shared_ptr<PortInsert> port_insert;
1081 if ((send = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
1082 send->disconnect_inputs (this);
1083 send->disconnect_outputs (this);
1084 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (*i)) != 0) {
1085 port_insert->disconnect_inputs (this);
1086 port_insert->disconnect_outputs (this);
1089 _redirects.erase (i);
1102 if (_reset_plugin_counts (err_streams)) {
1103 /* get back to where we where */
1104 _redirects.insert (i, redirect);
1105 /* we know this will work, because it worked before :) */
1106 _reset_plugin_counts (0);
1112 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1113 boost::shared_ptr<PluginInsert> pi;
1115 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1116 if (pi->is_generator()) {
1122 _have_internal_generator = foo;
1125 if (old_rmo != redirect_max_outs) {
1129 redirect->drop_references ();
1131 redirects_changed (src); /* EMIT SIGNAL */
1136 Route::reset_plugin_counts (uint32_t* lpc)
1138 Glib::RWLock::WriterLock lm (redirect_lock);
1139 return _reset_plugin_counts (lpc);
1144 Route::_reset_plugin_counts (uint32_t* err_streams)
1146 RedirectList::iterator r;
1149 map<Placement,list<InsertCount> > insert_map;
1150 nframes_t initial_streams;
1152 redirect_max_outs.reset();
1156 /* divide inserts up by placement so we get the signal flow
1157 properly modelled. we need to do this because the _redirects
1158 list is not sorted by placement, and because other reasons may
1159 exist now or in the future for this separate treatment.
1162 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1164 boost::shared_ptr<Insert> insert;
1166 /* do this here in case we bomb out before we get to the end of
1170 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1172 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1174 insert_map[insert->placement()].push_back (InsertCount (insert));
1176 /* reset plugin counts back to one for now so
1177 that we have a predictable, controlled
1178 state to try to configure.
1181 boost::shared_ptr<PluginInsert> pi;
1183 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
1187 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1200 /* Now process each placement in order, checking to see if we
1201 can really do what has been requested.
1206 if (check_some_plugin_counts (insert_map[PreFader], n_inputs ().get(_default_type), err_streams)) {
1210 /* figure out the streams that will feed into PreFader */
1212 if (!insert_map[PreFader].empty()) {
1213 InsertCount& ic (insert_map[PreFader].back());
1214 initial_streams = ic.insert->compute_output_streams (ic.cnt);
1216 initial_streams = n_inputs ().get(_default_type);
1221 if (check_some_plugin_counts (insert_map[PostFader], initial_streams, err_streams)) {
1225 /* OK, everything can be set up correctly, so lets do it */
1227 apply_some_plugin_counts (insert_map[PreFader]);
1228 apply_some_plugin_counts (insert_map[PostFader]);
1230 /* recompute max outs of any redirect */
1234 redirect_max_outs.reset();
1235 RedirectList::iterator prev = _redirects.end();
1237 for (r = _redirects.begin(); r != _redirects.end(); prev = r, ++r) {
1238 boost::shared_ptr<Send> s;
1240 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1241 if (r == _redirects.begin()) {
1242 s->expect_inputs (n_inputs());
1244 s->expect_inputs ((*prev)->output_streams());
1249 /* don't pay any attention to send output configuration, since it doesn't
1253 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1264 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1266 list<InsertCount>::iterator i;
1268 for (i = iclist.begin(); i != iclist.end(); ++i) {
1270 if ((*i).insert->configure_io ((*i).cnt, (*i).in, (*i).out)) {
1273 /* make sure that however many we have, they are all active */
1274 (*i).insert->activate ();
1281 Route::check_some_plugin_counts (list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams)
1283 list<InsertCount>::iterator i;
1285 for (i = iclist.begin(); i != iclist.end(); ++i) {
1287 if (((*i).cnt = (*i).insert->can_support_input_configuration (required_inputs)) < 0) {
1289 *err_streams = required_inputs;
1294 (*i).in = required_inputs;
1295 (*i).out = (*i).insert->compute_output_streams ((*i).cnt);
1297 required_inputs = (*i).out;
1304 Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_streams)
1306 ChanCount old_rmo = redirect_max_outs;
1312 RedirectList to_be_deleted;
1315 Glib::RWLock::WriterLock lm (redirect_lock);
1316 RedirectList::iterator tmp;
1317 RedirectList the_copy;
1319 the_copy = _redirects;
1321 /* remove all relevant redirects */
1323 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1327 if ((*i)->placement() == placement) {
1328 to_be_deleted.push_back (*i);
1329 _redirects.erase (i);
1335 /* now copy the relevant ones from "other" */
1337 for (RedirectList::const_iterator i = other._redirects.begin(); i != other._redirects.end(); ++i) {
1338 if ((*i)->placement() == placement) {
1339 _redirects.push_back (Redirect::clone (*i));
1343 /* reset plugin stream handling */
1345 if (_reset_plugin_counts (err_streams)) {
1347 /* FAILED COPY ATTEMPT: we have to restore order */
1349 /* delete all cloned redirects */
1351 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1356 if ((*i)->placement() == placement) {
1357 _redirects.erase (i);
1363 /* restore the natural order */
1365 _redirects = the_copy;
1366 redirect_max_outs = old_rmo;
1368 /* we failed, even though things are OK again */
1374 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1375 to_be_deleted.clear ();
1379 if (redirect_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
1383 redirects_changed (this); /* EMIT SIGNAL */
1388 Route::all_redirects_flip ()
1390 Glib::RWLock::ReaderLock lm (redirect_lock);
1392 if (_redirects.empty()) {
1396 bool first_is_on = _redirects.front()->active();
1398 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1399 (*i)->set_active (!first_is_on, this);
1403 /** Set all redirects with a given placement to a given active state.
1404 * @param p Placement of redirects to change.
1405 * @param state New active state for those redirects.
1408 Route::all_redirects_active (Placement p, bool state)
1410 Glib::RWLock::ReaderLock lm (redirect_lock);
1412 if (_redirects.empty()) {
1416 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1417 if ((*i)->placement() == p) {
1418 (*i)->set_active (state, this);
1423 struct RedirectSorter {
1424 bool operator() (boost::shared_ptr<const Redirect> a, boost::shared_ptr<const Redirect> b) {
1425 return a->sort_key() < b->sort_key();
1430 Route::sort_redirects (uint32_t* err_streams)
1433 RedirectSorter comparator;
1434 Glib::RWLock::WriterLock lm (redirect_lock);
1435 ChanCount old_rmo = redirect_max_outs;
1437 /* the sweet power of C++ ... */
1439 RedirectList as_it_was_before = _redirects;
1441 _redirects.sort (comparator);
1443 if (_reset_plugin_counts (err_streams)) {
1444 _redirects = as_it_was_before;
1445 redirect_max_outs = old_rmo;
1451 redirects_changed (this); /* EMIT SIGNAL */
1463 Route::get_template()
1465 return state(false);
1469 Route::state(bool full_state)
1471 XMLNode *node = new XMLNode("Route");
1472 RedirectList:: iterator i;
1476 node->add_property("flags", enum_2_string (_flags));
1479 node->add_property("default-type", _default_type.to_string());
1481 node->add_property("active", _active?"yes":"no");
1482 node->add_property("muted", _muted?"yes":"no");
1483 node->add_property("soloed", _soloed?"yes":"no");
1484 node->add_property("phase-invert", _phase_invert?"yes":"no");
1485 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1486 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1487 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1488 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1489 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1492 node->add_property("edit-group", _edit_group->name());
1495 node->add_property("mix-group", _mix_group->name());
1498 string order_string;
1499 OrderKeys::iterator x = order_keys.begin();
1501 while (x != order_keys.end()) {
1502 order_string += string ((*x).first);
1503 order_string += '=';
1504 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1505 order_string += buf;
1509 if (x == order_keys.end()) {
1513 order_string += ':';
1515 node->add_property ("order-keys", order_string);
1517 node->add_child_nocopy (IO::state (full_state));
1518 node->add_child_nocopy (_solo_control.get_state ());
1519 node->add_child_nocopy (_mute_control.get_state ());
1521 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1522 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1523 remote_control_node->add_property (X_("id"), buf);
1524 node->add_child_nocopy (*remote_control_node);
1526 if (_control_outs) {
1527 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1528 cnode->add_child_nocopy (_control_outs->state (full_state));
1529 node->add_child_nocopy (*cnode);
1532 if (_comment.length()) {
1533 XMLNode *cmt = node->add_child ("Comment");
1534 cmt->add_content (_comment);
1537 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1538 node->add_child_nocopy((*i)->state (full_state));
1542 node->add_child_copy (*_extra_xml);
1549 Route::get_redirect_state ()
1551 XMLNode* root = new XMLNode (X_("redirects"));
1552 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1553 root->add_child_nocopy ((*i)->state (true));
1560 Route::set_redirect_state (const XMLNode& root)
1562 if (root.name() != X_("redirects")) {
1568 XMLNodeConstIterator iter;
1569 XMLNodeConstIterator niter;
1570 Glib::RWLock::ReaderLock lm (redirect_lock);
1572 nlist = root.children();
1574 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1576 /* iter now points to a Redirect state node */
1578 nnlist = (*iter)->children ();
1580 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1582 /* find the IO child node, since it contains the ID we need */
1584 /* XXX OOP encapsulation violation, ugh */
1586 if ((*niter)->name() == IO::state_node_name) {
1588 XMLProperty* prop = (*niter)->property (X_("id"));
1591 warning << _("Redirect node has no ID, ignored") << endmsg;
1595 ID id = prop->value ();
1597 /* now look for a redirect with that ID */
1599 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1600 if ((*i)->id() == id) {
1601 (*i)->set_state (**iter);
1617 Route::set_deferred_state ()
1620 XMLNodeConstIterator niter;
1622 if (!deferred_state) {
1626 nlist = deferred_state->children();
1628 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1629 add_redirect_from_xml (**niter);
1632 delete deferred_state;
1637 Route::add_redirect_from_xml (const XMLNode& node)
1639 const XMLProperty *prop;
1641 if (node.name() == "Send") {
1645 boost::shared_ptr<Send> send (new Send (_session, node));
1646 add_redirect (send, this);
1649 catch (failed_constructor &err) {
1650 error << _("Send construction failed") << endmsg;
1654 } else if (node.name() == "Insert") {
1657 if ((prop = node.property ("type")) != 0) {
1659 boost::shared_ptr<Insert> insert;
1661 if (prop->value() == "ladspa" || prop->value() == "Ladspa" || prop->value() == "vst") {
1663 insert.reset (new PluginInsert(_session, node));
1665 } else if (prop->value() == "port") {
1668 insert.reset (new PortInsert (_session, node));
1672 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1675 add_redirect (insert, this);
1678 error << _("Insert XML node has no type property") << endmsg;
1682 catch (failed_constructor &err) {
1683 warning << _("insert could not be created. Ignored.") << endmsg;
1690 Route::set_state (const XMLNode& node)
1692 return _set_state (node, true);
1696 Route::_set_state (const XMLNode& node, bool call_base)
1699 XMLNodeConstIterator niter;
1701 XMLPropertyList plist;
1702 const XMLProperty *prop;
1704 if (node.name() != "Route"){
1705 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1709 if ((prop = node.property (X_("flags"))) != 0) {
1710 _flags = Flag (string_2_enum (prop->value(), _flags));
1715 if ((prop = node.property (X_("default-type"))) != 0) {
1716 _default_type = DataType(prop->value());
1717 assert(_default_type != DataType::NIL);
1720 if ((prop = node.property (X_("phase-invert"))) != 0) {
1721 set_phase_invert (prop->value()=="yes"?true:false, this);
1724 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1725 set_denormal_protection (prop->value()=="yes"?true:false, this);
1728 if ((prop = node.property (X_("active"))) != 0) {
1729 set_active (prop->value() == "yes");
1732 if ((prop = node.property (X_("muted"))) != 0) {
1733 bool yn = prop->value()=="yes"?true:false;
1735 /* force reset of mute status */
1739 mute_gain = desired_mute_gain;
1742 if ((prop = node.property (X_("soloed"))) != 0) {
1743 bool yn = prop->value()=="yes"?true:false;
1745 /* force reset of solo status */
1748 set_solo (yn, this);
1749 solo_gain = desired_solo_gain;
1752 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1753 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1756 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1757 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1760 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1761 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1764 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1765 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1768 if ((prop = node.property (X_("edit-group"))) != 0) {
1769 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1770 if(edit_group == 0) {
1771 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1773 set_edit_group(edit_group, this);
1777 if ((prop = node.property (X_("order-keys"))) != 0) {
1781 string::size_type colon, equal;
1782 string remaining = prop->value();
1784 while (remaining.length()) {
1786 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1787 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1790 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1791 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1794 set_order_key (remaining.substr (0, equal).c_str(), n);
1798 colon = remaining.find_first_of (':');
1800 if (colon != string::npos) {
1801 remaining = remaining.substr (colon+1);
1808 nlist = node.children();
1810 if (deferred_state) {
1811 delete deferred_state;
1814 deferred_state = new XMLNode(X_("deferred state"));
1816 /* set parent class properties before anything else */
1818 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1822 if (child->name() == IO::state_node_name && call_base) {
1824 IO::set_state (*child);
1829 XMLNodeList redirect_nodes;
1831 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1835 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1836 redirect_nodes.push_back(child);
1841 _set_redirect_states(redirect_nodes);
1844 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1846 // All redirects (sends and inserts) have been applied already
1848 if (child->name() == X_("Automation")) {
1850 if ((prop = child->property (X_("path"))) != 0) {
1851 load_automation (prop->value());
1854 } else if (child->name() == X_("ControlOuts")) {
1856 string coutname = _name;
1857 coutname += _("[control]");
1859 _control_outs = new IO (_session, coutname);
1860 _control_outs->set_state (**(child->children().begin()));
1862 } else if (child->name() == X_("Comment")) {
1864 /* XXX this is a terrible API design in libxml++ */
1866 XMLNode *cmt = *(child->children().begin());
1867 _comment = cmt->content();
1869 } else if (child->name() == X_("extra")) {
1871 _extra_xml = new XMLNode (*child);
1873 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1875 if (prop->value() == "solo") {
1876 _solo_control.set_state (*child);
1877 _session.add_controllable (&_solo_control);
1879 else if (prop->value() == "mute") {
1880 _mute_control.set_state (*child);
1881 _session.add_controllable (&_mute_control);
1884 else if (child->name() == X_("remote_control")) {
1885 if ((prop = child->property (X_("id"))) != 0) {
1887 sscanf (prop->value().c_str(), "%d", &x);
1888 set_remote_control_id (x);
1893 if ((prop = node.property (X_("mix-group"))) != 0) {
1894 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1895 if (mix_group == 0) {
1896 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1898 set_mix_group(mix_group, this);
1906 Route::_set_redirect_states(const XMLNodeList &nlist)
1908 XMLNodeConstIterator niter;
1911 RedirectList::iterator i, o;
1913 // Iterate through existing redirects, remove those which are not in the state list
1914 for (i = _redirects.begin(); i != _redirects.end(); ) {
1915 RedirectList::iterator tmp = i;
1918 bool redirectInStateList = false;
1920 (*i)->id().print (buf, sizeof (buf));
1923 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1925 if (strncmp(buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1926 redirectInStateList = true;
1931 if (!redirectInStateList) {
1932 remove_redirect ( *i, this);
1940 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1941 // set the state of existing redirects according to the new state on the same go
1942 i = _redirects.begin();
1943 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1945 // Check whether the next redirect in the list
1948 while (o != _redirects.end()) {
1949 (*o)->id().print (buf, sizeof (buf));
1950 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1955 if (o == _redirects.end()) {
1956 // If the redirect (*niter) is not on the route, we need to create it
1957 // and move it to the correct location
1959 RedirectList::iterator prev_last = _redirects.end();
1960 --prev_last; // We need this to check whether adding succeeded
1962 add_redirect_from_xml (**niter);
1964 RedirectList::iterator last = _redirects.end();
1967 if (prev_last == last) {
1968 cerr << "Could not fully restore state as some redirects were not possible to create" << endl;
1973 boost::shared_ptr<Redirect> tmp = (*last);
1974 // remove the redirect from the wrong location
1975 _redirects.erase(last);
1976 // insert the new redirect at the current location
1977 _redirects.insert(i, tmp);
1979 --i; // move pointer to the newly inserted redirect
1983 // We found the redirect (*niter) on the route, first we must make sure the redirect
1984 // is at the location provided in the XML state
1986 boost::shared_ptr<Redirect> tmp = (*o);
1987 // remove the old copy
1988 _redirects.erase(o);
1989 // insert the redirect at the correct location
1990 _redirects.insert(i, tmp);
1992 --i; // move pointer so it points to the right redirect
1995 (*i)->set_state( (**niter) );
1998 redirects_changed(this);
2002 Route::curve_reallocate ()
2004 // _gain_automation_curve.finish_resize ();
2005 // _pan_automation_curve.finish_resize ();
2009 Route::silence (nframes_t nframes, nframes_t offset)
2013 IO::silence (nframes, offset);
2015 if (_control_outs) {
2016 _control_outs->silence (nframes, offset);
2020 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2023 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2024 boost::shared_ptr<PluginInsert> pi;
2025 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2026 // skip plugins, they don't need anything when we're not active
2030 (*i)->silence (nframes, offset);
2033 if (nframes == _session.get_block_size() && offset == 0) {
2043 Route::set_control_outs (const vector<string>& ports)
2045 Glib::Mutex::Lock lm (control_outs_lock);
2046 vector<string>::const_iterator i;
2049 if (_control_outs) {
2050 delete _control_outs;
2054 if (control() || master()) {
2055 /* no control outs for these two special busses */
2059 if (ports.empty()) {
2063 string coutname = _name;
2064 coutname += _("[control]");
2066 _control_outs = new IO (_session, coutname);
2068 /* our control outs need as many outputs as we
2069 have audio outputs. we track the changes in ::output_change_handler().
2072 // XXX its stupid that we have to get this value twice
2074 limit = n_outputs().n_audio();
2076 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2080 /* now connect to the named ports */
2082 for (size_t n = 0; n < limit; ++n) {
2083 if (_control_outs->connect_output (_control_outs->output (n), ports[n], this)) {
2084 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2093 Route::set_edit_group (RouteGroup *eg, void *src)
2096 if (eg == _edit_group) {
2101 _edit_group->remove (this);
2104 if ((_edit_group = eg) != 0) {
2105 _edit_group->add (this);
2108 _session.set_dirty ();
2109 edit_group_changed (src); /* EMIT SIGNAL */
2113 Route::drop_edit_group (void *src)
2116 _session.set_dirty ();
2117 edit_group_changed (src); /* EMIT SIGNAL */
2121 Route::set_mix_group (RouteGroup *mg, void *src)
2124 if (mg == _mix_group) {
2129 _mix_group->remove (this);
2132 if ((_mix_group = mg) != 0) {
2133 _mix_group->add (this);
2136 _session.set_dirty ();
2137 mix_group_changed (src); /* EMIT SIGNAL */
2141 Route::drop_mix_group (void *src)
2144 _session.set_dirty ();
2145 mix_group_changed (src); /* EMIT SIGNAL */
2149 Route::set_comment (string cmt, void *src)
2152 comment_changed (src);
2153 _session.set_dirty ();
2157 Route::feeds (boost::shared_ptr<Route> other)
2162 uint32_t no = self.n_outputs().get_total();
2163 uint32_t ni = other->n_inputs ().get_total();
2165 for (i = 0; i < no; ++i) {
2166 for (j = 0; j < ni; ++j) {
2167 if (self.output(i)->connected_to (other->input(j)->name())) {
2173 /* check Redirects which may also interconnect Routes */
2175 for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); r++) {
2177 no = (*r)->n_outputs().get_total();
2179 for (i = 0; i < no; ++i) {
2180 for (j = 0; j < ni; ++j) {
2181 if ((*r)->output(i)->connected_to (other->input (j)->name())) {
2188 /* check for control room outputs which may also interconnect Routes */
2190 if (_control_outs) {
2192 no = _control_outs->n_outputs().get_total();
2194 for (i = 0; i < no; ++i) {
2195 for (j = 0; j < ni; ++j) {
2196 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2207 Route::set_mute_config (mute_type t, bool onoff, void *src)
2211 _mute_affects_pre_fader = onoff;
2212 pre_fader_changed(src); /* EMIT SIGNAL */
2216 _mute_affects_post_fader = onoff;
2217 post_fader_changed(src); /* EMIT SIGNAL */
2221 _mute_affects_control_outs = onoff;
2222 control_outs_changed(src); /* EMIT SIGNAL */
2226 _mute_affects_main_outs = onoff;
2227 main_outs_changed(src); /* EMIT SIGNAL */
2233 Route::get_mute_config (mute_type t)
2239 onoff = _mute_affects_pre_fader;
2242 onoff = _mute_affects_post_fader;
2245 onoff = _mute_affects_control_outs;
2248 onoff = _mute_affects_main_outs;
2256 Route::set_active (bool yn)
2259 active_changed(); /* EMIT SIGNAL */
2263 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_redirects)
2265 nframes_t now = _session.transport_frame();
2268 Glib::RWLock::ReaderLock lm (redirect_lock);
2271 automation_snapshot (now);
2274 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2276 if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
2277 (*i)->deactivate ();
2281 (*i)->transport_stopped (now);
2285 IO::transport_stopped (now);
2287 _roll_delay = _initial_delay;
2291 Route::input_change_handler (IOChange change, void *ignored)
2293 if (change & ConfigurationChanged) {
2294 reset_plugin_counts (0);
2299 Route::output_change_handler (IOChange change, void *ignored)
2301 if (change & ConfigurationChanged) {
2302 if (_control_outs) {
2303 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2306 reset_plugin_counts (0);
2311 Route::pans_required () const
2313 if (n_outputs().n_audio() < 2) {
2317 return max (n_inputs ().n_audio(), static_cast<size_t>(redirect_max_outs.n_audio()));
2321 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2322 bool session_state_changing, bool can_record, bool rec_monitors_input)
2324 if (n_outputs().get_total() == 0) {
2328 if (session_state_changing || !_active) {
2329 silence (nframes, offset);
2333 apply_gain_automation = false;
2335 if (n_inputs().get_total()) {
2336 passthru (start_frame, end_frame, nframes, offset, 0, false);
2338 silence (nframes, offset);
2345 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2347 if (_roll_delay > nframes) {
2349 _roll_delay -= nframes;
2350 silence (nframes, offset);
2351 /* transport frame is not legal for caller to use */
2354 } else if (_roll_delay > 0) {
2356 nframes -= _roll_delay;
2358 silence (_roll_delay, offset);
2360 offset += _roll_delay;
2361 transport_frame += _roll_delay;
2370 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2371 bool can_record, bool rec_monitors_input)
2374 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2376 // automation snapshot can also be called from the non-rt context
2377 // and it uses the redirect list, so we take the lock out here
2378 automation_snapshot (_session.transport_frame());
2382 if ((n_outputs().get_total() == 0 && _redirects.empty()) || n_inputs().get_total() == 0 || !_active) {
2383 silence (nframes, offset);
2387 nframes_t unused = 0;
2389 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2395 apply_gain_automation = false;
2398 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2400 if (am.locked() && _session.transport_rolling()) {
2402 if (gain_automation_playback()) {
2403 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2408 passthru (start_frame, end_frame, nframes, offset, declick, false);
2414 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2415 bool can_record, bool rec_monitors_input)
2417 silence (nframes, offset);
2422 Route::toggle_monitor_input ()
2424 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2425 i->ensure_monitor_input( ! i->monitoring_input());
2430 Route::has_external_redirects () const
2432 boost::shared_ptr<const PortInsert> pi;
2434 for (RedirectList::const_iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2435 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2437 for (PortSet::const_iterator port = pi->outputs().begin();
2438 port != pi->outputs().end(); ++port) {
2440 string port_name = port->name();
2441 string client_name = port_name.substr (0, port_name.find(':'));
2443 /* only say "yes" if the redirect is actually in use */
2445 if (client_name != "ardour" && pi->active()) {
2456 Route::flush_redirects ()
2458 /* XXX shouldn't really try to take this lock, since
2459 this is called from the RT audio thread.
2462 Glib::RWLock::ReaderLock lm (redirect_lock);
2464 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2465 (*i)->deactivate ();
2471 Route::set_meter_point (MeterPoint p, void *src)
2473 if (_meter_point != p) {
2475 meter_change (src); /* EMIT SIGNAL */
2476 _session.set_dirty ();
2481 Route::update_total_latency ()
2485 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2486 if ((*i)->active ()) {
2487 _own_latency += (*i)->latency ();
2491 set_port_latency (_own_latency);
2493 /* this (virtual) function is used for pure Routes,
2494 not derived classes like AudioTrack. this means
2495 that the data processed here comes from an input
2496 port, not prerecorded material, and therefore we
2497 have to take into account any input latency.
2500 _own_latency += input_latency ();
2502 return _own_latency;
2506 Route::set_latency_delay (nframes_t longest_session_latency)
2508 _initial_delay = longest_session_latency - _own_latency;
2510 if (_session.transport_stopped()) {
2511 _roll_delay = _initial_delay;
2516 Route::automation_snapshot (nframes_t now)
2518 IO::automation_snapshot (now);
2520 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2521 (*i)->automation_snapshot (now);
2525 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2526 : Controllable (name), route (s), type(tp)
2532 Route::ToggleControllable::set_value (float val)
2534 bool bval = ((val >= 0.5f) ? true: false);
2538 route.set_mute (bval, this);
2541 route.set_solo (bval, this);
2549 Route::ToggleControllable::get_value (void) const
2555 val = route.muted() ? 1.0f : 0.0f;
2558 val = route.soloed() ? 1.0f : 0.0f;
2568 Route::set_block_size (nframes_t nframes)
2570 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2571 (*i)->set_block_size (nframes);
2576 Route::redirect_active_proxy (Redirect* ignored, void* ignored_src)
2578 _session.update_latency_compensation (false, false);
2582 Route::protect_automation ()
2584 switch (gain_automation_state()) {
2586 set_gain_automation_state (Off);
2588 set_gain_automation_state (Play);
2594 switch (panner().automation_state ()) {
2596 panner().set_automation_state (Off);
2599 panner().set_automation_state (Play);
2605 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2606 boost::shared_ptr<PluginInsert> pi;
2607 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2608 pi->protect_automation ();
2614 Route::set_pending_declick (int declick)
2617 /* this call is not allowed to turn off a pending declick unless "force" is true */
2619 _pending_declick = declick;
2621 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2623 _pending_declick = 0;