mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
This commit is contained in:
parent
99d9da6ffd
commit
fc038dbd97
10 changed files with 71 additions and 89 deletions
|
|
@ -7,7 +7,7 @@ macro_rules! cmd_todo { ($msg:literal) => {{ println!($msg); None }}; }
|
|||
handle!(TuiIn: |self: App, input|self.handle_tui_key_with_history(input));
|
||||
impl App {
|
||||
fn handle_tui_key_with_history (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
||||
Ok(if let Some(command) = self.config.keys.command(self, input) {
|
||||
Ok(if let Some(command) = self.config.keys.keybind_resolve(self, input)? {
|
||||
// FIXME failed commands not persisted in undo history
|
||||
let undo = command.clone().execute(self)?;
|
||||
self.history.push((command, undo));
|
||||
|
|
@ -38,6 +38,7 @@ impl AppCommand {
|
|||
})
|
||||
}
|
||||
fn dialog (app: &mut App, command: DialogCommand) -> Perhaps<Self> {
|
||||
panic!("dialog");
|
||||
Ok(command.delegate(&mut app.dialog, |command|Self::Dialog{command})?)
|
||||
}
|
||||
fn project (app: &mut App, command: ArrangementCommand) -> Perhaps<Self> {
|
||||
|
|
@ -111,33 +112,10 @@ impl AppCommand {
|
|||
//Ok(None)
|
||||
//}
|
||||
}
|
||||
impl<'state> Context<'state, ClockCommand> for App {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<ClockCommand> {
|
||||
Context::get(&self.clock(), iter)
|
||||
}
|
||||
}
|
||||
impl<'state> Context<'state, MidiEditCommand> for App {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<MidiEditCommand> {
|
||||
self.editor().map(|e|Context::get(e, iter)).flatten()
|
||||
}
|
||||
}
|
||||
impl<'state> Context<'state, PoolCommand> for App {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<PoolCommand> {
|
||||
Context::get(&self.pool, iter)
|
||||
}
|
||||
}
|
||||
impl<'state> Context<'state, SamplerCommand> for App {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<SamplerCommand> {
|
||||
self.project.sampler().map(|p|Context::get(p, iter)).flatten()
|
||||
}
|
||||
}
|
||||
impl<'state> Context<'state, ArrangementCommand> for App {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<ArrangementCommand> {
|
||||
Context::get(&self.project, iter)
|
||||
}
|
||||
}
|
||||
impl<'state> Context<'state, DialogCommand> for App {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<DialogCommand> {
|
||||
Context::get(&self, iter)
|
||||
}
|
||||
}
|
||||
|
||||
dsl!(ClockCommand: |self: App, iter|self.clock().take(iter));
|
||||
dsl!(MidiEditCommand: |self: App, iter|Ok(self.editor().map(|x|x.take(iter)).transpose()?.flatten()));
|
||||
dsl!(PoolCommand: |self: App, iter|self.pool.take(iter));
|
||||
dsl!(SamplerCommand: |self: App, iter|Ok(self.project.sampler().map(|x|x.take(iter)).transpose()?.flatten()));
|
||||
dsl!(ArrangementCommand: |self: App, iter|self.project.take(iter));
|
||||
dsl!(DialogCommand: |self: App, iter|Dsl::take(&self.dialog, iter));
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ pub struct Configuration {
|
|||
/// View definition
|
||||
pub view: TokenIter<'static>,
|
||||
// Input keymap
|
||||
pub keys: InputMap<'static, App, AppCommand, TuiIn, TokenIter<'static>>,
|
||||
pub keys: InputMap<App, AppCommand, TuiIn, TokenIter<'static>>,
|
||||
}
|
||||
|
||||
impl Configuration {
|
||||
|
|
@ -406,7 +406,7 @@ impl Configuration {
|
|||
}
|
||||
|
||||
fn parse_keys (base: &impl AsRef<Path>, iter: Option<TokenIter<'static>>)
|
||||
-> Usually<InputMap<'static, App, AppCommand, TuiIn, TokenIter<'static>>>
|
||||
-> Usually<InputMap<App, AppCommand, TuiIn, TokenIter<'static>>>
|
||||
{
|
||||
if iter.is_none() {
|
||||
return Err(format!("missing keys definition").into())
|
||||
|
|
@ -435,15 +435,13 @@ impl Configuration {
|
|||
"layer-if" => {
|
||||
let mut cond = None;
|
||||
|
||||
let next = exp.next();
|
||||
if let Some(Token { value: Value::Sym(sym), .. }) = next {
|
||||
if let Some(Token { value: Value::Sym(sym), .. }) = exp.next() {
|
||||
cond = Some(leak(sym));
|
||||
} else {
|
||||
return Err(format!("(e4) unexpected non-symbol {next:?}").into())
|
||||
};
|
||||
|
||||
let token = exp.peek();
|
||||
if let Some(Token { value: Value::Str(path), .. }) = token {
|
||||
if let Some(Token { value: Value::Str(path), .. }) = exp.peek() {
|
||||
let path = base.as_ref().parent().unwrap().join(unquote(path));
|
||||
if !std::fs::exists(&path)? {
|
||||
return Err(format!("(e5) not found: {path:?}").into())
|
||||
|
|
@ -454,13 +452,10 @@ impl Configuration {
|
|||
let cond = cond.unwrap();
|
||||
println!("ok");
|
||||
map.add_layer_if(
|
||||
Box::new(move |state: &App|{
|
||||
Context::get(state,
|
||||
&mut format!("{cond}").as_str().into())
|
||||
.unwrap_or_else(||panic!(
|
||||
"missing input layer conditional {cond} from {exp:?}"))
|
||||
}),
|
||||
keys
|
||||
Box::new(move |state: &App|Dsl::take_or_fail(
|
||||
state, &mut exp.clone(),
|
||||
format!("missing input layer conditional")
|
||||
)), keys
|
||||
);
|
||||
} else {
|
||||
return Err(format!("(e4) unexpected non-symbol {next:?}").into())
|
||||
|
|
|
|||
|
|
@ -11,6 +11,13 @@ impl Arrangement {
|
|||
}
|
||||
}
|
||||
|
||||
dsl!(TrackCommand: |self: Arrangement, iter|self.take(iter));
|
||||
dsl!(MidiInputCommand: |self: Arrangement, iter|self.take(iter));
|
||||
dsl!(MidiOutputCommand: |self: Arrangement, iter|self.take(iter));
|
||||
dsl!(DeviceCommand: |self: Arrangement, iter|self.take(iter));
|
||||
dsl!(SceneCommand: |self: Arrangement, iter|self.take(iter));
|
||||
dsl!(ClipCommand: |self: Arrangement, iter|self.take(iter));
|
||||
|
||||
#[tengri_proc::command(Arrangement)]
|
||||
impl ArrangementCommand {
|
||||
fn home (arranger: &mut Arrangement) -> Perhaps<Self> {
|
||||
|
|
@ -243,39 +250,3 @@ impl ArrangementCommand {
|
|||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'state> Context<'state, TrackCommand> for Arrangement {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<TrackCommand> {
|
||||
Context::get(&self, iter)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'state> Context<'state, MidiInputCommand> for Arrangement {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<MidiInputCommand> {
|
||||
Context::get(&self, iter)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'state> Context<'state, MidiOutputCommand> for Arrangement {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<MidiOutputCommand> {
|
||||
Context::get(&self, iter)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'state> Context<'state, DeviceCommand> for Arrangement {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<DeviceCommand> {
|
||||
Context::get(&self, iter)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'state> Context<'state, SceneCommand> for Arrangement {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<SceneCommand> {
|
||||
Context::get(&self, iter)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'state> Context<'state, ClipCommand> for Arrangement {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<ClipCommand> {
|
||||
Context::get(&self, iter)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,47 @@ use crate::*;
|
|||
|
||||
#[tengri_proc::command(Option<Dialog>)]
|
||||
impl DialogCommand {
|
||||
fn dismiss (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
|
||||
fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
|
||||
*dialog = Some(new);
|
||||
Ok(None)
|
||||
}
|
||||
fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
|
||||
*dialog = None;
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
//#[derive(Clone, Debug)]
|
||||
//pub enum DialogCommand {
|
||||
//Open { dialog: Dialog },
|
||||
//Close
|
||||
//}
|
||||
|
||||
//impl Command<Option<Dialog>> for DialogCommand {
|
||||
//fn execute (self, state: &mut Option<Dialog>) -> Perhaps<Self> {
|
||||
//match self {
|
||||
//Self::Open { dialog } => {
|
||||
//*state = Some(dialog);
|
||||
//},
|
||||
//Self::Close => {
|
||||
//*state = None;
|
||||
//}
|
||||
//};
|
||||
//Ok(None)
|
||||
//}
|
||||
//}
|
||||
|
||||
//dsl!(DialogCommand: |self: Dialog, iter|todo!());
|
||||
//Dsl::take(&mut self.dialog, iter));
|
||||
|
||||
//#[tengri_proc::command(Option<Dialog>)]//Nope.
|
||||
//impl DialogCommand {
|
||||
//fn open (dialog: &mut Option<Dialog>, new: Dialog) -> Perhaps<Self> {
|
||||
//*dialog = Some(new);
|
||||
//Ok(None)
|
||||
//}
|
||||
//fn close (dialog: &mut Option<Dialog>) -> Perhaps<Self> {
|
||||
//*dialog = None;
|
||||
//Ok(None)
|
||||
//}
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -81,11 +81,8 @@ impl PoolCommand {
|
|||
|
||||
}
|
||||
|
||||
impl<'state> Context<'state, BrowserCommand> for Pool {
|
||||
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<BrowserCommand> {
|
||||
self.browser.as_ref().map(|p|Context::get(p, iter)).flatten()
|
||||
}
|
||||
}
|
||||
dsl!(BrowserCommand: |self: Pool, iter|Ok(self.browser
|
||||
.as_ref().map(|p|p.take(iter)).transpose()?.flatten()));
|
||||
|
||||
#[tengri_proc::command(Pool)]
|
||||
impl PoolClipCommand {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub(crate) use std::sync::{Arc, atomic::{AtomicUsize, AtomicBool, Ordering::Rela
|
|||
pub(crate) use std::fmt::Debug;
|
||||
pub(crate) use std::ops::{Add, Sub, Mul, Div, Rem};
|
||||
|
||||
pub(crate) use ::tengri::{from, Usually, Perhaps, Has, has, maybe_has, tui::*};
|
||||
pub(crate) use ::tengri::{from, Usually, Perhaps, Has, has, maybe_has, tui::*, dsl::*};
|
||||
|
||||
pub use ::atomic_float; pub(crate) use atomic_float::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ impl JackMidiIn {
|
|||
|
||||
#[tengri_proc::command(JackMidiIn)]
|
||||
impl MidiInputCommand {
|
||||
fn _todo_ (_port: &mut JackMidiIn) -> Perhaps<Self> { Ok(None) }
|
||||
}
|
||||
|
||||
impl<T: Has<Vec<JackMidiIn>>> HasMidiIns for T {
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ impl JackPortAutoconnect for JackMidiOut {
|
|||
|
||||
#[tengri_proc::command(JackMidiOut)]
|
||||
impl MidiOutputCommand {
|
||||
fn _todo_ (_port: &mut JackMidiOut) -> Perhaps<Self> { Ok(None) }
|
||||
}
|
||||
|
||||
impl<T: Has<Vec<JackMidiOut>>> HasMidiOuts for T {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue