MIDI file parsing - Javascript help

Dan Nigrin's icon

I'm trying to get around some of the clunkiness in using Max's built in objects to read in MIDI files (detonate, filein, seq, etc...). Specifically, I'd like an easier way to read the actual tick counts for the delta time and duration times for each note (rather than msec which detonate outputs), as well as the tempo.

I started to explore using some existing Javascript libraries to do this, but sadly, my Javascript skills are not great, especially in Max. V8, Node.js, etc... are all pretty new for me. I came across this, https://cycling74.com/projects/midi-parsing-using-javascript-in-max , which looked promising, but no accompanying help file to walk through its usage.

I also see midi-parser-js as a Node NPM project which looks even better, and I can load it into a node.script object in Max, but then don't know how to use it from there: https://www.npmjs.com/package/midi-parser-js

There's also midi-file, another NPM project, but again, just don't know what to do once loaded https://www.npmjs.com/package/midi-file

Any help incredibly appreciated!

Source Audio's icon

I am not really friend of java.

filein parsing covered all my midi parsing needs so far.

maybe you can also look into shell and some binaries ?

I used this stuff many years ago, before filein existed in max.

Dan Nigrin's icon

Thanks - will explore this approach too.

I still scratch my head about why this isn't core Max functionality, considering how ubiquitous MIDI is within multimedia applications....

Source Audio's icon

it is anyway unfortunate type of media.

if you load midi file into seq or detonate, you get rounded ms timing.

Now try to play seq using midi ticks - it will not match original

timing even in simplest midi file.

Dan Nigrin's icon

Exactly - that's what is frustrating about using seq or detonate....

Roman Thilenius's icon

that´s why i stopped exporting midi from detonate and use its custom format instead. as a result, replaying is limited to max, max4live and pluggo. :/

an interpreter around [filein] seems to be the best solution. but it is a lot of work if you want to make it as complete as possible. you would basically build a custom detonate with unlimited channel messages, in floating point, and then hook up midiparse and mpeparse plus an extension to those two, to cover everything.

yaniki's icon

Maybe Node4Max and midi-parser-js?

Source Audio's icon

that npm java link was included in original post,

and a question how to use it

yaniki's icon

SOURCE AUDIO Ah, haha... of course... I just bypassed it mentally for some reason...

I have an idea to add parsing MIDI files to my collection of JS-based solutions for different Max-related tasks, but this should wait a bit...

Dan Nigrin's icon

I'm traveling for work right now without a ton of time, but a quick update is that two of the links I posted in the original post are meant to be used together; this https://cycling74.com/projects/midi-parsing-using-javascript-in-max uses this https://www.npmjs.com/package/midi-file .

I was able to get it working, will post more soon.

Dan Nigrin's icon

I posted an example patch over here - probably makes sense to have future discussion in that location, to keep everything in one place: https://cycling74.com/projects/midi-parsing-using-javascript-in-max