Consolidate VST Plugin Info
authorRobin Gareus <robin@gareus.org>
Wed, 7 Nov 2018 22:37:10 +0000 (23:37 +0100)
committerRobin Gareus <robin@gareus.org>
Wed, 7 Nov 2018 22:37:10 +0000 (23:37 +0100)
This unifies common PluginManager VST code to construct *VSTPluginInfo
and also provides a dedicated is_instrument() method for VST plugins.

libs/ardour/ardour/lxvst_plugin.h
libs/ardour/ardour/mac_vst_plugin.h
libs/ardour/ardour/vst_plugin.h
libs/ardour/ardour/windows_vst_plugin.h
libs/ardour/lxvst_plugin.cc
libs/ardour/mac_vst_plugin.cc
libs/ardour/plugin_manager.cc
libs/ardour/vst_plugin.cc
libs/ardour/windows_vst_plugin.cc

index 5a35d9832e55b744fb4f6844c6bb0479e140eee4..25703956c7d9771e8bbe81496cc6e8eb383d2b0f 100644 (file)
@@ -40,10 +40,10 @@ class LIBARDOUR_API LXVSTPlugin : public VSTPlugin
        std::string state_node_name () const { return "lxvst"; }
 };
 
-class LIBARDOUR_API LXVSTPluginInfo : public PluginInfo
+class LIBARDOUR_API LXVSTPluginInfo : public VSTPluginInfo
 {
   public:
-       LXVSTPluginInfo ();
+       LXVSTPluginInfo (_VSTInfo*);
        ~LXVSTPluginInfo () {}
 
        PluginPtr load (Session& session);
index fa05dff80f8489adbebb11328334e14adb8959da..d7ab8c2698ca5bb119b07b0bec4e5b44f3a269fb 100644 (file)
@@ -42,10 +42,10 @@ protected:
        void open_plugin ();
 };
 
-class LIBARDOUR_API MacVSTPluginInfo : public PluginInfo
+class LIBARDOUR_API MacVSTPluginInfo : public VSTPluginInfo
 {
 public:
-       MacVSTPluginInfo ();
+       MacVSTPluginInfo (_VSTInfo*);
        ~MacVSTPluginInfo () {}
 
        PluginPtr load (Session& session);
index b2189143d3b8108324b8d347488d19941834b37f..21ac6775adf08527e7874044053399d07662da8a 100644 (file)
@@ -32,6 +32,8 @@ typedef struct _VSTState VSTState;
 
 #include "ardour/vestige/vestige.h"
 
+struct _VSTInfo;
+
 namespace ARDOUR {
 
 class PluginInsert;
@@ -134,6 +136,15 @@ protected:
        bool       _eff_bypassed;
 };
 
+class LIBARDOUR_API VSTPluginInfo : public PluginInfo
+{
+public:
+       VSTPluginInfo (_VSTInfo*);
+       bool is_instrument () const;
+protected:
+       bool _is_instrument;
+};
+
 }
 
 #endif
index 7566eab098a8eb6748ecbd7cb8b58a3206132899..fbbe8d1491780c2db56343f3b151dd919b87e780 100644 (file)
@@ -40,10 +40,10 @@ public:
        std::string state_node_name () const { return "windows-vst"; }
 };
 
-class LIBARDOUR_API WindowsVSTPluginInfo : public PluginInfo
+class LIBARDOUR_API WindowsVSTPluginInfo : public VSTPluginInfo
 {
 public:
-       WindowsVSTPluginInfo ();
+       WindowsVSTPluginInfo (_VSTInfo*);
        ~WindowsVSTPluginInfo () {}
 
        PluginPtr load (Session& session);
index 8bfd5d61d35abf88049cb6c2ff42b985f8440897..d9aa97138734a8c70b43822bd20ae584c42bbff5 100644 (file)
@@ -168,8 +168,8 @@ LXVSTPluginInfo::get_presets (bool user_only) const
        return p;
 }
 
