From efa35834dec8a95535b6fbc110523f3756e8afab Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 11 Jan 2025 17:48:44 +0100 Subject: [PATCH] add clips with enter --- cli/tek.rs | 2 +- midi/src/midi_pool.rs | 5 +++++ tek/src/arranger.rs | 52 ++++++++++++++++++++++--------------------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/cli/tek.rs b/cli/tek.rs index 4f6baefc..e2995eab 100644 --- a/cli/tek.rs +++ b/cli/tek.rs @@ -185,7 +185,7 @@ pub fn main () -> Usually<()> { midi_buf: vec![vec![];65536], note_buf: vec![], compact: false, - editing: true, + editing: true.into(), color, perf, size, diff --git a/midi/src/midi_pool.rs b/midi/src/midi_pool.rs index 664133ac..627ef941 100644 --- a/midi/src/midi_pool.rs +++ b/midi/src/midi_pool.rs @@ -5,6 +5,11 @@ pub type ClipPool = Vec>>; pub trait HasClips { fn clips <'a> (&'a self) -> std::sync::RwLockReadGuard<'a, ClipPool>; fn clips_mut <'a> (&'a self) -> std::sync::RwLockWriteGuard<'a, ClipPool>; + fn add_clip (&self) -> (usize, Arc>) { + let clip = Arc::new(RwLock::new(MidiClip::new("Clip", true, 384, None, None))); + self.clips_mut().push(clip.clone()); + (self.clips().len() - 1, clip) + } } #[macro_export] macro_rules! has_clips { diff --git a/tek/src/arranger.rs b/tek/src/arranger.rs index 3fe9b93d..5c3406bc 100644 --- a/tek/src/arranger.rs +++ b/tek/src/arranger.rs @@ -21,7 +21,7 @@ pub struct Arranger { pub note_buf: Vec, pub midi_buf: Vec>>, pub editor: MidiEditor, - pub editing: bool, + pub editing: AtomicBool, pub perf: PerfModel, pub compact: bool, } @@ -347,45 +347,35 @@ impl Arranger { let selected_track = self.selected.track(); let selected_scene = self.selected.scene(); (move||Fill::y(Align::c(Map::new(tracks, move|(_, track, x1, x2), t| { - let w = (x2 - x1) as u16; + let w = (x2 - x1) as u16; let color: ItemPalette = track.color().dark.into(); let last_color = Arc::new(RwLock::new(ItemPalette::from(Color::Rgb(0, 0, 0)))); let cells = Map::new(scenes, move|(_, scene, y1, y2), s| { - let h = (y2 - y1) as u16; + let h = (y2 - y1) as u16; let color = scene.color(); - let name = if let Some(c) = &scene.clips[t] { - c.read().unwrap().name.to_string() + let (name, fg, bg) = if let Some(c) = &scene.clips[t] { + let c = c.read().unwrap(); + (c.name.to_string(), c.color.lightest.rgb, c.color.base.rgb) } else { - "⏹ ".to_string() + ("⏹ ".to_string(), TuiTheme::g(64), TuiTheme::g(32)) }; - let last = last_color.read().unwrap().clone(); - //let cell = phat_sel_3( - //selected_track == Some(i) && selected_scene == Some(j), - //Tui::fg(TuiTheme::g(64), Push::x(1, name)), - //Tui::fg(TuiTheme::g(64), Push::x(1, name)), - //if selected_track == Some(i) && selected_scene.map(|s|s+1) == Some(j) { - //None - //} else { - //Some(TuiTheme::g(32).into()) - //}, - //TuiTheme::g(32).into(), - //TuiTheme::g(32).into(), - //); + let last = last_color.read().unwrap().clone(); let active = editing && selected_scene == Some(s) && selected_track == Some(t); let editor = Thunk::new(||&self.editor); let cell = Thunk::new(move||phat_sel_3( selected_track == Some(t) && selected_scene == Some(s), - Tui::fg(TuiTheme::g(64), Push::x(1, Tui::bold(true, name.to_string()))), - Tui::fg(TuiTheme::g(64), Push::x(1, Tui::bold(true, name.to_string()))), + Tui::fg(fg, Push::x(1, Tui::bold(true, name.to_string()))), + Tui::fg(fg, Push::x(1, Tui::bold(true, name.to_string()))), if selected_track == Some(t) && selected_scene.map(|s|s+1) == Some(s) { None } else { - Some(TuiTheme::g(32).into()) + Some(bg.into()) }, - TuiTheme::g(32).into(), - TuiTheme::g(32).into(), + bg.into(), + bg.into(), )); let cell = Either(active, editor, cell); + *last_color.write().unwrap() = bg.into(); map_south( y1 as u16, h + 1, @@ -738,7 +728,7 @@ fn clip_keymap (state: &Arranger, input: &Event, t: usize, s: usize) -> Option if state.scenes[s].clips[t].is_none() { // FIXME: get this clip from the pool (autoregister via intmut) - let clip = Arc::new(RwLock::new(MidiClip::default())); + let (_, clip) = state.add_clip(); Cmd::Clip(Clip::Put(t, s, Some(clip))) } else { return None @@ -987,3 +977,15 @@ command!(|self: ArrangerClipCommand, state: Arranger|match self { //Fill::xy(ArrangerVClips::new(self, 1)), //Fill::x(ArrangerVOuts::from(self))))) + //let cell = phat_sel_3( + //selected_track == Some(i) && selected_scene == Some(j), + //Tui::fg(TuiTheme::g(64), Push::x(1, name)), + //Tui::fg(TuiTheme::g(64), Push::x(1, name)), + //if selected_track == Some(i) && selected_scene.map(|s|s+1) == Some(j) { + //None + //} else { + //Some(TuiTheme::g(32).into()) + //}, + //TuiTheme::g(32).into(), + //TuiTheme::g(32).into(), + //);