[SCM] calf/master: + LV2 GUI: use less outrageous instance access

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:38:29 UTC 2013


The following commit has been merged in the master branch:
commit e5889e98486f8d41436b1f74e399761058066c3a
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sat Nov 15 23:08:42 2008 +0000

    + LV2 GUI: use less outrageous instance access

diff --git a/src/calf/lv2wrap.h b/src/calf/lv2wrap.h
index 0c6e567..9960e31 100644
--- a/src/calf/lv2wrap.h
+++ b/src/calf/lv2wrap.h
@@ -126,11 +126,16 @@ struct lv2_instance: public plugin_ctl_iface, public Module
     }
 };
 
+struct LV2_Calf_Descriptor {
+    plugin_ctl_iface *(*get_pci)(LV2_Handle Instance);
+};
+
 template<class Module>
 struct lv2_wrapper
 {
     typedef lv2_instance<Module> instance;
     static LV2_Descriptor descriptor;
+    static LV2_Calf_Descriptor calf_descriptor;
     std::string uri;
     
     lv2_wrapper()
@@ -145,6 +150,7 @@ struct lv2_wrapper
         descriptor.deactivate = cb_deactivate;
         descriptor.cleanup = cb_cleanup;
         descriptor.extension_data = cb_ext_data;
+        calf_descriptor.get_pci = cb_get_pci;
     }
 
     static void cb_connect(LV2_Handle Instance, uint32_t port, void *DataLocation) {
@@ -207,6 +213,11 @@ struct lv2_wrapper
             }
         }
     }
+    static plugin_ctl_iface *cb_get_pci(LV2_Handle Instance)
+    {
+        return (plugin_ctl_iface *)Instance;
+    }
+
     static inline void process_slice(Module *mod, uint32_t offset, uint32_t end)
     {
         while(offset < end)
@@ -269,6 +280,8 @@ struct lv2_wrapper
         delete mod;
     }
     static const void *cb_ext_data(const char *URI) {
+        if (!strcmp(URI, "http://foltman.com/ns/calf-plugin-instance"))
+            return &calf_descriptor;
         return NULL;
     }
     static lv2_wrapper &get() { 
diff --git a/src/lv2gui.cpp b/src/lv2gui.cpp
index bc8fc94..9240859 100644
--- a/src/lv2gui.cpp
+++ b/src/lv2gui.cpp
@@ -25,6 +25,7 @@
 #include <calf/giface.h>
 #include <calf/gui.h>
 #include <calf/main_win.h>
+#include <calf/lv2_data_access.h>
 #include <calf/lv2_ui.h>
 #include <calf/preset_gui.h>
 #include <calf/utils.h>
@@ -35,6 +36,10 @@ using namespace dsp;
 using namespace calf_plugins;
 using namespace calf_utils;
 
+struct LV2_Calf_Descriptor {
+    plugin_ctl_iface *(*get_pci)(LV2_Handle Instance);
+};
+
 struct plugin_proxy: public plugin_ctl_iface, public plugin_metadata_proxy
 {
     LV2UI_Write_Function write_function;
@@ -47,12 +52,16 @@ struct plugin_proxy: public plugin_ctl_iface, public plugin_metadata_proxy
     /// Instance pointer - usually NULL unless the host supports instance-access extension
     plugin_ctl_iface *instance;
     int source_id;
+    LV2_Handle instance_handle;
+    LV2_Extension_Data_Feature *data_access;
     
     plugin_proxy(plugin_metadata_iface *md)
     : plugin_metadata_proxy(md)
     {
         gui = NULL;
         instance = NULL;
+        instance_handle = NULL;
+        data_access = NULL;
         send = true;
         param_count = get_param_count();
         params = new float[param_count];
@@ -101,6 +110,15 @@ struct plugin_proxy: public plugin_ctl_iface, public plugin_metadata_proxy
     void clear_preset() {
         fprintf(stderr, "TODO: clear_preset (reset to init state) not implemented in LV2 GUIs\n");
     }
+    void resolve_instance() {
+        if (instance_handle && data_access)
+        {
+            LV2_Calf_Descriptor *calf = (LV2_Calf_Descriptor *)(*data_access->data_access)("http://foltman.com/ns/calf-plugin-instance");
+            if (calf && calf->get_pci)
+                instance = calf->get_pci(instance_handle);
+        }
+    }
+        
     ~plugin_proxy()
     {
         delete []params;
@@ -140,14 +158,14 @@ LV2UI_Handle gui_instantiate(const struct _LV2UI_Descriptor* descriptor,
     {
         if (!strcmp(features[i]->URI, "http://lv2plug.in/ns/ext/instance-access"))
         {
-            proxy->instance = (plugin_ctl_iface *)features[i]->data;
-            printf("Instance %p\n", features[i]->data);
+            proxy->instance_handle = features[i]->data;
         }
         if (!strcmp(features[i]->URI, "http://lv2plug.in/ns/ext/data-access"))
         {
-            printf("Data %p\n", features[i]->data);
+            proxy->data_access = (LV2_Extension_Data_Feature *)features[i]->data;
         }
     }
+    proxy->resolve_instance();
     scope_assign<bool> _a_(proxy->send, false);
     proxy->setup(write_function, controller);
     // dummy window
diff --git a/src/plugin.cpp b/src/plugin.cpp
index bbd8c04..1b1489e 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -29,6 +29,7 @@ using namespace calf_plugins;
 #if USE_LV2
 // instantiate descriptor templates
 template<class Module> LV2_Descriptor calf_plugins::lv2_wrapper<Module>::descriptor;
+template<class Module> LV2_Calf_Descriptor calf_plugins::lv2_wrapper<Module>::calf_descriptor;
 
 extern "C" {
 

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list