1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

Implement MainCore in MainWindow step3: device sets

This commit is contained in:
f4exb 2020-10-11 08:27:58 +02:00
parent 96329326b4
commit febbb4fa0f
6 changed files with 85 additions and 36 deletions

View File

@ -53,6 +53,11 @@ public:
void addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
void addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
void addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
// slave mode
void addChannelInstance(const QString& channelURI, ChannelAPI *channelAPI);
void removeChannelInstanceAt(int index);
void removeChannelInstance(ChannelAPI *channelAPI);
void clearChannels();
private:
struct ChannelInstanceRegistration

View File

@ -22,6 +22,7 @@
#include "loggerwithfile.h"
#include "dsp/dsptypes.h"
#include "feature/featureset.h"
#include "device/deviceset.h"
#include "maincore.h"
@ -123,3 +124,16 @@ void MainCore::removeLastFeatureSet()
m_featureSets.pop_back();
}
}
void MainCore::appendDeviceSet(int deviceType)
{
int newIndex = m_deviceSets.size();
m_deviceSets.push_back(new DeviceSet(newIndex, deviceType));
}
void MainCore::removeLastDeviceSet()
{
if (m_deviceSets.size() != 0) {
m_deviceSets.pop_back();
}
}

View File

@ -414,6 +414,8 @@ public:
void appendFeatureSet();
void removeFeatureSet(int index);
void removeLastFeatureSet();
void appendDeviceSet(int deviceType);
void removeLastDeviceSet();
friend class MainServer;
friend class MainWindow;

View File

