From 58709e0baeafc28d93907e3104bc42ba16b5d324 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 14 May 2016 18:12:39 +0200 Subject: [PATCH] Multi device support: add channels from device control working concept --- plugins/channel/demodam/amplugin.cpp | 10 ++++------ plugins/channel/demodam/amplugin.h | 4 +--- sdrbase/gui/samplingdevicecontrol.cpp | 17 +++++++++++++++++ sdrbase/gui/samplingdevicecontrol.h | 2 ++ sdrbase/mainwindow.cpp | 4 +++- sdrbase/plugin/pluginmanager.cpp | 18 ++++++++++++++++++ sdrbase/plugin/pluginmanager.h | 6 +++++- 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/plugins/channel/demodam/amplugin.cpp b/plugins/channel/demodam/amplugin.cpp index 4a12874fd..6aa195939 100644 --- a/plugins/channel/demodam/amplugin.cpp +++ b/plugins/channel/demodam/amplugin.cpp @@ -30,25 +30,23 @@ void AMPlugin::initPlugin(PluginAPI* pluginAPI) // register AM demodulator QAction* action = new QAction(tr("&AM Demodulator"), this); - connect(action, SIGNAL(triggered()), this, SLOT(createInstanceAM())); +// connect(action, SIGNAL(triggered()), this, SLOT(createInstanceAM())); m_pluginAPI->registerChannel("de.maintech.sdrangelove.channel.am", this, action); } PluginGUI* AMPlugin::createChannel(const QString& channelName) { if(channelName == "de.maintech.sdrangelove.channel.am") { - AMDemodGUI* gui = AMDemodGUI::create(m_pluginAPI); - m_pluginAPI->registerChannelInstance("de.maintech.sdrangelove.channel.am", gui); - m_pluginAPI->addChannelRollup(gui); - return gui; + return createInstanceAM(); } else { return NULL; } } -void AMPlugin::createInstanceAM() +PluginGUI* AMPlugin::createInstanceAM() { AMDemodGUI* gui = AMDemodGUI::create(m_pluginAPI); m_pluginAPI->registerChannelInstance("de.maintech.sdrangelove.channel.am", gui); m_pluginAPI->addChannelRollup(gui); + return gui; } diff --git a/plugins/channel/demodam/amplugin.h b/plugins/channel/demodam/amplugin.h index 3c974f310..cdf293a2c 100644 --- a/plugins/channel/demodam/amplugin.h +++ b/plugins/channel/demodam/amplugin.h @@ -21,9 +21,7 @@ private: static const PluginDescriptor m_pluginDescriptor; PluginAPI* m_pluginAPI; - -private slots: - void createInstanceAM(); + PluginGUI* createInstanceAM(); }; #endif // INCLUDE_AMPLUGIN_H diff --git a/sdrbase/gui/samplingdevicecontrol.cpp b/sdrbase/gui/samplingdevicecontrol.cpp index db21994c0..d0ba20535 100644 --- a/sdrbase/gui/samplingdevicecontrol.cpp +++ b/sdrbase/gui/samplingdevicecontrol.cpp @@ -38,6 +38,14 @@ QComboBox *SamplingDeviceControl::getDeviceSelector() return ui->deviceSelect; } +void SamplingDeviceControl::populateChannelSelector() +{ + if (m_pluginManager) + { + m_pluginManager->populateChannelComboBox(ui->channelSelect); + } +} + void SamplingDeviceControl::on_showLoadedPlugins_clicked(bool checked) { if (m_pluginManager) @@ -46,3 +54,12 @@ void SamplingDeviceControl::on_showLoadedPlugins_clicked(bool checked) pluginsDialog.exec(); } } + +void SamplingDeviceControl::on_addChannel_clicked(bool checked) +{ + if (m_pluginManager) + { + m_pluginManager->createChannelInstance(ui->channelSelect->currentIndex()); + } +} + diff --git a/sdrbase/gui/samplingdevicecontrol.h b/sdrbase/gui/samplingdevicecontrol.h index 1380c8fd6..b019e04cf 100644 --- a/sdrbase/gui/samplingdevicecontrol.h +++ b/sdrbase/gui/samplingdevicecontrol.h @@ -39,6 +39,7 @@ public: void setPluginManager(PluginManager *pluginManager) { m_pluginManager = pluginManager; } QComboBox *getDeviceSelector(); + void populateChannelSelector(); private: Ui::SamplingDeviceControl* ui; @@ -46,6 +47,7 @@ private: private slots: void on_showLoadedPlugins_clicked(bool checked); + void on_addChannel_clicked(bool checked); }; diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index 15a9a3e0f..ece4c8b32 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -191,9 +191,11 @@ void MainWindow::addDevice() PluginManager *pluginManager = new PluginManager(this, m_deviceUIs.size()-1, dspDeviceEngine, m_deviceUIs.back()->m_spectrum); m_deviceUIs.back()->m_pluginManager = pluginManager; - m_deviceUIs.back()->m_samplingDeviceControl->setPluginManager(pluginManager); pluginManager->loadPlugins(); + m_deviceUIs.back()->m_samplingDeviceControl->setPluginManager(pluginManager); + m_deviceUIs.back()->m_samplingDeviceControl->populateChannelSelector(); + dspDeviceEngine->addSink(m_deviceUIs.back()->m_spectrumVis); ui->tabSpectra->addTab(m_deviceUIs.back()->m_spectrum, tabNameCStr); ui->tabSpectraGUI->addTab(m_deviceUIs.back()->m_spectrumGUI, tabNameCStr); diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index c9f771952..96d7c5e85 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -519,3 +519,21 @@ void PluginManager::renameChannelInstances() m_channelInstanceRegistrations[i].m_gui->setName(QString("%1:%2").arg(m_channelInstanceRegistrations[i].m_channelName).arg(i)); } } + +void PluginManager::populateChannelComboBox(QComboBox *channels) +{ + for(ChannelRegistrations::iterator it = m_channelRegistrations.begin(); it != m_channelRegistrations.end(); ++it) + { + const PluginDescriptor& pluginDescipror = it->m_plugin->getPluginDescriptor(); + channels->addItem(pluginDescipror.displayedName); + } +} + +void PluginManager::createChannelInstance(int channelPluginIndex) +{ + if (channelPluginIndex < m_channelRegistrations.size()) + { + PluginInterface *pluginInterface = m_channelRegistrations[channelPluginIndex].m_plugin; + pluginInterface->createChannel(m_channelRegistrations[channelPluginIndex].m_channelName); + } +} diff --git a/sdrbase/plugin/pluginmanager.h b/sdrbase/plugin/pluginmanager.h index cd3f8c5fc..43114a152 100644 --- a/sdrbase/plugin/pluginmanager.h +++ b/sdrbase/plugin/pluginmanager.h @@ -45,12 +45,13 @@ public: void loadPlugins(); const Plugins& getPlugins() const { return m_plugins; } + // Callbacks from the plugins void registerChannel(const QString& channelName, PluginInterface* plugin, QAction* action); void registerChannelInstance(const QString& channelName, PluginGUI* pluginGUI); void addChannelRollup(QWidget* pluginGUI); void removeChannelInstance(PluginGUI* pluginGUI); - void registerSampleSource(const QString& sourceName, PluginInterface* plugin); + void setInputGUI(QWidget* gui); void addSink(SampleSink* sink); @@ -89,6 +90,9 @@ public: int selectFirstSampleSource(const QString& sourceId); int selectSampleSourceBySerialOrSequence(const QString& sourceId, const QString& sourceSerial, int sourceSequence); + void populateChannelComboBox(QComboBox *channels); + void createChannelInstance(int channelPluginIndex); + private: struct ChannelRegistration { QString m_channelName;