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)))
("edit" [c: bool]
Some(Self::Edit(c)))
("color" [c: Color]
("color" []
Some(Self::Color(ItemPalette::random())))
("color" [c: Color]
Some(Self::Color(c.map(ItemPalette::from).expect("no color"))))

View file

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