121 Q_PROPERTY(
double triggerThreshold READ getTriggerThreshold WRITE
122 setTriggerThreshold NOTIFY triggerThresholdChanged)
128 Q_PROPERTY(
double releaseThreshold READ getReleaseThreshold WRITE
129 setReleaseThreshold NOTIFY releaseThresholdChanged)
136 uint timeout READ getTimeout WRITE setTimeout NOTIFY timeoutChanged)
141 setScratchAlgorithm NOTIFY scratchAlgorithmChanged)
151 ScratchAlgorithmClassic
153 Q_ENUM(ScratchAlgorithm)
155 double triggerThreshold = 0.008;
156 double releaseThreshold = 0.004;
158 ScratchAlgorithm algorithm = ScratchAlgorithmAnalog;
161 auto getTriggerThreshold() const ->
double;
162 void setTriggerThreshold(
double value);
163 auto getReleaseThreshold() const ->
double;
164 void setReleaseThreshold(
double value);
165 auto getTimeout() const -> uint;
166 void setTimeout(uint
value);
167 auto getScratchAlgorithm() const -> ScratchAlgorithm;
168 void setScratchAlgorithm(ScratchAlgorithm
value);
171 void triggerThresholdChanged();
172 void releaseThresholdChanged();
173 void timeoutChanged();
174 void scratchAlgorithmChanged();
183 Q_PROPERTY(
bool configuring READ isConfiguring NOTIFY configuringChanged)
187 Q_PROPERTY(QVariant configuredButton READ getConfiguredButton WRITE
188 setConfiguredButton NOTIFY configuredButtonChanged)
189 Q_PROPERTY(QList<
Mapping> keyConfig READ getKeyConfig WRITE setKeyConfig
190 NOTIFY keyConfigModified)
191 Q_PROPERTY(
bool col11 READ col11 NOTIFY col11Changed)
192 Q_PROPERTY(
bool col12 READ col12 NOTIFY col12Changed)
193 Q_PROPERTY(
bool col13 READ col13 NOTIFY col13Changed)
194 Q_PROPERTY(
bool col14 READ col14 NOTIFY col14Changed)
195 Q_PROPERTY(
bool col15 READ col15 NOTIFY col15Changed)
196 Q_PROPERTY(
bool col16 READ col16 NOTIFY col16Changed)
197 Q_PROPERTY(
bool col17 READ col17 NOTIFY col17Changed)
198 Q_PROPERTY(
bool col1sUp READ col1sUp NOTIFY col1sUpChanged)
199 Q_PROPERTY(
bool col1sDown READ col1sDown NOTIFY col1sDownChanged)
200 Q_PROPERTY(
bool col21 READ col21 NOTIFY col21Changed)
201 Q_PROPERTY(
bool col22 READ col22 NOTIFY col22Changed)
202 Q_PROPERTY(
bool col23 READ col23 NOTIFY col23Changed)
203 Q_PROPERTY(
bool col24 READ col24 NOTIFY col24Changed)
204 Q_PROPERTY(
bool col25 READ col25 NOTIFY col25Changed)
205 Q_PROPERTY(
bool col26 READ col26 NOTIFY col26Changed)
206 Q_PROPERTY(
bool col27 READ col27 NOTIFY col27Changed)
207 Q_PROPERTY(
bool col2sUp READ col2sUp NOTIFY col2sUpChanged)
208 Q_PROPERTY(
bool col2sDown READ col2sDown NOTIFY col2sDownChanged)
209 Q_PROPERTY(
bool start1 READ start1 NOTIFY start1Changed)
210 Q_PROPERTY(
bool select1 READ select1 NOTIFY select1Changed)
211 Q_PROPERTY(
bool start2 READ start2 NOTIFY start2Changed)
212 Q_PROPERTY(
bool select2 READ select2 NOTIFY select2Changed)
214 getAnalogAxisConfig1 NOTIFY analogAxisConfig1Changed)
216 getAnalogAxisConfig2 NOTIFY analogAxisConfig2Changed)
217 Q_PROPERTY(
double debounceMs READ getDebounceMs WRITE setDebounceMs NOTIFY
218 debounceMsChanged RESET resetDebounceMs)
223 std::unique_ptr<QTimer> timer = std::make_unique<QTimer>();
227 double value = std::numeric_limits<double>::quiet_NaN();
238 enum class ReleaseMode
244 struct PendingRelease
247 std::optional<int64_t> inputDeadline;
252 bool physicallyPressed{};
253 bool logicallyPressed{};
254 std::optional<PendingRelease> pendingRelease;
255 QTimer debounceTimer;
260 template<
typename T,
typename U>
261 auto operator()(
const std::pair<T, U>& x)
const -> std::size_t
263 return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);
266 std::unordered_map<std::pair<Gamepad, uint8_t>, Scratch, PairHash>
268 std::optional<BmsKey> configuredButton;
269 std::unordered_map<std::pair<Gamepad, uint8_t>, AnalogAxisConfig*, PairHash>
271 QHash<Key, BmsKey> config;
273 std::array<ButtonState, magic_enum::enum_count<BmsKey>()> buttons;
274 std::array<QTimer, magic_enum::enum_count<BmsKey>()> tickTimers;
275 std::array<int, magic_enum::enum_count<BmsKey>()> tickNumbers{ {} };
276 std::array<TickType, magic_enum::enum_count<BmsKey>()> tickTypes{ {} };
277 std::optional<std::pair<Gamepad, uint8_t>> scratchAxis1;
278 std::optional<std::pair<Gamepad, uint8_t>> scratchAxis2;
279 double debounceMs = 5.0;
281 void pressButton(BmsKey button, int64_t time);
282 void releaseButton(BmsKey button,
284 ReleaseMode mode = ReleaseMode::Debounced);
285 void commitPendingRelease(BmsKey button);
286 void finishRelease(BmsKey button, int64_t time);
287 auto debounceInterval() const -> std::chrono::milliseconds;
288 void unpressAndUnbind(const Key& key, int64_t time);
289 void bindKeyToButton(const Key& key, BmsKey button, int64_t time);
290 void saveKeyConfig() const;
291 void saveAnalogAxisConfig() const;
292 void handleAxisChange(Gamepad gamepad,
296 int analogTickCount = 1);
297 void emitAnalogScratchTicks(Gamepad gamepad,
299 Key::Direction direction,
301 void checkAnalogAxisStatus();
302 void autoReleaseScratch(const std::pair<Gamepad, uint8_t>& scratchKey,
304 void emitTick(BmsKey button);
307 void handleAxis(Gamepad gamepad, Uint8 axis,
double value, int64_t time);
308 void handlePress(Gamepad gamepad, Uint8 button, int64_t time);
309 void handleRelease(Gamepad gamepad, Uint8 button, int64_t time);
310 void handleMidiNote(MidiDevice device,
315 void handleMidiControl(MidiDevice device,
320 void handleMidiPitchBend(MidiDevice device,
324 void handleMidiDeviceRemoved(MidiDevice device, int64_t time);
328 void handleKeyEvent(quint32 nativeScanCode,
bool isPress, int64_t time);
330 void loadKeyConfig();
331 void connectAnalogAxisConfig(const AnalogAxisConfig& config);
332 void loadAnalogAxisConfig();
335 explicit InputTranslator(
db::SqliteCppDb*
db, QObject* parent =
nullptr);
336 void setConfiguredButton(const QVariant& button);
337 auto getConfiguredButton() const -> QVariant;
338 auto isConfiguring() const ->
bool;
339 void setKeyConfig(const QList<Mapping>& config);
340 auto getKeyConfig() -> QList<Mapping>;
341 void setKeyConfig(const QHash<Key, BmsKey>& config);
342 auto getKeyConfigHash() -> QHash<Key, BmsKey>;
343 Q_INVOKABLE
void resetButton(BmsKey key);
344 auto col11() const ->
bool;
345 auto col12() const ->
bool;
346 auto col13() const ->
bool;
347 auto col14() const ->
bool;
348 auto col15() const ->
bool;
349 auto col16() const ->
bool;
350 auto col17() const ->
bool;
351 auto col1sUp() const ->
bool;
352 auto col1sDown() const ->
bool;
353 auto col21() const ->
bool;
354 auto col22() const ->
bool;
355 auto col23() const ->
bool;
356 auto col24() const ->
bool;
357 auto col25() const ->
bool;
358 auto col26() const ->
bool;
359 auto col27() const ->
bool;
360 auto col2sUp() const ->
bool;
361 auto col2sDown() const ->
bool;
362 auto start1() const ->
bool;
363 auto select1() const ->
bool;
364 auto start2() const ->
bool;
365 auto select2() const ->
bool;
368 void eventFilter(std::chrono::milliseconds timePoint, QEvent* event);
369 Q_INVOKABLE static QString scancodeToString(
int virtualKey);
370 static auto computeAnalogScratchTicks(
double oldValue,
double newValue)
372 auto getDebounceMs() const ->
double;
373 void setDebounceMs(
double value);
374 void resetDebounceMs();
377 void buttonPressed(
BmsKey button, int64_t time);
378 void buttonReleased(
BmsKey button, int64_t time);
379 void keyConfigModified();
380 void configuringChanged();
381 void configuredButtonChanged();
389 void col1sUpChanged();
390 void col1sDownChanged();
398 void col2sUpChanged();
399 void col2sDownChanged();
400 void start1Changed();
401 void select1Changed();
402 void start2Changed();
403 void select2Changed();
404 void analogAxisConfig1Changed();
405 void analogAxisConfig2Changed();
406 void debounceMsChanged();