make transport focusable

This commit is contained in:
🪞👃🪞 2024-07-12 13:23:32 +03:00
parent a7a798b484
commit 449615eea8
14 changed files with 220 additions and 237 deletions

View file

@ -1,22 +1,20 @@
use crate::{core::*, view::Split, model::App};
use crate::{core::*,view::*,model::{App, AppSection}};
pub struct TransportView {
pub playing: TransportState,
pub record: bool,
pub overdub: bool,
pub monitor: bool,
pub quant: usize,
pub ppq: usize,
pub bpm: usize,
pub pulse: usize,
pub usecs: usize,
focused: bool,
entered: bool,
playing: TransportState,
quant: usize,
ppq: usize,
bpm: usize,
pulse: usize,
usecs: usize,
}
impl TransportView {
pub fn new (app: &App) -> Self {
Self {
focused: app.section == AppSection::Transport,
entered: app.entered,
playing: *app.playing.as_ref().unwrap_or(&TransportState::Stopped),
monitor: app.track().map(|t|t.1.monitoring).unwrap_or(false),
record: app.track().map(|t|t.1.recording).unwrap_or(false),
overdub: app.track().map(|t|t.1.overdub).unwrap_or(false),
quant: app.quant,
ppq: app.timebase.ppq() as usize,
bpm: app.timebase.bpm() as usize,
@ -27,66 +25,53 @@ impl TransportView {
}
render!(TransportView |self, buf, area| {
let mut area = area;
area.height = if area.width > 100 { 1 } else { 2 };
area.height = 2;
let Self { ppq, bpm, quant, pulse, usecs, .. } = self;
fill_bg(buf, area, Color::Rgb(20, 45, 5));
let dim = Style::default().dim();
let not_dim = Style::default().not_dim();
let red = not_dim.red();
let green = not_dim.green();
let yellow = not_dim.yellow();
Split::right([
fill_bg(buf, area, Nord::bg_lo(self.focused, self.entered));
let gray = Style::default().gray();
let not_dim = Style::default().not_dim();
let not_dim_bold = not_dim.bold();
let area = Split::right([
// Play/Pause button
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
let style = Style::default().gray();
let style = Some(match &self.playing {
TransportState::Stopped => style.dim().bold(),
TransportState::Starting => style.not_dim().bold(),
TransportState::Rolling => style.not_dim().white().bold()
TransportState::Stopped => gray.dim().bold(),
TransportState::Starting => gray.not_dim().bold(),
TransportState::Rolling => gray.not_dim().white().bold()
});
let label = match &self.playing {
TransportState::Rolling => "▶ PLAYING",
TransportState::Starting => "READY ...",
TransportState::Stopped => "⏹ STOPPED",
};
label.blit(buf, x, y, style)
},
// Record button/indicator
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
"⏺ REC".blit(buf, x, y, Some(if self.record { red } else { dim }))
},
// Overdub button/indicator
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
"⏺ DUB".blit(buf, x, y, Some(if self.overdub { yellow } else { dim }))
},
// Monitor button/indicator
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
"⏺ MON".blit(buf, x, y, Some(if self.monitor { green } else { dim }))
let mut result = label.blit(buf, x + 1, y, style)?;
result.width = result.width + 1;
Ok(result)
},
// Beats per minute
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
"BPM".blit(buf, x, y, Some(not_dim))?;
format!("{}.{:03}", bpm, bpm % 1).blit(buf, x + 4, y, Some(not_dim.bold()))?;
Ok(Rect { x, y, width: 13, height: 1 })
let width = format!("{}.{:03}", bpm, bpm % 1).blit(buf, x, y + 1, Some(not_dim_bold))?.width;
Ok(Rect { x, y, width: (width + 2).max(10), height: 2 })
},
// Quantization
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
"QUANT".blit(buf, x, y, Some(not_dim))?;
ppq_to_name(*quant).blit(buf, x + 6, y, Some(not_dim.bold()))?;
Ok(Rect { x, y, width: 12, height: 1 })
let width = ppq_to_name(*quant).blit(buf, x, y + 1, Some(not_dim_bold))?.width;
Ok(Rect { x, y, width: (width + 2).max(10), height: 2 })
},
// Clip launch sync
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
"SYNC".blit(buf, x, y, Some(not_dim))?;
"4/4".blit(buf, x + 5, y, Some(not_dim.bold()))?;
Ok(Rect { x, y, width: 12, height: 1 })
let width = "4/4".blit(buf, x, y + 1, Some(not_dim_bold))?.width;
Ok(Rect { x, y, width: (width + 2).max(10), height: 2 })
},
// Clock
@ -96,8 +81,29 @@ render!(TransportView |self, buf, area| {
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 + width - timer.len() as u16 - 1, y, Some(Style::default().not_dim()))
timer.blit(buf, x + width - timer.len() as u16 - 1, y, Some(not_dim))
}
]).render(buf, area)
]).render(buf, area)?;
Ok(if self.focused && self.entered {
Corners(Style::default().green().not_dim()).draw(buf, area)?
} else {
area
})
});
// Record button/indicator
//&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
//"⏺ REC".blit(buf, x, y, Some(if self.record { red } else { dim }))
//},
//// Overdub button/indicator
//&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
//"⏺ DUB".blit(buf, x, y, Some(if self.overdub { yellow } else { dim }))
//},
//// Monitor button/indicator
//&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
//"⏺ MON".blit(buf, x, y, Some(if self.monitor { green } else { dim }))
//},