extract api with expose/impose macros

This commit is contained in:
🪞👃🪞 2025-04-14 13:41:35 +03:00
parent d893ae0309
commit 664cd8942f
9 changed files with 241 additions and 141 deletions

View file

@ -1,7 +1,9 @@
use crate::*;
mod model_track; pub use self::model_track::*;
mod model_scene; pub use self::model_scene::*;
mod model_select; pub use self::model_select::*;
#[derive(Default, Debug)] pub struct Tek {
/// Must not be dropped for the duration of the process
pub jack: Jack,
@ -62,73 +64,7 @@ mod model_select; pub use self::model_select::*;
// Cache of formatted strings
pub view_cache: Arc<RwLock<ViewCache>>,
}
has_size!(<TuiOut>|self: Tek|&self.size);
has_clock!(|self: Tek|self.clock);
has_clips!(|self: Tek|self.pool.as_ref().expect("no clip pool").clips);
//has_sampler!(|self: Tek|{
//sampler = self.sampler;
//index = self.editor.as_ref().map(|e|e.note_pos()).unwrap_or(0); });
has_editor!(|self: Tek|{
editor = self.editor;
editor_w = {
let size = self.size.w();
let editor = self.editor.as_ref().expect("missing editor");
let time_len = editor.time_len().get();
let time_zoom = editor.time_zoom().get().max(1);
(5 + (time_len / time_zoom)).min(size.saturating_sub(20)).max(16)
};
editor_h = 15;
is_editing = self.editing.load(Relaxed); });
provide!(Color: |self: Tek| {});
provide!(Arc<RwLock<MidiClip>>: |self: Tek| {});
provide!(Option<Arc<RwLock<MidiClip>>>: |self: Tek| {
":clip" => match self.selected {
Selection::Clip(t, s) => self.scenes[s].clips[t].clone(),
_ => None
}
});
provide_bool!(bool: |self: Tek| {});
provide_num!(isize: |self: Tek| {});
provide_num!(usize: |self: Tek| {
":scene-last" => self.scenes.len(),
":track-last" => self.tracks.len() });
provide!(Option<usize>: |self: Tek| {
":scene" => self.selected.scene(),
":track" => self.selected.track() });
provide!(Selection: |self: Tek| {
":scene-next" => match self.selected {
Selection::Mix => Selection::Scene(0),
Selection::Track(t) => Selection::Clip(t, 0),
Selection::Scene(s) if s + 1 < self.scenes.len() => Selection::Scene(s + 1),
Selection::Scene(s) => Selection::Mix,
Selection::Clip(t, s) if s + 1 < self.scenes.len() => Selection::Clip(t, s + 1),
Selection::Clip(t, s) => Selection::Track(t),
},
":scene-prev" => match self.selected {
Selection::Mix => Selection::Mix,
Selection::Track(t) => Selection::Track(t),
Selection::Scene(0) => Selection::Mix,
Selection::Scene(s) => Selection::Scene(s - 1),
Selection::Clip(t, 0) => Selection::Track(t),
Selection::Clip(t, s) => Selection::Clip(t, s - 1),
},
":track-next" => match self.selected {
Selection::Mix => Selection::Track(0),
Selection::Track(t) if t + 1 < self.tracks.len() => Selection::Track(t + 1),
Selection::Track(t) => Selection::Mix,
Selection::Scene(s) => Selection::Clip(0, s),
Selection::Clip(t, s) if t + 1 < self.tracks.len() => Selection::Clip(t + 1, s),
Selection::Clip(t, s) => Selection::Scene(s),
},
":track-prev" => match self.selected {
Selection::Mix => Selection::Mix,
Selection::Scene(s) => Selection::Scene(s),
Selection::Track(0) => Selection::Mix,
Selection::Track(t) => Selection::Track(t - 1),
Selection::Clip(0, s) => Selection::Scene(s),
Selection::Clip(t, s) => Selection::Clip(t - 1, s),
},
});
impl Tek {
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
self.scene()?.clips.get(self.selected().track()?)?.clone()
@ -164,9 +100,27 @@ impl Tek {
Ok(())
}
}
#[cfg(test)] #[test] fn test_model () {
let mut tek = Tek::default();
let _ = tek.clip();
let _ = tek.toggle_loop();
let _ = tek.activate();
}
has_size!(<TuiOut>|self: Tek|&self.size);
has_clock!(|self: Tek|self.clock);
has_clips!(|self: Tek|self.pool.as_ref().expect("no clip pool").clips);
has_editor!(|self: Tek|{
editor = self.editor;
editor_w = {
let size = self.size.w();
let editor = self.editor.as_ref().expect("missing editor");
let time_len = editor.time_len().get();
let time_zoom = editor.time_zoom().get().max(1);
(5 + (time_len / time_zoom)).min(size.saturating_sub(20)).max(16)
};
editor_h = 15;
is_editing = self.editing.load(Relaxed);
});
//has_sampler!(|self: Tek|{
//sampler = self.sampler;
//index = self.editor.as_ref().map(|e|e.note_pos()).unwrap_or(0);
//});