@@ -5,12 +5,12 @@ use vst::util::ParameterTransfer;
55
66use util:: parameter_value_conversion:: { f32_to_bool, f32_to_byte} ;
77use util:: parameters:: { ParameterConversion , get_exponential_scale_value} ;
8- use util:: { HostCallbackLock , DelayOffset } ;
8+ use util:: { HostCallbackLock , Duration } ;
99use util:: delayed_message_consumer:: MaxNotesParameter ;
1010use std:: fmt:: { Display , Formatter } ;
1111use std:: fmt;
1212
13- const PARAMETER_COUNT : usize = 4 ;
13+ pub const PARAMETER_COUNT : usize = 5 ;
1414
1515pub struct NoteOffDelayPluginParameters {
1616 pub host_mutex : Mutex < HostCallbackLock > ,
@@ -23,6 +23,7 @@ pub enum Parameter {
2323 MaxNotes ,
2424 MaxNotesAppliesToDelayedNotesOnly ,
2525 MultiplyLength ,
26+ Threshold
2627}
2728
2829impl From < i32 > for Parameter {
@@ -32,6 +33,7 @@ impl From<i32> for Parameter {
3233 1 => Parameter :: MaxNotes ,
3334 2 => Parameter :: MaxNotesAppliesToDelayedNotesOnly ,
3435 3 => Parameter :: MultiplyLength ,
36+ 4 => Parameter :: Threshold ,
3537 _ => panic ! ( "no such parameter {}" , i) ,
3638 }
3739 }
@@ -71,8 +73,9 @@ impl NoteOffDelayPluginParameters {
7173
7274 pub fn get_delay ( & self ) -> Delay {
7375 Delay {
74- offset : DelayOffset :: from ( self . get_parameter ( Parameter :: DelayOffset . into ( ) ) ) ,
75- multiplier : DelayMultiplier :: from ( self . get_parameter ( Parameter :: MultiplyLength . into ( ) ) )
76+ offset : Duration :: from ( self . get_parameter ( Parameter :: DelayOffset . into ( ) ) ) ,
77+ multiplier : DelayMultiplier :: from ( self . get_parameter ( Parameter :: MultiplyLength . into ( ) ) ) ,
78+ threshold : Duration :: from ( self . get_parameter ( Parameter :: Threshold . into ( ) ) ) ,
7679 }
7780 }
7881}
@@ -88,8 +91,9 @@ impl Default for NoteOffDelayPluginParameters {
8891
8992
9093pub struct Delay {
91- pub offset : DelayOffset ,
94+ pub offset : Duration ,
9295 pub multiplier : DelayMultiplier ,
96+ pub threshold : Duration
9397}
9498
9599
@@ -100,19 +104,26 @@ pub enum DelayMultiplier {
100104
101105impl Delay {
102106 pub fn is_active ( & self ) -> bool {
103- !matches ! ( ( & self . offset, & self . multiplier) , ( DelayOffset :: Off , DelayMultiplier :: Off ) )
107+ !matches ! ( ( & self . offset, & self . multiplier) , ( Duration :: Off , DelayMultiplier :: Off ) )
104108 }
105109
106110 pub fn apply ( & self , duration_in_samples : usize , sample_rate : f32 ) -> Option < usize > {
107111 if self . is_active ( ) {
112+ if let Duration :: Duration ( threshold) = self . threshold {
113+ let threshold_in_samples = ( threshold * sample_rate) as usize ;
114+ if duration_in_samples < threshold_in_samples {
115+ return Some ( duration_in_samples)
116+ }
117+ }
118+
108119 let duration_in_samples = match self . multiplier {
109120 DelayMultiplier :: Off => duration_in_samples as f32 ,
110121 DelayMultiplier :: Multiplier ( x) => x * duration_in_samples as f32
111122 } ;
112123
113124 Some ( match self . offset {
114- DelayOffset :: Off => duration_in_samples as usize ,
115- DelayOffset :: Duration ( x) => ( duration_in_samples + x * sample_rate) as usize
125+ Duration :: Off => duration_in_samples as usize ,
126+ Duration :: Duration ( x) => ( duration_in_samples + x * sample_rate) as usize
116127 } )
117128 } else {
118129 None
@@ -145,13 +156,14 @@ impl From<f32> for DelayMultiplier {
145156
146157impl vst:: plugin:: PluginParameters for NoteOffDelayPluginParameters {
147158 fn get_parameter_text ( & self , index : i32 ) -> String {
159+ let value = self . get_parameter ( index) ;
148160 match index. into ( ) {
149- Parameter :: DelayOffset => {
150- DelayOffset :: from ( self . get_parameter ( Parameter :: DelayOffset as i32 ) ) . to_string ( )
161+ Parameter :: DelayOffset | Parameter :: Threshold => {
162+ Duration :: from ( value ) . to_string ( )
151163 }
152164
153165 Parameter :: MaxNotes => {
154- if self . get_parameter ( Parameter :: MaxNotes as i32 ) == 0.0 {
166+ if value == 0.0 {
155167 "Off" . to_string ( )
156168 } else {
157169 format ! ( "{}" , self . get_max_notes( ) )
@@ -166,7 +178,7 @@ impl vst::plugin::PluginParameters for NoteOffDelayPluginParameters {
166178 } . to_string ( )
167179 }
168180 Parameter :: MultiplyLength => {
169- DelayMultiplier :: from ( self . get_parameter ( Parameter :: MultiplyLength as i32 ) ) . to_string ( )
181+ DelayMultiplier :: from ( value ) . to_string ( )
170182 }
171183 }
172184 }
@@ -176,7 +188,8 @@ impl vst::plugin::PluginParameters for NoteOffDelayPluginParameters {
176188 Parameter :: DelayOffset => "Delay" ,
177189 Parameter :: MaxNotes => "Max Notes" ,
178190 Parameter :: MaxNotesAppliesToDelayedNotesOnly => "Apply max notes to delayed notes only" ,
179- Parameter :: MultiplyLength => "Length multiplier"
191+ Parameter :: MultiplyLength => "Length multiplier" ,
192+ Parameter :: Threshold => "Threshold"
180193 }
181194 . to_string ( )
182195 }
@@ -187,7 +200,7 @@ impl vst::plugin::PluginParameters for NoteOffDelayPluginParameters {
187200
188201 fn set_parameter ( & self , index : i32 , value : f32 ) {
189202 match index. into ( ) {
190- Parameter :: DelayOffset | Parameter :: MultiplyLength => {
203+ Parameter :: DelayOffset | Parameter :: MultiplyLength | Parameter :: Threshold => {
191204 let old_value = self . get_parameter ( index) ;
192205 if ( value - old_value) . abs ( ) > 0.0001 || ( value == 0.0 && old_value != 0.0 ) {
193206 self . transfer . set_parameter ( index as usize , value)
0 commit comments