2014-05-18 15:52:39 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2016-03-04 17:51:03 +00:00
|
|
|
// Copyright (C) 2016 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// OpenGL interface modernization. //
|
|
|
|
// See: http://doc.qt.io/qt-5/qopenglshaderprogram.html //
|
2014-05-18 15:52:39 +00:00
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 12:43:33 +00:00
|
|
|
// (at your option) any later version. //
|
2014-05-18 15:52:39 +00:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef INCLUDE_GLSPECTRUM_H
|
|
|
|
#define INCLUDE_GLSPECTRUM_H
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMutex>
|
2016-03-02 02:09:50 +00:00
|
|
|
#include <QOpenGLBuffer>
|
|
|
|
#include <QOpenGLVertexArrayObject>
|
2016-03-02 21:50:05 +00:00
|
|
|
#include <QMatrix4x4>
|
2016-03-05 20:54:24 +00:00
|
|
|
#include <QGLWidget>
|
2020-04-28 16:44:03 +00:00
|
|
|
#include "dsp/glspectruminterface.h"
|
2014-05-18 15:52:39 +00:00
|
|
|
#include "gui/scaleengine.h"
|
2016-03-03 00:09:55 +00:00
|
|
|
#include "gui/glshadersimple.h"
|
2016-03-05 05:45:05 +00:00
|
|
|
#include "gui/glshadertextured.h"
|
2014-05-18 15:52:39 +00:00
|
|
|
#include "dsp/channelmarker.h"
|
2018-03-20 12:49:21 +00:00
|
|
|
#include "export.h"
|
2018-03-01 01:19:52 +00:00
|
|
|
#include "util/incrementalarray.h"
|
2018-07-01 18:48:30 +00:00
|
|
|
#include "util/message.h"
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2016-03-02 02:09:50 +00:00
|
|
|
class QOpenGLShaderProgram;
|
2018-07-01 18:48:30 +00:00
|
|
|
class MessageQueue;
|
2016-03-02 02:09:50 +00:00
|
|
|
|
2020-04-28 16:44:03 +00:00
|
|
|
class SDRGUI_API GLSpectrum : public QGLWidget, public GLSpectrumInterface {
|
2014-05-18 15:52:39 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-07-01 18:48:30 +00:00
|
|
|
class MsgReportSampleRate : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgReportSampleRate(quint32 sampleRate) :
|
|
|
|
Message(),
|
|
|
|
m_sampleRate(sampleRate)
|
2020-08-29 09:10:11 +00:00
|
|
|
{}
|
2018-07-01 18:48:30 +00:00
|
|
|
|
|
|
|
quint32 getSampleRate() const { return m_sampleRate; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
quint32 m_sampleRate;
|
|
|
|
};
|
|
|
|
|
2020-08-29 09:10:11 +00:00
|
|
|
class MsgReportWaterfallShare : public Message {
|
|
|
|
MESSAGE_CLASS_DECLARATION
|
|
|
|
|
|
|
|
public:
|
|
|
|
MsgReportWaterfallShare(Real waterfallShare) :
|
|
|
|
Message(),
|
|
|
|
m_waterfallShare(waterfallShare)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Real getWaterfallShare() const { return m_waterfallShare; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Real m_waterfallShare;
|
|
|
|
};
|
|
|
|
|
2020-04-28 16:44:03 +00:00
|
|
|
GLSpectrum(QWidget* parent = nullptr);
|
|
|
|
virtual ~GLSpectrum();
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2017-07-22 02:23:10 +00:00
|
|
|
void setCenterFrequency(qint64 frequency);
|
2014-05-18 15:52:39 +00:00
|
|
|
void setSampleRate(qint32 sampleRate);
|
2018-07-01 01:11:36 +00:00
|
|
|
void setTimingRate(qint32 timingRate);
|
2021-02-09 07:08:59 +00:00
|
|
|
void setFFTOverlap(int overlap);
|
2014-05-18 15:52:39 +00:00
|
|
|
void setReferenceLevel(Real referenceLevel);
|
|
|
|
void setPowerRange(Real powerRange);
|
|
|
|
void setDecay(int decay);
|
2018-10-18 22:40:14 +00:00
|
|
|
void setDecayDivisor(int decayDivisor);
|
2015-07-16 02:55:14 +00:00
|
|
|
void setHistoStroke(int stroke);
|
2014-05-18 15:52:39 +00:00
|
|
|
void setDisplayWaterfall(bool display);
|
2015-06-12 00:49:29 +00:00
|
|
|
void setSsbSpectrum(bool ssbSpectrum);
|
2017-07-22 02:23:10 +00:00
|
|
|
void setLsbDisplay(bool lsbDisplay);
|
2014-05-18 15:52:39 +00:00
|
|
|
void setInvertedWaterfall(bool inv);
|
|
|
|
void setDisplayMaxHold(bool display);
|
2015-07-16 02:55:14 +00:00
|
|
|
void setDisplayCurrent(bool display);
|
2014-05-18 15:52:39 +00:00
|
|
|
void setDisplayHistogram(bool display);
|
|
|
|
void setDisplayGrid(bool display);
|
2015-05-12 13:49:03 +00:00
|
|
|
void setDisplayGridIntensity(int intensity);
|
2015-07-18 15:53:57 +00:00
|
|
|
void setDisplayTraceIntensity(int intensity);
|
2018-07-05 23:34:05 +00:00
|
|
|
void setLinear(bool linear);
|
2018-07-01 18:48:30 +00:00
|
|
|
qint32 getSampleRate() const { return m_sampleRate; }
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
void addChannelMarker(ChannelMarker* channelMarker);
|
|
|
|
void removeChannelMarker(ChannelMarker* channelMarker);
|
2018-07-01 18:48:30 +00:00
|
|
|
void setMessageQueueToGUI(MessageQueue* messageQueue) { m_messageQueueToGUI = messageQueue; }
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2020-04-28 16:44:03 +00:00
|
|
|
virtual void newSpectrum(const std::vector<Real>& spectrum, int fftSize);
|
2015-07-23 23:09:03 +00:00
|
|
|
void clearSpectrumHistogram();
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2015-07-23 23:30:00 +00:00
|
|
|
Real getWaterfallShare() const { return m_waterfallShare; }
|
|
|
|
void setWaterfallShare(Real waterfallShare);
|
2015-08-01 01:33:07 +00:00
|
|
|
void connectTimer(const QTimer& timer);
|
2020-10-07 19:28:32 +00:00
|
|
|
void disconnectTimer();
|
2015-07-23 23:30:00 +00:00
|
|
|
|
2019-05-30 16:38:10 +00:00
|
|
|
void setDisplayedStream(bool sourceOrSink, int streamIndex)
|
|
|
|
{
|
|
|
|
m_displaySourceOrSink = sourceOrSink;
|
|
|
|
m_displayStreamIndex = streamIndex;
|
|
|
|
}
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
private:
|
|
|
|
struct ChannelMarkerState {
|
|
|
|
ChannelMarker* m_channelMarker;
|
2016-03-04 00:30:29 +00:00
|
|
|
QMatrix4x4 m_glMatrixWaterfall;
|
|
|
|
QMatrix4x4 m_glMatrixDsbWaterfall;
|
2016-03-04 01:24:08 +00:00
|
|
|
QMatrix4x4 m_glMatrixFreqScale;
|
2016-03-04 02:45:34 +00:00
|
|
|
QMatrix4x4 m_glMatrixDsbFreqScale;
|
|
|
|
QMatrix4x4 m_glMatrixHistogram;
|
|
|
|
QMatrix4x4 m_glMatrixDsbHistogram;
|
2014-05-18 15:52:39 +00:00
|
|
|
QRect m_rect;
|
|
|
|
|
|
|
|
ChannelMarkerState(ChannelMarker* channelMarker) :
|
2016-03-05 06:02:06 +00:00
|
|
|
m_channelMarker(channelMarker)
|
2014-05-18 15:52:39 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
QList<ChannelMarkerState*> m_channelMarkerStates;
|
|
|
|
|
|
|
|
enum CursorState {
|
|
|
|
CSNormal,
|
|
|
|
CSSplitter,
|
|
|
|
CSSplitterMoving,
|
|
|
|
CSChannel,
|
|
|
|
CSChannelMoving
|
|
|
|
};
|
2020-07-05 01:25:44 +00:00
|
|
|
struct HistogramMarker {
|
|
|
|
QPointF m_point;
|
|
|
|
float m_frequency;
|
|
|
|
float m_power;
|
|
|
|
QString m_frequencyStr;
|
|
|
|
QString m_powerStr;
|
|
|
|
QString m_deltaFrequencyStr;
|
|
|
|
QString m_deltaPowerStr;
|
|
|
|
HistogramMarker() :
|
|
|
|
m_point(0, 0),
|
|
|
|
m_frequency(0),
|
|
|
|
m_power(0),
|
|
|
|
m_frequencyStr(),
|
|
|
|
m_powerStr(),
|
|
|
|
m_deltaFrequencyStr(),
|
|
|
|
m_deltaPowerStr()
|
|
|
|
{}
|
|
|
|
HistogramMarker(
|
|
|
|
const QPointF& point,
|
|
|
|
float frequency,
|
|
|
|
float power,
|
|
|
|
const QString& frequencyStr,
|
|
|
|
const QString& powerStr,
|
|
|
|
const QString& deltaFrequencyStr,
|
|
|
|
const QString& deltaPowerStr
|
|
|
|
) :
|
|
|
|
m_point(point),
|
|
|
|
m_frequency(frequency),
|
|
|
|
m_power(power),
|
|
|
|
m_frequencyStr(frequencyStr),
|
|
|
|
m_powerStr(powerStr),
|
|
|
|
m_deltaFrequencyStr(deltaFrequencyStr),
|
|
|
|
m_deltaPowerStr(deltaPowerStr)
|
|
|
|
{}
|
|
|
|
HistogramMarker(const HistogramMarker& other) :
|
|
|
|
m_point(other.m_point),
|
|
|
|
m_frequency(other.m_frequency),
|
|
|
|
m_power(other.m_power),
|
|
|
|
m_frequencyStr(other.m_frequencyStr),
|
|
|
|
m_powerStr(other.m_powerStr),
|
|
|
|
m_deltaFrequencyStr(other.m_deltaFrequencyStr),
|
|
|
|
m_deltaPowerStr(other.m_deltaPowerStr)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
QList<HistogramMarker> m_histogramMarkers;
|
|
|
|
|
|
|
|
struct WaterfallMarker {
|
|
|
|
QPointF m_point;
|
|
|
|
float m_frequency;
|
|
|
|
float m_time;
|
|
|
|
QString m_frequencyStr;
|
|
|
|
QString m_timeStr;
|
|
|
|
QString m_deltaFrequencyStr;
|
|
|
|
QString m_deltaTimeStr;
|
|
|
|
WaterfallMarker() :
|
|
|
|
m_point(0, 0),
|
|
|
|
m_frequency(0),
|
|
|
|
m_time(0),
|
|
|
|
m_frequencyStr(),
|
|
|
|
m_timeStr(),
|
|
|
|
m_deltaFrequencyStr(),
|
|
|
|
m_deltaTimeStr()
|
|
|
|
{}
|
|
|
|
WaterfallMarker(
|
|
|
|
const QPointF& point,
|
|
|
|
float frequency,
|
|
|
|
float time,
|
|
|
|
const QString& frequencyStr,
|
|
|
|
const QString& timeStr,
|
|
|
|
const QString& deltaFrequencyStr,
|
|
|
|
const QString& deltaTimeStr
|
|
|
|
) :
|
|
|
|
m_point(point),
|
|
|
|
m_frequency(frequency),
|
|
|
|
m_time(time),
|
|
|
|
m_frequencyStr(frequencyStr),
|
|
|
|
m_timeStr(timeStr),
|
|
|
|
m_deltaFrequencyStr(deltaFrequencyStr),
|
|
|
|
m_deltaTimeStr(deltaTimeStr)
|
|
|
|
{}
|
|
|
|
WaterfallMarker(const WaterfallMarker& other) :
|
|
|
|
m_point(other.m_point),
|
|
|
|
m_frequency(other.m_frequency),
|
|
|
|
m_time(other.m_time),
|
|
|
|
m_frequencyStr(other.m_frequencyStr),
|
|
|
|
m_timeStr(other.m_timeStr),
|
|
|
|
m_deltaFrequencyStr(other.m_deltaFrequencyStr),
|
|
|
|
m_deltaTimeStr(other.m_deltaTimeStr)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
QList<WaterfallMarker> m_waterfallMarkers;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
CursorState m_cursorState;
|
|
|
|
int m_cursorChannel;
|
|
|
|
|
|
|
|
QTimer m_timer;
|
2020-10-07 19:28:32 +00:00
|
|
|
const QTimer *m_masterTimer;
|
2014-05-18 15:52:39 +00:00
|
|
|
QMutex m_mutex;
|
|
|
|
bool m_mouseInside;
|
|
|
|
bool m_changesPending;
|
|
|
|
|
|
|
|
qint64 m_centerFrequency;
|
|
|
|
Real m_referenceLevel;
|
|
|
|
Real m_powerRange;
|
2018-07-05 23:34:05 +00:00
|
|
|
bool m_linear;
|
2014-05-18 15:52:39 +00:00
|
|
|
int m_decay;
|
|
|
|
quint32 m_sampleRate;
|
2018-07-01 01:11:36 +00:00
|
|
|
quint32 m_timingRate;
|
2021-02-09 07:08:59 +00:00
|
|
|
int m_fftOverlap;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
int m_fftSize;
|
|
|
|
|
|
|
|
bool m_displayGrid;
|
2015-05-12 13:49:03 +00:00
|
|
|
int m_displayGridIntensity;
|
2015-07-18 15:53:57 +00:00
|
|
|
int m_displayTraceIntensity;
|
2014-05-18 15:52:39 +00:00
|
|
|
bool m_invertedWaterfall;
|
|
|
|
|
|
|
|
std::vector<Real> m_maxHold;
|
|
|
|
bool m_displayMaxHold;
|
2015-07-16 06:38:33 +00:00
|
|
|
const std::vector<Real> *m_currentSpectrum;
|
2015-07-16 02:55:14 +00:00
|
|
|
bool m_displayCurrent;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
Real m_waterfallShare;
|
|
|
|
|
2019-05-11 22:46:31 +00:00
|
|
|
int m_leftMargin;
|
2020-07-05 01:25:44 +00:00
|
|
|
int m_rightMargin;
|
|
|
|
int m_topMargin;
|
|
|
|
int m_frequencyScaleHeight;
|
|
|
|
int m_histogramHeight;
|
|
|
|
int m_waterfallHeight;
|
|
|
|
int m_bottomMargin;
|
|
|
|
QFont m_textOverlayFont;
|
2014-05-18 15:52:39 +00:00
|
|
|
QPixmap m_leftMarginPixmap;
|
2016-03-05 07:53:56 +00:00
|
|
|
QPixmap m_frequencyPixmap;
|
2014-05-18 15:52:39 +00:00
|
|
|
ScaleEngine m_timeScale;
|
|
|
|
ScaleEngine m_powerScale;
|
|
|
|
ScaleEngine m_frequencyScale;
|
2020-07-05 01:25:44 +00:00
|
|
|
QRectF m_histogramRect;
|
2014-05-18 15:52:39 +00:00
|
|
|
QRect m_frequencyScaleRect;
|
2020-07-05 01:25:44 +00:00
|
|
|
QRectF m_waterfallRect;
|
2016-03-03 18:56:54 +00:00
|
|
|
QMatrix4x4 m_glFrequencyScaleBoxMatrix;
|
|
|
|
QMatrix4x4 m_glLeftScaleBoxMatrix;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
QRgb m_waterfallPalette[240];
|
|
|
|
QImage* m_waterfallBuffer;
|
|
|
|
int m_waterfallBufferPos;
|
|
|
|
int m_waterfallTextureHeight;
|
|
|
|
int m_waterfallTexturePos;
|
2016-03-03 18:56:54 +00:00
|
|
|
QMatrix4x4 m_glWaterfallBoxMatrix;
|
2014-05-18 15:52:39 +00:00
|
|
|
bool m_displayWaterfall;
|
2015-06-12 00:49:29 +00:00
|
|
|
bool m_ssbSpectrum;
|
2017-07-22 02:23:10 +00:00
|
|
|
bool m_lsbDisplay;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
QRgb m_histogramPalette[240];
|
|
|
|
QImage* m_histogramBuffer;
|
2018-10-18 22:40:14 +00:00
|
|
|
quint8* m_histogram; //!< Spectrum phosphor matrix of FFT width and PSD height scaled to 100. values [0..239]
|
|
|
|
int m_decayDivisor;
|
|
|
|
int m_decayDivisorCount;
|
2015-07-15 06:48:02 +00:00
|
|
|
int m_histogramStroke;
|
2016-03-03 00:41:30 +00:00
|
|
|
QMatrix4x4 m_glHistogramSpectrumMatrix;
|
|
|
|
QMatrix4x4 m_glHistogramBoxMatrix;
|
2014-05-18 15:52:39 +00:00
|
|
|
bool m_displayHistogram;
|
|
|
|
bool m_displayChanged;
|
2019-05-30 16:38:10 +00:00
|
|
|
bool m_displaySourceOrSink;
|
|
|
|
int m_displayStreamIndex;
|
2014-05-18 15:52:39 +00:00
|
|
|
|
2016-03-03 18:56:54 +00:00
|
|
|
GLShaderSimple m_glShaderSimple;
|
2016-03-05 05:45:05 +00:00
|
|
|
GLShaderTextured m_glShaderLeftScale;
|
2016-03-05 07:53:56 +00:00
|
|
|
GLShaderTextured m_glShaderFrequencyScale;
|
2016-03-05 10:57:53 +00:00
|
|
|
GLShaderTextured m_glShaderWaterfall;
|
2016-03-05 13:28:55 +00:00
|
|
|
GLShaderTextured m_glShaderHistogram;
|
2020-07-05 01:25:44 +00:00
|
|
|
GLShaderTextured m_glShaderTextOverlay;
|
2016-03-02 02:09:50 +00:00
|
|
|
int m_matrixLoc;
|
|
|
|
int m_colorLoc;
|
2018-03-01 01:19:52 +00:00
|
|
|
IncrementalArray<GLfloat> m_q3TickTime;
|
|
|
|
IncrementalArray<GLfloat> m_q3TickFrequency;
|
|
|
|
IncrementalArray<GLfloat> m_q3TickPower;
|
|
|
|
IncrementalArray<GLfloat> m_q3FFT;
|
2016-03-02 02:09:50 +00:00
|
|
|
|
2018-07-01 18:48:30 +00:00
|
|
|
MessageQueue *m_messageQueueToGUI;
|
|
|
|
|
2016-03-05 10:57:53 +00:00
|
|
|
static const int m_waterfallBufferHeight = 256;
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
void updateWaterfall(const std::vector<Real>& spectrum);
|
|
|
|
void updateHistogram(const std::vector<Real>& spectrum);
|
|
|
|
|
|
|
|
void initializeGL();
|
|
|
|
void resizeGL(int width, int height);
|
|
|
|
void paintGL();
|
2020-07-06 02:08:08 +00:00
|
|
|
void drawMarkers();
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
void stopDrag();
|
|
|
|
void applyChanges();
|
|
|
|
|
|
|
|
void mouseMoveEvent(QMouseEvent* event);
|
|
|
|
void mousePressEvent(QMouseEvent* event);
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event);
|
2019-05-11 22:46:31 +00:00
|
|
|
void wheelEvent(QWheelEvent*);
|
2014-05-18 15:52:39 +00:00
|
|
|
|
|
|
|
void enterEvent(QEvent* event);
|
|
|
|
void leaveEvent(QEvent* event);
|
|
|
|
|
2020-07-05 01:25:44 +00:00
|
|
|
QString displayScaled(int64_t value, char type, int precision, bool showMult);
|
|
|
|
QString displayScaledF(float value, char type, int precision, bool showMult);
|
|
|
|
int getPrecision(int value);
|
|
|
|
void drawTextOverlay( //!< Draws a text overlay
|
|
|
|
const QString& text,
|
|
|
|
const QColor& color,
|
|
|
|
const QFont& font,
|
|
|
|
float shiftX,
|
|
|
|
float shiftY,
|
|
|
|
bool leftHalf,
|
|
|
|
bool topHalf,
|
|
|
|
const QRectF& glRect);
|
|
|
|
|
2014-05-18 15:52:39 +00:00
|
|
|
private slots:
|
2016-03-06 08:33:10 +00:00
|
|
|
void cleanup();
|
2014-05-18 15:52:39 +00:00
|
|
|
void tick();
|
|
|
|
void channelMarkerChanged();
|
|
|
|
void channelMarkerDestroyed(QObject* object);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDE_GLSPECTRUM_H
|