mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
bye launcher
This commit is contained in:
parent
7bc396e748
commit
2165e5d45d
10 changed files with 451 additions and 862 deletions
308
src/control.rs
308
src/control.rs
|
|
@ -1,9 +1,315 @@
|
|||
pub mod chain;
|
||||
pub mod focus;
|
||||
pub mod launcher;
|
||||
pub mod mixer;
|
||||
pub mod plugin;
|
||||
pub mod sampler;
|
||||
pub mod sequencer;
|
||||
|
||||
pub use self::focus::*;
|
||||
|
||||
use crate::{core::*, model::*, handle, App};
|
||||
|
||||
handle!(App |self, e| {
|
||||
if let Some(ref mut modal) = self.modal {
|
||||
if modal.handle(e)? {
|
||||
self.modal = None;
|
||||
return Ok(true)
|
||||
};
|
||||
}
|
||||
handle_keymap(self, e, KEYMAP)
|
||||
});
|
||||
|
||||
const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
||||
[F(1), NONE, "toggle_help", "toggle help", toggle_help],
|
||||
[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],
|
||||
[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],
|
||||
});
|
||||
|
||||
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 {
|
||||
app.section = 0;
|
||||
} else {
|
||||
app.section = app.section + 1;
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn focus_prev (app: &mut App) -> Usually<bool> {
|
||||
if app.section == 0 {
|
||||
app.section = 2;
|
||||
} else {
|
||||
app.section = app.section - 1;
|
||||
}
|
||||
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),
|
||||
_ => 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> {
|
||||
match app.section {
|
||||
0 => clip_prev(app),
|
||||
_ => 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 activate (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
//fn activate (_: &mut Launcher) -> Usually<bool> {
|
||||
//unimplemented!();
|
||||
////if let (
|
||||
////Some((_scene_id, scene)),
|
||||
////Some((track_id, track)),
|
||||
////) = (state.scene_mut(), state.track_mut()) {
|
||||
////// Launch clip
|
||||
////if let Some(phrase_id) = scene.clips.get(track_id) {
|
||||
////track.sequencer.sequence = *phrase_id;
|
||||
////}
|
||||
////if state.playing == TransportState::Stopped {
|
||||
////state.transport.start()?;
|
||||
////state.playing = TransportState::Starting;
|
||||
////}
|
||||
////} else if let Some((_scene_id, scene)) = state.scene() {
|
||||
////// Launch scene
|
||||
////for (track_id, track) in state.tracks.iter().enumerate() {
|
||||
////if let Some(phrase_id) = scene.clips.get(track_id) {
|
||||
////track.sequencer.sequence = *phrase_id;
|
||||
////}
|
||||
////}
|
||||
////if state.playing == TransportState::Stopped {
|
||||
////state.transport.start()?;
|
||||
////state.playing = TransportState::Starting;
|
||||
////}
|
||||
////} else if let Some((_track_id, _track)) = state.track() {
|
||||
////// Rename track?
|
||||
////}
|
||||
|
||||
////let track = state.active_track().unwrap();
|
||||
////let scene = state.active_scene();
|
||||
////if state.cursor.1 >= 2 {
|
||||
////if let Some(Some(index)) = scene.clips.get(state.cursor.1 - 2) {
|
||||
////track.enqueue(index)
|
||||
////} else {
|
||||
////}
|
||||
////}
|
||||
////if state.cursor.0 >= 1 {
|
||||
////let sequencer = state.tracks.get_mut(state.cursor.0 - 1);
|
||||
////if state.cursor.1 >= 2 {
|
||||
////let scene = state.scenes.get_mut(state.cursor.1 - 2);
|
||||
////if let Some(index) = scene.get(state.cursor.0 - 1) {
|
||||
////let phrase = sequencer.phrases.get(index);
|
||||
////} else {
|
||||
////let index = sequencer.phrases.len();
|
||||
////let phrase = Phrase::new(&format!("Phrase#{index}"));
|
||||
////sequencer.phrases.push(phrase);
|
||||
////scene[state.cursor.0 - 1] = Some(index);
|
||||
////}
|
||||
////}
|
||||
////}
|
||||
//Ok(true)
|
||||
//}
|
||||
|
||||
fn delete (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => delete_track(app),
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn enter (app: &mut App) -> Usually<bool> {
|
||||
if app.entered {
|
||||
activate(app)
|
||||
} else {
|
||||
app.entered = true;
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
|
||||
fn escape (app: &mut App) -> Usually<bool> {
|
||||
if app.entered {
|
||||
app.entered = false;
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
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(), &app.timebase, 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);
|
||||
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) }
|
||||
|
||||
fn rename (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
|
||||
//fn toggle_record (s: &mut Launcher) -> Usually<bool> {
|
||||
//s.sequencer_mut().map(|s|s.recording = !s.recording);
|
||||
//Ok(true)
|
||||
//}
|
||||
|
||||
//fn toggle_overdub (s: &mut Launcher) -> Usually<bool> {
|
||||
//s.sequencer_mut().map(|s|s.overdub = !s.overdub);
|
||||
//Ok(true)
|
||||
//}
|
||||
|
||||
//fn toggle_monitor (s: &mut Launcher) -> Usually<bool> {
|
||||
//s.sequencer_mut().map(|s|s.monitoring = !s.monitoring);
|
||||
//Ok(true)
|
||||
//}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue