From 3030f28ef73205809271afed17cd1862fd13ee66 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 16 Jan 2025 19:42:19 +0100 Subject: [PATCH] fix changing colors of scenes and tracks --- tek/src/keys_clip.edn | 2 +- tek/src/keys_scene.edn | 2 +- tek/src/keys_track.edn | 2 +- tek/src/lib.rs | 57 +++++++++++++++++++++++++++++++----------- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/tek/src/keys_clip.edn b/tek/src/keys_clip.edn index 21b9b319..0fe68e6d 100644 --- a/tek/src/keys_clip.edn +++ b/tek/src/keys_clip.edn @@ -8,7 +8,7 @@ (@d select :track-next :scene) (@q enqueue :clip) -(@c clip color) +(@c clip color :track :scene) (@g clip get) (@p clip put) (@delete clip del) diff --git a/tek/src/keys_scene.edn b/tek/src/keys_scene.edn index 60a45d57..512f60d1 100644 --- a/tek/src/keys_scene.edn +++ b/tek/src/keys_scene.edn @@ -6,7 +6,7 @@ (@d select :track-next :scene) (@q scene launch) -(@c scene color) +(@c scene color :scene) (@comma scene prev) (@period scene next) (@lt scene swap-prev) diff --git a/tek/src/keys_track.edn b/tek/src/keys_track.edn index 39fe6a32..d49798c5 100644 --- a/tek/src/keys_track.edn +++ b/tek/src/keys_track.edn @@ -6,7 +6,7 @@ (@s select :track :scene-next) (@q track launch) -(@c track color) +(@c track color :track) (@comma track prev) (@period track next) (@lt track swap-prev) diff --git a/tek/src/lib.rs b/tek/src/lib.rs index 2f0afe61..b0de7de1 100644 --- a/tek/src/lib.rs +++ b/tek/src/lib.rs @@ -661,7 +661,7 @@ edn_command!(TekCommand: |app: Tek| { (0, s) => Self::Select(Selection::Scene(s)), (t, s) => Self::Select(Selection::Clip(t, s)), }) - ("clip" [a, b, ..c] Self::Clip(ClipCommand::from_edn(app, &b.to_ref(), c) + ("clip" [a, ..b] Self::Clip(ClipCommand::from_edn(app, &a.to_ref(), b) .expect("invalid command"))) ("clock" [a, ..b] Self::Clock(ClockCommand::from_edn(app.clock(), &a.to_ref(), b) .expect("invalid command"))) @@ -735,9 +735,38 @@ command!(|self: TekCommand, app: Tek|match self { Self::Enqueue(clip) => app.player.as_mut() .map(|player|{player.enqueue_next(clip.as_ref());None}).flatten(), Self::Color(palette) => { - let old = app.color; - app.color = palette; - Some(Self::Color(old)) + use Selection::*; + Some(Self::Color(match app.selected { + Mix => { + let old = app.color; + app.color = palette; + old + }, + Track(t) => { + let t = t.saturating_sub(1); + let old = app.tracks[t].color; + app.tracks[t].color = palette; + old + } + Scene(s) => { + let s = s.saturating_sub(1); + let old = app.scenes[s].color; + app.scenes[s].color = palette; + old + } + Clip(t, s) => { + let t = t.saturating_sub(1); + let s = s.saturating_sub(1); + if let Some(ref clip) = app.scenes[s].clips[t] { + let mut clip = clip.write().unwrap(); + let old = clip.color; + clip.color = palette; + old + } else { + return Ok(None) + } + } + })) }, Self::StopAll => { for track in 0..app.tracks.len(){app.tracks[track].player.enqueue_next(None);} @@ -845,9 +874,9 @@ edn_command!(TrackCommand: |app: Tek| { ("add" [] Self::Add) ("size" [a: usize] Self::SetSize(a.unwrap())) ("zoom" [a: usize] Self::SetZoom(a.unwrap())) - ("color" [a: usize] Self::SetColor(a.unwrap(), ItemPalette::random())) - ("del" [a: usize] Self::Del(a.unwrap())) - ("stop" [a: usize] Self::Stop(a.unwrap())) + ("color" [a: usize] Self::SetColor(a.unwrap().saturating_sub(1), ItemPalette::random())) + ("del" [a: usize] Self::Del(a.unwrap().saturating_sub(1))) + ("stop" [a: usize] Self::Stop(a.unwrap().saturating_sub(1))) ("swap" [a: usize, b: usize] Self::Swap(a.unwrap(), b.unwrap())) }); command!(|self: TrackCommand, app: Tek|match self { @@ -1017,8 +1046,8 @@ edn_command!(SceneCommand: |app: Tek| { ("add" [] Self::Add) ("del" [a: usize] Self::Del(0)) ("zoom" [a: usize] Self::SetZoom(a.unwrap())) - ("color" [a: usize] Self::SetColor(a.unwrap(), ItemPalette::random())) - ("enqueue" [a: usize] Self::Enqueue(a.unwrap())) + ("color" [a: usize] Self::SetColor(a.unwrap().saturating_sub(1), ItemPalette::random())) + ("enqueue" [a: usize] Self::Enqueue(a.unwrap().saturating_sub(1))) ("swap" [a: usize, b: usize] Self::Swap(a.unwrap(), b.unwrap())) }); command!(|self: SceneCommand, app: Tek|match self { @@ -1121,17 +1150,17 @@ trait HasScenes: HasSelection + HasEditor + Send + Sync { } edn_command!(ClipCommand: |app: Tek| { ("get" [a: usize ,b: usize] - Self::Get(a.unwrap(), b.unwrap())) + Self::Get(a.unwrap().saturating_sub(1), b.unwrap().saturating_sub(1))) ("put" [a: usize, b: usize, c: Option>>] - Self::Put(a.unwrap(), b.unwrap(), c.unwrap())) + Self::Put(a.unwrap().saturating_sub(1), b.unwrap().saturating_sub(1), c.unwrap())) ("enqueue" [a: usize, b: usize] - Self::Enqueue(a.unwrap(), b.unwrap())) + Self::Enqueue(a.unwrap().saturating_sub(1), b.unwrap().saturating_sub(1))) ("edit" [a: Option>>] Self::Edit(a.unwrap())) ("loop" [a: usize, b: usize, c: bool] - Self::SetLoop(a.unwrap(), b.unwrap(), c.unwrap())) + Self::SetLoop(a.unwrap().saturating_sub(1), b.unwrap().saturating_sub(1), c.unwrap())) ("color" [a: usize, b: usize] - Self::SetColor(a.unwrap(), b.unwrap(), ItemPalette::random())) + Self::SetColor(a.unwrap().saturating_sub(1), b.unwrap().saturating_sub(1), ItemPalette::random())) }); command!(|self: ClipCommand, app: Tek|match self { Self::Get(track, scene) => { todo!() },