fix delivery of MMC events under split process cycle conditions
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 22 Oct 2014 21:06:53 +0000 (17:06 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 22 Oct 2014 21:07:11 +0000 (17:07 -0400)
libs/ardour/ardour/session.h
libs/ardour/session.cc
libs/ardour/session_midi.cc
libs/ardour/session_state.cc
libs/ardour/session_transport.cc

index 8621b64578c5ab54da45e2c99d0ebd91ec335a77..2c0ac05bdaa0fecf404ed71fe71412dbc6bd7f1a 100644 (file)
@@ -48,6 +48,7 @@
 #include "evoral/types.hpp"
 
 #include "midi++/types.h"
+#include "midi++/mmc.h"
 
 #include "timecode/time.h"
 
@@ -1248,6 +1249,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        MidiTimeoutList midi_timeouts;
        bool mmc_step_timeout ();
+       void send_immediate_mmc (MIDI::MachineControlCommand);
 
        MIDI::byte mtc_msg[16];
        MIDI::byte mtc_timecode_bits;   /* encoding of SMTPE type for MTC */
index b0d7a1ce4e5fb52b0c741e81b74a481e8329ee31..5575f423605d992fb04d3b15da2c7e0afbab2bd0 100644 (file)
@@ -1380,7 +1380,7 @@ Session::enable_record ()
                if (g_atomic_int_compare_and_exchange (&_record_status, rs, Recording)) {
 
                        _last_record_location = _transport_frame;
-                       _mmc->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordStrobe));
+                       send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordStrobe));
 
                        if (Config->get_monitoring_model() == HardwareMonitoring && config.get_auto_input()) {
                                set_track_monitor_input_status (true);
@@ -1401,7 +1401,7 @@ Session::disable_record (bool rt_context, bool force)
 
                if ((!Config->get_latched_record_enable () && !play_loop) || force) {
                        g_atomic_int_set (&_record_status, Disabled);
-                       _mmc->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordExit));
+                       send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordExit));
                } else {
                        if (rs == Recording) {
                                g_atomic_int_set (&_record_status, Enabled);
@@ -1455,7 +1455,7 @@ Session::maybe_enable_record ()
                        enable_record ();
                }
        } else {
-               _mmc->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordPause));
+               send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdRecordPause));
                RecordStateChanged (); /* EMIT SIGNAL */
        }
 
index 47c7bd4c4037d60aa327366bd84057adbd86e667..7becd9c667035ff2823490a00647d8fef95688d9 100644 (file)
@@ -33,6 +33,7 @@
 #include "pbd/error.h"
 #include "pbd/pthread_utils.h"
 #include "pbd/timersub.h"
+#include "pbd/stacktrace.h"
 
 #include "timecode/time.h"
 
@@ -425,7 +426,7 @@ Session::send_full_time_code (framepos_t const t, MIDI::pframes_t nframes)
        // Send message at offset 0, sent time is for the start of this cycle
        
        MidiBuffer& mb (_midi_ports->mtc_output_port()->get_midi_buffer (nframes));
-       mb.push_back (0, sizeof (msg), msg);
+       mb.push_back (Port::port_offset(), sizeof (msg), msg);
 
        _pframes_since_last_mtc = 0;
        return 0;
@@ -551,6 +552,16 @@ Session::send_midi_time_code_for_cycle (framepos_t start_frame, framepos_t end_f
  OUTBOUND MMC STUFF
 **********************************************************************/
 
+void
+Session::send_immediate_mmc (MachineControlCommand c)
+{
+       if (AudioEngine::instance()->in_process_thread()) {
+               _mmc->send (c, Port::port_offset());
+       } else {
+               _mmc->send (c, 0);
+       }
+               
+}
 
 bool
 Session::mmc_step_timeout ()
index 538c408abb5bd2f4d097505ad8404b262b33630d..6560c6004b30258f8578e6e1f10ee6000645f26a 100644 (file)
@@ -334,8 +334,8 @@ Session::post_engine_init ()
        // send_full_time_code (0);
        _engine.transport_locate (0);
 
-       _mmc->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdMmcReset));
-       _mmc->send (MIDI::MachineControlCommand (Timecode::Time ()));
+       send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdMmcReset));
+       send_immediate_mmc (MIDI::MachineControlCommand (Timecode::Time ()));
 
        MIDI::Name::MidiPatchManager::instance().set_session (this);
 
index 6954bd0288cf742e11900541bbd70eebc9fd8cac..dec3683c196a5f3e33a11450ae4148a972b7f1e2 100644 (file)
@@ -656,7 +656,7 @@ Session::non_realtime_stop (bool abort, int on_entry, bool& finished)
                _send_timecode_update = true;
                
                if (!dynamic_cast<MTC_Slave*>(_slave)) {
-                       _mmc->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdStop));
+                       send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdStop));
 
                        /* This (::non_realtime_stop()) gets called by main
                           process thread, which will lead to confusion
@@ -1371,7 +1371,7 @@ Session::start_transport ()
                Timecode::Time time;
                timecode_time_subframes (_transport_frame, time);
                if (!dynamic_cast<MTC_Slave*>(_slave)) {
-                       _mmc->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdDeferredPlay));
+                       send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdDeferredPlay));
                }
        }
 
@@ -1759,7 +1759,7 @@ Session::send_mmc_locate (framepos_t t)
        if (!_engine.freewheeling()) {
                Timecode::Time time;
                timecode_time_subframes (t, time);
-               _mmc->send (MIDI::MachineControlCommand (time));
+               send_immediate_mmc (MIDI::MachineControlCommand (time));
        }
 }