switch around ownership of pool and editort

This commit is contained in:
🪞👃🪞 2025-05-17 13:23:31 +03:00
parent 3f1a2fee80
commit c7e7c9f68c
8 changed files with 157 additions and 150 deletions

View file

@ -24,9 +24,10 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
Selection::TrackClip { track, scene } => {
let clip = &mut app.scenes_mut()[scene].clips[track];
if clip.is_none() {
//app.clip_auto_create();
*clip = Some(Default::default());
}
app.editor = clip.as_ref().map(|c|c.into());
app.project.editor = clip.as_ref().map(|c|c.into());
None
}
_ => None
@ -62,18 +63,19 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
//}
fn select (app: &mut App, selection: Selection) -> Perhaps<Self> {
*app.project.selection_mut() = selection;
if let Some(ref mut editor) = app.editor {
editor.set_clip(match app.project.selection() {
Selection::TrackClip { track, scene } if let Some(Some(Some(clip))) = app
.project
.scenes.get(*scene)
.map(|s|s.clips.get(*track))
=>
Some(clip),
_ =>
None
});
}
//todo!
//if let Some(ref mut editor) = app.editor_mut() {
//editor.set_clip(match selection {
//Selection::TrackClip { track, scene } if let Some(Some(Some(clip))) = app
//.project
//.scenes.get(scene)
//.map(|s|s.clips.get(track))
//=>
//Some(clip),
//_ =>
//None
//});
//}
Ok(None)
//("select" [t: usize, s: usize] Some(match (t.expect("no track"), s.expect("no scene")) {
//(0, 0) => Self::Select(Selection::Mix),
@ -102,7 +104,7 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
Ok(command.delegate(app, |command|Self::Message{command})?)
}
fn editor (app: &mut App, command: MidiEditCommand) -> Perhaps<Self> {
Ok(if let Some(editor) = app.editor.as_mut() {
Ok(if let Some(editor) = app.editor_mut() {
let undo = command.clone().delegate(editor, |command|AppCommand::Editor{command})?;
// update linked sampler after editor action
app.project.sampler_mut().map(|sampler|match command {
@ -117,18 +119,20 @@ handle!(TuiIn: |self: App, input|Ok(if let Some(command) = self.config.keys.comm
}
fn pool (app: &mut App, command: PoolCommand) -> Perhaps<Self> {
let undo = command.clone().delegate(
&mut app.project.pool,
&mut app.pool,
|command|AppCommand::Pool{command}
)?;
// update linked editor after pool action
app.editor.as_mut().map(|editor|match command {
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(app.project.pool.clip().as_ref()),
_ => {}
});
PoolCommand::Clip { command: PoolClipCommand::SetColor { .. } } => {
let clip = app.pool.clip().clone();
app.editor_mut().map(|editor|editor.set_clip(clip.as_ref()))
},
_ => None
};
Ok(undo)
}
}
@ -147,7 +151,7 @@ impl<'state> Context<'state, MidiEditCommand> for App {
impl<'state> Context<'state, PoolCommand> for App {
fn get <'source> (&'state self, iter: &mut TokenIter<'source>) -> Option<PoolCommand> {
Context::get(&self.project.pool, iter)
Context::get(&self.pool, iter)
}
}