@@ -57,12 +57,30 @@ impl ChannelValue {
57
57
"ChannelValue::get" ,
58
58
& format!( "values: {}" , self . values. len( ) )
59
59
) ;
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
62
66
. iter ( )
67
+ . filter ( |( priority, _) | priority. is_ltp ( ) )
63
68
. max_by_key ( |( priority, _) | * priority)
64
69
. 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)
65
75
. 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
+ }
66
84
}
67
85
68
86
pub fn clear ( & mut self ) {
@@ -598,7 +616,7 @@ mod tests {
598
616
599
617
use crate :: definition:: FixtureFaderControl ;
600
618
use crate :: fixture:: { ChannelLimit , FixtureConfiguration } ;
601
- use crate :: LTPPriority ;
619
+ use crate :: { FixturePriority , LTPPriority } ;
602
620
603
621
use super :: { convert_value, convert_value_16bit, convert_value_24bit} ;
604
622
@@ -730,4 +748,16 @@ mod tests {
730
748
731
749
assert_eq ! ( expected, result. unwrap( ) ) ;
732
750
}
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
+ }
733
763
}
0 commit comments