mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-02 14:50:41 -07:00
iidx, sdvx: SOCD cleaner for knobs and turntables (#497)
## Link to GitHub Issue, if one exists n/a ## Description of change Apply SOCD cleaner algorithm to deal with the case where both counter-clockwise and clockwise buttons are pressed at the same time. In SDVX, default algorithm is to prefer the most recently pressed direction. This is better for dealing with slams in rapid succession, for example, as you don't have to completely let go of one direction to hit the other now. In IIDX, default algorithm is neutral (same behavior as before). Using last or first algorithm results in double scratches which means you'll likely end up with an excessive poor after hitting a scratch, so neutral is actually beneficial. Besides, if you are serious about playing on the keyboard, you should be using `TT +/-` and `TT +/- Alternate`. ## Testing Tested SDVX 3, EG (old cab), EG valk cab modes, IIDX 24, 27, 33 (tdj/ldj)
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#include "socd_cleaner.h"
|
||||
|
||||
#include "util/logging.h"
|
||||
|
||||
#define DEBUG_VERBOSE 0
|
||||
|
||||
#if DEBUG_VERBOSE
|
||||
#define log_debug(module, format_str, ...) logger::push( \
|
||||
LOG_FORMAT("M", module, format_str, ## __VA_ARGS__), logger::Style::GREY)
|
||||
#else
|
||||
#define log_debug(module, format_str, ...)
|
||||
#endif
|
||||
|
||||
namespace socd {
|
||||
|
||||
SocdAlgorithm ALGORITHM = SocdAlgorithm::Neutral;
|
||||
|
||||
static double last_rising_edge[2][2] = {};
|
||||
static bool last_button_state[2][2] = {};
|
||||
|
||||
// this has no locking, use only if you know there is only one i/o thread that will call this
|
||||
SocdResult socd_clean(uint8_t device, bool ccw, bool cw, double time_now) {
|
||||
if (device >= 2) {
|
||||
log_fatal("socd", "invalid device index in socd_clean: {}", device);
|
||||
}
|
||||
|
||||
// SOCD last input algorithm needs to keep track of rising edge times
|
||||
if (ALGORITHM != SocdAlgorithm::Neutral) {
|
||||
// detect rising edges
|
||||
if (!last_button_state[device][SocdCCW] && ccw) {
|
||||
last_rising_edge[device][SocdCCW] = time_now;
|
||||
}
|
||||
if (!last_button_state[device][SocdCW] && cw) {
|
||||
last_rising_edge[device][SocdCW] = time_now;
|
||||
}
|
||||
|
||||
// update button state for next time
|
||||
last_button_state[device][SocdCCW] = ccw;
|
||||
last_button_state[device][SocdCW] = cw;
|
||||
}
|
||||
|
||||
// determine direction: easy cases
|
||||
if (!ccw && !cw) {
|
||||
return SocdNone;
|
||||
}
|
||||
if (ccw && !cw) {
|
||||
return SocdCCW;
|
||||
}
|
||||
if (!ccw && cw) {
|
||||
return SocdCW;
|
||||
}
|
||||
|
||||
// SOCD logic; depends on algorithm in use
|
||||
const auto ccw_time = last_rising_edge[device][SocdCCW];
|
||||
const auto cw_time = last_rising_edge[device][SocdCW];
|
||||
log_debug("socd", "ccw={}, cw ={}", ccw_time, cw_time);
|
||||
|
||||
if (ALGORITHM == SocdAlgorithm::PreferRecent) {
|
||||
// SOCD: prefer last input
|
||||
if (ccw_time < cw_time) {
|
||||
// while CCW is being held, CW got pressed
|
||||
return SocdCW;
|
||||
} else if (ccw_time > cw_time) {
|
||||
// while CW is being held, CCW got pressed
|
||||
return SocdCCW;
|
||||
} else {
|
||||
// it's a tie; instead of none, we'll pick a direction
|
||||
return SocdCW;
|
||||
}
|
||||
} else if (ALGORITHM == SocdAlgorithm::PreferFirst) {
|
||||
// SOCD: keep first input
|
||||
if (ccw_time < cw_time) {
|
||||
// while CCW is being held, CW got pressed
|
||||
return SocdCCW;
|
||||
} else if (ccw_time > cw_time) {
|
||||
// while CW is being held, CCW got pressed
|
||||
return SocdCW;
|
||||
} else {
|
||||
// it's a tie; instead of none, we'll pick a direction
|
||||
return SocdCW;
|
||||
}
|
||||
} else {
|
||||
// SOCD: neutral when both are pressed
|
||||
return SocdNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user