stub sampler import command

This commit is contained in:
🪞👃🪞 2024-12-17 18:51:27 +01:00
parent 17efdb9b8e
commit 9bd898ab33
6 changed files with 22 additions and 18 deletions

View file

@ -14,7 +14,7 @@ use crate::*;
($Command:ty: <$Engine:ty>|$state:ident:$State:ty,$input:ident|$handler:expr) => { ($Command:ty: <$Engine:ty>|$state:ident:$State:ty,$input:ident|$handler:expr) => {
impl InputToCommand<$Engine, $State> for $Command { impl InputToCommand<$Engine, $State> for $Command {
fn input_to_command ($state: &$State, $input: &<$Engine as Engine>::Input) -> Option<Self> { fn input_to_command ($state: &$State, $input: &<$Engine as Engine>::Input) -> Option<Self> {
$handler Some($handler)
} }
} }
} }

View file

@ -1,5 +1,6 @@
use crate::*; use crate::*;
use super::*; use super::*;
use KeyCode::Char;
impl TryFrom<&Arc<RwLock<JackClient>>> for GrooveboxTui { impl TryFrom<&Arc<RwLock<JackClient>>> for GrooveboxTui {
type Error = Box<dyn std::error::Error>; type Error = Box<dyn std::error::Error>;
@ -28,5 +29,9 @@ pub enum GrooveboxCommand {
render!(|self:GrooveboxTui|Bsp::s(Tui::fixed_y(self.split, &self.sequencer), &self.sampler)); render!(|self:GrooveboxTui|Bsp::s(Tui::fixed_y(self.split, &self.sequencer), &self.sampler));
audio!(|self:GrooveboxTui,_client,_process|Control::Continue); audio!(|self:GrooveboxTui,_client,_process|Control::Continue);
handle!(<Tui>|self:GrooveboxTui,input|GrooveboxCommand::execute_with_state(self, input)); handle!(<Tui>|self:GrooveboxTui,input|GrooveboxCommand::execute_with_state(self, input));
input_to_command!(GrooveboxCommand: <Tui>|state:GrooveboxTui,input|match input.event() {
// load sample
key_pat!(Char('l')) => GrooveboxCommand::Sampler(SamplerCommand::Import),
_ => GrooveboxCommand::Sequencer(SequencerCommand::input_to_command(&state.sequencer, input)?),
});
command!(|self:GrooveboxCommand,state:GrooveboxTui|todo!()); command!(|self:GrooveboxCommand,state:GrooveboxTui|todo!());
input_to_command!(GrooveboxCommand: <Tui>|state:GrooveboxTui,input|todo!());

View file

@ -9,6 +9,7 @@ use symphonia::core::audio::SampleBuffer;
use symphonia::default::get_codecs; use symphonia::default::get_codecs;
pub enum SamplerCommand { pub enum SamplerCommand {
Import
} }
impl TryFrom<&Arc<RwLock<JackClient>>> for SamplerTui { impl TryFrom<&Arc<RwLock<JackClient>>> for SamplerTui {

View file

@ -55,7 +55,7 @@ pub enum SequencerCommand {
} }
handle!(<Tui>|self:SequencerTui,input|SequencerCommand::execute_with_state(self, input)); handle!(<Tui>|self:SequencerTui,input|SequencerCommand::execute_with_state(self, input));
input_to_command!(SequencerCommand: <Tui>|state:SequencerTui,input|Some(match input.event() { input_to_command!(SequencerCommand: <Tui>|state:SequencerTui,input|match input.event() {
// Transport: Play/pause // Transport: Play/pause
key_pat!(Char(' ')) => Clock(if state.clock().is_stopped() { key_pat!(Char(' ')) => Clock(if state.clock().is_stopped() {
Play(None) } else { Pause(None) }), Play(None) } else { Pause(None) }),
@ -95,7 +95,7 @@ input_to_command!(SequencerCommand: <Tui>|state:SequencerTui,input|Some(match in
} else { } else {
return None return None
} }
})); });
command!(|self: SequencerCommand, state: SequencerTui|match self { command!(|self: SequencerCommand, state: SequencerTui|match self {
Self::Phrases(cmd) => { Self::Phrases(cmd) => {
let mut default = |cmd: PhrasesCommand|cmd.execute(&mut state.phrases).map(|x|x.map(Phrases)); let mut default = |cmd: PhrasesCommand|cmd.execute(&mut state.phrases).map(|x|x.map(Phrases));

View file

@ -139,7 +139,7 @@ command!(|self: FileBrowserCommand, state: PhraseListModel|{
input_to_command!(FileBrowserCommand:<Tui>|state:PhraseListModel,from|{ input_to_command!(FileBrowserCommand:<Tui>|state:PhraseListModel,from|{
if let Some(PhraseListMode::Import(_index, browser)) = state.phrases_mode() { if let Some(PhraseListMode::Import(_index, browser)) = state.phrases_mode() {
Some(match from.event() { match from.event() {
key_pat!(Up) => Select( key_pat!(Up) => Select(
browser.index.overflowing_sub(1).0.min(browser.len().saturating_sub(1)) browser.index.overflowing_sub(1).0.min(browser.len().saturating_sub(1))
), ),
@ -153,9 +153,9 @@ input_to_command!(FileBrowserCommand:<Tui>|state:PhraseListModel,from|{
key_pat!(Backspace) => { todo!() }, key_pat!(Backspace) => { todo!() },
key_pat!(Esc) => Self::Cancel, key_pat!(Esc) => Self::Cancel,
_ => return None _ => return None
}) }
} else if let Some(PhraseListMode::Export(_index, browser)) = state.phrases_mode() { } else if let Some(PhraseListMode::Export(_index, browser)) = state.phrases_mode() {
Some(match from.event() { match from.event() {
key_pat!(Up) => Select(browser.index.overflowing_sub(1).0.min(browser.len())), key_pat!(Up) => Select(browser.index.overflowing_sub(1).0.min(browser.len())),
key_pat!(Down) => Select(browser.index.saturating_add(1) % browser.len()), key_pat!(Down) => Select(browser.index.saturating_add(1) % browser.len()),
key_pat!(Right) => Chdir(browser.cwd.clone()), key_pat!(Right) => Chdir(browser.cwd.clone()),
@ -165,7 +165,7 @@ input_to_command!(FileBrowserCommand:<Tui>|state:PhraseListModel,from|{
key_pat!(Backspace) => { todo!() }, key_pat!(Backspace) => { todo!() },
key_pat!(Esc) => Self::Cancel, key_pat!(Esc) => Self::Cancel,
_ => return None _ => return None
}) }
} else { } else {
unreachable!() unreachable!()
} }
@ -173,7 +173,7 @@ input_to_command!(FileBrowserCommand:<Tui>|state:PhraseListModel,from|{
input_to_command!(PhraseLengthCommand:<Tui>|state:PhraseListModel,from|{ input_to_command!(PhraseLengthCommand:<Tui>|state:PhraseListModel,from|{
if let Some(PhraseListMode::Length(_, length, _)) = state.phrases_mode() { if let Some(PhraseListMode::Length(_, length, _)) = state.phrases_mode() {
Some(match from.event() { match from.event() {
key_pat!(Up) => Self::Inc, key_pat!(Up) => Self::Inc,
key_pat!(Down) => Self::Dec, key_pat!(Down) => Self::Dec,
key_pat!(Right) => Self::Next, key_pat!(Right) => Self::Next,
@ -181,7 +181,7 @@ input_to_command!(PhraseLengthCommand:<Tui>|state:PhraseListModel,from|{
key_pat!(Enter) => Self::Set(*length), key_pat!(Enter) => Self::Set(*length),
key_pat!(Esc) => Self::Cancel, key_pat!(Esc) => Self::Cancel,
_ => return None _ => return None
}) }
} else { } else {
unreachable!() unreachable!()
} }

View file

@ -99,14 +99,12 @@ command!(|self:PhrasesCommand, state:PhraseListModel|{
} }
}); });
input_to_command!(PhrasesCommand:<Tui>|state:PhraseListModel,input|{ input_to_command!(PhrasesCommand:<Tui>|state:PhraseListModel,input|match state.phrases_mode() {
Some(match state.phrases_mode() {
Some(PhraseListMode::Rename(..)) => Self::Rename(Rename::input_to_command(state, input)?), Some(PhraseListMode::Rename(..)) => Self::Rename(Rename::input_to_command(state, input)?),
Some(PhraseListMode::Length(..)) => Self::Length(Length::input_to_command(state, input)?), Some(PhraseListMode::Length(..)) => Self::Length(Length::input_to_command(state, input)?),
Some(PhraseListMode::Import(..)) => Self::Import(Browse::input_to_command(state, input)?), Some(PhraseListMode::Import(..)) => Self::Import(Browse::input_to_command(state, input)?),
Some(PhraseListMode::Export(..)) => Self::Export(Browse::input_to_command(state, input)?), Some(PhraseListMode::Export(..)) => Self::Export(Browse::input_to_command(state, input)?),
_ => to_phrases_command(state, input)? _ => to_phrases_command(state, input)?
})
}); });
fn to_phrases_command (state: &PhraseListModel, input: &TuiInput) -> Option<PhrasesCommand> { fn to_phrases_command (state: &PhraseListModel, input: &TuiInput) -> Option<PhrasesCommand> {