changeset 1581:11660e0c896f audio-source-refactor

Use shared_ptr for plugin instances throughout; also descriptors are copyable
author Chris Cannam
date Fri, 20 Mar 2020 16:31:23 +0000
parents a2ff9c01889e
children 1da52d5e6700
files widgets/PluginParameterBox.cpp widgets/PluginParameterBox.h widgets/PluginParameterDialog.cpp widgets/PluginParameterDialog.h widgets/PluginReviewDialog.cpp
diffstat 5 files changed, 19 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/PluginParameterBox.cpp	Fri Jan 24 15:11:08 2020 +0000
+++ b/widgets/PluginParameterBox.cpp	Fri Mar 20 16:31:23 2020 +0000
@@ -34,7 +34,8 @@
 
 #include <cmath>
 
-PluginParameterBox::PluginParameterBox(Vamp::PluginBase *plugin, QWidget *parent) :
+PluginParameterBox::PluginParameterBox(std::shared_ptr<Vamp::PluginBase> plugin,
+                                       QWidget *parent) :
     QFrame(parent),
     m_plugin(plugin),
     m_programCombo(nullptr)
@@ -100,7 +101,7 @@
         float value = m_plugin->getParameter(params[i].identifier);
 
         int hint = PortHint::NoHint;
-        RealTimePluginInstance *rtpi = dynamic_cast<RealTimePluginInstance *>
+        auto rtpi = std::dynamic_pointer_cast<RealTimePluginInstance>
             (m_plugin);
         if (rtpi) {
             hint = rtpi->getParameterDisplayHint(i);
--- a/widgets/PluginParameterBox.h	Fri Jan 24 15:11:08 2020 +0000
+++ b/widgets/PluginParameterBox.h	Fri Mar 20 16:31:23 2020 +0000
@@ -32,10 +32,11 @@
     Q_OBJECT
     
 public:
-    PluginParameterBox(Vamp::PluginBase *, QWidget *parent = 0);
+    PluginParameterBox(std::shared_ptr<Vamp::PluginBase>,
+                       QWidget *parent = 0);
     ~PluginParameterBox();
 
-    Vamp::PluginBase *getPlugin() { return m_plugin; }
+    std::shared_ptr<Vamp::PluginBase> getPlugin() { return m_plugin; }
 
 signals:
     void pluginConfigurationChanged(QString);
@@ -51,7 +52,7 @@
     void updateProgramCombo();
 
     QGridLayout *m_layout;
-    Vamp::PluginBase *m_plugin;
+    std::shared_ptr<Vamp::PluginBase> m_plugin;
 
     struct ParamRec {
         AudioDial *dial;
--- a/widgets/PluginParameterDialog.cpp	Fri Jan 24 15:11:08 2020 +0000
+++ b/widgets/PluginParameterDialog.cpp	Fri Mar 20 16:31:23 2020 +0000
@@ -43,7 +43,7 @@
 
 #include "base/Debug.h"
 
-PluginParameterDialog::PluginParameterDialog(Vamp::PluginBase *plugin,
+PluginParameterDialog::PluginParameterDialog(std::shared_ptr<Vamp::PluginBase> plugin,
                                              QWidget *parent) :
     QDialog(parent),
     m_plugin(plugin),
@@ -368,9 +368,7 @@
 
     if (showWindowSize) {
 
-        Vamp::Plugin *fePlugin = dynamic_cast<Vamp::Plugin *>(m_plugin);
-        if (!fePlugin) fePlugin = dynamic_cast<Vamp::PluginHostAdapter *>(m_plugin);
-        if (!fePlugin) fePlugin = dynamic_cast<Vamp::HostExt::PluginWrapper *>(m_plugin);
+        auto fePlugin = std::dynamic_pointer_cast<Vamp::Plugin>(m_plugin);
         int size = 1024;
         int increment = 1024;
         if (fePlugin) {
--- a/widgets/PluginParameterDialog.h	Fri Jan 24 15:11:08 2020 +0000
+++ b/widgets/PluginParameterDialog.h	Fri Mar 20 16:31:23 2020 +0000
@@ -43,7 +43,8 @@
     Q_OBJECT
     
 public:
-    PluginParameterDialog(Vamp::PluginBase *, QWidget *parent = 0);
+    PluginParameterDialog(std::shared_ptr<Vamp::PluginBase> plugin,
+                          QWidget *parent = 0);
     ~PluginParameterDialog();
 
     void setChannelArrangement(int sourceChannels,
@@ -61,7 +62,7 @@
                                  QString defaultName);
     void setShowSelectionOnlyOption(bool show);
 
-    Vamp::PluginBase *getPlugin() { return m_plugin; }
+    std::shared_ptr<Vamp::PluginBase> getPlugin() { return m_plugin; }
 
     int getChannel() const { return m_channel; }
 
@@ -93,7 +94,7 @@
     void dialogAccepted();
 
 protected:
-    Vamp::PluginBase *m_plugin;
+    std::shared_ptr<Vamp::PluginBase> m_plugin;
 
     int m_channel;
     int m_stepSize;
--- a/widgets/PluginReviewDialog.cpp	Fri Jan 24 15:11:08 2020 +0000
+++ b/widgets/PluginReviewDialog.cpp	Fri Mar 20 16:31:23 2020 +0000
@@ -90,13 +90,13 @@
 
     for (QString id: dssiIds) {
         auto descriptor = dssiFactory->getPluginDescriptor(id);
-        if (!descriptor) continue;
+        if (descriptor.name == "") continue;
         m_table->setItem(row, typeCol, new QTableWidgetItem
                          (tr("DSSI")));
         m_table->setItem(row, idCol, new QTableWidgetItem
-                         (QString::fromStdString(descriptor->label)));
+                         (QString::fromStdString(descriptor.label)));
         m_table->setItem(row, nameCol, new QTableWidgetItem
-                         (QString::fromStdString(descriptor->name)));
+                         (QString::fromStdString(descriptor.name)));
         QString path = dssiFactory->getPluginLibraryPath(id);
         m_table->setItem(row, libCol, new QTableWidgetItem
                          (QFileInfo(path).fileName()));
@@ -107,13 +107,13 @@
 
     for (QString id: ladspaIds) {
         auto descriptor = ladspaFactory->getPluginDescriptor(id);
-        if (!descriptor) continue;
+        if (descriptor.name == "") continue;
         m_table->setItem(row, typeCol, new QTableWidgetItem
                          (tr("LADSPA")));
         m_table->setItem(row, idCol, new QTableWidgetItem
-                         (QString::fromStdString(descriptor->label)));
+                         (QString::fromStdString(descriptor.label)));
         m_table->setItem(row, nameCol, new QTableWidgetItem
-                         (QString::fromStdString(descriptor->name)));
+                         (QString::fromStdString(descriptor.name)));
         QString path = ladspaFactory->getPluginLibraryPath(id);
         m_table->setItem(row, libCol, new QTableWidgetItem
                          (QFileInfo(path).fileName()));