1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-28 18:58:48 -05:00

Moved device and feature sets add and remove signals where appropriate. Improves #1139

This commit is contained in:
f4exb 2022-03-23 05:53:12 +01:00
parent 90620eed62
commit 8a3f15ba45
11 changed files with 55 additions and 35 deletions

View File

@ -92,40 +92,40 @@ void DeviceSet::deleteChannel(int channelIndex)
} }
} }
void DeviceSet::addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI) ChannelAPI *DeviceSet::addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
{ {
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // Available channel plugins PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getRxChannelRegistrations(); // Available channel plugins
ChannelAPI *rxChannel; ChannelAPI *rxChannel;
(*channelRegistrations)[selectedChannelIndex].m_plugin->createRxChannel(m_deviceAPI, nullptr, &rxChannel); (*channelRegistrations)[selectedChannelIndex].m_plugin->createRxChannel(m_deviceAPI, nullptr, &rxChannel);
ChannelAPI *channelAPI = rxChannel; m_channelInstanceRegistrations.append(rxChannel);
m_channelInstanceRegistrations.append(channelAPI); MainCore::instance()->addChannelInstance(this, rxChannel);
MainCore::instance()->addChannelInstance(this, channelAPI);
renameChannelInstances(); renameChannelInstances();
qDebug("DeviceSet::addRxChannel: %s", qPrintable(rxChannel->getName())); qDebug("DeviceSet::addRxChannel: %s", qPrintable(rxChannel->getName()));
return rxChannel;
} }
void DeviceSet::addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI) ChannelAPI *DeviceSet::addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
{ {
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations(); // Available channel plugins PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getTxChannelRegistrations(); // Available channel plugins
ChannelAPI *txChannel; ChannelAPI *txChannel;
(*channelRegistrations)[selectedChannelIndex].m_plugin->createTxChannel(m_deviceAPI, nullptr, &txChannel); (*channelRegistrations)[selectedChannelIndex].m_plugin->createTxChannel(m_deviceAPI, nullptr, &txChannel);
ChannelAPI *channelAPI = txChannel; m_channelInstanceRegistrations.append(txChannel);
m_channelInstanceRegistrations.append(channelAPI); MainCore::instance()->addChannelInstance(this, txChannel);
MainCore::instance()->addChannelInstance(this, channelAPI);
renameChannelInstances(); renameChannelInstances();
qDebug("DeviceSet::addTxChannel: %s", qPrintable(txChannel->getName())); qDebug("DeviceSet::addTxChannel: %s", qPrintable(txChannel->getName()));
return txChannel;
} }
void DeviceSet::addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI) ChannelAPI *DeviceSet::addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI)
{ {
PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getMIMOChannelRegistrations(); // Available channel plugins PluginAPI::ChannelRegistrations *channelRegistrations = pluginAPI->getMIMOChannelRegistrations(); // Available channel plugins
ChannelAPI *mimoChannel; ChannelAPI *mimoChannel;
(*channelRegistrations)[selectedChannelIndex].m_plugin->createMIMOChannel(m_deviceAPI, nullptr, &mimoChannel); (*channelRegistrations)[selectedChannelIndex].m_plugin->createMIMOChannel(m_deviceAPI, nullptr, &mimoChannel);
ChannelAPI *channelAPI = mimoChannel; m_channelInstanceRegistrations.append(mimoChannel);
m_channelInstanceRegistrations.append(channelAPI); MainCore::instance()->addChannelInstance(this, mimoChannel);
MainCore::instance()->addChannelInstance(this, channelAPI);
renameChannelInstances(); renameChannelInstances();
qDebug("DeviceSet::addMIMOChannel: %s", qPrintable(mimoChannel->getName())); qDebug("DeviceSet::addMIMOChannel: %s", qPrintable(mimoChannel->getName()));
return mimoChannel;
} }
void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI) void DeviceSet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)

View File

@ -61,9 +61,9 @@ public:
void saveTxChannelSettings(Preset* preset); void saveTxChannelSettings(Preset* preset);
void loadMIMOChannelSettings(const Preset* preset, PluginAPI *pluginAPI); void loadMIMOChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
void saveMIMOChannelSettings(Preset* preset); void saveMIMOChannelSettings(Preset* preset);
void addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI); ChannelAPI *addRxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
void addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI); ChannelAPI *addTxChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
void addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI); ChannelAPI *addMIMOChannel(int selectedChannelIndex, PluginAPI *pluginAPI);
// slave mode // slave mode
void addChannelInstance(ChannelAPI *channelAPI); void addChannelInstance(ChannelAPI *channelAPI);
void removeChannelInstanceAt(int index); void removeChannelInstanceAt(int index);

