Skip to content

Commit

Permalink
Merge pull request #12474 from ronso0/keyboard-repeat
Browse files Browse the repository at this point in the history
backport Keyboard repeat #11572 to 2.4
  • Loading branch information
daschuer authored Jan 12, 2024
2 parents c0c7e8a + 49d6816 commit ef04ed3
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/control/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ ControlDoublePrivate::ControlDoublePrivate()
m_trackFlags(Stat::COUNT | Stat::SUM | Stat::AVERAGE |
Stat::SAMPLE_VARIANCE | Stat::MIN | Stat::MAX),
// default CO is read only
m_confirmRequired(true) {
m_confirmRequired(true),
m_kbdRepeatable(false) {
m_value.setValue(0.0);
}

Expand All @@ -56,7 +57,8 @@ ControlDoublePrivate::ControlDoublePrivate(
m_trackType(Stat::UNSPECIFIED),
m_trackFlags(Stat::COUNT | Stat::SUM | Stat::AVERAGE |
Stat::SAMPLE_VARIANCE | Stat::MIN | Stat::MAX),
m_confirmRequired(false) {
m_confirmRequired(false),
m_kbdRepeatable(false) {
initialize(defaultValue);
}

Expand Down
11 changes: 11 additions & 0 deletions src/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ class ControlDoublePrivate : public QObject {
m_description = description;
}

void setKbdRepeatable(bool enable) {
m_kbdRepeatable = enable;
}

bool getKbdRepeatable() const {
return m_kbdRepeatable;
}

// Sets the control value.
void set(double value, QObject* pSender);
// directly sets the control value. Must be used from and only from the
Expand Down Expand Up @@ -198,6 +206,9 @@ class ControlDoublePrivate : public QObject {
// User-visible, i18n description for what the control does.
QString m_description;

// If true, this control will be issued repeatedly if the keyboard key is held.
bool m_kbdRepeatable;

// The control value.
ControlValueAtomic<double> m_value;
// The default control value.
Expand Down
10 changes: 10 additions & 0 deletions src/control/controlobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class ControlObject : public QObject {
}
}

void setKbdRepeatable(bool enable) {
if (m_pControl) {
m_pControl->setKbdRepeatable(enable);
}
}

bool getKbdRepeatable() const {
return m_pControl ? m_pControl->getKbdRepeatable() : false;
}

void addAlias(const ConfigKey& aliasKey) const {
ControlDoublePrivate::insertAlias(aliasKey, m_key);
}
Expand Down
5 changes: 5 additions & 0 deletions src/control/controlpotmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ PotmeterControls::PotmeterControls(const ConfigKey& key)
&ControlPushButton::valueChanged,
this,
&PotmeterControls::decSmallValue);
m_controlUp.setKbdRepeatable(true);
m_controlUpSmall.setKbdRepeatable(true);
m_controlDown.setKbdRepeatable(true);
m_controlDownSmall.setKbdRepeatable(true);

connect(&m_controlSetDefault,
&ControlPushButton::valueChanged,
this,
Expand Down
13 changes: 3 additions & 10 deletions src/controllers/keyboard/keyboardeventfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QKeyEvent>
#include <QtDebug>

#include "control/controlobject.h"
#include "moc_keyboardeventfilter.cpp"
#include "util/cmdlineargs.h"

Expand Down Expand Up @@ -36,15 +35,9 @@ bool KeyboardEventFilter::eventFilter(QObject*, QEvent* e) {
#else
int keyId = ke->nativeScanCode();
#endif
//qDebug() << "KeyPress event =" << ke->key() << "KeyId =" << keyId;

// Run through list of active keys to see if the pressed key is already active
// Just for returning true if we are consuming this key event

foreach (const KeyDownInformation& keyDownInfo, m_qActiveKeyList) {
if (keyDownInfo.keyId == keyId) {
return true;
}
if (shouldSkipHeldKey(keyId)) {
return true;
}

QKeySequence ks = getKeySeq(ke);
Expand Down Expand Up @@ -76,7 +69,7 @@ bool KeyboardEventFilter::eventFilter(QObject*, QEvent* e) {
}
return result;
}
} else if (e->type()==QEvent::KeyRelease) {
} else if (e->type() == QEvent::KeyRelease) {
QKeyEvent* ke = (QKeyEvent*)e;

#ifdef __APPLE__
Expand Down
15 changes: 14 additions & 1 deletion src/controllers/keyboard/keyboardeventfilter.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include <QObject>
#include <QMultiHash>
#include <QObject>

#include "control/controlobject.h"
#include "preferences/configobject.h"

class ControlObject;
Expand Down Expand Up @@ -39,6 +40,18 @@ class KeyboardEventFilter : public QObject {

// Returns a valid QString with modifier keys from a QKeyEvent
QKeySequence getKeySeq(QKeyEvent *e);

// Run through list of active keys to see if the pressed key is already active
// and is not a control that repeats when held.
bool shouldSkipHeldKey(int keyId) {
return std::any_of(
m_qActiveKeyList.cbegin(),
m_qActiveKeyList.cend(),
[&](const KeyDownInformation& keyDownInfo) {
return keyDownInfo.keyId == keyId && !keyDownInfo.pControl->getKbdRepeatable();
});
}

// List containing keys which is currently pressed
QList<KeyDownInformation> m_qActiveKeyList;
// Pointer to keyboard config object
Expand Down
4 changes: 4 additions & 0 deletions src/engine/controls/bpmcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ BpmControl::BpmControl(const QString& group,

m_pLocalBpm = new ControlObject(ConfigKey(group, "local_bpm"));
m_pAdjustBeatsFaster = new ControlPushButton(ConfigKey(group, "beats_adjust_faster"), false);
m_pAdjustBeatsFaster->setKbdRepeatable(true);
connect(m_pAdjustBeatsFaster, &ControlObject::valueChanged,
this, &BpmControl::slotAdjustBeatsFaster,
Qt::DirectConnection);
m_pAdjustBeatsSlower = new ControlPushButton(ConfigKey(group, "beats_adjust_slower"), false);
m_pAdjustBeatsSlower->setKbdRepeatable(true);
connect(m_pAdjustBeatsSlower, &ControlObject::valueChanged,
this, &BpmControl::slotAdjustBeatsSlower,
Qt::DirectConnection);
m_pTranslateBeatsEarlier = new ControlPushButton(ConfigKey(group, "beats_translate_earlier"), false);
m_pTranslateBeatsEarlier->setKbdRepeatable(true);
connect(m_pTranslateBeatsEarlier, &ControlObject::valueChanged,
this, &BpmControl::slotTranslateBeatsEarlier,
Qt::DirectConnection);
m_pTranslateBeatsLater = new ControlPushButton(ConfigKey(group, "beats_translate_later"), false);
m_pTranslateBeatsLater->setKbdRepeatable(true);
connect(m_pTranslateBeatsLater, &ControlObject::valueChanged,
this, &BpmControl::slotTranslateBeatsLater,
Qt::DirectConnection);
Expand Down
8 changes: 8 additions & 0 deletions src/engine/controls/loopingcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,24 @@ LoopingControl::LoopingControl(const QString& group,
Qt::DirectConnection);

m_pCOBeatJumpSizeHalve = new ControlPushButton(ConfigKey(group, "beatjump_size_halve"));
m_pCOBeatJumpSizeHalve->setKbdRepeatable(true);
connect(m_pCOBeatJumpSizeHalve,
&ControlObject::valueChanged,
this,
&LoopingControl::slotBeatJumpSizeHalve);
m_pCOBeatJumpSizeDouble = new ControlPushButton(ConfigKey(group, "beatjump_size_double"));
m_pCOBeatJumpSizeDouble->setKbdRepeatable(true);
connect(m_pCOBeatJumpSizeDouble,
&ControlObject::valueChanged,
this,
&LoopingControl::slotBeatJumpSizeDouble);

m_pCOBeatJumpForward = new ControlPushButton(ConfigKey(group, "beatjump_forward"));
m_pCOBeatJumpForward->setKbdRepeatable(true);
connect(m_pCOBeatJumpForward, &ControlObject::valueChanged,
this, &LoopingControl::slotBeatJumpForward);
m_pCOBeatJumpBackward = new ControlPushButton(ConfigKey(group, "beatjump_backward"));
m_pCOBeatJumpBackward->setKbdRepeatable(true);
connect(m_pCOBeatJumpBackward, &ControlObject::valueChanged,
this, &LoopingControl::slotBeatJumpBackward);

Expand Down Expand Up @@ -221,9 +225,11 @@ LoopingControl::LoopingControl(const QString& group,
connect(m_pCOLoopScale, &ControlObject::valueChanged,
this, &LoopingControl::slotLoopScale);
m_pLoopHalveButton = new ControlPushButton(ConfigKey(group, "loop_halve"));
m_pLoopHalveButton->setKbdRepeatable(true);
connect(m_pLoopHalveButton, &ControlObject::valueChanged,
this, &LoopingControl::slotLoopHalve);
m_pLoopDoubleButton = new ControlPushButton(ConfigKey(group, "loop_double"));
m_pLoopDoubleButton->setKbdRepeatable(true);
connect(m_pLoopDoubleButton, &ControlObject::valueChanged,
this, &LoopingControl::slotLoopDouble);

Expand Down Expand Up @@ -1790,11 +1796,13 @@ BeatJumpControl::BeatJumpControl(const QString& group, double size)
: m_dBeatJumpSize(size) {
m_pJumpForward = new ControlPushButton(
keyForControl(group, "beatjump_%1_forward", size));
m_pJumpForward->setKbdRepeatable(true);
connect(m_pJumpForward, &ControlObject::valueChanged,
this, &BeatJumpControl::slotJumpForward,
Qt::DirectConnection);
m_pJumpBackward = new ControlPushButton(
keyForControl(group, "beatjump_%1_backward", size));
m_pJumpBackward->setKbdRepeatable(true);
connect(m_pJumpBackward, &ControlObject::valueChanged,
this, &BeatJumpControl::slotJumpBackward,
Qt::DirectConnection);
Expand Down
4 changes: 4 additions & 0 deletions src/engine/controls/ratecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,28 @@ RateControl::RateControl(const QString& group,
connect(m_pButtonRatePermDown, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermDown,
Qt::DirectConnection);
m_pButtonRatePermDown->setKbdRepeatable(true);

m_pButtonRatePermDownSmall =
new ControlPushButton(ConfigKey(group,"rate_perm_down_small"));
connect(m_pButtonRatePermDownSmall, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermDownSmall,
Qt::DirectConnection);
m_pButtonRatePermDownSmall->setKbdRepeatable(true);

m_pButtonRatePermUp =
new ControlPushButton(ConfigKey(group,"rate_perm_up"));
connect(m_pButtonRatePermUp, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermUp,
Qt::DirectConnection);
m_pButtonRatePermUp->setKbdRepeatable(true);

m_pButtonRatePermUpSmall =
new ControlPushButton(ConfigKey(group,"rate_perm_up_small"));
connect(m_pButtonRatePermUpSmall, &ControlObject::valueChanged,
this, &RateControl::slotControlRatePermUpSmall,
Qt::DirectConnection);
m_pButtonRatePermUpSmall->setKbdRepeatable(true);

// Temporary rate-change buttons
m_pButtonRateTempDown =
Expand Down

0 comments on commit ef04ed3

Please sign in to comment.