move port and midi to tengri

This commit is contained in:
i do not exist 2026-07-26 21:50:00 +03:00
parent 711e4fe6a9
commit 8144d75abe
26 changed files with 1520 additions and 1977 deletions

View file

@ -1,5 +1,6 @@
use crate::{*, clock::*, device::*};
impl <T: AsRef<Sequencer>+AsMut<Sequencer>> HasSequencer for T {}
/// A MIDI sequence.
@ -229,7 +230,6 @@ pub trait MidiRecord: MidiMonitor + HasClock + HasPlayClip {
pub type MidiData = Vec<Vec<MidiMessage>>;
pub type ClipPool = Vec<Arc<RwLock<MidiClip>>>;
pub type CollectedMidiInput<'a> = Vec<Vec<(u32, Result<LiveEvent<'a>, MidiError>)>>;
pub trait HasClips {
fn clips <'a> (&'a self) -> std::sync::RwLockReadGuard<'a, ClipPool>;
@ -592,35 +592,6 @@ pub(crate) fn note_y_iter (note_lo: usize, note_hi: usize, y0: u16)
(note_lo..=note_hi).rev().enumerate().map(move|(y, n)|(y, y0 + y as u16, n))
}
/// Return boxed iterator of MIDI events
pub fn parse_midi_input <'a> (input: ::tengri::jack::MidiIter<'a>)
-> Box<dyn Iterator<Item=(usize, LiveEvent<'a>, &'a [u8])> + 'a>
{
Box::new(input.map(|::tengri::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; },
_ => {}
}
}
/// Returns the next shorter length
pub fn note_duration_prev (pulses: usize) -> usize {
for (length, _) in NOTE_DURATIONS.iter().rev() { if *length < pulses { return *length } }