View File

@ -136,7 +136,13 @@ public:
} }
int getIndexInFeatureSet() const { return m_indexInFeatureSet; } int getIndexInFeatureSet() const { return m_indexInFeatureSet; }
void setIndexInFeatureSet(int indexInFeatureSet) { m_indexInFeatureSet = indexInFeatureSet; }
void setIndexInFeatureSet(int indexInFeatureSet)
{
m_indexInFeatureSet = indexInFeatureSet;
emit indexInFeatureSetChanged(m_indexInFeatureSet);
}
uint64_t getUID() const { return m_uid; } uint64_t getUID() const { return m_uid; }
FeatureState getState() const { return m_state; } FeatureState getState() const { return m_state; }
const QString& getErrorMessage() const { return m_errorMessage; } const QString& getErrorMessage() const { return m_errorMessage; }
@ -164,6 +170,9 @@ private:
QString m_uri; //!< Unique non modifiable identifier attached to channel type QString m_uri; //!< Unique non modifiable identifier attached to channel type
uint64_t m_uid; uint64_t m_uid;
int m_indexInFeatureSet; int m_indexInFeatureSet;
signals:
void indexInFeatureSetChanged(int index);
}; };
#endif // SDRBASE_FETURE_FEATUREAPI_H_ #endif // SDRBASE_FETURE_FEATUREAPI_H_

View File

@ -34,7 +34,7 @@ FeatureSet::~FeatureSet()
{ {
} }
void FeatureSet::addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter) Feature *FeatureSet::addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter)
{ {
PluginAPI::FeatureRegistrations *featureRegistrations = pluginAPI->getFeatureRegistrations(); // Available feature plugins PluginAPI::FeatureRegistrations *featureRegistrations = pluginAPI->getFeatureRegistrations(); // Available feature plugins
Feature *feature = featureRegistrations->at(selectedFeatureIndex).m_plugin->createFeature(apiAdapter); Feature *feature = featureRegistrations->at(selectedFeatureIndex).m_plugin->createFeature(apiAdapter);
@ -43,6 +43,7 @@ void FeatureSet::addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebA
m_featureInstanceRegistrations.append(feature); m_featureInstanceRegistrations.append(feature);
MainCore::instance()->addFeatureInstance(this, feature); MainCore::instance()->addFeatureInstance(this, feature);
renameFeatureInstances(); renameFeatureInstances();
return feature;
} }
void FeatureSet::removeFeatureInstance(Feature* feature) void FeatureSet::removeFeatureInstance(Feature* feature)

View File

@ -36,7 +36,7 @@ public:
int getNumberOfFeatures() const { return m_featureInstanceRegistrations.size(); } int getNumberOfFeatures() const { return m_featureInstanceRegistrations.size(); }
int getIndex() const { return m_featureTabIndex; } int getIndex() const { return m_featureTabIndex; }
void addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter); Feature *addFeature(int selectedFeatureIndex, PluginAPI *pluginAPI, WebAPIAdapterInterface *apiAdapter);
void removeFeatureInstance(Feature* feature); void removeFeatureInstance(Feature* feature);
void freeFeatures(); void freeFeatures();
void deleteFeature(int featureIndex); void deleteFeature(int featureIndex);

View File

