From 9da2840ce1fc9de08d3bd052fc535c925416c45a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 Mar 2016 20:42:36 -0400 Subject: Load default plugin state Based on a patch from Hanspeter Portner. --- src/server/Engine.cpp | 4 ++++ src/server/LV2Block.cpp | 16 ++++++++++++++++ src/server/LV2Block.hpp | 2 ++ 3 files changed, 22 insertions(+) (limited to 'src/server') diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index 90a2c200..7ab7e315 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -21,6 +21,7 @@ #include #include "lv2/lv2plug.in/ns/ext/buf-size/buf-size.h" +#include "lv2/lv2plug.in/ns/ext/state/state.h" #include "events/CreateGraph.hpp" #include "ingen/Configuration.hpp" @@ -96,6 +97,9 @@ Engine::Engine(Ingen::World* world) _world->lv2_features().add_feature( SPtr( new LV2Features::EmptyFeature(LV2_BUF_SIZE__boundedBlockLength))); + _world->lv2_features().add_feature( + SPtr( + new LV2Features::EmptyFeature(LV2_STATE__loadDefaultState))); } Engine::~Engine() diff --git a/src/server/LV2Block.cpp b/src/server/LV2Block.cpp index f7627416..e1f67897 100644 --- a/src/server/LV2Block.cpp +++ b/src/server/LV2Block.cpp @@ -74,6 +74,20 @@ LV2Block::~LV2Block() delete _instances; } +void +LV2Block::load_default_state() +{ + const LilvPlugin* lplug = _lv2_plugin->lilv_plugin(); + const LilvNode* uri_node = lilv_plugin_get_uri(lplug); + const Raul::URI uri(lilv_node_as_string(uri_node)); + + LilvState* default_state = load_preset(_lv2_plugin->uri()); + if (default_state) { + apply_state(default_state); + lilv_state_free(default_state); + } +} + SPtr LV2Block::make_instance(URIs& uris, SampleRate rate, @@ -431,6 +445,8 @@ LV2Block::instantiate(BufferFactory& bufs) } } + load_default_state(); + // FIXME: Polyphony + worker? if (lilv_plugin_has_feature(plug, uris.work_schedule)) { _worker_iface = (const LV2_Worker_Interface*) diff --git a/src/server/LV2Block.hpp b/src/server/LV2Block.hpp index e5d41006..6483f8b0 100644 --- a/src/server/LV2Block.hpp +++ b/src/server/LV2Block.hpp @@ -83,6 +83,8 @@ protected: uint32_t voice, bool preparing); + void load_default_state(); + inline LilvInstance* instance(uint32_t voice) { return (LilvInstance*)(*_instances)[voice].get(); } -- cgit v1.2.1