Fix loading LV2 presets with non-float port values

In practice, this mostly means integers when presets leave off the ".0", but we
implement all the numeric types here for good measure.

Also while we're at it, warn about unknown types now so it doesn't take three
people a half an hour to figure out what's going on the next time something
like this happens.
This commit is contained in:
David Robillard 2022-12-13 22:03:48 -05:00
parent bd8c3af2a2
commit 27dfd8a7e3
3 changed files with 24 additions and 4 deletions

View File

@ -65,7 +65,10 @@ public:
uint32_t atom_URID;
uint32_t atom_Blank;
uint32_t atom_Object;
uint32_t atom_Double;
uint32_t atom_Float;
uint32_t atom_Long;
uint32_t atom_Int;
uint32_t log_Error;
uint32_t log_Note;
uint32_t log_Trace;

View File

@ -280,14 +280,28 @@ set_port_value(const char* port_symbol,
uint32_t type)
{
LV2Plugin* self = (LV2Plugin*)user_data;
if (type != 0 && type != URIMap::instance().urids.atom_Float) {
return; // TODO: Support non-float ports
float fvalue = 0.0f;
if (type == URIMap::instance ().urids.atom_Float) {
fvalue = *(const float*)value;
} else if (type == URIMap::instance ().urids.atom_Double) {
fvalue = static_cast<float> (*(const double*)value);
} else if (type == URIMap::instance ().urids.atom_Int) {
fvalue = static_cast<float> (*(const int32_t*)value);
} else if (type == URIMap::instance ().urids.atom_Long) {
fvalue = static_cast<float> (*(const int64_t*)value);
} else {
error << string_compose (
_("LV2<%1>: Preset value for port '%2' has unsupported datatype <%3>"),
self->name (),
port_symbol,
self->uri_map ().id_to_uri(type));
}
const uint32_t port_index = self->port_index(port_symbol);
if (port_index != (uint32_t)-1) {
self->set_parameter(port_index, *(const float*)value, 0);
self->PresetPortSetValue (port_index, *(const float*)value); /* EMIT SIGNAL */
self->set_parameter(port_index, fvalue, 0);
self->PresetPortSetValue (port_index, fvalue); /* EMIT SIGNAL */
}
}

View File

@ -45,7 +45,10 @@ URIMap::URIDs::init(URIMap& uri_map)
atom_URID = uri_map.uri_to_id("http://lv2plug.in/ns/ext/atom#URID");
atom_Blank = uri_map.uri_to_id("http://lv2plug.in/ns/ext/atom#Blank");
atom_Object = uri_map.uri_to_id("http://lv2plug.in/ns/ext/atom#Object");
atom_Double = uri_map.uri_to_id("http://lv2plug.in/ns/ext/atom#Double");
atom_Float = uri_map.uri_to_id("http://lv2plug.in/ns/ext/atom#Float");
atom_Long = uri_map.uri_to_id("http://lv2plug.in/ns/ext/atom#Long");
atom_Int = uri_map.uri_to_id("http://lv2plug.in/ns/ext/atom#Int");
log_Error = uri_map.uri_to_id("http://lv2plug.in/ns/ext/log#Error");
log_Note = uri_map.uri_to_id("http://lv2plug.in/ns/ext/log#Note");
log_Trace = uri_map.uri_to_id("http://lv2plug.in/ns/ext/log#Trace");