@ -133,11 +133,6 @@ DeviceAPI *MainCore::getDevice(unsigned int deviceSetIndex)
} }
} }
void MainCore::sendDeviceChanged(int deviceSetIndex)
{
emit deviceChanged(deviceSetIndex);
}
ChannelAPI *MainCore::getChannel(unsigned int deviceSetIndex, int channelIndex) ChannelAPI *MainCore::getChannel(unsigned int deviceSetIndex, int channelIndex)
{ {
if (deviceSetIndex < m_deviceSets.size()) { if (deviceSetIndex < m_deviceSets.size()) {
@ -162,7 +157,6 @@ void MainCore::appendFeatureSet()
FeatureSet *featureSet = new FeatureSet(newIndex); FeatureSet *featureSet = new FeatureSet(newIndex);
m_featureSets.push_back(featureSet); m_featureSets.push_back(featureSet);
m_featureSetsMap.insert(featureSet, newIndex); m_featureSetsMap.insert(featureSet, newIndex);
emit featureSetAdded(newIndex);
} }
void MainCore::removeFeatureSet(unsigned int index) void MainCore::removeFeatureSet(unsigned int index)
@ -172,7 +166,6 @@ void MainCore::removeFeatureSet(unsigned int index)
FeatureSet *featureSet = m_featureSets[index]; FeatureSet *featureSet = m_featureSets[index];
m_featureSetsMap.remove(featureSet); m_featureSetsMap.remove(featureSet);
m_featureSets.erase(m_featureSets.begin() + index); m_featureSets.erase(m_featureSets.begin() + index);
emit featureSetRemoved(index);
} }
} }
@ -180,11 +173,9 @@ void MainCore::removeLastFeatureSet()
{ {
if (m_featureSets.size() != 0) if (m_featureSets.size() != 0)
{ {
int size = m_featureSets.size();
FeatureSet *featureSet = m_featureSets.back(); FeatureSet *featureSet = m_featureSets.back();
m_featureSetsMap.remove(featureSet); m_featureSetsMap.remove(featureSet);
m_featureSets.pop_back(); m_featureSets.pop_back();
emit featureSetRemoved(size - 1);
} }
} }
@ -194,18 +185,15 @@ void MainCore::appendDeviceSet(int deviceType)
DeviceSet *deviceSet = new DeviceSet(newIndex, deviceType); DeviceSet *deviceSet = new DeviceSet(newIndex, deviceType);
m_deviceSets.push_back(deviceSet); m_deviceSets.push_back(deviceSet);
m_deviceSetsMap.insert(deviceSet, newIndex); m_deviceSetsMap.insert(deviceSet, newIndex);
emit deviceSetAdded(newIndex, deviceSet->m_deviceAPI);
} }
void MainCore::removeLastDeviceSet() void MainCore::removeLastDeviceSet()
{ {
if (m_deviceSets.size() != 0) if (m_deviceSets.size() != 0)
{ {
int size = m_deviceSets.size();
DeviceSet *deviceSet = m_deviceSets.back(); DeviceSet *deviceSet = m_deviceSets.back();
m_deviceSetsMap.remove(deviceSet); m_deviceSetsMap.remove(deviceSet);
m_deviceSets.pop_back(); m_deviceSets.pop_back();
emit deviceSetRemoved(size - 1);
} }
} }

View File

@ -716,7 +716,6 @@ public:
std::vector<FeatureSet*>& getFeatureeSets() { return m_featureSets; } std::vector<FeatureSet*>& getFeatureeSets() { return m_featureSets; }
void setLoggingOptions(); void setLoggingOptions();
DeviceAPI *getDevice(unsigned int deviceSetIndex); DeviceAPI *getDevice(unsigned int deviceSetIndex);
void sendDeviceChanged(int deviceSetIndex);
ChannelAPI *getChannel(unsigned int deviceSetIndex, int channelIndex); ChannelAPI *getChannel(unsigned int deviceSetIndex, int channelIndex);
Feature *getFeature(unsigned int featureSetIndex, int featureIndex); Feature *getFeature(unsigned int featureSetIndex, int featureIndex);
bool existsChannel(const ChannelAPI *channel) const { return m_channelsMap.contains(const_cast<ChannelAPI*>(channel)); } bool existsChannel(const ChannelAPI *channel) const { return m_channelsMap.contains(const_cast<ChannelAPI*>(channel)); }

View File

