diff options
Diffstat (limited to 'src/server')
125 files changed, 2161 insertions, 2392 deletions
diff --git a/src/server/.clang-tidy b/src/server/.clang-tidy index fc51d942..a580cc7e 100644 --- a/src/server/.clang-tidy +++ b/src/server/.clang-tidy @@ -1,62 +1,21 @@ Checks: > - *, -*-avoid-c-arrays, - -*-else-after-return, - -*-magic-numbers, - -*-named-parameter, -*-narrowing-conversions, -*-non-private-member-variables-in-classes, - -*-special-member-functions, - -*-uppercase-literal-suffix, -*-vararg, - -abseil-string-find-str-contains, - -android-cloexec-*, -bugprone-branch-clone, -bugprone-parent-virtual-call, -bugprone-reserved-identifier, - -bugprone-signed-char-misuse, -bugprone-suspicious-string-compare, - -cert-str34-c, - -clang-analyzer-optin.cplusplus.VirtualCall, - -cppcoreguidelines-avoid-non-const-global-variables, - -cppcoreguidelines-macro-usage, - -cppcoreguidelines-no-malloc, - -cppcoreguidelines-owning-memory, - -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cert-dcl37-c, + -cert-dcl51-cpp, -cppcoreguidelines-pro-bounds-constant-array-index, - -cppcoreguidelines-pro-bounds-pointer-arithmetic, - -cppcoreguidelines-pro-type-const-cast, - -cppcoreguidelines-pro-type-cstyle-cast, - -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-static-cast-downcast, - -cppcoreguidelines-pro-type-union-access, - -fuchsia-*, - -google-default-arguments, - -google-explicit-constructor, -google-readability-todo, -google-runtime-int, -google-runtime-references, - -hicpp-explicit-conversions, -hicpp-multiway-paths-covered, - -hicpp-no-array-decay, - -hicpp-no-malloc, - -hicpp-signed-bitwise, -llvm-header-guard, - -llvmlibc-*, - -misc-no-recursion, - -misc-unused-parameters, - -modernize-use-default-member-init, - -modernize-use-trailing-return-type, + -misc-redundant-expression, -portability-simd-intrinsics, - -readability-implicit-bool-conversion, - -readability-redundant-member-init, - -readability-use-anyofallof, -CheckOptions: - - key: modernize-use-override.AllowOverrideAndFinal - value: 'true' -CheckOptions: - - key: cppcoreguidelines-explicit-virtual-functions.AllowOverrideAndFinal - value: 'true' -WarningsAsErrors: '*' -HeaderFilterRegex: 'include/ingen/.*|tests/.*|src/.*' -FormatStyle: file +InheritParentConfig: true diff --git a/src/server/ArcImpl.cpp b/src/server/ArcImpl.cpp index 689be199..2c5b4ee1 100644 --- a/src/server/ArcImpl.cpp +++ b/src/server/ArcImpl.cpp @@ -22,15 +22,14 @@ #include "PortImpl.hpp" #include "PortType.hpp" -#include "ingen/URIs.hpp" -#include "raul/Path.hpp" +#include <ingen/URIs.hpp> +#include <raul/Path.hpp> #include <algorithm> #include <cassert> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { /** Constructor for an arc from a block's output port. * @@ -85,33 +84,30 @@ ArcImpl::can_connect(const PortImpl* src, const InputPort* dst) { const ingen::URIs& uris = src->bufs().uris(); return ( - // (Audio | Control | CV) => (Audio | Control | CV) - ( (src->is_a(PortType::ID::CONTROL) || - src->is_a(PortType::ID::AUDIO) || - src->is_a(PortType::ID::CV)) - && (dst->is_a(PortType::ID::CONTROL) - || dst->is_a(PortType::ID::AUDIO) - || dst->is_a(PortType::ID::CV))) + // (Audio | Control | CV) => (Audio | Control | CV) + ((src->is_a(PortType::CONTROL) || src->is_a(PortType::AUDIO) || + src->is_a(PortType::CV)) && + (dst->is_a(PortType::CONTROL) || dst->is_a(PortType::AUDIO) || + dst->is_a(PortType::CV))) - // Equal types - || (src->type() == dst->type() && - src->buffer_type() == dst->buffer_type()) + // Equal types + || + (src->type() == dst->type() && src->buffer_type() == dst->buffer_type()) - // Control => atom:Float Value - || (src->is_a(PortType::ID::CONTROL) && dst->supports(uris.atom_Float)) + // Control => atom:Float Value + || (src->is_a(PortType::CONTROL) && dst->supports(uris.atom_Float)) - // Audio => atom:Sound Value - || (src->is_a(PortType::ID::AUDIO) && dst->supports(uris.atom_Sound)) + // Audio => atom:Sound Value + || (src->is_a(PortType::AUDIO) && dst->supports(uris.atom_Sound)) - // atom:Float Value => Control - || (src->supports(uris.atom_Float) && dst->is_a(PortType::ID::CONTROL)) + // atom:Float Value => Control + || (src->supports(uris.atom_Float) && dst->is_a(PortType::CONTROL)) - // atom:Float Value => CV - || (src->supports(uris.atom_Float) && dst->is_a(PortType::ID::CV)) + // atom:Float Value => CV + || (src->supports(uris.atom_Float) && dst->is_a(PortType::CV)) - // atom:Sound Value => Audio - || (src->supports(uris.atom_Sound) && dst->is_a(PortType::ID::AUDIO))); + // atom:Sound Value => Audio + || (src->supports(uris.atom_Sound) && dst->is_a(PortType::AUDIO))); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/ArcImpl.hpp b/src/server/ArcImpl.hpp index 09c59c8f..5be51187 100644 --- a/src/server/ArcImpl.hpp +++ b/src/server/ArcImpl.hpp @@ -17,23 +17,16 @@ #ifndef INGEN_ENGINE_ARC_IMPL_HPP #define INGEN_ENGINE_ARC_IMPL_HPP -// IWYU pragma: no_include "raul/Path.hpp" - #include "BufferRef.hpp" -#include "ingen/Arc.hpp" -#include "raul/Noncopyable.hpp" +#include <ingen/Arc.hpp> +#include <raul/Noncopyable.hpp> #include <boost/intrusive/slist_hook.hpp> #include <cstdint> -namespace raul { -class Path; // IWYU pragma: keep -} // namespace raul - -namespace ingen { -namespace server { +namespace ingen::server { class InputPort; class PortImpl; @@ -60,8 +53,8 @@ public: ArcImpl(PortImpl* tail, PortImpl* head); ~ArcImpl() override; - inline PortImpl* tail() const { return _tail; } - inline PortImpl* head() const { return _head; } + PortImpl* tail() const { return _tail; } + PortImpl* head() const { return _head; } const raul::Path& tail_path() const override; const raul::Path& head_path() const override; @@ -83,7 +76,6 @@ protected: PortImpl* const _head; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_ARC_IMPL_HPP diff --git a/src/server/BlockFactory.cpp b/src/server/BlockFactory.cpp index 14a50098..a70de0b6 100644 --- a/src/server/BlockFactory.cpp +++ b/src/server/BlockFactory.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard <http://drobilla.net/> + Copyright 2007-2024 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -22,28 +22,30 @@ #include "PortType.hpp" #include "ThreadManager.hpp" -#include "ingen/LV2Features.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "internals/BlockDelay.hpp" -#include "internals/Controller.hpp" -#include "internals/Note.hpp" -#include "internals/Time.hpp" -#include "internals/Trigger.hpp" -#include "lilv/lilv.h" - +#include <ingen/LV2Features.hpp> +#include <ingen/Log.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <internals/BlockDelay.hpp> +#include <internals/Controller.hpp> +#include <internals/Note.hpp> +#include <internals/Time.hpp> +#include <internals/Trigger.hpp> +#include <lilv/lilv.h> + +#include <algorithm> #include <cstdint> +#include <iterator> #include <memory> +#include <string> #include <utility> #include <vector> -namespace ingen { -namespace server { +namespace ingen::server { BlockFactory::BlockFactory(ingen::World& world) : _world(world) - , _has_loaded(false) { load_internal_plugins(); } @@ -84,11 +86,10 @@ BlockFactory::refresh() } // Add any resurrected plugins to response - for (const auto& z : zombies) { - if (!z->is_zombie()) { - new_plugins.insert(z); - } - } + std::copy_if(zombies.begin(), + zombies.end(), + std::inserter(new_plugins, new_plugins.end()), + [](const auto& z) { return !z->is_zombie(); }); return new_plugins; } @@ -97,7 +98,7 @@ PluginImpl* BlockFactory::plugin(const URI& uri) { load_plugin(uri); - const Plugins::const_iterator i = _plugins.find(uri); + const auto i = _plugins.find(uri); return ((i != _plugins.end()) ? i->second.get() : nullptr); } @@ -149,21 +150,23 @@ BlockFactory::load_lv2_plugins() // Build an array of port type nodes for checking compatibility using Types = std::vector<std::shared_ptr<LilvNode>>; Types types; - for (unsigned t = PortType::ID::AUDIO; t <= PortType::ID::ATOM; ++t) { - const URI& uri(PortType(static_cast<PortType::ID>(t)).uri()); + for (auto t = static_cast<unsigned>(PortType::AUDIO); + t <= static_cast<unsigned>(PortType::ATOM); + ++t) { + const URI uri = port_type_uri(static_cast<PortType>(t)); types.push_back(std::shared_ptr<LilvNode>( lilv_new_uri(_world.lilv_world(), uri.c_str()), lilv_node_free)); } const LilvPlugins* plugins = lilv_world_get_all_plugins(_world.lilv_world()); - LILV_FOREACH(plugins, i, plugins) { + LILV_FOREACH (plugins, i, plugins) { const LilvPlugin* lv2_plug = lilv_plugins_get(plugins, i); const URI uri(lilv_node_as_uri(lilv_plugin_get_uri(lv2_plug))); // Ignore plugins that require features Ingen doesn't support LilvNodes* features = lilv_plugin_get_required_features(lv2_plug); bool supported = true; - LILV_FOREACH(nodes, f, features) { + LILV_FOREACH (nodes, f, features) { const char* feature = lilv_node_as_uri(lilv_nodes_get(features, f)); if (!_world.lv2_features().is_supported(feature)) { supported = false; @@ -187,13 +190,13 @@ BlockFactory::load_lv2_plugins() const uint32_t n_ports = lilv_plugin_get_num_ports(lv2_plug); for (uint32_t p = 0; p < n_ports; ++p) { const LilvPort* port = lilv_plugin_get_port_by_index(lv2_plug, p); - supported = false; - for (const auto& t : types) { - if (lilv_port_is_a(lv2_plug, port, t.get())) { - supported = true; - break; - } - } + supported = + std::any_of(types.begin(), + types.end(), + [&lv2_plug, &port](const auto& t) { + return lilv_port_is_a(lv2_plug, port, t.get()); + }); + if (!supported && !lilv_port_has_property(lv2_plug, port, @@ -221,5 +224,4 @@ BlockFactory::load_lv2_plugins() _world.log().info("Loaded %1% plugins\n", _plugins.size()); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/BlockFactory.hpp b/src/server/BlockFactory.hpp index 7cf28325..68699d8a 100644 --- a/src/server/BlockFactory.hpp +++ b/src/server/BlockFactory.hpp @@ -17,8 +17,8 @@ #ifndef INGEN_ENGINE_BLOCKFACTORY_HPP #define INGEN_ENGINE_BLOCKFACTORY_HPP -#include "ingen/URI.hpp" -#include "raul/Noncopyable.hpp" +#include <ingen/URI.hpp> +#include <raul/Noncopyable.hpp> #include <map> #include <memory> @@ -62,7 +62,7 @@ private: Plugins _plugins; ingen::World& _world; - bool _has_loaded; + bool _has_loaded{false}; }; } // namespace server diff --git a/src/server/BlockImpl.cpp b/src/server/BlockImpl.cpp index 26e83eb8..b4f407c3 100644 --- a/src/server/BlockImpl.cpp +++ b/src/server/BlockImpl.cpp @@ -20,20 +20,21 @@ #include "GraphImpl.hpp" #include "PluginImpl.hpp" #include "PortImpl.hpp" +#include "PortType.hpp" #include "RunContext.hpp" #include "ThreadManager.hpp" -#include "lv2/urid/urid.h" -#include "raul/Array.hpp" -#include "raul/Symbol.hpp" +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Symbol.hpp> +#include <algorithm> #include <cassert> #include <cstdint> #include <initializer_list> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { BlockImpl::BlockImpl(PluginImpl* plugin, const raul::Symbol& symbol, @@ -43,10 +44,7 @@ BlockImpl::BlockImpl(PluginImpl* plugin, : NodeImpl(plugin->uris(), parent, symbol) , _plugin(plugin) , _polyphony((polyphonic && parent) ? parent->internal_poly() : 1) - , _mark(Mark::UNVISITED) , _polyphonic(polyphonic) - , _activated(false) - , _enabled(true) { assert(_plugin); assert(_polyphony > 0); @@ -204,13 +202,15 @@ BlockImpl::bypass(RunContext& ctx) } // Dumb bypass - for (PortType t : { PortType::AUDIO, PortType::CV, PortType::ATOM }) { + for (const PortType t : { PortType::AUDIO, PortType::CV, PortType::ATOM }) { for (uint32_t i = 0;; ++i) { - PortImpl* in = nth_port_by_type(i, true, t); - PortImpl* out = nth_port_by_type(i, false, t); + const PortImpl* in = nth_port_by_type(i, true, t); + const PortImpl* out = nth_port_by_type(i, false, t); if (!out) { - break; // Finished writing all outputs - } else if (in) { + break; // Finished writing all outputs + } + + if (in) { // Copy corresponding input to output for (uint32_t v = 0; v < _polyphony; ++v) { out->buffer(v)->copy(ctx, in->buffer(v).get()); @@ -242,13 +242,11 @@ BlockImpl::process(RunContext& ctx) // Find earliest offset of a value change SampleCount chunk_end = ctx.nframes(); for (uint32_t i = 0; _ports && i < _ports->size(); ++i) { - PortImpl* const port = _ports->at(i); + const PortImpl* const port = _ports->at(i); if (port->type() == PortType::CONTROL && port->is_input()) { const SampleCount o = port->next_value_offset( offset, ctx.nframes()); - if (o < chunk_end) { - chunk_end = o; - } + chunk_end = std::min(o, chunk_end); } } @@ -266,7 +264,7 @@ BlockImpl::process(RunContext& ctx) // Emit control port outputs as events for (uint32_t i = 0; _ports && i < _ports->size(); ++i) { - PortImpl* const port = _ports->at(i); + const PortImpl* const port = _ports->at(i); if (port->type() == PortType::CONTROL && port->is_output()) { // TODO: Only emit events when value has actually changed? for (uint32_t v = 0; v < _polyphony; ++v) { @@ -298,5 +296,4 @@ BlockImpl::set_port_buffer(uint32_t, uint32_t, const BufferRef&, SampleCount) << " buffer " << buf << " offset " << offset << std::endl;*/ } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/BlockImpl.hpp b/src/server/BlockImpl.hpp index c285bdac..69564ff4 100644 --- a/src/server/BlockImpl.hpp +++ b/src/server/BlockImpl.hpp @@ -19,24 +19,22 @@ #include "BufferRef.hpp" #include "NodeImpl.hpp" -#include "PortType.hpp" #include "State.hpp" #include "types.hpp" -#include "ingen/Node.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URI.hpp" -#include "lilv/lilv.h" -#include "lv2/urid/urid.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <lilv/lilv.h> +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> #include <boost/intrusive/slist_hook.hpp> -#include <boost/optional/optional.hpp> #include <cstdint> #include <memory> +#include <optional> #include <set> namespace raul { @@ -44,6 +42,9 @@ class Symbol; } // namespace raul namespace ingen { + +enum class PortType; + namespace server { class BufferFactory; @@ -62,7 +63,7 @@ class Worker; * \ingroup engine */ class BlockImpl : public NodeImpl - , public boost::intrusive::slist_base_hook<> // In GraphImpl + , public boost::intrusive::slist_base_hook<> // In GraphImpl { public: using Ports = raul::Array<PortImpl*>; @@ -115,14 +116,16 @@ public: {} /** Save current state as preset. */ - virtual boost::optional<Resource> - save_preset(const URI& bundle, - const Properties& props) { return boost::optional<Resource>(); } + virtual std::optional<Resource> + save_preset(const URI& bundle, const Properties& props) + { + return std::nullopt; + } /** Learn the next incoming MIDI event (for internals) */ virtual void learn() {} - /** Do whatever needs doing in the process thread before process() is called */ + /** Do any necessary preparation in the process thread before process(). */ virtual void pre_process(RunContext& ctx); /** Run block for an entire process cycle (calls run()). */ @@ -208,10 +211,10 @@ protected: uint32_t _polyphony; std::set<BlockImpl*> _providers; ///< Blocks connected to this one's input ports std::set<BlockImpl*> _dependants; ///< Blocks this one's output ports are connected to - Mark _mark; ///< Mark for graph compilation algorithm + Mark _mark{Mark::UNVISITED}; ///< Mark for graph walks bool _polyphonic; - bool _activated; - bool _enabled; + bool _activated{false}; + bool _enabled{true}; }; } // namespace server diff --git a/src/server/Broadcaster.cpp b/src/server/Broadcaster.cpp index 6d32db84..76b21fc6 100644 --- a/src/server/Broadcaster.cpp +++ b/src/server/Broadcaster.cpp @@ -19,19 +19,17 @@ #include "BlockFactory.hpp" #include "PluginImpl.hpp" -#include "ingen/Interface.hpp" +#include <ingen/Interface.hpp> #include <cstddef> -#include <map> #include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { Broadcaster::~Broadcaster() { - std::lock_guard<std::mutex> lock(_clients_mutex); + const std::lock_guard<std::mutex> lock{_clients_mutex}; _clients.clear(); _broadcastees.clear(); } @@ -41,7 +39,7 @@ Broadcaster::~Broadcaster() void Broadcaster::register_client(const std::shared_ptr<Interface>& client) { - std::lock_guard<std::mutex> lock(_clients_mutex); + const std::lock_guard<std::mutex> lock{_clients_mutex}; _clients.insert(client); } @@ -52,7 +50,7 @@ Broadcaster::register_client(const std::shared_ptr<Interface>& client) bool Broadcaster::unregister_client(const std::shared_ptr<Interface>& client) { - std::lock_guard<std::mutex> lock(_clients_mutex); + const std::lock_guard<std::mutex> lock{_clients_mutex}; const size_t erased = _clients.erase(client); _broadcastees.erase(client); return (erased > 0); @@ -73,7 +71,7 @@ Broadcaster::set_broadcast(const std::shared_ptr<Interface>& client, void Broadcaster::send_plugins(const BlockFactory::Plugins& plugins) { - std::lock_guard<std::mutex> lock(_clients_mutex); + const std::lock_guard<std::mutex> lock{_clients_mutex}; for (const auto& c : _clients) { send_plugins_to(c.get(), plugins); } @@ -93,5 +91,4 @@ Broadcaster::send_plugins_to(Interface* client, client->bundle_end(); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/Broadcaster.hpp b/src/server/Broadcaster.hpp index 8e9848f4..4cdf65ca 100644 --- a/src/server/Broadcaster.hpp +++ b/src/server/Broadcaster.hpp @@ -19,18 +19,17 @@ #include "BlockFactory.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Message.hpp" -#include "ingen/URI.hpp" -#include "raul/Noncopyable.hpp" +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/URI.hpp> +#include <raul/Noncopyable.hpp> #include <atomic> #include <memory> #include <mutex> #include <set> -namespace ingen { -namespace server { +namespace ingen::server { /** Broadcaster for all clients. * @@ -76,7 +75,8 @@ public: * This makes doing the right thing in recursive functions that send * updates simple (e.g. Event::post_process()). */ - class Transfer : public raul::Noncopyable { + class Transfer : public raul::Noncopyable + { public: explicit Transfer(Broadcaster& b) : broadcaster(b) { if (++broadcaster._bundle_depth == 1) { @@ -97,7 +97,7 @@ public: send_plugins_to(Interface*, const BlockFactory::Plugins& plugins); void message(const Message& msg) override { - std::lock_guard<std::mutex> lock(_clients_mutex); + const std::lock_guard<std::mutex> lock{_clients_mutex}; for (const auto& c : _clients) { if (c != _ignore_client) { c->message(msg); @@ -120,7 +120,6 @@ private: std::shared_ptr<Interface> _ignore_client; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_BROADCASTER_HPP diff --git a/src/server/Buffer.cpp b/src/server/Buffer.cpp index 36dfaf19..0c4c0951 100644 --- a/src/server/Buffer.cpp +++ b/src/server/Buffer.cpp @@ -18,15 +18,16 @@ #include "BufferFactory.hpp" #include "Engine.hpp" +#include "PortType.hpp" #include "RunContext.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIs.hpp" #include "ingen_config.h" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/urid/urid.h" + +#include <ingen/Atom.hpp> +#include <ingen/Log.hpp> +#include <ingen/URIs.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/urid/urid.h> #include <algorithm> #include <cstdint> @@ -38,8 +39,7 @@ # include <xmmintrin.h> #endif -namespace ingen { -namespace server { +namespace ingen::server { Buffer::Buffer(BufferFactory& bufs, LV2_URID type, @@ -48,13 +48,10 @@ Buffer::Buffer(BufferFactory& bufs, bool external, void*) : _factory(bufs) - , _next(nullptr) , _buf(external ? nullptr : aligned_alloc(capacity)) - , _latest_event(0) , _type(type) , _value_type(value_type) , _capacity(capacity) - , _refs(0) , _external(external) { if (!external && !_buf) { @@ -135,7 +132,7 @@ Buffer::render_sequence(const RunContext& ctx, const Buffer* src, bool add) float value = init ? init->body : 0.0f; SampleCount offset = ctx.offset(); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (ev->time.frames >= offset && ev->body.type == atom_Float) { write_block(value, offset, ev->time.frames, add); value = reinterpret_cast<const LV2_Atom_Float*>(&ev->body)->body; @@ -150,7 +147,9 @@ Buffer::copy(const RunContext& ctx, const Buffer* src) { if (!_buf) { return; - } else if (_type == src->type()) { + } + + if (_type == src->type()) { const uint32_t src_size = src->size(); if (src_size <= _capacity) { memcpy(_buf, src->_buf, src_size); @@ -173,7 +172,12 @@ void Buffer::resize(uint32_t capacity) { if (!_external) { - _buf = realloc(_buf, capacity); + void* const new_buf = realloc(_buf, capacity); + if (!new_buf) { + throw std::bad_alloc{}; + } + + _buf = new_buf; _capacity = capacity; clear(); } else { @@ -184,18 +188,18 @@ Buffer::resize(uint32_t capacity) void* Buffer::port_data(PortType port_type, SampleCount offset) { - switch (port_type.id()) { - case PortType::ID::CONTROL: + switch (port_type) { + case PortType::CONTROL: return &_value_buffer->get<LV2_Atom_Float>()->body; - case PortType::ID::CV: - case PortType::ID::AUDIO: + case PortType::CV: + case PortType::AUDIO: if (_type == _factory.uris().atom_Float) { return &get<LV2_Atom_Float>()->body; } else if (_type == _factory.uris().atom_Sound) { return static_cast<Sample*>(_buf) + offset; } break; - case PortType::ID::ATOM: + case PortType::ATOM: if (_type != _factory.uris().atom_Sound) { return _buf; } @@ -209,8 +213,7 @@ Buffer::port_data(PortType port_type, SampleCount offset) const void* Buffer::port_data(PortType port_type, SampleCount offset) const { - return const_cast<void*>( - const_cast<Buffer*>(this)->port_data(port_type, offset)); + return const_cast<Buffer*>(this)->port_data(port_type, offset); } #ifdef __SSE__ @@ -218,7 +221,7 @@ Buffer::port_data(PortType port_type, SampleCount offset) const static inline __m128 mm_abs_ps(__m128 x) { - const __m128 sign_mask = _mm_set1_ps(-0.0f); // -0.0f = 1 << 31 + const __m128 sign_mask = _mm_set1_ps(-0.0f); // -0.0f = 1 << 31 return _mm_andnot_ps(sign_mask, x); } #endif @@ -259,7 +262,7 @@ Buffer::peak(const RunContext& ctx) const #else const Sample* const buf = samples(); float peak = 0.0f; - for (SampleCount i = 0; i < context.nframes(); ++i) { + for (SampleCount i = 0; i < ctx.nframes(); ++i) { peak = fmaxf(peak, fabsf(buf[i])); } return peak; @@ -300,7 +303,7 @@ Buffer::append_event(int64_t frames, auto* atom = get<LV2_Atom>(); if (atom->type == _factory.uris().atom_Chunk) { - clear(); // Chunk initialized with prepare_output_write(), clear + clear(); // Chunk initialized with prepare_output_write(), clear } if (sizeof(LV2_Atom) + atom->size + lv2_atom_pad_size(size) > _capacity) { @@ -340,14 +343,14 @@ Buffer::append_event_buffer(const Buffer* buf) reinterpret_cast<const LV2_Atom_Sequence*>(buf->get<LV2_Atom>()); if (seq->atom.type == _factory.uris().atom_Chunk) { - clear(); // Chunk initialized with prepare_output_write(), clear + clear(); // Chunk initialized with prepare_output_write(), clear } const uint32_t total_size = lv2_atom_total_size(&seq->atom); uint8_t* const end = reinterpret_cast<uint8_t*>(seq) + total_size; const uint32_t n_bytes = bseq->atom.size - sizeof(bseq->body); if (sizeof(LV2_Atom) + total_size + n_bytes >= _capacity) { - return false; // Not enough space + return false; // Not enough space } memcpy(end, bseq + 1, n_bytes); @@ -363,7 +366,7 @@ Buffer::next_value_offset(SampleCount offset, SampleCount end) const { if (_type == _factory.uris().atom_Sequence && _value_type) { const auto* seq = get<const LV2_Atom_Sequence>(); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (ev->time.frames > offset && ev->time.frames < end && ev->body.type == _value_type) { @@ -416,10 +419,12 @@ Buffer::update_value_buffer(SampleCount offset) auto* seq = get<LV2_Atom_Sequence>(); LV2_Atom_Event* latest = nullptr; - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (ev->time.frames > offset) { break; - } else if (ev->body.type == _value_type) { + } + + if (ev->body.type == _value_type) { latest = ev; } } @@ -433,9 +438,9 @@ Buffer::update_value_buffer(SampleCount offset) void* Buffer::aligned_alloc(size_t size) { -#ifdef HAVE_POSIX_MEMALIGN +#if USE_POSIX_MEMALIGN void* buf = nullptr; - if (!posix_memalign(static_cast<void**>(&buf), 16, size)) { + if (!posix_memalign(&buf, 16, size)) { memset(buf, 0, size); return buf; } @@ -457,5 +462,4 @@ intrusive_ptr_release(Buffer* b) b->deref(); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp index 21364fd9..2c32076b 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -19,13 +19,12 @@ #include "BufferFactory.hpp" #include "BufferRef.hpp" -#include "PortType.hpp" +#include "server.h" #include "types.hpp" -#include "ingen/URIs.hpp" -#include "ingen/ingen.h" -#include "lv2/atom/atom.h" -#include "lv2/urid/urid.h" +#include <ingen/URIs.hpp> +#include <lv2/atom/atom.h> +#include <lv2/urid/urid.h> #include <atomic> #include <cassert> @@ -34,13 +33,15 @@ namespace ingen { +enum class PortType; + class Atom; namespace server { class RunContext; -class INGEN_API Buffer +class INGEN_SERVER_API Buffer { public: Buffer(BufferFactory& bufs, @@ -61,10 +62,10 @@ public: void* port_data(PortType port_type, SampleCount offset); const void* port_data(PortType port_type, SampleCount offset) const; - inline LV2_URID type() const { return _type; } - inline LV2_URID value_type() const { return _value_type; } - inline uint32_t capacity() const { return _capacity; } - inline uint32_t size() const { + LV2_URID type() const { return _type; } + LV2_URID value_type() const { return _value_type; } + uint32_t capacity() const { return _capacity; } + uint32_t size() const { return is_audio() ? _capacity : sizeof(LV2_Atom) + get<LV2_Atom>()->size; } @@ -78,52 +79,60 @@ public: */ void set_type(GetFn get_func, LV2_URID type, LV2_URID value_type); - inline bool is_audio() const { + bool is_audio() const { return _type == _factory.uris().atom_Sound; } - inline bool is_control() const { + bool is_control() const { return _type == _factory.uris().atom_Float; } - inline bool is_sequence() const { + bool is_sequence() const { return _type == _factory.uris().atom_Sequence; } /// Audio or float buffers only - inline const Sample* samples() const { + const Sample* samples() const { if (is_control()) { return static_cast<const Sample*>( LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>())); - } else if (is_audio()) { + } + + if (is_audio()) { return static_cast<const Sample*>(_buf); } + return nullptr; } /// Audio buffers only - inline Sample* samples() { + Sample* samples() { if (is_control()) { return static_cast<Sample*>(LV2_ATOM_BODY(get<LV2_Atom_Float>())); - } else if (is_audio()) { + } + + if (is_audio()) { return static_cast<Sample*>(_buf); } + return nullptr; } /// Numeric buffers only - inline Sample value_at(SampleCount offset) const { + Sample value_at(SampleCount offset) const { if (is_audio() || is_control()) { return samples()[offset]; - } else if (_value_buffer) { + } + + if (_value_buffer) { return reinterpret_cast<const LV2_Atom_Float*>(value())->body; } + return 0.0f; } - inline void set_block(const Sample val, - const SampleCount start, - const SampleCount end) + void + set_block(const Sample val, const SampleCount start, const SampleCount end) { if (is_sequence()) { append_event(start, sizeof(val), _factory.uris().atom_Float, @@ -142,9 +151,8 @@ public: } } - inline void add_block(const Sample val, - const SampleCount start, - const SampleCount end) + void + add_block(const Sample val, const SampleCount start, const SampleCount end) { assert(is_audio() || is_control()); assert(end <= _capacity / sizeof(Sample)); @@ -155,10 +163,10 @@ public: } } - inline void write_block(const Sample val, - const SampleCount start, - const SampleCount end, - const bool add) + void write_block(const Sample val, + const SampleCount start, + const SampleCount end, + const bool add) { if (add) { add_block(val, start, end); @@ -212,9 +220,9 @@ public: template<typename T> const T* get() const { return reinterpret_cast<const T*>(_buf); } template<typename T> T* get() { return reinterpret_cast<T*>(_buf); } - inline void ref() { ++_refs; } + void ref() { ++_refs; } - inline void deref() { + void deref() { if ((--_refs) == 0) { recycle(); } @@ -229,15 +237,15 @@ private: BufferFactory& _factory; // NOLINTNEXTLINE(clang-analyzer-webkit.NoUncountedMemberChecker) - Buffer* _next; ///< Intrusive linked list for BufferFactory + Buffer* _next{nullptr}; ///< Intrusive linked list for BufferFactory void* _buf; ///< Actual buffer memory BufferRef _value_buffer; ///< Value buffer for numeric sequences - int64_t _latest_event; + int64_t _latest_event{0}; LV2_URID _type; LV2_URID _value_type; uint32_t _capacity; - std::atomic<unsigned> _refs; ///< Intrusive reference count + std::atomic<unsigned> _refs{0}; ///< Intrusive reference count bool _external; ///< Buffer is externally allocated }; diff --git a/src/server/BufferFactory.cpp b/src/server/BufferFactory.cpp index 4ecdfc3b..b8f6ee35 100644 --- a/src/server/BufferFactory.cpp +++ b/src/server/BufferFactory.cpp @@ -19,17 +19,16 @@ #include "Buffer.hpp" #include "Engine.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/atom/atom.h" -#include "lv2/urid/urid.h" +#include <ingen/Log.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/atom/atom.h> +#include <lv2/urid/urid.h> #include <algorithm> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { BufferFactory::BufferFactory(Engine& engine, URIs& uris) : _free_audio(nullptr) @@ -38,10 +37,8 @@ BufferFactory::BufferFactory(Engine& engine, URIs& uris) , _free_object(nullptr) , _engine(engine) , _uris(uris) - , _seq_size(0) , _silent_buffer(nullptr) -{ -} +{} BufferFactory::~BufferFactory() { @@ -101,19 +98,25 @@ BufferFactory::default_size(LV2_URID type) const { if (type == _uris.atom_Float) { return sizeof(LV2_Atom_Float); - } else if (type == _uris.atom_Sound) { + } + + if (type == _uris.atom_Sound) { return audio_buffer_size(_engine.block_length()); - } else if (type == _uris.atom_URID) { + } + + if (type == _uris.atom_URID) { return sizeof(LV2_Atom_URID); - } else if (type == _uris.atom_Sequence) { - if (_seq_size == 0) { + } + + if (type == _uris.atom_Sequence) { + if (_seq_size == 0U) { return _engine.sequence_size(); - } else { - return _seq_size; } - } else { - return 0; + + return _seq_size; } + + return 0; } Buffer* @@ -146,7 +149,7 @@ BufferFactory::get_buffer(LV2_URID type, try_head->_next = nullptr; try_head->set_type(&BufferFactory::get_buffer, type, value_type); try_head->clear(); - return BufferRef(try_head); + return {try_head}; } BufferRef @@ -155,12 +158,12 @@ BufferFactory::claim_buffer(LV2_URID type, LV2_URID value_type, uint32_t) Buffer* try_head = try_get_buffer(type); if (!try_head) { _engine.world().log().rt_error("Failed to obtain buffer"); - return BufferRef(); + return {}; } try_head->_next = nullptr; try_head->set_type(&BufferFactory::claim_buffer, type, value_type); - return BufferRef(try_head); + return {try_head}; } BufferRef @@ -181,7 +184,7 @@ BufferFactory::create(LV2_URID type, LV2_URID value_type, uint32_t capacity) capacity = std::max(capacity, default_size(_uris.atom_Sound)); } - return BufferRef(new Buffer(*this, type, value_type, capacity)); + return {new Buffer(*this, type, value_type, capacity)}; } void @@ -195,5 +198,4 @@ BufferFactory::recycle(Buffer* buf) } while (!head_ptr.compare_exchange_weak(try_head, buf)); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/BufferFactory.hpp b/src/server/BufferFactory.hpp index 19a61bed..dbadaede 100644 --- a/src/server/BufferFactory.hpp +++ b/src/server/BufferFactory.hpp @@ -17,18 +17,20 @@ #ifndef INGEN_ENGINE_BUFFERFACTORY_HPP #define INGEN_ENGINE_BUFFERFACTORY_HPP -#include "ingen/URIs.hpp" -#include "ingen/ingen.h" -#include "lv2/urid/urid.h" - #include "BufferRef.hpp" +#include "server.h" #include "types.hpp" +#include <ingen/URIs.hpp> +#include <lv2/urid/urid.h> + #include <atomic> #include <cstdint> #include <mutex> -namespace raul { class Maid; } +namespace raul { +class Maid; +} // namespace raul namespace ingen { @@ -39,7 +41,8 @@ namespace server { class Buffer; class Engine; -class INGEN_API BufferFactory { +class INGEN_SERVER_API BufferFactory +{ public: BufferFactory(Engine& engine, URIs& uris); ~BufferFactory(); @@ -82,29 +85,33 @@ private: Buffer* try_get_buffer(LV2_URID type); - inline std::atomic<Buffer*>& free_list(LV2_URID type) { + std::atomic<Buffer*>& free_list(LV2_URID type) { if (type == _uris.atom_Float) { return _free_control; - } else if (type == _uris.atom_Sound) { + } + + if (type == _uris.atom_Sound) { return _free_audio; - } else if (type == _uris.atom_Sequence) { + } + + if (type == _uris.atom_Sequence) { return _free_sequence; - } else { - return _free_object; } + + return _free_object; } static void free_list(Buffer* head); - std::atomic<Buffer*> _free_audio; - std::atomic<Buffer*> _free_control; - std::atomic<Buffer*> _free_sequence; - std::atomic<Buffer*> _free_object; + std::atomic<Buffer*> _free_audio{nullptr}; + std::atomic<Buffer*> _free_control{nullptr}; + std::atomic<Buffer*> _free_sequence{nullptr}; + std::atomic<Buffer*> _free_object{nullptr}; std::mutex _mutex; Engine& _engine; URIs& _uris; - uint32_t _seq_size; + uint32_t _seq_size{0U}; BufferRef _silent_buffer; }; diff --git a/src/server/BufferRef.hpp b/src/server/BufferRef.hpp index 958fcb06..cc5b840f 100644 --- a/src/server/BufferRef.hpp +++ b/src/server/BufferRef.hpp @@ -17,22 +17,20 @@ #ifndef INGEN_ENGINE_BUFFER_REF_HPP #define INGEN_ENGINE_BUFFER_REF_HPP -#include "ingen/ingen.h" +#include "server.h" #include <boost/smart_ptr/intrusive_ptr.hpp> // IWYU pragma: export -namespace ingen { -namespace server { +namespace ingen::server { class Buffer; using BufferRef = boost::intrusive_ptr<Buffer>; // Defined in Buffer.cpp -INGEN_API void intrusive_ptr_add_ref(Buffer* b); -INGEN_API void intrusive_ptr_release(Buffer* b); +INGEN_SERVER_API void intrusive_ptr_add_ref(Buffer* b); +INGEN_SERVER_API void intrusive_ptr_release(Buffer* b); -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_BUFFER_REF_HPP diff --git a/src/server/ClientUpdate.cpp b/src/server/ClientUpdate.cpp index 5034257b..008e9843 100644 --- a/src/server/ClientUpdate.cpp +++ b/src/server/ClientUpdate.cpp @@ -23,11 +23,14 @@ #include "PortImpl.hpp" #include "PortType.hpp" -#include "ingen/Arc.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/URIs.hpp" +#include <ingen/Arc.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <raul/Path.hpp> #include <boost/intrusive/slist.hpp> @@ -38,8 +41,7 @@ #include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { void ClientUpdate::put(const URI& uri, @@ -166,5 +168,4 @@ ClientUpdate::send(Interface& dest) } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/ClientUpdate.hpp b/src/server/ClientUpdate.hpp index 9fadae90..1d16e6d6 100644 --- a/src/server/ClientUpdate.hpp +++ b/src/server/ClientUpdate.hpp @@ -17,10 +17,10 @@ #ifndef INGEN_ENGINE_CLIENTUPDATE_HPP #define INGEN_ENGINE_CLIENTUPDATE_HPP -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URI.hpp" -#include "raul/Path.hpp" +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <raul/Path.hpp> #include <string> #include <vector> diff --git a/src/server/CompiledGraph.cpp b/src/server/CompiledGraph.cpp index e644d982..89fc8843 100644 --- a/src/server/CompiledGraph.cpp +++ b/src/server/CompiledGraph.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2015-2017 David Robillard <http://drobilla.net/> + Copyright 2015-2024 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -21,13 +21,12 @@ #include "GraphImpl.hpp" #include "ThreadManager.hpp" -#include "ingen/Atom.hpp" -#include "ingen/ColorContext.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Log.hpp" -#include "ingen/World.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" +#include <ingen/Atom.hpp> +#include <ingen/ColorContext.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Log.hpp> +#include <ingen/World.hpp> +#include <raul/Path.hpp> #include <boost/intrusive/slist.hpp> @@ -36,14 +35,16 @@ #include <cstdint> #include <cstdio> #include <exception> +#include <functional> #include <limits> +#include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { /** Graph contains ambiguous feedback with no delay nodes. */ -class FeedbackException : public std::exception { +class FeedbackException : public std::exception +{ public: explicit FeedbackException(const BlockImpl* n) : node(n) @@ -60,26 +61,24 @@ public: static bool has_provider_with_many_dependants(const BlockImpl* n) { - for (const auto* p : n->providers()) { - if (p->dependants().size() > 1) { - return true; - } - } - - return false; + return std::any_of(n->providers().begin(), + n->providers().end(), + [](const auto* p) { + return p->dependants().size() > 1; + }); } CompiledGraph::CompiledGraph(GraphImpl* graph) - : _master(std::unique_ptr<Task>(new Task(Task::Mode::SEQUENTIAL))) + : _master{std::make_unique<Task>(Task::Mode::SEQUENTIAL)} { compile_graph(graph); } -raul::managed_ptr<CompiledGraph> -CompiledGraph::compile(raul::Maid& maid, GraphImpl& graph) +std::unique_ptr<CompiledGraph> +CompiledGraph::compile(GraphImpl& graph) { try { - return maid.make_managed<CompiledGraph>(&graph); + return std::unique_ptr<CompiledGraph>(new CompiledGraph(&graph)); } catch (const FeedbackException& e) { Log& log = graph.engine().log(); if (e.node && e.root) { @@ -95,13 +94,11 @@ CompiledGraph::compile(raul::Maid& maid, GraphImpl& graph) static size_t num_unvisited_dependants(const BlockImpl* block) { - size_t count = 0; - for (const BlockImpl* b : block->dependants()) { - if (b->get_mark() == BlockImpl::Mark::UNVISITED) { - ++count; - } - } - return count; + return std::count_if(block->dependants().begin(), + block->dependants().end(), + [](const auto* b) { + return b->get_mark() == BlockImpl::Mark::UNVISITED; + }); } static size_t @@ -160,7 +157,7 @@ CompiledGraph::compile_graph(GraphImpl* graph) _master = Task::simplify(std::move(_master)); if (graph->engine().world().conf().option("trace").get<int32_t>()) { - ColorContext ctx(stderr, ColorContext::Color::YELLOW); + const ColorContext ctx{stderr, ColorContext::Color::YELLOW}; dump(graph->path()); } } @@ -285,5 +282,4 @@ CompiledGraph::dump(const std::string& name) const sink(")\n"); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/CompiledGraph.hpp b/src/server/CompiledGraph.hpp index 8c2bb815..1949563d 100644 --- a/src/server/CompiledGraph.hpp +++ b/src/server/CompiledGraph.hpp @@ -19,16 +19,14 @@ #include "Task.hpp" -#include "raul/Maid.hpp" -#include "raul/Noncopyable.hpp" +#include <raul/Noncopyable.hpp> #include <cstddef> #include <memory> #include <set> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { class BlockImpl; class GraphImpl; @@ -40,18 +38,15 @@ class RunContext; * execute the nodes in order and have nodes always executed before any of * their dependencies. */ -class CompiledGraph : public raul::Maid::Disposable - , public raul::Noncopyable +class CompiledGraph : public raul::Noncopyable { public: - static raul::managed_ptr<CompiledGraph> compile(raul::Maid& maid, GraphImpl& graph); + static std::unique_ptr<CompiledGraph> compile(GraphImpl& graph); void run(RunContext& ctx); private: - friend class raul::Maid; ///< Allow make_managed to construct - - CompiledGraph(GraphImpl* graph); + explicit CompiledGraph(GraphImpl* graph); using BlockSet = std::set<BlockImpl*>; @@ -73,13 +68,12 @@ private: std::unique_ptr<Task> _master; }; -inline raul::managed_ptr<CompiledGraph> -compile(raul::Maid& maid, GraphImpl& graph) +inline std::unique_ptr<CompiledGraph> +compile(GraphImpl& graph) { - return CompiledGraph::compile(maid, graph); + return CompiledGraph::compile(graph); } -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_COMPILEDGRAPH_HPP diff --git a/src/server/ControlBindings.cpp b/src/server/ControlBindings.cpp index 8bf52dfd..489d5384 100644 --- a/src/server/ControlBindings.cpp +++ b/src/server/ControlBindings.cpp @@ -23,18 +23,18 @@ #include "RunContext.hpp" #include "ThreadManager.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/forge.h" -#include "lv2/atom/util.h" -#include "lv2/midi/midi.h" -#include "lv2/urid/urid.h" -#include "raul/Path.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Log.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/forge.h> +#include <lv2/atom/util.h> +#include <lv2/midi/midi.h> +#include <lv2/urid/urid.h> +#include <raul/Path.hpp> #include <boost/intrusive/bstree.hpp> @@ -43,8 +43,7 @@ #include <cstring> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { ControlBindings::ControlBindings(Engine& engine) : _engine(engine) @@ -74,6 +73,12 @@ ControlBindings::port_binding(PortImpl* port) const return binding_key(binding); } +static int16_t +get_atom_num(const LV2_Atom* const atom) +{ + return static_cast<int16_t>(reinterpret_cast<const LV2_Atom_Int*>(atom)->body); +} + ControlBindings::Key ControlBindings::binding_key(const Atom& binding) const { @@ -83,9 +88,31 @@ ControlBindings::binding_key(const Atom& binding) const if (binding.type() == uris.atom_Object) { const auto* obj = static_cast<const LV2_Atom_Object_Body*>(binding.get_body()); if (obj->otype == uris.midi_Bender) { - key = Key(Type::MIDI_BENDER); + lv2_atom_object_body_get(binding.size(), + obj, + uris.midi_channel.urid(), + &num, + nullptr); + if (!num) { + _engine.log().rt_error("Bender binding missing channel\n"); + } else if (num->type != uris.atom_Int) { + _engine.log().rt_error("Bender channel not an integer\n"); + } else { + key = Key(Type::MIDI_BENDER, get_atom_num(num)); + } } else if (obj->otype == uris.midi_ChannelPressure) { - key = Key(Type::MIDI_CHANNEL_PRESSURE); + lv2_atom_object_body_get(binding.size(), + obj, + uris.midi_channel.urid(), + &num, + nullptr); + if (!num) { + _engine.log().rt_error("Pressure binding missing channel\n"); + } else if (num->type != uris.atom_Int) { + _engine.log().rt_error("Pressure channel not an integer\n"); + } else { + key = Key(Type::MIDI_CHANNEL_PRESSURE, get_atom_num(num)); + } } else if (obj->otype == uris.midi_Controller) { lv2_atom_object_body_get(binding.size(), obj, @@ -97,7 +124,7 @@ ControlBindings::binding_key(const Atom& binding) const } else if (num->type != uris.atom_Int) { _engine.log().rt_error("Controller number not an integer\n"); } else { - key = Key(Type::MIDI_CC, reinterpret_cast<LV2_Atom_Int*>(num)->body); + key = Key(Type::MIDI_CC, get_atom_num(num)); } } else if (obj->otype == uris.midi_NoteOn) { lv2_atom_object_body_get(binding.size(), @@ -110,7 +137,7 @@ ControlBindings::binding_key(const Atom& binding) const } else if (num->type != uris.atom_Int) { _engine.log().rt_error("Note number not an integer\n"); } else { - key = Key(Type::MIDI_NOTE, reinterpret_cast<LV2_Atom_Int*>(num)->body); + key = Key(Type::MIDI_NOTE, get_atom_num(num)); } } } else if (binding.type()) { @@ -120,21 +147,28 @@ ControlBindings::binding_key(const Atom& binding) const } ControlBindings::Key -ControlBindings::midi_event_key(uint16_t, const uint8_t* buf, uint16_t& value) +ControlBindings::midi_event_key(const uint8_t* buf, uint16_t& value) { switch (lv2_midi_message_type(buf)) { case LV2_MIDI_MSG_CONTROLLER: - value = static_cast<int8_t>(buf[2]); - return {Type::MIDI_CC, static_cast<int8_t>(buf[1])}; + value = buf[2]; + return {Type::MIDI_CC, + static_cast<int16_t>(((buf[0] & 0x0FU) << 8U) | buf[1])}; case LV2_MIDI_MSG_BENDER: - value = (static_cast<int8_t>(buf[2]) << 7) + static_cast<int8_t>(buf[1]); - return {Type::MIDI_BENDER}; + value = static_cast<uint16_t>((buf[2] << 7U) + buf[1]); + return {Type::MIDI_BENDER, static_cast<int16_t>((buf[0] & 0x0FU))}; case LV2_MIDI_MSG_CHANNEL_PRESSURE: - value = static_cast<int8_t>(buf[1]); - return {Type::MIDI_CHANNEL_PRESSURE}; + value = buf[1]; + return {Type::MIDI_CHANNEL_PRESSURE, + static_cast<int16_t>((buf[0] & 0x0FU))}; case LV2_MIDI_MSG_NOTE_ON: - value = 1.0f; - return {Type::MIDI_NOTE, static_cast<int8_t>(buf[1])}; + value = 1; + return {Type::MIDI_NOTE, + static_cast<int16_t>(((buf[0] & 0x0FU) << 8U) | buf[1])}; + case LV2_MIDI_MSG_NOTE_OFF: + value = 0; + return {Type::MIDI_NOTE, + static_cast<int16_t>(((buf[0] & 0x0FU) << 8U) | buf[1])}; default: return {}; } @@ -152,9 +186,9 @@ ControlBindings::set_port_binding(RunContext&, binding->port = port; _bindings->insert(*binding); return true; - } else { - return false; } + + return false; } void @@ -165,15 +199,16 @@ ControlBindings::port_value_changed(RunContext& ctx, { const ingen::URIs& uris = ctx.engine().world().uris(); if (!!key) { - int16_t value = port_value_to_control( - ctx, port, key.type, value_atom); + const int16_t value = + port_value_to_control(ctx, port, key.type, value_atom); + uint16_t size = 0; uint8_t buf[4]; switch (key.type) { case Type::MIDI_CC: size = 3; buf[0] = LV2_MIDI_MSG_CONTROLLER; - buf[1] = key.num; + buf[1] = static_cast<uint8_t>(key.num); buf[2] = static_cast<int8_t>(value); break; case Type::MIDI_CHANNEL_PRESSURE: @@ -194,7 +229,7 @@ ControlBindings::port_value_changed(RunContext& ctx, } else if (value == 0) { buf[0] = LV2_MIDI_MSG_NOTE_OFF; } - buf[1] = key.num; + buf[1] = static_cast<uint8_t>(key.num); buf[2] = 0x64; // MIDI spec default break; default: @@ -215,7 +250,7 @@ ControlBindings::start_learn(PortImpl* port) ThreadManager::assert_thread(THREAD_PRE_PROCESS); Binding* b = _learn_binding.load(); if (!b) { - _learn_binding = new Binding(Type::NULL_CONTROL, port); + _learn_binding = new Binding(); } else { b->port = port; } @@ -262,7 +297,7 @@ ControlBindings::control_to_port_value(RunContext& ctx, float max = 1.0f; get_range(ctx, port, &min, &max); - return normal * (max - min) + min; + return (normal * (max - min)) + min; } int16_t @@ -282,24 +317,18 @@ ControlBindings::port_value_to_control(RunContext& ctx, const float value = value_atom.get<float>(); float normal = (value - min) / (max - min); - if (normal < 0.0f) { - normal = 0.0f; - } - - if (normal > 1.0f) { - normal = 1.0f; - } + normal = std::max(0.0f, std::min(1.0f, normal)); if (port->is_logarithmic()) { - normal = logf(normal * (static_cast<float>(M_E) - 1.0f) + 1.0f); + normal = logf((normal * (static_cast<float>(M_E) - 1.0f)) + 1.0f); } switch (type) { case Type::MIDI_CC: case Type::MIDI_CHANNEL_PRESSURE: - return lrintf(normal * 127.0f); + return static_cast<int16_t>(lrintf(normal * 127.0f)); case Type::MIDI_BENDER: - return lrintf(normal * 16383.0f); + return static_cast<int16_t>(lrintf(normal * 16383.0f)); case Type::MIDI_NOTE: return (value > 0.0f) ? 1 : 0; default: @@ -322,9 +351,13 @@ forge_binding(const URIs& uris, break; case ControlBindings::Type::MIDI_BENDER: lv2_atom_forge_object(forge, &frame, 0, uris.midi_Bender); + lv2_atom_forge_key(forge, uris.midi_channel); + lv2_atom_forge_int(forge, value); break; case ControlBindings::Type::MIDI_CHANNEL_PRESSURE: lv2_atom_forge_object(forge, &frame, 0, uris.midi_ChannelPressure); + lv2_atom_forge_key(forge, uris.midi_channel); + lv2_atom_forge_int(forge, value); break; case ControlBindings::Type::MIDI_NOTE: lv2_atom_forge_object(forge, &frame, 0, uris.midi_NoteOn); @@ -353,7 +386,7 @@ ControlBindings::set_port_value(RunContext& ctx, // TODO: Set port value property so it is saved port->set_control_value(ctx, ctx.start(), val); - URIs& uris = ctx.engine().world().uris(); + const URIs& uris = ctx.engine().world().uris(); ctx.notify(uris.ingen_value, ctx.start(), port, sizeof(float), _forge.Float, &val); } @@ -411,22 +444,22 @@ ControlBindings::pre_process(RunContext& ctx, Buffer* buffer) _feedback->clear(); if ((!_learn_binding && _bindings->empty()) || !buffer->get<LV2_Atom>()) { - return; // Don't bother reading input + return; // Don't bother reading input } auto* seq = buffer->get<LV2_Atom_Sequence>(); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (ev->body.type == uris.midi_MidiEvent) { const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY(&ev->body)); - const Key key = midi_event_key(ev->body.size, buf, value); + const Key key = midi_event_key(buf, value); if (_learn_binding && !!key) { - finish_learn(ctx, key); // Learn new binding + finish_learn(ctx, key); // Learn new binding } // Set all controls bound to this key const Binding k = {key, nullptr}; - for (Bindings::const_iterator i = _bindings->lower_bound(k); + for (auto i = _bindings->lower_bound(k); i != _bindings->end() && i->key == key; ++i) { set_port_value(ctx, i->port, key.type, value); @@ -443,5 +476,4 @@ ControlBindings::post_process(RunContext&, Buffer* buffer) } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/ControlBindings.hpp b/src/server/ControlBindings.hpp index 1c231e22..0e6dbf63 100644 --- a/src/server/ControlBindings.hpp +++ b/src/server/ControlBindings.hpp @@ -19,9 +19,10 @@ #include "BufferRef.hpp" -#include "lv2/atom/forge.h" -#include "raul/Maid.hpp" +#include <lv2/atom/forge.h> +#include <raul/Maid.hpp> +#include <boost/intrusive/options.hpp> #include <boost/intrusive/set.hpp> #include <boost/intrusive/set_hook.hpp> @@ -30,15 +31,9 @@ #include <memory> #include <vector> -namespace raul { class Path; } - -namespace boost { -namespace intrusive { - -template <class Compare> struct compare; - -} // namespace intrusive -} // namespace boost +namespace raul { +class Path; +} // namespace raul namespace ingen { @@ -51,7 +46,8 @@ class Engine; class RunContext; class PortImpl; -class ControlBindings { +class ControlBindings +{ public: enum class Type : uint16_t { NULL_CONTROL, @@ -64,15 +60,20 @@ public: }; struct Key { - Key(Type t=Type::NULL_CONTROL, int16_t n=0) : type(t), num(n) {} - inline bool operator<(const Key& other) const { + Key(Type t, int16_t n) noexcept : type{t}, num{n} {} + Key() noexcept : Key{Type::NULL_CONTROL, 0U} {} + + bool operator<(const Key& other) const { return ((type < other.type) || (type == other.type && num < other.num)); } - inline bool operator==(const Key& other) const { + + bool operator==(const Key& other) const { return type == other.type && num == other.num; } - inline bool operator!() const { return type == Type::NULL_CONTROL; } + + bool operator!() const { return type == Type::NULL_CONTROL; } + Type type; int16_t num; }; @@ -80,9 +81,10 @@ public: /** One binding of a controller to a port. */ struct Binding : public boost::intrusive::set_base_hook<>, public raul::Maid::Disposable { - Binding(Key k=Key(), PortImpl* p=nullptr) : key(k), port(p) {} + Binding(Key k, PortImpl* p) noexcept : key{k}, port{p} {} + Binding() noexcept : Binding{Key{}, nullptr} {} - inline bool operator<(const Binding& rhs) const { return key < rhs.key; } + bool operator<(const Binding& rhs) const { return key < rhs.key; } Key key; PortImpl* port; @@ -129,7 +131,7 @@ private: boost::intrusive::compare<BindingLess>>; static Key - midi_event_key(uint16_t size, const uint8_t* buf, uint16_t& value); + midi_event_key(const uint8_t* buf, uint16_t& value); void set_port_value(RunContext& ctx, PortImpl* port, diff --git a/src/server/DirectDriver.hpp b/src/server/DirectDriver.hpp index 7c683493..bc52fc3a 100644 --- a/src/server/DirectDriver.hpp +++ b/src/server/DirectDriver.hpp @@ -24,20 +24,17 @@ #include "RunContext.hpp" #include "types.hpp" -#include "raul/Path.hpp" +#include <raul/Path.hpp> #include <boost/intrusive/slist.hpp> #include <cstddef> +#include <cstdint> #include <string> -namespace boost { -namespace intrusive { - +namespace boost::intrusive { template <bool Enabled> struct cache_last; - -} // namespace intrusive -} // namespace boost +} // namespace boost::intrusive namespace ingen { @@ -51,12 +48,13 @@ class Buffer; /** Driver for running Ingen directly as a library. * \ingroup engine */ -class DirectDriver : public Driver { +class DirectDriver : public Driver +{ public: DirectDriver(Engine& engine, double sample_rate, SampleCount block_length, - size_t seq_size) + uint32_t seq_size) : _engine(engine) , _sample_rate(sample_rate) , _block_length(block_length) @@ -103,7 +101,7 @@ public: SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } @@ -123,7 +121,7 @@ private: Ports _ports; SampleCount _sample_rate; SampleCount _block_length; - size_t _seq_size; + uint32_t _seq_size; }; } // namespace server diff --git a/src/server/Driver.hpp b/src/server/Driver.hpp index 1bc6213d..112fb8ba 100644 --- a/src/server/Driver.hpp +++ b/src/server/Driver.hpp @@ -19,12 +19,14 @@ #include "types.hpp" -#include "ingen/URI.hpp" -#include "raul/Noncopyable.hpp" +#include <ingen/URI.hpp> +#include <raul/Noncopyable.hpp> #include <cstddef> -namespace raul { class Path; } +namespace raul { +class Path; +} // namespace raul namespace ingen { @@ -44,7 +46,8 @@ class RunContext; * * \ingroup engine */ -class Driver : public raul::Noncopyable { +class Driver : public raul::Noncopyable +{ public: virtual ~Driver() = default; @@ -95,7 +98,7 @@ public: virtual SampleCount block_length() const = 0; /** Return the event buffer size in bytes */ - virtual size_t seq_size() const = 0; + virtual uint32_t seq_size() const = 0; /** Return the sample rate in Hz */ virtual SampleRate sample_rate() const = 0; diff --git a/src/server/DuplexPort.cpp b/src/server/DuplexPort.cpp index ce516b46..1e07afd2 100644 --- a/src/server/DuplexPort.cpp +++ b/src/server/DuplexPort.cpp @@ -23,23 +23,24 @@ #include "Engine.hpp" #include "GraphImpl.hpp" #include "NodeImpl.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Node.hpp" -#include "ingen/Properties.hpp" -#include "ingen/URIs.hpp" -#include "lv2/urid/urid.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" +#include "PortType.hpp" + +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> #include <algorithm> #include <map> #include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { DuplexPort::DuplexPort(BufferFactory& bufs, GraphImpl* parent, @@ -96,7 +97,7 @@ DuplexPort::duplicate(Engine& engine, GraphImpl* parent) { BufferFactory& bufs = *engine.buffer_factory(); - const Atom polyphonic = get_property(bufs.uris().ingen_polyphonic); + const Atom& polyphonic = get_property(bufs.uris().ingen_polyphonic); auto* dup = new DuplexPort( bufs, parent, symbol, _index, @@ -154,9 +155,12 @@ DuplexPort::get_buffers(BufferFactory& bufs, { if (!_is_driver_port && is_output()) { return InputPort::get_buffers(bufs, get, voices, poly, num_in_arcs); - } else if (!_is_driver_port && is_input()) { + } + + if (!_is_driver_port && is_input()) { return PortImpl::get_buffers(bufs, get, voices, poly, num_in_arcs); } + return false; } @@ -165,9 +169,12 @@ DuplexPort::setup_buffers(RunContext& ctx, BufferFactory& bufs, uint32_t poly) { if (!_is_driver_port && is_output()) { return InputPort::setup_buffers(ctx, bufs, poly); - } else if (!_is_driver_port && is_input()) { + } + + if (!_is_driver_port && is_input()) { return PortImpl::setup_buffers(ctx, bufs, poly); } + return false; } @@ -251,5 +258,4 @@ DuplexPort::next_value_offset(SampleCount offset, SampleCount end) const return PortImpl::next_value_offset(offset, end); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/DuplexPort.hpp b/src/server/DuplexPort.hpp index cdd764a0..fb3eb74e 100644 --- a/src/server/DuplexPort.hpp +++ b/src/server/DuplexPort.hpp @@ -19,32 +19,32 @@ #include "InputPort.hpp" #include "PortImpl.hpp" -#include "PortType.hpp" +#include "server.h" #include "types.hpp" -#include "ingen/URI.hpp" -#include "ingen/ingen.h" -#include "lv2/urid/urid.h" -#include "raul/Maid.hpp" +#include <lv2/urid/urid.h> +#include <raul/Maid.hpp> #include <boost/intrusive/slist_hook.hpp> #include <cstddef> #include <cstdint> -namespace raul { class Symbol; } +namespace raul { +class Symbol; +} // namespace raul namespace ingen { +enum class PortType; + class Atom; -class Properties; namespace server { class BufferFactory; class Engine; class GraphImpl; -class RunContext; /** A duplex Port (both an input and output port on a Graph) * @@ -55,7 +55,7 @@ class RunContext; * * \ingroup engine */ -class INGEN_API DuplexPort final +class INGEN_SERVER_API DuplexPort final : public InputPort , public boost::intrusive::slist_base_hook<> // In GraphImpl { diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index b48b291f..4d753bbc 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2017 David Robillard <http://drobilla.net/> + Copyright 2007-2024 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -19,7 +19,6 @@ #include "BlockFactory.hpp" #include "Broadcaster.hpp" #include "BufferFactory.hpp" -#include "BufferRef.hpp" #include "ControlBindings.hpp" #include "DirectDriver.hpp" #include "Driver.hpp" @@ -39,30 +38,32 @@ #include "events/CreateGraph.hpp" #include "ingen_config.h" -#ifdef HAVE_SOCKET +#if USE_SOCKET #include "SocketListener.hpp" #endif -#include "ingen/Atom.hpp" -#include "ingen/AtomReader.hpp" -#include "ingen/ColorContext.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/LV2Features.hpp" -#include "ingen/Log.hpp" -#include "ingen/Resource.hpp" -#include "ingen/Store.hpp" -#include "ingen/StreamWriter.hpp" -#include "ingen/Tee.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/buf-size/buf-size.h" -#include "lv2/state/state.h" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" -#include "raul/RingBuffer.hpp" +#include <ingen/Atom.hpp> +#include <ingen/AtomReader.hpp> +#include <ingen/Clock.hpp> +#include <ingen/ColorContext.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/LV2Features.hpp> +#include <ingen/Log.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/Store.hpp> +#include <ingen/StreamWriter.hpp> +#include <ingen/Tee.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/buf-size/buf-size.h> +#include <lv2/state/state.h> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> +#include <raul/RingBuffer.hpp> #include <algorithm> #include <cmath> @@ -71,11 +72,11 @@ #include <limits> #include <map> #include <memory> +#include <string> #include <thread> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { thread_local unsigned ThreadManager::flags(0); bool ThreadManager::single_threaded(true); @@ -98,25 +99,22 @@ Engine::Engine(ingen::World& world) , _interface(_event_writer) , _atom_interface( new AtomReader(world.uri_map(), world.uris(), world.log(), *_interface)) - , _root_graph(nullptr) - , _cycle_start_time(0) , _rand_engine(reinterpret_cast<uintptr_t>(this)) - , _uniform_dist(0.0f, 1.0f) - , _quit_flag(false) - , _reset_load_flag(false) , _atomic_bundles(world.conf().option("atomic-bundles").get<int32_t>()) - , _activated(false) { if (!world.store()) { world.set_store(std::make_shared<ingen::Store>()); } for (int i = 0; i < world.conf().option("threads").get<int32_t>(); ++i) { + const bool is_threaded = (i > 0); _notifications.emplace_back( - std::make_unique<raul::RingBuffer>(uint32_t(24 * event_queue_size()))); + std::make_unique<raul::RingBuffer>(24U * event_queue_size())); _run_contexts.emplace_back( - std::make_unique<RunContext>( - *this, _notifications.back().get(), unsigned(i), i > 0)); + std::make_unique<RunContext>(*this, + _notifications.back().get(), + static_cast<unsigned>(i), + is_threaded)); } _world.lv2_features().add_feature(_worker->schedule_feature()); @@ -187,7 +185,7 @@ Engine::~Engine() void Engine::listen() { -#ifdef HAVE_SOCKET +#if USE_SOCKET _listener = std::make_unique<SocketListener>(*this); #endif } @@ -244,12 +242,11 @@ Engine::emit_notifications(FrameTime end) bool Engine::pending_notifications() { - for (const auto& ctx : _run_contexts) { - if (ctx->pending_notifications()) { - return true; - } - } - return false; + return std::any_of(_run_contexts.begin(), + _run_contexts.end(), + [](const auto& ctx) { + return ctx->pending_notifications(); + }); } bool @@ -303,16 +300,17 @@ Engine::block_length() const return _driver->block_length(); } -size_t +uint32_t Engine::sequence_size() const { return _driver->seq_size(); } -size_t +uint32_t Engine::event_queue_size() const { - return _world.conf().option("queue-size").get<int32_t>(); + return static_cast<uint32_t>( + std::max(0, _world.conf().option("queue-size").get<int32_t>())); } void @@ -386,7 +384,7 @@ Engine::reset_load() } void -Engine::init(double sample_rate, uint32_t block_length, size_t seq_size) +Engine::init(double sample_rate, uint32_t block_length, uint32_t seq_size) { set_driver(std::make_shared<DirectDriver>( *this, sample_rate, block_length, seq_size)); @@ -537,5 +535,4 @@ Engine::unregister_client(const std::shared_ptr<Interface>& client) return _broadcaster->unregister_client(client); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index b5b6a311..8fa1d169 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -19,12 +19,12 @@ #include "Event.hpp" #include "Load.hpp" +#include "server.h" #include "types.hpp" -#include "ingen/Clock.hpp" -#include "ingen/EngineBase.hpp" -#include "ingen/Properties.hpp" -#include "ingen/ingen.h" +#include <ingen/Clock.hpp> +#include <ingen/EngineBase.hpp> +#include <ingen/Properties.hpp> #include <chrono> #include <condition_variable> @@ -75,7 +75,7 @@ class Worker; @ingroup engine */ -class INGEN_API Engine final : public EngineBase +class INGEN_SERVER_API Engine final : public EngineBase { public: explicit Engine(ingen::World& world); @@ -85,7 +85,7 @@ public: Engine& operator=(const Engine&) = delete; // EngineBase methods - void init(double sample_rate, uint32_t block_length, size_t seq_size) override; + void init(double sample_rate, uint32_t block_length, uint32_t seq_size) override; bool supports_dynamic_ports() const override; bool activate() override; void deactivate() override; @@ -114,7 +114,7 @@ public: * * This value is comparable to the value returned by current_time(). */ - inline uint64_t cycle_start_time(const RunContext&) const { + uint64_t cycle_start_time(const RunContext&) const { return _cycle_start_time; } @@ -170,8 +170,8 @@ public: SampleRate sample_rate() const; SampleCount block_length() const; - size_t sequence_size() const; - size_t event_queue_size() const; + uint32_t sequence_size() const; + uint32_t event_queue_size() const; size_t n_threads() const { return _run_contexts.size(); } bool atomic_bundles() const { return _atomic_bundles; } @@ -199,24 +199,24 @@ private: std::shared_ptr<EventWriter> _event_writer; std::shared_ptr<Interface> _interface; std::unique_ptr<AtomReader> _atom_interface; - GraphImpl* _root_graph; + GraphImpl* _root_graph{nullptr}; std::vector<std::unique_ptr<raul::RingBuffer>> _notifications; std::vector<std::unique_ptr<RunContext>> _run_contexts; - uint64_t _cycle_start_time; + uint64_t _cycle_start_time{0}; Load _run_load; Clock _clock; std::mt19937 _rand_engine; - std::uniform_real_distribution<float> _uniform_dist; + std::uniform_real_distribution<float> _uniform_dist{0.0f, 1.0f}; std::condition_variable _tasks_available; std::mutex _tasks_mutex; - bool _quit_flag; - bool _reset_load_flag; + bool _quit_flag{false}; + bool _reset_load_flag{false}; bool _atomic_bundles; - bool _activated; + bool _activated{false}; }; } // namespace server diff --git a/src/server/EnginePort.hpp b/src/server/EnginePort.hpp index ecfe59b3..d7e73f63 100644 --- a/src/server/EnginePort.hpp +++ b/src/server/EnginePort.hpp @@ -19,15 +19,14 @@ #include "DuplexPort.hpp" -#include "raul/Deletable.hpp" -#include "raul/Noncopyable.hpp" +#include <raul/Deletable.hpp> +#include <raul/Noncopyable.hpp> #include <boost/intrusive/slist_hook.hpp> #include <cstdint> -namespace ingen { -namespace server { +namespace ingen::server { /** A "system" port (e.g. a Jack port, an external port on Ingen). * @@ -40,9 +39,6 @@ class EnginePort : public raul::Noncopyable public: explicit EnginePort(DuplexPort* port) : _graph_port(port) - , _buffer(nullptr) - , _handle(nullptr) - , _driver_index(0) {} void set_buffer(void* buf) { _buffer = buf; } @@ -57,12 +53,11 @@ public: protected: DuplexPort* _graph_port; - void* _buffer; - void* _handle; - uint32_t _driver_index; + void* _buffer{nullptr}; + void* _handle{nullptr}; + uint32_t _driver_index{0}; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_ENGINE_PORT_HPP diff --git a/src/server/Event.hpp b/src/server/Event.hpp index e00aa0d1..3c9c5c26 100644 --- a/src/server/Event.hpp +++ b/src/server/Event.hpp @@ -19,12 +19,12 @@ #include "types.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Status.hpp" -#include "ingen/URI.hpp" -#include "ingen/paths.hpp" -#include "raul/Deletable.hpp" -#include "raul/Noncopyable.hpp" +#include <ingen/Interface.hpp> +#include <ingen/Status.hpp> +#include <ingen/URI.hpp> +#include <ingen/paths.hpp> +#include <raul/Deletable.hpp> +#include <raul/Noncopyable.hpp> #include <atomic> #include <cstdint> @@ -36,8 +36,7 @@ namespace raul { class Path; } // namespace raul -namespace ingen { -namespace server { +namespace ingen::server { class Engine; class RunContext; @@ -63,10 +62,10 @@ public: /** Execution mode for events that block and unblock preprocessing. */ enum class Execution { - NORMAL, ///< Normal pipelined execution - ATOMIC, ///< Block pre-processing until this event is executed - BLOCK, ///< Begin atomic block of events - UNBLOCK ///< Finish atomic executed block of events + NORMAL, ///< Normal pipelined execution + ATOMIC, ///< Block pre-processing until this event is executed + BLOCK, ///< Begin atomic block of events + UNBLOCK ///< Finish atomic executed block of events }; /** Claim position in undo stack before pre-processing (non-realtime). */ @@ -85,13 +84,13 @@ public: virtual void undo(Interface& target) {} /** Return true iff this event has been pre-processed. */ - inline bool is_prepared() const { return _status != Status::NOT_PREPARED; } + bool is_prepared() const { return _status != Status::NOT_PREPARED; } /** Return the time stamp of this event. */ - inline SampleCount time() const { return _time; } + SampleCount time() const { return _time; } /** Set the time stamp of this event. */ - inline void set_time(SampleCount time) { _time = time; } + void set_time(SampleCount time) { _time = time; } /** Get the next event to be processed after this one. */ Event* next() const { return _next.load(); } @@ -111,10 +110,13 @@ public: /** Set the undo mode of this event. */ void set_mode(Mode mode) { _mode = mode; } - inline Engine& engine() { return _engine; } + Engine& engine() { return _engine; } protected: - Event(Engine& engine, std::shared_ptr<Interface> client, int32_t id, FrameTime time) + Event(Engine& engine, + std::shared_ptr<Interface> client, + int32_t id, + FrameTime time) noexcept : _engine(engine) , _next(nullptr) , _request_client(std::move(client)) @@ -134,22 +136,22 @@ protected: , _mode(Mode::NORMAL) {} - inline bool pre_process_done(Status st) { + bool pre_process_done(Status st) { _status = st; return st == Status::SUCCESS; } - inline bool pre_process_done(Status st, const URI& subject) { + bool pre_process_done(Status st, const URI& subject) { _err_subject = subject; return pre_process_done(st); } - inline bool pre_process_done(Status st, const raul::Path& subject) { + bool pre_process_done(Status st, const raul::Path& subject) { return pre_process_done(st, path_to_uri(subject)); } /** Respond to the originating client. */ - inline Status respond() { + Status respond() { if (_request_client && _request_id) { _request_client->response(_request_id, _status, _err_subject); } @@ -166,7 +168,6 @@ protected: Mode _mode; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_EVENT_HPP diff --git a/src/server/EventWriter.cpp b/src/server/EventWriter.cpp index 9001b01a..fff9226a 100644 --- a/src/server/EventWriter.cpp +++ b/src/server/EventWriter.cpp @@ -18,27 +18,25 @@ #include "Engine.hpp" -#include "events/Connect.hpp" -#include "events/Copy.hpp" -#include "events/Delete.hpp" -#include "events/Delta.hpp" -#include "events/Disconnect.hpp" -#include "events/DisconnectAll.hpp" -#include "events/Get.hpp" -#include "events/Mark.hpp" -#include "events/Move.hpp" -#include "events/Undo.hpp" - -#include <boost/variant/apply_visitor.hpp> - -namespace ingen { -namespace server { +#include <events/Connect.hpp> +#include <events/Copy.hpp> +#include <events/Delete.hpp> +#include <events/Delta.hpp> +#include <events/Disconnect.hpp> +#include <events/DisconnectAll.hpp> +#include <events/Get.hpp> +#include <events/Mark.hpp> +#include <events/Move.hpp> +#include <events/Undo.hpp> +#include <ingen/Message.hpp> + +#include <variant> + +namespace ingen::server { EventWriter::EventWriter(Engine& engine) : _engine(engine) - , _event_mode(Event::Mode::NORMAL) -{ -} +{} SampleCount EventWriter::now() const @@ -49,7 +47,7 @@ EventWriter::now() const void EventWriter::message(const Message& msg) { - boost::apply_visitor(*this, msg); + std::visit(*this, msg); } void @@ -152,5 +150,4 @@ EventWriter::operator()(const Get& msg) _event_mode); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/EventWriter.hpp b/src/server/EventWriter.hpp index 184cefb7..55ee1158 100644 --- a/src/server/EventWriter.hpp +++ b/src/server/EventWriter.hpp @@ -20,14 +20,13 @@ #include "Event.hpp" #include "types.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Message.hpp" -#include "ingen/URI.hpp" +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/URI.hpp> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { class Engine; @@ -62,25 +61,24 @@ public: void operator()(const Delta&); void operator()(const Disconnect&); void operator()(const DisconnectAll&); - void operator()(const Error&) {} + void operator()(const Error&) noexcept {} void operator()(const Get&); void operator()(const Move&); void operator()(const Put&); void operator()(const Redo&); - void operator()(const Response&) {} + void operator()(const Response&) noexcept {} void operator()(const SetProperty&); void operator()(const Undo&); protected: Engine& _engine; std::shared_ptr<Interface> _respondee; - Event::Mode _event_mode; + Event::Mode _event_mode{Event::Mode::NORMAL}; private: SampleCount now() const; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_EVENTWRITER_HPP diff --git a/src/server/FrameTimer.hpp b/src/server/FrameTimer.hpp index 8a155777..0078f99c 100644 --- a/src/server/FrameTimer.hpp +++ b/src/server/FrameTimer.hpp @@ -20,8 +20,7 @@ #include <cmath> #include <cstdint> -namespace ingen { -namespace server { +namespace ingen::server { /** Delay-locked loop for monotonic sample time. * @@ -43,8 +42,7 @@ public: , b(sqrt(2) * omega) , c(omega * omega) , nper(period_size) - { - } + {} /** Update the timer for current real time `usec` and frame `frame`. */ void update(uint64_t usec, uint64_t frame) { @@ -96,16 +94,15 @@ private: const double b; const double c; - uint64_t nper = 0u; + uint64_t nper = 0U; double e2 = 0.0; double t0 = 0.0; double t1 = 0.0; - uint64_t n0 = 0u; - uint64_t n1 = 0u; + uint64_t n0 = 0U; + uint64_t n1 = 0U; bool initialized = false; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_FRAMETIMER_HPP diff --git a/src/server/GraphImpl.cpp b/src/server/GraphImpl.cpp index a668312d..9e44a4d4 100644 --- a/src/server/GraphImpl.cpp +++ b/src/server/GraphImpl.cpp @@ -28,24 +28,24 @@ #include "PortImpl.hpp" #include "ThreadManager.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Properties.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/urid/urid.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Forge.hpp> +#include <ingen/Properties.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Symbol.hpp> #include <cassert> #include <cstddef> #include <map> #include <memory> -#include <type_traits> +#include <string> #include <unordered_map> -namespace ingen { -namespace server { +namespace ingen::server { GraphImpl::GraphImpl(Engine& engine, const raul::Symbol& symbol, @@ -61,7 +61,6 @@ GraphImpl::GraphImpl(Engine& engine, , _engine(engine) , _poly_pre(internal_poly) , _poly_process(internal_poly) - , _process(false) { assert(internal_poly >= 1); assert(internal_poly <= 128); @@ -123,7 +122,7 @@ GraphImpl::duplicate(Engine& engine, } // Add duplicates of all arcs - for (const auto& a : _arcs) { + for (const auto& a : _graph_arcs) { auto arc = std::dynamic_pointer_cast<ArcImpl>(a.second); if (arc) { auto t = port_map.find(arc->tail()); @@ -286,38 +285,40 @@ void GraphImpl::add_arc(const std::shared_ptr<ArcImpl>& a) { ThreadManager::assert_thread(THREAD_PRE_PROCESS); - _arcs.emplace(std::make_pair(a->tail(), a->head()), a); + _graph_arcs.emplace(std::make_pair(a->tail(), a->head()), a); } std::shared_ptr<ArcImpl> GraphImpl::remove_arc(const PortImpl* tail, const PortImpl* dst_port) { ThreadManager::assert_thread(THREAD_PRE_PROCESS); - auto i = _arcs.find(std::make_pair(tail, dst_port)); - if (i != _arcs.end()) { + auto i = _graph_arcs.find(std::make_pair(tail, dst_port)); + if (i != _graph_arcs.end()) { auto arc = std::dynamic_pointer_cast<ArcImpl>(i->second); - _arcs.erase(i); + _graph_arcs.erase(i); return arc; - } else { - return nullptr; } + + return nullptr; } bool GraphImpl::has_arc(const PortImpl* tail, const PortImpl* dst_port) const { ThreadManager::assert_thread(THREAD_PRE_PROCESS); - auto i = _arcs.find(std::make_pair(tail, dst_port)); - return (i != _arcs.end()); + auto i = _graph_arcs.find(std::make_pair(tail, dst_port)); + return (i != _graph_arcs.end()); } -void -GraphImpl::set_compiled_graph(raul::managed_ptr<CompiledGraph>&& cg) +std::unique_ptr<CompiledGraph> +GraphImpl::swap_compiled_graph(std::unique_ptr<CompiledGraph> cg) { if (_compiled_graph && _compiled_graph != cg) { _engine.reset_load(); } - _compiled_graph = std::move(cg); + + _compiled_graph.swap(cg); + return cg; } uint32_t @@ -331,7 +332,7 @@ bool GraphImpl::has_port_with_index(uint32_t index) const { BufferFactory& bufs = *_engine.buffer_factory(); - const auto index_atom = bufs.forge().make(int32_t(index)); + const auto index_atom = bufs.forge().make(static_cast<int32_t>(index)); for (const auto& p : _inputs) { if (p.has_property(bufs.uris().lv2_index, index_atom)) { @@ -391,5 +392,4 @@ GraphImpl::build_ports_array(raul::Maid& maid) return result; } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/GraphImpl.hpp b/src/server/GraphImpl.hpp index cbbd57de..6c852106 100644 --- a/src/server/GraphImpl.hpp +++ b/src/server/GraphImpl.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard <http://drobilla.net/> + Copyright 2007-2023 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -20,12 +20,13 @@ #include "BlockImpl.hpp" #include "DuplexPort.hpp" #include "ThreadManager.hpp" +#include "server.h" #include "types.hpp" -#include "ingen/Node.hpp" -#include "lv2/urid/urid.h" -#include "raul/Maid.hpp" +#include <lv2/urid/urid.h> +#include <raul/Maid.hpp> +#include <boost/intrusive/options.hpp> #include <boost/intrusive/slist.hpp> #include <cassert> @@ -37,16 +38,7 @@ namespace raul { class Symbol; } // namespace raul -namespace boost { -namespace intrusive { - -template <bool Enabled> struct constant_time_size; - -} // namespace intrusive -} // namespace boost - -namespace ingen { -namespace server { +namespace ingen::server { class ArcImpl; class BufferFactory; @@ -63,7 +55,7 @@ class RunContext; * * \ingroup engine */ -class GraphImpl final : public BlockImpl +class INGEN_SERVER_API GraphImpl final : public BlockImpl { public: GraphImpl(Engine& engine, @@ -105,9 +97,14 @@ public: * Audio thread. * * \param ctx Process context + * * \param bufs New set of buffers - * \param poly Must be < the most recent value passed to prepare_internal_poly. - * \param maid Any objects no longer needed will be pushed to this + * + * \param poly Must be < the most recent value passed to + * prepare_internal_poly. + * + * \param maid Any objects no longer needed will be + * pushed to this */ bool apply_internal_poly(RunContext& ctx, BufferFactory& bufs, @@ -184,7 +181,8 @@ public: bool has_arc(const PortImpl* tail, const PortImpl* dst_port) const; /** Set a new compiled graph to run, and return the old one. */ - void set_compiled_graph(raul::managed_ptr<CompiledGraph>&& cg); + [[nodiscard]] std::unique_ptr<CompiledGraph> + swap_compiled_graph(std::unique_ptr<CompiledGraph> cg); const raul::managed_ptr<Ports>& external_ports() { return _ports; } @@ -203,17 +201,18 @@ public: Engine& engine() { return _engine; } private: - Engine& _engine; - uint32_t _poly_pre; ///< Pre-process thread only - uint32_t _poly_process; ///< Process thread only - raul::managed_ptr<CompiledGraph> _compiled_graph; ///< Process thread only - PortList _inputs; ///< Pre-process thread only - PortList _outputs; ///< Pre-process thread only - Blocks _blocks; ///< Pre-process thread only - bool _process; ///< True iff graph is enabled + using CompiledGraphPtr = std::unique_ptr<CompiledGraph>; + + Engine& _engine; + uint32_t _poly_pre; ///< Pre-process thread only + uint32_t _poly_process; ///< Process thread only + CompiledGraphPtr _compiled_graph; ///< Process thread only + PortList _inputs; ///< Pre-process thread only + PortList _outputs; ///< Pre-process thread only + Blocks _blocks; ///< Pre-process thread only + bool _process{false}; ///< True iff graph is enabled }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_GRAPHIMPL_HPP diff --git a/src/server/GraphPlugin.hpp b/src/server/GraphPlugin.hpp index b7a281f5..302141e7 100644 --- a/src/server/GraphPlugin.hpp +++ b/src/server/GraphPlugin.hpp @@ -19,15 +19,14 @@ #include "PluginImpl.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "lilv/lilv.h" -#include "raul/Symbol.hpp" +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <lilv/lilv.h> +#include <raul/Symbol.hpp> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { class BlockImpl; class BufferFactory; @@ -66,7 +65,6 @@ private: const std::string _name; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_GRAPHPLUGIN_HPP diff --git a/src/server/InputPort.cpp b/src/server/InputPort.cpp index 10a525cc..01622209 100644 --- a/src/server/InputPort.cpp +++ b/src/server/InputPort.cpp @@ -23,22 +23,23 @@ #include "BufferRef.hpp" #include "GraphImpl.hpp" #include "NodeImpl.hpp" +#include "PortType.hpp" #include "RunContext.hpp" #include "mix.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Node.hpp" -#include "ingen/URIs.hpp" -#include "lv2/urid/urid.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Node.hpp> +#include <ingen/URIs.hpp> +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <algorithm> #include <cassert> #include <cstdlib> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { InputPort::InputPort(BufferFactory& bufs, BlockImpl* parent, @@ -50,7 +51,6 @@ InputPort::InputPort(BufferFactory& bufs, const Atom& value, size_t buffer_size) : PortImpl(bufs, parent, symbol, index, poly, type, buffer_type, value, buffer_size, false) - , _num_arcs(0) { const ingen::URIs& uris = bufs.uris(); @@ -178,7 +178,7 @@ InputPort::pre_run(RunContext& ctx) { if ((_user_buffer || !_arcs.empty()) && !direct_connect()) { const uint32_t src_poly = max_tail_poly(ctx); - const uint32_t max_n_srcs = _arcs.size() * src_poly + 1; + const uint32_t max_n_srcs = (_arcs.size() * src_poly) + 1; for (uint32_t v = 0; v < _poly; ++v) { if (!buffer(v)->get<void>()) { @@ -232,9 +232,7 @@ InputPort::next_value_offset(SampleCount offset, SampleCount end) const for (const auto& arc : _arcs) { const SampleCount o = arc.tail()->next_value_offset(offset, end); - if (o < earliest) { - earliest = o; - } + earliest = std::min(o, earliest); } return earliest; @@ -262,5 +260,4 @@ InputPort::direct_connect() const && buffer(0)->type() != _bufs.uris().atom_Sequence; } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/InputPort.hpp b/src/server/InputPort.hpp index 9357c3ff..f3c6e553 100644 --- a/src/server/InputPort.hpp +++ b/src/server/InputPort.hpp @@ -17,31 +17,27 @@ #ifndef INGEN_ENGINE_INPUTPORT_HPP #define INGEN_ENGINE_INPUTPORT_HPP -#include "ArcImpl.hpp" // IWYU pragma: keep +#include "ArcImpl.hpp" #include "PortImpl.hpp" -#include "PortType.hpp" #include "types.hpp" -#include "lv2/urid/urid.h" -#include "raul/Maid.hpp" +#include <lv2/urid/urid.h> +#include <raul/Maid.hpp> +#include <boost/intrusive/options.hpp> #include <boost/intrusive/slist.hpp> #include <cstdint> #include <cstdlib> -namespace raul { class Symbol; } - -namespace boost { -namespace intrusive { - -template <bool Enabled> struct constant_time_size; - -} // namespace intrusive -} // namespace boost +namespace raul { +class Symbol; +} // namespace raul namespace ingen { +enum class PortType; + class Atom; namespace server { @@ -100,7 +96,7 @@ public: /** Like `get_buffers`, but for the pre-process thread. * - * This uses the "current" number of arcs fromthe perspective of the + * This uses the "current" number of arcs from the perspective of the * pre-process thread to allocate buffers for application of a * connection/disconnection/etc in the next process cycle. */ @@ -136,8 +132,8 @@ protected: uint32_t poly, size_t num_in_arcs) const override; - size_t _num_arcs; ///< Pre-process thread - Arcs _arcs; ///< Audio thread + size_t _num_arcs{0}; ///< Pre-process thread + Arcs _arcs; ///< Audio thread }; } // namespace server diff --git a/src/server/InternalBlock.cpp b/src/server/InternalBlock.cpp index 68e1f3e8..2eb0d411 100644 --- a/src/server/InternalBlock.cpp +++ b/src/server/InternalBlock.cpp @@ -23,8 +23,8 @@ #include "PluginImpl.hpp" #include "PortImpl.hpp" -#include "ingen/URIs.hpp" -#include "raul/Array.hpp" +#include <ingen/URIs.hpp> +#include <raul/Array.hpp> #include <boost/smart_ptr/intrusive_ptr.hpp> @@ -43,7 +43,6 @@ class Atom; namespace server { class GraphImpl; -class RunContext; InternalBlock::InternalBlock(PluginImpl* plugin, const raul::Symbol& symbol, diff --git a/src/server/InternalBlock.hpp b/src/server/InternalBlock.hpp index 2357f405..9eca9716 100644 --- a/src/server/InternalBlock.hpp +++ b/src/server/InternalBlock.hpp @@ -24,13 +24,10 @@ namespace raul { class Symbol; } // namespace raul -namespace ingen { -namespace server { +namespace ingen::server { -class Engine; class GraphImpl; class PluginImpl; -class RunContext; /** An internal Block implemented inside Ingen. * @@ -52,7 +49,6 @@ public: void pre_process(RunContext& ctx) override; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_BLOCKIMPL_HPP diff --git a/src/server/InternalPlugin.cpp b/src/server/InternalPlugin.cpp index 0355ff1e..7670c931 100644 --- a/src/server/InternalPlugin.cpp +++ b/src/server/InternalPlugin.cpp @@ -24,12 +24,14 @@ #include "internals/Trigger.hpp" #include "types.hpp" -#include "ingen/URIs.hpp" +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <lilv/lilv.h> +#include <raul/Symbol.hpp> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { InternalPlugin::InternalPlugin(URIs& uris, const URI& uri, raul::Symbol symbol) : PluginImpl(uris, uris.ingen_Internal.urid_atom(), uri) @@ -51,22 +53,29 @@ InternalPlugin::instantiate(BufferFactory& bufs, if (uri() == NS_INTERNALS "BlockDelay") { return new internals::BlockDelayNode( this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Controller") { + } + + if (uri() == NS_INTERNALS "Controller") { return new internals::ControllerNode( this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Note") { + } + + if (uri() == NS_INTERNALS "Note") { return new internals::NoteNode( this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Time") { + } + + if (uri() == NS_INTERNALS "Time") { return new internals::TimeNode( this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Trigger") { + } + + if (uri() == NS_INTERNALS "Trigger") { return new internals::TriggerNode( this, bufs, symbol, polyphonic, parent, srate); - } else { - return nullptr; } + + return nullptr; } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/InternalPlugin.hpp b/src/server/InternalPlugin.hpp index 9dfabc5f..4d715491 100644 --- a/src/server/InternalPlugin.hpp +++ b/src/server/InternalPlugin.hpp @@ -19,9 +19,9 @@ #include "PluginImpl.hpp" -#include "ingen/URI.hpp" -#include "lilv/lilv.h" -#include "raul/Symbol.hpp" +#include <ingen/URI.hpp> +#include <lilv/lilv.h> +#include <raul/Symbol.hpp> #define NS_INTERNALS "http://drobilla.net/ns/ingen-internals#" @@ -31,11 +31,6 @@ class URIs; namespace server { -class BlockImpl; -class BufferFactory; -class Engine; -class GraphImpl; - /** Implementation of an Internal plugin. */ class InternalPlugin : public PluginImpl diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp index f03689cb..e508c850 100644 --- a/src/server/JackDriver.cpp +++ b/src/server/JackDriver.cpp @@ -21,6 +21,7 @@ #include "BufferRef.hpp" #include "DuplexPort.hpp" #include "Engine.hpp" +#include "FrameTimer.hpp" #include "GraphImpl.hpp" #include "PortType.hpp" #include "RunContext.hpp" @@ -28,55 +29,45 @@ #include "ingen_config.h" #include "util.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Log.hpp" -#include "ingen/Properties.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/forge.h" -#include "lv2/atom/util.h" -#include "raul/Path.hpp" - +#include <ingen/Atom.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Log.hpp> +#include <ingen/Properties.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/forge.h> +#include <lv2/atom/util.h> +#include <raul/Path.hpp> +#include <raul/Semaphore.hpp> + +#include <jack/jack.h> #include <jack/midiport.h> #include <jack/transport.h> -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA #include "jackey.h" #include <jack/metadata.h> #endif #include <cassert> #include <chrono> +#include <cstdint> #include <map> #include <string> #include <utility> using jack_sample_t = jack_default_audio_sample_t; -namespace ingen { -namespace server { +namespace ingen::server { JackDriver::JackDriver(Engine& engine) - : _engine(engine) - , _forge() - , _sem(0) - , _flag(false) - , _client(nullptr) - , _block_length(0) - , _seq_size(0) - , _sample_rate(0) - , _is_activated(false) - , _position() - , _transport_state() - , _old_bpm(120.0) - , _old_frame(0) - , _old_rolling(false) + : _engine(engine) + , _forge() + , _midi_event_type(_engine.world().uris().midi_MidiEvent) { - _midi_event_type = _engine.world().uris().midi_MidiEvent; lv2_atom_forge_init(&_forge, &engine.world().uri_map().urid_map()); } @@ -102,7 +93,7 @@ JackDriver::attach(const std::string& server_name, } } - // Either server name not specified, or supplied server name does not exist + // Server name not specified, or that server doesn't exist // Connect to default server if (!_client) { if ((_client = jack_client_open(client_name.c_str(), JackNullOption, nullptr))) { @@ -121,7 +112,8 @@ JackDriver::attach(const std::string& server_name, _sample_rate = jack_get_sample_rate(_client); _block_length = jack_get_buffer_size(_client); - _seq_size = jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE); + _seq_size = static_cast<uint32_t>( + jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE)); _fallback_buffer = AudioBufPtr( static_cast<float*>( @@ -136,6 +128,8 @@ JackDriver::attach(const std::string& server_name, register_port(p); } + _timer = std::make_unique<FrameTimer>(_block_length, _sample_rate); + return true; } @@ -165,10 +159,10 @@ JackDriver::activate() if (jack_activate(_client)) { _engine.log().error("Could not activate Jack client, aborting\n"); return false; - } else { - _engine.log().info("Activated Jack client `%1%'\n", - world.conf().option("jack-name").ptr<char>()); } + + _engine.log().info("Activated Jack client `%1%'\n", + world.conf().option("jack-name").ptr<char>()); return true; } @@ -269,14 +263,14 @@ void JackDriver::rename_port(const raul::Path& old_path, const raul::Path& new_path) { - EnginePort* eport = get_port(old_path); + const EnginePort* eport = get_port(old_path); if (eport) { -#ifdef HAVE_JACK_PORT_RENAME +#if USE_JACK_PORT_RENAME jack_port_rename(_client, static_cast<jack_port_t*>(eport->handle()), new_path.substr(1).c_str()); #else - jack_port_set_name((jack_port_t*)eport->handle(), + jack_port_set_name(static_cast<jack_port_t*>(eport->handle()), new_path.substr(1).c_str()); #endif } @@ -287,7 +281,7 @@ JackDriver::port_property(const raul::Path& path, const URI& uri, const Atom& value) { -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA EnginePort* eport = get_port(path); if (eport) { const auto* const jport = @@ -303,7 +297,7 @@ JackDriver::port_property_internal(const jack_port_t* jport, const URI& uri, const Atom& value) { -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA if (uri == _engine.world().uris().lv2_name) { jack_set_property(_client, jack_port_uuid(jport), JACK_METADATA_PRETTY_NAME, value.ptr<char>(), "text/plain"); @@ -398,7 +392,7 @@ JackDriver::post_process_port(RunContext& ctx, EnginePort* port) const auto* seq = graph_buf->get<LV2_Atom_Sequence>(); jack_midi_clear_buffer(jack_buf); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY(&ev->body)); @@ -469,6 +463,12 @@ JackDriver::append_time_events(RunContext& ctx, Buffer& buffer) static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(lpos))); } +SampleCount +JackDriver::frame_time() const +{ + return _timer->frame_time(_engine.current_time()) + _engine.block_length(); +} + /**** Jack Callbacks ****/ /** Jack process callback, drives entire audio thread. @@ -491,6 +491,7 @@ JackDriver::_process_cb(jack_nframes_t nframes) _transport_state = jack_transport_query(_client, &_position); + _timer->update(_engine.current_time(), start_of_current_cycle - _engine.block_length()); _engine.locate(start_of_current_cycle, nframes); // Read input @@ -532,18 +533,22 @@ JackDriver::_shutdown_cb() int JackDriver::_block_length_cb(jack_nframes_t nframes) { + const URIs& uris = _engine.world().uris(); + if (_engine.root_graph()) { _block_length = nframes; - _seq_size = jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE); + _seq_size = static_cast<uint32_t>( + jack_port_type_get_buffer_size(_client, JACK_DEFAULT_MIDI_TYPE)); _engine.root_graph()->set_buffer_size( - _engine.run_context(), *_engine.buffer_factory(), PortType::AUDIO, + _engine.run_context(), *_engine.buffer_factory(), + uris.atom_Sound, _engine.buffer_factory()->audio_buffer_size(nframes)); _engine.root_graph()->set_buffer_size( - _engine.run_context(), *_engine.buffer_factory(), PortType::ATOM, + _engine.run_context(), *_engine.buffer_factory(), + uris.atom_Sequence, _seq_size); } return 0; } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp index d4ea03d0..4c8e779e 100644 --- a/src/server/JackDriver.hpp +++ b/src/server/JackDriver.hpp @@ -18,47 +18,35 @@ #define INGEN_ENGINE_JACKAUDIODRIVER_HPP #include "Driver.hpp" -#include "EnginePort.hpp" // IWYU pragma: keep +#include "EnginePort.hpp" #include "types.hpp" -#include "ingen/URI.hpp" -#include "ingen/memory.hpp" // IWYU pragma: keep -#include "lv2/atom/forge.h" -#include "raul/Semaphore.hpp" +#include <ingen/URI.hpp> +#include <ingen/memory.hpp> +#include <lv2/atom/forge.h> +#include <raul/Semaphore.hpp> +#include <boost/intrusive/options.hpp> #include <boost/intrusive/slist.hpp> -#include <jack/jack.h> -#include <jack/thread.h> +#include <jack/transport.h> // IWYU pragma: keep #include <jack/types.h> +#include <jack/thread.h> + #include <atomic> -#include <cstddef> #include <cstdint> #include <exception> #include <memory> #include <string> -namespace raul { -class Path; -} // namespace raul - -namespace boost { -namespace intrusive { - -template <bool Enabled> struct cache_last; - -} // namespace intrusive -} // namespace boost - namespace ingen { class Atom; namespace server { -class Buffer; -class DuplexPort; class Engine; +class FrameTimer; class RunContext; /** The Jack Driver. @@ -96,8 +84,8 @@ public: /** Transport state for this frame. * Intended to only be called from the audio thread. */ - inline const jack_position_t* position() { return &_position; } - inline jack_transport_state_t transport_state() { return _transport_state; } + const jack_position_t* position() { return &_position; } + jack_transport_state_t transport_state() { return _transport_state; } void append_time_events(RunContext& ctx, Buffer& buffer) override; @@ -107,14 +95,13 @@ public: jack_client_t* jack_client() const { return _client; } SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } - SampleCount frame_time() const override { - return _client ? jack_frame_time(_client) : 0; - } + SampleCount frame_time() const override; - class PortRegistrationFailedException : public std::exception {}; + class PortRegistrationFailedException : public std::exception + {}; private: friend class JackPort; @@ -122,16 +109,21 @@ private: static void thread_init_cb(void* jack_driver); // Static JACK callbacks which call the non-static callbacks (methods) - inline static void shutdown_cb(void* const jack_driver) { - return static_cast<JackDriver*>(jack_driver)->_shutdown_cb(); + + static void shutdown_cb(void* const jack_driver) { + static_cast<JackDriver*>(jack_driver)->_shutdown_cb(); } - inline static int process_cb(jack_nframes_t nframes, void* const jack_driver) { + + static int process_cb(jack_nframes_t nframes, void* const jack_driver) { return static_cast<JackDriver*>(jack_driver)->_process_cb(nframes); } - inline static int block_length_cb(jack_nframes_t nframes, void* const jack_driver) { + + static int block_length_cb(jack_nframes_t nframes, void* const jack_driver) { return static_cast<JackDriver*>(jack_driver)->_block_length_cb(nframes); } + // Internal methods for processing + void pre_process_port(RunContext& ctx, EnginePort* port); void post_process_port(RunContext& ctx, EnginePort* port) const; @@ -150,23 +142,24 @@ protected: using AudioBufPtr = std::unique_ptr<float, FreeDeleter<float>>; - Engine& _engine; - Ports _ports; - AudioBufPtr _fallback_buffer; - LV2_Atom_Forge _forge; - raul::Semaphore _sem; - std::atomic<bool> _flag; - jack_client_t* _client; - jack_nframes_t _block_length; - size_t _seq_size; - jack_nframes_t _sample_rate; - uint32_t _midi_event_type; - bool _is_activated; - jack_position_t _position; - jack_transport_state_t _transport_state; - double _old_bpm; - jack_nframes_t _old_frame; - bool _old_rolling; + Engine& _engine; + Ports _ports; + AudioBufPtr _fallback_buffer; + LV2_Atom_Forge _forge; + raul::Semaphore _sem{0}; + std::unique_ptr<FrameTimer> _timer; + std::atomic<bool> _flag{false}; + jack_client_t* _client{nullptr}; + jack_nframes_t _block_length{0}; + uint32_t _seq_size{0}; + jack_nframes_t _sample_rate{0}; + uint32_t _midi_event_type; + bool _is_activated{false}; + jack_position_t _position{}; + jack_transport_state_t _transport_state{}; + double _old_bpm{120.0}; + jack_nframes_t _old_frame{0}; + bool _old_rolling{false}; }; } // namespace server diff --git a/src/server/LV2Block.cpp b/src/server/LV2Block.cpp index 026b7d06..ad7b28ae 100644 --- a/src/server/LV2Block.cpp +++ b/src/server/LV2Block.cpp @@ -14,12 +14,13 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ +#include "LV2Block.hpp" + #include "Buffer.hpp" #include "BufferFactory.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "InputPort.hpp" -#include "LV2Block.hpp" #include "LV2Plugin.hpp" #include "OutputPort.hpp" #include "PortImpl.hpp" @@ -27,24 +28,27 @@ #include "RunContext.hpp" #include "Worker.hpp" -#include "ingen/Atom.hpp" -#include "ingen/FilePath.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Log.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/core/lv2.h" -#include "lv2/options/options.h" -#include "lv2/state/state.h" -#include "lv2/urid/urid.h" -#include "lv2/worker/worker.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Atom.hpp> +#include <ingen/FilePath.hpp> +#include <ingen/Forge.hpp> +#include <ingen/LV2Features.hpp> +#include <ingen/Log.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lilv/lilv.h> +#include <lv2/core/lv2.h> +#include <lv2/options/options.h> +#include <lv2/state/state.h> +#include <lv2/urid/urid.h> +#include <lv2/worker/worker.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> #include <algorithm> #include <cassert> @@ -52,11 +56,11 @@ #include <cstdint> #include <map> #include <memory> +#include <optional> #include <string> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { /** Partially construct a LV2Block. * @@ -70,7 +74,6 @@ LV2Block::LV2Block(LV2Plugin* plugin, SampleRate srate) : BlockImpl(plugin, symbol, polyphonic, parent, srate) , _lv2_plugin(plugin) - , _worker_iface(nullptr) { assert(_lv2_plugin); } @@ -110,7 +113,7 @@ LV2Block::make_instance(URIs& uris, } for (uint32_t p = 0; p < num_ports(); ++p) { - PortImpl* const port = _ports->at(p); + const PortImpl* const port = _ports->at(p); Buffer* const buffer = (preparing) ? port->prepared_buffer(voice).get() : port->buffer(voice).get(); @@ -223,7 +226,7 @@ LV2Block::apply_poly(RunContext& ctx, uint32_t poly) /** Instantiate self from LV2 plugin descriptor. * - * Implemented as a seperate function (rather than in the constructor) to + * Implemented as a separate function (rather than in the constructor) to * allow graceful error-catching of broken plugins. * * Returns whether or not plugin was successfully instantiated. If return @@ -271,7 +274,7 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) is_morph = true; LilvNodes* types = lilv_port_get_value( plug, id, uris.morph_supportsType); - LILV_FOREACH(nodes, i, types) { + LILV_FOREACH (nodes, i, types) { const LilvNode* type = lilv_nodes_get(types, i); if (lilv_node_equals(type, uris.lv2_CVPort)) { port_type = PortType::CV; @@ -302,7 +305,7 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) if (!buffer_type) { LilvNodes* types = lilv_port_get_value( plug, id, uris.atom_bufferType); - LILV_FOREACH(nodes, i, types) { + LILV_FOREACH (nodes, i, types) { const LilvNode* type = lilv_nodes_get(types, i); if (lilv_node_is_uri(type)) { buffer_type = world.uri_map().map_uri( @@ -327,7 +330,7 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) if (port_type == PortType::ATOM) { // Get default value, and its length LilvNodes* defaults = lilv_port_get_value(plug, id, uris.lv2_default); - LILV_FOREACH(nodes, i, defaults) { + LILV_FOREACH (nodes, i, defaults) { const LilvNode* d = lilv_nodes_get(defaults, i); if (lilv_node_is_string(d)) { const char* str_val = lilv_node_as_string(d); @@ -347,10 +350,10 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) // Get minimum size, if set in data LilvNodes* sizes = lilv_port_get_value(plug, id, uris.rsz_minimumSize); - LILV_FOREACH(nodes, i, sizes) { + LILV_FOREACH (nodes, i, sizes) { const LilvNode* d = lilv_nodes_get(sizes, i); if (lilv_node_is_int(d)) { - uint32_t size_val = lilv_node_as_int(d); + const uint32_t size_val = lilv_node_as_int(d); port_buffer_size = std::max(port_buffer_size, size_val); } } @@ -415,7 +418,7 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) nullptr }; for (int p = 0; preds[p]; ++p) { LilvNodes* values = lilv_port_get_value(plug, id, preds[p]); - LILV_FOREACH(nodes, v, values) { + LILV_FOREACH (nodes, v, values) { const LilvNode* value = lilv_nodes_get(values, v); if (lilv_node_is_uri(value)) { port->add_property(URI(lilv_node_as_uri(preds[p])), @@ -482,7 +485,7 @@ LV2Block::save_state(const FilePath& dir) const World& world = _lv2_plugin->world(); LilvWorld* lworld = world.lilv_world(); - StatePtr state{ + const StatePtr state{ lilv_state_new_from_instance(_lv2_plugin->lilv_plugin(), const_cast<LV2Block*>(this)->instance(0), &world.uri_map().urid_map(), @@ -497,7 +500,9 @@ LV2Block::save_state(const FilePath& dir) const if (!state) { return false; - } else if (lilv_state_get_num_properties(state.get()) == 0) { + } + + if (lilv_state_get_num_properties(state.get()) == 0) { return false; } @@ -520,7 +525,7 @@ LV2Block::duplicate(Engine& engine, const SampleRate rate = engine.sample_rate(); // Get current state - StatePtr state{ + const StatePtr state{ lilv_state_new_from_instance(_lv2_plugin->lilv_plugin(), instance(0), &engine.world().uri_map().urid_map(), @@ -588,10 +593,10 @@ LV2_Worker_Status LV2Block::work(uint32_t size, const void* data) { if (_worker_iface) { - std::lock_guard<std::mutex> lock(_work_mutex); + const std::lock_guard<std::mutex> lock{_work_mutex}; - LV2_Handle inst = lilv_instance_get_handle(instance(0)); - LV2_Worker_Status st = _worker_iface->work(inst, work_respond, this, size, data); + LV2_Handle inst = lilv_instance_get_handle(instance(0)); + const LV2_Worker_Status st = _worker_iface->work(inst, work_respond, this, size, data); if (st) { parent_graph()->engine().log().error( "Error calling %1% work method\n", _path); @@ -691,8 +696,8 @@ get_port_value(const char* port_symbol, uint32_t* size, uint32_t* type) { - auto* const block = static_cast<LV2Block*>(user_data); - auto* const port = block->port_by_symbol(port_symbol); + auto* const block = static_cast<LV2Block*>(user_data); + const auto* const port = block->port_by_symbol(port_symbol); if (port && port->is_input() && port->value().is_valid()) { *size = port->value().size(); @@ -703,7 +708,7 @@ get_port_value(const char* port_symbol, return nullptr; } -boost::optional<Resource> +std::optional<Resource> LV2Block::save_preset(const URI& uri, const Properties& props) { @@ -716,20 +721,20 @@ LV2Block::save_preset(const URI& uri, const FilePath dirname = path.parent_path(); const FilePath basename = path.stem(); - StatePtr state{lilv_state_new_from_instance(_lv2_plugin->lilv_plugin(), - instance(0), - lmap, - nullptr, - nullptr, - nullptr, - path.c_str(), - get_port_value, - this, - LV2_STATE_IS_NATIVE, - nullptr)}; + const StatePtr state{lilv_state_new_from_instance(_lv2_plugin->lilv_plugin(), + instance(0), + lmap, + nullptr, + nullptr, + nullptr, + path.c_str(), + get_port_value, + this, + LV2_STATE_IS_NATIVE, + nullptr)}; if (state) { - const Properties::const_iterator l = props.find(_uris.rdfs_label); + const auto l = props.find(_uris.rdfs_label); if (l != props.end() && l->second.type() == _uris.atom_String) { lilv_state_set_label(state.get(), l->second.ptr<char>()); } @@ -756,7 +761,7 @@ LV2Block::save_preset(const URI& uri, return {preset}; } - return boost::optional<Resource>(); + return {}; } void @@ -772,5 +777,4 @@ LV2Block::set_port_buffer(uint32_t voice, buf ? buf->port_data(_ports->at(port_num)->type(), offset) : nullptr); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/LV2Block.hpp b/src/server/LV2Block.hpp index c8f9e59a..78b5ffac 100644 --- a/src/server/LV2Block.hpp +++ b/src/server/LV2Block.hpp @@ -22,22 +22,21 @@ #include "State.hpp" #include "types.hpp" -#include "ingen/LV2Features.hpp" -#include "ingen/Properties.hpp" -#include "ingen/URI.hpp" -#include "lilv/lilv.h" -#include "lv2/worker/worker.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Noncopyable.hpp" - +#include <ingen/LV2Features.hpp> +#include <lilv/lilv.h> +#include <lv2/worker/worker.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Noncopyable.hpp> + +#include <boost/intrusive/options.hpp> #include <boost/intrusive/slist.hpp> #include <boost/intrusive/slist_hook.hpp> -#include <boost/optional/optional.hpp> #include <cstdint> #include <cstdlib> #include <cstring> +#include <filesystem> #include <memory> #include <mutex> @@ -45,33 +44,16 @@ namespace raul { class Symbol; } // namespace raul -namespace boost { -namespace intrusive { - -template <bool Enabled> -struct cache_last; - -template <bool Enabled> -struct constant_time_size; - -} // namespace intrusive -} // namespace boost - namespace ingen { -class FilePath; -class Resource; class URIs; class World; namespace server { class BufferFactory; -class Engine; class GraphImpl; class LV2Plugin; -class RunContext; -class Worker; /** An instance of a LV2 plugin. * @@ -91,7 +73,7 @@ public: bool instantiate(BufferFactory& bufs, const LilvState* state); LilvInstance* instance() override { return instance(0); } - bool save_state(const FilePath& dir) const override; + bool save_state(const std::filesystem::path& dir) const override; BlockImpl* duplicate(Engine& engine, const raul::Symbol& symbol, @@ -113,19 +95,19 @@ public: void apply_state(const std::unique_ptr<Worker>& worker, const LilvState* state) override; - boost::optional<Resource> save_preset(const URI& uri, - const Properties& props) override; + std::optional<Resource> save_preset(const URI& uri, + const Properties& props) override; void set_port_buffer(uint32_t voice, uint32_t port_num, const BufferRef& buf, SampleCount offset) override; - static StatePtr load_state(World& world, const FilePath& path); + static StatePtr load_state(World& world, const std::filesystem::path& path); protected: struct Instance : public raul::Noncopyable { - explicit Instance(LilvInstance* i) : instance(i) {} + explicit Instance(LilvInstance* i) noexcept : instance(i) {} ~Instance() { lilv_instance_free(instance); } @@ -135,7 +117,7 @@ protected: std::shared_ptr<Instance> make_instance(URIs& uris, SampleRate rate, uint32_t voice, bool preparing); - inline LilvInstance* instance(uint32_t voice) { + LilvInstance* instance(uint32_t voice) { return static_cast<LilvInstance*>((*_instances)[voice]->instance); } @@ -151,9 +133,8 @@ protected: struct Response : public raul::Maid::Disposable , public raul::Noncopyable - , public boost::intrusive::slist_base_hook<> - { - inline Response(uint32_t s, const void* d) + , public boost::intrusive::slist_base_hook<> { + Response(uint32_t s, const void* d) : size(s) , data(malloc(s)) { @@ -179,7 +160,7 @@ protected: LV2Plugin* _lv2_plugin; raul::managed_ptr<Instances> _instances; raul::managed_ptr<Instances> _prepared_instances; - const LV2_Worker_Interface* _worker_iface; + const LV2_Worker_Interface* _worker_iface{nullptr}; std::mutex _work_mutex; Responses _responses; std::shared_ptr<LV2Features::FeatureArray> _features; diff --git a/src/server/LV2Options.hpp b/src/server/LV2Options.hpp index 2ae1c6d7..b1b57429 100644 --- a/src/server/LV2Options.hpp +++ b/src/server/LV2Options.hpp @@ -17,10 +17,10 @@ #ifndef INGEN_ENGINE_LV2OPTIONS_HPP #define INGEN_ENGINE_LV2OPTIONS_HPP -#include "ingen/LV2Features.hpp" -#include "ingen/URIs.hpp" -#include "lv2/core/lv2.h" -#include "lv2/options/options.h" +#include <ingen/LV2Features.hpp> +#include <ingen/URIs.hpp> +#include <lv2/core/lv2.h> +#include <lv2/options/options.h> #include <cstdint> #include <cstdlib> @@ -34,7 +34,8 @@ class World; namespace server { -class LV2Options : public ingen::LV2Features::Feature { +class LV2Options : public ingen::LV2Features::Feature +{ public: explicit LV2Options(const URIs& uris) : _uris(uris) @@ -65,7 +66,7 @@ public: f->URI = LV2_OPTIONS__options; f->data = malloc(sizeof(options)); memcpy(f->data, options, sizeof(options)); - return std::shared_ptr<LV2_Feature>(f, &free_feature); + return {f, &free_feature}; } private: diff --git a/src/server/LV2Plugin.cpp b/src/server/LV2Plugin.cpp index 7a43ba67..87072ab0 100644 --- a/src/server/LV2Plugin.cpp +++ b/src/server/LV2Plugin.cpp @@ -19,16 +19,18 @@ #include "Engine.hpp" #include "LV2Block.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Log.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" +#include <ingen/Forge.hpp> +#include <ingen/Log.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lilv/lilv.h> +#include <raul/Symbol.hpp> #include <cstdlib> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { LV2Plugin::LV2Plugin(World& world, const LilvPlugin* lplugin) : PluginImpl(world.uris(), @@ -70,18 +72,18 @@ LV2Plugin::symbol() const { std::string working = uri(); if (working.back() == '/') { - working = working.substr(0, working.length() - 1); + working.resize(working.length() - 1); } - while (working.length() > 0) { - size_t last_slash = working.find_last_of('/'); + while (!working.empty()) { + const size_t last_slash = working.find_last_of('/'); const std::string symbol = working.substr(last_slash+1); if ( (symbol[0] >= 'a' && symbol[0] <= 'z') || (symbol[0] >= 'A' && symbol[0] <= 'Z') ) { return raul::Symbol::symbolify(symbol); - } else { - working = working.substr(0, last_slash); } + + working.resize(last_slash); } return raul::Symbol("lv2_symbol"); @@ -101,9 +103,9 @@ LV2Plugin::instantiate(BufferFactory& bufs, if (!b->instantiate(bufs, state)) { delete b; return nullptr; - } else { - return b; } + + return b; } void @@ -114,7 +116,7 @@ LV2Plugin::load_presets() LilvNodes* presets = lilv_plugin_get_related(_lilv_plugin, uris.pset_Preset); if (presets) { - LILV_FOREACH(nodes, i, presets) { + LILV_FOREACH (nodes, i, presets) { const LilvNode* preset = lilv_nodes_get(presets, i); lilv_world_load_resource(lworld, preset); @@ -140,5 +142,4 @@ LV2Plugin::load_presets() PluginImpl::load_presets(); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/LV2Plugin.hpp b/src/server/LV2Plugin.hpp index fa007327..c94e88f7 100644 --- a/src/server/LV2Plugin.hpp +++ b/src/server/LV2Plugin.hpp @@ -19,9 +19,8 @@ #include "PluginImpl.hpp" -#include "ingen/URI.hpp" -#include "lilv/lilv.h" -#include "raul/Symbol.hpp" +#include <ingen/URI.hpp> +#include <lilv/lilv.h> namespace ingen { @@ -29,11 +28,6 @@ class World; namespace server { -class BlockImpl; -class BufferFactory; -class Engine; -class GraphImpl; - /** Implementation of an LV2 plugin (loaded shared library). */ class LV2Plugin : public PluginImpl diff --git a/src/server/LV2ResizeFeature.hpp b/src/server/LV2ResizeFeature.hpp index ddad2ea7..66720e0d 100644 --- a/src/server/LV2ResizeFeature.hpp +++ b/src/server/LV2ResizeFeature.hpp @@ -21,13 +21,12 @@ #include "Buffer.hpp" #include "PortImpl.hpp" -#include "ingen/LV2Features.hpp" -#include "lv2/resize-port/resize-port.h" +#include <ingen/LV2Features.hpp> +#include <lv2/resize-port/resize-port.h> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { struct ResizeFeature : public ingen::LV2Features::Feature { static LV2_Resize_Port_Status resize_port( @@ -62,7 +61,6 @@ struct ResizeFeature : public ingen::LV2Features::Feature { } }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_LV2RESIZEFEATURE_HPP diff --git a/src/server/Load.hpp b/src/server/Load.hpp index f69d0659..a5216f7e 100644 --- a/src/server/Load.hpp +++ b/src/server/Load.hpp @@ -21,11 +21,9 @@ #include <cstdint> #include <limits> -namespace ingen { -namespace server { +namespace ingen::server { -struct Load -{ +struct Load { void update(uint64_t time, uint64_t available) { const uint64_t load = time * 100 / available; if (load < min) { @@ -40,8 +38,8 @@ struct Load mean = load; changed = true; } else { - const float a = mean + (static_cast<float>(load) - mean) / - static_cast<float>(++n); + const float a = mean + ((static_cast<float>(load) - mean) / + static_cast<float>(++n)); if (a != mean) { changed = floorf(a) != floorf(mean); @@ -57,7 +55,6 @@ struct Load bool changed = false; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_LOAD_HPP diff --git a/src/server/NodeImpl.cpp b/src/server/NodeImpl.cpp index d914ae1c..e820a44e 100644 --- a/src/server/NodeImpl.cpp +++ b/src/server/NodeImpl.cpp @@ -20,15 +20,15 @@ #include "GraphImpl.hpp" #include "ThreadManager.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Properties.hpp" -#include "raul/Path.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <raul/Path.hpp> #include <map> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { NodeImpl::NodeImpl(const ingen::URIs& uris, NodeImpl* parent, @@ -37,8 +37,7 @@ NodeImpl::NodeImpl(const ingen::URIs& uris, , _parent(parent) , _path(parent ? parent->path().child(symbol) : raul::Path("/")) , _symbol(symbol) -{ -} +{} const Atom& NodeImpl::get_property(const URI& key) const @@ -55,5 +54,4 @@ NodeImpl::parent_graph() const return dynamic_cast<GraphImpl*>(reinterpret_cast<BlockImpl*>(_parent)); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/NodeImpl.hpp b/src/server/NodeImpl.hpp index 8acce161..fcf2f57f 100644 --- a/src/server/NodeImpl.hpp +++ b/src/server/NodeImpl.hpp @@ -17,17 +17,15 @@ #ifndef INGEN_ENGINE_NODEIMPL_HPP #define INGEN_ENGINE_NODEIMPL_HPP -#include "ingen/Node.hpp" -#include "ingen/URI.hpp" -#include "ingen/paths.hpp" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Node.hpp> +#include <ingen/paths.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> #include <cstdint> namespace ingen { -class Atom; class URIs; namespace server { diff --git a/src/server/OutputPort.hpp b/src/server/OutputPort.hpp index 61fb44f5..b19cd361 100644 --- a/src/server/OutputPort.hpp +++ b/src/server/OutputPort.hpp @@ -20,7 +20,7 @@ #include "PortImpl.hpp" #include "PortType.hpp" -#include "lv2/urid/urid.h" +#include <lv2/urid/urid.h> #include <cstddef> #include <cstdint> diff --git a/src/server/PluginImpl.hpp b/src/server/PluginImpl.hpp index 3d7d596f..8e3642c0 100644 --- a/src/server/PluginImpl.hpp +++ b/src/server/PluginImpl.hpp @@ -17,11 +17,11 @@ #ifndef INGEN_ENGINE_PLUGINIMPL_HPP #define INGEN_ENGINE_PLUGINIMPL_HPP -#include "ingen/Atom.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URI.hpp" -#include "lilv/lilv.h" -#include "raul/Symbol.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <lilv/lilv.h> +#include <raul/Symbol.hpp> #include <map> #include <string> @@ -48,10 +48,7 @@ public: PluginImpl(ingen::URIs& uris, const Atom& type, const URI& uri) : Resource(uris, uri) , _type(type) - , _presets_loaded(false) - , _is_zombie(false) - { - } + {} PluginImpl(const PluginImpl&) = delete; PluginImpl& operator=(const PluginImpl&) = delete; @@ -90,8 +87,8 @@ public: protected: Atom _type; Presets _presets; - bool _presets_loaded; - bool _is_zombie; + bool _presets_loaded{false}; + bool _is_zombie{false}; }; } // namespace server diff --git a/src/server/PortAudioDriver.cpp b/src/server/PortAudioDriver.cpp index fcb9cf67..ef893478 100644 --- a/src/server/PortAudioDriver.cpp +++ b/src/server/PortAudioDriver.cpp @@ -14,17 +14,19 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ +#include "PortAudioDriver.hpp" + #include "DuplexPort.hpp" #include "Engine.hpp" #include "FrameTimer.hpp" -#include "PortAudioDriver.hpp" #include "PortType.hpp" #include "RunContext.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "raul/Path.hpp" + +#include <ingen/Atom.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <raul/Path.hpp> #include <portaudio.h> @@ -32,8 +34,7 @@ #include <cstring> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { static bool pa_error(const char* msg, PaError err) @@ -47,17 +48,8 @@ PortAudioDriver::PortAudioDriver(Engine& engine) : _engine(engine) , _inputParameters() , _outputParameters() - , _sem(0) - , _stream(nullptr) - , _seq_size(4096) , _block_length(engine.world().conf().option("buffer-size").get<int32_t>()) - , _sample_rate(48000) - , _n_inputs(0) - , _n_outputs(0) - , _flag(false) - , _is_activated(false) -{ -} +{} PortAudioDriver::~PortAudioDriver() { @@ -78,7 +70,9 @@ PortAudioDriver::attach() _outputParameters.device = Pa_GetDefaultOutputDevice(); if (_inputParameters.device == paNoDevice) { return pa_error("No default input device", paDeviceUnavailable); - } else if (_outputParameters.device == paNoDevice) { + } + + if (_outputParameters.device == paNoDevice) { return pa_error("No default output device", paDeviceUnavailable); } @@ -91,8 +85,7 @@ PortAudioDriver::attach() _sample_rate = in_dev->defaultSampleRate; - _timer = std::unique_ptr<FrameTimer>( - new FrameTimer(_block_length, _sample_rate)); + _timer = std::make_unique<FrameTimer>(_block_length, _sample_rate); return true; } @@ -184,26 +177,22 @@ PortAudioDriver::remove_port(RunContext&, EnginePort* port) void PortAudioDriver::register_port(EnginePort& port) -{ -} +{} void PortAudioDriver::unregister_port(EnginePort& port) -{ -} +{} void PortAudioDriver::rename_port(const raul::Path& old_path, const raul::Path& new_path) -{ -} +{} void PortAudioDriver::port_property(const raul::Path& path, const URI& uri, const Atom& value) -{ -} +{} EnginePort* PortAudioDriver::create_port(DuplexPort* graph_port) @@ -265,8 +254,7 @@ PortAudioDriver::post_process_port(RunContext&, EnginePort* port, const void* inputs, void* outputs) -{ -} +{} int PortAudioDriver::process_cb(const void* inputs, @@ -294,5 +282,4 @@ PortAudioDriver::process_cb(const void* inputs, return 0; } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/PortAudioDriver.hpp b/src/server/PortAudioDriver.hpp index 5f2bf7a1..6c7bfb9e 100644 --- a/src/server/PortAudioDriver.hpp +++ b/src/server/PortAudioDriver.hpp @@ -18,39 +18,21 @@ #define INGEN_ENGINE_PORTAUDIODRIVER_HPP #include "Driver.hpp" -#include "EnginePort.hpp" // IWYU pragma: keep +#include "EnginePort.hpp" #include "types.hpp" -#include "ingen/URI.hpp" -#include "raul/Semaphore.hpp" +#include <raul/Semaphore.hpp> +#include <boost/intrusive/options.hpp> #include <boost/intrusive/slist.hpp> #include <portaudio.h> #include <atomic> -#include <cstddef> #include <cstdint> #include <memory> -namespace raul { class Path; } +namespace ingen::server { -namespace boost { -namespace intrusive { - -template <bool Enabled> -struct cache_last; - -} // namespace intrusive -} // namespace boost - -namespace ingen { - -class Atom; - -namespace server { - -class Buffer; -class DuplexPort; class Engine; class FrameTimer; class RunContext; @@ -83,21 +65,21 @@ public: int real_time_priority() override { return 80; } SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } private: friend class PortAudioPort; - inline static int - pa_process_cb(const void* inputs, - void* outputs, - unsigned long nframes, - const PaStreamCallbackTimeInfo* time, - PaStreamCallbackFlags flags, - void* handle) { + static int pa_process_cb(const void* inputs, + void* outputs, + unsigned long nframes, + const PaStreamCallbackTimeInfo* time, + PaStreamCallbackFlags flags, + void* handle) + { return static_cast<PortAudioDriver*>(handle)->process_cb( - inputs, outputs, nframes, time, flags); + inputs, outputs, nframes, time, flags); } int process_cb(const void* inputs, @@ -124,19 +106,18 @@ protected: Ports _ports; PaStreamParameters _inputParameters; PaStreamParameters _outputParameters; - raul::Semaphore _sem; + raul::Semaphore _sem{0U}; std::unique_ptr<FrameTimer> _timer; - PaStream* _stream; - size_t _seq_size; + PaStream* _stream{nullptr}; + uint32_t _seq_size{4096U}; uint32_t _block_length; - uint32_t _sample_rate; - uint32_t _n_inputs; - uint32_t _n_outputs; - std::atomic<bool> _flag; - bool _is_activated; + uint32_t _sample_rate{48000U}; + uint32_t _n_inputs{0U}; + uint32_t _n_outputs{0U}; + std::atomic<bool> _flag{false}; + bool _is_activated{false}; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_PORTAUDIODRIVER_HPP diff --git a/src/server/PortImpl.cpp b/src/server/PortImpl.cpp index 68392707..f6eed11f 100644 --- a/src/server/PortImpl.cpp +++ b/src/server/PortImpl.cpp @@ -23,15 +23,17 @@ #include "PortType.hpp" #include "ThreadManager.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/urid/urid.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Node.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> #include <algorithm> #include <cassert> @@ -39,10 +41,9 @@ #include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { -static const uint32_t monitor_rate = 25.0; // Hz +static const uint32_t monitor_rate = 25.0; // Hz /** The length of time between monitor updates in frames */ static inline uint32_t @@ -67,24 +68,12 @@ PortImpl::PortImpl(BufferFactory& bufs, , _index(index) , _poly(poly) , _buffer_size(buffer_size) - , _frames_since_monitor(0) - , _monitor_value(0.0f) - , _peak(0.0f) , _type(type) , _buffer_type(buffer_type) , _value(value) , _min(bufs.forge().make(0.0f)) , _max(bufs.forge().make(1.0f)) , _voices(bufs.maid().make_managed<Voices>(poly)) - , _connected_flag(false) - , _monitored(false) - , _force_monitor_update(false) - , _is_morph(false) - , _is_auto_morph(false) - , _is_logarithmic(false) - , _is_sample_rate(false) - , _is_toggled(false) - , _is_driver_port(false) , _is_output(is_output) { assert(block != nullptr); @@ -148,13 +137,13 @@ PortImpl::set_type(PortType port_type, LV2_URID buffer_type) remove_property(uris.rdf_type, uris.lv2_CVPort); remove_property(uris.rdf_type, uris.lv2_ControlPort); remove_property(uris.rdf_type, uris.atom_AtomPort); - add_property(uris.rdf_type, world.forge().make_urid(port_type.uri())); + add_property(uris.rdf_type, world.forge().make_urid(port_type_uri(port_type))); // Update audio thread types _type = port_type; _buffer_type = buffer_type; if (!_buffer_type) { - switch (_type.id()) { + switch (_type) { case PortType::CONTROL: _buffer_type = uris.atom_Float; break; @@ -250,7 +239,7 @@ PortImpl::set_voice_value(const RunContext& ctx, FrameTime time, Sample value) { - switch (_type.id()) { + switch (_type) { case PortType::CONTROL: if (buffer(voice)->value()) { const_cast<LV2_Atom_Float*>( @@ -302,9 +291,9 @@ PortImpl::set_voice_value(const RunContext& ctx, void PortImpl::update_set_state(const RunContext& ctx, uint32_t v) { - Voice& voice = _voices->at(v); - SetState& state = voice.set_state; - BufferRef buf = voice.buffer; + Voice& voice = _voices->at(v); + SetState& state = voice.set_state; + const BufferRef buf = voice.buffer; switch (state.state) { case SetState::State::SET: break; @@ -342,9 +331,13 @@ PortImpl::prepare_poly(BufferFactory& bufs, uint32_t poly) if (_is_driver_port || _parent->is_main() || (_type == PortType::ATOM && !_value.is_valid())) { return false; - } else if (_poly == poly) { + } + + if (_poly == poly) { return true; - } else if (_prepared_voices && _prepared_voices->size() != poly) { + } + + if (_prepared_voices && _prepared_voices->size() != poly) { _prepared_voices.reset(); } @@ -365,7 +358,9 @@ PortImpl::apply_poly(RunContext& ctx, uint32_t poly) if (_parent->is_main() || (_type == PortType::ATOM && !_value.is_valid())) { return false; - } else if (!_prepared_voices) { + } + + if (!_prepared_voices) { return true; } @@ -426,7 +421,7 @@ PortImpl::set_is_driver_port(BufferFactory&) void PortImpl::clear_buffers(const RunContext& ctx) { - switch (_type.id()) { + switch (_type) { case PortType::AUDIO: default: for (uint32_t v = 0; v < _poly; ++v) { @@ -459,17 +454,17 @@ PortImpl::monitor(RunContext& ctx, bool send_now) _frames_since_monitor += ctx.nframes(); const bool time_to_send = send_now || _frames_since_monitor >= period; - const bool is_sequence = (_type.id() == PortType::ATOM && + const bool is_sequence = (_type == PortType::ATOM && _buffer_type == _bufs.uris().atom_Sequence); if (!time_to_send && !(is_sequence && _monitored) && (!is_sequence && buffer(0)->value())) { return; } - Forge& forge = ctx.engine().world().forge(); - URIs& uris = ctx.engine().world().uris(); - LV2_URID key = 0; - float val = 0.0f; - switch (_type.id()) { + const Forge& forge = ctx.engine().world().forge(); + const URIs& uris = ctx.engine().world().uris(); + LV2_URID key = 0; + float val = 0.0f; + switch (_type) { case PortType::UNKNOWN: break; case PortType::AUDIO: @@ -491,7 +486,7 @@ PortImpl::monitor(RunContext& ctx, bool send_now) } else if (_monitored) { /* Sequence explicitly monitored, send everything. */ const auto* seq = reinterpret_cast<const LV2_Atom_Sequence*>(atom); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { ctx.notify(uris.ingen_activity, ctx.start() + ev->time.frames, this, @@ -542,9 +537,7 @@ PortImpl::next_value_offset(SampleCount offset, SampleCount end) const SampleCount earliest = end; for (uint32_t v = 0; v < _poly; ++v) { const SampleCount o = _voices->at(v).buffer->next_value_offset(offset, end); - if (o < earliest) { - earliest = o; - } + earliest = std::min(o, earliest); } return earliest; } @@ -570,8 +563,7 @@ PortImpl::pre_process(RunContext& ctx) void PortImpl::pre_run(RunContext&) -{ -} +{} void PortImpl::post_process(RunContext& ctx) @@ -584,5 +576,4 @@ PortImpl::post_process(RunContext& ctx) monitor(ctx); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/PortImpl.hpp b/src/server/PortImpl.hpp index d79bb6cd..c202d4a0 100644 --- a/src/server/PortImpl.hpp +++ b/src/server/PortImpl.hpp @@ -20,17 +20,15 @@ #include "BufferFactory.hpp" #include "BufferRef.hpp" #include "NodeImpl.hpp" -#include "PortType.hpp" #include "RunContext.hpp" +#include "server.h" #include "types.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Node.hpp" -#include "ingen/URIs.hpp" -#include "ingen/ingen.h" -#include "lv2/urid/urid.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" +#include <ingen/Atom.hpp> +#include <ingen/URIs.hpp> +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> #include <atomic> #include <cstdint> @@ -43,6 +41,8 @@ class Symbol; namespace ingen { +enum class PortType; + class Properties; namespace server { @@ -57,7 +57,7 @@ class BlockImpl; * * \ingroup engine */ -class INGEN_API PortImpl : public NodeImpl +class INGEN_SERVER_API PortImpl : public NodeImpl { public: struct SetState { @@ -91,10 +91,8 @@ public: }; struct Voice { - Voice() : buffer(nullptr) {} - SetState set_state; - BufferRef buffer; + BufferRef buffer{nullptr}; }; using Voices = raul::Array<Voice>; @@ -147,10 +145,11 @@ public: void set_minimum(const Atom& min) { _min.set_rt(min); } void set_maximum(const Atom& max) { _max.set_rt(max); } - inline BufferRef buffer(uint32_t voice) const { + BufferRef buffer(uint32_t voice) const { return _voices->at((_poly == 1) ? 0 : voice).buffer; } - inline BufferRef prepared_buffer(uint32_t voice) const { + + BufferRef prepared_buffer(uint32_t voice) const { return _prepared_voices->at(voice).buffer; } @@ -207,7 +206,7 @@ public: uint32_t index() const { return _index; } void set_index(RunContext&, uint32_t index) { _index = index; } - inline bool is_a(PortType type) const { return _type == type; } + bool is_a(PortType type) const { return _type == type; } bool has_value() const; @@ -299,9 +298,9 @@ protected: uint32_t _index; uint32_t _poly; uint32_t _buffer_size; - uint32_t _frames_since_monitor; - float _monitor_value; - float _peak; + uint32_t _frames_since_monitor{0}; + float _monitor_value{0.0f}; + float _peak{0.0f}; PortType _type; LV2_URID _buffer_type; Atom _value; @@ -310,15 +309,15 @@ protected: raul::managed_ptr<Voices> _voices; raul::managed_ptr<Voices> _prepared_voices; BufferRef _user_buffer; - std::atomic_flag _connected_flag; - bool _monitored; - bool _force_monitor_update; - bool _is_morph; - bool _is_auto_morph; - bool _is_logarithmic; - bool _is_sample_rate; - bool _is_toggled; - bool _is_driver_port; + std::atomic_flag _connected_flag{false}; + bool _monitored{false}; + bool _force_monitor_update{false}; + bool _is_morph{false}; + bool _is_auto_morph{false}; + bool _is_logarithmic{false}; + bool _is_sample_rate{false}; + bool _is_toggled{false}; + bool _is_driver_port{false}; bool _is_output; }; diff --git a/src/server/PortType.hpp b/src/server/PortType.hpp index f84c271f..294c056a 100644 --- a/src/server/PortType.hpp +++ b/src/server/PortType.hpp @@ -14,80 +14,60 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef INGEN_INTERFACE_PORTTYPE_HPP -#define INGEN_INTERFACE_PORTTYPE_HPP +#ifndef INGEN_ENGINE_PORTTYPE_HPP +#define INGEN_ENGINE_PORTTYPE_HPP -#include "ingen/URI.hpp" - -#include "lv2/atom/atom.h" -#include "lv2/core/lv2.h" - -#include <cassert> +#include <ingen/URI.hpp> +#include <lv2/atom/atom.h> +#include <lv2/core/lv2.h> namespace ingen { -/** The type of a port. - * - * This type refers to the type of the port itself (not necessarily the type - * of its contents). Ports with different types can contain the same type of - * data, but may e.g. have different access semantics. - */ -class PortType { -public: - enum ID { - UNKNOWN = 0, - AUDIO = 1, - CONTROL = 2, - CV = 3, - ATOM = 4 - }; - - explicit PortType(const URI& uri) - : _id(UNKNOWN) - { - if (uri == type_uri(AUDIO)) { - _id = AUDIO; - } else if (uri == type_uri(CONTROL)) { - _id = CONTROL; - } else if (uri == type_uri(CV)) { - _id = CV; - } else if (uri == type_uri(ATOM)) { - _id = ATOM; - } - } - - PortType(ID id) : _id(id) {} - - inline const URI& uri() const { return type_uri(_id); } - inline ID id() const { return _id; } - - inline bool operator==(const ID& id) const { return (_id == id); } - inline bool operator!=(const ID& id) const { return (_id != id); } - inline bool operator==(const PortType& type) const { return (_id == type._id); } - inline bool operator!=(const PortType& type) const { return (_id != type._id); } - inline bool operator<(const PortType& type) const { return (_id < type._id); } - - inline bool is_audio() { return _id == AUDIO; } - inline bool is_control() { return _id == CONTROL; } - inline bool is_cv() { return _id == CV; } - inline bool is_atom() { return _id == ATOM; } +/// The type of a port +enum class PortType { + UNKNOWN, + AUDIO, + CONTROL, + CV, + ATOM, +}; -private: - static inline const URI& type_uri(unsigned id_num) { - assert(id_num <= ATOM); - static const URI uris[] = { - URI("http://www.w3.org/2002/07/owl#Nothing"), - URI(LV2_CORE__AudioPort), - URI(LV2_CORE__ControlPort), - URI(LV2_CORE__CVPort), - URI(LV2_ATOM__AtomPort) - }; - return uris[id_num]; +/// Return the URI for `port_type` +inline URI +port_type_uri(const PortType port_type) +{ + switch (port_type) { + case PortType::UNKNOWN: + break; + case PortType::AUDIO: + return URI{LV2_CORE__AudioPort}; + case PortType::CONTROL: + return URI{LV2_CORE__ControlPort}; + case PortType::CV: + return URI{LV2_CORE__CVPort}; + case PortType::ATOM: + return URI{LV2_ATOM__AtomPort}; } - ID _id; -}; + return URI{"http://www.w3.org/2002/07/owl#Nothing"}; +} + +/// Return the type with the given `uri`, or #PortType::UNKNOWN +inline PortType +port_type_from_uri(const URI& uri) +{ + static const URI lv2_AudioPort = URI{LV2_CORE__AudioPort}; + static const URI lv2_ControlPort = URI{LV2_CORE__ControlPort}; + static const URI lv2_CVPort = URI{LV2_CORE__CVPort}; + static const URI atom_AtomPort = URI{LV2_ATOM__AtomPort}; + + return (uri == lv2_AudioPort) ? PortType::AUDIO + : (uri == lv2_ControlPort) ? PortType::CONTROL + : (uri == lv2_CVPort) ? PortType::CV + : (uri == atom_AtomPort) ? PortType::ATOM + : PortType::UNKNOWN; +} } // namespace ingen -#endif // INGEN_INTERFACE_PORTTYPE_HPP +#endif // INGEN_ENGINE_PORTTYPE_HPP diff --git a/src/server/PostProcessor.cpp b/src/server/PostProcessor.cpp index 5a0a8f3e..4c071ecd 100644 --- a/src/server/PostProcessor.cpp +++ b/src/server/PostProcessor.cpp @@ -21,14 +21,12 @@ #include <cassert> -namespace ingen { -namespace server { +namespace ingen::server { -class PreProcessContext; - -class Sentinel : public Event { +class Sentinel : public Event +{ public: - explicit Sentinel(Engine& engine) : Event(engine) {} + explicit Sentinel(Engine& engine) noexcept : Event(engine) {} bool pre_process(PreProcessContext&) override { return false; } void execute(RunContext&) override {} @@ -40,8 +38,7 @@ PostProcessor::PostProcessor(Engine& engine) , _head(new Sentinel(engine)) , _tail(_head.load()) , _max_time(0) -{ -} +{} PostProcessor::~PostProcessor() { @@ -99,7 +96,7 @@ PostProcessor::process() // Post-process event ev->post_process(); - next = ev->next(); // [1] (see below) + next = ev->next(); // [1] (see below) } while (next && next->time() < end_time); /* Reached the tail (as far as we're concerned). There may be successors @@ -112,5 +109,4 @@ PostProcessor::process() _engine.emit_notifications(end_time); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/PostProcessor.hpp b/src/server/PostProcessor.hpp index ab8ba6bc..7b2a3035 100644 --- a/src/server/PostProcessor.hpp +++ b/src/server/PostProcessor.hpp @@ -17,14 +17,12 @@ #ifndef INGEN_ENGINE_POSTPROCESSOR_HPP #define INGEN_ENGINE_POSTPROCESSOR_HPP +#include "server.h" #include "types.hpp" -#include "ingen/ingen.h" - #include <atomic> -namespace ingen { -namespace server { +namespace ingen::server { class Engine; class Event; @@ -41,7 +39,7 @@ class RunContext; * * \ingroup engine */ -class INGEN_API PostProcessor +class INGEN_SERVER_API PostProcessor { public: explicit PostProcessor(Engine& engine); @@ -68,7 +66,6 @@ private: std::atomic<FrameTime> _max_time; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_POSTPROCESSOR_HPP diff --git a/src/server/PreProcessContext.hpp b/src/server/PreProcessContext.hpp index fa7d07c5..7c97af3c 100644 --- a/src/server/PreProcessContext.hpp +++ b/src/server/PreProcessContext.hpp @@ -20,12 +20,10 @@ #include "CompiledGraph.hpp" #include "GraphImpl.hpp" -#include "raul/Maid.hpp" - +#include <memory> #include <unordered_set> -namespace ingen { -namespace server { +namespace ingen::server { /** Event pre-processing context. * @@ -50,12 +48,14 @@ public: bool must_compile(GraphImpl& graph) { if (!graph.enabled()) { return false; - } else if (_in_bundle) { + } + + if (_in_bundle) { _dirty_graphs.insert(&graph); return false; - } else { - return true; } + + return true; } /** Compile graph and return the result if necessary. @@ -63,13 +63,9 @@ public: * This may return null when an atomic bundle is deferring compilation, in * which case the graph is flagged as dirty for later compilation. */ - raul::Maid::managed_ptr<CompiledGraph> - maybe_compile(raul::Maid& maid, GraphImpl& graph) + [[nodiscard]] std::unique_ptr<CompiledGraph> maybe_compile(GraphImpl& graph) { - if (must_compile(graph)) { - return compile(maid, graph); - } - return nullptr; + return must_compile(graph) ? compile(graph) : nullptr; } /** Return all graphs that require compilation after an atomic bundle. */ @@ -81,7 +77,6 @@ private: bool _in_bundle = false; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_PREPROCESSCONTEXT_HPP diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp index b2f0fd46..b3bad0b2 100644 --- a/src/server/PreProcessor.cpp +++ b/src/server/PreProcessor.cpp @@ -24,26 +24,22 @@ #include "ThreadManager.hpp" #include "UndoStack.hpp" -#include "ingen/Atom.hpp" -#include "ingen/AtomWriter.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/World.hpp" +#include <ingen/Atom.hpp> +#include <ingen/AtomWriter.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/World.hpp> +#include <raul/Semaphore.hpp> #include <cassert> #include <cstdint> #include <cstdio> #include <memory> +#include <string> -namespace ingen { -namespace server { +namespace ingen::server { PreProcessor::PreProcessor(Engine& engine) : _engine(engine) - , _sem(0) - , _head(nullptr) - , _tail(nullptr) - , _block_state(BlockState::UNBLOCKED) - , _exit_flag(false) , _thread(&PreProcessor::run, this) {} @@ -61,7 +57,7 @@ PreProcessor::event(Event* const ev, Event::Mode mode) { // TODO: Probably possible to make this lock-free with CAS ThreadManager::assert_not_thread(THREAD_IS_REAL_TIME); - std::lock_guard<std::mutex> lock(_mutex); + const std::lock_guard<std::mutex> lock{_mutex}; assert(!ev->is_prepared()); assert(!ev->next()); @@ -69,7 +65,7 @@ PreProcessor::event(Event* const ev, Event::Mode mode) /* Note that tail is only used here, not in process(). The head must be checked first here, since if it is null the tail pointer is junk. */ - Event* const head = _head.load(); + const Event* const head = _head.load(); if (!head) { _head = ev; _tail = ev; @@ -114,12 +110,14 @@ PreProcessor::process(RunContext& ctx, PostProcessor& dest, size_t limit) } if (_block_state == BlockState::BLOCKED) { - break; // Waiting for PRE_UNBLOCKED - } else if (ev->time() < ctx.start()) { - ev->set_time(ctx.start()); // Too late, nudge to context start + break; // Waiting for PRE_UNBLOCKED + } + + if (ev->time() < ctx.start()) { + ev->set_time(ctx.start()); // Too late, nudge to context start } else if (_block_state != BlockState::PROCESSING && ev->time() >= ctx.end()) { - break; // Event is for a future cycle + break; // Event is for a future cycle } // Execute event @@ -144,7 +142,7 @@ PreProcessor::process(RunContext& ctx, PostProcessor& dest, size_t limit) if (n_processed > 0) { #ifndef NDEBUG - Engine& engine = ctx.engine(); + const Engine& engine = ctx.engine(); if (engine.world().conf().option("trace").get<int32_t>()) { const uint64_t start = engine.cycle_start_time(ctx); const uint64_t end = engine.current_time(); @@ -153,7 +151,7 @@ PreProcessor::process(RunContext& ctx, PostProcessor& dest, size_t limit) } #endif - auto* next = static_cast<Event*>(last->next()); + auto* next = last->next(); last->next(nullptr); dest.append(ctx, head, last); @@ -245,9 +243,8 @@ PreProcessor::run() wait_for_block_state(BlockState::UNBLOCKED); } - back = static_cast<Event*>(ev->next()); + back = ev->next(); } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/PreProcessor.hpp b/src/server/PreProcessor.hpp index 05027638..03ba5dd7 100644 --- a/src/server/PreProcessor.hpp +++ b/src/server/PreProcessor.hpp @@ -19,7 +19,7 @@ #include "Event.hpp" -#include "raul/Semaphore.hpp" +#include <raul/Semaphore.hpp> #include <atomic> #include <chrono> @@ -27,8 +27,7 @@ #include <mutex> #include <thread> -namespace ingen { -namespace server { +namespace ingen::server { class Engine; class PostProcessor; @@ -42,7 +41,7 @@ public: ~PreProcessor(); /** Return true iff no events are enqueued. */ - inline bool empty() const { return !_head.load(); } + bool empty() const { return !_head.load(); } /** Enqueue an event. * This is safe to call from any non-realtime thread (it locks). @@ -61,11 +60,11 @@ protected: private: enum class BlockState { - UNBLOCKED, ///< Normal, unblocked execution - PRE_BLOCKED, ///< Preprocess thread has enqueued blocking event - BLOCKED, ///< Process thread has reached blocking event - PRE_UNBLOCKED, ///< Preprocess thread has enqueued unblocking event - PROCESSING ///< Process thread is executing all events in-between + UNBLOCKED, ///< Normal, unblocked execution + PRE_BLOCKED, ///< Preprocess thread has enqueued blocking event + BLOCKED, ///< Process thread has reached blocking event + PRE_UNBLOCKED, ///< Preprocess thread has enqueued unblocking event + PROCESSING ///< Process thread is executing all events in-between }; void wait_for_block_state(const BlockState state) { @@ -76,15 +75,14 @@ private: Engine& _engine; std::mutex _mutex; - raul::Semaphore _sem; - std::atomic<Event*> _head; - std::atomic<Event*> _tail; - std::atomic<BlockState> _block_state; - bool _exit_flag; + raul::Semaphore _sem{0}; + std::atomic<Event*> _head{nullptr}; + std::atomic<Event*> _tail{nullptr}; + std::atomic<BlockState> _block_state{BlockState::UNBLOCKED}; + bool _exit_flag{false}; std::thread _thread; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_PREPROCESSOR_HPP diff --git a/src/server/RunContext.cpp b/src/server/RunContext.cpp index a61e4afb..29985ccf 100644 --- a/src/server/RunContext.cpp +++ b/src/server/RunContext.cpp @@ -22,32 +22,30 @@ #include "PortImpl.hpp" #include "Task.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Log.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/urid/urid.h" -#include "raul/RingBuffer.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Log.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/urid/urid.h> +#include <raul/RingBuffer.hpp> #include <cerrno> #include <cstring> #include <pthread.h> #include <sched.h> -namespace ingen { -namespace server { +namespace ingen::server { -struct Notification -{ - explicit inline Notification(PortImpl* p = nullptr, - FrameTime f = 0, - LV2_URID k = 0, - uint32_t s = 0, - LV2_URID t = 0) - : port(p), time(f), key(k), size(s), type(t) +struct Notification { + explicit Notification(PortImpl* p = nullptr, + FrameTime f = 0, + LV2_URID k = 0, + uint32_t s = 0, + LV2_URID t = 0) + : port(p), time(f), key(k), size(s), type(t) {} PortImpl* port; @@ -63,22 +61,13 @@ RunContext::RunContext(Engine& engine, bool threaded) : _engine(engine) , _event_sink(event_sink) - , _task(nullptr) , _thread(threaded ? new std::thread(&RunContext::run, this) : nullptr) , _id(id) - , _start(0) - , _end(0) - , _offset(0) - , _nframes(0) - , _rate(0) - , _realtime(true) {} RunContext::RunContext(const RunContext& copy) : _engine(copy._engine) , _event_sink(copy._event_sink) - , _task(nullptr) - , _thread(nullptr) , _id(copy._id) , _start(copy._start) , _end(copy._end) @@ -171,9 +160,9 @@ void RunContext::set_priority(int priority) { if (_thread) { - pthread_t pthread = _thread->native_handle(); - const int policy = (priority > 0) ? SCHED_FIFO : SCHED_OTHER; - sched_param sp{}; + const pthread_t pthread = _thread->native_handle(); + const int policy = (priority > 0) ? SCHED_FIFO : SCHED_OTHER; + sched_param sp{}; sp.sched_priority = (priority > 0) ? priority : 0; if (pthread_setschedparam(pthread, policy, &sp)) { _engine.log().error( @@ -204,5 +193,4 @@ RunContext::run() } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/RunContext.hpp b/src/server/RunContext.hpp index 92aa1cf8..44304c5e 100644 --- a/src/server/RunContext.hpp +++ b/src/server/RunContext.hpp @@ -19,15 +19,14 @@ #include "types.hpp" -#include "lv2/urid/urid.h" -#include "raul/RingBuffer.hpp" +#include <lv2/urid/urid.h> +#include <raul/RingBuffer.hpp> #include <cstdint> #include <memory> #include <thread> -namespace ingen { -namespace server { +namespace ingen::server { class Engine; class PortImpl; @@ -103,17 +102,17 @@ public: * cycle (other than the fact that it must be processed in significantly * less time to avoid a dropout when running in real time). */ - inline uint64_t duration() const { + uint64_t duration() const { return static_cast<uint64_t>(_nframes) * 1e6 / _rate; } - inline void locate(FrameTime s, SampleCount nframes) { + void locate(FrameTime s, SampleCount nframes) { _start = s; _end = s + nframes; _nframes = nframes; } - inline void slice(SampleCount offset, SampleCount nframes) { + void slice(SampleCount offset, SampleCount nframes) { _offset = offset; _nframes = nframes; } @@ -129,35 +128,34 @@ public: void join(); - inline Engine& engine() const { return _engine; } - inline Task* task() const { return _task; } - inline unsigned id() const { return _id; } - inline FrameTime start() const { return _start; } - inline FrameTime time() const { return _start + _offset; } - inline FrameTime end() const { return _end; } - inline SampleCount offset() const { return _offset; } - inline SampleCount nframes() const { return _nframes; } - inline SampleCount rate() const { return _rate; } - inline bool realtime() const { return _realtime; } + Engine& engine() const { return _engine; } + Task* task() const { return _task; } + unsigned id() const { return _id; } + FrameTime start() const { return _start; } + FrameTime time() const { return _start + _offset; } + FrameTime end() const { return _end; } + SampleCount offset() const { return _offset; } + SampleCount nframes() const { return _nframes; } + SampleCount rate() const { return _rate; } + bool realtime() const { return _realtime; } protected: void run(); - Engine& _engine; ///< Engine we're running in - raul::RingBuffer* _event_sink; ///< Updates from process context - Task* _task; ///< Currently executing task - std::unique_ptr<std::thread> _thread; ///< Thread (or null for main) - unsigned _id; ///< Context ID - - FrameTime _start; ///< Start frame of this cycle, timeline relative - FrameTime _end; ///< End frame of this cycle, timeline relative - SampleCount _offset; ///< Offset into data buffers - SampleCount _nframes; ///< Number of frames past offset to process - SampleCount _rate; ///< Sample rate in Hz - bool _realtime; ///< True iff context is hard realtime + Engine& _engine; ///< Engine we're running in + raul::RingBuffer* _event_sink; ///< Updates from notify() + Task* _task{nullptr}; ///< Currently executing task + std::unique_ptr<std::thread> _thread; ///< Thread (or null for main) + unsigned _id; ///< Context ID + + FrameTime _start{0}; ///< Start frame of this cycle (timeline) + FrameTime _end{0}; ///< End frame of this cycle (timeline) + SampleCount _offset{0}; ///< Offset into data buffers + SampleCount _nframes{0}; ///< Number of frames past offset to process + SampleCount _rate{0}; ///< Sample rate in Hz + bool _realtime{true}; ///< True iff context is hard realtime }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_RUNCONTEXT_HPP diff --git a/src/server/SocketListener.cpp b/src/server/SocketListener.cpp index 445374c4..fb961ee2 100644 --- a/src/server/SocketListener.cpp +++ b/src/server/SocketListener.cpp @@ -19,15 +19,16 @@ #include "Engine.hpp" #include "SocketServer.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Log.hpp" -#include "ingen/URI.hpp" -#include "ingen/World.hpp" -#include "raul/Socket.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Log.hpp> +#include <ingen/URI.hpp> +#include <ingen/World.hpp> +#include <raul/Socket.hpp> #include <poll.h> #include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> #include <cerrno> @@ -40,8 +41,7 @@ #include <string> #include <thread> -namespace ingen { -namespace server { +namespace ingen::server { static constexpr const char* const unix_scheme = "unix://"; @@ -51,7 +51,7 @@ get_link_target(const char* link_path) // Stat the link to get the required size for the target path struct stat link_stat{}; if (lstat(link_path, &link_stat)) { - return std::string(); + return {}; } // Allocate buffer and read link target @@ -63,7 +63,7 @@ get_link_target(const char* link_path) } free(target); - return std::string(); + return {}; } static void ingen_listen(Engine* engine, @@ -141,7 +141,7 @@ ingen_listen(Engine* engine, raul::Socket* unix_sock, raul::Socket* net_sock) } if (unix_sock->fd() == -1 && net_sock->fd() == -1) { - return; // No sockets to listen to, exit thread + return; // No sockets to listen to, exit thread } struct pollfd pfds[2]; @@ -165,10 +165,14 @@ ingen_listen(Engine* engine, raul::Socket* unix_sock, raul::Socket* net_sock) if (ret == -1) { world.log().error("Poll error: %1%\n", strerror(errno)); break; - } else if (ret == 0) { + } + + if (ret == 0) { world.log().warn("Poll returned with no data\n"); continue; - } else if ((pfds[0].revents & POLLHUP) || pfds[1].revents & POLLHUP) { + } + + if ((pfds[0].revents & POLLHUP) || pfds[1].revents & POLLHUP) { break; } @@ -192,5 +196,4 @@ ingen_listen(Engine* engine, raul::Socket* unix_sock, raul::Socket* net_sock) } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/SocketListener.hpp b/src/server/SocketListener.hpp index 70a2d46b..a96105ef 100644 --- a/src/server/SocketListener.hpp +++ b/src/server/SocketListener.hpp @@ -14,13 +14,12 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "raul/Socket.hpp" +#include <raul/Socket.hpp> #include <memory> #include <thread> -namespace ingen { -namespace server { +namespace ingen::server { class Engine; @@ -28,7 +27,7 @@ class Engine; class SocketListener { public: - SocketListener(Engine& engine); + explicit SocketListener(Engine& engine); ~SocketListener(); private: @@ -37,5 +36,4 @@ private: std::unique_ptr<std::thread> thread; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/SocketServer.hpp b/src/server/SocketServer.hpp index ac8aa611..608d180d 100644 --- a/src/server/SocketServer.hpp +++ b/src/server/SocketServer.hpp @@ -21,24 +21,23 @@ #include "Engine.hpp" -#include "ingen/Atom.hpp" -#include "ingen/ColorContext.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Interface.hpp" -#include "ingen/SocketReader.hpp" -#include "ingen/SocketWriter.hpp" -#include "ingen/StreamWriter.hpp" -#include "ingen/Tee.hpp" -#include "ingen/URI.hpp" -#include "ingen/World.hpp" -#include "raul/Socket.hpp" +#include <ingen/Atom.hpp> +#include <ingen/ColorContext.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Interface.hpp> +#include <ingen/SocketReader.hpp> +#include <ingen/SocketWriter.hpp> +#include <ingen/StreamWriter.hpp> +#include <ingen/Tee.hpp> +#include <ingen/URI.hpp> +#include <ingen/World.hpp> +#include <raul/Socket.hpp> #include <cstdint> #include <cstdio> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { /** The server side of an Ingen socket connection. */ class SocketServer @@ -86,7 +85,6 @@ private: std::shared_ptr<SocketWriter> _writer; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server -#endif // INGEN_SERVER_SOCKET_SERVER_HPP +#endif // INGEN_SERVER_SOCKET_SERVER_HPP diff --git a/src/server/State.hpp b/src/server/State.hpp index b5a3f7c0..976cf67d 100644 --- a/src/server/State.hpp +++ b/src/server/State.hpp @@ -17,21 +17,18 @@ #ifndef INGEN_ENGINE_STATE_HPP #define INGEN_ENGINE_STATE_HPP -#include "lilv/lilv.h" +#include <lilv/lilv.h> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { -struct StateDeleter -{ +struct StateDeleter { void operator()(LilvState* state) { lilv_state_free(state); } }; using StatePtr = std::unique_ptr<LilvState, StateDeleter>; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_STATE_HPP diff --git a/src/server/Task.cpp b/src/server/Task.cpp index ec9568b3..345a4711 100644 --- a/src/server/Task.cpp +++ b/src/server/Task.cpp @@ -19,12 +19,12 @@ #include "BlockImpl.hpp" #include "RunContext.hpp" -#include "raul/Path.hpp" +#include <raul/Path.hpp> #include <cstddef> +#include <memory> -namespace ingen { -namespace server { +namespace ingen::server { void Task::run(RunContext& ctx) @@ -93,7 +93,7 @@ Task::get_task(RunContext& ctx) } if (_done_end >= _children.size()) { - return nullptr; // All child tasks are finished + return nullptr; // All child tasks are finished } // All child tasks claimed, but some are unfinished, steal a task @@ -116,7 +116,7 @@ Task::simplify(std::unique_ptr<Task>&& task) return std::move(task); } - std::unique_ptr<Task> ret = std::unique_ptr<Task>(new Task(task->mode())); + std::unique_ptr<Task> ret = std::make_unique<Task>(task->mode()); for (auto&& c : task->_children) { auto child = simplify(std::move(c)); if (!child->empty()) { @@ -162,5 +162,4 @@ Task::dump(const std::function<void(const std::string&)>& sink, } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/Task.hpp b/src/server/Task.hpp index a7657499..f2141bd5 100644 --- a/src/server/Task.hpp +++ b/src/server/Task.hpp @@ -17,7 +17,6 @@ #ifndef INGEN_ENGINE_TASK_HPP #define INGEN_ENGINE_TASK_HPP -#include <algorithm> #include <atomic> #include <cassert> #include <deque> @@ -26,30 +25,29 @@ #include <string> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { class BlockImpl; class RunContext; -class Task { +class Task +{ public: enum class Mode { - SINGLE, ///< Single block to run - SEQUENTIAL, ///< Elements must be run sequentially in order - PARALLEL ///< Elements may be run in any order in parallel + SINGLE, ///< Single block to run + SEQUENTIAL, ///< Elements must be run sequentially in order + PARALLEL ///< Elements may be run in any order in parallel }; - Task(Mode mode, BlockImpl* block = nullptr) + Task(Mode mode, BlockImpl* block) : _block(block) , _mode(mode) - , _done_end(0) - , _next(0) - , _done(false) { - assert(!(mode == Mode::SINGLE && !block)); + assert(mode != Mode::SINGLE || block); } + explicit Task(Mode mode) : Task{mode, nullptr} {} + Task(const Task&) = delete; Task& operator=(const Task&) = delete; @@ -92,7 +90,7 @@ public: /** Prepend a child to this task. */ void push_front(Task&& task) { - _children.emplace_front(std::unique_ptr<Task>(new Task(std::move(task)))); + _children.emplace_front(std::make_unique<Task>(std::move(task))); } Mode mode() const { return _mode; } @@ -110,15 +108,14 @@ private: _children.emplace_back(std::move(t)); } - Children _children; ///< Vector of child tasks - BlockImpl* _block; ///< Used for SINGLE only - Mode _mode; ///< Execution mode - unsigned _done_end; ///< Index of rightmost done sub-task - std::atomic<unsigned> _next; ///< Index of next sub-task - std::atomic<bool> _done; ///< Completion phase + Children _children; ///< Vector of child tasks + BlockImpl* _block; ///< Used for SINGLE only + Mode _mode; ///< Execution mode + unsigned _done_end{0}; ///< Index of rightmost done sub-task + std::atomic<unsigned> _next{0}; ///< Index of next sub-task + std::atomic<bool> _done{false}; ///< Completion phase }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_TASK_HPP diff --git a/src/server/ThreadManager.hpp b/src/server/ThreadManager.hpp index 81fb15cb..2e0ad966 100644 --- a/src/server/ThreadManager.hpp +++ b/src/server/ThreadManager.hpp @@ -17,12 +17,11 @@ #ifndef INGEN_ENGINE_THREADMANAGER_HPP #define INGEN_ENGINE_THREADMANAGER_HPP -#include "ingen/ingen.h" +#include "server.h" #include <cassert> -namespace ingen { -namespace server { +namespace ingen::server { enum ThreadFlag { THREAD_IS_REAL_TIME = 1, @@ -31,25 +30,26 @@ enum ThreadFlag { THREAD_MESSAGE = 1 << 3, }; -class INGEN_API ThreadManager { +class INGEN_SERVER_API ThreadManager +{ public: - static inline void set_flag(ThreadFlag f) { + static void set_flag(ThreadFlag f) { #ifndef NDEBUG - flags = (static_cast<unsigned>(flags) | f); + flags |= static_cast<unsigned>(f); #endif } - static inline void unset_flag(ThreadFlag f) { + static void unset_flag(ThreadFlag f) { #ifndef NDEBUG - flags = (static_cast<unsigned>(flags) & (~f)); + flags &= ~static_cast<unsigned>(f); #endif } - static inline void assert_thread(ThreadFlag f) { + static void assert_thread(ThreadFlag f) { assert(single_threaded || (flags & f)); } - static inline void assert_not_thread(ThreadFlag f) { + static void assert_not_thread(ThreadFlag f) { assert(single_threaded || !(flags & f)); } @@ -60,7 +60,6 @@ public: static thread_local unsigned flags; }; -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_THREADMANAGER_HPP diff --git a/src/server/UndoStack.cpp b/src/server/UndoStack.cpp index 97539823..c6555123 100644 --- a/src/server/UndoStack.cpp +++ b/src/server/UndoStack.cpp @@ -16,24 +16,23 @@ #include "UndoStack.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/patch/patch.h" -#include "serd/serd.h" -#include "sratom/sratom.h" +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/ingen.h> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/patch/patch.h> +#include <serd/serd.h> +#include <sratom/sratom.h> #include <ctime> #include <iterator> -#include <memory> #define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" #define USTR(s) reinterpret_cast<const uint8_t*>(s) -namespace ingen { -namespace server { +namespace ingen::server { int UndoStack::start_entry() @@ -41,7 +40,7 @@ UndoStack::start_entry() if (_depth == 0) { time_t now = {}; time(&now); - _stack.emplace_back(Entry(now)); + _stack.emplace_back(now); } return ++_depth; } @@ -86,18 +85,18 @@ UndoStack::ignore_later_event(const LV2_Atom* first, int UndoStack::finish_entry() { - if (--_depth > 0) { - return _depth; - } else if (_stack.back().events.empty()) { - // Disregard empty entry - _stack.pop_back(); - } else if (_stack.size() > 1 && _stack.back().events.size() == 1) { - // This entry and the previous one have one event, attempt to merge - auto i = _stack.rbegin(); - ++i; - if (i->events.size() == 1) { - if (ignore_later_event(i->events[0], _stack.back().events[0])) { - _stack.pop_back(); + if (--_depth == 0) { + if (_stack.back().events.empty()) { + // Disregard empty entry + _stack.pop_back(); + } else if (_stack.size() > 1 && _stack.back().events.size() == 1) { + // This entry and the previous one have one event, attempt to merge + auto i = _stack.rbegin(); + ++i; + if (i->events.size() == 1) { + if (ignore_later_event(i->events[0], _stack.back().events[0])) { + _stack.pop_back(); + } } } } @@ -117,7 +116,7 @@ UndoStack::pop() } struct BlankIDs { - explicit BlankIDs(char prefix='b') : c(prefix) {} + explicit BlankIDs(const char prefix = 'b') noexcept : c{prefix} {} SerdNode get() { snprintf(buf, sizeof(buf), "%c%u", c, n++); @@ -126,7 +125,7 @@ struct BlankIDs { char buf[16]{}; unsigned n{0}; - const char c{'b'}; + const char c; }; struct ListContext { @@ -138,8 +137,7 @@ struct ListContext { , s(*subject) , p(*predicate) , flags(statement_flags | SERD_LIST_O_BEGIN) - { - } + {} SerdNode start_node(SerdWriter* writer) { const SerdNode node = ids.get(); @@ -189,8 +187,8 @@ UndoStack::write_entry(Sratom* sratom, strftime(time_str, sizeof(time_str), "%FT%T", gmtime(&entry.time)); // entry rdf:type ingen:UndoEntry - SerdNode p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "time")); - SerdNode o = serd_node_from_string(SERD_LITERAL, USTR(time_str)); + SerdNode p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "time")); + const SerdNode o = serd_node_from_string(SERD_LITERAL, USTR(time_str)); serd_writer_write_statement(writer, SERD_ANON_CONT, nullptr, subject, &p, &o, nullptr, nullptr); p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "events")); @@ -226,7 +224,7 @@ UndoStack::save(FILE* stream, const char* name) const SerdNode base = serd_node_from_string(SERD_URI, USTR("ingen:/")); SerdURI base_uri; - serd_uri_parse(base.buf, &base_uri); + serd_uri_parse(USTR("ingen:/"), &base_uri); SerdWriter* writer = serd_writer_new(SERD_TURTLE, @@ -246,8 +244,8 @@ UndoStack::save(FILE* stream, const char* name) reinterpret_cast<SerdEndSink>(serd_writer_end_anon), writer); - SerdNode s = serd_node_from_string(SERD_BLANK, USTR(name)); - SerdNode p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "entries")); + const SerdNode s = serd_node_from_string(SERD_BLANK, USTR(name)); + const SerdNode p = serd_node_from_string(SERD_URI, USTR(INGEN_NS "entries")); BlankIDs ids('u'); ListContext ctx(ids, 0, &s, &p); @@ -264,5 +262,4 @@ UndoStack::save(FILE* stream, const char* name) serd_writer_free(writer); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/UndoStack.hpp b/src/server/UndoStack.hpp index 7749b8fb..443497cc 100644 --- a/src/server/UndoStack.hpp +++ b/src/server/UndoStack.hpp @@ -17,14 +17,13 @@ #ifndef INGEN_ENGINE_UNDOSTACK_HPP #define INGEN_ENGINE_UNDOSTACK_HPP -#include "ingen/AtomSink.hpp" -#include "ingen/ingen.h" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "serd/serd.h" -#include "sratom/sratom.h" - -#include <algorithm> +#include <ingen/AtomSink.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <serd/serd.h> +#include <server.h> +#include <sratom/sratom.h> + #include <cstdint> #include <cstdio> #include <cstdlib> @@ -39,10 +38,12 @@ class URIs; namespace server { -class INGEN_API UndoStack : public AtomSink { +class INGEN_SERVER_API UndoStack : public AtomSink +{ public: struct Entry { - Entry(time_t t=0) : time(t) {} + explicit Entry(time_t t) noexcept : time{t} {} + Entry() noexcept : Entry{0} {} Entry(const Entry& copy) : time(copy.time) @@ -83,7 +84,7 @@ public: std::deque<LV2_Atom*> events; }; - UndoStack(URIs& uris, URIMap& map) : _uris(uris), _map(map), _depth(0) {} + UndoStack(URIs& uris, URIMap& map) noexcept : _uris(uris), _map(map) {} int start_entry(); bool write(const LV2_Atom* msg, int32_t default_id=0) override; @@ -106,7 +107,7 @@ private: URIs& _uris; URIMap& _map; std::deque<Entry> _stack; - int _depth; + int _depth{0}; }; } // namespace server diff --git a/src/server/Worker.cpp b/src/server/Worker.cpp index 77d98612..1c04bb36 100644 --- a/src/server/Worker.cpp +++ b/src/server/Worker.cpp @@ -20,25 +20,23 @@ #include "GraphImpl.hpp" #include "LV2Block.hpp" -#include "ingen/Log.hpp" -#include "ingen/Node.hpp" -#include "lv2/core/lv2.h" -#include "lv2/worker/worker.h" +#include <ingen/Log.hpp> +#include <ingen/Node.hpp> +#include <lv2/core/lv2.h> +#include <lv2/worker/worker.h> +#include <raul/RingBuffer.hpp> +#include <raul/Semaphore.hpp> #include <cstdlib> #include <memory> -namespace ingen { - -class World; - -namespace server { +namespace ingen::server { /// A message in the Worker::_requests ring struct MessageHeader { - LV2Block* block; ///< Node this message is from + LV2Block* block; ///< Node this message is from uint32_t size; ///< Size of following data - // `size' bytes of data follow here + // `size' bytes of data follow here }; static LV2_Worker_Status @@ -46,8 +44,8 @@ schedule(LV2_Worker_Schedule_Handle handle, uint32_t size, const void* data) { - auto* block = static_cast<LV2Block*>(handle); - Engine& engine = block->parent_graph()->engine(); + auto* block = static_cast<LV2Block*>(handle); + const Engine& engine = block->parent_graph()->engine(); return engine.worker()->request(block, size, data); } @@ -57,8 +55,8 @@ schedule_sync(LV2_Worker_Schedule_Handle handle, uint32_t size, const void* data) { - auto* block = static_cast<LV2Block*>(handle); - Engine& engine = block->parent_graph()->engine(); + auto* block = static_cast<LV2Block*>(handle); + const Engine& engine = block->parent_graph()->engine(); return engine.sync_worker()->request(block, size, data); } @@ -72,7 +70,7 @@ Worker::request(LV2Block* block, return block->work(size, data); } - Engine& engine = block->parent_graph()->engine(); + const Engine& engine = block->parent_graph()->engine(); if (_requests.write_space() < sizeof(MessageHeader) + size) { engine.log().error("Work request ring overflow\n"); return LV2_WORKER_ERR_NO_SPACE; @@ -110,19 +108,17 @@ Worker::Schedule::feature(World&, Node* n) f->URI = LV2_WORKER__schedule; f->data = data; - return std::shared_ptr<LV2_Feature>(f, &free_feature); + return {f, &free_feature}; } Worker::Worker(Log& log, uint32_t buffer_size, bool synchronous) : _schedule(new Schedule(synchronous)) , _log(log) - , _sem(0) , _requests(buffer_size) , _responses(buffer_size) , _buffer(static_cast<uint8_t*>(malloc(buffer_size))) , _buffer_size(buffer_size) , _thread(nullptr) - , _exit_flag(false) , _synchronous(synchronous) { if (!synchronous) { @@ -166,5 +162,4 @@ Worker::run() } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/Worker.hpp b/src/server/Worker.hpp index dd799174..08b75509 100644 --- a/src/server/Worker.hpp +++ b/src/server/Worker.hpp @@ -17,11 +17,11 @@ #ifndef INGEN_ENGINE_WORKER_HPP #define INGEN_ENGINE_WORKER_HPP -#include "ingen/LV2Features.hpp" -#include "lv2/core/lv2.h" -#include "lv2/worker/worker.h" -#include "raul/RingBuffer.hpp" -#include "raul/Semaphore.hpp" +#include <ingen/LV2Features.hpp> +#include <lv2/core/lv2.h> +#include <lv2/worker/worker.h> +#include <raul/RingBuffer.hpp> +#include <raul/Semaphore.hpp> #include <cstdint> #include <memory> @@ -30,8 +30,6 @@ namespace ingen { class Log; -class Node; -class World; namespace server { @@ -44,7 +42,7 @@ public: ~Worker(); struct Schedule : public LV2Features::Feature { - Schedule(bool sync) : synchronous(sync) {} + explicit Schedule(bool sync) noexcept : synchronous(sync) {} const char* uri() const override { return LV2_WORKER__schedule; } @@ -63,13 +61,13 @@ private: std::shared_ptr<Schedule> _schedule; Log& _log; - raul::Semaphore _sem; + raul::Semaphore _sem{0}; raul::RingBuffer _requests; raul::RingBuffer _responses; uint8_t* const _buffer; const uint32_t _buffer_size; std::unique_ptr<std::thread> _thread; - bool _exit_flag; + bool _exit_flag{false}; bool _synchronous; void run(); diff --git a/src/server/events.hpp b/src/server/events.hpp index 5f77b431..7ab20ca7 100644 --- a/src/server/events.hpp +++ b/src/server/events.hpp @@ -17,19 +17,19 @@ #ifndef INGEN_ENGINE_EVENTS_HPP #define INGEN_ENGINE_EVENTS_HPP -#include "events/Connect.hpp" -#include "events/Copy.hpp" -#include "events/CreateBlock.hpp" -#include "events/CreateGraph.hpp" -#include "events/CreatePort.hpp" -#include "events/Delete.hpp" -#include "events/Delta.hpp" -#include "events/Disconnect.hpp" -#include "events/DisconnectAll.hpp" -#include "events/Get.hpp" -#include "events/Mark.hpp" -#include "events/Move.hpp" -#include "events/SetPortValue.hpp" -#include "events/Undo.hpp" +#include <events/Connect.hpp> +#include <events/Copy.hpp> +#include <events/CreateBlock.hpp> +#include <events/CreateGraph.hpp> +#include <events/CreatePort.hpp> +#include <events/Delete.hpp> +#include <events/Delta.hpp> +#include <events/Disconnect.hpp> +#include <events/DisconnectAll.hpp> +#include <events/Get.hpp> +#include <events/Mark.hpp> +#include <events/Move.hpp> +#include <events/SetPortValue.hpp> +#include <events/Undo.hpp> #endif // INGEN_ENGINE_EVENTS_HPP diff --git a/src/server/events/Connect.cpp b/src/server/events/Connect.cpp index 234bc550..6e20be8f 100644 --- a/src/server/events/Connect.cpp +++ b/src/server/events/Connect.cpp @@ -16,6 +16,7 @@ #include "Connect.hpp" +#include "../internals/BlockDelay.hpp" #include "ArcImpl.hpp" #include "BlockImpl.hpp" #include "Broadcaster.hpp" @@ -26,15 +27,16 @@ #include "InputPort.hpp" #include "PortImpl.hpp" #include "PreProcessContext.hpp" -#include "internals/BlockDelay.hpp" #include "types.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "ingen/paths.hpp" -#include "raul/Maid.hpp" +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/paths.hpp> +#include <raul/Maid.hpp> #include <cassert> #include <memory> @@ -42,9 +44,7 @@ #include <set> #include <utility> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { Connect::Connect(Engine& engine, const std::shared_ptr<Interface>& client, @@ -52,17 +52,14 @@ Connect::Connect(Engine& engine, const ingen::Connect& msg) : Event(engine, client, msg.seq, timestamp) , _msg(msg) - , _graph(nullptr) - , _head(nullptr) -{ -} +{} Connect::~Connect() = default; bool Connect::pre_process(PreProcessContext& ctx) { - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; Node* tail = _engine.store()->get(_msg.tail); if (!tail) { @@ -137,7 +134,7 @@ Connect::pre_process(PreProcessContext& ctx) head_block->providers().insert(tail_block); if (ctx.must_compile(*_graph)) { - if (!(_compiled_graph = compile(*_engine.maid(), *_graph))) { + if (!(_compiled_graph = compile(*_graph))) { head_block->providers().erase(tail_block); tail_block->dependants().erase(head_block); return Event::pre_process_done(Status::COMPILATION_FAILED); @@ -170,7 +167,7 @@ Connect::execute(RunContext& ctx) } _head->connect_buffers(); if (_compiled_graph) { - _graph->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = _graph->swap_compiled_graph(std::move(_compiled_graph)); } } } @@ -178,7 +175,7 @@ Connect::execute(RunContext& ctx) void Connect::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _engine.broadcaster()->message(_msg); if (!_tail_remove.empty() || !_tail_add.empty()) { @@ -198,6 +195,4 @@ Connect::undo(Interface& target) target.disconnect(_msg.tail, _msg.head); } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/Connect.hpp b/src/server/events/Connect.hpp index 941c0a25..458df0ef 100644 --- a/src/server/events/Connect.hpp +++ b/src/server/events/Connect.hpp @@ -21,9 +21,9 @@ #include "PortImpl.hpp" #include "types.hpp" -#include "ingen/Message.hpp" -#include "ingen/Properties.hpp" -#include "raul/Maid.hpp" +#include <ingen/Message.hpp> +#include <ingen/Properties.hpp> +#include <raul/Maid.hpp> #include <memory> @@ -38,8 +38,6 @@ class CompiledGraph; class Engine; class GraphImpl; class InputPort; -class PreProcessContext; -class RunContext; namespace events { @@ -64,9 +62,9 @@ public: private: const ingen::Connect _msg; - GraphImpl* _graph; - InputPort* _head; - raul::managed_ptr<CompiledGraph> _compiled_graph; + GraphImpl* _graph{nullptr}; + InputPort* _head{nullptr}; + std::unique_ptr<CompiledGraph> _compiled_graph; std::shared_ptr<ArcImpl> _arc; raul::managed_ptr<PortImpl::Voices> _voices; Properties _tail_remove; diff --git a/src/server/events/Copy.cpp b/src/server/events/Copy.cpp index 9ce7ead6..e75bf1c5 100644 --- a/src/server/events/Copy.cpp +++ b/src/server/events/Copy.cpp @@ -14,7 +14,7 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "events/Copy.hpp" +#include "Copy.hpp" #include "BlockImpl.hpp" #include "Broadcaster.hpp" @@ -23,28 +23,28 @@ #include "GraphImpl.hpp" #include "PreProcessContext.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Parser.hpp" -#include "ingen/Serialiser.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "ingen/URI.hpp" -#include "ingen/World.hpp" -#include "ingen/paths.hpp" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" - -#include <boost/optional/optional.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Node.hpp> +#include <ingen/Parser.hpp> +#include <ingen/Serialiser.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/World.hpp> +#include <ingen/paths.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> #include <map> #include <memory> #include <mutex> +#include <optional> #include <string> +#include <string_view> #include <utility> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { Copy::Copy(Engine& engine, const std::shared_ptr<Interface>& client, @@ -52,9 +52,6 @@ Copy::Copy(Engine& engine, const ingen::Copy& msg) : Event(engine, client, msg.seq, timestamp) , _msg(msg) - , _old_block(nullptr) - , _parent(nullptr) - , _block(nullptr) {} Copy::~Copy() = default; @@ -62,14 +59,14 @@ Copy::~Copy() = default; bool Copy::pre_process(PreProcessContext& ctx) { - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; if (uri_is_path(_msg.old_uri)) { // Old URI is a path within the engine const raul::Path old_path = uri_to_path(_msg.old_uri); // Find the old node - const Store::iterator i = _engine.store()->find(old_path); + const auto i = _engine.store()->find(old_path); if (i == _engine.store()->end()) { return Event::pre_process_done(Status::NOT_FOUND, old_path); } @@ -82,19 +79,23 @@ Copy::pre_process(PreProcessContext& ctx) if (uri_is_path(_msg.new_uri)) { // Copy to path within the engine return engine_to_engine(ctx); - } else if (_msg.new_uri.scheme() == "file") { + } + + if (_msg.new_uri.scheme() == "file") { // Copy to filesystem path (i.e. save) return engine_to_filesystem(ctx); - } else { - return Event::pre_process_done(Status::BAD_REQUEST); } - } else if (_msg.old_uri.scheme() == "file") { + + return Event::pre_process_done(Status::BAD_REQUEST); + } + + if (_msg.old_uri.scheme() == "file") { if (uri_is_path(_msg.new_uri)) { return filesystem_to_engine(ctx); - } else { - // Ingen is not your file manager - return Event::pre_process_done(Status::BAD_REQUEST); } + + // Ingen is not your file manager + return Event::pre_process_done(Status::BAD_REQUEST); } return Event::pre_process_done(Status::BAD_URI); @@ -115,8 +116,8 @@ Copy::engine_to_engine(PreProcessContext& ctx) } // Find new parent graph - const raul::Path parent_path = new_path.parent(); - const Store::iterator p = _engine.store()->find(parent_path); + const raul::Path parent_path = new_path.parent(); + const auto p = _engine.store()->find(parent_path); if (p == _engine.store()->end()) { return Event::pre_process_done(Status::NOT_FOUND, parent_path); } @@ -125,8 +126,7 @@ Copy::engine_to_engine(PreProcessContext& ctx) } // Create new block - if (!(_block = dynamic_cast<BlockImpl*>( - _old_block->duplicate(_engine, raul::Symbol(new_path.symbol()), _parent)))) { + if (!(_block = _old_block->duplicate(_engine, raul::Symbol(new_path.symbol()), _parent))) { return Event::pre_process_done(Status::INTERNAL_ERROR); } @@ -137,7 +137,7 @@ Copy::engine_to_engine(PreProcessContext& ctx) _engine.store()->add(_block); // Compile graph with new block added for insertion in audio thread - _compiled_graph = ctx.maybe_compile(*_engine.maid(), *_parent); + _compiled_graph = ctx.maybe_compile(*_parent); return Event::pre_process_done(Status::SUCCESS); } @@ -164,7 +164,7 @@ Copy::engine_to_filesystem(PreProcessContext&) return Event::pre_process_done(Status::INTERNAL_ERROR); } - std::lock_guard<std::mutex> lock(_engine.world().rdf_mutex()); + const std::lock_guard<std::mutex> lock{_engine.world().rdf_mutex()}; if (ends_with(_msg.new_uri, ".ingen") || ends_with(_msg.new_uri, ".ingen/")) { _engine.world().serialiser()->write_bundle(graph, URI(_msg.new_uri)); @@ -185,13 +185,13 @@ Copy::filesystem_to_engine(PreProcessContext&) return Event::pre_process_done(Status::INTERNAL_ERROR); } - std::lock_guard<std::mutex> lock(_engine.world().rdf_mutex()); + const std::lock_guard<std::mutex> lock{_engine.world().rdf_mutex()}; // Old URI is a filesystem path and new URI is a path within the engine - const std::string src_path(_msg.old_uri.path()); - const raul::Path dst_path = uri_to_path(_msg.new_uri); - boost::optional<raul::Path> dst_parent; - boost::optional<raul::Symbol> dst_symbol; + const std::string src_path(_msg.old_uri.path()); + const raul::Path dst_path = uri_to_path(_msg.new_uri); + std::optional<raul::Path> dst_parent; + std::optional<raul::Symbol> dst_symbol; if (!dst_path.is_root()) { dst_parent = dst_path.parent(); dst_symbol = raul::Symbol(dst_path.symbol()); @@ -208,14 +208,15 @@ void Copy::execute(RunContext&) { if (_block && _compiled_graph) { - _parent->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = + _parent->swap_compiled_graph(std::move(_compiled_graph)); } } void Copy::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _engine.broadcaster()->message(_msg); } @@ -229,6 +230,4 @@ Copy::undo(Interface& target) } } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/Copy.hpp b/src/server/events/Copy.hpp index f9c507f0..8031bb42 100644 --- a/src/server/events/Copy.hpp +++ b/src/server/events/Copy.hpp @@ -20,8 +20,7 @@ #include "Event.hpp" #include "types.hpp" -#include "ingen/Message.hpp" -#include "raul/Maid.hpp" +#include <ingen/Message.hpp> #include <memory> @@ -36,7 +35,6 @@ class CompiledGraph; class Engine; class GraphImpl; class PreProcessContext; -class RunContext; namespace events { @@ -64,10 +62,10 @@ private: bool filesystem_to_engine(PreProcessContext& ctx); const ingen::Copy _msg; - std::shared_ptr<BlockImpl> _old_block; - GraphImpl* _parent; - BlockImpl* _block; - raul::managed_ptr<CompiledGraph> _compiled_graph; + std::shared_ptr<BlockImpl> _old_block{nullptr}; + GraphImpl* _parent{nullptr}; + BlockImpl* _block{nullptr}; + std::unique_ptr<CompiledGraph> _compiled_graph; }; } // namespace events diff --git a/src/server/events/CreateBlock.cpp b/src/server/events/CreateBlock.cpp index 0898a6a0..55c9b782 100644 --- a/src/server/events/CreateBlock.cpp +++ b/src/server/events/CreateBlock.cpp @@ -28,32 +28,27 @@ #include "State.hpp" #include "types.hpp" -#include "ingen/FilePath.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/paths.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" +#include <ingen/FilePath.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/paths.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> #include <map> #include <memory> +#include <string> #include <utility> -namespace ingen { -namespace server { - -class RunContext; - -namespace events { +namespace ingen::server::events { CreateBlock::CreateBlock(Engine& engine, const std::shared_ptr<Interface>& client, @@ -64,8 +59,6 @@ CreateBlock::CreateBlock(Engine& engine, : Event(engine, client, id, timestamp) , _path(std::move(path)) , _properties(properties) - , _graph(nullptr) - , _block(nullptr) {} CreateBlock::~CreateBlock() = default; @@ -73,22 +66,24 @@ CreateBlock::~CreateBlock() = default; bool CreateBlock::pre_process(PreProcessContext& ctx) { - using iterator = Properties::const_iterator; - const ingen::URIs& uris = _engine.world().uris(); const std::shared_ptr<Store> store = _engine.store(); // Check sanity of target path if (_path.is_root()) { return Event::pre_process_done(Status::BAD_URI, _path); - } else if (store->get(_path)) { + } + + if (store->get(_path)) { return Event::pre_process_done(Status::EXISTS, _path); - } else if (!(_graph = dynamic_cast<GraphImpl*>(store->get(_path.parent())))) { + } + + if (!(_graph = dynamic_cast<GraphImpl*>(store->get(_path.parent())))) { return Event::pre_process_done(Status::PARENT_NOT_FOUND, _path.parent()); } // Map old ingen:prototype to new lv2:prototype - auto range = _properties.equal_range(uris.ingen_prototype); + const auto range = _properties.equal_range(uris.ingen_prototype); for (auto i = range.first; i != range.second;) { const auto value = i->second; auto next = i; @@ -98,7 +93,7 @@ CreateBlock::pre_process(PreProcessContext& ctx) } // Get prototype - iterator t = _properties.find(uris.lv2_prototype); + const auto t = _properties.find(uris.lv2_prototype); if (t == _properties.end() || !uris.forge.is_uri(t->second)) { // Missing/invalid prototype return Event::pre_process_done(Status::BAD_REQUEST); @@ -107,10 +102,10 @@ CreateBlock::pre_process(PreProcessContext& ctx) const URI prototype(uris.forge.str(t->second, false)); // Find polyphony - const iterator p = _properties.find(uris.ingen_polyphonic); - const bool polyphonic = (p != _properties.end() && - p->second.type() == uris.forge.Bool && - p->second.get<int32_t>()); + const auto p = _properties.find(uris.ingen_polyphonic); + const bool polyphonic = (p != _properties.end() && + p->second.type() == uris.forge.Bool && + p->second.get<int32_t>()); // Find and instantiate/duplicate prototype (plugin/existing node) if (uri_is_path(prototype)) { @@ -119,8 +114,11 @@ CreateBlock::pre_process(PreProcessContext& ctx) store->get(uri_to_path(prototype))); if (!ancestor) { return Event::pre_process_done(Status::PROTOTYPE_NOT_FOUND, prototype); - } else if (!(_block = ancestor->duplicate( - _engine, raul::Symbol(_path.symbol()), _graph))) { + } + + if (!(_block = ancestor->duplicate(_engine, + raul::Symbol(_path.symbol()), + _graph))) { return Event::pre_process_done(Status::CREATION_FAILED, _path); } @@ -167,7 +165,7 @@ CreateBlock::pre_process(PreProcessContext& ctx) /* Compile graph with new block added for insertion in audio thread TODO: Since the block is not connected at this point, a full compilation could be avoided and the block simply appended. */ - _compiled_graph = ctx.maybe_compile(*_engine.maid(), *_graph); + _compiled_graph = ctx.maybe_compile(*_graph); _update.put_block(_block); @@ -178,14 +176,15 @@ void CreateBlock::execute(RunContext&) { if (_status == Status::SUCCESS && _compiled_graph) { - _graph->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = + _graph->swap_compiled_graph(std::move(_compiled_graph)); } } void CreateBlock::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _update.send(*_engine.broadcaster()); } @@ -197,6 +196,4 @@ CreateBlock::undo(Interface& target) target.del(_block->uri()); } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/CreateBlock.hpp b/src/server/events/CreateBlock.hpp index 97a54b3f..0ee6e36f 100644 --- a/src/server/events/CreateBlock.hpp +++ b/src/server/events/CreateBlock.hpp @@ -21,8 +21,7 @@ #include "Event.hpp" #include "types.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" +#include <raul/Path.hpp> #include <cstdint> #include <memory> @@ -38,8 +37,6 @@ class BlockImpl; class CompiledGraph; class Engine; class GraphImpl; -class PreProcessContext; -class RunContext; namespace events { @@ -68,9 +65,9 @@ private: raul::Path _path; Properties& _properties; ClientUpdate _update; - GraphImpl* _graph; - BlockImpl* _block; - raul::managed_ptr<CompiledGraph> _compiled_graph; + GraphImpl* _graph{nullptr}; + BlockImpl* _block{nullptr}; + std::unique_ptr<CompiledGraph> _compiled_graph; }; } // namespace events diff --git a/src/server/events/CreateGraph.cpp b/src/server/events/CreateGraph.cpp index 2a74ddf0..5df28afa 100644 --- a/src/server/events/CreateGraph.cpp +++ b/src/server/events/CreateGraph.cpp @@ -14,54 +14,50 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "events/CreateGraph.hpp" +#include "CreateGraph.hpp" #include "BlockImpl.hpp" #include "Broadcaster.hpp" #include "CompiledGraph.hpp" +#include "CreatePort.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "PreProcessContext.hpp" -#include "events/CreatePort.hpp" #include "types.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Resource.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/paths.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/paths.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> #include <boost/intrusive/slist.hpp> #include <map> #include <memory> +#include <string> #include <utility> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { CreateGraph::CreateGraph(Engine& engine, const std::shared_ptr<Interface>& client, int32_t id, SampleCount timestamp, raul::Path path, - const Properties& properties) + Properties properties) : Event(engine, client, id, timestamp) , _path(std::move(path)) - , _properties(properties) - , _graph(nullptr) - , _parent(nullptr) -{ -} + , _properties(std::move(properties)) +{} CreateGraph::~CreateGraph() = default; @@ -136,11 +132,9 @@ CreateGraph::pre_process(PreProcessContext& ctx) const ingen::URIs& uris = _engine.world().uris(); - using iterator = Properties::const_iterator; - - uint32_t ext_poly = 1; - uint32_t int_poly = 1; - iterator p = _properties.find(uris.ingen_polyphony); + uint32_t ext_poly = 1; + uint32_t int_poly = 1; + const auto p = _properties.find(uris.ingen_polyphony); if (p != _properties.end() && p->second.type() == uris.forge.Int) { int_poly = p->second.get<int32_t>(); } @@ -156,7 +150,7 @@ CreateGraph::pre_process(PreProcessContext& ctx) const raul::Symbol symbol(_path.is_root() ? "graph" : _path.symbol()); // Get graph prototype - iterator t = _properties.find(uris.lv2_prototype); + auto t = _properties.find(uris.lv2_prototype); if (t == _properties.end()) { t = _properties.find(uris.lv2_prototype); } @@ -171,8 +165,10 @@ CreateGraph::pre_process(PreProcessContext& ctx) if (!ancestor) { return Event::pre_process_done(Status::PROTOTYPE_NOT_FOUND, prototype); - } else if (!(_graph = dynamic_cast<GraphImpl*>( - ancestor->duplicate(_engine, symbol, _parent)))) { + } + + if (!(_graph = dynamic_cast<GraphImpl*>( + ancestor->duplicate(_engine, symbol, _parent)))) { return Event::pre_process_done(Status::CREATION_FAILED, _path); } } else { @@ -197,7 +193,7 @@ CreateGraph::pre_process(PreProcessContext& ctx) if (_parent->enabled()) { _graph->enable(); } - _compiled_graph = ctx.maybe_compile(*_engine.maid(), *_parent); + _compiled_graph = ctx.maybe_compile(*_parent); } _graph->activate(*_engine.buffer_factory()); @@ -224,7 +220,8 @@ CreateGraph::execute(RunContext& ctx) if (_graph) { if (_parent) { if (_compiled_graph) { - _parent->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = + _parent->swap_compiled_graph(std::move(_compiled_graph)); } } else { _engine.set_root_graph(_graph); @@ -240,7 +237,7 @@ CreateGraph::execute(RunContext& ctx) void CreateGraph::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _update.send(*_engine.broadcaster()); } @@ -258,6 +255,4 @@ CreateGraph::undo(Interface& target) target.del(_graph->uri()); } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/CreateGraph.hpp b/src/server/events/CreateGraph.hpp index d9e994c0..1d7f04a5 100644 --- a/src/server/events/CreateGraph.hpp +++ b/src/server/events/CreateGraph.hpp @@ -21,9 +21,8 @@ #include "Event.hpp" #include "types.hpp" -#include "ingen/Properties.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" +#include <ingen/Properties.hpp> +#include <raul/Path.hpp> #include <cstdint> #include <list> @@ -38,8 +37,6 @@ namespace server { class CompiledGraph; class Engine; class GraphImpl; -class PreProcessContext; -class RunContext; namespace events { @@ -55,7 +52,7 @@ public: int32_t id, SampleCount timestamp, raul::Path path, - const Properties& properties); + Properties properties); ~CreateGraph() override; @@ -72,9 +69,9 @@ private: const raul::Path _path; Properties _properties; ClientUpdate _update; - GraphImpl* _graph; - GraphImpl* _parent; - raul::managed_ptr<CompiledGraph> _compiled_graph; + GraphImpl* _graph{nullptr}; + GraphImpl* _parent{nullptr}; + std::unique_ptr<CompiledGraph> _compiled_graph; std::list<std::unique_ptr<Event>> _child_events; }; diff --git a/src/server/events/CreatePort.cpp b/src/server/events/CreatePort.cpp index 1fa2a528..b42542f8 100644 --- a/src/server/events/CreatePort.cpp +++ b/src/server/events/CreatePort.cpp @@ -23,31 +23,32 @@ #include "Engine.hpp" #include "GraphImpl.hpp" #include "PortImpl.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/paths.hpp" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" +#include "PortType.hpp" + +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/paths.hpp> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> #include <cassert> #include <map> #include <memory> +#include <string> #include <utility> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { CreatePort::CreatePort(Engine& engine, const std::shared_ptr<Interface>& client, @@ -57,20 +58,12 @@ CreatePort::CreatePort(Engine& engine, const Properties& properties) : Event(engine, client, id, timestamp) , _path(std::move(path)) - , _port_type(PortType::UNKNOWN) - , _buf_type(0) - , _graph(nullptr) - , _graph_port(nullptr) - , _engine_port(nullptr) , _properties(properties) { const ingen::URIs& uris = _engine.world().uris(); - using Iterator = Properties::const_iterator; - using Range = std::pair<Iterator, Iterator>; - - const Range types = properties.equal_range(uris.rdf_type); - for (Iterator i = types.first; i != types.second; ++i) { + const auto types = properties.equal_range(uris.rdf_type); + for (auto i = types.first; i != types.second; ++i) { const Atom& type = i->second; if (type == uris.lv2_AudioPort) { _port_type = PortType::AUDIO; @@ -87,8 +80,8 @@ CreatePort::CreatePort(Engine& engine, } } - const Range buffer_types = properties.equal_range(uris.atom_bufferType); - for (Iterator i = buffer_types.first; i != buffer_types.second; ++i) { + const auto buffer_types = properties.equal_range(uris.atom_bufferType); + for (auto i = buffer_types.first; i != buffer_types.second; ++i) { if (uris.forge.is_uri(i->second)) { _buf_type = _engine.world().uri_map().map_uri( uris.forge.str(i->second, false)); @@ -101,9 +94,13 @@ CreatePort::pre_process(PreProcessContext&) { if (_port_type == PortType::UNKNOWN || !_flow) { return Event::pre_process_done(Status::UNKNOWN_TYPE, _path); - } else if (_path.is_root()) { + } + + if (_path.is_root()) { return Event::pre_process_done(Status::BAD_URI, _path); - } else if (_engine.store()->get(_path)) { + } + + if (_engine.store()->get(_path)) { return Event::pre_process_done(Status::EXISTS, _path); } @@ -111,10 +108,14 @@ CreatePort::pre_process(PreProcessContext&) Node* const parent = _engine.store()->get(parent_path); if (!parent) { return Event::pre_process_done(Status::PARENT_NOT_FOUND, parent_path); - } else if (!(_graph = dynamic_cast<GraphImpl*>(parent))) { + } + + if (!(_graph = dynamic_cast<GraphImpl*>(parent))) { return Event::pre_process_done(Status::INVALID_PARENT, parent_path); - } else if (!_graph->parent() && _engine.activated() && - !_engine.driver()->dynamic_ports()) { + } + + if (!_graph->parent() && _engine.activated() && + !_engine.driver()->dynamic_ports()) { return Event::pre_process_done(Status::CREATION_FAILED, _path); } @@ -123,10 +124,8 @@ CreatePort::pre_process(PreProcessContext&) const uint32_t buf_size = bufs.default_size(_buf_type); const int32_t old_n_ports = _graph->num_ports_non_rt(); - using PropIter = Properties::const_iterator; - - PropIter index_i = _properties.find(uris.lv2_index); - int32_t index = 0; + auto index_i = _properties.find(uris.lv2_index); + int32_t index = 0; if (index_i != _properties.end()) { // Ensure given index is sane and not taken if (index_i->second.type() != uris.forge.Int) { @@ -144,7 +143,7 @@ CreatePort::pre_process(PreProcessContext&) _engine.world().forge().make(index)); } - const PropIter poly_i = _properties.find(uris.ingen_polyphonic); + const auto poly_i = _properties.find(uris.ingen_polyphonic); const bool polyphonic = (poly_i != _properties.end() && poly_i->second.type() == uris.forge.Bool && poly_i->second.get<int32_t>()); @@ -182,7 +181,7 @@ CreatePort::pre_process(PreProcessContext&) _update = _graph_port->properties(); assert(_graph_port->index() == static_cast<uint32_t>(index_i->second.get<int32_t>())); - assert(_graph->num_ports_non_rt() == static_cast<uint32_t>(old_n_ports) + 1u); + assert(_graph->num_ports_non_rt() == static_cast<uint32_t>(old_n_ports) + 1U); assert(_ports_array->size() == _graph->num_ports_non_rt()); assert(_graph_port->index() < _ports_array->size()); return Event::pre_process_done(Status::SUCCESS); @@ -213,7 +212,7 @@ CreatePort::execute(RunContext& ctx) void CreatePort::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _engine.broadcaster()->put(path_to_uri(_path), _update); } @@ -225,6 +224,4 @@ CreatePort::undo(Interface& target) target.del(_graph_port->uri()); } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/CreatePort.hpp b/src/server/events/CreatePort.hpp index 73746434..151bf82f 100644 --- a/src/server/events/CreatePort.hpp +++ b/src/server/events/CreatePort.hpp @@ -22,15 +22,14 @@ #include "PortType.hpp" #include "types.hpp" -#include "ingen/Properties.hpp" -#include "lv2/urid/urid.h" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" - -#include <boost/optional/optional.hpp> +#include <ingen/Properties.hpp> +#include <lv2/urid/urid.h> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> #include <cstdint> #include <memory> +#include <optional> namespace ingen { @@ -42,8 +41,6 @@ class DuplexPort; class Engine; class EnginePort; class GraphImpl; -class PreProcessContext; -class RunContext; namespace events { @@ -73,15 +70,15 @@ private: }; raul::Path _path; - PortType _port_type; - LV2_URID _buf_type; - GraphImpl* _graph; - DuplexPort* _graph_port; + PortType _port_type{PortType::UNKNOWN}; + LV2_URID _buf_type{0}; + GraphImpl* _graph{nullptr}; + DuplexPort* _graph_port{nullptr}; raul::managed_ptr<BlockImpl::Ports> _ports_array; ///< New external port array for Graph - EnginePort* _engine_port; ///< Driver port if on the root + EnginePort* _engine_port{nullptr}; ///< Driver port if on the root Properties _properties; Properties _update; - boost::optional<Flow> _flow; + std::optional<Flow> _flow; }; } // namespace events diff --git a/src/server/events/Delete.cpp b/src/server/events/Delete.cpp index 3347b549..9e940ea7 100644 --- a/src/server/events/Delete.cpp +++ b/src/server/events/Delete.cpp @@ -30,31 +30,27 @@ #include "PortImpl.hpp" #include "PreProcessContext.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/paths.hpp" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Node.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/paths.hpp> +#include <raul/Array.hpp> +#include <raul/Path.hpp> #include <cassert> #include <cstddef> #include <memory> #include <mutex> #include <string> +#include <string_view> -namespace ingen { -namespace server { - -class RunContext; - -namespace events { +namespace ingen::server::events { Delete::Delete(Engine& engine, const std::shared_ptr<Interface>& client, @@ -62,8 +58,6 @@ Delete::Delete(Engine& engine, const ingen::Del& msg) : Event(engine, client, msg.seq, timestamp) , _msg(msg) - , _engine_port(nullptr) - , _disconnect_event(nullptr) { if (uri_is_path(msg.uri)) { _path = uri_to_path(msg.uri); @@ -72,7 +66,7 @@ Delete::Delete(Engine& engine, Delete::~Delete() { - for (ControlBindings::Binding* b : _removed_bindings) { + for (auto* b : _removed_bindings) { delete b; } } @@ -106,7 +100,7 @@ Delete::pre_process(PreProcessContext& ctx) } // Take a writer lock while we modify the store - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; _engine.store()->remove(iter, _removed_objects); @@ -115,14 +109,14 @@ Delete::pre_process(PreProcessContext& ctx) _disconnect_event = std::make_unique<DisconnectAll>(_engine, parent, _block.get()); _disconnect_event->pre_process(ctx); - _compiled_graph = ctx.maybe_compile(*_engine.maid(), *parent); + _compiled_graph = ctx.maybe_compile(*parent); } else if (_port) { parent->remove_port(*_port); _disconnect_event = std::make_unique<DisconnectAll>(_engine, parent, _port.get()); _disconnect_event->pre_process(ctx); - _compiled_graph = ctx.maybe_compile(*_engine.maid(), *parent); + _compiled_graph = ctx.maybe_compile(*parent); if (parent->enabled()) { _ports_array = parent->build_ports_array(*_engine.maid()); assert(_ports_array->size() == parent->num_ports_non_rt()); @@ -184,14 +178,14 @@ Delete::execute(RunContext& ctx) } if (parent && _compiled_graph) { - parent->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = parent->swap_compiled_graph(std::move(_compiled_graph)); } } void Delete::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS && (_block || _port)) { if (_block) { _block->deactivate(); @@ -227,12 +221,10 @@ Delete::undo(Interface& target) if (c.first != _msg.uri.path()) { target.set_property(path_to_uri(c.first), uris.lv2_index, - forge.make(int32_t(c.second.first))); + forge.make(static_cast<int32_t>(c.second.first))); } } } } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/Delete.hpp b/src/server/events/Delete.hpp index 50a925b5..7e901f4b 100644 --- a/src/server/events/Delete.hpp +++ b/src/server/events/Delete.hpp @@ -17,35 +17,36 @@ #ifndef INGEN_EVENTS_DELETE_HPP #define INGEN_EVENTS_DELETE_HPP -#include "BlockImpl.hpp" #include "ControlBindings.hpp" #include "Event.hpp" #include "GraphImpl.hpp" #include "types.hpp" -#include "ingen/Message.hpp" -#include "ingen/Store.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" +#include <ingen/Message.hpp> +#include <ingen/Store.hpp> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> #include <cstdint> #include <map> #include <memory> +#include <string> #include <utility> #include <vector> +// IWYU pragma: no_include <iterator> + namespace ingen { class Interface; namespace server { +class BlockImpl; class CompiledGraph; class DuplexPort; class Engine; class EnginePort; -class PreProcessContext; -class RunContext; namespace events { @@ -77,9 +78,9 @@ private: raul::Path _path; std::shared_ptr<BlockImpl> _block; ///< Non-null iff a block std::shared_ptr<DuplexPort> _port; ///< Non-null iff a port - EnginePort* _engine_port; + EnginePort* _engine_port{nullptr}; raul::managed_ptr<GraphImpl::Ports> _ports_array; ///< New (external) ports for Graph - raul::managed_ptr<CompiledGraph> _compiled_graph; ///< Graph's new process order + std::unique_ptr<CompiledGraph> _compiled_graph; ///< Graph's new process order std::unique_ptr<DisconnectAll> _disconnect_event; Store::Objects _removed_objects; IndexChanges _port_index_changes; diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index b4d46fb9..cba21214 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -32,53 +32,43 @@ #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 "ingen/paths.hpp" -#include "lilv/lilv.h" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" - -#include <algorithm> -#include <map> +#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/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/paths.hpp> +#include <lilv/lilv.h> +#include <raul/Path.hpp> + #include <memory> #include <mutex> #include <set> #include <string> +#include <string_view> #include <utility> #include <vector> -namespace ingen { -namespace server { - -class PreProcessContext; - -namespace events { +namespace ingen::server::events { 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() , _context(msg.ctx) , _type(Type::PUT) - , _block(false) { init(); } @@ -92,13 +82,8 @@ Delta::Delta(Engine& engine, , _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(); } @@ -110,13 +95,8 @@ Delta::Delta(Engine& engine, : 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(); } @@ -172,12 +152,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; } @@ -222,12 +205,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))) @@ -239,7 +222,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; @@ -260,7 +243,7 @@ Delta::pre_process(PreProcessContext& ctx) } 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); } @@ -332,8 +315,8 @@ Delta::pre_process(PreProcessContext& ctx) const Property& value = p.second; SpecialType op = SpecialType::NONE; if (obj) { - Resource& resource = *obj; if (value != uris.patch_wildcard) { + Resource& resource = *obj; if (resource.add_property(key, value, value.context())) { _added.emplace(key, value); } @@ -372,7 +355,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; @@ -409,9 +392,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; } } @@ -516,7 +499,7 @@ Delta::execute(RunContext& ctx) 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; @@ -530,7 +513,7 @@ Delta::execute(RunContext& ctx) 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 { @@ -608,18 +591,18 @@ Delta::post_process() _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 } } @@ -687,6 +670,4 @@ Delta::get_execution() const return _block ? Execution::ATOMIC : Execution::NORMAL; } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/Delta.hpp b/src/server/events/Delta.hpp index 726d8b48..befbdcc7 100644 --- a/src/server/events/Delta.hpp +++ b/src/server/events/Delta.hpp @@ -18,20 +18,20 @@ #define INGEN_EVENTS_DELTA_HPP #include "ClientUpdate.hpp" +#include "CompiledGraph.hpp" #include "ControlBindings.hpp" #include "Event.hpp" +#include "SetPortValue.hpp" #include "State.hpp" #include "types.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URI.hpp" -#include "raul/Maid.hpp" - -#include <boost/optional/optional.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> #include <cstdint> #include <memory> +#include <optional> #include <vector> namespace ingen { @@ -43,16 +43,11 @@ struct SetProperty; namespace server { -class CompiledGraph; class Engine; class GraphImpl; -class PreProcessContext; -class RunContext; namespace events { -class SetPortValue; - /** Set properties of a graph object. * \ingroup engine */ @@ -115,10 +110,10 @@ private: Properties _properties; Properties _remove; ClientUpdate _update; - ingen::Resource* _object; - GraphImpl* _graph; - raul::managed_ptr<CompiledGraph> _compiled_graph; - ControlBindings::Binding* _binding; + ingen::Resource* _object{nullptr}; + GraphImpl* _graph{nullptr}; + std::unique_ptr<CompiledGraph> _compiled_graph; + ControlBindings::Binding* _binding{nullptr}; StatePtr _state; Resource::Graph _context; Type _type; @@ -128,9 +123,9 @@ private: std::vector<ControlBindings::Binding*> _removed_bindings; - boost::optional<Resource> _preset; + std::optional<Resource> _preset; - bool _block; + bool _block{false}; }; } // namespace events diff --git a/src/server/events/Disconnect.cpp b/src/server/events/Disconnect.cpp index ea6bb8f0..7189fdd0 100644 --- a/src/server/events/Disconnect.cpp +++ b/src/server/events/Disconnect.cpp @@ -14,7 +14,7 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "events/Disconnect.hpp" +#include "Disconnect.hpp" #include "BlockImpl.hpp" #include "Broadcaster.hpp" @@ -30,14 +30,15 @@ #include "PreProcessContext.hpp" #include "ThreadManager.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Node.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> #include <cassert> #include <cstdint> @@ -47,8 +48,7 @@ #include <string> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { class RunContext; @@ -60,9 +60,7 @@ Disconnect::Disconnect(Engine& engine, const ingen::Disconnect& msg) : Event(engine, client, msg.seq, timestamp) , _msg(msg) - , _graph(nullptr) -{ -} +{} Disconnect::~Disconnect() = default; @@ -120,7 +118,7 @@ Disconnect::Impl::Impl(Engine& e, bool Disconnect::pre_process(PreProcessContext& ctx) { - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; if (_msg.tail.parent().parent() != _msg.head.parent().parent() && _msg.tail.parent() != _msg.head.parent().parent() @@ -159,7 +157,9 @@ Disconnect::pre_process(PreProcessContext& ctx) if (!_graph) { return Event::pre_process_done(Status::INTERNAL_ERROR, _msg.head); - } else if (!_graph->has_arc(tail, head)) { + } + + if (!_graph->has_arc(tail, head)) { return Event::pre_process_done(Status::NOT_FOUND, _msg.head); } @@ -169,10 +169,10 @@ Disconnect::pre_process(PreProcessContext& ctx) _impl = std::make_unique<Impl>(_engine, _graph, - dynamic_cast<PortImpl*>(tail), + tail, dynamic_cast<InputPort*>(head)); - _compiled_graph = ctx.maybe_compile(*_engine.maid(), *_graph); + _compiled_graph = ctx.maybe_compile(*_graph); return Event::pre_process_done(Status::SUCCESS); } @@ -209,7 +209,8 @@ Disconnect::execute(RunContext& ctx) if (_status == Status::SUCCESS) { if (_impl->execute(ctx, true)) { if (_compiled_graph) { - _graph->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = + _graph->swap_compiled_graph(std::move(_compiled_graph)); } } else { _status = Status::NOT_FOUND; @@ -220,7 +221,7 @@ Disconnect::execute(RunContext& ctx) void Disconnect::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _engine.broadcaster()->message(_msg); } @@ -233,5 +234,4 @@ Disconnect::undo(Interface& target) } } // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/events/Disconnect.hpp b/src/server/events/Disconnect.hpp index a835ed27..92dd81d3 100644 --- a/src/server/events/Disconnect.hpp +++ b/src/server/events/Disconnect.hpp @@ -21,8 +21,8 @@ #include "PortImpl.hpp" #include "types.hpp" -#include "ingen/Message.hpp" -#include "raul/Maid.hpp" +#include <ingen/Message.hpp> +#include <raul/Maid.hpp> #include <memory> @@ -37,7 +37,6 @@ class CompiledGraph; class Engine; class GraphImpl; class InputPort; -class PreProcessContext; class RunContext; namespace events { @@ -61,14 +60,15 @@ public: void post_process() override; void undo(Interface& target) override; - class Impl { + class Impl + { public: Impl(Engine& e, GraphImpl* graph, PortImpl* t, InputPort* h); bool execute(RunContext& ctx, bool set_head_buffers); - inline PortImpl* tail() { return _tail; } - inline InputPort* head() { return _head; } + PortImpl* tail() { return _tail; } + InputPort* head() { return _head; } private: Engine& _engine; @@ -80,9 +80,9 @@ public: private: const ingen::Disconnect _msg; - GraphImpl* _graph; + GraphImpl* _graph{nullptr}; std::unique_ptr<Impl> _impl; - raul::managed_ptr<CompiledGraph> _compiled_graph; + std::unique_ptr<CompiledGraph> _compiled_graph; }; } // namespace events diff --git a/src/server/events/DisconnectAll.cpp b/src/server/events/DisconnectAll.cpp index 35254ba0..8e7bfbbe 100644 --- a/src/server/events/DisconnectAll.cpp +++ b/src/server/events/DisconnectAll.cpp @@ -14,35 +14,35 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "events/DisconnectAll.hpp" +#include "DisconnectAll.hpp" #include "ArcImpl.hpp" #include "BlockImpl.hpp" #include "Broadcaster.hpp" #include "CompiledGraph.hpp" +#include "Disconnect.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "InputPort.hpp" #include "NodeImpl.hpp" #include "PortImpl.hpp" #include "PreProcessContext.hpp" -#include "events/Disconnect.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "raul/Maid.hpp" +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Node.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <raul/Path.hpp> -#include <map> +#include <algorithm> +#include <iterator> #include <memory> #include <mutex> #include <set> #include <utility> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { DisconnectAll::DisconnectAll(Engine& engine, const std::shared_ptr<Interface>& client, @@ -54,8 +54,7 @@ DisconnectAll::DisconnectAll(Engine& engine, , _block(nullptr) , _port(nullptr) , _deleting(false) -{ -} +{} /** Internal version for use by other events. */ @@ -68,12 +67,11 @@ DisconnectAll::DisconnectAll(Engine& engine, , _block(dynamic_cast<BlockImpl*>(object)) , _port(dynamic_cast<PortImpl*>(object)) , _deleting(true) -{ -} +{} DisconnectAll::~DisconnectAll() { - for (auto& i : _impls) { + for (auto* i : _impls) { delete i; } } @@ -114,28 +112,35 @@ DisconnectAll::pre_process(PreProcessContext& ctx) } // Create disconnect events to erase adjacent arcs in parent - for (const auto& a : adjacent_arcs(_parent)) { - _impls.push_back( - new Disconnect::Impl(_engine, - _parent, - dynamic_cast<PortImpl*>(a->tail()), - dynamic_cast<InputPort*>(a->head()))); - } + const auto& arcs = adjacent_arcs(_parent); + std::transform(arcs.begin(), + arcs.end(), + std::back_inserter(_impls), + [this](const auto& a) { + return new Disconnect::Impl(_engine, + _parent, + a->tail(), + dynamic_cast<InputPort*>(a->head())); + }); // Create disconnect events to erase adjacent arcs in parent's parent if (_port && _parent->parent()) { - GraphImpl* parent_parent = dynamic_cast<GraphImpl*>(_parent->parent()); - for (const auto& a : adjacent_arcs(parent_parent)) { - _impls.push_back( - new Disconnect::Impl(_engine, - parent_parent, - dynamic_cast<PortImpl*>(a->tail()), - dynamic_cast<InputPort*>(a->head()))); - } + auto* const grandparent = dynamic_cast<GraphImpl*>(_parent->parent()); + const auto& parent_arcs = adjacent_arcs(grandparent); + + std::transform(parent_arcs.begin(), + parent_arcs.end(), + std::back_inserter(_impls), + [this, grandparent](const auto& a) { + return new Disconnect::Impl(_engine, + grandparent, + a->tail(), + dynamic_cast<InputPort*>(a->head())); + }); } if (!_deleting && ctx.must_compile(*_parent)) { - if (!(_compiled_graph = compile(*_engine.maid(), *_parent))) { + if (!(_compiled_graph = compile(*_parent))) { return Event::pre_process_done(Status::COMPILATION_FAILED); } } @@ -154,14 +159,14 @@ DisconnectAll::execute(RunContext& ctx) } if (_compiled_graph) { - _parent->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = _parent->swap_compiled_graph(std::move(_compiled_graph)); } } void DisconnectAll::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _engine.broadcaster()->message(_msg); } @@ -196,6 +201,4 @@ DisconnectAll::adjacent_arcs(GraphImpl* const graph) return arcs; } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/DisconnectAll.hpp b/src/server/events/DisconnectAll.hpp index 70da5dd6..0eeda6f8 100644 --- a/src/server/events/DisconnectAll.hpp +++ b/src/server/events/DisconnectAll.hpp @@ -21,8 +21,7 @@ #include "Event.hpp" #include "types.hpp" -#include "ingen/Message.hpp" -#include "raul/Maid.hpp" +#include <ingen/Message.hpp> #include <list> #include <memory> @@ -41,8 +40,6 @@ class CompiledGraph; class Engine; class GraphImpl; class PortImpl; -class PreProcessContext; -class RunContext; namespace events { @@ -79,7 +76,7 @@ private: BlockImpl* _block; PortImpl* _port; Impls _impls; - raul::managed_ptr<CompiledGraph> _compiled_graph; + std::unique_ptr<CompiledGraph> _compiled_graph; bool _deleting; }; diff --git a/src/server/events/Get.cpp b/src/server/events/Get.cpp index 219af6fe..45e7ea94 100644 --- a/src/server/events/Get.cpp +++ b/src/server/events/Get.cpp @@ -22,24 +22,24 @@ #include "GraphImpl.hpp" #include "PortImpl.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Node.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/paths.hpp" +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Node.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/paths.hpp> #include <cstdint> #include <memory> #include <mutex> +#include <utility> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { Get::Get(Engine& engine, const std::shared_ptr<Interface>& client, @@ -47,22 +47,24 @@ Get::Get(Engine& engine, const ingen::Get& msg) : Event(engine, client, msg.seq, timestamp) , _msg(msg) - , _object(nullptr) - , _plugin(nullptr) {} bool Get::pre_process(PreProcessContext&) { - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; const auto& uri = _msg.subject; if (uri == "ingen:/plugins") { _plugins = _engine.block_factory()->plugins(); return Event::pre_process_done(Status::SUCCESS); - } else if (uri == "ingen:/engine") { + } + + if (uri == "ingen:/engine") { return Event::pre_process_done(Status::SUCCESS); - } else if (uri_is_path(uri)) { + } + + if (uri_is_path(uri)) { if ((_object = _engine.store()->get(uri_to_path(uri)))) { const BlockImpl* block = nullptr; const GraphImpl* graph = nullptr; @@ -79,23 +81,24 @@ Get::pre_process(PreProcessContext&) return Event::pre_process_done(Status::SUCCESS); } return Event::pre_process_done(Status::NOT_FOUND, uri); - } else if ((_plugin = _engine.block_factory()->plugin(uri))) { + } + + if ((_plugin = _engine.block_factory()->plugin(uri))) { _response.put_plugin(_plugin); return Event::pre_process_done(Status::SUCCESS); - } else { - return Event::pre_process_done(Status::NOT_FOUND, uri); } + + return Event::pre_process_done(Status::NOT_FOUND, uri); } void Get::execute(RunContext&) -{ -} +{} void Get::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS && _request_client) { if (_msg.subject == "ingen:/plugins") { _engine.broadcaster()->send_plugins_to(_request_client.get(), _plugins); @@ -104,11 +107,11 @@ Get::post_process() URIs& uris = _engine.world().uris(); Properties props = { { uris.param_sampleRate, - uris.forge.make(int32_t(_engine.sample_rate())) }, + uris.forge.make(static_cast<int32_t>(_engine.sample_rate())) }, { uris.bufsz_maxBlockLength, - uris.forge.make(int32_t(_engine.block_length())) }, + uris.forge.make(static_cast<int32_t>(_engine.block_length())) }, { uris.ingen_numThreads, - uris.forge.make(int32_t(_engine.n_threads())) } }; + uris.forge.make(static_cast<int32_t>(_engine.n_threads())) } }; const Properties load_props = _engine.load_properties(); props.insert(load_props.begin(), load_props.end()); @@ -119,6 +122,4 @@ Get::post_process() } } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/Get.hpp b/src/server/events/Get.hpp index fd3f8569..0f5ed235 100644 --- a/src/server/events/Get.hpp +++ b/src/server/events/Get.hpp @@ -17,7 +17,7 @@ #ifndef INGEN_EVENTS_GET_HPP #define INGEN_EVENTS_GET_HPP -#include "ingen/Message.hpp" +#include <ingen/Message.hpp> #include "BlockFactory.hpp" #include "ClientUpdate.hpp" @@ -35,8 +35,6 @@ namespace server { class Engine; class PluginImpl; -class PreProcessContext; -class RunContext; namespace events { @@ -58,8 +56,8 @@ public: private: const ingen::Get _msg; - const Node* _object; - PluginImpl* _plugin; + const Node* _object{nullptr}; + PluginImpl* _plugin{nullptr}; BlockFactory::Plugins _plugins; ClientUpdate _response; }; diff --git a/src/server/events/Mark.cpp b/src/server/events/Mark.cpp index 27ca6630..b60b0432 100644 --- a/src/server/events/Mark.cpp +++ b/src/server/events/Mark.cpp @@ -14,10 +14,7 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "events/Mark.hpp" - -#include "ingen/Message.hpp" -#include "ingen/Status.hpp" +#include "Mark.hpp" #include "CompiledGraph.hpp" #include "Engine.hpp" @@ -25,14 +22,15 @@ #include "PreProcessContext.hpp" #include "UndoStack.hpp" +#include <ingen/Message.hpp> +#include <ingen/Status.hpp> + #include <cassert> #include <memory> #include <unordered_set> #include <utility> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { Mark::Mark(Engine& engine, const std::shared_ptr<Interface>& client, @@ -86,7 +84,7 @@ Mark::pre_process(PreProcessContext& ctx) ctx.set_in_bundle(false); if (!ctx.dirty_graphs().empty()) { for (GraphImpl* g : ctx.dirty_graphs()) { - auto cg = compile(*_engine.maid(), *g); + auto cg = compile(*g); if (cg) { _compiled_graphs.emplace(g, std::move(cg)); } @@ -103,7 +101,7 @@ void Mark::execute(RunContext&) { for (auto& g : _compiled_graphs) { - g.first->set_compiled_graph(std::move(g.second)); + g.second = g.first->swap_compiled_graph(std::move(g.second)); } } @@ -136,6 +134,4 @@ Mark::get_execution() const return Execution::NORMAL; } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/Mark.hpp b/src/server/events/Mark.hpp index 7ebab080..e7180764 100644 --- a/src/server/events/Mark.hpp +++ b/src/server/events/Mark.hpp @@ -17,11 +17,10 @@ #ifndef INGEN_EVENTS_MARK_HPP #define INGEN_EVENTS_MARK_HPP +#include "CompiledGraph.hpp" #include "Event.hpp" #include "types.hpp" -#include "raul/Maid.hpp" - #include <map> #include <memory> @@ -33,11 +32,8 @@ struct BundleEnd; namespace server { -class CompiledGraph; class Engine; class GraphImpl; -class PreProcessContext; -class RunContext; namespace events { @@ -73,8 +69,7 @@ public: private: enum class Type { BUNDLE_BEGIN, BUNDLE_END }; - using CompiledGraphs = - std::map<GraphImpl*, raul::managed_ptr<CompiledGraph>>; + using CompiledGraphs = std::map<GraphImpl*, std::unique_ptr<CompiledGraph>>; CompiledGraphs _compiled_graphs; Type _type; diff --git a/src/server/events/Move.cpp b/src/server/events/Move.cpp index d85451c8..80ae5a11 100644 --- a/src/server/events/Move.cpp +++ b/src/server/events/Move.cpp @@ -14,22 +14,23 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ +#include "Move.hpp" + #include "Broadcaster.hpp" #include "Driver.hpp" #include "Engine.hpp" -#include "events/Move.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Status.hpp" -#include "ingen/Store.hpp" -#include "raul/Path.hpp" +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Status.hpp> +#include <ingen/Store.hpp> +#include <raul/Path.hpp> #include <map> #include <memory> #include <mutex> -namespace ingen { -namespace server { +namespace ingen::server { class EnginePort; @@ -41,19 +42,18 @@ Move::Move(Engine& engine, const ingen::Move& msg) : Event(engine, client, msg.seq, timestamp) , _msg(msg) -{ -} +{} bool Move::pre_process(PreProcessContext&) { - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; if (!_msg.old_path.parent().is_parent_of(_msg.new_path)) { return Event::pre_process_done(Status::PARENT_DIFFERS, _msg.new_path); } - const Store::iterator i = _engine.store()->find(_msg.old_path); + const auto i = _engine.store()->find(_msg.old_path); if (i == _engine.store()->end()) { return Event::pre_process_done(Status::NOT_FOUND, _msg.old_path); } @@ -74,13 +74,12 @@ Move::pre_process(PreProcessContext&) void Move::execute(RunContext&) -{ -} +{} void Move::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _engine.broadcaster()->message(_msg); } @@ -93,5 +92,4 @@ Move::undo(Interface& target) } } // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/events/Move.hpp b/src/server/events/Move.hpp index 3940e825..cca4d310 100644 --- a/src/server/events/Move.hpp +++ b/src/server/events/Move.hpp @@ -20,7 +20,7 @@ #include "Event.hpp" #include "types.hpp" -#include "ingen/Message.hpp" +#include <ingen/Message.hpp> #include <memory> @@ -31,8 +31,6 @@ class Interface; namespace server { class Engine; -class PreProcessContext; -class RunContext; namespace events { diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index a1b5bafa..ba6859dd 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -24,18 +24,17 @@ #include "PortImpl.hpp" #include "RunContext.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Status.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/atom/atom.h" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Status.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/atom/atom.h> #include <cassert> #include <memory> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { /** Internal */ SetPortValue::SetPortValue(Engine& engine, @@ -51,13 +50,12 @@ SetPortValue::SetPortValue(Engine& engine, , _value(value) , _activity(activity) , _synthetic(synthetic) -{ -} +{} bool SetPortValue::pre_process(PreProcessContext&) { - ingen::URIs& uris = _engine.world().uris(); + const ingen::URIs& uris = _engine.world().uris(); if (_port->is_output()) { return Event::pre_process_done(Status::DIRECTION_MISMATCH, _port->path()); } @@ -95,8 +93,8 @@ SetPortValue::apply(RunContext& ctx) return; } - ingen::URIs& uris = _engine.world().uris(); - Buffer* buf = _port->buffer(0).get(); + const ingen::URIs& uris = _engine.world().uris(); + Buffer* buf = _port->buffer(0).get(); if (_buffer) { if (_port->user_buffer(ctx)) { @@ -130,7 +128,7 @@ SetPortValue::apply(RunContext& ctx) void SetPortValue::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS && !_activity) { _engine.broadcaster()->set_property( _port->uri(), @@ -139,6 +137,4 @@ SetPortValue::post_process() } } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/SetPortValue.hpp b/src/server/events/SetPortValue.hpp index 69d742b8..32a8b761 100644 --- a/src/server/events/SetPortValue.hpp +++ b/src/server/events/SetPortValue.hpp @@ -22,7 +22,7 @@ #include "Event.hpp" #include "types.hpp" -#include "ingen/Atom.hpp" +#include <ingen/Atom.hpp> #include <cstdint> #include <memory> @@ -35,7 +35,6 @@ namespace server { class Engine; class PortImpl; -class PreProcessContext; class RunContext; namespace events { diff --git a/src/server/events/Undo.cpp b/src/server/events/Undo.cpp index 3c91235d..db7c1c86 100644 --- a/src/server/events/Undo.cpp +++ b/src/server/events/Undo.cpp @@ -19,18 +19,16 @@ #include "Engine.hpp" #include "EventWriter.hpp" -#include "ingen/AtomReader.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Message.hpp" -#include "ingen/Status.hpp" -#include "lv2/atom/atom.h" +#include <ingen/AtomReader.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Message.hpp> +#include <ingen/Status.hpp> +#include <lv2/atom/atom.h> #include <deque> #include <memory> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { Undo::Undo(Engine& engine, const std::shared_ptr<Interface>& client, @@ -81,8 +79,7 @@ Undo::pre_process(PreProcessContext&) void Undo::execute(RunContext&) -{ -} +{} void Undo::post_process() @@ -90,6 +87,4 @@ Undo::post_process() respond(); } -} // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server::events diff --git a/src/server/events/Undo.hpp b/src/server/events/Undo.hpp index eb9cb70a..818dc754 100644 --- a/src/server/events/Undo.hpp +++ b/src/server/events/Undo.hpp @@ -32,8 +32,6 @@ struct Undo; namespace server { class Engine; -class PreProcessContext; -class RunContext; namespace events { diff --git a/src/server/ingen_engine.cpp b/src/server/ingen_engine.cpp index a5735f33..48955143 100644 --- a/src/server/ingen_engine.cpp +++ b/src/server/ingen_engine.cpp @@ -14,13 +14,11 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -// IWYU pragma: no_include "ingen/Atom.hpp" - #include "Engine.hpp" #include "util.hpp" -#include "ingen/Module.hpp" -#include "ingen/World.hpp" +#include <ingen/Module.hpp> +#include <ingen/World.hpp> #include <memory> @@ -41,7 +39,7 @@ struct EngineModule : public Module { extern "C" { -ingen::Module* +INGEN_MODULE_EXPORT ingen::Module* ingen_module_load() { return new ingen::EngineModule(); diff --git a/src/server/ingen_jack.cpp b/src/server/ingen_jack.cpp index 97d72919..16369d0c 100644 --- a/src/server/ingen_jack.cpp +++ b/src/server/ingen_jack.cpp @@ -17,17 +17,16 @@ #include "Engine.hpp" #include "JackDriver.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/Log.hpp" -#include "ingen/Module.hpp" -#include "ingen/World.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/Log.hpp> +#include <ingen/Module.hpp> +#include <ingen/World.hpp> #include <memory> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { class Driver; @@ -53,12 +52,11 @@ struct JackModule : public Module { } }; -} // namespace server -} // namespace ingen +} // namespace ingen::server extern "C" { -ingen::Module* +INGEN_MODULE_EXPORT ingen::Module* ingen_module_load() { return new ingen::server::JackModule(); diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 90b9d944..658f759b 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -15,7 +15,6 @@ */ #include "Buffer.hpp" -#include "BufferRef.hpp" #include "Driver.hpp" #include "DuplexPort.hpp" #include "Engine.hpp" @@ -26,46 +25,47 @@ #include "ThreadManager.hpp" #include "types.hpp" -#include "ingen/AtomReader.hpp" -#include "ingen/AtomSink.hpp" -#include "ingen/AtomWriter.hpp" -#include "ingen/Configuration.hpp" -#include "ingen/EngineBase.hpp" -#include "ingen/FilePath.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Log.hpp" -#include "ingen/Node.hpp" -#include "ingen/Parser.hpp" -#include "ingen/Serialiser.hpp" -#include "ingen/Store.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/ingen.h" -#include "ingen/memory.hpp" -#include "ingen/runtime_paths.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/buf-size/buf-size.h" -#include "lv2/core/lv2.h" -#include "lv2/log/log.h" -#include "lv2/log/logger.h" -#include "lv2/options/options.h" -#include "lv2/state/state.h" -#include "lv2/urid/urid.h" -#include "raul/Maid.hpp" -#include "raul/Path.hpp" -#include "raul/RingBuffer.hpp" -#include "raul/Semaphore.hpp" -#include "raul/Symbol.hpp" -#include "serd/serd.h" -#include "sord/sordmm.hpp" +#include <ingen/AtomReader.hpp> +#include <ingen/AtomSink.hpp> +#include <ingen/AtomWriter.hpp> +#include <ingen/Configuration.hpp> +#include <ingen/EngineBase.hpp> +#include <ingen/FilePath.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Log.hpp> +#include <ingen/Node.hpp> +#include <ingen/Parser.hpp> +#include <ingen/Serialiser.hpp> +#include <ingen/Store.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/ingen.h> +#include <ingen/memory.hpp> +#include <ingen/runtime_paths.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/buf-size/buf-size.h> +#include <lv2/core/lv2.h> +#include <lv2/log/log.h> +#include <lv2/log/logger.h> +#include <lv2/options/options.h> +#include <lv2/state/state.h> +#include <lv2/urid/urid.h> +#include <raul/Maid.hpp> +#include <raul/Path.hpp> +#include <raul/RingBuffer.hpp> +#include <raul/Semaphore.hpp> +#include <raul/Symbol.hpp> +#include <serd/serd.h> +#include <sord/sordmm.hpp> #include <algorithm> #include <cstdint> #include <cstdlib> #include <cstring> +#include <iterator> #include <memory> #include <mutex> #include <set> @@ -74,11 +74,9 @@ #include <utility> #include <vector> -namespace ingen { +// #define CLEAR_GRAPH_ON_RESTORE 1 -class Atom; - -namespace server { +namespace ingen::server { class GraphImpl; @@ -90,7 +88,8 @@ struct LV2Graph : public Parser::ResourceRecord { }; /** Ingen LV2 library. */ -class Lib { +class Lib +{ public: explicit Lib(const char* bundle_path); @@ -99,19 +98,23 @@ public: Graphs graphs; }; +namespace { + inline size_t ui_ring_size(SampleCount block_length) { - return std::max(static_cast<size_t>(8192u), - static_cast<size_t>(block_length) * 16u); + return std::max(static_cast<size_t>(8192U), + static_cast<size_t>(block_length) * 16U); } +} // namespace + class LV2Driver : public Driver, public ingen::AtomSink { public: LV2Driver(Engine& engine, SampleCount block_length, - size_t seq_size, + uint32_t seq_size, SampleCount sample_rate) : _engine(engine) , _main_sem(0) @@ -124,15 +127,9 @@ public: *this) , _from_ui(ui_ring_size(block_length)) , _to_ui(ui_ring_size(block_length)) - , _root_graph(nullptr) - , _notify_capacity(0) , _block_length(block_length) , _seq_size(seq_size) , _sample_rate(sample_rate) - , _frame_time(0) - , _to_ui_overflow_sem(0) - , _to_ui_overflow(false) - , _instantiated(false) {} bool dynamic_ports() const override { return !_instantiated; } @@ -151,11 +148,11 @@ public: lv2_atom_total_size( static_cast<LV2_Atom*>(lv2_buf))); - if (graph_port->symbol() == "control") { // TODO: Safe to use index? + if (graph_port->symbol() == "control") { // TODO: Safe to use index? auto* seq = reinterpret_cast<LV2_Atom_Sequence*>(lv2_buf); bool enqueued = false; - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (AtomReader::is_message(uris, &ev->body)) { enqueued = enqueue_message(&ev->body) || enqueued; @@ -220,13 +217,12 @@ public: virtual GraphImpl* root_graph() { return _root_graph; } EnginePort* get_port(const raul::Path& path) override { - for (auto& p : _ports) { - if (p->graph_port()->path() == path) { - return p; - } - } + const auto i = + std::find_if(_ports.begin(), _ports.end(), [&path](const auto& p) { + return p->graph_port()->path() == path; + }); - return nullptr; + return i == _ports.end() ? nullptr : *i; } /** Add a port. Called only during init or restore. */ @@ -268,7 +264,7 @@ public: const URIs& uris = _engine.world().uris(); auto* seq = static_cast<LV2_Atom_Sequence*>(_ports[0]->buffer()); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (ev->body.type == uris.atom_Object) { const LV2_Atom_Object* obj = reinterpret_cast<LV2_Atom_Object*>(&ev->body); @@ -322,7 +318,13 @@ public: break; } - buf = realloc(buf, sizeof(LV2_Atom) + atom.size); + void* const new_buf = realloc(buf, sizeof(LV2_Atom) + atom.size); + if (!new_buf) { + _engine.log().rt_error("Failed to allocate for from-UI ring\n"); + break; + } + + buf = new_buf; memcpy(buf, &atom, sizeof(LV2_Atom)); if (!_from_ui.read(atom.size, @@ -365,14 +367,14 @@ public: if (seq->atom.size + lv2_atom_pad_size( sizeof(LV2_Atom_Event) + atom.size) > _notify_capacity) { - break; // Output port buffer full, resume next time + break; // Output port buffer full, resume next time } auto* ev = reinterpret_cast<LV2_Atom_Event*>( reinterpret_cast<uint8_t*>(seq) + lv2_atom_total_size(&seq->atom)); - ev->time.frames = 0; // TODO: Time? + ev->time.frames = 0; // TODO: Time? ev->body = atom; _to_ui.skip(sizeof(LV2_Atom)); @@ -392,7 +394,7 @@ public: } SampleCount block_length() const override { return _block_length; } - size_t seq_size() const override { return _seq_size; } + uint32_t seq_size() const override { return _seq_size; } SampleCount sample_rate() const override { return _sample_rate; } SampleCount frame_time() const override { return _frame_time; } @@ -413,15 +415,15 @@ private: AtomWriter _writer; raul::RingBuffer _from_ui; raul::RingBuffer _to_ui; - GraphImpl* _root_graph; - uint32_t _notify_capacity; + GraphImpl* _root_graph{nullptr}; + uint32_t _notify_capacity{0}; SampleCount _block_length; - size_t _seq_size; + uint32_t _seq_size; SampleCount _sample_rate; - SampleCount _frame_time; - raul::Semaphore _to_ui_overflow_sem; - bool _to_ui_overflow; - bool _instantiated; + SampleCount _frame_time{0}; + raul::Semaphore _to_ui_overflow_sem{0}; + bool _to_ui_overflow{false}; + bool _instantiated{false}; }; struct IngenPlugin { @@ -465,9 +467,10 @@ find_graphs(const URI& manifest_uri) URI(INGEN__Graph)); Lib::Graphs graphs; - for (const auto& r : resources) { - graphs.push_back(std::make_shared<LV2Graph>(r)); - } + std::transform(resources.begin(), + resources.end(), + std::back_inserter(graphs), + [](const auto& r) { return std::make_shared<LV2Graph>(r); }); return graphs; } @@ -501,7 +504,9 @@ ingen_instantiate(const LV2_Descriptor* descriptor, if (!map) { lv2_log_error(&logger, "host did not provide URI map feature\n"); return nullptr; - } else if (!unmap) { + } + + if (!unmap) { lv2_log_error(&logger, "host did not provide URI unmap feature\n"); return nullptr; } @@ -515,16 +520,16 @@ ingen_instantiate(const LV2_Descriptor* descriptor, nullptr, true); - Lib::Graphs graphs = find_graphs(URI(reinterpret_cast<const char*>(manifest_node.buf))); + const Lib::Graphs graphs = find_graphs(URI(reinterpret_cast<const char*>(manifest_node.buf))); serd_node_free(&manifest_node); - const LV2Graph* graph = nullptr; - for (const auto& g : graphs) { - if (g->uri == descriptor->URI) { - graph = g.get(); - break; - } - } + const auto g = std::find_if(graphs.begin(), + graphs.end(), + [&descriptor](const auto& graph) { + return graph->uri == descriptor->URI; + }); + + const LV2Graph* const graph = g == graphs.end() ? nullptr : g->get(); if (!graph) { lv2_log_error(&logger, "could not find graph <%s>\n", descriptor->URI); @@ -536,11 +541,11 @@ ingen_instantiate(const LV2_Descriptor* descriptor, plugin->world = std::make_unique<ingen::World>(map, unmap, log); plugin->world->load_configuration(plugin->argc, plugin->argv); - LV2_URID bufsz_max = map->map(map->handle, LV2_BUF_SIZE__maxBlockLength); - LV2_URID bufsz_seq = map->map(map->handle, LV2_BUF_SIZE__sequenceSize); - LV2_URID atom_Int = map->map(map->handle, LV2_ATOM__Int); - int32_t block_length = 0; - int32_t seq_size = 0; + const LV2_URID bufsz_max = map->map(map->handle, LV2_BUF_SIZE__maxBlockLength); + const LV2_URID bufsz_seq = map->map(map->handle, LV2_BUF_SIZE__sequenceSize); + const LV2_URID atom_Int = map->map(map->handle, LV2_ATOM__Int); + int32_t block_length = 0; + int32_t seq_size = 0; if (options) { for (const LV2_Options_Option* o = options; o->key; ++o) { if (o->key == bufsz_max && o->type == atom_Int) { @@ -554,7 +559,7 @@ ingen_instantiate(const LV2_Descriptor* descriptor, block_length = 4096; plugin->world->log().warn("No maximum block length given\n"); } - if (seq_size == 0) { + if (seq_size < 1) { seq_size = 16384; plugin->world->log().warn("No maximum sequence size given\n"); } @@ -570,20 +575,21 @@ ingen_instantiate(const LV2_Descriptor* descriptor, plugin->engine = engine; plugin->world->set_engine(engine); - std::shared_ptr<Interface> interface = engine->interface(); + const std::shared_ptr<Interface> interface = engine->interface(); plugin->world->set_interface(interface); ThreadManager::set_flag(THREAD_PRE_PROCESS); ThreadManager::single_threaded = true; - auto* driver = new LV2Driver(*engine, block_length, seq_size, rate); + auto* driver = new LV2Driver( + *engine, block_length, static_cast<uint32_t>(seq_size), rate); engine->set_driver(std::shared_ptr<Driver>(driver)); engine->activate(); ThreadManager::single_threaded = true; - std::lock_guard<std::mutex> lock(plugin->world->rdf_mutex()); + const std::lock_guard<std::mutex> lock{plugin->world->rdf_mutex()}; // Locate to time 0 to process initialization events engine->locate(0, block_length); @@ -605,7 +611,7 @@ ingen_instantiate(const LV2_Descriptor* descriptor, /* Register client after loading graph so the to-ui ring does not overflow. Since we are not yet rolling, it won't be drained, causing a deadlock. */ - std::shared_ptr<Interface> client(&driver->writer(), NullDeleter<Interface>); + const std::shared_ptr<Interface> client{&driver->writer(), NullDeleter<Interface>}; interface->set_respondee(client); engine->register_client(client); @@ -616,8 +622,8 @@ ingen_instantiate(const LV2_Descriptor* descriptor, static void ingen_connect_port(LV2_Handle instance, uint32_t port, void* data) { - auto* me = static_cast<IngenPlugin*>(instance); - Engine* engine = static_cast<Engine*>(me->world->engine().get()); + auto* me = static_cast<IngenPlugin*>(instance); + const Engine* engine = static_cast<Engine*>(me->world->engine().get()); const auto driver = std::static_pointer_cast<LV2Driver>(engine->driver()); if (port < driver->ports().size()) { driver->ports().at(port)->set_buffer(data); @@ -673,6 +679,7 @@ ingen_cleanup(LV2_Handle instance) auto world = std::move(me->world); delete me; + world.reset(); } static void @@ -706,9 +713,9 @@ ingen_save(LV2_Handle instance, return LV2_STATE_ERR_NO_FEATURE; } - LV2_URID ingen_file = plugin->map->map(plugin->map->handle, INGEN__file); - LV2_URID atom_Path = plugin->map->map(plugin->map->handle, - LV2_ATOM__Path); + const LV2_URID ingen_file = plugin->map->map(plugin->map->handle, INGEN__file); + const LV2_URID atom_Path = plugin->map->map(plugin->map->handle, + LV2_ATOM__Path); char* real_path = make_path->path(make_path->handle, "main.ttl"); char* state_path = map_path->abstract_path(map_path->handle, real_path); @@ -716,7 +723,7 @@ ingen_save(LV2_Handle instance, auto root = plugin->world->store()->find(raul::Path("/")); { - std::lock_guard<std::mutex> lock(plugin->world->rdf_mutex()); + const std::lock_guard<std::mutex> lock{plugin->world->rdf_mutex()}; plugin->world->serialiser()->start_to_file( root->second->path(), FilePath{real_path}); @@ -752,10 +759,10 @@ ingen_restore(LV2_Handle instance, return LV2_STATE_ERR_NO_FEATURE; } - LV2_URID ingen_file = plugin->map->map(plugin->map->handle, INGEN__file); - size_t size = 0; - uint32_t type = 0; - uint32_t valflags = 0; + const LV2_URID ingen_file = plugin->map->map(plugin->map->handle, INGEN__file); + size_t size = 0; + uint32_t type = 0; + uint32_t valflags = 0; // Get abstract path to graph file const char* path = static_cast<const char*>( @@ -770,7 +777,7 @@ ingen_restore(LV2_Handle instance, return LV2_STATE_ERR_UNKNOWN; } -#if 0 +#ifdef CLEAR_GRAPH_ON_RESTORE // Remove existing root graph contents std::shared_ptr<Engine> engine = plugin->engine; for (const auto& b : engine->root_graph()->blocks()) { @@ -787,7 +794,7 @@ ingen_restore(LV2_Handle instance, #endif // Load new graph - std::lock_guard<std::mutex> lock(plugin->world->rdf_mutex()); + const std::lock_guard<std::mutex> lock{plugin->world->rdf_mutex()}; plugin->world->parser()->parse_file( *plugin->world, *plugin->world->interface(), real_path); @@ -850,8 +857,8 @@ lib_get_plugin(LV2_Lib_Handle handle, uint32_t index) } } // extern "C" -} // namespace server -} // namespace ingen + +} // namespace ingen::server extern "C" { diff --git a/src/server/ingen_portaudio.cpp b/src/server/ingen_portaudio.cpp index 991470e4..68b1b0bc 100644 --- a/src/server/ingen_portaudio.cpp +++ b/src/server/ingen_portaudio.cpp @@ -14,19 +14,16 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -// IWYU pragma: no_include "ingen/FilePath.hpp" - -#include "PortAudioDriver.hpp" #include "Engine.hpp" +#include "PortAudioDriver.hpp" -#include "ingen/Log.hpp" -#include "ingen/Module.hpp" -#include "ingen/World.hpp" +#include <ingen/Log.hpp> +#include <ingen/Module.hpp> +#include <ingen/World.hpp> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { class Driver; @@ -46,12 +43,11 @@ struct PortAudioModule : public Module { } }; -} // namespace server -} // namespace ingen +} // namespace ingen::server extern "C" { -ingen::Module* +INGEN_MODULE_EXPORT ingen::Module* ingen_module_load() { return new ingen::server::PortAudioModule(); diff --git a/src/server/internals/BlockDelay.cpp b/src/server/internals/BlockDelay.cpp index 68252fe4..acc68851 100644 --- a/src/server/internals/BlockDelay.cpp +++ b/src/server/internals/BlockDelay.cpp @@ -14,7 +14,7 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "internals/BlockDelay.hpp" +#include "BlockDelay.hpp" #include "BlockImpl.hpp" #include "Buffer.hpp" @@ -24,21 +24,16 @@ #include "OutputPort.hpp" #include "PortType.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Forge.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Symbol.hpp> #include <memory> -namespace ingen { -namespace server { - -class RunContext; - -namespace internals { +namespace ingen::server::internals { InternalPlugin* BlockDelayNode::internal_plugin(URIs& uris) { return new InternalPlugin( @@ -91,6 +86,4 @@ BlockDelayNode::run(RunContext& ctx) _buffer->copy(ctx, _in_port->buffer(0).get()); } -} // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server::internals diff --git a/src/server/internals/BlockDelay.hpp b/src/server/internals/BlockDelay.hpp index 78a03c28..a9667fa0 100644 --- a/src/server/internals/BlockDelay.hpp +++ b/src/server/internals/BlockDelay.hpp @@ -36,7 +36,6 @@ class GraphImpl; class InputPort; class InternalPlugin; class OutputPort; -class RunContext; namespace internals { diff --git a/src/server/internals/Controller.cpp b/src/server/internals/Controller.cpp index d0d8cd39..9103649e 100644 --- a/src/server/internals/Controller.cpp +++ b/src/server/internals/Controller.cpp @@ -14,7 +14,8 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "BlockImpl.hpp" +#include "Controller.hpp" + #include "Buffer.hpp" #include "BufferFactory.hpp" #include "BufferRef.hpp" @@ -24,25 +25,23 @@ #include "PortType.hpp" #include "RunContext.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "internals/Controller.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/midi/midi.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/midi/midi.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Symbol.hpp> #include <cassert> #include <cmath> #include <initializer_list> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { class GraphImpl; @@ -60,7 +59,6 @@ ControllerNode::ControllerNode(InternalPlugin* plugin, GraphImpl* parent, SampleRate srate) : InternalBlock(plugin, symbol, false, parent, srate) - , _learning(false) { const ingen::URIs& uris = bufs.uris(); _ports = bufs.maid().make_managed<Ports>(7); @@ -125,7 +123,7 @@ ControllerNode::run(RunContext& ctx) auto* seq = midi_in->get<LV2_Atom_Sequence>(); const BufferRef midi_out = _midi_out_port->buffer(0); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body)); if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && ev->body.size >= 3 && @@ -174,7 +172,7 @@ ControllerNode::control(RunContext& ctx, uint8_t control_num, uint8_t val, Frame } const Sample min = logf(min_port_val + 1 + log_offset); const Sample max = logf(max_port_val + 1 + log_offset); - scaled_value = expf(nval * (max - min) + min) - 1 - log_offset; + scaled_value = expf((nval * (max - min)) + min) - 1 - log_offset; } else { scaled_value = ((nval) * (max_port_val - min_port_val)) + min_port_val; } @@ -185,5 +183,4 @@ ControllerNode::control(RunContext& ctx, uint8_t control_num, uint8_t val, Frame } } // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/internals/Controller.hpp b/src/server/internals/Controller.hpp index b5cea110..2a0bc834 100644 --- a/src/server/internals/Controller.hpp +++ b/src/server/internals/Controller.hpp @@ -74,7 +74,7 @@ private: InputPort* _min_port; InputPort* _max_port; OutputPort* _audio_port; - bool _learning; + bool _learning{false}; }; } // namespace internals diff --git a/src/server/internals/Note.cpp b/src/server/internals/Note.cpp index 4952310b..960bca85 100644 --- a/src/server/internals/Note.cpp +++ b/src/server/internals/Note.cpp @@ -14,28 +14,27 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "internals/Note.hpp" +#include "Note.hpp" #include "BlockImpl.hpp" #include "Buffer.hpp" #include "BufferFactory.hpp" -#include "BufferRef.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #include "OutputPort.hpp" #include "PortType.hpp" #include "RunContext.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/midi/midi.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/midi/midi.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Symbol.hpp> #include <cassert> #include <cmath> @@ -44,8 +43,7 @@ // #define NOTE_DEBUG 1 -namespace ingen { -namespace server { +namespace ingen::server { class GraphImpl; @@ -64,7 +62,6 @@ NoteNode::NoteNode(InternalPlugin* plugin, SampleRate srate) : InternalBlock(plugin, symbol, polyphonic, parent, srate) , _voices(bufs.maid().make_managed<Voices>(_polyphony)) - , _sustain(false) { const ingen::URIs& uris = bufs.uris(); _ports = bufs.maid().make_managed<Ports>(8); @@ -179,7 +176,7 @@ NoteNode::run(RunContext& ctx) Buffer* const midi_in = _midi_in_port->buffer(0).get(); auto* seq = midi_in->get<LV2_Atom_Sequence>(); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body)); @@ -360,7 +357,7 @@ NoteNode::free_voice(RunContext& ctx, uint32_t voice, FrameTime time) } } - if (replace_key != nullptr) { // Found a key to assign to freed voice + if (replace_key != nullptr) { // Found a key to assign to freed voice assert(&_keys[replace_key_num] == replace_key); assert(replace_key->state == Key::State::ON_UNASSIGNED); @@ -437,5 +434,4 @@ NoteNode::channel_pressure(RunContext& ctx, FrameTime time, float amount) } } // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/internals/Note.hpp b/src/server/internals/Note.hpp index 80816131..2cf6c1e2 100644 --- a/src/server/internals/Note.hpp +++ b/src/server/internals/Note.hpp @@ -20,8 +20,8 @@ #include "InternalBlock.hpp" #include "types.hpp" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" +#include <raul/Array.hpp> +#include <raul/Maid.hpp> #include <cstdint> @@ -105,7 +105,7 @@ private: raul::managed_ptr<Voices> _prepared_voices; Key _keys[128]; - bool _sustain; ///< Whether or not hold pedal is depressed + bool _sustain{false}; ///< Whether or not hold pedal is depressed InputPort* _midi_in_port; OutputPort* _freq_port; diff --git a/src/server/internals/Time.cpp b/src/server/internals/Time.cpp index 651a2f36..2ea09b0b 100644 --- a/src/server/internals/Time.cpp +++ b/src/server/internals/Time.cpp @@ -14,9 +14,8 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "internals/Time.hpp" +#include "Time.hpp" -#include "BlockImpl.hpp" #include "Buffer.hpp" #include "BufferFactory.hpp" #include "BufferRef.hpp" @@ -27,19 +26,18 @@ #include "PortType.hpp" #include "RunContext.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "lv2/atom/atom.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <lv2/atom/atom.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Symbol.hpp> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { class GraphImpl; @@ -73,8 +71,8 @@ TimeNode::TimeNode(InternalPlugin* plugin, void TimeNode::run(RunContext& ctx) { - BufferRef buf = _notify_port->buffer(0); - auto* seq = buf->get<LV2_Atom_Sequence>(); + const BufferRef buf = _notify_port->buffer(0); + auto* const seq = buf->get<LV2_Atom_Sequence>(); // Initialise output to the empty sequence seq->atom.type = _notify_port->bufs().uris().atom_Sequence; @@ -87,5 +85,4 @@ TimeNode::run(RunContext& ctx) } } // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/internals/Time.hpp b/src/server/internals/Time.hpp index fa3e90e5..228e67a8 100644 --- a/src/server/internals/Time.hpp +++ b/src/server/internals/Time.hpp @@ -34,7 +34,6 @@ class BufferFactory; class GraphImpl; class InternalPlugin; class OutputPort; -class RunContext; namespace internals { diff --git a/src/server/internals/Trigger.cpp b/src/server/internals/Trigger.cpp index 645ffabb..f033a345 100644 --- a/src/server/internals/Trigger.cpp +++ b/src/server/internals/Trigger.cpp @@ -14,9 +14,8 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "internals/Trigger.hpp" +#include "Trigger.hpp" -#include "BlockImpl.hpp" #include "Buffer.hpp" #include "BufferFactory.hpp" #include "BufferRef.hpp" @@ -26,23 +25,22 @@ #include "PortType.hpp" #include "RunContext.hpp" -#include "ingen/Atom.hpp" -#include "ingen/Forge.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIs.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/midi/midi.h" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Symbol.hpp" +#include <ingen/Atom.hpp> +#include <ingen/Forge.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIs.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <lv2/midi/midi.h> +#include <raul/Array.hpp> +#include <raul/Maid.hpp> +#include <raul/Symbol.hpp> #include <cassert> #include <cmath> #include <memory> -namespace ingen { -namespace server { +namespace ingen::server { class GraphImpl; @@ -60,7 +58,6 @@ TriggerNode::TriggerNode(InternalPlugin* plugin, GraphImpl* parent, SampleRate srate) : InternalBlock(plugin, symbol, false, parent, srate) - , _learning(false) { const ingen::URIs& uris = bufs.uris(); _ports = bufs.maid().make_managed<Ports>(6); @@ -124,7 +121,7 @@ TriggerNode::run(RunContext& ctx) // Initialise output to the empty sequence midi_out->prepare_write(ctx); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { const int64_t t = ev->time.frames; const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body)); @@ -199,5 +196,4 @@ TriggerNode::note_off(RunContext& ctx, uint8_t note_num, FrameTime time) } } // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/internals/Trigger.hpp b/src/server/internals/Trigger.hpp index d9553c3e..74634202 100644 --- a/src/server/internals/Trigger.hpp +++ b/src/server/internals/Trigger.hpp @@ -71,7 +71,7 @@ public: static InternalPlugin* internal_plugin(URIs& uris); private: - bool _learning; + bool _learning{false}; InputPort* _midi_in_port; OutputPort* _midi_out_port; diff --git a/src/server/meson.build b/src/server/meson.build new file mode 100644 index 00000000..c1fccf5e --- /dev/null +++ b/src/server/meson.build @@ -0,0 +1,135 @@ +# Copyright 2022 David Robillard <d@drobilla.net> +# SPDX-License-Identifier: 0BSD OR GPL-3.0-or-later + +########## +# Module # +########## + +server_sources = files( + 'events/Connect.cpp', + 'events/Copy.cpp', + 'events/CreateBlock.cpp', + 'events/CreateGraph.cpp', + 'events/CreatePort.cpp', + 'events/Delete.cpp', + 'events/Delta.cpp', + 'events/Disconnect.cpp', + 'events/DisconnectAll.cpp', + 'events/Get.cpp', + 'events/Mark.cpp', + 'events/Move.cpp', + 'events/SetPortValue.cpp', + 'events/Undo.cpp', + 'internals/BlockDelay.cpp', + 'internals/Controller.cpp', + 'internals/Note.cpp', + 'internals/Time.cpp', + 'internals/Trigger.cpp', + 'ArcImpl.cpp', + 'BlockFactory.cpp', + 'BlockImpl.cpp', + 'Broadcaster.cpp', + 'Buffer.cpp', + 'BufferFactory.cpp', + 'ClientUpdate.cpp', + 'CompiledGraph.cpp', + 'ControlBindings.cpp', + 'DuplexPort.cpp', + 'Engine.cpp', + 'EventWriter.cpp', + 'GraphImpl.cpp', + 'InputPort.cpp', + 'InternalBlock.cpp', + 'InternalPlugin.cpp', + 'LV2Block.cpp', + 'LV2Plugin.cpp', + 'NodeImpl.cpp', + 'PortImpl.cpp', + 'PostProcessor.cpp', + 'PreProcessor.cpp', + 'RunContext.cpp', + 'SocketListener.cpp', + 'Task.cpp', + 'UndoStack.cpp', + 'Worker.cpp', + 'ingen_engine.cpp', + 'mix.cpp', +) + +server_dependencies = [ + boost_dep, + ingen_dep, + lilv_dep, + raul_dep, + serd_dep, + sord_dep, + sratom_dep, + thread_dep, +] + +server_include_dirs = include_directories( + '.', + '../../include', + '../include', +) + +libingen_server = shared_library( + 'ingen_server', + server_sources, + cpp_args: cpp_suppressions + platform_defines + ['-DINGEN_SERVER_INTERNAL'], + dependencies: server_dependencies, + gnu_symbol_visibility: 'hidden', + implicit_include_directories: false, + include_directories: server_include_dirs, + install: true, + install_dir: ingen_module_dir, +) + +ingen_server_dep = declare_dependency( + dependencies: server_dependencies, + link_with: libingen_server, +) + +########### +# Drivers # +########### + +if jack_dep.found() + shared_module( + 'ingen_jack', + files('JackDriver.cpp', 'ingen_jack.cpp'), + cpp_args: cpp_suppressions + platform_defines, + dependencies: [ingen_server_dep, jack_dep], + gnu_symbol_visibility: 'hidden', + implicit_include_directories: false, + include_directories: ingen_include_dirs, + install: true, + install_dir: ingen_module_dir, + ) +endif + +if portaudio_dep.found() + shared_module( + 'ingen_portaudio', + files('PortAudioDriver.cpp', 'ingen_portaudio.cpp'), + cpp_args: cpp_suppressions + platform_defines, + dependencies: [ingen_server_dep, portaudio_dep], + gnu_symbol_visibility: 'hidden', + implicit_include_directories: false, + include_directories: ingen_include_dirs, + install: true, + install_dir: ingen_module_dir, + ) +endif + +shared_module( + 'ingen_lv2', + files('ingen_lv2.cpp'), + cpp_args: cpp_suppressions + platform_defines, + dependencies: [ingen_server_dep, lv2_dep], + gnu_symbol_visibility: 'hidden', + implicit_include_directories: false, + include_directories: ingen_include_dirs, + install: true, + install_dir: lv2dir / 'ingen.lv2', +) diff --git a/src/server/mix.cpp b/src/server/mix.cpp index a1e0c276..32500f97 100644 --- a/src/server/mix.cpp +++ b/src/server/mix.cpp @@ -20,11 +20,10 @@ #include "RunContext.hpp" #include "types.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> -namespace ingen { -namespace server { +namespace ingen::server { static inline bool is_end(const Buffer* buf, const LV2_Atom_Event* ev) @@ -59,15 +58,15 @@ mix(const RunContext& ctx, const SampleCount end = ctx.nframes(); for (uint32_t i = 1; i < num_srcs; ++i) { const Sample* __restrict const in = srcs[i]->samples(); - if (srcs[i]->is_control()) { // control => audio + if (srcs[i]->is_control()) { // control => audio for (SampleCount j = 0; j < end; ++j) { out[j] += in[0]; } - } else if (srcs[i]->is_audio()) { // audio => audio + } else if (srcs[i]->is_audio()) { // audio => audio for (SampleCount j = 0; j < end; ++j) { out[j] += in[j]; } - } else if (srcs[i]->is_sequence()) { // sequence => audio + } else if (srcs[i]->is_sequence()) { // sequence => audio dst->render_sequence(ctx, srcs[i], true); } } @@ -111,5 +110,4 @@ mix(const RunContext& ctx, } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/mix.hpp b/src/server/mix.hpp index 75e139d3..11a9a1d2 100644 --- a/src/server/mix.hpp +++ b/src/server/mix.hpp @@ -19,8 +19,7 @@ #include <cstdint> -namespace ingen { -namespace server { +namespace ingen::server { class Buffer; class RunContext; @@ -31,7 +30,6 @@ mix(const RunContext& ctx, const Buffer*const* srcs, uint32_t num_srcs); -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_MIX_HPP diff --git a/src/server/server.h b/src/server/server.h new file mode 100644 index 00000000..d4ca5155 --- /dev/null +++ b/src/server/server.h @@ -0,0 +1,31 @@ +/* + This file is part of Ingen. + Copyright 2014-2022 David Robillard <http://drobilla.net/> + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or any later version. + + Ingen is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef INGEN_SERVER_SERVER_H +#define INGEN_SERVER_SERVER_H + +#if defined(_WIN32) && !defined(INGEN_SERVER_STATIC) && \ + defined(INGEN_SERVER_INTERNAL) +# define INGEN_SERVER_API __declspec(dllexport) +#elif defined(_WIN32) && !defined(INGEN_SERVER_STATIC) +# define INGEN_SERVER_API __declspec(dllimport) +#elif defined(__GNUC__) +# define INGEN_SERVER_API __attribute__((visibility("default"))) +#else +# define INGEN_SERVER_API +#endif + +#endif // INGEN_SERVER_SERVER_H diff --git a/src/server/util.hpp b/src/server/util.hpp index 3c8d2058..abfa06b6 100644 --- a/src/server/util.hpp +++ b/src/server/util.hpp @@ -17,10 +17,10 @@ #ifndef INGEN_ENGINE_UTIL_HPP #define INGEN_ENGINE_UTIL_HPP -#include "ingen/Log.hpp" +#include <ingen/Log.hpp> #ifdef __SSE__ -#include <xmmintrin.h> // IWYU pragma: keep +#include <xmmintrin.h> #endif #ifdef __clang__ @@ -29,8 +29,7 @@ # define REALTIME #endif -namespace ingen { -namespace server { +namespace ingen::server { /** Set flags to disable denormal processing. */ @@ -43,7 +42,6 @@ set_denormal_flags(ingen::Log& log) #endif } -} // namespace server -} // namespace ingen +} // namespace ingen::server #endif // INGEN_ENGINE_UTIL_HPP diff --git a/src/server/wscript b/src/server/wscript deleted file mode 100644 index 5fdf4583..00000000 --- a/src/server/wscript +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python - - -def build(bld): - core_source = ''' - ArcImpl.cpp - BlockFactory.cpp - BlockImpl.cpp - Broadcaster.cpp - Buffer.cpp - BufferFactory.cpp - CompiledGraph.cpp - ClientUpdate.cpp - ControlBindings.cpp - DuplexPort.cpp - Engine.cpp - EventWriter.cpp - GraphImpl.cpp - InputPort.cpp - InternalBlock.cpp - InternalPlugin.cpp - LV2Block.cpp - LV2Plugin.cpp - NodeImpl.cpp - PortImpl.cpp - PostProcessor.cpp - PreProcessor.cpp - RunContext.cpp - SocketListener.cpp - Task.cpp - UndoStack.cpp - Worker.cpp - events/Connect.cpp - events/Copy.cpp - events/CreateBlock.cpp - events/CreateGraph.cpp - events/CreatePort.cpp - events/Delete.cpp - events/Delta.cpp - events/Disconnect.cpp - events/DisconnectAll.cpp - events/Get.cpp - events/Mark.cpp - events/Move.cpp - events/SetPortValue.cpp - events/Undo.cpp - ingen_engine.cpp - internals/BlockDelay.cpp - internals/Controller.cpp - internals/Note.cpp - internals/Time.cpp - internals/Trigger.cpp - mix.cpp - ''' - - core_libs = 'LV2 LILV RAUL SERD SORD SRATOM' - - bld(features = 'cxx cxxshlib', - source = core_source, - export_includes = ['../../include'], - includes = ['.', '../..', '../../include'], - name = 'libingen_server', - target = 'ingen_server', - install_path = '${LIBDIR}', - use = 'libingen libingen_socket', - uselib = core_libs, - cxxflags = bld.env.PTHREAD_CFLAGS + bld.env.INGEN_TEST_CXXFLAGS, - linkflags = bld.env.PTHREAD_LINKFLAGS + bld.env.INGEN_TEST_LINKFLAGS) - - if bld.env.HAVE_JACK: - bld(features = 'cxx cxxshlib', - source = 'JackDriver.cpp ingen_jack.cpp', - includes = ['.', '../../', '../../include'], - name = 'libingen_jack', - target = 'ingen_jack', - install_path = '${LIBDIR}', - use = 'libingen_server', - uselib = core_libs + ' JACK', - cxxflags = ['-fvisibility=hidden'] + bld.env.PTHREAD_CFLAGS, - linkflags = bld.env.PTHREAD_LINKFLAGS) - - if bld.env.HAVE_PORTAUDIO: - bld(features = 'cxx cxxshlib', - source = 'PortAudioDriver.cpp ingen_portaudio.cpp', - includes = ['.', '../../', '../../include'], - name = 'libingen_portaudio', - target = 'ingen_portaudio', - install_path = '${LIBDIR}', - use = 'libingen_server', - uselib = core_libs + ' PORTAUDIO', - cxxflags = ['-fvisibility=hidden'] + bld.env.PTHREAD_CFLAGS, - linkflags = bld.env.PTHREAD_LINKFLAGS) - - # Ingen LV2 wrapper - if bld.env.INGEN_BUILD_LV2: - bld(features = 'cxx cxxshlib', - source = ' ingen_lv2.cpp ', - cflags = ['-fvisibility=hidden'], - includes = ['../../', '../../include'], - name = 'libingen_lv2', - target = 'ingen_lv2', - install_path = '${LV2DIR}/ingen.lv2/', - use = 'libingen libingen_server', - uselib = core_libs, - cxxflags = ['-fvisibility=hidden'] + bld.env.PTHREAD_CFLAGS, - linkflags = bld.env.PTHREAD_LINKFLAGS) |