Can't call the wrong function when there's only one of them: remove ARDOUR::Parameter...
[ardour.git] / libs / ardour / lv2_plugin.cc
index a38c851c215055707c7d29437937be0bc7ecb0cb..231d267468b2e5499724a9e395b98916ccdf1aa5 100644 (file)
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
-
+       
 LV2Plugin::LV2Plugin (AudioEngine& e, Session& session, LV2World& world, SLV2Plugin plugin, nframes_t rate)
        : Plugin (e, session)
        , _world(world)
+       , _features(NULL)
 {
        init (world, plugin, rate);
 }
@@ -54,6 +55,7 @@ LV2Plugin::LV2Plugin (AudioEngine& e, Session& session, LV2World& world, SLV2Plu
 LV2Plugin::LV2Plugin (const LV2Plugin &other)
        : Plugin (other)
        , _world(other._world)
+       , _features(NULL)
 {
        init (other._world, other._plugin, other._sample_rate);
 
@@ -68,12 +70,13 @@ LV2Plugin::init (LV2World& world, SLV2Plugin plugin, nframes_t rate)
 {
        _world = world;
        _plugin = plugin;
+       _ui = NULL;
        _control_data = 0;
        _shadow_data = 0;
        _latency_control_port = 0;
        _was_activated = false;
-
-       _instance = slv2_plugin_instantiate(plugin, rate, NULL);
+       
+       _instance = slv2_plugin_instantiate(plugin, rate, _features);
        _name = slv2_plugin_get_name(plugin);
        assert(_name);
        _author = slv2_plugin_get_author_name(plugin);
@@ -90,6 +93,18 @@ LV2Plugin::init (LV2World& world, SLV2Plugin plugin, nframes_t rate)
                slv2_value_free(_author);
                throw failed_constructor();
        }
+       
+       _instance_access_feature.URI = "http://lv2plug.in/ns/ext/instance-access";
+       _instance_access_feature.data = (void*)_instance->lv2_handle;
+
+       _data_access_extension_data.extension_data = _instance->lv2_descriptor->extension_data;
+       _data_access_feature.URI = "http://lv2plug.in/ns/ext/data-access";
+       _data_access_feature.data = &_data_access_extension_data;
+       
+       _features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * 3);
+       _features[0] = &_instance_access_feature;
+       _features[1] = &_data_access_feature;
+       _features[2] = NULL;
 
        _sample_rate = rate;
 
@@ -124,6 +139,17 @@ LV2Plugin::init (LV2World& world, SLV2Plugin plugin, nframes_t rate)
                        _defaults[i] = 0.0f;
                }
        }
+       
+       SLV2UIs uis = slv2_plugin_get_uis(_plugin);
+       if (slv2_uis_size(uis) > 0) {
+               for (unsigned i=0; i < slv2_uis_size(uis); ++i) {
+                       SLV2UI ui = slv2_uis_get_at(uis, i);
+                       if (slv2_ui_is_a(ui, _world.gtk_gui)) {
+                               _ui = ui;
+                               break;
+                       }
+               }
+       }
 
        latency_compute_run ();
 }
@@ -243,6 +269,12 @@ LV2Plugin::save_preset (string name)
 {
        return Plugin::save_preset (name, "lv2");
 }
+       
+bool
+LV2Plugin::has_editor() const
+{
+       return (_ui != NULL);
+}
 
 int
 LV2Plugin::set_state(const XMLNode& node)
@@ -328,7 +360,7 @@ LV2Plugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc)
 
 
 string
-LV2Plugin::describe_parameter (Parameter which)
+LV2Plugin::describe_parameter (Evoral::Parameter which)
 {
        if (which.type() == PluginAutomation && which.id() < parameter_count()) {
                SLV2Value name = slv2_port_get_name(_plugin,
@@ -351,14 +383,14 @@ LV2Plugin::signal_latency () const
        }
 }
 
-set<Parameter>
+set<Evoral::Parameter>
 LV2Plugin::automatable () const
 {
-       set<Parameter> ret;
+       set<Evoral::Parameter> ret;
 
        for (uint32_t i = 0; i < parameter_count(); ++i){
                if (parameter_is_input(i) && parameter_is_control(i)) {
-                       ret.insert (ret.end(), Parameter(PluginAutomation, i));
+                       ret.insert (ret.end(), Evoral::Parameter(PluginAutomation, i));
                }
        }
 
@@ -536,6 +568,7 @@ LV2World::LV2World()
        integer = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "integer");
        toggled = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "toggled");
        srate = slv2_value_new_uri(world, SLV2_NAMESPACE_LV2 "sampleRate");
+       gtk_gui = slv2_value_new_uri(world, "http://lv2plug.in/ns/extensions/ui#GtkUI");
 }
 
 LV2World::~LV2World()