@ -151,6 +151,11 @@ void DeviceUISet::deleteChannel(int channelIndex)
m_deviceSet->removeChannelInstanceAt(channelIndex); m_deviceSet->removeChannelInstanceAt(channelIndex);
} }
ChannelAPI *DeviceUISet::getChannelAt(int channelIndex)
{
return m_deviceSet->getChannelAt(channelIndex);
}
void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI) void DeviceUISet::loadRxChannelSettings(const Preset *preset, PluginAPI *pluginAPI)
{ {
if (preset->isSourcePreset()) if (preset->isSourcePreset())

View File

@ -72,6 +72,7 @@ public:
int getNumberOfChannels() const { return m_channelInstanceRegistrations.size(); } int getNumberOfChannels() const { return m_channelInstanceRegistrations.size(); }
void freeChannels(); void freeChannels();
void deleteChannel(int channelIndex); void deleteChannel(int channelIndex);
ChannelAPI *getChannelAt(int channelIndex);
void loadRxChannelSettings(const Preset* preset, PluginAPI *pluginAPI); void loadRxChannelSettings(const Preset* preset, PluginAPI *pluginAPI);
void saveRxChannelSettings(Preset* preset); void saveRxChannelSettings(Preset* preset);
void loadTxChannelSettings(const Preset* preset, PluginAPI *pluginAPI); void loadTxChannelSettings(const Preset* preset, PluginAPI *pluginAPI);

View File

@ -412,6 +412,7 @@ void MainWindow::addSourceDevice(int deviceIndex)
m_deviceUIs.back()->m_deviceGUI = pluginGUI; m_deviceUIs.back()->m_deviceGUI = pluginGUI;
m_deviceUIs.back()->m_deviceAPI->getSampleSource()->init(); m_deviceUIs.back()->m_deviceAPI->getSampleSource()->init();
setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName()); setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName());
emit m_mainCore->deviceSetAdded(deviceTabIndex, deviceAPI);
} }
void MainWindow::addSinkDevice() void MainWindow::addSinkDevice()
@ -489,6 +490,7 @@ void MainWindow::addSinkDevice()
m_deviceUIs.back()->m_deviceGUI = pluginGUI; m_deviceUIs.back()->m_deviceGUI = pluginGUI;
m_deviceUIs.back()->m_deviceAPI->getSampleSink()->init(); m_deviceUIs.back()->m_deviceAPI->getSampleSink()->init();
setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName(), 1); setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName(), 1);
emit m_mainCore->deviceSetAdded(deviceTabIndex, deviceAPI);
} }
void MainWindow::addMIMODevice() void MainWindow::addMIMODevice()
@ -574,11 +576,14 @@ void MainWindow::addMIMODevice()
m_deviceUIs.back()->m_deviceGUI = pluginGUI; m_deviceUIs.back()->m_deviceGUI = pluginGUI;
m_deviceUIs.back()->m_deviceAPI->getSampleMIMO()->init(); m_deviceUIs.back()->m_deviceAPI->getSampleMIMO()->init();
setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName(), 2); setDeviceGUI(deviceTabIndex, gui, deviceAPI->getSamplingDeviceDisplayName(), 2);
emit m_mainCore->deviceSetAdded(deviceTabIndex, deviceAPI);
} }
void MainWindow::removeLastDevice() void MainWindow::removeLastDevice()
{ {
if (m_deviceUIs.back()->m_deviceSourceEngine) // source tab int removedTabIndex = m_deviceUIs.size() - 1;
if (m_deviceUIs.back()->m_deviceSourceEngine) // source tab
{ {
DSPDeviceSourceEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceSourceEngine; DSPDeviceSourceEngine *lastDeviceEngine = m_deviceUIs.back()->m_deviceSourceEngine;
lastDeviceEngine->stopAcquistion(); lastDeviceEngine->stopAcquistion();
@ -677,6 +682,7 @@ void MainWindow::removeLastDevice()
m_deviceUIs.pop_back(); m_deviceUIs.pop_back();
m_mainCore->removeLastDeviceSet(); m_mainCore->removeLastDeviceSet();
emit m_mainCore->deviceSetRemoved(removedTabIndex);
} }
void MainWindow::addFeatureSet() void MainWindow::addFeatureSet()
@ -685,6 +691,7 @@ void MainWindow::addFeatureSet()
m_mainCore->appendFeatureSet(); m_mainCore->appendFeatureSet();
m_featureUIs.push_back(new FeatureUISet(tabIndex, m_mainCore->m_featureSets[tabIndex])); m_featureUIs.push_back(new FeatureUISet(tabIndex, m_mainCore->m_featureSets[tabIndex]));
ui->tabFeatures->addTab(m_featureUIs.back()->m_featureWindow, QString("F%1").arg(tabIndex)); ui->tabFeatures->addTab(m_featureUIs.back()->m_featureWindow, QString("F%1").arg(tabIndex));
emit m_mainCore->featureSetAdded(tabIndex);
} }
void MainWindow::removeFeatureSet(unsigned int tabIndex) void MainWindow::removeFeatureSet(unsigned int tabIndex)
@ -694,6 +701,7 @@ void MainWindow::removeFeatureSet(unsigned int tabIndex)
delete m_featureUIs[tabIndex]; delete m_featureUIs[tabIndex];
m_featureUIs.pop_back(); m_featureUIs.pop_back();
m_mainCore->removeFeatureSet(tabIndex); m_mainCore->removeFeatureSet(tabIndex);
emit m_mainCore->featureSetRemoved(tabIndex);
} }
} }
@ -1964,7 +1972,7 @@ void MainWindow::samplingDeviceChanged(int deviceType, int tabIndex, int newDevi
sampleMIMOChanged(tabIndex, newDeviceIndex); sampleMIMOChanged(tabIndex, newDeviceIndex);
} }
MainCore::instance()->sendDeviceChanged(tabIndex); emit MainCore::instance()->deviceChanged(tabIndex);
} }
void MainWindow::sampleSourceChanged(int tabIndex, int newDeviceIndex) void MainWindow::sampleSourceChanged(int tabIndex, int newDeviceIndex)

