accessing tempo meta data in a midi file using possibly filein? or something else?
I'm trying to make a patch that selects a midi file, of which the initial tempo (from tempo meta data) matches the given tempo of my selection.
So, "hey, I want to play a song starts with a tempo closest to 135bpm", and then the patch finds it.
Anyhow, I'm stuck with accessing to the metadata info. Detonate wouldn't work, because it's only playing music tracks, not the "tempo track".
I found this old post: https://cycling74.com/forums/detect-midi-files-bpm/replies/1#reply-58ed20ffc2991221d9cc5b13
S/he says I'll need to use filein, in order to access the data that I can't access via detonate/seq. When I try to have that object read a format1 midi file, using filein.maxhelp, it gives me numbers that appear to be note on/off type of messages.
What am I missing here? I couldn't find a ton of examples using filein object, so I'm not quite sure how to even use it, and what it's really putting out.
This document may be helpful.
http://www.music.mcgill.ca/~ich/classes/mumt306/StandardMIDIfileformat.html
@BROC, thanks!!
It's really messy, but I was able to extract and filter the data.
But I have another issue.
After 255(meta message) and 51(tempo message), I got 3, which means that there are three bytes to form the final tempo value.
In the sample midi I'm using, I get 0F, 02, and 36 for the three bytes. What I really need to compute is 0x0F0236.
In order to concatenate those three bytes, I'm using append and then sprintf%s%s%s.
The problem occurs when I append each byte. When the hex number gets appended, it automatically gets converted to decimal. (appending as 15, instead of 0F) Also, rather than appending as "02", it appends "2". So in the end, I get "0x15254"
Is there a way to get around it? how do I disable automatic conversion?


nvm. I figured it out.
I simply multiplied each append by appropriate hex "spacer" and added together.
so essentially 235_10 = 2_10*100_10 + 3_10*10_10 + 5_10, but for hex.
since I needed to multiple 0F so that 0F is, in fact, 0F0000, I let max convert 0F to 15 and then multiplied it by 65536, which is 10000_16.

i use filein, too.
midi sucks big time because you have to search for the end of the header or the begin of a certain track byte by byte. but its doable. look into the specs, convert the search string to integer, know where you are.
ugh. you guys are too good. That looks so much simpler than mine.