mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
refactor sampler, flatten arranger
This commit is contained in:
parent
a9d22bd26f
commit
9f70441627
28 changed files with 1816 additions and 1836 deletions
119
crates/sampler/src/sampler_api.rs
Normal file
119
crates/sampler/src/sampler_api.rs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
use crate::*;
|
||||
provide!(Arc<str>: |self: Sampler| {});
|
||||
provide!(Option<Arc<RwLock<Sample>>>: |self: Sampler| {});
|
||||
provide!(PathBuf: |self: Sampler| {});
|
||||
provide!(f32: |self: Sampler| {});
|
||||
provide!(u7: |self: Sampler| {});
|
||||
provide!(usize: |self: Sampler| {});
|
||||
|
||||
//handle!(TuiIn: |self: Sampler, input|SamplerCommand::execute_with_state(self, input.event()));
|
||||
//input_to_command!(SamplerCommand: |state: Sampler, input: Event|match state.mode{
|
||||
//Some(SamplerMode::Import(..)) => Self::Import(
|
||||
//FileBrowserCommand::input_to_command(state, input)?
|
||||
//),
|
||||
//_ => match input {
|
||||
//// load sample
|
||||
//kpat!(Shift-Char('L')) => Self::Import(FileBrowserCommand::Begin),
|
||||
//kpat!(KeyCode::Up) => Self::Select(state.note_pos().overflowing_add(1).0.min(127)),
|
||||
//kpat!(KeyCode::Down) => Self::Select(state.note_pos().overflowing_sub(1).0.min(127)),
|
||||
//_ => return None
|
||||
//}
|
||||
//});
|
||||
|
||||
defcom! { |self, state: Sampler|
|
||||
|
||||
SamplerCommand {
|
||||
|
||||
Import(cmd: FileBrowserCommand) => match cmd {
|
||||
FileBrowserCommand::Begin => {
|
||||
//let voices = &state.state.voices;
|
||||
//let sample = Arc::new(RwLock::new(Sample::new("", 0, 0, vec![])));
|
||||
state.mode = Some(SamplerMode::Import(0, FileBrowser::new(None)?));
|
||||
None
|
||||
},
|
||||
_ => {
|
||||
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>>>) => {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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| {
|
||||
("select" [i: usize]
|
||||
Some(Self::Select(i.expect("no index"))))
|
||||
("import" [,..a]
|
||||
FileBrowserCommand::try_from_expr(state, a).map(Self::Import))
|
||||
("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")))) });
|
||||
Loading…
Add table
Add a link
Reference in a new issue