diff --git a/ui/audiomonitor.cpp b/ui/audiomonitor.cpp index d69277587..f5f2ba02e 100644 --- a/ui/audiomonitor.cpp +++ b/ui/audiomonitor.cpp @@ -46,9 +46,13 @@ AudioMonitor::AudioMonitor(QWidget *parent) : } void AudioMonitor::set_value(const QVector &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(); } diff --git a/ui/audiomonitor.h b/ui/audiomonitor.h index 8ce9da55f..70898ce60 100644 --- a/ui/audiomonitor.h +++ b/ui/audiomonitor.h @@ -23,6 +23,7 @@ #include #include +#include /** * @brief The AudioMonitor class @@ -84,6 +85,13 @@ private: */ QVector 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 *