mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 21:56:42 +01:00
midi import/export browser, pt.1
This commit is contained in:
parent
26eb5f0315
commit
6d8dbc6780
5 changed files with 263 additions and 140 deletions
|
|
@ -117,6 +117,8 @@ pub enum PhrasesCommand {
|
|||
Phrase(PhrasePoolCommand),
|
||||
Rename(PhraseRenameCommand),
|
||||
Length(PhraseLengthCommand),
|
||||
Import(FileBrowserCommand),
|
||||
Export(FileBrowserCommand),
|
||||
}
|
||||
|
||||
impl<T: PhrasesControl> Command<T> for PhrasesCommand {
|
||||
|
|
@ -124,8 +126,44 @@ impl<T: PhrasesControl> Command<T> for PhrasesCommand {
|
|||
use PhrasesCommand::*;
|
||||
Ok(match self {
|
||||
Phrase(command) => command.execute(state)?.map(Phrase),
|
||||
Rename(command) => command.execute(state)?.map(Rename),
|
||||
Length(command) => command.execute(state)?.map(Length),
|
||||
Rename(command) => match command {
|
||||
PhraseRenameCommand::Begin => {
|
||||
let length = state.phrases()[state.phrase_index()].read().unwrap().length;
|
||||
*state.phrases_mode_mut() = Some(
|
||||
PhrasesMode::Length(state.phrase_index(), length, PhraseLengthFocus::Bar)
|
||||
);
|
||||
None
|
||||
},
|
||||
_ => command.execute(state)?.map(Rename)
|
||||
},
|
||||
Length(command) => match command {
|
||||
PhraseLengthCommand::Begin => {
|
||||
let name = state.phrases()[state.phrase_index()].read().unwrap().name.clone();
|
||||
*state.phrases_mode_mut() = Some(
|
||||
PhrasesMode::Rename(state.phrase_index(), name)
|
||||
);
|
||||
None
|
||||
},
|
||||
_ => command.execute(state)?.map(Length)
|
||||
},
|
||||
Import(command) => match command {
|
||||
FileBrowserCommand::Begin => {
|
||||
*state.phrases_mode_mut() = Some(
|
||||
PhrasesMode::Import(state.phrase_index(), FileBrowser::new())
|
||||
);
|
||||
None
|
||||
},
|
||||
_ => command.execute(state)?.map(Import)
|
||||
},
|
||||
Export(command) => match command {
|
||||
FileBrowserCommand::Begin => {
|
||||
*state.phrases_mode_mut() = Some(
|
||||
PhrasesMode::Export(state.phrase_index(), FileBrowser::new())
|
||||
);
|
||||
None
|
||||
},
|
||||
_ => command.execute(state)?.map(Export)
|
||||
},
|
||||
Select(phrase) => {
|
||||
state.set_phrase_index(phrase);
|
||||
None
|
||||
|
|
@ -137,21 +175,20 @@ impl<T: PhrasesControl> Command<T> for PhrasesCommand {
|
|||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum PhraseLengthCommand {
|
||||
Begin,
|
||||
Cancel,
|
||||
Set(usize),
|
||||
Next,
|
||||
Prev,
|
||||
Inc,
|
||||
Dec,
|
||||
Set(usize),
|
||||
Cancel,
|
||||
}
|
||||
|
||||
impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhraseLengthFocus::*;
|
||||
use PhraseLengthCommand::*;
|
||||
let mut mode = state.phrases_mode_mut().clone();
|
||||
if let Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) = mode {
|
||||
match self {
|
||||
match state.phrases_mode_mut().clone() {
|
||||
Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) => match self {
|
||||
Cancel => { *state.phrases_mode_mut() = None; },
|
||||
Prev => { focus.prev() },
|
||||
Next => { focus.next() },
|
||||
|
|
@ -174,15 +211,9 @@ impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
|
|||
return Ok(Some(Self::Set(old_length)))
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
} else if self == Begin {
|
||||
let length = state.phrases()[state.phrase_index()].read().unwrap().length;
|
||||
*state.phrases_mode_mut() = Some(
|
||||
PhrasesMode::Length(state.phrase_index(), length, PhraseLengthFocus::Bar)
|
||||
);
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
|
@ -190,20 +221,16 @@ impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum PhraseRenameCommand {
|
||||
Begin,
|
||||
Set(String),
|
||||
Confirm,
|
||||
Cancel,
|
||||
Confirm,
|
||||
Set(String),
|
||||
}
|
||||
|
||||
impl<T> Command<T> for PhraseRenameCommand
|
||||
where
|
||||
T: PhrasesControl
|
||||
{
|
||||
impl<T: PhrasesControl> Command<T> for PhraseRenameCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhraseRenameCommand::*;
|
||||
let mut mode = state.phrases_mode_mut().clone();
|
||||
if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = mode {
|
||||
match self {
|
||||
match state.phrases_mode_mut().clone() {
|
||||
Some(PhrasesMode::Rename(phrase, ref mut old_name)) => match self {
|
||||
Set(s) => {
|
||||
state.phrases()[phrase].write().unwrap().name = s.into();
|
||||
return Ok(Some(Self::Set(old_name.clone())))
|
||||
|
|
@ -217,15 +244,40 @@ where
|
|||
state.phrases()[phrase].write().unwrap().name = old_name.clone();
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
} else if self == Begin {
|
||||
let name = state.phrases()[state.phrase_index()].read().unwrap().name.clone();
|
||||
*state.phrases_mode_mut() = Some(
|
||||
PhrasesMode::Rename(state.phrase_index(), name)
|
||||
);
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Commands supported by [FileBrowser]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum FileBrowserCommand {
|
||||
Begin,
|
||||
Cancel,
|
||||
Confirm,
|
||||
Select(usize),
|
||||
Chdir(PathBuf)
|
||||
}
|
||||
|
||||
impl<T: PhrasesControl> Command<T> for FileBrowserCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use FileBrowserCommand::*;
|
||||
match state.phrases_mode_mut().clone() {
|
||||
Some(PhrasesMode::Import(index, browser)) => {
|
||||
todo!()
|
||||
},
|
||||
Some(PhrasesMode::Export(index, browser)) => {
|
||||
todo!()
|
||||
},
|
||||
_ => match self {
|
||||
Begin => {
|
||||
todo!()
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
};
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue