add defcom! macro

This commit is contained in:
🪞👃🪞 2025-04-24 00:47:57 +03:00
parent ab37e2e7d4
commit 5db97825cc
2 changed files with 69 additions and 54 deletions

View file

@ -100,7 +100,7 @@ impose!([app: Tek] {
Some(Self::Edit(None))) Some(Self::Edit(None)))
("edit" [c: bool] ("edit" [c: bool]
Some(Self::Edit(c))) Some(Self::Edit(c)))
("color" [c: Color] ("color" []
Some(Self::Color(ItemPalette::random()))) Some(Self::Color(ItemPalette::random())))
("color" [c: Color] ("color" [c: Color]
Some(Self::Color(c.map(ItemPalette::from).expect("no color")))) Some(Self::Color(c.map(ItemPalette::from).expect("no color"))))

View file

@ -1,4 +1,5 @@
use crate::*; use crate::*;
handle!(TuiIn: |self: Tek, input|Ok({ handle!(TuiIn: |self: Tek, input|Ok({
// If editing, editor keys take priority // If editing, editor keys take priority
if self.is_editing() { if self.is_editing() {
@ -23,61 +24,75 @@ handle!(TuiIn: |self: Tek, input|Ok({
} }
None None
})); }));
#[derive(Clone, Debug)] pub enum TekCommand {
Clip(ClipCommand), macro_rules! defcom {
Clock(ClockCommand), ($($Command:ident { $(
Color(ItemPalette), $Variant:ident $(($($Param:ty),+))?
Edit(Option<bool>), )* $(,)? })*) => {
Editor(MidiEditCommand), $(#[derive(Clone, Debug)] pub enum $Command {
Enqueue(Option<Arc<RwLock<MidiClip>>>), $($Variant $(($($Param),+))?),*
History(isize), })*
Input(InputCommand), }
Launch,
Output(OutputCommand),
Pool(PoolCommand),
Sampler(SamplerCommand),
Scene(SceneCommand),
Select(Selection),
StopAll,
Track(TrackCommand),
Zoom(Option<usize>),
} }
#[derive(Clone, Debug)] pub enum InputCommand {
Add defcom! {
} TekCommand {
#[derive(Clone, Debug)] pub enum OutputCommand { Clip(ClipCommand)
Add Clock(ClockCommand)
} Color(ItemPalette)
#[derive(Clone, Debug)] pub enum TrackCommand { Edit(Option<bool>)
Add, Editor(MidiEditCommand)
Del(usize), Enqueue(Option<Arc<RwLock<MidiClip>>>)
Stop(usize), History(isize)
Swap(usize, usize), Input(InputCommand)
SetSize(usize), Launch
SetZoom(usize), Output(OutputCommand)
SetColor(usize, ItemPalette), Pool(PoolCommand)
TogglePlay, Sampler(SamplerCommand)
ToggleSolo, Scene(SceneCommand)
ToggleRecord, Select(Selection)
ToggleMonitor, StopAll
} Track(TrackCommand)
#[derive(Clone, Debug)] pub enum SceneCommand { Zoom(Option<usize>)
Add, }
Del(usize), InputCommand {
Swap(usize, usize), Add
SetSize(usize), }
SetZoom(usize), OutputCommand {
SetColor(usize, ItemPalette), Add
Enqueue(usize), }
} TrackCommand {
#[derive(Clone, Debug)] pub enum ClipCommand { Add
Get(usize, usize), Del(usize)
Put(usize, usize, Option<Arc<RwLock<MidiClip>>>), Stop(usize)
Enqueue(usize, usize), Swap(usize, usize)
Edit(Option<Arc<RwLock<MidiClip>>>), SetSize(usize)
SetLoop(usize, usize, bool), SetZoom(usize)
SetColor(usize, usize, ItemPalette), SetColor(usize, ItemPalette)
TogglePlay
ToggleSolo
ToggleRecord
ToggleMonitor
}
SceneCommand {
Add
Del(usize)
Swap(usize, usize)
SetSize(usize)
SetZoom(usize)
SetColor(usize, ItemPalette)
Enqueue(usize)
}
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)
}
} }
command!(|self: TekCommand, app: Tek|match self { command!(|self: TekCommand, app: Tek|match self {
Self::Zoom(_) => { println!("\n\rtodo: global zoom"); None }, Self::Zoom(_) => { println!("\n\rtodo: global zoom"); None },
Self::History(delta) => { println!("\n\rtodo: undo/redo"); None }, Self::History(delta) => { println!("\n\rtodo: undo/redo"); None },