View File

@ -311,6 +311,7 @@ void MainServer::addSinkDevice()
DeviceSampleSink *sink = deviceAPI->getPluginInterface()->createSampleSinkPluginInstance( DeviceSampleSink *sink = deviceAPI->getPluginInterface()->createSampleSinkPluginInstance(
deviceAPI->getSamplingDeviceId(), deviceAPI); deviceAPI->getSamplingDeviceId(), deviceAPI);
deviceAPI->setSampleSink(sink); deviceAPI->setSampleSink(sink);
emit m_mainCore->deviceSetAdded(deviceTabIndex, deviceAPI);
} }
void MainServer::addSourceDevice() void MainServer::addSourceDevice()
@ -357,6 +358,7 @@ void MainServer::addSourceDevice()
DeviceSampleSource *source = deviceAPI->getPluginInterface()->createSampleSourcePluginInstance( DeviceSampleSource *source = deviceAPI->getPluginInterface()->createSampleSourcePluginInstance(
deviceAPI->getSamplingDeviceId(), deviceAPI); deviceAPI->getSamplingDeviceId(), deviceAPI);
deviceAPI->setSampleSource(source); deviceAPI->setSampleSource(source);
emit m_mainCore->deviceSetAdded(deviceTabIndex, deviceAPI);
} }
void MainServer::addMIMODevice() void MainServer::addMIMODevice()
@ -401,10 +403,13 @@ void MainServer::addMIMODevice()
DeviceSampleMIMO *mimo = deviceAPI->getPluginInterface()->createSampleMIMOPluginInstance( DeviceSampleMIMO *mimo = deviceAPI->getPluginInterface()->createSampleMIMOPluginInstance(
deviceAPI->getSamplingDeviceId(), deviceAPI); deviceAPI->getSamplingDeviceId(), deviceAPI);
m_mainCore->m_deviceSets.back()->m_deviceAPI->setSampleMIMO(mimo); m_mainCore->m_deviceSets.back()->m_deviceAPI->setSampleMIMO(mimo);
emit m_mainCore->deviceSetAdded(deviceTabIndex, deviceAPI);
} }
void MainServer::removeLastDevice() void MainServer::removeLastDevice()
{ {
int removedTabIndex = m_mainCore->m_deviceSets.size() - 1;
if (m_mainCore->m_deviceSets.back()->m_deviceSourceEngine) // source set if (m_mainCore->m_deviceSets.back()->m_deviceSourceEngine) // source set
{ {
DSPDeviceSourceEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceSourceEngine; DSPDeviceSourceEngine *lastDeviceEngine = m_mainCore->m_deviceSets.back()->m_deviceSourceEngine;
@ -447,6 +452,7 @@ void MainServer::removeLastDevice()
} }
m_mainCore->m_deviceSets.pop_back(); m_mainCore->m_deviceSets.pop_back();
emit m_mainCore->deviceSetRemoved(removedTabIndex);
} }
void MainServer::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex) void MainServer::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex)
@ -531,7 +537,7 @@ void MainServer::changeSampleSource(int deviceSetIndex, int selectedDeviceIndex)
deviceSet->m_deviceAPI->loadSamplingDeviceSettings(m_mainCore->m_settings.getWorkingPreset()); // load new API settings deviceSet->m_deviceAPI->loadSamplingDeviceSettings(m_mainCore->m_settings.getWorkingPreset()); // load new API settings
// Notify // Notify
m_mainCore->sendDeviceChanged(deviceSetIndex); emit m_mainCore->deviceChanged(deviceSetIndex);
} }
} }
@ -701,12 +707,15 @@ void MainServer::deleteChannel(int deviceSetIndex, int channelIndex)
void MainServer::addFeatureSet() void MainServer::addFeatureSet()
{ {
m_mainCore->appendFeatureSet(); m_mainCore->appendFeatureSet();
emit m_mainCore->featureSetAdded(m_mainCore->getFeatureeSets().size() - 1);
} }
void MainServer::removeFeatureSet(unsigned int featureSetIndex) void MainServer::removeFeatureSet(unsigned int featureSetIndex)
{ {
if (featureSetIndex < m_mainCore->m_featureSets.size()) { if (featureSetIndex < m_mainCore->m_featureSets.size())
{
m_mainCore->removeFeatureSet(featureSetIndex); m_mainCore->removeFeatureSet(featureSetIndex);
emit m_mainCore->featureSetRemoved(featureSetIndex);
} }
} }