mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: reenable sampling
This commit is contained in:
parent
e9c825e865
commit
efd182f302
6 changed files with 61 additions and 38 deletions
|
|
@ -2,15 +2,17 @@ use crate::*;
|
|||
|
||||
expose!([self: Sampler]
|
||||
([Arc<str>])
|
||||
([Option<Arc<RwLock<Sample>>>])
|
||||
([MaybeSample])
|
||||
([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)));
|
||||
([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:
|
||||
|
|
@ -31,7 +33,7 @@ impose!([state: Sampler]
|
|||
Some(Self::RecordCancel))
|
||||
("record/finish" []
|
||||
Some(Self::RecordFinish))
|
||||
("set/sample" [i: u7, s: Option<Arc<RwLock<Sample>>>]
|
||||
("set/sample" [i: u7, s: MaybeSample]
|
||||
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"))))
|
||||
|
|
@ -42,17 +44,21 @@ impose!([state: Sampler]
|
|||
("note/off" [p: u7]
|
||||
Some(Self::NoteOff(p.expect("no pitch"))))));
|
||||
|
||||
macro_rules! cmd { ($cmd:expr) => {{ $cmd; None }}; }
|
||||
macro_rules! cmd_todo { ($msg:literal) => {{ println!($msg); None }}; }
|
||||
|
||||
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 {
|
||||
(Select [i: usize] Some(Self::Select(state.set_note_pos(i))))
|
||||
(RecordBegin [p: u7] cmd!(state.begin_recording(p.as_int() as usize)))
|
||||
(RecordCancel [] cmd!(state.cancel_recording()))
|
||||
(RecordFinish [] cmd!(state.finish_recording()))
|
||||
(SetStart [p: u7, frame: usize] cmd_todo!("\n\rtodo: {self:?}"))
|
||||
(SetGain [p: u7, gain: f32] cmd_todo!("\n\rtodo: {self:?}"))
|
||||
(NoteOn [p: u7, velocity: u7] cmd_todo!("\n\rtodo: {self:?}"))
|
||||
(NoteOff [p: u7] cmd_todo!("\n\rtodo: {self:?}"))
|
||||
(SetSample [p: u7, s: MaybeSample] Some(Self::SetSample(p, state.set_sample(p, s))))
|
||||
(Import [c: FileBrowserCommand] match c {
|
||||
FileBrowserCommand::Begin => {
|
||||
//let voices = &state.state.voices;
|
||||
//let sample = Arc::new(RwLock::new(Sample::new("", 0, 0, vec![])));
|
||||
|
|
@ -60,13 +66,7 @@ defcom!([self, state: Sampler]
|
|||
None
|
||||
},
|
||||
_ => {
|
||||
println!("\n\rtodo: import: filebrowser: {cmd:?}");
|
||||
println!("\n\rtodo: import: filebrowser: {c:?}");
|
||||
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))
|
||||
})));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
use crate::*;
|
||||
|
||||
pub type MaybeSample = Option<Arc<RwLock<Sample>>>;
|
||||
|
||||
/// The sampler device plays sounds in response to MIDI notes.
|
||||
#[derive(Debug)]
|
||||
pub struct Sampler {
|
||||
pub name: String,
|
||||
pub mapped: [Option<Arc<RwLock<Sample>>>;128],
|
||||
pub mapped: [MaybeSample;128],
|
||||
pub recording: Option<(usize, Arc<RwLock<Sample>>)>,
|
||||
pub unmapped: Vec<Arc<RwLock<Sample>>>,
|
||||
pub voices: Arc<RwLock<Vec<Voice>>>,
|
||||
|
|
@ -14,7 +16,7 @@ pub struct Sampler {
|
|||
pub audio_outs: Vec<JackAudioOut>,
|
||||
pub buffer: Vec<Vec<f32>>,
|
||||
pub output_gain: f32,
|
||||
pub editing: Option<Arc<RwLock<Sample>>>,
|
||||
pub editing: MaybeSample,
|
||||
pub mode: Option<SamplerMode>,
|
||||
/// Size of actual notes area
|
||||
pub size: Measure<TuiOut>,
|
||||
|
|
@ -83,7 +85,7 @@ impl Sampler {
|
|||
Arc::new(RwLock::new(Sample::new("Sample", 0, 0, vec![vec![];self.audio_ins.len()])))
|
||||
));
|
||||
}
|
||||
pub fn finish_recording (&mut self) -> Option<Arc<RwLock<Sample>>> {
|
||||
pub fn finish_recording (&mut self) -> MaybeSample {
|
||||
let recording = self.recording.take();
|
||||
if let Some((index, sample)) = recording {
|
||||
let old = self.mapped[index].clone();
|
||||
|
|
@ -111,6 +113,13 @@ impl Sampler {
|
|||
pub fn cursor (&self) -> (usize, usize) {
|
||||
(self.cursor.0.load(Relaxed), self.cursor.1.load(Relaxed))
|
||||
}
|
||||
/// Assign sample to pitch
|
||||
pub fn set_sample (&mut self, pitch: u7, sample: MaybeSample) -> MaybeSample {
|
||||
let i = pitch.as_int() as usize;
|
||||
let old = self.mapped[i].clone();
|
||||
self.mapped[i] = sample;
|
||||
old
|
||||
}
|
||||
}
|
||||
|
||||
impl NoteRange for Sampler {
|
||||
|
|
@ -123,8 +132,12 @@ impl NoteRange for Sampler {
|
|||
}
|
||||
|
||||
impl NotePoint for Sampler {
|
||||
fn note_len (&self) -> usize { 0/*TODO*/ }
|
||||
fn set_note_len (&self, x: usize) -> usize { 0 /*TODO*/ }
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue