bye sequencer

This commit is contained in:
🪞👃🪞 2024-07-03 18:36:16 +03:00
parent 2165e5d45d
commit 316fe45b2a
12 changed files with 510 additions and 759 deletions

View file

@ -1,203 +0,0 @@
use crate::{core::*, model::*};
pub fn handle (state: &mut Sequencer, event: &AppEvent) -> Usually<bool> {
handle_keymap(state, event, KEYMAP)
}
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],
[Right, NONE, "cursor_right", "move cursor right", cursor_right],
[Char('.'), NONE, "cursor_inc", "increase note duration", cursor_duration_inc],
[Char(','), NONE, "cursor_dec", "decrease note duration", cursor_duration_dec],
[Char('`'), NONE, "mode_next", "Next view mode", mode_next],
[Char('='), NONE, "zoom_in", "Zoom in", zoom_in],
[Char('-'), NONE, "zoom_out", "Zoom out", zoom_out],
[Char('a'), NONE, "note_add", "Add note", note_add],
[Char('z'), NONE, "note_del", "Delete note", note_del],
[CapsLock, NONE, "advance", "Toggle auto advance", nop],
[Char('w'), NONE, "rest", "Advance by note duration", nop],
[Char(' '), NONE, "toggle_play", "Toggle play/pause", toggle_play],
[Char('r'), NONE, "toggle_record", "Toggle recording", toggle_record],
[Char('d'), NONE, "toggle_overdub", "Toggle overdub", toggle_overdub],
[Char('m'), NONE, "toggle_monitor", "Toggle input monitoring", toggle_monitor],
[Char('s'), NONE, "stop_and_rewind", "Stop and rewind", stop_and_rewind],
[Char('q'), NONE, "quantize_next", "Next quantize value", quantize_next],
[Char('Q'), SHIFT, "quantize_prev", "Previous quantize value", quantize_prev],
});
fn nop (_: &mut Sequencer) -> Usually<bool> {
Ok(false)
}
fn note_add (s: &mut Sequencer) -> Usually<bool> {
if s.sequence.is_none() {
return Ok(false)
}
let ppq = s.timebase.ppq() as usize;
let step = s.time_start + s.time_cursor;
let start = step as usize * ppq / s.time_zoom;
let end = (step + 1) as usize * ppq / s.time_zoom;
let key = u7::from_int_lossy((s.note_cursor + s.note_start) as u8);
let note_on = MidiMessage::NoteOn { key, vel: 100.into() };
let note_off = MidiMessage::NoteOff { key, vel: 100.into() };
let sequence = &mut s.phrases[s.sequence.unwrap()].notes;
if sequence.contains_key(&start) {
sequence.get_mut(&start).unwrap().push(note_on.clone());
} else {
sequence.insert(start, vec![note_on]);
}
if sequence.contains_key(&end) {
sequence.get_mut(&end).unwrap().push(note_off.clone());
} else {
sequence.insert(end, vec![note_off]);
};
Ok(true)
}
fn note_del (_: &mut Sequencer) -> Usually<bool> {
Ok(true)
}
fn time_cursor_inc (s: &mut Sequencer) -> Usually<bool> {
s.time_cursor = s.time_cursor + 1;
Ok(true)
}
fn time_cursor_dec (s: &mut Sequencer) -> Usually<bool> {
s.time_cursor = s.time_cursor.saturating_sub(1);
Ok(true)
}
fn note_cursor_inc (s: &mut Sequencer) -> Usually<bool> {
s.note_cursor = s.note_cursor + 1;
Ok(true)
}
fn note_cursor_dec (s: &mut Sequencer) -> Usually<bool> {
s.note_cursor = s.note_cursor.saturating_sub(1);
Ok(true)
}
fn cursor_up (s: &mut Sequencer) -> Usually<bool> {
match s.view {
SequencerMode::Vertical => time_cursor_dec(s),
SequencerMode::Horizontal => note_cursor_dec(s),
_ => Ok(false)
}?;
Ok(true)
}
fn cursor_down (s: &mut Sequencer) -> Usually<bool> {
match s.view {
SequencerMode::Vertical => time_cursor_inc(s),
SequencerMode::Horizontal => note_cursor_inc(s),
_ => Ok(false)
}?;
Ok(true)
}
fn cursor_left (s: &mut Sequencer) -> Usually<bool> {
match s.view {
SequencerMode::Vertical => note_cursor_dec(s),
SequencerMode::Horizontal => time_cursor_dec(s),
_ => Ok(false)
}?;
Ok(true)
}
fn cursor_right (s: &mut Sequencer) -> Usually<bool> {
match s.view {
SequencerMode::Vertical => note_cursor_inc(s),
SequencerMode::Horizontal => time_cursor_inc(s),
_ => Ok(false)
}?;
Ok(true)
}
fn cursor_duration_inc (_: &mut Sequencer) -> Usually<bool> {
//s.cursor.2 = s.cursor.2 + 1
Ok(true)
}
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) -> Usually<bool> {
s.view = s.view.next();
Ok(true)
}
impl SequencerMode {
fn next (&self) -> Self {
match self {
Self::Horizontal => Self::Vertical,
Self::Vertical => Self::Tiny,
Self::Tiny => Self::Horizontal,
_ => self.clone()
}
}
}
fn stop_and_rewind (s: &mut Sequencer) -> Usually<bool> {
s.transport.stop()?;
s.transport.locate(0)?;
s.playing = TransportState::Stopped;
Ok(true)
}
fn toggle_play (s: &mut Sequencer) -> Usually<bool> {
s.playing = match s.playing {
TransportState::Stopped => {
s.transport.start()?;
TransportState::Starting
},
_ => {
s.transport.stop()?;
s.transport.locate(0)?;
TransportState::Stopped
},
};
Ok(true)
}
fn toggle_record (s: &mut Sequencer) -> Usually<bool> {
s.recording = !s.recording;
Ok(true)
}
fn toggle_overdub (s: &mut Sequencer) -> Usually<bool> {
s.overdub = !s.overdub;
Ok(true)
}
fn toggle_monitor (s: &mut Sequencer) -> Usually<bool> {
s.monitoring = !s.monitoring;
Ok(true)
}
fn quantize_next (s: &mut Sequencer) -> Usually<bool> {
if s.time_zoom < 64 {
s.time_zoom = s.time_zoom * 2;
}
Ok(true)
}
fn quantize_prev (s: &mut Sequencer) -> Usually<bool> {
if s.time_zoom > 1 {
s.time_zoom = s.time_zoom / 2;
}
Ok(true)
}
fn zoom_in (s: &mut Sequencer) -> Usually<bool> {
s.time_zoom = s.time_zoom / 2;
Ok(true)
}
fn zoom_out (s: &mut Sequencer) -> Usually<bool> {
s.time_zoom = s.time_zoom * 2;
Ok(true)
}