kopia lustrzana https://github.com/f4exb/sdrangel
DeviceSinkAPI code cleanup
rodzic
d5d7d40102
commit
f71803f58e
|
@ -18,22 +18,15 @@
|
|||
#include "device/devicesinkapi.h"
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "dsp/devicesamplesink.h"
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "plugin/plugininterface.h"
|
||||
#include "gui/glspectrum.h"
|
||||
#include "gui/channelwindow.h"
|
||||
#include "settings/preset.h"
|
||||
#include "dsp/dspengine.h"
|
||||
|
||||
// TODO: extract GUI dependencies in a separate object
|
||||
DeviceSinkAPI::DeviceSinkAPI(int deviceTabIndex,
|
||||
DSPDeviceSinkEngine *deviceSinkEngine,
|
||||
GLSpectrum *glSpectrum,
|
||||
ChannelWindow *channelWindow) :
|
||||
DSPDeviceSinkEngine *deviceSinkEngine) :
|
||||
m_deviceTabIndex(deviceTabIndex),
|
||||
m_deviceSinkEngine(deviceSinkEngine),
|
||||
m_spectrum(glSpectrum),
|
||||
m_channelWindow(channelWindow),
|
||||
m_sampleSinkSequence(0),
|
||||
m_pluginInterface(0),
|
||||
m_sampleSinkPluginInstanceUI(0),
|
||||
|
@ -136,16 +129,6 @@ MessageQueue *DeviceSinkAPI::getSampleSinkGUIMessageQueue()
|
|||
return getSampleSink()->getMessageQueueToGUI();
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::addChannelMarker(ChannelMarker* channelMarker)
|
||||
{
|
||||
m_spectrum->addChannelMarker(channelMarker);
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::addRollupWidget(QWidget *widget)
|
||||
{
|
||||
m_channelWindow->addRollupWidget(widget);
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::setHardwareId(const QString& id)
|
||||
{
|
||||
m_hardwareId = id;
|
||||
|
@ -187,43 +170,6 @@ void DeviceSinkAPI::setSampleSinkPluginInstanceUI(PluginInstanceGUI *gui)
|
|||
m_sampleSinkPluginInstanceUI = gui;
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::registerChannelInstance(const QString& channelName, PluginInstanceGUI* pluginGUI)
|
||||
{
|
||||
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, pluginGUI));
|
||||
renameChannelInstances();
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::removeChannelInstance(PluginInstanceGUI* pluginGUI)
|
||||
{
|
||||
for(ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it)
|
||||
{
|
||||
if(it->m_gui == pluginGUI)
|
||||
{
|
||||
m_channelInstanceRegistrations.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
renameChannelInstances();
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::renameChannelInstances()
|
||||
{
|
||||
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
|
||||
{
|
||||
m_channelInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i].m_channelName).arg(i));
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::freeChannels()
|
||||
{
|
||||
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
|
||||
{
|
||||
qDebug("DeviceSinkAPI::freeAll: destroying channel [%s]", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
|
||||
m_channelInstanceRegistrations[i].m_gui->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::loadSinkSettings(const Preset* preset)
|
||||
{
|
||||
if (preset->isSourcePreset())
|
||||
|
@ -271,116 +217,6 @@ void DeviceSinkAPI::saveSinkSettings(Preset* preset)
|
|||
}
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::loadChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
|
||||
{
|
||||
if (preset->isSourcePreset())
|
||||
{
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: Loading preset [%s | %s] not a sink preset", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: Loading preset [%s | %s]", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
|
||||
|
||||
// Available channel plugins
|
||||
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations();
|
||||
|
||||
// copy currently open channels and clear list
|
||||
ChannelInstanceRegistrations openChannels = m_channelInstanceRegistrations;
|
||||
m_channelInstanceRegistrations.clear();
|
||||
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: %d channel(s) in preset", preset->getChannelCount());
|
||||
|
||||
for(int i = 0; i < preset->getChannelCount(); i++)
|
||||
{
|
||||
const Preset::ChannelConfig& channelConfig = preset->getChannelConfig(i);
|
||||
ChannelInstanceRegistration reg;
|
||||
|
||||
// if we have one instance available already, use it
|
||||
|
||||
for(int i = 0; i < openChannels.count(); i++)
|
||||
{
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: channels compare [%s] vs [%s]", qPrintable(openChannels[i].m_channelName), qPrintable(channelConfig.m_channel));
|
||||
|
||||
if(openChannels[i].m_channelName == channelConfig.m_channel)
|
||||
{
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: channel [%s] found", qPrintable(openChannels[i].m_channelName));
|
||||
reg = openChannels.takeAt(i);
|
||||
m_channelInstanceRegistrations.append(reg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we haven't one already, create one
|
||||
|
||||
if(reg.m_gui == 0)
|
||||
{
|
||||
for(int i = 0; i < channelRegistrations->count(); i++)
|
||||
{
|
||||
if((*channelRegistrations)[i].m_channelName == channelConfig.m_channel)
|
||||
{
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: creating new channel [%s]", qPrintable(channelConfig.m_channel));
|
||||
//reg = ChannelInstanceRegistration(channelConfig.m_channel, (*channelRegistrations)[i].m_plugin->createTxChannel(channelConfig.m_channel, this));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(reg.m_gui != 0)
|
||||
{
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: deserializing channel [%s]", qPrintable(channelConfig.m_channel));
|
||||
reg.m_gui->deserialize(channelConfig.m_config);
|
||||
}
|
||||
}
|
||||
|
||||
// everything, that is still "available" is not needed anymore
|
||||
for(int i = 0; i < openChannels.count(); i++)
|
||||
{
|
||||
qDebug("DeviceSinkAPI::loadChannelSettings: destroying spare channel [%s]", qPrintable(openChannels[i].m_channelName));
|
||||
openChannels[i].m_gui->destroy();
|
||||
}
|
||||
|
||||
renameChannelInstances();
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::saveChannelSettings(Preset *preset)
|
||||
{
|
||||
if (preset->isSourcePreset())
|
||||
{
|
||||
qDebug("DeviceSinkAPI::saveChannelSettings: not a sink preset");
|
||||
}
|
||||
else
|
||||
{
|
||||
qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
|
||||
|
||||
for(int i = 0; i < m_channelInstanceRegistrations.count(); i++)
|
||||
{
|
||||
qDebug("DeviceSinkAPI::saveChannelSettings: channel [%s] saved", qPrintable(m_channelInstanceRegistrations[i].m_channelName));
|
||||
preset->addChannel(m_channelInstanceRegistrations[i].m_channelName, m_channelInstanceRegistrations[i].m_gui->serialize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sort by increasing delta frequency and type (i.e. name)
|
||||
bool DeviceSinkAPI::ChannelInstanceRegistration::operator<(const ChannelInstanceRegistration& other) const
|
||||
{
|
||||
if (m_gui && other.m_gui)
|
||||
{
|
||||
if (m_gui->getCenterFrequency() == other.m_gui->getCenterFrequency())
|
||||
{
|
||||
return m_gui->getName() < other.m_gui->getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_gui->getCenterFrequency() < other.m_gui->getCenterFrequency();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceSinkAPI::addSourceBuddy(DeviceSourceAPI* buddy)
|
||||
{
|
||||
m_sourceBuddies.push_back(buddy);
|
||||
|
|
|
@ -23,16 +23,11 @@
|
|||
#include "dsp/dspdevicesinkengine.h"
|
||||
#include "util/export.h"
|
||||
|
||||
class GLSpectrum;
|
||||
class ChannelWindow;
|
||||
class BasebandSampleSource;
|
||||
class ThreadedBasebandSampleSource;
|
||||
class DeviceSampleSink;
|
||||
class MessageQueue;
|
||||
class ChannelMarker;
|
||||
class QWidget;
|
||||
class PluginInstanceGUI;
|
||||
class PluginAPI;
|
||||
class PluginInterface;
|
||||
class Preset;
|
||||
class DeviceSourceAPI;
|
||||
|
@ -42,9 +37,7 @@ class SDRANGEL_API DeviceSinkAPI : public QObject {
|
|||
|
||||
public:
|
||||
DeviceSinkAPI(int deviceTabIndex,
|
||||
DSPDeviceSinkEngine *deviceEngine,
|
||||
GLSpectrum *glSpectrum,
|
||||
ChannelWindow *channelWindow);
|
||||
DSPDeviceSinkEngine *deviceEngine);
|
||||
~DeviceSinkAPI();
|
||||
|
||||
// Device engine stuff
|
||||
|
@ -67,13 +60,6 @@ public:
|
|||
MessageQueue *getSampleSinkInputMessageQueue();
|
||||
MessageQueue *getSampleSinkGUIMessageQueue();
|
||||
|
||||
// device GUI related stuff
|
||||
void addChannelMarker(ChannelMarker* channelMarker); //!< Add channel marker to spectrum
|
||||
void addRollupWidget(QWidget *widget); //!< Add rollup widget to channel window
|
||||
void freeChannels();
|
||||
void loadChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
|
||||
void saveChannelSettings(Preset* preset);
|
||||
|
||||
void setHardwareId(const QString& id);
|
||||
void setSampleSinkId(const QString& id);
|
||||
void resetSampleSinkId();
|
||||
|
@ -115,32 +101,8 @@ public:
|
|||
const QTimer& getMasterTimer() const { return m_masterTimer; } //!< This is the DSPEngine master timer
|
||||
|
||||
protected:
|
||||
struct ChannelInstanceRegistration
|
||||
{
|
||||
QString m_channelName;
|
||||
PluginInstanceGUI* m_gui;
|
||||
|
||||
ChannelInstanceRegistration() :
|
||||
m_channelName(),
|
||||
m_gui(0)
|
||||
{ }
|
||||
|
||||
ChannelInstanceRegistration(const QString& channelName, PluginInstanceGUI* pluginGUI) :
|
||||
m_channelName(channelName),
|
||||
m_gui(pluginGUI)
|
||||
{ }
|
||||
|
||||
bool operator<(const ChannelInstanceRegistration& other) const;
|
||||
};
|
||||
|
||||
typedef QList<ChannelInstanceRegistration> ChannelInstanceRegistrations;
|
||||
|
||||
void renameChannelInstances();
|
||||
|
||||
int m_deviceTabIndex;
|
||||
DSPDeviceSinkEngine *m_deviceSinkEngine;
|
||||
GLSpectrum *m_spectrum;
|
||||
ChannelWindow *m_channelWindow;
|
||||
|
||||
QString m_hardwareId;
|
||||
QString m_sampleSinkId;
|
||||
|
@ -150,8 +112,6 @@ protected:
|
|||
PluginInterface* m_pluginInterface;
|
||||
PluginInstanceGUI* m_sampleSinkPluginInstanceUI;
|
||||
|
||||
ChannelInstanceRegistrations m_channelInstanceRegistrations;
|
||||
|
||||
std::vector<DeviceSourceAPI*> m_sourceBuddies; //!< Device source APIs referencing the same physical device
|
||||
std::vector<DeviceSinkAPI*> m_sinkBuddies; //!< Device sink APIs referencing the same physical device
|
||||
void *m_buddySharedPtr;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "device/devicesourceapi.h"
|
||||
#include "device/devicesinkapi.h"
|
||||
#include "dsp/devicesamplesource.h"
|
||||
#include "plugin/pluginapi.h"
|
||||
#include "plugin/plugininterface.h"
|
||||
#include "settings/preset.h"
|
||||
#include "dsp/dspengine.h"
|
||||
|
|
|
@ -29,9 +29,7 @@ class BasebandSampleSink;
|
|||
class ThreadedBasebandSampleSink;
|
||||
class DeviceSampleSource;
|
||||
class MessageQueue;
|
||||
class ChannelMarker;
|
||||
class PluginInstanceGUI;
|
||||
class PluginAPI;
|
||||
class PluginInterface;
|
||||
class Preset;
|
||||
class DeviceSinkAPI;
|
||||
|
|
|
@ -30,6 +30,7 @@ class DeviceSourceAPI;
|
|||
class DSPDeviceSinkEngine;
|
||||
class DeviceSinkAPI;
|
||||
class ChannelMarker;
|
||||
class PluginAPI;
|
||||
|
||||
struct DeviceUISet
|
||||
{
|
||||
|
|
|
@ -273,7 +273,7 @@ void MainWindow::addSinkDevice()
|
|||
char tabNameCStr[16];
|
||||
sprintf(tabNameCStr, "T%d", deviceTabIndex);
|
||||
|
||||
DeviceSinkAPI *deviceSinkAPI = new DeviceSinkAPI(deviceTabIndex, dspDeviceSinkEngine, m_deviceUIs.back()->m_spectrum, m_deviceUIs.back()->m_channelWindow);
|
||||
DeviceSinkAPI *deviceSinkAPI = new DeviceSinkAPI(deviceTabIndex, dspDeviceSinkEngine);
|
||||
|
||||
m_deviceUIs.back()->m_deviceSourceAPI = 0;
|
||||
m_deviceUIs.back()->m_deviceSinkAPI = deviceSinkAPI;
|
||||
|
@ -368,7 +368,7 @@ void MainWindow::removeLastDevice()
|
|||
ui->tabSpectra->removeTab(ui->tabSpectra->count() - 1);
|
||||
|
||||
// deletes old UI and output object
|
||||
m_deviceUIs.back()->m_deviceSinkAPI->freeChannels();
|
||||
m_deviceUIs.back()->freeTxChannels();
|
||||
m_deviceUIs.back()->m_deviceSinkAPI->getSampleSink()->setMessageQueueToGUI(0); // have sink stop sending messages to the GUI
|
||||
m_deviceUIs.back()->m_deviceSinkAPI->getPluginInterface()->deleteSampleSourcePluginInstanceGUI(
|
||||
m_deviceUIs.back()->m_deviceSinkAPI->getSampleSinkPluginInstanceGUI());
|
||||
|
|
|
@ -54,11 +54,6 @@ public:
|
|||
|
||||
// channel Rx plugins
|
||||
|
||||
// TODO: remove this one when migration is complete
|
||||
virtual PluginInstanceGUI* createRxChannel(
|
||||
const QString& channelName __attribute__((unused)),
|
||||
DeviceSourceAPI *deviceAPI __attribute__((unused)) )
|
||||
{ return 0; }
|
||||
virtual PluginInstanceGUI* createRxChannel(
|
||||
const QString& channelName __attribute__((unused)),
|
||||
DeviceUISet *deviceUISet __attribute__((unused)) )
|
||||
|
|
Ładowanie…
Reference in New Issue