mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
sampler: arrows select slot
This commit is contained in:
parent
b376d75396
commit
2877545140
3 changed files with 38 additions and 21 deletions
|
|
@ -8,10 +8,10 @@ expose! {
|
||||||
[f32] => {}
|
[f32] => {}
|
||||||
[u7] => {}
|
[u7] => {}
|
||||||
[usize] => {
|
[usize] => {
|
||||||
":sample-up" => 0,
|
":sample-up" => self.note_pos().min(119) + 8,
|
||||||
":sample-down" => 0,
|
":sample-down" => self.note_pos().max(8) - 8,
|
||||||
":sample-left" => 0,
|
":sample-left" => self.note_pos().min(126) + 1,
|
||||||
":sample-right" => 0,
|
":sample-right" => self.note_pos().max(1) - 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,16 @@ pub struct Sampler {
|
||||||
pub audio_outs: Vec<JackAudioOut>,
|
pub audio_outs: Vec<JackAudioOut>,
|
||||||
pub buffer: Vec<Vec<f32>>,
|
pub buffer: Vec<Vec<f32>>,
|
||||||
pub output_gain: f32,
|
pub output_gain: f32,
|
||||||
pub cursor: (usize, usize),
|
|
||||||
pub editing: Option<Arc<RwLock<Sample>>>,
|
pub editing: Option<Arc<RwLock<Sample>>>,
|
||||||
pub mode: Option<SamplerMode>,
|
pub mode: Option<SamplerMode>,
|
||||||
/// Size of actual notes area
|
/// Size of actual notes area
|
||||||
pub size: Measure<TuiOut>,
|
pub size: Measure<TuiOut>,
|
||||||
/// Lowest note displayed
|
/// Lowest note displayed
|
||||||
pub note_lo: AtomicUsize,
|
pub note_lo: AtomicUsize,
|
||||||
|
/// Selected note
|
||||||
pub note_pt: AtomicUsize,
|
pub note_pt: AtomicUsize,
|
||||||
|
/// Selected note as row/col
|
||||||
|
pub cursor: (AtomicUsize, AtomicUsize),
|
||||||
pub color: ItemPalette
|
pub color: ItemPalette
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,11 +42,11 @@ impl Default for Sampler {
|
||||||
output_gain: 1.,
|
output_gain: 1.,
|
||||||
recording: None,
|
recording: None,
|
||||||
mode: None,
|
mode: None,
|
||||||
cursor: (0, 0),
|
|
||||||
editing: None,
|
editing: None,
|
||||||
size: Default::default(),
|
size: Default::default(),
|
||||||
note_lo: 0.into(),
|
note_lo: 0.into(),
|
||||||
note_pt: 0.into(),
|
note_pt: 0.into(),
|
||||||
|
cursor: (0.into(), 0.into()),
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,17 +96,43 @@ impl Sampler {
|
||||||
/// Immutable reference to sample at cursor.
|
/// Immutable reference to sample at cursor.
|
||||||
pub fn sample (&self) -> Option<&Arc<RwLock<Sample>>> {
|
pub fn sample (&self) -> Option<&Arc<RwLock<Sample>>> {
|
||||||
for (i, sample) in self.mapped.iter().enumerate() {
|
for (i, sample) in self.mapped.iter().enumerate() {
|
||||||
if i == self.cursor.0 {
|
if i == self.cursor().0 {
|
||||||
return sample.as_ref()
|
return sample.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i, sample) in self.unmapped.iter().enumerate() {
|
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)
|
return Some(sample)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
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.
|
/// A sound sample.
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,11 @@ impl Sampler {
|
||||||
pub fn view_grid_cell <'a> (
|
pub fn view_grid_cell <'a> (
|
||||||
&'a self, name: &'a str, x: u16, y: u16, w: u16, h: u16
|
&'a self, name: &'a str, x: u16, y: u16, w: u16, h: u16
|
||||||
) -> impl Content<TuiOut> + use<'a> {
|
) -> impl Content<TuiOut> + use<'a> {
|
||||||
|
let cursor = self.cursor();
|
||||||
let hi_fg = Color::Rgb(64, 64, 64);
|
let hi_fg = Color::Rgb(64, 64, 64);
|
||||||
let hi_bg = if y == 0 { Color::Reset } else { Color::Rgb(64, 64, 64) /*prev*/ };
|
let hi_bg = if y == 0 { Color::Reset } else { Color::Rgb(64, 64, 64) /*prev*/ };
|
||||||
let tx_fg = Color::Rgb(255, 255, 255);
|
let tx_fg = Color::Rgb(255, 255, 255);
|
||||||
let tx_bg = if x as usize == self.cursor.0 && y as usize == self.cursor.1 {
|
let tx_bg = if x as usize == cursor.0 && y as usize == cursor.1 {
|
||||||
Color::Rgb(96, 96, 96)
|
Color::Rgb(96, 96, 96)
|
||||||
} else {
|
} else {
|
||||||
Color::Rgb(64, 64, 64)
|
Color::Rgb(64, 64, 64)
|
||||||
|
|
@ -85,18 +86,6 @@ render!(TuiOut: |self: SamplesTui, to| {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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); }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Sampler {
|
impl Sampler {
|
||||||
const _EMPTY: &[(f64, f64)] = &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)];
|
const _EMPTY: &[(f64, f64)] = &[(0., 0.), (1., 1.), (2., 2.), (0., 2.), (2., 0.)];
|
||||||
pub fn list <'a> (&'a self, compact: bool, editor: &MidiEditor) -> impl Content<TuiOut> + 'a {
|
pub fn list <'a> (&'a self, compact: bool, editor: &MidiEditor) -> impl Content<TuiOut> + 'a {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue