wip: EdnKeymap

This commit is contained in:
🪞👃🪞 2025-01-12 01:48:43 +01:00
parent 8dcf73c18c
commit 364d617d37
6 changed files with 144 additions and 135 deletions

View file

@ -1,23 +1,78 @@
use crate::*;
use EdnItem::*;
use ClockCommand::{Play, Pause};
use self::ArrangerCommand as Cmd;
pub const TRACK_MIN_WIDTH: usize = 9;
impl Arrangement for App {
fn tracks (&self) -> &Vec<ArrangerTrack> { &self.tracks }
fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack> { &mut self.tracks }
fn scenes (&self) -> &Vec<ArrangerScene> { &self.scenes }
fn scenes_mut (&mut self) -> &mut Vec<ArrangerScene> { &mut self.scenes }
fn selected (&self) -> &ArrangerSelection { &self.selected }
fn selected_mut (&mut self) -> &mut ArrangerSelection { &mut self.selected }
command!(|self: ClipCommand, state: App|match self { _ => todo!("clip command") });
command!(|self: SceneCommand, state: App|match self { _ => todo!("scene command") });
command!(|self: TrackCommand, state: App|match self { _ => todo!("track command") });
#[derive(Clone, Debug)] pub enum ClipCommand {
Get(usize, usize),
Put(usize, usize, Option<Arc<RwLock<MidiClip>>>),
Enqueue(usize, usize),
Edit(Option<Arc<RwLock<MidiClip>>>),
SetLoop(usize, usize, bool),
SetColor(usize, usize, ItemPalette),
}
impl EdnCommand<App> for ClipCommand {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
match (head, tail) {
(Key("get"), [a, b ]) => Self::Get(0, 0),
(Key("put"), [a, b, c ]) => Self::Put(0, 0, None),
(Key("enqueue"), [a, b ]) => Self::Enqueue(0, 0),
(Key("edit"), [a ]) => Self::Edit(None),
(Key("loop"), [a, b, c ]) => Self::SetLoop(0, 0, true),
(Key("color"), [a, b, c ]) => Self::SetColor(0, 0, ItemPalette::random()),
_ => panic!(),
}
}
}
#[derive(Clone, Debug)] pub enum SceneCommand {
Add,
Del(usize),
Swap(usize, usize),
SetSize(usize),
SetZoom(usize),
SetColor(usize, ItemPalette),
Enqueue(usize),
}
impl EdnCommand<App> for SceneCommand {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
match (head, tail) {
(Key("add"), [ ]) => Self::Add,
(Key("del"), [a ]) => Self::Del(0),
(Key("swap"), [a, b ]) => Self::Swap(0, 0),
(Key("size"), [a ]) => Self::SetSize(0),
(Key("zoom"), [a, ]) => Self::SetZoom(0),
(Key("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()),
(Key("enqueue"), [a, ]) => Self::Enqueue(0),
_ => panic!(),
}
}
}
#[derive(Clone, Debug)] pub enum TrackCommand {
Add,
Del(usize),
Stop(usize),
Swap(usize, usize),
SetSize(usize),
SetZoom(usize),
SetColor(usize, ItemPalette),
}
impl EdnCommand<App> for TrackCommand {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
match (head, tail) {
(Key("add"), [ ]) => Self::Add,
(Key("del"), [a ]) => Self::Del(0),
(Key("stop"), [a ]) => Self::Stop(0),
(Key("swap"), [a, b ]) => Self::Swap(0, 0),
(Key("size"), [a ]) => Self::SetSize(0),
(Key("zoom"), [a, ]) => Self::SetZoom(0),
(Key("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()),
_ => panic!(),
}
}
}
//impl Arrangement for Arranger {
//fn tracks (&self) -> &Vec<ArrangerTrack> { &self.tracks }
//fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack> { &mut self.tracks }
//fn scenes (&self) -> &Vec<ArrangerScene> { &self.scenes }
//fn scenes_mut (&mut self) -> &mut Vec<ArrangerScene> { &mut self.scenes }
//fn selected (&self) -> &ArrangerSelection { &self.selected }
//fn selected_mut (&mut self) -> &mut ArrangerSelection { &mut self.selected }
//}
pub trait Arrangement: HasClock + HasJack {
fn tracks (&self) -> &Vec<ArrangerTrack>;
fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack>;
@ -283,3 +338,19 @@ impl ArrangerSelection {
}).into()
}
}
impl Arrangement for App {
fn tracks (&self) -> &Vec<ArrangerTrack> { &self.tracks }
fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack> { &mut self.tracks }
fn scenes (&self) -> &Vec<ArrangerScene> { &self.scenes }
fn scenes_mut (&mut self) -> &mut Vec<ArrangerScene> { &mut self.scenes }
fn selected (&self) -> &ArrangerSelection { &self.selected }
fn selected_mut (&mut self) -> &mut ArrangerSelection { &mut self.selected }
}
//impl Arrangement for Arranger {
//fn tracks (&self) -> &Vec<ArrangerTrack> { &self.tracks }
//fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack> { &mut self.tracks }
//fn scenes (&self) -> &Vec<ArrangerScene> { &self.scenes }
//fn scenes_mut (&mut self) -> &mut Vec<ArrangerScene> { &mut self.scenes }
//fn selected (&self) -> &ArrangerSelection { &self.selected }
//fn selected_mut (&mut self) -> &mut ArrangerSelection { &mut self.selected }
//}

