mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
use crate::*;
|
|
|
|
/// MIDI message serialized to bytes
|
|
pub type MIDIMessage = Vec<u8>;
|
|
|
|
/// Collection of serialized MIDI messages
|
|
pub type MIDIChunk = [Vec<MIDIMessage>];
|
|
|
|
/// Add "all notes off" to the start of a buffer.
|
|
pub fn all_notes_off (output: &mut MIDIChunk) {
|
|
let mut buf = vec![];
|
|
let msg = MidiMessage::Controller { controller: 123.into(), value: 0.into() };
|
|
let evt = LiveEvent::Midi { channel: 0.into(), message: msg };
|
|
evt.write(&mut buf).unwrap();
|
|
output[0].push(buf);
|
|
}
|
|
|
|
/// Return boxed iterator of MIDI events
|
|
pub fn parse_midi_input (input: MidiIter) -> Box<dyn Iterator<Item=(usize, LiveEvent, &[u8])> + '_> {
|
|
Box::new(input.map(|RawMidi { time, bytes }|(
|
|
time as usize,
|
|
LiveEvent::parse(bytes).unwrap(),
|
|
bytes
|
|
)))
|
|
}
|
|
|
|
/// Write to JACK port from output buffer (containing notes from sequence and/or monitor)
|
|
pub fn write_midi_output (writer: &mut MidiWriter, output: &MIDIChunk, frames: usize) {
|
|
for time in 0..frames {
|
|
for event in output[time].iter() {
|
|
writer.write(&RawMidi { time: time as u32, bytes: &event })
|
|
.expect(&format!("{event:?}"));
|
|
}
|
|
}
|
|
}
|