MIDI file parsing - Javascript help
Dan Nigrin
Mar 23, 2025, 7:24 PM
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
Mar 24, 2025, 10:52 AM
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
Mar 24, 2025, 11:17 AM
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
Mar 24, 2025, 1:08 PM
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
Mar 24, 2025, 3:16 PM
Exactly - that's what is frustrating about using seq or detonate....
Roman Thilenius
Mar 24, 2025, 8:39 PM
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
Mar 24, 2025, 9:02 PM
Maybe Node4Max and midi-parser-js?
Source Audio
Mar 25, 2025, 9:45 AM
that npm java link was included in original post,
and a question how to use it
yaniki
Mar 25, 2025, 11:50 AM
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
Mar 25, 2025, 1:24 PM
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
Mar 28, 2025, 9:35 PM
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