gluing
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-08-10 03:53:46 +03:00
parent f2d6e7724b
commit b991a49ad7
3 changed files with 106 additions and 87 deletions

View file

@ -1,4 +1,6 @@
use crate::*;
#[derive(Debug)]
pub enum AppCommand {}
handle!(TuiIn:|self: App, input|{
panic!("{input:?}");
//Ok(if let Some(binding) = self.profile.as_ref()
@ -12,7 +14,7 @@ handle!(TuiIn:|self: App, input|{
//} else {
//None
//})
})
});
dsl_sym!(|app: App| -> isize {
":_isize_stub" => -1
});
@ -70,91 +72,108 @@ dsl_sym!(|app: App| -> Selection {
});
dsl_sym!(|app: App| -> Option<u7> {
":editor/pitch" => Some((app.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into())
})
});
dsl_sym!(|app: App| -> Option<usize> {
":selected/scene" => app.selection().scene(),
":selected/track" => app.selection().track(),
});
dsl_sym!(|app: App| -> Option<Arc<RwLock<MidiClip>>> {
":selected/clip" => if let Selection::TrackClip { track, scene } = app.selection() {
app.scenes()[*scene].clips[*track].clone(),
app.scenes()[*scene].clips[*track].clone()
} else {
None
}
});
dsl_bind!(AppCommand: App {
enqueue = |app, clip: Option<Arc<RwLock<MidiClip>>>| { todo!() };
history = |app, delta: isize| { todo!() };
zoom = |app, zoom: usize| { todo!() };
stop_all = |app| { app.tracks_stop_all(); Ok(None) };
//dialog = |app, command: DialogCommand|
//Ok(command.delegate(&mut app.dialog, |c|Self::Dialog{command: c})?);
project = |app, command: ArrangementCommand|
Ok(command.delegate(&mut app.project, |c|Self::Project{command: c})?);
clock = |app, command: ClockCommand|
Ok(command.execute(app.clock_mut())?.map(|c|Self::Clock{command: c}));
sampler = |app, command: SamplerCommand|
Ok(app.project.sampler_mut().map(|s|command.delegate(s, |command|Self::Sampler{command}))
.transpose()?.flatten());
pool = |app, command: PoolCommand| {
let undo = command.clone().delegate(&mut app.pool, |command|AppCommand::Pool{command})?;
// update linked editor after pool action
match command {
// autoselect: automatically load selected clip in editor
PoolCommand::Select { .. } |
// autocolor: update color in all places simultaneously
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)
};
select = |app, selection: Selection| {
*app.project.selection_mut() = selection;
//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),
//(t, 0) => Self::Select(Selection::Track(t)),
//(0, s) => Self::Select(Selection::Scene(s)),
//(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
// autoedit: load focused clip in editor.
};
//fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
//Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
//}
//fn launch (app: &mut App) -> Perhaps<Self> {
//app.project.launch();
//Ok(None)
//}
toggle_editor = |app, value: bool|{ app.toggle_editor(Some(value)); Ok(None) };
editor = |app, command: MidiEditCommand| 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 {
// autoselect: automatically select sample in sampler
MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
_ => {}
});
undo
} else {
None
});
dsl_exp!(|app: App| -> AppCommand {
["stop-all"] => app.project.stop_all(),
["enqueue", clip?: Option<Arc<RwLock<MidiClip>>>] => todo!(),
["history", delta: isize] => todo!(),
["zoom", zoom: usize] => todo!(),
["select", selection: Selection] => todo!(),
["dialog" / command: DialogCommand] => todo!(),
["project" / command: ArrangementCommand] => todo!(),
["clock" / command: ClockCommand] => todo!(),
["sampler" / command: SamplerCommand] => todo!(),
["pool" / command: PoolCommand] => todo!(),
});
dsl_exp!(|app: App| -> DialogCommand {});
dsl_exp!(|app: App| -> ArrangementCommand {});
dsl_exp!(|app: App| -> ClockCommand {});
dsl_exp!(|app: App| -> SamplerCommand {});
dsl_exp!(|app: App| -> PoolCommand {});
//dsl_bind!(AppCommand: App {
//enqueue = |app, clip: Option<Arc<RwLock<MidiClip>>>| { todo!() };
//history = |app, delta: isize| { todo!() };
//zoom = |app, zoom: usize| { todo!() };
//stop_all = |app| { app.tracks_stop_all(); Ok(None) };
////dialog = |app, command: DialogCommand|
////Ok(command.delegate(&mut app.dialog, |c|Self::Dialog{command: c})?);
//project = |app, command: ArrangementCommand|
//Ok(command.delegate(&mut app.project, |c|Self::Project{command: c})?);
//clock = |app, command: ClockCommand|
//Ok(command.execute(app.clock_mut())?.map(|c|Self::Clock{command: c}));
//sampler = |app, command: SamplerCommand|
//Ok(app.project.sampler_mut().map(|s|command.delegate(s, |command|Self::Sampler{command}))
//.transpose()?.flatten());
//pool = |app, command: PoolCommand| {
//let undo = command.clone().delegate(&mut app.pool, |command|AppCommand::Pool{command})?;
//// update linked editor after pool action
//match command {
//// autoselect: automatically load selected clip in editor
//PoolCommand::Select { .. } |
//// autocolor: update color in all places simultaneously
//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)
//};
//select = |app, selection: Selection| {
//*app.project.selection_mut() = selection;
////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),
////(t, 0) => Self::Select(Selection::Track(t)),
////(0, s) => Self::Select(Selection::Scene(s)),
////(t, s) => Self::Select(Selection::TrackClip { track: t, scene: s }) })))
//// autoedit: load focused clip in editor.
//};
////fn color (app: &mut App, theme: ItemTheme) -> Perhaps<Self> {
////Ok(app.set_color(Some(theme)).map(|theme|Self::Color{theme}))
////}
////fn launch (app: &mut App) -> Perhaps<Self> {
////app.project.launch();
////Ok(None)
////}
//toggle_editor = |app, value: bool|{ app.toggle_editor(Some(value)); Ok(None) };
//editor = |app, command: MidiEditCommand| 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 {
//// autoselect: automatically select sample in sampler
//MidiEditCommand::SetNotePos { pos } => { sampler.set_note_pos(pos); },
//_ => {}
//});
//undo
//} else {
//None
//});
//});
//take!(ClockCommand |state: App, iter|Take::take(state.clock(), iter));
//take!(MidiEditCommand |state: App, iter|Ok(state.editor().map(|x|Take::take(x, iter)).transpose()?.flatten()));
//take!(PoolCommand |state: App, iter|Take::take(&state.pool, iter));