Skip to content

Commit

Permalink
Take debounce state into account for input filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinrabbid committed Nov 24, 2024
1 parent f5e1d84 commit 5fbc70b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/peripherals/Drum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void Drum::updateDigitalInputState(Utils::InputState &input_state, const std::ma
{entry.first, value_if_above_threshold(raw_values, m_config.trigger_thresholds, entry.first)});
}

// Only DON or KA can be active, zero minimum
// Only DON or KA can be active at a time, zero the lesser
if (std::max(filtered_raw_values.at(Id::DON_LEFT), filtered_raw_values.at(Id::DON_RIGHT)) >
std::max(filtered_raw_values.at(Id::KA_LEFT), filtered_raw_values.at(Id::KA_RIGHT))) {

Expand All @@ -173,6 +173,15 @@ void Drum::updateDigitalInputState(Utils::InputState &input_state, const std::ma
filtered_raw_values.at(Id::DON_RIGHT) = 0;
}

// Check same same with regard to current debounce state
if (m_pads.at(Id::DON_LEFT).getState() || m_pads.at(Id::DON_RIGHT).getState()) {
filtered_raw_values.at(Id::KA_LEFT) = 0;
filtered_raw_values.at(Id::KA_RIGHT) = 0;
} else if (m_pads.at(Id::KA_LEFT).getState() || m_pads.at(Id::KA_RIGHT).getState()) {
filtered_raw_values.at(Id::DON_LEFT) = 0;
filtered_raw_values.at(Id::DON_RIGHT) = 0;
}

// Zero values which are not within +/- 50% of their twin pad
const auto zero_if_not_within_twin = [](auto &values, Id a, Id b) {
if (values.at(a) == 0 || values.at(b) == 0) {
Expand All @@ -193,7 +202,7 @@ void Drum::updateDigitalInputState(Utils::InputState &input_state, const std::ma
zero_if_not_within_twin(filtered_raw_values, Id::DON_LEFT, Id::DON_RIGHT);
zero_if_not_within_twin(filtered_raw_values, Id::KA_LEFT, Id::KA_RIGHT);

// All values we now need to consider are != 0 and over their threshold.
// All values != 0 are already over their threshold.
for (const auto &entry : filtered_raw_values) {
if (entry.second != 0) {
m_pads.at(entry.first).setState(true, m_config.debounce_delay_ms);
Expand Down

0 comments on commit 5fbc70b

Please sign in to comment.