X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Flv2_plugin.cc;h=c900a21176b97efd8803f05399af9ac635908125;hb=54bf06e63cee78dfa218f604d862e577d0f5754c;hp=69efa2eeef1135a6fcf7ce020b512b50a26b1dbd;hpb=07112b55e0bb7ceb9e5c05ab4df167ecaf7edd9b;p=ardour.git diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 69efa2eeef..c900a21176 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -962,38 +962,38 @@ LV2Plugin::find_presets() lilv_node_free(lv2_appliesTo); } -bool -LV2Plugin::load_preset(PresetRecord r) +static void +set_port_value(const char* port_symbol, + void* user_data, + const void* value, + uint32_t /*size*/, + uint32_t type) { - std::map::iterator it; - - LilvNode* lv2_port = lilv_new_uri(_world.world, LILV_NS_LV2 "port"); - LilvNode* lv2_symbol = lilv_new_uri(_world.world, LILV_NS_LV2 "symbol"); - LilvNode* preset = lilv_new_uri(_world.world, r.uri.c_str()); - LilvNode* pset_value = lilv_new_uri(_world.world, LV2_PRESETS__value); - - LilvNodes* ports = lilv_world_find_nodes(_world.world, preset, lv2_port, NULL); - LILV_FOREACH(nodes, i, ports) { - const LilvNode* port = lilv_nodes_get(ports, i); - const LilvNode* symbol = get_value(_world.world, port, lv2_symbol); - const LilvNode* value = get_value(_world.world, port, pset_value); - if (value && lilv_node_is_float(value)) { - it = _port_indices.find(lilv_node_as_string(symbol)); - if (it != _port_indices.end()) { - set_parameter(it->second,lilv_node_as_float(value)); - } - } + LV2Plugin* self = (LV2Plugin*)user_data; + if (type != 0 && type != self->_uri_map.uri_to_id(LV2_ATOM__Float)) { + return; // TODO: Support non-float ports } - lilv_nodes_free(ports); - lilv_node_free(pset_value); - lilv_node_free(preset); - lilv_node_free(lv2_symbol); - lilv_node_free(lv2_port); + const uint32_t port_index = self->port_index(port_symbol); + if (port_index != (uint32_t)-1) { + self->set_parameter(port_index, *(const float*)value); + } +} - Plugin::load_preset(r); +bool +LV2Plugin::load_preset(PresetRecord r) +{ + LilvWorld* world = _world.world; + LilvNode* pset = lilv_new_uri(world, r.uri.c_str()); + LilvState* state = lilv_state_new_from_world(world, _uri_map.urid_map(), pset); - return true; + if (state) { + lilv_state_restore(state, _impl->instance, set_port_value, this, 0, NULL); + lilv_state_free(state); + } + + lilv_node_free(pset); + return state; } const void* @@ -1570,7 +1570,6 @@ LV2Plugin::connect_and_run(BufferSet& bufs, : m; // Now merge MIDI and any transport events into the buffer - LV2_Evbuf_Iterator i = lv2_evbuf_end(_ev_buffers[port_index]); const uint32_t type = LV2Plugin::urids.midi_MidiEvent; const framepos_t tend = _session.transport_frame() + nframes; ++metric_i;