#audio #midi #vst-plugin #user-interface #web #nom #ui #parser

augmented-midi

Experimental MIDI file/event parser using nom combinators

11 releases (3 stable)

Uses new Rust 2021

1.3.0 Oct 22, 2022
1.2.0 Sep 29, 2022
1.0.0-alpha.7 May 25, 2022
1.0.0-alpha.5 Apr 7, 2022
1.0.0-alpha.2 Jan 16, 2022

#7 in #vst-plugin

Download history 22/week @ 2022-08-09 10/week @ 2022-08-16 17/week @ 2022-08-23 16/week @ 2022-08-30 48/week @ 2022-09-06 27/week @ 2022-09-13 37/week @ 2022-09-20 80/week @ 2022-09-27 56/week @ 2022-10-04 29/week @ 2022-10-11 45/week @ 2022-10-18 52/week @ 2022-10-25 57/week @ 2022-11-01 32/week @ 2022-11-08 39/week @ 2022-11-15 15/week @ 2022-11-22

151 downloads per month
Used in 7 crates (via audio-processor-standalone)

MIT license

91KB
1.5K SLoC

augmented-midi

Implements a MIDI (file) parser/serializer using nom and cookie-factory combinators.

Thanks to the combinators this library requires no allocation for serialization/de-serialization into/from the MIDI types provided.

(This is part of augmented-audio)

Specification

Based on MIDI 1.0 specification. MIDI 1.0

License notes

There's a Bach MIDI file used from piano-midi.de linked here. This file is licensed as described in http://www.piano-midi.de/copy.htm. Name: Bernd Krueger The distribution or public playback of the files is only allowed under identical license conditions. The scores are open source.

Parsing a single message

We can parse a single MIDI message as follows.

use augmented_midi::{MIDIMessage, MIDIMessageNote, MIDIParseResult, parse_midi_event, ParserState};

// Initialize parser state. This is here to support rolling status on MIDI files
let mut state = ParserState::default();

// We'll parse this &[u8] buffer. This could be a vec
let input_buffer = [0x9_8, 0x3C, 0x44];

// We parse a message borrowing from the input buffer. We could use `MIDIMessage<Vec<u8>>` to
// allocate owned messages.
//
// This is only relevant for variable size messages like SysEx.
//
// Parsing is otherwise only using the stack.
let parse_result: MIDIParseResult<MIDIMessage<&[u8]>> =
    parse_midi_event(&input_buffer, &mut state);
let (_remaining_input, midi_message) = parse_result.unwrap();

assert_eq!(midi_message, MIDIMessage::NoteOn(MIDIMessageNote { channel: 8, note: 60, velocity: 68 }));

Serializing messages

use augmented_midi::{serialize_message, MIDIMessage};

let mut  writer = [0_u8;3]; // This could be a vec.
let message: MIDIMessage<Vec<u8>> = MIDIMessage::control_change(0, 55, 127); // CC#55 127 - channel 0
let _ = serialize_message(message, &mut writer[..]).unwrap();

assert_eq!(writer, [0xB0, 0x37, 0x7F]);

License: MIT

Dependencies

~1.7–2.5MB
~51K SLoC