From eb5f45142312af085cbd870698ec8ca7ad93fe91 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 25 Dec 2024 06:02:26 +0100 Subject: [PATCH] move phrase length/rename modes to tui/pool/ --- crates/tek/src/tui.rs | 15 +++++++++------ crates/tek/src/tui/pool.rs | 14 ++++++++------ crates/tek/src/tui/{ => pool}/phrase_length.rs | 10 +++++++++- crates/tek/src/tui/{ => pool}/phrase_rename.rs | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) rename crates/tek/src/tui/{ => pool}/phrase_length.rs (99%) rename crates/tek/src/tui/{ => pool}/phrase_rename.rs (99%) diff --git a/crates/tek/src/tui.rs b/crates/tek/src/tui.rs index 7d108d84..b4ee76d8 100644 --- a/crates/tek/src/tui.rs +++ b/crates/tek/src/tui.rs @@ -35,13 +35,16 @@ mod arranger_mode_v; pub(crate) use arranger_mode_v::*; //////////////////////////////////////////////////////// -mod status_bar; pub(crate) use status_bar::*; -mod file_browser; pub(crate) use file_browser::*; -mod phrase_editor; pub(crate) use phrase_editor::*; -mod piano_horizontal; pub(crate) use piano_horizontal::*; -mod phrase_length; pub(crate) use phrase_length::*; -mod phrase_rename; pub(crate) use phrase_rename::*; mod pool; pub(crate) use pool::*; + +mod phrase_editor; pub(crate) use phrase_editor::*; + +mod status_bar; pub(crate) use status_bar::*; + +mod file_browser; pub(crate) use file_browser::*; + +mod piano_horizontal; pub(crate) use piano_horizontal::*; + mod port_select; //////////////////////////////////////////////////////// diff --git a/crates/tek/src/tui/pool.rs b/crates/tek/src/tui/pool.rs index 61d506cc..91a87d5f 100644 --- a/crates/tek/src/tui/pool.rs +++ b/crates/tek/src/tui/pool.rs @@ -1,10 +1,12 @@ use super::*; -use crate::{ - PhrasePoolCommand as Pool, - tui::phrase_rename::PhraseRenameCommand as Rename, - tui::phrase_length::PhraseLengthCommand as Length, - tui::file_browser::FileBrowserCommand as Browse, -}; +use crate::PhrasePoolCommand as Pool; + +mod phrase_length; pub(crate) use phrase_length::*; +mod phrase_rename; pub(crate) use phrase_rename::*; + +use PhraseRenameCommand as Rename; +use PhraseLengthCommand as Length; +use FileBrowserCommand as Browse; #[derive(Debug)] pub struct PoolModel { diff --git a/crates/tek/src/tui/phrase_length.rs b/crates/tek/src/tui/pool/phrase_length.rs similarity index 99% rename from crates/tek/src/tui/phrase_length.rs rename to crates/tek/src/tui/pool/phrase_length.rs index 08ced486..32b642f3 100644 --- a/crates/tek/src/tui/phrase_length.rs +++ b/crates/tek/src/tui/pool/phrase_length.rs @@ -1,7 +1,8 @@ use crate::*; -use super::pool::{PoolModel, PoolMode}; +use super::*; use PhraseLengthFocus::*; use PhraseLengthCommand::*; + /// Displays and edits phrase length. #[derive(Clone)] pub struct PhraseLength { @@ -14,6 +15,7 @@ pub struct PhraseLength { /// Selected subdivision pub focus: Option, } + impl PhraseLength { pub fn new (pulses: usize, focus: Option) -> Self { Self { ppq: PPQ, bpb: 4, pulses, focus } @@ -37,6 +39,7 @@ impl PhraseLength { format!("{:>02}", self.ticks()) } } + /// Focused field of `PhraseLength` #[derive(Copy, Clone, Debug)] pub enum PhraseLengthFocus { @@ -47,6 +50,7 @@ pub enum PhraseLengthFocus { /// Editing the number of ticks Tick, } + impl PhraseLengthFocus { pub fn next (&mut self) { *self = match self { @@ -63,6 +67,7 @@ impl PhraseLengthFocus { } } } + render!(|self: PhraseLength|{ let bars = ||self.bars_string(); let beats = ||self.beats_string(); @@ -78,6 +83,7 @@ render!(|self: PhraseLength|{ add(&row!([" ", bars(), ".", beats(), "[", ticks()])), }) }); + #[derive(Copy, Clone, Debug, PartialEq)] pub enum PhraseLengthCommand { Begin, @@ -88,6 +94,7 @@ pub enum PhraseLengthCommand { Inc, Dec, } + command!(|self:PhraseLengthCommand,state:PoolModel|{ match state.phrases_mode_mut().clone() { Some(PoolMode::Length(phrase, ref mut length, ref mut focus)) => match self { @@ -118,6 +125,7 @@ command!(|self:PhraseLengthCommand,state:PoolModel|{ }; None }); + input_to_command!(PhraseLengthCommand:|state:PoolModel,from|{ if let Some(PoolMode::Length(_, length, _)) = state.phrases_mode() { match from.event() { diff --git a/crates/tek/src/tui/phrase_rename.rs b/crates/tek/src/tui/pool/phrase_rename.rs similarity index 99% rename from crates/tek/src/tui/phrase_rename.rs rename to crates/tek/src/tui/pool/phrase_rename.rs index 1b792f5b..67378f00 100644 --- a/crates/tek/src/tui/phrase_rename.rs +++ b/crates/tek/src/tui/pool/phrase_rename.rs @@ -1,4 +1,5 @@ use crate::*; +use super::*; #[derive(Clone, Debug, PartialEq)] pub enum PhraseRenameCommand { @@ -57,4 +58,3 @@ impl InputToCommand for PhraseRenameCommand { } } } -