api: compact

This commit is contained in:
🪞👃🪞 2025-04-26 21:20:06 +03:00
parent e4808f8fc1
commit 3ef3d5eb6f
22 changed files with 441 additions and 558 deletions

View file

@ -1,25 +1,48 @@
use crate::*;
expose! {
[self: Sampler] {
[Arc<str>] => {}
[Option<Arc<RwLock<Sample>>>] => {}
[PathBuf] => {}
[f32] => {}
[u7] => {
":sample" => (self.note_pos() as u8).into(),
}
[usize] => {
":sample-up" => self.note_pos().min(119) + 8,
":sample-down" => self.note_pos().max(8) - 8,
":sample-left" => self.note_pos().min(126) + 1,
":sample-right" => self.note_pos().max(1) - 1,
}
}
}
expose!([self: Sampler]
([Arc<str>])
([Option<Arc<RwLock<Sample>>>])
([PathBuf])
([f32])
([u7] (":pitch" (self.note_pos() as u8).into()) // TODO
(":sample" (self.note_pos() as u8).into()))
([usize] (":sample-up" self.note_pos().min(119) + 8)
(":sample-down" self.note_pos().max(8) - 8)
(":sample-left" self.note_pos().min(126) + 1)
(":sample-right" self.note_pos().max(1) - 1)));
impose!([state: Sampler]
(FileBrowserCommand:
("begin" [] Some(Self::Begin))
("cancel" [] Some(Self::Cancel))
("confirm" [] Some(Self::Confirm))
("select" [i: usize] Some(Self::Select(i.expect("no index"))))
("chdir" [p: PathBuf] Some(Self::Chdir(p.expect("no path"))))
("filter" [f: Arc<str>] Some(Self::Filter(f.expect("no filter")))))
(SamplerCommand:
("import" [,..a]
FileBrowserCommand::try_from_expr(state, a).map(Self::Import))
("select" [i: usize]
Some(Self::Select(i.expect("no index"))))
("record/begin" [i: u7]
Some(Self::RecordBegin(i.expect("no index"))))
("record/cancel" []
Some(Self::RecordCancel))
("record/finish" []
Some(Self::RecordFinish))
("set/sample" [i: u7, s: Option<Arc<RwLock<Sample>>>]
Some(Self::SetSample(i.expect("no index"), s.expect("no sampler"))))
("set/start" [i: u7, s: usize]
Some(Self::SetStart(i.expect("no index"), s.expect("no start"))))
("set/gain" [i: u7, g: f32]
Some(Self::SetGain(i.expect("no index"), g.expect("no gain"))))
("note/on" [p: u7, v: u7]
Some(Self::NoteOn(p.expect("no pitch"), v.expect("no velocity"))))
("note/off" [p: u7]
Some(Self::NoteOff(p.expect("no pitch"))))));
defcom! { |self, state: Sampler|
SamplerCommand {
Import(cmd: FileBrowserCommand) => match cmd {
@ -86,28 +109,3 @@ defcom! { |self, state: Sampler|
}
}
atom_command!(FileBrowserCommand: |state: Sampler| {
("begin" [] Some(Self::Begin))
("cancel" [] Some(Self::Cancel))
("confirm" [] Some(Self::Confirm))
("select" [i: usize] Some(Self::Select(i.expect("no index"))))
("chdir" [p: PathBuf] Some(Self::Chdir(p.expect("no path"))))
("filter" [f: Arc<str>] Some(Self::Filter(f.expect("no filter")))) });
atom_command!(SamplerCommand: |state: Sampler| {
("import" [,..a] FileBrowserCommand::try_from_expr(state, a).map(Self::Import))
("select" [i: usize] Some(Self::Select(i.expect("no index"))))
("record/begin" [i: u7] Some(Self::RecordBegin(i.expect("no index"))))
("record/cancel" [] Some(Self::RecordCancel))
("record/finish" [] Some(Self::RecordFinish))
("set/sample" [i: u7, s: Option<Arc<RwLock<Sample>>>]
Some(Self::SetSample(i.expect("no index"), s.expect("no sampler"))))
("set/start" [i: u7, s: usize]
Some(Self::SetStart(i.expect("no index"), s.expect("no start"))))
("set/gain" [i: u7, g: f32]
Some(Self::SetGain(i.expect("no index"), g.expect("no garin"))))
("note/on" [p: u7, v: u7]
Some(Self::NoteOn(p.expect("no pitch"), v.expect("no velocity"))))
("note/off" [p: u7]
Some(Self::NoteOff(p.expect("no pitch")))) });