tek/src/sampler/sample_list.rs

45 lines
1.5 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!(TuiOut: (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();
Outer(Style::default().fg(TuiTheme::g(96))).enclose(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 sampler.mapped[note].is_some() {
fg = TuiTheme::g(224);
bg = Color::Rgb(0, if note == note_pt { 96 } else { 64 }, 0);
}
if let Some((index, _)) = sampler.recording {
if note == index {
bg = if note == note_pt { Color::Rgb(96,24,0) } else { Color::Rgb(64,16,0) };
fg = Color::Rgb(224,64,32)
}
}
offset(Tui::fg_bg(fg, bg, format!("{note:3} {}", if *compact {
String::default()
} else if let Some(sample) = &sampler.mapped[note] {
sample.read().unwrap().name.clone()
} else {
String::from("(none)")
})))
}))
});