X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fmidi%2B%2B2%2Fmmc.cc;h=292b6cc1b4ff105242eb02f54ca0a86b4d4bb1b4;hb=31e203ac07cbda216fc842c68b9192d082ba8d65;hp=61c47e856f96d82edd7e21ab74b6d17ccc40c116;hpb=fe13d08874f08b723df53116e5655c3d229a657e;p=ardour.git diff --git a/libs/midi++2/mmc.cc b/libs/midi++2/mmc.cc index 61c47e856f..292b6cc1b4 100644 --- a/libs/midi++2/mmc.cc +++ b/libs/midi++2/mmc.cc @@ -18,12 +18,15 @@ $Id$ */ +#include #include -#include -#include -#include -#include +#include "timecode/time.h" +#include "pbd/error.h" +#include "midi++/mmc.h" +#include "midi++/port.h" +#include "midi++/parser.h" +#include "midi++/manager.h" using namespace std; using namespace MIDI; @@ -192,37 +195,36 @@ static void build_mmc_cmd_map () } -MachineControl::MachineControl (Port &p, float version, - CommandSignature &csig, - ResponseSignature &rsig) - - : _port (p) +MachineControl::MachineControl (Manager* m, jack_client_t* jack) { - Parser *parser; - build_mmc_cmd_map (); - _device_id = 1; - - if ((parser = _port.input()) != 0) { - parser->mmc.connect - (mem_fun (*this, &MachineControl::process_mmc_message)); - } else { - warning << "MMC connected to a non-input port: useless!" - << endmsg; - } + _receive_device_id = 0x7f; + _send_device_id = 0x7f; + + _input_port = m->add_port (new Port ("MMC in", Port::IsInput, jack)); + _output_port = m->add_port (new Port ("MMC out", Port::IsOutput, jack)); + + _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, _1, _2)); + _input_port->parser()->contineu.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_continue, this, _1, _2)); + _input_port->parser()->stop.connect_same_thread (port_connections, boost::bind (&MachineControl::spp_stop, this, _1, _2)); } void -MachineControl::set_device_id (byte id) +MachineControl::set_receive_device_id (byte id) +{ + _receive_device_id = id & 0x7f; +} +void +MachineControl::set_send_device_id (byte id) { - _device_id = id & 0x7f; + _send_device_id = id & 0x7f; } bool MachineControl::is_mmc (byte *sysex_buf, size_t len) - { if (len < 4 || len > 48) { return false; @@ -241,8 +243,7 @@ MachineControl::is_mmc (byte *sysex_buf, size_t len) } void -MachineControl::process_mmc_message (Parser &p, byte *msg, size_t len) - +MachineControl::process_mmc_message (Parser &, byte *msg, size_t len) { size_t skiplen; byte *mmc_msg; @@ -258,14 +259,14 @@ MachineControl::process_mmc_message (Parser &p, byte *msg, size_t len) */ #if 0 - cerr << "*** MMC message: len = " << len << "\n\t"; + cerr << "*** me = " << (int) _receive_device_id << " MMC message: len = " << len << "\n\t"; for (size_t i = 0; i < len; i++) { cerr << hex << (int) msg[i] << dec << ' '; } cerr << endl; #endif - if (msg[1] != 0x7f && msg[1] != _device_id) { + if (msg[1] != 0x7f && msg[1] != _receive_device_id) { return; } @@ -450,7 +451,6 @@ MachineControl::process_mmc_message (Parser &p, byte *msg, size_t len) int MachineControl::do_masked_write (byte *msg, size_t len) - { /* return the number of bytes "consumed" */ @@ -458,7 +458,11 @@ MachineControl::do_masked_write (byte *msg, size_t len) switch (msg[2]) { case 0x4f: /* Track Record Ready Status */ - write_track_record_ready (&msg[3], len - 3); + write_track_status (&msg[3], len - 3, msg[2]); + break; + + case 0x62: /* track mute */ + write_track_status (&msg[3], len - 3, msg[2]); break; default: @@ -472,8 +476,7 @@ MachineControl::do_masked_write (byte *msg, size_t len) } void -MachineControl::write_track_record_ready (byte *msg, size_t len) - +MachineControl::write_track_status (byte *msg, size_t /*len*/, byte reg) { size_t n; ssize_t base_track; @@ -543,14 +546,18 @@ MachineControl::write_track_record_ready (byte *msg, size_t len) bit set. */ - if (msg[2] & (1<port() << " - " << session_send_mmc << endl; + return; + } + + MIDI::byte buffer[32]; + MIDI::byte* b = c.fill_buffer (this, buffer); + + if (_output_port->midimsg (buffer, b - buffer, 0)) { + error << "MMC: cannot send command" << endmsg; + } +} + +void +MachineControl::spp_start (Parser& parser, framecnt_t timestamp) +{ + SPPStart (parser, timestamp); /* EMIT SIGNAL */ +} + +void +MachineControl::spp_continue (Parser& parser, framecnt_t timestamp) +{ + SPPContinue (parser, timestamp); /* EMIT SIGNAL */ +} + +void +MachineControl::spp_stop (Parser& parser, framecnt_t timestamp) +{ + SPPStop (parser, timestamp); /* EMIT SIGNAL */ +} + +MachineControlCommand::MachineControlCommand (MachineControl::Command c) + : _command (c) +{ + +} + +MachineControlCommand::MachineControlCommand (Timecode::Time t) + : _command (MachineControl::cmdLocate) + , _time (t) +{ + +} + +MIDI::byte * +MachineControlCommand::fill_buffer (MachineControl* mmc, MIDI::byte* b) const +{ + *b++ = 0xf0; // SysEx + *b++ = 0x7f; // Real-time SysEx ID for MMC + *b++ = mmc->send_device_id(); + *b++ = 0x6; // MMC command + + *b++ = _command; + + if (_command == MachineControl::cmdLocate) { + *b++ = 0x6; // byte count + *b++ = 0x1; // "TARGET" subcommand + *b++ = _time.hours; + *b++ = _time.minutes; + *b++ = _time.seconds; + *b++ = _time.frames; + *b++ = _time.subframes; + } + + *b++ = 0xf7; + + return b; +} +