sampler: arrows select slot

This commit is contained in:
🪞👃🪞 2025-04-25 20:56:36 +03:00
parent b376d75396
commit 2877545140
3 changed files with 38 additions and 21 deletions

View file

@ -14,14 +14,16 @@ pub struct Sampler {
pub audio_outs: Vec<JackAudioOut>,
pub buffer: Vec<Vec<f32>>,
pub output_gain: f32,
pub cursor: (usize, usize),
pub editing: Option<Arc<RwLock<Sample>>>,
pub mode: Option<SamplerMode>,
/// Size of actual notes area
pub size: Measure<TuiOut>,
/// Lowest note displayed
pub note_lo: AtomicUsize,
/// Selected note
pub note_pt: AtomicUsize,
/// Selected note as row/col
pub cursor: (AtomicUsize, AtomicUsize),
pub color: ItemPalette
}
@ -40,11 +42,11 @@ impl Default for Sampler {
output_gain: 1.,
recording: None,
mode: None,
cursor: (0, 0),
editing: None,
size: Default::default(),
note_lo: 0.into(),
note_pt: 0.into(),
cursor: (0.into(), 0.into()),
color: Default::default(),
}
}
@ -94,17 +96,43 @@ impl Sampler {
/// Immutable reference to sample at cursor.
pub fn sample (&self) -> Option<&Arc<RwLock<Sample>>> {
for (i, sample) in self.mapped.iter().enumerate() {
if i == self.cursor.0 {
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 {
if i + self.mapped.len() == self.cursor().0 {
return Some(sample)
}
}
None
}
/// Value of cursor
pub fn cursor (&self) -> (usize, usize) {
(self.cursor.0.load(Relaxed), self.cursor.1.load(Relaxed))
}
}
impl NoteRange for Sampler {
fn note_lo (&self) -> &AtomicUsize {
&self.note_lo
}
fn note_axis (&self) -> &AtomicUsize {
&self.size.y
}
}
impl NotePoint for Sampler {
fn note_len (&self) -> usize {0/*TODO*/}
fn set_note_len (&self, x: usize) {}
fn note_pos (&self) -> usize {
self.note_pt.load(Relaxed)
}
fn set_note_pos (&self, x: usize) {
self.note_pt.store(x, Relaxed);
self.cursor.0.store(x % 8, Relaxed);
self.cursor.1.store(x / 8, Relaxed);
}
}
/// A sound sample.