mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
use those macros in some places, a few more to go
This commit is contained in:
parent
fdafd15a01
commit
17efdb9b8e
3 changed files with 192 additions and 193 deletions
|
|
@ -218,23 +218,16 @@ pub enum TransportCommand {
|
||||||
Clock(ClockCommand),
|
Clock(ClockCommand),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command<TransportTui> for TransportCommand {
|
command!(|self:TransportCommand,state:TransportTui|match self {
|
||||||
fn execute (self, state: &mut TransportTui) -> Perhaps<Self> {
|
//Self::Focus(cmd) => cmd.execute(state)?.map(Self::Focus),
|
||||||
Ok(match self {
|
|
||||||
Self::Focus(cmd) => cmd.execute(state)?.map(Self::Focus),
|
|
||||||
Self::Clock(cmd) => cmd.execute(state)?.map(Self::Clock),
|
Self::Clock(cmd) => cmd.execute(state)?.map(Self::Clock),
|
||||||
})
|
_ => unreachable!(),
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
impl Command<TransportTui> for FocusCommand<TransportFocus> {
|
//command!(|self:TransportFocus,state:TransportTui|{
|
||||||
fn execute (self, state: &mut TransportTui) -> Perhaps<FocusCommand<TransportFocus>> {
|
//if let FocusCommand::Set(to) = self { state.set_focused(to); }
|
||||||
if let FocusCommand::Set(to) = self {
|
//Ok(None)
|
||||||
state.set_focused(to);
|
//});
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InputToCommand<Tui, TransportTui> for TransportCommand {
|
impl InputToCommand<Tui, TransportTui> for TransportCommand {
|
||||||
fn input_to_command (state: &TransportTui, input: &TuiInput) -> Option<Self> {
|
fn input_to_command (state: &TransportTui, input: &TuiInput) -> Option<Self> {
|
||||||
|
|
@ -262,34 +255,10 @@ where
|
||||||
Pause(Some(0))
|
Pause(Some(0))
|
||||||
}),
|
}),
|
||||||
_ => match state.transport_focused().unwrap() {
|
_ => match state.transport_focused().unwrap() {
|
||||||
TransportFocus::Bpm => match input.event() {
|
TransportFocus::Bpm => to_bpm_command(input, state.clock().bpm().get())?,
|
||||||
key_pat!(Char(',')) => Clock(SetBpm(state.clock().bpm().get() - 1.0)),
|
TransportFocus::Quant => to_quant_command(input, &state.clock().quant)?,
|
||||||
key_pat!(Char('.')) => Clock(SetBpm(state.clock().bpm().get() + 1.0)),
|
TransportFocus::Sync => to_sync_command(input, &state.clock().sync)?,
|
||||||
key_pat!(Char('<')) => Clock(SetBpm(state.clock().bpm().get() - 0.001)),
|
TransportFocus::Clock => to_seek_command(input)?,
|
||||||
key_pat!(Char('>')) => Clock(SetBpm(state.clock().bpm().get() + 0.001)),
|
|
||||||
_ => return None,
|
|
||||||
},
|
|
||||||
TransportFocus::Quant => match input.event() {
|
|
||||||
key_pat!(Char(',')) => Clock(SetQuant(state.clock().quant.prev())),
|
|
||||||
key_pat!(Char('.')) => Clock(SetQuant(state.clock().quant.next())),
|
|
||||||
key_pat!(Char('<')) => Clock(SetQuant(state.clock().quant.prev())),
|
|
||||||
key_pat!(Char('>')) => Clock(SetQuant(state.clock().quant.next())),
|
|
||||||
_ => return None,
|
|
||||||
},
|
|
||||||
TransportFocus::Sync => match input.event() {
|
|
||||||
key_pat!(Char(',')) => Clock(SetSync(state.clock().sync.prev())),
|
|
||||||
key_pat!(Char('.')) => Clock(SetSync(state.clock().sync.next())),
|
|
||||||
key_pat!(Char('<')) => Clock(SetSync(state.clock().sync.prev())),
|
|
||||||
key_pat!(Char('>')) => Clock(SetSync(state.clock().sync.next())),
|
|
||||||
_ => return None,
|
|
||||||
},
|
|
||||||
TransportFocus::Clock => match input.event() {
|
|
||||||
key_pat!(Char(',')) => todo!("transport seek bar"),
|
|
||||||
key_pat!(Char('.')) => todo!("transport seek bar"),
|
|
||||||
key_pat!(Char('<')) => todo!("transport seek beat"),
|
|
||||||
key_pat!(Char('>')) => todo!("transport seek beat"),
|
|
||||||
_ => return None,
|
|
||||||
},
|
|
||||||
TransportFocus::PlayPause => match input.event() {
|
TransportFocus::PlayPause => match input.event() {
|
||||||
key_pat!(Enter) => Clock(
|
key_pat!(Enter) => Clock(
|
||||||
if state.clock().is_stopped() {
|
if state.clock().is_stopped() {
|
||||||
|
|
@ -310,3 +279,43 @@ where
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn to_bpm_command (input: &TuiInput, bpm: f64) -> Option<TransportCommand> {
|
||||||
|
Some(match input.event() {
|
||||||
|
key_pat!(Char(',')) => Clock(SetBpm(bpm - 1.0)),
|
||||||
|
key_pat!(Char('.')) => Clock(SetBpm(bpm + 1.0)),
|
||||||
|
key_pat!(Char('<')) => Clock(SetBpm(bpm - 0.001)),
|
||||||
|
key_pat!(Char('>')) => Clock(SetBpm(bpm + 0.001)),
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_quant_command (input: &TuiInput, quant: &Quantize) -> Option<TransportCommand> {
|
||||||
|
Some(match input.event() {
|
||||||
|
key_pat!(Char(',')) => Clock(SetQuant(quant.prev())),
|
||||||
|
key_pat!(Char('.')) => Clock(SetQuant(quant.next())),
|
||||||
|
key_pat!(Char('<')) => Clock(SetQuant(quant.prev())),
|
||||||
|
key_pat!(Char('>')) => Clock(SetQuant(quant.next())),
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_sync_command (input: &TuiInput, sync: &LaunchSync) -> Option<TransportCommand> {
|
||||||
|
Some(match input.event() {
|
||||||
|
key_pat!(Char(',')) => Clock(SetSync(sync.prev())),
|
||||||
|
key_pat!(Char('.')) => Clock(SetSync(sync.next())),
|
||||||
|
key_pat!(Char('<')) => Clock(SetSync(sync.prev())),
|
||||||
|
key_pat!(Char('>')) => Clock(SetSync(sync.next())),
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_seek_command (input: &TuiInput) -> Option<TransportCommand> {
|
||||||
|
Some(match input.event() {
|
||||||
|
key_pat!(Char(',')) => todo!("transport seek bar"),
|
||||||
|
key_pat!(Char('.')) => todo!("transport seek bar"),
|
||||||
|
key_pat!(Char('<')) => todo!("transport seek beat"),
|
||||||
|
key_pat!(Char('>')) => todo!("transport seek beat"),
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,8 +95,7 @@ pub enum FileBrowserCommand {
|
||||||
Filter(String),
|
Filter(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command<PhraseListModel> for FileBrowserCommand {
|
command!(|self: FileBrowserCommand, state: PhraseListModel|{
|
||||||
fn execute (self, state: &mut PhraseListModel) -> Perhaps<Self> {
|
|
||||||
let mode = state.phrases_mode_mut();
|
let mode = state.phrases_mode_mut();
|
||||||
match mode {
|
match mode {
|
||||||
Some(Import(index, ref mut browser)) => match self {
|
Some(Import(index, ref mut browser)) => match self {
|
||||||
|
|
@ -135,12 +134,10 @@ impl Command<PhraseListModel> for FileBrowserCommand {
|
||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
Ok(None)
|
None
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
impl InputToCommand<Tui, PhraseListModel> for FileBrowserCommand {
|
input_to_command!(FileBrowserCommand:<Tui>|state:PhraseListModel,from|{
|
||||||
fn input_to_command (state: &PhraseListModel, from: &TuiInput) -> Option<Self> {
|
|
||||||
if let Some(PhraseListMode::Import(_index, browser)) = state.phrases_mode() {
|
if let Some(PhraseListMode::Import(_index, browser)) = state.phrases_mode() {
|
||||||
Some(match from.event() {
|
Some(match from.event() {
|
||||||
key_pat!(Up) => Select(
|
key_pat!(Up) => Select(
|
||||||
|
|
@ -172,11 +169,9 @@ impl InputToCommand<Tui, PhraseListModel> for FileBrowserCommand {
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
impl InputToCommand<Tui, PhraseListModel> for PhraseLengthCommand {
|
input_to_command!(PhraseLengthCommand:<Tui>|state:PhraseListModel,from|{
|
||||||
fn input_to_command (state: &PhraseListModel, from: &TuiInput) -> Option<Self> {
|
|
||||||
if let Some(PhraseListMode::Length(_, length, _)) = state.phrases_mode() {
|
if let Some(PhraseListMode::Length(_, length, _)) = state.phrases_mode() {
|
||||||
Some(match from.event() {
|
Some(match from.event() {
|
||||||
key_pat!(Up) => Self::Inc,
|
key_pat!(Up) => Self::Inc,
|
||||||
|
|
@ -190,5 +185,4 @@ impl InputToCommand<Tui, PhraseListModel> for PhraseLengthCommand {
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,9 @@ pub enum PhrasesCommand {
|
||||||
Export(Browse),
|
Export(Browse),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command<PhraseListModel> for PhrasesCommand {
|
command!(|self:PhrasesCommand, state:PhraseListModel|{
|
||||||
fn execute (self, state: &mut PhraseListModel) -> Perhaps<Self> {
|
|
||||||
use PhrasesCommand::*;
|
use PhrasesCommand::*;
|
||||||
Ok(match self {
|
match self {
|
||||||
Phrase(command) => command.execute(state)?.map(Phrase),
|
Phrase(command) => command.execute(state)?.map(Phrase),
|
||||||
Rename(command) => match command {
|
Rename(command) => match command {
|
||||||
PhraseRenameCommand::Begin => {
|
PhraseRenameCommand::Begin => {
|
||||||
|
|
@ -97,12 +96,10 @@ impl Command<PhraseListModel> for PhrasesCommand {
|
||||||
state.set_phrase_index(phrase);
|
state.set_phrase_index(phrase);
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
impl InputToCommand<Tui, PhraseListModel> for PhrasesCommand {
|
input_to_command!(PhrasesCommand:<Tui>|state:PhraseListModel,input|{
|
||||||
fn input_to_command (state: &PhraseListModel, input: &TuiInput) -> Option<Self> {
|
|
||||||
Some(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)?),
|
||||||
|
|
@ -110,8 +107,7 @@ impl InputToCommand<Tui, PhraseListModel> for PhrasesCommand {
|
||||||
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> {
|
||||||
use KeyCode::{Up, Down, Delete, Char};
|
use KeyCode::{Up, Down, Delete, Char};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue