wip: refactor pt.29: 12 errors

This commit is contained in:
🪞👃🪞 2024-11-14 20:56:23 +01:00
parent ceead4131c
commit ab85a86b6b
27 changed files with 1890 additions and 1865 deletions

View file

@ -1,6 +1,11 @@
use crate::*;
pub type TransportApp<E: Engine> = AppView<E, TransportView<E>, TransportViewCommand>;
pub type TransportApp<E: Engine> = AppView<
E,
TransportView<E>,
TransportViewCommand,
TransportStatusBar
>;
impl TryFrom<&Arc<RwLock<JackClient>>> for TransportApp<Tui> {
type Error = Box<dyn std::error::Error>;
@ -78,3 +83,194 @@ impl Audio for TransportView<Tui> {
self.model.process(client, scope)
}
}
#[derive(Copy, Clone)]
pub struct TransportStatusBar;
impl StatusBar for TransportStatusBar {
type State = ();
fn hotkey_fg () -> Color {
TuiTheme::hotkey_fg()
}
fn update (&mut self, state: &()) {
todo!()
}
}
impl Content for TransportStatusBar {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
todo!();
""
}
}
#[derive(Copy, Clone, PartialEq)]
pub enum TransportViewCommand {
Focus(FocusCommand),
Transport(TransportCommand),
}
impl Handle<Tui> for TransportView<Tui> {
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
TransportViewCommand::execute_with_state(self, from)
}
}
impl InputToCommand<Tui, TransportView<Tui>> for TransportViewCommand {
fn input_to_command (view: &TransportView<Tui>, input: &TuiInput) -> Option<Self> {
use TransportViewFocus as Focus;
use FocusCommand as FocusCmd;
use TransportCommand as Cmd;
let clock = view.model.clock();
Some(match input.event() {
key!(KeyCode::Left) => Self::Focus(FocusCmd::Prev),
key!(KeyCode::Right) => Self::Focus(FocusCmd::Next),
key!(KeyCode::Char('.')) => Self::Transport(match view.focus {
Focus::Bpm => Cmd::SetBpm(clock.timebase().bpm.get() + 1.0),
Focus::Quant => Cmd::SetQuant(next_note_length(clock.quant.get()as usize)as f64),
Focus::Sync => Cmd::SetSync(next_note_length(clock.sync.get()as usize)as f64+1.),
Focus::PlayPause => {todo!()},
Focus::Clock => {todo!()}
}),
key!(KeyCode::Char(',')) => Self::Transport(match view.focus {
Focus::Bpm => Cmd::SetBpm(clock.timebase().bpm.get() - 1.0),
Focus::Quant => Cmd::SetQuant(prev_note_length(clock.quant.get()as usize)as f64),
Focus::Sync => Cmd::SetSync(prev_note_length(clock.sync.get()as usize)as f64+1.),
Focus::PlayPause => {todo!()},
Focus::Clock => {todo!()}
}),
key!(KeyCode::Char('>')) => Self::Transport(match view.focus {
Focus::Bpm => Cmd::SetBpm(clock.timebase().bpm.get() + 0.001),
Focus::Quant => Cmd::SetQuant(next_note_length(clock.quant.get()as usize)as f64),
Focus::Sync => Cmd::SetSync(next_note_length(clock.sync.get()as usize)as f64+1.),
Focus::PlayPause => {todo!()},
Focus::Clock => {todo!()}
}),
key!(KeyCode::Char('<')) => Self::Transport(match view.focus {
Focus::Bpm => Cmd::SetBpm(clock.timebase().bpm.get() - 0.001),
Focus::Quant => Cmd::SetQuant(prev_note_length(clock.quant.get()as usize)as f64),
Focus::Sync => Cmd::SetSync(prev_note_length(clock.sync.get()as usize)as f64+1.),
Focus::PlayPause => {todo!()},
Focus::Clock => {todo!()}
}),
_ => return None
})
}
}
impl<E: Engine> Command<TransportView<E>> for TransportViewCommand {
fn execute (self, view: &mut TransportView<E>) -> Perhaps<Self> {
let clock = view.model.clock();
Ok(Some(match self {
Self::Focus(command) => Self::Focus({
use FocusCommand::*;
match command {
Next => { todo!() },
Prev => { todo!() },
_ => { todo!() }
}
}),
Self::Transport(command) => Self::Transport({
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!()
}
}
}),
}))
}
}
impl TransportViewFocus {
pub fn next (&mut self) {
*self = match self {
Self::PlayPause => Self::Bpm,
Self::Bpm => Self::Quant,
Self::Quant => Self::Sync,
Self::Sync => Self::Clock,
Self::Clock => Self::PlayPause,
}
}
pub fn prev (&mut self) {
*self = match self {
Self::PlayPause => Self::Clock,
Self::Bpm => Self::PlayPause,
Self::Quant => Self::Bpm,
Self::Sync => Self::Quant,
Self::Clock => Self::Sync,
}
}
pub fn wrap <'a, W: Widget<Engine = Tui>> (
self, parent_focus: bool, focus: Self, widget: &'a W
) -> impl Widget<Engine = Tui> + 'a {
let focused = parent_focus && focus == self;
let corners = focused.then_some(CORNERS);
let highlight = focused.then_some(Background(Color::Rgb(60, 70, 50)));
lay!(corners, highlight, *widget)
}
}
/// Which item of the transport toolbar is focused
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum TransportViewFocus {
Bpm,
Sync,
PlayPause,
Clock,
Quant,
}
impl FocusGrid for TransportApp<Tui> {
type Item = AppViewFocus<TransportViewFocus>;
fn cursor (&self) -> (usize, usize) {
self.cursor
}
fn cursor_mut (&mut self) -> &mut (usize, usize) {
&mut self.cursor
}
fn focus_enter (&mut self) {
let focused = self.focused();
if !self.entered {
self.entered = true;
// TODO
}
}
fn focus_exit (&mut self) {
if self.entered {
self.entered = false;
// TODO
}
}
fn entered (&self) -> Option<Self::Item> {
if self.entered {
Some(self.focused())
} else {
None
}
}
fn layout (&self) -> &[&[Self::Item]] {
use AppViewFocus::*;
use TransportViewFocus::*;
&[
&[Menu],
&[
Content(Bpm),
Content(Sync),
Content(PlayPause),
Content(Clock),
Content(Quant),
],
]
}
fn update_focus (&mut self) {
// TODO
}
}