wip: let's figure out how edn keymaps will work

This commit is contained in:
🪞👃🪞 2025-01-12 13:01:15 +01:00
parent 4ab08e48e5
commit 794d4210c6
33 changed files with 161 additions and 85 deletions

View file

@ -13,7 +13,7 @@ pub trait HasMidiClip {
}
/// A MIDI sequence.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct MidiClip {
pub uuid: uuid::Uuid,
/// Name of clip
@ -83,10 +83,7 @@ impl MidiClip {
}
false
}
}
impl Default for MidiClip {
fn default () -> Self {
pub fn stop_all () -> Self {
Self::new(
"Stop",
false,

View file

@ -1,8 +1,23 @@
use crate::*;
use self::MidiEditCommand::*;
use KeyCode::*;
#[derive(Clone, Debug)]
pub enum MidiEditCommand {
impl EdnCommand<MidiEditor> for MidiEditCommand {
fn from_edn <'a> (state: &MidiEditor, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
use EdnItem::*;
match (head, tail) {
(Key("note/put"), [a]) => Self::PutNote,
(Key("note/del"), [a]) => Self::AppendNote,
(Key("note/dur"), [a]) => Self::AppendNote,
(Key("note/range"), [a]) => Self::AppendNote,
(Key("note/pos"), [a]) => Self::AppendNote,
(Key("time/pos"), [a]) => Self::AppendNote,
(Key("time/zoom"), [a]) => Self::AppendNote,
(Key("time/lock"), [a]) => Self::AppendNote,
_ => todo!()
}
}
}
#[derive(Clone, Debug)] pub enum MidiEditCommand {
// TODO: 1-9 seek markers that by default start every 8th of the clip
AppendNote,
PutNote,
@ -70,8 +85,3 @@ impl Command<MidiEditor> for MidiEditCommand {
Ok(None)
}
}
impl EdnCommand<MidiEditor> for MidiEditCommand {
fn from_edn <'a> (state: &MidiEditor, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
todo!()
}
}

View file

@ -135,34 +135,3 @@ impl ClipLengthFocus {
*self = match self { Self::Bar => Self::Tick, Self::Beat => Self::Bar, Self::Tick => Self::Beat, }
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ClipRenameCommand {
Begin,
Cancel,
Confirm,
Set(Arc<str>),
}
impl Command<PoolModel> for ClipRenameCommand {
fn execute (self, state: &mut PoolModel) -> Perhaps<Self> {
use ClipRenameCommand::*;
match state.clips_mode_mut().clone() {
Some(PoolMode::Rename(clip, ref mut old_name)) => match self {
Set(s) => {
state.clips()[clip].write().unwrap().name = s;
return Ok(Some(Self::Set(old_name.clone().into())))
},
Confirm => {
let old_name = old_name.clone();
*state.clips_mode_mut() = None;
return Ok(Some(Self::Set(old_name)))
},
Cancel => {
state.clips()[clip].write().unwrap().name = old_name.clone().into();
},
_ => unreachable!()
},
_ => unreachable!()
};
Ok(None)
}
}

View file

@ -317,7 +317,6 @@ command!(|self: ClipLengthCommand,state:PoolModel|{
};
None
});
input_to_command!(ClipLengthCommand: |state: PoolModel, input: Event|{
if let Some(PoolMode::Length(_, length, _)) = state.clips_mode() {
match input {
@ -333,10 +332,6 @@ input_to_command!(ClipLengthCommand: |state: PoolModel, input: Event|{
unreachable!()
}
});
use crate::*;
use super::*;
impl InputToCommand<Event, PoolModel> for ClipRenameCommand {
fn input_to_command (state: &PoolModel, input: &Event) -> Option<Self> {
use KeyCode::{Char, Backspace, Enter, Esc};
@ -361,3 +356,34 @@ impl InputToCommand<Event, PoolModel> for ClipRenameCommand {
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ClipRenameCommand {
Begin,
Cancel,
Confirm,
Set(Arc<str>),
}
impl Command<PoolModel> for ClipRenameCommand {
fn execute (self, state: &mut PoolModel) -> Perhaps<Self> {
use ClipRenameCommand::*;
match state.clips_mode_mut().clone() {
Some(PoolMode::Rename(clip, ref mut old_name)) => match self {
Set(s) => {
state.clips()[clip].write().unwrap().name = s;
return Ok(Some(Self::Set(old_name.clone().into())))
},
Confirm => {
let old_name = old_name.clone();
*state.clips_mode_mut() = None;
return Ok(Some(Self::Set(old_name)))
},
Cancel => {
state.clips()[clip].write().unwrap().name = old_name.clone().into();
},
_ => unreachable!()
},
_ => unreachable!()
};
Ok(None)
}
}