API evolution
authorRobin Gareus <robin@gareus.org>
Sat, 9 Jan 2016 14:22:16 +0000 (15:22 +0100)
committerRobin Gareus <robin@gareus.org>
Sat, 9 Jan 2016 14:22:16 +0000 (15:22 +0100)
The Session-reference is only needed to instantiate/load the plugin.
Indexing presets is not supposed to call load() and be const WRT to
PluginInfo

libs/ardour/ardour/audio_unit.h
libs/ardour/ardour/ladspa_plugin.h
libs/ardour/ardour/lv2_plugin.h
libs/ardour/ardour/lxvst_plugin.h
libs/ardour/ardour/plugin.h
libs/ardour/ardour/windows_vst_plugin.h
libs/ardour/audio_unit.cc
libs/ardour/ladspa_plugin.cc
libs/ardour/lv2_plugin.cc
libs/ardour/lxvst_plugin.cc
libs/ardour/windows_vst_plugin.cc

index c495f010b3ad9de71761247a81d81b2df89b8325..e9a5622ea97a4a1689d2e6243b598798fa6001ab 100644 (file)
@@ -232,7 +232,7 @@ class LIBARDOUR_API AUPluginInfo : public PluginInfo {
 
        PluginPtr load (Session& session);
 
-       virtual std::vector<Plugin::PresetRecord> get_presets(Session& session);
+       std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
 
        bool needs_midi_input ();
        bool is_effect () const;
index 3336a31bf4635ba63e907abca243dc5deddd7faf..6fd214db6888d9df3e51473d2aad82efa6133bc9 100644 (file)
@@ -151,7 +151,7 @@ class LIBARDOUR_API LadspaPluginInfo : public PluginInfo {
        ~LadspaPluginInfo () { };
 
        PluginPtr load (Session& session);
-       virtual std::vector<Plugin::PresetRecord> get_presets(Session& session);
+       std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
 };
 
 typedef boost::shared_ptr<LadspaPluginInfo> LadspaPluginInfoPtr;
index 093d77817b7f72503a28e5526733029b945a2d97..a4cdfcd036f2bf69354953baeebf46903ad7cbd8 100644 (file)
@@ -281,7 +281,7 @@ public:
        static PluginInfoList* discover ();
 
        PluginPtr load (Session& session);
-       virtual std::vector<Plugin::PresetRecord> get_presets(Session& session);
+       std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
        virtual bool in_category (const std::string &c) const;
        virtual bool is_instrument() const;
 
index d58bc63d0647ee851f8062f7bf9638db7f98b7f0..5a35d9832e55b744fb4f6844c6bb0479e140eee4 100644 (file)
@@ -47,7 +47,7 @@ class LIBARDOUR_API LXVSTPluginInfo : public PluginInfo
        ~LXVSTPluginInfo () {}
 
        PluginPtr load (Session& session);
-       virtual std::vector<Plugin::PresetRecord> get_presets(Session&);
+       std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
 };
 
 } // namespace ARDOUR
index 07297c8cad3341ff872745b1f7cf3b3b369836a6..44090c3aeaacaca3307904046948e99724e5aa83 100644 (file)
@@ -336,7 +336,7 @@ class LIBARDOUR_API PluginInfo {
        virtual bool is_instrument() const;
        virtual bool in_category (const std::string &) const { return false; }
 
-       virtual std::vector<Plugin::PresetRecord> get_presets(Session& session) = 0;
+       virtual std::vector<Plugin::PresetRecord> get_presets (bool user_only) const = 0;
 
        /* NOTE: this block of virtual methods looks like the interface
           to a Processor, but Plugin does not inherit from Processor.
index c76bc13b46a437f135328c9993e0a6202f2305cb..7566eab098a8eb6748ecbd7cb8b58a3206132899 100644 (file)
@@ -47,7 +47,7 @@ public:
        ~WindowsVSTPluginInfo () {}
 
        PluginPtr load (Session& session);
-       virtual std::vector<Plugin::PresetRecord> get_presets(Session&);
+       std::vector<Plugin::PresetRecord> get_presets (bool user_only) const;
 };
 
 } // namespace ARDOUR
index 88bd981560d46a95469e552604658828b2e380e7..1c482736b8f905256d9d41193bf47414fe1ee32e 100644 (file)
@@ -2384,7 +2384,7 @@ AUPluginInfo::load (Session& session)
 }
 
 std::vector<Plugin::PresetRecord>
-AUPluginInfo::get_presets(Session& session)
+AUPluginInfo::get_presets (bool user_only) const
 {
        std::vector<Plugin::PresetRecord> p;
        boost::shared_ptr<CAComponent> comp;
@@ -2422,7 +2422,10 @@ AUPluginInfo::get_presets(Session& session)
                }
        }
 
-#if 0 // don't include factory presets in the sidebar, for now
+       if (user_only) {
+               return p;
+       }
+
        // factory presets
 
        CFArrayRef presets;
@@ -2455,7 +2458,6 @@ AUPluginInfo::get_presets(Session& session)
        }
        CFRelease (presets);
        unit->Uninitialize ();
-#endif // factory presets
 
 #endif // NO_PLUGIN_STATE
        return p;
index 6ec0723248fd859972d5db91a4785827202ffbf2..f30925ac51f36865947fdedbaeb3e80ec13f0c27 100644 (file)
@@ -739,7 +739,7 @@ LadspaPluginInfo::load (Session& session)
 }
 
 std::vector<Plugin::PresetRecord>
-LadspaPluginInfo::get_presets(Session& session)
+LadspaPluginInfo::get_presets (bool /*user_only*/) const
 {
        std::vector<Plugin::PresetRecord> p;
 #if (defined HAVE_LRDF && !defined NO_PLUGIN_STATE)
index e405b1a1cdfd8aa4538aea11ca44849621b91bbd..c39e40c7d5584de1547d7fde753145792baa6649 100644 (file)
@@ -2624,7 +2624,7 @@ LV2PluginInfo::load(Session& session)
 }
 
 std::vector<Plugin::PresetRecord>
