EdnProvide

This commit is contained in:
🪞👃🪞 2025-01-12 13:32:11 +01:00
parent 794d4210c6
commit fc06fb863b
7 changed files with 126 additions and 61 deletions

View file

@ -1,22 +1,37 @@
use crate::*;
use self::MidiEditCommand::*;
use KeyCode::*;
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!()
}
}
}
edn_provide!(bool: |self: MidiEditor|{
":true" => true,
":false" => false
});
edn_provide!(usize: |self: MidiEditor|{
":note-length" => self.note_len(),
":note-point" => self.note_point(),
":time-point" => self.time_point(),
":time-zoom" => self.time_zoom().get(),
});
edn_command!(MidiEditCommand: |state: MidiEditor| {
("note/put" [a: bool] Self::PutNote)
("note/del" [a: bool] Self::PutNote)
("note/dur" [a: usize] Self::SetNoteCursor(a))
});
//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,