Skip to content

Commit

Permalink
ControlIndicatorTimer: Add support for legacy vsyncthread mode
Browse files Browse the repository at this point in the history
Due to concerns that a regular QTimer that fires during vsync could
cause jerking legacy waveforms, this implements a way to use the
legacy vsync thread/GuiTick infrastructure instead of a `QTimer` in the
`ControlIndicatorTimer` (although I'm still not convinced that
this actually makes a difference).

This can be toggled explicitly using `setLegacyVsyncEnabled` when
switching between a legacy and a QML skin (the latter has no vsync
thread, so a regular timer needs to be used).

Relevant discussion can be found here:
#4157 (comment)
  • Loading branch information
Holzhaus committed Jul 29, 2021
1 parent 02fc274 commit fb86a27
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
38 changes: 37 additions & 1 deletion src/control/controlindicatortimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "control/controlobject.h"
#include "moc_controlindicatortimer.cpp"
#include "util/math.h"

namespace mixxx {

Expand All @@ -11,7 +12,9 @@ ControlIndicatorTimer::ControlIndicatorTimer(QObject* pParent)
ConfigKey("[Master]", "indicator_250millis"))),
m_pCOIndicator500millis(std::make_unique<ControlObject>(
ConfigKey("[Master]", "indicator_500millis"))),
m_toggleIndicator500millisOnNextTimeout(true) {
m_toggleIndicator500millisOnNextTimeout(true),
m_nextSwitchTime(0.0),
m_pCPGuiTick50ms(nullptr) {
m_pCOIndicator250millis->setReadOnly();
m_pCOIndicator500millis->setReadOnly();
connect(&m_timer, &QTimer::timeout, this, &ControlIndicatorTimer::slotTimeout);
Expand All @@ -29,4 +32,37 @@ void ControlIndicatorTimer::slotTimeout() {
m_toggleIndicator500millisOnNextTimeout = !m_toggleIndicator500millisOnNextTimeout;
}

// TODO: Everything below this comment only added for compatiblity with the
// legacy waveform vsync thread. It should be removed when the legacy skin
// system is dropped.

void ControlIndicatorTimer::setLegacyVsyncEnabled(bool enabled) {
const bool isLegacyVsyncEnabled = (m_pCPGuiTick50ms != nullptr);
if (isLegacyVsyncEnabled == enabled) {
return;
}

if (enabled) {
m_timer.stop();
m_pCPGuiTick50ms = std::make_unique<ControlProxy>(ConfigKey("[Master]", "guiTick50ms"));
m_pCPGuiTick50ms->connectValueChanged(this, &ControlIndicatorTimer::slotGuiTick50ms);
} else {
m_pCPGuiTick50ms->disconnect(this);
m_pCPGuiTick50ms.reset();
m_timer.start(250);
}
}

void ControlIndicatorTimer::slotGuiTick50ms(double cpuTime) {
if (m_nextSwitchTime > cpuTime) {
return;
}

constexpr double duration = 0.25;
const double tickTime = ControlObject::get(ConfigKey("[Master]", "guiTickTime"));
const double toggles = floor(tickTime / duration);
m_nextSwitchTime = (toggles + 1) * duration;
slotTimeout();
}

} // namespace mixxx
14 changes: 14 additions & 0 deletions src/control/controlindicatortimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <memory>

#include "control/controlobject.h"
#include "control/controlproxy.h"

namespace mixxx {

Expand All @@ -28,6 +29,19 @@ class ControlIndicatorTimer : public QObject {
std::unique_ptr<ControlObject> m_pCOIndicator250millis;
std::unique_ptr<ControlObject> m_pCOIndicator500millis;
bool m_toggleIndicator500millisOnNextTimeout;

/// TODO: Everything below this comment only added for compatiblity with the
/// legacy waveform vsync thread. It should be removed when the legacy skin
/// system is dropped.
public:
void setLegacyVsyncEnabled(bool enabled);

private slots:
void slotGuiTick50ms(double cpuTime);

private:
double m_nextSwitchTime;
std::unique_ptr<ControlProxy> m_pCPGuiTick50ms;
};

} // namespace mixxx
2 changes: 1 addition & 1 deletion src/coreservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void CoreServices::initialize(QApplication* pApp) {
exit(-1);
}

m_pControlIndicatorTimer = std::make_unique<mixxx::ControlIndicatorTimer>(this);
m_pControlIndicatorTimer = std::make_shared<mixxx::ControlIndicatorTimer>(this);

auto pChannelHandleFactory = std::make_shared<ChannelHandleFactory>();

Expand Down
6 changes: 5 additions & 1 deletion src/coreservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class CoreServices : public QObject {
return m_pKbdConfig;
}

std::shared_ptr<mixxx::ControlIndicatorTimer> getControlIndicatorTimer() const {
return m_pControlIndicatorTimer;
}

std::shared_ptr<SoundManager> getSoundManager() const {
return m_pSoundManager;
}
Expand Down Expand Up @@ -119,7 +123,7 @@ class CoreServices : public QObject {
bool initializeDatabase();

std::shared_ptr<SettingsManager> m_pSettingsManager;
std::unique_ptr<mixxx::ControlIndicatorTimer> m_pControlIndicatorTimer;
std::shared_ptr<mixxx::ControlIndicatorTimer> m_pControlIndicatorTimer;
std::shared_ptr<EffectsManager> m_pEffectsManager;
// owned by EffectsManager
LV2Backend* m_pLV2Backend;
Expand Down
5 changes: 5 additions & 0 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#ifdef __BROADCAST__
#include "broadcast/broadcastmanager.h"
#endif
#include "control/controlindicatortimer.h"
#include "control/controlpushbutton.h"
#include "controllers/controllermanager.h"
#include "controllers/keyboard/keyboardeventfilter.h"
Expand Down Expand Up @@ -132,6 +133,8 @@ MixxxMainWindow::MixxxMainWindow(

m_pCoreServices->initialize(pApp);

m_pCoreServices->getControlIndicatorTimer()->setLegacyVsyncEnabled(true);

UserSettingsPointer pConfig = m_pCoreServices->getSettings();

// Set the visibility of tooltips, default "1" = ON
Expand Down Expand Up @@ -426,6 +429,8 @@ MixxxMainWindow::~MixxxMainWindow() {
qDebug() << t.elapsed(false).debugMillisWithUnit() << "deleting DlgPreferences";
delete m_pPrefDlg;

m_pCoreServices->getControlIndicatorTimer()->setLegacyVsyncEnabled(false);

WaveformWidgetFactory::destroy();

delete m_pGuiTick;
Expand Down

0 comments on commit fb86a27

Please sign in to comment.