mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
seconds timer
This commit is contained in:
parent
4055662bbd
commit
91832e0072
2 changed files with 29 additions and 25 deletions
|
|
@ -5,19 +5,19 @@ mod grid;
|
|||
pub use self::grid::*; mod handle;
|
||||
pub use self::handle::*;
|
||||
pub struct Launcher {
|
||||
name: String,
|
||||
timebase: Arc<Timebase>,
|
||||
transport: ::jack::Transport,
|
||||
playing: TransportState,
|
||||
monitoring: bool,
|
||||
recording: bool,
|
||||
overdub: bool,
|
||||
position: usize,
|
||||
cursor: (usize, usize),
|
||||
pub tracks: Vec<Track>,
|
||||
scenes: Vec<Scene>,
|
||||
show_help: bool,
|
||||
view: LauncherView,
|
||||
name: String,
|
||||
timebase: Arc<Timebase>,
|
||||
transport: ::jack::Transport,
|
||||
playing: TransportState,
|
||||
monitoring: bool,
|
||||
recording: bool,
|
||||
overdub: bool,
|
||||
current_frame: usize,
|
||||
cursor: (usize, usize),
|
||||
pub tracks: Vec<Track>,
|
||||
scenes: Vec<Scene>,
|
||||
show_help: bool,
|
||||
view: LauncherView,
|
||||
}
|
||||
pub enum LauncherView { Tracks, Sequencer, Chains, Modal(Box<dyn Device>) }
|
||||
impl LauncherView {
|
||||
|
|
@ -57,7 +57,7 @@ impl Launcher {
|
|||
recording: false,
|
||||
overdub: true,
|
||||
cursor: (2, 2),
|
||||
position: 0,
|
||||
current_frame: 0,
|
||||
scenes: scenes.unwrap_or_else(||vec![Scene::new(&"Scene 1", &[None])]),
|
||||
tracks: if let Some(tracks) = tracks { tracks } else { vec![
|
||||
Track::new("Track 1", &timebase, None, Some(vec![
|
||||
|
|
@ -172,9 +172,9 @@ impl DynamicDevice<Launcher> {
|
|||
}
|
||||
impl PortList for Launcher {}
|
||||
pub fn process (state: &mut Launcher, _: &Client, _: &ProcessScope) -> Control {
|
||||
let transport = state.transport.query().unwrap();
|
||||
state.playing = transport.state;
|
||||
state.position = transport.pos.frame() as usize;
|
||||
let transport = state.transport.query().unwrap();
|
||||
state.playing = transport.state;
|
||||
state.current_frame = transport.pos.frame() as usize;
|
||||
Control::Continue
|
||||
}
|
||||
pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
|
||||
|
|
@ -188,14 +188,14 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
|
|||
draw_mon(buf, x + 19, y, state.monitoring);
|
||||
draw_dub(buf, x + 26, y, state.overdub);
|
||||
draw_bpm(buf, x + 33, y, state.timebase.bpm() as usize);
|
||||
draw_timer(buf, x + width - 1, y, &state.timebase, state.position);
|
||||
draw_timer(buf, x + width - 1, y, &state.timebase, state.current_frame);
|
||||
}
|
||||
let mut y = y + 1;
|
||||
y = y + LauncherGrid::new(
|
||||
state, buf, Rect { x, y, width, height: height / 3 }, state.view.is_tracks()
|
||||
state, buf, Rect { x, y, width, height: height/3 }, state.view.is_tracks()
|
||||
).draw()?.height;
|
||||
y = y + draw_section_sequencer(state, buf, Rect { x, y, width, height: height / 3 })?.height;
|
||||
y = y + draw_section_chains(state, buf, Rect { x, y, width, height: height /3 })?.height;
|
||||
y = y + draw_section_chains(state, buf, Rect { x, y, width, height: height/3 })?.height;
|
||||
y = y + draw_section_sequencer(state, buf, Rect { x, y, width, height: height - y })?.height;
|
||||
area.height = y;
|
||||
if state.show_help {
|
||||
let style = Some(Style::default().bold().white().not_dim().on_black().italic());
|
||||
|
|
|
|||
|
|
@ -2,10 +2,14 @@ use crate::core::*;
|
|||
use crate::layout::*;
|
||||
|
||||
pub fn draw_timer (buf: &mut Buffer, x: u16, y: u16, timebase: &Arc<Timebase>, frame: usize) {
|
||||
let tick = (frame as f64 / timebase.frames_per_tick());
|
||||
let (beats, ticks) = (tick / timebase.ppq(), tick % timebase.ppq());
|
||||
let (bars, beats) = (beats / 4.0, beats % 4.0);
|
||||
let timer = format!("{}.{}.{ticks:02}", bars as usize + 1, beats as usize + 1);
|
||||
let ppq = timebase.ppq() as usize;
|
||||
let pulse = timebase.frames_pulses(frame as f64) as usize;
|
||||
let (beats, pulses) = (pulse / ppq, pulse % ppq);
|
||||
let (bars, beats) = (beats / 4, beats % 4);
|
||||
let usecs = timebase.frames_usecs(frame as f64) as usize;
|
||||
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
|
||||
let (minutes, seconds) = (seconds / 60, seconds % 60);
|
||||
let timer = format!("{minutes}:{seconds:02}:{msecs:03} {}.{}.{pulses:02}", bars as usize + 1, beats as usize + 1);
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue