mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
fix timer of horizontal sequencer
This commit is contained in:
parent
2601592d17
commit
1259176576
6 changed files with 293 additions and 254 deletions
235
src/control.rs
235
src/control.rs
|
|
@ -5,7 +5,7 @@ pub mod sampler;
|
|||
|
||||
pub use self::focus::*;
|
||||
|
||||
use crate::{core::*, model::*, handle, App};
|
||||
use crate::{core::*, handle, App};
|
||||
|
||||
handle!(App |self, e| {
|
||||
if let Some(ref mut modal) = self.modal {
|
||||
|
|
@ -18,82 +18,117 @@ handle!(App |self, e| {
|
|||
});
|
||||
|
||||
const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
||||
[F(1), NONE, "toggle_help", "toggle help", toggle_help],
|
||||
[Char(' '), NONE, "toggle_play", "play or pause", |app: &mut App| {
|
||||
app.toggle_play()?;
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('a'), CONTROL, "add_scene", "add a new scene", |app: &mut App| {
|
||||
app.add_scene(None)?;
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('t'), CONTROL, "add_track", "add a new track", |app: &mut App| {
|
||||
app.add_track(None)?;
|
||||
Ok(true)
|
||||
}],
|
||||
[Char('`'), NONE, "switch_mode", "switch the display mode", |app: &mut App| {
|
||||
match app.section {
|
||||
0 => {app.grid_mode = !app.grid_mode; Ok(true)},
|
||||
1 => {app.chain_mode = !app.chain_mode; Ok(true)},
|
||||
2 => {app.seq_mode = !app.seq_mode; Ok(true)},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}],
|
||||
[F(1), NONE, "toggle_help", "toggle help", |_: &mut App| {Ok(true)}],
|
||||
[Char('r'), NONE, "toggle_record", "toggle recording", |_: &mut App| {Ok(true)}],
|
||||
[Char('d'), NONE, "toggle_overdub", "toggle overdub", |_: &mut App| {Ok(true)}],
|
||||
[Char('m'), NONE, "toggle_monitor", "toggle input monitoring", |_: &mut App| {Ok(true)}],
|
||||
[Up, NONE, "cursor_up", "move cursor up", |app: &mut App| {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_prev(app)
|
||||
}
|
||||
}],
|
||||
[Down, NONE, "cursor_down", "move cursor down", |app: &mut App| {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
true => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_next(app)
|
||||
}
|
||||
}],
|
||||
[Left, NONE, "cursor_left", "move cursor left", |app: &mut App| {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
1 => {
|
||||
if let Some((_, track)) = app.track_mut() {
|
||||
track.device = track.device.saturating_sub(1);
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
app.time_cursor = app.time_cursor.saturating_sub(1);
|
||||
Ok(true)
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}],
|
||||
[Right, NONE, "cursor_right", "move cursor right", |app: &mut App| {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
},
|
||||
1 => {
|
||||
if let Some((_, track)) = app.track_mut() {
|
||||
track.device = (track.device + 1).min(track.devices.len().saturating_sub(1));
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
app.time_cursor = app.time_cursor + 1;
|
||||
Ok(true)
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}],
|
||||
[Tab, NONE, "focus_next", "focus next area", focus_next],
|
||||
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],
|
||||
[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, "increment", "increment value at cursor", increment],
|
||||
[Char(','), NONE, "decrement", "decrement value at cursor", decrement],
|
||||
[Char('.'), NONE, "increment", "increment value", increment],
|
||||
[Char(','), NONE, "decrement", "decrement value", decrement],
|
||||
[Delete, CONTROL, "delete", "delete track", delete],
|
||||
[Char('d'), CONTROL, "duplicate", "duplicate scene or track", duplicate],
|
||||
[Enter, NONE, "activate", "activate item at cursor", enter],
|
||||
[Esc, NONE, "escape", "unfocus", escape],
|
||||
[Char(' '), NONE, "toggle_play", "play or 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('r'), CONTROL, "rename", "rename current element", rename],
|
||||
[Char('t'), CONTROL, "add_track", "add a new track", add_track],
|
||||
[Char('a'), CONTROL, "add_scene", "add a new scene", add_scene],
|
||||
[Char('`'), NONE, "switch_mode", "switch the display mode", switch_mode],
|
||||
// [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('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],
|
||||
});
|
||||
//-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 toggle_play (app: &mut App) -> Usually<bool> {
|
||||
app.playing = match app.playing.expect("after jack init") {
|
||||
TransportState::Stopped => {
|
||||
app.transport.as_ref().unwrap().start()?;
|
||||
Some(TransportState::Starting)
|
||||
},
|
||||
_ => {
|
||||
app.transport.as_ref().unwrap().stop()?;
|
||||
app.transport.as_ref().unwrap().locate(0)?;
|
||||
Some(TransportState::Stopped)
|
||||
},
|
||||
};
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn toggle_record (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn toggle_overdub (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn toggle_monitor (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn toggle_help (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
fn switch_mode (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => {app.grid_mode = !app.grid_mode; Ok(true)},
|
||||
1 => {app.chain_mode = !app.chain_mode; Ok(true)},
|
||||
2 => {app.seq_mode = !app.seq_mode; Ok(true)},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_next (app: &mut App) -> Usually<bool> {
|
||||
if app.section >= 2 {
|
||||
|
|
@ -113,54 +148,6 @@ fn focus_prev (app: &mut App) -> Usually<bool> {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
fn cursor_up (app: &mut App) -> Usually<bool> {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_prev(app)
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor_down (app: &mut App) -> Usually<bool> {
|
||||
if app.entered {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
true => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
} else {
|
||||
focus_next(app)
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor_left (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.track_cursor.saturating_sub(1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scene_cursor.saturating_sub(1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn cursor_right (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => match app.grid_mode {
|
||||
false => {app.track_cursor = app.tracks.len().min(app.track_cursor + 1); Ok(true)},
|
||||
true => {app.scene_cursor = app.scenes.len().min(app.scene_cursor + 1); Ok(true)},
|
||||
},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn increment (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => clip_next(app),
|
||||
|
|
@ -291,20 +278,6 @@ fn escape (app: &mut App) -> Usually<bool> {
|
|||
}
|
||||
}
|
||||
|
||||
fn add_scene (app: &mut App) -> Usually<bool> {
|
||||
let name = format!("Scene {}", app.scenes.len() + 1);
|
||||
app.scenes.push(Scene::new(&name, vec![]));
|
||||
app.scene_cursor = app.scenes.len();
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn add_track (app: &mut App) -> Usually<bool> {
|
||||
let name = format!("Track {}", app.tracks.len() + 1);
|
||||
app.tracks.push(Track::new(&name, app.jack.as_ref().unwrap().as_client(), None, None)?);
|
||||
app.track_cursor = app.tracks.len();
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn delete_track (app: &mut App) -> Usually<bool> {
|
||||
if app.tracks.len() > 0 {
|
||||
let track = app.tracks.remove(app.track_cursor);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue