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;
52 sigc::signal<void> Route::SyncOrderKeys;
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++;
83 _meter_point = MeterPostFader;
87 _have_internal_generator = false;
89 _pending_declick = true;
90 _remote_control_id = 0;
91 _ignore_gain_on_deliver = true;
96 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
97 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
98 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
99 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
102 desired_solo_gain = 1.0;
104 desired_mute_gain = 1.0;
108 input_changed.connect (mem_fun (this, &Route::input_change_handler));
109 output_changed.connect (mem_fun (this, &Route::output_change_handler));
114 clear_redirects (PreFader, this);
115 clear_redirects (PostFader, this);
117 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
118 free ((void*)(i->first));
122 delete _control_outs;
127 Route::set_remote_control_id (uint32_t id)
129 if (id != _remote_control_id) {
130 _remote_control_id = id;
131 RemoteControlIDChanged ();
136 Route::remote_control_id() const
138 return _remote_control_id;
142 Route::order_key (const char* name) const
144 OrderKeys::const_iterator i;
146 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
147 if (!strcmp (name, i->first)) {
156 Route::set_order_key (const char* name, long n)
158 order_keys[strdup(name)] = n;
160 if (Config->get_sync_all_route_ordering()) {
161 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
166 _session.set_dirty ();
170 Route::sync_order_keys ()
174 if (order_keys.empty()) {
178 OrderKeys::iterator x = order_keys.begin();
182 for (; x != order_keys.end(); ++x) {
188 Route::inc_gain (gain_t fraction, void *src)
190 IO::inc_gain (fraction, src);
194 Route::set_gain (gain_t val, void *src)
196 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
198 if (_mix_group->is_relative()) {
201 gain_t usable_gain = gain();
202 if (usable_gain < 0.000001f) {
203 usable_gain=0.000001f;
207 if (delta < 0.000001f) {
211 delta -= usable_gain;
213 if (delta == 0.0f) return;
215 gain_t factor = delta / usable_gain;
218 factor = _mix_group->get_max_factor(factor);
219 if (factor == 0.0f) {
224 factor = _mix_group->get_min_factor(factor);
225 if (factor == 0.0f) {
231 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
235 _mix_group->apply (&Route::set_gain, val, _mix_group);
245 IO::set_gain (val, src);
249 Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
250 nframes_t start_frame, nframes_t end_frame,
251 nframes_t nframes, nframes_t offset, bool with_redirects, int declick,
255 RedirectList::iterator i;
256 bool post_fader_work = false;
257 bool mute_declick_applied = false;
259 vector<Sample*>::iterator bufiter;
264 gain_t* gab = _session.gain_automation_buffer();
266 switch (Config->get_monitoring_model()) {
267 case HardwareMonitoring:
268 case ExternalMonitoring:
275 declick = _pending_declick;
278 Glib::Mutex::Lock cm (control_outs_lock, Glib::TRY_LOCK);
288 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
291 dmg = desired_mute_gain;
292 dsg = desired_solo_gain;
301 /* ----------------------------------------------------------------------------------------------------
302 GLOBAL DECLICK (for transport changes etc.)
303 -------------------------------------------------------------------------------------------------- */
306 apply_declick (bufs, nbufs, nframes, 0.0, 1.0, false);
307 _pending_declick = 0;
308 } else if (declick < 0) {
309 apply_declick (bufs, nbufs, nframes, 1.0, 0.0, false);
310 _pending_declick = 0;
313 /* no global declick */
315 if (solo_gain != dsg) {
316 apply_declick (bufs, nbufs, nframes, solo_gain, dsg, false);
322 /* ----------------------------------------------------------------------------------------------------
323 INPUT METERING & MONITORING
324 -------------------------------------------------------------------------------------------------- */
326 if (meter && (_meter_point == MeterInput)) {
327 for (n = 0; n < nbufs; ++n) {
328 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
332 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
333 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
335 mute_declick_applied = true;
338 if ((_meter_point == MeterInput) && co) {
340 solo_audible = dsg > 0;
341 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
343 if ( // muted by solo of another track
347 // muted by mute of this track
351 // rec-enabled but not s/w monitoring
353 // TODO: this is probably wrong
355 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
359 co->silence (nframes, offset);
363 co->deliver_output (bufs, nbufs, nframes, offset);
368 /* -----------------------------------------------------------------------------------------------------
370 -------------------------------------------------------------------------------------------------- */
372 if (_denormal_protection || Config->get_denormal_protection()) {
374 for (n = 0; n < nbufs; ++n) {
375 Sample *sp = bufs[n];
377 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
384 /* ----------------------------------------------------------------------------------------------------
386 -------------------------------------------------------------------------------------------------- */
388 if (with_redirects) {
389 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
391 if (mute_gain > 0 || !_mute_affects_pre_fader) {
392 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
393 switch ((*i)->placement()) {
396 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
397 (*i)->silence (nframes, offset);
400 (*i)->run (bufs, nbufs, nframes, offset);
404 post_fader_work = true;
409 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
410 switch ((*i)->placement()) {
412 (*i)->silence (nframes, offset);
415 post_fader_work = true;
424 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
425 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
427 mute_declick_applied = true;
430 /* ----------------------------------------------------------------------------------------------------
431 PRE-FADER METERING & MONITORING
432 -------------------------------------------------------------------------------------------------- */
434 if (meter && (_meter_point == MeterPreFader)) {
435 for (n = 0; n < nbufs; ++n) {
436 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
441 if ((_meter_point == MeterPreFader) && co) {
443 solo_audible = dsg > 0;
444 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
446 if ( // muted by solo of another track
450 // muted by mute of this track
454 // rec-enabled but not s/w monitoring
456 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
460 co->silence (nframes, offset);
464 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
469 /* ----------------------------------------------------------------------------------------------------
471 -------------------------------------------------------------------------------------------------- */
473 /* if not recording or recording and requiring any monitor signal, then apply gain */
475 if ( // not recording
477 !(record_enabled() && _session.actively_recording()) ||
481 // AND software monitoring required
483 (Config->get_monitoring_model() == SoftwareMonitoring)) {
485 if (apply_gain_automation) {
488 for (n = 0; n < nbufs; ++n) {
489 Sample *sp = bufs[n];
491 for (nframes_t nx = 0; nx < nframes; ++nx) {
496 for (n = 0; n < nbufs; ++n) {
497 Sample *sp = bufs[n];
499 for (nframes_t nx = 0; nx < nframes; ++nx) {
505 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
506 _effective_gain = gab[nframes-1];
511 /* manual (scalar) gain */
515 apply_declick (bufs, nbufs, nframes, _gain, dg, _phase_invert);
518 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
520 /* no need to interpolate current gain value,
521 but its non-unity, so apply it. if the gain
522 is zero, do nothing because we'll ship silence
534 for (n = 0; n < nbufs; ++n) {
535 Sample *sp = bufs[n];
536 Session::apply_gain_to_buffer(sp,nframes,this_gain);
539 } else if (_gain == 0) {
540 for (n = 0; n < nbufs; ++n) {
541 memset (bufs[n], 0, sizeof (Sample) * nframes);
548 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
552 /* ----------------------------------------------------------------------------------------------------
554 -------------------------------------------------------------------------------------------------- */
556 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
558 if (post_fader_work) {
560 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
562 if (mute_gain > 0 || !_mute_affects_post_fader) {
563 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
564 switch ((*i)->placement()) {
569 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
570 (*i)->silence (nframes, offset);
573 (*i)->run (bufs, nbufs, nframes, offset);
579 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
580 switch ((*i)->placement()) {
584 (*i)->silence (nframes, offset);
592 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
593 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
595 mute_declick_applied = true;
598 /* ----------------------------------------------------------------------------------------------------
600 -------------------------------------------------------------------------------------------------- */
602 if ((_meter_point == MeterPostFader) && co) {
604 solo_audible = solo_gain > 0;
605 mute_audible = dmg > 0 || !_mute_affects_control_outs;
607 if ( // silent anyway
609 (_gain == 0 && !apply_gain_automation) ||
611 // muted by solo of another track
615 // muted by mute of this track
619 // recording but not s/w monitoring
621 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
625 co->silence (nframes, offset);
629 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
633 /* ----------------------------------------------------------------------
635 ----------------------------------------------------------------------*/
637 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
638 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
640 mute_declick_applied = true;
643 /* ----------------------------------------------------------------------------------------------------
645 -------------------------------------------------------------------------------------------------- */
647 solo_audible = dsg > 0;
648 mute_audible = dmg > 0 || !_mute_affects_main_outs;
650 if (n_outputs() == 0) {
654 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
656 IO::silence (nframes, offset);
660 if ( // silent anyway
662 (_gain == 0 && !apply_gain_automation) ||
664 // muted by solo of another track, but not using control outs for solo
666 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
668 // muted by mute of this track
674 /* don't use Route::silence() here, because that causes
675 all outputs (sends, port inserts, etc. to be silent).
678 if (_meter_point == MeterPostFader) {
679 reset_peak_meters ();
682 IO::silence (nframes, offset);
686 if ((_session.transport_speed() > 1.5f ||
687 _session.transport_speed() < -1.5f) &&
688 Config->get_quieten_at_speed()) {
689 pan (bufs, nbufs, nframes, offset, speed_quietning);
691 // cerr << _name << " panner state = " << _panner->automation_state() << endl;
692 if (!_panner->empty() &&
693 (_panner->automation_state() & Play ||
694 ((_panner->automation_state() & Touch) && !_panner->touching()))) {
695 pan_automated (bufs, nbufs, start_frame, end_frame, nframes, offset);
697 pan (bufs, nbufs, nframes, offset, 1.0);
704 /* ----------------------------------------------------------------------------------------------------
706 -------------------------------------------------------------------------------------------------- */
708 if (meter && (_meter_point == MeterPostFader)) {
710 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
711 uint32_t no = n_outputs();
712 for (n = 0; n < no; ++n) {
716 uint32_t no = n_outputs();
717 for (n = 0; n < no; ++n) {
718 _peak_power[n] = Session::compute_peak (output(n)->get_buffer (nframes) + offset, nframes, _peak_power[n]);
725 Route::n_process_buffers ()
727 return max (n_inputs(), redirect_max_outs);
732 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
734 vector<Sample*>& bufs = _session.get_passthru_buffers();
735 uint32_t limit = n_process_buffers ();
739 collect_input (bufs, limit, nframes, offset);
741 #define meter_stream meter_first
744 for (uint32_t n = 0; n < limit; ++n) {
745 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
747 meter_stream = false;
752 process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, true, declick, meter_stream);
758 Route::set_phase_invert (bool yn, void *src)
760 if (_phase_invert != yn) {
762 // phase_invert_changed (src); /* EMIT SIGNAL */
767 Route::set_denormal_protection (bool yn, void *src)
769 if (_denormal_protection != yn) {
770 _denormal_protection = yn;
771 // denormal_protection_changed (src); /* EMIT SIGNAL */
776 Route::set_solo (bool yn, void *src)
782 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
783 _mix_group->apply (&Route::set_solo, yn, _mix_group);
789 solo_changed (src); /* EMIT SIGNAL */
790 _solo_control.Changed (); /* EMIT SIGNAL */
795 Route::set_solo_mute (bool yn)
797 Glib::Mutex::Lock lm (declick_lock);
799 /* Called by Session in response to another Route being soloed.
802 desired_solo_gain = (yn?0.0:1.0);
806 Route::set_solo_safe (bool yn, void *src)
808 if (_solo_safe != yn) {
810 solo_safe_changed (src); /* EMIT SIGNAL */
815 Route::set_mute (bool yn, void *src)
818 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
819 _mix_group->apply (&Route::set_mute, yn, _mix_group);
825 mute_changed (src); /* EMIT SIGNAL */
827 _mute_control.Changed (); /* EMIT SIGNAL */
829 Glib::Mutex::Lock lm (declick_lock);
830 desired_mute_gain = (yn?0.0f:1.0f);
835 Route::add_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
837 uint32_t old_rmo = redirect_max_outs;
839 if (!_session.engine().connected()) {
844 Glib::RWLock::WriterLock lm (redirect_lock);
846 boost::shared_ptr<PluginInsert> pi;
847 boost::shared_ptr<PortInsert> porti;
849 uint32_t potential_max_streams = 0;
851 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redirect)) != 0) {
854 if (pi->input_streams() == 0) {
855 /* instrument plugin */
856 _have_internal_generator = true;
859 potential_max_streams = max(pi->input_streams(), pi->output_streams());
861 } else if ((porti = boost::dynamic_pointer_cast<PortInsert>(redirect)) != 0) {
863 /* force new port inserts to start out with an i/o configuration
864 that matches this route's i/o configuration.
866 the "inputs" for the port are supposed to match the output
869 the "outputs" of the route should match the inputs of this
870 route. XXX shouldn't they match the number of active signal
871 streams at the point of insertion?
875 porti->ensure_io (n_outputs (), n_inputs(), false, this);
878 // Ensure peak vector sizes before the plugin is activated
879 while (_peak_power.size() < potential_max_streams) {
880 _peak_power.push_back(0);
882 while (_visible_peak_power.size() < potential_max_streams) {
883 _visible_peak_power.push_back(-INFINITY);
885 while (_max_peak_power.size() < potential_max_streams) {
886 _max_peak_power.push_back(-INFINITY);
889 _redirects.push_back (redirect);
891 if (_reset_plugin_counts (err_streams)) {
892 _redirects.pop_back ();
893 _reset_plugin_counts (0); // it worked before we tried to add it ...
897 redirect->activate ();
898 redirect->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
901 if (redirect_max_outs != old_rmo || old_rmo == 0) {
906 redirects_changed (src); /* EMIT SIGNAL */
911 Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_streams)
913 uint32_t old_rmo = redirect_max_outs;
915 assert (ports_legal);
917 if (!_session.engine().connected()) {
922 Glib::RWLock::WriterLock lm (redirect_lock);
924 RedirectList::iterator existing_end = _redirects.end();
927 uint32_t potential_max_streams = 0;
929 for (RedirectList::const_iterator i = others.begin(); i != others.end(); ++i) {
931 boost::shared_ptr<PluginInsert> pi;
933 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
936 uint32_t m = max(pi->input_streams(), pi->output_streams());
937 if (m > potential_max_streams)
938 potential_max_streams = m;
941 // Ensure peak vector sizes before the plugin is activated
942 while (_peak_power.size() < potential_max_streams) {
943 _peak_power.push_back(0);
945 while (_visible_peak_power.size() < potential_max_streams) {
946 _visible_peak_power.push_back(-INFINITY);
948 while (_max_peak_power.size() < potential_max_streams) {
949 _max_peak_power.push_back(-INFINITY);
952 _redirects.push_back (*i);
954 if (_reset_plugin_counts (err_streams)) {
956 _redirects.erase (existing_end, _redirects.end());
957 _reset_plugin_counts (0); // it worked before we tried to add it ...
962 (*i)->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
966 if (redirect_max_outs != old_rmo || old_rmo == 0) {
970 redirects_changed (src); /* EMIT SIGNAL */
974 /** Remove redirects with a given placement.
975 * @param p Placement of redirects to remove.
978 Route::clear_redirects (Placement p, void *src)
980 const uint32_t old_rmo = redirect_max_outs;
982 if (!_session.engine().connected()) {
987 Glib::RWLock::WriterLock lm (redirect_lock);
988 RedirectList new_list;
990 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
991 if ((*i)->placement() == p) {
992 /* it's the placement we want to get rid of */
993 (*i)->drop_references ();
995 /* it's a different placement, so keep it */
996 new_list.push_back (*i);
1000 _redirects = new_list;
1003 /* FIXME: can't see how this test can ever fire */
1004 if (redirect_max_outs != old_rmo) {
1008 redirect_max_outs = 0;
1009 _have_internal_generator = false;
1010 redirects_changed (src); /* EMIT SIGNAL */
1014 Route::remove_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
1016 uint32_t old_rmo = redirect_max_outs;
1018 assert (ports_legal);
1020 if (!_session.engine().connected()) {
1024 redirect_max_outs = 0;
1027 Glib::RWLock::WriterLock lm (redirect_lock);
1028 RedirectList::iterator i;
1029 bool removed = false;
1031 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1032 if (*i == redirect) {
1034 RedirectList::iterator tmp;
1036 /* move along, see failure case for reset_plugin_counts()
1037 where we may need to reinsert the redirect.
1043 /* stop redirects that send signals to JACK ports
1044 from causing noise as a result of no longer being
1048 boost::shared_ptr<Send> send;
1049 boost::shared_ptr<PortInsert> port_insert;
1051 if ((send = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
1052 send->disconnect_inputs (this);
1053 send->disconnect_outputs (this);
1054 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (*i)) != 0) {
1055 port_insert->disconnect_inputs (this);
1056 port_insert->disconnect_outputs (this);
1059 _redirects.erase (i);
1072 if (_reset_plugin_counts (err_streams)) {
1073 /* get back to where we where */
1074 _redirects.insert (i, redirect);
1075 /* we know this will work, because it worked before :) */
1076 _reset_plugin_counts (0);
1082 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1083 boost::shared_ptr<PluginInsert> pi;
1085 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1086 if (pi->is_generator()) {
1092 _have_internal_generator = foo;
1095 if (old_rmo != redirect_max_outs) {
1099 redirect->drop_references ();
1101 redirects_changed (src); /* EMIT SIGNAL */
1106 Route::reset_plugin_counts (uint32_t* lpc)
1108 Glib::RWLock::WriterLock lm (redirect_lock);
1109 return _reset_plugin_counts (lpc);
1114 Route::_reset_plugin_counts (uint32_t* err_streams)
1116 RedirectList::iterator r;
1119 map<Placement,list<InsertCount> > insert_map;
1120 nframes_t initial_streams;
1122 redirect_max_outs = 0;
1126 /* divide inserts up by placement so we get the signal flow
1127 properly modelled. we need to do this because the _redirects
1128 list is not sorted by placement, and because other reasons may
1129 exist now or in the future for this separate treatment.
1132 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1134 boost::shared_ptr<Insert> insert;
1136 /* do this here in case we bomb out before we get to the end of
1140 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1142 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1144 insert_map[insert->placement()].push_back (InsertCount (insert));
1146 /* reset plugin counts back to one for now so
1147 that we have a predictable, controlled
1148 state to try to configure.
1151 boost::shared_ptr<PluginInsert> pi;
1153 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
1157 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1170 /* Now process each placement in order, checking to see if we
1171 can really do what has been requested.
1176 if (check_some_plugin_counts (insert_map[PreFader], n_inputs (), err_streams)) {
1180 /* figure out the streams that will feed into PreFader */
1182 if (!insert_map[PreFader].empty()) {
1183 InsertCount& ic (insert_map[PreFader].back());
1184 initial_streams = ic.insert->compute_output_streams (ic.cnt);
1186 initial_streams = n_inputs ();
1191 if (check_some_plugin_counts (insert_map[PostFader], initial_streams, err_streams)) {
1195 /* OK, everything can be set up correctly, so lets do it */
1197 apply_some_plugin_counts (insert_map[PreFader]);
1198 apply_some_plugin_counts (insert_map[PostFader]);
1200 /* recompute max outs of any redirect */
1204 redirect_max_outs = 0;
1205 RedirectList::iterator prev = _redirects.end();
1207 for (r = _redirects.begin(); r != _redirects.end(); prev = r, ++r) {
1208 boost::shared_ptr<Send> s;
1210 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1211 if (r == _redirects.begin()) {
1212 s->expect_inputs (n_inputs());
1214 s->expect_inputs ((*prev)->output_streams());
1219 /* don't pay any attention to send output configuration, since it doesn't
1223 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1234 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1236 list<InsertCount>::iterator i;
1238 for (i = iclist.begin(); i != iclist.end(); ++i) {
1240 if ((*i).insert->configure_io ((*i).cnt, (*i).in, (*i).out)) {
1243 /* make sure that however many we have, they are all active */
1244 (*i).insert->activate ();
1251 Route::check_some_plugin_counts (list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams)
1253 list<InsertCount>::iterator i;
1255 for (i = iclist.begin(); i != iclist.end(); ++i) {
1257 if (((*i).cnt = (*i).insert->can_support_input_configuration (required_inputs)) < 0) {
1259 *err_streams = required_inputs;
1264 (*i).in = required_inputs;
1266 if (((*i).out = (*i).insert->compute_output_streams ((*i).cnt)) < 0) {
1268 *err_streams = required_inputs;
1273 required_inputs = (*i).out;
1280 Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_streams)
1282 uint32_t old_rmo = redirect_max_outs;
1288 RedirectList to_be_deleted;
1291 Glib::RWLock::WriterLock lm (redirect_lock);
1292 RedirectList::iterator tmp;
1293 RedirectList the_copy;
1295 the_copy = _redirects;
1297 /* remove all relevant redirects */
1299 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1303 if ((*i)->placement() == placement) {
1304 to_be_deleted.push_back (*i);
1305 _redirects.erase (i);
1311 /* now copy the relevant ones from "other" */
1313 for (RedirectList::const_iterator i = other._redirects.begin(); i != other._redirects.end(); ++i) {
1314 if ((*i)->placement() == placement) {
1315 _redirects.push_back (Redirect::clone (*i));
1319 /* reset plugin stream handling */
1321 if (_reset_plugin_counts (err_streams)) {
1323 /* FAILED COPY ATTEMPT: we have to restore order */
1325 /* delete all cloned redirects */
1327 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1332 if ((*i)->placement() == placement) {
1333 _redirects.erase (i);
1339 /* restore the natural order */
1341 _redirects = the_copy;
1342 redirect_max_outs = old_rmo;
1344 /* we failed, even though things are OK again */
1350 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1351 to_be_deleted.clear ();
1355 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1359 redirects_changed (this); /* EMIT SIGNAL */
1364 Route::all_redirects_flip ()
1366 Glib::RWLock::ReaderLock lm (redirect_lock);
1368 if (_redirects.empty()) {
1372 bool first_is_on = _redirects.front()->active();
1374 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1375 (*i)->set_active (!first_is_on, this);
1379 /** Set all redirects with a given placement to a given active state.
1380 * @param p Placement of redirects to change.
1381 * @param state New active state for those redirects.
1384 Route::all_redirects_active (Placement p, bool state)
1386 Glib::RWLock::ReaderLock lm (redirect_lock);
1388 if (_redirects.empty()) {
1392 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1393 if ((*i)->placement() == p) {
1394 (*i)->set_active (state, this);
1399 struct RedirectSorter {
1400 bool operator() (boost::shared_ptr<const Redirect> a, boost::shared_ptr<const Redirect> b) {
1401 return a->sort_key() < b->sort_key();
1406 Route::sort_redirects (uint32_t* err_streams)
1409 RedirectSorter comparator;
1410 Glib::RWLock::WriterLock lm (redirect_lock);
1411 uint32_t old_rmo = redirect_max_outs;
1413 /* the sweet power of C++ ... */
1415 RedirectList as_it_was_before = _redirects;
1417 _redirects.sort (comparator);
1419 if (_reset_plugin_counts (err_streams)) {
1420 _redirects = as_it_was_before;
1421 redirect_max_outs = old_rmo;
1427 redirects_changed (this); /* EMIT SIGNAL */
1439 Route::get_template()
1441 return state(false);
1445 Route::state(bool full_state)
1447 XMLNode *node = new XMLNode("Route");
1448 RedirectList:: iterator i;
1452 node->add_property("flags", enum_2_string (_flags));
1455 node->add_property("default-type", _default_type.to_string());
1457 node->add_property("muted", _muted?"yes":"no");
1458 node->add_property("soloed", _soloed?"yes":"no");
1459 node->add_property("phase-invert", _phase_invert?"yes":"no");
1460 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1461 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1462 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1463 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1464 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1467 node->add_property("edit-group", _edit_group->name());
1470 node->add_property("mix-group", _mix_group->name());
1473 string order_string;
1474 OrderKeys::iterator x = order_keys.begin();
1476 while (x != order_keys.end()) {
1477 order_string += string ((*x).first);
1478 order_string += '=';
1479 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1480 order_string += buf;
1484 if (x == order_keys.end()) {
1488 order_string += ':';
1490 node->add_property ("order-keys", order_string);
1492 node->add_child_nocopy (IO::state (full_state));
1493 node->add_child_nocopy (_solo_control.get_state ());
1494 node->add_child_nocopy (_mute_control.get_state ());
1496 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1497 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1498 remote_control_node->add_property (X_("id"), buf);
1499 node->add_child_nocopy (*remote_control_node);
1501 if (_control_outs) {
1502 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1503 cnode->add_child_nocopy (_control_outs->state (full_state));
1504 node->add_child_nocopy (*cnode);
1507 if (_comment.length()) {
1508 XMLNode *cmt = node->add_child ("Comment");
1509 cmt->add_content (_comment);
1512 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1513 node->add_child_nocopy((*i)->state (full_state));
1517 node->add_child_copy (*_extra_xml);
1524 Route::set_deferred_state ()
1527 XMLNodeConstIterator niter;
1529 if (!deferred_state) {
1533 nlist = deferred_state->children();
1535 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1536 add_redirect_from_xml (**niter);
1539 delete deferred_state;
1544 Route::add_redirect_from_xml (const XMLNode& node)
1546 const XMLProperty *prop;
1548 if (node.name() == "Send") {
1552 boost::shared_ptr<Send> send (new Send (_session, node));
1553 add_redirect (send, this);
1556 catch (failed_constructor &err) {
1557 error << _("Send construction failed") << endmsg;
1561 } else if (node.name() == "Insert") {
1564 if ((prop = node.property ("type")) != 0) {
1566 boost::shared_ptr<Insert> insert;
1567 bool have_insert = false;
1569 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1570 prop->value() == "vst" ||
1571 prop->value() == "audiounit") {
1573 insert.reset (new PluginInsert(_session, node));
1576 } else if (prop->value() == "port") {
1579 insert.reset (new PortInsert (_session, node));
1584 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1588 add_redirect (insert, this);
1592 error << _("Insert XML node has no type property") << endmsg;
1596 catch (failed_constructor &err) {
1597 warning << _("insert could not be created. Ignored.") << endmsg;
1604 Route::set_state (const XMLNode& node)
1606 return _set_state (node, true);
1610 Route::_set_state (const XMLNode& node, bool call_base)
1613 XMLNodeConstIterator niter;
1615 XMLPropertyList plist;
1616 const XMLProperty *prop;
1618 if (node.name() != "Route"){
1619 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1623 if ((prop = node.property (X_("flags"))) != 0) {
1624 _flags = Flag (string_2_enum (prop->value(), _flags));
1629 if ((prop = node.property (X_("default-type"))) != 0) {
1630 _default_type = DataType(prop->value());
1631 assert(_default_type != DataType::NIL);
1634 if ((prop = node.property (X_("phase-invert"))) != 0) {
1635 set_phase_invert (prop->value()=="yes"?true:false, this);
1638 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1639 set_denormal_protection (prop->value()=="yes"?true:false, this);
1642 if ((prop = node.property (X_("muted"))) != 0) {
1643 bool yn = prop->value()=="yes"?true:false;
1645 /* force reset of mute status */
1649 mute_gain = desired_mute_gain;
1652 if ((prop = node.property (X_("soloed"))) != 0) {
1653 bool yn = prop->value()=="yes"?true:false;
1655 /* force reset of solo status */
1658 set_solo (yn, this);
1659 solo_gain = desired_solo_gain;
1662 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1663 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1666 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1667 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1670 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1671 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1674 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1675 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1678 if ((prop = node.property (X_("edit-group"))) != 0) {
1679 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1680 if(edit_group == 0) {
1681 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1683 set_edit_group(edit_group, this);
1687 if ((prop = node.property (X_("order-keys"))) != 0) {
1691 string::size_type colon, equal;
1692 string remaining = prop->value();
1694 while (remaining.length()) {
1696 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1697 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1700 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1701 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1704 set_order_key (remaining.substr (0, equal).c_str(), n);
1708 colon = remaining.find_first_of (':');
1710 if (colon != string::npos) {
1711 remaining = remaining.substr (colon+1);
1718 nlist = node.children();
1720 if (deferred_state) {
1721 delete deferred_state;
1724 deferred_state = new XMLNode(X_("deferred state"));
1726 /* set parent class properties before anything else */
1728 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1732 if (child->name() == IO::state_node_name && call_base) {
1734 IO::set_state (*child);
1740 XMLNodeList redirect_nodes;
1742 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1746 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1747 redirect_nodes.push_back(child);
1752 _set_redirect_states (redirect_nodes);
1754 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1756 // All redirects (sends and inserts) have been applied already
1758 if (child->name() == X_("Automation")) {
1760 if ((prop = child->property (X_("path"))) != 0) {
1761 load_automation (prop->value());
1764 } else if (child->name() == X_("ControlOuts")) {
1766 string coutname = _name;
1767 coutname += _("[control]");
1769 _control_outs = new IO (_session, coutname);
1770 _control_outs->set_state (**(child->children().begin()));
1772 } else if (child->name() == X_("Comment")) {
1774 /* XXX this is a terrible API design in libxml++ */
1776 XMLNode *cmt = *(child->children().begin());
1777 _comment = cmt->content();
1779 } else if (child->name() == X_("extra")) {
1781 _extra_xml = new XMLNode (*child);
1783 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1785 if (prop->value() == "solo") {
1786 _solo_control.set_state (*child);
1787 _session.add_controllable (&_solo_control);
1789 else if (prop->value() == "mute") {
1790 _mute_control.set_state (*child);
1791 _session.add_controllable (&_mute_control);
1794 else if (child->name() == X_("remote_control")) {
1795 if ((prop = child->property (X_("id"))) != 0) {
1797 sscanf (prop->value().c_str(), "%d", &x);
1798 set_remote_control_id (x);
1803 if ((prop = node.property (X_("mix-group"))) != 0) {
1804 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1805 if (mix_group == 0) {
1806 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1808 set_mix_group(mix_group, this);
1816 Route::_set_redirect_states(const XMLNodeList &nlist)
1818 XMLNodeConstIterator niter;
1821 RedirectList::iterator i, o;
1825 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1826 deferred_state->add_child_copy (**niter);
1832 // Iterate through existing redirects, remove those which are not in the state list
1833 for (i = _redirects.begin(); i != _redirects.end(); ) {
1834 RedirectList::iterator tmp = i;
1837 bool redirectInStateList = false;
1839 (*i)->id().print (buf, sizeof (buf));
1841 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1843 if (strncmp (buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1844 redirectInStateList = true;
1849 if (!redirectInStateList) {
1850 remove_redirect ( *i, this);
1858 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1859 // set the state of existing redirects according to the new state on the same go
1860 i = _redirects.begin();
1861 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1863 // Check whether the next redirect in the list
1866 while (o != _redirects.end()) {
1867 (*o)->id().print (buf, sizeof (buf));
1868 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1873 if (o == _redirects.end()) {
1874 // If the redirect (*niter) is not on the route, we need to create it
1875 // and move it to the correct location
1877 RedirectList::iterator prev_last = _redirects.end();
1878 --prev_last; // We need this to check whether adding succeeded
1880 add_redirect_from_xml (**niter);
1882 RedirectList::iterator last = _redirects.end();
1885 if (prev_last == last) {
1886 warning << _name << ": could not fully restore state as some redirects were not possible to create" << endmsg;
1891 boost::shared_ptr<Redirect> tmp = (*last);
1892 // remove the redirect from the wrong location
1893 _redirects.erase(last);
1894 // insert the new redirect at the current location
1895 _redirects.insert(i, tmp);
1897 --i; // move pointer to the newly inserted redirect
1901 // We found the redirect (*niter) on the route, first we must make sure the redirect
1902 // is at the location provided in the XML state
1904 boost::shared_ptr<Redirect> tmp = (*o);
1905 // remove the old copy
1906 _redirects.erase(o);
1907 // insert the redirect at the correct location
1908 _redirects.insert(i, tmp);
1910 --i; // move pointer so it points to the right redirect
1913 (*i)->set_state( (**niter) );
1916 redirects_changed(this);
1920 Route::curve_reallocate ()
1922 // _gain_automation_curve.finish_resize ();
1923 // _pan_automation_curve.finish_resize ();
1927 Route::silence (nframes_t nframes, nframes_t offset)
1931 // reset_peak_meters ();
1933 IO::silence (nframes, offset);
1935 if (_control_outs) {
1936 _control_outs->silence (nframes, offset);
1940 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
1943 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1944 boost::shared_ptr<PluginInsert> pi;
1945 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1946 // skip plugins, they don't need anything when we're not active
1950 (*i)->silence (nframes, offset);
1953 if (nframes == _session.get_block_size() && offset == 0) {
1963 Route::set_control_outs (const vector<string>& ports)
1965 Glib::Mutex::Lock lm (control_outs_lock);
1966 vector<string>::const_iterator i;
1969 if (_control_outs) {
1970 delete _control_outs;
1974 if (control() || master()) {
1975 /* no control outs for these two special busses */
1979 if (ports.empty()) {
1983 string coutname = _name;
1984 coutname += _("[control]");
1986 _control_outs = new IO (_session, coutname);
1988 /* our control outs need as many outputs as we
1989 have outputs. we track the changes in ::output_change_handler().
1992 limit = n_outputs ();
1994 if (_control_outs->ensure_io (0, limit, true, this)) {
1998 /* now connect to the named ports */
2000 for (uint32_t n = 0; n < limit; ++n) {
2001 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2002 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2011 Route::set_edit_group (RouteGroup *eg, void *src)
2014 if (eg == _edit_group) {
2019 _edit_group->remove (this);
2022 if ((_edit_group = eg) != 0) {
2023 _edit_group->add (this);
2026 _session.set_dirty ();
2027 edit_group_changed (src); /* EMIT SIGNAL */
2031 Route::drop_edit_group (void *src)
2034 _session.set_dirty ();
2035 edit_group_changed (src); /* EMIT SIGNAL */
2039 Route::set_mix_group (RouteGroup *mg, void *src)
2042 if (mg == _mix_group) {
2047 _mix_group->remove (this);
2050 if ((_mix_group = mg) != 0) {
2051 _mix_group->add (this);
2054 _session.set_dirty ();
2055 mix_group_changed (src); /* EMIT SIGNAL */
2059 Route::drop_mix_group (void *src)
2062 _session.set_dirty ();
2063 mix_group_changed (src); /* EMIT SIGNAL */
2067 Route::set_comment (string cmt, void *src)
2070 comment_changed (src);
2071 _session.set_dirty ();
2075 Route::feeds (boost::shared_ptr<Route> other)
2080 uint32_t no = self.n_outputs();
2081 uint32_t ni = other->n_inputs ();
2083 for (i = 0; i < no; ++i) {
2084 for (j = 0; j < ni; ++j) {
2085 if (self.output(i)->connected_to (other->input(j)->name())) {
2091 /* check Redirects which may also interconnect Routes */
2093 for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); r++) {
2095 no = (*r)->n_outputs();
2097 for (i = 0; i < no; ++i) {
2098 for (j = 0; j < ni; ++j) {
2099 if ((*r)->output(i)->connected_to (other->input (j)->name())) {
2106 /* check for control room outputs which may also interconnect Routes */
2108 if (_control_outs) {
2110 no = _control_outs->n_outputs();
2112 for (i = 0; i < no; ++i) {
2113 for (j = 0; j < ni; ++j) {
2114 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2125 Route::set_mute_config (mute_type t, bool onoff, void *src)
2129 _mute_affects_pre_fader = onoff;
2130 pre_fader_changed(src); /* EMIT SIGNAL */
2134 _mute_affects_post_fader = onoff;
2135 post_fader_changed(src); /* EMIT SIGNAL */
2139 _mute_affects_control_outs = onoff;
2140 control_outs_changed(src); /* EMIT SIGNAL */
2144 _mute_affects_main_outs = onoff;
2145 main_outs_changed(src); /* EMIT SIGNAL */
2151 Route::get_mute_config (mute_type t)
2157 onoff = _mute_affects_pre_fader;
2160 onoff = _mute_affects_post_fader;
2163 onoff = _mute_affects_control_outs;
2166 onoff = _mute_affects_main_outs;
2174 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_redirects)
2176 nframes_t now = _session.transport_frame();
2179 Glib::RWLock::ReaderLock lm (redirect_lock);
2182 automation_snapshot (now);
2185 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2187 if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
2188 (*i)->deactivate ();
2192 (*i)->transport_stopped (now);
2196 IO::transport_stopped (now);
2198 _roll_delay = _initial_delay;
2202 Route::input_change_handler (IOChange change, void *ignored)
2204 if (change & ConfigurationChanged) {
2205 reset_plugin_counts (0);
2210 Route::output_change_handler (IOChange change, void *ignored)
2212 if (change & ConfigurationChanged) {
2213 if (_control_outs) {
2214 _control_outs->ensure_io (0, n_outputs(), true, this);
2217 reset_plugin_counts (0);
2222 Route::pans_required () const
2224 if (n_outputs() < 2) {
2228 return max (n_inputs (), redirect_max_outs);
2232 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2233 bool session_state_changing, bool can_record, bool rec_monitors_input)
2235 if (n_outputs() == 0) {
2239 if (session_state_changing || !_active) {
2240 silence (nframes, offset);
2244 apply_gain_automation = false;
2247 passthru (start_frame, end_frame, nframes, offset, 0, false);
2249 silence (nframes, offset);
2256 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2258 if (_roll_delay > nframes) {
2260 _roll_delay -= nframes;
2261 silence (nframes, offset);
2262 /* transport frame is not legal for caller to use */
2265 } else if (_roll_delay > 0) {
2267 nframes -= _roll_delay;
2269 silence (_roll_delay, offset);
2271 offset += _roll_delay;
2272 transport_frame += _roll_delay;
2281 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2282 bool can_record, bool rec_monitors_input)
2285 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2287 // automation snapshot can also be called from the non-rt context
2288 // and it uses the redirect list, so we take the lock out here
2289 automation_snapshot (_session.transport_frame());
2293 if ((n_outputs() == 0 && _redirects.empty()) || n_inputs() == 0 || !_active) {
2294 silence (nframes, offset);
2298 nframes_t unused = 0;
2300 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2306 apply_gain_automation = false;
2309 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2311 if (am.locked() && _session.transport_rolling()) {
2313 nframes_t start_frame = end_frame - nframes;
2315 if (gain_automation_playback()) {
2316 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2321 passthru (start_frame, end_frame, nframes, offset, declick, false);
2327 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2328 bool can_record, bool rec_monitors_input)
2330 silence (nframes, offset);
2335 Route::toggle_monitor_input ()
2337 for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2338 (*i)->ensure_monitor_input(!(*i)->monitoring_input());
2343 Route::has_external_redirects () const
2345 boost::shared_ptr<const PortInsert> pi;
2347 for (RedirectList::const_iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2348 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2350 uint32_t no = pi->n_outputs();
2352 for (uint32_t n = 0; n < no; ++n) {
2354 string port_name = pi->output(n)->name();
2355 string client_name = port_name.substr (0, port_name.find(':'));
2357 /* only say "yes" if the redirect is actually in use */
2359 if (client_name != "ardour" && pi->active()) {
2370 Route::flush_redirects ()
2372 /* XXX shouldn't really try to take this lock, since
2373 this is called from the RT audio thread.
2376 Glib::RWLock::ReaderLock lm (redirect_lock);
2378 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2379 (*i)->deactivate ();
2385 Route::set_meter_point (MeterPoint p, void *src)
2387 if (_meter_point != p) {
2389 meter_change (src); /* EMIT SIGNAL */
2390 _session.set_dirty ();
2395 Route::update_total_latency ()
2399 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2400 if ((*i)->active ()) {
2401 _own_latency += (*i)->latency ();
2405 set_port_latency (_own_latency);
2407 /* this (virtual) function is used for pure Routes,
2408 not derived classes like AudioTrack. this means
2409 that the data processed here comes from an input
2410 port, not prerecorded material, and therefore we
2411 have to take into account any input latency.
2414 _own_latency += input_latency ();
2416 return _own_latency;
2420 Route::set_latency_delay (nframes_t longest_session_latency)
2422 _initial_delay = longest_session_latency - _own_latency;
2424 if (_session.transport_stopped()) {
2425 _roll_delay = _initial_delay;
2430 Route::automation_snapshot (nframes_t now)
2432 IO::automation_snapshot (now);
2434 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2435 (*i)->automation_snapshot (now);
2439 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2440 : Controllable (name), route (s), type(tp)
2446 Route::ToggleControllable::set_value (float val)
2448 bool bval = ((val >= 0.5f) ? true: false);
2452 route.set_mute (bval, this);
2455 route.set_solo (bval, this);
2463 Route::ToggleControllable::get_value (void) const
2469 val = route.muted() ? 1.0f : 0.0f;
2472 val = route.soloed() ? 1.0f : 0.0f;
2482 Route::set_block_size (nframes_t nframes)
2484 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2485 (*i)->set_block_size (nframes);
2490 Route::redirect_active_proxy (Redirect* ignored, void* ignored_src)
2492 _session.update_latency_compensation (false, false);
2496 Route::protect_automation ()
2498 switch (gain_automation_state()) {
2500 set_gain_automation_state (Off);
2502 set_gain_automation_state (Play);
2508 switch (panner().automation_state ()) {
2510 panner().set_automation_state (Off);
2513 panner().set_automation_state (Play);
2519 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2520 boost::shared_ptr<PluginInsert> pi;
2521 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2522 pi->protect_automation ();
2528 Route::set_pending_declick (int declick)
2531 /* this call is not allowed to turn off a pending declick unless "force" is true */
2533 _pending_declick = declick;
2535 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2537 _pending_declick = 0;