diff options
Diffstat (limited to 'src/server')
124 files changed, 3853 insertions, 3135 deletions
diff --git a/src/server/.clang-tidy b/src/server/.clang-tidy new file mode 100644 index 00000000..8bb1a979 --- /dev/null +++ b/src/server/.clang-tidy @@ -0,0 +1,24 @@ +Checks: > + -*-avoid-c-arrays, + -*-narrowing-conversions, + -*-non-private-member-variables-in-classes, + -*-uppercase-literal-suffix, + -*-vararg, + -bugprone-branch-clone, + -bugprone-parent-virtual-call, + -bugprone-reserved-identifier, + -bugprone-suspicious-realloc-usage, + -bugprone-suspicious-string-compare, + -cert-dcl37-c, + -cert-dcl51-cpp, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-type-cstyle-cast, + -cppcoreguidelines-pro-type-static-cast-downcast, + -google-readability-todo, + -google-runtime-int, + -google-runtime-references, + -hicpp-multiway-paths-covered, + -llvm-header-guard, + -misc-redundant-expression, + -portability-simd-intrinsics, +InheritParentConfig: true diff --git a/src/server/ArcImpl.cpp b/src/server/ArcImpl.cpp index d9a2b783..0b503534 100644 --- a/src/server/ArcImpl.cpp +++ b/src/server/ArcImpl.cpp @@ -29,8 +29,7 @@ #include <cassert> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { /** Constructor for an arc from a block's output port. * @@ -55,13 +54,13 @@ ArcImpl::~ArcImpl() } } -const Raul::Path& +const raul::Path& ArcImpl::tail_path() const { return _tail->path(); } -const Raul::Path& +const raul::Path& ArcImpl::head_path() const { return _head->path(); @@ -113,5 +112,4 @@ ArcImpl::can_connect(const PortImpl* src, const InputPort* dst) || (src->supports(uris.atom_Sound) && dst->is_a(PortType::ID::AUDIO))); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/ArcImpl.hpp b/src/server/ArcImpl.hpp index 1f42d3a5..b1565390 100644 --- a/src/server/ArcImpl.hpp +++ b/src/server/ArcImpl.hpp @@ -21,14 +21,18 @@ #include "ingen/Arc.hpp" #include "raul/Noncopyable.hpp" -#include "raul/Path.hpp" #include <boost/intrusive/slist_hook.hpp> #include <cstdint> -namespace ingen { -namespace server { +// IWYU pragma: no_include "raul/Path.hpp" + +namespace raul { +class Path; // IWYU pragma: keep +} // namespace raul + +namespace ingen::server { class InputPort; class PortImpl; @@ -47,19 +51,19 @@ class RunContext; * \ingroup engine */ class ArcImpl - : private Raul::Noncopyable + : private raul::Noncopyable , public Arc , public boost::intrusive::slist_base_hook<> { public: ArcImpl(PortImpl* tail, PortImpl* head); - ~ArcImpl(); + ~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; + const raul::Path& tail_path() const override; + const raul::Path& head_path() const override; /** Get the buffer for a particular voice. * An Arc is smart - it knows the destination port requesting the @@ -78,7 +82,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 9e1693df..4c8dd1d7 100644 --- a/src/server/BlockFactory.cpp +++ b/src/server/BlockFactory.cpp @@ -35,17 +35,15 @@ #include <algorithm> #include <cstdint> +#include <iterator> +#include <memory> #include <utility> #include <vector> -namespace ingen { -namespace server { - -using namespace internals; +namespace ingen::server { BlockFactory::BlockFactory(ingen::World& world) : _world(world) - , _has_loaded(false) { load_internal_plugins(); } @@ -61,12 +59,12 @@ BlockFactory::plugins() return _plugins; } -std::set<SPtr<PluginImpl>> +std::set<std::shared_ptr<PluginImpl>> BlockFactory::refresh() { // Record current plugins, and those that are currently zombies - const Plugins old_plugins(_plugins); - std::set<SPtr<PluginImpl>> zombies; + const Plugins old_plugins(_plugins); + std::set<std::shared_ptr<PluginImpl>> zombies; for (const auto& p : _plugins) { if (p.second->is_zombie()) { zombies.insert(p.second); @@ -77,7 +75,7 @@ BlockFactory::refresh() load_lv2_plugins(); // Add any new plugins to response - std::set<SPtr<PluginImpl>> new_plugins; + std::set<std::shared_ptr<PluginImpl>> new_plugins; for (const auto& p : _plugins) { auto o = old_plugins.find(p.first); if (o == old_plugins.end()) { @@ -86,11 +84,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; } @@ -99,7 +96,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); } @@ -107,20 +104,23 @@ void BlockFactory::load_internal_plugins() { ingen::URIs& uris = _world.uris(); - InternalPlugin* block_delay_plug = BlockDelayNode::internal_plugin(uris); - _plugins.emplace(block_delay_plug->uri(), block_delay_plug); - InternalPlugin* controller_plug = ControllerNode::internal_plugin(uris); - _plugins.emplace(controller_plug->uri(), controller_plug); + InternalPlugin* block_delay = + internals::BlockDelayNode::internal_plugin(uris); + _plugins.emplace(block_delay->uri(), block_delay); + + InternalPlugin* controller = + internals::ControllerNode::internal_plugin(uris); + _plugins.emplace(controller->uri(), controller); - InternalPlugin* note_plug = NoteNode::internal_plugin(uris); - _plugins.emplace(note_plug->uri(), note_plug); + InternalPlugin* note = internals::NoteNode::internal_plugin(uris); + _plugins.emplace(note->uri(), note); - InternalPlugin* time_plug = TimeNode::internal_plugin(uris); - _plugins.emplace(time_plug->uri(), time_plug); + InternalPlugin* time = internals::TimeNode::internal_plugin(uris); + _plugins.emplace(time->uri(), time); - InternalPlugin* trigger_plug = TriggerNode::internal_plugin(uris); - _plugins.emplace(trigger_plug->uri(), trigger_plug); + InternalPlugin* trigger = internals::TriggerNode::internal_plugin(uris); + _plugins.emplace(trigger->uri(), trigger); } void @@ -146,24 +146,23 @@ void BlockFactory::load_lv2_plugins() { // Build an array of port type nodes for checking compatibility - using Types = std::vector<SPtr<LilvNode>>; + 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((PortType::ID)t).uri()); - types.push_back( - SPtr<LilvNode>(lilv_new_uri(_world.lilv_world(), uri.c_str()), - lilv_node_free)); + const URI uri{PortType(static_cast<PortType::ID>(t)).uri()}; + 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; @@ -221,5 +220,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 234a20fa..17c11bb4 100644 --- a/src/server/BlockFactory.hpp +++ b/src/server/BlockFactory.hpp @@ -18,10 +18,10 @@ #define INGEN_ENGINE_BLOCKFACTORY_HPP #include "ingen/URI.hpp" -#include "ingen/types.hpp" #include "raul/Noncopyable.hpp" #include <map> +#include <memory> #include <set> namespace ingen { @@ -36,7 +36,7 @@ class PluginImpl; * * \ingroup engine */ -class BlockFactory : public Raul::Noncopyable +class BlockFactory : public raul::Noncopyable { public: explicit BlockFactory(ingen::World& world); @@ -47,11 +47,11 @@ public: * * @return The set of newly loaded plugins. */ - std::set<SPtr<PluginImpl>> refresh(); + std::set<std::shared_ptr<PluginImpl>> refresh(); void load_plugin(const URI& uri); - using Plugins = std::map<URI, SPtr<PluginImpl>>; + using Plugins = std::map<URI, std::shared_ptr<PluginImpl>>; const Plugins& plugins(); PluginImpl* plugin(const URI& uri); @@ -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 ba0bdc77..d4285832 100644 --- a/src/server/BlockImpl.cpp +++ b/src/server/BlockImpl.cpp @@ -23,6 +23,7 @@ #include "RunContext.hpp" #include "ThreadManager.hpp" +#include "lv2/urid/urid.h" #include "raul/Array.hpp" #include "raul/Maid.hpp" #include "raul/Symbol.hpp" @@ -32,21 +33,17 @@ #include <initializer_list> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { BlockImpl::BlockImpl(PluginImpl* plugin, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate) : 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); @@ -57,7 +54,7 @@ BlockImpl::~BlockImpl() assert(!_activated); if (is_linked()) { - ((GraphImpl*)_parent)->remove_block(*this); + reinterpret_cast<GraphImpl*>(_parent)->remove_block(*this); } } @@ -120,7 +117,7 @@ BlockImpl::prepare_poly(BufferFactory& bufs, uint32_t poly) } bool -BlockImpl::apply_poly(RunContext& context, uint32_t poly) +BlockImpl::apply_poly(RunContext& ctx, uint32_t poly) { if (!_polyphonic) { poly = 1; @@ -130,7 +127,7 @@ BlockImpl::apply_poly(RunContext& context, uint32_t poly) if (_ports) { for (uint32_t i = 0; i < num_ports(); ++i) { - _ports->at(i)->apply_poly(context, poly); + _ports->at(i)->apply_poly(ctx, poly); } } @@ -138,7 +135,7 @@ BlockImpl::apply_poly(RunContext& context, uint32_t poly) } void -BlockImpl::set_buffer_size(RunContext& context, +BlockImpl::set_buffer_size(RunContext& ctx, BufferFactory& bufs, LV2_URID type, uint32_t size) @@ -147,7 +144,7 @@ BlockImpl::set_buffer_size(RunContext& context, for (uint32_t i = 0; i < _ports->size(); ++i) { PortImpl* const p = _ports->at(i); if (p->buffer_type() == type) { - p->set_buffer_size(context, bufs, size); + p->set_buffer_size(ctx, bufs, size); } } } @@ -180,18 +177,18 @@ BlockImpl::port_by_symbol(const char* symbol) } void -BlockImpl::pre_process(RunContext& context) +BlockImpl::pre_process(RunContext& ctx) { // Mix down input ports for (uint32_t i = 0; i < num_ports(); ++i) { PortImpl* const port = _ports->at(i); - port->pre_process(context); + port->pre_process(ctx); port->connect_buffers(); } } void -BlockImpl::bypass(RunContext& context) +BlockImpl::bypass(RunContext& ctx) { if (!_ports) { return; @@ -200,20 +197,22 @@ BlockImpl::bypass(RunContext& context) // Prepare port buffers for reading, converting/mixing if necessary for (uint32_t i = 0; i < _ports->size(); ++i) { _ports->at(i)->connect_buffers(); - _ports->at(i)->pre_run(context); + _ports->at(i)->pre_run(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); 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(context, in->buffer(v).get()); + out->buffer(v)->copy(ctx, in->buffer(v).get()); } } else { // Output but no corresponding input, clear @@ -223,29 +222,29 @@ BlockImpl::bypass(RunContext& context) } } } - post_process(context); + post_process(ctx); } void -BlockImpl::process(RunContext& context) +BlockImpl::process(RunContext& ctx) { - pre_process(context); + pre_process(ctx); if (!_enabled) { - bypass(context); - post_process(context); + bypass(ctx); + post_process(ctx); return; } - RunContext subcontext(context); - for (SampleCount offset = 0; offset < context.nframes();) { + RunContext subcontext(ctx); + for (SampleCount offset = 0; offset < ctx.nframes();) { // Find earliest offset of a value change - SampleCount chunk_end = context.nframes(); + SampleCount chunk_end = ctx.nframes(); for (uint32_t i = 0; _ports && i < _ports->size(); ++i) { PortImpl* const port = _ports->at(i); if (port->type() == PortType::CONTROL && port->is_input()) { const SampleCount o = port->next_value_offset( - offset, context.nframes()); + offset, ctx.nframes()); if (o < chunk_end) { chunk_end = o; } @@ -279,15 +278,15 @@ BlockImpl::process(RunContext& context) subcontext.slice(offset, chunk_end - offset); } - post_process(context); + post_process(ctx); } void -BlockImpl::post_process(RunContext& context) +BlockImpl::post_process(RunContext& ctx) { // Write output ports for (uint32_t i = 0; _ports && i < _ports->size(); ++i) { - _ports->at(i)->post_process(context); + _ports->at(i)->post_process(ctx); } } @@ -298,5 +297,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 15a4e075..ef76e9bf 100644 --- a/src/server/BlockImpl.hpp +++ b/src/server/BlockImpl.hpp @@ -20,27 +20,31 @@ #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 <boost/intrusive/slist_hook.hpp> -#include <boost/optional/optional.hpp> #include <cstdint> +#include <memory> +#include <optional> #include <set> -namespace Raul { +namespace raul { class Symbol; -} +} // namespace raul namespace ingen { +class Node; + namespace server { class BufferFactory; @@ -59,18 +63,18 @@ 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*>; + using Ports = raul::Array<PortImpl*>; BlockImpl(PluginImpl* plugin, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate rate); - virtual ~BlockImpl(); + ~BlockImpl() override; GraphType graph_type() const override { return GraphType::BLOCK; } @@ -91,7 +95,7 @@ public: /** Duplicate this Node. */ virtual BlockImpl* duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent) { return nullptr; } /** Return true iff this block is activated */ @@ -104,33 +108,37 @@ public: void set_enabled(bool e) { _enabled = e; } /** Load a preset from the world for this block. */ - virtual LilvState* load_preset(const URI& uri) { return nullptr; } + virtual StatePtr load_preset(const URI& uri) { return {}; } /** Restore `state`. */ - virtual void apply_state(const UPtr<Worker>& worker, const LilvState* state) {} + virtual void + apply_state(const std::unique_ptr<Worker>& worker, const LilvState* state) + {} /** 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 */ - virtual void pre_process(RunContext& context); + virtual void pre_process(RunContext& ctx); /** Run block for an entire process cycle (calls run()). */ - virtual void process(RunContext& context); + virtual void process(RunContext& ctx); /** Bypass block for an entire process cycle (called from process()). */ - virtual void bypass(RunContext& context); + virtual void bypass(RunContext& ctx); /** Run block for a portion of process cycle (called from process()). */ - virtual void run(RunContext& context) = 0; + virtual void run(RunContext& ctx) = 0; /** Do whatever needs doing in the process thread after process() is called */ - virtual void post_process(RunContext& context); + virtual void post_process(RunContext& ctx); /** Set the buffer of a port to a given buffer (e.g. connect plugin to buffer) */ virtual void set_port_buffer(uint32_t voice, @@ -145,10 +153,12 @@ public: virtual PortImpl* port_by_symbol(const char* symbol); /** Blocks that are connected to this Block's inputs. */ - std::set<BlockImpl*>& providers() { return _providers; } + std::set<BlockImpl*>& providers() { return _providers; } + const std::set<BlockImpl*>& providers() const { return _providers; } /** Blocks that are connected to this Block's outputs. */ - std::set<BlockImpl*>& dependants() { return _dependants; } + std::set<BlockImpl*>& dependants() { return _dependants; } + const std::set<BlockImpl*>& dependants() const { return _dependants; } /** Flag block as polyphonic. * @@ -159,7 +169,7 @@ public: virtual void set_polyphonic(bool p) { _polyphonic = p; } bool prepare_poly(BufferFactory& bufs, uint32_t poly) override; - bool apply_poly(RunContext& context, uint32_t poly) override; + bool apply_poly(RunContext& ctx, uint32_t poly) override; /** Information about the Plugin this Block is an instance of. * Not the best name - not all blocks come from plugins (ie Graph) @@ -173,13 +183,16 @@ public: virtual void plugin(PluginImpl* pi) { _plugin = pi; } - virtual void set_buffer_size(RunContext& context, + virtual void set_buffer_size(RunContext& ctx, BufferFactory& bufs, LV2_URID type, uint32_t size); /** The Graph this Block belongs to. */ - GraphImpl* parent_graph() const override { return (GraphImpl*)_parent; } + GraphImpl* parent_graph() const override + { + return reinterpret_cast<GraphImpl*>(_parent); + } uint32_t num_ports() const override { return _ports ? _ports->size() : 0; } @@ -193,15 +206,15 @@ public: protected: PortImpl* nth_port_by_type(uint32_t n, bool input, PortType type); - PluginImpl* _plugin; - MPtr<Ports> _ports; ///< Access in audio thread only - 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 - bool _polyphonic; - bool _activated; - bool _enabled; + PluginImpl* _plugin; + raul::managed_ptr<Ports> _ports; ///< Access in audio thread only + 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::UNVISITED}; ///< Mark for graph walks + bool _polyphonic; + bool _activated{false}; + bool _enabled{true}; }; } // namespace server diff --git a/src/server/Broadcaster.cpp b/src/server/Broadcaster.cpp index 914b891b..e7406dc6 100644 --- a/src/server/Broadcaster.cpp +++ b/src/server/Broadcaster.cpp @@ -22,19 +22,14 @@ #include "ingen/Interface.hpp" #include <cstddef> +#include <memory> #include <utility> -namespace ingen { -namespace server { - -Broadcaster::Broadcaster() - : _must_broadcast(false) - , _bundle_depth(0) -{} +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(); } @@ -42,9 +37,9 @@ Broadcaster::~Broadcaster() /** Register a client to receive messages over the notification band. */ void -Broadcaster::register_client(const SPtr<Interface>& client) +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); } @@ -53,16 +48,17 @@ Broadcaster::register_client(const SPtr<Interface>& client) * @return true if client was found and removed. */ bool -Broadcaster::unregister_client(const SPtr<Interface>& client) +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); } void -Broadcaster::set_broadcast(const SPtr<Interface>& client, bool broadcast) +Broadcaster::set_broadcast(const std::shared_ptr<Interface>& client, + bool broadcast) { if (broadcast) { _broadcastees.insert(client); @@ -75,7 +71,7 @@ Broadcaster::set_broadcast(const SPtr<Interface>& client, bool broadcast) 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); } @@ -95,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 d8857356..9bae44b1 100644 --- a/src/server/Broadcaster.hpp +++ b/src/server/Broadcaster.hpp @@ -22,15 +22,14 @@ #include "ingen/Interface.hpp" #include "ingen/Message.hpp" #include "ingen/URI.hpp" -#include "ingen/types.hpp" #include "raul/Noncopyable.hpp" #include <atomic> +#include <memory> #include <mutex> #include <set> -namespace ingen { -namespace server { +namespace ingen::server { /** Broadcaster for all clients. * @@ -42,20 +41,21 @@ namespace server { class Broadcaster : public Interface { public: - Broadcaster(); - ~Broadcaster(); + Broadcaster() = default; + ~Broadcaster() override; - void register_client(const SPtr<Interface>& client); - bool unregister_client(const SPtr<Interface>& client); + void register_client(const std::shared_ptr<Interface>& client); + bool unregister_client(const std::shared_ptr<Interface>& client); - void set_broadcast(const SPtr<Interface>& client, bool broadcast); + void + set_broadcast(const std::shared_ptr<Interface>& client, bool broadcast); /** Ignore a client when broadcasting. * * This is used to prevent feeding back updates to the client that * initiated a property set in the first place. */ - void set_ignore_client(const SPtr<Interface>& client) + void set_ignore_client(const std::shared_ptr<Interface>& client) { _ignore_client = client; } @@ -75,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) { @@ -96,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); @@ -109,17 +110,16 @@ public: private: friend class Transfer; - using Clients = std::set<SPtr<Interface>>; + using Clients = std::set<std::shared_ptr<Interface>>; - std::mutex _clients_mutex; - Clients _clients; - std::set< SPtr<Interface> > _broadcastees; - std::atomic<bool> _must_broadcast; - unsigned _bundle_depth; - SPtr<Interface> _ignore_client; + std::mutex _clients_mutex; + Clients _clients; + std::set<std::shared_ptr<Interface>> _broadcastees; + std::atomic<bool> _must_broadcast{false}; + unsigned _bundle_depth{0}; + 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 fffc86b0..394d3323 100644 --- a/src/server/Buffer.cpp +++ b/src/server/Buffer.cpp @@ -14,24 +14,22 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#define __STDC_LIMIT_MACROS 1 - #include "Buffer.hpp" #include "BufferFactory.hpp" #include "Engine.hpp" #include "RunContext.hpp" +#include "ingen_config.h" #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 <algorithm> #include <cstdint> -#include <cstdio> #include <cstdlib> #include <cstring> #include <new> @@ -40,8 +38,7 @@ # include <xmmintrin.h> #endif -namespace ingen { -namespace server { +namespace ingen::server { Buffer::Buffer(BufferFactory& bufs, LV2_URID type, @@ -50,13 +47,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) { @@ -102,12 +96,12 @@ Buffer::recycle() } void -Buffer::set_type(GetFn get, LV2_URID type, LV2_URID value_type) +Buffer::set_type(GetFn get_func, LV2_URID type, LV2_URID value_type) { _type = type; _value_type = value_type; if (type == _factory.uris().atom_Sequence && value_type) { - _value_buffer = (_factory.*get)(value_type, 0, 0); + _value_buffer = (_factory.*get_func)(value_type, 0, 0); } } @@ -129,30 +123,32 @@ Buffer::clear() } void -Buffer::render_sequence(const RunContext& context, const Buffer* src, bool add) +Buffer::render_sequence(const RunContext& ctx, const Buffer* src, bool add) { const LV2_URID atom_Float = _factory.uris().atom_Float; const auto* seq = src->get<const LV2_Atom_Sequence>(); - const auto* init = (const LV2_Atom_Float*)src->value(); + const auto* init = reinterpret_cast<const LV2_Atom_Float*>(src->value()); float value = init ? init->body : 0.0f; - SampleCount offset = context.offset(); + 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 = ((const LV2_Atom_Float*)&ev->body)->body; + value = reinterpret_cast<const LV2_Atom_Float*>(&ev->body)->body; offset = ev->time.frames; } } - write_block(value, offset, context.offset() + context.nframes(), add); + write_block(value, offset, ctx.offset() + ctx.nframes(), add); } void -Buffer::copy(const RunContext& context, const Buffer* src) +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); @@ -162,10 +158,10 @@ Buffer::copy(const RunContext& context, const Buffer* src) } else if (src->is_audio() && is_control()) { samples()[0] = src->samples()[0]; } else if (src->is_control() && is_audio()) { - set_block(src->samples()[0], 0, context.nframes()); + set_block(src->samples()[0], 0, ctx.nframes()); } else if (src->is_sequence() && is_audio() && src->value_type() == _factory.uris().atom_Float) { - render_sequence(context, src, false); + render_sequence(ctx, src, false); } else { clear(); } @@ -194,14 +190,16 @@ Buffer::port_data(PortType port_type, SampleCount offset) if (_type == _factory.uris().atom_Float) { return &get<LV2_Atom_Float>()->body; } else if (_type == _factory.uris().atom_Sound) { - return (Sample*)_buf + offset; + return static_cast<Sample*>(_buf) + offset; } break; case PortType::ID::ATOM: if (_type != _factory.uris().atom_Sound) { return _buf; } - default: break; + break; + default: + break; } return nullptr; } @@ -218,18 +216,18 @@ 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 float -Buffer::peak(const RunContext& context) const +Buffer::peak(const RunContext& ctx) const { #ifdef __SSE__ - const auto* const vbuf = (const __m128*)samples(); + const auto* const vbuf = reinterpret_cast<const __m128*>(samples()); __m128 vpeak = mm_abs_ps(vbuf[0]); - const SampleCount nblocks = context.nframes() / 4; + const SampleCount nblocks = ctx.nframes() / 4; // First, find the vector absolute max of the buffer for (SampleCount i = 1; i < nblocks; ++i) { @@ -252,14 +250,14 @@ Buffer::peak(const RunContext& context) const vpeak = _mm_max_ps(vpeak, tmp); // peak = vpeak[0] - float peak; + float peak = 0.0f; _mm_store_ss(&peak, vpeak); return peak; #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; @@ -272,7 +270,7 @@ Buffer::prepare_write(RunContext&) if (_type == _factory.uris().atom_Sequence) { auto* atom = get<LV2_Atom>(); - atom->type = (LV2_URID)_factory.uris().atom_Sequence; + atom->type = static_cast<LV2_URID>(_factory.uris().atom_Sequence); atom->size = sizeof(LV2_Atom_Sequence_Body); _latest_event = 0; } @@ -284,7 +282,7 @@ Buffer::prepare_output_write(RunContext&) if (_type == _factory.uris().atom_Sequence) { auto* atom = get<LV2_Atom>(); - atom->type = (LV2_URID)_factory.uris().atom_Chunk; + atom->type = static_cast<LV2_URID>(_factory.uris().atom_Chunk); atom->size = _capacity - sizeof(LV2_Atom); _latest_event = 0; } @@ -300,16 +298,16 @@ 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) { return false; } - auto* seq = (LV2_Atom_Sequence*)atom; - auto* ev = (LV2_Atom_Event*)( - (uint8_t*)seq + lv2_atom_total_size(&seq->atom)); + auto* seq = reinterpret_cast<LV2_Atom_Sequence*>(atom); + auto* ev = reinterpret_cast<LV2_Atom_Event*>( + reinterpret_cast<uint8_t*>(seq) + lv2_atom_total_size(&seq->atom)); ev->time.frames = frames; ev->body.size = size; @@ -326,23 +324,28 @@ Buffer::append_event(int64_t frames, bool Buffer::append_event(int64_t frames, const LV2_Atom* body) { - return append_event(frames, body->size, body->type, (const uint8_t*)(body + 1)); + return append_event(frames, + body->size, + body->type, + reinterpret_cast<const uint8_t*>(body + 1)); } bool Buffer::append_event_buffer(const Buffer* buf) { - auto* seq = (LV2_Atom_Sequence*)get<LV2_Atom>(); - auto* bseq = (LV2_Atom_Sequence*)buf->get<LV2_Atom>(); + auto* seq = reinterpret_cast<LV2_Atom_Sequence*>(get<LV2_Atom>()); + const auto* bseq = + 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 = (uint8_t*)seq + total_size; + 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); @@ -358,7 +361,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) { @@ -411,10 +414,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; } } @@ -426,27 +431,11 @@ Buffer::update_value_buffer(SampleCount offset) } } -#ifndef NDEBUG -void -Buffer::dump_cv(const RunContext& context) const -{ - float value = samples()[0]; - fprintf(stderr, "{ 0000: %.02f\n", value); - for (uint32_t i = 0; i < context.nframes(); ++i) { - if (samples()[i] != value) { - value = samples()[i]; - fprintf(stderr, " %4d: %.02f\n", i, value); - } - } - fprintf(stderr, "}\n"); -} -#endif - void* Buffer::aligned_alloc(size_t size) { -#ifdef HAVE_POSIX_MEMALIGN - void* buf; - if (!posix_memalign((void**)&buf, 16, size)) { +#if USE_POSIX_MEMALIGN + void* buf = nullptr; + if (!posix_memalign(static_cast<void**>(&buf), 16, size)) { memset(buf, 0, size); return buf; } @@ -468,5 +457,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 c67f9fd7..8a64e621 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -20,11 +20,10 @@ #include "BufferFactory.hpp" #include "BufferRef.hpp" #include "PortType.hpp" +#include "server.h" #include "types.hpp" #include "ingen/URIs.hpp" -#include "ingen/ingen.h" -#include "ingen/types.hpp" #include "lv2/atom/atom.h" #include "lv2/urid/urid.h" @@ -41,7 +40,7 @@ namespace server { class RunContext; -class INGEN_API Buffer +class INGEN_SERVER_API Buffer { public: Buffer(BufferFactory& bufs, @@ -56,74 +55,83 @@ public: void clear(); void resize(uint32_t capacity); - void copy(const RunContext& context, const Buffer* src); - void prepare_write(RunContext& context); + void copy(const RunContext& ctx, const Buffer* src); + void prepare_write(RunContext& ctx); 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; } - typedef BufferRef (BufferFactory::*GetFn)(LV2_URID, LV2_URID, uint32_t); + using GetFn = BufferRef (BufferFactory::*)(LV2_URID, LV2_URID, uint32_t); /** Set the buffer type and optional value type for this buffer. * - * @param get Called to get auxiliary buffers if necessary. + * @param get_func Called to get auxiliary buffers if necessary. * @param type Type of buffer. * @param value_type Type of values in buffer if applicable (for sequences). */ - void set_type(GetFn get, LV2_URID type, LV2_URID value_type); + 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 (const Sample*)LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>()); - } else if (is_audio()) { - return (const Sample*)_buf; + return static_cast<const Sample*>( + LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>())); } + + if (is_audio()) { + return static_cast<const Sample*>(_buf); + } + return nullptr; } /// Audio buffers only - inline Sample* samples() { + Sample* samples() { if (is_control()) { - return (Sample*)LV2_ATOM_BODY(get<LV2_Atom_Float>()); - } else if (is_audio()) { - return (Sample*)_buf; + return static_cast<Sample*>(LV2_ATOM_BODY(get<LV2_Atom_Float>())); } + + 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) { - return ((LV2_Atom_Float*)value())->body; } + + 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 +150,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 +162,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); @@ -168,10 +175,10 @@ public: } /// Audio buffers only - float peak(const RunContext& context) const; + float peak(const RunContext& ctx) const; /// Sequence buffers only - void prepare_output_write(RunContext& context); + void prepare_output_write(RunContext& ctx); /// Sequence buffers only bool append_event(int64_t frames, @@ -201,11 +208,7 @@ public: void update_value_buffer(SampleCount offset); /// Set/add to audio buffer from the Sequence of Float in `src` - void render_sequence(const RunContext& context, const Buffer* src, bool add); - -#ifndef NDEBUG - void dump_cv(const RunContext& context) const; -#endif + void render_sequence(const RunContext& ctx, const Buffer* src, bool add); void set_capacity(uint32_t capacity) { _capacity = capacity; } @@ -216,9 +219,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(); } @@ -230,15 +233,18 @@ private: void recycle(); - BufferFactory& _factory; - Buffer* _next; ///< Intrusive linked list for BufferFactory + BufferFactory& _factory; + + // NOLINTNEXTLINE(clang-analyzer-webkit.NoUncountedMemberChecker) + 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 23b44884..1afbf93f 100644 --- a/src/server/BufferFactory.cpp +++ b/src/server/BufferFactory.cpp @@ -26,9 +26,9 @@ #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) @@ -37,18 +37,20 @@ BufferFactory::BufferFactory(Engine& engine, URIs& uris) , _free_object(nullptr) , _engine(engine) , _uris(uris) - , _seq_size(0) , _silent_buffer(nullptr) -{ -} +{} BufferFactory::~BufferFactory() { _silent_buffer.reset(); - free_list(_free_audio.load()); - free_list(_free_control.load()); - free_list(_free_sequence.load()); - free_list(_free_object.load()); + + // Run twice to delete value buffer references which are dropped + for (unsigned i = 0; i < 2; ++i) { + free_list(_free_audio.exchange(nullptr)); + free_list(_free_control.exchange(nullptr)); + free_list(_free_sequence.exchange(nullptr)); + free_list(_free_object.exchange(nullptr)); + } } Forge& @@ -57,7 +59,7 @@ BufferFactory::forge() return _engine.world().forge(); } -Raul::Maid& +raul::Maid& BufferFactory::maid() { return *_engine.maid(); @@ -96,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 (type == _uris.atom_Sequence) { if (_seq_size == 0) { return _engine.sequence_size(); - } else { - return _seq_size; } - } else { - return 0; + + return _seq_size; } + + return 0; } Buffer* @@ -116,7 +124,7 @@ BufferFactory::try_get_buffer(LV2_URID type) { std::atomic<Buffer*>& head_ptr = free_list(type); Buffer* head = nullptr; - Buffer* next; + Buffer* next = nullptr; do { head = head_ptr.load(); if (!head) { @@ -141,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 @@ -150,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 @@ -170,24 +178,24 @@ BufferFactory::create(LV2_URID type, LV2_URID value_type, uint32_t capacity) if (capacity == 0) { capacity = default_size(type); } else if (type == _uris.atom_Float) { - capacity = std::max(capacity, (uint32_t)sizeof(LV2_Atom_Float)); + capacity = + std::max(capacity, static_cast<uint32_t>(sizeof(LV2_Atom_Float))); } else if (type == _uris.atom_Sound) { 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 BufferFactory::recycle(Buffer* buf) { std::atomic<Buffer*>& head_ptr = free_list(buf->type()); - Buffer* try_head; + Buffer* try_head = nullptr; do { try_head = head_ptr.load(); buf->_next = try_head; } 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 03a85d1c..657ce7d2 100644 --- a/src/server/BufferFactory.hpp +++ b/src/server/BufferFactory.hpp @@ -18,17 +18,19 @@ #define INGEN_ENGINE_BUFFERFACTORY_HPP #include "ingen/URIs.hpp" -#include "ingen/ingen.h" #include "lv2/urid/urid.h" +#include "server.h" #include "BufferRef.hpp" #include "types.hpp" #include <atomic> -#include <mutex> #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(); @@ -71,7 +74,7 @@ public: void set_seq_size(uint32_t seq_size) { _seq_size = seq_size; } Forge& forge(); - Raul::Maid& maid(); + raul::Maid& maid(); URIs& uris() { return _uris; } Engine& engine() { return _engine; } @@ -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{0}; BufferRef _silent_buffer; }; diff --git a/src/server/BufferRef.hpp b/src/server/BufferRef.hpp index 64eab668..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/intrusive_ptr.hpp> +#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 26f45ef1..c69f5b49 100644 --- a/src/server/ClientUpdate.cpp +++ b/src/server/ClientUpdate.cpp @@ -24,20 +24,20 @@ #include "PortType.hpp" #include "ingen/Arc.hpp" -#include "ingen/Atom.hpp" #include "ingen/Forge.hpp" #include "ingen/Interface.hpp" -#include "ingen/Node.hpp" #include "ingen/URIs.hpp" -#include "ingen/types.hpp" + +#include <boost/intrusive/slist.hpp> #include <algorithm> #include <cstddef> #include <cstdint> +#include <map> +#include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { void ClientUpdate::put(const URI& uri, @@ -69,7 +69,7 @@ ClientUpdate::put_block(const BlockImpl* block) const URIs& uris = plugin->uris(); if (uris.ingen_Graph == plugin->type()) { - put_graph((const GraphImpl*)block); + put_graph(static_cast<const GraphImpl*>(block)); } else { put(block->uri(), block->properties()); for (size_t j = 0; j < block->num_ports(); ++j) { @@ -101,8 +101,8 @@ ClientUpdate::put_graph(const GraphImpl* graph) // Enqueue arcs for (const auto& a : graph->arcs()) { - const SPtr<const Arc> arc = a.second; - const Connect connect = { arc->tail_path(), arc->head_path() }; + const auto arc = a.second; + const Connect connect = {arc->tail_path(), arc->head_path()}; connects.push_back(connect); } } @@ -124,7 +124,7 @@ ClientUpdate::put_preset(const URIs& uris, const std::string& label) { const Properties props{ - { uris.rdf_type, uris.pset_Preset.urid }, + { uris.rdf_type, uris.pset_Preset.urid_atom() }, { uris.rdfs_label, uris.forge.alloc(label) }, { uris.lv2_appliesTo, uris.forge.make_urid(plugin) }}; put(preset, props); @@ -164,5 +164,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 57848e62..9fadae90 100644 --- a/src/server/ClientUpdate.hpp +++ b/src/server/ClientUpdate.hpp @@ -67,8 +67,8 @@ struct ClientUpdate { }; struct Connect { - Raul::Path tail; - Raul::Path head; + raul::Path tail; + raul::Path head; }; std::vector<URI> dels; diff --git a/src/server/CompiledGraph.cpp b/src/server/CompiledGraph.cpp index 9efed05f..08e558a8 100644 --- a/src/server/CompiledGraph.cpp +++ b/src/server/CompiledGraph.cpp @@ -21,37 +21,46 @@ #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/Path.hpp" + +#include <boost/intrusive/slist.hpp> #include <algorithm> #include <cassert> #include <cstdint> #include <cstdio> +#include <exception> #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* node, - const BlockImpl* root = nullptr) - : node(node), root(root) + explicit FeedbackException(const BlockImpl* n) + : node(n) + {} + + FeedbackException(const BlockImpl* n, const BlockImpl* r) + : node(n), root(r) {} - const BlockImpl* node; - const BlockImpl* root; + const BlockImpl* node = nullptr; + const BlockImpl* root = nullptr; }; static bool -has_provider_with_many_dependants(BlockImpl* n) +has_provider_with_many_dependants(const BlockImpl* n) { - for (BlockImpl* p : n->providers()) { + for (const auto* p : n->providers()) { if (p->dependants().size() > 1) { return true; } @@ -61,16 +70,16 @@ has_provider_with_many_dependants(BlockImpl* n) } 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); } -MPtr<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) { @@ -79,15 +88,15 @@ CompiledGraph::compile(Raul::Maid& maid, GraphImpl& graph) } else { log.error("Feedback compiling %1%\n", e.node->path()); } - return MPtr<CompiledGraph>(); + return nullptr; } } static size_t -num_unvisited_dependants(BlockImpl* block) +num_unvisited_dependants(const BlockImpl* block) { size_t count = 0; - for (BlockImpl* b : block->dependants()) { + for (const BlockImpl* b : block->dependants()) { if (b->get_mark() == BlockImpl::Mark::UNVISITED) { ++count; } @@ -96,14 +105,14 @@ num_unvisited_dependants(BlockImpl* block) } static size_t -parallel_depth(BlockImpl* block) +parallel_depth(const BlockImpl* block) { if (has_provider_with_many_dependants(block)) { return 2; } size_t min_provider_depth = std::numeric_limits<size_t>::max(); - for (auto p : block->providers()) { + for (const auto* p : block->providers()) { min_provider_depth = std::min(min_provider_depth, parallel_depth(p)); } @@ -133,12 +142,12 @@ CompiledGraph::compile_graph(GraphImpl* graph) // Calculate maximum sequential depth to consume this phase size_t depth = std::numeric_limits<size_t>::max(); - for (auto i : blocks) { + for (const auto* i : blocks) { depth = std::min(depth, parallel_depth(i)); } Task par(Task::Mode::PARALLEL); - for (auto b : blocks) { + for (auto* b : blocks) { assert(num_unvisited_dependants(b) == 0); Task seq(Task::Mode::SEQUENTIAL); compile_block(b, seq, depth, predecessors); @@ -151,7 +160,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()); } } @@ -164,7 +173,7 @@ check_feedback(const BlockImpl* root, BlockImpl* provider) throw FeedbackException(root); } - for (auto p : provider->providers()) { + for (auto* p : provider->providers()) { const BlockImpl::Mark mark = p->get_mark(); switch (mark) { case BlockImpl::Mark::UNVISITED: @@ -227,12 +236,12 @@ CompiledGraph::compile_block(BlockImpl* n, if (n->providers().size() < 2) { // Single provider, prepend it to this sequential task - for (auto p : n->providers()) { + for (auto* p : n->providers()) { compile_provider(n, p, task, max_depth - 1, k); } } else if (has_provider_with_many_dependants(n)) { // Stop recursion and enqueue providers for the next round - for (auto p : n->providers()) { + for (auto* p : n->providers()) { if (num_unvisited_dependants(p) == 0) { k.insert(p); } @@ -241,7 +250,7 @@ CompiledGraph::compile_block(BlockImpl* n, // Multiple providers with only this node as dependant, // make a new parallel task to execute them Task par(Task::Mode::PARALLEL); - for (auto p : n->providers()) { + for (auto* p : n->providers()) { compile_provider(n, p, par, max_depth - 1, k); } task.push_front(std::move(par)); @@ -258,9 +267,9 @@ CompiledGraph::compile_block(BlockImpl* n, } void -CompiledGraph::run(RunContext& context) +CompiledGraph::run(RunContext& ctx) { - _master->run(context); + _master->run(ctx); } void @@ -276,5 +285,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 959fb18e..89aab289 100644 --- a/src/server/CompiledGraph.hpp +++ b/src/server/CompiledGraph.hpp @@ -19,16 +19,14 @@ #include "Task.hpp" -#include "ingen/types.hpp" -#include "raul/Maid.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,17 +38,14 @@ 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 MPtr<CompiledGraph> compile(Raul::Maid& maid, GraphImpl& graph); + static std::unique_ptr<CompiledGraph> compile(GraphImpl& graph); - void run(RunContext& context); + void run(RunContext& ctx); private: - friend class Raul::Maid; ///< Allow make_managed to construct - CompiledGraph(GraphImpl* graph); using BlockSet = std::set<BlockImpl*>; @@ -73,12 +68,12 @@ private: std::unique_ptr<Task> _master; }; -inline MPtr<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 3e123a16..e8dd3554 100644 --- a/src/server/ControlBindings.cpp +++ b/src/server/ControlBindings.cpp @@ -36,12 +36,13 @@ #include "lv2/urid/urid.h" #include "raul/Path.hpp" +#include <boost/intrusive/bstree.hpp> + #include <cmath> #include <cstring> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { ControlBindings::ControlBindings(Engine& engine) : _engine(engine) @@ -53,8 +54,7 @@ ControlBindings::ControlBindings(Engine& engine) 4096)) // FIXME: capacity? , _forge() { - lv2_atom_forge_init( - &_forge, &engine.world().uri_map().urid_map_feature()->urid_map); + lv2_atom_forge_init(&_forge, &engine.world().uri_map().urid_map()); } ControlBindings::~ControlBindings() @@ -72,6 +72,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 { @@ -79,15 +85,37 @@ ControlBindings::binding_key(const Atom& binding) const Key key; LV2_Atom* num = nullptr; if (binding.type() == uris.atom_Object) { - const auto* obj = (const LV2_Atom_Object_Body*)binding.get_body(); + 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, - (LV2_URID)uris.midi_controllerNumber, + uris.midi_controllerNumber.urid(), &num, nullptr); if (!num) { @@ -95,12 +123,12 @@ 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, ((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(), obj, - (LV2_URID)uris.midi_noteNumber, + uris.midi_noteNumber.urid(), &num, nullptr); if (!num) { @@ -108,7 +136,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, ((LV2_Atom_Int*)num)->body); + key = Key(Type::MIDI_NOTE, get_atom_num(num)); } } } else if (binding.type()) { @@ -118,21 +146,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 {}; } @@ -150,9 +185,9 @@ ControlBindings::set_port_binding(RunContext&, binding->port = port; _bindings->insert(*binding); return true; - } else { - return false; } + + return false; } void @@ -163,15 +198,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: @@ -192,14 +228,17 @@ 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: break; } if (size > 0) { - _feedback->append_event(ctx.nframes() - 1, size, (LV2_URID)uris.midi_MidiEvent, buf); + _feedback->append_event(ctx.nframes() - 1, + size, + static_cast<LV2_URID>(uris.midi_MidiEvent), + buf); } } } @@ -217,18 +256,18 @@ ControlBindings::start_learn(PortImpl* port) } static void -get_range(RunContext& context, const PortImpl* port, float* min, float* max) +get_range(RunContext& ctx, const PortImpl* port, float* min, float* max) { *min = port->minimum().get<float>(); *max = port->maximum().get<float>(); if (port->is_sample_rate()) { - *min *= context.engine().sample_rate(); - *max *= context.engine().sample_rate(); + *min *= ctx.engine().sample_rate(); + *max *= ctx.engine().sample_rate(); } } float -ControlBindings::control_to_port_value(RunContext& context, +ControlBindings::control_to_port_value(RunContext& ctx, const PortImpl* port, Type type, int16_t value) @@ -237,10 +276,10 @@ ControlBindings::control_to_port_value(RunContext& context, switch (type) { case Type::MIDI_CC: case Type::MIDI_CHANNEL_PRESSURE: - normal = (float)value / 127.0f; + normal = static_cast<float>(value) / 127.0f; break; case Type::MIDI_BENDER: - normal = (float)value / 16383.0f; + normal = static_cast<float>(value) / 16383.0f; break; case Type::MIDI_NOTE: normal = (value == 0) ? 0.0f : 1.0f; @@ -250,18 +289,18 @@ ControlBindings::control_to_port_value(RunContext& context, } if (port->is_logarithmic()) { - normal = (expf(normal) - 1.0f) / ((float)M_E - 1.0f); + normal = (expf(normal) - 1.0f) / (static_cast<float>(M_E) - 1.0f); } float min = 0.0f; float max = 1.0f; - get_range(context, port, &min, &max); + get_range(ctx, port, &min, &max); return normal * (max - min) + min; } int16_t -ControlBindings::port_value_to_control(RunContext& context, +ControlBindings::port_value_to_control(RunContext& ctx, PortImpl* port, Type type, const Atom& value_atom) @@ -272,7 +311,7 @@ ControlBindings::port_value_to_control(RunContext& context, float min = 0.0f; float max = 1.0f; - get_range(context, port, &min, &max); + get_range(ctx, port, &min, &max); const float value = value_atom.get<float>(); float normal = (value - min) / (max - min); @@ -286,15 +325,15 @@ ControlBindings::port_value_to_control(RunContext& context, } if (port->is_logarithmic()) { - normal = logf(normal * ((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: @@ -317,9 +356,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); @@ -334,29 +377,29 @@ forge_binding(const URIs& uris, } void -ControlBindings::set_port_value(RunContext& context, +ControlBindings::set_port_value(RunContext& ctx, PortImpl* port, Type type, - int16_t value) + int16_t value) const { float min = 0.0f; float max = 1.0f; - get_range(context, port, &min, &max); + get_range(ctx, port, &min, &max); - const float val = control_to_port_value(context, port, type, value); + const float val = control_to_port_value(ctx, port, type, value); // TODO: Set port value property so it is saved - port->set_control_value(context, context.start(), val); + port->set_control_value(ctx, ctx.start(), val); - URIs& uris = context.engine().world().uris(); - context.notify(uris.ingen_value, context.start(), port, - sizeof(float), _forge.Float, &val); + const URIs& uris = ctx.engine().world().uris(); + ctx.notify(uris.ingen_value, ctx.start(), port, + sizeof(float), _forge.Float, &val); } bool -ControlBindings::finish_learn(RunContext& context, Key key) +ControlBindings::finish_learn(RunContext& ctx, Key key) { - const ingen::URIs& uris = context.engine().world().uris(); + const ingen::URIs& uris = ctx.engine().world().uris(); Binding* binding = _learn_binding.exchange(nullptr); if (!binding || (key.type == Type::MIDI_NOTE && !binding->port->is_toggled())) { return false; @@ -367,19 +410,19 @@ ControlBindings::finish_learn(RunContext& context, Key key) LV2_Atom buf[16]; memset(buf, 0, sizeof(buf)); - lv2_atom_forge_set_buffer(&_forge, (uint8_t*)buf, sizeof(buf)); + lv2_atom_forge_set_buffer(&_forge, reinterpret_cast<uint8_t*>(buf), sizeof(buf)); forge_binding(uris, &_forge, key.type, key.num); const LV2_Atom* atom = buf; - context.notify(uris.midi_binding, - context.start(), - binding->port, - atom->size, atom->type, LV2_ATOM_BODY_CONST(atom)); + ctx.notify(uris.midi_binding, + ctx.start(), + binding->port, + atom->size, atom->type, LV2_ATOM_BODY_CONST(atom)); return true; } void -ControlBindings::get_all(const Raul::Path& path, std::vector<Binding*>& bindings) +ControlBindings::get_all(const raul::Path& path, std::vector<Binding*>& bindings) { ThreadManager::assert_thread(THREAD_PRE_PROCESS); @@ -406,22 +449,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 = (const uint8_t*)LV2_ATOM_BODY(&ev->body); - const Key key = midi_event_key(ev->body.size, buf, value); + const auto* buf = static_cast<const uint8_t*>(LV2_ATOM_BODY(&ev->body)); + 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); @@ -438,5 +481,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 bb113666..9a7f66a2 100644 --- a/src/server/ControlBindings.hpp +++ b/src/server/ControlBindings.hpp @@ -19,20 +19,24 @@ #include "BufferRef.hpp" -#include "ingen/types.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> #include <atomic> #include <cstdint> -#include <utility> +#include <memory> #include <vector> -namespace Raul { class Path; } +namespace raul { +class Path; +} // namespace raul + +namespace boost::intrusive { +template <class Compare> struct compare; +} // namespace boost::intrusive namespace ingen { @@ -45,7 +49,8 @@ class Engine; class RunContext; class PortImpl; -class ControlBindings { +class ControlBindings +{ public: enum class Type : uint16_t { NULL_CONTROL, @@ -58,25 +63,31 @@ 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 = Type::NULL_CONTROL, int16_t n = 0) noexcept + : type(t), num(n) + {} + + 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; }; /** 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(std::move(k)), port(p) {} + public raul::Maid::Disposable { + Binding(Key k=Key(), PortImpl* p=nullptr) : key(k), port(p) {} - 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; @@ -112,7 +123,7 @@ public: void post_process(RunContext& ctx, Buffer* buffer); /** Get all bindings for `path` or children of `path`. */ - void get_all(const Raul::Path& path, std::vector<Binding*>& bindings); + void get_all(const raul::Path& path, std::vector<Binding*>& bindings); /** Remove a set of bindings from an earlier call to get_all(). */ void remove(RunContext& ctx, const std::vector<Binding*>& bindings); @@ -123,30 +134,30 @@ 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& context, + void set_port_value(RunContext& ctx, PortImpl* port, Type type, - int16_t value); + int16_t value) const; - bool finish_learn(RunContext& context, Key key); + bool finish_learn(RunContext& ctx, Key key); - static float control_to_port_value(RunContext& context, - const PortImpl* port, - Type type, - int16_t value); + static float control_to_port_value(RunContext& ctx, + const PortImpl* port, + Type type, + int16_t value); - static int16_t port_value_to_control(RunContext& context, + static int16_t port_value_to_control(RunContext& ctx, PortImpl* port, Type type, const Atom& value_atom); - Engine& _engine; - std::atomic<Binding*> _learn_binding; - SPtr<Bindings> _bindings; - BufferRef _feedback; - LV2_Atom_Forge _forge; + Engine& _engine; + std::atomic<Binding*> _learn_binding; + std::shared_ptr<Bindings> _bindings; + BufferRef _feedback; + LV2_Atom_Forge _forge; }; } // namespace server diff --git a/src/server/DirectDriver.hpp b/src/server/DirectDriver.hpp index bb949a14..2361034c 100644 --- a/src/server/DirectDriver.hpp +++ b/src/server/DirectDriver.hpp @@ -18,17 +18,37 @@ #define INGEN_ENGINE_DIRECT_DRIVER_HPP #include "Driver.hpp" +#include "DuplexPort.hpp" #include "Engine.hpp" +#include "EnginePort.hpp" +#include "RunContext.hpp" +#include "types.hpp" + +#include "raul/Path.hpp" #include <boost/intrusive/slist.hpp> +#include <cstddef> +#include <string> + +namespace boost::intrusive { +template <bool Enabled> struct cache_last; +} // namespace boost::intrusive + namespace ingen { + +class Atom; +class URI; + namespace server { +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, @@ -40,7 +60,7 @@ public: , _seq_size(seq_size) {} - virtual ~DirectDriver() { + ~DirectDriver() override { _ports.clear_and_dispose([](EnginePort* p) { delete p; }); } @@ -50,7 +70,7 @@ public: return new EnginePort(graph_port); } - EnginePort* get_port(const Raul::Path& path) override { + EnginePort* get_port(const raul::Path& path) override { for (auto& p : _ports) { if (p.graph_port()->path() == path) { return &p; @@ -60,18 +80,18 @@ public: return nullptr; } - void add_port(RunContext& context, EnginePort* port) override { + void add_port(RunContext&, EnginePort* port) override { _ports.push_back(*port); } - void remove_port(RunContext& context, EnginePort* port) override { + void remove_port(RunContext&, EnginePort* port) override { _ports.erase(_ports.iterator_to(*port)); } - void rename_port(const Raul::Path& old_path, - const Raul::Path& new_path) override {} + void rename_port(const raul::Path& old_path, + const raul::Path& new_path) override {} - void port_property(const Raul::Path& path, + void port_property(const raul::Path& path, const URI& uri, const Atom& value) override {} @@ -88,7 +108,7 @@ public: return _engine.run_context().start(); } - void append_time_events(RunContext& context, Buffer& buffer) override {} + void append_time_events(RunContext&, Buffer&) override {} int real_time_priority() override { return 60; } diff --git a/src/server/Driver.hpp b/src/server/Driver.hpp index 4da04a55..83436389 100644 --- a/src/server/Driver.hpp +++ b/src/server/Driver.hpp @@ -17,18 +17,27 @@ #ifndef INGEN_ENGINE_DRIVER_HPP #define INGEN_ENGINE_DRIVER_HPP -#include "DuplexPort.hpp" -#include "EnginePort.hpp" +#include "types.hpp" +#include "ingen/URI.hpp" #include "raul/Noncopyable.hpp" -namespace Raul { class Path; } +#include <cstddef> + +namespace raul { +class Path; +} // namespace raul namespace ingen { + +class Atom; + namespace server { +class Buffer; class DuplexPort; class EnginePort; +class RunContext; /** Engine driver base class. * @@ -37,7 +46,8 @@ class EnginePort; * * \ingroup engine */ -class Driver : public Raul::Noncopyable { +class Driver : public raul::Noncopyable +{ public: virtual ~Driver() = default; @@ -53,10 +63,10 @@ public: virtual EnginePort* create_port(DuplexPort* graph_port) = 0; /** Find a system port by path. */ - virtual EnginePort* get_port(const Raul::Path& path) = 0; + virtual EnginePort* get_port(const raul::Path& path) = 0; /** Add a system visible port (e.g. a port on the root graph). */ - virtual void add_port(RunContext& context, EnginePort* port) = 0; + virtual void add_port(RunContext& ctx, EnginePort* port) = 0; /** Remove a system visible port. * @@ -64,7 +74,7 @@ public: * destroy the port. To actually remove the system port, unregister_port() * must be called later in another thread. */ - virtual void remove_port(RunContext& context, EnginePort* port) = 0; + virtual void remove_port(RunContext& ctx, EnginePort* port) = 0; /** Return true iff driver supports dynamic adding/removing of ports. */ virtual bool dynamic_ports() const { return false; } @@ -76,11 +86,11 @@ public: virtual void unregister_port(EnginePort& port) = 0; /** Rename a system visible port. */ - virtual void rename_port(const Raul::Path& old_path, - const Raul::Path& new_path) = 0; + virtual void rename_port(const raul::Path& old_path, + const raul::Path& new_path) = 0; /** Apply a system visible port property. */ - virtual void port_property(const Raul::Path& path, + virtual void port_property(const raul::Path& path, const URI& uri, const Atom& value) = 0; @@ -97,8 +107,7 @@ public: virtual SampleCount frame_time() const = 0; /** Append time events for this cycle to `buffer`. */ - virtual void append_time_events(RunContext& context, - Buffer& buffer) = 0; + virtual void append_time_events(RunContext& ctx, Buffer& buffer) = 0; /** Return the real-time priority of the audio thread, or -1. */ virtual int real_time_priority() = 0; diff --git a/src/server/DuplexPort.cpp b/src/server/DuplexPort.cpp index 8297e3cc..941beb10 100644 --- a/src/server/DuplexPort.cpp +++ b/src/server/DuplexPort.cpp @@ -29,19 +29,20 @@ #include "ingen/Node.hpp" #include "ingen/Properties.hpp" #include "ingen/URIs.hpp" -#include "ingen/types.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, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, uint32_t index, bool polyphonic, PortType type, @@ -69,8 +70,11 @@ DuplexPort::DuplexPort(BufferFactory& bufs, _is_output = is_output; if (is_output) { if (parent->graph_type() != Node::GraphType::GRAPH) { - remove_property(bufs.uris().rdf_type, bufs.uris().lv2_InputPort.urid); - add_property(bufs.uris().rdf_type, bufs.uris().lv2_OutputPort.urid); + remove_property(bufs.uris().rdf_type, + bufs.uris().lv2_InputPort.urid_atom()); + + add_property(bufs.uris().rdf_type, + bufs.uris().lv2_OutputPort.urid_atom()); } } @@ -87,7 +91,7 @@ DuplexPort::~DuplexPort() DuplexPort* DuplexPort::duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent) { BufferFactory& bufs = *engine.buffer_factory(); @@ -141,17 +145,20 @@ DuplexPort::on_property(const URI& uri, const Atom& value) } bool -DuplexPort::get_buffers(BufferFactory& bufs, - PortImpl::GetFn get, - const MPtr<Voices>& voices, - uint32_t poly, - size_t num_in_arcs) const +DuplexPort::get_buffers(BufferFactory& bufs, + PortImpl::GetFn get, + const raul::managed_ptr<Voices>& voices, + uint32_t poly, + size_t num_in_arcs) const { 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; } @@ -160,9 +167,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; } @@ -198,46 +208,46 @@ DuplexPort::prepare_poly(BufferFactory& bufs, uint32_t poly) } bool -DuplexPort::apply_poly(RunContext& context, uint32_t poly) +DuplexPort::apply_poly(RunContext& ctx, uint32_t poly) { if (!parent()->parent() || poly != parent()->parent_graph()->internal_poly()) { return false; } - return PortImpl::apply_poly(context, poly); + return PortImpl::apply_poly(ctx, poly); } void -DuplexPort::pre_process(RunContext& context) +DuplexPort::pre_process(RunContext& ctx) { if (_is_output) { /* This is a graph output, which is an input from the internal perspective. Prepare buffers for write so plugins can deliver to them */ for (uint32_t v = 0; v < _poly; ++v) { - _voices->at(v).buffer->prepare_write(context); + _voices->at(v).buffer->prepare_write(ctx); } } else { /* This is a a graph input, which is an output from the internal perspective. Do whatever a normal block's input port does to prepare input for reading. */ - InputPort::pre_process(context); - InputPort::pre_run(context); + InputPort::pre_process(ctx); + InputPort::pre_run(ctx); } } void -DuplexPort::post_process(RunContext& context) +DuplexPort::post_process(RunContext& ctx) { if (_is_output) { /* This is a graph output, which is an input from the internal perspective. Mix down input delivered by plugins so output (external perspective) is ready. */ - InputPort::pre_process(context); - InputPort::pre_run(context); + InputPort::pre_process(ctx); + InputPort::pre_run(ctx); } - monitor(context); + monitor(ctx); } SampleCount @@ -246,5 +256,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 6b3d0ae6..3cc0efba 100644 --- a/src/server/DuplexPort.hpp +++ b/src/server/DuplexPort.hpp @@ -20,17 +20,21 @@ #include "InputPort.hpp" #include "PortImpl.hpp" #include "PortType.hpp" +#include "server.h" #include "types.hpp" #include "ingen/URI.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 { @@ -53,14 +57,14 @@ 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 { public: DuplexPort(BufferFactory& bufs, GraphImpl* parent, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, uint32_t index, bool polyphonic, PortType type, @@ -69,10 +73,10 @@ public: const Atom& value, bool is_output); - virtual ~DuplexPort(); + ~DuplexPort() override; DuplexPort* duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent); void inherit_neighbour(const PortImpl* port, @@ -81,17 +85,17 @@ public: void on_property(const URI& uri, const Atom& value) override; - uint32_t max_tail_poly(RunContext& context) const override; + uint32_t max_tail_poly(RunContext& ctx) const override; bool prepare_poly(BufferFactory& bufs, uint32_t poly) override; - bool apply_poly(RunContext& context, uint32_t poly) override; + bool apply_poly(RunContext& ctx, uint32_t poly) override; - bool get_buffers(BufferFactory& bufs, - PortImpl::GetFn get, - const MPtr<Voices>& voices, - uint32_t poly, - size_t num_in_arcs) const override; + bool get_buffers(BufferFactory& bufs, + PortImpl::GetFn get, + const raul::managed_ptr<Voices>& voices, + uint32_t poly, + size_t num_in_arcs) const override; void set_is_driver_port(BufferFactory& bufs) override; @@ -105,8 +109,8 @@ public: bool setup_buffers(RunContext& ctx, BufferFactory& bufs, uint32_t poly) override; - void pre_process(RunContext& context) override; - void post_process(RunContext& context) override; + void pre_process(RunContext& ctx) override; + void post_process(RunContext& ctx) override; SampleCount next_value_offset(SampleCount offset, SampleCount end) const override; diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index 8256981b..c4c492b7 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -26,52 +26,63 @@ #include "EventWriter.hpp" #include "GraphImpl.hpp" #include "LV2Options.hpp" +#include "NodeImpl.hpp" +#include "PortImpl.hpp" #include "PostProcessor.hpp" #include "PreProcessor.hpp" #include "RunContext.hpp" +#include "Task.hpp" #include "ThreadManager.hpp" #include "UndoStack.hpp" #include "Worker.hpp" #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 "ingen/types.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> #include <cstdint> #include <cstdio> #include <limits> +#include <map> +#include <memory> #include <thread> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { -INGEN_THREAD_LOCAL unsigned ThreadManager::flags(0); -bool ThreadManager::single_threaded(true); +thread_local unsigned ThreadManager::flags(0); +bool ThreadManager::single_threaded(true); Engine::Engine(ingen::World& world) : _world(world) , _options(new LV2Options(world.uris())) , _buffer_factory(new BufferFactory(*this, world.uris())) - , _maid(new Raul::Maid) + , _maid(new raul::Maid) , _worker(new Worker(world.log(), event_queue_size())) , _sync_worker(new Worker(world.log(), event_queue_size(), true)) , _broadcaster(new Broadcaster()) @@ -85,14 +96,8 @@ 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>()); @@ -100,26 +105,26 @@ Engine::Engine(ingen::World& world) for (int i = 0; i < world.conf().option("threads").get<int32_t>(); ++i) { _notifications.emplace_back( - make_unique<Raul::RingBuffer>(uint32_t(24 * event_queue_size()))); + std::make_unique<raul::RingBuffer>(uint32_t(24 * event_queue_size()))); _run_contexts.emplace_back( - make_unique<RunContext>( + std::make_unique<RunContext>( *this, _notifications.back().get(), unsigned(i), i > 0)); } _world.lv2_features().add_feature(_worker->schedule_feature()); _world.lv2_features().add_feature(_options); _world.lv2_features().add_feature( - SPtr<LV2Features::Feature>( - new LV2Features::EmptyFeature(LV2_BUF_SIZE__powerOf2BlockLength))); + std::make_shared<LV2Features::EmptyFeature>( + LV2_BUF_SIZE__powerOf2BlockLength)); _world.lv2_features().add_feature( - SPtr<LV2Features::Feature>( - new LV2Features::EmptyFeature(LV2_BUF_SIZE__fixedBlockLength))); + std::make_shared<LV2Features::EmptyFeature>( + LV2_BUF_SIZE__fixedBlockLength)); _world.lv2_features().add_feature( - SPtr<LV2Features::Feature>( - new LV2Features::EmptyFeature(LV2_BUF_SIZE__boundedBlockLength))); + std::make_shared<LV2Features::EmptyFeature>( + LV2_BUF_SIZE__boundedBlockLength)); _world.lv2_features().add_feature( - SPtr<LV2Features::Feature>( - new LV2Features::EmptyFeature(LV2_STATE__loadDefaultState))); + std::make_shared<LV2Features::EmptyFeature>( + LV2_STATE__loadDefaultState)); if (world.conf().option("dump").get<int32_t>()) { _interface = std::make_shared<Tee>( @@ -154,28 +159,28 @@ Engine::~Engine() // Delete run contexts _quit_flag = true; _tasks_available.notify_all(); - for (const auto& ctx : _run_contexts) { - ctx->join(); + for (const auto& thread_ctx : _run_contexts) { + thread_ctx->join(); } - const SPtr<Store> store = this->store(); + const auto store = this->store(); if (store) { - for (auto& s : *store.get()) { - if (!dynamic_ptr_cast<NodeImpl>(s.second)->parent()) { + for (auto& s : *store) { + if (!std::dynamic_pointer_cast<NodeImpl>(s.second)->parent()) { s.second.reset(); } } store->clear(); } - _world.set_store(SPtr<ingen::Store>()); + _world.set_store(nullptr); } void Engine::listen() { -#ifdef HAVE_SOCKET - _listener = UPtr<SocketListener>(new SocketListener(*this)); +#if USE_SOCKET + _listener = std::make_unique<SocketListener>(*this); #endif } @@ -272,7 +277,7 @@ Engine::steal_task(unsigned start_thread) return nullptr; } -SPtr<Store> +std::shared_ptr<Store> Engine::store() const { return _world.store(); @@ -336,7 +341,7 @@ Engine::main_iteration() } void -Engine::set_driver(const SPtr<Driver>& driver) +Engine::set_driver(const std::shared_ptr<Driver>& driver) { _driver = driver; for (const auto& ctx : _run_contexts) { @@ -375,7 +380,8 @@ Engine::reset_load() void Engine::init(double sample_rate, uint32_t block_length, size_t seq_size) { - set_driver(SPtr<Driver>(new DirectDriver(*this, sample_rate, block_length, seq_size))); + set_driver(std::make_shared<DirectDriver>( + *this, sample_rate, block_length, seq_size)); } bool @@ -405,7 +411,7 @@ Engine::activate() enqueue_event( new events::CreateGraph( - *this, SPtr<Interface>(), -1, 0, Raul::Path("/"), properties)); + *this, nullptr, -1, 0, raul::Path("/"), properties)); flush_events(std::chrono::milliseconds(10)); if (!_root_graph) { @@ -510,18 +516,17 @@ Engine::log() const } void -Engine::register_client(const SPtr<Interface>& client) +Engine::register_client(const std::shared_ptr<Interface>& client) { log().info("Registering client <%1%>\n", client->uri().c_str()); _broadcaster->register_client(client); } bool -Engine::unregister_client(const SPtr<Interface>& client) +Engine::unregister_client(const std::shared_ptr<Interface>& client) { log().info("Unregistering client <%1%>\n", client->uri().c_str()); 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 45379ad1..f0f19740 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -19,26 +19,29 @@ #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/types.hpp" #include <chrono> #include <condition_variable> #include <cstddef> #include <cstdint> +#include <memory> #include <mutex> #include <random> #include <vector> -namespace Raul { +// IWYU pragma: no_include "RunContext.hpp" +// IWYU pragma: no_include "raul/RingBuffer.hpp" + +namespace raul { class Maid; -class RingBuffer; -} +class RingBuffer; // IWYU pragma: keep +} // namespace raul namespace ingen { @@ -60,7 +63,7 @@ class GraphImpl; class LV2Options; class PostProcessor; class PreProcessor; -class RunContext; +class RunContext; // IWYU pragma: keep class SocketListener; class Task; class UndoStack; @@ -75,11 +78,11 @@ 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); - virtual ~Engine(); + ~Engine() override; Engine(const Engine&) = delete; Engine& operator=(const Engine&) = delete; @@ -93,15 +96,15 @@ public: unsigned run(uint32_t sample_count) override; void quit() override; bool main_iteration() override; - void register_client(const SPtr<Interface>& client) override; - bool unregister_client(const SPtr<Interface>& client) override; + void register_client(const std::shared_ptr<Interface>& client) override; + bool unregister_client(const std::shared_ptr<Interface>& client) override; void listen() override; /** Return a random [0..1] float with uniform distribution */ float frand() { return _uniform_dist(_rand_engine); } - void set_driver(const SPtr<Driver>& driver); + void set_driver(const std::shared_ptr<Driver>& driver); /** Return the frame time to execute an event that arrived now. * @@ -114,7 +117,7 @@ public: * * This value is comparable to the value returned by current_time(). */ - inline uint64_t cycle_start_time(const RunContext& context) const { + uint64_t cycle_start_time(const RunContext&) const { return _cycle_start_time; } @@ -136,20 +139,20 @@ public: ingen::World& world() const { return _world; } Log& log() const; - const SPtr<Interface>& interface() const { return _interface; } - const SPtr<EventWriter>& event_writer() const { return _event_writer; } - const UPtr<AtomReader>& atom_interface() const { return _atom_interface; } - const UPtr<BlockFactory>& block_factory() const { return _block_factory; } - const UPtr<Broadcaster>& broadcaster() const { return _broadcaster; } - const UPtr<BufferFactory>& buffer_factory() const { return _buffer_factory; } - const UPtr<ControlBindings>& control_bindings() const { return _control_bindings; } - const SPtr<Driver>& driver() const { return _driver; } - const UPtr<PostProcessor>& post_processor() const { return _post_processor; } - const UPtr<Raul::Maid>& maid() const { return _maid; } - const UPtr<UndoStack>& undo_stack() const { return _undo_stack; } - const UPtr<UndoStack>& redo_stack() const { return _redo_stack; } - const UPtr<Worker>& worker() const { return _worker; } - const UPtr<Worker>& sync_worker() const { return _sync_worker; } + const std::shared_ptr<Interface>& interface() const { return _interface; } + const std::shared_ptr<EventWriter>& event_writer() const { return _event_writer; } + const std::unique_ptr<AtomReader>& atom_interface() const { return _atom_interface; } + const std::unique_ptr<BlockFactory>& block_factory() const { return _block_factory; } + const std::unique_ptr<Broadcaster>& broadcaster() const { return _broadcaster; } + const std::unique_ptr<BufferFactory>& buffer_factory() const { return _buffer_factory; } + const std::unique_ptr<ControlBindings>& control_bindings() const { return _control_bindings; } + const std::shared_ptr<Driver>& driver() const { return _driver; } + const std::unique_ptr<PostProcessor>& post_processor() const { return _post_processor; } + const std::unique_ptr<raul::Maid>& maid() const { return _maid; } + const std::unique_ptr<UndoStack>& undo_stack() const { return _undo_stack; } + const std::unique_ptr<UndoStack>& redo_stack() const { return _redo_stack; } + const std::unique_ptr<Worker>& worker() const { return _worker; } + const std::unique_ptr<Worker>& sync_worker() const { return _sync_worker; } GraphImpl* root_graph() const { return _root_graph; } void set_root_graph(GraphImpl* graph); @@ -166,7 +169,7 @@ public: void signal_tasks_available(); Task* steal_task(unsigned start_thread); - SPtr<Store> store() const; + std::shared_ptr<Store> store() const; SampleRate sample_rate() const; SampleCount block_length() const; @@ -182,41 +185,41 @@ public: private: ingen::World& _world; - SPtr<LV2Options> _options; - UPtr<BufferFactory> _buffer_factory; - UPtr<Raul::Maid> _maid; - SPtr<Driver> _driver; - UPtr<Worker> _worker; - UPtr<Worker> _sync_worker; - UPtr<Broadcaster> _broadcaster; - UPtr<ControlBindings> _control_bindings; - UPtr<BlockFactory> _block_factory; - UPtr<UndoStack> _undo_stack; - UPtr<UndoStack> _redo_stack; - UPtr<PostProcessor> _post_processor; - UPtr<PreProcessor> _pre_processor; - UPtr<SocketListener> _listener; - SPtr<EventWriter> _event_writer; - SPtr<Interface> _interface; - UPtr<AtomReader> _atom_interface; - GraphImpl* _root_graph; - - std::vector<UPtr<Raul::RingBuffer>> _notifications; - std::vector<UPtr<RunContext>> _run_contexts; - uint64_t _cycle_start_time; - Load _run_load; - Clock _clock; + std::shared_ptr<LV2Options> _options; + std::unique_ptr<BufferFactory> _buffer_factory; + std::unique_ptr<raul::Maid> _maid; + std::shared_ptr<Driver> _driver; + std::unique_ptr<Worker> _worker; + std::unique_ptr<Worker> _sync_worker; + std::unique_ptr<Broadcaster> _broadcaster; + std::unique_ptr<ControlBindings> _control_bindings; + std::unique_ptr<BlockFactory> _block_factory; + std::unique_ptr<UndoStack> _undo_stack; + std::unique_ptr<UndoStack> _redo_stack; + std::unique_ptr<PostProcessor> _post_processor; + std::unique_ptr<PreProcessor> _pre_processor; + std::unique_ptr<SocketListener> _listener; + std::shared_ptr<EventWriter> _event_writer; + std::shared_ptr<Interface> _interface; + std::unique_ptr<AtomReader> _atom_interface; + 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{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 33e0e29c..7a25bda5 100644 --- a/src/server/EnginePort.hpp +++ b/src/server/EnginePort.hpp @@ -22,25 +22,23 @@ #include "raul/Deletable.hpp" #include "raul/Noncopyable.hpp" -#include <boost/intrusive/slist.hpp> +#include <boost/intrusive/slist_hook.hpp> -namespace ingen { -namespace server { +#include <cstdint> + +namespace ingen::server { /** A "system" port (e.g. a Jack port, an external port on Ingen). * * @ingroup engine */ -class EnginePort : public Raul::Noncopyable - , public Raul::Deletable +class EnginePort : public raul::Noncopyable + , public raul::Deletable , public boost::intrusive::slist_base_hook<> { public: explicit EnginePort(DuplexPort* port) : _graph_port(port) - , _buffer(nullptr) - , _handle(nullptr) - , _driver_index(0) {} void set_buffer(void* buf) { _buffer = buf; } @@ -55,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 b2477ce8..de1f2384 100644 --- a/src/server/Event.hpp +++ b/src/server/Event.hpp @@ -20,17 +20,23 @@ #include "types.hpp" #include "ingen/Interface.hpp" -#include "ingen/Node.hpp" #include "ingen/Status.hpp" -#include "ingen/types.hpp" +#include "ingen/URI.hpp" +#include "ingen/paths.hpp" #include "raul/Deletable.hpp" #include "raul/Noncopyable.hpp" -#include "raul/Path.hpp" #include <atomic> +#include <cstdint> +#include <memory> +#include <string> +#include <utility> -namespace ingen { -namespace server { +namespace raul { +class Path; +} // namespace raul + +namespace ingen::server { class Engine; class RunContext; @@ -48,7 +54,7 @@ class PreProcessContext; * * \ingroup engine */ -class Event : public Raul::Deletable, public Raul::Noncopyable +class Event : public raul::Deletable, public raul::Noncopyable { public: /** Event mode to distinguish normal events from undo events. */ @@ -56,20 +62,20 @@ 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). */ - virtual void mark(PreProcessContext&) {}; + virtual void mark(PreProcessContext&) {} /** Pre-process event before execution (non-realtime). */ virtual bool pre_process(PreProcessContext& ctx) = 0; /** Execute this event in the audio thread (realtime). */ - virtual void execute(RunContext& context) = 0; + virtual void execute(RunContext& ctx) = 0; /** Post-process event after execution (non-realtime). */ virtual void post_process() = 0; @@ -78,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(); } @@ -104,20 +110,20 @@ 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, - const SPtr<Interface>& client, - int32_t id, - FrameTime time) - : _engine(engine) - , _next(nullptr) - , _request_client(std::move(client)) - , _request_id(id) - , _time(time) - , _status(Status::NOT_PREPARED) - , _mode(Mode::NORMAL) + Event(Engine& engine, + std::shared_ptr<Interface> client, + int32_t id, + FrameTime time) noexcept + : _engine(engine) + , _next(nullptr) + , _request_client(std::move(client)) + , _request_id(id) + , _time(time) + , _status(Status::NOT_PREPARED) + , _mode(Mode::NORMAL) {} /** Constructor for internal events only */ @@ -130,39 +136,38 @@ 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); } return _status; } - Engine& _engine; - std::atomic<Event*> _next; - SPtr<Interface> _request_client; - int32_t _request_id; - FrameTime _time; - Status _status; - std::string _err_subject; - Mode _mode; + Engine& _engine; + std::atomic<Event*> _next; + std::shared_ptr<Interface> _request_client; + int32_t _request_id; + FrameTime _time; + Status _status; + std::string _err_subject; + 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 c7db23ee..2feef347 100644 --- a/src/server/EventWriter.cpp +++ b/src/server/EventWriter.cpp @@ -17,18 +17,25 @@ #include "EventWriter.hpp" #include "Engine.hpp" -#include "events.hpp" -#include <boost/variant/apply_visitor.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" -namespace ingen { -namespace server { +#include <variant> + +namespace ingen::server { EventWriter::EventWriter(Engine& engine) : _engine(engine) - , _event_mode(Event::Mode::NORMAL) -{ -} +{} SampleCount EventWriter::now() const @@ -39,7 +46,7 @@ EventWriter::now() const void EventWriter::message(const Message& msg) { - boost::apply_visitor(*this, msg); + std::visit(*this, msg); } void @@ -142,5 +149,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 85aa6f70..ea35ceea 100644 --- a/src/server/EventWriter.hpp +++ b/src/server/EventWriter.hpp @@ -23,10 +23,10 @@ #include "ingen/Interface.hpp" #include "ingen/Message.hpp" #include "ingen/URI.hpp" -#include "ingen/types.hpp" -namespace ingen { -namespace server { +#include <memory> + +namespace ingen::server { class Engine; @@ -39,11 +39,12 @@ public: URI uri() const override { return URI("ingen:/clients/event_writer"); } - SPtr<Interface> respondee() const override { + std::shared_ptr<Interface> respondee() const override { return _respondee; } - void set_respondee(SPtr<Interface> respondee) override { + void set_respondee(const std::shared_ptr<Interface>& respondee) override + { _respondee = respondee; } @@ -60,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; - SPtr<Interface> _respondee; - Event::Mode _event_mode; + Engine& _engine; + std::shared_ptr<Interface> _respondee; + 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 57acbaa5..1f653f67 100644 --- a/src/server/FrameTimer.hpp +++ b/src/server/FrameTimer.hpp @@ -17,12 +17,10 @@ #ifndef INGEN_ENGINE_FRAMETIMER_HPP #define INGEN_ENGINE_FRAMETIMER_HPP -#include <chrono> #include <cmath> #include <cstdint> -namespace ingen { -namespace server { +namespace ingen::server { /** Delay-locked loop for monotonic sample time. * @@ -37,13 +35,14 @@ public: static constexpr double us_per_s = 1000000.0; FrameTimer(uint32_t period_size, uint32_t sample_rate) - : tper(((double)period_size / (double)sample_rate) * us_per_s) - , omega(2 * PI * bandwidth / us_per_s * tper) - , b(sqrt(2) * omega) - , c(omega * omega) - , nper(period_size) - { - } + : tper((static_cast<double>(period_size) / + static_cast<double>(sample_rate)) * + us_per_s) + , omega(2 * PI * bandwidth / us_per_s * tper) + , 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) { @@ -53,7 +52,7 @@ public: } // Calculate loop error - const double e = ((double)usec - t1); + const double e = (static_cast<double>(usec) - t1); // Update loop t0 = t1; @@ -71,7 +70,7 @@ public: return 0; } - const double delta = (double)usec - t0; + const double delta = static_cast<double>(usec) - t0; const double period = t1 - t0; return n0 + std::round(delta / period * nper); } @@ -95,16 +94,15 @@ private: const double b; const double c; - uint64_t nper; - double e2; - double t0; - double t1; - uint64_t n0; - uint64_t n1; - bool initialized; + uint64_t nper = 0u; + double e2 = 0.0; + double t0 = 0.0; + double t1 = 0.0; + 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 00d4cfd6..0d3c5234 100644 --- a/src/server/GraphImpl.cpp +++ b/src/server/GraphImpl.cpp @@ -23,37 +23,43 @@ #include "DuplexPort.hpp" #include "Engine.hpp" #include "GraphPlugin.hpp" +#include "InputPort.hpp" +#include "PluginImpl.hpp" #include "PortImpl.hpp" #include "ThreadManager.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 <unordered_map> -namespace ingen { -namespace server { +namespace ingen::server { GraphImpl::GraphImpl(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, uint32_t poly, GraphImpl* parent, SampleRate srate, uint32_t internal_poly) : BlockImpl(new GraphPlugin(engine.world().uris(), engine.world().uris().ingen_Graph, - Raul::Symbol("graph"), + raul::Symbol("graph"), "Ingen Graph"), symbol, poly, parent, srate) , _engine(engine) , _poly_pre(internal_poly) , _poly_process(internal_poly) - , _process(false) { assert(internal_poly >= 1); assert(internal_poly <= 128); @@ -70,7 +76,7 @@ GraphImpl::~GraphImpl() BlockImpl* GraphImpl::duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent) { BufferFactory& bufs = *engine.buffer_factory(); @@ -115,8 +121,8 @@ GraphImpl::duplicate(Engine& engine, } // Add duplicates of all arcs - for (const auto& a : _arcs) { - SPtr<ArcImpl> arc = dynamic_ptr_cast<ArcImpl>(a.second); + for (const auto& a : _graph_arcs) { + auto arc = std::dynamic_pointer_cast<ArcImpl>(a.second); if (arc) { auto t = port_map.find(arc->tail()); auto h = port_map.find(arc->head()); @@ -156,11 +162,11 @@ GraphImpl::deactivate() } void -GraphImpl::disable(RunContext& context) +GraphImpl::disable(RunContext& ctx) { _process = false; for (auto& o : _outputs) { - o.clear_buffers(context); + o.clear_buffers(ctx); } } @@ -180,22 +186,22 @@ GraphImpl::prepare_internal_poly(BufferFactory& bufs, uint32_t poly) } bool -GraphImpl::apply_internal_poly(RunContext& context, +GraphImpl::apply_internal_poly(RunContext& ctx, BufferFactory& bufs, - Raul::Maid&, + raul::Maid&, uint32_t poly) { // TODO: Subgraph dynamic polyphony (i.e. changing port polyphony) for (auto& b : _blocks) { - b.apply_poly(context, poly); + b.apply_poly(ctx, poly); } for (auto& b : _blocks) { for (uint32_t j = 0; j < b.num_ports(); ++j) { PortImpl* const port = b.port_impl(j); if (port->is_input() && dynamic_cast<InputPort*>(port)->direct_connect()) { - port->setup_buffers(context, bufs, port->poly()); + port->setup_buffers(ctx, bufs, port->poly()); } port->connect_buffers(); } @@ -203,7 +209,7 @@ GraphImpl::apply_internal_poly(RunContext& context, const bool polyphonic = parent_graph() && (poly == parent_graph()->internal_poly_process()); for (auto& o : _outputs) { - o.setup_buffers(context, bufs, polyphonic ? poly : 1); + o.setup_buffers(ctx, bufs, polyphonic ? poly : 1); } _poly_process = poly; @@ -211,52 +217,52 @@ GraphImpl::apply_internal_poly(RunContext& context, } void -GraphImpl::pre_process(RunContext& context) +GraphImpl::pre_process(RunContext& ctx) { // Mix down input ports and connect buffers for (uint32_t i = 0; i < num_ports(); ++i) { PortImpl* const port = _ports->at(i); if (!port->is_driver_port()) { - port->pre_process(context); - port->pre_run(context); + port->pre_process(ctx); + port->pre_run(ctx); port->connect_buffers(); } } } void -GraphImpl::process(RunContext& context) +GraphImpl::process(RunContext& ctx) { if (!_process) { return; } - pre_process(context); - run(context); - post_process(context); + pre_process(ctx); + run(ctx); + post_process(ctx); } void -GraphImpl::run(RunContext& context) +GraphImpl::run(RunContext& ctx) { if (_compiled_graph) { - _compiled_graph->run(context); + _compiled_graph->run(ctx); } } void -GraphImpl::set_buffer_size(RunContext& context, +GraphImpl::set_buffer_size(RunContext& ctx, BufferFactory& bufs, LV2_URID type, uint32_t size) { - BlockImpl::set_buffer_size(context, bufs, type, size); + BlockImpl::set_buffer_size(ctx, bufs, type, size); if (_compiled_graph) { // FIXME // for (size_t i = 0; i < _compiled_graph->size(); ++i) { // const CompiledBlock& block = (*_compiled_graph)[i]; - // block.block()->set_buffer_size(context, bufs, type, size); + // block.block()->set_buffer_size(ctx, bufs, type, size); // } } } @@ -275,41 +281,43 @@ GraphImpl::remove_block(BlockImpl& block) } void -GraphImpl::add_arc(const SPtr<ArcImpl>& a) +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); } -SPtr<ArcImpl> +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()) { - SPtr<ArcImpl> arc = dynamic_ptr_cast<ArcImpl>(i->second); - _arcs.erase(i); + 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); + _graph_arcs.erase(i); return arc; - } else { - return SPtr<ArcImpl>(); } + + 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(MPtr<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 @@ -357,13 +365,13 @@ GraphImpl::clear_ports() _outputs.clear(); } -MPtr<BlockImpl::Ports> -GraphImpl::build_ports_array(Raul::Maid& maid) +raul::managed_ptr<BlockImpl::Ports> +GraphImpl::build_ports_array(raul::Maid& maid) { ThreadManager::assert_thread(THREAD_PRE_PROCESS); - const size_t n = _inputs.size() + _outputs.size(); - MPtr<Ports> result = maid.make_managed<Ports>(n); + const size_t n = _inputs.size() + _outputs.size(); + raul::managed_ptr<Ports> result = maid.make_managed<Ports>(n); std::map<size_t, DuplexPort*> ports; for (auto& p : _inputs) { @@ -383,5 +391,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 3e3c6159..c5f978fb 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,22 +20,36 @@ #include "BlockImpl.hpp" #include "DuplexPort.hpp" #include "ThreadManager.hpp" +#include "server.h" +#include "types.hpp" -#include "ingen/types.hpp" +#include "lv2/urid/urid.h" +#include "raul/Maid.hpp" + +#include <boost/intrusive/slist.hpp> #include <cassert> #include <cstdint> #include <memory> #include <utility> -namespace raul { class Maid; } +// IWYU pragma: no_include "CompiledGraph.hpp" + +namespace raul { +class Symbol; +} // namespace raul + +namespace boost::intrusive { +template <bool Enabled> struct constant_time_size; +} // namespace boost::intrusive -namespace ingen { -namespace server { +namespace ingen::server { class ArcImpl; -class CompiledGraph; +class BufferFactory; +class CompiledGraph; // IWYU pragma: keep class Engine; +class PortImpl; class RunContext; /** A group of blocks in a graph, possibly polyphonic. @@ -46,32 +60,32 @@ class RunContext; * * \ingroup engine */ -class GraphImpl final : public BlockImpl +class INGEN_SERVER_API GraphImpl final : public BlockImpl { public: GraphImpl(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, uint32_t poly, GraphImpl* parent, SampleRate srate, uint32_t internal_poly); - virtual ~GraphImpl(); + ~GraphImpl() override; GraphType graph_type() const override { return GraphType::GRAPH; } BlockImpl* duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent) override; void activate(BufferFactory& bufs) override; void deactivate() override; - void pre_process(RunContext& context) override; - void process(RunContext& context) override; - void run(RunContext& context) override; + void pre_process(RunContext& ctx) override; + void process(RunContext& ctx) override; + void run(RunContext& ctx) override; - void set_buffer_size(RunContext& context, + void set_buffer_size(RunContext& ctx, BufferFactory& bufs, LV2_URID type, uint32_t size) override; @@ -87,14 +101,14 @@ public: * * Audio thread. * - * \param context Process context + * \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 */ - bool apply_internal_poly(RunContext& context, + bool apply_internal_poly(RunContext& ctx, BufferFactory& bufs, - Raul::Maid& maid, + raul::Maid& maid, uint32_t poly); // Graph specific stuff not inherited from Block @@ -156,28 +170,30 @@ public: /** Add an arc to this graph. * Pre-processing thread only. */ - void add_arc(const SPtr<ArcImpl>& a); + void add_arc(const std::shared_ptr<ArcImpl>& a); /** Remove an arc from this graph. * Pre-processing thread only. */ - SPtr<ArcImpl> remove_arc(const PortImpl* tail, const PortImpl* dst_port); + std::shared_ptr<ArcImpl> + remove_arc(const PortImpl* tail, const PortImpl* dst_port); 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(MPtr<CompiledGraph>&& cg); + [[nodiscard]] std::unique_ptr<CompiledGraph> + swap_compiled_graph(std::unique_ptr<CompiledGraph> cg); - const MPtr<Ports>& external_ports() { return _ports; } + const raul::managed_ptr<Ports>& external_ports() { return _ports; } - void set_external_ports(MPtr<Ports>&& pa) { _ports = std::move(pa); } + void set_external_ports(raul::managed_ptr<Ports>&& pa) { _ports = std::move(pa); } - MPtr<Ports> build_ports_array(Raul::Maid& maid); + raul::managed_ptr<Ports> build_ports_array(raul::Maid& maid); /** Whether to run this graph's DSP bits in the audio thread */ bool enabled() const { return _process; } void enable() { _process = true; } - void disable(RunContext& context); + void disable(RunContext& ctx); uint32_t internal_poly() const { return _poly_pre; } uint32_t internal_poly_process() const { return _poly_process; } @@ -185,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 - MPtr<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 9e221689..ac89c7a9 100644 --- a/src/server/GraphPlugin.hpp +++ b/src/server/GraphPlugin.hpp @@ -19,12 +19,19 @@ #include "PluginImpl.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; +class Engine; +class GraphImpl; /** Implementation of a Graph plugin. * @@ -35,13 +42,13 @@ class GraphPlugin : public PluginImpl public: GraphPlugin(URIs& uris, const URI& uri, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, const std::string& name) - : PluginImpl(uris, uris.ingen_Graph.urid, uri) + : PluginImpl(uris, uris.ingen_Graph.urid_atom(), uri) {} BlockImpl* instantiate(BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, Engine& engine, @@ -50,15 +57,14 @@ public: return nullptr; } - Raul::Symbol symbol() const override { return Raul::Symbol("graph"); } - std::string name() const { return "Ingen Graph"; } + raul::Symbol symbol() const override { return raul::Symbol("graph"); } + static std::string name() { return "Ingen Graph"; } private: const std::string _symbol; 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 9d02fd99..4a464ea8 100644 --- a/src/server/InputPort.cpp +++ b/src/server/InputPort.cpp @@ -29,17 +29,19 @@ #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 <cassert> #include <cstdlib> +#include <memory> -namespace ingen { -namespace server { +namespace ingen::server { InputPort::InputPort(BufferFactory& bufs, BlockImpl* parent, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, uint32_t index, uint32_t poly, PortType type, @@ -47,19 +49,18 @@ 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(); if (parent->graph_type() != Node::GraphType::GRAPH) { - add_property(uris.rdf_type, uris.lv2_InputPort.urid); + add_property(uris.rdf_type, uris.lv2_InputPort.urid_atom()); } } bool -InputPort::apply_poly(RunContext& context, const uint32_t poly) +InputPort::apply_poly(RunContext& ctx, const uint32_t poly) { - const bool ret = PortImpl::apply_poly(context, poly); + const bool ret = PortImpl::apply_poly(ctx, poly); (void)ret; assert(_voices->size() >= (ret ? poly : 1)); @@ -68,11 +69,11 @@ InputPort::apply_poly(RunContext& context, const uint32_t poly) } bool -InputPort::get_buffers(BufferFactory& bufs, - PortImpl::GetFn get, - const MPtr<Voices>& voices, - uint32_t poly, - size_t num_in_arcs) const +InputPort::get_buffers(BufferFactory& bufs, + PortImpl::GetFn get, + const raul::managed_ptr<Voices>& voices, + uint32_t poly, + size_t num_in_arcs) const { if (is_a(PortType::ATOM) && !_value.is_valid()) { poly = 1; @@ -100,9 +101,9 @@ InputPort::get_buffers(BufferFactory& bufs, } bool -InputPort::pre_get_buffers(BufferFactory& bufs, - MPtr<Voices>& voices, - uint32_t poly) const +InputPort::pre_get_buffers(BufferFactory& bufs, + raul::managed_ptr<Voices>& voices, + uint32_t poly) const { return get_buffers(bufs, &BufferFactory::get_buffer, voices, poly, _num_arcs); } @@ -144,37 +145,37 @@ InputPort::max_tail_poly(RunContext&) const } void -InputPort::pre_process(RunContext& context) +InputPort::pre_process(RunContext& ctx) { if (_arcs.empty()) { // No incoming arcs, just handle user-set value for (uint32_t v = 0; v < _poly; ++v) { // Update set state - update_set_state(context, v); + update_set_state(ctx, v); // Prepare for write in case a set event executes this cycle if (!_parent->is_main()) { - buffer(v)->prepare_write(context); + buffer(v)->prepare_write(ctx); } } } else if (direct_connect()) { // Directly connected, use source's buffer directly for (uint32_t v = 0; v < _poly; ++v) { - _voices->at(v).buffer = _arcs.front().buffer(context, v); + _voices->at(v).buffer = _arcs.front().buffer(ctx, v); } } else { // Mix down to local buffers in pre_run() for (uint32_t v = 0; v < _poly; ++v) { - buffer(v)->prepare_write(context); + buffer(v)->prepare_write(ctx); } } } void -InputPort::pre_run(RunContext& context) +InputPort::pre_run(RunContext& ctx) { if ((_user_buffer || !_arcs.empty()) && !direct_connect()) { - const uint32_t src_poly = max_tail_poly(context); + const uint32_t src_poly = max_tail_poly(ctx); const uint32_t max_n_srcs = _arcs.size() * src_poly + 1; for (uint32_t v = 0; v < _poly; ++v) { @@ -196,24 +197,24 @@ InputPort::pre_run(RunContext& context) // P -> 1 or 1 -> 1: all tail voices => each head voice for (uint32_t w = 0; w < arc.tail()->poly(); ++w) { assert(n_srcs < max_n_srcs); - srcs[n_srcs++] = arc.buffer(context, w).get(); + srcs[n_srcs++] = arc.buffer(ctx, w).get(); assert(srcs[n_srcs - 1]); } } else { // P -> P or 1 -> P: tail voice => corresponding head voice assert(n_srcs < max_n_srcs); - srcs[n_srcs++] = arc.buffer(context, v).get(); + srcs[n_srcs++] = arc.buffer(ctx, v).get(); assert(srcs[n_srcs - 1]); } } // Then mix them into our buffer for this voice - mix(context, buffer(v).get(), srcs, n_srcs); - update_values(context.offset(), v); + mix(ctx, buffer(v).get(), srcs, n_srcs); + update_values(ctx.offset(), v); } } else if (is_a(PortType::CONTROL)) { for (uint32_t v = 0; v < _poly; ++v) { - update_values(context.offset(), v); + update_values(ctx.offset(), v); } } } @@ -238,10 +239,10 @@ InputPort::next_value_offset(SampleCount offset, SampleCount end) const } void -InputPort::post_process(RunContext& context) +InputPort::post_process(RunContext& ctx) { if (!_arcs.empty() || _force_monitor_update) { - monitor(context, _force_monitor_update); + monitor(ctx, _force_monitor_update); _force_monitor_update = false; } @@ -259,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 35ddb2b9..834a6d8a 100644 --- a/src/server/InputPort.hpp +++ b/src/server/InputPort.hpp @@ -17,21 +17,28 @@ #ifndef INGEN_ENGINE_INPUTPORT_HPP #define INGEN_ENGINE_INPUTPORT_HPP -#include "ArcImpl.hpp" +#include "ArcImpl.hpp" // IWYU pragma: keep #include "PortImpl.hpp" #include "PortType.hpp" #include "types.hpp" -#include "ingen/types.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 raul { +class Symbol; +} // namespace raul + +namespace boost::intrusive { + +template <bool Enabled> struct constant_time_size; + +} // namespace boost::intrusive namespace ingen { @@ -59,7 +66,7 @@ class InputPort : public PortImpl public: InputPort(BufferFactory& bufs, BlockImpl* parent, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, uint32_t index, uint32_t poly, PortType type, @@ -72,9 +79,9 @@ public: boost::intrusive::constant_time_size<true>>; /** Return the maximum polyphony of an output connected to this input. */ - virtual uint32_t max_tail_poly(RunContext& context) const; + virtual uint32_t max_tail_poly(RunContext& ctx) const; - bool apply_poly(RunContext& context, uint32_t poly) override; + bool apply_poly(RunContext& ctx, uint32_t poly) override; /** Add an arc. Realtime safe. * @@ -83,7 +90,7 @@ public: * * setup_buffers() must be called later for the change to take effect. */ - void add_arc(RunContext& context, ArcImpl& c); + void add_arc(RunContext& ctx, ArcImpl& c); /** Remove an arc. Realtime safe. * @@ -97,21 +104,21 @@ public: * pre-process thread to allocate buffers for application of a * connection/disconnection/etc in the next process cycle. */ - bool pre_get_buffers(BufferFactory& bufs, - MPtr<Voices>& voices, - uint32_t poly) const; + bool pre_get_buffers(BufferFactory& bufs, + raul::managed_ptr<Voices>& voices, + uint32_t poly) const; bool setup_buffers(RunContext& ctx, BufferFactory& bufs, uint32_t poly) override; /** Set up buffer pointers. */ - void pre_process(RunContext& context) override; + void pre_process(RunContext& ctx) override; /** Prepare buffer for access, mixing if necessary. */ - void pre_run(RunContext& context) override; + void pre_run(RunContext& ctx) override; /** Prepare buffer for next process cycle. */ - void post_process(RunContext& context) override; + void post_process(RunContext& ctx) override; SampleCount next_value_offset(SampleCount offset, SampleCount end) const override; @@ -123,14 +130,14 @@ public: bool direct_connect() const; protected: - bool get_buffers(BufferFactory& bufs, - PortImpl::GetFn get, - const MPtr<Voices>& voices, - uint32_t poly, - size_t num_in_arcs) const override; - - size_t _num_arcs; ///< Pre-process thread - Arcs _arcs; ///< Audio thread + bool get_buffers(BufferFactory& bufs, + PortImpl::GetFn get, + const raul::managed_ptr<Voices>& voices, + uint32_t poly, + size_t num_in_arcs) const override; + + 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 3cea7698..68e1f3e8 100644 --- a/src/server/InternalBlock.cpp +++ b/src/server/InternalBlock.cpp @@ -26,12 +26,15 @@ #include "ingen/URIs.hpp" #include "raul/Array.hpp" +#include <boost/smart_ptr/intrusive_ptr.hpp> + #include <cstddef> #include <cstdint> +#include <memory> -namespace Raul { +namespace raul { class Symbol; -} // namespace Raul +} // namespace raul namespace ingen { @@ -43,7 +46,7 @@ class GraphImpl; class RunContext; InternalBlock::InternalBlock(PluginImpl* plugin, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool poly, GraphImpl* parent, SampleRate rate) @@ -52,7 +55,7 @@ InternalBlock::InternalBlock(PluginImpl* plugin, BlockImpl* InternalBlock::duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent) { BufferFactory& bufs = *engine.buffer_factory(); @@ -70,12 +73,12 @@ InternalBlock::duplicate(Engine& engine, } void -InternalBlock::pre_process(RunContext& context) +InternalBlock::pre_process(RunContext& ctx) { for (uint32_t i = 0; i < num_ports(); ++i) { PortImpl* const port = _ports->at(i); if (port->is_input()) { - port->pre_process(context); + port->pre_process(ctx); } else if (port->buffer_type() == _plugin->uris().atom_Sequence) { /* Output sequences are initialized in LV2 format, an atom:Chunk with size set to the capacity of the buffer. Internal nodes diff --git a/src/server/InternalBlock.hpp b/src/server/InternalBlock.hpp index e7f0ca95..9db7325a 100644 --- a/src/server/InternalBlock.hpp +++ b/src/server/InternalBlock.hpp @@ -18,9 +18,13 @@ #define INGEN_ENGINE_INTERNALBLOCK_HPP #include "BlockImpl.hpp" +#include "types.hpp" -namespace ingen { -namespace server { +namespace raul { +class Symbol; +} // namespace raul + +namespace ingen::server { class Engine; class GraphImpl; @@ -35,19 +39,18 @@ class InternalBlock : public BlockImpl { public: InternalBlock(PluginImpl* plugin, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool poly, GraphImpl* parent, SampleRate rate); BlockImpl* duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent) override; - void pre_process(RunContext& context) override; + 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 8d43a321..b2f2bae7 100644 --- a/src/server/InternalPlugin.cpp +++ b/src/server/InternalPlugin.cpp @@ -22,26 +22,26 @@ #include "internals/Note.hpp" #include "internals/Time.hpp" #include "internals/Trigger.hpp" +#include "types.hpp" #include "ingen/URIs.hpp" +#include "lilv/lilv.h" +#include "raul/Symbol.hpp" -namespace ingen { -namespace server { +#include <utility> -using namespace internals; +namespace ingen::server { -InternalPlugin::InternalPlugin(URIs& uris, - const URI& uri, - const Raul::Symbol& symbol) - : PluginImpl(uris, uris.ingen_Internal.urid, uri) - , _symbol(symbol) +InternalPlugin::InternalPlugin(URIs& uris, const URI& uri, raul::Symbol symbol) + : PluginImpl(uris, uris.ingen_Internal.urid_atom(), uri) + , _symbol(std::move(symbol)) { set_property(uris.rdf_type, uris.ingen_Internal); } BlockImpl* InternalPlugin::instantiate(BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, Engine& engine, @@ -50,19 +50,31 @@ InternalPlugin::instantiate(BufferFactory& bufs, const SampleCount srate = engine.sample_rate(); if (uri() == NS_INTERNALS "BlockDelay") { - return new BlockDelayNode(this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Controller") { - return new ControllerNode(this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Note") { - return new NoteNode(this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Time") { - return new TimeNode(this, bufs, symbol, polyphonic, parent, srate); - } else if (uri() == NS_INTERNALS "Trigger") { - return new TriggerNode(this, bufs, symbol, polyphonic, parent, srate); - } else { - return nullptr; + return new internals::BlockDelayNode( + this, bufs, symbol, polyphonic, parent, srate); } + + if (uri() == NS_INTERNALS "Controller") { + return new internals::ControllerNode( + this, bufs, symbol, polyphonic, parent, srate); + } + + if (uri() == NS_INTERNALS "Note") { + return new internals::NoteNode( + this, bufs, symbol, polyphonic, parent, srate); + } + + if (uri() == NS_INTERNALS "Time") { + return new internals::TimeNode( + this, bufs, symbol, polyphonic, parent, srate); + } + + if (uri() == NS_INTERNALS "Trigger") { + return new internals::TriggerNode( + this, bufs, symbol, polyphonic, parent, srate); + } + + return nullptr; } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/InternalPlugin.hpp b/src/server/InternalPlugin.hpp index d96ea86a..9dfabc5f 100644 --- a/src/server/InternalPlugin.hpp +++ b/src/server/InternalPlugin.hpp @@ -17,12 +17,12 @@ #ifndef INGEN_ENGINE_INTERNALPLUGIN_HPP #define INGEN_ENGINE_INTERNALPLUGIN_HPP +#include "PluginImpl.hpp" + #include "ingen/URI.hpp" #include "lilv/lilv.h" #include "raul/Symbol.hpp" -#include "PluginImpl.hpp" - #define NS_INTERNALS "http://drobilla.net/ns/ingen-internals#" namespace ingen { @@ -41,21 +41,19 @@ class GraphImpl; class InternalPlugin : public PluginImpl { public: - InternalPlugin(URIs& uris, - const URI& uri, - const Raul::Symbol& symbol); + InternalPlugin(URIs& uris, const URI& uri, raul::Symbol symbol); BlockImpl* instantiate(BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, Engine& engine, const LilvState* state) override; - Raul::Symbol symbol() const override { return _symbol; } + raul::Symbol symbol() const override { return _symbol; } private: - const Raul::Symbol _symbol; + const raul::Symbol _symbol; }; } // namespace server diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp index 6d15f3a8..d991879e 100644 --- a/src/server/JackDriver.cpp +++ b/src/server/JackDriver.cpp @@ -17,62 +17,55 @@ #include "JackDriver.hpp" #include "Buffer.hpp" +#include "BufferFactory.hpp" +#include "BufferRef.hpp" #include "DuplexPort.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" -#include "PortImpl.hpp" +#include "PortType.hpp" +#include "RunContext.hpp" #include "ThreadManager.hpp" #include "ingen_config.h" #include "util.hpp" +#include "ingen/Atom.hpp" #include "ingen/Configuration.hpp" -#include "ingen/LV2Features.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 "ingen/fmt.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/midiport.h> -#ifdef INGEN_JACK_SESSION -#include <jack/session.h> -#include "ingen/Serialiser.hpp" -#endif -#ifdef HAVE_JACK_METADATA -#include <jack/metadata.h> +#include <jack/transport.h> + +#if USE_JACK_METADATA #include "jackey.h" +#include <jack/metadata.h> #endif #include <cassert> #include <chrono> -#include <cstdlib> -#include <cstring> -#include <mutex> +#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) - , _sem(0) - , _flag(false) - , _client(nullptr) - , _block_length(0) - , _seq_size(0) - , _sample_rate(0) - , _is_activated(false) - , _old_bpm(120.0f) - , _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_feature()->urid_map); + lv2_atom_forge_init(&_forge, &engine.world().uri_map().urid_map()); } JackDriver::~JackDriver() @@ -88,17 +81,6 @@ JackDriver::attach(const std::string& server_name, { assert(!_client); if (!jack_client) { -#ifdef INGEN_JACK_SESSION - const std::string uuid = _engine.world().jack_uuid(); - if (!uuid.empty()) { - _client = jack_client_open(client_name.c_str(), - JackSessionID, nullptr, - uuid.c_str()); - _engine.log().info("Connected to Jack as `%1%' (UUID `%2%')\n", - client_name.c_str(), uuid); - } -#endif - // Try supplied server name if (!_client && !server_name.empty()) { if ((_client = jack_client_open(client_name.c_str(), @@ -108,7 +90,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))) { @@ -122,7 +104,7 @@ JackDriver::attach(const std::string& server_name, return false; } } else { - _client = (jack_client_t*)jack_client; + _client = static_cast<jack_client_t*>(jack_client); } _sample_rate = jack_get_sample_rate(_client); @@ -137,9 +119,6 @@ JackDriver::attach(const std::string& server_name, jack_set_thread_init_callback(_client, thread_init_cb, this); jack_set_buffer_size_callback(_client, block_length_cb, this); -#ifdef INGEN_JACK_SESSION - jack_set_session_callback(_client, session_cb, this); -#endif for (auto& p : _ports) { register_port(p); @@ -174,10 +153,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; } @@ -204,7 +183,7 @@ JackDriver::deactivate() } EnginePort* -JackDriver::get_port(const Raul::Path& path) +JackDriver::get_port(const raul::Path& path) { for (auto& p : _ports) { if (p.graph_port()->path() == path) { @@ -216,14 +195,14 @@ JackDriver::get_port(const Raul::Path& path) } void -JackDriver::add_port(RunContext& context, EnginePort* port) +JackDriver::add_port(RunContext& ctx, EnginePort* port) { _ports.push_back(*port); DuplexPort* graph_port = port->graph_port(); if (graph_port->is_a(PortType::AUDIO) || graph_port->is_a(PortType::CV)) { - const SampleCount nframes = context.nframes(); - jack_port_t* jport = (jack_port_t*)port->handle(); + const SampleCount nframes = ctx.nframes(); + auto* jport = static_cast<jack_port_t*>(port->handle()); void* jbuf = jack_port_get_buffer(jport, nframes); /* Jack fails to return a buffer if this is too soon after registering @@ -235,7 +214,7 @@ JackDriver::add_port(RunContext& context, EnginePort* port) } void -JackDriver::remove_port(RunContext& context, EnginePort* port) +JackDriver::remove_port(RunContext&, EnginePort* port) { _ports.erase(_ports.iterator_to(*port)); } @@ -267,7 +246,7 @@ JackDriver::register_port(EnginePort& port) void JackDriver::unregister_port(EnginePort& port) { - if (jack_port_unregister(_client, (jack_port_t*)port.handle())) { + if (jack_port_unregister(_client, static_cast<jack_port_t*>(port.handle()))) { _engine.log().error("Failed to unregister Jack port\n"); } @@ -275,14 +254,15 @@ JackDriver::unregister_port(EnginePort& port) } void -JackDriver::rename_port(const Raul::Path& old_path, - const Raul::Path& new_path) +JackDriver::rename_port(const raul::Path& old_path, + const raul::Path& new_path) { EnginePort* eport = get_port(old_path); if (eport) { -#ifdef HAVE_JACK_PORT_RENAME - jack_port_rename( - _client, (jack_port_t*)eport->handle(), new_path.substr(1).c_str()); +#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(), new_path.substr(1).c_str()); @@ -291,14 +271,16 @@ JackDriver::rename_port(const Raul::Path& old_path, } void -JackDriver::port_property(const Raul::Path& path, +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 jack_port_t* const jport = (const jack_port_t*)eport->handle(); + const auto* const jport = + static_cast<const jack_port_t*>(eport->handle()); + port_property_internal(jport, uri, value); } #endif @@ -309,7 +291,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"); @@ -348,11 +330,11 @@ JackDriver::create_port(DuplexPort* graph_port) } void -JackDriver::pre_process_port(RunContext& context, EnginePort* port) +JackDriver::pre_process_port(RunContext& ctx, EnginePort* port) { - const URIs& uris = context.engine().world().uris(); - const SampleCount nframes = context.nframes(); - jack_port_t* jack_port = (jack_port_t*)port->handle(); + const URIs& uris = ctx.engine().world().uris(); + const SampleCount nframes = ctx.nframes(); + auto* jack_port = static_cast<jack_port_t*>(port->handle()); DuplexPort* graph_port = port->graph_port(); Buffer* graph_buf = graph_port->buffer(0).get(); void* jack_buf = jack_port_get_buffer(jack_port, nframes); @@ -360,12 +342,12 @@ JackDriver::pre_process_port(RunContext& context, EnginePort* port) if (graph_port->is_a(PortType::AUDIO) || graph_port->is_a(PortType::CV)) { graph_port->set_driver_buffer(jack_buf, nframes * sizeof(float)); if (graph_port->is_input()) { - graph_port->monitor(context); + graph_port->monitor(ctx); } else { graph_port->buffer(0)->clear(); // TODO: Avoid when possible } } else if (graph_port->buffer_type() == uris.atom_Sequence) { - graph_buf->prepare_write(context); + graph_buf->prepare_write(ctx); if (graph_port->is_input()) { // Copy events from Jack port buffer into graph port buffer const jack_nframes_t event_count = jack_midi_get_event_count(jack_buf); @@ -378,16 +360,16 @@ JackDriver::pre_process_port(RunContext& context, EnginePort* port) } } } - graph_port->monitor(context); + graph_port->monitor(ctx); } } void -JackDriver::post_process_port(RunContext& context, EnginePort* port) +JackDriver::post_process_port(RunContext& ctx, EnginePort* port) const { - const URIs& uris = context.engine().world().uris(); - const SampleCount nframes = context.nframes(); - jack_port_t* jack_port = (jack_port_t*)port->handle(); + const URIs& uris = ctx.engine().world().uris(); + const SampleCount nframes = ctx.nframes(); + auto* jack_port = static_cast<jack_port_t*>(port->handle()); DuplexPort* graph_port = port->graph_port(); void* jack_buf = port->buffer(); @@ -400,13 +382,15 @@ JackDriver::post_process_port(RunContext& context, EnginePort* port) if (graph_port->buffer_type() == uris.atom_Sequence) { // Copy LV2 MIDI events to Jack MIDI buffer - Buffer* const graph_buf = graph_port->buffer(0).get(); - LV2_Atom_Sequence* seq = graph_buf->get<LV2_Atom_Sequence>(); + Buffer* const graph_buf = graph_port->buffer(0).get(); + auto* seq = graph_buf->get<LV2_Atom_Sequence>(); jack_midi_clear_buffer(jack_buf); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); - if (ev->body.type == _midi_event_type) { + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { + const auto* buf = + static_cast<const uint8_t*>(LV2_ATOM_BODY(&ev->body)); + + if (ev->body.type == this->_midi_event_type) { jack_midi_event_write( jack_buf, ev->time.frames, buf, ev->body.size); } @@ -421,10 +405,9 @@ JackDriver::post_process_port(RunContext& context, EnginePort* port) } void -JackDriver::append_time_events(RunContext& context, - Buffer& buffer) +JackDriver::append_time_events(RunContext& ctx, Buffer& buffer) { - const URIs& uris = context.engine().world().uris(); + const URIs& uris = ctx.engine().world().uris(); const jack_position_t* pos = &_position; const bool rolling = (_transport_state == JackTransportRolling); @@ -443,7 +426,10 @@ JackDriver::append_time_events(RunContext& context, // Build an LV2 position object to append to the buffer LV2_Atom pos_buf[16]; LV2_Atom_Forge_Frame frame; - lv2_atom_forge_set_buffer(&_forge, (uint8_t*)pos_buf, sizeof(pos_buf)); + lv2_atom_forge_set_buffer(&_forge, + reinterpret_cast<uint8_t*>(pos_buf), + sizeof(pos_buf)); + lv2_atom_forge_object(&_forge, &frame, 0, uris.time_Position); lv2_atom_forge_key(&_forge, uris.time_frame); lv2_atom_forge_long(&_forge, pos->frame); @@ -464,9 +450,11 @@ JackDriver::append_time_events(RunContext& context, } // Append position to buffer at offset 0 (start of this cycle) - LV2_Atom* lpos = (LV2_Atom*)pos_buf; - buffer.append_event( - 0, lpos->size, lpos->type, (const uint8_t*)LV2_ATOM_BODY_CONST(lpos)); + auto* lpos = static_cast<LV2_Atom*>(pos_buf); + buffer.append_event(0, + lpos->size, + lpos->type, + static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(lpos))); } /**** Jack Callbacks ****/ @@ -515,7 +503,7 @@ JackDriver::_process_cb(jack_nframes_t nframes) } void -JackDriver::_thread_init_cb() +JackDriver::thread_init_cb(void*) { ThreadManager::set_flag(THREAD_PROCESS); ThreadManager::set_flag(THREAD_IS_REAL_TIME); @@ -545,43 +533,4 @@ JackDriver::_block_length_cb(jack_nframes_t nframes) return 0; } -#ifdef INGEN_JACK_SESSION -void -JackDriver::_session_cb(jack_session_event_t* event) -{ - _engine.log().info("Jack session save to %1%\n", event->session_dir); - - const std::string cmd = fmt("ingen -eg -n %1% -u %2% -l ${SESSION_DIR}", - jack_get_client_name(_client), - event->client_uuid); - - SPtr<Serialiser> serialiser = _engine.world().serialiser(); - if (serialiser) { - std::lock_guard<std::mutex> lock(_engine.world().rdf_mutex()); - - SPtr<Node> root(_engine.root_graph(), NullDeleter<Node>); - serialiser->write_bundle(root, - URI(std::string("file://") + event->session_dir)); - } - - event->command_line = (char*)malloc(cmd.size() + 1); - memcpy(event->command_line, cmd.c_str(), cmd.size() + 1); - jack_session_reply(_client, event); - - switch (event->type) { - case JackSessionSave: - break; - case JackSessionSaveAndQuit: - _engine.log().warn("Jack session quit\n"); - _engine.quit(); - break; - case JackSessionSaveTemplate: - break; - } - - jack_session_event_free(event); -} -#endif - -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp index 00b1836a..8bb7cff3 100644 --- a/src/server/JackDriver.hpp +++ b/src/server/JackDriver.hpp @@ -18,35 +18,44 @@ #define INGEN_ENGINE_JACKAUDIODRIVER_HPP #include "Driver.hpp" -#include "EnginePort.hpp" -#include "ingen_config.h" +#include "EnginePort.hpp" // IWYU pragma: keep +#include "types.hpp" -#include "ingen/types.hpp" +#include "ingen/URI.hpp" +#include "ingen/memory.hpp" // IWYU pragma: keep #include "lv2/atom/forge.h" #include "raul/Semaphore.hpp" +#include <boost/intrusive/slist.hpp> #include <jack/jack.h> #include <jack/thread.h> -#include <jack/transport.h> -#ifdef INGEN_JACK_SESSION -#include <jack/session.h> -#endif +#include <jack/types.h> #include <atomic> #include <cstddef> #include <cstdint> +#include <exception> +#include <memory> #include <string> -namespace Raul { class Path; } +namespace raul { +class Path; +} // namespace raul + +namespace boost::intrusive { +template <bool Enabled> struct cache_last; +} // namespace boost::intrusive namespace ingen { + +class Atom; + namespace server { +class Buffer; class DuplexPort; class Engine; -class GraphImpl; -class JackDriver; -class PortImpl; +class RunContext; /** The Jack Driver. * @@ -60,7 +69,7 @@ class JackDriver : public Driver { public: explicit JackDriver(Engine& engine); - ~JackDriver(); + ~JackDriver() override; bool attach(const std::string& server_name, const std::string& client_name, @@ -72,21 +81,21 @@ public: bool dynamic_ports() const override { return true; } EnginePort* create_port(DuplexPort* graph_port) override; - EnginePort* get_port(const Raul::Path& path) override; + EnginePort* get_port(const raul::Path& path) override; - void rename_port(const Raul::Path& old_path, const Raul::Path& new_path) override; - void port_property(const Raul::Path& path, const URI& uri, const Atom& value) override; - void add_port(RunContext& context, EnginePort* port) override; - void remove_port(RunContext& context, EnginePort* port) override; + void rename_port(const raul::Path& old_path, const raul::Path& new_path) override; + void port_property(const raul::Path& path, const URI& uri, const Atom& value) override; + void add_port(RunContext& ctx, EnginePort* port) override; + void remove_port(RunContext& ctx, EnginePort* port) override; void register_port(EnginePort& port) override; void unregister_port(EnginePort& port) override; /** 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& context, Buffer& buffer) override; + void append_time_events(RunContext& ctx, Buffer& buffer) override; int real_time_priority() override { return jack_client_real_time_priority(_client); @@ -101,69 +110,65 @@ public: return _client ? jack_frame_time(_client) : 0; } - class PortRegistrationFailedException : public std::exception {}; + class PortRegistrationFailedException : public std::exception + {}; private: friend class JackPort; + static void thread_init_cb(void* jack_driver); + // Static JACK callbacks which call the non-static callbacks (methods) - inline static void thread_init_cb(void* const jack_driver) { - return ((JackDriver*)jack_driver)->_thread_init_cb(); - } - inline static void shutdown_cb(void* const jack_driver) { - return ((JackDriver*)jack_driver)->_shutdown_cb(); - } - inline static int process_cb(jack_nframes_t nframes, void* const jack_driver) { - return ((JackDriver*)jack_driver)->_process_cb(nframes); + + static void shutdown_cb(void* const jack_driver) { + return static_cast<JackDriver*>(jack_driver)->_shutdown_cb(); } - inline static int block_length_cb(jack_nframes_t nframes, void* const jack_driver) { - return ((JackDriver*)jack_driver)->_block_length_cb(nframes); + + static int process_cb(jack_nframes_t nframes, void* const jack_driver) { + return static_cast<JackDriver*>(jack_driver)->_process_cb(nframes); } -#ifdef INGEN_JACK_SESSION - inline static void session_cb(jack_session_event_t* event, void* jack_driver) { - ((JackDriver*)jack_driver)->_session_cb(event); + + static int block_length_cb(jack_nframes_t nframes, void* const jack_driver) { + return static_cast<JackDriver*>(jack_driver)->_block_length_cb(nframes); } -#endif - void pre_process_port(RunContext& context, EnginePort* port); - void post_process_port(RunContext& context, EnginePort* port); + // Internal methods for processing + + void pre_process_port(RunContext& ctx, EnginePort* port); + void post_process_port(RunContext& ctx, EnginePort* port) const; void port_property_internal(const jack_port_t* jport, const URI& uri, const Atom& value); // Non static callbacks (methods) - void _thread_init_cb(); void _shutdown_cb(); int _process_cb(jack_nframes_t nframes); int _block_length_cb(jack_nframes_t nframes); -#ifdef INGEN_JACK_SESSION - void _session_cb(jack_session_event_t* event); -#endif protected: using Ports = boost::intrusive::slist<EnginePort, boost::intrusive::cache_last<true>>; - using AudioBufPtr = UPtr<float, FreeDeleter<float>>; + 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; + raul::Semaphore _sem{0}; + std::atomic<bool> _flag{false}; + jack_client_t* _client{nullptr}; + jack_nframes_t _block_length{0}; + size_t _seq_size{0}; + jack_nframes_t _sample_rate{0}; uint32_t _midi_event_type; - bool _is_activated; - jack_position_t _position; - jack_transport_state_t _transport_state; - float _old_bpm; - jack_nframes_t _old_frame; - bool _old_rolling; + 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 124390ff..c5cd73dc 100644 --- a/src/server/LV2Block.cpp +++ b/src/server/LV2Block.cpp @@ -14,38 +14,50 @@ 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" +#include "PortType.hpp" #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 "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> #include <cmath> #include <cstdint> +#include <map> +#include <memory> #include <string> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { /** Partially construct a LV2Block. * @@ -53,13 +65,12 @@ namespace server { * (It _will_ crash!) */ LV2Block::LV2Block(LV2Plugin* plugin, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate) : BlockImpl(plugin, symbol, polyphonic, parent, srate) , _lv2_plugin(plugin) - , _worker_iface(nullptr) { assert(_lv2_plugin); } @@ -75,7 +86,7 @@ LV2Block::~LV2Block() drop_instances(_prepared_instances); } -SPtr<LV2Block::Instance> +std::shared_ptr<LV2Block::Instance> LV2Block::make_instance(URIs& uris, SampleRate rate, uint32_t voice, @@ -89,13 +100,13 @@ LV2Block::make_instance(URIs& uris, if (!inst) { engine.log().error("Failed to instantiate <%1%>\n", _lv2_plugin->uri().c_str()); - return SPtr<Instance>(); + return nullptr; } const LV2_Options_Interface* options_iface = nullptr; if (lilv_plugin_has_extension_data(lplug, uris.opt_interface)) { - options_iface = (const LV2_Options_Interface*) - lilv_instance_get_extension_data(inst, LV2_OPTIONS__interface); + options_iface = static_cast<const LV2_Options_Interface*>( + lilv_instance_get_extension_data(inst, LV2_OPTIONS__interface)); } for (uint32_t p = 0; p < num_ports(); ++p) { @@ -137,7 +148,7 @@ LV2Block::make_instance(URIs& uris, options_iface->get(inst->lv2_handle, options); if (options[0].value) { - LV2_URID type = *(const LV2_URID*)options[0].value; + LV2_URID type = *static_cast<const LV2_URID*>(options[0].value); if (type == _uris.lv2_ControlPort) { port->set_type(PortType::CONTROL, 0); } else if (type == _uris.lv2_CVPort) { @@ -147,7 +158,7 @@ LV2Block::make_instance(URIs& uris, "%1% auto-morphed to unknown type %2%\n", port->path().c_str(), type); - return SPtr<Instance>(); + return nullptr; } } else { parent_graph()->engine().log().error( @@ -177,9 +188,9 @@ LV2Block::prepare_poly(BufferFactory& bufs, uint32_t poly) const SampleRate rate = bufs.engine().sample_rate(); assert(!_prepared_instances); _prepared_instances = bufs.maid().make_managed<Instances>( - poly, *_instances, SPtr<Instance>()); + poly, *_instances, nullptr); for (uint32_t i = _polyphony; i < _prepared_instances->size(); ++i) { - SPtr<Instance> inst = make_instance(bufs.uris(), rate, i, true); + auto inst = make_instance(bufs.uris(), rate, i, true); if (!inst) { _prepared_instances.reset(); return false; @@ -196,7 +207,7 @@ LV2Block::prepare_poly(BufferFactory& bufs, uint32_t poly) } bool -LV2Block::apply_poly(RunContext& context, uint32_t poly) +LV2Block::apply_poly(RunContext& ctx, uint32_t poly) { if (!_polyphonic) { poly = 1; @@ -207,7 +218,7 @@ LV2Block::apply_poly(RunContext& context, uint32_t poly) } assert(poly <= _instances->size()); - return BlockImpl::apply_poly(context, poly); + return BlockImpl::apply_poly(ctx, poly); } /** Instantiate self from LV2 plugin descriptor. @@ -246,7 +257,7 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) /* LV2 port symbols are guaranteed to be unique, valid C identifiers, and Lilv guarantees that lilv_port_get_symbol() is valid. */ - const Raul::Symbol port_sym( + const raul::Symbol port_sym( lilv_node_as_string(lilv_port_get_symbol(plug, id))); // Get port type @@ -260,7 +271,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; @@ -291,7 +302,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( @@ -316,7 +327,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); @@ -336,10 +347,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); } } @@ -404,11 +415,11 @@ 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) { - const LilvNode* val = lilv_nodes_get(values, v); - if (lilv_node_is_uri(val)) { + 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])), - forge.make_urid(URI(lilv_node_as_uri(val)))); + forge.make_urid(URI(lilv_node_as_uri(value)))); } } lilv_nodes_free(values); @@ -435,7 +446,7 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) // Actually create plugin instances and port buffers. const SampleRate rate = bufs.engine().sample_rate(); _instances = bufs.maid().make_managed<Instances>( - _polyphony, SPtr<Instance>()); + _polyphony, nullptr); for (uint32_t i = 0; i < _polyphony; ++i) { _instances->at(i) = make_instance(bufs.uris(), rate, i, false); if (!_instances->at(i)) { @@ -444,9 +455,10 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) } // Load initial state if no state is explicitly given - LilvState* default_state = nullptr; + StatePtr default_state{}; if (!state) { - state = default_state = load_preset(_lv2_plugin->uri()); + default_state = load_preset(_lv2_plugin->uri()); + state = default_state.get(); } // Apply state @@ -454,15 +466,11 @@ LV2Block::instantiate(BufferFactory& bufs, const LilvState* state) apply_state(nullptr, state); } - if (default_state) { - lilv_state_free(default_state); - } - // FIXME: Polyphony + worker? if (lilv_plugin_has_feature(plug, uris.work_schedule)) { - _worker_iface = (const LV2_Worker_Interface*) + _worker_iface = static_cast<const LV2_Worker_Interface*>( lilv_instance_get_extension_data(instance(0), - LV2_WORKER__interface); + LV2_WORKER__interface)); } return ret; @@ -474,48 +482,62 @@ LV2Block::save_state(const FilePath& dir) const World& world = _lv2_plugin->world(); LilvWorld* lworld = world.lilv_world(); - LilvState* state = lilv_state_new_from_instance( - _lv2_plugin->lilv_plugin(), const_cast<LV2Block*>(this)->instance(0), - &world.uri_map().urid_map_feature()->urid_map, - nullptr, dir.c_str(), dir.c_str(), dir.c_str(), nullptr, nullptr, - LV2_STATE_IS_POD|LV2_STATE_IS_PORTABLE, nullptr); + const StatePtr state{ + lilv_state_new_from_instance(_lv2_plugin->lilv_plugin(), + const_cast<LV2Block*>(this)->instance(0), + &world.uri_map().urid_map(), + nullptr, + dir.c_str(), + dir.c_str(), + dir.c_str(), + nullptr, + nullptr, + LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE, + nullptr)}; if (!state) { return false; - } else if (lilv_state_get_num_properties(state) == 0) { - lilv_state_free(state); + } + + if (lilv_state_get_num_properties(state.get()) == 0) { return false; } lilv_state_save(lworld, - &world.uri_map().urid_map_feature()->urid_map, - &world.uri_map().urid_unmap_feature()->urid_unmap, - state, + &world.uri_map().urid_map(), + &world.uri_map().urid_unmap(), + state.get(), nullptr, dir.c_str(), "state.ttl"); - lilv_state_free(state); - return true; } BlockImpl* LV2Block::duplicate(Engine& engine, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, GraphImpl* parent) { const SampleRate rate = engine.sample_rate(); // Get current state - LilvState* state = lilv_state_new_from_instance( - _lv2_plugin->lilv_plugin(), instance(0), - &engine.world().uri_map().urid_map_feature()->urid_map, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, LV2_STATE_IS_NATIVE, nullptr); + const StatePtr state{ + lilv_state_new_from_instance(_lv2_plugin->lilv_plugin(), + instance(0), + &engine.world().uri_map().urid_map(), + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + LV2_STATE_IS_NATIVE, + nullptr)}; // Duplicate and instantiate block auto* dup = new LV2Block(_lv2_plugin, symbol, _polyphonic, parent, rate); - if (!dup->instantiate(*engine.buffer_factory(), state)) { + if (!dup->instantiate(*engine.buffer_factory(), state.get())) { delete dup; return nullptr; } @@ -558,7 +580,7 @@ LV2Block::work_respond(LV2_Worker_Respond_Handle handle, uint32_t size, const void* data) { - auto* block = (LV2Block*)handle; + auto* block = static_cast<LV2Block*>(handle); auto* r = new LV2Block::Response(size, data); block->_responses.push_back(*r); return LV2_WORKER_SUCCESS; @@ -568,10 +590,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); @@ -582,15 +604,15 @@ LV2Block::work(uint32_t size, const void* data) } void -LV2Block::run(RunContext& context) +LV2Block::run(RunContext& ctx) { for (uint32_t i = 0; i < _polyphony; ++i) { - lilv_instance_run(instance(i), context.nframes()); + lilv_instance_run(instance(i), ctx.nframes()); } } void -LV2Block::post_process(RunContext& context) +LV2Block::post_process(RunContext& ctx) { /* Handle any worker responses. Note that this may write to output ports, so must be done first to prevent clobbering worker responses and @@ -601,7 +623,7 @@ LV2Block::post_process(RunContext& context) Response& r = _responses.front(); _worker_iface->work_response(inst, r.size, r.data); _responses.pop_front(); - context.engine().maid()->dispose(&r); + ctx.engine().maid()->dispose(&r); } if (_worker_iface->end_run) { @@ -610,10 +632,10 @@ LV2Block::post_process(RunContext& context) } /* Run cycle truly finished, finalise output ports. */ - BlockImpl::post_process(context); + BlockImpl::post_process(ctx); } -LilvState* +StatePtr LV2Block::load_preset(const URI& uri) { World& world = _lv2_plugin->world(); @@ -624,35 +646,33 @@ LV2Block::load_preset(const URI& uri) lilv_world_load_resource(lworld, preset); // Load preset from world - LV2_URID_Map* map = &world.uri_map().urid_map_feature()->urid_map; - LilvState* state = lilv_state_new_from_world(lworld, map, preset); + LV2_URID_Map* map = &world.uri_map().urid_map(); + StatePtr state{lilv_state_new_from_world(lworld, map, preset)}; lilv_node_free(preset); return state; } -LilvState* +StatePtr LV2Block::load_state(World& world, const FilePath& path) { LilvWorld* lworld = world.lilv_world(); const URI uri = URI(path); LilvNode* subject = lilv_new_uri(lworld, uri.c_str()); - LilvState* state = lilv_state_new_from_file( - lworld, - &world.uri_map().urid_map_feature()->urid_map, - subject, - path.c_str()); + StatePtr state{lilv_state_new_from_file( + lworld, &world.uri_map().urid_map(), subject, path.c_str())}; lilv_node_free(subject); return state; } void -LV2Block::apply_state(const UPtr<Worker>& worker, const LilvState* state) +LV2Block::apply_state(const std::unique_ptr<Worker>& worker, + const LilvState* state) { - World& world = parent_graph()->engine().world(); - SPtr<LV2_Feature> sched; + World& world = parent_graph()->engine().world(); + std::shared_ptr<LV2_Feature> sched; if (worker) { sched = worker->schedule_feature()->feature(world, this); } @@ -673,7 +693,7 @@ get_port_value(const char* port_symbol, uint32_t* size, uint32_t* type) { - auto* const block = (LV2Block*)user_data; + auto* const block = static_cast<LV2Block*>(user_data); auto* const port = block->port_by_symbol(port_symbol); if (port && port->is_input() && port->value().is_valid()) { @@ -685,40 +705,46 @@ get_port_value(const char* port_symbol, return nullptr; } -boost::optional<Resource> +std::optional<Resource> LV2Block::save_preset(const URI& uri, const Properties& props) { World& world = parent_graph()->engine().world(); LilvWorld* lworld = world.lilv_world(); - LV2_URID_Map* lmap = &world.uri_map().urid_map_feature()->urid_map; - LV2_URID_Unmap* lunmap = &world.uri_map().urid_unmap_feature()->urid_unmap; + LV2_URID_Map* lmap = &world.uri_map().urid_map(); + LV2_URID_Unmap* lunmap = &world.uri_map().urid_unmap(); const FilePath path = FilePath(uri.path()); const FilePath dirname = path.parent_path(); const FilePath basename = path.stem(); - LilvState* 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, l->second.ptr<char>()); + lilv_state_set_label(state.get(), l->second.ptr<char>()); } - lilv_state_save(lworld, lmap, lunmap, state, nullptr, + lilv_state_save(lworld, lmap, lunmap, state.get(), nullptr, dirname.c_str(), basename.c_str()); - const URI uri(lilv_node_as_uri(lilv_state_get_uri(state))); - const std::string label(lilv_state_get_label(state) - ? lilv_state_get_label(state) - : basename); - lilv_state_free(state); + const URI state_uri(lilv_node_as_uri(lilv_state_get_uri(state.get()))); + const std::string label(lilv_state_get_label(state.get()) + ? lilv_state_get_label(state.get()) + : basename); - Resource preset(_uris, uri); + Resource preset(_uris, state_uri); preset.set_property(_uris.rdf_type, _uris.pset_Preset); preset.set_property(_uris.rdfs_label, world.forge().alloc(label)); preset.set_property(_uris.lv2_appliesTo, @@ -729,10 +755,10 @@ LV2Block::save_preset(const URI& uri, lilv_world_load_bundle(lworld, lbundle); lilv_node_free(lbundle); - return preset; + return {preset}; } - return boost::optional<Resource>(); + return {}; } void @@ -748,5 +774,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 9b454b07..fd446106 100644 --- a/src/server/LV2Block.hpp +++ b/src/server/LV2Block.hpp @@ -17,11 +17,14 @@ #ifndef INGEN_ENGINE_LV2BLOCK_HPP #define INGEN_ENGINE_LV2BLOCK_HPP -#include "BufferRef.hpp" #include "BlockImpl.hpp" +#include "BufferRef.hpp" +#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" @@ -29,19 +32,44 @@ #include "raul/Noncopyable.hpp" #include <boost/intrusive/slist.hpp> +#include <boost/intrusive/slist_hook.hpp> #include <cstdint> #include <cstdlib> #include <cstring> +#include <filesystem> +#include <memory> #include <mutex> +#include <optional> + +namespace raul { +class Symbol; +} // namespace raul + +namespace boost::intrusive { + +template <bool Enabled> +struct cache_last; + +template <bool Enabled> +struct constant_time_size; + +} // namespace boost::intrusive 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. * @@ -51,68 +79,67 @@ class LV2Block final : public BlockImpl { public: LV2Block(LV2Plugin* plugin, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate); - ~LV2Block(); + ~LV2Block() override; 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, + const raul::Symbol& symbol, GraphImpl* parent) override; bool prepare_poly(BufferFactory& bufs, uint32_t poly) override; - bool apply_poly(RunContext& context, uint32_t poly) override; + bool apply_poly(RunContext& ctx, uint32_t poly) override; void activate(BufferFactory& bufs) override; void deactivate() override; LV2_Worker_Status work(uint32_t size, const void* data); - void run(RunContext& context) override; - void post_process(RunContext& context) override; + void run(RunContext& ctx) override; + void post_process(RunContext& ctx) override; - LilvState* load_preset(const URI& uri) override; + StatePtr load_preset(const URI& uri) override; - void apply_state(const UPtr<Worker>& worker, const LilvState* state) override; + 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 LilvState* 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) {} + struct Instance : public raul::Noncopyable { + explicit Instance(LilvInstance* i) noexcept : instance(i) {} ~Instance() { lilv_instance_free(instance); } LilvInstance* const instance; }; - SPtr<Instance> make_instance(URIs& uris, - SampleRate rate, - uint32_t voice, - bool preparing); + std::shared_ptr<Instance> + make_instance(URIs& uris, SampleRate rate, uint32_t voice, bool preparing); inline LilvInstance* instance(uint32_t voice) { - return (LilvInstance*)(*_instances)[voice]->instance; + return static_cast<LilvInstance*>((*_instances)[voice]->instance); } - using Instances = Raul::Array<SPtr<Instance>>; + using Instances = raul::Array<std::shared_ptr<Instance>>; - void drop_instances(const MPtr<Instances>& instances) { + static void drop_instances(const raul::managed_ptr<Instances>& instances) { if (instances) { for (size_t i = 0; i < instances->size(); ++i) { (*instances)[i].reset(); @@ -120,18 +147,17 @@ protected: } } - struct Response : public Raul::Maid::Disposable - , public Raul::Noncopyable - , public boost::intrusive::slist_base_hook<> - { - inline Response(uint32_t s, const void* d) + struct Response : public raul::Maid::Disposable + , public raul::Noncopyable + , public boost::intrusive::slist_base_hook<> { + Response(uint32_t s, const void* d) : size(s) , data(malloc(s)) { memcpy(data, d, s); } - ~Response() { + ~Response() override { free(data); } @@ -147,13 +173,13 @@ protected: static LV2_Worker_Status work_respond( LV2_Worker_Respond_Handle handle, uint32_t size, const void* data); - LV2Plugin* _lv2_plugin; - MPtr<Instances> _instances; - MPtr<Instances> _prepared_instances; - const LV2_Worker_Interface* _worker_iface; - std::mutex _work_mutex; - Responses _responses; - SPtr<LV2Features::FeatureArray> _features; + LV2Plugin* _lv2_plugin; + raul::managed_ptr<Instances> _instances; + raul::managed_ptr<Instances> _prepared_instances; + const LV2_Worker_Interface* _worker_iface{nullptr}; + std::mutex _work_mutex; + Responses _responses; + std::shared_ptr<LV2Features::FeatureArray> _features; }; } // namespace server diff --git a/src/server/LV2Options.hpp b/src/server/LV2Options.hpp index fbe46eee..02824be6 100644 --- a/src/server/LV2Options.hpp +++ b/src/server/LV2Options.hpp @@ -19,12 +19,23 @@ #include "ingen/LV2Features.hpp" #include "ingen/URIs.hpp" +#include "lv2/core/lv2.h" #include "lv2/options/options.h" +#include <cstdint> +#include <cstdlib> +#include <cstring> +#include <memory> + namespace ingen { + +class Node; +class World; + namespace server { -class LV2Options : public ingen::LV2Features::Feature { +class LV2Options : public ingen::LV2Features::Feature +{ public: explicit LV2Options(const URIs& uris) : _uris(uris) @@ -38,7 +49,7 @@ public: const char* uri() const override { return LV2_OPTIONS__options; } - SPtr<LV2_Feature> feature(World& w, Node* n) override { + std::shared_ptr<LV2_Feature> feature(World& w, Node* n) override { const LV2_Options_Option options[] = { { LV2_OPTIONS_INSTANCE, 0, _uris.bufsz_minBlockLength, sizeof(int32_t), _uris.atom_Int, &_block_length }, @@ -51,18 +62,18 @@ public: { LV2_OPTIONS_INSTANCE, 0, 0, 0, 0, nullptr } }; - LV2_Feature* f = (LV2_Feature*)malloc(sizeof(LV2_Feature)); + auto* f = static_cast<LV2_Feature*>(malloc(sizeof(LV2_Feature))); f->URI = LV2_OPTIONS__options; f->data = malloc(sizeof(options)); memcpy(f->data, options, sizeof(options)); - return SPtr<LV2_Feature>(f, &free_feature); + return {f, &free_feature}; } private: const URIs& _uris; - int32_t _sample_rate; - int32_t _block_length; - int32_t _seq_size; + int32_t _sample_rate = 0; + int32_t _block_length = 0; + int32_t _seq_size = 0; }; } // namespace server diff --git a/src/server/LV2Plugin.cpp b/src/server/LV2Plugin.cpp index 01357d8d..1e88952e 100644 --- a/src/server/LV2Plugin.cpp +++ b/src/server/LV2Plugin.cpp @@ -23,16 +23,17 @@ #include "ingen/Log.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(), - world.uris().lv2_Plugin.urid, + world.uris().lv2_Plugin.urid_atom(), URI(lilv_node_as_uri(lilv_plugin_get_uri(lplugin)))) , _world(world) , _lilv_plugin(lplugin) @@ -65,7 +66,7 @@ LV2Plugin::update_properties() lilv_node_free(micro); } -Raul::Symbol +raul::Symbol LV2Plugin::symbol() const { std::string working = uri(); @@ -74,22 +75,22 @@ LV2Plugin::symbol() const } while (working.length() > 0) { - size_t last_slash = working.find_last_of('/'); + 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); + return raul::Symbol::symbolify(symbol); } + + working = working.substr(0, last_slash); } - return Raul::Symbol("lv2_symbol"); + return raul::Symbol("lv2_symbol"); } BlockImpl* LV2Plugin::instantiate(BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, Engine& engine, @@ -101,9 +102,9 @@ LV2Plugin::instantiate(BufferFactory& bufs, if (!b->instantiate(bufs, state)) { delete b; return nullptr; - } else { - return b; } + + return b; } void @@ -114,7 +115,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 +141,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 24d764cc..fa007327 100644 --- a/src/server/LV2Plugin.hpp +++ b/src/server/LV2Plugin.hpp @@ -42,13 +42,13 @@ public: LV2Plugin(World& world, const LilvPlugin* lplugin); BlockImpl* instantiate(BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, Engine& engine, const LilvState* state) override; - Raul::Symbol symbol() const override; + raul::Symbol symbol() const override; World& world() const { return _world; } const LilvPlugin* lilv_plugin() const { return _lilv_plugin; } diff --git a/src/server/LV2ResizeFeature.hpp b/src/server/LV2ResizeFeature.hpp index 1bd93ee0..485695d7 100644 --- a/src/server/LV2ResizeFeature.hpp +++ b/src/server/LV2ResizeFeature.hpp @@ -24,8 +24,9 @@ #include "ingen/LV2Features.hpp" #include "lv2/resize-port/resize-port.h" -namespace ingen { -namespace server { +#include <memory> + +namespace ingen::server { struct ResizeFeature : public ingen::LV2Features::Feature { static LV2_Resize_Port_Status resize_port( @@ -44,10 +45,11 @@ struct ResizeFeature : public ingen::LV2Features::Feature { const char* uri() const { return LV2_RESIZE_PORT_URI; } - SPtr<LV2_Feature> feature(World& w, Node* n) { + std::shared_ptr<LV2_Feature> feature(World& w, Node* n) { BlockImpl* block = dynamic_cast<BlockImpl*>(n); - if (!block) - return SPtr<LV2_Feature>(); + if (!block) { + return nullptr; + } LV2_Resize_Port_Resize* data = (LV2_Resize_Port_Resize*)malloc(sizeof(LV2_Resize_Port_Resize)); data->data = block; @@ -55,11 +57,10 @@ struct ResizeFeature : public ingen::LV2Features::Feature { LV2_Feature* f = (LV2_Feature*)malloc(sizeof(LV2_Feature)); f->URI = LV2_RESIZE_PORT_URI; f->data = data; - return SPtr<LV2_Feature>(f, &free_feature); + return std::shared_ptr<LV2_Feature>(f, &free_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 2d806684..c2f1f3df 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,7 +38,9 @@ struct Load mean = load; changed = true; } else { - const float a = mean + ((float)load - mean) / (float)++n; + const float a = mean + (static_cast<float>(load) - mean) / + static_cast<float>(++n); + if (a != mean) { changed = floorf(a) != floorf(mean); mean = a; @@ -55,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 47d4a990..c76c66d4 100644 --- a/src/server/NodeImpl.cpp +++ b/src/server/NodeImpl.cpp @@ -27,20 +27,16 @@ #include <map> #include <utility> -namespace Raul { class Symbol; } - -namespace ingen { -namespace server { +namespace ingen::server { NodeImpl::NodeImpl(const ingen::URIs& uris, NodeImpl* parent, - const Raul::Symbol& symbol) - : Node(uris, parent ? parent->path().child(symbol) : Raul::Path("/")) + const raul::Symbol& symbol) + : Node(uris, parent ? parent->path().child(symbol) : raul::Path("/")) , _parent(parent) - , _path(parent ? parent->path().child(symbol) : Raul::Path("/")) + , _path(parent ? parent->path().child(symbol) : raul::Path("/")) , _symbol(symbol) -{ -} +{} const Atom& NodeImpl::get_property(const URI& key) const @@ -54,8 +50,7 @@ NodeImpl::get_property(const URI& key) const GraphImpl* NodeImpl::parent_graph() const { - return dynamic_cast<GraphImpl*>((BlockImpl*)_parent); + 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 1b73e792..8acce161 100644 --- a/src/server/NodeImpl.hpp +++ b/src/server/NodeImpl.hpp @@ -38,7 +38,7 @@ class RunContext; /** An object on the audio graph (a Graph, Block, or Port). * - * Each of these is a Raul::Deletable and so can be deleted in a realtime safe + * Each of these is a raul::Deletable and so can be deleted in a realtime safe * way from anywhere, and they all have a map of variable for clients to store * arbitrary values in (which the engine puts no significance to whatsoever). * @@ -47,17 +47,17 @@ class RunContext; class NodeImpl : public Node { public: - const Raul::Symbol& symbol() const override { return _symbol; } + const raul::Symbol& symbol() const override { return _symbol; } Node* graph_parent() const override { return _parent; } NodeImpl* parent() const { return _parent; } /** Rename */ - void set_path(const Raul::Path& new_path) override { + void set_path(const raul::Path& new_path) override { _path = new_path; const char* const new_sym = new_path.symbol(); if (new_sym[0] != '\0') { - _symbol = Raul::Symbol(new_sym); + _symbol = raul::Symbol(new_sym); } set_uri(path_to_uri(new_path)); } @@ -67,7 +67,7 @@ public: /** The Graph this object is a child of. */ virtual GraphImpl* parent_graph() const; - const Raul::Path& path() const override { return _path; } + const raul::Path& path() const override { return _path; } /** Prepare for a new (external) polyphony value. * @@ -78,10 +78,10 @@ public: /** Apply a new (external) polyphony value. * - * \param context Process context (process thread only). + * \param ctx Process context (process thread only). * \param poly Must be <= the most recent value passed to prepare_poly. */ - virtual bool apply_poly(RunContext& context, uint32_t poly) = 0; + virtual bool apply_poly(RunContext& ctx, uint32_t poly) = 0; /** Return true iff this is main (the top level Node). * @@ -94,11 +94,11 @@ public: protected: NodeImpl(const ingen::URIs& uris, NodeImpl* parent, - const Raul::Symbol& symbol); + const raul::Symbol& symbol); NodeImpl* _parent; - Raul::Path _path; - Raul::Symbol _symbol; + raul::Path _path; + raul::Symbol _symbol; }; } // namespace server diff --git a/src/server/OutputPort.hpp b/src/server/OutputPort.hpp index 0437c367..61fb44f5 100644 --- a/src/server/OutputPort.hpp +++ b/src/server/OutputPort.hpp @@ -18,10 +18,26 @@ #define INGEN_ENGINE_OUTPUTPORT_HPP #include "PortImpl.hpp" +#include "PortType.hpp" + +#include "lv2/urid/urid.h" + +#include <cstddef> +#include <cstdint> + +namespace raul { +class Symbol; +} // namespace raul namespace ingen { + +class Atom; + namespace server { +class BlockImpl; +class BufferFactory; + /** An output port. * * Output ports always have a locally allocated buffer, and buffer() will @@ -34,7 +50,7 @@ class OutputPort : public PortImpl public: OutputPort(BufferFactory& bufs, BlockImpl* parent, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, uint32_t index, uint32_t poly, PortType type, diff --git a/src/server/PluginImpl.hpp b/src/server/PluginImpl.hpp index 3c93aa21..3184be11 100644 --- a/src/server/PluginImpl.hpp +++ b/src/server/PluginImpl.hpp @@ -17,10 +17,15 @@ #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 <cstdlib> +#include <map> +#include <string> +#include <utility> namespace ingen { @@ -43,19 +48,19 @@ 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; virtual BlockImpl* instantiate(BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, Engine& engine, const LilvState* state) = 0; - virtual Raul::Symbol symbol() const = 0; + virtual raul::Symbol symbol() const = 0; const Atom& type() const { return _type; } void set_type(const Atom& t) { _type = t; } @@ -82,12 +87,8 @@ public: protected: Atom _type; Presets _presets; - bool _presets_loaded; - bool _is_zombie; - -private: - PluginImpl(const PluginImpl&) = delete; - PluginImpl& operator=(const PluginImpl&) = delete; + bool _presets_loaded{false}; + bool _is_zombie{false}; }; } // namespace server diff --git a/src/server/PortAudioDriver.cpp b/src/server/PortAudioDriver.cpp index 38b04842..11bca592 100644 --- a/src/server/PortAudioDriver.cpp +++ b/src/server/PortAudioDriver.cpp @@ -14,10 +14,11 @@ 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" @@ -32,8 +33,7 @@ #include <cstring> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { static bool pa_error(const char* msg, PaError err) @@ -45,17 +45,10 @@ pa_error(const char* msg, PaError err) PortAudioDriver::PortAudioDriver(Engine& engine) : _engine(engine) - , _sem(0) - , _stream(nullptr) - , _seq_size(4096) + , _inputParameters() + , _outputParameters() , _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() { @@ -76,7 +69,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); } @@ -89,8 +84,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; } @@ -157,7 +151,7 @@ PortAudioDriver::frame_time() const } EnginePort* -PortAudioDriver::get_port(const Raul::Path& path) +PortAudioDriver::get_port(const raul::Path& path) { for (auto& p : _ports) { if (p.graph_port()->path() == path) { @@ -169,39 +163,35 @@ PortAudioDriver::get_port(const Raul::Path& path) } void -PortAudioDriver::add_port(RunContext& context, EnginePort* port) +PortAudioDriver::add_port(RunContext&, EnginePort* port) { _ports.push_back(*port); } void -PortAudioDriver::remove_port(RunContext& context, EnginePort* port) +PortAudioDriver::remove_port(RunContext&, EnginePort* port) { _ports.erase(_ports.iterator_to(*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) -{ -} +PortAudioDriver::rename_port(const raul::Path& old_path, + const raul::Path& new_path) +{} void -PortAudioDriver::port_property(const Raul::Path& path, +PortAudioDriver::port_property(const raul::Path& path, const URI& uri, const Atom& value) -{ -} +{} EnginePort* PortAudioDriver::create_port(DuplexPort* graph_port) @@ -233,7 +223,7 @@ PortAudioDriver::create_port(DuplexPort* graph_port) } void -PortAudioDriver::pre_process_port(RunContext& context, +PortAudioDriver::pre_process_port(RunContext&, EnginePort* port, const void* inputs, void* outputs) @@ -243,9 +233,14 @@ PortAudioDriver::pre_process_port(RunContext& context, } if (port->is_input()) { - port->set_buffer(((float**)inputs)[port->driver_index()]); + const auto* const* const ins = + static_cast<const float* const*>(inputs); + + port->set_buffer(const_cast<float*>(ins[port->driver_index()])); } else { - port->set_buffer(((float**)outputs)[port->driver_index()]); + auto* const* const outs = static_cast<float* const*>(inputs); + + port->set_buffer(outs[port->driver_index()]); memset(port->buffer(), 0, _block_length * sizeof(float)); } @@ -254,12 +249,11 @@ PortAudioDriver::pre_process_port(RunContext& context, } void -PortAudioDriver::post_process_port(RunContext& context, +PortAudioDriver::post_process_port(RunContext&, EnginePort* port, const void* inputs, void* outputs) -{ -} +{} int PortAudioDriver::process_cb(const void* inputs, @@ -287,5 +281,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 679223ad..9f17a100 100644 --- a/src/server/PortAudioDriver.hpp +++ b/src/server/PortAudioDriver.hpp @@ -18,14 +18,13 @@ #define INGEN_ENGINE_PORTAUDIODRIVER_HPP #include "Driver.hpp" -#include "EnginePort.hpp" -#include "ingen_config.h" +#include "EnginePort.hpp" // IWYU pragma: keep #include "types.hpp" #include "ingen/URI.hpp" -#include "lv2/atom/forge.h" #include "raul/Semaphore.hpp" +#include <boost/intrusive/slist.hpp> #include <portaudio.h> #include <atomic> @@ -33,7 +32,16 @@ #include <cstdint> #include <memory> -namespace Raul { class Path; } +namespace raul { +class Path; +} // namespace raul + +namespace boost::intrusive { + +template <bool Enabled> +struct cache_last; + +} // namespace boost::intrusive namespace ingen { @@ -51,7 +59,7 @@ class PortAudioDriver : public Driver { public: explicit PortAudioDriver(Engine& engine); - ~PortAudioDriver(); + ~PortAudioDriver() override; bool attach(); @@ -59,16 +67,16 @@ public: void deactivate() override; EnginePort* create_port(DuplexPort* graph_port) override; - EnginePort* get_port(const Raul::Path& path) override; + EnginePort* get_port(const raul::Path& path) override; - void rename_port(const Raul::Path& old_path, const Raul::Path& new_path) override; - void port_property(const Raul::Path& path, const URI& uri, const Atom& value) override; - void add_port(RunContext& context, EnginePort* port) override; - void remove_port(RunContext& context, EnginePort* port) override; + void rename_port(const raul::Path& old_path, const raul::Path& new_path) override; + void port_property(const raul::Path& path, const URI& uri, const Atom& value) override; + void add_port(RunContext& ctx, EnginePort* port) override; + void remove_port(RunContext& ctx, EnginePort* port) override; void register_port(EnginePort& port) override; void unregister_port(EnginePort& port) override; - void append_time_events(RunContext& context, Buffer& buffer) override {} + void append_time_events(RunContext& ctx, Buffer& buffer) override {} SampleCount frame_time() const override; @@ -81,15 +89,15 @@ public: 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) { - return ((PortAudioDriver*)handle)->process_cb( - inputs, outputs, nframes, time, flags); + 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); } int process_cb(const void* inputs, @@ -98,12 +106,12 @@ private: const PaStreamCallbackTimeInfo* time, PaStreamCallbackFlags flags); - void pre_process_port(RunContext& context, + void pre_process_port(RunContext& ctx, EnginePort* port, const void* inputs, void* outputs); - void post_process_port(RunContext& context, + void post_process_port(RunContext& ctx, EnginePort* port, const void* inputs, void* outputs); @@ -116,16 +124,16 @@ protected: Ports _ports; PaStreamParameters _inputParameters; PaStreamParameters _outputParameters; - Raul::Semaphore _sem; + raul::Semaphore _sem{0}; std::unique_ptr<FrameTimer> _timer; - PaStream* _stream; - size_t _seq_size; + PaStream* _stream{nullptr}; + size_t _seq_size{4096}; 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{48000}; + uint32_t _n_inputs{0}; + uint32_t _n_outputs{0}; + std::atomic<bool> _flag{false}; + bool _is_activated{false}; }; } // namespace server diff --git a/src/server/PortImpl.cpp b/src/server/PortImpl.cpp index 5161750d..c7b20f2b 100644 --- a/src/server/PortImpl.cpp +++ b/src/server/PortImpl.cpp @@ -24,21 +24,25 @@ #include "ThreadManager.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> #include <cstdio> +#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 @@ -50,7 +54,7 @@ monitor_period(const Engine& engine) PortImpl::PortImpl(BufferFactory& bufs, BlockImpl* const block, - const Raul::Symbol& name, + const raul::Symbol& name, uint32_t index, uint32_t poly, PortType type, @@ -63,24 +67,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); @@ -91,7 +83,7 @@ PortImpl::PortImpl(BufferFactory& bufs, set_type(type, buffer_type); remove_property(uris.lv2_index, uris.patch_wildcard); - set_property(uris.lv2_index, bufs.forge().make((int32_t)index)); + set_property(uris.lv2_index, bufs.forge().make(static_cast<int32_t>(index))); if (has_value()) { set_property(uris.ingen_value, value); @@ -103,7 +95,8 @@ PortImpl::PortImpl(BufferFactory& bufs, if (is_output) { if (_parent->graph_type() != Node::GraphType::GRAPH) { - add_property(bufs.uris().rdf_type, bufs.uris().lv2_OutputPort.urid); + add_property(bufs.uris().rdf_type, + bufs.uris().lv2_OutputPort.urid_atom()); } } @@ -111,10 +104,10 @@ PortImpl::PortImpl(BufferFactory& bufs, } bool -PortImpl::get_buffers(BufferFactory& bufs, - GetFn get, - const MPtr<Voices>& voices, - uint32_t poly, +PortImpl::get_buffers(BufferFactory& bufs, + GetFn get, + const raul::managed_ptr<Voices>& voices, + uint32_t poly, size_t) const { for (uint32_t v = 0; v < poly; ++v) { @@ -211,7 +204,7 @@ PortImpl::deactivate() } void -PortImpl::set_voices(RunContext&, MPtr<Voices>&& voices) +PortImpl::set_voices(RunContext&, raul::managed_ptr<Voices>&& voices) { _voices = std::move(voices); connect_buffers(); @@ -229,18 +222,18 @@ PortImpl::cache_properties() } void -PortImpl::set_control_value(const RunContext& context, +PortImpl::set_control_value(const RunContext& ctx, FrameTime time, Sample value) { for (uint32_t v = 0; v < _poly; ++v) { - update_set_state(context, v); - set_voice_value(context, v, time, value); + update_set_state(ctx, v); + set_voice_value(ctx, v, time, value); } } void -PortImpl::set_voice_value(const RunContext& context, +PortImpl::set_voice_value(const RunContext& ctx, uint32_t voice, FrameTime time, Sample value) @@ -248,37 +241,39 @@ PortImpl::set_voice_value(const RunContext& context, switch (_type.id()) { case PortType::CONTROL: if (buffer(voice)->value()) { - ((LV2_Atom_Float*)buffer(voice)->value())->body = value; + const_cast<LV2_Atom_Float*>( + reinterpret_cast<const LV2_Atom_Float*>(buffer(voice)->value())) + ->body = value; } - _voices->at(voice).set_state.set(context, context.start(), value); + _voices->at(voice).set_state.set(ctx, ctx.start(), value); break; case PortType::AUDIO: case PortType::CV: { // Time may be at end so internal blocks can set triggers - assert(time >= context.start()); - assert(time <= context.start() + context.nframes()); + assert(time >= ctx.start()); + assert(time <= ctx.start() + ctx.nframes()); - const FrameTime offset = time - context.start(); - if (offset < context.nframes()) { - buffer(voice)->set_block(value, offset, context.nframes()); + const FrameTime offset = time - ctx.start(); + if (offset < ctx.nframes()) { + buffer(voice)->set_block(value, offset, ctx.nframes()); } /* else, this is a set at context.nframes(), used to reset a CV port's value for the next block, particularly for triggers on the last frame of a block (set nframes-1 to 1, then nframes to 0). */ - _voices->at(voice).set_state.set(context, time, value); + _voices->at(voice).set_state.set(ctx, time, value); } break; case PortType::ATOM: if (buffer(voice)->is_sequence()) { - const FrameTime offset = time - context.start(); + const FrameTime offset = time - ctx.start(); // Same deal as above - if (offset < context.nframes()) { + if (offset < ctx.nframes()) { buffer(voice)->append_event(offset, sizeof(value), _bufs.uris().atom_Float, - (const uint8_t*)&value); + reinterpret_cast<const uint8_t*>(&value)); } - _voices->at(voice).set_state.set(context, time, value); + _voices->at(voice).set_state.set(ctx, time, value); } else { #ifndef NDEBUG fprintf(stderr, @@ -286,27 +281,28 @@ PortImpl::set_voice_value(const RunContext& context, path().c_str(), buffer(voice)->type()); #endif } + break; default: break; } } void -PortImpl::update_set_state(const RunContext& context, uint32_t v) +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; case SetState::State::SET_CYCLE_1: - if (state.time < context.start() && + if (state.time < ctx.start() && buf->is_sequence() && buf->value_type() == _bufs.uris().atom_Float && !_parent->is_main()) { buf->clear(); - state.time = context.start(); + state.time = ctx.start(); } state.state = SetState::State::SET; break; @@ -318,9 +314,9 @@ PortImpl::update_set_state(const RunContext& context, uint32_t v) buf->clear(); buf->append_event( 0, sizeof(float), _bufs.uris().atom_Float, - (const uint8_t*)&state.value); + reinterpret_cast<const uint8_t*>(&state.value)); } else { - buf->set_block(state.value, 0, context.nframes()); + buf->set_block(state.value, 0, ctx.nframes()); } state.state = SetState::State::SET_CYCLE_1; break; @@ -334,9 +330,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(); } @@ -352,12 +352,14 @@ PortImpl::prepare_poly(BufferFactory& bufs, uint32_t poly) } bool -PortImpl::apply_poly(RunContext& context, uint32_t poly) +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; } @@ -369,7 +371,7 @@ PortImpl::apply_poly(RunContext& context, uint32_t poly) _voices = std::move(_prepared_voices); if (is_a(PortType::CONTROL) || is_a(PortType::CV)) { - set_control_value(context, context.start(), _value.get<float>()); + set_control_value(ctx, ctx.start(), _value.get<float>()); } assert(_voices->size() >= poly); @@ -441,14 +443,14 @@ PortImpl::clear_buffers(const RunContext& ctx) } void -PortImpl::monitor(RunContext& context, bool send_now) +PortImpl::monitor(RunContext& ctx, bool send_now) { - if (!context.must_notify(this)) { + if (!ctx.must_notify(this)) { return; } - const uint32_t period = monitor_period(context.engine()); - _frames_since_monitor += context.nframes(); + const uint32_t period = monitor_period(ctx.engine()); + _frames_since_monitor += ctx.nframes(); const bool time_to_send = send_now || _frames_since_monitor >= period; const bool is_sequence = (_type.id() == PortType::ATOM && @@ -457,16 +459,16 @@ PortImpl::monitor(RunContext& context, bool send_now) return; } - Forge& forge = context.engine().world().forge(); - URIs& uris = context.engine().world().uris(); - LV2_URID key = 0; - float val = 0.0f; + const Forge& forge = ctx.engine().world().forge(); + const URIs& uris = ctx.engine().world().uris(); + LV2_URID key = 0; + float val = 0.0f; switch (_type.id()) { case PortType::UNKNOWN: break; case PortType::AUDIO: key = uris.ingen_activity; - val = _peak = std::max(_peak, buffer(0)->peak(context)); + val = _peak = std::max(_peak, buffer(0)->peak(ctx)); break; case PortType::CONTROL: case PortType::CV: @@ -482,28 +484,28 @@ PortImpl::monitor(RunContext& context, bool send_now) uninitialized Chunk, so do nothing. */ } else if (_monitored) { /* Sequence explicitly monitored, send everything. */ - const auto* seq = (const LV2_Atom_Sequence*)atom; - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - context.notify(uris.ingen_activity, - context.start() + ev->time.frames, - this, - ev->body.size, - ev->body.type, - LV2_ATOM_BODY(&ev->body)); + const auto* seq = reinterpret_cast<const LV2_Atom_Sequence*>(atom); + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { + ctx.notify(uris.ingen_activity, + ctx.start() + ev->time.frames, + this, + ev->body.size, + ev->body.type, + LV2_ATOM_BODY(&ev->body)); } } else if (value && value->type == _bufs.uris().atom_Float) { /* Float sequence, monitor as a control. */ key = uris.ingen_value; - val = ((LV2_Atom_Float*)buffer(0)->value())->body; + val = reinterpret_cast<const LV2_Atom_Float*>(buffer(0)->value())->body; } else if (atom->size > sizeof(LV2_Atom_Sequence_Body)) { /* General sequence, send activity for blinkenlights. */ const int32_t one = 1; - context.notify(uris.ingen_activity, - context.start(), - this, - sizeof(int32_t), - (LV2_URID)uris.atom_Bool, - &one); + ctx.notify(uris.ingen_activity, + ctx.start(), + this, + sizeof(int32_t), + static_cast<LV2_URID>(uris.atom_Bool), + &one); _force_monitor_update = false; } } @@ -511,8 +513,7 @@ PortImpl::monitor(RunContext& context, bool send_now) _frames_since_monitor = _frames_since_monitor % period; if (key && val != _monitor_value) { - if (context.notify(key, context.start(), this, - sizeof(float), forge.Float, &val)) { + if (ctx.notify(key, ctx.start(), this, sizeof(float), forge.Float, &val)) { /* Update frames since last update to conceptually zero, but keep the remainder to preserve load balancing. */ _frames_since_monitor = _frames_since_monitor % period; @@ -524,7 +525,7 @@ PortImpl::monitor(RunContext& context, bool send_now) } BufferRef -PortImpl::value_buffer(uint32_t voice) +PortImpl::value_buffer(uint32_t voice) const { return buffer(voice)->value_buffer(); } @@ -543,34 +544,37 @@ PortImpl::next_value_offset(SampleCount offset, SampleCount end) const } void -PortImpl::update_values(SampleCount offset, uint32_t voice) +PortImpl::update_values(SampleCount offset, uint32_t voice) const { buffer(voice)->update_value_buffer(offset); } void -PortImpl::pre_process(RunContext& context) +PortImpl::pre_process(RunContext& ctx) { if (!_connected_flag.test_and_set(std::memory_order_acquire)) { connect_buffers(); - clear_buffers(context); + clear_buffers(ctx); } for (uint32_t v = 0; v < _poly; ++v) { - _voices->at(v).buffer->prepare_output_write(context); + _voices->at(v).buffer->prepare_output_write(ctx); } } void -PortImpl::post_process(RunContext& context) +PortImpl::pre_run(RunContext&) +{} + +void +PortImpl::post_process(RunContext& ctx) { for (uint32_t v = 0; v < _poly; ++v) { - update_set_state(context, v); + update_set_state(ctx, v); update_values(0, v); } - monitor(context); + monitor(ctx); } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/PortImpl.hpp b/src/server/PortImpl.hpp index 5392d9b7..64c3322f 100644 --- a/src/server/PortImpl.hpp +++ b/src/server/PortImpl.hpp @@ -17,20 +17,33 @@ #ifndef INGEN_ENGINE_PORTIMPL_HPP #define INGEN_ENGINE_PORTIMPL_HPP +#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/URIs.hpp" +#include "lv2/urid/urid.h" #include "raul/Array.hpp" +#include "raul/Maid.hpp" #include <atomic> #include <cstdint> #include <cstdlib> +#include <utility> + +namespace raul { +class Symbol; +} // namespace raul namespace ingen { + +class Properties; + namespace server { class BlockImpl; @@ -43,7 +56,7 @@ class BlockImpl; * * \ingroup engine */ -class INGEN_API PortImpl : public NodeImpl +class INGEN_SERVER_API PortImpl : public NodeImpl { public: struct SetState { @@ -61,33 +74,31 @@ public: SET }; - SetState() : state(State::SET), value(0), time(0) {} + SetState() = default; - void set(const RunContext& context, FrameTime t, Sample v) { + void set(const RunContext& ctx, FrameTime t, Sample v) { time = t; value = v; - state = (time == context.start() + state = (time == ctx.start() ? State::SET : State::HALF_SET_CYCLE_1); } - State state; ///< State of buffer for setting control value - Sample value; ///< Value currently being set - FrameTime time; ///< Time value was set + State state = State::SET; ///< State for setting control value + Sample value = 0; ///< Value currently being set + FrameTime time = 0; ///< Time value was set }; struct Voice { - Voice() : buffer(nullptr) {} - SetState set_state; - BufferRef buffer; + BufferRef buffer{nullptr}; }; - using Voices = Raul::Array<Voice>; + using Voices = raul::Array<Voice>; PortImpl(BufferFactory& bufs, BlockImpl* block, - const Raul::Symbol& name, + const raul::Symbol& name, uint32_t index, uint32_t poly, PortType type, @@ -99,10 +110,10 @@ public: GraphType graph_type() const override { return GraphType::PORT; } /** A port's parent is always a block, so static cast should be safe */ - BlockImpl* parent_block() const { return (BlockImpl*)_parent; } + BlockImpl* parent_block() const { return reinterpret_cast<BlockImpl*>(_parent); } /** Set the the voices (buffers) for this port in the audio thread. */ - void set_voices(RunContext& context, MPtr<Voices>&& voices); + void set_voices(RunContext& ctx, raul::managed_ptr<Voices>&& voices); /** Prepare for a new (external) polyphony value. * @@ -115,7 +126,7 @@ public: * Audio thread. * \a poly Must be < the most recent value passed to prepare_poly. */ - bool apply_poly(RunContext& context, uint32_t poly) override; + bool apply_poly(RunContext& ctx, uint32_t poly) override; /** Return the number of arcs (pre-process thraed). */ virtual size_t num_arcs() const { return 0; } @@ -133,21 +144,22 @@ 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; } - void update_set_state(const RunContext& context, uint32_t v); + void update_set_state(const RunContext& ctx, uint32_t v); - void set_voice_value(const RunContext& context, + void set_voice_value(const RunContext& ctx, uint32_t voice, FrameTime time, Sample value); - void set_control_value(const RunContext& context, + void set_control_value(const RunContext& ctx, FrameTime time, Sample value); @@ -164,9 +176,9 @@ public: bool is_driver_port() const { return _is_driver_port; } /** Called once per process cycle */ - virtual void pre_process(RunContext& context); - virtual void pre_run(RunContext& context) {} - virtual void post_process(RunContext& context); + virtual void pre_process(RunContext& ctx); + virtual void pre_run(RunContext& ctx); + virtual void post_process(RunContext& ctx); /** Clear/silence all buffers */ virtual void clear_buffers(const RunContext& ctx); @@ -193,7 +205,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; @@ -212,7 +224,7 @@ public: return (_prepared_voices) ? _prepared_voices->size() : 1; } - void set_buffer_size(RunContext& context, BufferFactory& bufs, size_t size); + void set_buffer_size(RunContext& ctx, BufferFactory& bufs, size_t size); /** Return true iff this port is explicitly monitored. * @@ -226,21 +238,25 @@ public: void enable_monitoring(bool monitored) { _monitored = monitored; } /** Monitor port value and broadcast to clients periodically. */ - void monitor(RunContext& context, bool send_now=false); + void monitor(RunContext& ctx, bool send_now=false); BufferFactory& bufs() const { return _bufs; } - BufferRef value_buffer(uint32_t voice); + BufferRef value_buffer(uint32_t voice) const; BufferRef user_buffer(RunContext&) const { return _user_buffer; } - void set_user_buffer(RunContext&, BufferRef b) { _user_buffer = b; } + + void set_user_buffer(RunContext&, BufferRef b) + { + _user_buffer = std::move(b); + } /** Return offset of the first value change after `offset`. */ virtual SampleCount next_value_offset(SampleCount offset, SampleCount end) const; /** Update value buffer for `voice` to be current as of `offset`. */ - void update_values(SampleCount offset, uint32_t voice); + void update_values(SampleCount offset, uint32_t voice) const; void force_monitor_update() { _force_monitor_update = true; } @@ -262,7 +278,7 @@ public: bool is_toggled() const { return _is_toggled; } protected: - typedef BufferRef (BufferFactory::*GetFn)(LV2_URID, LV2_URID, uint32_t); + using GetFn = BufferRef (BufferFactory::*)(LV2_URID, LV2_URID, uint32_t); /** Set `voices` as the buffers to be used for this port. * @@ -271,37 +287,37 @@ protected: * * @return true iff buffers are locally owned by the port */ - virtual bool get_buffers(BufferFactory& bufs, - GetFn get, - const MPtr<Voices>& voices, - uint32_t poly, - size_t num_in_arcs) const; - - BufferFactory& _bufs; - uint32_t _index; - uint32_t _poly; - uint32_t _buffer_size; - uint32_t _frames_since_monitor; - float _monitor_value; - float _peak; - PortType _type; - LV2_URID _buffer_type; - Atom _value; - Atom _min; - Atom _max; - MPtr<Voices> _voices; - MPtr<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; - bool _is_output; + virtual bool get_buffers(BufferFactory& bufs, + GetFn get, + const raul::managed_ptr<Voices>& voices, + uint32_t poly, + size_t num_in_arcs) const; + + BufferFactory& _bufs; + uint32_t _index; + uint32_t _poly; + uint32_t _buffer_size; + uint32_t _frames_since_monitor{0}; + float _monitor_value{0.0f}; + float _peak{0.0f}; + PortType _type; + LV2_URID _buffer_type; + Atom _value; + Atom _min; + Atom _max; + raul::managed_ptr<Voices> _voices; + raul::managed_ptr<Voices> _prepared_voices; + BufferRef _user_buffer; + 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; }; } // namespace server diff --git a/src/server/PortType.hpp b/src/server/PortType.hpp index c711ad79..65f87d02 100644 --- a/src/server/PortType.hpp +++ b/src/server/PortType.hpp @@ -17,6 +17,8 @@ #ifndef INGEN_INTERFACE_PORTTYPE_HPP #define INGEN_INTERFACE_PORTTYPE_HPP +#include "ingen/URI.hpp" + #include "lv2/atom/atom.h" #include "lv2/core/lv2.h" @@ -30,7 +32,8 @@ namespace ingen { * of its contents). Ports with different types can contain the same type of * data, but may e.g. have different access semantics. */ -class PortType { +class PortType +{ public: enum ID { UNKNOWN = 0, @@ -54,24 +57,24 @@ public: } } - PortType(ID id) : _id(id) {} + PortType(ID id) noexcept : _id(id) {} - inline const URI& uri() const { return type_uri(_id); } - inline ID id() const { return _id; } + const URI& uri() const { return type_uri(_id); } + 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); } + bool operator==(const ID& id) const { return (_id == id); } + bool operator!=(const ID& id) const { return (_id != id); } + bool operator==(const PortType& type) const { return (_id == type._id); } + bool operator!=(const PortType& type) const { return (_id != type._id); } + 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; } + bool is_audio() { return _id == AUDIO; } + bool is_control() { return _id == CONTROL; } + bool is_cv() { return _id == CV; } + bool is_atom() { return _id == ATOM; } private: - static inline const URI& type_uri(unsigned id_num) { + static const URI& type_uri(unsigned id_num) { assert(id_num <= ATOM); static const URI uris[] = { URI("http://www.w3.org/2002/07/owl#Nothing"), diff --git a/src/server/PostProcessor.cpp b/src/server/PostProcessor.cpp index 5a0a8f3e..a97fc451 100644 --- a/src/server/PostProcessor.cpp +++ b/src/server/PostProcessor.cpp @@ -21,14 +21,14 @@ #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 +40,7 @@ PostProcessor::PostProcessor(Engine& engine) , _head(new Sentinel(engine)) , _tail(_head.load()) , _max_time(0) -{ -} +{} PostProcessor::~PostProcessor() { @@ -99,7 +98,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 +111,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 2733b209..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); @@ -50,7 +48,7 @@ public: /** Push a list of events on to the process queue. realtime-safe, not thread-safe. */ - void append(RunContext& context, Event* first, Event* last); + void append(RunContext& ctx, Event* first, Event* last); /** Post-process and delete all pending events */ void process(); @@ -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 7579e1e2..7c97af3c 100644 --- a/src/server/PreProcessContext.hpp +++ b/src/server/PreProcessContext.hpp @@ -20,12 +20,10 @@ #include "CompiledGraph.hpp" #include "GraphImpl.hpp" +#include <memory> #include <unordered_set> -namespace Raul { class Maid; } - -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,11 +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. */ - MPtr<CompiledGraph> maybe_compile(Raul::Maid& maid, GraphImpl& graph) { - if (must_compile(graph)) { - return compile(maid, graph); - } - return MPtr<CompiledGraph>(); + [[nodiscard]] std::unique_ptr<CompiledGraph> maybe_compile(GraphImpl& graph) + { + return must_compile(graph) ? compile(graph) : nullptr; } /** Return all graphs that require compilation after an atomic bundle. */ @@ -79,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 61a3598e..f9d7ecb3 100644 --- a/src/server/PreProcessor.cpp +++ b/src/server/PreProcessor.cpp @@ -28,22 +28,17 @@ #include "ingen/AtomWriter.hpp" #include "ingen/Configuration.hpp" #include "ingen/World.hpp" +#include "raul/Semaphore.hpp" #include <cassert> #include <cstdint> #include <cstdio> #include <memory> -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 +56,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()); @@ -82,7 +77,7 @@ PreProcessor::event(Event* const ev, Event::Mode mode) } unsigned -PreProcessor::process(RunContext& context, PostProcessor& dest, size_t limit) +PreProcessor::process(RunContext& ctx, PostProcessor& dest, size_t limit) { Event* const head = _head.load(); size_t n_processed = 0; @@ -114,16 +109,18 @@ PreProcessor::process(RunContext& context, PostProcessor& dest, size_t limit) } if (_block_state == BlockState::BLOCKED) { - break; // Waiting for PRE_UNBLOCKED - } else if (ev->time() < context.start()) { - ev->set_time(context.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() >= context.end()) { - break; // Event is for a future cycle + ev->time() >= ctx.end()) { + break; // Event is for a future cycle } // Execute event - ev->execute(context); + ev->execute(ctx); ++n_processed; // Unblock pre-processing if this is a non-bundled atomic event @@ -144,18 +141,18 @@ PreProcessor::process(RunContext& context, PostProcessor& dest, size_t limit) if (n_processed > 0) { #ifndef NDEBUG - Engine& engine = context.engine(); + const Engine& engine = ctx.engine(); if (engine.world().conf().option("trace").get<int32_t>()) { - const uint64_t start = engine.cycle_start_time(context); + const uint64_t start = engine.cycle_start_time(ctx); const uint64_t end = engine.current_time(); fprintf(stderr, "Processed %zu events in %u us\n", - n_processed, (unsigned)(end - start)); + n_processed, static_cast<unsigned>(end - start)); } #endif - auto* next = (Event*)last->next(); + auto* next = static_cast<Event*>(last->next()); last->next(nullptr); - dest.append(context, head, last); + dest.append(ctx, head, last); // Since _head was not null, we know it hasn't been changed since _head = next; @@ -245,9 +242,8 @@ PreProcessor::run() wait_for_block_state(BlockState::UNBLOCKED); } - back = (Event*)ev->next(); + back = static_cast<Event*>(ev->next()); } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/PreProcessor.hpp b/src/server/PreProcessor.hpp index 8d15c0a6..e0b0cc4a 100644 --- a/src/server/PreProcessor.hpp +++ b/src/server/PreProcessor.hpp @@ -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). @@ -52,7 +51,7 @@ public: /** Process events for a cycle. * @return The number of events processed. */ - unsigned process(RunContext& context, + unsigned process(RunContext& ctx, PostProcessor& dest, size_t limit = 0); @@ -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 57aaa299..95d68f57 100644 --- a/src/server/RunContext.cpp +++ b/src/server/RunContext.cpp @@ -22,10 +22,14 @@ #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 <cerrno> @@ -33,17 +37,15 @@ #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; @@ -54,27 +56,18 @@ struct Notification }; RunContext::RunContext(Engine& engine, - Raul::RingBuffer* event_sink, + raul::RingBuffer* event_sink, unsigned id, 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) @@ -124,8 +117,7 @@ RunContext::emit_notifications(FrameTime end) return; } if (_event_sink->read(sizeof(note), ¬e) == sizeof(note)) { - Atom value = _engine.world().forge().alloc( - note.size, note.type, nullptr); + Atom value = Forge::alloc(note.size, note.type, nullptr); if (_event_sink->read(note.size, value.get_body()) == note.size) { i += note.size; const char* key = _engine.world().uri_map().unmap_uri(note.key); @@ -168,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( @@ -195,11 +187,10 @@ void RunContext::run() { while (_engine.wait_for_tasks()) { - for (Task* t; (t = _engine.steal_task(0));) { + for (Task* t = nullptr; (t = _engine.steal_task(0));) { t->run(*this); } } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/RunContext.hpp b/src/server/RunContext.hpp index 9190d172..a91a3e17 100644 --- a/src/server/RunContext.hpp +++ b/src/server/RunContext.hpp @@ -17,17 +17,16 @@ #ifndef INGEN_ENGINE_RUNCONTEXT_HPP #define INGEN_ENGINE_RUNCONTEXT_HPP -#include "ingen/types.hpp" #include "types.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; @@ -57,7 +56,7 @@ public: * a thread and execute tasks as they become available. */ RunContext(Engine& engine, - Raul::RingBuffer* event_sink, + raul::RingBuffer* event_sink, unsigned id, bool threaded); @@ -68,6 +67,9 @@ public: */ RunContext(const RunContext& copy); + RunContext& operator=(const RunContext&) = delete; + RunContext& operator=(RunContext&&) = delete; + /** Return true iff the given port should broadcast its value. * * Whether or not broadcasting is actually done is a per-client property, @@ -100,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 { - return (uint64_t)_nframes * 1e6 / _rate; + 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; } @@ -126,37 +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: - const RunContext& operator=(const RunContext& copy) = delete; - void run(); - Engine& _engine; ///< Engine we're running in - Raul::RingBuffer* _event_sink; ///< Port updates from process context - Task* _task; ///< Currently executing task - UPtr<std::thread> _thread; ///< Thread (null for main run context) - 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 b4b50a14..075d78cc 100644 --- a/src/server/SocketListener.cpp +++ b/src/server/SocketListener.cpp @@ -19,8 +19,10 @@ #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" @@ -33,12 +35,12 @@ #include <cstdint> #include <cstdlib> #include <cstring> +#include <memory> #include <sstream> #include <string> #include <thread> -namespace ingen { -namespace server { +namespace ingen::server { static constexpr const char* const unix_scheme = "unix://"; @@ -48,29 +50,29 @@ 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 - char* target = (char*)calloc(1, link_stat.st_size + 1); + char* target = static_cast<char*>(calloc(1, link_stat.st_size + 1)); if (readlink(link_path, target, link_stat.st_size) != -1) { - const std::string result(target); + std::string result(target); free(target); return result; } free(target); - return std::string(); + return {}; } static void ingen_listen(Engine* engine, - Raul::Socket* unix_sock, - Raul::Socket* net_sock); + raul::Socket* unix_sock, + raul::Socket* net_sock); SocketListener::SocketListener(Engine& engine) - : unix_sock(Raul::Socket::Type::UNIX) - , net_sock(Raul::Socket::Type::TCP) + : unix_sock(raul::Socket::Type::UNIX) + , net_sock(raul::Socket::Type::TCP) , thread(new std::thread(ingen_listen, &engine, &unix_sock, &net_sock)) {} @@ -82,7 +84,7 @@ SocketListener::~SocketListener() { } static void -ingen_listen(Engine* engine, Raul::Socket* unix_sock, Raul::Socket* net_sock) +ingen_listen(Engine* engine, raul::Socket* unix_sock, raul::Socket* net_sock) { ingen::World& world = engine->world(); @@ -138,7 +140,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]; @@ -162,22 +164,26 @@ 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; } if (pfds[0].revents & POLLIN) { - SPtr<Raul::Socket> conn = unix_sock->accept(); + auto conn = unix_sock->accept(); if (conn) { new SocketServer(world, *engine, conn); } } if (pfds[1].revents & POLLIN) { - SPtr<Raul::Socket> conn = net_sock->accept(); + auto conn = net_sock->accept(); if (conn) { new SocketServer(world, *engine, conn); } @@ -189,5 +195,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 21070c23..65df5af5 100644 --- a/src/server/SocketListener.hpp +++ b/src/server/SocketListener.hpp @@ -19,8 +19,7 @@ #include <memory> #include <thread> -namespace ingen { -namespace server { +namespace ingen::server { class Engine; @@ -32,10 +31,9 @@ public: ~SocketListener(); private: - Raul::Socket unix_sock; - Raul::Socket net_sock; + raul::Socket unix_sock; + raul::Socket net_sock; 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 f3f02a26..92bab5eb 100644 --- a/src/server/SocketServer.hpp +++ b/src/server/SocketServer.hpp @@ -21,35 +21,42 @@ #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" -namespace ingen { -namespace server { +#include <cstdint> +#include <cstdio> +#include <memory> + +namespace ingen::server { /** The server side of an Ingen socket connection. */ class SocketServer { public: - SocketServer(World& world, - server::Engine& engine, - SPtr<Raul::Socket> sock) + SocketServer(World& world, + server::Engine& engine, + const std::shared_ptr<raul::Socket>& sock) : _engine(engine) , _sink(world.conf().option("dump").get<int32_t>() - ? SPtr<Interface>( - new Tee({SPtr<Interface>(new EventWriter(engine)), - SPtr<Interface>(new StreamWriter(world.uri_map(), + ? std::shared_ptr<Interface>( + new Tee({std::shared_ptr<Interface>(new EventWriter(engine)), + std::shared_ptr<Interface>(new StreamWriter(world.uri_map(), world.uris(), URI("ingen:/engine"), stderr, ColorContext::Color::CYAN))})) - : SPtr<Interface>(new EventWriter(engine))) - , _reader(new SocketReader(world, *_sink.get(), sock)) + : std::shared_ptr<Interface>(new EventWriter(engine))) + , _reader(new SocketReader(world, *_sink, sock)) , _writer(new SocketWriter(world.uri_map(), world.uris(), URI(sock->uri()), @@ -72,13 +79,12 @@ protected: } private: - server::Engine& _engine; - SPtr<Interface> _sink; - SPtr<SocketReader> _reader; - SPtr<SocketWriter> _writer; + server::Engine& _engine; + std::shared_ptr<Interface> _sink; + std::shared_ptr<SocketReader> _reader; + std::shared_ptr<SocketWriter> _writer; }; -} // namespace ingen -} // namespace Socket +} // 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 new file mode 100644 index 00000000..673b175b --- /dev/null +++ b/src/server/State.hpp @@ -0,0 +1,34 @@ +/* + This file is part of Ingen. + Copyright 2020 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_ENGINE_STATE_HPP +#define INGEN_ENGINE_STATE_HPP + +#include "lilv/lilv.h" + +#include <memory> + +namespace ingen::server { + +struct StateDeleter { + void operator()(LilvState* state) { lilv_state_free(state); } +}; + +using StatePtr = std::unique_ptr<LilvState, StateDeleter>; + +} // namespace ingen::server + +#endif // INGEN_ENGINE_STATE_HPP diff --git a/src/server/Task.cpp b/src/server/Task.cpp index b61a08eb..2b8ff0cd 100644 --- a/src/server/Task.cpp +++ b/src/server/Task.cpp @@ -22,21 +22,21 @@ #include "raul/Path.hpp" #include <cstddef> +#include <memory> -namespace ingen { -namespace server { +namespace ingen::server { void -Task::run(RunContext& context) +Task::run(RunContext& ctx) { switch (_mode) { case Mode::SINGLE: // fprintf(stderr, "%u run %s\n", context.id(), _block->path().c_str()); - _block->process(context); + _block->process(ctx); break; case Mode::SEQUENTIAL: for (const auto& task : _children) { - task->run(context); + task->run(ctx); } break; case Mode::PARALLEL: @@ -48,16 +48,16 @@ Task::run(RunContext& context) // Grab the first sub-task _next = 0; _done_end = 0; - Task* t = steal(context); + Task* t = steal(ctx); // Allow other threads to steal sub-tasks - context.claim_task(this); + ctx.claim_task(this); // Run available tasks until this task is finished - for (; t; t = get_task(context)) { - t->run(context); + for (; t; t = get_task(ctx)) { + t->run(ctx); } - context.claim_task(nullptr); + ctx.claim_task(nullptr); break; } @@ -78,10 +78,10 @@ Task::steal(RunContext&) } Task* -Task::get_task(RunContext& context) +Task::get_task(RunContext& ctx) { // Attempt to "steal" a task from ourselves - Task* t = steal(context); + Task* t = steal(ctx); if (t) { return t; } @@ -93,11 +93,11 @@ Task::get_task(RunContext& context) } 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 - if ((t = context.steal_task())) { + if ((t = ctx.steal_task())) { return t; } @@ -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 e8b658c3..30941f28 100644 --- a/src/server/Task.hpp +++ b/src/server/Task.hpp @@ -17,6 +17,7 @@ #ifndef INGEN_ENGINE_TASK_HPP #define INGEN_ENGINE_TASK_HPP +#include <algorithm> #include <atomic> #include <cassert> #include <deque> @@ -25,31 +26,31 @@ #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) : _block(block) , _mode(mode) - , _done_end(0) - , _next(0) - , _done(false) { - assert(!(mode == Mode::SINGLE && !block)); + assert(mode != Mode::SINGLE || block); } - Task(Task&& task) + Task(const Task&) = delete; + Task& operator=(const Task&) = delete; + + Task(Task&& task) noexcept : _children(std::move(task._children)) , _block(task._block) , _mode(task._mode) @@ -58,7 +59,7 @@ public: , _done(task._done.load()) {} - Task& operator=(Task&& task) + Task& operator=(Task&& task) noexcept { _children = std::move(task._children); _block = task._block; @@ -70,7 +71,7 @@ public: } /** Run task in the given context. */ - void run(RunContext& context); + void run(RunContext& ctx); /** Pretty print task to the given stream (recursively). */ void dump(const std::function<void(const std::string&)>& sink, @@ -84,11 +85,11 @@ public: static std::unique_ptr<Task> simplify(std::unique_ptr<Task>&& task); /** Steal a child task from this task (succeeds for PARALLEL only). */ - Task* steal(RunContext& context); + Task* steal(RunContext& ctx); /** 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; } @@ -100,24 +101,20 @@ public: private: using Children = std::deque<std::unique_ptr<Task>>; - Task(const Task&) = delete; - Task& operator=(const Task&) = delete; - - Task* get_task(RunContext& context); + Task* get_task(RunContext& ctx); void append(std::unique_ptr<Task>&& t) { _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 17f2c6ff..07a01c2b 100644 --- a/src/server/ThreadManager.hpp +++ b/src/server/ThreadManager.hpp @@ -17,14 +17,11 @@ #ifndef INGEN_ENGINE_THREADMANAGER_HPP #define INGEN_ENGINE_THREADMANAGER_HPP -#include "util.hpp" - -#include "ingen/ingen.h" +#include "server.h" #include <cassert> -namespace ingen { -namespace server { +namespace ingen::server { enum ThreadFlag { THREAD_IS_REAL_TIME = 1, @@ -33,36 +30,36 @@ 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 = ((unsigned)flags | f); + flags = (static_cast<unsigned>(flags) | f); #endif } - static inline void unset_flag(ThreadFlag f) { + static void unset_flag(ThreadFlag f) { #ifndef NDEBUG - flags = ((unsigned)flags & (~f)); + flags = (static_cast<unsigned>(flags) & (~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)); } /** Set to true during initialisation so ensure_thread doesn't fail. * Defined in Engine.cpp */ - static bool single_threaded; - static INGEN_THREAD_LOCAL unsigned flags; + static bool single_threaded; + 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 a94617a5..abb9fe46 100644 --- a/src/server/UndoStack.cpp +++ b/src/server/UndoStack.cpp @@ -18,31 +18,29 @@ #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 "lv2/urid/urid.h" #include "serd/serd.h" #include "sratom/sratom.h" #include <ctime> #include <iterator> -#include <memory> -#define NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#" +#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" -#define USTR(s) ((const uint8_t*)(s)) +#define USTR(s) reinterpret_cast<const uint8_t*>(s) -namespace ingen { -namespace server { +namespace ingen::server { int UndoStack::start_entry() { if (_depth == 0) { - time_t now; + time_t now = {}; time(&now); - _stack.emplace_back(Entry(now)); + _stack.emplace_back(now); } return ++_depth; } @@ -62,22 +60,22 @@ UndoStack::ignore_later_event(const LV2_Atom* first, return false; } - const auto* f = (const LV2_Atom_Object*)first; - const auto* s = (const LV2_Atom_Object*)second; + const auto* f = reinterpret_cast<const LV2_Atom_Object*>(first); + const auto* s = reinterpret_cast<const LV2_Atom_Object*>(second); if (f->body.otype == _uris.patch_Set && f->body.otype == s->body.otype) { const LV2_Atom* f_subject = nullptr; const LV2_Atom* f_property = nullptr; const LV2_Atom* s_subject = nullptr; const LV2_Atom* s_property = nullptr; lv2_atom_object_get(f, - (LV2_URID)_uris.patch_subject, &f_subject, - (LV2_URID)_uris.patch_property, &f_property, + _uris.patch_subject.urid(), &f_subject, + _uris.patch_property.urid(), &f_property, 0); lv2_atom_object_get(s, - (LV2_URID)_uris.patch_subject, &s_subject, - (LV2_URID)_uris.patch_property, &s_property, + _uris.patch_subject.urid(), &s_subject, + _uris.patch_property.urid(), &s_property, 0); - return (lv2_atom_equals(f_subject, s_subject) && + return (lv2_atom_equals(f_subject, s_subject) && lv2_atom_equals(f_property, s_property)); } @@ -87,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(); + } } } } @@ -118,7 +116,7 @@ UndoStack::pop() } struct BlankIDs { - explicit BlankIDs(char c='b') : c(c) {} + explicit BlankIDs(const char prefix = 'b') noexcept : c{prefix} {} SerdNode get() { snprintf(buf, sizeof(buf), "%c%u", c, n++); @@ -127,15 +125,18 @@ struct BlankIDs { char buf[16]{}; unsigned n{0}; - const char c{'b'}; + const char c; }; struct ListContext { - explicit ListContext(BlankIDs& ids, unsigned flags, const SerdNode* s, const SerdNode* p) - : ids(ids) - , s(*s) - , p(*p) - , flags(flags | SERD_LIST_O_BEGIN) + explicit ListContext(BlankIDs& blank_ids, + unsigned statement_flags, + const SerdNode* subject, + const SerdNode* predicate) + : ids(blank_ids) + , s(*subject) + , p(*predicate) + , flags(statement_flags | SERD_LIST_O_BEGIN) {} SerdNode start_node(SerdWriter* writer) { @@ -149,7 +150,7 @@ struct ListContext { const SerdNode node = start_node(writer); // node rdf:first value - p = serd_node_from_string(SERD_URI, NS_RDF "first"); + p = serd_node_from_string(SERD_URI, USTR(NS_RDF "first")); flags = SERD_LIST_CONT; serd_writer_write_statement(writer, flags|oflags, nullptr, &node, &p, value, nullptr, nullptr); @@ -159,12 +160,15 @@ struct ListContext { void end_node(SerdWriter*, const SerdNode* node) { // Prepare for next call: node rdf:rest ... s = *node; - p = serd_node_from_string(SERD_URI, NS_RDF "rest"); + p = serd_node_from_string(SERD_URI, USTR(NS_RDF "rest")); } void end(SerdWriter* writer) { - const SerdNode nil = serd_node_from_string(SERD_URI, NS_RDF "nil"); - serd_writer_write_statement(writer, flags, nullptr, &s, &p, &nil, nullptr, nullptr); + const SerdNode nil = + serd_node_from_string(SERD_URI, USTR(NS_RDF "nil")); + + serd_writer_write_statement( + writer, flags, nullptr, &s, &p, &nil, nullptr, nullptr); } BlankIDs& ids; @@ -183,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")); @@ -195,9 +199,12 @@ UndoStack::write_entry(Sratom* sratom, for (const LV2_Atom* atom : entry.events) { const SerdNode node = ctx.start_node(writer); - p = serd_node_from_string(SERD_URI, NS_RDF "first"); + p = serd_node_from_string(SERD_URI, + reinterpret_cast<const uint8_t*>(NS_RDF + "first")); + ctx.flags = SERD_LIST_CONT; - sratom_write(sratom, &_map.urid_unmap_feature()->urid_unmap, SERD_LIST_CONT, + sratom_write(sratom, &_map.urid_unmap(), SERD_LIST_CONT, &node, &p, atom->type, atom->size, LV2_ATOM_BODY_CONST(atom)); @@ -217,26 +224,28 @@ 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); - - SerdWriter* writer = serd_writer_new( - SERD_TURTLE, - (SerdStyle)(SERD_STYLE_RESOLVED|SERD_STYLE_ABBREVIATED|SERD_STYLE_CURIED), - env, - &base_uri, - serd_file_sink, - stream); + serd_uri_parse(USTR("ingen:/"), &base_uri); + + SerdWriter* writer = + serd_writer_new(SERD_TURTLE, + static_cast<SerdStyle>(SERD_STYLE_RESOLVED | + SERD_STYLE_ABBREVIATED | + SERD_STYLE_CURIED), + env, + &base_uri, + serd_file_sink, + stream); // Configure sratom to write directly to the writer (and thus the socket) - Sratom* sratom = sratom_new(&_map.urid_map_feature()->urid_map); + Sratom* sratom = sratom_new(&_map.urid_map()); sratom_set_sink(sratom, - (const char*)base.buf, - (SerdStatementSink)serd_writer_write_statement, - (SerdEndSink)serd_writer_end_anon, + reinterpret_cast<const char*>(base.buf), + reinterpret_cast<SerdStatementSink>(serd_writer_write_statement), + reinterpret_cast<SerdEndSink>(serd_writer_end_anon), writer); - SerdNode s = serd_node_from_string(SERD_BLANK, (const uint8_t*)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); @@ -253,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 04021b99..8195920a 100644 --- a/src/server/UndoStack.hpp +++ b/src/server/UndoStack.hpp @@ -18,12 +18,13 @@ #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 "server.h" #include "sratom/sratom.h" +#include <algorithm> #include <cstdint> #include <cstdio> #include <cstdlib> @@ -38,10 +39,11 @@ class URIs; namespace server { -class INGEN_API UndoStack : public AtomSink { +class INGEN_SERVER_API UndoStack : public AtomSink +{ public: struct Entry { - Entry(time_t time=0) : time(time) {} + Entry(time_t t = 0) noexcept : time(t) {} Entry(const Entry& copy) : time(copy.time) @@ -54,10 +56,12 @@ public: ~Entry() { clear(); } Entry& operator=(const Entry& rhs) { - clear(); - time = rhs.time; - for (const LV2_Atom* ev : rhs.events) { - push_event(ev); + if (&rhs != this) { + clear(); + time = rhs.time; + for (const LV2_Atom* ev : rhs.events) { + push_event(ev); + } } return *this; } @@ -71,7 +75,7 @@ public: void push_event(const LV2_Atom* ev) { const uint32_t size = lv2_atom_total_size(ev); - LV2_Atom* copy = (LV2_Atom*)malloc(size); + auto* copy = static_cast<LV2_Atom*>(malloc(size)); memcpy(copy, ev, size); events.push_front(copy); } @@ -80,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; @@ -103,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 68926278..cf252d37 100644 --- a/src/server/Worker.cpp +++ b/src/server/Worker.cpp @@ -21,18 +21,26 @@ #include "LV2Block.hpp" #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 { /// 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 @@ -40,8 +48,8 @@ schedule(LV2_Worker_Schedule_Handle handle, uint32_t size, const void* data) { - auto* block = (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); } @@ -51,8 +59,8 @@ schedule_sync(LV2_Worker_Schedule_Handle handle, uint32_t size, const void* data) { - auto* block = (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); } @@ -66,7 +74,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; @@ -87,39 +95,38 @@ Worker::request(LV2Block* block, return LV2_WORKER_SUCCESS; } -SPtr<LV2_Feature> +std::shared_ptr<LV2_Feature> Worker::Schedule::feature(World&, Node* n) { auto* block = dynamic_cast<LV2Block*>(n); if (!block) { - return SPtr<LV2_Feature>(); + return nullptr; } - auto* data = (LV2_Worker_Schedule*)malloc(sizeof(LV2_Worker_Schedule)); + auto* data = static_cast<LV2_Worker_Schedule*>(malloc(sizeof(LV2_Worker_Schedule))); + data->handle = block; data->schedule_work = synchronous ? schedule_sync : schedule; - auto* f = (LV2_Feature*)malloc(sizeof(LV2_Feature)); + auto* f = static_cast<LV2_Feature*>(malloc(sizeof(LV2_Feature))); f->URI = LV2_WORKER__schedule; f->data = data; - return SPtr<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((uint8_t*)malloc(buffer_size)) + , _buffer(static_cast<uint8_t*>(malloc(buffer_size))) , _buffer_size(buffer_size) , _thread(nullptr) - , _exit_flag(false) , _synchronous(synchronous) { if (!synchronous) { - _thread = make_unique<std::thread>(&Worker::run, this); + _thread = std::make_unique<std::thread>(&Worker::run, this); } } diff --git a/src/server/Worker.hpp b/src/server/Worker.hpp index 2e4a965f..540347df 100644 --- a/src/server/Worker.hpp +++ b/src/server/Worker.hpp @@ -18,17 +18,20 @@ #define INGEN_ENGINE_WORKER_HPP #include "ingen/LV2Features.hpp" -#include "ingen/types.hpp" +#include "lv2/core/lv2.h" #include "lv2/worker/worker.h" #include "raul/RingBuffer.hpp" #include "raul/Semaphore.hpp" #include <cstdint> +#include <memory> #include <thread> namespace ingen { class Log; +class Node; +class World; namespace server { @@ -41,11 +44,11 @@ public: ~Worker(); struct Schedule : public LV2Features::Feature { - Schedule(bool sync) : synchronous(sync) {} + Schedule(bool sync) noexcept : synchronous(sync) {} const char* uri() const override { return LV2_WORKER__schedule; } - SPtr<LV2_Feature> feature(World& world, Node* n) override; + std::shared_ptr<LV2_Feature> feature(World& world, Node* n) override; const bool synchronous; }; @@ -54,20 +57,20 @@ public: uint32_t size, const void* data); - SPtr<Schedule> schedule_feature() { return _schedule; } + std::shared_ptr<Schedule> schedule_feature() { return _schedule; } private: - SPtr<Schedule> _schedule; - - Log& _log; - Raul::Semaphore _sem; - Raul::RingBuffer _requests; - Raul::RingBuffer _responses; - uint8_t* const _buffer; - const uint32_t _buffer_size; - UPtr<std::thread> _thread; - bool _exit_flag; - bool _synchronous; + std::shared_ptr<Schedule> _schedule; + + Log& _log; + 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{false}; + bool _synchronous; void run(); }; diff --git a/src/server/events/Connect.cpp b/src/server/events/Connect.cpp index dd5b32a9..e1854ef2 100644 --- a/src/server/events/Connect.cpp +++ b/src/server/events/Connect.cpp @@ -17,8 +17,10 @@ #include "Connect.hpp" #include "ArcImpl.hpp" +#include "BlockImpl.hpp" #include "Broadcaster.hpp" #include "BufferFactory.hpp" +#include "CompiledGraph.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "InputPort.hpp" @@ -27,31 +29,35 @@ #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 <cassert> +#include <memory> #include <mutex> +#include <set> #include <utility> -namespace ingen { -namespace server { -namespace events { - -Connect::Connect(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Connect& msg) - : Event(engine, client, msg.seq, timestamp) - , _msg(msg) - , _graph(nullptr) - , _head(nullptr) +namespace ingen::server::events { + +Connect::Connect(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Connect& msg) + : Event(engine, client, msg.seq, timestamp) + , _msg(msg) {} +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) { @@ -126,7 +132,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); @@ -150,16 +156,16 @@ Connect::pre_process(PreProcessContext& ctx) } void -Connect::execute(RunContext& context) +Connect::execute(RunContext& ctx) { if (_status == Status::SUCCESS) { - _head->add_arc(context, *_arc.get()); + _head->add_arc(ctx, *_arc); if (!_head->is_driver_port()) { - _head->set_voices(context, std::move(_voices)); + _head->set_voices(ctx, std::move(_voices)); } _head->connect_buffers(); if (_compiled_graph) { - _graph->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = _graph->swap_compiled_graph(std::move(_compiled_graph)); } } } @@ -167,7 +173,7 @@ Connect::execute(RunContext& context) 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()) { @@ -187,6 +193,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 adc80afc..4224f109 100644 --- a/src/server/events/Connect.hpp +++ b/src/server/events/Connect.hpp @@ -17,17 +17,29 @@ #ifndef INGEN_EVENTS_CONNECT_HPP #define INGEN_EVENTS_CONNECT_HPP -#include "CompiledGraph.hpp" #include "Event.hpp" #include "PortImpl.hpp" #include "types.hpp" +#include "ingen/Message.hpp" +#include "ingen/Properties.hpp" +#include "raul/Maid.hpp" + +#include <memory> + namespace ingen { + +class Interface; + namespace server { class ArcImpl; +class CompiledGraph; +class Engine; class GraphImpl; class InputPort; +class PreProcessContext; +class RunContext; namespace events { @@ -38,27 +50,29 @@ namespace events { class Connect : public Event { public: - Connect(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Connect& msg); + Connect(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Connect& msg); + + ~Connect() override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; private: - const ingen::Connect _msg; - GraphImpl* _graph; - InputPort* _head; - MPtr<CompiledGraph> _compiled_graph; - SPtr<ArcImpl> _arc; - MPtr<PortImpl::Voices> _voices; - Properties _tail_remove; - Properties _tail_add; - Properties _head_remove; - Properties _head_add; + const ingen::Connect _msg; + 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; + Properties _tail_add; + Properties _head_remove; + Properties _head_add; }; } // namespace events diff --git a/src/server/events/Copy.cpp b/src/server/events/Copy.cpp index 5418af4b..f6529da3 100644 --- a/src/server/events/Copy.cpp +++ b/src/server/events/Copy.cpp @@ -18,71 +18,83 @@ #include "BlockImpl.hpp" #include "Broadcaster.hpp" +#include "CompiledGraph.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "PreProcessContext.hpp" +#include "ingen/Interface.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 { - -Copy::Copy(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Copy& msg) - : Event(engine, client, msg.seq, timestamp) - , _msg(msg) - , _old_block(nullptr) - , _parent(nullptr) - , _block(nullptr) +namespace ingen::server::events { + +Copy::Copy(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Copy& msg) + : Event(engine, client, msg.seq, timestamp) + , _msg(msg) {} +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); + 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); } // Ensure it is a block (ports are not supported for now) - if (!(_old_block = dynamic_ptr_cast<BlockImpl>(i->second))) { + if (!(_old_block = std::dynamic_pointer_cast<BlockImpl>(i->second))) { return Event::pre_process_done(Status::BAD_OBJECT_TYPE, old_path); } 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); @@ -92,8 +104,8 @@ bool Copy::engine_to_engine(PreProcessContext& ctx) { // Only support a single source for now - const Raul::Path new_path = uri_to_path(_msg.new_uri); - if (!Raul::Symbol::is_valid(new_path.symbol())) { + const raul::Path new_path = uri_to_path(_msg.new_uri); + if (!raul::Symbol::is_valid(new_path.symbol())) { return Event::pre_process_done(Status::BAD_REQUEST); } @@ -103,8 +115,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); } @@ -114,7 +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)))) { + _old_block->duplicate(_engine, raul::Symbol(new_path.symbol()), _parent)))) { return Event::pre_process_done(Status::INTERNAL_ERROR); } @@ -125,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); } @@ -143,7 +155,7 @@ bool Copy::engine_to_filesystem(PreProcessContext&) { // Ensure source is a graph - SPtr<GraphImpl> graph = dynamic_ptr_cast<GraphImpl>(_old_block); + auto graph = std::dynamic_pointer_cast<GraphImpl>(_old_block); if (!graph) { return Event::pre_process_done(Status::BAD_OBJECT_TYPE, _msg.old_uri); } @@ -152,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)); @@ -173,16 +185,16 @@ 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()); + dst_symbol = raul::Symbol(dst_path.symbol()); } _engine.world().parser()->parse_file( @@ -196,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); } @@ -217,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 26673a55..744a61c2 100644 --- a/src/server/events/Copy.hpp +++ b/src/server/events/Copy.hpp @@ -17,15 +17,25 @@ #ifndef INGEN_EVENTS_COPY_HPP #define INGEN_EVENTS_COPY_HPP -#include "CompiledGraph.hpp" #include "Event.hpp" +#include "types.hpp" + +#include "ingen/Message.hpp" + +#include <memory> namespace ingen { + +class Interface; + namespace server { class BlockImpl; +class CompiledGraph; class Engine; class GraphImpl; +class PreProcessContext; +class RunContext; namespace events { @@ -35,13 +45,15 @@ namespace events { class Copy : public Event { public: - Copy(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Copy& msg); + Copy(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Copy& msg); + + ~Copy() override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; @@ -50,11 +62,11 @@ private: bool engine_to_filesystem(PreProcessContext& ctx); bool filesystem_to_engine(PreProcessContext& ctx); - const ingen::Copy _msg; - SPtr<BlockImpl> _old_block; - GraphImpl* _parent; - BlockImpl* _block; - MPtr<CompiledGraph> _compiled_graph; + const ingen::Copy _msg; + 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 4b48cfde..7f50411c 100644 --- a/src/server/events/CreateBlock.cpp +++ b/src/server/events/CreateBlock.cpp @@ -19,57 +19,74 @@ #include "BlockFactory.hpp" #include "BlockImpl.hpp" #include "Broadcaster.hpp" +#include "CompiledGraph.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "LV2Block.hpp" #include "PluginImpl.hpp" #include "PreProcessContext.hpp" +#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 "raul/Maid.hpp" +#include "ingen/paths.hpp" #include "raul/Path.hpp" +#include "raul/Symbol.hpp" +#include <map> +#include <memory> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { + +class RunContext; + namespace events { -CreateBlock::CreateBlock(Engine& engine, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - const Raul::Path& path, - Properties& properties) - : Event(engine, client, id, timestamp) - , _path(path) - , _properties(properties) - , _graph(nullptr) - , _block(nullptr) +CreateBlock::CreateBlock(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + raul::Path path, + Properties& properties) + : Event(engine, client, id, timestamp) + , _path(std::move(path)) + , _properties(properties) {} +CreateBlock::~CreateBlock() = default; + bool CreateBlock::pre_process(PreProcessContext& ctx) { - using iterator = Properties::const_iterator; - - const ingen::URIs& uris = _engine.world().uris(); - const SPtr<Store> store = _engine.store(); + 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; @@ -79,7 +96,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); @@ -88,10 +105,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)) { @@ -100,8 +117,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); } @@ -119,7 +139,7 @@ CreateBlock::pre_process(PreProcessContext& ctx) } // Load state from directory if given in properties - LilvState* state = nullptr; + StatePtr state{}; auto s = _properties.find(uris.state_state); if (s != _properties.end() && s->second.type() == uris.forge.Path) { state = LV2Block::load_state( @@ -128,11 +148,11 @@ CreateBlock::pre_process(PreProcessContext& ctx) // Instantiate plugin if (!(_block = plugin->instantiate(*_engine.buffer_factory(), - Raul::Symbol(_path.symbol()), + raul::Symbol(_path.symbol()), polyphonic, _graph, _engine, - state))) { + state.get()))) { return Event::pre_process_done(Status::CREATION_FAILED, _path); } } @@ -148,7 +168,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); @@ -159,14 +179,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()); } @@ -179,5 +200,4 @@ CreateBlock::undo(Interface& target) } } // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/events/CreateBlock.hpp b/src/server/events/CreateBlock.hpp index 00f58008..e8a49ea0 100644 --- a/src/server/events/CreateBlock.hpp +++ b/src/server/events/CreateBlock.hpp @@ -18,16 +18,27 @@ #define INGEN_EVENTS_CREATEBLOCK_HPP #include "ClientUpdate.hpp" -#include "CompiledGraph.hpp" #include "Event.hpp" +#include "types.hpp" + +#include "raul/Path.hpp" #include <cstdint> +#include <memory> namespace ingen { + +class Interface; +class Properties; + namespace server { class BlockImpl; +class CompiledGraph; +class Engine; class GraphImpl; +class PreProcessContext; +class RunContext; namespace events { @@ -38,25 +49,27 @@ namespace events { class CreateBlock : public Event { public: - CreateBlock(Engine& engine, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - const Raul::Path& path, - Properties& properties); + CreateBlock(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + raul::Path path, + Properties& properties); + + ~CreateBlock() override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; private: - Raul::Path _path; - Properties& _properties; - ClientUpdate _update; - GraphImpl* _graph; - BlockImpl* _block; - MPtr<CompiledGraph> _compiled_graph; + raul::Path _path; + Properties& _properties; + ClientUpdate _update; + 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 3e847bdd..7a8a973d 100644 --- a/src/server/events/CreateGraph.cpp +++ b/src/server/events/CreateGraph.cpp @@ -16,38 +16,49 @@ #include "events/CreateGraph.hpp" +#include "BlockImpl.hpp" #include "Broadcaster.hpp" +#include "CompiledGraph.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 "raul/Maid.hpp" +#include "ingen/paths.hpp" #include "raul/Path.hpp" +#include "raul/Symbol.hpp" +#include <boost/intrusive/slist.hpp> + +#include <map> +#include <memory> #include <utility> -namespace ingen { -namespace server { -namespace events { - -CreateGraph::CreateGraph(Engine& engine, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - const Raul::Path& path, - const Properties& properties) - : Event(engine, client, id, timestamp) - , _path(path) - , _properties(properties) - , _graph(nullptr) - , _parent(nullptr) +namespace ingen::server::events { + +CreateGraph::CreateGraph(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + raul::Path path, + Properties properties) + : Event(engine, client, id, timestamp) + , _path(std::move(path)) + , _properties(std::move(properties)) {} +CreateGraph::~CreateGraph() = default; + void CreateGraph::build_child_events() { @@ -67,30 +78,40 @@ CreateGraph::build_child_events() in_properties.put(uris.lv2_index, uris.forge.make(0)); in_properties.put(uris.lv2_name, uris.forge.alloc("Control")); in_properties.put(uris.rdf_type, uris.lv2_InputPort); - in_properties.put(uris.ingen_canvasX, uris.forge.make(32.0f), + in_properties.put(uris.ingen_canvasX, + uris.forge.make(32.0f), Resource::Graph::EXTERNAL); - in_properties.put(uris.ingen_canvasY, uris.forge.make(32.0f), + in_properties.put(uris.ingen_canvasY, + uris.forge.make(32.0f), Resource::Graph::EXTERNAL); - _child_events.push_back( - make_unique<events::CreatePort>(_engine, _request_client, -1, _time, - _path.child(Raul::Symbol("control")), - in_properties)); + _child_events.push_back(std::make_unique<events::CreatePort>( + _engine, + _request_client, + -1, + _time, + _path.child(raul::Symbol("control")), + in_properties)); // Add notify port (message respond) Properties out_properties(control_properties); out_properties.put(uris.lv2_index, uris.forge.make(1)); out_properties.put(uris.lv2_name, uris.forge.alloc("Notify")); out_properties.put(uris.rdf_type, uris.lv2_OutputPort); - out_properties.put(uris.ingen_canvasX, uris.forge.make(128.0f), + out_properties.put(uris.ingen_canvasX, + uris.forge.make(128.0f), Resource::Graph::EXTERNAL); - out_properties.put(uris.ingen_canvasY, uris.forge.make(32.0f), + out_properties.put(uris.ingen_canvasY, + uris.forge.make(32.0f), Resource::Graph::EXTERNAL); _child_events.push_back( - make_unique<events::CreatePort>(_engine, _request_client, -1, _time, - _path.child(Raul::Symbol("notify")), - out_properties)); + std::make_unique<events::CreatePort>(_engine, + _request_client, + -1, + _time, + _path.child(raul::Symbol("notify")), + out_properties)); } bool @@ -101,7 +122,7 @@ CreateGraph::pre_process(PreProcessContext& ctx) } if (!_path.is_root()) { - const Raul::Path up(_path.parent()); + const raul::Path up(_path.parent()); if (!(_parent = dynamic_cast<GraphImpl*>(_engine.store()->get(up)))) { return Event::pre_process_done(Status::PARENT_NOT_FOUND, up); } @@ -109,11 +130,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>(); } @@ -126,33 +145,39 @@ CreateGraph::pre_process(PreProcessContext& ctx) ext_poly = int_poly; } - const Raul::Symbol symbol(_path.is_root() ? "graph" : _path.symbol()); + 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); } - if (t != _properties.end() && - uris.forge.is_uri(t->second) && + if (t != _properties.end() && uris.forge.is_uri(t->second) && URI::is_valid(uris.forge.str(t->second, false)) && uri_is_path(URI(uris.forge.str(t->second, false)))) { // Create a duplicate of an existing graph const URI prototype(uris.forge.str(t->second, false)); GraphImpl* ancestor = dynamic_cast<GraphImpl*>( - _engine.store()->get(uri_to_path(prototype))); + _engine.store()->get(uri_to_path(prototype))); if (!ancestor) { - return Event::pre_process_done(Status::PROTOTYPE_NOT_FOUND, prototype); - } else if (!(_graph = dynamic_cast<GraphImpl*>( - ancestor->duplicate(_engine, symbol, _parent)))) { + return Event::pre_process_done(Status::PROTOTYPE_NOT_FOUND, + prototype); + } + + if (!(_graph = dynamic_cast<GraphImpl*>( + ancestor->duplicate(_engine, symbol, _parent)))) { return Event::pre_process_done(Status::CREATION_FAILED, _path); } } else { // Create a new graph - _graph = new GraphImpl(_engine, symbol, ext_poly, _parent, - _engine.sample_rate(), int_poly); - _graph->add_property(uris.rdf_type, uris.ingen_Graph.urid); + _graph = new GraphImpl(_engine, + symbol, + ext_poly, + _parent, + _engine.sample_rate(), + int_poly); + _graph->add_property(uris.rdf_type, uris.ingen_Graph.urid_atom()); _graph->add_property(uris.rdf_type, Property(uris.ingen_Block, Resource::Graph::EXTERNAL)); @@ -166,7 +191,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()); @@ -188,12 +213,13 @@ CreateGraph::pre_process(PreProcessContext& ctx) } void -CreateGraph::execute(RunContext& context) +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); @@ -201,7 +227,7 @@ CreateGraph::execute(RunContext& context) } for (const auto& ev : _child_events) { - ev->execute(context); + ev->execute(ctx); } } } @@ -209,7 +235,7 @@ CreateGraph::execute(RunContext& context) void CreateGraph::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _update.send(*_engine.broadcaster()); } @@ -227,6 +253,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 dadb644e..b083ae8c 100644 --- a/src/server/events/CreateGraph.hpp +++ b/src/server/events/CreateGraph.hpp @@ -18,18 +18,27 @@ #define INGEN_EVENTS_CREATEGRAPH_HPP #include "ClientUpdate.hpp" -#include "CompiledGraph.hpp" #include "Event.hpp" +#include "types.hpp" -#include "ingen/types.hpp" +#include "ingen/Properties.hpp" +#include "raul/Path.hpp" #include <cstdint> #include <list> +#include <memory> namespace ingen { + +class Interface; + namespace server { +class CompiledGraph; +class Engine; class GraphImpl; +class PreProcessContext; +class RunContext; namespace events { @@ -40,15 +49,17 @@ namespace events { class CreateGraph : public Event { public: - CreateGraph(Engine& engine, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - const Raul::Path& path, - const Properties& properties); + CreateGraph(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + raul::Path path, + Properties properties); + + ~CreateGraph() override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; @@ -57,13 +68,13 @@ public: private: void build_child_events(); - const Raul::Path _path; - Properties _properties; - ClientUpdate _update; - GraphImpl* _graph; - GraphImpl* _parent; - MPtr<CompiledGraph> _compiled_graph; - std::list<UPtr<Event>> _child_events; + const raul::Path _path; + Properties _properties; + ClientUpdate _update; + GraphImpl* _graph{nullptr}; + GraphImpl* _parent{nullptr}; + std::unique_ptr<CompiledGraph> _compiled_graph; + std::list<std::unique_ptr<Event>> _child_events; }; } // namespace events diff --git a/src/server/events/CreatePort.cpp b/src/server/events/CreatePort.cpp index d0dcbaf3..937842a7 100644 --- a/src/server/events/CreatePort.cpp +++ b/src/server/events/CreatePort.cpp @@ -26,42 +26,42 @@ #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 <cassert> +#include <map> +#include <memory> #include <utility> -namespace ingen { -namespace server { -namespace events { - -CreatePort::CreatePort(Engine& engine, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - const Raul::Path& path, - const Properties& properties) - : Event(engine, client, id, timestamp) - , _path(path) - , _port_type(PortType::UNKNOWN) - , _buf_type(0) - , _graph(nullptr) - , _graph_port(nullptr) - , _engine_port(nullptr) - , _properties(properties) +namespace ingen::server::events { + +CreatePort::CreatePort(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + raul::Path path, + const Properties& properties) + : Event(engine, client, id, timestamp) + , _path(std::move(path)) + , _port_type(PortType::UNKNOWN) + , _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; @@ -78,8 +78,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)); @@ -92,20 +92,28 @@ 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); } - const Raul::Path parent_path = _path.parent(); + const raul::Path parent_path = _path.parent(); 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); } @@ -114,10 +122,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) { @@ -135,7 +141,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>()); @@ -147,7 +153,7 @@ CreatePort::pre_process(PreProcessContext&) } // Create port - _graph_port = new DuplexPort(bufs, _graph, Raul::Symbol(_path.symbol()), + _graph_port = new DuplexPort(bufs, _graph, raul::Symbol(_path.symbol()), index, polyphonic, _port_type, _buf_type, buf_size, @@ -172,18 +178,18 @@ CreatePort::pre_process(PreProcessContext&) _update = _graph_port->properties(); - assert(_graph_port->index() == (uint32_t)index_i->second.get<int32_t>()); - assert(_graph->num_ports_non_rt() == (uint32_t)old_n_ports + 1); + 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(_ports_array->size() == _graph->num_ports_non_rt()); assert(_graph_port->index() < _ports_array->size()); return Event::pre_process_done(Status::SUCCESS); } void -CreatePort::execute(RunContext& context) +CreatePort::execute(RunContext& ctx) { if (_status == Status::SUCCESS) { - const MPtr<GraphImpl::Ports>& old_ports = _graph->external_ports(); + const auto& old_ports = _graph->external_ports(); if (old_ports) { for (uint32_t i = 0; i < old_ports->size(); ++i) { const auto* const old_port = (*old_ports)[i]; @@ -196,7 +202,7 @@ CreatePort::execute(RunContext& context) _graph->set_external_ports(std::move(_ports_array)); if (_engine_port) { - _engine.driver()->add_port(context, _engine_port); + _engine.driver()->add_port(ctx, _engine_port); } } } @@ -204,7 +210,7 @@ CreatePort::execute(RunContext& context) 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); } @@ -216,6 +222,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 8137328d..6d3e9ca2 100644 --- a/src/server/events/CreatePort.hpp +++ b/src/server/events/CreatePort.hpp @@ -20,20 +20,29 @@ #include "BlockImpl.hpp" #include "Event.hpp" #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 <cstdint> +#include <memory> +#include <optional> namespace ingen { + +class Interface; + namespace server { class DuplexPort; +class Engine; class EnginePort; class GraphImpl; +class PreProcessContext; +class RunContext; namespace events { @@ -44,15 +53,15 @@ namespace events { class CreatePort : public Event { public: - CreatePort(Engine& engine, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - const Raul::Path& path, - const Properties& properties); + CreatePort(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + raul::Path path, + const Properties& properties); bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; @@ -62,16 +71,16 @@ private: OUTPUT }; - Raul::Path _path; - PortType _port_type; - LV2_URID _buf_type; - GraphImpl* _graph; - DuplexPort* _graph_port; - MPtr<BlockImpl::Ports> _ports_array; ///< New external port array for Graph - EnginePort* _engine_port; ///< Driver port if on the root - Properties _properties; - Properties _update; - boost::optional<Flow> _flow; + raul::Path _path; + PortType _port_type; + 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{nullptr}; ///< Driver port if on the root + Properties _properties; + Properties _update; + std::optional<Flow> _flow; }; } // namespace events diff --git a/src/server/events/Delete.cpp b/src/server/events/Delete.cpp index 5d605bca..62653752 100644 --- a/src/server/events/Delete.cpp +++ b/src/server/events/Delete.cpp @@ -19,9 +19,11 @@ #include "BlockImpl.hpp" #include "Broadcaster.hpp" #include "BufferFactory.hpp" +#include "CompiledGraph.hpp" #include "ControlBindings.hpp" #include "DisconnectAll.hpp" #include "Driver.hpp" +#include "DuplexPort.hpp" #include "Engine.hpp" #include "EnginePort.hpp" #include "GraphImpl.hpp" @@ -29,28 +31,37 @@ #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 <cassert> #include <cstddef> +#include <memory> #include <mutex> #include <string> +#include <string_view> + +namespace ingen::server { + +class RunContext; -namespace ingen { -namespace server { namespace events { -Delete::Delete(Engine& engine, - const SPtr<Interface>& client, - FrameTime timestamp, - const ingen::Del& msg) +Delete::Delete(Engine& engine, + const std::shared_ptr<Interface>& client, + FrameTime timestamp, + 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); @@ -59,7 +70,7 @@ Delete::Delete(Engine& engine, Delete::~Delete() { - for (ControlBindings::Binding* b : _removed_bindings) { + for (auto* b : _removed_bindings) { delete b; } } @@ -79,8 +90,8 @@ Delete::pre_process(PreProcessContext& ctx) return Event::pre_process_done(Status::NOT_FOUND, _path); } - if (!(_block = dynamic_ptr_cast<BlockImpl>(iter->second))) { - _port = dynamic_ptr_cast<DuplexPort>(iter->second); + if (!(_block = std::dynamic_pointer_cast<BlockImpl>(iter->second))) { + _port = std::dynamic_pointer_cast<DuplexPort>(iter->second); } if ((!_block && !_port) || (_port && !_engine.driver()->dynamic_ports())) { @@ -93,23 +104,23 @@ 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); if (_block) { parent->remove_block(*_block); _disconnect_event = - make_unique<DisconnectAll>(_engine, parent, _block.get()); + 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 = - make_unique<DisconnectAll>(_engine, parent, _port.get()); + 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()); @@ -121,9 +132,9 @@ Delete::pre_process(PreProcessContext& ctx) _port_index_changes.emplace( port->path(), std::make_pair(port->index(), i)); port->remove_property(uris.lv2_index, uris.patch_wildcard); - port->set_property( - uris.lv2_index, - _engine.buffer_factory()->forge().make((int32_t)i)); + port->set_property(uris.lv2_index, + _engine.buffer_factory()->forge().make( + static_cast<int32_t>(i))); } } } @@ -137,27 +148,27 @@ Delete::pre_process(PreProcessContext& ctx) } void -Delete::execute(RunContext& context) +Delete::execute(RunContext& ctx) { if (_status != Status::SUCCESS) { return; } if (_disconnect_event) { - _disconnect_event->execute(context); + _disconnect_event->execute(ctx); } if (!_removed_bindings.empty()) { - _engine.control_bindings()->remove(context, _removed_bindings); + _engine.control_bindings()->remove(ctx, _removed_bindings); } GraphImpl* parent = _block ? _block->parent_graph() : nullptr; - if (_port) { + if (_ports_array && _port) { // Adjust port indices if necessary for (size_t i = 0; i < _ports_array->size(); ++i) { PortImpl* const port = _ports_array->at(i); if (port->index() != i) { - port->set_index(context, i); + port->set_index(ctx, i); } } @@ -166,19 +177,19 @@ Delete::execute(RunContext& context) parent->set_external_ports(std::move(_ports_array)); if (_engine_port) { - _engine.driver()->remove_port(context, _engine_port); + _engine.driver()->remove_port(ctx, _engine_port); } } 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(); @@ -221,5 +232,4 @@ Delete::undo(Interface& target) } } // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/events/Delete.hpp b/src/server/events/Delete.hpp index 6b3149e9..87cde2c7 100644 --- a/src/server/events/Delete.hpp +++ b/src/server/events/Delete.hpp @@ -20,20 +20,33 @@ #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 <cstdint> #include <map> +#include <memory> +#include <string> #include <utility> #include <vector> namespace ingen { + +class Interface; + namespace server { +class BlockImpl; class CompiledGraph; class DuplexPort; +class Engine; class EnginePort; +class PreProcessContext; +class RunContext; namespace events { @@ -45,32 +58,32 @@ class DisconnectAll; class Delete : public Event { public: - Delete(Engine& engine, - const SPtr<Interface>& client, - FrameTime timestamp, - const ingen::Del& msg); + Delete(Engine& engine, + const std::shared_ptr<Interface>& client, + FrameTime timestamp, + const ingen::Del& msg); - ~Delete(); + ~Delete() override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; private: using IndexChange = std::pair<uint32_t, uint32_t>; - using IndexChanges = std::map<Raul::Path, IndexChange>; - - const ingen::Del _msg; - Raul::Path _path; - SPtr<BlockImpl> _block; ///< Non-null iff a block - SPtr<DuplexPort> _port; ///< Non-null iff a port - EnginePort* _engine_port; - MPtr<GraphImpl::Ports> _ports_array; ///< New (external) ports for Graph - MPtr<CompiledGraph> _compiled_graph; ///< Graph's new process order - UPtr<DisconnectAll> _disconnect_event; - Store::Objects _removed_objects; - IndexChanges _port_index_changes; + using IndexChanges = std::map<raul::Path, IndexChange>; + + const ingen::Del _msg; + 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{nullptr}; + raul::managed_ptr<GraphImpl::Ports> _ports_array; ///< New (external) ports for Graph + 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; std::vector<ControlBindings::Binding*> _removed_bindings; }; diff --git a/src/server/events/Delta.cpp b/src/server/events/Delta.cpp index 0a7b05ea..11a0b0ff 100644 --- a/src/server/events/Delta.cpp +++ b/src/server/events/Delta.cpp @@ -16,91 +16,89 @@ #include "Delta.hpp" +#include "BlockFactory.hpp" +#include "BlockImpl.hpp" #include "Broadcaster.hpp" +#include "CompiledGraph.hpp" #include "ControlBindings.hpp" #include "CreateBlock.hpp" #include "CreateGraph.hpp" #include "CreatePort.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" +#include "NodeImpl.hpp" #include "PluginImpl.hpp" #include "PortImpl.hpp" #include "PortType.hpp" #include "SetPortValue.hpp" +#include "ingen/Atom.hpp" +#include "ingen/FilePath.hpp" #include "ingen/Forge.hpp" +#include "ingen/Interface.hpp" #include "ingen/Log.hpp" +#include "ingen/Message.hpp" +#include "ingen/Node.hpp" +#include "ingen/Status.hpp" #include "ingen/Store.hpp" #include "ingen/URIs.hpp" #include "ingen/World.hpp" -#include "raul/Maid.hpp" +#include "ingen/paths.hpp" +#include "lilv/lilv.h" +#include "raul/Path.hpp" +#include <algorithm> +#include <memory> #include <mutex> #include <set> #include <string> +#include <string_view> #include <utility> #include <vector> -namespace ingen { -namespace server { +namespace ingen::server { class PreProcessContext; namespace events { -Delta::Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Put& msg) +Delta::Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Put& msg) : Event(engine, client, msg.seq, timestamp) - , _create_event(nullptr) , _subject(msg.uri) , _properties(msg.properties) - , _object(nullptr) - , _graph(nullptr) - , _binding(nullptr) - , _state(nullptr) , _context(msg.ctx) , _type(Type::PUT) - , _block(false) { init(); } -Delta::Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Delta& msg) +Delta::Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Delta& msg) : Event(engine, client, msg.seq, timestamp) , _create_event(nullptr) , _subject(msg.uri) , _properties(msg.add) , _remove(msg.remove) - , _object(nullptr) - , _graph(nullptr) - , _binding(nullptr) - , _state(nullptr) , _context(msg.ctx) , _type(Type::PATCH) - , _block(false) { init(); } -Delta::Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::SetProperty& msg) +Delta::Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::SetProperty& msg) : Event(engine, client, msg.seq, timestamp) , _subject(msg.subject) , _properties{{msg.predicate, msg.value}} - , _object(nullptr) - , _graph(nullptr) - , _binding(nullptr) - , _state(nullptr) , _context(msg.ctx) , _type(Type::SET) - , _block(false) { init(); } @@ -136,7 +134,7 @@ Delta::add_set_event(const char* port_symbol, } _set_events.emplace_back( - make_unique<SetPortValue>( + std::make_unique<SetPortValue>( _engine, _request_client, _request_id, _time, port, Atom(size, type, value), false, true)); } @@ -148,7 +146,7 @@ s_add_set_event(const char* port_symbol, uint32_t size, uint32_t type) { - ((Delta*)user_data)->add_set_event(port_symbol, value, size, type); + static_cast<Delta*>(user_data)->add_set_event(port_symbol, value, size, type); } static LilvNode* @@ -156,12 +154,15 @@ get_file_node(LilvWorld* lworld, const URIs& uris, const Atom& value) { if (value.type() == uris.atom_Path) { return lilv_new_file_uri(lworld, nullptr, value.ptr<char>()); - } else if (uris.forge.is_uri(value)) { + } + + if (uris.forge.is_uri(value)) { const std::string str = uris.forge.str(value, false); if (str.substr(0, 5) == "file:") { return lilv_new_uri(lworld, value.ptr<char>()); } } + return nullptr; } @@ -206,12 +207,12 @@ Delta::pre_process(PreProcessContext& ctx) if ((_preset = block->save_preset(_subject, _properties))) { return Event::pre_process_done(Status::SUCCESS); - } else { - return Event::pre_process_done(Status::FAILURE); } + + return Event::pre_process_done(Status::FAILURE); } - std::lock_guard<Store::Mutex> lock(_engine.store()->mutex()); + const std::lock_guard<Store::Mutex> lock{_engine.store()->mutex()}; _object = is_graph_object ? static_cast<ingen::Resource*>(_engine.store()->get(uri_to_path(_subject))) @@ -223,7 +224,7 @@ Delta::pre_process(PreProcessContext& ctx) } if (is_graph_object && !_object) { - Raul::Path path(uri_to_path(_subject)); + const raul::Path path{uri_to_path(_subject)}; bool is_graph = false; bool is_block = false; @@ -232,19 +233,19 @@ Delta::pre_process(PreProcessContext& ctx) ingen::Resource::type(uris, _properties, is_graph, is_block, is_port, is_output); if (is_graph) { - _create_event = make_unique<CreateGraph>( + _create_event = std::make_unique<CreateGraph>( _engine, _request_client, _request_id, _time, path, _properties); } else if (is_block) { - _create_event = make_unique<CreateBlock>( + _create_event = std::make_unique<CreateBlock>( _engine, _request_client, _request_id, _time, path, _properties); } else if (is_port) { - _create_event = make_unique<CreatePort>( + _create_event = std::make_unique<CreatePort>( _engine, _request_client, _request_id, _time, path, _properties); } if (_create_event) { if (_create_event->pre_process(ctx)) { - _object = _engine.store()->get(path); // Get object for setting + _object = _engine.store()->get(path); // Get object for setting } else { return Event::pre_process_done(Status::CREATION_FAILED, _subject); } @@ -334,7 +335,7 @@ Delta::pre_process(PreProcessContext& ctx) } } else if (key == uris.ingen_value || key == uris.ingen_activity) { _set_events.emplace_back( - make_unique<SetPortValue>( + std::make_unique<SetPortValue>( _engine, _request_client, _request_id, _time, port, value, key == uris.ingen_activity)); } else if (key == uris.midi_binding) { @@ -356,7 +357,7 @@ Delta::pre_process(PreProcessContext& ctx) } } else if ((block = dynamic_cast<BlockImpl*>(_object))) { if (key == uris.midi_binding && value == uris.patch_wildcard) { - op = SpecialType::CONTROL_BINDING; // Internal block learn + op = SpecialType::CONTROL_BINDING; // Internal block learn } else if (key == uris.ingen_enabled) { if (value.type() == uris.forge.Bool) { op = SpecialType::ENABLE; @@ -377,8 +378,9 @@ Delta::pre_process(PreProcessContext& ctx) if (!uri.empty()) { op = SpecialType::PRESET; if ((_state = block->load_preset(uri))) { - lilv_state_emit_port_values( - _state, s_add_set_event, this); + lilv_state_emit_port_values(_state.get(), + s_add_set_event, + this); } else { _engine.log().warn("Failed to load preset <%1%>\n", uri); } @@ -392,9 +394,9 @@ Delta::pre_process(PreProcessContext& ctx) if (key == uris.ingen_enabled) { if (value.type() == uris.forge.Bool) { op = SpecialType::ENABLE; - // FIXME: defer this until all other metadata has been processed + // FIXME: defer until all other data has been processed if (value.get<int32_t>() && !_graph->enabled()) { - if (!(_compiled_graph = compile(*_engine.maid(), *_graph))) { + if (!(_compiled_graph = compile(*_graph))) { _status = Status::COMPILATION_FAILED; } } @@ -423,9 +425,8 @@ Delta::pre_process(PreProcessContext& ctx) } else if (value.type() != uris.forge.Bool) { _status = Status::BAD_VALUE_TYPE; } else { - op = SpecialType::POLYPHONIC; + op = SpecialType::POLYPHONIC; obj->set_property(key, value, value.context()); - auto* block = dynamic_cast<BlockImpl*>(obj); if (block) { block->set_polyphonic(value.get<int32_t>()); } @@ -446,9 +447,9 @@ Delta::pre_process(PreProcessContext& ctx) lilv_world_load_bundle(lworld, bundle); const auto new_plugins = _engine.block_factory()->refresh(); - for (const auto& p : new_plugins) { - if (p->bundle_uri() == lilv_node_as_string(bundle)) { - _update.put_plugin(p.get()); + for (const auto& plugin : new_plugins) { + if (plugin->bundle_uri() == lilv_node_as_string(bundle)) { + _update.put_plugin(plugin.get()); } } lilv_node_free(bundle); @@ -474,7 +475,7 @@ Delta::pre_process(PreProcessContext& ctx) } void -Delta::execute(RunContext& context) +Delta::execute(RunContext& ctx) { if (_status != Status::SUCCESS || _preset) { return; @@ -484,23 +485,23 @@ Delta::execute(RunContext& context) if (_create_event) { _create_event->set_time(_time); - _create_event->execute(context); + _create_event->execute(ctx); } for (auto& s : _set_events) { s->set_time(_time); - s->execute(context); + s->execute(ctx); } if (!_removed_bindings.empty()) { - _engine.control_bindings()->remove(context, _removed_bindings); + _engine.control_bindings()->remove(ctx, _removed_bindings); } auto* const object = dynamic_cast<NodeImpl*>(_object); auto* const block = dynamic_cast<BlockImpl*>(_object); auto* const port = dynamic_cast<PortImpl*>(_object); - std::vector<SpecialType>::const_iterator t = _types.begin(); + auto t = _types.begin(); for (const auto& p : _properties) { const URI& key = p.first; const Atom& value = p.second; @@ -514,11 +515,11 @@ Delta::execute(RunContext& context) if (_graph) { if (value.get<int32_t>()) { if (_compiled_graph) { - _graph->set_compiled_graph(std::move(_compiled_graph)); + _compiled_graph = _graph->swap_compiled_graph(std::move(_compiled_graph)); } _graph->enable(); } else { - _graph->disable(context); + _graph->disable(ctx); } } else if (block) { block->set_enabled(value.get<int32_t>()); @@ -528,15 +529,15 @@ Delta::execute(RunContext& context) if (object) { if (value.get<int32_t>()) { auto* parent = reinterpret_cast<GraphImpl*>(object->parent()); - object->apply_poly(context, parent->internal_poly_process()); + object->apply_poly(ctx, parent->internal_poly_process()); } else { - object->apply_poly(context, 1); + object->apply_poly(ctx, 1); } } } break; case SpecialType::POLYPHONY: if (_graph && - !_graph->apply_internal_poly(context, + !_graph->apply_internal_poly(ctx, *_engine.buffer_factory(), *_engine.maid(), value.get<int32_t>())) { @@ -545,12 +546,12 @@ Delta::execute(RunContext& context) break; case SpecialType::PORT_INDEX: if (port) { - port->set_index(context, value.get<int32_t>()); + port->set_index(ctx, value.get<int32_t>()); } break; case SpecialType::CONTROL_BINDING: if (port) { - if (!_engine.control_bindings()->set_port_binding(context, port, _binding, value)) { + if (!_engine.control_bindings()->set_port_binding(ctx, port, _binding, value)) { _status = Status::BAD_VALUE; } } else if (block) { @@ -572,6 +573,7 @@ Delta::execute(RunContext& context) port->set_maximum(value); } } + break; case SpecialType::LOADED_BUNDLE: break; } @@ -584,24 +586,25 @@ Delta::post_process() if (_state) { auto* block = dynamic_cast<BlockImpl*>(_object); if (block) { - block->apply_state(_engine.sync_worker(), _state); + block->apply_state(_engine.sync_worker(), _state.get()); block->set_enabled(true); } - lilv_state_free(_state); + + _state.reset(); } - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (_create_event) { _create_event->post_process(); if (_create_event->status() != Status::SUCCESS) { - return; // Creation failed, nothing else to do + return; // Creation failed, nothing else to do } } for (auto& s : _set_events) { if (s->synthetic() || s->status() != Status::SUCCESS) { - s->post_process(); // Set failed, report error + s->post_process(); // Set failed, report error } } @@ -670,5 +673,4 @@ Delta::get_execution() const } } // namespace events -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/events/Delta.hpp b/src/server/events/Delta.hpp index 1dce2663..ed04f8c9 100644 --- a/src/server/events/Delta.hpp +++ b/src/server/events/Delta.hpp @@ -20,49 +20,61 @@ #include "ClientUpdate.hpp" #include "ControlBindings.hpp" #include "Event.hpp" +#include "SetPortValue.hpp" +#include "State.hpp" +#include "types.hpp" -#include "lilv/lilv.h" +#include "ingen/Properties.hpp" +#include "ingen/Resource.hpp" +#include "ingen/URI.hpp" -#include <boost/optional/optional.hpp> - -#include <algorithm> #include <cstdint> +#include <memory> +#include <optional> #include <vector> +// IWYU pragma: no_include "CompiledGraph.hpp" +// IWYU pragma: no_include <algorithm> + namespace ingen { + +class Interface; +struct Delta; +struct Put; +struct SetProperty; + namespace server { -class CompiledGraph; +class CompiledGraph; // IWYU pragma: keep class Engine; class GraphImpl; +class PreProcessContext; class RunContext; namespace events { -class SetPortValue; - /** Set properties of a graph object. * \ingroup engine */ class Delta : public Event { public: - Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Put& msg); + Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Put& msg); - Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Delta& msg); + Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Delta& msg); - Delta(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::SetProperty& msg); + Delta(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::SetProperty& msg); - ~Delta() = default; + ~Delta() override = default; void add_set_event(const char* port_symbol, const void* value, @@ -70,18 +82,14 @@ public: uint32_t type); bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; Execution get_execution() const override; private: - enum class Type { - SET, - PUT, - PATCH - }; + enum class Type { SET, PUT, PATCH }; enum class SpecialType { NONE, @@ -95,34 +103,34 @@ private: LOADED_BUNDLE }; - using SetEvents = std::vector<UPtr<SetPortValue>>; + using SetEvents = std::vector<std::unique_ptr<SetPortValue>>; void init(); - UPtr<Event> _create_event; - SetEvents _set_events; - std::vector<SpecialType> _types; - std::vector<SpecialType> _remove_types; - URI _subject; - Properties _properties; - Properties _remove; - ClientUpdate _update; - ingen::Resource* _object; - GraphImpl* _graph; - MPtr<CompiledGraph> _compiled_graph; - ControlBindings::Binding* _binding; - LilvState* _state; - Resource::Graph _context; - Type _type; + std::unique_ptr<Event> _create_event; + SetEvents _set_events; + std::vector<SpecialType> _types; + std::vector<SpecialType> _remove_types; + URI _subject; + Properties _properties; + Properties _remove; + ClientUpdate _update; + ingen::Resource* _object{nullptr}; + GraphImpl* _graph{nullptr}; + std::unique_ptr<CompiledGraph> _compiled_graph; + ControlBindings::Binding* _binding{nullptr}; + StatePtr _state; + Resource::Graph _context; + Type _type; Properties _added; Properties _removed; 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 531d70af..e0db262a 100644 --- a/src/server/events/Disconnect.cpp +++ b/src/server/events/Disconnect.cpp @@ -16,42 +16,52 @@ #include "events/Disconnect.hpp" -#include "ArcImpl.hpp" +#include "BlockImpl.hpp" #include "Broadcaster.hpp" #include "Buffer.hpp" -#include "DuplexPort.hpp" +#include "BufferFactory.hpp" +#include "BufferRef.hpp" +#include "CompiledGraph.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "InputPort.hpp" #include "PortImpl.hpp" +#include "PortType.hpp" #include "PreProcessContext.hpp" -#include "RunContext.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 <cassert> #include <cstdint> +#include <memory> #include <mutex> #include <set> #include <string> #include <utility> -namespace ingen { -namespace server { +namespace ingen::server { + +class RunContext; + namespace events { -Disconnect::Disconnect(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Disconnect& msg) +Disconnect::Disconnect(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Disconnect& msg) : Event(engine, client, msg.seq, timestamp) , _msg(msg) - , _graph(nullptr) -{ -} +{} + +Disconnect::~Disconnect() = default; Disconnect::Impl::Impl(Engine& e, GraphImpl* graph, @@ -107,7 +117,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() @@ -146,7 +156,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); } @@ -154,33 +166,33 @@ Disconnect::pre_process(PreProcessContext& ctx) return Event::pre_process_done(Status::PARENT_NOT_FOUND, _msg.head); } - _impl = make_unique<Impl>(_engine, - _graph, - dynamic_cast<PortImpl*>(tail), - dynamic_cast<InputPort*>(head)); + _impl = std::make_unique<Impl>(_engine, + _graph, + dynamic_cast<PortImpl*>(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); } bool -Disconnect::Impl::execute(RunContext& context, bool set_head_buffers) +Disconnect::Impl::execute(RunContext& ctx, bool set_head_buffers) { if (!_arc) { return false; } - _head->remove_arc(*_arc.get()); + _head->remove_arc(*_arc); if (_head->is_driver_port()) { return true; } if (set_head_buffers) { if (_voices) { - _head->set_voices(context, std::move(_voices)); + _head->set_voices(ctx, std::move(_voices)); } else { - _head->setup_buffers(context, *_engine.buffer_factory(), _head->poly()); + _head->setup_buffers(ctx, *_engine.buffer_factory(), _head->poly()); } _head->connect_buffers(); } else { @@ -191,12 +203,13 @@ Disconnect::Impl::execute(RunContext& context, bool set_head_buffers) } void -Disconnect::execute(RunContext& context) +Disconnect::execute(RunContext& ctx) { if (_status == Status::SUCCESS) { - if (_impl->execute(context, true)) { + 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; @@ -207,7 +220,7 @@ Disconnect::execute(RunContext& context) void Disconnect::post_process() { - Broadcaster::Transfer t(*_engine.broadcaster()); + const Broadcaster::Transfer t{*_engine.broadcaster()}; if (respond() == Status::SUCCESS) { _engine.broadcaster()->message(_msg); } @@ -220,5 +233,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 ec638c73..ad3d07b0 100644 --- a/src/server/events/Disconnect.hpp +++ b/src/server/events/Disconnect.hpp @@ -17,16 +17,28 @@ #ifndef INGEN_EVENTS_DISCONNECT_HPP #define INGEN_EVENTS_DISCONNECT_HPP -#include "CompiledGraph.hpp" #include "Event.hpp" #include "PortImpl.hpp" #include "types.hpp" +#include "ingen/Message.hpp" +#include "raul/Maid.hpp" + +#include <memory> + namespace ingen { + +class Interface; + namespace server { class ArcImpl; +class CompiledGraph; +class Engine; +class GraphImpl; class InputPort; +class PreProcessContext; +class RunContext; namespace events { @@ -37,38 +49,41 @@ namespace events { class Disconnect : public Event { public: - Disconnect(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Disconnect& msg); + Disconnect(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Disconnect& msg); + + ~Disconnect() override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; 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& context, bool set_head_buffers); + 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; - PortImpl* _tail; - InputPort* _head; - SPtr<ArcImpl> _arc; - MPtr<PortImpl::Voices> _voices; + Engine& _engine; + PortImpl* _tail; + InputPort* _head; + std::shared_ptr<ArcImpl> _arc; + raul::managed_ptr<PortImpl::Voices> _voices; }; private: - const ingen::Disconnect _msg; - GraphImpl* _graph; - UPtr<Impl> _impl; - MPtr<CompiledGraph> _compiled_graph; + const ingen::Disconnect _msg; + GraphImpl* _graph{nullptr}; + std::unique_ptr<Impl> _impl; + std::unique_ptr<CompiledGraph> _compiled_graph; }; } // namespace events diff --git a/src/server/events/DisconnectAll.cpp b/src/server/events/DisconnectAll.cpp index 4444bb26..5f0e9a5e 100644 --- a/src/server/events/DisconnectAll.cpp +++ b/src/server/events/DisconnectAll.cpp @@ -19,39 +19,38 @@ #include "ArcImpl.hpp" #include "BlockImpl.hpp" #include "Broadcaster.hpp" +#include "CompiledGraph.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" #include "InputPort.hpp" +#include "NodeImpl.hpp" #include "PortImpl.hpp" #include "PreProcessContext.hpp" #include "events/Disconnect.hpp" -#include "util.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 <memory> #include <mutex> #include <set> #include <utility> -namespace ingen { -namespace server { -namespace events { - -DisconnectAll::DisconnectAll(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::DisconnectAll& msg) - : Event(engine, client, msg.seq, timestamp) - , _msg(msg) - , _parent(nullptr) - , _block(nullptr) - , _port(nullptr) - , _deleting(false) -{ -} +namespace ingen::server::events { + +DisconnectAll::DisconnectAll(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::DisconnectAll& msg) + : Event(engine, client, msg.seq, timestamp) + , _msg(msg) + , _parent(nullptr) + , _block(nullptr) + , _port(nullptr) + , _deleting(false) +{} /** Internal version for use by other events. */ @@ -64,8 +63,7 @@ DisconnectAll::DisconnectAll(Engine& engine, , _block(dynamic_cast<BlockImpl*>(object)) , _port(dynamic_cast<PortImpl*>(object)) , _deleting(true) -{ -} +{} DisconnectAll::~DisconnectAll() { @@ -109,32 +107,29 @@ DisconnectAll::pre_process(PreProcessContext& ctx) } } - // Find set of arcs to remove - std::set<ArcImpl*> to_remove; - for (const auto& a : _parent->arcs()) { - auto* const arc = static_cast<ArcImpl*>(a.second.get()); - if (_block) { - if (arc->tail()->parent_block() == _block - || arc->head()->parent_block() == _block) { - to_remove.insert(arc); - } - } else if (_port) { - if (arc->tail() == _port || arc->head() == _port) { - to_remove.insert(arc); - } - } + // 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()))); } - // Create disconnect events (which erases from _parent->arcs()) - for (const auto& a : to_remove) { - _impls.push_back(new Disconnect::Impl( - _engine, _parent, - dynamic_cast<PortImpl*>(a->tail()), - dynamic_cast<InputPort*>(a->head()))); + // Create disconnect events to erase adjacent arcs in parent's parent + if (_port && _parent->parent()) { + auto* const 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()))); + } } 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); } } @@ -143,24 +138,24 @@ DisconnectAll::pre_process(PreProcessContext& ctx) } void -DisconnectAll::execute(RunContext& context) +DisconnectAll::execute(RunContext& ctx) { if (_status == Status::SUCCESS) { for (auto& i : _impls) { - i->execute(context, + i->execute(ctx, !_deleting || (i->head()->parent_block() != _block)); } } 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); } @@ -174,6 +169,25 @@ DisconnectAll::undo(Interface& target) } } -} // namespace events -} // namespace server -} // namespace ingen +std::set<ArcImpl*> +DisconnectAll::adjacent_arcs(GraphImpl* const graph) +{ + std::set<ArcImpl*> arcs; + for (const auto& a : graph->arcs()) { + auto* const arc = static_cast<ArcImpl*>(a.second.get()); + if (_block) { + if (arc->tail()->parent_block() == _block + || arc->head()->parent_block() == _block) { + arcs.insert(arc); + } + } else if (_port) { + if (arc->tail() == _port || arc->head() == _port) { + arcs.insert(arc); + } + } + } + + return arcs; +} + +} // namespace ingen::server::events diff --git a/src/server/events/DisconnectAll.hpp b/src/server/events/DisconnectAll.hpp index 9ab908c1..aeb180de 100644 --- a/src/server/events/DisconnectAll.hpp +++ b/src/server/events/DisconnectAll.hpp @@ -17,25 +17,34 @@ #ifndef INGEN_EVENTS_DISCONNECTALL_HPP #define INGEN_EVENTS_DISCONNECTALL_HPP -#include "CompiledGraph.hpp" #include "Disconnect.hpp" #include "Event.hpp" +#include "types.hpp" -#include "raul/Path.hpp" +#include "ingen/Message.hpp" #include <list> +#include <memory> +#include <set> namespace ingen { + +class Interface; +class Node; + namespace server { +class ArcImpl; class BlockImpl; +class CompiledGraph; +class Engine; class GraphImpl; class PortImpl; +class PreProcessContext; +class RunContext; namespace events { -class Disconnect; - /** An event to disconnect all connections to a Block. * * \ingroup engine @@ -43,32 +52,34 @@ class Disconnect; class DisconnectAll : public Event { public: - DisconnectAll(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::DisconnectAll& msg); + DisconnectAll(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::DisconnectAll& msg); DisconnectAll(Engine& engine, GraphImpl* parent, Node* object); - ~DisconnectAll(); + ~DisconnectAll() override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; private: using Impls = std::list<Disconnect::Impl*>; - const ingen::DisconnectAll _msg; - GraphImpl* _parent; - BlockImpl* _block; - PortImpl* _port; - Impls _impls; - MPtr<CompiledGraph> _compiled_graph; - bool _deleting; + std::set<ArcImpl*> adjacent_arcs(GraphImpl* graph); + + const ingen::DisconnectAll _msg; + GraphImpl* _parent; + BlockImpl* _block; + PortImpl* _port; + Impls _impls; + std::unique_ptr<CompiledGraph> _compiled_graph; + bool _deleting; }; } // namespace events diff --git a/src/server/events/Get.cpp b/src/server/events/Get.cpp index 2335c09f..9efef123 100644 --- a/src/server/events/Get.cpp +++ b/src/server/events/Get.cpp @@ -18,47 +18,51 @@ #include "BlockImpl.hpp" #include "Broadcaster.hpp" -#include "BufferFactory.hpp" #include "Engine.hpp" #include "GraphImpl.hpp" -#include "PluginImpl.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 <cstdint> +#include <memory> #include <mutex> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { -Get::Get(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Get& msg) +Get::Get(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + 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; @@ -75,18 +79,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); @@ -110,6 +120,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 e24c9998..1ec49bfa 100644 --- a/src/server/events/Get.hpp +++ b/src/server/events/Get.hpp @@ -17,18 +17,26 @@ #ifndef INGEN_EVENTS_GET_HPP #define INGEN_EVENTS_GET_HPP +#include "ingen/Message.hpp" + #include "BlockFactory.hpp" #include "ClientUpdate.hpp" #include "Event.hpp" #include "types.hpp" +#include <memory> + namespace ingen { + +class Interface; +class Node; + namespace server { -class BlockImpl; -class GraphImpl; +class Engine; class PluginImpl; -class PortImpl; +class PreProcessContext; +class RunContext; namespace events { @@ -39,19 +47,19 @@ namespace events { class Get : public Event { public: - Get(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Get& msg); + Get(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Get& msg); bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override {} + void execute(RunContext&) override; void post_process() override; 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 eb50e4a0..87bc1035 100644 --- a/src/server/events/Mark.cpp +++ b/src/server/events/Mark.cpp @@ -16,40 +16,48 @@ #include "events/Mark.hpp" +#include "ingen/Message.hpp" +#include "ingen/Status.hpp" + +#include "CompiledGraph.hpp" #include "Engine.hpp" +#include "GraphImpl.hpp" #include "PreProcessContext.hpp" #include "UndoStack.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 SPtr<Interface>& client, - SampleCount timestamp, - const ingen::BundleBegin& msg) +Mark::Mark(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::BundleBegin& msg) : Event(engine, client, msg.seq, timestamp) , _type(Type::BUNDLE_BEGIN) , _depth(-1) {} -Mark::Mark(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::BundleEnd& msg) +Mark::Mark(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::BundleEnd& msg) : Event(engine, client, msg.seq, timestamp) , _type(Type::BUNDLE_END) , _depth(-1) {} +Mark::~Mark() = default; + void -Mark::mark(PreProcessContext& ctx) +Mark::mark(PreProcessContext&) { - const UPtr<UndoStack>& stack = ((_mode == Mode::UNDO) - ? _engine.redo_stack() - : _engine.undo_stack()); + const std::unique_ptr<UndoStack>& stack = ((_mode == Mode::UNDO) + ? _engine.redo_stack() + : _engine.undo_stack()); switch (_type) { case Type::BUNDLE_BEGIN: @@ -76,7 +84,7 @@ Mark::pre_process(PreProcessContext& ctx) ctx.set_in_bundle(false); if (!ctx.dirty_graphs().empty()) { for (GraphImpl* g : ctx.dirty_graphs()) { - MPtr<CompiledGraph> cg = compile(*_engine.maid(), *g); + auto cg = compile(*g); if (cg) { _compiled_graphs.emplace(g, std::move(cg)); } @@ -93,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)); } } @@ -126,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 bff38f06..eb99c5a9 100644 --- a/src/server/events/Mark.hpp +++ b/src/server/events/Mark.hpp @@ -18,15 +18,26 @@ #define INGEN_EVENTS_MARK_HPP #include "Event.hpp" +#include "types.hpp" #include <map> +#include <memory> + +// IWYU pragma: no_include "CompiledGraph.hpp" namespace ingen { + +class Interface; +struct BundleBegin; +struct BundleEnd; + namespace server { -class CompiledGraph; +class CompiledGraph; // IWYU pragma: keep class Engine; class GraphImpl; +class PreProcessContext; +class RunContext; namespace events { @@ -40,19 +51,21 @@ namespace events { class Mark : public Event { public: - Mark(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::BundleBegin& msg); + Mark(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::BundleBegin& msg); + + Mark(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::BundleEnd& msg); - Mark(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::BundleEnd& msg); + ~Mark() override; void mark(PreProcessContext& ctx) override; bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; Execution get_execution() const override; @@ -60,7 +73,7 @@ public: private: enum class Type { BUNDLE_BEGIN, BUNDLE_END }; - using CompiledGraphs = std::map<GraphImpl*, MPtr<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 f6a39f1f..3af0ce6c 100644 --- a/src/server/events/Move.cpp +++ b/src/server/events/Move.cpp @@ -14,42 +14,45 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/Store.hpp" -#include "raul/Path.hpp" +#include "events/Move.hpp" -#include "BlockImpl.hpp" #include "Broadcaster.hpp" #include "Driver.hpp" #include "Engine.hpp" -#include "EnginePort.hpp" -#include "GraphImpl.hpp" -#include "events/Move.hpp" +#include "ingen/Interface.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; + namespace events { -Move::Move(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Move& msg) +Move::Move(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + 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); } @@ -69,14 +72,13 @@ Move::pre_process(PreProcessContext&) } void -Move::execute(RunContext& context) -{ -} +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); } @@ -89,5 +91,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 b4487b78..3940e825 100644 --- a/src/server/events/Move.hpp +++ b/src/server/events/Move.hpp @@ -18,15 +18,21 @@ #define INGEN_EVENTS_MOVE_HPP #include "Event.hpp" +#include "types.hpp" -#include "ingen/Store.hpp" -#include "raul/Path.hpp" +#include "ingen/Message.hpp" + +#include <memory> namespace ingen { + +class Interface; + namespace server { -class GraphImpl; -class PortImpl; +class Engine; +class PreProcessContext; +class RunContext; namespace events { @@ -36,13 +42,13 @@ namespace events { class Move : public Event { public: - Move(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Move& msg); + Move(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Move& msg); bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; void undo(Interface& target) override; diff --git a/src/server/events/SetPortValue.cpp b/src/server/events/SetPortValue.cpp index 2eecf9ce..04da7338 100644 --- a/src/server/events/SetPortValue.cpp +++ b/src/server/events/SetPortValue.cpp @@ -16,47 +16,45 @@ #include "SetPortValue.hpp" -#include "BlockImpl.hpp" #include "Broadcaster.hpp" #include "Buffer.hpp" +#include "BufferFactory.hpp" #include "ControlBindings.hpp" #include "Engine.hpp" #include "PortImpl.hpp" #include "RunContext.hpp" #include "ingen/Forge.hpp" -#include "ingen/LV2Features.hpp" -#include "ingen/Store.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, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - PortImpl* port, - const Atom& value, - bool activity, - bool synthetic) +SetPortValue::SetPortValue(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + PortImpl* port, + const Atom& value, + bool activity, + bool synthetic) : Event(engine, client, id, timestamp) , _port(port) , _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()); } @@ -80,43 +78,43 @@ SetPortValue::pre_process(PreProcessContext&) } void -SetPortValue::execute(RunContext& context) +SetPortValue::execute(RunContext& ctx) { - assert(_time >= context.start() && _time <= context.end()); - apply(context); - _engine.control_bindings()->port_value_changed(context, _port, _binding, _value); + assert(_time >= ctx.start() && _time <= ctx.end()); + apply(ctx); + _engine.control_bindings()->port_value_changed(ctx, _port, _binding, _value); } void -SetPortValue::apply(RunContext& context) +SetPortValue::apply(RunContext& ctx) { if (_status != Status::SUCCESS) { 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(context)) { - buf = _port->user_buffer(context).get(); + if (_port->user_buffer(ctx)) { + buf = _port->user_buffer(ctx).get(); } else { - _port->set_user_buffer(context, _buffer); + _port->set_user_buffer(ctx, _buffer); buf = _buffer.get(); } } if (buf->type() == uris.atom_Sound || buf->type() == uris.atom_Float) { if (_value.type() == uris.forge.Float) { - _port->set_control_value(context, _time, _value.get<float>()); + _port->set_control_value(ctx, _time, _value.get<float>()); } else { _status = Status::TYPE_MISMATCH; } } else if (buf->type() == uris.atom_Sequence) { - if (!buf->append_event(_time - context.start(), + if (!buf->append_event(_time - ctx.start(), _value.size(), _value.type(), - (const uint8_t*)_value.get_body())) { + reinterpret_cast<const uint8_t*>(_value.get_body()))) { _status = Status::NO_SPACE; } } else if (buf->type() == uris.atom_URID) { @@ -129,7 +127,7 @@ SetPortValue::apply(RunContext& context) 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(), @@ -138,6 +136,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 99d55af3..69d742b8 100644 --- a/src/server/events/SetPortValue.hpp +++ b/src/server/events/SetPortValue.hpp @@ -25,11 +25,18 @@ #include "ingen/Atom.hpp" #include <cstdint> +#include <memory> namespace ingen { + +class Interface; + namespace server { +class Engine; class PortImpl; +class PreProcessContext; +class RunContext; namespace events { @@ -40,23 +47,23 @@ namespace events { class SetPortValue : public Event { public: - SetPortValue(Engine& engine, - const SPtr<Interface>& client, - int32_t id, - SampleCount timestamp, - PortImpl* port, - const Atom& value, - bool activity, - bool synthetic = false); + SetPortValue(Engine& engine, + const std::shared_ptr<Interface>& client, + int32_t id, + SampleCount timestamp, + PortImpl* port, + const Atom& value, + bool activity, + bool synthetic = false); bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; bool synthetic() const { return _synthetic; } private: - void apply(RunContext& context); + void apply(RunContext& ctx); PortImpl* _port; const Atom _value; diff --git a/src/server/events/Undo.cpp b/src/server/events/Undo.cpp index 0741e60d..ea8c7d69 100644 --- a/src/server/events/Undo.cpp +++ b/src/server/events/Undo.cpp @@ -20,25 +20,28 @@ #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 <deque> +#include <memory> -namespace ingen { -namespace server { -namespace events { +namespace ingen::server::events { -Undo::Undo(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Undo& msg) +Undo::Undo(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Undo& msg) : Event(engine, client, msg.seq, timestamp) , _is_redo(false) {} -Undo::Undo(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Redo& msg) +Undo::Undo(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Redo& msg) : Event(engine, client, msg.seq, timestamp) , _is_redo(true) {} @@ -46,8 +49,10 @@ Undo::Undo(Engine& engine, bool Undo::pre_process(PreProcessContext&) { - const UPtr<UndoStack>& stack = _is_redo ? _engine.redo_stack() : _engine.undo_stack(); - const Event::Mode mode = _is_redo ? Event::Mode::REDO : Event::Mode::UNDO; + const std::unique_ptr<UndoStack>& stack = + _is_redo ? _engine.redo_stack() : _engine.undo_stack(); + + const Event::Mode mode = _is_redo ? Event::Mode::REDO : Event::Mode::UNDO; if (stack->empty()) { return Event::pre_process_done(Status::NOT_FOUND); @@ -73,9 +78,8 @@ Undo::pre_process(PreProcessContext&) } void -Undo::execute(RunContext& context) -{ -} +Undo::execute(RunContext&) +{} void Undo::post_process() @@ -83,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 e36ebaad..eb9cb70a 100644 --- a/src/server/events/Undo.hpp +++ b/src/server/events/Undo.hpp @@ -21,8 +21,20 @@ #include "UndoStack.hpp" #include "types.hpp" +#include <memory> + namespace ingen { + +class Interface; +struct Redo; +struct Undo; + namespace server { + +class Engine; +class PreProcessContext; +class RunContext; + namespace events { /** A request to undo the last change to the engine. @@ -32,18 +44,18 @@ namespace events { class Undo : public Event { public: - Undo(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Undo& msg); + Undo(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Undo& msg); - Undo(Engine& engine, - const SPtr<Interface>& client, - SampleCount timestamp, - const ingen::Redo& msg); + Undo(Engine& engine, + const std::shared_ptr<Interface>& client, + SampleCount timestamp, + const ingen::Redo& msg); bool pre_process(PreProcessContext& ctx) override; - void execute(RunContext& context) override; + void execute(RunContext& ctx) override; void post_process() override; private: diff --git a/src/server/ingen_engine.cpp b/src/server/ingen_engine.cpp index fba2e434..db1794de 100644 --- a/src/server/ingen_engine.cpp +++ b/src/server/ingen_engine.cpp @@ -15,18 +15,21 @@ */ #include "Engine.hpp" -#include "EventWriter.hpp" #include "util.hpp" #include "ingen/Module.hpp" #include "ingen/World.hpp" -using namespace ingen; +#include <memory> -struct IngenEngineModule : public ingen::Module { - void load(ingen::World& world) override { +// IWYU pragma: no_include "ingen/Atom.hpp" + +namespace ingen { + +struct EngineModule : public Module { + void load(World& world) override { server::set_denormal_flags(world.log()); - SPtr<server::Engine> engine(new server::Engine(world)); + auto engine = std::make_shared<server::Engine>(world); world.set_engine(engine); if (!world.interface()) { world.set_interface(engine->interface()); @@ -34,12 +37,14 @@ struct IngenEngineModule : public ingen::Module { } }; +} // namespace ingen + extern "C" { -ingen::Module* +INGEN_MODULE_EXPORT ingen::Module* ingen_module_load() { - return new IngenEngineModule(); + return new ingen::EngineModule(); } } // extern "C" diff --git a/src/server/ingen_jack.cpp b/src/server/ingen_jack.cpp index 37aa9c7b..9aedacad 100644 --- a/src/server/ingen_jack.cpp +++ b/src/server/ingen_jack.cpp @@ -14,8 +14,8 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "JackDriver.hpp" #include "Engine.hpp" +#include "JackDriver.hpp" #include "ingen/Atom.hpp" #include "ingen/Configuration.hpp" @@ -23,35 +23,43 @@ #include "ingen/Module.hpp" #include "ingen/World.hpp" +#include <memory> #include <string> -using namespace ingen; +namespace ingen::server { + +class Driver; + +struct JackModule : public Module { + void load(World& world) override { + server::Engine* const engine = + static_cast<server::Engine*>(world.engine().get()); -struct IngenJackModule : public ingen::Module { - void load(ingen::World& world) override { - if (((server::Engine*)world.engine().get())->driver()) { + if (engine->driver()) { world.log().warn("Engine already has a driver\n"); return; } - server::JackDriver* driver = new server::JackDriver( - *(server::Engine*)world.engine().get()); - const Atom& s = world.conf().option("jack-server"); + auto* driver = new server::JackDriver(*engine); + const Atom& s = world.conf().option("jack-server"); const std::string server_name = s.is_valid() ? s.ptr<char>() : ""; + driver->attach(server_name, world.conf().option("jack-name").ptr<char>(), nullptr); - ((server::Engine*)world.engine().get())->set_driver( - SPtr<server::Driver>(driver)); + + engine->set_driver(std::shared_ptr<server::Driver>(driver)); } }; +} // namespace ingen::server + extern "C" { -ingen::Module* +INGEN_MODULE_EXPORT ingen::Module* ingen_module_load() { - return new IngenJackModule(); + return new ingen::server::JackModule(); } } // extern "C" diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 57663344..45a193c1 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" @@ -43,9 +42,8 @@ #include "ingen/URIs.hpp" #include "ingen/World.hpp" #include "ingen/ingen.h" +#include "ingen/memory.hpp" #include "ingen/runtime_paths.hpp" -#include "ingen/types.hpp" -#include "lv2/atom/atom.h" #include "lv2/atom/atom.h" #include "lv2/atom/util.h" #include "lv2/buf-size/buf-size.h" @@ -75,42 +73,40 @@ #include <utility> #include <vector> -#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" -#define NS_RDFS "http://www.w3.org/2000/01/rdf-schema#" - namespace ingen { +class Atom; + +namespace server { + +class GraphImpl; + /** Record of a graph in this bundle. */ struct LV2Graph : public Parser::ResourceRecord { - LV2Graph(Parser::ResourceRecord record); + explicit LV2Graph(Parser::ResourceRecord record); LV2_Descriptor descriptor; }; /** Ingen LV2 library. */ -class Lib { +class Lib +{ public: explicit Lib(const char* bundle_path); - using Graphs = std::vector<SPtr<const LV2Graph>>; + using Graphs = std::vector<std::shared_ptr<const LV2Graph>>; Graphs graphs; }; -namespace server { - -class LV2Driver; - -void signal_main(RunContext& context, LV2Driver* driver); - inline size_t ui_ring_size(SampleCount block_length) { - return std::max((size_t)8192, (size_t)block_length * 16); + return std::max(static_cast<size_t>(8192u), + static_cast<size_t>(block_length) * 16u); } -class LV2Driver : public ingen::server::Driver - , public ingen::AtomSink +class LV2Driver : public Driver, public ingen::AtomSink { public: LV2Driver(Engine& engine, @@ -122,28 +118,22 @@ public: , _reader(engine.world().uri_map(), engine.world().uris(), engine.world().log(), - *engine.world().interface().get()) + *engine.world().interface()) , _writer(engine.world().uri_map(), engine.world().uris(), *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; } - void pre_process_port(RunContext& context, EnginePort* port) { + void pre_process_port(RunContext& ctx, EnginePort* port) { const URIs& uris = _engine.world().uris(); - const SampleCount nframes = context.nframes(); + const SampleCount nframes = ctx.nframes(); DuplexPort* graph_port = port->graph_port(); Buffer* graph_buf = graph_port->buffer(0).get(); void* lv2_buf = port->buffer(); @@ -151,11 +141,16 @@ public: if (graph_port->is_a(PortType::AUDIO) || graph_port->is_a(PortType::CV)) { graph_port->set_driver_buffer(lv2_buf, nframes * sizeof(float)); } else if (graph_port->buffer_type() == uris.atom_Sequence) { - graph_port->set_driver_buffer(lv2_buf, lv2_atom_total_size((LV2_Atom*)lv2_buf)); - if (graph_port->symbol() == "control") { // TODO: Safe to use index? - LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)lv2_buf; - bool enqueued = false; - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + graph_port->set_driver_buffer(lv2_buf, + lv2_atom_total_size( + static_cast<LV2_Atom*>(lv2_buf))); + + 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) + { if (AtomReader::is_message(uris, &ev->body)) { enqueued = enqueue_message(&ev->body) || enqueued; } @@ -169,13 +164,13 @@ public: } if (graph_port->is_input()) { - graph_port->monitor(context); + graph_port->monitor(ctx); } else { - graph_buf->prepare_write(context); + graph_buf->prepare_write(ctx); } } - void post_process_port(RunContext& context, EnginePort* port) { + static void post_process_port(RunContext&, EnginePort* port) { DuplexPort* graph_port = port->graph_port(); // No copying necessary, host buffers are used directly @@ -189,7 +184,8 @@ public: _engine.locate(_frame_time, nframes); // Notify buffer is a Chunk with size set to the available space - _notify_capacity = ((LV2_Atom_Sequence*)_ports[1]->buffer())->atom.size; + _notify_capacity = + static_cast<LV2_Atom_Sequence*>(_ports[1]->buffer())->atom.size; for (auto& p : _ports) { pre_process_port(_engine.run_context(), p); @@ -217,7 +213,7 @@ public: virtual void set_root_graph(GraphImpl* graph) { _root_graph = graph; } virtual GraphImpl* root_graph() { return _root_graph; } - EnginePort* get_port(const Raul::Path& path) override { + EnginePort* get_port(const raul::Path& path) override { for (auto& p : _ports) { if (p->graph_port()->path() == path) { return p; @@ -228,7 +224,7 @@ public: } /** Add a port. Called only during init or restore. */ - void add_port(RunContext& context, EnginePort* port) override { + void add_port(RunContext&, EnginePort* port) override { const uint32_t index = port->graph_port()->index(); if (_ports.size() <= index) { _ports.resize(index + 1); @@ -237,7 +233,7 @@ public: } /** Remove a port. Called only during init or restore. */ - void remove_port(RunContext& context, EnginePort* port) override { + void remove_port(RunContext&, EnginePort* port) override { const uint32_t index = port->graph_port()->index(); _ports[index] = nullptr; } @@ -249,11 +245,11 @@ public: void unregister_port(EnginePort& port) override {} /** Unused since LV2 has no dynamic ports. */ - void rename_port(const Raul::Path& old_path, - const Raul::Path& new_path) override {} + void rename_port(const raul::Path& old_path, + const raul::Path& new_path) override {} /** Unused since LV2 has no dynamic ports. */ - void port_property(const Raul::Path& path, + void port_property(const raul::Path& path, const URI& uri, const Atom& value) override {} @@ -262,17 +258,20 @@ public: return new EnginePort(graph_port); } - void append_time_events(RunContext& context, Buffer& buffer) override { - const URIs& uris = _engine.world().uris(); - LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)_ports[0]->buffer(); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { + void append_time_events(RunContext&, Buffer& buffer) override { + const URIs& uris = _engine.world().uris(); + auto* seq = static_cast<LV2_Atom_Sequence*>(_ports[0]->buffer()); + + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { if (ev->body.type == uris.atom_Object) { - const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; + const LV2_Atom_Object* obj = + reinterpret_cast<LV2_Atom_Object*>(&ev->body); + if (obj->body.otype == uris.time_Position) { buffer.append_event(ev->time.frames, ev->body.size, ev->body.type, - (const uint8_t*)(&ev->body + 1)); + reinterpret_cast<const uint8_t*>(&ev->body + 1)); } } } @@ -291,7 +290,7 @@ public: return true; } - Raul::Semaphore& main_sem() { return _main_sem; } + raul::Semaphore& main_sem() { return _main_sem; } /** AtomSink::write implementation called by the PostProcessor in the main * thread to write responses to the UI. @@ -320,24 +319,26 @@ public: buf = realloc(buf, sizeof(LV2_Atom) + atom.size); memcpy(buf, &atom, sizeof(LV2_Atom)); - if (!_from_ui.read(atom.size, (char*)buf + sizeof(LV2_Atom))) { - _engine.log().rt_error("Error reading body from from-UI ring\n"); + if (!_from_ui.read(atom.size, + static_cast<char*>(buf) + sizeof(LV2_Atom))) { + _engine.log().rt_error( + "Error reading body from from-UI ring\n"); break; } - _reader.write((LV2_Atom*)buf); + _reader.write(static_cast<LV2_Atom*>(buf)); read += sizeof(LV2_Atom) + atom.size; } free(buf); } - void flush_to_ui(RunContext& context) { + void flush_to_ui(RunContext&) { if (_ports.size() < 2) { _engine.log().rt_error("Standard control ports are not present\n"); return; } - LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)_ports[1]->buffer(); + auto* seq = static_cast<LV2_Atom_Sequence*>(_ports[1]->buffer()); if (!seq) { _engine.log().rt_error("Notify output not connected\n"); return; @@ -358,13 +359,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 } - LV2_Atom_Event* ev = (LV2_Atom_Event*)( - (uint8_t*)seq + lv2_atom_total_size(&seq->atom)); + 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)); @@ -400,32 +402,36 @@ public: private: Engine& _engine; Ports _ports; - Raul::Semaphore _main_sem; + raul::Semaphore _main_sem; AtomReader _reader; AtomWriter _writer; - Raul::RingBuffer _from_ui; - Raul::RingBuffer _to_ui; - GraphImpl* _root_graph; - uint32_t _notify_capacity; + raul::RingBuffer _from_ui; + raul::RingBuffer _to_ui; + GraphImpl* _root_graph{nullptr}; + uint32_t _notify_capacity{0}; SampleCount _block_length; size_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}; }; -} // namespace server -} // namespace ingen +struct IngenPlugin { + std::unique_ptr<World> world; + std::shared_ptr<Engine> engine; + std::unique_ptr<std::thread> main; + LV2_URID_Map* map = nullptr; + int argc = 0; + char** argv = nullptr; +}; extern "C" { -using namespace ingen; -using namespace ingen::server; - static void -ingen_lv2_main(const SPtr<Engine>& engine, const SPtr<LV2Driver>& driver) +ingen_lv2_main(const std::shared_ptr<Engine>& engine, + const std::shared_ptr<LV2Driver>& driver) { while (true) { // Wait until there is work to be done @@ -441,22 +447,6 @@ ingen_lv2_main(const SPtr<Engine>& engine, const SPtr<LV2Driver>& driver) } } -struct IngenPlugin { - IngenPlugin() - : main(nullptr) - , map(nullptr) - , argc(0) - , argv(nullptr) - {} - - UPtr<ingen::World> world; - SPtr<Engine> engine; - UPtr<std::thread> main; - LV2_URID_Map* map; - int argc; - char** argv; -}; - static Lib::Graphs find_graphs(const URI& manifest_uri) { @@ -470,7 +460,7 @@ find_graphs(const URI& manifest_uri) Lib::Graphs graphs; for (const auto& r : resources) { - graphs.push_back(SPtr<const LV2Graph>(new LV2Graph(r))); + graphs.push_back(std::make_shared<LV2Graph>(r)); } return graphs; @@ -489,13 +479,13 @@ ingen_instantiate(const LV2_Descriptor* descriptor, const LV2_Options_Option* options = nullptr; for (int i = 0; features[i]; ++i) { if (!strcmp(features[i]->URI, LV2_URID__map)) { - map = (LV2_URID_Map*)features[i]->data; + map = static_cast<LV2_URID_Map*>(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_URID__unmap)) { - unmap = (LV2_URID_Unmap*)features[i]->data; + unmap = static_cast<LV2_URID_Unmap*>(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_LOG__log)) { - log = (LV2_Log_Log*)features[i]->data; + log = static_cast<LV2_Log_Log*>(features[i]->data); } else if (!strcmp(features[i]->URI, LV2_OPTIONS__options)) { - options = (const LV2_Options_Option*)features[i]->data; + options = static_cast<const LV2_Options_Option*>(features[i]->data); } } @@ -505,17 +495,23 @@ 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; } set_bundle_path(bundle_path); const std::string manifest_path = ingen::bundle_file_path("manifest.ttl"); - SerdNode manifest_node = serd_node_new_file_uri( - (const uint8_t*)manifest_path.c_str(), nullptr, nullptr, true); - - Lib::Graphs graphs = find_graphs(URI((const char*)manifest_node.buf)); + SerdNode manifest_node = + serd_node_new_file_uri(reinterpret_cast<const uint8_t*>( + manifest_path.c_str()), + nullptr, + nullptr, + true); + + const Lib::Graphs graphs = find_graphs(URI(reinterpret_cast<const char*>(manifest_node.buf))); serd_node_free(&manifest_node); const LV2Graph* graph = nullptr; @@ -531,22 +527,22 @@ ingen_instantiate(const LV2_Descriptor* descriptor, return nullptr; } - IngenPlugin* plugin = new IngenPlugin(); + auto* plugin = new IngenPlugin(); plugin->map = map; - plugin->world = UPtr<ingen::World>(new ingen::World(map, unmap, log)); + 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) { - block_length = *(const int32_t*)o->value; + block_length = *static_cast<const int32_t*>(o->value); } else if (o->key == bufsz_seq && o->type == atom_Int) { - seq_size = *(const int32_t*)o->value; + seq_size = *static_cast<const int32_t*>(o->value); } } } @@ -566,24 +562,24 @@ ingen_instantiate(const LV2_Descriptor* descriptor, "queue-size", plugin->world->forge().make(std::max(block_length, seq_size) * 4)); - SPtr<server::Engine> engine(new server::Engine(*plugin->world)); + auto engine = std::make_shared<Engine>(*plugin->world); plugin->engine = engine; plugin->world->set_engine(engine); - SPtr<Interface> interface = engine->interface(); + const std::shared_ptr<Interface> interface = engine->interface(); plugin->world->set_interface(interface); - server::ThreadManager::set_flag(server::THREAD_PRE_PROCESS); - server::ThreadManager::single_threaded = true; + ThreadManager::set_flag(THREAD_PRE_PROCESS); + ThreadManager::single_threaded = true; - LV2Driver* driver = new LV2Driver(*engine.get(), block_length, seq_size, rate); - engine->set_driver(SPtr<ingen::server::Driver>(driver)); + auto* driver = new LV2Driver(*engine, block_length, seq_size, rate); + engine->set_driver(std::shared_ptr<Driver>(driver)); engine->activate(); - server::ThreadManager::single_threaded = true; + 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,22 +601,20 @@ 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. */ - SPtr<Interface> client(&driver->writer(), NullDeleter<Interface>); + const std::shared_ptr<Interface> client{&driver->writer(), NullDeleter<Interface>}; interface->set_respondee(client); engine->register_client(client); driver->set_instantiated(true); - return (LV2_Handle)plugin; + return static_cast<LV2_Handle>(plugin); } static void ingen_connect_port(LV2_Handle instance, uint32_t port, void* data) { - using namespace ingen::server; - - IngenPlugin* me = (IngenPlugin*)instance; - server::Engine* engine = (server::Engine*)me->world->engine().get(); - const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); + auto* me = static_cast<IngenPlugin*>(instance); + 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); } else { @@ -631,22 +625,22 @@ ingen_connect_port(LV2_Handle instance, uint32_t port, void* data) static void ingen_activate(LV2_Handle instance) { - IngenPlugin* me = (IngenPlugin*)instance; - SPtr<server::Engine> engine = static_ptr_cast<server::Engine>(me->world->engine()); - const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); + auto* me = static_cast<IngenPlugin*>(instance); + auto engine = std::static_pointer_cast<Engine>(me->world->engine()); + const auto driver = std::static_pointer_cast<LV2Driver>(engine->driver()); engine->activate(); - me->main = make_unique<std::thread>(ingen_lv2_main, engine, driver); + me->main = std::make_unique<std::thread>(ingen_lv2_main, engine, driver); } static void ingen_run(LV2_Handle instance, uint32_t sample_count) { - IngenPlugin* me = (IngenPlugin*)instance; - SPtr<server::Engine> engine = static_ptr_cast<server::Engine>(me->world->engine()); - const SPtr<LV2Driver>& driver = static_ptr_cast<LV2Driver>(engine->driver()); + auto* me = static_cast<IngenPlugin*>(instance); + auto engine = std::static_pointer_cast<Engine>(me->world->engine()); + const auto driver = std::static_pointer_cast<LV2Driver>(engine->driver()); - server::ThreadManager::set_flag(ingen::server::THREAD_PROCESS); - server::ThreadManager::set_flag(ingen::server::THREAD_IS_REAL_TIME); + ThreadManager::set_flag(THREAD_PROCESS); + ThreadManager::set_flag(THREAD_IS_REAL_TIME); driver->run(sample_count); } @@ -654,7 +648,7 @@ ingen_run(LV2_Handle instance, uint32_t sample_count) static void ingen_deactivate(LV2_Handle instance) { - IngenPlugin* me = (IngenPlugin*)instance; + auto* me = static_cast<IngenPlugin*>(instance); me->world->engine()->deactivate(); if (me->main) { me->main->join(); @@ -665,9 +659,9 @@ ingen_deactivate(LV2_Handle instance) static void ingen_cleanup(LV2_Handle instance) { - IngenPlugin* me = (IngenPlugin*)instance; - me->world->set_engine(SPtr<ingen::server::Engine>()); - me->world->set_interface(SPtr<ingen::Interface>()); + auto* me = static_cast<IngenPlugin*>(instance); + me->world->set_engine(nullptr); + me->world->set_interface(nullptr); if (me->main) { me->main->join(); me->main.reset(); @@ -684,9 +678,9 @@ get_state_features(const LV2_Feature* const* features, { for (int i = 0; features[i]; ++i) { if (map && !strcmp(features[i]->URI, LV2_STATE__mapPath)) { - *map = (LV2_State_Map_Path*)features[i]->data; + *map = static_cast<LV2_State_Map_Path*>(features[i]->data); } else if (make && !strcmp(features[i]->URI, LV2_STATE__makePath)) { - *make = (LV2_State_Make_Path*)features[i]->data; + *make = static_cast<LV2_State_Make_Path*>(features[i]->data); } } } @@ -698,7 +692,7 @@ ingen_save(LV2_Handle instance, uint32_t flags, const LV2_Feature* const* features) { - IngenPlugin* plugin = (IngenPlugin*)instance; + auto* plugin = static_cast<IngenPlugin*>(instance); LV2_State_Map_Path* map_path = nullptr; LV2_State_Make_Path* make_path = nullptr; @@ -708,17 +702,17 @@ 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); - auto root = plugin->world->store()->find(Raul::Path("/")); + 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}); @@ -745,7 +739,7 @@ ingen_restore(LV2_Handle instance, uint32_t flags, const LV2_Feature* const* features) { - IngenPlugin* plugin = (IngenPlugin*)instance; + auto* plugin = static_cast<IngenPlugin*>(instance); LV2_State_Map_Path* map_path = nullptr; get_state_features(features, &map_path, nullptr); @@ -754,14 +748,14 @@ 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; - uint32_t type; - uint32_t valflags; + 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 = (const char*)retrieve( - handle, ingen_file, &size, &type, &valflags); + const char* path = static_cast<const char*>( + retrieve(handle, ingen_file, &size, &type, &valflags)); if (!path) { return LV2_STATE_ERR_NO_PROPERTY; } @@ -774,7 +768,7 @@ ingen_restore(LV2_Handle instance, #if 0 // Remove existing root graph contents - SPtr<Engine> engine = plugin->engine; + std::shared_ptr<Engine> engine = plugin->engine; for (const auto& b : engine->root_graph()->blocks()) { plugin->world->interface()->del(b.uri()); } @@ -789,7 +783,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); @@ -809,6 +803,7 @@ ingen_extension_data(const char* uri) LV2Graph::LV2Graph(Parser::ResourceRecord record) : Parser::ResourceRecord(std::move(record)) + , descriptor() { descriptor.URI = uri.c_str(); descriptor.instantiate = ingen_instantiate; @@ -824,10 +819,14 @@ Lib::Lib(const char* bundle_path) { ingen::set_bundle_path(bundle_path); const std::string manifest_path = ingen::bundle_file_path("manifest.ttl"); - SerdNode manifest_node = serd_node_new_file_uri( - (const uint8_t*)manifest_path.c_str(), nullptr, nullptr, true); + SerdNode manifest_node = + serd_node_new_file_uri(reinterpret_cast<const uint8_t*>( + manifest_path.c_str()), + nullptr, + nullptr, + true); - graphs = find_graphs(URI((const char*)manifest_node.buf)); + graphs = find_graphs(URI(reinterpret_cast<const char*>(manifest_node.buf))); serd_node_free(&manifest_node); } @@ -835,17 +834,23 @@ Lib::Lib(const char* bundle_path) static void lib_cleanup(LV2_Lib_Handle handle) { - Lib* lib = (Lib*)handle; + Lib* lib = static_cast<Lib*>(handle); delete lib; } static const LV2_Descriptor* lib_get_plugin(LV2_Lib_Handle handle, uint32_t index) { - Lib* lib = (Lib*)handle; + Lib* lib = static_cast<Lib*>(handle); return index < lib->graphs.size() ? &lib->graphs[index]->descriptor : nullptr; } +} // extern "C" +} // namespace server +} // namespace ingen + +extern "C" { + /** LV2 plugin library entry point */ LV2_SYMBOL_EXPORT const LV2_Lib_Descriptor* @@ -853,16 +858,16 @@ lv2_lib_descriptor(const char* bundle_path, const LV2_Feature*const* features) { static const uint32_t desc_size = sizeof(LV2_Lib_Descriptor); - Lib* lib = new Lib(bundle_path); + auto* lib = new ingen::server::Lib(bundle_path); // FIXME: memory leak. I think the LV2_Lib_Descriptor API is botched :( - LV2_Lib_Descriptor* desc = (LV2_Lib_Descriptor*)malloc(desc_size); + auto* desc = static_cast<LV2_Lib_Descriptor*>(malloc(desc_size)); desc->handle = lib; desc->size = desc_size; - desc->cleanup = lib_cleanup; - desc->get_plugin = lib_get_plugin; + desc->cleanup = ingen::server::lib_cleanup; + desc->get_plugin = ingen::server::lib_get_plugin; return desc; } -} // extern "C" +} diff --git a/src/server/ingen_portaudio.cpp b/src/server/ingen_portaudio.cpp index f4e633d0..6de5a40c 100644 --- a/src/server/ingen_portaudio.cpp +++ b/src/server/ingen_portaudio.cpp @@ -14,39 +14,45 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "PortAudioDriver.hpp" #include "Engine.hpp" +#include "PortAudioDriver.hpp" #include "ingen/Log.hpp" #include "ingen/Module.hpp" #include "ingen/World.hpp" -#include "ingen/types.hpp" -namespace ingen { namespace server { class Driver; } } +#include <memory> + +// IWYU pragma: no_include "ingen/FilePath.hpp" -using namespace ingen; +namespace ingen::server { -struct IngenPortAudioModule : public ingen::Module { - void load(ingen::World& world) override { - if (((server::Engine*)world.engine().get())->driver()) { +class Driver; + +struct PortAudioModule : public Module { + void load(World& world) override { + server::Engine* const engine = + static_cast<server::Engine*>(world.engine().get()); + + if (engine->driver()) { world.log().warn("Engine already has a driver\n"); return; } - server::PortAudioDriver* driver = new server::PortAudioDriver( - *(server::Engine*)world.engine().get()); + auto* driver = new server::PortAudioDriver(*engine); driver->attach(); - ((server::Engine*)world.engine().get())->set_driver( - SPtr<server::Driver>(driver)); + engine->set_driver(std::shared_ptr<server::Driver>(driver)); } }; +} // namespace ingen::server + extern "C" { -ingen::Module* +INGEN_MODULE_EXPORT ingen::Module* ingen_module_load() { - return new IngenPortAudioModule(); + return new ingen::server::PortAudioModule(); } } // extern "C" diff --git a/src/server/internals/BlockDelay.cpp b/src/server/internals/BlockDelay.cpp index 0176c9b1..516b7cf4 100644 --- a/src/server/internals/BlockDelay.cpp +++ b/src/server/internals/BlockDelay.cpp @@ -16,18 +16,24 @@ #include "internals/BlockDelay.hpp" +#include "BlockImpl.hpp" #include "Buffer.hpp" +#include "BufferFactory.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #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" -namespace ingen { -namespace server { +#include <memory> + +namespace ingen::server { class RunContext; @@ -35,12 +41,12 @@ namespace internals { InternalPlugin* BlockDelayNode::internal_plugin(URIs& uris) { return new InternalPlugin( - uris, URI(NS_INTERNALS "BlockDelay"), Raul::Symbol("blockDelay")); + uris, URI(NS_INTERNALS "BlockDelay"), raul::Symbol("blockDelay")); } BlockDelayNode::BlockDelayNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate) @@ -49,12 +55,12 @@ BlockDelayNode::BlockDelayNode(InternalPlugin* plugin, const ingen::URIs& uris = bufs.uris(); _ports = bufs.maid().make_managed<Ports>(2); - _in_port = new InputPort(bufs, this, Raul::Symbol("in"), 0, 1, + _in_port = new InputPort(bufs, this, raul::Symbol("in"), 0, 1, PortType::AUDIO, 0, bufs.forge().make(0.0f)); _in_port->set_property(uris.lv2_name, bufs.forge().alloc("In")); _ports->at(0) = _in_port; - _out_port = new OutputPort(bufs, this, Raul::Symbol("out"), 0, 1, + _out_port = new OutputPort(bufs, this, raul::Symbol("out"), 0, 1, PortType::AUDIO, 0, bufs.forge().make(0.0f)); _out_port->set_property(uris.lv2_name, bufs.forge().alloc("Out")); _ports->at(1) = _out_port; @@ -75,15 +81,14 @@ BlockDelayNode::activate(BufferFactory& bufs) } void -BlockDelayNode::run(RunContext& context) +BlockDelayNode::run(RunContext& ctx) { // Copy buffer from last cycle to output - _out_port->buffer(0)->copy(context, _buffer.get()); + _out_port->buffer(0)->copy(ctx, _buffer.get()); // Copy input from this cycle to buffer - _buffer->copy(context, _in_port->buffer(0).get()); + _buffer->copy(ctx, _in_port->buffer(0).get()); } } // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/internals/BlockDelay.hpp b/src/server/internals/BlockDelay.hpp index 0e8fadce..78a03c28 100644 --- a/src/server/internals/BlockDelay.hpp +++ b/src/server/internals/BlockDelay.hpp @@ -21,13 +21,22 @@ #include "InternalBlock.hpp" #include "types.hpp" +namespace raul { +class Symbol; +} // namespace raul + namespace ingen { + +class URIs; + namespace server { +class BufferFactory; +class GraphImpl; class InputPort; -class OutputPort; class InternalPlugin; -class BufferFactory; +class OutputPort; +class RunContext; namespace internals { @@ -36,16 +45,16 @@ class BlockDelayNode : public InternalBlock public: BlockDelayNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate); - ~BlockDelayNode(); + ~BlockDelayNode() override; void activate(BufferFactory& bufs) override; - void run(RunContext& context) override; + void run(RunContext& ctx) override; static InternalPlugin* internal_plugin(URIs& uris); @@ -55,8 +64,8 @@ private: BufferRef _buffer; }; +} // namespace internals } // namespace server } // namespace ingen -} // namespace internals #endif // INGEN_INTERNALS_BLOCKDELAY_HPP diff --git a/src/server/internals/Controller.cpp b/src/server/internals/Controller.cpp index b8738e1e..ec400075 100644 --- a/src/server/internals/Controller.cpp +++ b/src/server/internals/Controller.cpp @@ -15,41 +15,49 @@ */ #include "Buffer.hpp" -#include "Engine.hpp" +#include "BufferFactory.hpp" +#include "BufferRef.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #include "OutputPort.hpp" -#include "PostProcessor.hpp" +#include "PortType.hpp" #include "RunContext.hpp" -#include "util.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 <cassert> #include <cmath> #include <initializer_list> +#include <memory> + +namespace ingen::server { + +class GraphImpl; -namespace ingen { -namespace server { namespace internals { InternalPlugin* ControllerNode::internal_plugin(URIs& uris) { return new InternalPlugin( - uris, URI(NS_INTERNALS "Controller"), Raul::Symbol("controller")); + uris, URI(NS_INTERNALS "Controller"), raul::Symbol("controller")); } ControllerNode::ControllerNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, 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); @@ -58,21 +66,21 @@ ControllerNode::ControllerNode(InternalPlugin* plugin, const Atom one = bufs.forge().make(1.0f); const Atom atom_Float = bufs.forge().make_urid(URI(LV2_ATOM__Float)); - _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1, + _midi_in_port = new InputPort(bufs, this, raul::Symbol("input"), 0, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); _midi_in_port->set_property(uris.atom_supports, bufs.forge().make_urid(uris.midi_MidiEvent)); _ports->at(0) = _midi_in_port; - _midi_out_port = new OutputPort(bufs, this, Raul::Symbol("event"), 1, 1, + _midi_out_port = new OutputPort(bufs, this, raul::Symbol("event"), 1, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_out_port->set_property(uris.lv2_name, bufs.forge().alloc("Event")); _midi_out_port->set_property(uris.atom_supports, bufs.forge().make_urid(uris.midi_MidiEvent)); _ports->at(1) = _midi_out_port; - _param_port = new InputPort(bufs, this, Raul::Symbol("controller"), 2, 1, + _param_port = new InputPort(bufs, this, raul::Symbol("controller"), 2, 1, PortType::ATOM, uris.atom_Sequence, zero); _param_port->set_property(uris.atom_supports, atom_Float); _param_port->set_property(uris.lv2_minimum, zero); @@ -81,26 +89,26 @@ ControllerNode::ControllerNode(InternalPlugin* plugin, _param_port->set_property(uris.lv2_name, bufs.forge().alloc("Controller")); _ports->at(2) = _param_port; - _log_port = new InputPort(bufs, this, Raul::Symbol("logarithmic"), 3, 1, + _log_port = new InputPort(bufs, this, raul::Symbol("logarithmic"), 3, 1, PortType::ATOM, uris.atom_Sequence, zero); _log_port->set_property(uris.atom_supports, atom_Float); _log_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _log_port->set_property(uris.lv2_name, bufs.forge().alloc("Logarithmic")); _ports->at(3) = _log_port; - _min_port = new InputPort(bufs, this, Raul::Symbol("minimum"), 4, 1, + _min_port = new InputPort(bufs, this, raul::Symbol("minimum"), 4, 1, PortType::ATOM, uris.atom_Sequence, zero); _min_port->set_property(uris.atom_supports, atom_Float); _min_port->set_property(uris.lv2_name, bufs.forge().alloc("Minimum")); _ports->at(4) = _min_port; - _max_port = new InputPort(bufs, this, Raul::Symbol("maximum"), 5, 1, + _max_port = new InputPort(bufs, this, raul::Symbol("maximum"), 5, 1, PortType::ATOM, uris.atom_Sequence, one); _max_port->set_property(uris.atom_supports, atom_Float); _max_port->set_property(uris.lv2_name, bufs.forge().alloc("Maximum")); _ports->at(5) = _max_port; - _audio_port = new OutputPort(bufs, this, Raul::Symbol("output"), 6, 1, + _audio_port = new OutputPort(bufs, this, raul::Symbol("output"), 6, 1, PortType::ATOM, uris.atom_Sequence, zero); _audio_port->set_property(uris.atom_supports, atom_Float); _audio_port->set_property(uris.lv2_name, bufs.forge().alloc("Output")); @@ -108,17 +116,18 @@ ControllerNode::ControllerNode(InternalPlugin* plugin, } void -ControllerNode::run(RunContext& context) +ControllerNode::run(RunContext& ctx) { - const BufferRef midi_in = _midi_in_port->buffer(0); - LV2_Atom_Sequence* seq = midi_in->get<LV2_Atom_Sequence>(); - const BufferRef midi_out = _midi_out_port->buffer(0); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); + const BufferRef midi_in = _midi_in_port->buffer(0); + auto* seq = midi_in->get<LV2_Atom_Sequence>(); + const BufferRef midi_out = _midi_out_port->buffer(0); + + 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 && lv2_midi_message_type(buf) == LV2_MIDI_MSG_CONTROLLER) { - if (control(context, buf[1], buf[2], ev->time.frames + context.start())) { + if (control(ctx, buf[1], buf[2], ev->time.frames + ctx.start())) { midi_out->append_event(ev->time.frames, &ev->body); } } @@ -126,15 +135,15 @@ ControllerNode::run(RunContext& context) } bool -ControllerNode::control(RunContext& context, uint8_t control_num, uint8_t val, FrameTime time) +ControllerNode::control(RunContext& ctx, uint8_t control_num, uint8_t val, FrameTime time) { - assert(time >= context.start() && time <= context.end()); - const uint32_t offset = time - context.start(); + assert(time >= ctx.start() && time <= ctx.end()); + const uint32_t offset = time - ctx.start(); const Sample nval = (val / 127.0f); // normalized [0, 1] if (_learning) { - _param_port->set_control_value(context, time, control_num); + _param_port->set_control_value(ctx, time, control_num); _param_port->force_monitor_update(); _learning = false; } else { @@ -153,25 +162,24 @@ ControllerNode::control(RunContext& context, uint8_t control_num, uint8_t val, F const Sample max_port_val = _max_port->buffer(0)->value_at(offset); const Sample log_port_val = _log_port->buffer(0)->value_at(offset); - Sample scaled_value; + Sample scaled_value = 0.0f; if (log_port_val > 0.0f) { // haaaaack, stupid negatives and logarithms - Sample log_offset = 0; + Sample log_offset = 0.0f; if (min_port_val < 0) { - log_offset = fabs(min_port_val); + log_offset = fabsf(min_port_val); } - const Sample min = log(min_port_val + 1 + log_offset); - const Sample max = log(max_port_val + 1 + log_offset); + 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; } else { scaled_value = ((nval) * (max_port_val - min_port_val)) + min_port_val; } - _audio_port->set_control_value(context, time, scaled_value); + _audio_port->set_control_value(ctx, time, scaled_value); return true; } } // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/internals/Controller.hpp b/src/server/internals/Controller.hpp index 0a62b235..2a0bc834 100644 --- a/src/server/internals/Controller.hpp +++ b/src/server/internals/Controller.hpp @@ -18,15 +18,26 @@ #define INGEN_INTERNALS_CONTROLLER_HPP #include "InternalBlock.hpp" +#include "types.hpp" #include <cstdint> +namespace raul { +class Symbol; +} // namespace raul + namespace ingen { + +class URIs; + namespace server { +class BufferFactory; +class GraphImpl; class InputPort; -class OutputPort; class InternalPlugin; +class OutputPort; +class RunContext; namespace internals { @@ -42,14 +53,14 @@ class ControllerNode : public InternalBlock public: ControllerNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate); - void run(RunContext& context) override; + void run(RunContext& ctx) override; - bool control(RunContext& context, uint8_t control_num, uint8_t val, FrameTime time); + bool control(RunContext& ctx, uint8_t control_num, uint8_t val, FrameTime time); void learn() override { _learning = true; } @@ -63,11 +74,11 @@ private: InputPort* _min_port; InputPort* _max_port; OutputPort* _audio_port; - bool _learning; + bool _learning{false}; }; +} // namespace internals } // namespace server } // namespace ingen -} // namespace internals #endif // INGEN_INTERNALS_CONTROLLER_HPP diff --git a/src/server/internals/Note.cpp b/src/server/internals/Note.cpp index cfc0c157..94598fb7 100644 --- a/src/server/internals/Note.cpp +++ b/src/server/internals/Note.cpp @@ -16,43 +16,52 @@ #include "internals/Note.hpp" +#include "BlockImpl.hpp" #include "Buffer.hpp" +#include "BufferFactory.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 <cassert> #include <cmath> +#include <memory> #include <utility> // #define NOTE_DEBUG 1 -namespace ingen { -namespace server { +namespace ingen::server { + +class GraphImpl; + namespace internals { InternalPlugin* NoteNode::internal_plugin(URIs& uris) { return new InternalPlugin( - uris, URI(NS_INTERNALS "Note"), Raul::Symbol("note")); + uris, URI(NS_INTERNALS "Note"), raul::Symbol("note")); } NoteNode::NoteNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, 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); @@ -60,14 +69,14 @@ NoteNode::NoteNode(InternalPlugin* plugin, const Atom zero = bufs.forge().make(0.0f); const Atom one = bufs.forge().make(1.0f); - _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1, + _midi_in_port = new InputPort(bufs, this, raul::Symbol("input"), 0, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); _midi_in_port->set_property(uris.atom_supports, bufs.forge().make_urid(uris.midi_MidiEvent)); _ports->at(0) = _midi_in_port; - _freq_port = new OutputPort(bufs, this, Raul::Symbol("frequency"), 1, _polyphony, + _freq_port = new OutputPort(bufs, this, raul::Symbol("frequency"), 1, _polyphony, PortType::ATOM, uris.atom_Sequence, bufs.forge().make(440.0f)); _freq_port->set_property(uris.atom_supports, bufs.uris().atom_Float); @@ -76,7 +85,7 @@ NoteNode::NoteNode(InternalPlugin* plugin, _freq_port->set_property(uris.lv2_maximum, bufs.forge().make(25088.0f)); _ports->at(1) = _freq_port; - _num_port = new OutputPort(bufs, this, Raul::Symbol("number"), 1, _polyphony, + _num_port = new OutputPort(bufs, this, raul::Symbol("number"), 1, _polyphony, PortType::ATOM, uris.atom_Sequence, zero); _num_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _num_port->set_property(uris.lv2_minimum, zero); @@ -85,7 +94,7 @@ NoteNode::NoteNode(InternalPlugin* plugin, _num_port->set_property(uris.lv2_name, bufs.forge().alloc("Number")); _ports->at(2) = _num_port; - _vel_port = new OutputPort(bufs, this, Raul::Symbol("velocity"), 2, _polyphony, + _vel_port = new OutputPort(bufs, this, raul::Symbol("velocity"), 2, _polyphony, PortType::ATOM, uris.atom_Sequence, zero); _vel_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _vel_port->set_property(uris.lv2_minimum, zero); @@ -93,21 +102,21 @@ NoteNode::NoteNode(InternalPlugin* plugin, _vel_port->set_property(uris.lv2_name, bufs.forge().alloc("Velocity")); _ports->at(3) = _vel_port; - _gate_port = new OutputPort(bufs, this, Raul::Symbol("gate"), 3, _polyphony, + _gate_port = new OutputPort(bufs, this, raul::Symbol("gate"), 3, _polyphony, PortType::ATOM, uris.atom_Sequence, zero); _gate_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _gate_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _gate_port->set_property(uris.lv2_name, bufs.forge().alloc("Gate")); _ports->at(4) = _gate_port; - _trig_port = new OutputPort(bufs, this, Raul::Symbol("trigger"), 4, _polyphony, + _trig_port = new OutputPort(bufs, this, raul::Symbol("trigger"), 4, _polyphony, PortType::ATOM, uris.atom_Sequence, zero); _trig_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _trig_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _trig_port->set_property(uris.lv2_name, bufs.forge().alloc("Trigger")); _ports->at(5) = _trig_port; - _bend_port = new OutputPort(bufs, this, Raul::Symbol("bend"), 5, _polyphony, + _bend_port = new OutputPort(bufs, this, raul::Symbol("bend"), 5, _polyphony, PortType::ATOM, uris.atom_Sequence, zero); _bend_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _bend_port->set_property(uris.lv2_name, bufs.forge().alloc("Bender")); @@ -116,7 +125,7 @@ NoteNode::NoteNode(InternalPlugin* plugin, _bend_port->set_property(uris.lv2_maximum, one); _ports->at(6) = _bend_port; - _pressure_port = new OutputPort(bufs, this, Raul::Symbol("pressure"), 6, _polyphony, + _pressure_port = new OutputPort(bufs, this, raul::Symbol("pressure"), 6, _polyphony, PortType::ATOM, uris.atom_Sequence, zero); _pressure_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _pressure_port->set_property(uris.lv2_name, bufs.forge().alloc("Pressure")); @@ -146,9 +155,9 @@ NoteNode::prepare_poly(BufferFactory& bufs, uint32_t poly) } bool -NoteNode::apply_poly(RunContext& context, uint32_t poly) +NoteNode::apply_poly(RunContext& ctx, uint32_t poly) { - if (!BlockImpl::apply_poly(context, poly)) { + if (!BlockImpl::apply_poly(ctx, poly)) { return false; } @@ -162,50 +171,58 @@ NoteNode::apply_poly(RunContext& context, uint32_t poly) } void -NoteNode::run(RunContext& context) +NoteNode::run(RunContext& ctx) { - Buffer* const midi_in = _midi_in_port->buffer(0).get(); - LV2_Atom_Sequence* seq = midi_in->get<LV2_Atom_Sequence>(); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY_CONST(&ev->body); - const FrameTime time = context.start() + (FrameTime)ev->time.frames; + Buffer* const midi_in = _midi_in_port->buffer(0).get(); + auto* seq = midi_in->get<LV2_Atom_Sequence>(); + + LV2_ATOM_SEQUENCE_FOREACH (seq, ev) { + const auto* buf = + static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&ev->body)); + + const FrameTime time = + ctx.start() + static_cast<FrameTime>(ev->time.frames); + if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && ev->body.size >= 3) { switch (lv2_midi_message_type(buf)) { case LV2_MIDI_MSG_NOTE_ON: if (buf[2] == 0) { - note_off(context, buf[1], time); + note_off(ctx, buf[1], time); } else { - note_on(context, buf[1], buf[2], time); + note_on(ctx, buf[1], buf[2], time); } break; case LV2_MIDI_MSG_NOTE_OFF: - note_off(context, buf[1], time); + note_off(ctx, buf[1], time); break; case LV2_MIDI_MSG_CONTROLLER: switch (buf[1]) { case LV2_MIDI_CTL_ALL_NOTES_OFF: case LV2_MIDI_CTL_ALL_SOUNDS_OFF: - all_notes_off(context, time); + all_notes_off(ctx, time); break; case LV2_MIDI_CTL_SUSTAIN: if (buf[2] > 63) { - sustain_on(context, time); + sustain_on(ctx, time); } else { - sustain_off(context, time); + sustain_off(ctx, time); } break; } break; case LV2_MIDI_MSG_BENDER: - bend(context, time, (((((uint16_t)buf[2] << 7) | buf[1]) - 8192.0f) - / 8192.0f)); + bend(ctx, + time, + ((((static_cast<uint16_t>(buf[2]) << 7) | buf[1]) - + 8192.0f) / + 8192.0f)); break; case LV2_MIDI_MSG_CHANNEL_PRESSURE: - channel_pressure(context, time, buf[1] / 127.0f); + channel_pressure(ctx, time, buf[1] / 127.0f); break; case LV2_MIDI_MSG_NOTE_PRESSURE: - note_pressure(context, time, buf[1], buf[2] / 127.0f); + note_pressure(ctx, time, buf[1], buf[2] / 127.0f); break; default: break; @@ -218,13 +235,13 @@ static inline float note_to_freq(uint8_t num) { static const float A4 = 440.0f; - return A4 * powf(2.0f, (float)(num - 57.0f) / 12.0f); + return A4 * powf(2.0f, static_cast<float>(num - 57.0f) / 12.0f); } void -NoteNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time) +NoteNode::note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time) { - assert(time >= context.start() && time <= context.end()); + assert(time >= ctx.start() && time <= ctx.end()); assert(note_num <= 127); Key* key = &_keys[note_num]; @@ -285,13 +302,13 @@ NoteNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, Frame assert(_keys[voice->note].state == Key::State::ON_ASSIGNED); assert(_keys[voice->note].voice == voice_num); - _freq_port->set_voice_value(context, voice_num, time, note_to_freq(note_num)); - _num_port->set_voice_value(context, voice_num, time, (float)note_num); - _vel_port->set_voice_value(context, voice_num, time, velocity / 127.0f); - _gate_port->set_voice_value(context, voice_num, time, 1.0f); + _freq_port->set_voice_value(ctx, voice_num, time, note_to_freq(note_num)); + _num_port->set_voice_value(ctx, voice_num, time, static_cast<float>(note_num)); + _vel_port->set_voice_value(ctx, voice_num, time, velocity / 127.0f); + _gate_port->set_voice_value(ctx, voice_num, time, 1.0f); if (!double_trigger) { - _trig_port->set_voice_value(context, voice_num, time, 1.0f); - _trig_port->set_voice_value(context, voice_num, time + 1, 0.0f); + _trig_port->set_voice_value(ctx, voice_num, time, 1.0f); + _trig_port->set_voice_value(ctx, voice_num, time + 1, 0.0f); } assert(key->state == Key::State::ON_ASSIGNED); @@ -301,9 +318,9 @@ NoteNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, Frame } void -NoteNode::note_off(RunContext& context, uint8_t note_num, FrameTime time) +NoteNode::note_off(RunContext& ctx, uint8_t note_num, FrameTime time) { - assert(time >= context.start() && time <= context.end()); + assert(time >= ctx.start() && time <= ctx.end()); Key* key = &_keys[note_num]; @@ -312,7 +329,7 @@ NoteNode::note_off(RunContext& context, uint8_t note_num, FrameTime time) if ((*_voices)[key->voice].state == Voice::State::ACTIVE) { assert((*_voices)[key->voice].note == note_num); if ( ! _sustain) { - free_voice(context, key->voice, time); + free_voice(ctx, key->voice, time); } else { (*_voices)[key->voice].state = Voice::State::HOLDING; } @@ -323,9 +340,9 @@ NoteNode::note_off(RunContext& context, uint8_t note_num, FrameTime time) } void -NoteNode::free_voice(RunContext& context, uint32_t voice, FrameTime time) +NoteNode::free_voice(RunContext& ctx, uint32_t voice, FrameTime time) { - assert(time >= context.start() && time <= context.end()); + assert(time >= ctx.start() && time <= ctx.end()); // Find a key to reassign to the freed voice (the newest, if there is one) Key* replace_key = nullptr; @@ -340,13 +357,13 @@ NoteNode::free_voice(RunContext& context, 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); // Change the freq but leave the gate high and don't retrigger - _freq_port->set_voice_value(context, voice, time, note_to_freq(replace_key_num)); - _num_port->set_voice_value(context, voice, time, replace_key_num); + _freq_port->set_voice_value(ctx, voice, time, note_to_freq(replace_key_num)); + _num_port->set_voice_value(ctx, voice, time, replace_key_num); replace_key->state = Key::State::ON_ASSIGNED; replace_key->voice = voice; @@ -355,67 +372,66 @@ NoteNode::free_voice(RunContext& context, uint32_t voice, FrameTime time) (*_voices)[voice].state = Voice::State::ACTIVE; } else { // No new note for voice, deactivate (set gate low) - _gate_port->set_voice_value(context, voice, time, 0.0f); + _gate_port->set_voice_value(ctx, voice, time, 0.0f); (*_voices)[voice].state = Voice::State::FREE; } } void -NoteNode::all_notes_off(RunContext& context, FrameTime time) +NoteNode::all_notes_off(RunContext& ctx, FrameTime time) { - assert(time >= context.start() && time <= context.end()); + assert(time >= ctx.start() && time <= ctx.end()); // FIXME: set all keys to Key::OFF? for (uint32_t i = 0; i < _polyphony; ++i) { - _gate_port->set_voice_value(context, i, time, 0.0f); + _gate_port->set_voice_value(ctx, i, time, 0.0f); (*_voices)[i].state = Voice::State::FREE; } } void -NoteNode::sustain_on(RunContext& context, FrameTime time) +NoteNode::sustain_on(RunContext&, FrameTime) { _sustain = true; } void -NoteNode::sustain_off(RunContext& context, FrameTime time) +NoteNode::sustain_off(RunContext& ctx, FrameTime time) { - assert(time >= context.start() && time <= context.end()); + assert(time >= ctx.start() && time <= ctx.end()); _sustain = false; for (uint32_t i=0; i < _polyphony; ++i) { if ((*_voices)[i].state == Voice::State::HOLDING) { - free_voice(context, i, time); + free_voice(ctx, i, time); } } } void -NoteNode::bend(RunContext& context, FrameTime time, float amount) +NoteNode::bend(RunContext& ctx, FrameTime time, float amount) { - _bend_port->set_control_value(context, time, amount); + _bend_port->set_control_value(ctx, time, amount); } void -NoteNode::note_pressure(RunContext& context, FrameTime time, uint8_t note_num, float amount) +NoteNode::note_pressure(RunContext& ctx, FrameTime time, uint8_t note_num, float amount) { for (uint32_t i=0; i < _polyphony; ++i) { if ((*_voices)[i].state != Voice::State::FREE && (*_voices)[i].note == note_num) { - _pressure_port->set_voice_value(context, i, time, amount); + _pressure_port->set_voice_value(ctx, i, time, amount); return; } } } void -NoteNode::channel_pressure(RunContext& context, FrameTime time, float amount) +NoteNode::channel_pressure(RunContext& ctx, FrameTime time, float amount) { - _pressure_port->set_control_value(context, time, amount); + _pressure_port->set_control_value(ctx, time, 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 eed5dda7..3aa3217e 100644 --- a/src/server/internals/Note.hpp +++ b/src/server/internals/Note.hpp @@ -20,14 +20,27 @@ #include "InternalBlock.hpp" #include "types.hpp" +#include "raul/Array.hpp" +#include "raul/Maid.hpp" + #include <cstdint> +namespace raul { +class Symbol; +} // namespace raul + namespace ingen { + +class URIs; + namespace server { +class BufferFactory; +class GraphImpl; class InputPort; -class OutputPort; class InternalPlugin; +class OutputPort; +class RunContext; namespace internals { @@ -42,26 +55,26 @@ class NoteNode : public InternalBlock public: NoteNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate); bool prepare_poly(BufferFactory& bufs, uint32_t poly) override; - bool apply_poly(RunContext& context, uint32_t poly) override; + bool apply_poly(RunContext& ctx, uint32_t poly) override; - void run(RunContext& context) override; + void run(RunContext& ctx) override; - void note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time); - void note_off(RunContext& context, uint8_t note_num, FrameTime time); - void all_notes_off(RunContext& context, FrameTime time); + void note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time); + void note_off(RunContext& ctx, uint8_t note_num, FrameTime time); + void all_notes_off(RunContext& ctx, FrameTime time); - void sustain_on(RunContext& context, FrameTime time); - void sustain_off(RunContext& context, FrameTime time); + void sustain_on(RunContext& ctx, FrameTime time); + void sustain_off(RunContext& ctx, FrameTime time); - void bend(RunContext& context, FrameTime time, float amount); - void note_pressure(RunContext& context, FrameTime time, uint8_t note_num, float amount); - void channel_pressure(RunContext& context, FrameTime time, float amount); + void bend(RunContext& ctx, FrameTime time, float amount); + void note_pressure(RunContext& ctx, FrameTime time, uint8_t note_num, float amount); + void channel_pressure(RunContext& ctx, FrameTime time, float amount); static InternalPlugin* internal_plugin(URIs& uris); @@ -69,30 +82,30 @@ private: /** Key, one for each key on the keyboard */ struct Key { enum class State { OFF, ON_ASSIGNED, ON_UNASSIGNED }; - Key() : state(State::OFF), voice(0), time(0) {} - State state; - uint32_t voice; - SampleCount time; + + State state = State::OFF; + uint32_t voice = 0; + SampleCount time = 0; }; /** Voice, one of these always exists for each voice */ struct Voice { enum class State { FREE, ACTIVE, HOLDING }; - Voice() : state(State::FREE), note(0), time(0) {} - State state; - uint8_t note; - SampleCount time; + + State state = State::FREE; + uint8_t note = 0; + SampleCount time = 0; }; - using Voices = Raul::Array<Voice>; + using Voices = raul::Array<Voice>; - void free_voice(RunContext& context, uint32_t voice, FrameTime time); + void free_voice(RunContext& ctx, uint32_t voice, FrameTime time); - MPtr<Voices> _voices; - MPtr<Voices> _prepared_voices; + raul::managed_ptr<Voices> _voices; + 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; @@ -104,8 +117,8 @@ private: OutputPort* _pressure_port; }; +} // namespace internals } // namespace server } // namespace ingen -} // namespace internals #endif // INGEN_INTERNALS_NOTE_HPP diff --git a/src/server/internals/Time.cpp b/src/server/internals/Time.cpp index 3b6f12ba..d8f1ddef 100644 --- a/src/server/internals/Time.cpp +++ b/src/server/internals/Time.cpp @@ -17,30 +17,40 @@ #include "internals/Time.hpp" #include "Buffer.hpp" +#include "BufferFactory.hpp" +#include "BufferRef.hpp" #include "Driver.hpp" #include "Engine.hpp" #include "InternalPlugin.hpp" #include "OutputPort.hpp" +#include "PortType.hpp" #include "RunContext.hpp" -#include "util.hpp" +#include "ingen/Atom.hpp" #include "ingen/Forge.hpp" +#include "ingen/URI.hpp" #include "ingen/URIs.hpp" -#include "lv2/atom/util.h" -#include "lv2/midi/midi.h" +#include "lv2/atom/atom.h" +#include "raul/Array.hpp" +#include "raul/Maid.hpp" +#include "raul/Symbol.hpp" + +#include <memory> + +namespace ingen::server { + +class GraphImpl; -namespace ingen { -namespace server { namespace internals { InternalPlugin* TimeNode::internal_plugin(URIs& uris) { return new InternalPlugin( - uris, URI(NS_INTERNALS "Time"), Raul::Symbol("time")); + uris, URI(NS_INTERNALS "Time"), raul::Symbol("time")); } TimeNode::TimeNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate) @@ -50,7 +60,7 @@ TimeNode::TimeNode(InternalPlugin* plugin, _ports = bufs.maid().make_managed<Ports>(1); _notify_port = new OutputPort( - bufs, this, Raul::Symbol("notify"), 0, 1, + bufs, this, raul::Symbol("notify"), 0, 1, PortType::ATOM, uris.atom_Sequence, Atom(), 1024); _notify_port->set_property(uris.lv2_name, bufs.forge().alloc("Notify")); _notify_port->set_property(uris.atom_supports, @@ -59,10 +69,10 @@ TimeNode::TimeNode(InternalPlugin* plugin, } void -TimeNode::run(RunContext& context) +TimeNode::run(RunContext& ctx) { - BufferRef buf = _notify_port->buffer(0); - LV2_Atom_Sequence* 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; @@ -71,10 +81,8 @@ TimeNode::run(RunContext& context) seq->body.pad = 0; // Ask the driver to append any time events for this cycle - context.engine().driver()->append_time_events( - context, *_notify_port->buffer(0)); + ctx.engine().driver()->append_time_events(ctx, *_notify_port->buffer(0)); } } // namespace internals -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/internals/Time.hpp b/src/server/internals/Time.hpp index 958cd239..fa3e90e5 100644 --- a/src/server/internals/Time.hpp +++ b/src/server/internals/Time.hpp @@ -18,13 +18,23 @@ #define INGEN_INTERNALS_TIME_HPP #include "InternalBlock.hpp" +#include "types.hpp" + +namespace raul { +class Symbol; +} // namespace raul namespace ingen { + +class URIs; + namespace server { -class InputPort; -class OutputPort; +class BufferFactory; +class GraphImpl; class InternalPlugin; +class OutputPort; +class RunContext; namespace internals { @@ -39,12 +49,12 @@ class TimeNode : public InternalBlock public: TimeNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate); - void run(RunContext& context) override; + void run(RunContext& ctx) override; static InternalPlugin* internal_plugin(URIs& uris); @@ -52,8 +62,8 @@ private: OutputPort* _notify_port; }; +} // namespace internals } // namespace server } // namespace ingen -} // namespace internals #endif // INGEN_INTERNALS_TIME_HPP diff --git a/src/server/internals/Trigger.cpp b/src/server/internals/Trigger.cpp index 4ceae3c8..9b3b8f98 100644 --- a/src/server/internals/Trigger.cpp +++ b/src/server/internals/Trigger.cpp @@ -17,60 +17,68 @@ #include "internals/Trigger.hpp" #include "Buffer.hpp" -#include "Engine.hpp" +#include "BufferFactory.hpp" +#include "BufferRef.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" #include "OutputPort.hpp" +#include "PortType.hpp" #include "RunContext.hpp" -#include "ingen_config.h" -#include "util.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::server { + +class GraphImpl; -namespace ingen { -namespace server { namespace internals { InternalPlugin* TriggerNode::internal_plugin(URIs& uris) { return new InternalPlugin( - uris, URI(NS_INTERNALS "Trigger"), Raul::Symbol("trigger")); + uris, URI(NS_INTERNALS "Trigger"), raul::Symbol("trigger")); } TriggerNode::TriggerNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, 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); const Atom zero = bufs.forge().make(0.0f); - _midi_in_port = new InputPort(bufs, this, Raul::Symbol("input"), 0, 1, + _midi_in_port = new InputPort(bufs, this, raul::Symbol("input"), 0, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_in_port->set_property(uris.lv2_name, bufs.forge().alloc("Input")); _midi_in_port->set_property(uris.atom_supports, bufs.forge().make_urid(uris.midi_MidiEvent)); _ports->at(0) = _midi_in_port; - _midi_out_port = new OutputPort(bufs, this, Raul::Symbol("event"), 1, 1, + _midi_out_port = new OutputPort(bufs, this, raul::Symbol("event"), 1, 1, PortType::ATOM, uris.atom_Sequence, Atom()); _midi_out_port->set_property(uris.lv2_name, bufs.forge().alloc("Event")); _midi_out_port->set_property(uris.atom_supports, bufs.forge().make_urid(uris.midi_MidiEvent)); _ports->at(1) = _midi_out_port; - _note_port = new InputPort(bufs, this, Raul::Symbol("note"), 2, 1, + _note_port = new InputPort(bufs, this, raul::Symbol("note"), 2, 1, PortType::ATOM, uris.atom_Sequence, bufs.forge().make(60.0f)); _note_port->set_property(uris.atom_supports, bufs.uris().atom_Float); @@ -80,21 +88,21 @@ TriggerNode::TriggerNode(InternalPlugin* plugin, _note_port->set_property(uris.lv2_name, bufs.forge().alloc("Note")); _ports->at(2) = _note_port; - _gate_port = new OutputPort(bufs, this, Raul::Symbol("gate"), 3, 1, + _gate_port = new OutputPort(bufs, this, raul::Symbol("gate"), 3, 1, PortType::ATOM, uris.atom_Sequence, zero); _gate_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _gate_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _gate_port->set_property(uris.lv2_name, bufs.forge().alloc("Gate")); _ports->at(3) = _gate_port; - _trig_port = new OutputPort(bufs, this, Raul::Symbol("trigger"), 4, 1, + _trig_port = new OutputPort(bufs, this, raul::Symbol("trigger"), 4, 1, PortType::ATOM, uris.atom_Sequence, zero); _trig_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _trig_port->set_property(uris.lv2_portProperty, uris.lv2_toggled); _trig_port->set_property(uris.lv2_name, bufs.forge().alloc("Trigger")); _ports->at(4) = _trig_port; - _vel_port = new OutputPort(bufs, this, Raul::Symbol("velocity"), 5, 1, + _vel_port = new OutputPort(bufs, this, raul::Symbol("velocity"), 5, 1, PortType::ATOM, uris.atom_Sequence, zero); _vel_port->set_property(uris.atom_supports, bufs.uris().atom_Float); _vel_port->set_property(uris.lv2_minimum, zero); @@ -104,40 +112,42 @@ TriggerNode::TriggerNode(InternalPlugin* plugin, } void -TriggerNode::run(RunContext& context) +TriggerNode::run(RunContext& ctx) { - const BufferRef midi_in = _midi_in_port->buffer(0); - LV2_Atom_Sequence* const seq = midi_in->get<LV2_Atom_Sequence>(); - const BufferRef midi_out = _midi_out_port->buffer(0); + const BufferRef midi_in = _midi_in_port->buffer(0); + auto* const seq = midi_in->get<LV2_Atom_Sequence>(); + const BufferRef midi_out = _midi_out_port->buffer(0); // Initialise output to the empty sequence - midi_out->prepare_write(context); + midi_out->prepare_write(ctx); - LV2_ATOM_SEQUENCE_FOREACH(seq, ev) { - const int64_t t = ev->time.frames; - const uint8_t* buf = (const uint8_t*)LV2_ATOM_BODY(&ev->body); - bool emit = false; + 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)); + bool emit = false; if (ev->body.type == _midi_in_port->bufs().uris().midi_MidiEvent && ev->body.size >= 3) { - const FrameTime time = context.start() + t; + const FrameTime time = ctx.start() + t; switch (lv2_midi_message_type(buf)) { case LV2_MIDI_MSG_NOTE_ON: if (buf[2] == 0) { - emit = note_off(context, buf[1], time); + emit = note_off(ctx, buf[1], time); } else { - emit = note_on(context, buf[1], buf[2], time); + emit = note_on(ctx, buf[1], buf[2], time); } break; case LV2_MIDI_MSG_NOTE_OFF: - emit = note_off(context, buf[1], time); + emit = note_off(ctx, buf[1], time); break; case LV2_MIDI_MSG_CONTROLLER: switch (buf[1]) { case LV2_MIDI_CTL_ALL_NOTES_OFF: case LV2_MIDI_CTL_ALL_SOUNDS_OFF: - _gate_port->set_control_value(context, time, 0.0f); + _gate_port->set_control_value(ctx, time, 0.0f); emit = true; } + break; default: break; } @@ -150,35 +160,35 @@ TriggerNode::run(RunContext& context) } bool -TriggerNode::note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time) +TriggerNode::note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time) { - assert(time >= context.start() && time <= context.end()); - const uint32_t offset = time - context.start(); + assert(time >= ctx.start() && time <= ctx.end()); + const uint32_t offset = time - ctx.start(); if (_learning) { - _note_port->set_control_value(context, time, (float)note_num); + _note_port->set_control_value(ctx, time, static_cast<float>(note_num)); _note_port->force_monitor_update(); _learning = false; } if (note_num == lrintf(_note_port->buffer(0)->value_at(offset))) { - _gate_port->set_control_value(context, time, 1.0f); - _trig_port->set_control_value(context, time, 1.0f); - _trig_port->set_control_value(context, time + 1, 0.0f); - _vel_port->set_control_value(context, time, velocity / 127.0f); + _gate_port->set_control_value(ctx, time, 1.0f); + _trig_port->set_control_value(ctx, time, 1.0f); + _trig_port->set_control_value(ctx, time + 1, 0.0f); + _vel_port->set_control_value(ctx, time, velocity / 127.0f); return true; } return false; } bool -TriggerNode::note_off(RunContext& context, uint8_t note_num, FrameTime time) +TriggerNode::note_off(RunContext& ctx, uint8_t note_num, FrameTime time) { - assert(time >= context.start() && time <= context.end()); - const uint32_t offset = time - context.start(); + assert(time >= ctx.start() && time <= ctx.end()); + const uint32_t offset = time - ctx.start(); if (note_num == lrintf(_note_port->buffer(0)->value_at(offset))) { - _gate_port->set_control_value(context, time, 0.0f); + _gate_port->set_control_value(ctx, time, 0.0f); return true; } @@ -186,5 +196,4 @@ TriggerNode::note_off(RunContext& context, 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 0508b615..74634202 100644 --- a/src/server/internals/Trigger.hpp +++ b/src/server/internals/Trigger.hpp @@ -18,15 +18,26 @@ #define INGEN_INTERNALS_TRIGGER_HPP #include "InternalBlock.hpp" +#include "types.hpp" #include <cstdint> +namespace raul { +class Symbol; +} // namespace raul + namespace ingen { + +class URIs; + namespace server { +class BufferFactory; +class GraphImpl; class InputPort; -class OutputPort; class InternalPlugin; +class OutputPort; +class RunContext; namespace internals { @@ -45,22 +56,22 @@ class TriggerNode : public InternalBlock public: TriggerNode(InternalPlugin* plugin, BufferFactory& bufs, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate srate); - void run(RunContext& context) override; + void run(RunContext& ctx) override; - bool note_on(RunContext& context, uint8_t note_num, uint8_t velocity, FrameTime time); - bool note_off(RunContext& context, uint8_t note_num, FrameTime time); + bool note_on(RunContext& ctx, uint8_t note_num, uint8_t velocity, FrameTime time); + bool note_off(RunContext& ctx, uint8_t note_num, FrameTime time); void learn() override { _learning = true; } static InternalPlugin* internal_plugin(URIs& uris); private: - bool _learning; + bool _learning{false}; InputPort* _midi_in_port; OutputPort* _midi_out_port; @@ -70,8 +81,8 @@ private: OutputPort* _vel_port; }; +} // namespace internals } // namespace server } // namespace ingen -} // namespace internals #endif // INGEN_INTERNALS_TRIGGER_HPP 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 5f77eda2..db491e28 100644 --- a/src/server/mix.cpp +++ b/src/server/mix.cpp @@ -18,30 +18,31 @@ #include "Buffer.hpp" #include "RunContext.hpp" +#include "types.hpp" +#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) { - const LV2_Atom* atom = buf->get<const LV2_Atom>(); + const auto* atom = buf->get<const LV2_Atom>(); return lv2_atom_sequence_is_end( - (const LV2_Atom_Sequence_Body*)LV2_ATOM_BODY_CONST(atom), + static_cast<const LV2_Atom_Sequence_Body*>(LV2_ATOM_BODY_CONST(atom)), atom->size, ev); } void -mix(const RunContext& context, +mix(const RunContext& ctx, Buffer* dst, const Buffer*const* srcs, uint32_t num_srcs) { if (num_srcs == 1) { - dst->copy(context, srcs[0]); + dst->copy(ctx, srcs[0]); } else if (dst->is_control()) { Sample* const out = dst->samples(); out[0] = srcs[0]->value_at(0); @@ -50,23 +51,23 @@ mix(const RunContext& context, } } else if (dst->is_audio()) { // Copy the first source - dst->copy(context, srcs[0]); + dst->copy(ctx, srcs[0]); // Mix in the rest Sample* __restrict const out = dst->samples(); - const SampleCount end = context.nframes(); + 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 - for (SampleCount i = 0; i < end; ++i) { - out[i] += in[0]; + 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 - for (SampleCount i = 0; i < end; ++i) { - out[i] += in[i]; + } 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 - dst->render_sequence(context, srcs[i], true); + } else if (srcs[i]->is_sequence()) { // sequence => audio + dst->render_sequence(ctx, srcs[i], true); } } } else if (dst->is_sequence()) { @@ -74,7 +75,7 @@ mix(const RunContext& context, for (uint32_t i = 0; i < num_srcs; ++i) { iters[i] = nullptr; if (srcs[i]->is_sequence()) { - const LV2_Atom_Sequence* seq = srcs[i]->get<const LV2_Atom_Sequence>(); + const auto* seq = srcs[i]->get<const LV2_Atom_Sequence>(); iters[i] = lv2_atom_sequence_begin(&seq->body); if (is_end(srcs[i], iters[i])) { iters[i] = nullptr; @@ -96,7 +97,7 @@ mix(const RunContext& context, if (first) { dst->append_event( first->time.frames, first->body.size, first->body.type, - (const uint8_t*)LV2_ATOM_BODY_CONST(&first->body)); + static_cast<const uint8_t*>(LV2_ATOM_BODY_CONST(&first->body))); iters[first_i] = lv2_atom_sequence_next(first); if (is_end(srcs[first_i], iters[first_i])) { @@ -109,5 +110,4 @@ mix(const RunContext& context, } } -} // namespace server -} // namespace ingen +} // namespace ingen::server diff --git a/src/server/mix.hpp b/src/server/mix.hpp index 1878200c..11a9a1d2 100644 --- a/src/server/mix.hpp +++ b/src/server/mix.hpp @@ -19,19 +19,17 @@ #include <cstdint> -namespace ingen { -namespace server { +namespace ingen::server { class Buffer; class RunContext; void -mix(const RunContext& context, +mix(const RunContext& ctx, Buffer* dst, 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 34e2ee79..2076aa62 100644 --- a/src/server/util.hpp +++ b/src/server/util.hpp @@ -17,34 +17,19 @@ #ifndef INGEN_ENGINE_UTIL_HPP #define INGEN_ENGINE_UTIL_HPP -#include "ingen_config.h" - #include "ingen/Log.hpp" -#include "raul/Path.hpp" #ifdef __SSE__ -#include <xmmintrin.h> +#include <xmmintrin.h> // IWYU pragma: keep #endif -#include <fenv.h> -#include <cstdlib> - #ifdef __clang__ # define REALTIME __attribute__((annotate("realtime"))) #else # define REALTIME #endif -#if defined(INGEN_HAVE_THREAD_LOCAL) -# define INGEN_THREAD_LOCAL thread_local -#elif defined(INGEN_HAVE_THREAD_BUILTIN) -# define INGEN_THREAD_LOCAL __thread -#else -# define INGEN_THREAD_LOCAL -#endif - -namespace ingen { -namespace server { +namespace ingen::server { /** Set flags to disable denormal processing. */ @@ -57,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 00588915..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 = ['../..'], - includes = ['.', '../..'], - 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 = ['.', '../..'], - 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 = ['.', '../..'], - 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 = ['.', '../..'], - 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) |