summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2021-09-24 11:44:17 +0200
committerGitHub <noreply@github.com>2021-09-24 11:44:17 +0200
commit93841fd8fbe8a5c78a06c6275b5f304df86a07f0 (patch)
tree4ea6651384c0d3176379b8e6dd59bd03d6725867
parent77fafc5dfd8ac6185d53f939fbdee1d8c00159d7 (diff)
parent1931eb8db8706bf8155e09eb0d14a27b4f800950 (diff)
Merge pull request #4312 from daschuer/lp1943320
Remove potentially long runnig while loops from the engine (lp:1943320)
-rw-r--r--src/engine/controls/loopingcontrol.cpp19
-rw-r--r--src/engine/enginemaster.cpp2
-rw-r--r--src/engine/sync/basesyncablelistener.cpp3
-rw-r--r--src/engine/sync/internalclock.cpp6
4 files changed, 16 insertions, 14 deletions
diff --git a/src/engine/controls/loopingcontrol.cpp b/src/engine/controls/loopingcontrol.cpp
index 77010bcfff..e055c0257c 100644
--- a/src/engine/controls/loopingcontrol.cpp
+++ b/src/engine/controls/loopingcontrol.cpp
@@ -1277,24 +1277,29 @@ double LoopingControl::seekInsideAdjustedLoop(
double new_loop_size = new_loop_out - new_loop_in;
DEBUG_ASSERT(new_loop_size > 0);
double adjusted_position = currentSample;
- while (adjusted_position > new_loop_out) {
- adjusted_position -= new_loop_size;
+ if (adjusted_position > new_loop_out) {
+ // In case play head has already passed the new out position, seek in whole
+ // loop size steps back, as if playback has been looped within the boundaries
+ double adjust_steps = ceil((adjusted_position - new_loop_out) / new_loop_size);
+ adjusted_position -= adjust_steps * new_loop_size;
+ DEBUG_ASSERT(adjusted_position <= new_loop_out);
VERIFY_OR_DEBUG_ASSERT(adjusted_position > new_loop_in) {
// I'm not even sure this is possible. The new loop would have to be bigger than the
// old loop, and the playhead was somehow outside the old loop.
qWarning() << "SHOULDN'T HAPPEN: seekInsideAdjustedLoop couldn't find a new position --"
<< " seeking to in point";
adjusted_position = new_loop_in;
- break;
}
- }
- while (adjusted_position < new_loop_in) {
- adjusted_position += new_loop_size;
+ } else if (adjusted_position < new_loop_in) {
+ // In case play head has already been looped back to the old loop in position,
+ // seek in whole loop size steps forward until we are in the new loop boundaries
+ double adjust_steps = ceil((new_loop_in - adjusted_position) / new_loop_size);
+ adjusted_position += adjust_steps * new_loop_size;
+ DEBUG_ASSERT(adjusted_position >= new_loop_in);
VERIFY_OR_DEBUG_ASSERT(adjusted_position < new_loop_out) {
qWarning() << "SHOULDN'T HAPPEN: seekInsideAdjustedLoop couldn't find a new position --"
<< " seeking to in point";
adjusted_position = new_loop_in;
- break;
}
}
if (adjusted_position != currentSample) {
diff --git a/src/engine/enginemaster.cpp b/src/engine/enginemaster.cpp
index 33cd29d5e4..3ec2d7afd0 100644
--- a/src/engine/enginemaster.cpp
+++ b/src/engine/enginemaster.cpp
@@ -83,7 +83,7 @@ EngineMaster::EngineMaster(
// The last-used bpm value is saved in the destructor of EngineSync.
double default_bpm = pConfig->getValue(
ConfigKey("[InternalClock]", "bpm"), 124.0);
- ControlObject::getControl(ConfigKey("[InternalClock]","bpm"))->set(default_bpm);
+ ControlObject::set(ConfigKey("[InternalClock]", "bpm"), default_bpm);
// Crossfader
m_pCrossfader = new ControlPotmeter(ConfigKey(group, "crossfader"), -1., 1.);
diff --git a/src/engine/sync/basesyncablelistener.cpp b/src/engine/sync/basesyncablelistener.cpp
index e2c309c6bc..f8bc458faf 100644
--- a/src/engine/sync/basesyncablelistener.cpp
+++ b/src/engine/sync/basesyncablelistener.cpp
@@ -20,8 +20,7 @@ BaseSyncableListener::BaseSyncableListener(UserSettingsPointer pConfig)
BaseSyncableListener::~BaseSyncableListener() {
// We use the slider value because that is never set to 0.0.
- m_pConfig->set(ConfigKey("[InternalClock]", "bpm"), ConfigValue(
- m_pInternalClock->getBpm()));
+ m_pConfig->setValue(ConfigKey(kInternalClockGroup, "bpm"), m_pInternalClock->getBpm());
delete m_pInternalClock;
}
diff --git a/src/engine/sync/internalclock.cpp b/src/engine/sync/internalclock.cpp
index a0b15a9a8c..212764ae31 100644
--- a/src/engine/sync/internalclock.cpp
+++ b/src/engine/sync/internalclock.cpp
@@ -9,6 +9,7 @@
#include "moc_internalclock.cpp"
#include "preferences/usersettings.h"
#include "util/logger.h"
+#include "util/math.h"
namespace {
const mixxx::Logger kLogger("InternalClock");
@@ -219,10 +220,7 @@ void InternalClock::onCallbackEnd(int sampleRate, int bufferSize) {
m_dBeatLength = 21338;
}
- while (m_dClockPosition >= m_dBeatLength) {
- m_dClockPosition -= m_dBeatLength;
- }
-
+ m_dClockPosition = fmod(m_dClockPosition, m_dBeatLength);
double beat_distance = getBeatDistance();
m_pClockBeatDistance->set(beat_distance);
m_pEngineSync->notifyBeatDistanceChanged(this, beat_distance);