mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
67 lines
2.1 KiB
Rust
67 lines
2.1 KiB
Rust
use crate::prelude::*;
|
|
use super::Sequencer;
|
|
|
|
pub fn handle (state: &mut Sequencer, event: &Event) -> Result<(), Box<dyn Error>> {
|
|
|
|
if let Event::Input(crossterm::event::Event::Key(event)) = event {
|
|
|
|
match event.code {
|
|
KeyCode::Char('c') => {
|
|
if event.modifiers == KeyModifiers::CONTROL {
|
|
state.exit();
|
|
}
|
|
},
|
|
KeyCode::Down => {
|
|
state.cursor.0 = if state.cursor.0 >= 3 {
|
|
0
|
|
} else {
|
|
state.cursor.0 + 1
|
|
}
|
|
},
|
|
KeyCode::Up => {
|
|
state.cursor.0 = if state.cursor.0 == 0 {
|
|
3
|
|
} else {
|
|
state.cursor.0 - 1
|
|
}
|
|
},
|
|
KeyCode::Left => {
|
|
state.cursor.1 = if state.cursor.1 == 0 {
|
|
63
|
|
} else {
|
|
state.cursor.1 - 1
|
|
}
|
|
},
|
|
KeyCode::Right => {
|
|
state.cursor.1 = if state.cursor.1 == 63 {
|
|
0
|
|
} else {
|
|
state.cursor.1 + 1
|
|
}
|
|
},
|
|
KeyCode::Char('[') => {
|
|
if state.cursor.2 > 0 {
|
|
state.cursor.2 = state.cursor.2 - 1
|
|
}
|
|
},
|
|
KeyCode::Char(']') => {
|
|
state.cursor.2 = state.cursor.2 + 1
|
|
},
|
|
KeyCode::Char('a') => {
|
|
let row = state.cursor.0 as usize;
|
|
let step = state.cursor.1 as usize;
|
|
let duration = state.cursor.2 as usize;
|
|
let mut sequence = state.sequence.lock().unwrap();
|
|
sequence[row][step] = Some(super::Event::NoteOn(35, 128));
|
|
if state.cursor.2 > 0 {
|
|
sequence[row][step + duration] = Some(super::Event::NoteOff(35));
|
|
}
|
|
},
|
|
_ => {
|
|
println!("{event:?}");
|
|
}
|
|
}
|
|
|
|
}
|
|
Ok(())
|
|
}
|