From 2b7f092b857df8cde0cd4680e9de55f4cb98596b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 14 May 2011 18:43:34 +0000 Subject: Generic scale points API. Hide scale points implementation inside specific Plugin subclass. Don't needlessley/slowly get scale points twice for each port while building UI. Remove dependence on specific plugin types from GenericPluginUI. git-svn-id: svn://localhost/ardour2/branches/3.0@9511 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/ladspa_plugin.h | 5 ++++- libs/ardour/ardour/lv2_plugin.h | 3 +++ libs/ardour/ardour/plugin.h | 7 +++++++ libs/ardour/ladspa_plugin.cc | 22 ++++++++++++++++++++++ libs/ardour/lv2_plugin.cc | 27 +++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) (limited to 'libs') diff --git a/libs/ardour/ardour/ladspa_plugin.h b/libs/ardour/ardour/ladspa_plugin.h index 457921cf36..c49e9d3a21 100644 --- a/libs/ardour/ardour/ladspa_plugin.h +++ b/libs/ardour/ardour/ladspa_plugin.h @@ -97,7 +97,10 @@ class LadspaPlugin : public ARDOUR::Plugin bool parameter_is_output(uint32_t) const; bool parameter_is_toggled(uint32_t) const; - int set_state (const XMLNode&, int version); + boost::shared_ptr + get_scale_points(uint32_t port_index) const; + + int set_state (const XMLNode&, int version); bool load_preset (PresetRecord); diff --git a/libs/ardour/ardour/lv2_plugin.h b/libs/ardour/ardour/lv2_plugin.h index 91dc2f61a5..ff66ec2868 100644 --- a/libs/ardour/ardour/lv2_plugin.h +++ b/libs/ardour/ardour/lv2_plugin.h @@ -108,6 +108,9 @@ class LV2Plugin : public ARDOUR::Plugin bool parameter_is_output (uint32_t) const; bool parameter_is_toggled (uint32_t) const; + boost::shared_ptr + get_scale_points(uint32_t port_index) const; + static uint32_t midi_event_type () { return _midi_event_type; } void set_insert_info(const PluginInsert* insert); diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h index d8f33c21f4..bc796712af 100644 --- a/libs/ardour/ardour/plugin.h +++ b/libs/ardour/ardour/plugin.h @@ -134,6 +134,13 @@ class Plugin : public PBD::StatefulDestructible, public Latent virtual bool parameter_is_input(uint32_t) const = 0; virtual bool parameter_is_output(uint32_t) const = 0; + typedef std::map ScalePoints; + + virtual boost::shared_ptr + get_scale_points(uint32_t port_index) const { + return boost::shared_ptr(); + } + void realtime_handle_transport_stopped (); struct PresetRecord { diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index 1ea158d7cd..f5426500a4 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -605,6 +605,28 @@ LadspaPlugin::print_parameter (uint32_t param, char *buf, uint32_t len) const } } +boost::shared_ptr +LadspaPlugin::get_scale_points(uint32_t port_index) const +{ + const uint32_t id = atol(unique_id().c_str()); + lrdf_defaults* points = lrdf_get_scale_values(id, port_index); + + boost::shared_ptr ret; + if (!points) { + return ret; + } + + ret = boost::shared_ptr(new ScalePoints()); + + for (uint32_t i = 0; i < points->count; ++i) { + ret->insert(make_pair(points->items[i].label, + points->items[i].value)); + } + + lrdf_free_setting_values(points); + return ret; +} + void LadspaPlugin::run_in_place (pframes_t nframes) { diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index e7c9dad4ec..6c1664bc01 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -1027,6 +1027,33 @@ LV2Plugin::print_parameter(uint32_t param, char* buf, uint32_t len) const } } +boost::shared_ptr +LV2Plugin::get_scale_points(uint32_t port_index) const +{ + SLV2Port port = slv2_plugin_get_port_by_index(_plugin, port_index); + SLV2ScalePoints points = slv2_port_get_scale_points(_plugin, port); + + boost::shared_ptr ret; + if (!points) { + return ret; + } + + ret = boost::shared_ptr(new ScalePoints()); + + for (unsigned i = 0; i < slv2_scale_points_size(points); ++i) { + SLV2ScalePoint p = slv2_scale_points_get_at(points, i); + SLV2Value label = slv2_scale_point_get_label(p); + SLV2Value value = slv2_scale_point_get_value(p); + if (label && (slv2_value_is_float(value) || slv2_value_is_int(value))) { + ret->insert(make_pair(slv2_value_as_string(label), + slv2_value_as_float(value))); + } + } + + slv2_scale_points_free(points); + return ret; +} + void LV2Plugin::run(pframes_t nframes) { -- cgit v1.2.3