SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
glspectrum.h
Go to the documentation of this file.
1 // Copyright (C) 2016 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // OpenGL interface modernization. //
6 // See: http://doc.qt.io/qt-5/qopenglshaderprogram.html //
7 // //
8 // This program is free software; you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation as version 3 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // This program is distributed in the hope that it will be useful, //
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
16 // GNU General Public License V3 for more details. //
17 // //
18 // You should have received a copy of the GNU General Public License //
19 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
21 
22 #ifndef INCLUDE_GLSPECTRUM_H
23 #define INCLUDE_GLSPECTRUM_H
24 
25 #include <QTimer>
26 #include <QMutex>
27 #include <QOpenGLBuffer>
28 #include <QOpenGLVertexArrayObject>
29 #include <QMatrix4x4>
30 #include <QGLWidget>
31 #include "dsp/dsptypes.h"
32 #include "gui/scaleengine.h"
33 #include "gui/glshadersimple.h"
34 #include "gui/glshadertextured.h"
35 #include "dsp/channelmarker.h"
36 #include "export.h"
37 #include "util/incrementalarray.h"
38 #include "util/message.h"
39 
40 class QOpenGLShaderProgram;
41 class MessageQueue;
42 
43 class SDRGUI_API GLSpectrum : public QGLWidget {
44  Q_OBJECT
45 
46 public:
47  class MsgReportSampleRate : public Message {
49 
50  public:
51  MsgReportSampleRate(quint32 sampleRate) :
52  Message(),
53  m_sampleRate(sampleRate)
54  {
55  m_sampleRate = sampleRate;
56  }
57 
58  quint32 getSampleRate() const { return m_sampleRate; }
59 
60  private:
61  quint32 m_sampleRate;
62  };
63 
64  GLSpectrum(QWidget* parent = NULL);
65  ~GLSpectrum();
66 
67  void setCenterFrequency(qint64 frequency);
68  void setSampleRate(qint32 sampleRate);
69  void setTimingRate(qint32 timingRate);
70  void setReferenceLevel(Real referenceLevel);
71  void setPowerRange(Real powerRange);
72  void setDecay(int decay);
73  void setDecayDivisor(int decayDivisor);
74  void setHistoStroke(int stroke);
75  void setDisplayWaterfall(bool display);
76  void setSsbSpectrum(bool ssbSpectrum);
77  void setLsbDisplay(bool lsbDisplay);
78  void setInvertedWaterfall(bool inv);
79  void setDisplayMaxHold(bool display);
80  void setDisplayCurrent(bool display);
81  void setDisplayHistogram(bool display);
82  void setDisplayGrid(bool display);
83  void setDisplayGridIntensity(int intensity);
84  void setDisplayTraceIntensity(int intensity);
85  void setLinear(bool linear);
86  qint32 getSampleRate() const { return m_sampleRate; }
87 
88  void addChannelMarker(ChannelMarker* channelMarker);
89  void removeChannelMarker(ChannelMarker* channelMarker);
90  void setMessageQueueToGUI(MessageQueue* messageQueue) { m_messageQueueToGUI = messageQueue; }
91 
92  void newSpectrum(const std::vector<Real>& spectrum, int fftSize);
93  void clearSpectrumHistogram();
94 
95  Real getWaterfallShare() const { return m_waterfallShare; }
96  void setWaterfallShare(Real waterfallShare);
97  void connectTimer(const QTimer& timer);
98 
99  void setDisplayedStream(bool sourceOrSink, int streamIndex)
100  {
101  m_displaySourceOrSink = sourceOrSink;
102  m_displayStreamIndex = streamIndex;
103  }
104 
105 private:
114  QRect m_rect;
115 
117  m_channelMarker(channelMarker)
118  { }
119  };
120  QList<ChannelMarkerState*> m_channelMarkerStates;
121 
122  enum CursorState {
127  CSChannelMoving
128  };
129 
132 
133  QTimer m_timer;
134  QMutex m_mutex;
137 
141  bool m_linear;
142  int m_decay;
143  quint32 m_sampleRate;
144  quint32 m_timingRate;
145 
147 
152 
153  std::vector<Real> m_maxHold;
155  const std::vector<Real> *m_currentSpectrum;
157 
159 
169 
170  QRgb m_waterfallPalette[240];
179 
180  QRgb m_histogramPalette[240];
182  quint8* m_histogram;
192 
204 
206 
207  static const int m_waterfallBufferHeight = 256;
208 
209  void updateWaterfall(const std::vector<Real>& spectrum);
210  void updateHistogram(const std::vector<Real>& spectrum);
211 
212  void initializeGL();
213  void resizeGL(int width, int height);
214  void paintGL();
215 
216  void stopDrag();
217  void applyChanges();
218 
219  void mouseMoveEvent(QMouseEvent* event);
220  void mousePressEvent(QMouseEvent* event);
221  void mouseReleaseEvent(QMouseEvent* event);
222  void wheelEvent(QWheelEvent*);
223 
224  void enterEvent(QEvent* event);
225  void leaveEvent(QEvent* event);
226 
227 private slots:
228  void cleanup();
229  void tick();
230  void channelMarkerChanged();
231  void channelMarkerDestroyed(QObject* object);
232 };
233 
234 #endif // INCLUDE_GLSPECTRUM_H
int m_cursorChannel
Definition: glspectrum.h:131
int m_displayStreamIndex
Definition: glspectrum.h:191
Real m_referenceLevel
Definition: glspectrum.h:139
int m_displayTraceIntensity
Definition: glspectrum.h:150
qint32 getSampleRate() const
Definition: glspectrum.h:86
bool m_displayGrid
Definition: glspectrum.h:148
Real m_powerRange
Definition: glspectrum.h:140
QTimer m_timer
Definition: glspectrum.h:133
Real getWaterfallShare() const
Definition: glspectrum.h:95
QMatrix4x4 m_glFrequencyScaleBoxMatrix
Definition: glspectrum.h:167
QMatrix4x4 m_glHistogramBoxMatrix
Definition: glspectrum.h:187
bool m_linear
Definition: glspectrum.h:141
QList< ChannelMarkerState * > m_channelMarkerStates
Definition: glspectrum.h:120
IncrementalArray< GLfloat > m_q3TickFrequency
Definition: glspectrum.h:201
std::vector< Real > m_maxHold
Definition: glspectrum.h:153
bool m_invertedWaterfall
Definition: glspectrum.h:151
bool m_displayChanged
Definition: glspectrum.h:189
ChannelMarkerState(ChannelMarker *channelMarker)
Definition: glspectrum.h:116
void setDisplayedStream(bool sourceOrSink, int streamIndex)
Definition: glspectrum.h:99
ScaleEngine m_frequencyScale
Definition: glspectrum.h:165
qint64 m_centerFrequency
Definition: glspectrum.h:138
bool m_changesPending
Definition: glspectrum.h:136
CursorState m_cursorState
Definition: glspectrum.h:130
MsgReportSampleRate(quint32 sampleRate)
Definition: glspectrum.h:51
int m_decayDivisor
Definition: glspectrum.h:183
bool m_displayWaterfall
Definition: glspectrum.h:176
QMatrix4x4 m_glWaterfallBoxMatrix
Definition: glspectrum.h:175
QMatrix4x4 m_glLeftScaleBoxMatrix
Definition: glspectrum.h:168
#define SDRGUI_API
Definition: export.h:52
QRect m_frequencyScaleRect
Definition: glspectrum.h:166
IncrementalArray< GLfloat > m_q3TickTime
Definition: glspectrum.h:200
quint32 m_sampleRate
Definition: glspectrum.h:143
QPixmap m_leftMarginPixmap
Definition: glspectrum.h:161
bool m_ssbSpectrum
Definition: glspectrum.h:177
int m_waterfallTextureHeight
Definition: glspectrum.h:173
int m_matrixLoc
Definition: glspectrum.h:198
#define MESSAGE_CLASS_DECLARATION
Definition: message.h:43
void setMessageQueueToGUI(MessageQueue *messageQueue)
Definition: glspectrum.h:90
ScaleEngine m_powerScale
Definition: glspectrum.h:164
bool m_displaySourceOrSink
Definition: glspectrum.h:190
QPixmap m_frequencyPixmap
Definition: glspectrum.h:162
GLShaderTextured m_glShaderFrequencyScale
Definition: glspectrum.h:195
bool m_displayMaxHold
Definition: glspectrum.h:154
GLShaderTextured m_glShaderWaterfall
Definition: glspectrum.h:196
int m_decayDivisorCount
Definition: glspectrum.h:184
const std::vector< Real > * m_currentSpectrum
Definition: glspectrum.h:155
QImage * m_waterfallBuffer
Definition: glspectrum.h:171
bool m_displayCurrent
Definition: glspectrum.h:156
Real m_waterfallShare
Definition: glspectrum.h:158
int m_colorLoc
Definition: glspectrum.h:199
int m_displayGridIntensity
Definition: glspectrum.h:149
int m_waterfallTexturePos
Definition: glspectrum.h:174
quint8 * m_histogram
Spectrum phosphor matrix of FFT width and PSD height scaled to 100. values [0..239].
Definition: glspectrum.h:182
QMatrix4x4 m_glHistogramSpectrumMatrix
Definition: glspectrum.h:186
int m_histogramStroke
Definition: glspectrum.h:185
IncrementalArray< GLfloat > m_q3FFT
Definition: glspectrum.h:203
MessageQueue * m_messageQueueToGUI
Definition: glspectrum.h:205
quint32 m_timingRate
Definition: glspectrum.h:144
quint32 getSampleRate() const
Definition: glspectrum.h:58
GLShaderTextured m_glShaderLeftScale
Definition: glspectrum.h:194
QImage * m_histogramBuffer
Definition: glspectrum.h:181
bool m_displayHistogram
Definition: glspectrum.h:188
int m_fftSize
Definition: glspectrum.h:146
GLShaderTextured m_glShaderHistogram
Definition: glspectrum.h:197
QMutex m_mutex
Definition: glspectrum.h:134
GLShaderSimple m_glShaderSimple
Definition: glspectrum.h:193
ScaleEngine m_timeScale
Definition: glspectrum.h:163
float Real
Definition: dsptypes.h:42
bool m_lsbDisplay
Definition: glspectrum.h:178
int m_waterfallBufferPos
Definition: glspectrum.h:172
ChannelMarker * m_channelMarker
Definition: glspectrum.h:107
bool m_mouseInside
Definition: glspectrum.h:135
int m_leftMargin
Definition: glspectrum.h:160
IncrementalArray< GLfloat > m_q3TickPower
Definition: glspectrum.h:202