2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <sigc++/bind.h>
25 #include <pbd/xml++.h>
26 #include <pbd/enumwriter.h>
28 #include <ardour/timestamps.h>
29 #include <ardour/audioengine.h>
30 #include <ardour/route.h>
31 #include <ardour/buffer.h>
32 #include <ardour/processor.h>
33 #include <ardour/plugin_insert.h>
34 #include <ardour/port_insert.h>
35 #include <ardour/send.h>
36 #include <ardour/session.h>
37 #include <ardour/utils.h>
38 #include <ardour/configuration.h>
39 #include <ardour/cycle_timer.h>
40 #include <ardour/route_group.h>
41 #include <ardour/port.h>
42 #include <ardour/audio_port.h>
43 #include <ardour/ladspa_plugin.h>
44 #include <ardour/panner.h>
45 #include <ardour/dB.h>
46 #include <ardour/amp.h>
47 #include <ardour/meter.h>
48 #include <ardour/buffer_set.h>
49 #include <ardour/mix.h>
50 #include <ardour/profile.h>
55 using namespace ARDOUR;
58 uint32_t Route::order_key_cnt = 0;
59 sigc::signal<void> Route::SyncOrderKeys;
61 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
62 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
64 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
65 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
70 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
71 : IO (sess, *node.child ("IO"), default_type),
72 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
73 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
76 _set_state (node, false);
82 processor_max_outs.reset();
88 _phase_invert = false;
89 _denormal_protection = false;
90 order_keys[strdup (N_("signal"))] = order_key_cnt++;
92 _meter_point = MeterPostFader;
97 _have_internal_generator = false;
99 _pending_declick = true;
100 _remote_control_id = 0;
105 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
106 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
107 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
108 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
111 desired_solo_gain = 1.0;
113 desired_mute_gain = 1.0;
117 input_changed.connect (mem_fun (this, &Route::input_change_handler));
118 output_changed.connect (mem_fun (this, &Route::output_change_handler));
123 clear_processors (PreFader);
124 clear_processors (PostFader);
126 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
127 free ((void*)(i->first));
131 delete _control_outs;
136 Route::set_remote_control_id (uint32_t id)
138 if (id != _remote_control_id) {
139 _remote_control_id = id;
140 RemoteControlIDChanged ();
145 Route::remote_control_id() const
147 return _remote_control_id;
151 Route::order_key (const char* name) const
153 OrderKeys::const_iterator i;
155 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
156 if (!strcmp (name, i->first)) {
165 Route::set_order_key (const char* name, long n)
167 order_keys[strdup(name)] = n;
169 if (Config->get_sync_all_route_ordering()) {
170 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
175 _session.set_dirty ();
179 Route::sync_order_keys ()
183 if (order_keys.empty()) {
187 OrderKeys::iterator x = order_keys.begin();
191 for (; x != order_keys.end(); ++x) {
197 Route::ensure_track_or_route_name(string name, Session &session)
199 string newname = name;
201 while (session.route_by_name (newname)!=NULL)
203 newname = bump_name_once (newname);
211 Route::inc_gain (gain_t fraction, void *src)
213 IO::inc_gain (fraction, src);
217 Route::set_gain (gain_t val, void *src)
219 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
221 if (_mix_group->is_relative()) {
223 gain_t usable_gain = gain();
224 if (usable_gain < 0.000001f) {
225 usable_gain = 0.000001f;
229 if (delta < 0.000001f) {
233 delta -= usable_gain;
238 gain_t factor = delta / usable_gain;
241 factor = _mix_group->get_max_factor(factor);
242 if (factor == 0.0f) {
243 _gain_control->Changed(); /* EMIT SIGNAL */
247 factor = _mix_group->get_min_factor(factor);
248 if (factor == 0.0f) {
249 _gain_control->Changed(); /* EMIT SIGNAL */
254 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
258 _mix_group->apply (&Route::set_gain, val, _mix_group);
268 IO::set_gain (val, src);
271 /** Process this route for one (sub) cycle (process thread)
273 * @param bufs Scratch buffers to use for the signal path
274 * @param start_frame Initial transport frame
275 * @param end_frame Final transport frame
276 * @param nframes Number of frames to output (to ports)
277 * @param offset Output offset (of port buffers, for split cycles)
279 * Note that (end_frame - start_frame) may not be equal to nframes when the
280 * transport speed isn't 1.0 (eg varispeed).
283 Route::process_output_buffers (BufferSet& bufs,
284 nframes_t start_frame, nframes_t end_frame,
285 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
288 // This is definitely very audio-only for now
289 assert(_default_type == DataType::AUDIO);
291 ProcessorList::iterator i;
292 bool post_fader_work = false;
293 bool mute_declick_applied = false;
299 gain_t* gab = _session.gain_automation_buffer();
301 switch (Config->get_monitoring_model()) {
302 case HardwareMonitoring:
303 case ExternalMonitoring:
310 declick = _pending_declick;
313 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
323 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
326 dmg = desired_mute_gain;
327 dsg = desired_solo_gain;
336 /* ----------------------------------------------------------------------------------------------------
337 GLOBAL DECLICK (for transport changes etc.)
338 -------------------------------------------------------------------------------------------------- */
341 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
342 _pending_declick = 0;
343 } else if (declick < 0) {
344 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
345 _pending_declick = 0;
348 /* no global declick */
350 if (solo_gain != dsg) {
351 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
357 /* ----------------------------------------------------------------------------------------------------
358 INPUT METERING & MONITORING
359 -------------------------------------------------------------------------------------------------- */
361 if (meter && (_meter_point == MeterInput)) {
362 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
365 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
366 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
368 mute_declick_applied = true;
371 if ((_meter_point == MeterInput) && co) {
373 solo_audible = dsg > 0;
374 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
376 if ( // muted by solo of another track
380 // muted by mute of this track
384 // rec-enabled but not s/w monitoring
386 // TODO: this is probably wrong
388 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
392 co->silence (nframes, offset);
396 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
401 /* -----------------------------------------------------------------------------------------------------
403 -------------------------------------------------------------------------------------------------- */
405 if (_denormal_protection || Config->get_denormal_protection()) {
407 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
408 Sample* const sp = i->data();
410 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
416 /* ----------------------------------------------------------------------------------------------------
418 -------------------------------------------------------------------------------------------------- */
420 if (with_processors) {
421 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
423 if (mute_gain > 0 || !_mute_affects_pre_fader) {
424 for (i = _processors.begin(); i != _processors.end(); ++i) {
425 switch ((*i)->placement()) {
427 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
430 post_fader_work = true;
435 for (i = _processors.begin(); i != _processors.end(); ++i) {
436 switch ((*i)->placement()) {
438 (*i)->silence (nframes, offset);
441 post_fader_work = true;
449 // This really should already be true...
450 bufs.set_count(pre_fader_streams());
452 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
453 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
455 mute_declick_applied = true;
458 /* ----------------------------------------------------------------------------------------------------
459 PRE-FADER METERING & MONITORING
460 -------------------------------------------------------------------------------------------------- */
462 if (meter && (_meter_point == MeterPreFader)) {
463 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
467 if ((_meter_point == MeterPreFader) && co) {
469 solo_audible = dsg > 0;
470 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
472 if ( // muted by solo of another track
476 // muted by mute of this track
480 // rec-enabled but not s/w monitoring
482 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
486 co->silence (nframes, offset);
490 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
494 /* ----------------------------------------------------------------------------------------------------
496 -------------------------------------------------------------------------------------------------- */
498 /* if not recording or recording and requiring any monitor signal, then apply gain */
500 if ( // not recording
502 !(record_enabled() && _session.actively_recording()) ||
506 // AND software monitoring required
508 Config->get_monitoring_model() == SoftwareMonitoring) {
510 if (apply_gain_automation) {
513 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
514 Sample* const sp = i->data();
516 for (nframes_t nx = 0; nx < nframes; ++nx) {
521 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
522 Sample* const sp = i->data();
524 for (nframes_t nx = 0; nx < nframes; ++nx) {
530 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
531 _effective_gain = gab[nframes-1];
536 /* manual (scalar) gain */
540 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
543 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
545 /* no need to interpolate current gain value,
546 but its non-unity, so apply it. if the gain
547 is zero, do nothing because we'll ship silence
559 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
560 Sample* const sp = i->data();
561 apply_gain_to_buffer(sp,nframes,this_gain);
564 } else if (_gain == 0) {
565 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
573 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
577 /* ----------------------------------------------------------------------------------------------------
579 -------------------------------------------------------------------------------------------------- */
581 /* note that post_fader_work cannot be true unless with_processors was also true, so don't test both */
583 if (post_fader_work) {
585 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
587 if (mute_gain > 0 || !_mute_affects_post_fader) {
588 for (i = _processors.begin(); i != _processors.end(); ++i) {
589 switch ((*i)->placement()) {
593 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
598 for (i = _processors.begin(); i != _processors.end(); ++i) {
599 switch ((*i)->placement()) {
603 (*i)->silence (nframes, offset);
611 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
612 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
614 mute_declick_applied = true;
617 /* ----------------------------------------------------------------------------------------------------
619 -------------------------------------------------------------------------------------------------- */
621 if ((_meter_point == MeterPostFader) && co) {
623 solo_audible = solo_gain > 0;
624 mute_audible = dmg > 0 || !_mute_affects_control_outs;
626 if ( // silent anyway
628 (_gain == 0 && !apply_gain_automation) ||
630 // muted by solo of another track
634 // muted by mute of this track
638 // recording but not s/w monitoring
640 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
644 co->silence (nframes, offset);
648 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
652 /* ----------------------------------------------------------------------
654 ----------------------------------------------------------------------*/
656 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
657 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
659 mute_declick_applied = true;
662 /* ----------------------------------------------------------------------------------------------------
664 -------------------------------------------------------------------------------------------------- */
666 solo_audible = dsg > 0;
667 mute_audible = dmg > 0 || !_mute_affects_main_outs;
669 if (n_outputs().get(_default_type) == 0) {
673 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
675 IO::silence (nframes, offset);
679 if ( // silent anyway
681 (_gain == 0 && !apply_gain_automation) ||
683 // muted by solo of another track, but not using control outs for solo
685 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
687 // muted by mute of this track
693 /* don't use Route::silence() here, because that causes
694 all outputs (sends, port processors, etc. to be silent).
697 if (_meter_point == MeterPostFader) {
698 peak_meter().reset();
701 IO::silence (nframes, offset);
705 deliver_output(bufs, start_frame, end_frame, nframes, offset);
711 /* ----------------------------------------------------------------------------------------------------
713 -------------------------------------------------------------------------------------------------- */
715 if (meter && (_meter_point == MeterPostFader)) {
716 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
719 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
725 Route::n_process_buffers ()
727 return max (n_inputs(), processor_max_outs);
731 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
733 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
737 collect_input (bufs, nframes, offset);
740 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
744 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
748 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
750 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
754 Route::set_solo (bool yn, void *src)
760 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
761 _mix_group->apply (&Route::set_solo, yn, _mix_group);
767 solo_changed (src); /* EMIT SIGNAL */
768 _solo_control->Changed (); /* EMIT SIGNAL */
773 Route::set_solo_mute (bool yn)
775 Glib::Mutex::Lock lm (declick_lock);
777 /* Called by Session in response to another Route being soloed.
780 desired_solo_gain = (yn?0.0:1.0);
784 Route::set_solo_safe (bool yn, void *src)
786 if (_solo_safe != yn) {
788 solo_safe_changed (src); /* EMIT SIGNAL */
793 Route::set_mute (bool yn, void *src)
796 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
797 _mix_group->apply (&Route::set_mute, yn, _mix_group);
803 mute_changed (src); /* EMIT SIGNAL */
805 _mute_control->Changed (); /* EMIT SIGNAL */
807 Glib::Mutex::Lock lm (declick_lock);
808 desired_mute_gain = (yn?0.0f:1.0f);
813 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
815 ChanCount old_rmo = processor_max_outs;
817 if (!_session.engine().connected()) {
822 Glib::RWLock::WriterLock lm (_processor_lock);
824 boost::shared_ptr<PluginInsert> pi;
825 boost::shared_ptr<PortInsert> porti;
827 //processor->set_default_type(_default_type);
829 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
832 if (pi->natural_input_streams() == ChanCount::ZERO) {
833 /* generator plugin */
834 _have_internal_generator = true;
839 _processors.push_back (processor);
841 // Set up processor list channels. This will set processor->[input|output]_streams(),
842 // configure redirect ports properly, etc.
843 if (_reset_plugin_counts (err)) {
844 _processors.pop_back ();
845 _reset_plugin_counts (0); // it worked before we tried to add it ...
849 // Ensure peak vector sizes before the plugin is activated
850 ChanCount potential_max_streams = max(processor->input_streams(), processor->output_streams());
851 _meter->configure_io(potential_max_streams, potential_max_streams);
853 processor->activate ();
854 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
859 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
863 processors_changed (); /* EMIT SIGNAL */
869 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
871 ChanCount old_rmo = processor_max_outs;
873 if (!_session.engine().connected()) {
878 Glib::RWLock::WriterLock lm (_processor_lock);
880 ProcessorList::iterator existing_end = _processors.end();
883 ChanCount potential_max_streams;
885 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
887 boost::shared_ptr<PluginInsert> pi;
889 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
892 ChanCount m = max(pi->input_streams(), pi->output_streams());
893 if (m > potential_max_streams)
894 potential_max_streams = m;
897 // Ensure peak vector sizes before the plugin is activated
898 _meter->configure_io(potential_max_streams, potential_max_streams);
900 _processors.push_back (*i);
902 if (_reset_plugin_counts (err)) {
904 _processors.erase (existing_end, _processors.end());
905 _reset_plugin_counts (0); // it worked before we tried to add it ...
910 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
916 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
920 processors_changed (); /* EMIT SIGNAL */
924 /** Turn off all processors with a given placement
925 * @param p Placement of processors to disable
929 Route::disable_processors (Placement p)
931 Glib::RWLock::ReaderLock lm (_processor_lock);
933 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
934 if ((*i)->placement() == p) {
935 (*i)->set_active (false);
939 _session.set_dirty ();
942 /** Turn off all redirects
946 Route::disable_processors ()
948 Glib::RWLock::ReaderLock lm (_processor_lock);
950 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
951 (*i)->set_active (false);
954 _session.set_dirty ();
957 /** Turn off all redirects with a given placement
958 * @param p Placement of redirects to disable
962 Route::disable_plugins (Placement p)
964 Glib::RWLock::ReaderLock lm (_processor_lock);
966 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
967 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
968 (*i)->set_active (false);
972 _session.set_dirty ();
975 /** Turn off all plugins
979 Route::disable_plugins ()
981 Glib::RWLock::ReaderLock lm (_processor_lock);
983 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
984 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
985 (*i)->set_active (false);
989 _session.set_dirty ();
994 Route::ab_plugins (bool forward)
996 Glib::RWLock::ReaderLock lm (_processor_lock);
1000 /* forward = turn off all active redirects, and mark them so that the next time
1001 we go the other way, we will revert them
1004 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1005 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1009 if ((*i)->active()) {
1010 (*i)->set_active (false);
1011 (*i)->set_next_ab_is_active (true);
1013 (*i)->set_next_ab_is_active (false);
1019 /* backward = if the redirect was marked to go active on the next ab, do so */
1021 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1023 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1027 if ((*i)->get_next_ab_is_active()) {
1028 (*i)->set_active (true);
1030 (*i)->set_active (false);
1035 _session.set_dirty ();
1039 /* Figure out the streams that will feed into PreFader */
1041 Route::pre_fader_streams() const
1043 boost::shared_ptr<Processor> processor;
1045 // Find the last pre-fader redirect
1046 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1047 if ((*i)->placement() == PreFader) {
1053 return processor->output_streams();
1060 /** Remove processors with a given placement.
1061 * @param p Placement of processors to remove.
1064 Route::clear_processors (Placement p)
1066 const ChanCount old_rmo = processor_max_outs;
1068 if (!_session.engine().connected()) {
1073 Glib::RWLock::WriterLock lm (_processor_lock);
1074 ProcessorList new_list;
1076 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1077 if ((*i)->placement() == p) {
1078 /* it's the placement we want to get rid of */
1079 (*i)->drop_references ();
1081 /* it's a different placement, so keep it */
1082 new_list.push_back (*i);
1086 _processors = new_list;
1089 /* FIXME: can't see how this test can ever fire */
1090 if (processor_max_outs != old_rmo) {
1094 processor_max_outs.reset();
1095 _have_internal_generator = false;
1096 processors_changed (); /* EMIT SIGNAL */
1100 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1102 ChanCount old_rmo = processor_max_outs;
1104 if (!_session.engine().connected()) {
1108 processor_max_outs.reset();
1111 Glib::RWLock::WriterLock lm (_processor_lock);
1112 ProcessorList::iterator i;
1113 bool removed = false;
1115 for (i = _processors.begin(); i != _processors.end(); ++i) {
1116 if (*i == processor) {
1118 ProcessorList::iterator tmp;
1120 /* move along, see failure case for reset_plugin_counts()
1121 where we may need to reprocessor the processor.
1127 /* stop redirects that send signals to JACK ports
1128 from causing noise as a result of no longer being
1132 boost::shared_ptr<IOProcessor> redirect;
1134 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1135 redirect->io()->disconnect_inputs (this);
1136 redirect->io()->disconnect_outputs (this);
1139 _processors.erase (i);
1154 if (_reset_plugin_counts (err)) {
1155 /* get back to where we where */
1156 _processors.insert (i, processor);
1157 /* we know this will work, because it worked before :) */
1158 _reset_plugin_counts (0);
1164 for (i = _processors.begin(); i != _processors.end(); ++i) {
1165 boost::shared_ptr<PluginInsert> pi;
1167 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1168 if (pi->is_generator()) {
1174 _have_internal_generator = foo;
1177 if (old_rmo != processor_max_outs) {
1181 processor->drop_references ();
1183 processors_changed (); /* EMIT SIGNAL */
1188 Route::reset_plugin_counts (ProcessorStreams* err)
1190 Glib::RWLock::WriterLock lm (_processor_lock);
1191 return _reset_plugin_counts (err);
1196 Route::_reset_plugin_counts (ProcessorStreams* err)
1198 ProcessorList::iterator r;
1199 map<Placement,list<ProcessorCount> > processor_map;
1200 ChanCount initial_streams;
1201 ChanCount post_fader_input;
1204 /* Process each placement in order, checking to see if we
1205 can really do what has been requested.
1208 /* divide processors up by placement so we get the signal flow
1209 properly modelled. we need to do this because the _processors
1210 list is not sorted by placement, and because other reasons may
1211 exist now or in the future for this separate treatment.
1214 /* ... but it should/will be... */
1216 for (r = _processors.begin(); r != _processors.end(); ++r) {
1218 boost::shared_ptr<Processor> processor;
1220 if ((processor = boost::dynamic_pointer_cast<Processor>(*r)) != 0) {
1221 processor_map[processor->placement()].push_back (ProcessorCount (processor));
1227 if ( ! check_some_plugin_counts (processor_map[PreFader], n_inputs (), err)) {
1231 post_fader_input = (err ? err->count : n_inputs());
1235 if ( ! check_some_plugin_counts (processor_map[PostFader], post_fader_input, err)) {
1239 /* OK, everything can be set up correctly, so lets do it */
1241 apply_some_plugin_counts (processor_map[PreFader]);
1242 apply_some_plugin_counts (processor_map[PostFader]);
1244 /* recompute max outs of any processor */
1249 processor_max_outs.reset();
1251 for (r = _processors.begin(); r != _processors.end(); ++r) {
1252 processor_max_outs = max ((*r)->output_streams (), processor_max_outs);
1259 Route::apply_some_plugin_counts (list<ProcessorCount>& iclist)
1261 list<ProcessorCount>::iterator i;
1263 for (i = iclist.begin(); i != iclist.end(); ++i) {
1265 cerr << "now applying for " << (*i).processor->name() << " in = " << (*i).in.n_audio() << " out = " << (*i).out.n_audio() << endl;
1267 if ((*i).processor->configure_io ((*i).in, (*i).out)) {
1270 /* make sure that however many we have, they are all active */
1271 (*i).processor->activate ();
1277 /** Returns whether \a iclist can be configured and run starting with
1278 * \a required_inputs at the first processor's inputs.
1279 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1280 * Otherwise, \a err is set to the output of the list.
1283 Route::check_some_plugin_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1285 list<ProcessorCount>::iterator i;
1290 err->count = required_inputs;
1293 for (i = iclist.begin(); i != iclist.end(); ++i) {
1296 cerr << "Checking whether " << (*i).processor->name() << " can support " << required_inputs.n_audio() << " inputs\n";
1298 if ((*i).processor->can_support_input_configuration (required_inputs) < 0) {
1301 err->count = required_inputs;
1306 (*i).in = required_inputs;
1307 (*i).out = (*i).processor->output_for_input_configuration (required_inputs);
1309 cerr << "config looks like " << (*i).processor->name() << " in = " << (*i).in.n_audio() << " out = " << (*i).out.n_audio() << endl;
1311 required_inputs = (*i).out;
1317 if (!iclist.empty()) {
1319 err->count = iclist.back().processor->output_for_input_configuration(required_inputs);
1327 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1329 ChanCount old_rmo = processor_max_outs;
1331 ProcessorList to_be_deleted;
1334 Glib::RWLock::WriterLock lm (_processor_lock);
1335 ProcessorList::iterator tmp;
1336 ProcessorList the_copy;
1338 the_copy = _processors;
1340 /* remove all relevant processors */
1342 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1346 if ((*i)->placement() == placement) {
1347 to_be_deleted.push_back (*i);
1348 _processors.erase (i);
1354 /* now copy the relevant ones from "other" */
1356 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1357 if ((*i)->placement() == placement) {
1358 _processors.push_back (IOProcessor::clone (*i));
1362 /* reset plugin stream handling */
1364 if (_reset_plugin_counts (err)) {
1366 /* FAILED COPY ATTEMPT: we have to restore order */
1368 /* delete all cloned processors */
1370 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1375 if ((*i)->placement() == placement) {
1376 _processors.erase (i);
1382 /* restore the natural order */
1384 _processors = the_copy;
1385 processor_max_outs = old_rmo;
1387 /* we failed, even though things are OK again */
1393 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1394 to_be_deleted.clear ();
1399 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
1403 processors_changed (); /* EMIT SIGNAL */
1408 Route::all_processors_flip ()
1410 Glib::RWLock::ReaderLock lm (_processor_lock);
1412 if (_processors.empty()) {
1416 bool first_is_on = _processors.front()->active();
1418 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1419 (*i)->set_active (!first_is_on);
1422 _session.set_dirty ();
1425 /** Set all processors with a given placement to a given active state.
1426 * @param p Placement of processors to change.
1427 * @param state New active state for those processors.
1430 Route::all_processors_active (Placement p, bool state)
1432 Glib::RWLock::ReaderLock lm (_processor_lock);
1434 if (_processors.empty()) {
1438 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1439 if ((*i)->placement() == p) {
1440 (*i)->set_active (state);
1444 _session.set_dirty ();
1447 struct ProcessorSorter {
1448 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1449 return a->sort_key() < b->sort_key();
1454 Route::sort_processors (ProcessorStreams* err)
1457 ProcessorSorter comparator;
1458 Glib::RWLock::WriterLock lm (_processor_lock);
1459 ChanCount old_rmo = processor_max_outs;
1461 /* the sweet power of C++ ... */
1463 ProcessorList as_it_was_before = _processors;
1465 _processors.sort (comparator);
1467 if (_reset_plugin_counts (err)) {
1468 _processors = as_it_was_before;
1469 processor_max_outs = old_rmo;
1475 processors_changed (); /* EMIT SIGNAL */
1487 Route::get_template()
1489 return state(false);
1493 Route::state(bool full_state)
1495 XMLNode *node = new XMLNode("Route");
1496 ProcessorList::iterator i;
1500 node->add_property("flags", enum_2_string (_flags));
1503 node->add_property("default-type", _default_type.to_string());
1505 node->add_property("active", _active?"yes":"no");
1506 node->add_property("muted", _muted?"yes":"no");
1507 node->add_property("soloed", _soloed?"yes":"no");
1508 node->add_property("phase-invert", _phase_invert?"yes":"no");
1509 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1510 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1511 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1512 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1513 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1516 node->add_property("edit-group", _edit_group->name());
1519 node->add_property("mix-group", _mix_group->name());
1522 string order_string;
1523 OrderKeys::iterator x = order_keys.begin();
1525 while (x != order_keys.end()) {
1526 order_string += string ((*x).first);
1527 order_string += '=';
1528 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1529 order_string += buf;
1533 if (x == order_keys.end()) {
1537 order_string += ':';
1539 node->add_property ("order-keys", order_string);
1541 node->add_child_nocopy (IO::state (full_state));
1542 node->add_child_nocopy (_solo_control->get_state ());
1543 node->add_child_nocopy (_mute_control->get_state ());
1545 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1546 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1547 remote_control_node->add_property (X_("id"), buf);
1548 node->add_child_nocopy (*remote_control_node);
1550 if (_control_outs) {
1551 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1552 cnode->add_child_nocopy (_control_outs->state (full_state));
1553 node->add_child_nocopy (*cnode);
1556 if (_comment.length()) {
1557 XMLNode *cmt = node->add_child ("Comment");
1558 cmt->add_content (_comment);
1561 for (i = _processors.begin(); i != _processors.end(); ++i) {
1562 node->add_child_nocopy((*i)->state (full_state));
1566 node->add_child_copy (*_extra_xml);
1573 Route::get_processor_state ()
1575 XMLNode* root = new XMLNode (X_("redirects"));
1576 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1577 root->add_child_nocopy ((*i)->state (true));
1584 Route::set_processor_state (const XMLNode& root)
1586 if (root.name() != X_("redirects")) {
1592 XMLNodeConstIterator iter;
1593 XMLNodeConstIterator niter;
1594 Glib::RWLock::ReaderLock lm (_processor_lock);
1596 nlist = root.children();
1598 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1600 /* iter now points to a IOProcessor state node */
1602 nnlist = (*iter)->children ();
1604 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1606 /* find the IO child node, since it contains the ID we need */
1608 /* XXX OOP encapsulation violation, ugh */
1610 if ((*niter)->name() == IO::state_node_name) {
1612 XMLProperty* prop = (*niter)->property (X_("id"));
1615 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1619 ID id = prop->value ();
1621 /* now look for a processor with that ID */
1623 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1624 if ((*i)->id() == id) {
1625 (*i)->set_state (**iter);
1641 Route::set_deferred_state ()
1644 XMLNodeConstIterator niter;
1646 if (!deferred_state) {
1650 nlist = deferred_state->children();
1652 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1653 add_processor_from_xml (**niter);
1656 delete deferred_state;
1661 Route::add_processor_from_xml (const XMLNode& node)
1663 const XMLProperty *prop;
1665 // legacy sessions use a different node name for sends
1666 if (node.name() == "Send") {
1669 boost::shared_ptr<Send> send (new Send (_session, node));
1670 add_processor (send);
1673 catch (failed_constructor &err) {
1674 error << _("Send construction failed") << endmsg;
1678 // use "Processor" in XML?
1679 } else if (node.name() == "Processor") {
1682 if ((prop = node.property ("type")) != 0) {
1684 boost::shared_ptr<Processor> processor;
1685 bool have_insert = false;
1687 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1688 prop->value() == "lv2" ||
1689 prop->value() == "vst" ||
1690 prop->value() == "audiounit") {
1692 processor.reset (new PluginInsert(_session, node));
1695 } else if (prop->value() == "port") {
1697 processor.reset (new PortInsert (_session, node));
1699 } else if (prop->value() == "send") {
1701 processor.reset (new Send (_session, node));
1706 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
1709 add_processor (processor);
1712 error << _("Processor XML node has no type property") << endmsg;
1716 catch (failed_constructor &err) {
1717 warning << _("processor could not be created. Ignored.") << endmsg;
1724 Route::set_state (const XMLNode& node)
1726 return _set_state (node, true);
1730 Route::_set_state (const XMLNode& node, bool call_base)
1733 XMLNodeConstIterator niter;
1735 XMLPropertyList plist;
1736 const XMLProperty *prop;
1738 if (node.name() != "Route"){
1739 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1743 if ((prop = node.property (X_("flags"))) != 0) {
1744 _flags = Flag (string_2_enum (prop->value(), _flags));
1749 if ((prop = node.property (X_("default-type"))) != 0) {
1750 _default_type = DataType(prop->value());
1751 assert(_default_type != DataType::NIL);
1754 if ((prop = node.property (X_("phase-invert"))) != 0) {
1755 set_phase_invert (prop->value()=="yes"?true:false, this);
1758 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1759 set_denormal_protection (prop->value()=="yes"?true:false, this);
1763 if ((prop = node.property (X_("active"))) != 0) {
1764 set_active (prop->value() == "yes");
1767 if ((prop = node.property (X_("muted"))) != 0) {
1768 bool yn = prop->value()=="yes"?true:false;
1770 /* force reset of mute status */
1774 mute_gain = desired_mute_gain;
1777 if ((prop = node.property (X_("soloed"))) != 0) {
1778 bool yn = prop->value()=="yes"?true:false;
1780 /* force reset of solo status */
1783 set_solo (yn, this);
1784 solo_gain = desired_solo_gain;
1787 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1788 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1791 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1792 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1795 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1796 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1799 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1800 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1803 if ((prop = node.property (X_("edit-group"))) != 0) {
1804 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1805 if(edit_group == 0) {
1806 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1808 set_edit_group(edit_group, this);
1812 if ((prop = node.property (X_("order-keys"))) != 0) {
1816 string::size_type colon, equal;
1817 string remaining = prop->value();
1819 while (remaining.length()) {
1821 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1822 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1825 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1826 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1829 set_order_key (remaining.substr (0, equal).c_str(), n);
1833 colon = remaining.find_first_of (':');
1835 if (colon != string::npos) {
1836 remaining = remaining.substr (colon+1);
1843 nlist = node.children();
1845 if (deferred_state) {
1846 delete deferred_state;
1849 deferred_state = new XMLNode(X_("deferred state"));
1851 /* set parent class properties before anything else */
1853 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1857 if (child->name() == IO::state_node_name && call_base) {
1859 IO::set_state (*child);
1864 XMLNodeList processor_nodes;
1866 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1870 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
1871 processor_nodes.push_back(child);
1876 _set_processor_states(processor_nodes);
1879 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1881 // All processors have been applied already
1883 if (child->name() == X_("Automation")) {
1885 if ((prop = child->property (X_("path"))) != 0) {
1886 load_automation (prop->value());
1889 } else if (child->name() == X_("ControlOuts")) {
1891 string coutname = _name;
1892 coutname += _("[control]");
1894 _control_outs = new IO (_session, coutname);
1895 _control_outs->set_state (**(child->children().begin()));
1897 } else if (child->name() == X_("Comment")) {
1899 /* XXX this is a terrible API design in libxml++ */
1901 XMLNode *cmt = *(child->children().begin());
1902 _comment = cmt->content();
1904 } else if (child->name() == X_("extra")) {
1906 _extra_xml = new XMLNode (*child);
1908 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1910 if (prop->value() == "solo") {
1911 _solo_control->set_state (*child);
1912 _session.add_controllable (_solo_control);
1914 else if (prop->value() == "mute") {
1915 _mute_control->set_state (*child);
1916 _session.add_controllable (_mute_control);
1919 else if (child->name() == X_("remote_control")) {
1920 if ((prop = child->property (X_("id"))) != 0) {
1922 sscanf (prop->value().c_str(), "%d", &x);
1923 set_remote_control_id (x);
1928 if ((prop = node.property (X_("mix-group"))) != 0) {
1929 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1930 if (mix_group == 0) {
1931 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1933 set_mix_group(mix_group, this);
1941 Route::_set_processor_states(const XMLNodeList &nlist)
1943 XMLNodeConstIterator niter;
1946 ProcessorList::iterator i, o;
1948 // Iterate through existing processors, remove those which are not in the state list
1949 for (i = _processors.begin(); i != _processors.end(); ) {
1950 ProcessorList::iterator tmp = i;
1953 bool processorInStateList = false;
1955 (*i)->id().print (buf, sizeof (buf));
1958 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1960 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
1961 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1962 processorInStateList = true;
1964 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1965 processorInStateList = true;
1970 if (!processorInStateList) {
1971 remove_processor (*i);
1979 // Iterate through state list and make sure all processors are on the track and in the correct order,
1980 // set the state of existing processors according to the new state on the same go
1981 i = _processors.begin();
1982 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1984 // Check whether the next processor in the list
1987 while (o != _processors.end()) {
1988 (*o)->id().print (buf, sizeof (buf));
1989 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1991 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1997 if (o == _processors.end()) {
1998 // If the processor (*niter) is not on the route, we need to create it
1999 // and move it to the correct location
2001 ProcessorList::iterator prev_last = _processors.end();
2002 --prev_last; // We need this to check whether adding succeeded
2004 add_processor_from_xml (**niter);
2006 ProcessorList::iterator last = _processors.end();
2009 if (prev_last == last) {
2010 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2015 boost::shared_ptr<Processor> tmp = (*last);
2016 // remove the processor from the wrong location
2017 _processors.erase(last);
2018 // processor the new processor at the current location
2019 _processors.insert(i, tmp);
2021 --i; // move pointer to the newly processored processor
2025 // We found the processor (*niter) on the route, first we must make sure the processor
2026 // is at the location provided in the XML state
2028 boost::shared_ptr<Processor> tmp = (*o);
2029 // remove the old copy
2030 _processors.erase(o);
2031 // processor the processor at the correct location
2032 _processors.insert(i, tmp);
2034 --i; // move pointer so it points to the right processor
2037 (*i)->set_state( (**niter) );
2040 processors_changed ();
2044 Route::curve_reallocate ()
2046 // _gain_automation_curve.finish_resize ();
2047 // _pan_automation_curve.finish_resize ();
2051 Route::silence (nframes_t nframes, nframes_t offset)
2055 IO::silence (nframes, offset);
2057 if (_control_outs) {
2058 _control_outs->silence (nframes, offset);
2062 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2065 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2066 boost::shared_ptr<PluginInsert> pi;
2067 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2068 // skip plugins, they don't need anything when we're not active
2072 (*i)->silence (nframes, offset);
2075 if (nframes == _session.get_block_size() && offset == 0) {
2085 Route::set_control_outs (const vector<string>& ports)
2087 Glib::Mutex::Lock lm (_control_outs_lock);
2088 vector<string>::const_iterator i;
2091 if (_control_outs) {
2092 delete _control_outs;
2096 if (is_control() || is_master()) {
2097 /* no control outs for these two special busses */
2101 if (ports.empty()) {
2105 string coutname = _name;
2106 coutname += _("[control]");
2108 _control_outs = new IO (_session, coutname);
2110 /* our control outs need as many outputs as we
2111 have audio outputs. we track the changes in ::output_change_handler().
2114 // XXX its stupid that we have to get this value twice
2116 limit = n_outputs().n_audio();
2118 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2122 /* now connect to the named ports */
2124 for (size_t n = 0; n < limit; ++n) {
2125 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2126 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2135 Route::set_edit_group (RouteGroup *eg, void *src)
2138 if (eg == _edit_group) {
2143 _edit_group->remove (this);
2146 if ((_edit_group = eg) != 0) {
2147 _edit_group->add (this);
2150 _session.set_dirty ();
2151 edit_group_changed (src); /* EMIT SIGNAL */
2155 Route::drop_edit_group (void *src)
2158 _session.set_dirty ();
2159 edit_group_changed (src); /* EMIT SIGNAL */
2163 Route::set_mix_group (RouteGroup *mg, void *src)
2166 if (mg == _mix_group) {
2171 _mix_group->remove (this);
2174 if ((_mix_group = mg) != 0) {
2175 _mix_group->add (this);
2178 _session.set_dirty ();
2179 mix_group_changed (src); /* EMIT SIGNAL */
2183 Route::drop_mix_group (void *src)
2186 _session.set_dirty ();
2187 mix_group_changed (src); /* EMIT SIGNAL */
2191 Route::set_comment (string cmt, void *src)
2194 comment_changed (src);
2195 _session.set_dirty ();
2199 Route::feeds (boost::shared_ptr<Route> other)
2204 uint32_t no = self.n_outputs().n_total();
2205 uint32_t ni = other->n_inputs ().n_total();
2207 for (i = 0; i < no; ++i) {
2208 for (j = 0; j < ni; ++j) {
2209 if (self.output(i)->connected_to (other->input(j)->name())) {
2215 /* check IOProcessors which may also interconnect Routes */
2217 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2219 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2224 // TODO: support internal redirects here
2226 no = redirect->io()->n_outputs().n_total();
2228 for (i = 0; i < no; ++i) {
2229 for (j = 0; j < ni; ++j) {
2230 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2237 /* check for control room outputs which may also interconnect Routes */
2239 if (_control_outs) {
2241 no = _control_outs->n_outputs().n_total();
2243 for (i = 0; i < no; ++i) {
2244 for (j = 0; j < ni; ++j) {
2245 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2256 Route::set_mute_config (mute_type t, bool onoff, void *src)
2260 _mute_affects_pre_fader = onoff;
2261 pre_fader_changed(src); /* EMIT SIGNAL */
2265 _mute_affects_post_fader = onoff;
2266 post_fader_changed(src); /* EMIT SIGNAL */
2270 _mute_affects_control_outs = onoff;
2271 control_outs_changed(src); /* EMIT SIGNAL */
2275 _mute_affects_main_outs = onoff;
2276 main_outs_changed(src); /* EMIT SIGNAL */
2282 Route::get_mute_config (mute_type t)
2288 onoff = _mute_affects_pre_fader;
2291 onoff = _mute_affects_post_fader;
2294 onoff = _mute_affects_control_outs;
2297 onoff = _mute_affects_main_outs;
2305 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2307 nframes_t now = _session.transport_frame();
2310 Glib::RWLock::ReaderLock lm (_processor_lock);
2313 automation_snapshot (now, true);
2316 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2318 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2319 (*i)->deactivate ();
2323 (*i)->transport_stopped (now);
2327 IO::transport_stopped (now);
2329 _roll_delay = _initial_delay;
2333 Route::input_change_handler (IOChange change, void *ignored)
2335 if (change & ConfigurationChanged) {
2336 reset_plugin_counts (0);
2341 Route::output_change_handler (IOChange change, void *ignored)
2343 if (change & ConfigurationChanged) {
2344 if (_control_outs) {
2345 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2348 reset_plugin_counts (0);
2353 Route::pans_required () const
2355 if (n_outputs().n_audio() < 2) {
2359 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2363 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2364 bool session_state_changing, bool can_record, bool rec_monitors_input)
2366 if (n_outputs().n_total() == 0) {
2370 if (session_state_changing || !_active) {
2371 silence (nframes, offset);
2375 apply_gain_automation = false;
2377 if (n_inputs().n_total()) {
2378 passthru (start_frame, end_frame, nframes, offset, 0, false);
2380 silence (nframes, offset);
2387 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2389 if (_roll_delay > nframes) {
2391 _roll_delay -= nframes;
2392 silence (nframes, offset);
2393 /* transport frame is not legal for caller to use */
2396 } else if (_roll_delay > 0) {
2398 nframes -= _roll_delay;
2400 silence (_roll_delay, offset);
2402 offset += _roll_delay;
2403 transport_frame += _roll_delay;
2412 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2413 bool can_record, bool rec_monitors_input)
2416 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2418 // automation snapshot can also be called from the non-rt context
2419 // and it uses the processor list, so we take the lock out here
2420 automation_snapshot (_session.transport_frame(), false);
2424 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2425 silence (nframes, offset);
2429 nframes_t unused = 0;
2431 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2437 apply_gain_automation = false;
2440 Glib::Mutex::Lock am (_automation_lock, Glib::TRY_LOCK);
2442 if (am.locked() && _session.transport_rolling()) {
2444 if (_gain_control->list()->automation_playback()) {
2445 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2446 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2451 passthru (start_frame, end_frame, nframes, offset, declick, false);
2457 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2458 bool can_record, bool rec_monitors_input)
2460 silence (nframes, offset);
2465 Route::toggle_monitor_input ()
2467 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2468 i->ensure_monitor_input( ! i->monitoring_input());
2473 Route::has_external_redirects () const
2475 // FIXME: what about sends?
2477 boost::shared_ptr<const PortInsert> pi;
2479 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2480 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2482 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2483 port != pi->io()->outputs().end(); ++port) {
2485 string port_name = port->name();
2486 string client_name = port_name.substr (0, port_name.find(':'));
2488 /* only say "yes" if the redirect is actually in use */
2490 if (client_name != "ardour" && pi->active()) {
2501 Route::flush_processors ()
2503 /* XXX shouldn't really try to take this lock, since
2504 this is called from the RT audio thread.
2507 Glib::RWLock::ReaderLock lm (_processor_lock);
2509 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2510 (*i)->deactivate ();
2516 Route::set_meter_point (MeterPoint p, void *src)
2518 if (_meter_point != p) {
2520 meter_change (src); /* EMIT SIGNAL */
2521 _session.set_dirty ();
2526 Route::update_total_latency ()
2528 nframes_t old = _own_latency;
2530 if (_user_latency) {
2531 _own_latency = _user_latency;
2535 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2536 if ((*i)->active ()) {
2537 _own_latency += (*i)->signal_latency ();
2542 set_port_latency (_own_latency);
2544 if (!_user_latency) {
2545 /* this (virtual) function is used for pure Routes,
2546 not derived classes like AudioTrack. this means
2547 that the data processed here comes from an input
2548 port, not prerecorded material, and therefore we
2549 have to take into account any input latency.
2553 _own_latency += input_latency ();
2556 if (old != _own_latency) {
2557 signal_latency_changed (); /* EMIT SIGNAL */
2560 return _own_latency;
2564 Route::set_user_latency (nframes_t nframes)
2566 Latent::set_user_latency (nframes);
2567 _session.update_latency_compensation (false, false);
2571 Route::set_latency_delay (nframes_t longest_session_latency)
2573 nframes_t old = _initial_delay;
2575 if (_own_latency < longest_session_latency) {
2576 _initial_delay = longest_session_latency - _own_latency;
2581 if (_initial_delay != old) {
2582 initial_delay_changed (); /* EMIT SIGNAL */
2585 if (_session.transport_stopped()) {
2586 _roll_delay = _initial_delay;
2591 Route::automation_snapshot (nframes_t now, bool force)
2593 if (!force && !should_snapshot(now)) {
2597 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2598 // IO::automation_snapshot (now, force); ?
2599 (*i)->automation_snapshot (now, force);
2603 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2604 : Controllable (name), route (s), type(tp)
2610 Route::ToggleControllable::set_value (float val)
2612 bool bval = ((val >= 0.5f) ? true: false);
2616 route.set_mute (bval, this);
2619 route.set_solo (bval, this);
2627 Route::ToggleControllable::get_value (void) const
2633 val = route.muted() ? 1.0f : 0.0f;
2636 val = route.soloed() ? 1.0f : 0.0f;
2646 Route::set_block_size (nframes_t nframes)
2648 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2649 (*i)->set_block_size (nframes);
2654 Route::protect_automation ()
2656 Automatable::protect_automation();
2658 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2659 (*i)->protect_automation();
2663 Route::set_pending_declick (int declick)
2666 /* this call is not allowed to turn off a pending declick unless "force" is true */
2668 _pending_declick = declick;
2670 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2672 _pending_declick = 0;