-LXVSTPluginInfo::LXVSTPluginInfo()
+LXVSTPluginInfo::LXVSTPluginInfo (_VSTInfo* nfo) : VSTPluginInfo (nfo)
 {
-       type = ARDOUR::LXVST;
+       type = ARDOUR::LXVST;
 }
 
index 240da414a05d1b69130e940becda27aab6e67713..60ff7220bd23d87d4baa93ffec257672a9608b48 100644 (file)
@@ -175,7 +175,7 @@ MacVSTPluginInfo::get_presets (bool user_only) const
        return p;
 }
 
-MacVSTPluginInfo::MacVSTPluginInfo ()
+MacVSTPluginInfo::MacVSTPluginInfo (_VSTInfo* nfo) : VSTPluginInfo (nfo)
 {
        type = ARDOUR::MacVST;
 }
index aa151aa97505e40e7e97b143f47207eac911fb36..06a7e0ee774fed5f0773b7037f5782f179141e6e 100644 (file)
@@ -993,7 +993,6 @@ PluginManager::windows_vst_discover (string path, bool cache_only)
        uint32_t discovered = 0;
        for (vector<VSTInfo *>::iterator x = finfos->begin(); x != finfos->end(); ++x) {
                VSTInfo* finfo = *x;
-               char buf[32];
 
                if (!finfo->canProcessReplacing) {
                        warning << string_compose (_("VST plugin %1 does not support processReplacing, and cannot be used in %2 at this time"),
@@ -1002,33 +1001,14 @@ PluginManager::windows_vst_discover (string path, bool cache_only)
                        continue;
                }
 
-               PluginInfoPtr info (new WindowsVSTPluginInfo);
+               PluginInfoPtr info (new WindowsVSTPluginInfo (finfo));
+               info->path = path;
 
                /* what a joke freeware VST is */
-
                if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
                        info->name = PBD::basename_nosuffix (path);
-               } else {
-                       info->name = finfo->name;
                }
 
-
-               snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
-               info->unique_id = buf;
-               if (finfo->isInstrument) {
-                       info->category = X_("Instrument");
-               } else {
-                       info->category = finfo->Category;
-               }
-               info->path = path;
-               info->creator = finfo->creator;
-               info->index = 0;
-               info->n_inputs.set_audio (finfo->numInputs);
-               info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
-               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
-               info->type = ARDOUR::Windows_VST;
-
                /* if we don't have any tags for this plugin, make some up. */
                set_tags (info->type, info->unique_id, info->category, info->name, FromPlug);
 
@@ -1144,7 +1124,6 @@ PluginManager::mac_vst_discover (string path, bool cache_only)
        uint32_t discovered = 0;
        for (vector<VSTInfo *>::iterator x = finfos->begin(); x != finfos->end(); ++x) {
                VSTInfo* finfo = *x;
-               char buf[32];
 
                if (!finfo->canProcessReplacing) {
                        warning << string_compose (_("Mac VST plugin %1 does not support processReplacing, and so cannot be used in %2 at this time"),
@@ -1153,25 +1132,8 @@ PluginManager::mac_vst_discover (string path, bool cache_only)
                        continue;
                }
 
-               PluginInfoPtr info (new MacVSTPluginInfo);
-
-               info->name = finfo->name;
-
-               snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
-               info->unique_id = buf;
-               if (finfo->isInstrument) {
-                       info->category = X_("Instrument");
-               } else {
-                       info->category = finfo->Category;
-               }
+               PluginInfoPtr info (new MacVSTPluginInfo (finfo));
                info->path = path;
-               info->creator = finfo->creator;
-               info->index = 0;
-               info->n_inputs.set_audio (finfo->numInputs);
-               info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
-               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
-               info->type = ARDOUR::MacVST;
 
                /* if we don't have any tags for this plugin, make some up. */
                set_tags (info->type, info->unique_id, info->category, info->name, FromPlug);
@@ -1265,7 +1227,6 @@ PluginManager::lxvst_discover (string path, bool cache_only)
        uint32_t discovered = 0;
        for (vector<VSTInfo *>::iterator x = finfos->begin(); x != finfos->end(); ++x) {
                VSTInfo* finfo = *x;
-               char buf[32];
 
                if (!finfo->canProcessReplacing) {
                        warning << string_compose (_("linuxVST plugin %1 does not support processReplacing, and so cannot be used in %2 at this time"),
@@ -1274,31 +1235,13 @@ PluginManager::lxvst_discover (string path, bool cache_only)
                        continue;
                }
 
-               PluginInfoPtr info(new LXVSTPluginInfo);
+               PluginInfoPtr info(new LXVSTPluginInfo (finfo));
+               info->path = path;
 
                if (!strcasecmp ("The Unnamed plugin", finfo->name)) {
                        info->name = PBD::basename_nosuffix (path);
-               } else {
-                       info->name = finfo->name;
                }
 
-
-               snprintf (buf, sizeof (buf), "%d", finfo->UniqueID);
-               info->unique_id = buf;
-               if (finfo->isInstrument) {
-                       info->category = X_("Instrument");
-               } else {
-                       info->category = finfo->Category;
-               }
-               info->path = path;
-               info->creator = finfo->creator;
-               info->index = 0;
-               info->n_inputs.set_audio (finfo->numInputs);
-               info->n_outputs.set_audio (finfo->numOutputs);
-               info->n_inputs.set_midi ((finfo->wantMidi&1) ? 1 : 0);
-               info->n_outputs.set_midi ((finfo->wantMidi&2) ? 1 : 0);
-               info->type = ARDOUR::LXVST;
-
                set_tags (info->type, info->unique_id, info->category, info->name, FromPlug);
 
                /* Make sure we don't find the same plugin in more than one place along
index cbd88877cd8bcb033de9858471bd3ddc2c173599..4183283bffe0f4acf158c6132fcf9a4c7317eebc 100644 (file)
 #include "pbd/floating.h"
 #include "pbd/locale_guard.h"
 
+#include "ardour/vst_types.h"
 #include "ardour/vst_plugin.h"
 #include "ardour/vestige/vestige.h"
 #include "ardour/session.h"
-#include "ardour/vst_types.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/audio_buffer.h"
 
@@ -923,3 +923,31 @@ VSTPlugin::presets_file () const
        return string("vst-") + unique_id ();
 }
 
+
+VSTPluginInfo::VSTPluginInfo (VSTInfo* nfo)
+{
+
+       char buf[32];
+       snprintf (buf, sizeof (buf), "%d", nfo->UniqueID);
+       unique_id = buf;
+
+       index = 0;
+
+       name = nfo->name;
+       creator = nfo->creator;
+       n_inputs.set_audio  (nfo->numInputs);
+       n_outputs.set_audio (nfo->numOutputs);
+       n_inputs.set_midi  ((nfo->wantMidi & 1) ? 1 : 0);
+       n_outputs.set_midi ((nfo->wantMidi & 2) ? 1 : 0);
+
+       _is_instrument = nfo->isInstrument;
+}
+
+bool
+VSTPluginInfo::is_instrument () const
+{
+       if (_is_instrument) {
+               return true;
+       }
+       return PluginInfo::is_instrument ();
+}
index 4bfe8226459699f67c921262bf8a01c8a3a517f1..7a7caa9ed817cda11b25448b922d919fedc44d92 100644 (file)
@@ -134,8 +134,8 @@ WindowsVSTPluginInfo::get_presets (bool user_only) const
        return p;
 }
 
-WindowsVSTPluginInfo::WindowsVSTPluginInfo()
+WindowsVSTPluginInfo::WindowsVSTPluginInfo (_VSTInfo* nfo) : VSTPluginInfo (nfo)
 {
-       type = ARDOUR::Windows_VST;
+       type = ARDOUR::Windows_VST;
 }