A Rust library for parsing/building SMF (Standard MIDI File).
ghakuf
has parse module and build module separatory.
ghakuf
's parser is made by Event-driven online algorithm. You must prepare original handler implementing Handler trait to catch SMF messages. Any number of handlers you can add for parser if you want.
```rust use ghakuf::messages::; use ghakuf::reader::;
let mut reader = Reader::new( Box::new(HogeHandler {}), "test.mid", ).unwrap(); let _ = reader.read();
struct HogeHandler {}
impl Handler for HogeHandler {
fn header(&mut self, format: Format, track: u16, timebase: u16) {
// Something
}
fn metaevent(&mut self, deltatime: u32, event: &MetaEvent, data: &Vec
ghakuf
build SMF by Message enums. Message enum consists of MetaEvent, MidiEvent, SysExEvent, and TrackChange. You can use running status if you want. At track change, you should use not only MetaEvent::EndOfTrack message, but also TrackChange message.
```rust use ghakuf::messages::; use ghakuf::writer::;
let mut writer = Writer::new(); writer.runningstatus(true); let tempo: u32 = 60 * 1000000 / 102; //bpm:102 writer.push(Message::MetaEvent { deltatime: 0, event: MetaEvent::SetTempo, data: [(tempo >> 16) as u8, (tempo >> 8) as u8, tempo as u8].tovec(), }); writer.push(Message::MetaEvent { deltatime: 0, event: MetaEvent::EndOfTrack, data: Vec::new(), }); writer.push(Message::TrackChange); writer.push(Message::MidiEvent { deltatime: 0, event: MidiEvent::NoteOn { ch: 0, note: 0x3c, velocity: 0x7f }, }); writer.push(Message::MidiEvent { deltatime: 192, event: MidiEvent::NoteOn { ch: 0, note: 0x40, velocity: 0 }, }); writer.push(Message::MetaEvent { delta_time: 0, event: MetaEvent::EndOfTrack, data: Vec::new(), }); writer.write("test.mid"); ```
You can use three type events. In Message enum, these events have delta time and data.
ghakuf
is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.
See LICENSE-APACHE, and LICENSE-MIT for details.