refactor transport into render-only struct

This commit is contained in:
🪞👃🪞 2024-07-02 21:30:08 +03:00
parent a7344f8a72
commit cc2b59d772
4 changed files with 51 additions and 22 deletions

View file

@ -1,6 +1,28 @@
use crate::core::*;
use crate::layout::*;
pub struct Transport<'a> {
pub timebase: &'a Arc<Timebase>,
pub playing: TransportState,
pub record: bool,
pub overdub: bool,
pub monitor: bool,
pub frame: usize,
}
impl<'a> Render for Transport<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Rect { x, y, width, .. } = area;
draw_play_stop(buf, x + 1, y, &self.playing);
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);
draw_timer(buf, x + width - 1, y, &self.timebase, self.frame);
Ok(Rect { x, y, width, height: 1 })
}
}
pub fn draw_timer (buf: &mut Buffer, x: u16, y: u16, timebase: &Arc<Timebase>, frame: usize) {
let ppq = timebase.ppq() as usize;