NodeJS - Converting MTC (Midi Timecode) "quater message" into a full timecode string

459 views Asked by At

So here's my problem. I'm working on a script in NodeJS, that will take an MTC, or MIDI Timecode signal, and eventually, trigger different things off of certain points in said timecode.

The issue I'm having currently is that the current Timecode clock program I am using, sends the MIDI timecode message as what is known as a "quarter frame" message. Put simply, it sends, in hex, eight consecutive messages, that altogether make up the hh:mm:ss:ff (hour, minute, second, frame) format. If the first message is 00, that means that the units digit of the frames number is 0 (still in hex), if the second message is 15, from the 1, that means that the frames tens digit is 5. That's a super dodgy explanation, so here is the only valid documentation I could find to explain it.

I managed to find another StackOverflow question that is the same, except the code provided is in C#, and I don't know how to translate that over to JavaScript with my limited knowledge. Here is that question.

Thanks in advance

1

There are 1 answers

0
AudioBubble On

There is a library named JZZ.js that, among other things, allows to convert sequential MTC into a time code. A code snippet is available at https://jazz-soft.net/doc/JZZ/smpte.html#read

code:

var master = JZZ.SMPTE();                // master clock
var slave = JZZ.SMPTE();                 // slave clock
var sender = JZZ.Widget();               // sending port
var receiver = JZZ.Widget();             // receiving port
receiver._receive = function(msg) {
  if (slave.read(msg))                   // print and consume the MTC messages
    console.log(master.toString(), ' ==> ', msg.toString(), ' ==> ', slave.toString());
  else _emit(msg);                       // forward all other MIDI messages
};
sender.connect(receiver);
master.reset(24, 7, 39, 59);             // 7:40 it arrives...
for (var n = 0; n < 25; n++) {
  sender.mtc(master);
  master.incrQF();
}

output:

07:39:59:00  ==>  f1 00 -- MIDI Time Code  ==>  00:00:00:00
07:39:59:00  ==>  f1 10 -- MIDI Time Code  ==>  00:00:00:00
07:39:59:00  ==>  f1 2b -- MIDI Time Code  ==>  00:00:00:00
07:39:59:00  ==>  f1 33 -- MIDI Time Code  ==>  00:00:00:00
07:39:59:01  ==>  f1 47 -- MIDI Time Code  ==>  00:00:00:01
07:39:59:01  ==>  f1 52 -- MIDI Time Code  ==>  00:00:00:01
07:39:59:01  ==>  f1 67 -- MIDI Time Code  ==>  00:00:00:01
07:39:59:01  ==>  f1 70 -- MIDI Time Code  ==>  00:00:00:01
07:39:59:02  ==>  f1 02 -- MIDI Time Code  ==>  07:39:59:02
07:39:59:02  ==>  f1 10 -- MIDI Time Code  ==>  07:39:59:02
07:39:59:02  ==>  f1 2b -- MIDI Time Code  ==>  07:39:59:02
07:39:59:02  ==>  f1 33 -- MIDI Time Code  ==>  07:39:59:02
07:39:59:03  ==>  f1 47 -- MIDI Time Code  ==>  07:39:59:03
07:39:59:03  ==>  f1 52 -- MIDI Time Code  ==>  07:39:59:03
07:39:59:03  ==>  f1 67 -- MIDI Time Code  ==>  07:39:59:03
07:39:59:03  ==>  f1 70 -- MIDI Time Code  ==>  07:39:59:03
07:39:59:04  ==>  f1 04 -- MIDI Time Code  ==>  07:39:59:04
07:39:59:04  ==>  f1 10 -- MIDI Time Code  ==>  07:39:59:04
07:39:59:04  ==>  f1 2b -- MIDI Time Code  ==>  07:39:59:04
07:39:59:04  ==>  f1 33 -- MIDI Time Code  ==>  07:39:59:04
07:39:59:05  ==>  f1 47 -- MIDI Time Code  ==>  07:39:59:05
07:39:59:05  ==>  f1 52 -- MIDI Time Code  ==>  07:39:59:05
07:39:59:05  ==>  f1 67 -- MIDI Time Code  ==>  07:39:59:05
07:39:59:05  ==>  f1 70 -- MIDI Time Code  ==>  07:39:59:05
07:39:59:06  ==>  f1 06 -- MIDI Time Code  ==>  07:39:59:06