Make check for new Lilv optional.
[ardour.git] / libs / midi++2 / mmc.cc
index b8aa253f80385d0ce2c02d37ce28e2d12692ebb3..06eadb5b34adcead348030f8061b05d769cc5b02 100644 (file)
     $Id$
 */
 
+#include <fcntl.h>
 #include <map>
 
-#include "control_protocol/timecode.h"
+#include "timecode/time.h"
 #include "pbd/error.h"
 #include "midi++/mmc.h"
 #include "midi++/port.h"
+#include "midi++/jack_midi_port.h"
 #include "midi++/parser.h"
+#include "midi++/manager.h"
 
 using namespace std;
 using namespace MIDI;
 using namespace PBD;
 
-pthread_t MachineControl::_sending_thread;
-
 static std::map<int,string> mmc_cmd_map;
 static void build_mmc_cmd_map ()
 {
@@ -195,28 +196,20 @@ static void build_mmc_cmd_map ()
 }
 
 
-MachineControl::MachineControl ()
-       : _port (0)
-       , _pending (16)
+MachineControl::MachineControl (Manager* m, jack_client_t* jack)
 {
        build_mmc_cmd_map ();
 
-       _receive_device_id = 0;
+       _receive_device_id = 0x7f;
        _send_device_id = 0x7f;
-}
 
-void
-MachineControl::set_port (Port* p)
-{
-       _port = p;
+       _input_port = m->add_port (new JackMIDIPort ("MMC in", Port::IsInput, jack));
+       _output_port = m->add_port (new JackMIDIPort ("MMC out", Port::IsOutput, jack));
 
-       mmc_connection.disconnect ();
-
-       if (_port->input()) {
-               _port->input()->mmc.connect_same_thread (mmc_connection, boost::bind (&MachineControl::process_mmc_message, this, _1, _2, _3));
-       } else {
-               warning << "MMC connected to a non-input port: useless!" << endmsg;
-       }
+       _input_port->parser()->mmc.connect_same_thread (port_connections, boost::bind (&MachineControl::process_mmc_message, this, _1, _2, _3));
+       _input_port->parser()->start.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_start, this));
+       _input_port->parser()->contineu.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_continue, this));
+       _input_port->parser()->stop.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_stop, this));
 }
 
 void
@@ -558,10 +551,12 @@ MachineControl::write_track_status (byte *msg, size_t /*len*/, byte reg)
                        
                        switch (reg) {
                        case 0x4f:
+                               trackRecordStatus[base_track+n] = val;
                                TrackRecordStatusChange (*this, base_track+n, val);
                                break;
                                
                        case 0x62:
+                               trackMute[base_track+n] = val;
                                TrackMuteChange (*this, base_track+n, val);
                                break;
                        }
@@ -635,38 +630,13 @@ MachineControl::enable_send (bool yn)
        _enable_send = yn;
 }
 
-/** Send a MMC command.  It will be sent immediately if the call is made in _sending_thread,
- *  otherwise it will be queued and sent next time flush_pending()
- *  is called.
- *  @param c command, which this method takes ownership of.
+/** Send a MMC command to a the MMC port.
+ *  @param c command.
  */
 void
 MachineControl::send (MachineControlCommand const & c)
 {
-       if (pthread_self() == _sending_thread) {
-               send_immediately (c);
-       } else {
-               _pending.write (&c, 1);
-       }
-}
-
-/** Send any pending MMC commands immediately.  Must be called from _sending_thread */
-void
-MachineControl::flush_pending ()
-{
-       MachineControlCommand c;
-       while (_pending.read (&c, 1) == 1) {
-               send_immediately (c);
-       }
-}
-
-/** Send a MMC immediately.  Must be called from _sending_thread.
- *  @param c command, which this method takes ownership of.
- */
-void
-MachineControl::send_immediately (MachineControlCommand const & c)
-{
-       if (_port == 0 || !_enable_send) {
+       if (_output_port == 0 || !_enable_send) {
                // cerr << "Not delivering MMC " << _mmc->port() << " - " << session_send_mmc << endl;
                return;
        }
@@ -674,16 +644,27 @@ MachineControl::send_immediately (MachineControlCommand const & c)
        MIDI::byte buffer[32];
        MIDI::byte* b = c.fill_buffer (this, buffer);
 
-       if (_port->midimsg (buffer, b - buffer, 0)) {
+       if (_output_port->midimsg (buffer, b - buffer, 0)) {
                error << "MMC: cannot send command" << endmsg;
        }
 }
 
-/** Set the thread that we should send MMC in */
 void
-MachineControl::set_sending_thread (pthread_t t)
+MachineControl::spp_start ()
+{
+       SPPStart (); /* EMIT SIGNAL */
+}
+
+void
+MachineControl::spp_continue ()
 {
-       _sending_thread = t;
+       SPPContinue (); /* EMIT SIGNAL */
+}
+
+void
+MachineControl::spp_stop ()
+{
+       SPPStop (); /* EMIT SIGNAL */
 }
 
 MachineControlCommand::MachineControlCommand (MachineControl::Command c)
@@ -723,3 +704,4 @@ MachineControlCommand::fill_buffer (MachineControl* mmc, MIDI::byte* b) const
 
        return b;
 }
+