wip: p.58, e=57

This commit is contained in:
🪞👃🪞 2024-11-19 00:30:03 +01:00
parent 0c94c2af8f
commit e95230a340
5 changed files with 173 additions and 174 deletions

View file

@ -38,17 +38,21 @@ pub enum SequencerCommand {
impl<T> Command<T> for SequencerCommand
where
T: FocusGrid + PhrasesControl + PhraseControl + ClockApi + PlayheadApi
T: PhrasesControl + PhraseControl + ClockApi + PlayheadApi
+ FocusGrid<Item = SequencerFocus> + FocusEnter<Item = SequencerFocus>
{
fn execute (self, state: T) -> Perhaps<Self> {
fn execute (self, state: &mut T) -> Perhaps<Self> {
use SequencerCommand::*;
match self {
Focus(cmd) => delegate(cmd, Focus, state),
Phrases(cmd) => delegate(cmd, Phrases, state),
Editor(cmd) => delegate(cmd, Editor, state),
Clock(cmd) => delegate(cmd, Clock, state),
Playhead(cmd) => delegate(cmd, Playhead, state)
}
Ok(match self {
Focus(cmd) => cmd.execute(state)?.map(Focus),
Phrases(cmd) => cmd.execute(state)?.map(Phrases),
Editor(cmd) => cmd.execute(state)?.map(Editor),
Clock(cmd) => cmd.execute(state)?.map(Clock),
Playhead(cmd) => cmd.execute(state)?.map(Playhead),
Undo => { todo!() },
Redo => { todo!() },
Clear => { todo!() },
})
}
}
@ -72,28 +76,32 @@ pub enum ArrangerCommand {
impl<T> Command<T> for ArrangerCommand
where
T: FocusGrid + ArrangerControl + HasPhrases + PhraseControl + ClockApi + PlayheadApi
T: ArrangerControl + HasPhrases + PhraseControl + ClockApi + PlayheadApi
+ FocusGrid<Item = ArrangerFocus> + FocusEnter<Item = ArrangerFocus>
{
fn execute (self, state: &mut T) -> Perhaps<Self> {
use ArrangerCommand::*;
match self {
Focus(cmd) => { delegate(cmd, Focus, &mut state) },
Scene(cmd) => { delegate(cmd, Scene, &mut state) },
Track(cmd) => { delegate(cmd, Track, &mut state) },
Clip(cmd) => { delegate(cmd, Clip, &mut state) },
Phrases(cmd) => { delegate(cmd, Phrases, &mut state) },
Editor(cmd) => { delegate(cmd, Editor, &mut state) },
Clock(cmd) => { delegate(cmd, Clock, &mut state) },
Playhead(cmd) => { delegate(cmd, Playhead, &mut state) },
Ok(match self {
Focus(cmd) => cmd.execute(state)?.map(Focus),
Scene(cmd) => cmd.execute(state)?.map(Scene),
Track(cmd) => cmd.execute(state)?.map(Track),
Clip(cmd) => cmd.execute(state)?.map(Clip),
Phrases(cmd) => cmd.execute(state)?.map(Phrases),
Editor(cmd) => cmd.execute(state)?.map(Editor),
Clock(cmd) => cmd.execute(state)?.map(Clock),
Playhead(cmd) => cmd.execute(state)?.map(Playhead),
Zoom(zoom) => { todo!(); },
Select(selected) => { state.selected = selected; Ok(None) },
Select(selected) => {
state.selected = selected;
None
},
EditPhrase(phrase) => {
state.editor.phrase = phrase.clone();
state.focus(ArrangerFocus::PhraseEditor);
state.focus_enter();
Ok(None)
None
}
}
})
}
}
@ -124,31 +132,21 @@ pub enum PhrasesCommand {
Phrase(PhrasePoolCommand),
Rename(PhraseRenameCommand),
Length(PhraseLengthCommand),
MoveUp,
MoveDown,
}
impl<T: PhrasesControl> Command<T> for PhrasesCommand {
fn execute (self, state: &mut T) -> Perhaps<Self> {
use PhraseRenameCommand as Rename;
use PhraseLengthCommand as Length;
match self {
Ok(match self {
Self::Phrase(command) => command.execute(state)?.map(Self::Phrase),
Self::Rename(command) => command.execute(state)?.map(Self::Rename),
Self::Length(command) => command.execute(state)?.map(Self::Length),
Self::Select(phrase) => {
state.phrase = phrase
state.phrase = phrase;
None
},
Self::Phrase(command) => {
return Ok(command.execute(&mut state)?.map(Self::Phrase))
}
Self::Rename(command) => match command {
Rename::Begin => self.phrases_rename_begin(),
_ => return Ok(command.execute(state)?.map(Self::Rename)),
},
Self::Length(command) => match command {
Length::Begin => self.phrases_length_begin(),
_ => return Ok(command.execute(state)?.map(Self::Length)),
},
}
Ok(None)
})
}
}
@ -199,7 +197,7 @@ impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
}
Ok(None)
} else if self == Begin {
self.phrases_length_begin();
state.phrase_length_begin();
Ok(None)
} else {
unreachable!()
@ -239,7 +237,7 @@ where
};
Ok(None)
} else if self == Begin {
self.phrase_rename_begin();
state.phrase_rename_begin();
Ok(None)
} else {
unreachable!()
@ -279,81 +277,107 @@ where
//}
fn execute (self, state: &mut T) -> Perhaps<Self> {
use PhraseCommand::*;
match self.translate(state) {
Ok(match self {
ToggleDirection => {
state.mode = !state.mode;
None
},
EnterEditMode => {
state.focus_enter();
None
},
ExitEditMode => {
state.focus_exit();
None
},
TimeZoomOut => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().scale = next_note_length(scale)
state.time_axis().write().unwrap().scale = next_note_length(scale);
None
},
TimeZoomIn => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().scale = prev_note_length(scale)
state.time_axis().write().unwrap().scale = prev_note_length(scale);
None
},
TimeCursorDec => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().point_dec(scale);
None
},
TimeCursorInc => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().point_inc(scale);
None
},
TimeScrollDec => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().start_dec(scale);
None
},
TimeScrollInc => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().start_inc(scale);
None
},
NoteCursorDec => {
let mut axis = state.note_axis().write().unwrap();
axis.point_inc(1);
if let Some(point) = axis.point { if point > 73 { axis.point = Some(73); } }
if let Some(point) = axis.point {
if point > 73 { axis.point = Some(73); }
}
None
},
NoteCursorInc => {
let mut axis = state.note_axis().write().unwrap();
axis.point_dec(1);
if let Some(point) = axis.point { if point < axis.start { axis.start = (point / 2) * 2; } }
if let Some(point) = axis.point {
if point < axis.start { axis.start = (point / 2) * 2; }
}
None
},
NoteScrollDec => {
state.note_axis().write().unwrap().start_inc(1);
None
},
NoteScrollInc => {
state.note_axis().write().unwrap().start_dec(1);
None
},
NoteLengthDec => {
*state.note_len_mut() = prev_note_length(state.note_len())
*state.note_len_mut() = prev_note_length(state.note_len());
None
},
NoteLengthInc => {
*state.note_len_mut() = next_note_length(state.note_len())
*state.note_len_mut() = next_note_length(state.note_len());
None
},
NotePageUp => {
let mut axis = state.note_axis().write().unwrap();
axis.start_dec(3);
axis.point_dec(3);
None
},
NotePageDown => {
let mut axis = state.note_axis().write().unwrap();
axis.start_inc(3);
axis.point_inc(3);
None
},
NoteAppend => if state.focus_entered() {
state.put();
state.time_cursor_advance();
None
} else {
None
},
NoteSet => if state.focus_entered() {
state.put();
None
} else {
None
},
_ => unreachable!()
}
Ok(None)
})
}
}