From d5eb49e1e468377fea4c5f13840d0435714d34c4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 26 Mar 2017 18:15:16 +0200 Subject: Remove Node port accessors --- ingen/Node.hpp | 4 +-- src/Serialiser.cpp | 64 ++++++++++++++++++++++----------------- src/Store.cpp | 4 --- src/server/Engine.cpp | 18 +++++++++++ src/server/Engine.hpp | 3 ++ src/server/events/Copy.cpp | 2 +- src/server/events/CreateBlock.cpp | 2 +- src/server/events/CreateGraph.cpp | 5 +-- src/server/events/CreatePort.cpp | 2 +- 9 files changed, 63 insertions(+), 41 deletions(-) diff --git a/ingen/Node.hpp b/ingen/Node.hpp index cde50f63..5f8e0bc6 100644 --- a/ingen/Node.hpp +++ b/ingen/Node.hpp @@ -57,9 +57,7 @@ public: const Arcs& arcs() const { return _arcs; } // Blocks and graphs only - virtual uint32_t num_ports() const { return 0; } - virtual Node* port(uint32_t index) const { return NULL; } - virtual const Resource* plugin() const { return NULL; } + virtual const Resource* plugin() const { return NULL; } // Plugin blocks only virtual bool save_state(const std::string& dir) const { return false; } diff --git a/src/Serialiser.cpp b/src/Serialiser.cpp index 518f0bea..70a1d286 100644 --- a/src/Serialiser.cpp +++ b/src/Serialiser.cpp @@ -75,7 +75,7 @@ struct Serialiser::Impl { const Sord::Node& class_id, const Sord::Node& id); - void serialise_port(const Node* p, + void serialise_port(SPtr p, Resource::Graph context, const Sord::Node& id); @@ -311,7 +311,7 @@ Serialiser::serialise(SPtr object) throw (std::logic_error) me->serialise_block(object, plugin_id, me->path_rdf_node(object->path())); } else if (object->has_property(uris.rdf_type, uris.lv2_InputPort) || object->has_property(uris.rdf_type, uris.lv2_OutputPort)) { - me->serialise_port(object.get(), + me->serialise_port(object, Resource::Graph::DEFAULT, me->path_rdf_node(object->path())); } else { @@ -362,7 +362,7 @@ Serialiser::Impl::serialise_graph(SPtr graph, continue; if (n->second->has_property(uris.rdf_type, uris.ingen_Graph)) { - SPtr subgraph = n->second; + const SPtr subgraph = n->second; SerdURI base_uri; serd_uri_parse((const uint8_t*)_base_uri.c_str(), &base_uri); @@ -395,7 +395,7 @@ Serialiser::Impl::serialise_graph(SPtr graph, block_id); serialise_block(subgraph, subgraph_id, block_id); } else if (n->second->has_property(uris.rdf_type, uris.ingen_Block)) { - SPtr block = n->second; + const SPtr block = n->second; const Sord::URI class_id(world, block->plugin()->uri()); const Sord::Node block_id(path_rdf_node(n->second->path())); @@ -405,23 +405,26 @@ Serialiser::Impl::serialise_graph(SPtr graph, serialise_block(block, class_id, block_id); plugins.insert(block->plugin()); - } - } - - for (uint32_t i = 0; i < graph->num_ports(); ++i) { - Node* p = graph->port(i); - const Sord::Node port_id = path_rdf_node(p->path()); + } else if (n->second->has_property(uris.rdf_type, uris.lv2_InputPort) || + n->second->has_property(uris.rdf_type, uris.lv2_OutputPort)) { + const SPtr p = n->second; - // Ensure lv2:name always exists so Graph is a valid LV2 plugin - if (p->properties().find(uris.lv2_name) == p->properties().end()) - p->set_property(uris.lv2_name, - _world.forge().alloc(p->symbol().c_str())); + // Ensure lv2:name always exists so Graph is a valid LV2 plugin + const Sord::Node port_id(path_rdf_node(p->path())); + if (p->properties().find(uris.lv2_name) == p->properties().end()) + _model->add_statement(port_id, + Sord::URI(world, uris.lv2_name), + Sord::Literal(world, p->symbol())); - _model->add_statement(graph_id, - Sord::URI(world, LV2_CORE__port), - port_id); - serialise_port(p, Resource::Graph::DEFAULT, port_id); - serialise_port(p, Resource::Graph::INTERNAL, port_id); + _model->add_statement(graph_id, + Sord::URI(world, LV2_CORE__port), + port_id); + serialise_port(p, Resource::Graph::DEFAULT, port_id); + serialise_port(p, Resource::Graph::INTERNAL, port_id); + } else { + _world.log().warn(fmt("<%1%> has no known type\n") + % n->second->uri()); + } } for (const auto& a : graph->arcs()) { @@ -462,18 +465,25 @@ Serialiser::Impl::serialise_block(SPtr block, } } - for (uint32_t i = 0; i < block->num_ports(); ++i) { - Node* const p = block->port(i); - const Sord::Node port_id = path_rdf_node(p->path()); - serialise_port(p, Resource::Graph::DEFAULT, port_id); - _model->add_statement(block_id, - Sord::URI(_model->world(), uris.lv2_port), - port_id); + const Store::const_range kids = _world.store()->children_range(block); + for (Store::const_iterator n = kids.first; n != kids.second; ++n) { + if (n->first.parent() != block->path()) + continue; + + if (n->second->has_property(uris.rdf_type, uris.lv2_InputPort) || + n->second->has_property(uris.rdf_type, uris.lv2_InputPort)) { + const SPtr p = n->second; + const Sord::Node port_id = path_rdf_node(p->path()); + serialise_port(p, Resource::Graph::DEFAULT, port_id); + _model->add_statement(block_id, + Sord::URI(_model->world(), uris.lv2_port), + port_id); + } } } void -Serialiser::Impl::serialise_port(const Node* port, +Serialiser::Impl::serialise_port(SPtr port, Resource::Graph context, const Sord::Node& port_id) { diff --git a/src/Store.cpp b/src/Store.cpp index 2c7294a8..e2f0f368 100644 --- a/src/Store.cpp +++ b/src/Store.cpp @@ -30,10 +30,6 @@ Store::add(Node* o) } insert(make_pair(o->path(), SPtr(o))); - - for (uint32_t i = 0; i < o->num_ports(); ++i) { - add(o->port(i)); - } } /* diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index 35b71a39..eb7c94ee 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -524,6 +524,24 @@ Engine::process_all_events() return _pre_processor->process(run_context(), *_post_processor, 0); } +void +Engine::add_to_store(Node* const node) +{ + store()->add(node); + + if (BlockImpl* const block = dynamic_cast(node)) { + for (uint32_t i = 0; i < block->num_ports(); ++i) { + store()->add(block->port(i)); + } + } + + if (GraphImpl* const graph = dynamic_cast(node)) { + for (BlockImpl& block : graph->blocks()) { + store()->add(&block); + } + } +} + void Engine::register_client(SPtr client) { diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index f735aedd..adae816b 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -124,6 +124,9 @@ public: /** Process all events (no RT limits). */ unsigned process_all_events(); + /** Add `node` and all its children to the store. */ + void add_to_store(Node* node); + Ingen::World* world() const { return _world; } Interface* interface() const { return _interface.get(); } diff --git a/src/server/events/Copy.cpp b/src/server/events/Copy.cpp index 53f62958..4a066691 100644 --- a/src/server/events/Copy.cpp +++ b/src/server/events/Copy.cpp @@ -120,7 +120,7 @@ Copy::engine_to_engine(PreProcessContext& ctx) // Add block to the store and the graph's pre-processor only block list _parent->add_block(*_block); - _engine.store()->add(_block); + _engine.add_to_store(_block); // Compile graph with new block added for insertion in audio thread _compiled_graph = ctx.maybe_compile(*_engine.maid(), *_parent); diff --git a/src/server/events/CreateBlock.cpp b/src/server/events/CreateBlock.cpp index eb696c6b..1910ef80 100644 --- a/src/server/events/CreateBlock.cpp +++ b/src/server/events/CreateBlock.cpp @@ -142,7 +142,7 @@ CreateBlock::pre_process(PreProcessContext& ctx) // Add block to the store and the graph's pre-processor only block list _graph->add_block(*_block); - store->add(_block); + _engine.add_to_store(_block); /* Compile graph with new block added for insertion in audio thread TODO: Since the block is not connected at this point, a full compilation diff --git a/src/server/events/CreateGraph.cpp b/src/server/events/CreateGraph.cpp index 99b29b66..3ac37d51 100644 --- a/src/server/events/CreateGraph.cpp +++ b/src/server/events/CreateGraph.cpp @@ -175,11 +175,8 @@ CreateGraph::pre_process(PreProcessContext& ctx) _graph->activate(*_engine.buffer_factory()); // Insert into store and build update to send to clients - _engine.store()->add(_graph); + _engine.add_to_store(_graph); _update.put_graph(_graph); - for (BlockImpl& block : _graph->blocks()) { - _engine.store()->add(&block); - } // Build and pre-process child events to create standard ports build_child_events(); diff --git a/src/server/events/CreatePort.cpp b/src/server/events/CreatePort.cpp index 3adf2f8b..0f63cc46 100644 --- a/src/server/events/CreatePort.cpp +++ b/src/server/events/CreatePort.cpp @@ -146,7 +146,7 @@ CreatePort::pre_process(PreProcessContext& ctx) (_flow == Flow::INPUT && _graph_port->is_input())); _graph_port->properties().insert(_properties.begin(), _properties.end()); - _engine.store()->add(_graph_port); + _engine.add_to_store(_graph_port); if (_flow == Flow::OUTPUT) { _graph->add_output(*_graph_port); } else { -- cgit v1.2.1