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>
27 #include <pbd/stacktrace.h>
28 #include <pbd/memento_command.h>
30 #include <ardour/timestamps.h>
31 #include <ardour/buffer.h>
32 #include <ardour/audioengine.h>
33 #include <ardour/route.h>
34 #include <ardour/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/ladspa_plugin.h>
43 #include <ardour/panner.h>
44 #include <ardour/dB.h>
45 #include <ardour/mix.h>
46 #include <ardour/profile.h>
51 using namespace ARDOUR
;
54 uint32_t Route::order_key_cnt
= 0;
55 sigc::signal
<void,const char*> Route::SyncOrderKeys
;
57 Route::Route (Session
& sess
, string name
, int input_min
, int input_max
, int output_min
, int output_max
, Flag flg
, DataType default_type
)
58 : IO (sess
, name
, input_min
, input_max
, output_min
, output_max
, default_type
),
60 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl
),
61 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl
)
66 Route::Route (Session
& sess
, const XMLNode
& node
, DataType default_type
)
67 : IO (sess
, *node
.child ("IO"), default_type
),
68 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl
),
69 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl
)
72 _set_state (node
, false);
78 redirect_max_outs
= 0;
82 _phase_invert
= false;
83 _denormal_protection
= false;
84 order_keys
[strdup (N_("signal"))] = order_key_cnt
++;
86 _meter_point
= MeterPostFader
;
90 _have_internal_generator
= false;
92 _pending_declick
= true;
93 _remote_control_id
= 0;
94 _ignore_gain_on_deliver
= true;
99 _mute_affects_pre_fader
= Config
->get_mute_affects_pre_fader();
100 _mute_affects_post_fader
= Config
->get_mute_affects_post_fader();
101 _mute_affects_control_outs
= Config
->get_mute_affects_control_outs();
102 _mute_affects_main_outs
= Config
->get_mute_affects_main_outs();
105 desired_solo_gain
= 1.0;
107 desired_mute_gain
= 1.0;
111 input_changed
.connect (mem_fun (this, &Route::input_change_handler
));
112 output_changed
.connect (mem_fun (this, &Route::output_change_handler
));
117 clear_redirects (PreFader
, this);
118 clear_redirects (PostFader
, this);
120 for (OrderKeys::iterator i
= order_keys
.begin(); i
!= order_keys
.end(); ++i
) {
121 free ((void*)(i
->first
));
125 delete _control_outs
;
130 Route::set_remote_control_id (uint32_t id
)
132 if (id
!= _remote_control_id
) {
133 _remote_control_id
= id
;
134 RemoteControlIDChanged ();
139 Route::remote_control_id() const
141 return _remote_control_id
;
145 Route::order_key (const char* name
) const
147 OrderKeys::const_iterator i
;
149 for (i
= order_keys
.begin(); i
!= order_keys
.end(); ++i
) {
150 if (!strcmp (name
, i
->first
)) {
159 Route::set_order_key (const char* name
, long n
)
161 order_keys
[strdup(name
)] = n
;
163 if (Config
->get_sync_all_route_ordering()) {
164 for (OrderKeys::iterator x
= order_keys
.begin(); x
!= order_keys
.end(); ++x
) {
169 _session
.set_dirty ();
173 Route::sync_order_keys (const char* base
)
175 if (order_keys
.empty()) {
179 OrderKeys::iterator i
;
182 if ((i
= order_keys
.find (base
)) == order_keys
.end()) {
183 /* key doesn't exist, use the first existing
184 key (this is done during session initialization)
186 i
= order_keys
.begin();
190 /* key exists - use it and reset all others
191 (actually, itself included)
193 i
= order_keys
.begin();
197 for (; i
!= order_keys
.end(); ++i
) {
203 Route::ensure_track_or_route_name(string name
, Session
&session
)
205 string newname
= name
;
207 while (session
.route_by_name (newname
)!=NULL
)
209 newname
= bump_name_once (newname
);
217 Route::inc_gain (gain_t fraction
, void *src
)
219 IO::inc_gain (fraction
, src
);
223 Route::set_gain (gain_t val
, void *src
)
225 if (src
!= 0 && _mix_group
&& src
!= _mix_group
&& _mix_group
->is_active()) {
227 if (_mix_group
->is_relative()) {
230 gain_t usable_gain
= gain();
231 if (usable_gain
< 0.000001f
) {
232 usable_gain
=0.000001f
;
236 if (delta
< 0.000001f
) {
240 delta
-= usable_gain
;
242 if (delta
== 0.0f
) return;
244 gain_t factor
= delta
/ usable_gain
;
247 factor
= _mix_group
->get_max_factor(factor
);
248 if (factor
== 0.0f
) {
253 factor
= _mix_group
->get_min_factor(factor
);
254 if (factor
== 0.0f
) {
260 _mix_group
->apply (&Route::inc_gain
, factor
, _mix_group
);
264 _mix_group
->apply (&Route::set_gain
, val
, _mix_group
);
274 IO::set_gain (val
, src
);
278 Route::process_output_buffers (vector
<Sample
*>& bufs
, uint32_t nbufs
,
279 nframes_t start_frame
, nframes_t end_frame
,
280 nframes_t nframes
, bool with_redirects
, int declick
,
284 RedirectList::iterator i
;
285 bool post_fader_work
= false;
286 bool mute_declick_applied
= false;
288 vector
<Sample
*>::iterator bufiter
;
293 gain_t
* gab
= _session
.gain_automation_buffer();
295 switch (Config
->get_monitoring_model()) {
296 case HardwareMonitoring
:
297 case ExternalMonitoring
:
304 declick
= _pending_declick
;
307 Glib::Mutex::Lock
cm (control_outs_lock
, Glib::TRY_LOCK
);
317 Glib::Mutex::Lock
dm (declick_lock
, Glib::TRY_LOCK
);
320 dmg
= desired_mute_gain
;
321 dsg
= desired_solo_gain
;
330 /* ----------------------------------------------------------------------------------------------------
331 GLOBAL DECLICK (for transport changes etc.)
332 -------------------------------------------------------------------------------------------------- */
335 apply_declick (bufs
, nbufs
, nframes
, 0.0, 1.0, false);
336 _pending_declick
= 0;
337 } else if (declick
< 0) {
338 apply_declick (bufs
, nbufs
, nframes
, 1.0, 0.0, false);
339 _pending_declick
= 0;
342 /* no global declick */
344 if (solo_gain
!= dsg
) {
345 apply_declick (bufs
, nbufs
, nframes
, solo_gain
, dsg
, false);
351 /* ----------------------------------------------------------------------------------------------------
352 INPUT METERING & MONITORING
353 -------------------------------------------------------------------------------------------------- */
355 if (meter
&& (_meter_point
== MeterInput
)) {
356 for (n
= 0; n
< nbufs
; ++n
) {
357 _peak_power
[n
] = Session::compute_peak (bufs
[n
], nframes
, _peak_power
[n
]);
361 if (!_soloed
&& _mute_affects_pre_fader
&& (mute_gain
!= dmg
)) {
362 apply_declick (bufs
, nbufs
, nframes
, mute_gain
, dmg
, false);
364 mute_declick_applied
= true;
367 if ((_meter_point
== MeterInput
) && co
) {
369 solo_audible
= dsg
> 0;
370 mute_audible
= dmg
> 0;// || !_mute_affects_pre_fader;
372 if ( // muted by solo of another track
376 // muted by mute of this track
380 // rec-enabled but not s/w monitoring
382 // TODO: this is probably wrong
384 (no_monitor
&& record_enabled() && (!Config
->get_auto_input() || _session
.actively_recording()))
388 co
->silence (nframes
);
392 co
->deliver_output (bufs
, nbufs
, nframes
);
397 /* -----------------------------------------------------------------------------------------------------
399 -------------------------------------------------------------------------------------------------- */
401 if (_denormal_protection
|| Config
->get_denormal_protection()) {
403 for (n
= 0; n
< nbufs
; ++n
) {
404 Sample
*sp
= bufs
[n
];
406 for (nframes_t nx
= 0; nx
< nframes
; ++nx
) {
413 /* ----------------------------------------------------------------------------------------------------
415 -------------------------------------------------------------------------------------------------- */
417 if (with_redirects
) {
418 Glib::RWLock::ReaderLock
rm (redirect_lock
, Glib::TRY_LOCK
);
420 if (mute_gain
> 0 || !_mute_affects_pre_fader
) {
421 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
422 switch ((*i
)->placement()) {
425 if (boost::dynamic_pointer_cast
<Send
>(*i
) || boost::dynamic_pointer_cast
<PortInsert
>(*i
)) {
426 (*i
)->silence (nframes
);
429 (*i
)->run (bufs
, nbufs
, nframes
);
433 post_fader_work
= true;
438 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
439 switch ((*i
)->placement()) {
441 (*i
)->silence (nframes
);
444 post_fader_work
= true;
453 if (!_soloed
&& (mute_gain
!= dmg
) && !mute_declick_applied
&& _mute_affects_post_fader
) {
454 apply_declick (bufs
, nbufs
, nframes
, mute_gain
, dmg
, false);
456 mute_declick_applied
= true;
459 /* ----------------------------------------------------------------------------------------------------
460 PRE-FADER METERING & MONITORING
461 -------------------------------------------------------------------------------------------------- */
463 if (meter
&& (_meter_point
== MeterPreFader
)) {
464 for (n
= 0; n
< nbufs
; ++n
) {
465 _peak_power
[n
] = Session::compute_peak (bufs
[n
], nframes
, _peak_power
[n
]);
470 if ((_meter_point
== MeterPreFader
) && co
) {
472 solo_audible
= dsg
> 0;
473 mute_audible
= dmg
> 0 || !_mute_affects_pre_fader
;
475 if ( // muted by solo of another track
479 // muted by mute of this track
483 // rec-enabled but not s/w monitoring
485 (no_monitor
&& record_enabled() && (!Config
->get_auto_input() || _session
.actively_recording()))
489 co
->silence (nframes
);
493 co
->deliver_output_no_pan (bufs
, nbufs
, nframes
);
498 /* ----------------------------------------------------------------------------------------------------
500 -------------------------------------------------------------------------------------------------- */
502 /* if not recording or recording and requiring any monitor signal, then apply gain */
504 if ( // not recording
506 !(record_enabled() && _session
.actively_recording()) ||
510 // AND software monitoring required
512 (Config
->get_monitoring_model() == SoftwareMonitoring
)) {
514 if (apply_gain_automation
) {
517 for (n
= 0; n
< nbufs
; ++n
) {
518 Sample
*sp
= bufs
[n
];
520 for (nframes_t nx
= 0; nx
< nframes
; ++nx
) {
525 for (n
= 0; n
< nbufs
; ++n
) {
526 Sample
*sp
= bufs
[n
];
528 for (nframes_t nx
= 0; nx
< nframes
; ++nx
) {
534 if (apply_gain_automation
&& _session
.transport_rolling() && nframes
> 0) {
535 _effective_gain
= gab
[nframes
-1];
540 /* manual (scalar) gain */
544 apply_declick (bufs
, nbufs
, nframes
, _gain
, dg
, _phase_invert
);
547 } else if (_gain
!= 0 && (_phase_invert
|| _gain
!= 1.0)) {
549 /* no need to interpolate current gain value,
550 but its non-unity, so apply it. if the gain
551 is zero, do nothing because we'll ship silence
563 for (n
= 0; n
< nbufs
; ++n
) {
564 Sample
*sp
= bufs
[n
];
565 Session::apply_gain_to_buffer(sp
,nframes
,this_gain
);
568 } else if (_gain
== 0) {
569 for (n
= 0; n
< nbufs
; ++n
) {
570 memset (bufs
[n
], 0, sizeof (Sample
) * nframes
);
577 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
581 /* ----------------------------------------------------------------------------------------------------
583 -------------------------------------------------------------------------------------------------- */
585 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
587 if (post_fader_work
) {
589 Glib::RWLock::ReaderLock
rm (redirect_lock
, Glib::TRY_LOCK
);
591 if (mute_gain
> 0 || !_mute_affects_post_fader
) {
592 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
593 switch ((*i
)->placement()) {
598 if (boost::dynamic_pointer_cast
<Send
>(*i
) || boost::dynamic_pointer_cast
<PortInsert
>(*i
)) {
599 (*i
)->silence (nframes
);
602 (*i
)->run (bufs
, nbufs
, nframes
);
608 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
609 switch ((*i
)->placement()) {
613 (*i
)->silence (nframes
);
621 if (!_soloed
&& (mute_gain
!= dmg
) && !mute_declick_applied
&& _mute_affects_control_outs
) {
622 apply_declick (bufs
, nbufs
, nframes
, mute_gain
, dmg
, false);
624 mute_declick_applied
= true;
627 /* ----------------------------------------------------------------------------------------------------
629 -------------------------------------------------------------------------------------------------- */
631 if ((_meter_point
== MeterPostFader
) && co
) {
633 solo_audible
= solo_gain
> 0;
634 mute_audible
= dmg
> 0 || !_mute_affects_control_outs
;
636 if ( // silent anyway
638 (_gain
== 0 && !apply_gain_automation
) ||
640 // muted by solo of another track
644 // muted by mute of this track
648 // recording but not s/w monitoring
650 (no_monitor
&& record_enabled() && (!Config
->get_auto_input() || _session
.actively_recording()))
654 co
->silence (nframes
);
658 co
->deliver_output_no_pan (bufs
, nbufs
, nframes
);
662 /* ----------------------------------------------------------------------
664 ----------------------------------------------------------------------*/
666 if (!_soloed
&& (mute_gain
!= dmg
) && !mute_declick_applied
&& _mute_affects_main_outs
) {
667 apply_declick (bufs
, nbufs
, nframes
, mute_gain
, dmg
, false);
669 mute_declick_applied
= true;
672 /* ----------------------------------------------------------------------------------------------------
674 -------------------------------------------------------------------------------------------------- */
676 solo_audible
= dsg
> 0;
677 mute_audible
= dmg
> 0 || !_mute_affects_main_outs
;
679 if (n_outputs() == 0) {
683 } else if (no_monitor
&& record_enabled() && (!Config
->get_auto_input() || _session
.actively_recording())) {
685 IO::silence (nframes
);
689 if ( // silent anyway
691 (_gain
== 0 && !apply_gain_automation
) ||
693 // muted by solo of another track, but not using control outs for solo
695 (!solo_audible
&& (Config
->get_solo_model() != SoloBus
)) ||
697 // muted by mute of this track
703 /* don't use Route::silence() here, because that causes
704 all outputs (sends, port inserts, etc. to be silent).
707 if (_meter_point
== MeterPostFader
) {
708 reset_peak_meters ();
711 IO::silence (nframes
);
715 if ((_session
.transport_speed() > 1.5f
||
716 _session
.transport_speed() < -1.5f
) &&
717 Config
->get_quieten_at_speed()) {
718 pan (bufs
, nbufs
, nframes
, speed_quietning
);
720 // cerr << _name << " panner state = " << _panner->automation_state() << endl;
721 if (!_panner
->empty() &&
722 (_panner
->automation_state() & Play
||
723 ((_panner
->automation_state() & Touch
) && !_panner
->touching()))) {
724 pan_automated (bufs
, nbufs
, start_frame
, end_frame
, nframes
);
726 pan (bufs
, nbufs
, nframes
, 1.0);
733 /* ----------------------------------------------------------------------------------------------------
735 -------------------------------------------------------------------------------------------------- */
737 if (meter
&& (_meter_point
== MeterPostFader
)) {
739 if ((_gain
== 0 && !apply_gain_automation
) || dmg
== 0) {
740 uint32_t no
= n_outputs();
741 for (n
= 0; n
< no
; ++n
) {
745 uint32_t no
= n_outputs();
746 for (n
= 0; n
< no
; ++n
) {
747 _peak_power
[n
] = Session::compute_peak (get_output_buffer (n
, nframes
), nframes
, _peak_power
[n
]);
754 Route::n_process_buffers ()
756 return max (n_inputs(), redirect_max_outs
);
761 Route::passthru (nframes_t start_frame
, nframes_t end_frame
, nframes_t nframes
, int declick
, bool meter_first
)
763 vector
<Sample
*>& bufs
= _session
.get_passthru_buffers();
764 uint32_t limit
= n_process_buffers ();
768 collect_input (bufs
, limit
, nframes
);
770 #define meter_stream meter_first
773 for (uint32_t n
= 0; n
< limit
; ++n
) {
774 _peak_power
[n
] = Session::compute_peak (bufs
[n
], nframes
, _peak_power
[n
]);
776 meter_stream
= false;
781 process_output_buffers (bufs
, limit
, start_frame
, end_frame
, nframes
, true, declick
, meter_stream
);
787 Route::set_phase_invert (bool yn
, void *src
)
789 if (_phase_invert
!= yn
) {
791 // phase_invert_changed (src); /* EMIT SIGNAL */
796 Route::set_denormal_protection (bool yn
, void *src
)
798 if (_denormal_protection
!= yn
) {
799 _denormal_protection
= yn
;
800 // denormal_protection_changed (src); /* EMIT SIGNAL */
805 Route::set_solo (bool yn
, void *src
)
811 if (_mix_group
&& src
!= _mix_group
&& _mix_group
->is_active()) {
812 _mix_group
->apply (&Route::set_solo
, yn
, _mix_group
);
818 solo_changed (src
); /* EMIT SIGNAL */
819 _solo_control
.Changed (); /* EMIT SIGNAL */
822 catch_up_on_solo_mute_override ();
826 Route::catch_up_on_solo_mute_override ()
828 if (Config
->get_solo_model() != InverseMute
) {
834 Glib::Mutex::Lock
lm (declick_lock
);
837 if (Config
->get_solo_mute_override()) {
838 desired_mute_gain
= (_soloed
?1.0:0.0);
840 desired_mute_gain
= 0.0;
843 desired_mute_gain
= 1.0;
849 Route::set_solo_mute (bool yn
)
851 Glib::Mutex::Lock
lm (declick_lock
);
853 /* Called by Session in response to another Route being soloed.
856 desired_solo_gain
= (yn
?0.0:1.0);
860 Route::set_solo_safe (bool yn
, void *src
)
862 if (_solo_safe
!= yn
) {
864 solo_safe_changed (src
); /* EMIT SIGNAL */
869 Route::set_mute (bool yn
, void *src
)
872 if (_mix_group
&& src
!= _mix_group
&& _mix_group
->is_active()) {
873 _mix_group
->apply (&Route::set_mute
, yn
, _mix_group
);
879 mute_changed (src
); /* EMIT SIGNAL */
881 _mute_control
.Changed (); /* EMIT SIGNAL */
883 Glib::Mutex::Lock
lm (declick_lock
);
885 if (_soloed
&& Config
->get_solo_mute_override()){
886 desired_mute_gain
= 1.0f
;
888 desired_mute_gain
= (yn
?0.0f
:1.0f
);
894 Route::add_redirect (boost::shared_ptr
<Redirect
> redirect
, void *src
, uint32_t* err_streams
)
896 uint32_t old_rmo
= redirect_max_outs
;
898 if (!_session
.engine().connected()) {
903 Glib::RWLock::WriterLock
lm (redirect_lock
);
905 boost::shared_ptr
<PluginInsert
> pi
;
906 boost::shared_ptr
<PortInsert
> porti
;
908 _redirects
.push_back (redirect
);
910 if (_reset_plugin_counts (err_streams
)) {
911 _redirects
.pop_back ();
912 _reset_plugin_counts (0); // it worked before we tried to add it ...
916 uint32_t potential_max_streams
= 0;
918 if ((pi
= boost::dynamic_pointer_cast
<PluginInsert
>(redirect
)) != 0) {
920 if (pi
->input_streams() == 0) {
921 /* instrument plugin */
922 _have_internal_generator
= true;
925 potential_max_streams
= max(pi
->input_streams(), pi
->output_streams());
927 } else if ((porti
= boost::dynamic_pointer_cast
<PortInsert
>(redirect
)) != 0) {
929 /* force new port inserts to start out with an i/o configuration
930 that matches this route's i/o configuration.
932 the "inputs" for the port are supposed to match the output
935 the "outputs" of the route should match the inputs of this
936 route. XXX shouldn't they match the number of active signal
937 streams at the point of insertion?
941 porti
->ensure_io (n_outputs (), n_inputs(), false, this);
944 // Ensure peak vector sizes before the plugin is activated
945 while (_peak_power
.size() < potential_max_streams
) {
946 _peak_power
.push_back(0);
948 while (_visible_peak_power
.size() < potential_max_streams
) {
949 _visible_peak_power
.push_back(-INFINITY
);
951 while (_max_peak_power
.size() < potential_max_streams
) {
952 _max_peak_power
.push_back(-INFINITY
);
955 redirect
->active_changed
.connect (mem_fun (*this, &Route::redirect_active_proxy
));
958 if (redirect_max_outs
!= old_rmo
|| old_rmo
== 0) {
962 redirects_changed (src
); /* EMIT SIGNAL */
968 Route::add_redirects (const RedirectList
& others
, void *src
, uint32_t* err_streams
)
970 uint32_t old_rmo
= redirect_max_outs
;
972 assert (ports_legal
);
974 if (!_session
.engine().connected()) {
979 Glib::RWLock::WriterLock
lm (redirect_lock
);
981 RedirectList::iterator existing_end
= _redirects
.end();
984 uint32_t potential_max_streams
= 0;
986 for (RedirectList::const_iterator i
= others
.begin(); i
!= others
.end(); ++i
) {
988 boost::shared_ptr
<PluginInsert
> pi
;
990 if ((pi
= boost::dynamic_pointer_cast
<PluginInsert
>(*i
)) != 0) {
993 uint32_t m
= max(pi
->input_streams(), pi
->output_streams());
994 if (m
> potential_max_streams
)
995 potential_max_streams
= m
;
998 // Ensure peak vector sizes before the plugin is activated
999 while (_peak_power
.size() < potential_max_streams
) {
1000 _peak_power
.push_back(0);
1002 while (_visible_peak_power
.size() < potential_max_streams
) {
1003 _visible_peak_power
.push_back(-INFINITY
);
1005 while (_max_peak_power
.size() < potential_max_streams
) {
1006 _max_peak_power
.push_back(-INFINITY
);
1009 _redirects
.push_back (*i
);
1011 if (_reset_plugin_counts (err_streams
)) {
1013 _redirects
.erase (existing_end
, _redirects
.end());
1014 _reset_plugin_counts (0); // it worked before we tried to add it ...
1018 (*i
)->active_changed
.connect (mem_fun (*this, &Route::redirect_active_proxy
));
1022 if (redirect_max_outs
!= old_rmo
|| old_rmo
== 0) {
1026 redirects_changed (src
); /* EMIT SIGNAL */
1030 /** Remove redirects with a given placement.
1031 * @param p Placement of redirects to remove.
1034 Route::clear_redirects (Placement p
, void *src
)
1036 const uint32_t old_rmo
= redirect_max_outs
;
1038 if (!_session
.engine().connected()) {
1043 Glib::RWLock::WriterLock
lm (redirect_lock
);
1044 RedirectList new_list
;
1046 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
1047 if ((*i
)->placement() == p
) {
1048 /* it's the placement we want to get rid of */
1049 (*i
)->drop_references ();
1051 /* it's a different placement, so keep it */
1052 new_list
.push_back (*i
);
1056 _redirects
= new_list
;
1059 /* FIXME: can't see how this test can ever fire */
1060 if (redirect_max_outs
!= old_rmo
) {
1064 redirect_max_outs
= 0;
1065 _have_internal_generator
= false;
1066 redirects_changed (src
); /* EMIT SIGNAL */
1070 Route::remove_redirect (boost::shared_ptr
<Redirect
> redirect
, void *src
, uint32_t* err_streams
)
1072 uint32_t old_rmo
= redirect_max_outs
;
1074 assert (ports_legal
);
1076 if (!_session
.engine().connected()) {
1080 redirect_max_outs
= 0;
1083 Glib::RWLock::WriterLock
lm (redirect_lock
);
1084 RedirectList::iterator i
;
1085 bool removed
= false;
1087 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
1088 if (*i
== redirect
) {
1090 RedirectList::iterator tmp
;
1092 /* move along, see failure case for reset_plugin_counts()
1093 where we may need to reinsert the redirect.
1099 /* stop redirects that send signals to JACK ports
1100 from causing noise as a result of no longer being
1104 boost::shared_ptr
<Send
> send
;
1105 boost::shared_ptr
<PortInsert
> port_insert
;
1107 if ((send
= boost::dynamic_pointer_cast
<Send
> (*i
)) != 0) {
1108 send
->disconnect_inputs (this);
1109 send
->disconnect_outputs (this);
1110 } else if ((port_insert
= boost::dynamic_pointer_cast
<PortInsert
> (*i
)) != 0) {
1111 port_insert
->disconnect_inputs (this);
1112 port_insert
->disconnect_outputs (this);
1115 _redirects
.erase (i
);
1128 if (_reset_plugin_counts (err_streams
)) {
1129 /* get back to where we where */
1130 _redirects
.insert (i
, redirect
);
1131 /* we know this will work, because it worked before :) */
1132 _reset_plugin_counts (0);
1136 _have_internal_generator
= false;
1138 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
1139 boost::shared_ptr
<PluginInsert
> pi
;
1141 if ((pi
= boost::dynamic_pointer_cast
<PluginInsert
>(*i
)) != 0) {
1142 if (pi
->is_generator()) {
1143 _have_internal_generator
= true;
1150 if (old_rmo
!= redirect_max_outs
) {
1154 redirect
->drop_references ();
1155 redirects_changed (src
); /* EMIT SIGNAL */
1161 Route::reset_plugin_counts (uint32_t* lpc
)
1163 Glib::RWLock::WriterLock
lm (redirect_lock
);
1164 return _reset_plugin_counts (lpc
);
1169 Route::_reset_plugin_counts (uint32_t* err_streams
)
1171 RedirectList::iterator r
;
1172 uint32_t insert_cnt
= 0;
1173 uint32_t send_cnt
= 0;
1174 map
<Placement
,list
<InsertCount
> > insert_map
;
1175 RedirectList::iterator prev
;
1176 int32_t initial_streams
= n_inputs ();;
1177 int32_t previous_initial_streams
= n_inputs ();
1180 redirect_max_outs
= 0;
1182 /* Step 1: build a map that links each insert to an in/out channel count
1184 Divide inserts up by placement so we get the signal flow
1185 properly modelled. we need to do this because the _redirects
1186 list is not sorted by placement, and because other reasons may
1187 exist now or in the future for this separate treatment.
1190 for (r
= _redirects
.begin(); r
!= _redirects
.end(); ++r
) {
1192 boost::shared_ptr
<Insert
> insert
;
1194 if ((insert
= boost::dynamic_pointer_cast
<Insert
>(*r
)) != 0) {
1196 insert_map
[insert
->placement()].push_back (InsertCount (insert
));
1198 /* reset plugin counts back to one for now so
1199 that we have a predictable, controlled
1200 state to try to configure.
1203 boost::shared_ptr
<PluginInsert
> pi
;
1205 if ((pi
= boost::dynamic_pointer_cast
<PluginInsert
>(insert
)) != 0) {
1209 } else if (boost::dynamic_pointer_cast
<Send
> (*r
) != 0) {
1214 if (insert_cnt
== 0) {
1223 /* Now process each placement in order, checking to see if we
1224 can really do what has been requested.
1229 if (check_some_plugin_counts (insert_map
[PreFader
], n_inputs (), err_streams
)) {
1233 /* figure out the streams that will feed into PreFader */
1235 if (!insert_map
[PreFader
].empty()) {
1236 previous_initial_streams
= n_inputs ();
1237 for (list
<InsertCount
>::iterator i
= insert_map
[PreFader
].begin(); i
!= insert_map
[PreFader
].end(); i
++) {
1238 if (i
->insert
->can_do (previous_initial_streams
, initial_streams
) < 0) {
1241 previous_initial_streams
= initial_streams
;
1247 if (check_some_plugin_counts (insert_map
[PostFader
], initial_streams
, err_streams
)) {
1251 if (!insert_map
[PostFader
].empty()) {
1252 for (list
<InsertCount
>::iterator i
= insert_map
[PostFader
].begin(); i
!= insert_map
[PostFader
].end(); i
++) {
1253 if (i
->insert
->can_do (previous_initial_streams
, initial_streams
) < 0) {
1256 previous_initial_streams
= initial_streams
;
1260 /* OK, everything can be set up correctly, so lets do it */
1262 apply_some_plugin_counts (insert_map
[PreFader
]);
1263 apply_some_plugin_counts (insert_map
[PostFader
]);
1265 /* recompute max outs of any redirect */
1269 redirect_max_outs
= 0;
1270 prev
= _redirects
.end();
1272 for (r
= _redirects
.begin(); r
!= _redirects
.end(); prev
= r
, ++r
) {
1273 boost::shared_ptr
<Send
> s
;
1275 if ((s
= boost::dynamic_pointer_cast
<Send
> (*r
)) != 0) {
1276 if (r
== _redirects
.begin()) {
1277 s
->expect_inputs (n_inputs());
1279 s
->expect_inputs ((*prev
)->output_streams());
1284 /* don't pay any attention to send output configuration, since it doesn't
1288 redirect_max_outs
= max ((*r
)->output_streams (), redirect_max_outs
);
1297 for (r
= _redirects
.begin(); r
!= _redirects
.end(); ++r
) {
1298 redirect_max_outs
= max ((*r
)->output_streams (), redirect_max_outs
);
1304 Route::apply_some_plugin_counts (list
<InsertCount
>& iclist
)
1306 list
<InsertCount
>::iterator i
;
1308 for (i
= iclist
.begin(); i
!= iclist
.end(); ++i
) {
1310 if ((*i
).insert
->configure_io ((*i
).cnt
, (*i
).in
, (*i
).out
)) {
1313 /* make sure that however many we have, they are all active */
1314 (*i
).insert
->activate ();
1321 Route::check_some_plugin_counts (list
<InsertCount
>& iclist
, int32_t required_inputs
, uint32_t* err_streams
)
1323 list
<InsertCount
>::iterator i
;
1325 for (i
= iclist
.begin(); i
!= iclist
.end(); ++i
) {
1327 if (((*i
).cnt
= (*i
).insert
->can_do (required_inputs
, (*i
).out
)) < 0) {
1329 *err_streams
= required_inputs
;
1334 (*i
).in
= required_inputs
;
1335 required_inputs
= (*i
).out
;
1342 Route::copy_redirects (const Route
& other
, Placement placement
, uint32_t* err_streams
)
1344 uint32_t old_rmo
= redirect_max_outs
;
1350 RedirectList to_be_deleted
;
1353 Glib::RWLock::WriterLock
lm (redirect_lock
);
1354 RedirectList::iterator tmp
;
1355 RedirectList the_copy
;
1357 the_copy
= _redirects
;
1359 /* remove all relevant redirects */
1361 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ) {
1365 if ((*i
)->placement() == placement
) {
1366 to_be_deleted
.push_back (*i
);
1367 _redirects
.erase (i
);
1373 /* now copy the relevant ones from "other" */
1375 for (RedirectList::const_iterator i
= other
._redirects
.begin(); i
!= other
._redirects
.end(); ++i
) {
1376 if ((*i
)->placement() == placement
) {
1377 _redirects
.push_back (Redirect::clone (*i
));
1381 /* reset plugin stream handling */
1383 if (_reset_plugin_counts (err_streams
)) {
1385 /* FAILED COPY ATTEMPT: we have to restore order */
1387 /* delete all cloned redirects */
1389 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ) {
1394 if ((*i
)->placement() == placement
) {
1395 _redirects
.erase (i
);
1401 /* restore the natural order */
1403 _redirects
= the_copy
;
1404 redirect_max_outs
= old_rmo
;
1406 /* we failed, even though things are OK again */
1412 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1413 to_be_deleted
.clear ();
1417 if (redirect_max_outs
!= old_rmo
|| old_rmo
== 0) {
1421 redirects_changed (this); /* EMIT SIGNAL */
1426 Route::all_redirects_flip ()
1428 Glib::RWLock::ReaderLock
lm (redirect_lock
);
1430 if (_redirects
.empty()) {
1434 bool first_is_on
= _redirects
.front()->active();
1436 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
1437 (*i
)->set_active (!first_is_on
, this);
1441 /** Set all redirects with a given placement to a given active state.
1442 * @param p Placement of redirects to change.
1443 * @param state New active state for those redirects.
1446 Route::all_redirects_active (Placement p
, bool state
)
1448 Glib::RWLock::ReaderLock
lm (redirect_lock
);
1450 if (_redirects
.empty()) {
1454 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
1455 if ((*i
)->placement() == p
) {
1456 (*i
)->set_active (state
, this);
1461 struct RedirectSorter
{
1462 bool operator() (boost::shared_ptr
<const Redirect
> a
, boost::shared_ptr
<const Redirect
> b
) {
1463 return a
->sort_key() < b
->sort_key();
1468 Route::sort_redirects (uint32_t* err_streams
)
1471 RedirectSorter comparator
;
1472 Glib::RWLock::WriterLock
lm (redirect_lock
);
1473 uint32_t old_rmo
= redirect_max_outs
;
1475 /* the sweet power of C++ ... */
1477 RedirectList as_it_was_before
= _redirects
;
1479 _redirects
.sort (comparator
);
1481 if (_reset_plugin_counts (err_streams
)) {
1482 _redirects
= as_it_was_before
;
1483 redirect_max_outs
= old_rmo
;
1489 redirects_changed (this); /* EMIT SIGNAL */
1501 Route::get_template()
1503 return state(false);
1507 Route::state(bool full_state
)
1509 XMLNode
*node
= new XMLNode("Route");
1510 RedirectList:: iterator i
;
1514 node
->add_property("flags", enum_2_string (_flags
));
1517 node
->add_property("default-type", _default_type
.to_string());
1519 node
->add_property("muted", _muted
?"yes":"no");
1520 node
->add_property("soloed", _soloed
?"yes":"no");
1521 node
->add_property("phase-invert", _phase_invert
?"yes":"no");
1522 node
->add_property("denormal-protection", _denormal_protection
?"yes":"no");
1523 node
->add_property("mute-affects-pre-fader", _mute_affects_pre_fader
?"yes":"no");
1524 node
->add_property("mute-affects-post-fader", _mute_affects_post_fader
?"yes":"no");
1525 node
->add_property("mute-affects-control-outs", _mute_affects_control_outs
?"yes":"no");
1526 node
->add_property("mute-affects-main-outs", _mute_affects_main_outs
?"yes":"no");
1527 node
->add_property("meter-point", enum_2_string (_meter_point
));
1530 node
->add_property("edit-group", _edit_group
->name());
1533 node
->add_property("mix-group", _mix_group
->name());
1536 string order_string
;
1537 OrderKeys::iterator x
= order_keys
.begin();
1539 while (x
!= order_keys
.end()) {
1540 order_string
+= string ((*x
).first
);
1541 order_string
+= '=';
1542 snprintf (buf
, sizeof(buf
), "%ld", (*x
).second
);
1543 order_string
+= buf
;
1547 if (x
== order_keys
.end()) {
1551 order_string
+= ':';
1553 node
->add_property ("order-keys", order_string
);
1555 node
->add_child_nocopy (IO::state (full_state
));
1556 node
->add_child_nocopy (_solo_control
.get_state ());
1557 node
->add_child_nocopy (_mute_control
.get_state ());
1559 XMLNode
* remote_control_node
= new XMLNode (X_("remote_control"));
1560 snprintf (buf
, sizeof (buf
), "%d", _remote_control_id
);
1561 remote_control_node
->add_property (X_("id"), buf
);
1562 node
->add_child_nocopy (*remote_control_node
);
1564 if (_control_outs
) {
1565 XMLNode
* cnode
= new XMLNode (X_("ControlOuts"));
1566 cnode
->add_child_nocopy (_control_outs
->state (full_state
));
1567 node
->add_child_nocopy (*cnode
);
1570 if (_comment
.length()) {
1571 XMLNode
*cmt
= node
->add_child ("Comment");
1572 cmt
->add_content (_comment
);
1575 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
1576 node
->add_child_nocopy((*i
)->state (full_state
));
1580 node
->add_child_copy (*_extra_xml
);
1587 Route::set_deferred_state ()
1590 XMLNodeConstIterator niter
;
1592 if (!deferred_state
) {
1596 nlist
= deferred_state
->children();
1598 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
){
1599 add_redirect_from_xml (**niter
);
1602 delete deferred_state
;
1607 Route::add_redirect_from_xml (const XMLNode
& node
)
1609 const XMLProperty
*prop
;
1611 if (node
.name() == "Send") {
1615 boost::shared_ptr
<Send
> send (new Send (_session
, node
));
1616 add_redirect (send
, this);
1619 catch (failed_constructor
&err
) {
1620 error
<< _("Send construction failed") << endmsg
;
1624 } else if (node
.name() == "Insert") {
1627 if ((prop
= node
.property ("type")) != 0) {
1629 boost::shared_ptr
<Insert
> insert
;
1630 bool have_insert
= false;
1632 if (prop
->value() == "ladspa" || prop
->value() == "Ladspa" ||
1633 prop
->value() == "lv2" ||
1634 prop
->value() == "vst" ||
1635 prop
->value() == "audiounit") {
1637 insert
.reset (new PluginInsert(_session
, node
));
1640 } else if (prop
->value() == "port") {
1643 insert
.reset (new PortInsert (_session
, node
));
1648 error
<< string_compose(_("unknown Insert type \"%1\"; ignored"), prop
->value()) << endmsg
;
1652 add_redirect (insert
, this);
1656 error
<< _("Insert XML node has no type property") << endmsg
;
1660 catch (failed_constructor
&err
) {
1661 warning
<< _("insert could not be created. Ignored.") << endmsg
;
1668 Route::set_state (const XMLNode
& node
)
1670 return _set_state (node
, true);
1674 Route::_set_state (const XMLNode
& node
, bool call_base
)
1677 XMLNodeConstIterator niter
;
1679 XMLPropertyList plist
;
1680 const XMLProperty
*prop
;
1682 if (node
.name() != "Route"){
1683 error
<< string_compose(_("Bad node sent to Route::set_state() [%1]"), node
.name()) << endmsg
;
1687 if ((prop
= node
.property (X_("flags"))) != 0) {
1688 _flags
= Flag (string_2_enum (prop
->value(), _flags
));
1693 if ((prop
= node
.property (X_("default-type"))) != 0) {
1694 _default_type
= DataType(prop
->value());
1695 assert(_default_type
!= DataType::NIL
);
1698 if ((prop
= node
.property (X_("phase-invert"))) != 0) {
1699 set_phase_invert (string_is_affirmative (prop
->value()), this);
1702 if ((prop
= node
.property (X_("denormal-protection"))) != 0) {
1703 set_denormal_protection (string_is_affirmative (prop
->value()), this);
1706 if ((prop
= node
.property (X_("muted"))) != 0) {
1707 bool yn
= string_is_affirmative (prop
->value());
1709 /* force reset of mute status */
1713 mute_gain
= desired_mute_gain
;
1716 if ((prop
= node
.property (X_("soloed"))) != 0) {
1717 bool yn
= string_is_affirmative (prop
->value());
1719 /* force reset of solo status */
1722 set_solo (yn
, this);
1723 solo_gain
= desired_solo_gain
;
1726 if ((prop
= node
.property (X_("mute-affects-pre-fader"))) != 0) {
1727 _mute_affects_pre_fader
= string_is_affirmative (prop
->value());
1730 if ((prop
= node
.property (X_("mute-affects-post-fader"))) != 0) {
1731 _mute_affects_post_fader
= string_is_affirmative (prop
->value());
1734 if ((prop
= node
.property (X_("mute-affects-control-outs"))) != 0) {
1735 _mute_affects_control_outs
= string_is_affirmative (prop
->value());
1738 if ((prop
= node
.property (X_("mute-affects-main-outs"))) != 0) {
1739 _mute_affects_main_outs
= string_is_affirmative (prop
->value());
1742 if ((prop
= node
.property (X_("meter-point"))) != 0) {
1743 _meter_point
= MeterPoint (string_2_enum (prop
->value (), _meter_point
));
1746 if ((prop
= node
.property (X_("edit-group"))) != 0) {
1747 RouteGroup
* edit_group
= _session
.edit_group_by_name(prop
->value());
1748 if(edit_group
== 0) {
1749 error
<< string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name
, prop
->value()) << endmsg
;
1751 set_edit_group(edit_group
, this);
1755 if ((prop
= node
.property (X_("order-keys"))) != 0) {
1759 string::size_type colon
, equal
;
1760 string remaining
= prop
->value();
1762 while (remaining
.length()) {
1764 if ((equal
= remaining
.find_first_of ('=')) == string::npos
|| equal
== remaining
.length()) {
1765 error
<< string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining
)
1768 if (sscanf (remaining
.substr (equal
+1).c_str(), "%ld", &n
) != 1) {
1769 error
<< string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining
)
1772 set_order_key (remaining
.substr (0, equal
).c_str(), n
);
1776 colon
= remaining
.find_first_of (':');
1778 if (colon
!= string::npos
) {
1779 remaining
= remaining
.substr (colon
+1);
1786 nlist
= node
.children();
1788 if (deferred_state
) {
1789 delete deferred_state
;
1792 deferred_state
= new XMLNode(X_("deferred state"));
1794 /* set parent class properties before anything else */
1796 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
){
1800 if (child
->name() == IO::state_node_name
&& call_base
) {
1802 IO::set_state (*child
);
1808 XMLNodeList redirect_nodes
;
1810 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
){
1814 if (child
->name() == X_("Send") || child
->name() == X_("Insert")) {
1815 redirect_nodes
.push_back(child
);
1820 _set_redirect_states (redirect_nodes
);
1822 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
){
1824 // All redirects (sends and inserts) have been applied already
1826 if (child
->name() == X_("Automation")) {
1828 if ((prop
= child
->property (X_("path"))) != 0) {
1829 load_automation (prop
->value());
1832 } else if (child
->name() == X_("ControlOuts")) {
1834 string coutname
= _name
;
1835 coutname
+= _("[control]");
1837 delete _control_outs
;
1838 _control_outs
= new IO (_session
, coutname
);
1840 /* fix up the control out name in the XML before setting it.
1841 Otherwise track templates don't work because the control
1842 outs end up with the stored template name, rather than
1843 the new name of the track based on the template.
1846 XMLProperty
* prop
= (*child
->children().begin())->property ("name");
1848 prop
->set_value (coutname
);
1851 _control_outs
->set_state (**(child
->children().begin()));
1853 } else if (child
->name() == X_("Comment")) {
1855 /* XXX this is a terrible API design in libxml++ */
1857 XMLNode
*cmt
= *(child
->children().begin());
1858 _comment
= cmt
->content();
1860 } else if (child
->name() == X_("extra")) {
1862 _extra_xml
= new XMLNode (*child
);
1864 } else if (child
->name() == X_("controllable") && (prop
= child
->property("name")) != 0) {
1866 if (prop
->value() == "solo") {
1867 _solo_control
.set_state (*child
);
1868 _session
.add_controllable (&_solo_control
);
1870 else if (prop
->value() == "mute") {
1871 _mute_control
.set_state (*child
);
1872 _session
.add_controllable (&_mute_control
);
1875 else if (child
->name() == X_("remote_control")) {
1876 if ((prop
= child
->property (X_("id"))) != 0) {
1878 sscanf (prop
->value().c_str(), "%d", &x
);
1879 set_remote_control_id (x
);
1884 if ((prop
= node
.property (X_("mix-group"))) != 0) {
1885 RouteGroup
* mix_group
= _session
.mix_group_by_name(prop
->value());
1886 if (mix_group
== 0) {
1887 error
<< string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name
, prop
->value()) << endmsg
;
1889 set_mix_group(mix_group
, this);
1897 Route::_set_redirect_states(const XMLNodeList
&nlist
)
1899 XMLNodeConstIterator niter
;
1902 RedirectList::iterator i
, o
;
1906 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
) {
1907 deferred_state
->add_child_copy (**niter
);
1913 // Iterate through existing redirects, remove those which are not in the state list
1914 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ) {
1915 RedirectList::iterator tmp
= i
;
1918 bool redirectInStateList
= false;
1920 (*i
)->id().print (buf
, sizeof (buf
));
1922 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
) {
1924 if (strncmp (buf
,(*niter
)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf
)) == 0) {
1925 redirectInStateList
= true;
1930 if (!redirectInStateList
) {
1931 remove_redirect ( *i
, this);
1939 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1940 // set the state of existing redirects according to the new state on the same go
1941 i
= _redirects
.begin();
1942 for (niter
= nlist
.begin(); niter
!= nlist
.end(); ++niter
, ++i
) {
1944 // Check whether the next redirect in the list
1947 while (o
!= _redirects
.end()) {
1948 (*o
)->id().print (buf
, sizeof (buf
));
1949 if ( strncmp(buf
, (*niter
)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf
)) == 0)
1954 if (o
== _redirects
.end()) {
1955 // If the redirect (*niter) is not on the route, we need to create it
1956 // and move it to the correct location
1958 RedirectList::iterator prev_last
= _redirects
.end();
1959 --prev_last
; // We need this to check whether adding succeeded
1961 add_redirect_from_xml (**niter
);
1963 RedirectList::iterator last
= _redirects
.end();
1966 if (prev_last
== last
) {
1967 warning
<< _name
<< ": could not fully restore state as some redirects were not possible to create" << endmsg
;
1972 boost::shared_ptr
<Redirect
> tmp
= (*last
);
1973 // remove the redirect from the wrong location
1974 _redirects
.erase(last
);
1975 // insert the new redirect at the current location
1976 _redirects
.insert(i
, tmp
);
1978 --i
; // move pointer to the newly inserted redirect
1982 // We found the redirect (*niter) on the route, first we must make sure the redirect
1983 // is at the location provided in the XML state
1985 boost::shared_ptr
<Redirect
> tmp
= (*o
);
1986 // remove the old copy
1987 _redirects
.erase(o
);
1988 // insert the redirect at the correct location
1989 _redirects
.insert(i
, tmp
);
1991 --i
; // move pointer so it points to the right redirect
1994 (*i
)->set_state( (**niter
) );
1997 redirects_changed(this);
2001 Route::curve_reallocate ()
2003 // _gain_automation_curve.finish_resize ();
2004 // _pan_automation_curve.finish_resize ();
2008 Route::silence (nframes_t nframes
)
2012 // reset_peak_meters ();
2014 IO::silence (nframes
);
2016 if (_control_outs
) {
2017 _control_outs
->silence (nframes
);
2021 Glib::RWLock::ReaderLock
lm (redirect_lock
, Glib::TRY_LOCK
);
2024 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2025 boost::shared_ptr
<PluginInsert
> pi
;
2026 if (!_active
&& (pi
= boost::dynamic_pointer_cast
<PluginInsert
> (*i
)) != 0) {
2027 // skip plugins, they don't need anything when we're not active
2031 (*i
)->silence (nframes
);
2034 if (nframes
== _session
.get_block_size()) {
2044 Route::set_control_outs (const vector
<string
>& ports
)
2046 Glib::Mutex::Lock
lm (control_outs_lock
);
2047 vector
<string
>::const_iterator i
;
2050 if (_control_outs
) {
2051 delete _control_outs
;
2055 if (control() || master()) {
2056 /* no control outs for these two special busses */
2060 if (ports
.empty()) {
2064 string coutname
= _name
;
2065 coutname
+= _("[control]");
2067 _control_outs
= new IO (_session
, coutname
);
2069 /* our control outs need as many outputs as we
2070 have outputs. we track the changes in ::output_change_handler().
2073 limit
= n_outputs ();
2075 if (_control_outs
->ensure_io (0, limit
, true, this)) {
2079 /* now connect to the named ports */
2081 for (uint32_t n
= 0; n
< limit
; ++n
) {
2082 if (_control_outs
->connect_output (_control_outs
->output (n
), ports
[n
% ports
.size()], this)) {
2083 error
<< string_compose (_("could not connect %1 to %2"), _control_outs
->output(n
)->name(), ports
[n
]) << endmsg
;
2092 Route::set_edit_group (RouteGroup
*eg
, void *src
)
2095 if (eg
== _edit_group
) {
2100 _edit_group
->remove (this);
2103 if ((_edit_group
= eg
) != 0) {
2104 _edit_group
->add (this);
2107 _session
.set_dirty ();
2108 edit_group_changed (src
); /* EMIT SIGNAL */
2112 Route::drop_edit_group (void *src
)
2115 _session
.set_dirty ();
2116 edit_group_changed (src
); /* EMIT SIGNAL */
2120 Route::set_mix_group (RouteGroup
*mg
, void *src
)
2123 if (mg
== _mix_group
) {
2128 _mix_group
->remove (this);
2131 if ((_mix_group
= mg
) != 0) {
2132 _mix_group
->add (this);
2135 _session
.set_dirty ();
2136 mix_group_changed (src
); /* EMIT SIGNAL */
2140 Route::drop_mix_group (void *src
)
2143 _session
.set_dirty ();
2144 mix_group_changed (src
); /* EMIT SIGNAL */
2148 Route::set_comment (string cmt
, void *src
)
2151 comment_changed (src
);
2152 _session
.set_dirty ();
2156 Route::feeds (boost::shared_ptr
<Route
> other
)
2161 uint32_t no
= self
.n_outputs();
2162 uint32_t ni
= other
->n_inputs ();
2164 for (i
= 0; i
< no
; ++i
) {
2165 for (j
= 0; j
< ni
; ++j
) {
2166 if (self
.output(i
)->connected_to (other
->input(j
)->name())) {
2172 /* check Redirects which may also interconnect Routes */
2174 for (RedirectList::iterator r
= _redirects
.begin(); r
!= _redirects
.end(); r
++) {
2176 no
= (*r
)->n_outputs();
2178 for (i
= 0; i
< no
; ++i
) {
2179 for (j
= 0; j
< ni
; ++j
) {
2180 if ((*r
)->output(i
)->connected_to (other
->input (j
)->name())) {
2187 /* check for control room outputs which may also interconnect Routes */
2189 if (_control_outs
) {
2191 no
= _control_outs
->n_outputs();
2193 for (i
= 0; i
< no
; ++i
) {
2194 for (j
= 0; j
< ni
; ++j
) {
2195 if (_control_outs
->output(i
)->connected_to (other
->input (j
)->name())) {
2206 Route::set_mute_config (mute_type t
, bool onoff
, void *src
)
2210 _mute_affects_pre_fader
= onoff
;
2211 pre_fader_changed(src
); /* EMIT SIGNAL */
2215 _mute_affects_post_fader
= onoff
;
2216 post_fader_changed(src
); /* EMIT SIGNAL */
2220 _mute_affects_control_outs
= onoff
;
2221 control_outs_changed(src
); /* EMIT SIGNAL */
2225 _mute_affects_main_outs
= onoff
;
2226 main_outs_changed(src
); /* EMIT SIGNAL */
2232 Route::get_mute_config (mute_type t
)
2238 onoff
= _mute_affects_pre_fader
;
2241 onoff
= _mute_affects_post_fader
;
2244 onoff
= _mute_affects_control_outs
;
2247 onoff
= _mute_affects_main_outs
;
2255 Route::handle_transport_stopped (bool abort_ignored
, bool did_locate
, bool can_flush_redirects
)
2257 nframes_t now
= _session
.transport_frame();
2260 Glib::RWLock::ReaderLock
lm (redirect_lock
);
2263 automation_snapshot (now
, true);
2266 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2268 if (Config
->get_plugins_stop_with_transport() && can_flush_redirects
) {
2269 (*i
)->deactivate ();
2273 (*i
)->transport_stopped (now
);
2277 IO::transport_stopped (now
);
2279 _roll_delay
= _initial_delay
;
2283 Route::input_change_handler (IOChange change
, void *ignored
)
2285 if (change
& ConfigurationChanged
) {
2286 reset_plugin_counts (0);
2291 Route::output_change_handler (IOChange change
, void *ignored
)
2293 if (change
& ConfigurationChanged
) {
2294 if (_control_outs
) {
2295 _control_outs
->ensure_io (0, n_outputs(), true, this);
2298 reset_plugin_counts (0);
2303 Route::pans_required () const
2305 if (n_outputs() < 2) {
2309 return max (n_inputs (), redirect_max_outs
);
2313 Route::no_roll (nframes_t nframes
, nframes_t start_frame
, nframes_t end_frame
,
2314 bool session_state_changing
, bool can_record
, bool rec_monitors_input
)
2316 if (n_outputs() == 0) {
2320 if (session_state_changing
|| !_active
) {
2325 apply_gain_automation
= false;
2328 passthru (start_frame
, end_frame
, nframes
, 0, false);
2337 Route::check_initial_delay (nframes_t nframes
, nframes_t
& transport_frame
)
2339 if (_roll_delay
> nframes
) {
2341 _roll_delay
-= nframes
;
2343 /* transport frame is not legal for caller to use */
2346 } else if (_roll_delay
> 0) {
2348 nframes
-= _roll_delay
;
2350 silence (_roll_delay
);
2352 /* we've written _roll_delay of samples into the
2353 output ports, so make a note of that for
2357 increment_output_offset (_roll_delay
);
2359 transport_frame
+= _roll_delay
;
2368 Route::roll (nframes_t nframes
, nframes_t start_frame
, nframes_t end_frame
, int declick
,
2369 bool can_record
, bool rec_monitors_input
)
2372 Glib::RWLock::ReaderLock
lm (redirect_lock
, Glib::TRY_LOCK
);
2374 // automation snapshot can also be called from the non-rt context
2375 // and it uses the redirect list, so we take the lock out here
2376 automation_snapshot (_session
.transport_frame(), false);
2380 if ((n_outputs() == 0 && _redirects
.empty()) || n_inputs() == 0 || !_active
) {
2385 nframes_t unused
= 0;
2387 if ((nframes
= check_initial_delay (nframes
, unused
)) == 0) {
2393 apply_gain_automation
= false;
2396 Glib::Mutex::Lock
am (automation_lock
, Glib::TRY_LOCK
);
2398 if (am
.locked() && _session
.transport_rolling()) {
2400 nframes_t start_frame
= end_frame
- nframes
;
2402 if (gain_automation_playback()) {
2403 apply_gain_automation
= _gain_automation_curve
.rt_safe_get_vector (start_frame
, end_frame
, _session
.gain_automation_buffer(), nframes
);
2408 passthru (start_frame
, end_frame
, nframes
, declick
, false);
2414 Route::silent_roll (nframes_t nframes
, nframes_t start_frame
, nframes_t end_frame
,
2415 bool can_record
, bool rec_monitors_input
)
2422 Route::toggle_monitor_input ()
2424 for (vector
<Port
*>::iterator i
= _inputs
.begin(); i
!= _inputs
.end(); ++i
) {
2425 (*i
)->ensure_monitor_input(!(*i
)->monitoring_input());
2430 Route::has_external_redirects () const
2432 boost::shared_ptr
<const PortInsert
> pi
;
2434 for (RedirectList::const_iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2435 if ((pi
= boost::dynamic_pointer_cast
<const PortInsert
>(*i
)) != 0) {
2437 uint32_t no
= pi
->n_outputs();
2439 for (uint32_t n
= 0; n
< no
; ++n
) {
2441 string port_name
= pi
->output(n
)->name();
2442 string client_name
= port_name
.substr (0, port_name
.find(':'));
2444 /* only say "yes" if the redirect is actually in use */
2446 if (client_name
!= "ardour" && pi
->active()) {
2457 Route::flush_redirects ()
2459 /* XXX shouldn't really try to take this lock, since
2460 this is called from the RT audio thread.
2463 Glib::RWLock::ReaderLock
lm (redirect_lock
);
2465 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2466 (*i
)->deactivate ();
2472 Route::set_meter_point (MeterPoint p
, void *src
)
2474 if (_meter_point
!= p
) {
2476 meter_change (src
); /* EMIT SIGNAL */
2477 _session
.set_dirty ();
2482 Route::update_total_latency ()
2486 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2487 if ((*i
)->active ()) {
2488 _own_latency
+= (*i
)->latency ();
2492 #undef DEBUG_LATENCY
2493 #ifdef DEBUG_LATENCY
2494 cerr
<< _name
<< ": internal redirect latency = " << _own_latency
<< endl
;
2497 set_port_latency (_own_latency
);
2499 /* this (virtual) function is used for pure Routes,
2500 not derived classes like AudioTrack. this means
2501 that the data processed here comes from an input
2502 port, not prerecorded material, and therefore we
2503 have to take into account any input latency.
2506 _own_latency
+= input_latency ();
2508 #ifdef DEBUG_LATENCY
2509 cerr
<< _name
<< ": input latency = " << input_latency() << " total = "
2510 << _own_latency
<< endl
;
2513 return _own_latency
;
2517 Route::set_latency_delay (nframes_t longest_session_latency
)
2519 _initial_delay
= longest_session_latency
- _own_latency
;
2521 if (_session
.transport_stopped()) {
2522 _roll_delay
= _initial_delay
;
2527 Route::automation_snapshot (nframes_t now
, bool force
)
2529 if (!force
&& !should_snapshot(now
)) {
2533 IO::automation_snapshot (now
, force
);
2535 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2536 (*i
)->automation_snapshot (now
, force
);
2540 Route::ToggleControllable::ToggleControllable (std::string name
, Route
& s
, ToggleType tp
)
2541 : Controllable (name
), route (s
), type(tp
)
2547 Route::ToggleControllable::set_value (float val
)
2549 bool bval
= ((val
>= 0.5f
) ? true: false);
2553 route
.set_mute (bval
, this);
2556 route
.set_solo (bval
, this);
2564 Route::ToggleControllable::get_value (void) const
2570 val
= route
.muted() ? 1.0f
: 0.0f
;
2573 val
= route
.soloed() ? 1.0f
: 0.0f
;
2583 Route::set_block_size (nframes_t nframes
)
2585 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2586 (*i
)->set_block_size (nframes
);
2591 Route::redirect_active_proxy (Redirect
* ignored
, void* ignored_src
)
2593 _session
.update_latency_compensation (false, false);
2597 Route::protect_automation ()
2599 switch (gain_automation_state()) {
2601 set_gain_automation_state (Off
);
2603 set_gain_automation_state (Play
);
2609 switch (panner().automation_state ()) {
2611 panner().set_automation_state (Off
);
2614 panner().set_automation_state (Play
);
2620 for (RedirectList::iterator i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2621 boost::shared_ptr
<PluginInsert
> pi
;
2622 if ((pi
= boost::dynamic_pointer_cast
<PluginInsert
> (*i
)) != 0) {
2623 pi
->protect_automation ();
2629 Route::set_pending_declick (int declick
)
2632 /* this call is not allowed to turn off a pending declick unless "force" is true */
2634 _pending_declick
= declick
;
2636 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2638 _pending_declick
= 0;
2643 /** Shift automation forwards from a particular place, thereby inserting time.
2644 * Adds undo commands for any shifts that are performed.
2646 * @param pos Position to start shifting from.
2647 * @param frames Amount to shift forwards by.
2651 Route::shift (nframes64_t pos
, nframes64_t frames
)
2653 /* gain automation */
2654 XMLNode
&before
= _gain_automation_curve
.get_state ();
2655 _gain_automation_curve
.shift (pos
, frames
);
2656 XMLNode
&after
= _gain_automation_curve
.get_state ();
2657 _session
.add_command (new MementoCommand
<AutomationList
> (_gain_automation_curve
, &before
, &after
));
2659 /* pan automation */
2660 for (std::vector
<StreamPanner
*>::iterator i
= _panner
->begin (); i
!= _panner
->end (); ++i
) {
2661 Curve
& c
= (*i
)->automation ();
2662 XMLNode
&before
= c
.get_state ();
2663 c
.shift (pos
, frames
);
2664 XMLNode
&after
= c
.get_state ();
2665 _session
.add_command (new MementoCommand
<AutomationList
> (c
, &before
, &after
));
2668 /* redirect automation */
2670 Glib::RWLock::ReaderLock
lm (redirect_lock
);
2671 for (RedirectList::iterator i
= _redirects
.begin (); i
!= _redirects
.end (); ++i
) {
2674 (*i
)->what_has_automation (a
);
2676 for (set
<uint32_t>::const_iterator j
= a
.begin (); j
!= a
.end (); ++j
) {
2677 AutomationList
& al
= (*i
)->automation_list (*j
);
2678 XMLNode
&before
= al
.get_state ();
2679 al
.shift (pos
, frames
);
2680 XMLNode
&after
= al
.get_state ();
2681 _session
.add_command (new MementoCommand
<AutomationList
> (al
, &before
, &after
));
2688 Route::save_as_template (const string
& path
, const string
& name
)
2690 XMLNode
& node (state (false));
2693 IO::set_name_in_state (*node
.children().front(), name
);
2695 tree
.set_root (&node
);
2696 return tree
.write (path
.c_str());
2700 Route::set_name (string str
, void* src
)
2704 if ((ret
= IO::set_name (str
, src
)) == 0) {
2705 if (_control_outs
) {
2706 string coutname
= _name
;
2707 coutname
+= _("[control]");
2708 cerr
<< _name
<< " reset control outs to " << coutname
<< endl
;
2709 return _control_outs
->set_name (coutname
, src
);
2717 Route::has_io_redirect_named (const string
& name
)
2719 Glib::RWLock::ReaderLock
lm (redirect_lock
);
2720 RedirectList::iterator i
;
2722 for (i
= _redirects
.begin(); i
!= _redirects
.end(); ++i
) {
2723 if (boost::dynamic_pointer_cast
<Send
> (*i
) ||
2724 boost::dynamic_pointer_cast
<PortInsert
> (*i
)) {
2725 if ((*i
)->name() == name
) {