even wackier focus logic

This commit is contained in:
🪞👃🪞 2024-06-20 21:33:15 +03:00
parent ce1c28edb9
commit f5d02f9f08
3 changed files with 206 additions and 135 deletions

View file

@ -415,10 +415,10 @@ fn draw_horizontal (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect
}
pub fn handle (s: &mut Sequencer, event: &AppEvent) -> Usually<bool> {
handle_keymap(COMMANDS, s, event)
handle_keymap(s, event, KEYMAP)
}
pub const COMMANDS: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
pub const KEYMAP: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
[Up, NONE, "cursor_up", "move cursor up", cursor_up],
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
[Left, NONE, "cursor_left", "move cursor left", cursor_left],
@ -444,9 +444,10 @@ pub const COMMANDS: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
[Char('s'), SHIFT, "sync", "Focus sync selector", nop]
});
fn nop (_: &mut Sequencer) {
fn nop (_: &mut Sequencer) -> Usually<bool> {
Ok(false)
}
fn note_add (s: &mut Sequencer) {
fn note_add (s: &mut Sequencer) -> Usually<bool> {
let pos = s.transport.query().unwrap().pos;
let usecs = s.timebase.frame_to_usec(pos.frame() as usize);
let step = (s.time_axis.0 + s.time_cursor) as u32;
@ -464,62 +465,75 @@ fn note_add (s: &mut Sequencer) {
s.sequence.get_mut(&end).unwrap().push(note_off.clone());
} else {
s.sequence.insert(end, vec![note_off]);
}
};
Ok(true)
}
fn note_del (_: &mut Sequencer) {
fn note_del (_: &mut Sequencer) -> Usually<bool> {
Ok(true)
}
fn time_cursor_inc (s: &mut Sequencer) {
fn time_cursor_inc (s: &mut Sequencer) -> Usually<bool> {
let time = s.time_axis.1 - s.time_axis.0;
s.time_cursor = ((time + s.time_cursor) + 1) % time
s.time_cursor = ((time + s.time_cursor) + 1) % time;
Ok(true)
}
fn time_cursor_dec (s: &mut Sequencer) {
fn time_cursor_dec (s: &mut Sequencer) -> Usually<bool> {
let time = s.time_axis.1 - s.time_axis.0;
s.time_cursor = ((time + s.time_cursor) - 1) % time
s.time_cursor = ((time + s.time_cursor) - 1) % time;
Ok(true)
}
fn note_cursor_inc (s: &mut Sequencer) {
fn note_cursor_inc (s: &mut Sequencer) -> Usually<bool> {
let note = s.note_axis.1 - s.note_axis.0;
s.note_cursor = ((note + s.note_cursor) + 1) % note
s.note_cursor = ((note + s.note_cursor) + 1) % note;
Ok(true)
}
fn note_cursor_dec (s: &mut Sequencer) {
fn note_cursor_dec (s: &mut Sequencer) -> Usually<bool> {
let note = s.note_axis.1 - s.note_axis.0;
s.note_cursor = ((note + s.note_cursor) - 1) % note
s.note_cursor = ((note + s.note_cursor) - 1) % note;
Ok(true)
}
fn cursor_up (s: &mut Sequencer) {
fn cursor_up (s: &mut Sequencer) -> Usually<bool> {
match s.mode {
SequencerView::Vertical => time_cursor_dec(s),
SequencerView::Horizontal => note_cursor_dec(s),
_ => unimplemented!()
}
};
Ok(true)
}
fn cursor_down (s: &mut Sequencer) {
fn cursor_down (s: &mut Sequencer) -> Usually<bool> {
match s.mode {
SequencerView::Vertical => time_cursor_inc(s),
SequencerView::Horizontal => note_cursor_inc(s),
_ => unimplemented!()
}
};
Ok(true)
}
fn cursor_left (s: &mut Sequencer) {
fn cursor_left (s: &mut Sequencer) -> Usually<bool> {
match s.mode {
SequencerView::Vertical => note_cursor_dec(s),
SequencerView::Horizontal => time_cursor_dec(s),
_ => unimplemented!()
}
};
Ok(true)
}
fn cursor_right (s: &mut Sequencer) {
fn cursor_right (s: &mut Sequencer) -> Usually<bool> {
match s.mode {
SequencerView::Vertical => note_cursor_inc(s),
SequencerView::Horizontal => time_cursor_inc(s),
_ => unimplemented!()
}
};
Ok(true)
}
fn cursor_duration_inc (_: &mut Sequencer) {
fn cursor_duration_inc (_: &mut Sequencer) -> Usually<bool> {
//s.cursor.2 = s.cursor.2 + 1
Ok(true)
}
fn cursor_duration_dec (_: &mut Sequencer) {
fn cursor_duration_dec (_: &mut Sequencer) -> Usually<bool> {
//if s.cursor.2 > 0 { s.cursor.2 = s.cursor.2 - 1 }
Ok(true)
}
fn mode_next (s: &mut Sequencer) {
s.mode = s.mode.next()
fn mode_next (s: &mut Sequencer) -> Usually<bool> {
s.mode = s.mode.next();
Ok(true)
}
impl SequencerView {
fn next (&self) -> Self {
@ -530,27 +544,33 @@ impl SequencerView {
}
}
}
fn stop_and_rewind (s: &mut Sequencer) {
s.playing = false
fn stop_and_rewind (s: &mut Sequencer) -> Usually<bool> {
s.playing = false;
Ok(true)
}
fn toggle_play (s: &mut Sequencer) {
s.playing = !s.playing
fn toggle_play (s: &mut Sequencer) -> Usually<bool> {
s.playing = !s.playing;
Ok(true)
}
fn toggle_record (s: &mut Sequencer) {
s.recording = !s.recording
fn toggle_record (s: &mut Sequencer) -> Usually<bool> {
s.recording = !s.recording;
Ok(true)
}
fn toggle_overdub (s: &mut Sequencer) {
s.overdub = !s.overdub
fn toggle_overdub (s: &mut Sequencer) -> Usually<bool> {
s.overdub = !s.overdub;
Ok(true)
}
fn quantize_next (s: &mut Sequencer) {
fn quantize_next (s: &mut Sequencer) -> Usually<bool> {
if s.resolution < 64 {
s.resolution = s.resolution * 2
s.resolution = s.resolution * 2;
}
Ok(true)
}
fn quantize_prev (s: &mut Sequencer) {
fn quantize_prev (s: &mut Sequencer) -> Usually<bool> {
if s.resolution > 1 {
s.resolution = s.resolution / 2
s.resolution = s.resolution / 2;
}
Ok(true)
}
#[cfg(test)] mod test {