Skip to main content

ascii_file

Function ascii_file 

Source
pub fn ascii_file(
    format: i128,
    ticks_per_quarter: i128,
    tracks: &[Vec<String>],
) -> Result<(Vec<u8>, Vec<Unsupported>)>
Expand description

A file written from music21’s text notation for MIDI, and the events it left out: music21’s midiAsciiStringToBinaryString.

Each track is a list of events, each delta status key velocity: the delta in decimal, the status and key in hexadecimal, the velocity in decimal. Only note-ons and note-offs are written, on the channel of the track’s place, counted from one. A file of one track is format 1 whatever format says.

use music21::midi::translate::ascii_file;

let (bytes, unsupported) = ascii_file(1, 960, &[vec!["0 90 31 15".to_string()]])?;
assert_eq!(&bytes[14..], b"MTrk\x00\x00\x00\x04\x00\x901\x0f");
assert!(unsupported.is_empty());

§Errors

An event of fewer than four fields, or a field that is no number.