mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
use crate::*;
|
|
|
|
pub use ::midly::{
|
|
Smf,
|
|
TrackEventKind,
|
|
MidiMessage,
|
|
Error as MidiError,
|
|
num::*,
|
|
live::*,
|
|
};
|
|
|
|
/// Return boxed iterator of MIDI events
|
|
pub fn parse_midi_input <'a> (input: ::jack::MidiIter<'a>) -> Box<dyn Iterator<Item=(usize, LiveEvent<'a>, &'a [u8])> + 'a> {
|
|
Box::new(input.map(|::jack::RawMidi { time, bytes }|(
|
|
time as usize,
|
|
LiveEvent::parse(bytes).unwrap(),
|
|
bytes
|
|
)))
|
|
}
|
|
|
|
/// Add "all notes off" to the start of a buffer.
|
|
pub fn all_notes_off (output: &mut [Vec<Vec<u8>>]) {
|
|
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);
|
|
}
|
|
|
|
/// Update notes_in array
|
|
pub fn update_keys (keys: &mut[bool;128], message: &MidiMessage) {
|
|
match message {
|
|
MidiMessage::NoteOn { key, .. } => { keys[key.as_int() as usize] = true; }
|
|
MidiMessage::NoteOff { key, .. } => { keys[key.as_int() as usize] = false; },
|
|
_ => {}
|
|
}
|
|
}
|