jdachtera / node-rtpmidi

A node js implementation of Apples Network Midi Protocol.
92 stars 17 forks source link

MTC and conversion #2

Closed Isilwing closed 10 years ago

Isilwing commented 10 years ago

Hello Jdachtera,

I came here by Tobias Erichsen recommendation. I tested your code 0.0.2 and it work great, i was able to connect two PC. I test it sending MTC and i saw that it get the hexadecimal message on the buffer under debbug mode:

Incoming Message = Buffer 80 61 19 0f 02 07 7f 3a cf 73 b5 e1 02 f1 74 Incoming Message = Buffer 80 61 19 10 02 07 7f 8a cf 73 b5 e1 02 f1 04 Incoming Message = Buffer 80 61 19 11 02 07 7f e4 cf 73 b5 e1 02 f1 11 etc...

Im familiar with MTC but toooo new to node and javascript, so my question: its possible to convert the MTC received on HH:MM:SS.FF ? Can you point me in some direction? I saw that the buffer is constructed in 4 blocks, start, version, buffer and ifValid, so not really sure how to extract the hh:mm:ss.ff from it. My goal is to create a counter to display the MTC in hours, min, sec and frames.

I would really appreciate any lights on it.

Regards Isilwing

jdachtera commented 10 years ago

Hi Isilwing, the buffers you are seeing are the rtp packets. You don't have to deal with this stuff to simply receive midi messages. Until now this library only supported the basic channel messages like Note on/off etc. But I now pushed some commits to enable all possible midi commands. I also included a parser to construct the full timecode from the quarter time messages. Please take a look at examples/mtc.js.

Isilwing commented 10 years ago

Hi Jdachtera!

AWESOME! i will test it right away! thanks a lot!.

Isilwing commented 10 years ago

Hello Jdachtera,

Reporting back, i test it today with the following results:

C:\wamp\www\rtp2\examples>node mtc.js mDNS discovery is not available. <--- sorry i just notice that i need to install it and python as well.

C:\wamp\www\rtp2\src\Session.js:203 this.log("Server at " + rinfo.address + ':' + rinfo.port + ' d ^ TypeError: Object [object Object] has no method 'log' at null. (C:\wamp\www\rtp2\src\Session.js:203:22) at wrapper (timers.js:252:14) at Timer.listOnTimeout -as ontimeout- (timers.js:110:15) <-- i replaced the brackets by - so you can see the full line

C:\wamp\www\rtp2\examples>

I did a second test, adding the following block of code from mtc.js to examples/track_session.js: // Create a clock ..... and // Log the time code HH:MM:SS:FF.....

and it got the MTC, but as soon as i stop the sequencer thats generating the MTC i got another error, reporting it:

Position: 0 Time: 01:01:01:00 Position: 0 Time: 01:01:01:02 Position: 0 Time: 01:01:01:08

ReferenceError: lostSequenceNumbers is not defined at Stream.sendReceiverFeedback (C:\wamp\www\rtp2\src\Stream.js:203:45) at Timer.listOnTimeout -as ontimeout- (timers.js:110:15) <-- i replaced the brackets by - so you can see the full line

One last update, not sure if is the desired behavior, watching the mtc sequence i notice that are blocks of 17 lines others of 18 lines and seems that the frames jump in pairs (the test was done at 29,97 drop frame) , sometimes there is a odd time in the sequence

Position: 0 Time: 01:00:49:00 Position: 0 Time: 01:00:49:02 Position: 0 Time: 01:00:49:04 Position: 0 Time: 01:00:49:06 Position: 0 Time: 01:00:49:08 Position: 0 Time: 01:00:49:10 Position: 0 Time: 01:00:49:12 Position: 0 Time: 01:00:49:14 Position: 0 Time: 01:00:49:00 Position: 0 Time: 01:00:49:16 Position: 0 Time: 01:00:49:18 Position: 0 Time: 01:00:49:20 Position: 0 Time: 01:00:49:22 Position: 0 Time: 01:00:49:24 Position: 0 Time: 01:00:49:26 Position: 0 Time: 01:00:49:16 Position: 0 Time: 01:00:49:00

in this block there is a odd timecode in between

Position: 0 Time: 01:00:59:00 Position: 0 Time: 01:00:59:02 Position: 0 Time: 01:00:59:04 Position: 0 Time: 01:00:59:06 Position: 0 Time: 01:00:59:08 Position: 0 Time: 01:00:59:10 Position: 0 Time: 01:00:59:12 Position: 0 Time: 01:00:59:14 Position: 0 Time: 01:00:59:00 Position: 0 Time: 01:00:59:16 Position: 0 Time: 01:00:59:18 Position: 0 Time: 01:00:59:20 Position: 0 Time: 01:00:59:22 Position: 0 Time: 01:00:59:24 Position: 0 Time: 01:00:59:26 Position: 0 Time: 01:00:59:28 Position: 0 Time: 01:00:59:18 Position: 0 Time: 01:00:59:02 Position: 0 Time: 01:00:48:02 <<<<<------ this one Position: 0 Time: 01:00:00:02

Hope this reports can help in any way.

Regards

jdachtera commented 10 years ago

Thanks for the report. The typos that caused the error messages are now fixed. Regarding the mtc: Yes the frame jump in pairs is by design. Each quarter frame message contains only one eighth of the whole time code. This means it takes 8 messages / two frames to transmit a complete timestamp.

http://www.blitter.com/~russtopia/MIDI/~jglatt/tech/mtc.htm

I think this is also the source of the odd values. I now changed the code to emit the change event only if all 8 subsequent messages have been received. This should fix it.

Isilwing commented 10 years ago

Hey Jdachtera,

Awesome, everthing work lovely i did a stress test, it was running receiving MTC for around 1 hour, connecting two pc over internet, doing stop, play, and perfect! Thanks for this great work.

Ill play with it further!!