Variable-length quantity in Midi files
Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller
Variable-length quantity in Midi files
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
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
-
- Posts: 341
- Joined: Wed Apr 24, 2013 4:53 pm
- Contact:
Re: Variable-length quantity in Midi files

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.
My LCB Repos: https://github.com/PaulMcClernan/
-
- Posts: 341
- Joined: Wed Apr 24, 2013 4:53 pm
- Contact:
Re: Variable-length quantity in Midi files
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.
My LCB Repos: https://github.com/PaulMcClernan/
Re: Variable-length quantity in Midi files
Hi Paul,
I was looking for creating a LiveCode version of Mozart Dice Musical Game
but have to stop until I finish some pending work...
http://sunsite.univie.ac.at/Mozart/dice/
Al
I was looking for creating a LiveCode version of Mozart Dice Musical Game

but have to stop until I finish some pending work...
http://sunsite.univie.ac.at/Mozart/dice/
Al
-
- Posts: 341
- Joined: Wed Apr 24, 2013 4:53 pm
- Contact:
Re: Variable-length quantity in Midi files
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.
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.
My LCB Repos: https://github.com/PaulMcClernan/
-
- Posts: 341
- Joined: Wed Apr 24, 2013 4:53 pm
- Contact:
Re: Variable-length quantity in Midi files
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)
My LCB Repos: https://github.com/PaulMcClernan/