extract transport

This commit is contained in:
🪞👃🪞 2024-07-12 14:23:43 +03:00
parent 449615eea8
commit 5a9ec0a63d
12 changed files with 178 additions and 182 deletions

View file

@ -11,8 +11,6 @@ pub struct ArrangerView<'a> {
vertical: bool,
}
const HELP: &'static str = "[C-t] Add track [C-a] Add scene [v] Show/hide track";
impl<'a> ArrangerView<'a> {
pub fn new (app: &'a App, vertical: bool) -> Self {
Self {
@ -39,11 +37,8 @@ impl<'a> Render for ArrangerView<'a> {
} else {
self.draw_horizontal(buf, area)
}?;
if self.focused {
//HELP.blit(buf, area.x + 2, area.y + area.height - 1, Some(Style::default().dim()))?;
if self.entered {
Corners(Style::default().green().not_dim()).draw(buf, area)?;
}
if self.focused && self.entered {
Corners(Style::default().green().not_dim()).draw(buf, area)?;
}
Ok(area)
}
@ -62,7 +57,7 @@ impl<'a> ArrangerView<'a> {
if y + 2 * scene_index as u16 >= height {
break
}
let style = Some(highlight(
let style = Some(Nord::style_hi(
self.focused,
(0 == self.cursor.0) && (scene_index + 1 == self.cursor.1)
).bold());
@ -82,7 +77,7 @@ impl<'a> ArrangerView<'a> {
if x >= width {
break
}
let mut width = 16u16;
let width = 16u16;
track.name.blit(buf, x, y, Some(Style::default().bold()))?;
for (scene_index, scene) in self.scenes.iter().enumerate() {
if y + 2 * scene_index as u16 >= height {
@ -90,11 +85,8 @@ impl<'a> ArrangerView<'a> {
}
let label = if let Some(Some(clip)) = scene.clips.get(track_index) {
if let Some(phrase) = track.phrases.get(*clip) {
format!("{} {}", if track.sequence == Some(*clip) {
""
} else {
""
}, phrase.name)
let icon = match track.sequence { Some(_) => "", None => "" };
format!("{icon} {}", phrase.name)
} else {
format!(" ??? ")
}
@ -102,12 +94,11 @@ impl<'a> ArrangerView<'a> {
format!("┊ ········")
};
let hi = (track_index + 1 == self.cursor.0) && (scene_index + 1 == self.cursor.1);
let style = Some(highlight(self.focused, hi));
let style = Some(Nord::style_hi(self.focused, hi));
let y = 1 + y + 2 * scene_index as u16;
"".blit(buf, x, y, Some(Style::default().dim()))?;
"".blit(buf, x, y + 1, Some(Style::default().dim()))?;
label.blit(buf, x, y, style)?;
//width = width.max(2label.len() as u16 + 3);
}
if track_index + 1 == self.cursor.0 {
let bg = Nord::bg_hi(self.focused, self.entered);
@ -305,9 +296,7 @@ impl<'a> ArrangerView<'a> {
x3 = x3.max(label.len() as u16)
}
}
x2 = x2 + x3;
x2 = x2 + 1;
x2 = x2 + x3 + 1;
}
Ok(Rect { x, y, height, width: x2 })
},
@ -315,18 +304,6 @@ impl<'a> ArrangerView<'a> {
}
}
fn highlight (focused: bool, highlight: bool) -> Style {
if highlight {
if focused {
Style::default().yellow().not_dim()
} else {
Style::default().yellow().dim()
}
} else {
Style::default()
}
}
//use crate::core::*;
//use crate::view::*;
//use crate::model::*;

View file

@ -113,8 +113,8 @@ impl<'a> SequencerView<'a> {
phrase: app.phrase(),
focused: app.section == AppSection::Sequencer,
entered: app.entered,
ppq: app.timebase.ppq() as usize,
now: app.timebase.frame_to_pulse(app.playhead as f64) as usize,
ppq: app.transport.ppq(),
now: app.transport.pulse(),
time_cursor: app.time_cursor,
time_start: app.seq_buf.time_start,
time_zoom: app.seq_buf.time_zoom,

View file

@ -29,6 +29,16 @@ pub trait Theme {
Color::Reset
}
}
fn style_hi (focused: bool, highlight: bool) -> Style {
if highlight && focused {
Style::default().yellow().not_dim()
} else if highlight {
Style::default().yellow().dim()
} else {
Style::default()
}
}
}
pub struct Nord;

View file

@ -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