remove Samplerviewer, SamplerStatus

This commit is contained in:
🪞👃🪞 2025-01-11 19:13:59 +01:00
parent 532b648a9e
commit a9cad18891
2 changed files with 59 additions and 61 deletions

View file

@ -124,24 +124,21 @@ render!(TuiOut: (self: SampleList<'a>) => {
}))
});
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> {
if let Some((_, sample)) = &self.recording {
SampleViewer(Some(sample.clone()))
let sample = if let Some((_, sample)) = &self.recording {
Some(sample.clone())
} else if let Some(sample) = &self.mapped[note_pt] {
SampleViewer(Some(sample.clone()))
Some(sample.clone())
} else {
SampleViewer(None)
}
}
}
const EMPTY: &[(f64, f64)] = &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)];
pub struct SampleViewer(pub Option<Arc<RwLock<Sample>>>);
render!(TuiOut: |self: SampleViewer, to|{
None
};
let min_db = -40.0;
RenderThunk::new(move|to: &mut TuiOut|{
let [x, y, width, height] = to.area();
let area = Rect { x, y, width, height };
let min_db = -40.0;
let (x_bounds, y_bounds, lines): ([f64;2], [f64;2], Vec<Line>) =
if let Some(sample) = &self.0 {
if let Some(sample) = &sample {
let sample = sample.read().unwrap();
let start = sample.start as f64;
let end = sample.end as f64;
@ -180,12 +177,13 @@ render!(TuiOut: |self: SampleViewer, to|{
.y_bounds(y_bounds)
.paint(|ctx| { for line in lines.iter() { ctx.draw(line) } })
.render(area, &mut to.buffer);
});
pub struct SamplerStatus<'a>(pub &'a Sampler, pub usize);
render!(TuiOut: (self: SamplerStatus<'a>) => Tui::bold(true, Tui::fg(TuiTheme::g(224), self.0.mapped[self.1].as_ref().map(|sample|format!(
})
}
pub fn status (&self, index: usize) -> impl Content<TuiOut> {
Tui::bold(true, Tui::fg(TuiTheme::g(224), self.mapped[index].as_ref().map(|sample|format!(
"Sample {}-{}",
sample.read().unwrap().start,
sample.read().unwrap().end,
)).unwrap_or_else(||"No sample".to_string()))));
)).unwrap_or_else(||"No sample".to_string())))
}
}

View file

@ -80,7 +80,7 @@ impl Groovebox {
let sample_h = if self.compact { 0 } else { 5 };
Max::y(sample_h, Fill::xy(
Bsp::a(
Fill::x(Align::w(Fixed::y(1, SamplerStatus(&self.sampler, note_pt)))),
Fill::x(Align::w(Fixed::y(1, self.sampler.status(note_pt)))),
self.sampler.viewer(note_pt))))
}
fn pool_view (&self) -> impl Content<TuiOut> + use<'_> {