mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
parent
f2d6e7724b
commit
b991a49ad7
3 changed files with 106 additions and 87 deletions
|
|
@ -41,11 +41,6 @@ use std::fmt::Write;
|
||||||
use ::tengri::tui::ratatui::prelude::Position;
|
use ::tengri::tui::ratatui::prelude::Position;
|
||||||
use xdg::BaseDirectories;
|
use xdg::BaseDirectories;
|
||||||
mod app_dsl; pub use self::app_dsl::*;
|
mod app_dsl; pub use self::app_dsl::*;
|
||||||
macro_rules!dsl_sym(
|
|
||||||
(|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{
|
|
||||||
impl<'t> DslSymNs<'t, $type> for $State {
|
|
||||||
const NS: DslNs<'t, fn (&'t $State)->$type> =
|
|
||||||
DslNs(&[$(($lit, |$state: &$State|$exp)),*]); } });
|
|
||||||
mod app_view; pub use self::app_view::*;
|
mod app_view; pub use self::app_view::*;
|
||||||
mod app_ctrl; pub use self::app_ctrl::*;
|
mod app_ctrl; pub use self::app_ctrl::*;
|
||||||
mod app_jack; pub use self::app_jack::*;
|
mod app_jack; pub use self::app_jack::*;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum AppCommand {}
|
||||||
handle!(TuiIn:|self: App, input|{
|
handle!(TuiIn:|self: App, input|{
|
||||||
panic!("{input:?}");
|
panic!("{input:?}");
|
||||||
//Ok(if let Some(binding) = self.profile.as_ref()
|
//Ok(if let Some(binding) = self.profile.as_ref()
|
||||||
|
|
@ -12,7 +14,7 @@ handle!(TuiIn:|self: App, input|{
|
||||||
//} else {
|
//} else {
|
||||||
//None
|
//None
|
||||||
//})
|
//})
|
||||||
})
|
});
|
||||||
dsl_sym!(|app: App| -> isize {
|
dsl_sym!(|app: App| -> isize {
|
||||||
":_isize_stub" => -1
|
":_isize_stub" => -1
|
||||||
});
|
});
|
||||||
|
|
@ -70,91 +72,108 @@ dsl_sym!(|app: App| -> Selection {
|
||||||
});
|
});
|
||||||
dsl_sym!(|app: App| -> Option<u7> {
|
dsl_sym!(|app: App| -> Option<u7> {
|
||||||
":editor/pitch" => Some((app.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into())
|
":editor/pitch" => Some((app.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into())
|
||||||
})
|
});
|
||||||
dsl_sym!(|app: App| -> Option<usize> {
|
dsl_sym!(|app: App| -> Option<usize> {
|
||||||
":selected/scene" => app.selection().scene(),
|
":selected/scene" => app.selection().scene(),
|
||||||
":selected/track" => app.selection().track(),
|
":selected/track" => app.selection().track(),
|
||||||
});
|
});
|
||||||
dsl_sym!(|app: App| -> Option<Arc<RwLock<MidiClip>>> {
|
dsl_sym!(|app: App| -> Option<Arc<RwLock<MidiClip>>> {
|
||||||
":selected/clip" => if let Selection::TrackClip { track, scene } = app.selection() {
|
":selected/clip" => if let Selection::TrackClip { track, scene } = app.selection() {
|
||||||
app.scenes()[*scene].clips[*track].clone(),
|
app.scenes()[*scene].clips[*track].clone()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dsl_bind!(AppCommand: App {
|
dsl_exp!(|app: App| -> AppCommand {
|
||||||
enqueue = |app, clip: Option<Arc<RwLock<MidiClip>>>| { todo!() };
|
["stop-all"] => app.project.stop_all(),
|
||||||
history = |app, delta: isize| { todo!() };
|
["enqueue", clip?: Option<Arc<RwLock<MidiClip>>>] => todo!(),
|
||||||
zoom = |app, zoom: usize| { todo!() };
|
["history", delta: isize] => todo!(),
|
||||||
stop_all = |app| { app.tracks_stop_all(); Ok(None) };
|
["zoom", zoom: usize] => todo!(),
|
||||||
//dialog = |app, command: DialogCommand|
|
["select", selection: Selection] => todo!(),
|
||||||
//Ok(command.delegate(&mut app.dialog, |c|Self::Dialog{command: c})?);
|
["dialog" / command: DialogCommand] => todo!(),
|
||||||
project = |app, command: ArrangementCommand|
|
["project" / command: ArrangementCommand] => todo!(),
|
||||||
Ok(command.delegate(&mut app.project, |c|Self::Project{command: c})?);
|
["clock" / command: ClockCommand] => todo!(),
|
||||||
clock = |app, command: ClockCommand|
|
["sampler" / command: SamplerCommand] => todo!(),
|
||||||
Ok(command.execute(app.clock_mut())?.map(|c|Self::Clock{command: c}));
|
["pool" / command: PoolCommand] => todo!(),
|
||||||
sampler = |app, command: SamplerCommand|
|
|
||||||
Ok(app.project.sampler_mut().map(|s|command.delegate(s, |command|Self::Sampler{command}))
|
|
||||||
.transpose()?.flatten());
|
|
||||||
pool = |app, command: PoolCommand| {
|
|
||||||
let undo = command.clone().delegate(&mut app.pool, |command|AppCommand::Pool{command})?;
|
|
||||||
// update linked editor after pool action
|
|
||||||
match command {
|
|
||||||
// autoselect: automatically load selected clip in editor
|
|
||||||
PoolCommand::Select { .. } |
|
|
||||||
// autocolor: update color in all places simultaneously
|
|
||||||
PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => {
|
|
||||||
let clip = app.pool.clip().clone();
|
|
||||||
app.editor_mut().map(|editor|editor.set_clip(clip.as_ref()))
|
|
||||||
},
|
|
||||||
_ => None
|
|
||||||
};
|
|
||||||
Ok(undo)
|
|
||||||
};
|
|
||||||
select = |app, selection: Selection| {
|
|
||||||
*app.project.selection_mut() = selection;
|
|
||||||
//todo!
|
|
||||||
//if let Some(ref mut editor) = app.editor_mut() {
|
|
||||||
//editor.set_clip(match selection {
|
|
||||||
//Selection::TrackClip { track, scene } if let Some(Some(Some(clip))) = app
|
|
||||||
//.project
|
|
||||||
//.scenes.get(scene)
|
|
||||||
//.map(|s|s.clips.get(track))
|
|
||||||
//=>
|
|
||||||
//Some(clip),
|
|
||||||
//_ =>
|
|
||||||
//None
|
|
||||||
//});
|
|
||||||
//}
|
|
||||||
Ok(None)
|
|
||||||
//("select" [t: usize, s: usize] Some(match (t.expect("no track"), s.expect("no scene")) {
|
|
||||||
//(0, 0) => Self::Select(Selection::Mix),
|
|
||||||
//(t, 0) => Self::Select(Selection::Track(t)),
|
|
||||||
//(0, s) => Self::Select(Selection::Scene(s)),
|
|
||||||
//(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
|
|
||||||
// autoedit: load focused clip in editor.
|
|
||||||
};
|
|
||||||
//fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
|
|
||||||
//Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
|
|
||||||
//}
|
|
||||||
//fn launch (app: &mut App) -> Perhaps<Self> {
|
|
||||||
//app.project.launch();
|
|
||||||
//Ok(None)
|
|
||||||
//}
|
|
||||||
toggle_editor = |app, value: bool|{ app.toggle_editor(Some(value)); Ok(None) };
|
|
||||||
editor = |app, command: MidiEditCommand| Ok(if let Some(editor) = app.editor_mut() {
|
|
||||||
let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?;
|
|
||||||
// update linked sampler after editor action
|
|
||||||
app.project.sampler_mut().map(|sampler|match command {
|
|
||||||
// autoselect: automatically select sample in sampler
|
|
||||||
MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
|
|
||||||
_ => {}
|
|
||||||
});
|
|
||||||
undo
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
dsl_exp!(|app: App| -> DialogCommand {});
|
||||||
|
dsl_exp!(|app: App| -> ArrangementCommand {});
|
||||||
|
dsl_exp!(|app: App| -> ClockCommand {});
|
||||||
|
dsl_exp!(|app: App| -> SamplerCommand {});
|
||||||
|
dsl_exp!(|app: App| -> PoolCommand {});
|
||||||
|
//dsl_bind!(AppCommand: App {
|
||||||
|
//enqueue = |app, clip: Option<Arc<RwLock<MidiClip>>>| { todo!() };
|
||||||
|
//history = |app, delta: isize| { todo!() };
|
||||||
|
//zoom = |app, zoom: usize| { todo!() };
|
||||||
|
//stop_all = |app| { app.tracks_stop_all(); Ok(None) };
|
||||||
|
////dialog = |app, command: DialogCommand|
|
||||||
|
////Ok(command.delegate(&mut app.dialog, |c|Self::Dialog{command: c})?);
|
||||||
|
//project = |app, command: ArrangementCommand|
|
||||||
|
//Ok(command.delegate(&mut app.project, |c|Self::Project{command: c})?);
|
||||||
|
//clock = |app, command: ClockCommand|
|
||||||
|
//Ok(command.execute(app.clock_mut())?.map(|c|Self::Clock{command: c}));
|
||||||
|
//sampler = |app, command: SamplerCommand|
|
||||||
|
//Ok(app.project.sampler_mut().map(|s|command.delegate(s, |command|Self::Sampler{command}))
|
||||||
|
//.transpose()?.flatten());
|
||||||
|
//pool = |app, command: PoolCommand| {
|
||||||
|
//let undo = command.clone().delegate(&mut app.pool, |command|AppCommand::Pool{command})?;
|
||||||
|
//// update linked editor after pool action
|
||||||
|
//match command {
|
||||||
|
//// autoselect: automatically load selected clip in editor
|
||||||
|
//PoolCommand::Select { .. } |
|
||||||
|
//// autocolor: update color in all places simultaneously
|
||||||
|
//PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => {
|
||||||
|
//let clip = app.pool.clip().clone();
|
||||||
|
//app.editor_mut().map(|editor|editor.set_clip(clip.as_ref()))
|
||||||
|
//},
|
||||||
|
//_ => None
|
||||||
|
//};
|
||||||
|
//Ok(undo)
|
||||||
|
//};
|
||||||
|
//select = |app, selection: Selection| {
|
||||||
|
//*app.project.selection_mut() = selection;
|
||||||
|
////todo!
|
||||||
|
////if let Some(ref mut editor) = app.editor_mut() {
|
||||||
|
////editor.set_clip(match selection {
|
||||||
|
////Selection::TrackClip { track, scene } if let Some(Some(Some(clip))) = app
|
||||||
|
////.project
|
||||||
|
////.scenes.get(scene)
|
||||||
|
////.map(|s|s.clips.get(track))
|
||||||
|
////=>
|
||||||
|
////Some(clip),
|
||||||
|
////_ =>
|
||||||
|
////None
|
||||||
|
////});
|
||||||
|
////}
|
||||||
|
//Ok(None)
|
||||||
|
////("select" [t: usize, s: usize] Some(match (t.expect("no track"), s.expect("no scene")) {
|
||||||
|
////(0, 0) => Self::Select(Selection::Mix),
|
||||||
|
////(t, 0) => Self::Select(Selection::Track(t)),
|
||||||
|
////(0, s) => Self::Select(Selection::Scene(s)),
|
||||||
|
////(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
|
||||||
|
//// autoedit: load focused clip in editor.
|
||||||
|
//};
|
||||||
|
////fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
|
||||||
|
////Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
|
||||||
|
////}
|
||||||
|
////fn launch (app: &mut App) -> Perhaps<Self> {
|
||||||
|
////app.project.launch();
|
||||||
|
////Ok(None)
|
||||||
|
////}
|
||||||
|
//toggle_editor = |app, value: bool|{ app.toggle_editor(Some(value)); Ok(None) };
|
||||||
|
//editor = |app, command: MidiEditCommand| Ok(if let Some(editor) = app.editor_mut() {
|
||||||
|
//let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?;
|
||||||
|
//// update linked sampler after editor action
|
||||||
|
//app.project.sampler_mut().map(|sampler|match command {
|
||||||
|
//// autoselect: automatically select sample in sampler
|
||||||
|
//MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
|
||||||
|
//_ => {}
|
||||||
|
//});
|
||||||
|
//undo
|
||||||
|
//} else {
|
||||||
|
//None
|
||||||
|
//});
|
||||||
|
//});
|
||||||
//take!(ClockCommand |state: App, iter|Take::take(state.clock(), iter));
|
//take!(ClockCommand |state: App, iter|Take::take(state.clock(), iter));
|
||||||
//take!(MidiEditCommand |state: App, iter|Ok(state.editor().map(|x|Take::take(x, iter)).transpose()?.flatten()));
|
//take!(MidiEditCommand |state: App, iter|Ok(state.editor().map(|x|Take::take(x, iter)).transpose()?.flatten()));
|
||||||
//take!(PoolCommand |state: App, iter|Take::take(&state.pool, iter));
|
//take!(PoolCommand |state: App, iter|Take::take(&state.pool, iter));
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,24 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
macro_rules!dsl_sym(
|
pub struct DslNs<'t, T: 't>(pub &'t [(&'t str, T)]);
|
||||||
|
|
||||||
|
pub trait DslSymNs<'t, T: 't>: 't { const NS: DslNs<'t, fn (&'t Self)->T>; }
|
||||||
|
#[macro_export] macro_rules! dsl_sym (
|
||||||
(|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{
|
(|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{
|
||||||
impl<'t> DslSymNs<'t, $type> for $State {
|
impl<'t> DslSymNs<'t, $type> for $State {
|
||||||
const NS: DslNs<'t, fn (&'t $State)->$type> =
|
const NS: DslNs<'t, fn (&'t $State)->$type> =
|
||||||
DslNs(&[$(($lit, |$state: &$State|$exp)),*]); } });
|
DslNs(&[$(($lit, |$state: &$State|$exp)),*]); } });
|
||||||
|
|
||||||
pub trait DslSymNs<'t, T: 't>: 't {
|
pub trait DslExpNs<'t, T: 't>: 't { const NS: DslNs<'t, fn (&'t Self, &str)->T>; }
|
||||||
const NS: DslNs<'t, fn (&'t Self)->T>;
|
#[macro_export] macro_rules! dsl_exp (
|
||||||
}
|
(|$state:ident:$State:ty|->$type:ty { $(
|
||||||
|
[$key:literal $(/ $sub:ident: $Sub:ty)? $(, $arg:ident $(?)? :$argtype:ty)*] => $body:expr
|
||||||
pub struct DslNs<'t, T: 't>(pub &'t [(&'t str, T)]);
|
),* $(,)? }) => {
|
||||||
|
impl<'t> DslExpNs<'t, $type> for $State {
|
||||||
|
const NS: DslNs<'t, fn (&'t $State, &str)->$type> =
|
||||||
|
DslNs(&[]); } });
|
||||||
|
|
||||||
pub type DslCb = fn (&App) -> Box<dyn Render<TuiOut>>;
|
pub type DslCb = fn (&App) -> Box<dyn Render<TuiOut>>;
|
||||||
|
|
||||||
impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
|
impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
|
||||||
type Output = DslCb;
|
type Output = DslCb;
|
||||||
fn index (&self, index: D) -> &Self::Output {
|
fn index (&self, index: D) -> &Self::Output {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue