Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove potentially long runnig while loops from the engine (lp:1943320) #4312

Merged
merged 5 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/engine/controls/loopingcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
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);
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/engine/enginemaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.);
Expand Down
3 changes: 1 addition & 2 deletions src/engine/sync/basesyncablelistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions src/engine/sync/internalclock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down