use crate::*; impl Handle for Sampler { fn handle (&mut self, from: &Tui) -> Perhaps { handle_keymap(self, &from.event(), KEYMAP_SAMPLER) } } /// Key bindings for sampler device. pub const KEYMAP_SAMPLER: &'static [KeyBinding] = 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) }], });