possible fix for #691

This commit is contained in:
itsmattkc
2019-04-05 04:40:45 +11:00
parent ce725ae32a
commit 6e9a8e7613
2 changed files with 18 additions and 2 deletions
+10 -2
View File
@@ -46,9 +46,13 @@ AudioMonitor::AudioMonitor(QWidget *parent) :
}
void AudioMonitor::set_value(const QVector<double> &ivalues) {
values = ivalues;
update();
qDebug() << "am set";
value_lock.lock();
values = ivalues;
value_lock.unlock();
QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection);
QMetaObject::invokeMethod(&clear_timer, "start", Qt::QueuedConnection);
}
@@ -68,7 +72,10 @@ void AudioMonitor::resizeEvent(QResizeEvent *e) {
}
void AudioMonitor::paintEvent(QPaintEvent *) {
value_lock.lock();
qDebug() << "am paint";
if (values.size() > 0) {
qDebug() << "am paint 2";
QPainter p(this);
int channel_x = AUDIO_MONITOR_GAP;
int channel_count = values.size();
@@ -95,4 +102,5 @@ void AudioMonitor::paintEvent(QPaintEvent *) {
channel_x += channel_width + AUDIO_MONITOR_GAP;
}
}
value_lock.unlock();
}
+8
View File
@@ -23,6 +23,7 @@
#include <QWidget>
#include <QTimer>
#include <QMutex>
/**
* @brief The AudioMonitor class
@@ -84,6 +85,13 @@ private:
*/
QVector<double> values;
/**
* @brief Value mutex
*
* Audio is often processed and sent to this object from other threads. To keep them synchronized, we lock them here.
*/
QMutex value_lock;
/**
* @brief Internal timer to clear the audio monitor after a certain amount of time
*