Skip to content

Commit 20aa534

Browse files
committed
feat(fixtures): properly implement htp priority
1 parent 69caa79 commit 20aa534

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

crates/components/fixtures/src/fixture.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,30 @@ impl ChannelValue {
5757
"ChannelValue::get",
5858
&format!("values: {}", self.values.len())
5959
);
60-
// TODO: find highest htp value before ltp values
61-
self.values
60+
61+
if let Some((_, value)) = self.values.iter().find(|(priority, _)| priority.is_programmer()) {
62+
return Some(*value);
63+
}
64+
65+
let ltp_highest = self.values
6266
.iter()
67+
.filter(|(priority, _)| priority.is_ltp())
6368
.max_by_key(|(priority, _)| *priority)
6469
.map(|(_, value)| *value)
70+
.map(|value| value.clamp(0., 1.));
71+
let htp_highest = self.values
72+
.iter()
73+
.filter(|(priority, _)| priority.is_htp())
74+
.map(|(_, value)| *value)
6575
.map(|value| value.clamp(0., 1.))
76+
.max_by(|a, b| a.partial_cmp(b).unwrap());
77+
78+
match (ltp_highest, htp_highest) {
79+
(None, Some(value)) => Some(value),
80+
(Some(value), None) => Some(value),
81+
(Some(ltp), Some(htp)) => Some(ltp.max(htp)),
82+
(None, None) => None,
83+
}
6684
}
6785

6886
pub fn clear(&mut self) {
@@ -598,7 +616,7 @@ mod tests {
598616

599617
use crate::definition::FixtureFaderControl;
600618
use crate::fixture::{ChannelLimit, FixtureConfiguration};
601-
use crate::LTPPriority;
619+
use crate::{FixturePriority, LTPPriority};
602620

603621
use super::{convert_value, convert_value_16bit, convert_value_24bit};
604622

@@ -730,4 +748,16 @@ mod tests {
730748

731749
assert_eq!(expected, result.unwrap());
732750
}
751+
752+
#[test_case(0.5, 1.0, 1.0)]
753+
#[test_case(1.0, 0.5, 1.0)]
754+
fn channel_value_should_return_highest_value_when_htp_is_used(value_ltp: f64, value_htp: f64, expected: f64) {
755+
let mut channel_value = super::ChannelValue::default();
756+
channel_value.insert(value_ltp, LTPPriority::Low.into());
757+
channel_value.insert(value_htp, FixturePriority::HTP);
758+
759+
let result = channel_value.get();
760+
761+
assert_eq!(expected, result.unwrap());
762+
}
733763
}

crates/components/fixtures/src/priority.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ impl FixturePriority {
6363
pub const HIGH: Self = Self::LTP(LTPPriority::High);
6464
pub const LOW: Self = Self::LTP(LTPPriority::Low);
6565
pub const LOWEST: Self = Self::LTP(LTPPriority::Lowest);
66+
67+
pub fn is_programmer(&self) -> bool {
68+
matches!(self, Self::Programmer)
69+
}
70+
71+
pub fn is_ltp(&self) -> bool {
72+
matches!(self, Self::LTP(_))
73+
}
74+
75+
pub fn is_htp(&self) -> bool {
76+
matches!(self, Self::HTP)
77+
}
6678
}
6779

6880
impl Default for FixturePriority {

0 commit comments

Comments
 (0)