summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-03-26 18:15:16 +0200
committerDavid Robillard <d@drobilla.net>2017-03-26 18:15:16 +0200
commitd5eb49e1e468377fea4c5f13840d0435714d34c4 (patch)
tree5758545d6050b290c2155aebc70dc882b9527f73
parentba3e956f5be02730368b75fbec704e75b3f036da (diff)
downloadingen-d5eb49e1e468377fea4c5f13840d0435714d34c4.tar.gz
ingen-d5eb49e1e468377fea4c5f13840d0435714d34c4.tar.bz2
ingen-d5eb49e1e468377fea4c5f13840d0435714d34c4.zip
Remove Node port accessors
-rw-r--r--ingen/Node.hpp4
-rw-r--r--src/Serialiser.cpp64
-rw-r--r--src/Store.cpp4
-rw-r--r--src/server/Engine.cpp18
-rw-r--r--src/server/Engine.hpp3
-rw-r--r--src/server/events/Copy.cpp2
-rw-r--r--src/server/events/CreateBlock.cpp2
-rw-r--r--src/server/events/CreateGraph.cpp5
-rw-r--r--src/server/events/CreatePort.cpp2
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<const Node> p,
Resource::Graph context,
const Sord::Node& id);
@@ -311,7 +311,7 @@ Serialiser::serialise(SPtr<const Node> 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<const Node> graph,
continue;
if (n->second->has_property(uris.rdf_type, uris.ingen_Graph)) {
- SPtr<Node> subgraph = n->second;
+ const SPtr<const Node> 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<const Node> graph,
block_id);
serialise_block(subgraph, subgraph_id, block_id);
} else if (n->second->has_property(uris.rdf_type, uris.ingen_Block)) {
- SPtr<const Node> block = n->second;
+ const SPtr<const Node> 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<const Node> 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<const Node> 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<const Node> 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<const Node> 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<const Node> 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<Node>(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
@@ -525,6 +525,24 @@ Engine::process_all_events()
}
void
+Engine::add_to_store(Node* const node)
+{
+ store()->add(node);
+
+ if (BlockImpl* const block = dynamic_cast<BlockImpl*>(node)) {
+ for (uint32_t i = 0; i < block->num_ports(); ++i) {
+ store()->add(block->port(i));
+ }
+ }
+
+ if (GraphImpl* const graph = dynamic_cast<GraphImpl*>(node)) {
+ for (BlockImpl& block : graph->blocks()) {
+ store()->add(&block);
+ }
+ }
+}
+
+void
Engine::register_client(SPtr<Interface> client)
{
log().info(fmt("Registering client <%1%>\n") % client->uri().c_str());
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 {