wip: p.59, e=54

This commit is contained in:
🪞👃🪞 2024-11-19 23:05:17 +01:00
parent e95230a340
commit f4a4b08c8a
3 changed files with 38 additions and 56 deletions

View file

@ -25,7 +25,7 @@ impl PhraseTui {
entered: false, entered: false,
mode: false, mode: false,
now: Arc::new(0.into()), now: Arc::new(0.into()),
size: Measure::default(), size: Measure::new(),
//width: 0.into(), //width: 0.into(),
//height: 0.into(), //height: 0.into(),
note_axis: RwLock::new(FixedAxis { note_axis: RwLock::new(FixedAxis {
@ -43,43 +43,6 @@ impl PhraseTui {
} }
} }
//pub fn track_next (&mut self, last_track: usize) {
//use ArrangerSelection::*;
//*self = match self {
//Mix => Track(0),
//Track(t) => Track(last_track.min(*t + 1)),
//Scene(s) => Clip(0, *s),
//Clip(t, s) => Clip(last_track.min(*t + 1), *s),
//}
//}
//pub fn track_prev (&mut self) {
//use ArrangerSelection::*;
//*self = match self {
//Mix => Mix,
//Scene(s) => Scene(*s),
//Track(t) => if *t == 0 { Mix } else { Track(*t - 1) },
//Clip(t, s) => if *t == 0 { Scene(*s) } else { Clip(t.saturating_sub(1), *s) }
//}
//}
//pub fn scene_next (&mut self, last_scene: usize) {
//use ArrangerSelection::*;
//*self = match self {
//Mix => Scene(0),
//Track(t) => Clip(*t, 0),
//Scene(s) => Scene(last_scene.min(*s + 1)),
//Clip(t, s) => Clip(*t, last_scene.min(*s + 1)),
//}
//}
//pub fn scene_prev (&mut self) {
//use ArrangerSelection::*;
//*self = match self {
//Mix => Mix,
//Track(t) => Track(*t),
//Scene(s) => if *s == 0 { Mix } else { Scene(*s - 1) },
//Clip(t, s) => if *s == 0 { Track(*t) } else { Clip(*t, s.saturating_sub(1)) }
//}
//}
//pub fn arranger_menu_bar () -> MenuBar { //pub fn arranger_menu_bar () -> MenuBar {
//use ArrangerCommand as Cmd; //use ArrangerCommand as Cmd;
//use ArrangerCommand as Edit; //use ArrangerCommand as Edit;

View file

@ -136,14 +136,12 @@ pub enum PhrasesCommand {
impl<T: PhrasesControl> Command<T> for PhrasesCommand { impl<T: PhrasesControl> Command<T> for PhrasesCommand {
fn execute (self, state: &mut T) -> Perhaps<Self> { fn execute (self, state: &mut T) -> Perhaps<Self> {
use PhraseRenameCommand as Rename;
use PhraseLengthCommand as Length;
Ok(match self { Ok(match self {
Self::Phrase(command) => command.execute(state)?.map(Self::Phrase), Self::Phrase(command) => command.execute(state)?.map(Self::Phrase),
Self::Rename(command) => command.execute(state)?.map(Self::Rename), Self::Rename(command) => command.execute(state)?.map(Self::Rename),
Self::Length(command) => command.execute(state)?.map(Self::Length), Self::Length(command) => command.execute(state)?.map(Self::Length),
Self::Select(phrase) => { Self::Select(phrase) => {
state.phrase = phrase; *state.phrase_index_mut() = phrase;
None None
}, },
}) })
@ -165,10 +163,15 @@ impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
fn execute (self, state: &mut T) -> Perhaps<Self> { fn execute (self, state: &mut T) -> Perhaps<Self> {
use PhraseLengthFocus::*; use PhraseLengthFocus::*;
use PhraseLengthCommand::*; use PhraseLengthCommand::*;
if let Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) = state.mode { let mode = state.phrases_mode_mut();
if let Some(PhrasesMode::Length(
phrase,
ref mut length,
ref mut focus,
)) = mode {
match self { match self {
Self::Cancel => { Self::Cancel => {
state.mode = None; *state.phrases_mode_mut() = None;
}, },
Self::Prev => { Self::Prev => {
focus.prev() focus.prev()
@ -190,7 +193,7 @@ impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
let mut phrase = state.phrases[phrase].write().unwrap(); let mut phrase = state.phrases[phrase].write().unwrap();
let old_length = phrase.length; let old_length = phrase.length;
phrase.length = length; phrase.length = length;
state.mode = None; *mode = None;
return Ok(Some(Self::Set(old_length))) return Ok(Some(Self::Set(old_length)))
}, },
_ => unreachable!() _ => unreachable!()
@ -219,7 +222,7 @@ where
{ {
fn execute (self, state: &mut T) -> Perhaps<Self> { fn execute (self, state: &mut T) -> Perhaps<Self> {
use PhraseRenameCommand::*; use PhraseRenameCommand::*;
if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = state.phrases_mode() { if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = state.phrases_mode_mut() {
match self { match self {
Set(s) => { Set(s) => {
state.phrases()[*phrase].write().unwrap().name = s.into(); state.phrases()[*phrase].write().unwrap().name = s.into();
@ -279,7 +282,7 @@ where
use PhraseCommand::*; use PhraseCommand::*;
Ok(match self { Ok(match self {
ToggleDirection => { ToggleDirection => {
state.mode = !state.mode; state.phrase_mode_mut() = !state.mode;
None None
}, },
EnterEditMode => { EnterEditMode => {

View file

@ -147,8 +147,16 @@ where
key!(KeyCode::Up) => match state.selected() { key!(KeyCode::Up) => match state.selected() {
Select::Mix => return None, Select::Mix => return None,
Select::Track(t) => return None, Select::Track(t) => return None,
Select::Scene(s) => Select(Select::Scene(s - 1)), Select::Scene(s) => if s > 0 {
Select::Clip(t, s) => Select(Select::Clip(t, s - 1)), Select(Select::Scene(s - 1))
} else {
Select(Select::Mix)
},
Select::Clip(t, s) => if s > 0 {
Select(Select::Clip(t, s - 1))
} else {
Select(Select::Track(t))
},
}, },
key!(KeyCode::Down) => match state.selected() { key!(KeyCode::Down) => match state.selected() {
@ -160,9 +168,17 @@ where
key!(KeyCode::Left) => match state.selected() { key!(KeyCode::Left) => match state.selected() {
Select::Mix => return None, Select::Mix => return None,
Select::Track(t) => Select(Select::Track(t - 1)), Select::Track(t) => if t > 0 {
Select(Select::Track(t - 1))
} else {
Select(Select::Mix)
},
Select::Scene(s) => return None, Select::Scene(s) => return None,
Select::Clip(t, s) => Select(Select::Clip(t - 1, s)), Select::Clip(t, s) => if t > 0 {
Select(Select::Clip(t - 1, s))
} else {
Select(Select::Scene(s))
},
}, },
key!(KeyCode::Right) => match state.selected() { key!(KeyCode::Right) => match state.selected() {
@ -256,31 +272,31 @@ impl<T: PhrasesControl> InputToCommand<Tui, T> for PhrasesCommand {
use PhrasePoolCommand as Phrase; use PhrasePoolCommand as Phrase;
use PhraseRenameCommand as Rename; use PhraseRenameCommand as Rename;
use PhraseLengthCommand as Length; use PhraseLengthCommand as Length;
let index = state.phrase(); let index = state.phrase_index();
let count = state.phrases().len(); let count = state.phrases().len();
match input.event() { match input.event() {
key!(KeyCode::Up) => Some(Self::Select(0)), key!(KeyCode::Up) => Some(Self::Select(0)),
key!(KeyCode::Down) => Some(Self::Select(0)), key!(KeyCode::Down) => Some(Self::Select(0)),
key!(KeyCode::Char(',')) => { key!(KeyCode::Char(',')) => {
if index > 1 { if index > 1 {
*state.phrase_index_mut() -= 1;
Some(Self::Phrase(Phrase::Swap(index - 1, index))) Some(Self::Phrase(Phrase::Swap(index - 1, index)))
//index -= 1;
} else { } else {
None None
} }
}, },
key!(KeyCode::Char('.')) => { key!(KeyCode::Char('.')) => {
if index < count.saturating_sub(1) { if index < count.saturating_sub(1) {
*state.phrase_index_mut() += 1;
Some(Self::Phrase(Phrase::Swap(index + 1, index))) Some(Self::Phrase(Phrase::Swap(index + 1, index)))
//index += 1;
} else { } else {
None None
} }
}, },
key!(KeyCode::Delete) => { key!(KeyCode::Delete) => {
if index > 0 { if index > 0 {
Some(Self::Delete(index)) *state.phrase_index_mut() = index.min(count.saturating_sub(1));
//index = index.min(count.saturating_sub(1)); Some(Self::Phrase(Phrase::Delete(index)))
} else { } else {
None None
} }
@ -288,7 +304,7 @@ impl<T: PhrasesControl> InputToCommand<Tui, T> for PhrasesCommand {
key!(KeyCode::Char('a')) => Some(Self::Phrase(Phrase::Add(count))), key!(KeyCode::Char('a')) => Some(Self::Phrase(Phrase::Add(count))),
key!(KeyCode::Char('i')) => Some(Self::Phrase(Phrase::Add(index + 1))), key!(KeyCode::Char('i')) => Some(Self::Phrase(Phrase::Add(index + 1))),
key!(KeyCode::Char('d')) => Some(Self::Phrase(Phrase::Duplicate(index))), key!(KeyCode::Char('d')) => Some(Self::Phrase(Phrase::Duplicate(index))),
key!(KeyCode::Char('c')) => Some(Self::Phrase(Phrase::RandomColor(index))), key!(KeyCode::Char('c')) => Some(Self::Phrase(Phrase::Color(index, ItemColor::random()))),
key!(KeyCode::Char('n')) => Some(Self::Rename(Rename::Begin)), key!(KeyCode::Char('n')) => Some(Self::Rename(Rename::Begin)),
key!(KeyCode::Char('t')) => Some(Self::Length(Length::Begin)), key!(KeyCode::Char('t')) => Some(Self::Length(Length::Begin)),
_ => match state.phrases_mode() { _ => match state.phrases_mode() {