edit toggle; reallow add/duplicate phrase

This commit is contained in:
🪞👃🪞 2024-12-11 21:58:26 +01:00
parent 14fac03f5d
commit d0d187b5b6
2 changed files with 19 additions and 6 deletions

View file

@ -280,7 +280,17 @@ pub fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<S
})),
// E: Toggle between editing currently playing or other phrase
//key!(Char('e')) => {}
key!(Char('e')) => if let Some((_, Some(playing_phrase))) = state.player.play_phrase() {
let editing_phrase = state.editor.phrase.as_ref().map(|p|p.read().unwrap().clone());
let selected_phrase = state.phrases.phrase().clone();
if Some(selected_phrase.read().unwrap().clone()) != editing_phrase {
Editor(Show(Some(selected_phrase)))
} else {
Editor(Show(Some(playing_phrase.clone())))
}
} else {
return None
},
// Transport: Play/pause
key!(Char(' ')) =>
@ -295,7 +305,7 @@ pub fn to_sequencer_command (state: &SequencerTui, input: &TuiInput) -> Option<S
Editor(PhraseCommand::input_to_command(&state.editor, input)?),
// List: select phrase to edit, change color
key!(Char('[')) | key!(Char(']')) | key!(Char('c')) =>
key!(Char('[')) | key!(Char(']')) | key!(Char('c')) | key!(Shift-Char('A')) | key!(Shift-Char('D')) =>
Phrases(PhrasesCommand::input_to_command(&state.phrases, input)?),
// Enqueue currently edited phrase

View file

@ -33,6 +33,9 @@ impl Default for PhraseListModel {
}
impl PhraseListModel {
pub(crate) fn phrase (&self) -> &Arc<RwLock<Phrase>> {
&self.phrases[self.phrase_index()]
}
pub(crate) fn phrase_index (&self) -> usize {
self.phrase.load(Ordering::Relaxed)
}
@ -250,10 +253,10 @@ fn to_phrases_command (state: &PhraseListModel, input: &TuiInput) -> Option<Phra
key!(Char('m')) => Cmd::Import(Browse::Begin),
key!(Char('x')) => Cmd::Export(Browse::Begin),
key!(Char('c')) => Cmd::Phrase(Pool::SetColor(index, ItemColor::random())),
key!(Up) => Cmd::Select(
key!(Up) | key!(Char('[')) => Cmd::Select(
index.overflowing_sub(1).0.min(state.phrases().len() - 1)
),
key!(Down) => Cmd::Select(
key!(Down) | key!(Char(']')) => Cmd::Select(
index.saturating_add(1) % state.phrases().len()
),
key!(Char('<')) => if index > 1 {
@ -274,13 +277,13 @@ fn to_phrases_command (state: &PhraseListModel, input: &TuiInput) -> Option<Phra
} else {
return None
},
key!(Char('a')) => Cmd::Phrase(Pool::Add(count, Phrase::new(
key!(Char('a')) | key!(Shift-Char('A')) => Cmd::Phrase(Pool::Add(count, Phrase::new(
String::from("(new)"), true, 4 * PPQ, None, Some(ItemPalette::random())
))),
key!(Char('i')) => Cmd::Phrase(Pool::Add(index + 1, Phrase::new(
String::from("(new)"), true, 4 * PPQ, None, Some(ItemPalette::random())
))),
key!(Char('d')) => {
key!(Char('d')) | key!(Shift-Char('D')) => {
let mut phrase = state.phrases()[index].read().unwrap().duplicate();
phrase.color = ItemPalette::random_near(phrase.color, 0.25);
Cmd::Phrase(Pool::Add(index + 1, phrase))