mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-10-08 18:56:42 +02:00
multidispatch; mode/select status
This commit is contained in:
parent
6aff4e55a6
commit
0a89fab28a
3 changed files with 104 additions and 173 deletions
69
src/tek.rs
69
src/tek.rs
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
mod deps; pub use self::deps::*;
|
||||
|
||||
|
||||
mod midi_octave; pub use self::midi_octave::*;
|
||||
mod midi_piano; pub use self::midi_piano::*;
|
||||
mod midi_point; pub use self::midi_point::*;
|
||||
|
|
@ -358,28 +357,28 @@ fn get_vec_arc_str <'a> (_: &App, _: impl Language) -> Perhaps<Vec<Arc<str>>> {
|
|||
todo!()
|
||||
}
|
||||
|
||||
impl_has!(Clock: |self: App|self.project.clock);
|
||||
impl_has!(Dialog: |self: App|self.dialog);
|
||||
impl_has!(Jack<'static>: |self: App|self.jack);
|
||||
impl_has!(Pool<MidiClip>: |self: App|self.project.clips);
|
||||
impl_has!(Pool<Sample>: |self: App|self.project.samples);
|
||||
impl_has!(Selection: |self: App|self.project.selection);
|
||||
impl_has!(Sizer: |self: App|self.size);
|
||||
primitive!(u8: try_to_u8);
|
||||
primitive!(u16: try_to_u16);
|
||||
primitive!(usize: try_to_usize);
|
||||
primitive!(isize: try_to_isize);
|
||||
impl_has!(Clock: |self: App|self.project.clock);
|
||||
impl_has!(Dialog: |self: App|self.dialog);
|
||||
impl_has!(Jack<'static>: |self: App|self.jack);
|
||||
impl_has!(Pool<MidiClip>: |self: App|self.project.clips);
|
||||
impl_has!(Pool<Sample>: |self: App|self.project.samples);
|
||||
impl_has!(Selection: |self: App|self.project.selection);
|
||||
impl_has!(Sizer: |self: App|self.size);
|
||||
impl_as_ref!(Option<Project>: |self: App|todo!());
|
||||
impl_as_mut!(Option<Project>: |self: App|todo!());
|
||||
impl_as_ref!(Option<MidiEditor>: |self: App|self.project.as_ref());
|
||||
impl_as_mut!(Option<MidiEditor>: |self: App|self.project.as_mut());
|
||||
|
||||
impl HasClip for App {
|
||||
fn clip_slot (&self) -> Option<Slot<MidiClip>> {
|
||||
self.project.clip_slot()
|
||||
}
|
||||
}
|
||||
|
||||
primitive!(u8: try_to_u8);
|
||||
primitive!(u16: try_to_u16);
|
||||
primitive!(usize: try_to_usize);
|
||||
primitive!(isize: try_to_isize);
|
||||
|
||||
tui_keys!(self: App, input {
|
||||
#[cfg(feature = "prof2")] profiling::scope!("App::tui_keys!");
|
||||
Self::input_cmd(self, input)
|
||||
|
|
@ -388,13 +387,13 @@ tui_keys!(self: App, input {
|
|||
impl App {
|
||||
|
||||
fn input_cmd (state: &mut Self, input: &TuiEvent) -> Usually<()> {
|
||||
if let Some(bindings) = Self::input_cmd_find(state, input) {
|
||||
return Self::input_cmd_exec(state, bindings)
|
||||
if let Some(bindings) = Self::input_cmds_find(state, input) {
|
||||
return Self::input_cmds_exec(state, bindings)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn input_cmd_find (state: &mut Self, input: &TuiEvent) -> Option<Arc<[Binding<Arc<str>>]>> {
|
||||
fn input_cmds_find (state: &mut Self, input: &TuiEvent) -> Option<Arc<[Binding<Arc<str>>]>> {
|
||||
for name in state.modes.read().iter().rev() {
|
||||
let mode = state.config.get_mode(name).as_ref().map(Arc::clone);
|
||||
if let Some(mode) = mode {
|
||||
|
|
@ -410,42 +409,30 @@ impl App {
|
|||
None
|
||||
}
|
||||
|
||||
fn input_cmd_exec (state: &mut Self, bindings: Arc<[Binding<Arc<str>>]>) -> Usually<()> {
|
||||
fn input_cmds_exec (state: &mut Self, bindings: Arc<[Binding<Arc<str>>]>) -> Usually<()> {
|
||||
for binding in bindings.iter() {
|
||||
for cmd in binding.commands.iter() {
|
||||
if Self::cmd::<AppCmd>(state, cmd)? {
|
||||
return Ok(())
|
||||
for src in binding.commands.iter() {
|
||||
if let Some(command) = Namespace::<AppCmd>::namespace(state, &src)? {
|
||||
Self::cmd_dispatch(state, command)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd <
|
||||
T: Dispatch<Self> + Clone + Into<AppCmd>
|
||||
> (state: &mut Self, src: &str) -> Usually<bool> where
|
||||
Self: Namespace<T>,
|
||||
{
|
||||
if let Some(cmd) = Namespace::<T>::namespace(state, &src)? {
|
||||
return Self::cmd_dispatch(state, cmd.into())
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
fn cmd_dispatch (state: &mut Self, cmd: AppCmd) -> Usually<bool> where
|
||||
Self: Namespace<AppCmd>,
|
||||
{
|
||||
match cmd.clone().dispatch(state) {
|
||||
Err(err) => {
|
||||
state.history.push((cmd.into(), None));
|
||||
return Err(err)
|
||||
},
|
||||
fn cmd_dispatch (state: &mut Self, command: AppCmd) -> Usually<()> {
|
||||
match command.clone().dispatch(state) {
|
||||
Ok(undo) => {
|
||||
state.history.push((cmd.into(), undo.map(Into::into)));
|
||||
return Ok(true)
|
||||
state.history.push((command, undo));
|
||||
Ok(())
|
||||
},
|
||||
Err(err) => {
|
||||
state.history.push((command, None));
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// A control axis.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue