From aef939ff10362285ce1ebd872518627e524917bc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 19 Feb 2015 09:44:41 +0000 Subject: Server side presets. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5587 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/events/Delta.cpp | 63 +++++++++++++++++++++++++++++++++++++- src/server/events/Delta.hpp | 11 ++++++- src/server/events/SetPortValue.cpp | 4 ++- src/server/events/SetPortValue.hpp | 6 +++- 4 files changed, 80 insertions(+), 4 deletions(-) (limited to 'src/server/events') diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 03a7ccd5..8df79994 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -17,6 +17,7 @@ #include #include +#include "ingen/Log.hpp" #include "ingen/Store.hpp" #include "ingen/URIs.hpp" #include "raul/Maid.hpp" @@ -60,6 +61,7 @@ Delta::Delta(Engine& engine, , _object(NULL) , _graph(NULL) , _compiled_graph(NULL) + , _state(NULL) , _context(context) , _type(type) , _poly_lock(engine.store()->mutex(), std::defer_lock) @@ -98,6 +100,37 @@ Delta::~Delta() delete _create_event; } +void +Delta::add_set_event(const char* port_symbol, + const void* value, + uint32_t size, + uint32_t type) +{ + BlockImpl* block = dynamic_cast(_object); + PortImpl* port = block->port_by_symbol(port_symbol); + if (!port) { + _engine.log().warn(fmt("Unknown port `%1' in state") % port_symbol); + return; + } + + SetPortValue* ev = new SetPortValue( + _engine, _request_client, _request_id, _time, + port, Atom(size, type, value), true); + + ev->pre_process(); + _set_events.push_back(ev); +} + +static void +s_add_set_event(const char* port_symbol, + void* user_data, + const void* value, + uint32_t size, + uint32_t type) +{ + ((Delta*)user_data)->add_set_event(port_symbol, value, size, type); +} + bool Delta::pre_process() { @@ -216,6 +249,22 @@ Delta::pre_process() } else { _status = Status::BAD_VALUE_TYPE; } + } else if (key == uris.pset_preset) { + if (value.type() == uris.forge.URI) { + const char* str = value.ptr(); + if (Raul::URI::is_valid(str)) { + op = SpecialType::PRESET; + const Raul::URI uri(str); + if ((_state = block->load_preset(Raul::URI(str)))) { + lilv_state_emit_port_values( + _state, s_add_set_event, this); + } + } else { + _status = Status::BAD_VALUE; + } + } else { + _status = Status::BAD_VALUE_TYPE; + } } } @@ -362,6 +411,9 @@ Delta::execute(ProcessContext& context) } } break; + case SpecialType::PRESET: + block->set_enabled(false); + break; case SpecialType::NONE: if (port) { if (key == uris.lv2_minimum) { @@ -382,6 +434,15 @@ Delta::post_process() _poly_lock.unlock(); } + if (_state) { + BlockImpl* block = dynamic_cast(_object); + if (block) { + block->apply_state(_state); + block->set_enabled(true); + } + lilv_state_free(_state); + } + Broadcaster::Transfer t(*_engine.broadcaster()); if (_create_event) { @@ -392,7 +453,7 @@ Delta::post_process() } for (auto& s : _set_events) { - if (s->status() != Status::SUCCESS) { + if (s->synthetic() || s->status() != Status::SUCCESS) { s->post_process(); // Set failed, report error } } diff --git a/src/server/events/Delta.hpp b/src/server/events/Delta.hpp index 43edacbf..750411ff 100644 --- a/src/server/events/Delta.hpp +++ b/src/server/events/Delta.hpp @@ -19,6 +19,8 @@ #include +#include "lilv/lilv.h" + #include "raul/URI.hpp" #include "ControlBindings.hpp" @@ -87,6 +89,11 @@ public: ~Delta(); + void add_set_event(const char* port_symbol, + const void* value, + uint32_t size, + uint32_t type); + bool pre_process(); void execute(ProcessContext& context); void post_process(); @@ -98,7 +105,8 @@ private: ENABLE_BROADCAST, POLYPHONY, POLYPHONIC, - CONTROL_BINDING + CONTROL_BINDING, + PRESET }; typedef std::vector SetEvents; @@ -113,6 +121,7 @@ private: Ingen::Resource* _object; GraphImpl* _graph; CompiledGraph* _compiled_graph; + LilvState* _state; Resource::Graph _context; ControlBindings::Key _binding; Type _type; diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index df0cb06d..655ff281 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -39,10 +39,12 @@ SetPortValue::SetPortValue(Engine& engine, int32_t id, SampleCount timestamp, PortImpl* port, - const Atom& value) + const Atom& value, + bool synthetic) : Event(engine, client, id, timestamp) , _port(port) , _value(value) + , _synthetic(synthetic) { } diff --git a/src/server/events/SetPortValue.hpp b/src/server/events/SetPortValue.hpp index 852c694e..ed81db47 100644 --- a/src/server/events/SetPortValue.hpp +++ b/src/server/events/SetPortValue.hpp @@ -42,7 +42,8 @@ public: int32_t id, SampleCount timestamp, PortImpl* port, - const Atom& value); + const Atom& value, + bool synthetic = false); ~SetPortValue(); @@ -50,12 +51,15 @@ public: void execute(ProcessContext& context); void post_process(); + bool synthetic() const { return _synthetic; } + private: void apply(Context& context); PortImpl* _port; const Atom _value; ControlBindings::Key _binding; + bool _synthetic; }; } // namespace Events -- cgit v1.2.1