mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: refactor pt.12, separate tek_snd
This commit is contained in:
parent
47c9cd2fe8
commit
2be7aee002
28 changed files with 955 additions and 766 deletions
|
|
@ -11,6 +11,7 @@ pub(crate) use std::fs::read_dir;
|
|||
|
||||
submod! {
|
||||
tui_app
|
||||
tui_app_foc
|
||||
|
||||
tui_arrangement
|
||||
tui_arrangement_cmd
|
||||
|
|
|
|||
|
|
@ -1,26 +1,28 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct App<T, E, C, U, A, S>
|
||||
pub struct AppContainer<T, E, C, U, A, S>
|
||||
where
|
||||
T: Send + Sync,
|
||||
E: Engine,
|
||||
C: Command<T>,
|
||||
U: From<Arc<RwLock<T>>> + Widget<Engine = E> + Handle<E>,
|
||||
A: From<Arc<RwLock<T>>> + Audio,
|
||||
S: From<Arc<RwLock<T>>> + StatusBar<E>
|
||||
{
|
||||
cursor: (usize, usize),
|
||||
entered: bool,
|
||||
menu_bar: Option<MenuBar<E, T, C>>,
|
||||
status_bar: Option<S>,
|
||||
history: Vec<C>,
|
||||
size: Measure<E>,
|
||||
ui: U,
|
||||
audio: A,
|
||||
model: Arc<RwLock<T>>,
|
||||
pub cursor: (usize, usize),
|
||||
pub entered: bool,
|
||||
pub menu_bar: Option<MenuBar<E, T, C>>,
|
||||
pub status_bar: Option<S>,
|
||||
pub history: Vec<C>,
|
||||
pub size: Measure<E>,
|
||||
pub ui: U,
|
||||
pub audio: A,
|
||||
pub model: Arc<RwLock<T>>,
|
||||
}
|
||||
|
||||
impl<T, E, C, U, A, S> From<T> for App<T, E, C, U, A, S>
|
||||
impl<T, E, C, U, A, S> From<T> for AppContainer<T, E, C, U, A, S>
|
||||
where
|
||||
T: Send + Sync,
|
||||
E: Engine,
|
||||
C: Command<T>,
|
||||
U: From<Arc<RwLock<T>>> + Widget<Engine = E> + Handle<E>,
|
||||
|
|
@ -42,3 +44,27 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, C, U, A, S> Content for AppContainer<T, Tui, C, U, A, S>
|
||||
where
|
||||
T: Send + Sync,
|
||||
C: Command<T>,
|
||||
U: From<Arc<RwLock<T>>> + Widget<Engine = Tui> + Handle<Tui>,
|
||||
A: From<Arc<RwLock<T>>> + Audio,
|
||||
S: From<Arc<RwLock<T>>> + StatusBar<Tui>
|
||||
{
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Split::down(
|
||||
if self.menu_bar.is_some() { 1 } else { 0 },
|
||||
row!(menu in self.menu_bar.menus.iter() => {
|
||||
row!(" ", menu.title.as_str(), " ")
|
||||
}),
|
||||
Split::up(
|
||||
if self.status_bar.is_some() { 1 } else { 0 },
|
||||
widget(&self.status_bar),
|
||||
self.ui
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
59
crates/tek_tui/src/tui_app_foc.rs
Normal file
59
crates/tek_tui/src/tui_app_foc.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
use crate::*;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum AppContainerCommand<T: std::fmt::Debug + Copy + Clone> {
|
||||
Focus(FocusCommand),
|
||||
App(T)
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum AppContainerFocus<F: std::fmt::Debug + Copy + Clone> {
|
||||
Menu,
|
||||
Content(F),
|
||||
}
|
||||
|
||||
impl<T, C, U, A, S> FocusGrid for AppContainer<T, Tui, C, U, A, S>
|
||||
where
|
||||
T: Send + Sync,
|
||||
C: Command<T>,
|
||||
U: From<Arc<RwLock<T>>> + Widget<Engine = Tui> + Handle<Tui> + FocusGrid,
|
||||
A: From<Arc<RwLock<T>>> + Audio,
|
||||
S: From<Arc<RwLock<T>>> + StatusBar<Tui>
|
||||
{
|
||||
type Item = AppContainerFocus<<U as FocusGrid>::Item>;
|
||||
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]] {
|
||||
&[
|
||||
&[AppContainerFocus::Menu],
|
||||
&[AppContainerFocus::Content],
|
||||
]
|
||||
}
|
||||
fn update_focus (&mut self) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ impl<E: Engine> Audio for ArrangerView<E> {
|
|||
if let Some((ref started_at, Some(ref playing))) = track.player.phrase {
|
||||
let phrase = phrase.read().unwrap();
|
||||
if *playing.read().unwrap() == *phrase {
|
||||
let pulse = self.clock.current.pulse.get();
|
||||
let pulse = self.sequencer.transport.state.clock.current.pulse.get();
|
||||
let start = started_at.pulse.get();
|
||||
let now = (pulse - start) % phrase.length as f64;
|
||||
self.sequencer.editor.now.set(now);
|
||||
|
|
@ -38,7 +38,7 @@ impl<E: Engine> Audio for ArrangerView<E> {
|
|||
}
|
||||
}
|
||||
self.sequencer.editor.now.set(0.);
|
||||
self.state.process(client, scope)
|
||||
return Control::Continue
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue