Skip to content

Commit 26f9d32

Browse files
authored
Merge pull request mixxxdj#16503 from ronso0/sync-2.6-to-main
sync 2.6 to main
2 parents 54e5edc + b84e316 commit 26f9d32

9 files changed

Lines changed: 96 additions & 32 deletions

File tree

.gitignore

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@
1212
# Might be created when running a Python script from the tools folder
1313
__pycache__
1414

15+
# Ignore the patch files that our CI provides to fix pre-commit
16+
/pre-commit.patch
17+
1518
# Clang/cmake
1619
*_build
1720
compile_commands.json
1821

22+
# CMake build configurations, generated by tools/windows_buildenv.bat
23+
/CMakeSettings*.json
24+
25+
# List of discovery files, generated by CTest when running tests with CMake
26+
/cmake_test_discovery_*.json
27+
1928
# Doxygen documentation
2029
/doxygen
2130

2231
# Exclude buildenv directory from our helper scripts
2332
/buildenv
2433

25-
# CMake build configurations, generated by tools/windows_buildenv.bat
26-
/CMakeSettings*.json
27-
2834
# Build and distribution directories for various build configurations
2935
/build*
3036
/install

src/engine/controls/keycontrol.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
#include "control/controlpotmeter.h"
88
#include "control/controlproxy.h"
99
#include "control/controlpushbutton.h"
10+
#include "engine/defs_keylock.h"
1011
#include "engine/enginebuffer.h"
1112
#include "mixer/playermanager.h"
1213
#include "moc_keycontrol.cpp"
1314
#include "track/keyutils.h"
1415

1516
constexpr bool kEnableDebugOutput = false;
1617

17-
static const double kLockCurrentKey = 1;
18-
static const double kKeepUnlockedKey = 1;
19-
2018
KeyControl::KeyControl(const QString& group,
2119
UserSettingsPointer pConfig)
2220
: EngineControl(group, pConfig),
@@ -147,9 +145,9 @@ void KeyControl::slotRateChanged() {
147145
updateRate();
148146
}
149147

