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.
wfmdemodgui.cpp
Go to the documentation of this file.
1 #include "wfmdemodgui.h"
2 
3 #include "device/deviceuiset.h"
4 #include "dsp/downchannelizer.h"
5 
6 #include <QDockWidget>
7 #include <QMainWindow>
8 #include <QDebug>
9 
10 #include "ui_wfmdemodgui.h"
11 #include "dsp/dspengine.h"
12 #include "plugin/pluginapi.h"
13 #include "util/simpleserializer.h"
14 #include "util/db.h"
16 #include "gui/crightclickenabler.h"
17 #include "gui/audioselectdialog.h"
18 #include "mainwindow.h"
19 
20 #include "wfmdemod.h"
21 
23 {
24  WFMDemodGUI* gui = new WFMDemodGUI(pluginAPI, deviceUISet, rxChannel);
25  return gui;
26 }
27 
29 {
30  delete this;
31 }
32 
33 void WFMDemodGUI::setName(const QString& name)
34 {
35  setObjectName(name);
36 }
37 
38 QString WFMDemodGUI::getName() const
39 {
40  return objectName();
41 }
42 
44 {
46 }
47 
48 void WFMDemodGUI::setCenterFrequency(qint64 centerFrequency)
49 {
50  m_channelMarker.setCenterFrequency(centerFrequency);
51  applySettings();
52 }
53 
55 {
58  applySettings();
59 }
60 
61 QByteArray WFMDemodGUI::serialize() const
62 {
63  return m_settings.serialize();
64 }
65 
66 bool WFMDemodGUI::deserialize(const QByteArray& data)
67 {
68  if(m_settings.deserialize(data)) {
70  applySettings(true);
71  return true;
72  } else {
74  return false;
75  }
76 }
77 
78 bool WFMDemodGUI::handleMessage(const Message& message)
79 {
80  (void) message;
82  {
83  qDebug("WFMDemodGUI::handleMessage: WFMDemod::MsgConfigureWFMDemod");
85  m_settings = cfg.getSettings();
86  blockApplySettings(true);
88  blockApplySettings(false);
89  return true;
90  }
91  else
92  {
93  return false;
94  }
95 }
96 
98 {
99  Message* message;
100 
101  while ((message = getInputMessageQueue()->pop()) != 0)
102  {
103  if (handleMessage(*message))
104  {
105  delete message;
106  }
107  }
108 }
109 
111 {
112  ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
114  applySettings();
115 }
116 
118 {
120 }
121 
123 {
126  applySettings();
127 }
128 
129 void WFMDemodGUI::on_rfBW_changed(quint64 value)
130 {
132  m_settings.m_rfBandwidth = value;
133  applySettings();
134 }
135 
137 {
138  ui->afBWText->setText(QString("%1 kHz").arg(value));
139  m_settings.m_afBandwidth = value * 1000.0;
140  applySettings();
141 }
142 
144 {
145  ui->volumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1));
146  m_settings.m_volume = value / 10.0;
147  applySettings();
148 }
149 
151 {
152  ui->squelchText->setText(QString("%1 dB").arg(value));
153  m_settings.m_squelch = value;
154  applySettings();
155 }
156 
158 {
159  m_settings.m_audioMute = checked;
160  applySettings();
161 }
162 
163 void WFMDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown)
164 {
165  (void) widget;
166  (void) rollDown;
167 }
168 
169 void WFMDemodGUI::onMenuDialogCalled(const QPoint &p)
170 {
172  {
179 
180  dialog.move(p);
181  dialog.exec();
182 
191 
192  setWindowTitle(m_settings.m_title);
194 
195  applySettings();
196  }
197 
199 }
200 
201 WFMDemodGUI::WFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget* parent) :
202  RollupWidget(parent),
203  ui(new Ui::WFMDemodGUI),
204  m_pluginAPI(pluginAPI),
205  m_deviceUISet(deviceUISet),
206  m_channelMarker(this),
207  m_basicSettingsShown(false)
208 {
209  ui->setupUi(this);
210  setAttribute(Qt::WA_DeleteOnClose, true);
211  connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
212  connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
213  connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
214 
215  m_wfmDemod = (WFMDemod*) rxChannel; //new WFMDemod(m_deviceUISet->m_deviceSourceAPI);
217 
218  connect(&MainWindow::getInstance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick()));
219 
220  CRightClickEnabler *audioMuteRightClickEnabler = new CRightClickEnabler(ui->audioMute);
221  connect(audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect()));
222 
223  ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03)));
224  ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
225  ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999);
226  ui->channelPowerMeter->setColorTheme(LevelMeterSignalDB::ColorGreenAndBlue);
227 
228  ui->rfBW->setColorMapper(ColorMapper(ColorMapper::GrayYellow));
230 
231  m_channelMarker.blockSignals(true);
234  m_channelMarker.setTitle("WFM Demodulator");
236  m_channelMarker.blockSignals(false);
237  m_channelMarker.setVisible(true); // activate signal on the last setting only
238 
241 
245 
246  connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor()));
247  connect(&m_channelMarker, SIGNAL(highlightedByCursor()), this, SLOT(channelMarkerHighlightedByCursor()));
248 
249  displaySettings();
250  applySettings(true);
251 }
252 
254 {
256  delete m_wfmDemod; // TODO: check this: when the GUI closes it has to delete the demodulator
257  //delete m_channelMarker;
258  delete ui;
259 }
260 
262 {
263  m_doApplySettings = !block;
264 }
265 
267 {
268  if (m_doApplySettings)
269  {
273  m_wfmDemod->getInputMessageQueue()->push(msgChan);
274 
276  m_wfmDemod->getInputMessageQueue()->push(msgConfig);
277  }
278 }
279 
281 {
282  m_channelMarker.blockSignals(true);
286  m_channelMarker.blockSignals(false);
287  m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only
288 
290  setWindowTitle(m_channelMarker.getTitle());
291 
292  blockApplySettings(true);
293 
294  ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
295  ui->rfBW->setValue(m_settings.m_rfBandwidth);
296  ui->afBW->setValue(m_settings.m_afBandwidth/1000.0);
297  ui->afBWText->setText(QString("%1 kHz").arg(m_settings.m_afBandwidth/1000.0));
298  ui->volume->setValue(m_settings.m_volume * 10.0);
299  ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 0, 'f', 1));
300  ui->squelch->setValue(m_settings.m_squelch);
301  ui->squelchText->setText(QString("%1 dB").arg(m_settings.m_squelch));
302  ui->audioMute->setChecked(m_settings.m_audioMute);
303 
304  blockApplySettings(false);
305 }
306 
308 {
310 }
311 
313 {
315 }
316 
318 {
319  qDebug("WFMDemodGUI::audioSelect");
321  audioSelect.exec();
322 
323  if (audioSelect.m_selected)
324  {
326  applySettings();
327  }
328 }
329 
331 {
332  double magsqAvg, magsqPeak;
333  int nbMagsqSamples;
334  m_wfmDemod->getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples);
335  double powDbAvg = CalcDb::dbPower(magsqAvg);
336  double powDbPeak = CalcDb::dbPower(magsqPeak);
337 
338  ui->channelPower->setText(QString::number(powDbAvg, 'f', 1));
339  ui->channelPowerMeter->levelChanged(
340  (100.0f + powDbAvg) / 100.0f,
341  (100.0f + powDbPeak) / 100.0f,
342  nbMagsqSamples);
343 
344  bool squelchOpen = m_wfmDemod->getSquelchOpen();
345 
346  if (squelchOpen != m_squelchOpen)
347  {
348  if (squelchOpen) {
349  ui->audioMute->setStyleSheet("QToolButton { background-color : green; }");
350  } else {
351  ui->audioMute->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
352  }
353 
354  m_squelchOpen = squelchOpen;
355  }
356 }
static MainWindow * getInstance()
Definition: mainwindow.h:73
void leaveEvent(QEvent *)
const QString & getReverseAPIAddress() const
qint64 m_inputFrequencyOffset
static const int m_rfBWDigits
bool m_basicSettingsShown
Definition: wfmdemodgui.h:48
WFMDemod * m_wfmDemod
Definition: wfmdemodgui.h:53
int getCenterFrequency() const
Definition: channelmarker.h:42
void push(Message *message, bool emitSignal=true)
Push message onto queue.
static double dbPower(double magsq, double floor=1e-12)
Definition: db.cpp:22
virtual qint64 getCenterFrequency() const
Definition: wfmdemodgui.cpp:43
WFMDemodGUI(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel, QWidget *parent=0)
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
uint16_t m_reverseAPIPort
virtual void destroy()
Definition: wfmdemodgui.cpp:28
uint16_t m_reverseAPIChannelIndex
void onMenuDialogCalled(const QPoint &p)
Ui::WFMDemodGUI * ui
Definition: wfmdemodgui.h:43
virtual void setCenterFrequency(qint64 centerFrequency)
Definition: wfmdemodgui.cpp:48
static const int m_rfBWMin
virtual ~WFMDemodGUI()
void on_squelch_valueChanged(int value)
QByteArray serialize() const
void setReverseAPIChannelIndex(uint16_t channelIndex)
void resetContextMenuType()
Definition: rollupwidget.h:50
void addChannelMarker(ChannelMarker *channelMarker)
Add channel marker to spectrum.
Definition: deviceuiset.cpp:72
void channelMarkerHighlightedByCursor()
void on_volume_valueChanged(int value)
const WFMDemodSettings & getSettings() const
Definition: wfmdemod.h:55
void applySettings(bool force=false)
static WFMDemodGUI * create(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSink *rxChannel)
Definition: wfmdemodgui.cpp:22
ContextMenuType m_contextMenuType
Definition: rollupwidget.h:33
PluginAPI * m_pluginAPI
Definition: wfmdemodgui.h:44
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
bool deserialize(const QByteArray &data)
bool m_doApplySettings
Definition: wfmdemodgui.h:49
void channelMarkerChangedByCursor()
uint16_t m_reverseAPIDeviceIndex
bool getSquelchOpen() const
Definition: wfmdemod.h:124
virtual void setMessageQueueToGUI(MessageQueue *queue)
static int requiredBW(int rfBW)
Definition: wfmdemod.h:158
static DSPEngine * instance()
Definition: dspengine.cpp:51
void enterEvent(QEvent *)
void getMagSqLevels(double &avg, double &peak, int &nbSamples)
Definition: wfmdemod.h:126
QString m_reverseAPIAddress
void setTitleColor(const QColor &c)
void on_audioMute_toggled(bool checked)
void setHighlighted(bool highlighted)
void registerRxChannelInstance(const QString &channelName, PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:82
void displaySettings()
void addRollupWidget(QWidget *widget)
Add rollup widget to channel window.
Definition: deviceuiset.cpp:77
void removeRxChannelInstance(PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:94
void on_afBW_valueChanged(int value)
const QString & getTitle() const
Definition: channelmarker.h:38
void blockApplySettings(bool block)
static bool match(const Message *message)
Definition: message.cpp:45
bool getHighlighted() const
Definition: channelmarker.h:61
void handleInputMessages()
Definition: wfmdemodgui.cpp:97
void on_deltaFrequency_changed(qint64 value)
WFMDemodSettings m_settings
Definition: wfmdemodgui.h:47
static MsgConfigureChannelizer * create(int sampleRate, int centerFrequency)
Definition: wfmdemod.h:81
DeviceUISet * m_deviceUISet
Definition: wfmdemodgui.h:45
static const QString m_channelIdURI
Definition: wfmdemod.h:167
void resetToDefaults()
Definition: wfmdemodgui.cpp:54
void setReverseAPIAddress(const QString &address)
void setHighlighted(bool highlighted)
bool m_squelchOpen
Definition: wfmdemodgui.h:51
static MsgConfigureWFMDemod * create(const WFMDemodSettings &settings, bool force)
Definition: wfmdemod.h:58
void setColor(const QColor &color)
void setVisible(bool visible)
QString getName() const
Definition: wfmdemodgui.cpp:38
void setBandwidth(int bandwidth)
const QColor & getColor() const
Definition: channelmarker.h:64
void setTitle(const QString &title)
void setChannelMarker(Serializable *channelMarker)
QByteArray serialize() const
Definition: wfmdemodgui.cpp:61
void setName(const QString &name)
Definition: wfmdemodgui.cpp:33
void setCenterFrequency(int centerFrequency)
void on_rfBW_changed(quint64 value)
void onWidgetRolled(QWidget *widget, bool rollDown)
void widgetRolled(QWidget *widget, bool rollDown)
ChannelMarker m_channelMarker
Definition: wfmdemodgui.h:46
void audioSelect()
void setUseReverseAPI(bool useReverseAPI)
virtual bool handleMessage(const Message &message)
Definition: wfmdemodgui.cpp:78
bool deserialize(const QByteArray &data)
Definition: wfmdemodgui.cpp:66
virtual MessageQueue * getInputMessageQueue()
Definition: wfmdemodgui.h:35
static const int m_rfBWMax