@@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize};
15
15
use std:: cmp:: Ordering ;
16
16
use std:: collections:: HashMap ;
17
17
use std:: time:: Duration ;
18
+ use mizer_fixtures:: programmer:: ProgrammedPreset ;
18
19
19
20
#[ derive( Debug , Clone , Deserialize , Serialize , PartialEq ) ]
20
21
pub struct Cue {
@@ -60,7 +61,7 @@ impl Cue {
60
61
}
61
62
}
62
63
63
- pub fn merge ( & mut self , controls : Vec < CueControl > ) {
64
+ pub fn merge_controls ( & mut self , controls : Vec < CueControl > ) {
64
65
for control in controls {
65
66
if let Some ( target) = self
66
67
. controls
@@ -86,6 +87,21 @@ impl Cue {
86
87
self . controls . retain ( |c| !c. fixtures . is_empty ( ) ) ;
87
88
}
88
89
90
+ pub fn merge_presets ( & mut self , presets : & [ ProgrammedPreset ] ) {
91
+ for new_preset in presets {
92
+ for existing in self . presets . iter_mut ( ) {
93
+ if existing. preset_id . preset_type ( ) == new_preset. preset_id . preset_type ( ) {
94
+ existing. fixtures . retain (
95
+ |fixture_id| !new_preset. fixtures . contains ( fixture_id) ,
96
+ )
97
+ }
98
+ }
99
+ }
100
+ self . presets . retain ( |preset| !preset. fixtures . is_empty ( ) ) ;
101
+ let new_presets = presets. into_iter ( ) . cloned ( ) . map ( Into :: into) ;
102
+ self . presets . extend ( new_presets) ;
103
+ }
104
+
89
105
pub ( crate ) fn is_done ( & self , state : & SequenceState ) -> bool {
90
106
state
91
107
. channel_state
@@ -494,7 +510,7 @@ mod tests {
494
510
let mut cue = Cue :: new ( 1 , "" , vec ! [ old_control. clone( ) ] ) ;
495
511
let controls = vec ! [ new_control. clone( ) ] ;
496
512
497
- cue. merge ( controls) ;
513
+ cue. merge_controls ( controls) ;
498
514
499
515
assert_eq ! ( vec![ old_control, new_control] , cue. controls) ;
500
516
}
@@ -521,7 +537,7 @@ mod tests {
521
537
control: FixtureFaderControl :: Intensity ,
522
538
} ] ;
523
539
524
- cue. merge ( controls) ;
540
+ cue. merge_controls ( controls) ;
525
541
526
542
assert_eq ! ( vec![ expected] , cue. controls) ;
527
543
}
@@ -550,7 +566,7 @@ mod tests {
550
566
} ] ,
551
567
) ;
552
568
553
- cue. merge ( expected. clone ( ) ) ;
569
+ cue. merge_controls ( expected. clone ( ) ) ;
554
570
555
571
assert_eq ! ( expected, cue. controls) ;
556
572
}
0 commit comments