| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2019 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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 06:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01: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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QPixmap>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "freedvdemodgui.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "device/deviceuiset.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dsp/spectrumvis.h"
 | 
					
						
							|  |  |  | #include "dsp/dspengine.h"
 | 
					
						
							|  |  |  | #include "dsp/dspcommands.h"
 | 
					
						
							|  |  |  | #include "gui/glspectrum.h"
 | 
					
						
							|  |  |  | #include "gui/basicchannelsettingsdialog.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  | #include "gui/devicestreamselectiondialog.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | #include "plugin/pluginapi.h"
 | 
					
						
							|  |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | #include "util/db.h"
 | 
					
						
							|  |  |  | #include "gui/crightclickenabler.h"
 | 
					
						
							|  |  |  | #include "gui/audioselectdialog.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-12 21:59:04 +02:00
										 |  |  | #include "maincore.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:25:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "ui_freedvdemodgui.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | #include "freedvdemod.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FreeDVDemodGUI* FreeDVDemodGUI::create(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     FreeDVDemodGUI* gui = new FreeDVDemodGUI(pluginAPI, deviceUISet, rxChannel); | 
					
						
							|  |  |  | 	return gui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_settings.resetToDefaults(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray FreeDVDemodGUI::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FreeDVDemodGUI::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if(m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							| 
									
										
										
										
											2019-02-28 02:42:19 +01:00
										 |  |  |         applyBandwidths(5 - ui->spanLog2->value(), true); // does applySettings(true)
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.resetToDefaults(); | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							| 
									
										
										
										
											2019-02-28 02:42:19 +01:00
										 |  |  |         applyBandwidths(5 - ui->spanLog2->value(), true); // does applySettings(true)
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FreeDVDemodGUI::handleMessage(const Message& message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (FreeDVDemod::MsgConfigureFreeDVDemod::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("FreeDVDemodGUI::handleMessage: FreeDVDemodGUI::MsgConfigureFreeDVDemod"); | 
					
						
							|  |  |  |         const FreeDVDemod::MsgConfigureFreeDVDemod& cfg = (FreeDVDemod::MsgConfigureFreeDVDemod&) message; | 
					
						
							|  |  |  |         m_settings = cfg.getSettings(); | 
					
						
							|  |  |  |         blockApplySettings(true); | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							|  |  |  |         blockApplySettings(false); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (DSPConfigureAudio::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("FreeDVDemodGUI::handleMessage: DSPConfigureAudio: %d", m_freeDVDemod->getAudioSampleRate()); | 
					
						
							|  |  |  |         applyBandwidths(5 - ui->spanLog2->value()); // will update spectrum details with new sample rate
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::handleInputMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ((message = getInputMessageQueue()->pop()) != 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (handleMessage(*message)) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             delete message; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::channelMarkerChangedByCursor() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); | 
					
						
							|  |  |  |     m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::channelMarkerHighlightedByCursor() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     setHighlighted(m_channelMarker.getHighlighted()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::on_deltaFrequency_changed(qint64 value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_channelMarker.setCenterFrequency(value); | 
					
						
							|  |  |  |     m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-27 14:53:50 +01:00
										 |  |  | void FreeDVDemodGUI::on_reSync_clicked(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-27 17:41:11 +01:00
										 |  |  |     (void) checked; | 
					
						
							| 
									
										
										
										
											2019-02-27 14:53:50 +01:00
										 |  |  |     FreeDVDemod::MsgResyncFreeDVDemod* message = FreeDVDemod::MsgResyncFreeDVDemod::create(); | 
					
						
							|  |  |  |     m_freeDVDemod->getInputMessageQueue()->push(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 01:15:10 +01:00
										 |  |  | void FreeDVDemodGUI::on_freeDVMode_currentIndexChanged(int index) | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-25 01:15:10 +01:00
										 |  |  |     m_settings.m_freeDVMode = (FreeDVDemodSettings::FreeDVMode) index; | 
					
						
							|  |  |  |     m_channelMarker.setBandwidth(FreeDVDemodSettings::getHiCutoff(m_settings.m_freeDVMode) * 2); | 
					
						
							|  |  |  |     m_channelMarker.setLowCutoff(FreeDVDemodSettings::getLowCutoff(m_settings.m_freeDVMode)); | 
					
						
							|  |  |  |     m_channelMarker.setSidebands(ChannelMarker::usb); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::on_volume_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui->volumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1)); | 
					
						
							|  |  |  | 	m_settings.m_volume = value / 10.0; | 
					
						
							|  |  |  | 	applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-28 15:15:04 +01:00
										 |  |  | void FreeDVDemodGUI::on_volumeIn_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ui->volumeInText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1)); | 
					
						
							|  |  |  | 	m_settings.m_volumeIn = value / 10.0; | 
					
						
							|  |  |  | 	applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | void FreeDVDemodGUI::on_agc_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_agc = checked; | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::on_audioMute_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_audioMute = checked; | 
					
						
							|  |  |  | 	m_settings.m_audioMute = checked; | 
					
						
							|  |  |  | 	applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::on_spanLog2_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ((value < 0) || (value > 4)) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     applyBandwidths(5 - ui->spanLog2->value()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::onMenuDialogCalled(const QPoint &p) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-09 21:07:05 +02:00
										 |  |  |     if (m_contextMenuType == ContextMenuChannelSettings) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         BasicChannelSettingsDialog dialog(&m_channelMarker, this); | 
					
						
							|  |  |  |         dialog.setUseReverseAPI(m_settings.m_useReverseAPI); | 
					
						
							|  |  |  |         dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress); | 
					
						
							|  |  |  |         dialog.setReverseAPIPort(m_settings.m_reverseAPIPort); | 
					
						
							|  |  |  |         dialog.setReverseAPIDeviceIndex(m_settings.m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |         dialog.setReverseAPIChannelIndex(m_settings.m_reverseAPIChannelIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dialog.move(p); | 
					
						
							|  |  |  |         dialog.exec(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); | 
					
						
							|  |  |  |         m_settings.m_rgbColor = m_channelMarker.getColor().rgb(); | 
					
						
							|  |  |  |         m_settings.m_title = m_channelMarker.getTitle(); | 
					
						
							|  |  |  |         m_settings.m_useReverseAPI = dialog.useReverseAPI(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIChannelIndex = dialog.getReverseAPIChannelIndex(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         setWindowTitle(m_settings.m_title); | 
					
						
							|  |  |  |         setTitleColor(m_settings.m_rgbColor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         applySettings(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  |     else if ((m_contextMenuType == ContextMenuStreamSettings) && (m_deviceUISet->m_deviceMIMOEngine)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DeviceStreamSelectionDialog dialog(this); | 
					
						
							|  |  |  |         dialog.setNumberOfStreams(m_freeDVDemod->getNumberOfDeviceStreams()); | 
					
						
							|  |  |  |         dialog.setStreamIndex(m_settings.m_streamIndex); | 
					
						
							|  |  |  |         dialog.move(p); | 
					
						
							|  |  |  |         dialog.exec(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_settings.m_streamIndex = dialog.getSelectedStreamIndex(); | 
					
						
							|  |  |  |         m_channelMarker.clearStreamIndexes(); | 
					
						
							|  |  |  |         m_channelMarker.addStreamIndex(m_settings.m_streamIndex); | 
					
						
							|  |  |  |         displayStreamIndex(); | 
					
						
							|  |  |  |         applySettings(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 21:07:05 +02:00
										 |  |  |     resetContextMenuType(); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) widget; | 
					
						
							|  |  |  |     (void) rollDown; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FreeDVDemodGUI::FreeDVDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) : | 
					
						
							| 
									
										
										
										
											2020-10-04 06:16:15 +02:00
										 |  |  | 	ChannelGUI(parent), | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 	ui(new Ui::FreeDVDemodGUI), | 
					
						
							|  |  |  | 	m_pluginAPI(pluginAPI), | 
					
						
							|  |  |  | 	m_deviceUISet(deviceUISet), | 
					
						
							|  |  |  | 	m_channelMarker(this), | 
					
						
							|  |  |  | 	m_doApplySettings(true), | 
					
						
							|  |  |  |     m_spectrumRate(6000), | 
					
						
							|  |  |  | 	m_audioBinaural(false), | 
					
						
							|  |  |  | 	m_audioFlipChannels(false), | 
					
						
							|  |  |  |     m_audioMute(false), | 
					
						
							| 
									
										
										
										
											2020-08-01 10:09:39 +02:00
										 |  |  | 	m_squelchOpen(false), | 
					
						
							|  |  |  |     m_audioSampleRate(-1) | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	ui->setupUi(this); | 
					
						
							|  |  |  | 	setAttribute(Qt::WA_DeleteOnClose, true); | 
					
						
							|  |  |  | 	connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); | 
					
						
							|  |  |  | 	connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_freeDVDemod = (FreeDVDemod*) rxChannel; | 
					
						
							| 
									
										
										
										
											2020-04-30 09:57:05 +02:00
										 |  |  |     m_spectrumVis = m_freeDVDemod->getSpectrumVis(); | 
					
						
							|  |  |  | 	m_spectrumVis->setGLSpectrum(ui->glSpectrum); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 	m_freeDVDemod->setMessageQueueToGUI(getInputMessageQueue()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	resetToDefaults(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->glSpectrum->setCenterFrequency(m_spectrumRate/2); | 
					
						
							|  |  |  |     ui->glSpectrum->setSampleRate(m_spectrumRate); | 
					
						
							|  |  |  | 	ui->glSpectrum->setDisplayWaterfall(true); | 
					
						
							|  |  |  | 	ui->glSpectrum->setDisplayMaxHold(true); | 
					
						
							|  |  |  |     ui->glSpectrum->setSsbSpectrum(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-12 21:59:04 +02:00
										 |  |  | 	connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	CRightClickEnabler *audioMuteRightClickEnabler = new CRightClickEnabler(ui->audioMute); | 
					
						
							|  |  |  |     connect(audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); | 
					
						
							|  |  |  |     ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); | 
					
						
							|  |  |  |     ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999); | 
					
						
							|  |  |  | 	ui->channelPowerMeter->setColorTheme(LevelMeterSignalDB::ColorGreenAndBlue); | 
					
						
							| 
									
										
										
										
											2019-02-27 18:37:07 +01:00
										 |  |  |     ui->snrMeter->setColorTheme(LevelMeterSignalDB::ColorCyanAndBlue); | 
					
						
							| 
									
										
										
										
											2019-02-28 02:42:19 +01:00
										 |  |  |     ui->snrMeter->setRange(-10, 30); | 
					
						
							| 
									
										
										
										
											2019-02-27 18:37:07 +01:00
										 |  |  |     ui->snrMeter->setAverageSmoothing(2); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_channelMarker.setVisible(true); // activate signal on the last setting only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_settings.setChannelMarker(&m_channelMarker); | 
					
						
							|  |  |  |     m_settings.setSpectrumGUI(ui->spectrumGUI); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_deviceUISet->addChannelMarker(&m_channelMarker); | 
					
						
							|  |  |  | 	m_deviceUISet->addRollupWidget(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor())); | 
					
						
							|  |  |  |     connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor())); | 
					
						
							|  |  |  |     connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); | 
					
						
							| 
									
										
										
										
											2019-12-08 10:09:24 +01:00
										 |  |  |     m_freeDVDemod->setLevelMeter(ui->volumeInMeter); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-01 02:33:50 +02:00
										 |  |  | 	ui->spectrumGUI->setBuddies(m_spectrumVis, ui->glSpectrum); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	m_iconDSBUSB.addPixmap(QPixmap("://dsb.png"), QIcon::Normal, QIcon::On); | 
					
						
							|  |  |  |     m_iconDSBUSB.addPixmap(QPixmap("://usb.png"), QIcon::Normal, QIcon::Off); | 
					
						
							|  |  |  | 	m_iconDSBLSB.addPixmap(QPixmap("://dsb.png"), QIcon::Normal, QIcon::On); | 
					
						
							|  |  |  |     m_iconDSBLSB.addPixmap(QPixmap("://lsb.png"), QIcon::Normal, QIcon::Off); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	displaySettings(); | 
					
						
							|  |  |  | 	applyBandwidths(5 - ui->spanLog2->value(), true); // does applySettings(true)
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FreeDVDemodGUI::~FreeDVDemodGUI() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	delete ui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FreeDVDemodGUI::blockApplySettings(bool block) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     bool ret = !m_doApplySettings; | 
					
						
							|  |  |  |     m_doApplySettings = !block; | 
					
						
							|  |  |  |     return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::applySettings(bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_doApplySettings) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  |         FreeDVDemod::MsgConfigureFreeDVDemod* message = FreeDVDemod::MsgConfigureFreeDVDemod::create( m_settings, force); | 
					
						
							|  |  |  |         m_freeDVDemod->getInputMessageQueue()->push(message); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::applyBandwidths(int spanLog2, bool force) | 
					
						
							| 
									
										
										
										
											2019-04-17 17:34:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-26 23:55:23 +02:00
										 |  |  |     displayBandwidths(spanLog2); | 
					
						
							| 
									
										
										
										
											2019-04-17 17:34:02 +02:00
										 |  |  |     m_settings.m_spanLog2 = spanLog2; | 
					
						
							|  |  |  |     applySettings(force); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::displayBandwidths(int spanLog2) | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-25 01:15:10 +01:00
										 |  |  |     m_spectrumRate = m_freeDVDemod->getModemSampleRate() / (1<<spanLog2); | 
					
						
							|  |  |  |     int bwMax = m_freeDVDemod->getModemSampleRate() / (100*(1<<spanLog2)); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 17:34:02 +02:00
										 |  |  |     qDebug() << "FreeDVDemodGUI::displayBandwidths:" | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |             << " spanLog2: " << spanLog2 | 
					
						
							|  |  |  |             << " m_spectrumRate: " << m_spectrumRate | 
					
						
							| 
									
										
										
										
											2019-02-25 01:15:10 +01:00
										 |  |  |             << " bwMax: " << bwMax; | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QString spanStr = QString::number(bwMax/10.0, 'f', 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 01:15:10 +01:00
										 |  |  |     ui->spanText->setText(tr("%1k").arg(spanStr)); | 
					
						
							|  |  |  |     ui->glSpectrum->setCenterFrequency(m_spectrumRate/2); | 
					
						
							|  |  |  |     ui->glSpectrum->setSampleRate(m_spectrumRate); | 
					
						
							|  |  |  |     ui->glSpectrum->setSsbSpectrum(true); | 
					
						
							|  |  |  |     ui->glSpectrum->setLsbDisplay(false); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::displaySettings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_channelMarker.blockSignals(true); | 
					
						
							|  |  |  |     m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); | 
					
						
							|  |  |  |     m_channelMarker.setTitle(m_settings.m_title); | 
					
						
							| 
									
										
										
										
											2019-02-25 01:15:10 +01:00
										 |  |  |     m_channelMarker.setBandwidth(FreeDVDemodSettings::getHiCutoff(m_settings.m_freeDVMode) * 2); | 
					
						
							|  |  |  |     m_channelMarker.setLowCutoff(FreeDVDemodSettings::getLowCutoff(m_settings.m_freeDVMode)); | 
					
						
							|  |  |  |     m_channelMarker.setSidebands(ChannelMarker::usb); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |     m_channelMarker.blockSignals(false); | 
					
						
							|  |  |  |     m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     setTitleColor(m_settings.m_rgbColor); | 
					
						
							|  |  |  |     setWindowTitle(m_channelMarker.getTitle()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     blockApplySettings(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 17:34:02 +02:00
										 |  |  |     ui->freeDVMode->setCurrentIndex((int) m_settings.m_freeDVMode); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |     ui->agc->setChecked(m_settings.m_agc); | 
					
						
							|  |  |  |     ui->audioMute->setChecked(m_settings.m_audioMute); | 
					
						
							|  |  |  |     ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Prevent uncontrolled triggering of applyBandwidths
 | 
					
						
							|  |  |  |     ui->spanLog2->blockSignals(true); | 
					
						
							|  |  |  |     ui->spanLog2->setValue(5 - m_settings.m_spanLog2); | 
					
						
							| 
									
										
										
										
											2019-04-17 17:34:02 +02:00
										 |  |  |     displayBandwidths(m_settings.m_spanLog2); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |     ui->spanLog2->blockSignals(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->volume->setValue(m_settings.m_volume * 10.0); | 
					
						
							|  |  |  |     ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 0, 'f', 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 00:25:57 +01:00
										 |  |  |     ui->volumeIn->setValue(m_settings.m_volumeIn * 10.0); | 
					
						
							|  |  |  |     ui->volumeInText->setText(QString("%1").arg(m_settings.m_volumeIn, 0, 'f', 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  |     displayStreamIndex(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |     blockApplySettings(false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  | void FreeDVDemodGUI::displayStreamIndex() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_deviceUISet->m_deviceMIMOEngine) { | 
					
						
							|  |  |  |         setStreamIndicator(tr("%1").arg(m_settings.m_streamIndex)); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         setStreamIndicator("S"); // single channel indicator
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  | void FreeDVDemodGUI::leaveEvent(QEvent*) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_channelMarker.setHighlighted(false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::enterEvent(QEvent*) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_channelMarker.setHighlighted(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::audioSelect() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     qDebug("FreeDVDemodGUI::audioSelect"); | 
					
						
							|  |  |  |     AudioSelectDialog audioSelect(DSPEngine::instance()->getAudioDeviceManager(), m_settings.m_audioDeviceName); | 
					
						
							|  |  |  |     audioSelect.exec(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (audioSelect.m_selected) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_settings.m_audioDeviceName = audioSelect.m_audioDeviceName; | 
					
						
							|  |  |  |         applySettings(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FreeDVDemodGUI::tick() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     double magsqAvg, magsqPeak; | 
					
						
							|  |  |  |     int nbMagsqSamples; | 
					
						
							|  |  |  |     m_freeDVDemod->getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples); | 
					
						
							|  |  |  |     double powDbAvg = CalcDb::dbPower(magsqAvg); | 
					
						
							|  |  |  |     double powDbPeak = CalcDb::dbPower(magsqPeak); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->channelPowerMeter->levelChanged( | 
					
						
							|  |  |  |             (FreeDVDemodSettings::m_mminPowerThresholdDBf + powDbAvg) / FreeDVDemodSettings::m_mminPowerThresholdDBf, | 
					
						
							|  |  |  |             (FreeDVDemodSettings::m_mminPowerThresholdDBf + powDbPeak) / FreeDVDemodSettings::m_mminPowerThresholdDBf, | 
					
						
							|  |  |  |             nbMagsqSamples); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-27 18:37:07 +01:00
										 |  |  |     double snrAvg, snrPeak; | 
					
						
							|  |  |  |     int nbSNRSamples; | 
					
						
							|  |  |  |     m_freeDVDemod->getSNRLevels(snrAvg, snrPeak, nbSNRSamples); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->snrMeter->levelChanged( | 
					
						
							| 
									
										
										
										
											2019-02-28 02:42:19 +01:00
										 |  |  |         (10.0f + snrAvg) / 40.0f, | 
					
						
							|  |  |  |         (10.0f + snrPeak) / 40.0f, | 
					
						
							| 
									
										
										
										
											2019-02-27 18:37:07 +01:00
										 |  |  |         nbSNRSamples | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-28 02:42:19 +01:00
										 |  |  |     ui->berText->setText(tr("%1").arg(m_freeDVDemod->getBER())); | 
					
						
							|  |  |  |     float freqOffset = m_freeDVDemod->getFrequencyOffset(); | 
					
						
							|  |  |  |     int freqOffsetInt = freqOffset < -999 ? -999 : freqOffset > 999 ? 999 : freqOffset; | 
					
						
							|  |  |  |     ui->freqOffset->setText(tr("%1Hz").arg(freqOffsetInt)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_freeDVDemod->isSync()) { | 
					
						
							|  |  |  |         ui->syncLabel->setStyleSheet("QLabel { background-color : green; }"); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         ui->syncLabel->setStyleSheet("QLabel { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_tickCount % 4 == 0) { | 
					
						
							|  |  |  |         ui->channelPower->setText(tr("%1 dB").arg(powDbAvg, 0, 'f', 1)); | 
					
						
							|  |  |  |         ui->snrText->setText(tr("%1 dB").arg(snrAvg < -90 ? -90 : snrAvg > 90 ? 90 : snrAvg, 0, 'f', 1)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 10:09:39 +02:00
										 |  |  |     int audioSampleRate = m_freeDVDemod->getAudioSampleRate(); | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |     bool squelchOpen = m_freeDVDemod->getAudioActive(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 10:09:39 +02:00
										 |  |  |     if ((audioSampleRate != m_audioSampleRate) || (squelchOpen != m_squelchOpen)) | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-08-01 10:09:39 +02:00
										 |  |  |         if (audioSampleRate < 0) { | 
					
						
							|  |  |  |             ui->audioMute->setStyleSheet("QToolButton { background-color : red; }"); | 
					
						
							|  |  |  |         } else if (squelchOpen) { | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |             ui->audioMute->setStyleSheet("QToolButton { background-color : green; }"); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             ui->audioMute->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-01 10:09:39 +02:00
										 |  |  |         m_audioSampleRate = audioSampleRate; | 
					
						
							| 
									
										
										
										
											2019-02-25 00:13:57 +01:00
										 |  |  |         m_squelchOpen = squelchOpen; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_tickCount++; | 
					
						
							|  |  |  | } |