tek/src/sampler/sample_list.rs

44 lines
1.3 KiB
Rust

use crate::*;
pub struct SampleList<'a> {
compact: bool,
sampler: &'a Sampler,
editor: &'a MidiEditor
}
impl<'a> SampleList<'a> {
pub fn new (compact: bool, sampler: &'a Sampler, editor: &'a MidiEditor) -> Self {
Self { compact, sampler, editor }
}
}
render!(Tui: (self: SampleList<'a>) => {
let Self { compact, sampler, editor } = self;
let note_lo = editor.note_lo().load(Relaxed);
let note_pt = editor.note_point();
let note_hi = editor.note_hi();
Fill::xy(Tui::map(move||(note_lo..=note_hi).rev(), move|note, i| {
let offset = |a|Push::y(i as u16, Align::n(Fixed::y(1, Fill::x(a))));
let mut bg = if note == note_pt { TuiTheme::g(64) } else { Color::Reset };
let mut fg = TuiTheme::g(160);
if let Some((index, _)) = sampler.recording {
if note == index {
bg = Color::Rgb(64,16,0);
fg = Color::Rgb(224,64,32)
}
} else if sampler.mapped[note].is_some() {
fg = TuiTheme::g(224);
}
offset(Tui::fg_bg(fg, bg, format!("{note:3} {}", if *compact {
""
} else if let Some(sample) = &sampler.mapped[note] {
"??????"
} else {
"(none)"
})))
}))
});