diff options
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/client/NodeModel.cpp | 32 | ||||
-rw-r--r-- | src/libs/client/NodeModel.hpp | 3 | ||||
-rw-r--r-- | src/libs/engine/LV2Node.cpp | 18 |
3 files changed, 35 insertions, 18 deletions
diff --git a/src/libs/client/NodeModel.cpp b/src/libs/client/NodeModel.cpp index 2f8af584..d47e0b8c 100644 --- a/src/libs/client/NodeModel.cpp +++ b/src/libs/client/NodeModel.cpp @@ -18,6 +18,7 @@ #include CONFIG_H_PATH #include <cassert> +#include <cmath> #include "interface/Port.hpp" #include "NodeModel.hpp" #include "PatchModel.hpp" @@ -30,12 +31,16 @@ NodeModel::NodeModel(Store& store, SharedPtr<PluginModel> plugin, const Path& pa : ObjectModel(store, path, polyphonic) , _plugin_uri(plugin->uri()) , _plugin(plugin) + , _min_values(0) + , _max_values(0) { } NodeModel::NodeModel(Store& store, const string& plugin_uri, const Path& path, bool polyphonic) : ObjectModel(store, path, polyphonic) , _plugin_uri(plugin_uri) + , _min_values(0) + , _max_values(0) { } @@ -78,6 +83,10 @@ NodeModel::clear() { _ports.clear(); assert(_ports.empty()); + delete [] _min_values; + delete [] _max_values; + _min_values = 0; + _max_values = 0; } @@ -155,17 +164,22 @@ NodeModel::port_value_range(SharedPtr<PortModel> port, float& min, float& max) #ifdef HAVE_SLV2 // Plugin value first if (_plugin && _plugin->type() == PluginModel::LV2) { - Glib::Mutex::Lock(PluginModel::rdf_world()->mutex()); - SLV2Value min_val, max_val; - slv2_port_get_range(_plugin->slv2_plugin(), - _plugin->slv2_port(port->index()), - NULL, &min_val, &max_val); + if (!_min_values) { + + Glib::Mutex::Lock(PluginModel::rdf_world()->mutex()); + + uint32_t num_lv2_ports = slv2_plugin_get_num_ports(_plugin->slv2_plugin()); + _min_values = new float[num_lv2_ports]; + _max_values = new float[num_lv2_ports]; + slv2_plugin_get_port_ranges(_plugin->slv2_plugin(), + _min_values, _max_values, 0); + } - if (min_val) - min = slv2_value_as_float(min_val); - if (max_val) - max = slv2_value_as_float(max_val); + if (!std::isnan(_min_values[port->index()])) + min = _min_values[port->index()]; + if (!std::isnan(_max_values[port->index()])) + max = _max_values[port->index()]; } #endif diff --git a/src/libs/client/NodeModel.hpp b/src/libs/client/NodeModel.hpp index 9e26daaa..d50926ae 100644 --- a/src/libs/client/NodeModel.hpp +++ b/src/libs/client/NodeModel.hpp @@ -85,6 +85,9 @@ protected: PortModelList _ports; ///< List of ports (not a Table to preserve order) string _plugin_uri; ///< Plugin URI (if PluginModel is unknown) SharedPtr<PluginModel> _plugin; ///< The plugin this node is an instance of + + float* _min_values; ///< The min values for the node ports (only used for LV2 so far) + float* _max_values; ///< The max values for the node ports (only used for LV2 so far) }; diff --git a/src/libs/engine/LV2Node.cpp b/src/libs/engine/LV2Node.cpp index a0fdebc0..bdeca701 100644 --- a/src/libs/engine/LV2Node.cpp +++ b/src/libs/engine/LV2Node.cpp @@ -149,6 +149,9 @@ LV2Node::instantiate() PortImpl* port = NULL; + float* def_values = new float[num_ports]; + slv2_plugin_get_port_ranges(plug, 0, 0, def_values); + for (uint32_t j=0; j < num_ports; ++j) { SLV2Port id = slv2_plugin_get_port_by_index(plug, j); @@ -186,11 +189,9 @@ LV2Node::instantiate() return false; } - SLV2Value def, min, max; - slv2_port_get_range(plug, id, &def, &min, &max); - // FIXME: need nice type preserving SLV2Value -> Raul::Atom conversion - Atom defatm = (float)((def && slv2_value_is_float(def)) ? slv2_value_as_float(def) : 0.0f); + float def = isnan(def_values[j]) ? 0.0f : def_values[j]; + Atom defatm = def; if (direction == INPUT) port = new InputPort(this, port_name, j, _polyphony, data_type, defatm, port_buffer_size); @@ -198,14 +199,13 @@ LV2Node::instantiate() port = new OutputPort(this, port_name, j, _polyphony, data_type, defatm, port_buffer_size); if (direction == INPUT && data_type == DataType::CONTROL) - ((AudioBuffer*)port->buffer(0))->set(slv2_value_as_float(def), 0); - - slv2_value_free(def); - slv2_value_free(min); - slv2_value_free(max); + ((AudioBuffer*)port->buffer(0))->set(def, 0); _ports->at(j) = port; } + + delete [] def_values; + return true; } |