From 5648c96c6a008e5de00d47492cc12803efb8c98e Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 10 May 2025 16:10:52 +0300 Subject: [PATCH] groovebox: record at selected pitch --- crates/app/src/api.rs | 54 +++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/crates/app/src/api.rs b/crates/app/src/api.rs index 408f5555..39d7f317 100644 --- a/crates/app/src/api.rs +++ b/crates/app/src/api.rs @@ -287,29 +287,6 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm app.toggle_editor(Some(value)); Ok(None) } - fn editor (app: &mut App, command: MidiEditCommand) -> Perhaps { - Ok(app.editor.as_mut().map(|editor|command.execute(editor)) - .transpose()? - .flatten() - .map(|undo|Self::Editor { command: undo })) - } - fn pool (app: &mut App, command: PoolCommand) -> Perhaps { - Ok(if let Some(pool) = app.pool.as_mut() { - let undo = command.clone().delegate(pool, |command|AppCommand::Pool{command})?; - // update linked editor after pool action - app.editor.as_mut().map(|editor|match command { - // autoselect: automatically load selected clip in editor - PoolCommand::Select { .. } | - // autocolor: update color in all places simultaneously - PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => - editor.set_clip(pool.clip().as_ref()), - _ => {} - }); - undo - } else { - None - }) - } fn color (app: &mut App, theme: ItemTheme) -> Perhaps { Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme})) } @@ -369,6 +346,37 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm fn message (app: &mut App, command: MessageCommand) -> Perhaps { Ok(command.delegate(app, |command|Self::Message{command})?) } + fn editor (app: &mut App, command: MidiEditCommand) -> Perhaps { + Ok(if let Some(editor) = app.editor.as_mut() { + let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?; + // update linked sampler after editor action + app.sampler_mut().map(|sampler|match command { + // autoselect: automatically select sample in sampler + MidiEditCommand::NotePos { pos } => { sampler.set_note_pos(pos); }, + _ => {} + }); + undo + } else { + None + }) + } + fn pool (app: &mut App, command: PoolCommand) -> Perhaps { + Ok(if let Some(pool) = app.pool.as_mut() { + let undo = command.clone().delegate(pool, |command|AppCommand::Pool{command})?; + // update linked editor after pool action + app.editor.as_mut().map(|editor|match command { + // autoselect: automatically load selected clip in editor + PoolCommand::Select { .. } | + // autocolor: update color in all places simultaneously + PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => + editor.set_clip(pool.clip().as_ref()), + _ => {} + }); + undo + } else { + None + }) + } } impl<'state> Context<'state, ClockCommand> for App {