Skip to content

Commit 6259967

Browse files
committed
fix(sequences): merging multiple presets into a single cue doesn't work
1 parent 3eb6f44 commit 6259967

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

crates/components/sequencer/commands/src/store_programmer_in_sequence.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ impl<'a> Command<'a> for StoreProgrammerInSequenceCommand {
6666
.collect();
6767
match self.store_mode {
6868
StoreMode::Merge => {
69-
cue.merge(cue_channels);
69+
cue.merge_controls(cue_channels);
70+
cue.merge_presets(&self.presets);
7071
// TODO: this can cause the same effect to run multiple times
7172
for effect in &self.effects {
7273
cue.effects.push(CueEffect {

crates/components/sequencer/src/cue.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize};
1515
use std::cmp::Ordering;
1616
use std::collections::HashMap;
1717
use std::time::Duration;
18+
use mizer_fixtures::programmer::ProgrammedPreset;
1819

1920
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
2021
pub struct Cue {
@@ -60,7 +61,7 @@ impl Cue {
6061
}
6162
}
6263

63-
pub fn merge(&mut self, controls: Vec<CueControl>) {
64+
pub fn merge_controls(&mut self, controls: Vec<CueControl>) {
6465
for control in controls {
6566
if let Some(target) = self
6667
.controls
@@ -86,6 +87,21 @@ impl Cue {
8687
self.controls.retain(|c| !c.fixtures.is_empty());
8788
}
8889

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+
89105
pub(crate) fn is_done(&self, state: &SequenceState) -> bool {
90106
state
91107
.channel_state
@@ -494,7 +510,7 @@ mod tests {
494510
let mut cue = Cue::new(1, "", vec![old_control.clone()]);
495511
let controls = vec![new_control.clone()];
496512

497-
cue.merge(controls);
513+
cue.merge_controls(controls);
498514

499515
assert_eq!(vec![old_control, new_control], cue.controls);
500516
}
@@ -521,7 +537,7 @@ mod tests {
521537
control: FixtureFaderControl::Intensity,
522538
}];
523539

524-
cue.merge(controls);
540+
cue.merge_controls(controls);
525541

526542
assert_eq!(vec![expected], cue.controls);
527543
}
@@ -550,7 +566,7 @@ mod tests {
550566
}],
551567
);
552568

553-
cue.merge(expected.clone());
569+
cue.merge_controls(expected.clone());
554570

555571
assert_eq!(expected, cue.controls);
556572
}

0 commit comments

Comments
 (0)