Crates.io | midi-vlq |
lib.rs | midi-vlq |
version | 0.1.0 |
source | src |
created_at | 2022-01-22 17:00:42.690286 |
updated_at | 2022-01-22 17:00:42.690286 |
description | Variable-Length Quantity for the MIDI file format |
homepage | |
repository | https://github.com/m-rinaldi/midi-vlq |
max_upload_size | |
id | 519228 |
size | 13,996 |
midi-vlq
The Variable-Length Quantities (VLQs) as defined by the Standard MIDI file format.
From the Standard MIDI-File Format Spec. 1.1:
Some numbers in MIDI Files are represented in a form called a variable-length quantity. These numbers are represented 7 bits per byte, most significant bits first. All bytes except the last have bit 7 set, and the last byte has bit 7 clear. If the number is between 0 and 127, it is thus represented exactly as one byte.
use midi_vlq::MidiVlq;
// encode 127 as VLQ
let vlq = MidiVlq::from(127u8);
// 127 is encoded with a single byte
assert_eq!(vlq, [127]);
// encode 128 as VLQ
let vlq = MidiVlq::from(128u8);
// 128 needs two bytes
assert_eq!(vlq, [0x81, 0x00]);