break up into crates again
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-09-09 19:28:22 +03:00
parent 2c3bfe4ebb
commit ef81b085a0
106 changed files with 6866 additions and 7106 deletions

35
engine/midi.rs Normal file
View file

@ -0,0 +1,35 @@
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; },
_ => {}
}
}