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/buffer.h>
30 #include <ardour/audioengine.h>
31 #include <ardour/route.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/ladspa_plugin.h>
41 #include <ardour/panner.h>
42 #include <ardour/dB.h>
43 #include <ardour/mix.h>
48 using namespace ARDOUR;
52 uint32_t Route::order_key_cnt = 0;
55 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
56 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
58 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
59 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
64 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
65 : IO (sess, *node.child ("IO"), default_type),
66 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
67 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
70 _set_state (node, false);
76 redirect_max_outs = 0;
80 _phase_invert = false;
81 order_keys[strdup (N_("signal"))] = order_key_cnt++;
84 _meter_point = MeterPostFader;
88 _have_internal_generator = false;
90 _pending_declick = true;
91 _remote_control_id = 0;
92 _ignore_gain_on_deliver = true;
97 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
98 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
99 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
100 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
103 desired_solo_gain = 1.0;
105 desired_mute_gain = 1.0;
109 input_changed.connect (mem_fun (this, &Route::input_change_handler));
110 output_changed.connect (mem_fun (this, &Route::output_change_handler));
115 clear_redirects (PreFader, this);
116 clear_redirects (PostFader, this);
118 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
119 free ((void*)(i->first));
123 delete _control_outs;
128 Route::set_remote_control_id (uint32_t id)
130 if (id != _remote_control_id) {
131 _remote_control_id = id;
132 RemoteControlIDChanged ();
137 Route::remote_control_id() const
139 return _remote_control_id;
143 Route::order_key (const char* name) const
145 OrderKeys::const_iterator i;
147 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
148 if (!strcmp (name, i->first)) {
157 Route::set_order_key (const char* name, long n)
159 order_keys[strdup(name)] = n;
160 _session.set_dirty ();
164 Route::inc_gain (gain_t fraction, void *src)
166 IO::inc_gain (fraction, src);
170 Route::set_gain (gain_t val, void *src)
172 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
174 if (_mix_group->is_relative()) {
177 gain_t usable_gain = gain();
178 if (usable_gain < 0.000001f) {
179 usable_gain=0.000001f;
183 if (delta < 0.000001f) {
187 delta -= usable_gain;
189 if (delta == 0.0f) return;
191 gain_t factor = delta / usable_gain;
194 factor = _mix_group->get_max_factor(factor);
195 if (factor == 0.0f) {
200 factor = _mix_group->get_min_factor(factor);
201 if (factor == 0.0f) {
207 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
211 _mix_group->apply (&Route::set_gain, val, _mix_group);
221 IO::set_gain (val, src);
225 Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
226 nframes_t start_frame, nframes_t end_frame,
227 nframes_t nframes, nframes_t offset, bool with_redirects, int declick,
231 RedirectList::iterator i;
232 bool post_fader_work = false;
233 bool mute_declick_applied = false;
235 vector<Sample*>::iterator bufiter;
240 gain_t* gab = _session.gain_automation_buffer();
242 switch (Config->get_monitoring_model()) {
243 case HardwareMonitoring:
244 case ExternalMonitoring:
251 declick = _pending_declick;
254 Glib::Mutex::Lock cm (control_outs_lock, Glib::TRY_LOCK);
264 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
267 dmg = desired_mute_gain;
268 dsg = desired_solo_gain;
277 /* ----------------------------------------------------------------------------------------------------
278 GLOBAL DECLICK (for transport changes etc.)
279 -------------------------------------------------------------------------------------------------- */
282 apply_declick (bufs, nbufs, nframes, 0.0, 1.0, false);
283 _pending_declick = 0;
284 } else if (declick < 0) {
285 apply_declick (bufs, nbufs, nframes, 1.0, 0.0, false);
286 _pending_declick = 0;
289 /* no global declick */
291 if (solo_gain != dsg) {
292 apply_declick (bufs, nbufs, nframes, solo_gain, dsg, false);
298 /* ----------------------------------------------------------------------------------------------------
299 INPUT METERING & MONITORING
300 -------------------------------------------------------------------------------------------------- */
302 if (meter && (_meter_point == MeterInput)) {
303 for (n = 0; n < nbufs; ++n) {
304 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
308 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
309 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
311 mute_declick_applied = true;
314 if ((_meter_point == MeterInput) && co) {
316 solo_audible = dsg > 0;
317 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
319 if ( // muted by solo of another track
323 // muted by mute of this track
327 // rec-enabled but not s/w monitoring
329 // TODO: this is probably wrong
331 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
335 co->silence (nframes, offset);
339 co->deliver_output (bufs, nbufs, nframes, offset);
344 /* ----------------------------------------------------------------------------------------------------
346 -------------------------------------------------------------------------------------------------- */
348 if (with_redirects) {
349 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
351 if (mute_gain > 0 || !_mute_affects_pre_fader) {
352 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
353 switch ((*i)->placement()) {
356 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
357 (*i)->silence (nframes, offset);
360 (*i)->run (bufs, nbufs, nframes, offset);
364 post_fader_work = true;
369 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
370 switch ((*i)->placement()) {
372 (*i)->silence (nframes, offset);
375 post_fader_work = true;
384 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
385 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
387 mute_declick_applied = true;
390 /* ----------------------------------------------------------------------------------------------------
391 PRE-FADER METERING & MONITORING
392 -------------------------------------------------------------------------------------------------- */
394 if (meter && (_meter_point == MeterPreFader)) {
395 for (n = 0; n < nbufs; ++n) {
396 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
401 if ((_meter_point == MeterPreFader) && co) {
403 solo_audible = dsg > 0;
404 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
406 if ( // muted by solo of another track
410 // muted by mute of this track
414 // rec-enabled but not s/w monitoring
416 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
420 co->silence (nframes, offset);
424 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
429 /* ----------------------------------------------------------------------------------------------------
431 -------------------------------------------------------------------------------------------------- */
433 /* if not recording or recording and requiring any monitor signal, then apply gain */
435 if ( // not recording
437 !(record_enabled() && _session.actively_recording()) ||
441 // h/w monitoring not in use
443 (!Config->get_monitoring_model() == HardwareMonitoring &&
445 // AND software monitoring required
447 Config->get_monitoring_model() == SoftwareMonitoring)) {
449 if (apply_gain_automation) {
452 for (n = 0; n < nbufs; ++n) {
453 Sample *sp = bufs[n];
455 for (nframes_t nx = 0; nx < nframes; ++nx) {
460 for (n = 0; n < nbufs; ++n) {
461 Sample *sp = bufs[n];
463 for (nframes_t nx = 0; nx < nframes; ++nx) {
469 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
470 _effective_gain = gab[nframes-1];
475 /* manual (scalar) gain */
479 apply_declick (bufs, nbufs, nframes, _gain, dg, _phase_invert);
482 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
484 /* no need to interpolate current gain value,
485 but its non-unity, so apply it. if the gain
486 is zero, do nothing because we'll ship silence
498 for (n = 0; n < nbufs; ++n) {
499 Sample *sp = bufs[n];
500 Session::apply_gain_to_buffer(sp,nframes,this_gain);
503 } else if (_gain == 0) {
504 for (n = 0; n < nbufs; ++n) {
505 memset (bufs[n], 0, sizeof (Sample) * nframes);
512 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
516 /* ----------------------------------------------------------------------------------------------------
518 -------------------------------------------------------------------------------------------------- */
520 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
522 if (post_fader_work) {
524 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
526 if (mute_gain > 0 || !_mute_affects_post_fader) {
527 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
528 switch ((*i)->placement()) {
533 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
534 (*i)->silence (nframes, offset);
537 (*i)->run (bufs, nbufs, nframes, offset);
543 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
544 switch ((*i)->placement()) {
548 (*i)->silence (nframes, offset);
556 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
557 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
559 mute_declick_applied = true;
562 /* ----------------------------------------------------------------------------------------------------
564 -------------------------------------------------------------------------------------------------- */
566 if ((_meter_point == MeterPostFader) && co) {
568 solo_audible = solo_gain > 0;
569 mute_audible = dmg > 0 || !_mute_affects_control_outs;
571 if ( // silent anyway
573 (_gain == 0 && !apply_gain_automation) ||
575 // muted by solo of another track
579 // muted by mute of this track
583 // recording but not s/w monitoring
585 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
589 co->silence (nframes, offset);
593 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
597 /* ----------------------------------------------------------------------
599 ----------------------------------------------------------------------*/
601 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
602 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
604 mute_declick_applied = true;
607 /* ----------------------------------------------------------------------------------------------------
609 -------------------------------------------------------------------------------------------------- */
611 solo_audible = dsg > 0;
612 mute_audible = dmg > 0 || !_mute_affects_main_outs;
614 if (n_outputs() == 0) {
618 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
620 IO::silence (nframes, offset);
624 if ( // silent anyway
626 (_gain == 0 && !apply_gain_automation) ||
628 // muted by solo of another track, but not using control outs for solo
630 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
632 // muted by mute of this track
638 /* don't use Route::silence() here, because that causes
639 all outputs (sends, port inserts, etc. to be silent).
642 if (_meter_point == MeterPostFader) {
643 reset_peak_meters ();
646 IO::silence (nframes, offset);
650 if ((_session.transport_speed() > 1.5f ||
651 _session.transport_speed() < -1.5f) &&
652 Config->get_quieten_at_speed()) {
653 pan (bufs, nbufs, nframes, offset, speed_quietning);
655 // cerr << _name << " panner state = " << _panner->automation_state() << endl;
656 if (!_panner->empty() &&
657 (_panner->automation_state() & Play ||
658 ((_panner->automation_state() & Touch) && !_panner->touching()))) {
659 pan_automated (bufs, nbufs, start_frame, end_frame, nframes, offset);
661 pan (bufs, nbufs, nframes, offset, 1.0);
668 /* ----------------------------------------------------------------------------------------------------
670 -------------------------------------------------------------------------------------------------- */
672 if (meter && (_meter_point == MeterPostFader)) {
673 // cerr << "meter post" << endl;
675 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
676 uint32_t no = n_outputs();
677 for (n = 0; n < no; ++n) {
681 uint32_t no = n_outputs();
682 for (n = 0; n < no; ++n) {
683 _peak_power[n] = Session::compute_peak (output(n)->get_buffer (nframes) + offset, nframes, _peak_power[n]);
690 Route::n_process_buffers ()
692 return max (n_inputs(), redirect_max_outs);
697 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
699 vector<Sample*>& bufs = _session.get_passthru_buffers();
700 uint32_t limit = n_process_buffers ();
704 collect_input (bufs, limit, nframes, offset);
706 #define meter_stream meter_first
709 for (uint32_t n = 0; n < limit; ++n) {
710 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
712 meter_stream = false;
717 process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, true, declick, meter_stream);
723 Route::set_phase_invert (bool yn, void *src)
725 if (_phase_invert != yn) {
728 // phase_invert_changed (src); /* EMIT SIGNAL */
732 Route::set_solo (bool yn, void *src)
738 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
739 _mix_group->apply (&Route::set_solo, yn, _mix_group);
745 solo_changed (src); /* EMIT SIGNAL */
746 _solo_control.Changed (); /* EMIT SIGNAL */
751 Route::set_solo_mute (bool yn)
753 Glib::Mutex::Lock lm (declick_lock);
755 /* Called by Session in response to another Route being soloed.
758 desired_solo_gain = (yn?0.0:1.0);
762 Route::set_solo_safe (bool yn, void *src)
764 if (_solo_safe != yn) {
766 solo_safe_changed (src); /* EMIT SIGNAL */
771 Route::set_mute (bool yn, void *src)
774 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
775 _mix_group->apply (&Route::set_mute, yn, _mix_group);
781 mute_changed (src); /* EMIT SIGNAL */
783 _mute_control.Changed (); /* EMIT SIGNAL */
785 Glib::Mutex::Lock lm (declick_lock);
786 desired_mute_gain = (yn?0.0f:1.0f);
791 Route::add_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
793 uint32_t old_rmo = redirect_max_outs;
795 if (!_session.engine().connected()) {
800 Glib::RWLock::WriterLock lm (redirect_lock);
802 boost::shared_ptr<PluginInsert> pi;
803 boost::shared_ptr<PortInsert> porti;
805 uint32_t potential_max_streams = 0;
807 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redirect)) != 0) {
810 if (pi->input_streams() == 0) {
811 /* instrument plugin */
812 _have_internal_generator = true;
815 potential_max_streams = max(pi->input_streams(), pi->output_streams());
817 } else if ((porti = boost::dynamic_pointer_cast<PortInsert>(redirect)) != 0) {
819 /* force new port inserts to start out with an i/o configuration
820 that matches this route's i/o configuration.
822 the "inputs" for the port are supposed to match the output
825 the "outputs" of the route should match the inputs of this
826 route. XXX shouldn't they match the number of active signal
827 streams at the point of insertion?
831 porti->ensure_io (n_outputs (), n_inputs(), false, this);
834 // Ensure peak vector sizes before the plugin is activated
835 while (_peak_power.size() < potential_max_streams) {
836 _peak_power.push_back(0);
838 while (_visible_peak_power.size() < potential_max_streams) {
839 _visible_peak_power.push_back(-INFINITY);
841 while (_max_peak_power.size() < potential_max_streams) {
842 _max_peak_power.push_back(-INFINITY);
845 _redirects.push_back (redirect);
847 if (_reset_plugin_counts (err_streams)) {
848 _redirects.pop_back ();
849 _reset_plugin_counts (0); // it worked before we tried to add it ...
853 redirect->activate ();
854 redirect->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
857 if (redirect_max_outs != old_rmo || old_rmo == 0) {
862 redirects_changed (src); /* EMIT SIGNAL */
867 Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_streams)
869 uint32_t old_rmo = redirect_max_outs;
871 if (!_session.engine().connected()) {
876 Glib::RWLock::WriterLock lm (redirect_lock);
878 RedirectList::iterator existing_end = _redirects.end();
881 uint32_t potential_max_streams = 0;
883 for (RedirectList::const_iterator i = others.begin(); i != others.end(); ++i) {
885 boost::shared_ptr<PluginInsert> pi;
887 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
890 uint32_t m = max(pi->input_streams(), pi->output_streams());
891 if (m > potential_max_streams)
892 potential_max_streams = m;
895 // Ensure peak vector sizes before the plugin is activated
896 while (_peak_power.size() < potential_max_streams) {
897 _peak_power.push_back(0);
899 while (_visible_peak_power.size() < potential_max_streams) {
900 _visible_peak_power.push_back(-INFINITY);
902 while (_max_peak_power.size() < potential_max_streams) {
903 _max_peak_power.push_back(-INFINITY);
906 _redirects.push_back (*i);
908 if (_reset_plugin_counts (err_streams)) {
910 _redirects.erase (existing_end, _redirects.end());
911 _reset_plugin_counts (0); // it worked before we tried to add it ...
916 (*i)->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
920 if (redirect_max_outs != old_rmo || old_rmo == 0) {
924 redirects_changed (src); /* EMIT SIGNAL */
928 /** Remove redirects with a given placement.
929 * @param p Placement of redirects to remove.
932 Route::clear_redirects (Placement p, void *src)
934 const uint32_t old_rmo = redirect_max_outs;
936 if (!_session.engine().connected()) {
941 Glib::RWLock::WriterLock lm (redirect_lock);
942 RedirectList new_list;
944 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
945 if ((*i)->placement() == p) {
946 /* it's the placement we want to get rid of */
947 (*i)->drop_references ();
949 /* it's a different placement, so keep it */
950 new_list.push_back (*i);
954 _redirects = new_list;
957 /* FIXME: can't see how this test can ever fire */
958 if (redirect_max_outs != old_rmo) {
962 redirect_max_outs = 0;
963 _have_internal_generator = false;
964 redirects_changed (src); /* EMIT SIGNAL */
968 Route::remove_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
970 uint32_t old_rmo = redirect_max_outs;
972 if (!_session.engine().connected()) {
976 redirect_max_outs = 0;
979 Glib::RWLock::WriterLock lm (redirect_lock);
980 RedirectList::iterator i;
981 bool removed = false;
983 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
984 if (*i == redirect) {
986 RedirectList::iterator tmp;
988 /* move along, see failure case for reset_plugin_counts()
989 where we may need to reinsert the redirect.
995 /* stop redirects that send signals to JACK ports
996 from causing noise as a result of no longer being
1000 boost::shared_ptr<Send> send;
1001 boost::shared_ptr<PortInsert> port_insert;
1003 if ((send = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
1004 send->disconnect_inputs (this);
1005 send->disconnect_outputs (this);
1006 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (*i)) != 0) {
1007 port_insert->disconnect_inputs (this);
1008 port_insert->disconnect_outputs (this);
1011 _redirects.erase (i);
1024 if (_reset_plugin_counts (err_streams)) {
1025 /* get back to where we where */
1026 _redirects.insert (i, redirect);
1027 /* we know this will work, because it worked before :) */
1028 _reset_plugin_counts (0);
1034 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1035 boost::shared_ptr<PluginInsert> pi;
1037 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1038 if (pi->is_generator()) {
1044 _have_internal_generator = foo;
1047 if (old_rmo != redirect_max_outs) {
1051 redirect->drop_references ();
1053 redirects_changed (src); /* EMIT SIGNAL */
1058 Route::reset_plugin_counts (uint32_t* lpc)
1060 Glib::RWLock::WriterLock lm (redirect_lock);
1061 return _reset_plugin_counts (lpc);
1066 Route::_reset_plugin_counts (uint32_t* err_streams)
1068 RedirectList::iterator r;
1071 map<Placement,list<InsertCount> > insert_map;
1072 nframes_t initial_streams;
1074 redirect_max_outs = 0;
1078 /* divide inserts up by placement so we get the signal flow
1079 properly modelled. we need to do this because the _redirects
1080 list is not sorted by placement, and because other reasons may
1081 exist now or in the future for this separate treatment.
1084 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1086 boost::shared_ptr<Insert> insert;
1088 /* do this here in case we bomb out before we get to the end of
1092 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1094 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1096 insert_map[insert->placement()].push_back (InsertCount (insert));
1098 /* reset plugin counts back to one for now so
1099 that we have a predictable, controlled
1100 state to try to configure.
1103 boost::shared_ptr<PluginInsert> pi;
1105 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
1109 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1122 /* Now process each placement in order, checking to see if we
1123 can really do what has been requested.
1128 if (check_some_plugin_counts (insert_map[PreFader], n_inputs (), err_streams)) {
1132 /* figure out the streams that will feed into PreFader */
1134 if (!insert_map[PreFader].empty()) {
1135 InsertCount& ic (insert_map[PreFader].back());
1136 initial_streams = ic.insert->compute_output_streams (ic.cnt);
1138 initial_streams = n_inputs ();
1143 if (check_some_plugin_counts (insert_map[PostFader], initial_streams, err_streams)) {
1147 /* OK, everything can be set up correctly, so lets do it */
1149 apply_some_plugin_counts (insert_map[PreFader]);
1150 apply_some_plugin_counts (insert_map[PostFader]);
1152 /* recompute max outs of any redirect */
1156 redirect_max_outs = 0;
1157 RedirectList::iterator prev = _redirects.end();
1159 for (r = _redirects.begin(); r != _redirects.end(); prev = r, ++r) {
1160 boost::shared_ptr<Send> s;
1162 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1163 if (r == _redirects.begin()) {
1164 s->expect_inputs (n_inputs());
1166 s->expect_inputs ((*prev)->output_streams());
1171 /* don't pay any attention to send output configuration, since it doesn't
1175 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1186 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1188 list<InsertCount>::iterator i;
1190 for (i = iclist.begin(); i != iclist.end(); ++i) {
1192 if ((*i).insert->configure_io ((*i).cnt, (*i).in, (*i).out)) {
1195 /* make sure that however many we have, they are all active */
1196 (*i).insert->activate ();
1203 Route::check_some_plugin_counts (list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams)
1205 list<InsertCount>::iterator i;
1207 for (i = iclist.begin(); i != iclist.end(); ++i) {
1209 if (((*i).cnt = (*i).insert->can_support_input_configuration (required_inputs)) < 0) {
1211 *err_streams = required_inputs;
1216 (*i).in = required_inputs;
1217 (*i).out = (*i).insert->compute_output_streams ((*i).cnt);
1219 required_inputs = (*i).out;
1226 Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_streams)
1228 uint32_t old_rmo = redirect_max_outs;
1234 RedirectList to_be_deleted;
1237 Glib::RWLock::WriterLock lm (redirect_lock);
1238 RedirectList::iterator tmp;
1239 RedirectList the_copy;
1241 the_copy = _redirects;
1243 /* remove all relevant redirects */
1245 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1249 if ((*i)->placement() == placement) {
1250 to_be_deleted.push_back (*i);
1251 _redirects.erase (i);
1257 /* now copy the relevant ones from "other" */
1259 for (RedirectList::const_iterator i = other._redirects.begin(); i != other._redirects.end(); ++i) {
1260 if ((*i)->placement() == placement) {
1261 _redirects.push_back (Redirect::clone (*i));
1265 /* reset plugin stream handling */
1267 if (_reset_plugin_counts (err_streams)) {
1269 /* FAILED COPY ATTEMPT: we have to restore order */
1271 /* delete all cloned redirects */
1273 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1278 if ((*i)->placement() == placement) {
1279 _redirects.erase (i);
1285 /* restore the natural order */
1287 _redirects = the_copy;
1288 redirect_max_outs = old_rmo;
1290 /* we failed, even though things are OK again */
1296 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1297 to_be_deleted.clear ();
1301 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1305 redirects_changed (this); /* EMIT SIGNAL */
1310 Route::all_redirects_flip ()
1312 Glib::RWLock::ReaderLock lm (redirect_lock);
1314 if (_redirects.empty()) {
1318 bool first_is_on = _redirects.front()->active();
1320 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1321 (*i)->set_active (!first_is_on, this);
1325 /** Set all redirects with a given placement to a given active state.
1326 * @param p Placement of redirects to change.
1327 * @param state New active state for those redirects.
1330 Route::all_redirects_active (Placement p, bool state)
1332 Glib::RWLock::ReaderLock lm (redirect_lock);
1334 if (_redirects.empty()) {
1338 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1339 if ((*i)->placement() == p) {
1340 (*i)->set_active (state, this);
1345 struct RedirectSorter {
1346 bool operator() (boost::shared_ptr<const Redirect> a, boost::shared_ptr<const Redirect> b) {
1347 return a->sort_key() < b->sort_key();
1352 Route::sort_redirects (uint32_t* err_streams)
1355 RedirectSorter comparator;
1356 Glib::RWLock::WriterLock lm (redirect_lock);
1357 uint32_t old_rmo = redirect_max_outs;
1359 /* the sweet power of C++ ... */
1361 RedirectList as_it_was_before = _redirects;
1363 _redirects.sort (comparator);
1365 if (_reset_plugin_counts (err_streams)) {
1366 _redirects = as_it_was_before;
1367 redirect_max_outs = old_rmo;
1373 redirects_changed (this); /* EMIT SIGNAL */
1385 Route::get_template()
1387 return state(false);
1391 Route::state(bool full_state)
1393 XMLNode *node = new XMLNode("Route");
1394 RedirectList:: iterator i;
1398 node->add_property("flags", enum_2_string (_flags));
1401 node->add_property("default-type", _default_type.to_string());
1403 node->add_property("active", _active?"yes":"no");
1404 node->add_property("muted", _muted?"yes":"no");
1405 node->add_property("soloed", _soloed?"yes":"no");
1406 node->add_property("phase-invert", _phase_invert?"yes":"no");
1407 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1408 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1409 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1410 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1413 node->add_property("edit-group", _edit_group->name());
1416 node->add_property("mix-group", _mix_group->name());
1419 string order_string;
1420 OrderKeys::iterator x = order_keys.begin();
1422 while (x != order_keys.end()) {
1423 order_string += string ((*x).first);
1424 order_string += '=';
1425 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1426 order_string += buf;
1430 if (x == order_keys.end()) {
1434 order_string += ':';
1436 node->add_property ("order-keys", order_string);
1438 node->add_child_nocopy (IO::state (full_state));
1439 node->add_child_nocopy (_solo_control.get_state ());
1440 node->add_child_nocopy (_mute_control.get_state ());
1442 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1443 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1444 remote_control_node->add_property (X_("id"), buf);
1445 node->add_child_nocopy (*remote_control_node);
1447 if (_control_outs) {
1448 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1449 cnode->add_child_nocopy (_control_outs->state (full_state));
1450 node->add_child_nocopy (*cnode);
1453 if (_comment.length()) {
1454 XMLNode *cmt = node->add_child ("Comment");
1455 cmt->add_content (_comment);
1458 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1459 node->add_child_nocopy((*i)->state (full_state));
1463 node->add_child_copy (*_extra_xml);
1470 Route::set_deferred_state ()
1473 XMLNodeConstIterator niter;
1475 if (!deferred_state) {
1479 nlist = deferred_state->children();
1481 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1482 add_redirect_from_xml (**niter);
1485 delete deferred_state;
1490 Route::add_redirect_from_xml (const XMLNode& node)
1492 const XMLProperty *prop;
1494 if (node.name() == "Send") {
1498 boost::shared_ptr<Send> send (new Send (_session, node));
1499 add_redirect (send, this);
1502 catch (failed_constructor &err) {
1503 error << _("Send construction failed") << endmsg;
1507 } else if (node.name() == "Insert") {
1510 if ((prop = node.property ("type")) != 0) {
1512 boost::shared_ptr<Insert> insert;
1514 if (prop->value() == "ladspa" || prop->value() == "Ladspa" || prop->value() == "vst") {
1516 insert.reset (new PluginInsert(_session, node));
1518 } else if (prop->value() == "port") {
1521 insert.reset (new PortInsert (_session, node));
1525 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1528 add_redirect (insert, this);
1531 error << _("Insert XML node has no type property") << endmsg;
1535 catch (failed_constructor &err) {
1536 warning << _("insert could not be created. Ignored.") << endmsg;
1543 Route::set_state (const XMLNode& node)
1545 return _set_state (node, true);
1549 Route::_set_state (const XMLNode& node, bool call_base)
1552 XMLNodeConstIterator niter;
1554 XMLPropertyList plist;
1555 const XMLProperty *prop;
1557 if (node.name() != "Route"){
1558 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1562 if ((prop = node.property (X_("flags"))) != 0) {
1563 _flags = Flag (string_2_enum (prop->value(), _flags));
1568 if ((prop = node.property (X_("default-type"))) != 0) {
1569 _default_type = DataType(prop->value());
1570 assert(_default_type != DataType::NIL);
1573 if ((prop = node.property (X_("phase-invert"))) != 0) {
1574 set_phase_invert(prop->value()=="yes"?true:false, this);
1577 if ((prop = node.property (X_("active"))) != 0) {
1578 set_active (prop->value() == "yes");
1581 if ((prop = node.property (X_("muted"))) != 0) {
1582 bool yn = prop->value()=="yes"?true:false;
1584 /* force reset of mute status */
1588 mute_gain = desired_mute_gain;
1591 if ((prop = node.property (X_("soloed"))) != 0) {
1592 bool yn = prop->value()=="yes"?true:false;
1594 /* force reset of solo status */
1597 set_solo (yn, this);
1598 solo_gain = desired_solo_gain;
1601 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1602 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1605 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1606 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1609 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1610 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1613 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1614 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1617 if ((prop = node.property (X_("edit-group"))) != 0) {
1618 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1619 if(edit_group == 0) {
1620 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1622 set_edit_group(edit_group, this);
1626 if ((prop = node.property (X_("order-keys"))) != 0) {
1630 string::size_type colon, equal;
1631 string remaining = prop->value();
1633 while (remaining.length()) {
1635 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1636 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1639 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1640 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1643 set_order_key (remaining.substr (0, equal).c_str(), n);
1647 colon = remaining.find_first_of (':');
1649 if (colon != string::npos) {
1650 remaining = remaining.substr (colon+1);
1657 nlist = node.children();
1659 if (deferred_state) {
1660 delete deferred_state;
1663 deferred_state = new XMLNode(X_("deferred state"));
1665 /* set parent class properties before anything else */
1667 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1671 if (child->name() == IO::state_node_name && call_base) {
1673 IO::set_state (*child);
1680 /* if ports are not legal, this will happen in set_deferred_state() */
1682 XMLNodeList redirect_nodes;
1684 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1688 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1689 redirect_nodes.push_back(child);
1694 _set_redirect_states (redirect_nodes);
1698 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1700 // All redirects (sends and inserts) have been applied already
1702 if (child->name() == X_("Automation")) {
1704 if ((prop = child->property (X_("path"))) != 0) {
1705 load_automation (prop->value());
1708 } else if (child->name() == X_("ControlOuts")) {
1710 string coutname = _name;
1711 coutname += _("[control]");
1713 _control_outs = new IO (_session, coutname);
1714 _control_outs->set_state (**(child->children().begin()));
1716 } else if (child->name() == X_("Comment")) {
1718 /* XXX this is a terrible API design in libxml++ */
1720 XMLNode *cmt = *(child->children().begin());
1721 _comment = cmt->content();
1723 } else if (child->name() == X_("extra")) {
1725 _extra_xml = new XMLNode (*child);
1727 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1729 if (prop->value() == "solo") {
1730 _solo_control.set_state (*child);
1731 _session.add_controllable (&_solo_control);
1733 else if (prop->value() == "mute") {
1734 _mute_control.set_state (*child);
1735 _session.add_controllable (&_mute_control);
1738 else if (child->name() == X_("remote_control")) {
1739 if ((prop = child->property (X_("id"))) != 0) {
1741 sscanf (prop->value().c_str(), "%d", &x);
1742 set_remote_control_id (x);
1747 if ((prop = node.property (X_("mix-group"))) != 0) {
1748 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1749 if (mix_group == 0) {
1750 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1752 set_mix_group(mix_group, this);
1760 Route::_set_redirect_states(const XMLNodeList &nlist)
1762 XMLNodeConstIterator niter;
1765 RedirectList::iterator i, o;
1767 // Iterate through existing redirects, remove those which are not in the state list
1768 for (i = _redirects.begin(); i != _redirects.end(); ) {
1769 RedirectList::iterator tmp = i;
1772 bool redirectInStateList = false;
1774 (*i)->id().print (buf, sizeof (buf));
1777 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1779 if (strncmp(buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1780 redirectInStateList = true;
1785 if (!redirectInStateList) {
1786 remove_redirect ( *i, this);
1794 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1795 // set the state of existing redirects according to the new state on the same go
1796 i = _redirects.begin();
1797 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1799 // Check whether the next redirect in the list
1802 while (o != _redirects.end()) {
1803 (*o)->id().print (buf, sizeof (buf));
1804 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1809 if (o == _redirects.end()) {
1810 // If the redirect (*niter) is not on the route, we need to create it
1811 // and move it to the correct location
1813 RedirectList::iterator prev_last = _redirects.end();
1814 --prev_last; // We need this to check whether adding succeeded
1816 add_redirect_from_xml (**niter);
1818 RedirectList::iterator last = _redirects.end();
1821 if (prev_last == last) {
1822 warning << _name << ": could not fully restore state as some redirects were not possible to create" << endmsg;
1827 boost::shared_ptr<Redirect> tmp = (*last);
1828 // remove the redirect from the wrong location
1829 _redirects.erase(last);
1830 // insert the new redirect at the current location
1831 _redirects.insert(i, tmp);
1833 --i; // move pointer to the newly inserted redirect
1837 // We found the redirect (*niter) on the route, first we must make sure the redirect
1838 // is at the location provided in the XML state
1840 boost::shared_ptr<Redirect> tmp = (*o);
1841 // remove the old copy
1842 _redirects.erase(o);
1843 // insert the redirect at the correct location
1844 _redirects.insert(i, tmp);
1846 --i; // move pointer so it points to the right redirect
1849 (*i)->set_state( (**niter) );
1852 redirects_changed(this);
1856 Route::curve_reallocate ()
1858 // _gain_automation_curve.finish_resize ();
1859 // _pan_automation_curve.finish_resize ();
1863 Route::silence (nframes_t nframes, nframes_t offset)
1867 // reset_peak_meters ();
1869 IO::silence (nframes, offset);
1871 if (_control_outs) {
1872 _control_outs->silence (nframes, offset);
1876 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
1879 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1880 boost::shared_ptr<PluginInsert> pi;
1881 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1882 // skip plugins, they don't need anything when we're not active
1886 (*i)->silence (nframes, offset);
1889 if (nframes == _session.get_block_size() && offset == 0) {
1899 Route::set_control_outs (const vector<string>& ports)
1901 Glib::Mutex::Lock lm (control_outs_lock);
1902 vector<string>::const_iterator i;
1905 if (_control_outs) {
1906 delete _control_outs;
1910 if (control() || master()) {
1911 /* no control outs for these two special busses */
1915 if (ports.empty()) {
1919 string coutname = _name;
1920 coutname += _("[control]");
1922 _control_outs = new IO (_session, coutname);
1924 /* our control outs need as many outputs as we
1925 have outputs. we track the changes in ::output_change_handler().
1928 limit = n_outputs ();
1930 if (_control_outs->ensure_io (0, limit, true, this)) {
1934 /* now connect to the named ports */
1936 for (uint32_t n = 0; n < limit; ++n) {
1937 if (_control_outs->connect_output (_control_outs->output (n), ports[n], this)) {
1938 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
1947 Route::set_edit_group (RouteGroup *eg, void *src)
1950 if (eg == _edit_group) {
1955 _edit_group->remove (this);
1958 if ((_edit_group = eg) != 0) {
1959 _edit_group->add (this);
1962 _session.set_dirty ();
1963 edit_group_changed (src); /* EMIT SIGNAL */
1967 Route::drop_edit_group (void *src)
1970 _session.set_dirty ();
1971 edit_group_changed (src); /* EMIT SIGNAL */
1975 Route::set_mix_group (RouteGroup *mg, void *src)
1978 if (mg == _mix_group) {
1983 _mix_group->remove (this);
1986 if ((_mix_group = mg) != 0) {
1987 _mix_group->add (this);
1990 _session.set_dirty ();
1991 mix_group_changed (src); /* EMIT SIGNAL */
1995 Route::drop_mix_group (void *src)
1998 _session.set_dirty ();
1999 mix_group_changed (src); /* EMIT SIGNAL */
2003 Route::set_comment (string cmt, void *src)
2006 comment_changed (src);
2007 _session.set_dirty ();
2011 Route::feeds (boost::shared_ptr<Route> other)
2016 uint32_t no = self.n_outputs();
2017 uint32_t ni = other->n_inputs ();
2019 for (i = 0; i < no; ++i) {
2020 for (j = 0; j < ni; ++j) {
2021 if (self.output(i)->connected_to (other->input(j)->name())) {
2027 /* check Redirects which may also interconnect Routes */
2029 for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); r++) {
2031 no = (*r)->n_outputs();
2033 for (i = 0; i < no; ++i) {
2034 for (j = 0; j < ni; ++j) {
2035 if ((*r)->output(i)->connected_to (other->input (j)->name())) {
2042 /* check for control room outputs which may also interconnect Routes */
2044 if (_control_outs) {
2046 no = _control_outs->n_outputs();
2048 for (i = 0; i < no; ++i) {
2049 for (j = 0; j < ni; ++j) {
2050 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2061 Route::set_mute_config (mute_type t, bool onoff, void *src)
2065 _mute_affects_pre_fader = onoff;
2066 pre_fader_changed(src); /* EMIT SIGNAL */
2070 _mute_affects_post_fader = onoff;
2071 post_fader_changed(src); /* EMIT SIGNAL */
2075 _mute_affects_control_outs = onoff;
2076 control_outs_changed(src); /* EMIT SIGNAL */
2080 _mute_affects_main_outs = onoff;
2081 main_outs_changed(src); /* EMIT SIGNAL */
2087 Route::get_mute_config (mute_type t)
2093 onoff = _mute_affects_pre_fader;
2096 onoff = _mute_affects_post_fader;
2099 onoff = _mute_affects_control_outs;
2102 onoff = _mute_affects_main_outs;
2110 Route::set_active (bool yn)
2113 active_changed(); /* EMIT SIGNAL */
2117 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_redirects)
2119 nframes_t now = _session.transport_frame();
2122 Glib::RWLock::ReaderLock lm (redirect_lock);
2125 automation_snapshot (now);
2128 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2130 if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
2131 (*i)->deactivate ();
2135 (*i)->transport_stopped (now);
2139 IO::transport_stopped (now);
2141 _roll_delay = _initial_delay;
2145 Route::input_change_handler (IOChange change, void *ignored)
2147 if (change & ConfigurationChanged) {
2148 reset_plugin_counts (0);
2153 Route::output_change_handler (IOChange change, void *ignored)
2155 if (change & ConfigurationChanged) {
2156 if (_control_outs) {
2157 _control_outs->ensure_io (0, n_outputs(), true, this);
2160 reset_plugin_counts (0);
2165 Route::pans_required () const
2167 if (n_outputs() < 2) {
2171 return max (n_inputs (), redirect_max_outs);
2175 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2176 bool session_state_changing, bool can_record, bool rec_monitors_input)
2178 if (n_outputs() == 0) {
2182 if (session_state_changing || !_active) {
2183 silence (nframes, offset);
2187 apply_gain_automation = false;
2190 passthru (start_frame, end_frame, nframes, offset, 0, false);
2192 silence (nframes, offset);
2199 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2201 if (_roll_delay > nframes) {
2203 _roll_delay -= nframes;
2204 silence (nframes, offset);
2205 /* transport frame is not legal for caller to use */
2208 } else if (_roll_delay > 0) {
2210 nframes -= _roll_delay;
2212 silence (_roll_delay, offset);
2214 offset += _roll_delay;
2215 transport_frame += _roll_delay;
2224 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2225 bool can_record, bool rec_monitors_input)
2228 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2230 // automation snapshot can also be called from the non-rt context
2231 // and it uses the redirect list, so we take the lock out here
2232 automation_snapshot (_session.transport_frame());
2236 if ((n_outputs() == 0 && _redirects.empty()) || n_inputs() == 0 || !_active) {
2237 silence (nframes, offset);
2241 nframes_t unused = 0;
2243 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2249 apply_gain_automation = false;
2252 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2254 if (am.locked() && _session.transport_rolling()) {
2256 nframes_t start_frame = end_frame - nframes;
2258 if (gain_automation_playback()) {
2259 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2264 passthru (start_frame, end_frame, nframes, offset, declick, false);
2270 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2271 bool can_record, bool rec_monitors_input)
2273 silence (nframes, offset);
2278 Route::toggle_monitor_input ()
2280 for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2281 (*i)->ensure_monitor_input(!(*i)->monitoring_input());
2286 Route::has_external_redirects () const
2288 boost::shared_ptr<const PortInsert> pi;
2290 for (RedirectList::const_iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2291 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2293 uint32_t no = pi->n_outputs();
2295 for (uint32_t n = 0; n < no; ++n) {
2297 string port_name = pi->output(n)->name();
2298 string client_name = port_name.substr (0, port_name.find(':'));
2300 /* only say "yes" if the redirect is actually in use */
2302 if (client_name != "ardour" && pi->active()) {
2313 Route::flush_redirects ()
2315 /* XXX shouldn't really try to take this lock, since
2316 this is called from the RT audio thread.
2319 Glib::RWLock::ReaderLock lm (redirect_lock);
2321 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2322 (*i)->deactivate ();
2328 Route::set_meter_point (MeterPoint p, void *src)
2330 if (_meter_point != p) {
2332 meter_change (src); /* EMIT SIGNAL */
2333 _session.set_dirty ();
2338 Route::update_total_latency ()
2342 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2343 if ((*i)->active ()) {
2344 _own_latency += (*i)->latency ();
2348 set_port_latency (_own_latency);
2350 /* this (virtual) function is used for pure Routes,
2351 not derived classes like AudioTrack. this means
2352 that the data processed here comes from an input
2353 port, not prerecorded material, and therefore we
2354 have to take into account any input latency.
2357 _own_latency += input_latency ();
2359 return _own_latency;
2363 Route::set_latency_delay (nframes_t longest_session_latency)
2365 _initial_delay = longest_session_latency - _own_latency;
2367 if (_session.transport_stopped()) {
2368 _roll_delay = _initial_delay;
2373 Route::automation_snapshot (nframes_t now)
2375 IO::automation_snapshot (now);
2377 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2378 (*i)->automation_snapshot (now);
2382 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2383 : Controllable (name), route (s), type(tp)
2389 Route::ToggleControllable::set_value (float val)
2391 bool bval = ((val >= 0.5f) ? true: false);
2395 route.set_mute (bval, this);
2398 route.set_solo (bval, this);
2406 Route::ToggleControllable::get_value (void) const
2412 val = route.muted() ? 1.0f : 0.0f;
2415 val = route.soloed() ? 1.0f : 0.0f;
2425 Route::set_block_size (nframes_t nframes)
2427 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2428 (*i)->set_block_size (nframes);
2433 Route::redirect_active_proxy (Redirect* ignored, void* ignored_src)
2435 _session.update_latency_compensation (false, false);
2439 Route::protect_automation ()
2441 switch (gain_automation_state()) {
2443 set_gain_automation_state (Off);
2445 set_gain_automation_state (Play);
2451 switch (panner().automation_state ()) {
2453 panner().set_automation_state (Off);
2456 panner().set_automation_state (Play);
2462 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2463 boost::shared_ptr<PluginInsert> pi;
2464 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2465 pi->protect_automation ();
2471 Route::set_pending_declick (int declick)
2474 /* this call is not allowed to turn off a pending declick unless "force" is true */
2476 _pending_declick = declick;
2478 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2480 _pending_declick = 0;