convert all def_command! to #[commands]
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
i do not exist 2026-08-10 12:11:17 +03:00
parent 7fcab73b04
commit 62f30daac6
6 changed files with 295 additions and 195 deletions

View file

@ -46,40 +46,83 @@ pub struct Arrangement {
#[cfg(feature = "scene")] pub scene_scroll: usize,
}
def_command!(TrackCommand: |track: Track| {
Stop => { track.sequencer.enqueue_next(None); Ok(None) },
SetRec { rec: Option<bool> } => toggle_bool(&mut track.sequencer.recording, rec, |rec|Self::SetRec { rec }),
SetMon { mon: Option<bool> } => toggle_bool(&mut track.sequencer.monitoring, mon, |mon|Self::SetMon { mon }),
SetMute { mute: Option<bool> } => todo!(),
SetSolo { solo: Option<bool> } => todo!(),
SetSize { size: usize } => todo!(),
SetZoom { zoom: usize } => todo!(),
SetName { name: Arc<str> } => swap_value(&mut track.name, name, |name|Self::SetName { name }),
SetColor { color: ItemTheme } => swap_value(&mut track.color, color, |color|Self::SetColor { color }),
});
#[tek_proc::commands(TrackCommand = "track")]
impl Track {
#[command(Stop = "stop")]
fn stop (&mut self) -> Perhaps<TrackCommand> {
self.sequencer.enqueue_next(None);
Ok(None)
}
#[command(SetRec = "rec")]
fn set_rec (&mut self, rec: Option<bool>) -> Perhaps<TrackCommand> {
toggle_bool(&mut self.sequencer.recording, &rec, |rec|TrackCommand::SetRec { rec })
}
#[command(SetMon = "mon")]
fn set_mon (&mut self, mon: Option<bool>) -> Perhaps<TrackCommand> {
toggle_bool(&mut self.sequencer.monitoring, &mon, |mon|TrackCommand::SetMon { mon })
}
#[command(SetMute = "mute")]
fn set_mute (&mut self, mute: Option<bool>) -> Perhaps<TrackCommand> {
todo!()
}
#[command(SetSolo = "solo")]
fn set_solo (&mut self, solo: Option<bool>) -> Perhaps<TrackCommand> {
todo!()
}
#[command(SetSize = "size")]
fn set_size (&mut self, size: usize) -> Perhaps<TrackCommand> {
todo!()
}
#[command(SetZoom = "zoom")]
fn set_zoom (&mut self, zoom: usize) -> Perhaps<TrackCommand> {
todo!()
}
#[command(SetName = "name")]
fn set_name (&mut self, name: Arc<str>) -> Perhaps<TrackCommand> {
swap_value(&mut self.name, &name, |name|TrackCommand::SetName { name })
}
#[command(SetColor = "color")]
fn set_color (&mut self, color: ItemTheme) -> Perhaps<TrackCommand> {
swap_value(&mut self.color, &color, |color|TrackCommand::SetColor { color })
}
}
def_command!(SceneCommand: |scene: Scene| {
SetSize { size: usize } => { todo!() },
SetZoom { size: usize } => { todo!() },
SetName { name: Arc<str> } =>
swap_value(&mut scene.name, name, |name|Self::SetName{name}),
SetColor { color: ItemTheme } =>
swap_value(&mut scene.color, color, |color|Self::SetColor{color}),
});
#[tek_proc::commands(SceneCommand = "scene")]
impl Scene {
#[command(SetSize = "size")]
fn set_size (&mut self, size: usize) -> Perhaps<SceneCommand> {
todo!()
}
#[command(SetZoom = "zoom")]
fn set_zoom (&mut self, size: usize) -> Perhaps<SceneCommand> {
todo!()
}
#[command(SetName = "name")]
fn set_name (&mut self, name: Arc<str>) -> Perhaps<SceneCommand> {
swap_value(&mut self.name, &name, |name|SceneCommand::SetName{name})
}
#[command(SetColor = "color")]
fn set_color (&mut self, color: ItemTheme) -> Perhaps<SceneCommand> {
swap_value(&mut self.color, &color, |color|SceneCommand::SetColor{color})
}
}
def_command!(ClipCommand: |clip: MidiClip| {
SetColor { color: Option<ItemTheme> } => {
#[tek_proc::commands(ClipCommand = "clip")]
impl MidiClip {
#[command(SetColor = "color")]
fn set_color (&mut self, color: Option<ItemTheme>) -> Perhaps<ClipCommand> {
//(SetColor [t: usize, s: usize, c: ItemTheme]
//clip.clip_set_color(t, s, c).map(|o|Self::SetColor(t, s, o)))));
//("color" [a: usize, b: usize] Some(Self::SetColor(a.unwrap(), b.unwrap(), ItemTheme::random())))
todo!()
},
SetLoop { looping: Option<bool> } => {
}
#[command(SetLoop = "loop")]
fn set_loop (&mut self, looping: Option<bool>) -> Perhaps<ClipCommand> {
//(SetLoop [t: usize, s: usize, l: bool] cmd_todo!("\n\rtodo: {self:?}"))
//("loop" [a: usize, b: usize, c: bool] Some(Self::SetLoop(a.unwrap(), b.unwrap(), c.unwrap())))
todo!()
}
});
}
/// Represents the current user selection in the arranger
#[derive(PartialEq, Clone, Copy, Debug, Default)]
@ -1068,3 +1111,27 @@ macro_rules! def_sizes_iter {
def_sizes_iter!(PortsSizes => Arc<str>, [Connect]);
def_sizes_iter!(ScenesSizes => Scene);
def_sizes_iter!(TracksSizes => Track);
fn swap_value <T: Clone + PartialEq, U> (
target: &mut T, value: &T, returned: impl Fn(T)->U
) -> Perhaps<U> {
if *target == *value {
Ok(None)
} else {
let mut value = value.clone();
std::mem::swap(target, &mut value);
Ok(Some(returned(value)))
}
}
fn toggle_bool <U> (
target: &mut bool, value: &Option<bool>, returned: impl Fn(Option<bool>)->U
) -> Perhaps<U> {
let mut value = value.unwrap_or(!*target);
if value == *target {
Ok(None)
} else {
std::mem::swap(target, &mut value);
Ok(Some(returned(Some(value))))
}
}