mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-10-08 18:56:42 +02:00
toggle edit mode with editor
This commit is contained in:
parent
ea74aba7b7
commit
767f917302
5 changed files with 156 additions and 144 deletions
|
|
@ -1,5 +1,56 @@
|
|||
use crate::*;
|
||||
|
||||
tui_keys!(self: App, input {
|
||||
#[cfg(feature = "prof2")] profiling::scope!("App::tui_keys!");
|
||||
self.input_cmds(input)
|
||||
});
|
||||
|
||||
impl App {
|
||||
fn input_cmds (&mut self, input: &TuiEvent) -> Usually<()> {
|
||||
if let Some(bindings) = Self::input_cmds_find(self, input) {
|
||||
return Self::input_cmds_exec(self, bindings)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn input_cmds_find (state: &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 {
|
||||
let binds = state.config.binds.clone();
|
||||
for id in mode.keys.iter() {
|
||||
if let Some(event_map) = binds.find(id)
|
||||
&& let Some(bindings) = event_map.query(input) {
|
||||
return Some(bindings.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
fn input_cmds_exec (state: &mut Self, bindings: Arc<[Binding<Arc<str>>]>) -> Usually<()> {
|
||||
for binding in bindings.iter() {
|
||||
for src in binding.commands.iter() {
|
||||
if let Some(command) = Namespace::<AppCmd>::namespace(state, &src)? {
|
||||
Self::cmd_dispatch(state, command)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn cmd_dispatch (state: &mut Self, command: AppCmd) -> Usually<()> {
|
||||
match command.clone().dispatch(state) {
|
||||
Ok(undo) => {
|
||||
state.history.push((command, undo));
|
||||
Ok(())
|
||||
},
|
||||
Err(err) => {
|
||||
state.history.push((command, None));
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_from!(AppCmd: |x: AxisCmd| AppCmd::Axis { command: x });
|
||||
impl_from!(AppCmd: |x: BrowseCmd| AppCmd::Browse { command: x });
|
||||
impl_from!(AppCmd: |x: MidiClipCmd| AppCmd::MidiClip { command: x });
|
||||
|
|
@ -22,7 +73,7 @@ impl_from!(AppCmd: |x: TracksCmd| AppCmd::Tracks { command: x });
|
|||
Ok(None)
|
||||
}
|
||||
/// Enter a contextual mode.
|
||||
#[command(Enter = "enter")] pub fn cmd_mode_enter (&mut self, mode: Arc<str>) -> Perhaps<AppCmd> {
|
||||
#[command(Enter = "enter")] pub fn enter_mode (&mut self, mode: Arc<str>) -> Perhaps<AppCmd> {
|
||||
let mut modes = self.modes_mut();
|
||||
Ok(if modes.last() != Some(&mode) {
|
||||
modes.push(mode);
|
||||
|
|
@ -32,7 +83,7 @@ impl_from!(AppCmd: |x: TracksCmd| AppCmd::Tracks { command: x });
|
|||
})
|
||||
}
|
||||
/// Leave a contextual mode.
|
||||
#[command(Leave = "leave")] fn cmd_mode_leave (&mut self) -> Perhaps<AppCmd> {
|
||||
#[command(Leave = "leave")] fn leave_mode (&mut self) -> Perhaps<AppCmd> {
|
||||
let mut modes = self.modes_mut();
|
||||
if modes.len() > 1 {
|
||||
let mode = modes.pop();
|
||||
|
|
@ -85,6 +136,13 @@ impl_from!(AppCmd: |x: TracksCmd| AppCmd::Tracks { command: x });
|
|||
}
|
||||
/// Commands pertaining to the MIDI clip editor.
|
||||
#[command(MidiEdit = "edit")] pub fn cmd_midi_edit (&mut self, command: MidiEditCmd) -> Perhaps<AppCmd> {
|
||||
if matches!(command, MidiEditCmd::Toggle) {
|
||||
if self.is_editing() {
|
||||
self.leave_mode()?;
|
||||
} else {
|
||||
self.enter_mode("Edit".into())?;
|
||||
}
|
||||
}
|
||||
Ok(command.dispatch(self)?.map(Into::into))
|
||||
}
|
||||
#[command(Scene = "scene")] pub fn cmd_scene (&mut self, command: SceneCmd) -> Perhaps<AppCmd> {
|
||||
|
|
@ -512,7 +570,8 @@ impl<T: HasScene
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: HasClip + HasEditor
|
||||
impl<T: HasClip
|
||||
+ HasEditor
|
||||
+ Namespace<u32>
|
||||
+ Namespace<f64>
|
||||
+ Namespace<bool>
|
||||
|
|
@ -521,7 +580,8 @@ impl<T: HasClip + HasEditor
|
|||
+ Namespace<ClipSlot>
|
||||
> MidiEditControl for T {}
|
||||
|
||||
#[tek_proc::commands(MidiEditCmd)] pub trait MidiEditControl: HasClip + HasEditor
|
||||
#[tek_proc::commands(MidiEditCmd)] pub trait MidiEditControl: HasClip
|
||||
+ HasEditor
|
||||
+ Namespace<u32>
|
||||
+ Namespace<f64>
|
||||
+ Namespace<bool>
|
||||
|
|
@ -533,29 +593,12 @@ impl<T: HasClip + HasEditor
|
|||
if self.is_editing() {
|
||||
*self.editor_mut() = None;
|
||||
} else if let Some(clip) = self.clip() {
|
||||
let editor = MidiEditor {
|
||||
mode: PianoHorizontal {
|
||||
keys_width: 4,
|
||||
range: MidiSelection {
|
||||
time_len: Arc::new(96usize.into()),
|
||||
time_zoom: Arc::new(1usize.into()),
|
||||
note_axis: Arc::new(12usize.into()),
|
||||
..Default::default()
|
||||
},
|
||||
size: Sizer(
|
||||
Arc::new(16usize.into()),
|
||||
Arc::new(6usize.into()),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
size: Sizer(
|
||||
Arc::new(20usize.into()),
|
||||
Arc::new(6usize.into()),
|
||||
),
|
||||
};
|
||||
let editor = MidiEditor::new();
|
||||
*editor.mode.clip.0.write() = clip.clone();
|
||||
editor.redraw();
|
||||
*self.editor_mut() = Some(editor);
|
||||
} else {
|
||||
return Ok(None)
|
||||
}
|
||||
Ok(Some(MidiEditCmd::Toggle))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue