mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
104 lines
3.8 KiB
Rust
104 lines
3.8 KiB
Rust
use crate::core::*;
|
|
|
|
pub struct TransportView<'a> {
|
|
pub timebase: &'a Arc<Timebase>,
|
|
pub playing: TransportState,
|
|
pub record: bool,
|
|
pub overdub: bool,
|
|
pub monitor: bool,
|
|
pub frame: usize,
|
|
pub quant: usize,
|
|
}
|
|
|
|
impl<'a> Render for TransportView<'a> {
|
|
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
|
fill_bg(buf, area, Color::Rgb(20, 45, 5));
|
|
let Rect { x, y, width, .. } = area;
|
|
draw_play_stop(buf, x + 1, y, &self.playing);
|
|
if width > 100 {
|
|
draw_rec(buf, x + 12, y, self.record);
|
|
draw_dub(buf, x + 19, y, self.overdub);
|
|
draw_mon(buf, x + 26, y, self.monitor);
|
|
draw_bpm(buf, x + 33, y, self.timebase.bpm() as usize, self.quant);
|
|
draw_timer(buf, x + width - 1, y,
|
|
self.timebase.ppq() as usize,
|
|
self.timebase.frame_to_pulse(self.frame as f64) as usize,
|
|
self.timebase.frame_to_usec(self.frame as f64) as usize,
|
|
);
|
|
Ok(Rect { x, y, width, height: 1 })
|
|
} else {
|
|
draw_bpm(buf, x + 12, y, self.timebase.bpm() as usize, self.quant);
|
|
draw_timer(buf, x + width - 1, y,
|
|
self.timebase.ppq() as usize,
|
|
self.timebase.frame_to_pulse(self.frame as f64) as usize,
|
|
self.timebase.frame_to_usec(self.frame as f64) as usize,
|
|
);
|
|
draw_rec(buf, x + 1, y + 1, self.record);
|
|
draw_dub(buf, x + 8, y + 1, self.overdub);
|
|
draw_mon(buf, x + 15, y + 1, self.monitor);
|
|
Ok(Rect { x, y, width, height: 2 })
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn draw_timer (buf: &mut Buffer, x: u16, y: u16, ppq: usize, pulse: usize, usecs: usize) {
|
|
let (beats, pulses) = (pulse / ppq, pulse % ppq);
|
|
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!("{minutes}:{seconds:02}:{msecs:03} {bars}.{beats}.{pulses:02}");
|
|
timer.blit(buf, x - timer.len() as u16, y, Some(Style::default().not_dim()));
|
|
}
|
|
|
|
pub fn draw_play_stop (buf: &mut Buffer, x: u16, y: u16, state: &TransportState) {
|
|
let style = Style::default().gray();
|
|
match state {
|
|
TransportState::Rolling => "▶ PLAYING",
|
|
TransportState::Starting => "READY ...",
|
|
TransportState::Stopped => "⏹ STOPPED",
|
|
}.blit(buf, x, y, Some(match state {
|
|
TransportState::Stopped => style.dim().bold(),
|
|
TransportState::Starting => style.not_dim().bold(),
|
|
TransportState::Rolling => style.not_dim().white().bold()
|
|
}));
|
|
}
|
|
|
|
pub fn draw_rec (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
|
"⏺ REC".blit(buf, x, y, Some(if on {
|
|
Style::default().bold().red()
|
|
} else {
|
|
Style::default().bold().dim()
|
|
}))
|
|
}
|
|
|
|
pub fn draw_dub (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
|
"⏺ DUB".blit(buf, x, y, Some(if on {
|
|
Style::default().bold().yellow()
|
|
} else {
|
|
Style::default().bold().dim()
|
|
}))
|
|
}
|
|
|
|
pub fn draw_mon (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
|
"⏺ MON".blit(buf, x, y, Some(if on {
|
|
Style::default().bold().green()
|
|
} else {
|
|
Style::default().bold().dim()
|
|
}))
|
|
}
|
|
|
|
pub fn draw_bpm (buf: &mut Buffer, x: u16, y: u16, bpm: usize, quant: usize) {
|
|
let style = Style::default().not_dim();
|
|
"BPM"
|
|
.blit(buf, x, y, Some(style));
|
|
format!("{}.{:03}", bpm as usize, bpm % 1)
|
|
.blit(buf, x + 4, y, Some(style.bold()));
|
|
"SYNC"
|
|
.blit(buf, x + 13, y, Some(style));
|
|
"4/4"
|
|
.blit(buf, x + 18, y, Some(style.bold()));
|
|
"QUANT"
|
|
.blit(buf, x + 23, y, Some(style));
|
|
ppq_to_name(quant)
|
|
.blit(buf, x + 29, y, Some(style.bold()));
|
|
}
|