mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
midi: return old values from cursor traits
This commit is contained in:
parent
397e71edee
commit
e9c825e865
6 changed files with 76 additions and 92 deletions
|
|
@ -14,38 +14,45 @@ expose!([self: Sampler]
|
|||
|
||||
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"))))
|
||||
("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]
|
||||
("import" [,..a]
|
||||
FileBrowserCommand::try_from_expr(state, a).map(Self::Import))
|
||||
("select" [i: usize]
|
||||
("select" [i: usize]
|
||||
Some(Self::Select(i.expect("no index"))))
|
||||
("record/begin" [i: u7]
|
||||
("record/begin" [i: u7]
|
||||
Some(Self::RecordBegin(i.expect("no index"))))
|
||||
("record/cancel" []
|
||||
Some(Self::RecordCancel))
|
||||
("record/finish" []
|
||||
("record/finish" []
|
||||
Some(Self::RecordFinish))
|
||||
("set/sample" [i: u7, s: Option<Arc<RwLock<Sample>>>]
|
||||
("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]
|
||||
("set/start" [i: u7, s: usize]
|
||||
Some(Self::SetStart(i.expect("no index"), s.expect("no start"))))
|
||||
("set/gain" [i: u7, g: f32]
|
||||
("set/gain" [i: u7, g: f32]
|
||||
Some(Self::SetGain(i.expect("no index"), g.expect("no gain"))))
|
||||
("note/on" [p: u7, v: u7]
|
||||
("note/on" [p: u7, v: u7]
|
||||
Some(Self::NoteOn(p.expect("no pitch"), v.expect("no velocity"))))
|
||||
("note/off" [p: u7]
|
||||
("note/off" [p: u7]
|
||||
Some(Self::NoteOff(p.expect("no pitch"))))));
|
||||
|
||||
defcom! { |self, state: Sampler|
|
||||
SamplerCommand {
|
||||
|
||||
Import(cmd: FileBrowserCommand) => match cmd {
|
||||
defcom!([self, state: Sampler]
|
||||
(SamplerCommand
|
||||
(Select [i: usize] Some(Self::Select(state.set_note_pos(i))))
|
||||
(RecordBegin [p: u7] { state.begin_recording(p.as_int() as usize); None })
|
||||
(RecordCancel [] { state.cancel_recording(); None })
|
||||
(RecordFinish [] { state.finish_recording(); None })
|
||||
(SetStart [pitch: u7, frame: usize] { println!("\n\rtodo: {self:?}"); None })
|
||||
(SetGain [pitch: u7, gain: f32] { println!("\n\rtodo: {self:?}"); None })
|
||||
(NoteOn [pitch: u7, velocity: u7] { println!("\n\rtodo: {self:?}"); None })
|
||||
(NoteOff [pitch: u7] { println!("\n\rtodo: {self:?}"); None })
|
||||
(Import [cmd: FileBrowserCommand] match cmd {
|
||||
FileBrowserCommand::Begin => {
|
||||
//let voices = &state.state.voices;
|
||||
//let sample = Arc::new(RwLock::new(Sample::new("", 0, 0, vec![])));
|
||||
|
|
@ -56,56 +63,10 @@ defcom! { |self, state: Sampler|
|
|||
println!("\n\rtodo: import: filebrowser: {cmd:?}");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
Select(index: usize) => {
|
||||
let old = state.note_pos();
|
||||
state.set_note_pos(index);
|
||||
Some(Self::Select(old))
|
||||
}
|
||||
|
||||
RecordBegin(pitch: u7) => {
|
||||
state.begin_recording(pitch.as_int() as usize);
|
||||
None
|
||||
}
|
||||
|
||||
RecordCancel => {
|
||||
state.cancel_recording();
|
||||
None
|
||||
}
|
||||
|
||||
RecordFinish => {
|
||||
state.finish_recording();
|
||||
None
|
||||
}
|
||||
|
||||
SetSample(pitch: u7, sample: Option<Arc<RwLock<Sample>>>) => {
|
||||
})
|
||||
(SetSample [pitch: u7, sample: Option<Arc<RwLock<Sample>>>] {
|
||||
let i = pitch.as_int() as usize;
|
||||
let old = state.mapped[i].clone();
|
||||
state.mapped[i] = sample;
|
||||
Some(Self::SetSample(pitch, old))
|
||||
}
|
||||
|
||||
SetStart(pitch: u7, frame: usize) => {
|
||||
println!("\n\rtodo: {self:?}");
|
||||
None
|
||||
}
|
||||
|
||||
SetGain(pitch: u7, gain: f32) => {
|
||||
println!("\n\rtodo: {self:?}");
|
||||
None
|
||||
}
|
||||
|
||||
NoteOn(pitch: u7, velocity: u7) => {
|
||||
println!("\n\rtodo: {self:?}");
|
||||
None
|
||||
}
|
||||
|
||||
NoteOff(pitch: u7) => {
|
||||
println!("\n\rtodo: {self:?}");
|
||||
None
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
})));
|
||||
|
|
|
|||
|
|
@ -123,15 +123,16 @@ impl NoteRange for Sampler {
|
|||
}
|
||||
|
||||
impl NotePoint for Sampler {
|
||||
fn note_len (&self) -> usize {0/*TODO*/}
|
||||
fn set_note_len (&self, x: usize) {}
|
||||
fn note_len (&self) -> usize { 0/*TODO*/ }
|
||||
fn set_note_len (&self, x: usize) -> usize { 0 /*TODO*/ }
|
||||
fn note_pos (&self) -> usize {
|
||||
self.note_pt.load(Relaxed)
|
||||
}
|
||||
fn set_note_pos (&self, x: usize) {
|
||||
self.note_pt.store(x, Relaxed);
|
||||
fn set_note_pos (&self, x: usize) -> usize {
|
||||
let old = self.note_pt.swap(x, Relaxed);
|
||||
self.cursor.0.store(x % 8, Relaxed);
|
||||
self.cursor.1.store(x / 8, Relaxed);
|
||||
old
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue