mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-01 22:30:42 -07:00
gitadora: option for guitar picking algorithm (#528)
## Link to GitHub Issue, if one exists n/a ## Description of change Adds an option to pick from four algorithms for guitar picking input. The default behavior is being switched from legacy (rising edge only, always 1 frame of input) to SOCD "prefer recent" algorithm. This makes it slightly easier to navigate the menu with the guitar. ## Testing Validated gw, gwdelta, and sdvx just in case.
This commit is contained in:
@@ -15,18 +15,23 @@ namespace socd {
|
||||
|
||||
SocdAlgorithm ALGORITHM = SocdAlgorithm::Neutral;
|
||||
|
||||
static double last_rising_edge[2][2] = {};
|
||||
static bool last_button_state[2][2] = {};
|
||||
static double last_rising_edge[4][2] = {};
|
||||
static bool last_button_state[4][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) {
|
||||
SocdResult socd_clean(
|
||||
uint8_t device, bool ccw, bool cw, double time_now,
|
||||
std::optional<SocdAlgorithm> algorithm_override) {
|
||||
|
||||
if (device >= 4) {
|
||||
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
|
||||
SocdAlgorithm algo =
|
||||
algorithm_override.has_value() ? algorithm_override.value() : ALGORITHM;
|
||||
|
||||
// keep track of rising edge times
|
||||
if (algo == SocdAlgorithm::PreferRecent || algo == SocdAlgorithm::PreferFirst) {
|
||||
if (!last_button_state[device][SocdCCW] && ccw) {
|
||||
last_rising_edge[device][SocdCCW] = time_now;
|
||||
}
|
||||
@@ -55,7 +60,7 @@ namespace socd {
|
||||
const auto cw_time = last_rising_edge[device][SocdCW];
|
||||
log_debug("socd", "ccw={}, cw ={}", ccw_time, cw_time);
|
||||
|
||||
if (ALGORITHM == SocdAlgorithm::PreferRecent) {
|
||||
if (algo == SocdAlgorithm::PreferRecent) {
|
||||
// SOCD: prefer last input
|
||||
if (ccw_time < cw_time) {
|
||||
// while CCW is being held, CW got pressed
|
||||
@@ -67,7 +72,7 @@ namespace socd {
|
||||
// it's a tie; instead of none, we'll pick a direction
|
||||
return SocdCW;
|
||||
}
|
||||
} else if (ALGORITHM == SocdAlgorithm::PreferFirst) {
|
||||
} else if (algo == SocdAlgorithm::PreferFirst) {
|
||||
// SOCD: keep first input
|
||||
if (ccw_time < cw_time) {
|
||||
// while CCW is being held, CW got pressed
|
||||
@@ -79,9 +84,15 @@ namespace socd {
|
||||
// it's a tie; instead of none, we'll pick a direction
|
||||
return SocdCW;
|
||||
}
|
||||
} else {
|
||||
} else if (algo == SocdAlgorithm::Neutral) {
|
||||
// SOCD: neutral when both are pressed
|
||||
return SocdNone;
|
||||
} else if (algo == SocdAlgorithm::None) {
|
||||
// SOCD: both are pressed
|
||||
return SocdBoth;
|
||||
} else {
|
||||
log_fatal("socd", "invalid SOCD algorithm");
|
||||
return SocdNone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +108,8 @@ namespace socd {
|
||||
log_fatal("socd", "invalid device index in socd_clean: {}", device);
|
||||
}
|
||||
|
||||
const auto socd_result = socd_clean(device, up, down, time_now);
|
||||
const auto socd_result = socd_clean(
|
||||
device + 2, up, down, time_now, SocdAlgorithm::PreferRecent);
|
||||
|
||||
if (up) {
|
||||
most_recent_active[device][TiltUp] = time_now;
|
||||
@@ -125,7 +137,7 @@ namespace socd {
|
||||
result = TiltUp;
|
||||
} else if (socd_result == SocdCW) {
|
||||
result = TiltDown;
|
||||
} else {
|
||||
} else if (socd_result == SocdBoth) {
|
||||
result = TiltUp;
|
||||
}
|
||||
} else if (is_up) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <cstdint>
|
||||
|
||||
namespace socd {
|
||||
@@ -9,7 +10,8 @@ namespace socd {
|
||||
enum class SocdAlgorithm {
|
||||
Neutral,
|
||||
PreferRecent,
|
||||
PreferFirst
|
||||
PreferFirst,
|
||||
None,
|
||||
};
|
||||
|
||||
extern SocdAlgorithm ALGORITHM;
|
||||
@@ -17,10 +19,16 @@ namespace socd {
|
||||
typedef enum _SocdResult {
|
||||
SocdCCW = 0,
|
||||
SocdCW = 1,
|
||||
SocdNone = 2
|
||||
SocdNone = 2,
|
||||
SocdBoth = 3
|
||||
} SocdResult;
|
||||
|
||||
SocdResult socd_clean(uint8_t device, bool ccw, bool cw, double time_now);
|
||||
SocdResult socd_clean(
|
||||
uint8_t device,
|
||||
bool ccw,
|
||||
bool cw,
|
||||
double time_now,
|
||||
std::optional<SocdAlgorithm> algorithm = std::nullopt);
|
||||
|
||||
// for guitar wail (up/down only)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user