update all to use TuiOutput; still slow?

This commit is contained in:
🪞👃🪞 2024-09-15 17:26:54 +03:00
parent bb7d215ba1
commit f5fbc11b24
21 changed files with 873 additions and 888 deletions

View file

@ -321,13 +321,13 @@ impl Widget for TransportBPM<Tui> {
area.expect_min(10, 1)?;
Ok(Some([10, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
let area = to.area();
let [x, y, ..] = area;
let Self { value, focused, .. } = self;
to.blit(&"BPM", x, y, Some(NOT_DIM))?;
to.blit(&"BPM", x, y, Some(NOT_DIM));
let bpm = format!("{}.{:03}", value, (value * 1000.0) % 1000.0);
to.blit(&bpm, x, y + 1, Some(NOT_DIM_BOLD))?;
to.blit(&bpm, x, y + 1, Some(NOT_DIM_BOLD));
let width = bpm.len() as u16;
let area = [x, y, (width + 2).max(10), 2];
if *focused {
@ -335,7 +335,8 @@ impl Widget for TransportBPM<Tui> {
CORNERS.draw(to)?;
to.fill_bg(area, COLOR_BG1);
}
Ok(Some(area))
//Ok(Some(area))
Ok(())
}
}
@ -375,20 +376,21 @@ impl Widget for TransportQuantize<Tui> {
area.expect_min(10, 1)?;
Ok(Some([10, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
let [x, y, ..] = to.area();
let Self { value, focused, .. } = self;
to.blit(&"QUANT", x, y, Some(NOT_DIM))?;
to.blit(&"QUANT", x, y, Some(NOT_DIM));
let name = ppq_to_name(*value as usize);
let width = name.len() as u16;
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD))?;
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD));
let area = [x, y, (width + 2).max(10), 2];
if *focused {
let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ];
CORNERS.draw(to)?;
to.fill_bg(area, COLOR_BG1);
}
Ok(Some(area))
//Ok(Some(area))
Ok(())
}
}
@ -428,20 +430,21 @@ impl Widget for TransportSync<Tui> {
area.expect_min(10, 1)?;
Ok(Some([10, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
let [x, y, ..] = to.area();
let Self { value, focused, .. } = self;
to.blit(&"SYNC", x, y, Some(NOT_DIM))?;
to.blit(&"SYNC", x, y, Some(NOT_DIM));
let name = ppq_to_name(*value as usize);
let width = name.len() as u16;
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD))?;
to.blit(&name, x, y + 1, Some(NOT_DIM_BOLD));
let area = [x, y, (width + 2).max(10), 2];
if *focused {
let area = [area.x() - 1, area.y(), area.w() - 1, area.h() ];
CORNERS.draw(to)?;
to.fill_bg(area, COLOR_BG1);
}
Ok(Some(area))
//Ok(Some(area))
Ok(())
}
}
@ -474,7 +477,7 @@ impl Widget for TransportClock<Tui> {
area.expect_min(20, 1)?;
Ok(Some([20, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
let [x, y, width, _] = to.area();
let Self { frame: _frame, pulse, ppq, usecs, focused, .. } = self;
let (beats, pulses) = if *ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
@ -482,9 +485,9 @@ impl Widget for TransportClock<Tui> {
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
let (minutes, seconds) = (seconds / 60, seconds % 60);
let timer = format!("{bars}.{beats}.{pulses:02}");
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM))?;
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM));
let timer = format!("{minutes}:{seconds:02}:{msecs:03}");
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM))?;
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM));
let area = to.area();
let area = [area.x(), area.y(), area.w() + 1, area.h()];
if *focused {
@ -492,7 +495,8 @@ impl Widget for TransportClock<Tui> {
CORNERS.draw(to)?;
to.fill_bg(area, COLOR_BG1);
}
Ok(Some(area))
//Ok(Some(area))
Ok(())
}
}