| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2016-03-04 18:51:03 +01:00
										 |  |  | // Copyright (C) 2016 F4EXB                                                      //
 | 
					
						
							|  |  |  | // written by Edouard Griffiths                                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // OpenGL interface modernization.                                               //
 | 
					
						
							|  |  |  | // See: http://doc.qt.io/qt-5/qopenglshaderprogram.html                          //
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01: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                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 03:09:50 +01:00
										 |  |  | #include <QOpenGLBuffer>
 | 
					
						
							|  |  |  | #include <QOpenGLVertexArrayObject>
 | 
					
						
							| 
									
										
										
										
											2016-03-02 22:50:05 +01:00
										 |  |  | #include <QMatrix4x4>
 | 
					
						
							| 
									
										
										
										
											2016-03-05 21:54:24 +01:00
										 |  |  | #include <QGLWidget>
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "dsp/dsptypes.h"
 | 
					
						
							|  |  |  | #include "gui/scaleengine.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-03 01:09:55 +01:00
										 |  |  | #include "gui/glshadersimple.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-05 06:45:05 +01:00
										 |  |  | #include "gui/glshadertextured.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "dsp/channelmarker.h"
 | 
					
						
							|  |  |  | #include "util/export.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 03:09:50 +01:00
										 |  |  | class QOpenGLShaderProgram; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 21:54:24 +01:00
										 |  |  | class SDRANGEL_API GLSpectrum : public QGLWidget { | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	GLSpectrum(QWidget* parent = NULL); | 
					
						
							|  |  |  | 	~GLSpectrum(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-22 04:23:10 +02:00
										 |  |  | 	void setCenterFrequency(qint64 frequency); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void setSampleRate(qint32 sampleRate); | 
					
						
							|  |  |  | 	void setReferenceLevel(Real referenceLevel); | 
					
						
							|  |  |  | 	void setPowerRange(Real powerRange); | 
					
						
							|  |  |  | 	void setDecay(int decay); | 
					
						
							| 
									
										
										
										
											2015-07-16 04:55:14 +02:00
										 |  |  | 	void setHistoLateHoldoff(int lateHoldoff); | 
					
						
							|  |  |  | 	void setHistoStroke(int stroke); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void setDisplayWaterfall(bool display); | 
					
						
							| 
									
										
										
										
											2015-06-12 02:49:29 +02:00
										 |  |  | 	void setSsbSpectrum(bool ssbSpectrum); | 
					
						
							| 
									
										
										
										
											2017-07-22 04:23:10 +02:00
										 |  |  | 	void setLsbDisplay(bool lsbDisplay); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void setInvertedWaterfall(bool inv); | 
					
						
							|  |  |  | 	void setDisplayMaxHold(bool display); | 
					
						
							| 
									
										
										
										
											2015-07-16 04:55:14 +02:00
										 |  |  | 	void setDisplayCurrent(bool display); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void setDisplayHistogram(bool display); | 
					
						
							|  |  |  | 	void setDisplayGrid(bool display); | 
					
						
							| 
									
										
										
										
											2015-05-12 15:49:03 +02:00
										 |  |  | 	void setDisplayGridIntensity(int intensity); | 
					
						
							| 
									
										
										
										
											2015-07-18 17:53:57 +02:00
										 |  |  | 	void setDisplayTraceIntensity(int intensity); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void addChannelMarker(ChannelMarker* channelMarker); | 
					
						
							|  |  |  | 	void removeChannelMarker(ChannelMarker* channelMarker); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void newSpectrum(const std::vector<Real>& spectrum, int fftSize); | 
					
						
							| 
									
										
										
										
											2015-07-24 01:09:03 +02:00
										 |  |  | 	void clearSpectrumHistogram(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-24 01:30:00 +02:00
										 |  |  | 	Real getWaterfallShare() const { return m_waterfallShare; } | 
					
						
							|  |  |  | 	void setWaterfallShare(Real waterfallShare); | 
					
						
							| 
									
										
										
										
											2015-08-01 03:33:07 +02:00
										 |  |  | 	void connectTimer(const QTimer& timer); | 
					
						
							| 
									
										
										
										
											2015-07-24 01:30:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | private: | 
					
						
							|  |  |  | 	struct ChannelMarkerState { | 
					
						
							|  |  |  | 		ChannelMarker* m_channelMarker; | 
					
						
							| 
									
										
										
										
											2016-03-04 01:30:29 +01:00
										 |  |  | 		QMatrix4x4 m_glMatrixWaterfall; | 
					
						
							|  |  |  | 		QMatrix4x4 m_glMatrixDsbWaterfall; | 
					
						
							| 
									
										
										
										
											2016-03-04 02:24:08 +01:00
										 |  |  | 		QMatrix4x4 m_glMatrixFreqScale; | 
					
						
							| 
									
										
										
										
											2016-03-04 03:45:34 +01:00
										 |  |  | 		QMatrix4x4 m_glMatrixDsbFreqScale; | 
					
						
							|  |  |  | 		QMatrix4x4 m_glMatrixHistogram; | 
					
						
							|  |  |  | 		QMatrix4x4 m_glMatrixDsbHistogram; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		QRect m_rect; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ChannelMarkerState(ChannelMarker* channelMarker) : | 
					
						
							| 
									
										
										
										
											2016-03-05 07:02:06 +01:00
										 |  |  | 			m_channelMarker(channelMarker) | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		{ } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	QList<ChannelMarkerState*> m_channelMarkerStates; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	enum CursorState { | 
					
						
							|  |  |  | 		CSNormal, | 
					
						
							|  |  |  | 		CSSplitter, | 
					
						
							|  |  |  | 		CSSplitterMoving, | 
					
						
							|  |  |  | 		CSChannel, | 
					
						
							|  |  |  | 		CSChannelMoving | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CursorState m_cursorState; | 
					
						
							|  |  |  | 	int m_cursorChannel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QTimer m_timer; | 
					
						
							|  |  |  | 	QMutex m_mutex; | 
					
						
							|  |  |  | 	bool m_mouseInside; | 
					
						
							|  |  |  | 	bool m_changesPending; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	qint64 m_centerFrequency; | 
					
						
							|  |  |  | 	Real m_referenceLevel; | 
					
						
							|  |  |  | 	Real m_powerRange; | 
					
						
							|  |  |  | 	int m_decay; | 
					
						
							|  |  |  | 	quint32 m_sampleRate; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int m_fftSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool m_displayGrid; | 
					
						
							| 
									
										
										
										
											2015-05-12 15:49:03 +02:00
										 |  |  | 	int m_displayGridIntensity; | 
					
						
							| 
									
										
										
										
											2015-07-18 17:53:57 +02:00
										 |  |  | 	int m_displayTraceIntensity; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	bool m_invertedWaterfall; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::vector<Real> m_maxHold; | 
					
						
							|  |  |  | 	bool m_displayMaxHold; | 
					
						
							| 
									
										
										
										
											2015-07-16 08:38:33 +02:00
										 |  |  | 	const std::vector<Real> *m_currentSpectrum; | 
					
						
							| 
									
										
										
										
											2015-07-16 04:55:14 +02:00
										 |  |  | 	bool m_displayCurrent; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Real m_waterfallShare; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QPixmap m_leftMarginPixmap; | 
					
						
							| 
									
										
										
										
											2016-03-05 08:53:56 +01:00
										 |  |  | 	QPixmap m_frequencyPixmap; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	ScaleEngine m_timeScale; | 
					
						
							|  |  |  | 	ScaleEngine m_powerScale; | 
					
						
							|  |  |  | 	ScaleEngine m_frequencyScale; | 
					
						
							|  |  |  | 	QRect m_frequencyScaleRect; | 
					
						
							| 
									
										
										
										
											2016-03-03 19:56:54 +01:00
										 |  |  | 	QMatrix4x4 m_glFrequencyScaleBoxMatrix; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glLeftScaleBoxMatrix; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QRgb m_waterfallPalette[240]; | 
					
						
							|  |  |  | 	QImage* m_waterfallBuffer; | 
					
						
							|  |  |  | 	int m_waterfallBufferPos; | 
					
						
							|  |  |  | 	int m_waterfallTextureHeight; | 
					
						
							|  |  |  | 	int m_waterfallTexturePos; | 
					
						
							| 
									
										
										
										
											2016-03-03 19:56:54 +01:00
										 |  |  | 	QMatrix4x4 m_glWaterfallBoxMatrix; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	bool m_displayWaterfall; | 
					
						
							| 
									
										
										
										
											2015-06-12 02:49:29 +02:00
										 |  |  | 	bool m_ssbSpectrum; | 
					
						
							| 
									
										
										
										
											2017-07-22 04:23:10 +02:00
										 |  |  | 	bool m_lsbDisplay; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QRgb m_histogramPalette[240]; | 
					
						
							|  |  |  | 	QImage* m_histogramBuffer; | 
					
						
							|  |  |  | 	quint8* m_histogram; | 
					
						
							|  |  |  | 	quint8* m_histogramHoldoff; | 
					
						
							|  |  |  | 	int m_histogramHoldoffBase; | 
					
						
							|  |  |  | 	int m_histogramHoldoffCount; | 
					
						
							|  |  |  | 	int m_histogramLateHoldoff; | 
					
						
							| 
									
										
										
										
											2015-07-15 08:48:02 +02:00
										 |  |  | 	int m_histogramStroke; | 
					
						
							| 
									
										
										
										
											2016-03-03 01:41:30 +01:00
										 |  |  | 	QMatrix4x4 m_glHistogramSpectrumMatrix; | 
					
						
							|  |  |  | 	QMatrix4x4 m_glHistogramBoxMatrix; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	bool m_displayHistogram; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool m_displayChanged; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-03 19:56:54 +01:00
										 |  |  | 	GLShaderSimple m_glShaderSimple; | 
					
						
							| 
									
										
										
										
											2016-03-05 06:45:05 +01:00
										 |  |  | 	GLShaderTextured m_glShaderLeftScale; | 
					
						
							| 
									
										
										
										
											2016-03-05 08:53:56 +01:00
										 |  |  | 	GLShaderTextured m_glShaderFrequencyScale; | 
					
						
							| 
									
										
										
										
											2016-03-05 11:57:53 +01:00
										 |  |  | 	GLShaderTextured m_glShaderWaterfall; | 
					
						
							| 
									
										
										
										
											2016-03-05 14:28:55 +01:00
										 |  |  | 	GLShaderTextured m_glShaderHistogram; | 
					
						
							| 
									
										
										
										
											2016-03-02 03:09:50 +01:00
										 |  |  | 	int m_matrixLoc; | 
					
						
							|  |  |  | 	int m_colorLoc; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 11:57:53 +01:00
										 |  |  | 	static const int m_waterfallBufferHeight = 256; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01: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(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void stopDrag(); | 
					
						
							|  |  |  | 	void applyChanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void mouseMoveEvent(QMouseEvent* event); | 
					
						
							|  |  |  | 	void mousePressEvent(QMouseEvent* event); | 
					
						
							|  |  |  | 	void mouseReleaseEvent(QMouseEvent* event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void enterEvent(QEvent* event); | 
					
						
							|  |  |  | 	void leaveEvent(QEvent* event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							| 
									
										
										
										
											2016-03-06 09:33:10 +01:00
										 |  |  | 	void cleanup(); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	void tick(); | 
					
						
							|  |  |  | 	void channelMarkerChanged(); | 
					
						
							|  |  |  | 	void channelMarkerDestroyed(QObject* object); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // INCLUDE_GLSPECTRUM_H
 |