Page 1 of 1

Variable-length quantity in Midi files

Posted: Sun Feb 26, 2017 3:47 am
by capellan
Hi All,

Recently, while looking at the binary data of MIDI files, I found about Variable Length Quantity, a clever method for storing very large quantities using just a few hexadecimal numbers.

Using a single byte (1 ascii character = 1 hexadecimal number)
we could represent quantities from 0 to 127 (In hexadecimal 00 to 7F)
With two bytes, from 0 to 16383 (hexadecimal 0000 to FF7F)
Three bytes, from 0 to 2,097,151 (hexadecimal from 000000 to FFFF7F)
Four bytes, from 0 to 268,435,455 (hexadecimal from 00000000 to FFFFFF7F)

This stack is a simple interface for code posted by Paul McCleman in rossetacode:
https://rosettacode.org/wiki/Variable-l ... y#LiveCode

Al
Variable_Lenght_Quantity_v01.zip
Compressed Stack
(4.94 KiB) Downloaded 112 times

Re: Variable-length quantity in Midi files

Posted: Wed Mar 29, 2017 4:24 pm
by PaulDaMacMan
:D
Glad someone found it useful.
My interest in VLQ has everything to do with the MIDI file format.
As far as I know it's not really used for much else.

Re: Variable-length quantity in Midi files

Posted: Wed Mar 29, 2017 4:30 pm
by PaulDaMacMan
Also there are upper limits to that code, If I remember correctly it's only accurate up to 28 bit numbers. That's fine for MIDI use because in MIDI it's used for META Times (the amount of time that's passed since the last event on a given channel) so it's enough for many hours of time passing.

Re: Variable-length quantity in Midi files

Posted: Wed Mar 29, 2017 9:56 pm
by capellan
Hi Paul,

I was looking for creating a LiveCode version of Mozart Dice Musical Game :D
but have to stop until I finish some pending work...
http://sunsite.univie.ac.at/Mozart/dice/


Al

Re: Variable-length quantity in Midi files

Posted: Thu Mar 30, 2017 5:22 pm
by PaulDaMacMan
Not sure what platform you are targeting. There hasn't been an easy way to play MIDI files from LiveCode on Mac OS X since Apple abandoned QT Musical Instruments after Quicktime 7.
It is possible to do it in LC using the Browser Widget (NO AudioContext Support) or BrowserCEF extension (AudioContext supported) & Web Browser Plug-In called Jazz-MIDI Widget, then using JavaScript to send MIDI to Apples DLS Synth, or with BrowserCEF extension you can use various Javascript Libraries for WebAudio based output (this does not work with the Browser Widget)
http://jazz-soft.net/
Another option is installing & using FluidSynth to play MIDI, which I'm hoping could will eventually be wrapped with LCB w/FFI for a LC Library Extension.

Re: Variable-length quantity in Midi files

Posted: Thu Mar 30, 2017 5:25 pm
by PaulDaMacMan
There is also a Commercial LiveCode extension called SunnyMIDI (sorry if that's not accurate name), but that has several drawbacks IMO (it's Mac OS only for one)