Skip to content

Commit

Permalink
force waveformwidgetfactory events from library tableview
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB committed Sep 25, 2023
1 parent c219553 commit 1527e90
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/dao/settingsdao.cpp
src/library/dao/trackdao.cpp
src/library/dao/trackschema.cpp
src/library/defaultdelegate.cpp
src/library/dlganalysis.cpp
src/library/dlganalysis.ui
src/library/dlgcoverartfullsize.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/library/basetracktablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "library/coverartcache.h"
#include "library/coverartdelegate.h"
#include "library/dao/trackschema.h"
#include "library/defaultdelegate.h"
#include "library/locationdelegate.h"
#include "library/multilineeditdelegate.h"
#include "library/previewbuttondelegate.h"
Expand Down Expand Up @@ -416,7 +417,7 @@ QAbstractItemDelegate* BaseTrackTableModel::delegateForColumn(
&BaseTrackTableModel::slotRefreshCoverRows);
return pCoverArtDelegate;
}
return nullptr;
return new DefaultDelegate(pTableView);
}

QVariant BaseTrackTableModel::data(
Expand Down
37 changes: 37 additions & 0 deletions src/library/defaultdelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "library/defaultdelegate.h"

#include <QCoreApplication>
#include <QPainter>

#include "mixxxapplication.h"
#include "moc_defaultdelegate.cpp"

DefaultDelegate::DefaultDelegate(QTableView* pTableView)
: QStyledItemDelegate(pTableView), m_pTableView(pTableView) {
}

void DefaultDelegate::paint(
QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const {
processTimeSensitiveEvents(painter);
QStyledItemDelegate::paint(painter, option, index);
}

void DefaultDelegate::processTimeSensitiveEvents(QPainter* painter) const {
// Drawing the table can be slow, resulting in time sensitive events not
// being delivered in time. (The WaveformWidgetFactory not receiving its
// render and swap signals in time). We force processing these events
// during the drawing of the table cells to fix this.
auto app = qobject_cast<MixxxApplication*>(QCoreApplication::instance());

Check warning on line 26 in src/library/defaultdelegate.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'auto app' can be declared as 'auto *app' [readability-qualified-auto]
if (app->hasTimeSensitiveEvents()) {

Check failure on line 27 in src/library/defaultdelegate.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (Qt 6.2, gcc)

‘class MixxxApplication’ has no member named ‘hasTimeSensitiveEvents’
QPaintDevice* device = painter->device();
if (device) {
painter->end();
}
app->processTimeSensitiveEvents();

Check failure on line 32 in src/library/defaultdelegate.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 (Qt 6.2, gcc)

‘class MixxxApplication’ has no member named ‘processTimeSensitiveEvents’
if (device) {
painter->begin(device);
}
}
}
22 changes: 22 additions & 0 deletions src/library/defaultdelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <QStyledItemDelegate>
#include <QTableView>

class DefaultDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit DefaultDelegate(
QTableView* pTableView);
~DefaultDelegate() override = default;

void paint(
QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const override;

protected:
void processTimeSensitiveEvents(QPainter* painter) const;

QTableView* m_pTableView;
};
6 changes: 4 additions & 2 deletions src/library/tableitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include <QPainter>
#include <QTableView>

#include "mixxxapplication.h"
#include "moc_tableitemdelegate.cpp"
#include "util/painterscope.h"
#include "widget/wtracktableview.h"

TableItemDelegate::TableItemDelegate(QTableView* pTableView)
: QStyledItemDelegate(pTableView),
m_pTableView(pTableView) {
: DefaultDelegate(pTableView) {
DEBUG_ASSERT(m_pTableView);
auto* pTrackTableView = qobject_cast<WTrackTableView*>(m_pTableView);
if (pTrackTableView) {
Expand All @@ -21,6 +21,8 @@ void TableItemDelegate::paint(
QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const {
processTimeSensitiveEvents(painter);

PainterScope painterScope(painter);
painter->setClipRect(option.rect);

Expand Down
6 changes: 3 additions & 3 deletions src/library/tableitemdelegate.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#pragma once

#include <QStyledItemDelegate>
#include <QTableView>

class TableItemDelegate : public QStyledItemDelegate {
#include "library/defaultdelegate.h"

class TableItemDelegate : public DefaultDelegate {
Q_OBJECT
public:
explicit TableItemDelegate(
Expand All @@ -29,5 +30,4 @@ class TableItemDelegate : public QStyledItemDelegate {
int columnWidth(const QModelIndex &index) const;

QColor m_pFocusBorderColor;
QTableView* m_pTableView;
};
9 changes: 9 additions & 0 deletions src/mixxxapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "util/color/rgbcolor.h"
#include "util/fileinfo.h"
#include "util/math.h"
#include "waveform/waveformwidgetfactory.h"

// When linking Qt statically, the Q_IMPORT_PLUGIN is needed for each linked plugin.
// https://doc.qt.io/qt-5/plugins-howto.html#details-of-linking-static-plugins
Expand Down Expand Up @@ -171,6 +172,14 @@ bool MixxxApplication::notify(QObject* target, QEvent* event) {
return QApplication::notify(target, event);
}

bool MixxxApplication::hasTimeSensitiveEvents() const {
return WaveformWidgetFactory::instance()->hasPendingTimeSensitiveEvents();
}

void MixxxApplication::processTimeSensitiveEvents() {
QCoreApplication::sendPostedEvents(WaveformWidgetFactory::instance());
}

bool MixxxApplication::touchIsRightButton() {
if (!m_pTouchShift) {
m_pTouchShift = new ControlProxy(
Expand Down
2 changes: 2 additions & 0 deletions src/mixxxapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class MixxxApplication : public QApplication {

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bool notify(QObject*, QEvent*) override;
bool hasTimeSensitiveEvents() const;
void processTimeSensitiveEvents();
#endif

private:
Expand Down
2 changes: 2 additions & 0 deletions src/waveform/vsyncthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void VSyncThread::run() {
usleep(1000);
} else { // if (m_vSyncMode == ST_TIMER) {
emit vsyncRender(); // renders the new waveform.
setHasPendingRender(true);

// wait until rendering was scheduled. It might be delayed due a
// pending swap (depends one driver vSync settings)
Expand All @@ -68,6 +69,7 @@ void VSyncThread::run() {

// swaps the new waveform to front in case of gl-wf
emit vsyncSwap();
setHasPendingSwap(true);

// wait until swap occurred. It might be delayed due to driver vSync
// settings.
Expand Down
15 changes: 15 additions & 0 deletions src/waveform/vsyncthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ class VSyncThread : public QThread {
int getSyncIntervalTimeMicros() const {
return m_syncIntervalTimeMicros;
}
bool hasPendingRender() const {
return m_hasPendingRender.load();
}
bool hasPendingSwap() const {
return m_hasPendingSwap.load();
}

void setHasPendingRender(bool value) {
m_hasPendingRender.store(value);
}
void setHasPendingSwap(bool value) {
m_hasPendingSwap.store(value);
}
signals:
void vsyncRender();
void vsyncSwap();
Expand All @@ -59,4 +72,6 @@ class VSyncThread : public QThread {
double m_displayFrameRate;
int m_vSyncPerRendering;
mixxx::Duration m_sinceLastSwap;
std::atomic<bool> m_hasPendingRender{};
std::atomic<bool> m_hasPendingSwap{};
};
6 changes: 6 additions & 0 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ void WaveformWidgetFactory::notifyZoomChange(WWaveformViewer* viewer) {
}

void WaveformWidgetFactory::render() {
m_vsyncThread->setHasPendingRender(false);
ScopedTimer t("WaveformWidgetFactory::render() %1waveforms",
static_cast<int>(m_waveformWidgetHolders.size()));

Expand Down Expand Up @@ -783,6 +784,7 @@ void WaveformWidgetFactory::render() {
}

void WaveformWidgetFactory::swap() {
m_vsyncThread->setHasPendingSwap(false);
ScopedTimer t("WaveformWidgetFactory::swap() %1waveforms",
static_cast<int>(m_waveformWidgetHolders.size()));

Expand Down Expand Up @@ -1224,3 +1226,7 @@ QSurfaceFormat WaveformWidgetFactory::getSurfaceFormat() {
#endif
return format;
}

bool WaveformWidgetFactory::hasPendingTimeSensitiveEvents() const {
return m_vsyncThread->hasPendingSwap() || m_vsyncThread->hasPendingRender();
}
1 change: 1 addition & 0 deletions src/waveform/waveformwidgetfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac

WaveformWidgetType::Type autoChooseWidgetType() const;

bool hasPendingTimeSensitiveEvents() const;
signals:
void waveformUpdateTick();
void waveformMeasured(float frameRate, int droppedFrames);
Expand Down

0 comments on commit 1527e90

Please sign in to comment.