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.
localsourcegui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include <QLocale>
19 
20 #include "device/deviceuiset.h"
23 #include "mainwindow.h"
24 
25 #include "localsourcegui.h"
26 #include "localsource.h"
27 #include "ui_localsourcegui.h"
28 
30 {
31  LocalSourceGUI* gui = new LocalSourceGUI(pluginAPI, deviceUISet, channelTx);
32  return gui;
33 }
34 
36 {
37  delete this;
38 }
39 
40 void LocalSourceGUI::setName(const QString& name)
41 {
42  setObjectName(name);
43 }
44 
45 QString LocalSourceGUI::getName() const
46 {
47  return objectName();
48 }
49 
51  return 0;
52 }
53 
54 void LocalSourceGUI::setCenterFrequency(qint64 centerFrequency)
55 {
56  (void) centerFrequency;
57 }
58 
60 {
63  applySettings(true);
64 }
65 
66 QByteArray LocalSourceGUI::serialize() const
67 {
68  return m_settings.serialize();
69 }
70 
71 bool LocalSourceGUI::deserialize(const QByteArray& data)
72 {
73  if(m_settings.deserialize(data)) {
75  applySettings(true);
76  return true;
77  } else {
79  return false;
80  }
81 }
82 
84 {
86  {
88  //m_channelMarker.setBandwidth(notif.getSampleRate());
89  m_sampleRate = notif.getSampleRate();
91  return true;
92  }
94  {
96  m_settings = cfg.getSettings();
97  blockApplySettings(true);
99  blockApplySettings(false);
100  return true;
101  }
102  else
103  {
104  return false;
105  }
106 }
107 
108 LocalSourceGUI::LocalSourceGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *channeltx, QWidget* parent) :
109  RollupWidget(parent),
110  ui(new Ui::LocalSourceGUI),
111  m_pluginAPI(pluginAPI),
112  m_deviceUISet(deviceUISet),
113  m_sampleRate(0),
114  m_tickCount(0)
115 {
116  ui->setupUi(this);
117  setAttribute(Qt::WA_DeleteOnClose, true);
118  connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
119  connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
120 
121  m_localSource = (LocalSource*) channeltx;
123 
124  m_channelMarker.blockSignals(true);
127  m_channelMarker.setTitle("Local Source");
129  m_channelMarker.blockSignals(false);
130  m_channelMarker.setVisible(true); // activate signal on the last setting only
131 
133 
137 
138  connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages()));
139  //connect(&(m_deviceUISet->m_deviceSourceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
140 
141  m_time.start();
142 
144  displaySettings();
145  applySettings(true);
146 }
147 
149 {
151  delete m_localSource; // TODO: check this: when the GUI closes it has to delete the demodulator
152  delete ui;
153 }
154 
156 {
157  m_doApplySettings = !block;
158 }
159 
161 {
162  if (m_doApplySettings)
163  {
165 
168  }
169 }
170 
172 {
173  if (m_doApplySettings)
174  {
179  }
180 }
181 
183 {
184  m_channelMarker.blockSignals(true);
188  m_channelMarker.setMovable(false); // do not let user move the center arbitrarily
189  m_channelMarker.blockSignals(false);
190  m_channelMarker.setColor(m_settings.m_rgbColor); // activate signal on the last setting only
191 
193  setWindowTitle(m_channelMarker.getTitle());
194 
195  blockApplySettings(true);
196  ui->interpolationFactor->setCurrentIndex(m_settings.m_log2Interp);
198  blockApplySettings(false);
199 }
200 
202 {
203  int shift = m_shiftFrequencyFactor * m_sampleRate;
204  double channelSampleRate = ((double) m_sampleRate) / (1<<m_settings.m_log2Interp);
205  QLocale loc;
206  ui->offsetFrequencyText->setText(tr("%1 Hz").arg(loc.toString(shift)));
207  ui->channelRateText->setText(tr("%1k").arg(QString::number(channelSampleRate / 1000.0, 'g', 5)));
209  m_channelMarker.setBandwidth(channelSampleRate);
210 }
211 
213 {
214  std::vector<uint32_t> localDevicesIndexes;
215  m_localSource->getLocalDevices(localDevicesIndexes);
216  ui->localDevice->clear();
217  std::vector<uint32_t>::const_iterator it = localDevicesIndexes.begin();
218 
219  for (; it != localDevicesIndexes.end(); ++it) {
220  ui->localDevice->addItem(tr("%1").arg(*it), QVariant(*it));
221  }
222 }
223 
225 {
227 }
228 
230 {
232 }
233 
235 {
236  Message* message;
237 
238  while ((message = getInputMessageQueue()->pop()) != 0)
239  {
240  if (handleMessage(*message))
241  {
242  delete message;
243  }
244  }
245 }
246 
247 void LocalSourceGUI::onWidgetRolled(QWidget* widget, bool rollDown)
248 {
249  (void) widget;
250  (void) rollDown;
251 }
252 
254 {
256  {
263 
264  dialog.move(p);
265  dialog.exec();
266 
274 
275  setWindowTitle(m_settings.m_title);
277 
278  applySettings();
279  }
280 
282 }
283 
285 {
286  m_settings.m_log2Interp = index;
288 }
289 
291 {
293  applyPosition();
294 }
295 
297 {
298  m_settings.m_localDeviceIndex = ui->localDevice->itemData(index).toInt();
299  applySettings();
300 }
301 
303 {
304  (void) checked;
306 }
307 
309 {
310  uint32_t maxHash = 1;
311 
312  for (uint32_t i = 0; i < m_settings.m_log2Interp; i++) {
313  maxHash *= 3;
314  }
315 
316  ui->position->setMaximum(maxHash-1);
317  ui->position->setValue(m_settings.m_filterChainHash);
318  m_settings.m_filterChainHash = ui->position->value();
319  applyPosition();
320 }
321 
323 {
324  ui->filterChainIndex->setText(tr("%1").arg(m_settings.m_filterChainHash));
325  QString s;
327  ui->filterChainText->setText(s);
328 
331 }
332 
334 {
335  if (++m_tickCount == 20) { // once per second
336  m_tickCount = 0;
337  }
338 }
void removeTxChannelInstance(PluginInstanceGUI *pluginGUI)
const QString & getReverseAPIAddress() const
LocalSourceGUI(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *txChannel, QWidget *parent=0)
void registerTxChannelInstance(const QString &channelName, PluginInstanceGUI *pluginGUI)
Definition: deviceuiset.cpp:88
static MsgConfigureChannelizer * create(unsigned int m_log2Interp, unsigned int m_filterChainHash)
Definition: localsource.h:91
void push(Message *message, bool emitSignal=true)
Push message onto queue.
const LocalSourceSettings & getSettings() const
Definition: localsource.h:45
ChannelMarker m_channelMarker
void handleSourceMessages()
void onMenuDialogCalled(const QPoint &p)
static MsgConfigureLocalSource * create(const LocalSourceSettings &settings, bool force)
Definition: localsource.h:48
PluginAPI * m_pluginAPI
static const QString m_channelIdURI
Definition: localsource.h:152
QByteArray serialize() const
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
void setReverseAPIChannelIndex(uint16_t channelIndex)
void getLocalDevices(std::vector< uint32_t > &indexes)
void resetContextMenuType()
Definition: rollupwidget.h:50
void addChannelMarker(ChannelMarker *channelMarker)
Add channel marker to spectrum.
Definition: deviceuiset.cpp:72
virtual ~LocalSourceGUI()
void on_localDevicesRefresh_clicked(bool checked)
unsigned int uint32_t
Definition: rtptypes_win.h:46
ContextMenuType m_contextMenuType
Definition: rollupwidget.h:33
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
void setReverseAPIDeviceIndex(uint16_t deviceIndex)
virtual bool handleMessage(const Message &message)
virtual qint64 getCenterFrequency() const
void enterEvent(QEvent *)
static double convertToString(unsigned int log2, unsigned int chainHash, QString &chainString)
void applySettings(bool force=false)
QByteArray serialize() const
uint32_t m_tickCount
void setSourceOrSinkStream(bool sourceOrSinkStream)
Definition: channelmarker.h:75
void setMovable(bool movable)
Definition: channelmarker.h:66
void setTitleColor(const QColor &c)
void displayRateAndShift()
void setHighlighted(bool highlighted)
virtual void setCenterFrequency(qint64 centerFrequency)
void applyChannelSettings()
int32_t i
Definition: decimators.h:244
void addRollupWidget(QWidget *widget)
Add rollup widget to channel window.
Definition: deviceuiset.cpp:77
virtual void setMessageQueueToGUI(MessageQueue *queue)
const QString & getTitle() const
Definition: channelmarker.h:38
static bool match(const Message *message)
Definition: message.cpp:45
void setChannelMarker(Serializable *channelMarker)
void on_interpolationFactor_currentIndexChanged(int index)
LocalSourceSettings m_settings
bool deserialize(const QByteArray &data)
QString getName() const
static LocalSourceGUI * create(PluginAPI *pluginAPI, DeviceUISet *deviceUISet, BasebandSampleSource *txChannel)
void setReverseAPIAddress(const QString &address)
void on_localDevice_currentIndexChanged(int index)
void setColor(const QColor &color)
void blockApplySettings(bool block)
void leaveEvent(QEvent *)
virtual MessageQueue * getInputMessageQueue()
LocalSource * m_localSource
void setVisible(bool visible)
void setBandwidth(int bandwidth)
const QColor & getColor() const
Definition: channelmarker.h:64
void setTitle(const QString &title)
void on_position_valueChanged(int value)
Ui::LocalSourceGUI * ui
DeviceUISet * m_deviceUISet
void setCenterFrequency(int centerFrequency)
void onWidgetRolled(QWidget *widget, bool rollDown)
void widgetRolled(QWidget *widget, bool rollDown)
void setUseReverseAPI(bool useReverseAPI)
bool deserialize(const QByteArray &data)
void setName(const QString &name)
virtual void destroy()
double m_shiftFrequencyFactor
Channel frequency shift factor.