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;
51 uint32_t Route::order_key_cnt = 0;
54 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
55 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
57 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
58 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
63 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
64 : IO (sess, *node.child ("IO"), default_type),
65 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
66 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
69 _set_state (node, false);
75 redirect_max_outs = 0;
79 _phase_invert = false;
80 _denormal_protection = 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 (_denormal_protection || Config->get_denormal_protection()) {
350 for (n = 0; n < nbufs; ++n) {
351 Sample *sp = bufs[n];
353 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
360 /* ----------------------------------------------------------------------------------------------------
362 -------------------------------------------------------------------------------------------------- */
364 if (with_redirects) {
365 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
367 if (mute_gain > 0 || !_mute_affects_pre_fader) {
368 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
369 switch ((*i)->placement()) {
372 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
373 (*i)->silence (nframes, offset);
376 (*i)->run (bufs, nbufs, nframes, offset);
380 post_fader_work = true;
385 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
386 switch ((*i)->placement()) {
388 (*i)->silence (nframes, offset);
391 post_fader_work = true;
400 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
401 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
403 mute_declick_applied = true;
406 /* ----------------------------------------------------------------------------------------------------
407 PRE-FADER METERING & MONITORING
408 -------------------------------------------------------------------------------------------------- */
410 if (meter && (_meter_point == MeterPreFader)) {
411 for (n = 0; n < nbufs; ++n) {
412 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
417 if ((_meter_point == MeterPreFader) && co) {
419 solo_audible = dsg > 0;
420 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
422 if ( // muted by solo of another track
426 // muted by mute of this track
430 // rec-enabled but not s/w monitoring
432 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
436 co->silence (nframes, offset);
440 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
445 /* ----------------------------------------------------------------------------------------------------
447 -------------------------------------------------------------------------------------------------- */
449 /* if not recording or recording and requiring any monitor signal, then apply gain */
451 if ( // not recording
453 !(record_enabled() && _session.actively_recording()) ||
457 // h/w monitoring not in use
459 (!Config->get_monitoring_model() == HardwareMonitoring &&
461 // AND software monitoring required
463 Config->get_monitoring_model() == SoftwareMonitoring)) {
465 if (apply_gain_automation) {
468 for (n = 0; n < nbufs; ++n) {
469 Sample *sp = bufs[n];
471 for (nframes_t nx = 0; nx < nframes; ++nx) {
476 for (n = 0; n < nbufs; ++n) {
477 Sample *sp = bufs[n];
479 for (nframes_t nx = 0; nx < nframes; ++nx) {
485 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
486 _effective_gain = gab[nframes-1];
491 /* manual (scalar) gain */
495 apply_declick (bufs, nbufs, nframes, _gain, dg, _phase_invert);
498 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
500 /* no need to interpolate current gain value,
501 but its non-unity, so apply it. if the gain
502 is zero, do nothing because we'll ship silence
514 for (n = 0; n < nbufs; ++n) {
515 Sample *sp = bufs[n];
516 Session::apply_gain_to_buffer(sp,nframes,this_gain);
519 } else if (_gain == 0) {
520 for (n = 0; n < nbufs; ++n) {
521 memset (bufs[n], 0, sizeof (Sample) * nframes);
528 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
532 /* ----------------------------------------------------------------------------------------------------
534 -------------------------------------------------------------------------------------------------- */
536 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
538 if (post_fader_work) {
540 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
542 if (mute_gain > 0 || !_mute_affects_post_fader) {
543 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
544 switch ((*i)->placement()) {
549 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
550 (*i)->silence (nframes, offset);
553 (*i)->run (bufs, nbufs, nframes, offset);
559 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
560 switch ((*i)->placement()) {
564 (*i)->silence (nframes, offset);
572 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
573 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
575 mute_declick_applied = true;
578 /* ----------------------------------------------------------------------------------------------------
580 -------------------------------------------------------------------------------------------------- */
582 if ((_meter_point == MeterPostFader) && co) {
584 solo_audible = solo_gain > 0;
585 mute_audible = dmg > 0 || !_mute_affects_control_outs;
587 if ( // silent anyway
589 (_gain == 0 && !apply_gain_automation) ||
591 // muted by solo of another track
595 // muted by mute of this track
599 // recording but not s/w monitoring
601 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
605 co->silence (nframes, offset);
609 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
613 /* ----------------------------------------------------------------------
615 ----------------------------------------------------------------------*/
617 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
618 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
620 mute_declick_applied = true;
623 /* ----------------------------------------------------------------------------------------------------
625 -------------------------------------------------------------------------------------------------- */
627 solo_audible = dsg > 0;
628 mute_audible = dmg > 0 || !_mute_affects_main_outs;
630 if (n_outputs() == 0) {
634 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
636 IO::silence (nframes, offset);
640 if ( // silent anyway
642 (_gain == 0 && !apply_gain_automation) ||
644 // muted by solo of another track, but not using control outs for solo
646 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
648 // muted by mute of this track
654 /* don't use Route::silence() here, because that causes
655 all outputs (sends, port inserts, etc. to be silent).
658 if (_meter_point == MeterPostFader) {
659 reset_peak_meters ();
662 IO::silence (nframes, offset);
666 if ((_session.transport_speed() > 1.5f ||
667 _session.transport_speed() < -1.5f) &&
668 Config->get_quieten_at_speed()) {
669 pan (bufs, nbufs, nframes, offset, speed_quietning);
671 // cerr << _name << " panner state = " << _panner->automation_state() << endl;
672 if (!_panner->empty() &&
673 (_panner->automation_state() & Play ||
674 ((_panner->automation_state() & Touch) && !_panner->touching()))) {
675 pan_automated (bufs, nbufs, start_frame, end_frame, nframes, offset);
677 pan (bufs, nbufs, nframes, offset, 1.0);
684 /* ----------------------------------------------------------------------------------------------------
686 -------------------------------------------------------------------------------------------------- */
688 if (meter && (_meter_point == MeterPostFader)) {
689 // cerr << "meter post" << endl;
691 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
692 uint32_t no = n_outputs();
693 for (n = 0; n < no; ++n) {
697 uint32_t no = n_outputs();
698 for (n = 0; n < no; ++n) {
699 _peak_power[n] = Session::compute_peak (output(n)->get_buffer (nframes) + offset, nframes, _peak_power[n]);
706 Route::n_process_buffers ()
708 return max (n_inputs(), redirect_max_outs);
713 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
715 vector<Sample*>& bufs = _session.get_passthru_buffers();
716 uint32_t limit = n_process_buffers ();
720 collect_input (bufs, limit, nframes, offset);
722 #define meter_stream meter_first
725 for (uint32_t n = 0; n < limit; ++n) {
726 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
728 meter_stream = false;
733 process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, true, declick, meter_stream);
739 Route::set_phase_invert (bool yn, void *src)
741 if (_phase_invert != yn) {
743 // phase_invert_changed (src); /* EMIT SIGNAL */
748 Route::set_denormal_protection (bool yn, void *src)
750 if (_denormal_protection != yn) {
751 _denormal_protection = yn;
752 // denormal_protection_changed (src); /* EMIT SIGNAL */
757 Route::set_solo (bool yn, void *src)
763 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
764 _mix_group->apply (&Route::set_solo, yn, _mix_group);
770 solo_changed (src); /* EMIT SIGNAL */
771 _solo_control.Changed (); /* EMIT SIGNAL */
776 Route::set_solo_mute (bool yn)
778 Glib::Mutex::Lock lm (declick_lock);
780 /* Called by Session in response to another Route being soloed.
783 desired_solo_gain = (yn?0.0:1.0);
787 Route::set_solo_safe (bool yn, void *src)
789 if (_solo_safe != yn) {
791 solo_safe_changed (src); /* EMIT SIGNAL */
796 Route::set_mute (bool yn, void *src)
799 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
800 _mix_group->apply (&Route::set_mute, yn, _mix_group);
806 mute_changed (src); /* EMIT SIGNAL */
808 _mute_control.Changed (); /* EMIT SIGNAL */
810 Glib::Mutex::Lock lm (declick_lock);
811 desired_mute_gain = (yn?0.0f:1.0f);
816 Route::add_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
818 uint32_t old_rmo = redirect_max_outs;
820 if (!_session.engine().connected()) {
825 Glib::RWLock::WriterLock lm (redirect_lock);
827 boost::shared_ptr<PluginInsert> pi;
828 boost::shared_ptr<PortInsert> porti;
830 uint32_t potential_max_streams = 0;
832 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redirect)) != 0) {
835 if (pi->input_streams() == 0) {
836 /* instrument plugin */
837 _have_internal_generator = true;
840 potential_max_streams = max(pi->input_streams(), pi->output_streams());
842 } else if ((porti = boost::dynamic_pointer_cast<PortInsert>(redirect)) != 0) {
844 /* force new port inserts to start out with an i/o configuration
845 that matches this route's i/o configuration.
847 the "inputs" for the port are supposed to match the output
850 the "outputs" of the route should match the inputs of this
851 route. XXX shouldn't they match the number of active signal
852 streams at the point of insertion?
856 porti->ensure_io (n_outputs (), n_inputs(), false, this);
859 // Ensure peak vector sizes before the plugin is activated
860 while (_peak_power.size() < potential_max_streams) {
861 _peak_power.push_back(0);
863 while (_visible_peak_power.size() < potential_max_streams) {
864 _visible_peak_power.push_back(-INFINITY);
866 while (_max_peak_power.size() < potential_max_streams) {
867 _max_peak_power.push_back(-INFINITY);
870 _redirects.push_back (redirect);
872 if (_reset_plugin_counts (err_streams)) {
873 _redirects.pop_back ();
874 _reset_plugin_counts (0); // it worked before we tried to add it ...
878 redirect->activate ();
879 redirect->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
882 if (redirect_max_outs != old_rmo || old_rmo == 0) {
887 redirects_changed (src); /* EMIT SIGNAL */
892 Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_streams)
894 uint32_t old_rmo = redirect_max_outs;
896 assert (ports_legal);
898 if (!_session.engine().connected()) {
903 Glib::RWLock::WriterLock lm (redirect_lock);
905 RedirectList::iterator existing_end = _redirects.end();
908 uint32_t potential_max_streams = 0;
910 for (RedirectList::const_iterator i = others.begin(); i != others.end(); ++i) {
912 boost::shared_ptr<PluginInsert> pi;
914 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
917 uint32_t m = max(pi->input_streams(), pi->output_streams());
918 if (m > potential_max_streams)
919 potential_max_streams = m;
922 // Ensure peak vector sizes before the plugin is activated
923 while (_peak_power.size() < potential_max_streams) {
924 _peak_power.push_back(0);
926 while (_visible_peak_power.size() < potential_max_streams) {
927 _visible_peak_power.push_back(-INFINITY);
929 while (_max_peak_power.size() < potential_max_streams) {
930 _max_peak_power.push_back(-INFINITY);
933 _redirects.push_back (*i);
935 if (_reset_plugin_counts (err_streams)) {
937 _redirects.erase (existing_end, _redirects.end());
938 _reset_plugin_counts (0); // it worked before we tried to add it ...
943 (*i)->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
947 if (redirect_max_outs != old_rmo || old_rmo == 0) {
951 redirects_changed (src); /* EMIT SIGNAL */
955 /** Remove redirects with a given placement.
956 * @param p Placement of redirects to remove.
959 Route::clear_redirects (Placement p, void *src)
961 const uint32_t old_rmo = redirect_max_outs;
963 if (!_session.engine().connected()) {
968 Glib::RWLock::WriterLock lm (redirect_lock);
969 RedirectList new_list;
971 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
972 if ((*i)->placement() == p) {
973 /* it's the placement we want to get rid of */
974 (*i)->drop_references ();
976 /* it's a different placement, so keep it */
977 new_list.push_back (*i);
981 _redirects = new_list;
984 /* FIXME: can't see how this test can ever fire */
985 if (redirect_max_outs != old_rmo) {
989 redirect_max_outs = 0;
990 _have_internal_generator = false;
991 redirects_changed (src); /* EMIT SIGNAL */
995 Route::remove_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
997 uint32_t old_rmo = redirect_max_outs;
999 assert (ports_legal);
1001 if (!_session.engine().connected()) {
1005 redirect_max_outs = 0;
1008 Glib::RWLock::WriterLock lm (redirect_lock);
1009 RedirectList::iterator i;
1010 bool removed = false;
1012 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1013 if (*i == redirect) {
1015 RedirectList::iterator tmp;
1017 /* move along, see failure case for reset_plugin_counts()
1018 where we may need to reinsert the redirect.
1024 /* stop redirects that send signals to JACK ports
1025 from causing noise as a result of no longer being
1029 boost::shared_ptr<Send> send;
1030 boost::shared_ptr<PortInsert> port_insert;
1032 if ((send = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
1033 send->disconnect_inputs (this);
1034 send->disconnect_outputs (this);
1035 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (*i)) != 0) {
1036 port_insert->disconnect_inputs (this);
1037 port_insert->disconnect_outputs (this);
1040 _redirects.erase (i);
1053 if (_reset_plugin_counts (err_streams)) {
1054 /* get back to where we where */
1055 _redirects.insert (i, redirect);
1056 /* we know this will work, because it worked before :) */
1057 _reset_plugin_counts (0);
1063 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1064 boost::shared_ptr<PluginInsert> pi;
1066 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1067 if (pi->is_generator()) {
1073 _have_internal_generator = foo;
1076 if (old_rmo != redirect_max_outs) {
1080 redirect->drop_references ();
1082 redirects_changed (src); /* EMIT SIGNAL */
1087 Route::reset_plugin_counts (uint32_t* lpc)
1089 Glib::RWLock::WriterLock lm (redirect_lock);
1090 return _reset_plugin_counts (lpc);
1095 Route::_reset_plugin_counts (uint32_t* err_streams)
1097 RedirectList::iterator r;
1100 map<Placement,list<InsertCount> > insert_map;
1101 nframes_t initial_streams;
1103 redirect_max_outs = 0;
1107 /* divide inserts up by placement so we get the signal flow
1108 properly modelled. we need to do this because the _redirects
1109 list is not sorted by placement, and because other reasons may
1110 exist now or in the future for this separate treatment.
1113 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1115 boost::shared_ptr<Insert> insert;
1117 /* do this here in case we bomb out before we get to the end of
1121 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1123 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1125 insert_map[insert->placement()].push_back (InsertCount (insert));
1127 /* reset plugin counts back to one for now so
1128 that we have a predictable, controlled
1129 state to try to configure.
1132 boost::shared_ptr<PluginInsert> pi;
1134 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
1138 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1151 /* Now process each placement in order, checking to see if we
1152 can really do what has been requested.
1157 if (check_some_plugin_counts (insert_map[PreFader], n_inputs (), err_streams)) {
1161 /* figure out the streams that will feed into PreFader */
1163 if (!insert_map[PreFader].empty()) {
1164 InsertCount& ic (insert_map[PreFader].back());
1165 initial_streams = ic.insert->compute_output_streams (ic.cnt);
1167 initial_streams = n_inputs ();
1172 if (check_some_plugin_counts (insert_map[PostFader], initial_streams, err_streams)) {
1176 /* OK, everything can be set up correctly, so lets do it */
1178 apply_some_plugin_counts (insert_map[PreFader]);
1179 apply_some_plugin_counts (insert_map[PostFader]);
1181 /* recompute max outs of any redirect */
1185 redirect_max_outs = 0;
1186 RedirectList::iterator prev = _redirects.end();
1188 for (r = _redirects.begin(); r != _redirects.end(); prev = r, ++r) {
1189 boost::shared_ptr<Send> s;
1191 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1192 if (r == _redirects.begin()) {
1193 s->expect_inputs (n_inputs());
1195 s->expect_inputs ((*prev)->output_streams());
1200 /* don't pay any attention to send output configuration, since it doesn't
1204 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1215 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1217 list<InsertCount>::iterator i;
1219 for (i = iclist.begin(); i != iclist.end(); ++i) {
1221 if ((*i).insert->configure_io ((*i).cnt, (*i).in, (*i).out)) {
1224 /* make sure that however many we have, they are all active */
1225 (*i).insert->activate ();
1232 Route::check_some_plugin_counts (list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams)
1234 list<InsertCount>::iterator i;
1236 for (i = iclist.begin(); i != iclist.end(); ++i) {
1238 if (((*i).cnt = (*i).insert->can_support_input_configuration (required_inputs)) < 0) {
1240 *err_streams = required_inputs;
1245 (*i).in = required_inputs;
1246 (*i).out = (*i).insert->compute_output_streams ((*i).cnt);
1248 required_inputs = (*i).out;
1255 Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_streams)
1257 uint32_t old_rmo = redirect_max_outs;
1263 RedirectList to_be_deleted;
1266 Glib::RWLock::WriterLock lm (redirect_lock);
1267 RedirectList::iterator tmp;
1268 RedirectList the_copy;
1270 the_copy = _redirects;
1272 /* remove all relevant redirects */
1274 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1278 if ((*i)->placement() == placement) {
1279 to_be_deleted.push_back (*i);
1280 _redirects.erase (i);
1286 /* now copy the relevant ones from "other" */
1288 for (RedirectList::const_iterator i = other._redirects.begin(); i != other._redirects.end(); ++i) {
1289 if ((*i)->placement() == placement) {
1290 _redirects.push_back (Redirect::clone (*i));
1294 /* reset plugin stream handling */
1296 if (_reset_plugin_counts (err_streams)) {
1298 /* FAILED COPY ATTEMPT: we have to restore order */
1300 /* delete all cloned redirects */
1302 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1307 if ((*i)->placement() == placement) {
1308 _redirects.erase (i);
1314 /* restore the natural order */
1316 _redirects = the_copy;
1317 redirect_max_outs = old_rmo;
1319 /* we failed, even though things are OK again */
1325 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1326 to_be_deleted.clear ();
1330 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1334 redirects_changed (this); /* EMIT SIGNAL */
1339 Route::all_redirects_flip ()
1341 Glib::RWLock::ReaderLock lm (redirect_lock);
1343 if (_redirects.empty()) {
1347 bool first_is_on = _redirects.front()->active();
1349 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1350 (*i)->set_active (!first_is_on, this);
1354 /** Set all redirects with a given placement to a given active state.
1355 * @param p Placement of redirects to change.
1356 * @param state New active state for those redirects.
1359 Route::all_redirects_active (Placement p, bool state)
1361 Glib::RWLock::ReaderLock lm (redirect_lock);
1363 if (_redirects.empty()) {
1367 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1368 if ((*i)->placement() == p) {
1369 (*i)->set_active (state, this);
1374 struct RedirectSorter {
1375 bool operator() (boost::shared_ptr<const Redirect> a, boost::shared_ptr<const Redirect> b) {
1376 return a->sort_key() < b->sort_key();
1381 Route::sort_redirects (uint32_t* err_streams)
1384 RedirectSorter comparator;
1385 Glib::RWLock::WriterLock lm (redirect_lock);
1386 uint32_t old_rmo = redirect_max_outs;
1388 /* the sweet power of C++ ... */
1390 RedirectList as_it_was_before = _redirects;
1392 _redirects.sort (comparator);
1394 if (_reset_plugin_counts (err_streams)) {
1395 _redirects = as_it_was_before;
1396 redirect_max_outs = old_rmo;
1402 redirects_changed (this); /* EMIT SIGNAL */
1414 Route::get_template()
1416 return state(false);
1420 Route::state(bool full_state)
1422 XMLNode *node = new XMLNode("Route");
1423 RedirectList:: iterator i;
1427 node->add_property("flags", enum_2_string (_flags));
1430 node->add_property("default-type", _default_type.to_string());
1432 node->add_property("active", _active?"yes":"no");
1433 node->add_property("muted", _muted?"yes":"no");
1434 node->add_property("soloed", _soloed?"yes":"no");
1435 node->add_property("phase-invert", _phase_invert?"yes":"no");
1436 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1437 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1438 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1439 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1440 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1443 node->add_property("edit-group", _edit_group->name());
1446 node->add_property("mix-group", _mix_group->name());
1449 string order_string;
1450 OrderKeys::iterator x = order_keys.begin();
1452 while (x != order_keys.end()) {
1453 order_string += string ((*x).first);
1454 order_string += '=';
1455 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1456 order_string += buf;
1460 if (x == order_keys.end()) {
1464 order_string += ':';
1466 node->add_property ("order-keys", order_string);
1468 node->add_child_nocopy (IO::state (full_state));
1469 node->add_child_nocopy (_solo_control.get_state ());
1470 node->add_child_nocopy (_mute_control.get_state ());
1472 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1473 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1474 remote_control_node->add_property (X_("id"), buf);
1475 node->add_child_nocopy (*remote_control_node);
1477 if (_control_outs) {
1478 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1479 cnode->add_child_nocopy (_control_outs->state (full_state));
1480 node->add_child_nocopy (*cnode);
1483 if (_comment.length()) {
1484 XMLNode *cmt = node->add_child ("Comment");
1485 cmt->add_content (_comment);
1488 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1489 node->add_child_nocopy((*i)->state (full_state));
1493 node->add_child_copy (*_extra_xml);
1500 Route::set_deferred_state ()
1503 XMLNodeConstIterator niter;
1505 if (!deferred_state) {
1509 nlist = deferred_state->children();
1511 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1512 add_redirect_from_xml (**niter);
1515 delete deferred_state;
1520 Route::add_redirect_from_xml (const XMLNode& node)
1522 const XMLProperty *prop;
1524 if (node.name() == "Send") {
1528 boost::shared_ptr<Send> send (new Send (_session, node));
1529 add_redirect (send, this);
1532 catch (failed_constructor &err) {
1533 error << _("Send construction failed") << endmsg;
1537 } else if (node.name() == "Insert") {
1540 if ((prop = node.property ("type")) != 0) {
1542 boost::shared_ptr<Insert> insert;
1544 if (prop->value() == "ladspa" || prop->value() == "Ladspa" || prop->value() == "vst") {
1546 insert.reset (new PluginInsert(_session, node));
1548 } else if (prop->value() == "port") {
1551 insert.reset (new PortInsert (_session, node));
1555 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1558 add_redirect (insert, this);
1561 error << _("Insert XML node has no type property") << endmsg;
1565 catch (failed_constructor &err) {
1566 warning << _("insert could not be created. Ignored.") << endmsg;
1573 Route::set_state (const XMLNode& node)
1575 return _set_state (node, true);
1579 Route::_set_state (const XMLNode& node, bool call_base)
1582 XMLNodeConstIterator niter;
1584 XMLPropertyList plist;
1585 const XMLProperty *prop;
1587 if (node.name() != "Route"){
1588 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1592 if ((prop = node.property (X_("flags"))) != 0) {
1593 _flags = Flag (string_2_enum (prop->value(), _flags));
1598 if ((prop = node.property (X_("default-type"))) != 0) {
1599 _default_type = DataType(prop->value());
1600 assert(_default_type != DataType::NIL);
1603 if ((prop = node.property (X_("phase-invert"))) != 0) {
1604 set_phase_invert (prop->value()=="yes"?true:false, this);
1607 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1608 set_denormal_protection (prop->value()=="yes"?true:false, this);
1611 if ((prop = node.property (X_("active"))) != 0) {
1612 set_active (prop->value() == "yes");
1615 if ((prop = node.property (X_("muted"))) != 0) {
1616 bool yn = prop->value()=="yes"?true:false;
1618 /* force reset of mute status */
1622 mute_gain = desired_mute_gain;
1625 if ((prop = node.property (X_("soloed"))) != 0) {
1626 bool yn = prop->value()=="yes"?true:false;
1628 /* force reset of solo status */
1631 set_solo (yn, this);
1632 solo_gain = desired_solo_gain;
1635 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1636 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1639 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1640 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1643 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1644 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1647 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1648 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1651 if ((prop = node.property (X_("edit-group"))) != 0) {
1652 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1653 if(edit_group == 0) {
1654 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1656 set_edit_group(edit_group, this);
1660 if ((prop = node.property (X_("order-keys"))) != 0) {
1664 string::size_type colon, equal;
1665 string remaining = prop->value();
1667 while (remaining.length()) {
1669 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1670 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1673 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1674 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1677 set_order_key (remaining.substr (0, equal).c_str(), n);
1681 colon = remaining.find_first_of (':');
1683 if (colon != string::npos) {
1684 remaining = remaining.substr (colon+1);
1691 nlist = node.children();
1693 if (deferred_state) {
1694 delete deferred_state;
1697 deferred_state = new XMLNode(X_("deferred state"));
1699 /* set parent class properties before anything else */
1701 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1705 if (child->name() == IO::state_node_name && call_base) {
1707 IO::set_state (*child);
1713 XMLNodeList redirect_nodes;
1715 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1719 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1720 redirect_nodes.push_back(child);
1725 _set_redirect_states (redirect_nodes);
1727 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1729 // All redirects (sends and inserts) have been applied already
1731 if (child->name() == X_("Automation")) {
1733 if ((prop = child->property (X_("path"))) != 0) {
1734 load_automation (prop->value());
1737 } else if (child->name() == X_("ControlOuts")) {
1739 string coutname = _name;
1740 coutname += _("[control]");
1742 _control_outs = new IO (_session, coutname);
1743 _control_outs->set_state (**(child->children().begin()));
1745 } else if (child->name() == X_("Comment")) {
1747 /* XXX this is a terrible API design in libxml++ */
1749 XMLNode *cmt = *(child->children().begin());
1750 _comment = cmt->content();
1752 } else if (child->name() == X_("extra")) {
1754 _extra_xml = new XMLNode (*child);
1756 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1758 if (prop->value() == "solo") {
1759 _solo_control.set_state (*child);
1760 _session.add_controllable (&_solo_control);
1762 else if (prop->value() == "mute") {
1763 _mute_control.set_state (*child);
1764 _session.add_controllable (&_mute_control);
1767 else if (child->name() == X_("remote_control")) {
1768 if ((prop = child->property (X_("id"))) != 0) {
1770 sscanf (prop->value().c_str(), "%d", &x);
1771 set_remote_control_id (x);
1776 if ((prop = node.property (X_("mix-group"))) != 0) {
1777 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1778 if (mix_group == 0) {
1779 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1781 set_mix_group(mix_group, this);
1789 Route::_set_redirect_states(const XMLNodeList &nlist)
1791 XMLNodeConstIterator niter;
1794 RedirectList::iterator i, o;
1798 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1799 deferred_state->add_child_copy (**niter);
1805 // Iterate through existing redirects, remove those which are not in the state list
1806 for (i = _redirects.begin(); i != _redirects.end(); ) {
1807 RedirectList::iterator tmp = i;
1810 bool redirectInStateList = false;
1812 (*i)->id().print (buf, sizeof (buf));
1814 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1816 if (strncmp (buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1817 redirectInStateList = true;
1822 if (!redirectInStateList) {
1823 remove_redirect ( *i, this);
1831 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1832 // set the state of existing redirects according to the new state on the same go
1833 i = _redirects.begin();
1834 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1836 // Check whether the next redirect in the list
1839 while (o != _redirects.end()) {
1840 (*o)->id().print (buf, sizeof (buf));
1841 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1846 if (o == _redirects.end()) {
1847 // If the redirect (*niter) is not on the route, we need to create it
1848 // and move it to the correct location
1850 RedirectList::iterator prev_last = _redirects.end();
1851 --prev_last; // We need this to check whether adding succeeded
1853 add_redirect_from_xml (**niter);
1855 RedirectList::iterator last = _redirects.end();
1858 if (prev_last == last) {
1859 warning << _name << ": could not fully restore state as some redirects were not possible to create" << endmsg;
1864 boost::shared_ptr<Redirect> tmp = (*last);
1865 // remove the redirect from the wrong location
1866 _redirects.erase(last);
1867 // insert the new redirect at the current location
1868 _redirects.insert(i, tmp);
1870 --i; // move pointer to the newly inserted redirect
1874 // We found the redirect (*niter) on the route, first we must make sure the redirect
1875 // is at the location provided in the XML state
1877 boost::shared_ptr<Redirect> tmp = (*o);
1878 // remove the old copy
1879 _redirects.erase(o);
1880 // insert the redirect at the correct location
1881 _redirects.insert(i, tmp);
1883 --i; // move pointer so it points to the right redirect
1886 (*i)->set_state( (**niter) );
1889 redirects_changed(this);
1893 Route::curve_reallocate ()
1895 // _gain_automation_curve.finish_resize ();
1896 // _pan_automation_curve.finish_resize ();
1900 Route::silence (nframes_t nframes, nframes_t offset)
1904 // reset_peak_meters ();
1906 IO::silence (nframes, offset);
1908 if (_control_outs) {
1909 _control_outs->silence (nframes, offset);
1913 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
1916 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1917 boost::shared_ptr<PluginInsert> pi;
1918 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1919 // skip plugins, they don't need anything when we're not active
1923 (*i)->silence (nframes, offset);
1926 if (nframes == _session.get_block_size() && offset == 0) {
1936 Route::set_control_outs (const vector<string>& ports)
1938 Glib::Mutex::Lock lm (control_outs_lock);
1939 vector<string>::const_iterator i;
1942 if (_control_outs) {
1943 delete _control_outs;
1947 if (control() || master()) {
1948 /* no control outs for these two special busses */
1952 if (ports.empty()) {
1956 string coutname = _name;
1957 coutname += _("[control]");
1959 _control_outs = new IO (_session, coutname);
1961 /* our control outs need as many outputs as we
1962 have outputs. we track the changes in ::output_change_handler().
1965 limit = n_outputs ();
1967 if (_control_outs->ensure_io (0, limit, true, this)) {
1971 /* now connect to the named ports */
1973 for (uint32_t n = 0; n < limit; ++n) {
1974 if (_control_outs->connect_output (_control_outs->output (n), ports[n], this)) {
1975 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
1984 Route::set_edit_group (RouteGroup *eg, void *src)
1987 if (eg == _edit_group) {
1992 _edit_group->remove (this);
1995 if ((_edit_group = eg) != 0) {
1996 _edit_group->add (this);
1999 _session.set_dirty ();
2000 edit_group_changed (src); /* EMIT SIGNAL */
2004 Route::drop_edit_group (void *src)
2007 _session.set_dirty ();
2008 edit_group_changed (src); /* EMIT SIGNAL */
2012 Route::set_mix_group (RouteGroup *mg, void *src)
2015 if (mg == _mix_group) {
2020 _mix_group->remove (this);
2023 if ((_mix_group = mg) != 0) {
2024 _mix_group->add (this);
2027 _session.set_dirty ();
2028 mix_group_changed (src); /* EMIT SIGNAL */
2032 Route::drop_mix_group (void *src)
2035 _session.set_dirty ();
2036 mix_group_changed (src); /* EMIT SIGNAL */
2040 Route::set_comment (string cmt, void *src)
2043 comment_changed (src);
2044 _session.set_dirty ();
2048 Route::feeds (boost::shared_ptr<Route> other)
2053 uint32_t no = self.n_outputs();
2054 uint32_t ni = other->n_inputs ();
2056 for (i = 0; i < no; ++i) {
2057 for (j = 0; j < ni; ++j) {
2058 if (self.output(i)->connected_to (other->input(j)->name())) {
2064 /* check Redirects which may also interconnect Routes */
2066 for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); r++) {
2068 no = (*r)->n_outputs();
2070 for (i = 0; i < no; ++i) {
2071 for (j = 0; j < ni; ++j) {
2072 if ((*r)->output(i)->connected_to (other->input (j)->name())) {
2079 /* check for control room outputs which may also interconnect Routes */
2081 if (_control_outs) {
2083 no = _control_outs->n_outputs();
2085 for (i = 0; i < no; ++i) {
2086 for (j = 0; j < ni; ++j) {
2087 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2098 Route::set_mute_config (mute_type t, bool onoff, void *src)
2102 _mute_affects_pre_fader = onoff;
2103 pre_fader_changed(src); /* EMIT SIGNAL */
2107 _mute_affects_post_fader = onoff;
2108 post_fader_changed(src); /* EMIT SIGNAL */
2112 _mute_affects_control_outs = onoff;
2113 control_outs_changed(src); /* EMIT SIGNAL */
2117 _mute_affects_main_outs = onoff;
2118 main_outs_changed(src); /* EMIT SIGNAL */
2124 Route::get_mute_config (mute_type t)
2130 onoff = _mute_affects_pre_fader;
2133 onoff = _mute_affects_post_fader;
2136 onoff = _mute_affects_control_outs;
2139 onoff = _mute_affects_main_outs;
2147 Route::set_active (bool yn)
2150 active_changed(); /* EMIT SIGNAL */
2154 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_redirects)
2156 nframes_t now = _session.transport_frame();
2159 Glib::RWLock::ReaderLock lm (redirect_lock);
2162 automation_snapshot (now);
2165 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2167 if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
2168 (*i)->deactivate ();
2172 (*i)->transport_stopped (now);
2176 IO::transport_stopped (now);
2178 _roll_delay = _initial_delay;
2182 Route::input_change_handler (IOChange change, void *ignored)
2184 if (change & ConfigurationChanged) {
2185 reset_plugin_counts (0);
2190 Route::output_change_handler (IOChange change, void *ignored)
2192 if (change & ConfigurationChanged) {
2193 if (_control_outs) {
2194 _control_outs->ensure_io (0, n_outputs(), true, this);
2197 reset_plugin_counts (0);
2202 Route::pans_required () const
2204 if (n_outputs() < 2) {
2208 return max (n_inputs (), redirect_max_outs);
2212 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2213 bool session_state_changing, bool can_record, bool rec_monitors_input)
2215 if (n_outputs() == 0) {
2219 if (session_state_changing || !_active) {
2220 silence (nframes, offset);
2224 apply_gain_automation = false;
2227 passthru (start_frame, end_frame, nframes, offset, 0, false);
2229 silence (nframes, offset);
2236 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2238 if (_roll_delay > nframes) {
2240 _roll_delay -= nframes;
2241 silence (nframes, offset);
2242 /* transport frame is not legal for caller to use */
2245 } else if (_roll_delay > 0) {
2247 nframes -= _roll_delay;
2249 silence (_roll_delay, offset);
2251 offset += _roll_delay;
2252 transport_frame += _roll_delay;
2261 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2262 bool can_record, bool rec_monitors_input)
2265 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2267 // automation snapshot can also be called from the non-rt context
2268 // and it uses the redirect list, so we take the lock out here
2269 automation_snapshot (_session.transport_frame());
2273 if ((n_outputs() == 0 && _redirects.empty()) || n_inputs() == 0 || !_active) {
2274 silence (nframes, offset);
2278 nframes_t unused = 0;
2280 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2286 apply_gain_automation = false;
2289 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2291 if (am.locked() && _session.transport_rolling()) {
2293 nframes_t start_frame = end_frame - nframes;
2295 if (gain_automation_playback()) {
2296 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2301 passthru (start_frame, end_frame, nframes, offset, declick, false);
2307 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2308 bool can_record, bool rec_monitors_input)
2310 silence (nframes, offset);
2315 Route::toggle_monitor_input ()
2317 for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2318 (*i)->ensure_monitor_input(!(*i)->monitoring_input());
2323 Route::has_external_redirects () const
2325 boost::shared_ptr<const PortInsert> pi;
2327 for (RedirectList::const_iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2328 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2330 uint32_t no = pi->n_outputs();
2332 for (uint32_t n = 0; n < no; ++n) {
2334 string port_name = pi->output(n)->name();
2335 string client_name = port_name.substr (0, port_name.find(':'));
2337 /* only say "yes" if the redirect is actually in use */
2339 if (client_name != "ardour" && pi->active()) {
2350 Route::flush_redirects ()
2352 /* XXX shouldn't really try to take this lock, since
2353 this is called from the RT audio thread.
2356 Glib::RWLock::ReaderLock lm (redirect_lock);
2358 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2359 (*i)->deactivate ();
2365 Route::set_meter_point (MeterPoint p, void *src)
2367 if (_meter_point != p) {
2369 meter_change (src); /* EMIT SIGNAL */
2370 _session.set_dirty ();
2375 Route::update_total_latency ()
2379 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2380 if ((*i)->active ()) {
2381 _own_latency += (*i)->latency ();
2385 set_port_latency (_own_latency);
2387 /* this (virtual) function is used for pure Routes,
2388 not derived classes like AudioTrack. this means
2389 that the data processed here comes from an input
2390 port, not prerecorded material, and therefore we
2391 have to take into account any input latency.
2394 _own_latency += input_latency ();
2396 return _own_latency;
2400 Route::set_latency_delay (nframes_t longest_session_latency)
2402 _initial_delay = longest_session_latency - _own_latency;
2404 if (_session.transport_stopped()) {
2405 _roll_delay = _initial_delay;
2410 Route::automation_snapshot (nframes_t now)
2412 IO::automation_snapshot (now);
2414 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2415 (*i)->automation_snapshot (now);
2419 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2420 : Controllable (name), route (s), type(tp)
2426 Route::ToggleControllable::set_value (float val)
2428 bool bval = ((val >= 0.5f) ? true: false);
2432 route.set_mute (bval, this);
2435 route.set_solo (bval, this);
2443 Route::ToggleControllable::get_value (void) const
2449 val = route.muted() ? 1.0f : 0.0f;
2452 val = route.soloed() ? 1.0f : 0.0f;
2462 Route::set_block_size (nframes_t nframes)
2464 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2465 (*i)->set_block_size (nframes);
2470 Route::redirect_active_proxy (Redirect* ignored, void* ignored_src)
2472 _session.update_latency_compensation (false, false);
2476 Route::protect_automation ()
2478 switch (gain_automation_state()) {
2480 set_gain_automation_state (Off);
2482 set_gain_automation_state (Play);
2488 switch (panner().automation_state ()) {
2490 panner().set_automation_state (Off);
2493 panner().set_automation_state (Play);
2499 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2500 boost::shared_ptr<PluginInsert> pi;
2501 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2502 pi->protect_automation ();
2508 Route::set_pending_declick (int declick)
2511 /* this call is not allowed to turn off a pending declick unless "force" is true */
2513 _pending_declick = declick;
2515 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2517 _pending_declick = 0;