From 0f9c8151d5b42b243a499bb31a1e1f0b2e8c5f6f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 8 Feb 2015 07:02:59 +0000 Subject: Server-side copy paste with LV2 state support. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5541 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/LV2Block.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/server/LV2Block.cpp') diff --git a/src/server/LV2Block.cpp b/src/server/LV2Block.cpp index 4369107e..3f6f4be1 100644 --- a/src/server/LV2Block.cpp +++ b/src/server/LV2Block.cpp @@ -22,6 +22,7 @@ #include "lv2/lv2plug.in/ns/ext/morph/morph.h" #include "lv2/lv2plug.in/ns/ext/options/options.h" #include "lv2/lv2plug.in/ns/ext/resize-port/resize-port.h" +#include "lv2/lv2plug.in/ns/ext/state/state.h" #include "raul/Maid.hpp" #include "raul/Array.hpp" @@ -432,6 +433,46 @@ LV2Block::instantiate(BufferFactory& bufs) return ret; } +BlockImpl* +LV2Block::duplicate(Engine& engine, + const Raul::Symbol& symbol, + GraphImpl* parent) +{ + const SampleRate rate = engine.driver()->sample_rate(); + + // Duplicate and instantiate block + LV2Block* dup = new LV2Block(_lv2_plugin, symbol, _polyphonic, parent, rate); + if (!dup->instantiate(*engine.buffer_factory())) { + delete dup; + return NULL; + } + dup->set_properties(properties()); + + // Set duplicate port values and properties to the same as ours + for (uint32_t p = 0; p < num_ports(); ++p) { + const Atom& val = port_impl(p)->value(); + if (val.is_valid()) { + dup->port_impl(p)->set_value(val); + } + dup->port_impl(p)->set_properties(port_impl(p)->properties()); + } + + // Copy internal plugin state + for (uint32_t v = 0; v < _polyphony; ++v) { + LilvState* state = lilv_state_new_from_instance( + _lv2_plugin->lilv_plugin(), instance(v), + &engine.world()->uri_map().urid_map_feature()->urid_map, + NULL, NULL, NULL, NULL, NULL, NULL, LV2_STATE_IS_NATIVE, NULL); + if (state) { + lilv_state_restore(state, dup->instance(v), + NULL, NULL, LV2_STATE_IS_NATIVE, NULL); + lilv_state_free(state); + } + } + + return dup; +} + void LV2Block::activate(BufferFactory& bufs) { -- cgit v1.2.1