attempt to stop sending MMC/MTC while exporting or freewheeling for any reason
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 6 Feb 2012 17:09:53 +0000 (17:09 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 6 Feb 2012 17:09:53 +0000 (17:09 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11457 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audioengine.h
libs/ardour/ardour/session.h
libs/ardour/audioengine.cc
libs/ardour/session_export.cc
libs/ardour/session_midi.cc
libs/ardour/session_process.cc
libs/ardour/session_state.cc
libs/ardour/session_transport.cc
libs/midi++2/midi++/mmc.h

index 7b4ba2d15df287ec76e2f56a604ea7d1a8e58bcb..fdaf864a0d4430e7310db46c0f15444b44a3a7b9 100644 (file)
@@ -280,6 +280,7 @@ private:
        /// the number of frames processed since start() was called
        framecnt_t                _processed_frames;
        bool                      _freewheeling;
+       bool                      _pre_freewheel_mmc_enabled;
        int                       _usecs_per_cycle;
        bool                       port_remove_in_progress;
 
@@ -314,6 +315,7 @@ private:
        int  jack_sync_callback (jack_transport_state_t, jack_position_t*);
        int  jack_bufsize_callback (pframes_t);
        int  jack_sample_rate_callback (pframes_t);
+       void freewheel_callback (int);
 
        void set_jack_callbacks ();
 
index 973374ab32976205d050170b8a52141c36f8ded2..a0e1b5a0fd16d53f49f932c03d35848e856772c2 100644 (file)
@@ -983,6 +983,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
        int  pre_export ();
        int  stop_audio_export ();
        void finalize_audio_export ();
+       bool _pre_export_mmc_enabled;
 
        PBD::ScopedConnection export_freewheel_connection;
 
index abf4999e7f9c7aec41292517de829dc71f1405f0..9cec374716fa011f0c04625d6f4c0b419df48d95 100644 (file)
@@ -84,6 +84,7 @@ AudioEngine::AudioEngine (string client_name, string session_uuid)
        _frame_rate = 0;
        _buffer_size = 0;
        _freewheeling = false;
+       _pre_freewheel_mmc_enabled = false;
         _main_thread = 0;
        port_remove_in_progress = false;
 
@@ -344,7 +345,20 @@ AudioEngine::_process_thread (void *arg)
 void
 AudioEngine::_freewheel_callback (int onoff, void *arg)
 {
-       static_cast<AudioEngine*>(arg)->_freewheeling = onoff;
+       static_cast<AudioEngine*>(arg)->freewheel_callback (onoff);
+}
+
+void
+AudioEngine::freewheel_callback (int onoff)
+{
+       _freewheeling = onoff;
+
+       if (onoff) {
+               _pre_freewheel_mmc_enabled = MIDI::Manager::instance()->mmc()->send_enabled ();
+               MIDI::Manager::instance()->mmc()->enable_send (false);
+       } else {
+               MIDI::Manager::instance()->mmc()->enable_send (_pre_freewheel_mmc_enabled);
+       }
 }
 
 void
index 4f46535a978e88429c8e350a8da13afb1eb1d162..4d2944aad54619ef129b96cf2001829da8664796 100644 (file)
@@ -21,6 +21,9 @@
 #include "pbd/error.h"
 #include <glibmm/thread.h>
 
+#include <midi++/manager.h>
+#include <midi++/mmc.h>
+
 #include "ardour/audioengine.h"
 #include "ardour/butler.h"
 #include "ardour/export_failed.h"
@@ -89,6 +92,11 @@ Session::pre_export ()
        export_status->running = true;
        export_status->Aborting.connect_same_thread (*this, boost::bind (&Session::stop_audio_export, this));
        export_status->Finished.connect_same_thread (*this, boost::bind (&Session::finalize_audio_export, this));
+       
+       /* disable MMC output early */
+
+       _pre_export_mmc_enabled = MIDI::Manager::instance()->mmc()->send_enabled ();
+       MIDI::Manager::instance()->mmc()->enable_send (false);
 
        return 0;
 }
@@ -223,6 +231,8 @@ Session::finalize_audio_export ()
        _engine.freewheel (false);
        export_freewheel_connection.disconnect();
        
+       MIDI::Manager::instance()->mmc()->enable_send (_pre_export_mmc_enabled);
+
        /* maybe write CUE/TOC */
 
        export_handler.reset();
index 3fe6925186a85cdc4531b1692497afdea99d1775..453718c024ad874814d8cac5def0fd2462027bea 100644 (file)
@@ -361,7 +361,7 @@ Session::send_full_time_code (framepos_t const t)
 
        _send_timecode_update = false;
 
-       if (!Config->get_send_mtc() || _slave) {
+       if (_engine.freewheeling() || !Config->get_send_mtc() || _slave) {
                return 0;
        }
 
@@ -415,7 +415,7 @@ Session::send_full_time_code (framepos_t const t)
 int
 Session::send_midi_time_code_for_cycle (framepos_t start_frame, framepos_t end_frame, pframes_t nframes)
 {
-       if (_slave || !_send_qf_mtc || transmitting_timecode_time.negative || (next_quarter_frame_to_send < 0)) {
+       if (_engine.freewheeling() || _slave || !_send_qf_mtc || transmitting_timecode_time.negative || (next_quarter_frame_to_send < 0)) {
                // cerr << "(MTC) Not sending MTC\n";
                return 0;
        }
index cd3c023f3eed5ad40e565687838be052937aa079..60cb6ecee1f634022a00a86a82effcecdf6c474c 100644 (file)
@@ -88,7 +88,7 @@ Session::process (pframes_t nframes)
         */
 
        try {
-               if (Config->get_send_midi_clock() && transport_speed() == 1.0f && midi_clock->has_midi_port()) {
+               if (!_engine.freewheeling() && Config->get_send_midi_clock() && transport_speed() == 1.0f && midi_clock->has_midi_port()) {
                        midi_clock->tick (transport_at_start);
                }
        } catch (...) {
index 30590e3665ff8fa849e3d2e0b80bafe37d281ba6..3c7ec0f780a94a1ec10ae7c24f1215caf21f7e8b 100644 (file)
@@ -226,6 +226,7 @@ Session::first_stage_init (string fullpath, string snapshot_name)
         _speakers.reset (new Speakers);
        _clicks_cleared = 0;
        ignore_route_processor_changes = false;
+       _pre_export_mmc_enabled = false;
 
        AudioDiskstream::allocate_working_buffers();
 
index 6347c553a9759f523518d10f1e52a2231fb00dfd..ffcb7e8d2472aba73e46a2365bacc961fa29e51a 100644 (file)
@@ -616,11 +616,13 @@ Session::non_realtime_stop (bool abort, int on_entry, bool& finished)
 
        have_looped = false;
 
-       send_full_time_code (_transport_frame);
-
-       if (!dynamic_cast<MTC_Slave*>(_slave)) {
-               MIDI::Manager::instance()->mmc()->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdStop));
-               send_mmc_locate (_transport_frame);
+       if (!_engine.freewheeling()) {
+               send_full_time_code (_transport_frame);
+               
+               if (!dynamic_cast<MTC_Slave*>(_slave)) {
+                       MIDI::Manager::instance()->mmc()->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdStop));
+                       send_mmc_locate (_transport_frame);
+               }
        }
 
        if ((ptw & PostTransportLocate) && get_record_enabled()) {
@@ -1187,10 +1189,12 @@ Session::start_transport ()
                (*i)->automation_snapshot (_transport_frame, true);
        }
 
-       Timecode::Time time;
-       timecode_time_subframes (_transport_frame, time);
-       if (!dynamic_cast<MTC_Slave*>(_slave)) {
-               MIDI::Manager::instance()->mmc()->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdDeferredPlay));
+       if (!_engine.freewheeling()) {
+               Timecode::Time time;
+               timecode_time_subframes (_transport_frame, time);
+               if (!dynamic_cast<MTC_Slave*>(_slave)) {
+                       MIDI::Manager::instance()->mmc()->send (MIDI::MachineControlCommand (MIDI::MachineControl::cmdDeferredPlay));
+               }
        }
 
        TransportStateChange (); /* EMIT SIGNAL */
@@ -1551,9 +1555,11 @@ Session::maybe_stop (framepos_t limit)
 void
 Session::send_mmc_locate (framepos_t t)
 {
-       Timecode::Time time;
-       timecode_time_subframes (t, time);
-       MIDI::Manager::instance()->mmc()->send (MIDI::MachineControlCommand (time));
+       if (!_engine.freewheeling()) {
+               Timecode::Time time;
+               timecode_time_subframes (t, time);
+               MIDI::Manager::instance()->mmc()->send (MIDI::MachineControlCommand (time));
+       }
 }
 
 /** Ask the transport to not send timecode until further notice.  The suspension
index 80169c2c25cfc901b6968443e0e8b9a52c124085..e54b69a04daca1274c57bc7914a11363996ccd1b 100644 (file)
@@ -99,6 +99,7 @@ class MachineControl
        byte receive_device_id () const { return _receive_device_id; }
        byte send_device_id () const { return _send_device_id; }
        void enable_send (bool);
+       bool send_enabled () const { return _enable_send; }
        void send (MachineControlCommand const &);
 
        static bool is_mmc (byte *sysex_buf, size_t len);