View file

@ -44,10 +44,14 @@ impl EdnCommand<App> for AppCommand {
(Key("select"), [a]) => Self::Select(ArrangerSelection::Mix),
(Key("zoom"), [a]) => Self::Zoom(0),
(Key("clock"), [a, b @ ..]) => Self::Clock(ClockCommand::from_edn(state, &a.to_ref(), b)),
(Key("track"), [a, b @ ..]) => Self::Track(TrackCommand::from_edn(state, &a.to_ref(), b)),
(Key("scene"), [a, b @ ..]) => Self::Scene(SceneCommand::from_edn(state, &a.to_ref(), b)),
(Key("clip"), [a, b @ ..]) => Self::Clip(ClipCommand::from_edn(state, &a.to_ref(), b)),
(Key("clock"), [a, b @ ..]) => Self::Clock(
ClockCommand::from_edn(state, &a.to_ref(), b)),
(Key("track"), [a, b @ ..]) => Self::Track(
TrackCommand::from_edn(state, &a.to_ref(), b)),
(Key("scene"), [a, b @ ..]) => Self::Scene(
SceneCommand::from_edn(state, &a.to_ref(), b)),
(Key("clip"), [a, b @ ..]) => Self::Clip(
ClipCommand::from_edn(state, &a.to_ref(), b)),
(Key("pool"), [a, b @ ..]) if let Some(pool) = state.pool.as_ref() =>
Self::Pool(PoolCommand::from_edn(pool, &a.to_ref(), b)),
@ -147,76 +151,6 @@ command!(|self: AppCommand, state: App|match self {
None
},
});
#[derive(Clone, Debug)] pub enum ClipCommand {
Get(usize, usize),
Put(usize, usize, Option<Arc<RwLock<MidiClip>>>),
Enqueue(usize, usize),
Edit(Option<Arc<RwLock<MidiClip>>>),
SetLoop(usize, usize, bool),
SetColor(usize, usize, ItemPalette),
}
impl EdnCommand<App> for ClipCommand {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
match (head, tail) {
(Key("get"), [a, b ]) => Self::Get(0, 0),
(Key("put"), [a, b, c ]) => Self::Put(0, 0, None),
(Key("enqueue"), [a, b ]) => Self::Enqueue(0, 0),
(Key("edit"), [a ]) => Self::Edit(None),
(Key("loop"), [a, b, c ]) => Self::SetLoop(0, 0, true),
(Key("color"), [a, b, c ]) => Self::SetColor(0, 0, ItemPalette::random()),
_ => panic!(),
}
}
}
command!(|self: ClipCommand, state: App|match self { _ => todo!("clip command") });
#[derive(Clone, Debug)] pub enum SceneCommand {
Add,
Del(usize),
Swap(usize, usize),
SetSize(usize),
SetZoom(usize),
SetColor(usize, ItemPalette),
Enqueue(usize),
}
impl EdnCommand<App> for SceneCommand {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
match (head, tail) {
(Key("add"), [ ]) => Self::Add,
(Key("del"), [a ]) => Self::Del(0),
(Key("swap"), [a, b ]) => Self::Swap(0, 0),
(Key("size"), [a ]) => Self::SetSize(0),
(Key("zoom"), [a, ]) => Self::SetZoom(0),
(Key("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()),
(Key("enqueue"), [a, ]) => Self::Enqueue(0),
_ => panic!(),
}
}
}
command!(|self: SceneCommand, state: App|match self { _ => todo!("scene command") });
#[derive(Clone, Debug)] pub enum TrackCommand {
Add,
Del(usize),
Stop(usize),
Swap(usize, usize),
SetSize(usize),
SetZoom(usize),
SetColor(usize, ItemPalette),
}
impl EdnCommand<App> for TrackCommand {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
match (head, tail) {
(Key("add"), [ ]) => Self::Add,
(Key("del"), [a ]) => Self::Del(0),
(Key("stop"), [a ]) => Self::Stop(0),
(Key("swap"), [a, b ]) => Self::Swap(0, 0),
(Key("size"), [a ]) => Self::SetSize(0),
(Key("zoom"), [a, ]) => Self::SetZoom(0),
(Key("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()),
_ => panic!(),
}
}
}
command!(|self: TrackCommand, state: App|match self { _ => todo!("track command") });
#[derive(Clone, Debug)] pub enum SequencerCommand {
Compact(bool),
History(isize),