-LV2PluginInfo::get_presets(Session&)
+LV2PluginInfo::get_presets (bool /*user_only*/) const
 {
        std::vector<Plugin::PresetRecord> p;
 #ifndef NO_PLUGIN_STATE
index ac868cd565f83d33332fdc63f639086792c6763c..2c50144f26f24e8acace6c494f77de5165ec12a0 100644 (file)
@@ -99,7 +99,7 @@ LXVSTPluginInfo::load (Session& session)
 }
 
 std::vector<Plugin::PresetRecord>
-LXVSTPluginInfo::get_presets(Session&)
+LXVSTPluginInfo::get_presets (bool user_only) const
 {
        std::vector<Plugin::PresetRecord> p;
 #ifndef NO_PLUGIN_STATE
@@ -107,45 +107,47 @@ LXVSTPluginInfo::get_presets(Session&)
                return p;
        }
 
-#if 0 // TODO - cache, instantiating the plugin can be heavy
-       /* Built-in presets */
-       VSTHandle* handle = vstfx_load(path.c_str());
-       Session::vst_current_loading_id = atoi (unique_id);
-       AEffect* plugin = handle->main_entry (Session::vst_callback);
-       Session::vst_current_loading_id = 0;
-
-       plugin->dispatcher (plugin, effOpen, 0, 0, 0, 0); // :(
-       int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, NULL, 0);
-
-       for (int i = 0; i < plugin->numPrograms; ++i) {
-               Plugin::PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id, i), "", false);
-               if (vst_version >= 2) {
-                       char buf[256];
-                       if (plugin->dispatcher (plugin, 29, i, 0, buf, 0) == 1) {
-                               r.label = buf;
+       if (!user_only) {
+               // TODO - cache, instantiating the plugin can be heavy
+               /* Built-in presets */
+               VSTHandle* handle = vstfx_load(path.c_str());
+               Session::vst_current_loading_id = atoi (unique_id);
+               AEffect* plugin = handle->main_entry (Session::vst_callback);
+               Session::vst_current_loading_id = 0;
+
+               plugin->dispatcher (plugin, effOpen, 0, 0, 0, 0); // :(
+               int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, NULL, 0);
+
+               for (int i = 0; i < plugin->numPrograms; ++i) {
+                       Plugin::PresetRecord r (string_compose (X_("VST:%1:%2"), unique_id, i), "", false);
+                       if (vst_version >= 2) {
+                               char buf[256];
+                               if (plugin->dispatcher (plugin, 29, i, 0, buf, 0) == 1) {
+                                       r.label = buf;
+                               } else {
+                                       r.label = string_compose (_("Preset %1"), i);
+                               }
                        } else {
                                r.label = string_compose (_("Preset %1"), i);
                        }
-               } else {
-                       r.label = string_compose (_("Preset %1"), i);
+                       p.push_back (r);
                }
-               p.push_back (r);
-       }
 
-       plugin->dispatcher (plugin, effMainsChanged, 0, 0, 0, 0);
-       plugin->dispatcher (plugin, effClose, 0, 0, 0, 0); // :(
+               plugin->dispatcher (plugin, effMainsChanged, 0, 0, 0, 0);
+               plugin->dispatcher (plugin, effClose, 0, 0, 0, 0); // :(
 
-       if (handle->plugincnt) {
-               handle->plugincnt--;
+               if (handle->plugincnt) {
+                       handle->plugincnt--;
+               }
+               vstfx_unload (handle);
        }
-       vstfx_unload (handle);
-#endif
+
        /* user presets */
        XMLTree* t = new XMLTree;
        std::string pf = Glib::build_filename (ARDOUR::user_config_directory (), "presets", string_compose ("vst-%1", unique_id));
        if (Glib::file_test (pf, Glib::FILE_TEST_EXISTS)) {
                t->set_filename (pf);
-               if (t->read ()) {
+               if (t->read ()) { // TODO read names only. skip parsing the actual data
                        XMLNode* root = t->root ();
                        for (XMLNodeList::const_iterator i = root->children().begin(); i != root->children().end(); ++i) {
                                XMLProperty* uri = (*i)->property (X_("uri"));
index 46097e7feb10683f4958fda12c32a8ffba3befc9..a480642e3afbb030d2d99bc0d8b7db12fbd0fa24 100644 (file)
@@ -95,7 +95,7 @@ WindowsVSTPluginInfo::load (Session& session)
 }
 
 std::vector<Plugin::PresetRecord>
-WindowsVSTPluginInfo::get_presets(Session&)
+WindowsVSTPluginInfo::get_presets (bool user_only) const
 {
        std::vector<Plugin::PresetRecord> p;
 #ifndef NO_PLUGIN_STATE
@@ -103,7 +103,9 @@ WindowsVSTPluginInfo::get_presets(Session&)
                return p;
        }
 
-       // TODO cache and load factory-preset names
+       if (!user_only) {
+               // TODO cache and load factory-preset names
+       }
 
        /* user presets */
        XMLTree* t = new XMLTree;