@ -26,6 +26,7 @@
#include "gui/glspectrumgui.h"
#include "gui/channelwindow.h"
#include "device/devicegui.h"
#include "device/deviceset.h"
#include "plugin/pluginapi.h"
#include "plugin/plugininterface.h"
#include "channel/channelutils.h"
@ -35,7 +36,7 @@
#include "deviceuiset.h"
DeviceUISet::DeviceUISet(int tabIndex, int deviceType, QTimer& timer)
DeviceUISet::DeviceUISet(int tabIndex, DeviceSet *deviceSet, int deviceType, QTimer& timer)
{
m_spectrum = new GLSpectrum;
@ -60,6 +61,7 @@ DeviceUISet::DeviceUISet(int tabIndex, int deviceType, QTimer& timer)
m_deviceSinkEngine = nullptr;
m_deviceMIMOEngine = nullptr;
m_deviceTabIndex = tabIndex;
m_deviceSet = deviceSet;
m_nbAvailableRxChannels = 0; // updated at enumeration for UI selector
m_nbAvailableTxChannels = 0; // updated at enumeration for UI selector
m_nbAvailableMIMOChannels = 0; // updated at enumeration for UI selector
@ -97,6 +99,7 @@ void DeviceUISet::addRollupWidget(QWidget *widget)
void DeviceUISet::registerRxChannelInstance(const QString& channelName, ChannelAPI *channelAPI, ChannelGUI* channelGUI)
{
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI, channelGUI, 0));
m_deviceSet->addChannelInstance(channelName, channelAPI);
QObject::connect(
channelGUI,
&ChannelGUI::closing,
@ -109,6 +112,7 @@ void DeviceUISet::registerRxChannelInstance(const QString& channelName, ChannelA
void DeviceUISet::registerTxChannelInstance(const QString& channelName, ChannelAPI *channelAPI, ChannelGUI* channelGUI)
{
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI, channelGUI, 1));
m_deviceSet->addChannelInstance(channelName, channelAPI);
QObject::connect(
channelGUI,
&ChannelGUI::closing,
@ -121,6 +125,7 @@ void DeviceUISet::registerTxChannelInstance(const QString& channelName, ChannelA
void DeviceUISet::registerChannelInstance(const QString& channelName, ChannelAPI *channelAPI, ChannelGUI* channelGUI)
{
m_channelInstanceRegistrations.append(ChannelInstanceRegistration(channelName, channelAPI, channelGUI, 2));
m_deviceSet->addChannelInstance(channelName, channelAPI);
QObject::connect(
channelGUI,
&ChannelGUI::closing,
@ -138,6 +143,8 @@ void DeviceUISet::freeChannels()
m_channelInstanceRegistrations[i].m_gui->destroy();
m_channelInstanceRegistrations[i].m_channelAPI->destroy();
}
m_deviceSet->clearChannels();
}
void DeviceUISet::deleteChannel(int channelIndex)
@ -150,6 +157,8 @@ void DeviceUISet::deleteChannel(int channelIndex)
m_channelInstanceRegistrations[channelIndex].m_gui->destroy();
m_channelInstanceRegistrations[channelIndex].m_channelAPI->destroy();
}
m_deviceSet->removeChannelInstanceAt(channelIndex);
}
void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
@ -172,6 +181,7 @@ void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginA
}
m_channelInstanceRegistrations.clear();
m_deviceSet->clearChannels();
qDebug("DeviceUISet::loadRxChannelSettings: %d channel(s) in preset", preset->getChannelCount());
for (int i = 0; i < preset->getChannelCount(); i++)
@ -256,6 +266,7 @@ void DeviceUISet::loadTxChannelSettings(const Preset *preset, PluginAPI *pluginA
}
m_channelInstanceRegistrations.clear();
m_deviceSet->clearChannels();
qDebug("DeviceUISet::loadTxChannelSettings: %d channel(s) in preset", preset->getChannelCount());
for(int i = 0; i < preset->getChannelCount(); i++)
@ -340,6 +351,7 @@ void DeviceUISet::loadMIMOChannelSettings(const Preset *preset, PluginAPI *plugi
}
m_channelInstanceRegistrations.clear();
m_deviceSet->clearChannels();
qDebug("DeviceUISet::loadMIMOChannelSettings: %d channel(s) in preset", preset->getChannelCount());
for (int i = 0; i < preset->getChannelCount(); i++)
@ -431,6 +443,7 @@ void DeviceUISet::handleChannelGUIClosing(ChannelGUI* channelGUI)
{
if (it->m_gui == channelGUI)
{
m_deviceSet->removeChannelInstance(it->m_channelAPI);
it->m_channelAPI->destroy();
m_channelInstanceRegistrations.erase(it);
break;

View File

@ -29,6 +29,7 @@ class GLSpectrum;
class GLSpectrumGUI;
class ChannelWindow;
class DeviceAPI;
class DeviceSet;
class DSPDeviceSourceEngine;
class DSPDeviceSinkEngine;
class DSPDeviceMIMOEngine;
@ -54,7 +55,7 @@ public:
DSPDeviceMIMOEngine *m_deviceMIMOEngine;
QByteArray m_mainWindowState;
DeviceUISet(int tabIndex, int deviceType, QTimer& timer);
DeviceUISet(int tabIndex, DeviceSet *deviceSet, int deviceType, QTimer& timer);
~DeviceUISet();
GLSpectrum *getSpectrum() { return m_spectrum; } //!< Direct spectrum getter
@ -114,6 +115,7 @@ private:
// ChannelInstanceRegistrations m_txChannelInstanceRegistrations;
ChannelInstanceRegistrations m_channelInstanceRegistrations;
int m_deviceTabIndex;
DeviceSet *m_deviceSet;
int m_nbAvailableRxChannels; //!< Number of Rx channels available for selection
int m_nbAvailableTxChannels; //!< Number of Tx channels available for selection
int m_nbAvailableMIMOChannels; //!< Number of MIMO channels available for selection

View File

@ -32,6 +32,7 @@
#include "device/devicegui.h"
#include "device/deviceapi.h"
#include "device/deviceuiset.h"
#include "device/deviceset.h"
#include "device/deviceenumerator.h"
#include "channel/channelapi.h"
#include "channel/channelgui.h"
@ -186,6 +187,7 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse
qDebug() << "MainWindow::MainWindow: load plugins...";
m_pluginManager = new PluginManager(this);
m_mainCore->m_pluginManager = m_pluginManager;
m_pluginManager->loadPlugins(QString("plugins"));
m_pluginManager->loadPluginsNonDiscoverable(m_mainCore->m_settings.getDeviceUserArgs());
@ -296,10 +298,14 @@ void MainWindow::addSourceDevice(int deviceIndex)
int deviceTabIndex = m_deviceUIs.size();
ui->inputViewDock->addDevice(0, deviceTabIndex);
m_deviceUIs.push_back(new DeviceUISet(deviceTabIndex, 0, m_mainCore->m_masterTimer));
m_mainCore->appendDeviceSet(0);
m_deviceUIs.push_back(new DeviceUISet(deviceTabIndex, m_mainCore->m_deviceSets.back(), 0, m_mainCore->m_masterTimer));
m_deviceUIs.back()->m_deviceSourceEngine = dspDeviceSourceEngine;
m_mainCore->m_deviceSets.back()->m_deviceSourceEngine = dspDeviceSourceEngine;
m_deviceUIs.back()->m_deviceSinkEngine = nullptr;
m_mainCore->m_deviceSets.back()->m_deviceSinkEngine = nullptr;
m_deviceUIs.back()->m_deviceMIMOEngine = nullptr;
m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = nullptr;
char tabNameCStr[16];
sprintf(tabNameCStr, "R%d", deviceTabIndex);
@ -307,6 +313,7 @@ void MainWindow::addSourceDevice(int deviceIndex)
DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleRx, deviceTabIndex, dspDeviceSourceEngine, nullptr, nullptr);
m_deviceUIs.back()->m_deviceAPI = deviceAPI;
m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI;
QList<QString> channelNames;
m_pluginManager->listRxChannels(channelNames);
m_deviceUIs.back()->setNumberOfAvailableRxChannels(channelNames.size());
@ -322,19 +329,19 @@ void MainWindow::addSourceDevice(int deviceIndex)
}
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(deviceIndex);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceUIs.back()->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
m_deviceUIs.back()->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
m_deviceUIs.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceUIs.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(deviceIndex));
deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getRxPluginInterface(deviceIndex));
QString userArgs = m_mainCore->m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence);
if (userArgs.size() > 0) {
m_deviceUIs.back()->m_deviceAPI->setHardwareUserArguments(userArgs);
deviceAPI->setHardwareUserArguments(userArgs);
}
ui->inputViewDock->setSelectedDeviceIndex(deviceTabIndex, deviceIndex);
@ -344,18 +351,18 @@ void MainWindow::addSourceDevice(int deviceIndex)
m_deviceUIs.back()->m_deviceGUI->destroy();
}
DeviceSampleSource *source = m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->createSampleSourcePluginInstance(
m_deviceUIs.back()->m_deviceAPI->getSamplingDeviceId(), m_deviceUIs.back()->m_deviceAPI);
m_deviceUIs.back()->m_deviceAPI->setSampleSource(source);
DeviceSampleSource *source = deviceAPI->getPluginInterface()->createSampleSourcePluginInstance(
deviceAPI->getSamplingDeviceId(), deviceAPI);
deviceAPI->setSampleSource(source);
QWidget *gui;
DeviceGUI *pluginGUI = m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->createSampleSourcePluginInstanceGUI(
m_deviceUIs.back()->m_deviceAPI->getSamplingDeviceId(),
DeviceGUI *pluginGUI = deviceAPI->getPluginInterface()->createSampleSourcePluginInstanceGUI(
deviceAPI->getSamplingDeviceId(),
&gui,
m_deviceUIs.back());
m_deviceUIs.back()->m_deviceAPI->getSampleSource()->setMessageQueueToGUI(pluginGUI->getInputMessageQueue());
deviceAPI->getSampleSource()->setMessageQueueToGUI(pluginGUI->getInputMessageQueue());
m_deviceUIs.back()->m_deviceGUI = pluginGUI;
m_deviceUIs.back()->m_deviceAPI->getSampleSource()->init();
setDeviceGUI(deviceTabIndex, gui, m_deviceUIs.back()->m_deviceAPI->getSamplingDeviceDisplayName());
setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName());
}
void MainWindow::addSinkDevice()
@ -370,10 +377,14 @@ void MainWindow::addSinkDevice()
int deviceTabIndex = m_deviceUIs.size();
ui->inputViewDock->addDevice(1, deviceTabIndex);
m_deviceUIs.push_back(new DeviceUISet(deviceTabIndex, 1, m_mainCore->m_masterTimer));
m_mainCore->appendDeviceSet(1);
m_deviceUIs.push_back(new DeviceUISet(deviceTabIndex, m_mainCore->m_deviceSets.back(), 1, m_mainCore->m_masterTimer));
m_deviceUIs.back()->m_deviceSourceEngine = nullptr;
m_mainCore->m_deviceSets.back()->m_deviceSourceEngine = nullptr;
m_deviceUIs.back()->m_deviceSinkEngine = dspDeviceSinkEngine;
m_mainCore->m_deviceSets.back()->m_deviceSinkEngine = dspDeviceSinkEngine;
m_deviceUIs.back()->m_deviceMIMOEngine = nullptr;
m_mainCore->m_deviceSets.back()->m_deviceMIMOEngine = nullptr;
char tabNameCStr[16];
sprintf(tabNameCStr, "T%d", deviceTabIndex);
@ -381,6 +392,7 @@ void MainWindow::addSinkDevice()
DeviceAPI *deviceAPI = new DeviceAPI(DeviceAPI::StreamSingleTx, deviceTabIndex, nullptr, dspDeviceSinkEngine, nullptr);
m_deviceUIs.back()->m_deviceAPI = deviceAPI;
m_mainCore->m_deviceSets.back()->m_deviceAPI = deviceAPI;
QList<QString> channelNames;
m_pluginManager->listTxChannels(channelNames);
m_deviceUIs.back()->setNumberOfAvailableTxChannels(channelNames.size());
@ -394,19 +406,19 @@ void MainWindow::addSinkDevice()
// create a file sink by default
int fileSinkDeviceIndex = DeviceEnumerator::instance()->getFileOutputDeviceIndex();
const PluginInterface::SamplingDevice *samplingDevice = DeviceEnumerator::instance()->getTxSamplingDevice(fileSinkDeviceIndex);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
m_deviceUIs.back()->m_deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
m_deviceUIs.back()->m_deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
m_deviceUIs.back()->m_deviceAPI->setHardwareId(samplingDevice->hardwareId);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceId(samplingDevice->id);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
m_deviceUIs.back()->m_deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
m_deviceUIs.back()->m_deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex));
deviceAPI->setSamplingDeviceSequence(samplingDevice->sequence);
deviceAPI->setDeviceNbItems(samplingDevice->deviceNbItems);
deviceAPI->setDeviceItemIndex(samplingDevice->deviceItemIndex);
deviceAPI->setHardwareId(samplingDevice->hardwareId);
deviceAPI->setSamplingDeviceId(samplingDevice->id);
deviceAPI->setSamplingDeviceSerial(samplingDevice->serial);
deviceAPI->setSamplingDeviceDisplayName(samplingDevice->displayedName);
deviceAPI->setSamplingDevicePluginInterface(DeviceEnumerator::instance()->getTxPluginInterface(fileSinkDeviceIndex));
QString userArgs = m_mainCore->m_settings.getDeviceUserArgs().findUserArgs(samplingDevice->hardwareId, samplingDevice->sequence);
if (userArgs.size() > 0) {
m_deviceUIs.back()->m_deviceAPI->setHardwareUserArguments(userArgs);
deviceAPI->setHardwareUserArguments(userArgs);
}
ui->inputViewDock->setSelectedDeviceIndex(deviceTabIndex, fileSinkDeviceIndex);
@ -416,18 +428,18 @@ void MainWindow::addSinkDevice()
m_deviceUIs.back()->m_deviceGUI->destroy();
}
DeviceSampleSink *sink = m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->createSampleSinkPluginInstance(
m_deviceUIs.back()->m_deviceAPI->getSamplingDeviceId(), m_deviceUIs.back()->m_deviceAPI);
m_deviceUIs.back()->m_deviceAPI->setSampleSink(sink);
DeviceSampleSink *sink = deviceAPI->getPluginInterface()->createSampleSinkPluginInstance(
deviceAPI->getSamplingDeviceId(), deviceAPI);
deviceAPI->setSampleSink(sink);
QWidget *gui;
DeviceGUI *pluginGUI = m_deviceUIs.back()->m_deviceAPI->getPluginInterface()->createSampleSinkPluginInstanceGUI(
m_deviceUIs.back()->m_deviceAPI->getSamplingDeviceId(),
DeviceGUI *pluginGUI = deviceAPI->getPluginInterface()->createSampleSinkPluginInstanceGUI(
deviceAPI->getSamplingDeviceId(),
&gui,
m_deviceUIs.back());
m_deviceUIs.back()->m_deviceAPI->getSampleSink()->setMessageQueueToGUI(pluginGUI->getInputMessageQueue());
deviceAPI->getSampleSink()->setMessageQueueToGUI(pluginGUI->getInputMessageQueue());
m_deviceUIs.back()->m_deviceGUI = pluginGUI;
m_deviceUIs.back()->m_deviceAPI->getSampleSink()->init();
setDeviceGUI(deviceTabIndex, gui, m_deviceUIs.back()->m_deviceAPI->getSamplingDeviceDisplayName(), 1);
setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName(), 1);
}
void MainWindow::removeLastDevice()
@ -551,6 +563,7 @@ void MainWindow::removeLastDevice()
}
m_deviceUIs.pop_back();
m_mainCore->removeLastDeviceSet();
}
void MainWindow::addFeatureSet()