summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-03-25 00:34:26 +0000
committerDavid Robillard <d@drobilla.net>2013-03-25 00:34:26 +0000
commit29c8bfe6d5a9bce0df87176ccd8ac1b1d7db6002 (patch)
tree62994873f942498e1dedf5f6e5ad7609a8f468ba /src
parentc3aca5cef2df7ed6929636b38d116442f6e8f3bd (diff)
downloadingen-29c8bfe6d5a9bce0df87176ccd8ac1b1d7db6002.tar.gz
ingen-29c8bfe6d5a9bce0df87176ccd8ac1b1d7db6002.tar.bz2
ingen-29c8bfe6d5a9bce0df87176ccd8ac1b1d7db6002.zip
Fix preset loading.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5101 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/gui/NodeMenu.cpp65
-rw-r--r--src/gui/ObjectMenu.hpp3
2 files changed, 36 insertions, 32 deletions
diff --git a/src/gui/NodeMenu.cpp b/src/gui/NodeMenu.cpp
index cf245edb..de744226 100644
--- a/src/gui/NodeMenu.cpp
+++ b/src/gui/NodeMenu.cpp
@@ -21,6 +21,7 @@
#include "ingen/Interface.hpp"
#include "ingen/Log.hpp"
+#include "ingen/URIMap.hpp"
#include "ingen/client/BlockModel.hpp"
#include "ingen/client/PluginModel.hpp"
#include "lv2/lv2plug.in/ns/ext/presets/presets.h"
@@ -172,46 +173,46 @@ NodeMenu::on_menu_disconnect()
_app->interface()->disconnect_all(_object->parent()->path(), _object->path());
}
+static void
+set_port_value(const char* port_symbol,
+ void* user_data,
+ const void* value,
+ uint32_t size,
+ uint32_t type)
+{
+ NodeMenu* menu = (NodeMenu*)user_data;
+ const BlockModel* const block = (const BlockModel*)menu->object().get();
+
+ if (!Raul::Symbol::is_valid(port_symbol)) {
+ menu->app()->log().error(
+ fmt("Preset with invalid port symbol `%1'\n") % port_symbol);
+ return;
+ }
+
+ menu->app()->interface()->set_property(
+ Node::path_to_uri(block->path().child(Raul::Symbol(port_symbol))),
+ menu->app()->uris().ingen_value,
+ menu->app()->forge().alloc(size, type, value));
+}
+
void
NodeMenu::on_preset_activated(const std::string& uri)
{
const BlockModel* const block = (const BlockModel*)_object.get();
const PluginModel* const plugin = dynamic_cast<const PluginModel*>(block->plugin());
- LilvNode* port_pred = lilv_new_uri(plugin->lilv_world(),
- LV2_CORE__port);
- LilvNode* symbol_pred = lilv_new_uri(plugin->lilv_world(),
- LV2_CORE__symbol);
- LilvNode* value_pred = lilv_new_uri(plugin->lilv_world(),
- LV2_PRESETS__value);
- LilvNode* subject = lilv_new_uri(plugin->lilv_world(), uri.c_str());
- LilvNodes* ports = lilv_world_find_nodes(
+ LilvNode* pset = lilv_new_uri(plugin->lilv_world(), uri.c_str());
+ LilvState* state = lilv_state_new_from_world(
plugin->lilv_world(),
- subject,
- port_pred,
- NULL);
- _app->interface()->bundle_begin();
- LILV_FOREACH(nodes, i, ports) {
- const LilvNode* uri = lilv_nodes_get(ports, i);
- LilvNodes* values = lilv_world_find_nodes(
- plugin->lilv_world(), uri, value_pred, NULL);
- LilvNodes* symbols = lilv_world_find_nodes(
- plugin->lilv_world(), uri, symbol_pred, NULL);
- if (values && symbols) {
- const LilvNode* val = lilv_nodes_get_first(values);
- const LilvNode* sym = lilv_nodes_get_first(symbols);
- _app->interface()->set_property(
- Node::path_to_uri(
- block->path().child(Raul::Symbol(lilv_node_as_string(sym)))),
- _app->uris().ingen_value,
- _app->forge().make(lilv_node_as_float(val)));
- }
+ &_app->world()->uri_map().urid_map_feature()->urid_map,
+ pset);
+
+ if (state) {
+ lilv_state_restore(state, NULL, set_port_value, this, 0, NULL);
+ lilv_state_free(state);
}
- _app->interface()->bundle_end();
- lilv_nodes_free(ports);
- lilv_node_free(value_pred);
- lilv_node_free(symbol_pred);
- lilv_node_free(port_pred);
+
+ lilv_node_free(pset);
}
bool
diff --git a/src/gui/ObjectMenu.hpp b/src/gui/ObjectMenu.hpp
index fc63c7a8..d3ed647e 100644
--- a/src/gui/ObjectMenu.hpp
+++ b/src/gui/ObjectMenu.hpp
@@ -44,6 +44,9 @@ public:
void init(App& app, SPtr<const Client::ObjectModel> object);
+ SPtr<const Client::ObjectModel> object() const { return _object; }
+ App* app() const { return _app; }
+
protected:
void on_menu_learn();
void on_menu_unlearn();