wip: remodularize 2

This commit is contained in:
🪞👃🪞 2025-01-08 19:19:35 +01:00
parent 3b6ff81dad
commit d38dc14e84
27 changed files with 564 additions and 563 deletions

View file

@ -1,6 +1,3 @@
pub(crate) use ::tek_tui::{*, tek_input::*, tek_output::*, crossterm::event::KeyCode};
pub(crate) use ::tek_jack::*;
mod midi_pool; pub(crate) use midi_pool::*;
mod midi_clip; pub(crate) use midi_clip::*;
mod midi_launch; pub(crate) use midi_launch::*;
@ -8,11 +5,34 @@ mod midi_player; pub(crate) use midi_player::*;
mod midi_in; pub(crate) use midi_in::*;
mod midi_out; pub(crate) use midi_out::*;
mod midi_note; pub(crate) use midi_note::*;
mod midi_pitch; pub(crate) use midi_pitch::*;
mod midi_range; pub(crate) use midi_range::*;
mod midi_point; pub(crate) use midi_point::*;
mod midi_view; pub(crate) use midi_view::*;
mod midi_editor; pub(crate) use midi_editor::*;
mod midi_select; pub(crate) use midi_select::*;
mod piano_h; pub(crate) use self::piano_h::*;
mod piano_h_cursor; pub(crate) use self::piano_h_cursor::*;
mod piano_h_keys; pub(crate) use self::piano_h_keys::*;
mod piano_h_notes; pub(crate) use self::piano_h_notes::*;
mod piano_h_time; pub(crate) use self::piano_h_time::*;
pub(crate) use ::tek_time::*;
pub(crate) use ::tek_jack::{*, jack::*};
pub(crate) use ::tek_tui::{
*,
tek_input::*,
tek_output::*,
crossterm::event::KeyCode,
ratatui::style::{Style, Stylize, Color}
};
pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicUsize, AtomicBool, Ordering::Relaxed}};
pub(crate) use std::path::PathBuf;
pub(crate) use std::fmt::Debug;
pub use ::midly; pub(crate) use ::midly::{*, num::*, live::*};
/// Add "all notes off" to the start of a buffer.
pub fn all_notes_off (output: &mut [Vec<Vec<u8>>]) {
@ -24,7 +44,7 @@ pub fn all_notes_off (output: &mut [Vec<Vec<u8>>]) {
}
/// Return boxed iterator of MIDI events
pub fn parse_midi_input (input: MidiIter) -> Box<dyn Iterator<Item=(usize, LiveEvent, &[u8])> + '_> {
pub fn parse_midi_input <'a> (input: MidiIter<'a>) -> Box<dyn Iterator<Item=(usize, LiveEvent<'a>, &'a [u8])> + 'a> {
Box::new(input.map(|RawMidi { time, bytes }|(
time as usize,
LiveEvent::parse(bytes).unwrap(),
@ -41,3 +61,41 @@ pub fn update_keys (keys: &mut[bool;128], message: &MidiMessage) {
}
}
/// A phrase, rendered as a horizontal piano roll.
pub struct PianoHorizontal {
phrase: Option<Arc<RwLock<MidiClip>>>,
/// Buffer where the whole phrase is rerendered on change
buffer: Arc<RwLock<BigBuffer>>,
/// Size of actual notes area
size: Measure<TuiOut>,
/// The display window
range: MidiRangeModel,
/// The note cursor
point: MidiPointModel,
/// The highlight color palette
color: ItemPalette,
/// Width of the keyboard
keys_width: u16,
}
impl PianoHorizontal {
pub fn new (phrase: Option<&Arc<RwLock<MidiClip>>>) -> Self {
let size = Measure::new();
let mut range = MidiRangeModel::from((24, true));
range.time_axis = size.x.clone();
range.note_axis = size.y.clone();
let mut piano = Self {
keys_width: 5,
size,
range,
buffer: RwLock::new(Default::default()).into(),
point: MidiPointModel::default(),
phrase: phrase.cloned(),
color: phrase.as_ref()
.map(|p|p.read().unwrap().color)
.unwrap_or(ItemPalette::from(ItemColor::from(TuiTheme::g(64)))),
};
piano.redraw();
piano
}
}