Variable-length quantity in Midi files

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
capellan
Posts: 527
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Variable-length quantity in Midi files

Post by capellan » Sun Feb 26, 2017 3:47 am

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 90 times

PaulDaMacMan
Posts: 190
Joined: Wed Apr 24, 2013 4:53 pm

Re: Variable-length quantity in Midi files

Post by PaulDaMacMan » Wed Mar 29, 2017 4:24 pm

: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.

PaulDaMacMan
Posts: 190
Joined: Wed Apr 24, 2013 4:53 pm

Re: Variable-length quantity in Midi files

Post by PaulDaMacMan » Wed Mar 29, 2017 4:30 pm

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.

capellan
Posts: 527
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: Variable-length quantity in Midi files

Post by capellan » Wed Mar 29, 2017 9:56 pm

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

PaulDaMacMan
Posts: 190
Joined: Wed Apr 24, 2013 4:53 pm

Re: Variable-length quantity in Midi files

Post by PaulDaMacMan » Thu Mar 30, 2017 5:22 pm

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.

PaulDaMacMan
Posts: 190
Joined: Wed Apr 24, 2013 4:53 pm

Re: Variable-length quantity in Midi files

Post by PaulDaMacMan » Thu Mar 30, 2017 5:25 pm

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)

Post Reply

Return to “Rich Media”