mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
sampler: arrows select slot
This commit is contained in:
parent
b376d75396
commit
2877545140
3 changed files with 38 additions and 21 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue