diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-19 15:59:50 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-19 15:59:50 +0000 |
commit | 7a24e49fa07a363f677b89613e0e281cceef2804 (patch) | |
tree | 6c859e3d7190b03b4d7a47d34a03cd6758e0a610 /libs/ardour | |
parent | 34321110dd0e1477d455232b9ceece3025a204ad (diff) |
2nd half of patch for handling LV2 presets from colinf (#4698)
git-svn-id: svn://localhost/ardour2/branches/3.0@12786 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r-- | libs/ardour/ardour/lv2_plugin.h | 12 | ||||
-rw-r--r-- | libs/ardour/lv2_plugin.cc | 88 |
2 files changed, 95 insertions, 5 deletions
diff --git a/libs/ardour/ardour/lv2_plugin.h b/libs/ardour/ardour/lv2_plugin.h index 27e002ca66..baf9c959ae 100644 --- a/libs/ardour/ardour/lv2_plugin.h +++ b/libs/ardour/ardour/lv2_plugin.h @@ -31,6 +31,13 @@ namespace ARDOUR { +// a callback function for lilv_state_new_from_instance(). friend of LV2Plugin +// so we can pass an LV2Plugin* in user_data and access its private members. +const void* lv2plugin_get_port_value(const char* port_symbol, + void* user_data, + uint32_t* size, + uint32_t* type); + class AudioEngine; class Session; @@ -159,6 +166,11 @@ class LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee float* _latency_control_port; ///< Special output set by ardour PBD::ID _insert_id; + friend const void* lv2plugin_get_port_value(const char* port_symbol, + void* user_data, + uint32_t* size, + uint32_t* type); + typedef enum { PORT_INPUT = 1, PORT_OUTPUT = 1 << 1, diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 6c8fb3c9db..f8a41c5ecd 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -835,7 +835,6 @@ LV2Plugin::find_presets() bool LV2Plugin::load_preset(PresetRecord r) { - Plugin::load_preset(r); std::map<std::string,uint32_t>::iterator it; @@ -862,18 +861,97 @@ LV2Plugin::load_preset(PresetRecord r) lilv_node_free(lv2_symbol); lilv_node_free(lv2_port); + Plugin::load_preset(r); + return true; } +const void* +ARDOUR::lv2plugin_get_port_value(const char* port_symbol, + void* user_data, + uint32_t* size, + uint32_t* type) +{ + // cerr << "get_port_value(" << port_symbol << ", ...) ... "; + LV2Plugin *plugin = (LV2Plugin *) user_data; + + uint32_t index = plugin->port_index(port_symbol); + if (index != (uint32_t) -1) { + if (plugin->parameter_is_input(index) && plugin->parameter_is_control(index)) { + float *value; + *size = sizeof(float); + *type = plugin->_uri_map.uri_to_id(LV2_ATOM__Float); + value = &plugin->_shadow_data[index]; + // cerr << "index="<< index << ",*size=" << *size << ",*type=" << *type << ",*value=" << *value << endl; + + return value; + } + // cerr << "port is not input control port! "; + } + + // cerr << "returning NULL!" << endl; + *size = *type = 0; + return NULL; +} + + std::string -LV2Plugin::do_save_preset(string /*name*/) +LV2Plugin::do_save_preset(string name) { - return ""; + // cerr << "LV2Plugin::do_save_preset(" << name << ")" << endl; + + string pset_uri = uri(); + pset_uri += "#"; + pset_uri += name; + + string save_dir = Glib::build_filename( + Glib::get_home_dir(), + Glib::build_filename(".lv2", "presets") + ); + + LilvState* state = lilv_state_new_from_instance( + _impl->plugin, + _impl->instance, + _uri_map.urid_map(), + scratch_dir().c_str(), // file_dir + NULL, // copy_dir + NULL, // link_dir + save_dir.c_str(), // save_dir + lv2plugin_get_port_value, // get_value + (void*) this, // user_data + LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE, // flags + _features // features + ); + + lilv_state_set_label(state, name.c_str()); + lilv_state_save( + _world.world, // world + _uri_map.urid_map(), // map + _uri_map.urid_unmap(), // unmap + state, // state + pset_uri.c_str(), // uri + save_dir.c_str(), // dir + (name + ".ttl").c_str() // filename + + ); + + lilv_state_free(state); + return pset_uri; } void -LV2Plugin::do_remove_preset(string /*name*/) -{} +LV2Plugin::do_remove_preset(string name) +{ + string preset_file = Glib::build_filename( + Glib::get_home_dir(), + Glib::build_filename( + Glib::build_filename(".lv2", "presets"), + name + ".ttl" + ) + ); + unlink(preset_file.c_str()); + +} bool LV2Plugin::has_editor() const |