wip: unify apps

This commit is contained in:
🪞👃🪞 2025-01-11 20:16:46 +01:00
parent a9cad18891
commit cff87657b9
12 changed files with 291 additions and 247 deletions

View file

@ -77,38 +77,33 @@ impl NotePoint for SamplerTui {
fn note_point (&self) -> usize { self.note_pt.load(Relaxed) }
fn set_note_point (&self, x: usize) { self.note_pt.store(x, Relaxed); }
}
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::new(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)
impl Sampler {
const EMPTY: &[(f64, f64)] = &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)];
pub fn list <'a> (&'a self, compact: bool, editor: &MidiEditor) -> impl Content<TuiOut> + 'a {
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::new(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 self.mapped[note].is_some() {
fg = TuiTheme::g(224);
bg = Color::Rgb(0, if note == note_pt { 96 } else { 64 }, 0);
}
}
let label = if *compact {
if let Some((index, _)) = self.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} {}", self.list_item(note, compact))))
}))
}
pub fn list_item (&self, note: usize, compact: bool) -> String {
if compact {
String::default()
} else if let Some(sample) = &sampler.mapped[note] {
} else if let Some(sample) = &self.mapped[note] {
let sample = sample.read().unwrap();
format!("{:8} {:3} {:6}-{:6}/{:6}",
sample.name,
@ -119,12 +114,8 @@ render!(TuiOut: (self: SampleList<'a>) => {
)
} else {
String::from("(none)")
};
offset(Tui::fg_bg(fg, bg, format!("{note:3} {}", label)))
}))
});
impl Sampler {
const EMPTY: &[(f64, f64)] = &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)];
}
}
pub fn viewer (&self, note_pt: usize) -> impl Content<TuiOut> {
let sample = if let Some((_, sample)) = &self.recording {
Some(sample.clone())