mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue