"Run plugins while recording" -> "Do not run plugins while recording"
[ardour.git] / libs / ardour / route.cc
index 03059c6c82fa86c615787b3426418716484d37b5..5fcbd53bb68c8c2a968cbccdf31d84a8af9c47a8 100644 (file)
@@ -86,6 +86,7 @@ Route::init ()
        _have_internal_generator = false;
        _declickable = false;
        _pending_declick = true;
+       _remote_control_id = 0;
 
        _edit_group = 0;
        _mix_group = 0;
@@ -118,6 +119,21 @@ Route::~Route ()
        }
 }
 
+void
+Route::set_remote_control_id (uint32_t id)
+{
+       if (id != _remote_control_id) {
+               _remote_control_id = id;
+               RemoteControlIDChanged ();
+       }
+}
+
+uint32_t
+Route::remote_control_id() const
+{
+       return _remote_control_id;
+}
+
 long
 Route::order_key (string name) const
 {
@@ -213,7 +229,7 @@ Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
        IO *co;
        bool mute_audible;
        bool solo_audible;
-       bool no_monitor = (Config->get_use_hardware_monitoring() || Config->get_no_sw_monitoring ());
+       bool no_monitor = (Config->get_use_hardware_monitoring() || !Config->get_use_sw_monitoring ());
        gain_t* gab = _session.gain_automation_buffer();
 
        declick = _pending_declick;
@@ -314,7 +330,7 @@ Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
           -------------------------------------------------------------------------------------------------- */
 
        if (with_redirects) {
-               TentativeLockMonitor rm (redirect_lock, __LINE__, __FILE__);
+               TentativeRWLockMonitor rm (redirect_lock, false, __LINE__, __FILE__);
                if (rm.locked()) {
                        if (mute_gain > 0 || !_mute_affects_pre_fader) {
                                for (i = _redirects.begin(); i != _redirects.end(); ++i) {
@@ -406,7 +422,7 @@ Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
 
                 // AND software monitoring required
 
-                !Config->get_no_sw_monitoring())) { 
+                Config->get_use_sw_monitoring())) { 
                
                if (apply_gain_automation) {
                        
@@ -428,7 +444,7 @@ Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
                                }
                        }
                        
-                       if (apply_gain_automation) {
+                       if (apply_gain_automation && _session.transport_rolling()) {
                                _effective_gain = gab[nframes-1];
                        }
                        
@@ -483,7 +499,7 @@ Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
 
        if (post_fader_work) {
 
-               TentativeLockMonitor rm (redirect_lock, __LINE__, __FILE__);
+               TentativeRWLockMonitor rm (redirect_lock, false, __LINE__, __FILE__);
                if (rm.locked()) {
                        if (mute_gain > 0 || !_mute_affects_post_fader) {
                                for (i = _redirects.begin(); i != _redirects.end(); ++i) {
@@ -755,7 +771,7 @@ Route::add_redirect (Redirect *redirect, void *src, uint32_t* err_streams)
        }
 
        {
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, true, __LINE__, __FILE__);
 
                PluginInsert* pi;
                PortInsert* porti;
@@ -816,7 +832,7 @@ Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_strea
        }
 
        {
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, true, __LINE__, __FILE__);
 
                RedirectList::iterator existing_end = _redirects.end();
                --existing_end;
@@ -861,7 +877,7 @@ Route::clear_redirects (void *src)
        }
 
        {
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, true, __LINE__, __FILE__);
 
                for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
                        delete *i;
@@ -891,7 +907,7 @@ Route::remove_redirect (Redirect *redirect, void *src, uint32_t* err_streams)
        redirect_max_outs = 0;
 
        {
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, true, __LINE__, __FILE__);
                RedirectList::iterator i;
                bool removed = false;
 
@@ -970,7 +986,7 @@ Route::remove_redirect (Redirect *redirect, void *src, uint32_t* err_streams)
 int
 Route::reset_plugin_counts (uint32_t* lpc)
 {
-       LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+       RWLockMonitor lm (redirect_lock, true, __LINE__, __FILE__);
        return _reset_plugin_counts (lpc);
 }
 
@@ -1140,7 +1156,7 @@ Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_st
        RedirectList to_be_deleted;
 
        {
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, true, __LINE__, __FILE__);
                RedirectList::iterator tmp;
                RedirectList the_copy;
 
@@ -1219,7 +1235,7 @@ Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_st
 void
 Route::all_redirects_flip ()
 {
-       LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+       RWLockMonitor lm (redirect_lock, false, __LINE__, __FILE__);
 
        if (_redirects.empty()) {
                return;
@@ -1235,7 +1251,7 @@ Route::all_redirects_flip ()
 void
 Route::all_redirects_active (bool state)
 {
-       LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+       RWLockMonitor lm (redirect_lock, false,  __LINE__, __FILE__);
 
        if (_redirects.empty()) {
                return;
@@ -1257,7 +1273,7 @@ Route::sort_redirects (uint32_t* err_streams)
 {
        {
                RedirectSorter comparator;
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, true, __LINE__, __FILE__);
                uint32_t old_rmo = redirect_max_outs;
 
                /* the sweet power of C++ ... */
@@ -1736,7 +1752,7 @@ Route::silence (jack_nframes_t nframes, jack_nframes_t offset)
                }
 
                { 
-                       TentativeLockMonitor lm (redirect_lock, __LINE__, __FILE__);
+                       TentativeRWLockMonitor lm (redirect_lock, false, __LINE__, __FILE__);
                        
                        if (lm.locked()) {
                                for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
@@ -1935,12 +1951,13 @@ Route::transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_re
 {
        jack_nframes_t now = _session.transport_frame();
 
-       if (!did_locate) {
-               automation_snapshot (now);
-       }
-
        {
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, false, __LINE__, __FILE__);
+
+               if (!did_locate) {
+                       automation_snapshot (now);
+               }
+
                for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
                        
                        if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
@@ -2014,7 +2031,7 @@ Route::no_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes
        }
 
        apply_gain_automation = false;
-
+       
        if (n_inputs()) {
                passthru (start_frame, end_frame, nframes, offset, 0, false);
        } else {
@@ -2053,8 +2070,15 @@ int
 Route::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t offset, int declick,
             bool can_record, bool rec_monitors_input)
 {
-       automation_snapshot (_session.transport_frame());
-
+       {
+               TentativeRWLockMonitor lm(redirect_lock, false, __LINE__, __FILE__);
+               if (lm.locked()) {
+                       // automation snapshot can also be called from the non-rt context
+                       // and it uses the redirect list, so we take the lock out here
+                       automation_snapshot (_session.transport_frame());
+               }
+       }
+               
        if ((n_outputs() == 0 && _redirects.empty()) || n_inputs() == 0 || !_active) {
                silence (nframes, offset);
                return 0;
@@ -2067,12 +2091,13 @@ Route::roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t
        }
 
        _silent = false;
+
        apply_gain_automation = false;
 
        { 
                TentativeLockMonitor am (automation_lock, __LINE__, __FILE__);
                
-               if (am.locked()) {
+               if (am.locked() && _session.transport_rolling()) {
                        
                        jack_nframes_t start_frame = end_frame - nframes;
                        
@@ -2162,7 +2187,7 @@ Route::send_all_midi_feedback ()
        if (_session.get_midi_feedback()) {
 
                {
-                       LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+                       RWLockMonitor lm (redirect_lock, false, __LINE__, __FILE__);
                        for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
                                (*i)->send_all_midi_feedback ();
                        }
@@ -2182,7 +2207,7 @@ Route::write_midi_feedback (MIDI::byte* buf, int32_t& bufsize)
        buf = _midi_mute_control.write_feedback (buf, bufsize, _muted);
 
        {
-               LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+               RWLockMonitor lm (redirect_lock, false, __LINE__, __FILE__);
                for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
                        buf = (*i)->write_midi_feedback (buf, bufsize);
                }
@@ -2198,7 +2223,7 @@ Route::flush_redirects ()
           this is called from the RT audio thread.
        */
 
-       LockMonitor lm (redirect_lock, __LINE__, __FILE__);
+       RWLockMonitor lm (redirect_lock, false, __LINE__, __FILE__);
 
        for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
                (*i)->deactivate ();
@@ -2333,7 +2358,8 @@ Route::MIDIToggleControl::send_feedback (bool value)
                if (get_control_info (ch, ev, additional)) {
                        data.controller_number = additional;
                        data.value = val;
-
+                       last_written = value;
+                       
                        route._session.send_midi_message (get_port(), ev, ch, data);
                }
        }