mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
whew! refactor complete
This commit is contained in:
parent
deaa66d6e2
commit
685ccfaf49
7 changed files with 58 additions and 58 deletions
|
|
@ -26,5 +26,6 @@ submod! {
|
|||
sampler
|
||||
sampler_edn
|
||||
sampler_view
|
||||
sampler_handle
|
||||
voice
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Multi-track mixer
|
||||
include!("lib.rs");
|
||||
pub fn main () -> Usually<()> {
|
||||
tek_core::run(Arc::new(RwLock::new(crate::Mixer::from_args()?)))?;
|
||||
Tui::run(Arc::new(RwLock::new(crate::Mixer::from_args()?)))?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +1,44 @@
|
|||
use crate::*;
|
||||
impl Handle<Tui> for Sampler {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
handle_keymap(self, &from.event(), KEYMAP_SAMPLER)
|
||||
match from.event() {
|
||||
key!(KeyCode::Up) => {
|
||||
self.cursor.0 = if self.cursor.0 == 0 {
|
||||
self.mapped.len() + self.unmapped.len() - 1
|
||||
} else {
|
||||
self.cursor.0 - 1
|
||||
};
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::Down) => {
|
||||
self.cursor.0 = (self.cursor.0 + 1) % (self.mapped.len() + self.unmapped.len());
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::Char('p')) => {
|
||||
if let Some(sample) = self.sample() {
|
||||
self.voices.write().unwrap().push(Sample::play(sample, 0, &100.into()));
|
||||
}
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::Char('a')) => {
|
||||
let sample = Arc::new(RwLock::new(Sample::new("", 0, 0, vec![])));
|
||||
*self.modal.lock().unwrap() = Some(Exit::boxed(AddSampleModal::new(&sample, &self.voices)?));
|
||||
self.unmapped.push(sample);
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::Char('r')) => {
|
||||
if let Some(sample) = self.sample() {
|
||||
*self.modal.lock().unwrap() = Some(Exit::boxed(AddSampleModal::new(&sample, &self.voices)?));
|
||||
}
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::Enter) => {
|
||||
if let Some(sample) = self.sample() {
|
||||
self.editing = Some(sample.clone());
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
_ => Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
/// 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)
|
||||
}],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Sample player
|
||||
include!("lib.rs");
|
||||
pub fn main () -> Usually<()> {
|
||||
tek_core::run(Arc::new(RwLock::new(crate::Sampler::new("", None)?)))?;
|
||||
Tui::run(Arc::new(RwLock::new(crate::Sampler::new("", None)?)))?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Multi-track mixer
|
||||
include!("lib.rs");
|
||||
pub fn main () -> Usually<()> {
|
||||
tek_core::run(Arc::new(RwLock::new(crate::Track::new("")?)))?;
|
||||
Tui::run(Arc::new(RwLock::new(crate::Track::new("")?)))?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,32 +104,32 @@ impl Handle<Tui> for ArrangerStandalone<Tui> {
|
|||
}
|
||||
},
|
||||
key!(KeyCode::Tab) => {
|
||||
self.arranger.focus_next();
|
||||
self.focus_next();
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::BackTab) => {
|
||||
self.arranger.focus_prev();
|
||||
self.focus_prev();
|
||||
Ok(Some(true))
|
||||
},
|
||||
key!(KeyCode::Down) => {
|
||||
if self.focus == 0 || (
|
||||
self.focus == 1 && self.arranger.is_last_row()
|
||||
) {
|
||||
self.arranger.focus_next();
|
||||
self.focus_next();
|
||||
Ok(Some(true))
|
||||
} else {
|
||||
self.arranger.focused_mut().handle(from)
|
||||
self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
key!(KeyCode::Up) => {
|
||||
if self.focus == 1 && self.arranger.is_first_row() {
|
||||
self.arranger.focus_prev();
|
||||
self.focus_prev();
|
||||
Ok(Some(true))
|
||||
} else {
|
||||
self.arranger.focused_mut().handle(from)
|
||||
self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
_ => self.arranger.focused_mut().handle(from)
|
||||
_ => self.focused_mut().handle(from)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -142,23 +142,23 @@ impl Handle<Tui> for SequencerProxy<Tui> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Focus<2, E: Engine> for ArrangerStandalone<E> {
|
||||
impl Focus<2, Tui> for ArrangerStandalone<Tui> {
|
||||
fn focus (&self) -> usize {
|
||||
self.focus
|
||||
}
|
||||
fn focus_mut (&mut self) -> &mut usize {
|
||||
&mut self.focus
|
||||
}
|
||||
fn focusable (&self) -> [&dyn Focusable<E>;2] {
|
||||
fn focusable (&self) -> [&dyn Focusable<Tui>;2] {
|
||||
[
|
||||
&self.transport as &dyn Focusable<E>,
|
||||
&self.arranger as &dyn Focusable<E>,
|
||||
&self.transport as &dyn Focusable<Tui>,
|
||||
&self.arranger as &dyn Focusable<Tui>,
|
||||
]
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<E>;2] {
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;2] {
|
||||
[
|
||||
&mut self.transport as &mut dyn Focusable<E>,
|
||||
&mut self.arranger as &mut dyn Focusable<E>,
|
||||
&mut self.transport as &mut dyn Focusable<Tui>,
|
||||
&mut self.arranger as &mut dyn Focusable<Tui>,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
include!("lib.rs");
|
||||
/// Application entrypoint.
|
||||
pub fn main () -> Usually<()> {
|
||||
run(TransportToolbar::standalone()?)?;
|
||||
Tui::run(TransportToolbar::standalone()?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue