diff options
Diffstat (limited to 'src/server/events/Delta.cpp')
-rw-r--r-- | src/server/events/Delta.cpp | 146 |
1 files changed, 74 insertions, 72 deletions
diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 0a7b05ea..11a0b0ff 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -16,91 +16,89 @@ #include "Delta.hpp" +#include "BlockFactory.hpp" +#include "BlockImpl.hpp" #include "Broadcaster.hpp" +#include "CompiledGraph.hpp" #include "ControlBindings.hpp" #include "CreateBlock.hpp" #include "CreateGraph.hpp" #include "CreatePort.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" +#include "NodeImpl.hpp" #include "PluginImpl.hpp" #include "PortImpl.hpp" #include "PortType.hpp" #include "SetPortValue.hpp" +#include "ingen/Atom.hpp" +#include "ingen/FilePath.hpp" #include "ingen/Forge.hpp" +#include "ingen/Interface.hpp" #include "ingen/Log.hpp" +#include "ingen/Message.hpp" +#include "ingen/Node.hpp" +#include "ingen/Status.hpp" #include "ingen/Store.hpp" #include "ingen/URIs.hpp" #include "ingen/World.hpp" -#include "raul/Maid.hpp" +#include "ingen/paths.hpp" +#include "lilv/lilv.h" +#include "raul/Path.hpp" +#include <algorithm> +#include <memory> #include <mutex> #include <set> #include <string> +#include <string_view> #include <utility> #include <vector> -namespace ingen { -namespace server { +namespace ingen::server { class PreProcessContext; namespace events { -Delta::Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Put& msg) +Delta::Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Put& msg) : Event(engine, client, msg.seq, timestamp) - , _create_event(nullptr) , _subject(msg.uri) , _properties(msg.properties) - , _object(nullptr) - , _graph(nullptr) - , _binding(nullptr) - , _state(nullptr) , _context(msg.ctx) , _type(Type::PUT) - , _block(false) { init(); } -Delta::Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Delta& msg) +Delta::Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Delta& msg) : Event(engine, client, msg.seq, timestamp) , _create_event(nullptr) , _subject(msg.uri) , _properties(msg.add) , _remove(msg.remove) - , _object(nullptr) - , _graph(nullptr) - , _binding(nullptr) - , _state(nullptr) , _context(msg.ctx) , _type(Type::PATCH) - , _block(false) { init(); } -Delta::Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::SetProperty& msg) +Delta::Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::SetProperty& msg) : Event(engine, client, msg.seq, timestamp) , _subject(msg.subject) , _properties{{msg.predicate, msg.value}} - , _object(nullptr) - , _graph(nullptr) - , _binding(nullptr) - , _state(nullptr) , _context(msg.ctx) , _type(Type::SET) - , _block(false) { init(); } @@ -136,7 +134,7 @@ Delta::add_set_event(const char* port_symbol, } _set_events.emplace_back( - make_unique<SetPortValue>( + std::make_unique<SetPortValue>( _engine, _request_client, _request_id, _time, port, Atom(size, type, value), false, true)); } @@ -148,7 +146,7 @@ s_add_set_event(const char* port_symbol, uint32_t size, uint32_t type) { - ((Delta*)user_data)->add_set_event(port_symbol, value, size, type); + static_cast<Delta*>(user_data)->add_set_event(port_symbol, value, size, type); } static LilvNode* @@ -156,12 +154,15 @@ get_file_node(LilvWorld* lworld, const URIs& uris, const Atom& value) { if (value.type() == uris.atom_Path) { return lilv_new_file_uri(lworld, nullptr, value.ptr<char>()); - } else if (uris.forge.is_uri(value)) { + } + + if (uris.forge.is_uri(value)) { const std::string str = uris.forge.str(value, false); if (str.substr(0, 5) == "file:") { return lilv_new_uri(lworld, value.ptr<char>()); } } + return nullptr; } @@ -206,12 +207,12 @@ Delta::pre_process(PreProcessContext& ctx) if ((_preset = block->save_preset(_subject, _properties))) { return Event::pre_process_done(Status::SUCCESS); - } else { - return Event::pre_process_done(Status::FAILURE); } + + return Event::pre_process_done(Status::FAILURE); } - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; _object = is_graph_object ? static_cast<ingen::Resource*>(_engine.store()->get(uri_to_path(_subject))) @@ -223,7 +224,7 @@ Delta::pre_process(PreProcessContext& ctx) } if (is_graph_object && !_object) { - Raul::Path path(uri_to_path(_subject)); + const raul::Path path{uri_to_path(_subject)}; bool is_graph = false; bool is_block = false; @@ -232,19 +233,19 @@ Delta::pre_process(PreProcessContext& ctx) ingen::Resource::type(uris, _properties, is_graph, is_block, is_port, is_output); if (is_graph) { - _create_event = make_unique<CreateGraph>( + _create_event = std::make_unique<CreateGraph>( _engine, _request_client, _request_id, _time, path, _properties); } else if (is_block) { - _create_event = make_unique<CreateBlock>( + _create_event = std::make_unique<CreateBlock>( _engine, _request_client, _request_id, _time, path, _properties); } else if (is_port) { - _create_event = make_unique<CreatePort>( + _create_event = std::make_unique<CreatePort>( _engine, _request_client, _request_id, _time, path, _properties); } if (_create_event) { if (_create_event->pre_process(ctx)) { - _object = _engine.store()->get(path); // Get object for setting + _object = _engine.store()->get(path); // Get object for setting } else { return Event::pre_process_done(Status::CREATION_FAILED, _subject); } @@ -334,7 +335,7 @@ Delta::pre_process(PreProcessContext& ctx) } } else if (key == uris.ingen_value || key == uris.ingen_activity) { _set_events.emplace_back( - make_unique<SetPortValue>( + std::make_unique<SetPortValue>( _engine, _request_client, _request_id, _time, port, value, key == uris.ingen_activity)); } else if (key == uris.midi_binding) { @@ -356,7 +357,7 @@ Delta::pre_process(PreProcessContext& ctx) } } else if ((block = dynamic_cast<BlockImpl*>(_object))) { if (key == uris.midi_binding && value == uris.patch_wildcard) { - op = SpecialType::CONTROL_BINDING; // Internal block learn + op = SpecialType::CONTROL_BINDING; // Internal block learn } else if (key == uris.ingen_enabled) { if (value.type() == uris.forge.Bool) { op = SpecialType::ENABLE; @@ -377,8 +378,9 @@ Delta::pre_process(PreProcessContext& ctx) if (!uri.empty()) { op = SpecialType::PRESET; if ((_state = block->load_preset(uri))) { - lilv_state_emit_port_values( - _state, s_add_set_event, this); + lilv_state_emit_port_values(_state.get(), + s_add_set_event, + this); } else { _engine.log().warn("Failed to load preset <%1%>\n", uri); } @@ -392,9 +394,9 @@ Delta::pre_process(PreProcessContext& ctx) if (key == uris.ingen_enabled) { if (value.type() == uris.forge.Bool) { op = SpecialType::ENABLE; - // FIXME: defer this until all other metadata has been processed + // FIXME: defer until all other data has been processed if (value.get<int32_t>() && !_graph->enabled()) { - if (!(_compiled_graph = compile(*_engine.maid(), *_graph))) { + if (!(_compiled_graph = compile(*_graph))) { _status = Status::COMPILATION_FAILED; } } @@ -423,9 +425,8 @@ Delta::pre_process(PreProcessContext& ctx) } else if (value.type() != uris.forge.Bool) { _status = Status::BAD_VALUE_TYPE; } else { - op = SpecialType::POLYPHONIC; + op = SpecialType::POLYPHONIC; obj->set_property(key, value, value.context()); - auto* block = dynamic_cast<BlockImpl*>(obj); if (block) { block->set_polyphonic(value.get<int32_t>()); } @@ -446,9 +447,9 @@ Delta::pre_process(PreProcessContext& ctx) lilv_world_load_bundle(lworld, bundle); const auto new_plugins = _engine.block_factory()->refresh(); - for (const auto& p : new_plugins) { - if (p->bundle_uri() == lilv_node_as_string(bundle)) { - _update.put_plugin(p.get()); + for (const auto& plugin : new_plugins) { + if (plugin->bundle_uri() == lilv_node_as_string(bundle)) { + _update.put_plugin(plugin.get()); } } lilv_node_free(bundle); @@ -474,7 +475,7 @@ Delta::pre_process(PreProcessContext& ctx) } void -Delta::execute(RunContext& context) +Delta::execute(RunContext& ctx) { if (_status != Status::SUCCESS || _preset) { return; @@ -484,23 +485,23 @@ Delta::execute(RunContext& context) if (_create_event) { _create_event->set_time(_time); - _create_event->execute(context); + _create_event->execute(ctx); } for (auto& s : _set_events) { s->set_time(_time); - s->execute(context); + s->execute(ctx); } if (!_removed_bindings.empty()) { - _engine.control_bindings()->remove(context, _removed_bindings); + _engine.control_bindings()->remove(ctx, _removed_bindings); } auto* const object = dynamic_cast<NodeImpl*>(_object); auto* const block = dynamic_cast<BlockImpl*>(_object); auto* const port = dynamic_cast<PortImpl*>(_object); - std::vector<SpecialType>::const_iterator t = _types.begin(); + auto t = _types.begin(); for (const auto& p : _properties) { const URI& key = p.first; const Atom& value = p.second; @@ -514,11 +515,11 @@ Delta::execute(RunContext& context) if (_graph) { if (value.get<int32_t>()) { if (_compiled_graph) { - _graph->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = _graph->swap_compiled_graph(std::move(_compiled_graph)); } _graph->enable(); } else { - _graph->disable(context); + _graph->disable(ctx); } } else if (block) { block->set_enabled(value.get<int32_t>()); @@ -528,15 +529,15 @@ Delta::execute(RunContext& context) if (object) { if (value.get<int32_t>()) { auto* parent = reinterpret_cast<GraphImpl*>(object->parent()); - object->apply_poly(context, parent->internal_poly_process()); + object->apply_poly(ctx, parent->internal_poly_process()); } else { - object->apply_poly(context, 1); + object->apply_poly(ctx, 1); } } } break; case SpecialType::POLYPHONY: if (_graph && - !_graph->apply_internal_poly(context, + !_graph->apply_internal_poly(ctx, *_engine.buffer_factory(), *_engine.maid(), value.get<int32_t>())) { @@ -545,12 +546,12 @@ Delta::execute(RunContext& context) break; case SpecialType::PORT_INDEX: if (port) { - port->set_index(context, value.get<int32_t>()); + port->set_index(ctx, value.get<int32_t>()); } break; case SpecialType::CONTROL_BINDING: if (port) { - if (!_engine.control_bindings()->set_port_binding(context, port, _binding, value)) { + if (!_engine.control_bindings()->set_port_binding(ctx, port, _binding, value)) { _status = Status::BAD_VALUE; } } else if (block) { @@ -572,6 +573,7 @@ Delta::execute(RunContext& context) port->set_maximum(value); } } + break; case SpecialType::LOADED_BUNDLE: break; } @@ -584,24 +586,25 @@ Delta::post_process() if (_state) { auto* block = dynamic_cast<BlockImpl*>(_object); if (block) { - block->apply_state(_engine.sync_worker(), _state); + block->apply_state(_engine.sync_worker(), _state.get()); block->set_enabled(true); } - lilv_state_free(_state); + + _state.reset(); } - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (_create_event) { _create_event->post_process(); if (_create_event->status() != Status::SUCCESS) { - return; // Creation failed, nothing else to do + return; // Creation failed, nothing else to do } } for (auto& s : _set_events) { if (s->synthetic() || s->status() != Status::SUCCESS) { - s->post_process(); // Set failed, report error + s->post_process(); // Set failed, report error } } @@ -670,5 +673,4 @@ Delta::get_execution() const } } // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server |