watch it do: display sample waveform during recording

This commit is contained in:
🪞👃🪞 2024-12-28 19:23:19 +01:00
parent 080c4131b7
commit 1859f378ea
2 changed files with 8 additions and 10 deletions

View file

@ -77,7 +77,7 @@ render!(<Tui>|self:GrooveboxTui|{
PhraseSelector::next_phrase(&self.player), PhraseSelector::next_phrase(&self.player),
]))), ]))),
row!([ row!([
Tui::split_n(false, 5, Tui::split_n(false, 9,
col!([ col!([
row!(|add|{ row!(|add|{
if let Some(sample) = &self.sampler.mapped[note_pt] { if let Some(sample) = &self.sampler.mapped[note_pt] {
@ -88,7 +88,7 @@ render!(<Tui>|self:GrooveboxTui|{
}), }),
lay!([ lay!([
Outer(Style::default().fg(TuiTheme::g(128))), Outer(Style::default().fg(TuiTheme::g(128))),
Fill::w(Fixed::h(4, if let Some((_, sample)) = &self.sampler.recording { Fill::w(Fixed::h(8, if let Some((_, sample)) = &self.sampler.recording {
SampleViewer(Some(sample.clone())) SampleViewer(Some(sample.clone()))
} else if let Some(sample) = &self.sampler.mapped[note_pt] { } else if let Some(sample) = &self.sampler.mapped[note_pt] {
SampleViewer(Some(sample.clone())) SampleViewer(Some(sample.clone()))

View file

@ -18,18 +18,16 @@ render!(<Tui>|self: SampleViewer|render(|to|{
let step = length / width as f64; let step = length / width as f64;
let mut t = start; let mut t = start;
while t < end { while t < end {
points.push((t as f64, 0.)); let chunk = &sample.channels[0][t as usize..((t + step) as usize).min(sample.end)];
points.push((t as f64, 1.)); let total: f32 = chunk.iter().map(|x|x.abs()).sum();
points.push((t as f64, 0.5)); let count = chunk.len() as f32;
points.push((t as f64, 0.25)); let meter = 10. * (total / count).log10();
points.push((t as f64, 0.125)); points.push((t as f64, meter as f64));
points.push((t as f64, 0.0625));
points.push((t as f64, 0.03125));
t += step; t += step;
} }
( (
[sample.start as f64, sample.end as f64], [sample.start as f64, sample.end as f64],
[0., 1.], [-40., 0.],
points.as_slice() points.as_slice()
) )
} else { } else {