X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fmidi%2B%2B2%2Fmtc.cc;h=e2a018ca51ddda65af2b8ae18706279194a152c8;hb=81d47f5b8c843ebf9a5b6d02282cd752c8fc1811;hp=55ceb97b8f57b768949cdc3e5c4514cb33f3d91e;hpb=50131b3751e6ed5c9ed7450406049b2195ea9ecf;p=ardour.git diff --git a/libs/midi++2/mtc.cc b/libs/midi++2/mtc.cc index 55ceb97b8f..e2a018ca51 100644 --- a/libs/midi++2/mtc.cc +++ b/libs/midi++2/mtc.cc @@ -33,8 +33,10 @@ using namespace std; using namespace sigc; using namespace MIDI; +#undef DEBUG_MTC + bool -Parser::possible_mtc (byte *sysex_buf, size_t msglen) +Parser::possible_mtc (MIDI::byte *sysex_buf, size_t msglen) { byte fake_mtc_time[5]; @@ -61,7 +63,10 @@ Parser::possible_mtc (byte *sysex_buf, size_t msglen) /* emit signals */ mtc (*this, &sysex_buf[1], msglen - 1); - mtc_time (fake_mtc_time, true); + mtc_time (fake_mtc_time, true, _timestamp); +#ifdef DEBUG_MTC + cerr << "New full-MTC message marks state stopped" << endl; +#endif mtc_status (MTC_Stopped); return true; @@ -70,6 +75,11 @@ Parser::possible_mtc (byte *sysex_buf, size_t msglen) void Parser::reset_mtc_state () { +#ifdef DEBUG_MTC + cerr << "MTC state reset" << endl; +#endif + /* MUST REMAIN RT-SAFE */ + _mtc_forward = false; _mtc_running = MTC_Stopped; _mtc_locked = false; @@ -81,7 +91,7 @@ Parser::reset_mtc_state () } void -Parser::process_mtc_quarter_frame (byte *msg) +Parser::process_mtc_quarter_frame (MIDI::byte *msg) { int which_quarter_frame = (msg[1] & 0xf0) >> 4; @@ -119,14 +129,17 @@ Parser::process_mtc_quarter_frame (byte *msg) /* third quarter frame */ - // cerr << "second seen qframe = " << (int) which_quarter_frame << endl; - +#ifdef DEBUG_MTC + cerr << "second seen qframe = " << (int) which_quarter_frame << endl; +#endif if (last_qtr_frame < which_quarter_frame) { _mtc_running = MTC_Forward; } else if (last_qtr_frame > which_quarter_frame) { _mtc_running = MTC_Backward; } - +#ifdef DEBUG_MTC + cerr << "Send MTC status as " << _mtc_running << endl; +#endif mtc_status (_mtc_running); } @@ -172,7 +185,9 @@ Parser::process_mtc_quarter_frame (byte *msg) true, just ignore this in terms of it being an error. */ - if (1) { /* mtc_skipped () */ + boost::optional res = mtc_skipped (); + + if (res.get_value_or (false)) { /* no error, reset next expected frame */ @@ -204,13 +219,12 @@ Parser::process_mtc_quarter_frame (byte *msg) return; } - /* go back to waiting for the first frame */ - - expected_mtc_quarter_frame_code = 0; - memset (_qtr_mtc_time, 0, sizeof (_qtr_mtc_time)); + /* skip counts as an error ... go back to waiting for the first frame */ - _mtc_running = MTC_Stopped; - _mtc_locked = false; +#ifdef DEBUG_MTC + cerr << "Skipped MTC qtr frame, return to stopped state" << endl; +#endif + reset_mtc_state (); mtc_status (MTC_Stopped); return; @@ -271,18 +285,22 @@ Parser::process_mtc_quarter_frame (byte *msg) break; default: - /*NOTREACHED*/ + abort(); /*NOTREACHED*/ break; } - mtc_qtr (*this, which_quarter_frame); /* EMIT_SIGNAL */ +#ifdef DEBUG_MTC + cerr << "Emit MTC Qtr\n"; +#endif + + mtc_qtr (*this, which_quarter_frame, _timestamp); /* EMIT_SIGNAL */ // mtc (*this, &msg[1], msglen - 1); switch (_mtc_running) { case MTC_Forward: - if ((which_quarter_frame == 7)) { + if (which_quarter_frame == 7) { /* we've reached the final of 8 quarter frame messages. store the time, reset the pending time holder, @@ -296,7 +314,7 @@ Parser::process_mtc_quarter_frame (byte *msg) _mtc_locked = true; } - mtc_time (_mtc_time, false); + mtc_time (_mtc_time, false, _timestamp); } expected_mtc_quarter_frame_code = 0; @@ -319,7 +337,7 @@ Parser::process_mtc_quarter_frame (byte *msg) if (!_mtc_locked) { _mtc_locked = true; } - mtc_time (_mtc_time, false); + mtc_time (_mtc_time, false, _timestamp); } expected_mtc_quarter_frame_code = 7;