wip: 12 errors

This commit is contained in:
🪞👃🪞 2024-09-05 18:08:43 +03:00
parent ea5bc2e3b1
commit e0c8a427f1
9 changed files with 65 additions and 66 deletions

View file

@ -58,8 +58,8 @@ impl Render<Tui> for AddSampleModal {
}
}
impl Handle<Tui> for AddSampleModal {
fn handle (&mut self, e: &Tui) -> Usually<bool> {
if handle_keymap(self, e, KEYMAP_ADD_SAMPLE)? {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
if handle_keymap(self, &from.event(), KEYMAP_ADD_SAMPLE)? {
return Ok(true)
}
Ok(true)

View file

@ -13,61 +13,8 @@ pub struct Sampler {
pub modal: Arc<Mutex<Option<Box<dyn Exit + Send>>>>,
pub output_gain: f32
}
impl Handle<Tui> for Sampler {
fn handle (&mut self, e: &Tui) -> Perhaps<bool> {
handle_keymap(self, event, KEYMAP_SAMPLER)
}
}
impl Render<Tui> for Sampler {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
tui_render_sampler(self, to)
}
}
process!(Sampler = Sampler::process);
/// 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)
}],
});
impl Sampler {
pub fn from_edn <'e> (args: &[Edn<'e>]) -> Usually<JackDevice<Tui>> {
let mut name = String::new();

View file

@ -0,0 +1,45 @@
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)
}],
});

View file

@ -1,5 +1,11 @@
use crate::*;
impl Render<Tui> for Sampler {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
tui_render_sampler(self, to)
}
}
pub fn tui_render_sampler (sampler: &Sampler, to: &mut Tui) -> Perhaps<Rect> {
let Rect { x, y, height, .. } = to.area();
let style = Style::default().gray();

View file

@ -50,7 +50,7 @@ impl<E: Engine> Track<E> {
//})
//}
pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Self> {
pub fn from_edn <'a, 'e> (args: &[Edn<'e>]) -> Usually<Track<Tui>> {
let mut _gain = 0.0f64;
let mut track = Self::new("")?;
#[allow(unused_mut)]

View file

@ -1,5 +1,5 @@
use crate::*;
impl<'a> Arranger<Tui> {
impl Arranger<Tui> {
pub fn rename_selected (&mut self) {
self.modal = Some(Box::new(ArrangerRenameModal::new(
self.selected,

View file

@ -146,7 +146,7 @@ impl Phrase {
}}
}
impl<T, U> Arranger<T, U> {
impl<E: Engine> Arranger<E> {
pub fn phrase (&self) -> Option<&Arc<RwLock<Phrase>>> {
let track_id = self.selected.track()?;
self.tracks.get(track_id)?.phrases.get((*self.scene()?.clips.get(track_id)?)?)

View file

@ -1,6 +1,6 @@
use crate::*;
impl Handle<Tui> for TransportQuantize {
impl Handle<Tui> for Sequencer {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
handle_keymap(self, &from.event(), KEYMAP_SEQUENCER)
}

View file

@ -2,13 +2,14 @@ use crate::*;
impl Handle<Tui> for TransportToolbar {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
Ok(
from.key(KeyCode::Right).does(||self.focus_next())?
||
from.key(KeyCode::Left).does(||self.focus_prev())?
||
from.key(KeyCode::Char(' ')).does(||self.toggle_play())?
)
Ok(None)
//Ok(
//from.key(KeyCode::Right).does(||self.focus_next())?
//||
//from.key(KeyCode::Left).does(||self.focus_prev())?
//||
//from.key(KeyCode::Char(' ')).does(||self.toggle_play())?
//)
}
}