mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
extract transport
This commit is contained in:
parent
449615eea8
commit
5a9ec0a63d
12 changed files with 178 additions and 182 deletions
|
|
@ -1,52 +1,33 @@
|
|||
use crate::{core::*,view::*,model::{App, AppSection}};
|
||||
pub struct TransportView {
|
||||
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),
|
||||
quant: app.quant,
|
||||
ppq: app.timebase.ppq() as usize,
|
||||
bpm: app.timebase.bpm() as usize,
|
||||
pulse: app.timebase.frame_to_pulse(app.playhead as f64) as usize,
|
||||
usecs: app.timebase.frame_to_usec(app.playhead as f64) as usize,
|
||||
}
|
||||
}
|
||||
}
|
||||
render!(TransportView |self, buf, area| {
|
||||
let mut area = area;
|
||||
area.height = 2;
|
||||
let Self { ppq, bpm, quant, pulse, usecs, .. } = self;
|
||||
|
||||
fill_bg(buf, area, Nord::bg_lo(self.focused, self.entered));
|
||||
use crate::{core::*,view::*,model::*};
|
||||
|
||||
render!(TransportToolbar |self, buf, area| {
|
||||
let gray = Style::default().gray();
|
||||
let not_dim = Style::default().not_dim();
|
||||
let not_dim_bold = not_dim.bold();
|
||||
|
||||
let mut area = area;
|
||||
area.height = 2;
|
||||
let ppq = self.ppq();
|
||||
let bpm = self.bpm();
|
||||
let pulse = self.pulse();
|
||||
let usecs = self.usecs();
|
||||
let Self { quant, focused, entered, .. } = self;
|
||||
fill_bg(buf, area, Nord::bg_lo(*focused, *entered));
|
||||
let area = Split::right([
|
||||
|
||||
// Play/Pause button
|
||||
&|buf: &mut Buffer, Rect { x, y, .. }: Rect|{
|
||||
let style = Some(match &self.playing {
|
||||
TransportState::Stopped => gray.dim().bold(),
|
||||
TransportState::Starting => gray.not_dim().bold(),
|
||||
TransportState::Rolling => gray.not_dim().white().bold()
|
||||
let style = Some(match self.playing {
|
||||
Some(TransportState::Stopped) => gray.dim().bold(),
|
||||
Some(TransportState::Starting) => gray.not_dim().bold(),
|
||||
Some(TransportState::Rolling) => gray.not_dim().white().bold(),
|
||||
_ => unreachable!(),
|
||||
});
|
||||
let label = match &self.playing {
|
||||
TransportState::Rolling => "▶ PLAYING",
|
||||
TransportState::Starting => "READY ...",
|
||||
TransportState::Stopped => "⏹ STOPPED",
|
||||
let label = match self.playing {
|
||||
Some(TransportState::Rolling) => "▶ PLAYING",
|
||||
Some(TransportState::Starting) => "READY ...",
|
||||
Some(TransportState::Stopped) => "⏹ STOPPED",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let mut result = label.blit(buf, x + 1, y, style)?;
|
||||
result.width = result.width + 1;
|
||||
|
|
@ -86,7 +67,7 @@ render!(TransportView |self, buf, area| {
|
|||
|
||||
]).render(buf, area)?;
|
||||
|
||||
Ok(if self.focused && self.entered {
|
||||
Ok(if *focused && *entered {
|
||||
Corners(Style::default().green().not_dim()).draw(buf, area)?
|
||||
} else {
|
||||
area
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue