mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
wip: refactor pt.32: 89 errors, traits
This commit is contained in:
parent
8b5931c321
commit
ce78b95d8a
28 changed files with 946 additions and 822 deletions
|
|
@ -32,48 +32,57 @@ pub type TransportAppCommand = AppViewCommand<TransportCommand>;
|
|||
|
||||
impl InputToCommand<Tui, TransportApp<Tui>> for TransportAppCommand {
|
||||
fn input_to_command (app: &TransportApp<Tui>, input: &TuiInput) -> Option<Self> {
|
||||
use TransportViewFocus as Focus;
|
||||
use FocusCommand as FocusCmd;
|
||||
use TransportCommand as Cmd;
|
||||
use KeyCode::{Left, Right};
|
||||
use FocusCommand::{Prev, Next};
|
||||
use AppViewCommand::{Focus, App};
|
||||
Some(match input.event() {
|
||||
key!(Left) => Focus(Prev),
|
||||
key!(Right) => Focus(Next),
|
||||
_ => TransportCommand::input_to_command(app.app, input).map(App)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl InputToCommand<Tui, TransportApp<Tui>> for TransportCommand {
|
||||
fn input_to_command (app: &TransportApp<Tui>, input: &TuiInput) -> Option<Self> {
|
||||
use KeyCode::Char;
|
||||
use AppViewFocus::Content;
|
||||
use TransportCommand::{SetBpm, SetQuant, SetSync};
|
||||
use TransportViewFocus::{Bpm, Quant, Sync, PlayPause, Clock};
|
||||
let clock = app.app.model.clock();
|
||||
Some(match input.event() {
|
||||
|
||||
key!(KeyCode::Left) => Self::Focus(FocusCmd::Prev),
|
||||
key!(KeyCode::Right) => Self::Focus(FocusCmd::Next),
|
||||
|
||||
key!(KeyCode::Char('.')) => Self::App(match app.focused() {
|
||||
AppViewFocus::Content(Focus::Bpm) => Cmd::SetBpm(clock.timebase().bpm.get() + 1.0),
|
||||
AppViewFocus::Content(Focus::Quant) => Cmd::SetQuant(next_note_length(clock.quant.get()as usize)as f64),
|
||||
AppViewFocus::Content(Focus::Sync) => Cmd::SetSync(next_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
AppViewFocus::Content(Focus::PlayPause) => {todo!()},
|
||||
AppViewFocus::Content(Focus::Clock) => {todo!()},
|
||||
key!(Char('.')) => match app.focused() {
|
||||
Content(Bpm) => SetBpm(clock.timebase().bpm.get() + 1.0),
|
||||
Content(Quant) => SetQuant(next_note_length(clock.quant.get()as usize)as f64),
|
||||
Content(Sync) => SetSync(next_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
Content(PlayPause) => {todo!()},
|
||||
Content(Clock) => {todo!()},
|
||||
_ => {todo!()}
|
||||
}),
|
||||
key!(KeyCode::Char(',')) => Self::App(match app.focused() {
|
||||
AppViewFocus::Content(Focus::Bpm) => Cmd::SetBpm(clock.timebase().bpm.get() - 1.0),
|
||||
AppViewFocus::Content(Focus::Quant) => Cmd::SetQuant(prev_note_length(clock.quant.get()as usize)as f64),
|
||||
AppViewFocus::Content(Focus::Sync) => Cmd::SetSync(prev_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
AppViewFocus::Content(Focus::PlayPause) => {todo!()},
|
||||
AppViewFocus::Content(Focus::Clock) => {todo!()}
|
||||
},
|
||||
key!(KeyCode::Char(',')) => match app.focused() {
|
||||
Content(Bpm) => SetBpm(clock.timebase().bpm.get() - 1.0),
|
||||
Content(Quant) => SetQuant(prev_note_length(clock.quant.get()as usize)as f64),
|
||||
Content(Sync) => SetSync(prev_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
Content(PlayPause) => {todo!()},
|
||||
Content(Clock) => {todo!()}
|
||||
_ => {todo!()}
|
||||
}),
|
||||
key!(KeyCode::Char('>')) => Self::App(match app.focused() {
|
||||
AppViewFocus::Content(Focus::Bpm) => Cmd::SetBpm(clock.timebase().bpm.get() + 0.001),
|
||||
AppViewFocus::Content(Focus::Quant) => Cmd::SetQuant(next_note_length(clock.quant.get()as usize)as f64),
|
||||
AppViewFocus::Content(Focus::Sync) => Cmd::SetSync(next_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
AppViewFocus::Content(Focus::PlayPause) => {todo!()},
|
||||
AppViewFocus::Content(Focus::Clock) => {todo!()}
|
||||
},
|
||||
key!(KeyCode::Char('>')) => match app.focused() {
|
||||
Content(Bpm) => SetBpm(clock.timebase().bpm.get() + 0.001),
|
||||
Content(Quant) => SetQuant(next_note_length(clock.quant.get()as usize)as f64),
|
||||
Content(Sync) => SetSync(next_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
Content(PlayPause) => {todo!()},
|
||||
Content(Clock) => {todo!()}
|
||||
_ => {todo!()}
|
||||
}),
|
||||
key!(KeyCode::Char('<')) => Self::App(match app.focused() {
|
||||
AppViewFocus::Content(Focus::Bpm) => Cmd::SetBpm(clock.timebase().bpm.get() - 0.001),
|
||||
AppViewFocus::Content(Focus::Quant) => Cmd::SetQuant(prev_note_length(clock.quant.get()as usize)as f64),
|
||||
AppViewFocus::Content(Focus::Sync) => Cmd::SetSync(prev_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
AppViewFocus::Content(Focus::PlayPause) => {todo!()},
|
||||
AppViewFocus::Content(Focus::Clock) => {todo!()}
|
||||
},
|
||||
key!(KeyCode::Char('<')) => match app.focused() {
|
||||
Content(Bpm) => SetBpm(clock.timebase().bpm.get() - 0.001),
|
||||
Content(Quant) => SetQuant(prev_note_length(clock.quant.get()as usize)as f64),
|
||||
Content(Sync) => SetSync(prev_note_length(clock.sync.get()as usize)as f64+1.),
|
||||
Content(PlayPause) => {todo!()},
|
||||
Content(Clock) => {todo!()}
|
||||
_ => {todo!()}
|
||||
}),
|
||||
|
||||
},
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
|
|
@ -81,32 +90,37 @@ impl InputToCommand<Tui, TransportApp<Tui>> for TransportAppCommand {
|
|||
|
||||
impl Command<TransportApp<Tui>> for TransportAppCommand {
|
||||
fn execute (self, state: &mut TransportApp<Tui>) -> Perhaps<Self> {
|
||||
let clock = state.app.model.clock();
|
||||
use AppViewCommand::{Focus, App};
|
||||
use FocusCommand::{Next, Prev};
|
||||
Ok(Some(match self {
|
||||
Self::Focus(command) => Self::Focus({
|
||||
use FocusCommand::*;
|
||||
match command {
|
||||
Next => { todo!() },
|
||||
Prev => { todo!() },
|
||||
_ => { todo!() }
|
||||
}
|
||||
}),
|
||||
Self::App(command) => Self::App({
|
||||
use TransportCommand::*;
|
||||
match command {
|
||||
SetBpm(bpm) => SetBpm(clock.timebase().bpm.set(bpm)),
|
||||
SetQuant(quant) => SetQuant(clock.quant.set(quant)),
|
||||
SetSync(sync) => SetSync(clock.sync.set(sync)),
|
||||
_ => {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
App(command) => if let Some(undo) = TransportCommand::execute(command, state)? {
|
||||
App(undo)
|
||||
} else {
|
||||
return Ok(None)
|
||||
},
|
||||
Focus(command) => Focus(match command {
|
||||
Next => { todo!() },
|
||||
Prev => { todo!() },
|
||||
_ => { todo!() }
|
||||
}),
|
||||
_ => todo!()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<TransportApp<Tui>> for TransportCommand {
|
||||
fn execute (self, state: &mut TransportApp<Tui>) -> Perhaps<Self> {
|
||||
use TransportCommand::{SetBpm, SetQuant, SetSync};
|
||||
let clock = state.app.model.clock();
|
||||
Ok(Some(match self {
|
||||
SetBpm(bpm) => SetBpm(clock.timebase().bpm.set(bpm)),
|
||||
SetQuant(quant) => SetQuant(clock.quant.set(quant)),
|
||||
SetSync(sync) => SetSync(clock.sync.set(sync)),
|
||||
_ => return Ok(None)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine> From<TransportModel> for TransportView<E> {
|
||||
fn from (model: TransportModel) -> Self {
|
||||
Self {
|
||||
|
|
@ -122,11 +136,17 @@ impl<E: Engine> From<TransportModel> for TransportView<E> {
|
|||
/// Stores and displays time-related info.
|
||||
#[derive(Debug)]
|
||||
pub struct TransportView<E: Engine> {
|
||||
_engine: PhantomData<E>,
|
||||
pub model: TransportModel,
|
||||
pub focus: TransportViewFocus,
|
||||
pub focused: bool,
|
||||
pub size: Measure<E>,
|
||||
_engine: PhantomData<E>,
|
||||
jack: Arc<RwLock<JackClient>>,
|
||||
/// Current sample rate, tempo, and PPQ.
|
||||
clock: Arc<Clock>,
|
||||
/// JACK transport handle.
|
||||
transport: jack::Transport,
|
||||
/// Enable metronome?
|
||||
metronome: bool,
|
||||
focus: TransportViewFocus,
|
||||
focused: bool,
|
||||
size: Measure<E>,
|
||||
}
|
||||
|
||||
/// Which item of the transport toolbar is focused
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue