@@ -3,6 +3,7 @@ use std::{
33 time:: { Duration , SystemTime } ,
44} ;
55
6+ use egui:: Color32 ;
67use log:: { debug, error, info} ;
78use tween:: SineInOut ;
89
@@ -13,7 +14,7 @@ use crate::{
1314 settings:: { Cli , CHANNELS_PER_UNIVERSE } ,
1415 tether_interface:: {
1516 RemoteControlMessage , RemoteMacroMessage , RemoteMacroValue , RemoteSceneMessage ,
16- TetherMidiMessage , TetherNotePayload ,
17+ TetherControlChangePayload , TetherMidiMessage , TetherNotePayload ,
1718 } ,
1819 ui:: { render_gui, ViewMode } ,
1920} ;
@@ -183,16 +184,12 @@ impl Model {
183184 self . selected_macro_group_index = index as usize ;
184185 }
185186 // TetherMidiMessage::NoteOff(_) => todo!(),
186- TetherMidiMessage :: ControlChange ( _cc) => {
187- // let TetherControlChangePayload {
188- // channel: _,
189- // controller,
190- // value,
191- // } = cc;
192-
193- todo ! ( ) ;
194-
195- // TODO: reimplement remote via Tether-MIDI
187+ TetherMidiMessage :: ControlChange ( cc) => {
188+ let TetherControlChangePayload {
189+ channel : _,
190+ controller,
191+ value,
192+ } = cc;
196193
197194 // let active_macros = self
198195 // .project
@@ -208,31 +205,44 @@ impl Model {
208205 // })
209206 // .filter_map(|x| x);
210207
211- // let controller_start = 48;
212-
213- // for (i, (fixture_config, m)) in active_macros.enumerate() {
214- // if self.selected_macro_group_index as usize == i {
215- // debug!("Adjust for macros {:?}", m);
216- // let target_macro_index = controller - controller_start;
217- // debug!("Controller {} => {}", controller, target_macro_index);
218- // match m.get(target_macro_index as usize) {
219- // Some(macro_control) => {
220- // let value = value * 2;
221- // debug!("Adjust {:?} to {}", macro_control, value);
222- // // macro_control.current_value = value * 2;
223- // for c in ¯o_control.channels {
224- // let channel_index =
225- // (*c - 1 + fixture_config.offset_channels) as usize;
226- // debug!("Set channel {} to value {}", channel_index, value);
227- // self.channels_state[channel_index] = value;
228- // }
229- // }
230- // None => {
231- // error!("Failed to match macro control");
232- // }
233- // }
234- // }
235- // }
208+ let controller_start = 48 ;
209+
210+ for ( i, fixture) in self . project . fixtures . iter_mut ( ) . enumerate ( ) {
211+ if self . selected_macro_group_index as usize == i {
212+ let target_macro_index = controller - controller_start;
213+ debug ! (
214+ "Controller number {} => target macro index {}" ,
215+ controller, target_macro_index
216+ ) ;
217+ match fixture
218+ . config
219+ . active_mode
220+ . macros
221+ . get_mut ( target_macro_index as usize )
222+ {
223+ Some ( m) => match m {
224+ crate :: project:: FixtureMacro :: Control ( control_macro) => {
225+ let value = value * 2 ;
226+ debug ! ( "Adjust {} to {}" , & control_macro. label, value) ;
227+ control_macro. current_value = value;
228+ }
229+ crate :: project:: FixtureMacro :: Colour ( colour_macro) => {
230+ let value = value * 2 ;
231+
232+ let [ r, g, b, a] = colour_macro. current_value . to_array ( ) ;
233+
234+ colour_macro. current_value =
235+ Color32 :: from_rgba_premultiplied ( r, g, b, value) ;
236+
237+ debug ! ( "Color a {} => {}" , a, colour_macro. current_value. a( ) ) ;
238+ }
239+ } ,
240+ None => {
241+ error ! ( "Failed to match macro control" ) ;
242+ }
243+ }
244+ }
245+ }
236246 }
237247 }
238248 }
0 commit comments