mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
317 lines
11 KiB
Rust
317 lines
11 KiB
Rust
pub mod focus;
|
|
pub mod mixer;
|
|
pub mod plugin;
|
|
pub mod sampler;
|
|
|
|
pub use self::focus::*;
|
|
|
|
use crate::{core::*, handle, App, AppSection};
|
|
|
|
handle!(App |self, e| {
|
|
if let Some(ref mut modal) = self.modal {
|
|
if modal.handle(e)? {
|
|
self.modal = None;
|
|
return Ok(true)
|
|
};
|
|
}
|
|
let handle_focused = |state: &mut Self|match state.section {
|
|
AppSection::Grid =>
|
|
handle_keymap(state, e, KEYMAP_GRID),
|
|
AppSection::Sequencer =>
|
|
handle_keymap(state, e, KEYMAP_SEQUENCER),
|
|
AppSection::Chain =>
|
|
handle_keymap(state, e, KEYMAP_CHAIN),
|
|
};
|
|
Ok(if self.entered {
|
|
handle_focused(self)?
|
|
|| handle_keymap(self, e, KEYMAP)?
|
|
|| handle_keymap(self, e, KEYMAP_FOCUS)?
|
|
} else {
|
|
handle_keymap(self, e, KEYMAP)?
|
|
|| handle_keymap(self, e, KEYMAP_FOCUS)?
|
|
|| handle_focused(self)?
|
|
})
|
|
});
|
|
|
|
const KEYMAP_FOCUS: &'static [KeyBinding<App>] = keymap!(App {
|
|
[Tab, NONE, "focus_next", "focus next area", focus_next],
|
|
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],
|
|
[Esc, NONE, "focus_exit", "unfocus", |app: &mut App|{
|
|
app.entered = false;
|
|
Ok(true)
|
|
}],
|
|
[Enter, NONE, "focus_enter", "activate item at cursor", |app: &mut App|{
|
|
app.entered = true;
|
|
Ok(true)
|
|
}],
|
|
});
|
|
|
|
const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
|
|
|
[F(1), NONE, "help_toggle", "toggle help", |_: &mut App| {Ok(true)}],
|
|
|
|
[Up, NONE, "focus_prev", "focus previous area", focus_prev],
|
|
[Down, NONE, "focus_next", "focus next area", focus_next],
|
|
|
|
[Char(' '), NONE, "play_toggle", "play or pause", |app: &mut App| {
|
|
app.toggle_play()?;
|
|
Ok(true)
|
|
}],
|
|
[Char('r'), NONE, "record_toggle", "toggle recording", |app: &mut App| {
|
|
app.track_mut().map(|t|t.1.toggle_record());
|
|
Ok(true)
|
|
}],
|
|
[Char('o'), NONE, "overdub_toggle", "toggle overdub", |app: &mut App| {
|
|
app.track_mut().map(|t|t.1.toggle_overdub());
|
|
Ok(true)
|
|
}],
|
|
[Char('m'), NONE, "monitor_toggle", "toggle monitor", |app: &mut App| {
|
|
app.track_mut().map(|t|t.1.toggle_monitor());
|
|
Ok(true)
|
|
}],
|
|
|
|
[Char('+'), NONE, "quant_inc", "Quantize coarser", |app: &mut App| {
|
|
app.quant = next_note_length(app.quant);
|
|
Ok(true)
|
|
}],
|
|
[Char('_'), NONE, "quant_dec", "Quantize finer", |app: &mut App| {
|
|
app.quant = prev_note_length(app.quant);
|
|
Ok(true)
|
|
}],
|
|
|
|
[Char('='), NONE, "zoom_in", "Zoom in", |app: &mut App| {
|
|
app.time_zoom = prev_note_length(app.time_zoom);
|
|
Ok(true)
|
|
}],
|
|
[Char('-'), NONE, "zoom_out", "Zoom out", |app: &mut App| {
|
|
app.time_zoom = next_note_length(app.time_zoom);
|
|
Ok(true)
|
|
}],
|
|
|
|
[Char('x'), NONE, "extend", "double the current clip", |app: &mut App| {
|
|
if let Some(phrase) = app.phrase_mut() {
|
|
let mut notes = BTreeMap::new();
|
|
for (time, events) in phrase.notes.iter() {
|
|
notes.insert(time + phrase.length, events.clone());
|
|
}
|
|
phrase.notes.append(&mut notes);
|
|
phrase.length = phrase.length * 2;
|
|
}
|
|
Ok(true)
|
|
}],
|
|
|
|
[Char('l'), NONE, "loop_toggle", "toggle looping", |_app: &mut App| {
|
|
// TODO: This toggles the loop flag for the clip under the cursor.
|
|
Ok(true)
|
|
}],
|
|
[Char('['), NONE, "loop_start_dec", "move loop start back", |_app: &mut App| {
|
|
// TODO: This moves the loop start to the previous quant.
|
|
Ok(true)
|
|
}],
|
|
[Char(']'), NONE, "loop_start_inc", "move loop start forward", |_app: &mut App| {
|
|
// TODO: This moves the loop start to the next quant.
|
|
Ok(true)
|
|
}],
|
|
[Char('{'), NONE, "loop_end_dec", "move loop end back", |_app: &mut App| {
|
|
// TODOO: This moves the loop end to the previous quant.
|
|
Ok(true)
|
|
}],
|
|
[Char('}'), NONE, "loop_end_inc", "move loop end forward", |_app: &mut App| {
|
|
// TODO: This moves the loop end to the next quant.
|
|
Ok(true)
|
|
}],
|
|
|
|
|
|
[Char('a'), CONTROL, "scene_add", "add a new scene", |app: &mut App| {
|
|
app.add_scene(None)?;
|
|
Ok(true)
|
|
}],
|
|
[Char('t'), CONTROL, "track_add", "add a new track", |app: &mut App| {
|
|
app.add_track(None)?;
|
|
Ok(true)
|
|
}],
|
|
|
|
[Char('.'), NONE, "cursor_inc", "increment value", increment],
|
|
[Char(','), NONE, "cursor_dec", "decrement value", decrement],
|
|
[Delete, CONTROL, "cursor_delete", "delete item at cursor", delete],
|
|
[Char('d'), CONTROL, "cursor_duplicate", "duplicate scene or track", duplicate],
|
|
|
|
//[Char('r'), CONTROL, "rename", "rename current element", rename],
|
|
// [Char('s'), NONE, "stop_and_rewind", "Stop and rewind", stop_and_rewind],
|
|
});
|
|
|
|
const KEYMAP_GRID: &'static [KeyBinding<App>] = keymap!(App {
|
|
[Up, NONE, "grid_cursor_up", "move cursor up", |app: &mut App| Ok(match app.grid_mode {
|
|
false => {app.scene_cursor = app.scene_cursor.saturating_sub(1); true},
|
|
true => {app.track_cursor = app.track_cursor.saturating_sub(1); true},
|
|
})],
|
|
[Down, NONE, "grid_cursor_down", "move cursor down", |app: &mut App| Ok(match app.grid_mode {
|
|
false => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); true},
|
|
true => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); true},
|
|
})],
|
|
[Left, NONE, "grid_cursor_left", "move cursor left", |app: &mut App| Ok(match app.grid_mode {
|
|
false => {app.track_cursor = app.track_cursor.saturating_sub(1); true},
|
|
true => {app.scene_cursor = app.scene_cursor.saturating_sub(1); true},
|
|
})],
|
|
[Right, NONE, "grid_cursor_right", "move cursor right", |app: &mut App| Ok(match app.grid_mode {
|
|
false => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); true},
|
|
true => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); true},
|
|
})],
|
|
[Enter, NONE, "grid_activate", "activate item at cursor", |app: &mut App| Ok(
|
|
if app.scene_cursor == 0 {
|
|
false
|
|
} else {
|
|
let scene = &app.scenes[app.scene_cursor - 1];
|
|
if app.track_cursor == 0 {
|
|
for (i, track) in app.tracks.iter_mut().enumerate() {
|
|
track.sequence = scene.clips[i];
|
|
track.reset = true;
|
|
}
|
|
} else {
|
|
let track = &mut app.tracks[app.track_cursor - 1];
|
|
track.sequence = scene.clips[app.track_cursor - 1];
|
|
track.reset = true;
|
|
};
|
|
true
|
|
}
|
|
)],
|
|
[Char('.'), NONE, "grid_increment", "increment item at cursor", clip_next],
|
|
[Char(','), NONE, "grid_decrement", "decrement item at cursor", clip_prev],
|
|
[Char('`'), NONE, "grid_mode_switch", "switch the display mode", |app: &mut App| {
|
|
app.grid_mode = !app.seq_mode;
|
|
Ok(true)
|
|
}],
|
|
});
|
|
|
|
const KEYMAP_SEQUENCER: &'static [KeyBinding<App>] = keymap!(App {
|
|
[Up, NONE, "seq_cursor_up", "move cursor up", |app: &mut App| {
|
|
app.note_cursor = app.note_cursor.saturating_sub(1);
|
|
Ok(true)
|
|
}],
|
|
[Down, NONE, "seq_cursor_down", "move cursor up", |app: &mut App| {
|
|
app.note_cursor = app.note_cursor + 1;
|
|
Ok(true)
|
|
}],
|
|
[Left, NONE, "seq_cursor_left", "move cursor up", |app: &mut App| {
|
|
if app.entered {
|
|
app.time_cursor = app.time_cursor.saturating_sub(1);
|
|
} else {
|
|
app.time_start = app.time_start.saturating_sub(1);
|
|
}
|
|
Ok(true)
|
|
}],
|
|
[Right, NONE, "seq_cursor_right", "move cursor up", |app: &mut App| {
|
|
if app.entered {
|
|
app.time_cursor = app.time_cursor + 1;
|
|
} else {
|
|
app.time_start = app.time_start + 1;
|
|
}
|
|
Ok(true)
|
|
}],
|
|
[Char('`'), NONE, "seq_mode_switch", "switch the display mode", |app: &mut App| {
|
|
app.seq_mode = !app.seq_mode;
|
|
Ok(true)
|
|
}],
|
|
// [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],
|
|
});
|
|
|
|
const KEYMAP_CHAIN: &'static [KeyBinding<App>] = keymap!(App {
|
|
[Up, NONE, "chain_cursor_up", "move cursor up", |_: &mut App| Ok(true)],
|
|
[Down, NONE, "chain_cursor_down", "move cursor down", |_: &mut App| Ok(true)],
|
|
[Left, NONE, "chain_cursor_left", "move cursor left", |app: &mut App| {
|
|
if let Some((_, track)) = app.track_mut() {
|
|
track.device = track.device.saturating_sub(1);
|
|
Ok(true)
|
|
} else {
|
|
Ok(false)
|
|
}
|
|
}],
|
|
[Right, NONE, "chain_cursor_right", "move cursor right", |app: &mut App| {
|
|
if let Some((_, track)) = app.track_mut() {
|
|
track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
|
|
Ok(true)
|
|
} else {
|
|
Ok(false)
|
|
}
|
|
}],
|
|
[Char('`'), NONE, "chain_mode_switch", "switch the display mode", |app: &mut App| {
|
|
app.chain_mode = !app.seq_mode;
|
|
Ok(true)
|
|
}],
|
|
});
|
|
|
|
fn focus_next (app: &mut App) -> Usually<bool> {
|
|
app.section.next();
|
|
Ok(true)
|
|
}
|
|
|
|
fn focus_prev (app: &mut App) -> Usually<bool> {
|
|
app.section.prev();
|
|
Ok(true)
|
|
}
|
|
|
|
fn increment (app: &mut App) -> Usually<bool> {
|
|
Ok(false)
|
|
}
|
|
|
|
fn clip_next (_: &mut App) -> Usually<bool> { Ok(true) }
|
|
//fn clip_next (state: &mut Launcher) -> Usually<bool> {
|
|
//if state.cursor.0 >= 1 && state.cursor.1 >= 1 {
|
|
//let scene_id = state.cursor.1 - 1;
|
|
//let clip_id = state.cursor.0 - 1;
|
|
//let scene = &mut state.scenes[scene_id];
|
|
//scene.clips[clip_id] = match scene.clips[clip_id] {
|
|
//None => Some(0),
|
|
//Some(i) => if i >= state.tracks[clip_id].sequencer.phrases.len().saturating_sub(1) {
|
|
//None
|
|
//} else {
|
|
//Some(i + 1)
|
|
//}
|
|
//};
|
|
//}
|
|
//Ok(true)
|
|
//}
|
|
|
|
fn decrement (app: &mut App) -> Usually<bool> {
|
|
Ok(false)
|
|
}
|
|
|
|
fn clip_prev (_: &mut App) -> Usually<bool> { Ok(true) }
|
|
//fn clip_prev (state: &mut Launcher) -> Usually<bool> {
|
|
//if state.cursor.0 >= 1 && state.cursor.1 >= 1 {
|
|
//let scene_id = state.cursor.1 - 1;
|
|
//let clip_id = state.cursor.0 - 1;
|
|
//let scene = &mut state.scenes[scene_id];
|
|
//scene.clips[clip_id] = match scene.clips[clip_id] {
|
|
//None => Some(state.tracks[clip_id].sequencer.phrases.len().saturating_sub(1)),
|
|
//Some(i) => if i == 0 {
|
|
//None
|
|
//} else {
|
|
//Some(i - 1)
|
|
//}
|
|
//};
|
|
//}
|
|
//Ok(true)
|
|
//}
|
|
|
|
fn delete (app: &mut App) -> Usually<bool> {
|
|
match app.section {
|
|
AppSection::Grid => delete_track(app),
|
|
_ => Ok(false)
|
|
}
|
|
}
|
|
|
|
fn delete_track (app: &mut App) -> Usually<bool> {
|
|
if app.tracks.len() > 0 {
|
|
let track = app.tracks.remove(app.track_cursor);
|
|
app.track_cursor = app.track_cursor.saturating_sub(1);
|
|
app.jack.as_ref().unwrap().as_client().unregister_port(track.midi_out)?;
|
|
return Ok(true)
|
|
}
|
|
Ok(false)
|
|
}
|
|
|
|
fn duplicate (_: &mut App) -> Usually<bool> { Ok(true) }
|