mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
45 lines
1.8 KiB
Rust
45 lines
1.8 KiB
Rust
use crate::*;
|
|
impl Handle<Tui> for Sampler {
|
|
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
|
handle_keymap(self, &from.event(), KEYMAP_SAMPLER)
|
|
}
|
|
}
|
|
/// Key bindings for sampler device.
|
|
pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
|
|
[Up, NONE, "/sampler/cursor/up", "move cursor up", |state: &mut Sampler| {
|
|
state.cursor.0 = if state.cursor.0 == 0 {
|
|
state.mapped.len() + state.unmapped.len() - 1
|
|
} else {
|
|
state.cursor.0 - 1
|
|
};
|
|
Ok(true)
|
|
}],
|
|
[Down, NONE, "/sampler/cursor/down", "move cursor down", |state: &mut Sampler| {
|
|
state.cursor.0 = (state.cursor.0 + 1) % (state.mapped.len() + state.unmapped.len());
|
|
Ok(true)
|
|
}],
|
|
[Char('p'), NONE, "/sampler/play", "play current sample", |state: &mut Sampler| {
|
|
if let Some(sample) = state.sample() {
|
|
state.voices.write().unwrap().push(Sample::play(sample, 0, &100.into()));
|
|
}
|
|
Ok(true)
|
|
}],
|
|
[Char('a'), NONE, "/sampler/add", "add a new sample", |state: &mut Sampler| {
|
|
let sample = Arc::new(RwLock::new(Sample::new("", 0, 0, vec![])));
|
|
*state.modal.lock().unwrap() = Some(Exit::boxed(AddSampleModal::new(&sample, &state.voices)?));
|
|
state.unmapped.push(sample);
|
|
Ok(true)
|
|
}],
|
|
[Char('r'), NONE, "/sampler/replace", "replace selected sample", |state: &mut Sampler| {
|
|
if let Some(sample) = state.sample() {
|
|
*state.modal.lock().unwrap() = Some(Exit::boxed(AddSampleModal::new(&sample, &state.voices)?));
|
|
}
|
|
Ok(true)
|
|
}],
|
|
[Enter, NONE, "/sampler/edit", "edit selected sample", |state: &mut Sampler| {
|
|
if let Some(sample) = state.sample() {
|
|
state.editing = Some(sample.clone());
|
|
}
|
|
Ok(true)
|
|
}],
|
|
});
|