wip: midi import/export browser, pt.5

This commit is contained in:
🪞👃🪞 2024-11-24 21:23:33 +01:00
parent bd354bbc67
commit 4adb8d45fe
4 changed files with 35 additions and 18 deletions

View file

@ -275,6 +275,11 @@ impl<T: PhrasesControl> Command<T> for FileBrowserCommand {
index, FileBrowser::new(Some(cwd))? index, FileBrowser::new(Some(cwd))?
)); ));
}, },
Select(index) => {
*state.phrases_mode_mut() = Some(PhrasesMode::Import(
index, browser
))
},
_ => todo!(), _ => todo!(),
_ => unreachable!() _ => unreachable!()
}, },
@ -287,6 +292,11 @@ impl<T: PhrasesControl> Command<T> for FileBrowserCommand {
index, FileBrowser::new(Some(cwd))? index, FileBrowser::new(Some(cwd))?
)); ));
}, },
Select(index) => {
*state.phrases_mode_mut() = Some(PhrasesMode::Import(
index, browser
))
},
_ => unreachable!() _ => unreachable!()
}, },
_ => unreachable!(), _ => unreachable!(),

View file

@ -188,11 +188,18 @@ impl Content for FileBrowser {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Widget<Engine = Tui> {
Stack::down(|add|{ Stack::down(|add|{
let mut i = 0;
for (_, name) in self.dirs.iter() { for (_, name) in self.dirs.iter() {
add(&name.as_str())?; if i >= self.scroll {
add(&TuiStyle::bold(name.as_str(), i == self.index))?;
}
i += 1;
} }
for (_, name) in self.files.iter() { for (_, name) in self.files.iter() {
add(&name.as_str())?; if i >= self.scroll {
add(&TuiStyle::bold(name.as_str(), i == self.index))?;
}
i += 1;
} }
Ok(()) Ok(())
}) })

View file

@ -89,7 +89,7 @@ where
} }
fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<SequencerCommand> { fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<SequencerCommand> {
use SequencerCommand as Cmd; use SequencerCommand::*;
if !state.entered() { if !state.entered() {
return None return None
} }
@ -98,18 +98,14 @@ fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<Seque
todo!() todo!()
}, },
AppFocus::Content(focused) => match focused { AppFocus::Content(focused) => match focused {
SequencerFocus::Phrases => Phrases(PhrasesCommand::input_to_command(state, input)?),
SequencerFocus::PhraseEditor => Editor(PhraseCommand::input_to_command(state, input)?),
SequencerFocus::Transport(_) => { SequencerFocus::Transport(_) => {
match TransportCommand::input_to_command(state, input)? { match TransportCommand::input_to_command(state, input)? {
TransportCommand::Clock(_) => { todo!() }, TransportCommand::Clock(_) => { todo!() },
TransportCommand::Focus(command) => Cmd::Focus(command), TransportCommand::Focus(command) => Focus(command),
} }
}, },
SequencerFocus::Phrases => {
Cmd::Phrases(PhrasesCommand::input_to_command(state, input)?)
},
SequencerFocus::PhraseEditor => {
Cmd::Editor(PhraseCommand::input_to_command(state, input)?)
},
} }
}) })
} }
@ -317,12 +313,13 @@ fn to_phrases_command <T: PhrasesControl> (state: &T, input: &TuiInput) -> Optio
impl<T: PhrasesControl> InputToCommand<Tui, T> for FileBrowserCommand { impl<T: PhrasesControl> InputToCommand<Tui, T> for FileBrowserCommand {
fn input_to_command (state: &T, from: &TuiInput) -> Option<Self> { fn input_to_command (state: &T, from: &TuiInput) -> Option<Self> {
use KeyCode::{Up, Down, Right, Left, Enter, Esc, Char, Backspace}; use KeyCode::{Up, Down, Right, Left, Enter, Esc, Char, Backspace};
use FileBrowserCommand::*;
if let Some(PhrasesMode::Import(index, browser)) = state.phrases_mode() { if let Some(PhrasesMode::Import(index, browser)) = state.phrases_mode() {
Some(match from.event() { Some(match from.event() {
key!(Up) => Self::Select(0), key!(Up) => Select(browser.index.overflowing_sub(1).0.min(browser.len())),
key!(Down) => Self::Select(0), key!(Down) => Select(browser.index.saturating_add(1) % browser.len()),
key!(Right) => Self::Chdir(browser.cwd.clone()), key!(Right) => Chdir(browser.cwd.clone()),
key!(Left) => Self::Chdir(browser.cwd.clone()), key!(Left) => Chdir(browser.cwd.clone()),
key!(Enter) => { todo!() }, key!(Enter) => { todo!() },
key!(Char(c)) => { todo!() }, key!(Char(c)) => { todo!() },
key!(Backspace) => { todo!() }, key!(Backspace) => { todo!() },
@ -331,10 +328,10 @@ impl<T: PhrasesControl> InputToCommand<Tui, T> for FileBrowserCommand {
}) })
} else if let Some(PhrasesMode::Export(index, browser)) = state.phrases_mode() { } else if let Some(PhrasesMode::Export(index, browser)) = state.phrases_mode() {
Some(match from.event() { Some(match from.event() {
key!(Up) => Self::Select(0), key!(Up) => Select(browser.index.overflowing_sub(1).0.min(browser.len())),
key!(Down) => Self::Select(0), key!(Down) => Select(browser.index.saturating_add(1) % browser.len()),
key!(Right) => Self::Chdir(browser.cwd.clone()), key!(Right) => Chdir(browser.cwd.clone()),
key!(Left) => Self::Chdir(browser.cwd.clone()), key!(Left) => Chdir(browser.cwd.clone()),
key!(Enter) => { todo!() }, key!(Enter) => { todo!() },
key!(Char(c)) => { todo!() }, key!(Char(c)) => { todo!() },
key!(Backspace) => { todo!() }, key!(Backspace) => { todo!() },

View file

@ -206,6 +206,9 @@ impl FileBrowser {
size: Measure::new(), size: Measure::new(),
}) })
} }
pub fn len (&self) -> usize {
self.dirs.len() + self.files.len()
}
} }
/// Displays and edits phrase length. /// Displays and edits phrase length.