B.Cornaz at gmx.net
Fri Feb 20 09:55:22 EST 2009
Hi René ,
I have been abroad and could not react earlier. Fortunalety Kurt has
helped you out quite a bit.
Maybe the following can be of use to you. The thing that took the
longest time for me in the Midi code to 'crack' was the 'Delta time' ,
being the time to the next midi event (whether a Note on, Note off or
Midi message). As the Delta time cannot be fixed into a fixed data
format (it must be flexible tpo accomodate for long Delta times), the
Midi format uses 'Variable Length coding', which can accomodate any
As it is some years ago that I have coded my 'MakeMidiFile' script, I
can't remember exactly how the Variable Length coding works, but I can
send you the
handler or post it here if someone else is ineterested.
Another thing I remember, is that one of the Rev functions -
baseconvert() or BinaryDecode() would not work anymore as the number
to convert got too big. I have made a workaround. I just looked in my
MidiLib, but could not find it anymore. Maybe it has been fixed in the
newer Rev versions, as I tried big numbers and they converted just
fine.But I realised that my MidiLib needs some serious cleaning up!!
In a midi file (as Kurt already explained), some (Hex) stuff is always
there, like the Header , Tempo, TimeSignature and Key. The actual data
for the Tempo (e.g. 120) etc. is given by you of course (in Hex).
Track 1 contains all this information and the actual notes start in
track 2. (In any case in a midi file with more than 1 track). After
you have the whole Midifile in Hex, you convert it to Binary (with
BinaryEncode). Of course, the binary encode can be done earlier on,
like after each Hex duplet or Hex part has been established (I think I
remember Kurt does it that way).
In the header of each track, you'll need the specify the length of the
data of that track (the number of Hex digits in that track).
So basically you have to convert decimal data (like noteNrs, velocity,
duration etc) to Hex and the whole Hex data to binary.
I can send you my MidiLib, so you can see how I have done it. I will
have to clean it up before I send it, it's too messy, but it works fine.
I have not yet experimented with the QT synth, as I was (am) aiming to
directly address Logic. But I guess I will try with the QT synth as
well, as my bigger goal is quite a challange it seems.
In my MidiLib, there is also a handler to import a MidiFile. I use it
to import from Logic, then make variantions of the theme in my Rev
stack and make a new MidiFile which I drag into my sequencer.
Don't let the dataformat of the Midi file get to you. It takes a while
to get it. I have been 'struggling' with it for some months untill the
handler finally worked. Bit by bit, you'll get to understand it
better. I'll be gladly helping you, but unfortunately I don't have
the time to read the usergroup's mails on a daily basis.
I hope this helps some,
kind regards, Beat
More information about the Use-livecode