mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
nice top level command dispatch
This commit is contained in:
parent
aad7aa6c5e
commit
8dcf73c18c
8 changed files with 137 additions and 144 deletions
|
|
@ -1,5 +1,6 @@
|
|||
mod sampler; pub use self::sampler::*;
|
||||
mod sampler_tui; pub use self::sampler_tui::*;
|
||||
mod sampler_cmd; pub use self::sampler_cmd::*;
|
||||
|
||||
pub(crate) use ::tek_jack::{*, jack::*};
|
||||
pub(crate) use ::tek_midi::{*, midly::{*, live::*, num::*}};
|
||||
|
|
|
|||
|
|
@ -415,14 +415,6 @@ impl Iterator for Voice {
|
|||
}
|
||||
}
|
||||
|
||||
input_to_command!(FileBrowserCommand: |state:SamplerTui, input: Event|match input {
|
||||
_ => return None
|
||||
});
|
||||
|
||||
command!(|self:FileBrowserCommand,state:SamplerTui|match self {
|
||||
_ => todo!()
|
||||
});
|
||||
|
||||
pub struct AddSampleModal {
|
||||
exited: bool,
|
||||
dir: PathBuf,
|
||||
|
|
@ -656,86 +648,6 @@ impl Content<TuiOut> for AddSampleModal {
|
|||
//});
|
||||
|
||||
|
||||
handle!(TuiIn: |self: SamplerTui, input|SamplerTuiCommand::execute_with_state(self, input.event()));
|
||||
|
||||
#[derive(Clone, Debug)] pub enum SamplerTuiCommand {
|
||||
Import(FileBrowserCommand),
|
||||
Select(usize),
|
||||
Sample(SamplerCommand),
|
||||
}
|
||||
impl SamplerTuiCommand {
|
||||
pub fn from_edn <'a> (head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)] pub enum SamplerCommand {
|
||||
RecordBegin(u7),
|
||||
RecordCancel,
|
||||
RecordFinish,
|
||||
SetSample(u7, Option<Arc<RwLock<Sample>>>),
|
||||
SetStart(u7, usize),
|
||||
SetGain(f32),
|
||||
NoteOn(u7, u7),
|
||||
NoteOff(u7),
|
||||
}
|
||||
impl SamplerCommand {
|
||||
pub fn from_edn <'a> (head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
input_to_command!(SamplerTuiCommand: |state: SamplerTui, input: Event|match state.mode{
|
||||
Some(SamplerMode::Import(..)) => Self::Import(
|
||||
FileBrowserCommand::input_to_command(state, input)?
|
||||
),
|
||||
_ => match input {
|
||||
// load sample
|
||||
kpat!(Shift-Char('L')) => Self::Import(FileBrowserCommand::Begin),
|
||||
kpat!(KeyCode::Up) => Self::Select(state.note_point().overflowing_add(1).0.min(127)),
|
||||
kpat!(KeyCode::Down) => Self::Select(state.note_point().overflowing_sub(1).0.min(127)),
|
||||
_ => return None
|
||||
}
|
||||
});
|
||||
|
||||
command!(|self: SamplerTuiCommand, state: SamplerTui|match self {
|
||||
Self::Import(FileBrowserCommand::Begin) => {
|
||||
let voices = &state.state.voices;
|
||||
let sample = Arc::new(RwLock::new(Sample::new("", 0, 0, vec![])));
|
||||
state.mode = Some(SamplerMode::Import(0, FileBrowser::new(None)?));
|
||||
None
|
||||
},
|
||||
Self::Select(index) => {
|
||||
let old = state.note_point();
|
||||
state.set_note_point(index);
|
||||
Some(Self::Select(old))
|
||||
},
|
||||
Self::Sample(cmd) => cmd.execute(&mut state.state)?.map(Self::Sample),
|
||||
_ => todo!()
|
||||
});
|
||||
|
||||
command!(|self: SamplerCommand, state: Sampler|match self {
|
||||
Self::SetSample(index, sample) => {
|
||||
let i = index.as_int() as usize;
|
||||
let old = state.mapped[i].clone();
|
||||
state.mapped[i] = sample;
|
||||
Some(Self::SetSample(index, old))
|
||||
},
|
||||
Self::RecordBegin(index) => {
|
||||
state.begin_recording(index.as_int() as usize);
|
||||
None
|
||||
},
|
||||
Self::RecordCancel => {
|
||||
state.cancel_recording();
|
||||
None
|
||||
},
|
||||
Self::RecordFinish => {
|
||||
state.finish_recording();
|
||||
None
|
||||
},
|
||||
_ => todo!()
|
||||
});
|
||||
|
||||
pub enum SamplerMode {
|
||||
// Load sample from path
|
||||
Import(usize, FileBrowser),
|
||||
|
|
|
|||
89
sampler/src/sampler_cmd.rs
Normal file
89
sampler/src/sampler_cmd.rs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
use crate::*;
|
||||
|
||||
handle!(TuiIn: |self: SamplerTui, input|SamplerTuiCommand::execute_with_state(self, input.event()));
|
||||
|
||||
#[derive(Clone, Debug)] pub enum SamplerTuiCommand {
|
||||
Import(FileBrowserCommand),
|
||||
Select(usize),
|
||||
Sample(SamplerCommand),
|
||||
}
|
||||
impl EdnCommand<SamplerTui> for SamplerTuiCommand {
|
||||
fn from_edn <'a> (state: &SamplerTui, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)] pub enum SamplerCommand {
|
||||
RecordBegin(u7),
|
||||
RecordCancel,
|
||||
RecordFinish,
|
||||
SetSample(u7, Option<Arc<RwLock<Sample>>>),
|
||||
SetStart(u7, usize),
|
||||
SetGain(f32),
|
||||
NoteOn(u7, u7),
|
||||
NoteOff(u7),
|
||||
}
|
||||
impl EdnCommand<Sampler> for SamplerCommand {
|
||||
fn from_edn <'a> (state: &Sampler, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
input_to_command!(FileBrowserCommand: |state:SamplerTui, input: Event|match input {
|
||||
_ => return None
|
||||
});
|
||||
|
||||
command!(|self:FileBrowserCommand,state:SamplerTui|match self {
|
||||
_ => todo!()
|
||||
});
|
||||
|
||||
input_to_command!(SamplerTuiCommand: |state: SamplerTui, input: Event|match state.mode{
|
||||
Some(SamplerMode::Import(..)) => Self::Import(
|
||||
FileBrowserCommand::input_to_command(state, input)?
|
||||
),
|
||||
_ => match input {
|
||||
// load sample
|
||||
kpat!(Shift-Char('L')) => Self::Import(FileBrowserCommand::Begin),
|
||||
kpat!(KeyCode::Up) => Self::Select(state.note_point().overflowing_add(1).0.min(127)),
|
||||
kpat!(KeyCode::Down) => Self::Select(state.note_point().overflowing_sub(1).0.min(127)),
|
||||
_ => return None
|
||||
}
|
||||
});
|
||||
|
||||
command!(|self: SamplerTuiCommand, state: SamplerTui|match self {
|
||||
Self::Import(FileBrowserCommand::Begin) => {
|
||||
let voices = &state.state.voices;
|
||||
let sample = Arc::new(RwLock::new(Sample::new("", 0, 0, vec![])));
|
||||
state.mode = Some(SamplerMode::Import(0, FileBrowser::new(None)?));
|
||||
None
|
||||
},
|
||||
Self::Select(index) => {
|
||||
let old = state.note_point();
|
||||
state.set_note_point(index);
|
||||
Some(Self::Select(old))
|
||||
},
|
||||
Self::Sample(cmd) => cmd.execute(&mut state.state)?.map(Self::Sample),
|
||||
_ => todo!()
|
||||
});
|
||||
|
||||
command!(|self: SamplerCommand, state: Sampler|match self {
|
||||
Self::SetSample(index, sample) => {
|
||||
let i = index.as_int() as usize;
|
||||
let old = state.mapped[i].clone();
|
||||
state.mapped[i] = sample;
|
||||
Some(Self::SetSample(index, old))
|
||||
},
|
||||
Self::RecordBegin(index) => {
|
||||
state.begin_recording(index.as_int() as usize);
|
||||
None
|
||||
},
|
||||
Self::RecordCancel => {
|
||||
state.cancel_recording();
|
||||
None
|
||||
},
|
||||
Self::RecordFinish => {
|
||||
state.finish_recording();
|
||||
None
|
||||
},
|
||||
_ => todo!()
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue