const QColor dark(40, 40, 39, 255);
const QColor dark2(25, 25, 23, 255);
-const QPen AbstractScopeWidget::penThick(QBrush(QColor(250, 250, 250)), 2, Qt::SolidLine);
-const QPen AbstractScopeWidget::penThin(QBrush(QColor(250, 250, 250)), 1, Qt::SolidLine);
-const QPen AbstractScopeWidget::penLight(QBrush(QColor(200, 200, 250, 150)), 1, Qt::SolidLine);
+const QPen AbstractScopeWidget::penThick(QBrush(QColor(250, 250, 250)), 2, Qt::SolidLine);
+const QPen AbstractScopeWidget::penThin(QBrush(QColor(250, 250, 250)), 1, Qt::SolidLine);
+const QPen AbstractScopeWidget::penLight(QBrush(QColor(200, 200, 250, 150)), 1, Qt::SolidLine);
const QPen AbstractScopeWidget::penLightDots(QBrush(QColor(200, 200, 250, 150)), 1, Qt::DotLine);
-const QPen AbstractScopeWidget::penDark(QBrush(QColor(0, 0, 20, 250)), 1, Qt::SolidLine);
-const QPen AbstractScopeWidget::penDarkDots(QBrush(QColor(0, 0, 20, 250)), 1, Qt::DotLine);
+const QPen AbstractScopeWidget::penLighter(QBrush(QColor(225, 225, 250, 225)), 1, Qt::SolidLine);
+const QPen AbstractScopeWidget::penDark(QBrush(QColor(0, 0, 20, 250)), 1, Qt::SolidLine);
+const QPen AbstractScopeWidget::penDarkDots(QBrush(QColor(0, 0, 20, 250)), 1, Qt::DotLine);
const QString AbstractScopeWidget::directions[] = {"North", "Northeast", "East", "Southeast"};
m_newBackgroundFrames.fetchAndAddRelaxed(1);
#ifdef DEBUG_ASW
- qDebug() << "Monitor incoming at " << widgetName() << ". New frames total HUD/Scope/Background: " << m_newHUDFrames
+ qDebug() << "Data incoming at " << widgetName() << ". New frames total HUD/Scope/Background: " << m_newHUDFrames
<< "/" << m_newScopeFrames << "/" << m_newBackgroundFrames;
#endif
Q_OBJECT
public:
+ /** trackMouse enables mouse tracking; The variables m_mousePos and m_mouseWithinWidget will be set
+ if mouse tracking is enabled. See also signalMousePositionChanged(). */
AbstractScopeWidget(bool trackMouse = false, QWidget *parent = 0);
virtual ~AbstractScopeWidget(); // Must be virtual because of inheritance, to avoid memory leaks
static const QPen penThin;
static const QPen penLight;
static const QPen penLightDots;
+ static const QPen penLighter;
static const QPen penDark;
static const QPen penDarkDots;
void signalBackgroundRenderingFinished(uint mseconds, uint accelerationFactor);
/** For the mouse position itself see m_mousePos.
- To check whether the mouse has leaved the widget, see m_mouseWithinWidget. */
+ To check whether the mouse has leaved the widget, see m_mouseWithinWidget.
+ This signal is typically connected to forceUpdateHUD(). */
void signalMousePositionChanged();
/** Do we need the renderer to send its frames to us? */
#include <QMouseEvent>
#include <QPainter>
+// Uncomment for debugging
+//#define DEBUG_AASW
+
+#ifdef DEBUG_AASW
+#include <QDebug>
+#endif
+
AbstractAudioScopeWidget::AbstractAudioScopeWidget(bool trackMouse, QWidget *parent) :
AbstractScopeWidget(trackMouse, parent),
m_audioFrame(),
m_freq(0),
m_nChannels(0),
- m_nSamples(0)
+ m_nSamples(0),
+ m_newData(0)
{
}
-void AbstractAudioScopeWidget::slotReceiveAudio(const QVector<int16_t>& sampleData, int freq, int num_channels, int num_samples)
+void AbstractAudioScopeWidget::slotReceiveAudio(const QVector<int16_t> &sampleData, int freq, int num_channels, int num_samples)
{
+#ifdef DEBUG_AASW
+ qDebug() << "Received audio for " << widgetName() << ".";
+#endif
m_audioFrame = sampleData;
m_freq = freq;
m_nChannels = num_channels;
m_nSamples = num_samples;
+
+ m_newData.fetchAndAddAcquire(1);
+
AbstractScopeWidget::slotRenderZoneUpdated();
}
QImage AbstractAudioScopeWidget::renderScope(uint accelerationFactor)
{
- return renderAudioScope(accelerationFactor, m_audioFrame, m_freq, m_nChannels, m_nSamples);
+ int newData = m_newData.fetchAndStoreAcquire(0);
+
+ return renderAudioScope(accelerationFactor, m_audioFrame, m_freq, m_nChannels, m_nSamples, newData);
}
+
+#ifdef DEBUG_AASW
+#undef DEBUG_AASW
+#endif
when calculation has finished, to allow multi-threading.
accelerationFactor hints how much faster than usual the calculation should be accomplished, if possible. */
virtual QImage renderAudioScope(uint accelerationFactor,
- const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples) = 0;
+ const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples,
+ const int newData) = 0;
private:
QVector<int16_t> m_audioFrame;
int m_freq;
int m_nChannels;
int m_nSamples;
+ QAtomicInt m_newData;
private slots:
void slotReceiveAudio(const QVector<int16_t>& sampleData, int freq, int num_channels, int num_samples);