@@ -1500,7 +1500,8 @@ void Edrumulus::Pad::process_control_sample ( const int* input,
1500
1500
int cur_midi_ctrl_value = ( ( ADC_MAX_RANGE - input[0 ] - control_threshold ) / control_range * 127 );
1501
1501
cur_midi_ctrl_value = max ( 0 , min ( 127 , cur_midi_ctrl_value ) );
1502
1502
1503
- // detect pedal hit
1503
+
1504
+ // Detect pedal stomp --------------------------------------------------------
1504
1505
update_fifo ( cur_midi_ctrl_value, ctrl_history_len, ctrl_hist );
1505
1506
1506
1507
float prev_ctrl_average = 0 .0f ;
@@ -1513,24 +1514,30 @@ void Edrumulus::Pad::process_control_sample ( const int* input,
1513
1514
prev_ctrl_average /= ctrl_history_len_half;
1514
1515
cur_ctrl_average /= ctrl_history_len_half;
1515
1516
1516
- const float ctrl_gradient = ( cur_ctrl_average - prev_ctrl_average ) / ctrl_history_len_half;
1517
-
1517
+ // check if we just crossed the transition from open to close
1518
1518
if ( ( prev_ctrl_average < hi_hat_is_open_MIDI_threshold ) &&
1519
- ( cur_ctrl_average >= hi_hat_is_open_MIDI_threshold ) &&
1520
- ( ctrl_gradient > ctrl_velocity_threshold ) )
1519
+ ( cur_ctrl_average >= hi_hat_is_open_MIDI_threshold ) )
1521
1520
{
1522
- // map curve difference (gradient) to velocity
1523
- midi_velocity = min ( 127 , max ( 1 , static_cast <int > ( ( ctrl_gradient - ctrl_velocity_threshold ) * ctrl_velocity_range_fact ) ) );
1524
- peak_found = true ;
1521
+ // calculate the gradient which is the measure for the pedal stomp velocity
1522
+ const float ctrl_gradient = ( cur_ctrl_average - prev_ctrl_average ) / ctrl_history_len_half;
1525
1523
1526
- // reset the history after a detection to suppress multiple detections
1527
- for ( int i = 0 ; i < ctrl_history_len; i++ )
1524
+ // only send MIDI note for pedal stomp if we are above the given threshold
1525
+ if ( ctrl_gradient > ctrl_velocity_threshold )
1528
1526
{
1529
- ctrl_hist[i] = hi_hat_is_open_MIDI_threshold;
1527
+ // map curve difference (gradient) to velocity
1528
+ midi_velocity = min ( 127 , max ( 1 , static_cast <int > ( ( ctrl_gradient - ctrl_velocity_threshold ) * ctrl_velocity_range_fact ) ) );
1529
+ peak_found = true ;
1530
+
1531
+ // reset the history after a detection to suppress multiple detections
1532
+ for ( int i = 0 ; i < ctrl_history_len; i++ )
1533
+ {
1534
+ ctrl_hist[i] = hi_hat_is_open_MIDI_threshold;
1535
+ }
1530
1536
}
1531
1537
}
1532
1538
1533
- // introduce hysteresis to avoid sending too many MIDI control messages
1539
+
1540
+ // Introduce hysteresis to avoid sending too many MIDI control messages ------
1534
1541
change_found = false ;
1535
1542
1536
1543
if ( ( cur_midi_ctrl_value > ( prev_ctrl_value + control_midi_hysteresis ) ) ||
0 commit comments