mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
177 lines
6.8 KiB
Rust
177 lines
6.8 KiB
Rust
use crate::*;
|
|
|
|
#[tengri_proc::expose]
|
|
impl Sampler {
|
|
//fn file_browser_filter (&self) -> Arc<str> {
|
|
//todo!()
|
|
//}
|
|
//fn file_browser_path (&self) -> PathBuf {
|
|
//todo!();
|
|
//}
|
|
///// Immutable reference to sample at cursor.
|
|
//fn sample_selected (&self) -> Option<Arc<RwLock<Sample>>> {
|
|
//for (i, sample) in self.mapped.iter().enumerate() {
|
|
//if i == self.cursor().0 {
|
|
//return sample.as_ref()
|
|
//}
|
|
//}
|
|
//for (i, sample) in self.unmapped.iter().enumerate() {
|
|
//if i + self.mapped.len() == self.cursor().0 {
|
|
//return Some(sample)
|
|
//}
|
|
//}
|
|
//None
|
|
//}
|
|
//fn sample_gain (&self) -> f32 {
|
|
//todo!()
|
|
//}
|
|
//fn sample_above () -> usize {
|
|
//self.note_pos().min(119) + 8
|
|
//}
|
|
//fn sample_below () -> usize {
|
|
//self.note_pos().max(8) - 8
|
|
//}
|
|
//fn sample_to_left () -> usize {
|
|
//self.note_pos().min(126) + 1
|
|
//}
|
|
//fn sample_to_right () -> usize {
|
|
//self.note_pos().max(1) - 1
|
|
//}
|
|
//fn selected_pitch () -> u7 {
|
|
//(self.note_pos() as u8).into() // TODO
|
|
//}
|
|
fn sample_selected (&self) -> usize {
|
|
(self.get_note_pos() as u8).into()
|
|
}
|
|
fn sample_selected_pitch (&self) -> u7 {
|
|
(self.get_note_pos() as u8).into()
|
|
}
|
|
}
|
|
|
|
#[tengri_proc::command(Sampler)]
|
|
impl SamplerCommand {
|
|
fn record_toggle (sampler: &mut Sampler, sample: usize) -> Perhaps<Self> {
|
|
if sampler.recording.is_some() {
|
|
Self::record_finish(sampler)
|
|
} else {
|
|
Self::record_begin(sampler, sample)
|
|
}
|
|
}
|
|
fn record_begin (sampler: &mut Sampler, sample: usize) -> Perhaps<Self> {
|
|
sampler.recording = Some((
|
|
sample,
|
|
Arc::new(RwLock::new(Sample::new(
|
|
"Sample",
|
|
0,
|
|
0,
|
|
vec![vec![];sampler.audio_ins.len()]
|
|
)))
|
|
));
|
|
Ok(None)
|
|
}
|
|
fn record_finish (sampler: &mut Sampler) -> Perhaps<Self> {
|
|
let recording = sampler.recording.take();
|
|
let _sample = if let Some((index, sample)) = recording {
|
|
let old = sampler.mapped[index].clone();
|
|
sampler.mapped[index] = Some(sample);
|
|
old
|
|
} else {
|
|
None
|
|
};
|
|
Ok(None)
|
|
}
|
|
fn record_cancel (sampler: &mut Sampler) -> Perhaps<Self> {
|
|
sampler.recording = None;
|
|
Ok(None)
|
|
}
|
|
//fn select (&self, state: &mut Sampler, i: usize) -> Option<Self> {
|
|
//Self::Select(state.set_note_pos(i))
|
|
//}
|
|
///// Assign sample to pitch
|
|
//fn set (&self, pitch: u7, sample: Option<Arc<RwLock<Sample>>>) -> Option<Self> {
|
|
//let i = pitch.as_int() as usize;
|
|
//let old = self.mapped[i].clone();
|
|
//self.mapped[i] = sample;
|
|
//Some(Self::Set(old))
|
|
//}
|
|
//fn set_start (&self, state: &mut Sampler, pitch: u7, frame: usize) -> Option<Self> {
|
|
//todo!()
|
|
//}
|
|
//fn set_gain (&self, state: &mut Sampler, pitch: u7, g: f32) -> Option<Self> {
|
|
//todo!()
|
|
//}
|
|
//fn note_on (&self, state: &mut Sampler, pitch: u7, v: u7) -> Option<Self> {
|
|
//todo!()
|
|
//}
|
|
//fn note_off (&self, state: &mut Sampler, pitch: u7) -> Option<Self> {
|
|
//todo!()
|
|
//}
|
|
//fn set_sample (&self, state: &mut Sampler, pitch: u7, s: Option<Arc<RwLock<Sample>>>) -> Option<Self> {
|
|
//Some(Self::SetSample(p, state.set_sample(p, s)))
|
|
//}
|
|
//fn import (&self, state: &mut Sampler, c: FileBrowserCommand) -> Option<Self> {
|
|
//match c {
|
|
//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: {c:?}");
|
|
//None
|
|
//}
|
|
//}
|
|
//}
|
|
////(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: Option<Arc<RwLock<Sample>>>] 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![])));
|
|
////state.mode = Some(SamplerMode::Import(0, FileBrowser::new(None)?));
|
|
////None
|
|
////},
|
|
////_ => {
|
|
////println!("\n\rtodo: import: filebrowser: {c:?}");
|
|
////None
|
|
////}
|
|
////})));
|
|
////("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"))))));
|
|
}
|
|
|
|
#[tengri_proc::command(Sampler)]
|
|
impl 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")))))
|
|
}
|