150-
// This is called when rate_ratio, vinylcontrol_rate, vinylcontrol_enabled or
151-
// keylock are changed, but also when EngineBuffer::processTrackLocked requests
152-
// m_pitchRateInfo struct while rate, pitch or pitch_adjust were just updated.
148+
/// This is called when rate_ratio, vinylcontrol_rate, vinylcontrol_enabled or
149+
/// keylock are changed, but also when EngineBuffer::processTrackLocked requests
150+
/// m_pitchRateInfo struct while rate, pitch or pitch_adjust were just updated.
153151
void KeyControl::updateRate() {
154152
if (m_pVCEnabled && m_pVCRate && m_pVCEnabled->toBool()) {
155153
m_pitchRateInfo.tempoRatio = m_pVCRate->get();
@@ -191,7 +189,9 @@ void KeyControl::updateRate() {
191189

192190
if (m_pKeylock->toBool()) {
193191
if (!m_pitchRateInfo.keylock) { // Enabling keylock
194-
if (m_keylockMode->get() == kLockCurrentKey) { // Lock at current pitch
192+
if (m_keylockMode->get() ==
193+
static_cast<double>(KeylockMode::LockCurrentKey)) {
194+
// Lock at current pitch
195195
speedSliderPitchRatio = m_pitchRateInfo.tempoRatio;
196196
if constexpr (kEnableDebugOutput) {
197197
qDebug() << " LOCKING current key";
@@ -223,7 +223,7 @@ void KeyControl::updateRate() {
223223
}
224224
} else { // !m_pKeylock
225225
if (m_pitchRateInfo.keylock) { // Disabling Keylock
226-
if (m_keyunlockMode->get() == kKeepUnlockedKey) {
226+
if (m_keyunlockMode->get() == static_cast<double>(KeyunlockMode::KeepLockedKey)) {
227227
// adopt speedSliderPitchRatio change as pitchTweakRatio
228228
m_pitchRateInfo.pitchTweakRatio *=
229229
(speedSliderPitchRatio / m_pitchRateInfo.tempoRatio);
@@ -299,6 +299,8 @@ void KeyControl::updateRate() {
299299
updateKeyCOs(dFileKey, pitchOctaves);
300300
}
301301

302+
/// This is called when the file key is changed (by analysis or user input),
303+
/// or when a track with a different key is loaded
302304
void KeyControl::slotFileKeyChanged(double value) {
303305
updateKeyCOs(value, m_pPitch->get() / 12);
304306
}
@@ -352,6 +354,9 @@ void KeyControl::setEngineKey(double key, double key_distance) {
352354
return;
353355
}
354356

357+
/// This is called when pitch is changed either by user interaction,
358+
/// or when BaseTrackPlayerImpl resets the pitch on track load per configuration
359+
/// AND key is locked with KeylockMode::LockCurrentKey
355360
void KeyControl::slotPitchChanged(double pitch) {
356361
Q_UNUSED(pitch)
357362
m_updatePitchRequest = 1;
@@ -391,6 +396,9 @@ void KeyControl::updatePitch() {
391396
}
392397
}
393398

399+
/// This is called when pitch_adjust is changed either by user interaction,
400+
/// or when BaseTrackPlayerImpl resets the pitch on track load per configuration
401+
/// AND key is unlocked or locked with LockOriginalKey
394402
void KeyControl::slotPitchAdjustChanged(double pitchAdjust) {
395403
Q_UNUSED(pitchAdjust);
396404
m_updatePitchAdjustRequest = 1;

src/engine/defs_keylock.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
enum class KeylockMode {
4+
LockOriginalKey,
5+
LockCurrentKey
6+
};
7+
8+
enum class KeyunlockMode {
9+
ResetLockedKey,
10+
KeepLockedKey
11+
};

src/mixer/basetrackplayer.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "control/controlobject.h"
99
#include "engine/channels/enginedeck.h"
1010
#include "engine/controls/enginecontrol.h"
11+
#include "engine/defs_keylock.h"
1112
#include "engine/engine.h"
1213
#include "engine/enginebuffer.h"
1314
#include "engine/enginemixer.h"
@@ -327,7 +328,10 @@ BaseTrackPlayerImpl::BaseTrackPlayerImpl(
327328
m_pPlay->connectValueChanged(this, &BaseTrackPlayerImpl::slotPlayToggled);
328329

329330
m_pRateRatio = make_parented<ControlProxy>(getGroup(), "rate_ratio", this);
331+
m_pPitch = make_parented<ControlProxy>(getGroup(), "pitch", this);
330332
m_pPitchAdjust = make_parented<ControlProxy>(getGroup(), "pitch_adjust", this);
333+
m_pKeylock = make_parented<ControlProxy>(getGroup(), "keylock", this);
334+
m_pKeylockMode = make_parented<ControlProxy>(getGroup(), "keylockMode", this);
331335

332336
m_pUpdateReplayGainFromPregain = std::make_unique<ControlPushButton>(
333337
ConfigKey(getGroup(), "update_replaygain_from_pregain"));
@@ -745,7 +749,7 @@ void BaseTrackPlayerImpl::slotTrackLoaded(TrackPointer pNewTrack,
745749
}
746750

747751
if (!m_pChannelToCloneFrom) {
748-
BaseTrackPlayer::TrackLoadReset reset = m_pConfig->getValue(
752+
TrackLoadReset reset = m_pConfig->getValue(
749753
ConfigKey("[Controls]", "SpeedAutoReset"), TrackLoadReset::RESET_PITCH);
750754
if (reset == TrackLoadReset::RESET_SPEED ||
751755
reset == TrackLoadReset::RESET_PITCH_AND_SPEED) {
@@ -757,7 +761,16 @@ void BaseTrackPlayerImpl::slotTrackLoaded(TrackPointer pNewTrack,
757761
}
758762
if (reset == TrackLoadReset::RESET_PITCH ||
759763
reset == TrackLoadReset::RESET_PITCH_AND_SPEED) {
760-
m_pPitchAdjust->set(0.0);
764+
// With KeylockMode::LockCurrentKey we need to reset `pitch`
765+
// instead of `pitch_adjust` to avoid a roundtrip in KeyControl
766+
// which would lead `pitch` != 0
767+
if (m_pKeylock->toBool() &&
768+
m_pKeylockMode->get() ==
769+
static_cast<double>(KeylockMode::LockCurrentKey)) {
770+
m_pPitch->set(0.0);
771+
} else {
772+
m_pPitchAdjust->set(0.0);
773+
}
761774
}
762775
} else {
763776
// perform a clone of the given channel

src/mixer/basetrackplayer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,8 @@ class BaseTrackPlayerImpl : public BaseTrackPlayer {
247247
parented_ptr<ControlProxy> m_pHighFilterKill;
248248
parented_ptr<ControlProxy> m_pPreGain;
249249
parented_ptr<ControlProxy> m_pRateRatio;
250+
parented_ptr<ControlProxy> m_pPitch;
250251
parented_ptr<ControlProxy> m_pPitchAdjust;
252+
parented_ptr<ControlProxy> m_pKeylock;
253+
parented_ptr<ControlProxy> m_pKeylockMode;
251254
};

src/preferences/dialog/dlgprefdeck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "engine/controls/cuecontrol.h"
66
#include "engine/controls/ratecontrol.h"
7+
#include "engine/defs_keylock.h"
78
#include "preferences/dialog/dlgpreferencepage.h"
89
#include "preferences/dialog/ui_dlgprefdeckdlg.h"
910
#include "preferences/interface.h"

src/preferences/interface.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ enum class DisplayFormat {
1717
};
1818
} // namespace TrackTime
1919

20-
enum class KeylockMode {
21-
LockOriginalKey,
22-
LockCurrentKey
23-
};
24-
25-
enum class KeyunlockMode {
26-
ResetLockedKey,
27-
KeepLockedKey
28-
};
29-
3020
enum class LoadWhenDeckPlaying {
3121
Reject,
3222
Allow,

src/qml/qmlconfigproxy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "engine/controls/cuecontrol.h"
88
#include "engine/controls/ratecontrol.h"
9+
#include "engine/defs_keylock.h"
910
#include "engine/sync/enginesync.h"
1011
#include "mixer/basetrackplayer.h"
1112
#include "preferences/constants.h"

src/test/enginebuffertest.cpp

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "control/controlobject.h"
1111
#include "engine/controls/ratecontrol.h"
12+
#include "engine/defs_keylock.h"
1213
#include "mixer/basetrackplayer.h"
1314
#include "preferences/usersettings.h"
1415
#include "test/mixxxtest.h"
@@ -31,9 +32,9 @@ TEST_F(EngineBufferTest, DisableKeylockResetsPitch) {
3132
// To prevent one-slider users from getting stuck on a key,
3233
// KeyunlockMode::ResetLockedKey resets the musical pitch.
3334
ControlObject::set(ConfigKey(m_sGroup1, "keylockMode"),
34-
1.0); // KeylockMode::LockCurrentKey
35+
static_cast<double>(KeylockMode::LockCurrentKey));
3536
ControlObject::set(ConfigKey(m_sGroup1, "keyunlockMode"),
36-
0.0); // KeyunlockMode::ResetLockedKey
37+
static_cast<double>(KeyunlockMode::ResetLockedKey));
3738
ControlObject::set(ConfigKey(m_sGroup1, "file_bpm"), 128.0);
3839
ControlObject::set(ConfigKey(m_sGroup1, "keylock"), 1.0);
3940
ControlObject::set(ConfigKey(m_sGroup1, "pitch"), 0.5);
@@ -48,9 +49,9 @@ TEST_F(EngineBufferTest, DisableKeylockResetsPitch) {
4849
TEST_F(EngineBufferTest, DisableKeylockKeepsPitch) {
4950
// Pitch must not change when unlocking with KeyunlockMode::KeepLockedKey.
5051
ControlObject::set(ConfigKey(m_sGroup1, "keylockMode"),
51-
1.0); // KeylockMode::LockCurrentKey
52+
static_cast<double>(KeylockMode::LockCurrentKey));
5253
ControlObject::set(ConfigKey(m_sGroup1, "keyunlockMode"),
53-
1.0); // KeyunlockMode::KeepLockedKey
54+
static_cast<double>(KeyunlockMode::KeepLockedKey));
5455
ControlObject::set(ConfigKey(m_sGroup1, "file_bpm"), 128.0);
5556
ControlObject::set(ConfigKey(m_sGroup1, "keylock"), 1.0);
5657
ControlObject::set(ConfigKey(m_sGroup1, "pitch"), 0.5);
@@ -75,12 +76,42 @@ TEST_F(EngineBufferTest, TrackLoadResetsPitch) {
7576
ASSERT_NEAR(0.0, ControlObject::get(ConfigKey(m_sGroup1, "pitch_adjust")), 1e-10);
7677
}
7778

79+
TEST_F(EngineBufferTest, TrackLoadResetsPitch_LockCurrentKey) {
80+
// The pitch should be reset to 0 when a new track was loaded when
81+
// * rate is not 0
82+
// * keylock is ON
83+
// * keylock mode is LockCurrentKey,
84+
// * Reset Pitch on track load option is enabled
85+
//
86+
// First test case:
87+
// * change tempo with key unlocked -> pitch changes
88+
// * lock key
89+
// // * reset pitch -> is now 0 OPTIONAL
90+
// * load another track -> pitch should (still) be 0
91+
config()->setValue(ConfigKey("[Controls]", "SpeedAutoReset"),
92+
BaseTrackPlayer::TrackLoadReset::RESET_PITCH);
93+
ControlObject::set(ConfigKey(m_sGroup1, "keylockMode"),
94+
static_cast<double>(KeylockMode::LockCurrentKey));
95+
ControlObject::set(ConfigKey(m_sGroup1, "rate"), 0.5);
96+
ControlObject::set(ConfigKey(m_sGroup1, "keylock"), 1.0);
97+
ControlObject::set(ConfigKey(m_sGroup1, "reset_key"), 1.0);
98+
ProcessBuffer();
99+
// Note that pitch_adjust is NOT reset to 0 with KeylockMode::LockCurrentKey
100+
ASSERT_DOUBLE_EQ(0.0, ControlObject::get(ConfigKey(m_sGroup1, "pitch")));
101+
ProcessBuffer();
102+
103+
m_pMixerDeck1->loadFakeTrack(false, 0.0);
104+
ProcessBuffer();
105+
106+
ASSERT_DOUBLE_EQ(0.0, ControlObject::get(ConfigKey(m_sGroup1, "pitch")));
107+
}
108+
78109
TEST_F(EngineBufferTest, PitchRoundtrip) {
79110
ControlObject::set(ConfigKey(m_sGroup1, "keylock"), 0.0);
80111
ControlObject::set(ConfigKey(m_sGroup1, "keylockMode"),
81-
0.0); // KeylockMode::LockOriginalKey
112+
static_cast<double>(KeylockMode::LockOriginalKey));
82113
ControlObject::set(ConfigKey(m_sGroup1, "keyunlockMode"),
83-
0.0); // KeyunlockMode::ResetLockedKey
114+
static_cast<double>(KeyunlockMode::ResetLockedKey));
84115
ProcessBuffer();
85116
// we are in kPakmOffsetScaleReseting mode
86117
ControlObject::set(ConfigKey(m_sGroup1, "rate"), 0.5);
@@ -103,15 +134,15 @@ TEST_F(EngineBufferTest, PitchRoundtrip) {
103134
ASSERT_DOUBLE_EQ(0.0, ControlObject::get(ConfigKey(m_sGroup1, "pitch_adjust")));
104135

105136
ControlObject::set(ConfigKey(m_sGroup1, "keylockMode"),
106-
1.0); // KeylockMode::LockCurrentKey
137+
static_cast<double>(KeylockMode::LockCurrentKey));
107138
ProcessBuffer();
108139
// rate must not change
109140
ASSERT_DOUBLE_EQ(0.5, ControlObject::get(ConfigKey(m_sGroup1, "rate")));
110141
// pitch must reflect the absolute pitch
111142
ASSERT_DOUBLE_EQ(0.0, ControlObject::get(ConfigKey(m_sGroup1, "pitch")));
112143

113144
ControlObject::set(ConfigKey(m_sGroup1, "keylockMode"),
114-
0.0); // KeylockMode::LockOriginalKey
145+
static_cast<double>(KeylockMode::LockOriginalKey));
115146
ProcessBuffer();
116147
// rate must not change
117148
ASSERT_DOUBLE_EQ(0.5, ControlObject::get(ConfigKey(m_sGroup1, "rate")));
@@ -370,7 +401,7 @@ TEST_F(EngineBufferE2ETest, DISABLED_KeylockReverseTest) {
370401
ControlObject::set(ConfigKey(kAppGroup, QStringLiteral("keylock_engine")),
371402
static_cast<double>(EngineBuffer::KeylockEngine::SoundTouch));
372403
ControlObject::set(ConfigKey(m_sGroup1, "keylockMode"),
373-
0.0);
404+
static_cast<double>(KeylockMode::LockOriginalKey));
374405
ControlObject::set(ConfigKey(m_sGroup1, "rate"), 0.5);
375406
ControlObject::set(ConfigKey(m_sGroup1, "play"), 1.0);
376407
ControlObject::set(ConfigKey(m_sGroup1, "keylock"), 1.0);

0 commit comments

Comments
 (0)