$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 ()
{
}
-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
_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;
}
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)
return b;
}
+