unify arranger, sequencer, transport

This commit is contained in:
🪞👃🪞 2024-09-12 15:30:38 +03:00
parent cd2555ffc7
commit 77519dbb5c
18 changed files with 1618 additions and 1639 deletions

View file

@ -260,3 +260,205 @@ impl Focusable<Tui> for TransportClock<Tui> {
self.focused = focused
}
}
impl Handle<Tui> for TransportToolbar<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
Ok(None)
//Ok(
//from.key(KeyCode::Right).does(||self.focus_next())?
//||
//from.key(KeyCode::Left).does(||self.focus_prev())?
//||
//from.key(KeyCode::Char(' ')).does(||self.toggle_play())?
//)
}
}
impl Handle<Tui> for TransportPlayPauseButton<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
Ok(None)
}
}
impl Handle<Tui> for TransportBPM<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
//TransportFocus::BPM => {
//transport.timebase.bpm.fetch_add(1.0, Ordering::Relaxed);
//},
//TransportFocus::BPM => {
//transport.timebase.bpm.fetch_sub(1.0, Ordering::Relaxed);
//},
Ok(None)
}
}
impl Handle<Tui> for TransportQuantize<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
//TransportFocus::Quant => {
//transport.quant.value = next_note_length(transport.quant)
//},
//TransportFocus::Quant => {
//transport.quant.value = prev_note_length(transport.quant);
//},
Ok(None)
}
}
impl Handle<Tui> for TransportSync<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
//TransportFocus::Sync => {
//transport.sync.value = next_note_length(transport.sync)
//},
//TransportFocus::Sync => {
//transport.sync.value = prev_note_length(transport.sync);
//},
Ok(None)
}
}
impl Handle<Tui> for TransportClock<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
//TransportFocus::Sync => {
//transport.sync.value = next_note_length(transport.sync)
//},
//TransportFocus::Sync => {
//transport.sync.value = prev_note_length(transport.sync);
//},
Ok(None)
}
}
const CORNERS: Corners = Corners(NOT_DIM_GREEN);
impl Content for TransportToolbar<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
Split::right(|add|{
add(&self.playing)?;
add(&self.bpm)?;
add(&self.quant)?;
add(&self.sync)?;
add(&self.clock)?;
Ok(())
})
}
}
impl Content for TransportPlayPauseButton<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
Layers::new(|add|{
//add(&self.focused.then_some(CORNERS))?;
add(&Styled(match self.value {
Some(TransportState::Stopped) => Some(GRAY_DIM.bold()),
Some(TransportState::Starting) => Some(GRAY_NOT_DIM_BOLD),
Some(TransportState::Rolling) => Some(WHITE_NOT_DIM_BOLD),
_ => unreachable!(),
}, match self.value {
Some(TransportState::Rolling) => "▶ PLAYING",
Some(TransportState::Starting) => "READY ...",
Some(TransportState::Stopped) => "⏹ STOPPED",
_ => unreachable!(),
}))?;
Ok(())
})
}
}
impl Widget for TransportBPM<Tui> {
type Engine = Tui;
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
area.expect_min(10, 1)?;
Ok(Some([area.x(), area.y(), 10, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
let area = to.area();
let [x, y, ..] = area;
let Self { value, focused, .. } = self;
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))?;
let width = bpm.len() as u16;
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))
}
}
impl Widget for TransportQuantize<Tui> {
type Engine = Tui;
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
area.expect_min(10, 1)?;
Ok(Some([area.x(), area.y(), 10, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
let [x, y, ..] = to.area();
let Self { value, focused, .. } = self;
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))?;
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))
}
}
impl Widget for TransportSync<Tui> {
type Engine = Tui;
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
area.expect_min(10, 1)?;
Ok(Some([area.x(), area.y(), 10, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
let [x, y, ..] = to.area();
let Self { value, focused, .. } = self;
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))?;
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))
}
}
impl Widget for TransportClock<Tui> {
type Engine = Tui;
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
area.expect_min(10, 1)?;
Ok(Some([area.x(), area.y(), 20, 1]))
}
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
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) };
let (bars, beats) = ((beats / 4) + 1, (beats % 4) + 1);
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))?;
let timer = format!("{minutes}:{seconds:02}:{msecs:03}");
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 {
let area = [area.x() - 1, area.y(), area.w(), area.h() ];
CORNERS.draw(to)?;
to.fill_bg(area, COLOR_BG1);
}
Ok(Some(area))
}
}