summaryrefslogtreecommitdiffstats
path: root/src/serialisation
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-18 23:05:06 +0000
committerDavid Robillard <d@drobilla.net>2012-08-18 23:05:06 +0000
commit317627ef40f7654c298aa1ac707851c852259e3a (patch)
tree38f7ed57aafb7b3b8e21e6caa3429a39207e4a9a /src/serialisation
parent160b2baf7df8b960f22619c013b3197c0dc51c2b (diff)
downloadingen-317627ef40f7654c298aa1ac707851c852259e3a.tar.gz
ingen-317627ef40f7654c298aa1ac707851c852259e3a.tar.bz2
ingen-317627ef40f7654c298aa1ac707851c852259e3a.zip
Node => Block
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4720 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/serialisation')
-rw-r--r--src/serialisation/Parser.cpp71
-rw-r--r--src/serialisation/Serialiser.cpp118
2 files changed, 97 insertions, 92 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp
index bac5e06f..900aba02 100644
--- a/src/serialisation/Parser.cpp
+++ b/src/serialisation/Parser.cpp
@@ -36,9 +36,6 @@
#include "sord/sordmm.hpp"
#include "sratom/sratom.h"
-#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-#define NS_RDFS "http://www.w3.org/2000/01/rdf-schema#"
-
using namespace std;
typedef set<Sord::Node> RDFNodes;
@@ -192,7 +189,7 @@ parse_patch(
boost::optional<Resource::Properties> data = boost::optional<Resource::Properties>());
static boost::optional<Raul::Path>
-parse_node(
+parse_block(
World* world,
Interface* target,
Sord::Model& model,
@@ -218,21 +215,21 @@ parse_edges(
const Raul::Path& patch);
static boost::optional<Raul::Path>
-parse_node(Ingen::World* world,
- Ingen::Interface* target,
- Sord::Model& model,
- const Sord::Node& subject,
- const Raul::Path& path,
- boost::optional<GraphObject::Properties> data)
+parse_block(Ingen::World* world,
+ Ingen::Interface* target,
+ Sord::Model& model,
+ const Sord::Node& subject,
+ const Raul::Path& path,
+ boost::optional<GraphObject::Properties> data)
{
const URIs& uris = world->uris();
- const Sord::URI ingen_prototype(*world->rdf_world(), NS_INGEN "prototype");
+ const Sord::URI ingen_prototype(*world->rdf_world(), uris.ingen_prototype);
const Sord::Node nil;
Sord::Iter i = model.find(subject, ingen_prototype, nil);
if (i.end() || i.get_object().type() != Sord::Node::URI) {
- world->log().error("Node missing mandatory ingen:prototype\n");
+ world->log().error("BLock missing mandatory ingen:prototype\n");
return boost::optional<Raul::Path>();
}
@@ -274,7 +271,7 @@ parse_node(Ingen::World* world,
} else {
Resource::Properties props = get_properties(world, model, subject);
props.insert(make_pair(uris.rdf_type,
- uris.forge.alloc_uri(uris.ingen_Node)));
+ uris.forge.alloc_uri(uris.ingen_Block)));
target->put(GraphObject::path_to_uri(path), props);
}
return path;
@@ -289,8 +286,10 @@ parse_patch(Ingen::World* world,
boost::optional<Raul::Symbol> a_symbol,
boost::optional<GraphObject::Properties> data)
{
- const Sord::URI ingen_node(*world->rdf_world(), NS_INGEN "node");
- const Sord::URI ingen_polyphony(*world->rdf_world(), NS_INGEN "polyphony");
+ URIs& uris = world->uris();
+
+ const Sord::URI ingen_block(*world->rdf_world(), uris.ingen_block);
+ const Sord::URI ingen_polyphony(*world->rdf_world(), uris.ingen_polyphony);
const Sord::URI lv2_port(*world->rdf_world(), LV2_CORE__port);
const Sord::Node& patch = subject_node;
@@ -320,24 +319,24 @@ parse_patch(Ingen::World* world,
Resource::Properties props = get_properties(world, model, subject_node);
target->put(GraphObject::path_to_uri(patch_path), props);
- // For each node in this patch
- for (Sord::Iter n = model.find(subject_node, ingen_node, nil); !n.end(); ++n) {
- Sord::Node node = n.get_object();
- const Raul::Path node_path = patch_path.child(
+ // For each block in this patch
+ for (Sord::Iter n = model.find(subject_node, ingen_block, nil); !n.end(); ++n) {
+ Sord::Node node = n.get_object();
+ const Raul::Path block_path = patch_path.child(
Raul::Symbol(get_basename(node.to_string())));
- // Parse and create node
- parse_node(world, target, model, node, node_path,
- boost::optional<GraphObject::Properties>());
+ // Parse and create block
+ parse_block(world, target, model, node, block_path,
+ boost::optional<GraphObject::Properties>());
- // For each port on this node
+ // For each port on this block
for (Sord::Iter p = model.find(node, lv2_port, nil); !p.end(); ++p) {
Sord::Node port = p.get_object();
// Get all properties
uint32_t index = 0;
boost::optional<PortRecord> port_record = get_port(
- world, model, port, node_path, index);
+ world, model, port, block_path, index);
if (!port_record) {
world->log().error(Raul::fmt("Invalid port %1%\n") % port);
return boost::optional<Raul::Path>();
@@ -386,8 +385,10 @@ parse_edge(Ingen::World* world,
const Sord::Node& subject,
const Raul::Path& parent)
{
- const Sord::URI ingen_tail(*world->rdf_world(), NS_INGEN "tail");
- const Sord::URI ingen_head(*world->rdf_world(), NS_INGEN "head");
+ URIs& uris = world->uris();
+
+ const Sord::URI ingen_tail(*world->rdf_world(), uris.ingen_tail);
+ const Sord::URI ingen_head(*world->rdf_world(), uris.ingen_head);
const Sord::Node nil;
Sord::Iter t = model.find(subject, ingen_tail, nil);
@@ -437,7 +438,7 @@ parse_edges(Ingen::World* world,
const Sord::Node& subject,
const Raul::Path& parent)
{
- const Sord::URI ingen_edge(*world->rdf_world(), NS_INGEN "edge");
+ const Sord::URI ingen_edge(*world->rdf_world(), world->uris().ingen_edge);
const Sord::Node nil;
for (Sord::Iter i = model.find(subject, ingen_edge, nil); !i.end(); ++i) {
@@ -476,14 +477,16 @@ parse(Ingen::World* world,
boost::optional<Raul::Symbol> symbol,
boost::optional<GraphObject::Properties> data)
{
- const Sord::URI patch_class (*world->rdf_world(), NS_INGEN "Patch");
- const Sord::URI node_class (*world->rdf_world(), NS_INGEN "Node");
- const Sord::URI edge_class (*world->rdf_world(), NS_INGEN "Edge");
- const Sord::URI internal_class(*world->rdf_world(), NS_INGEN "Internal");
+ URIs& uris = world->uris();
+
+ const Sord::URI patch_class (*world->rdf_world(), uris.ingen_Patch);
+ const Sord::URI block_class (*world->rdf_world(), uris.ingen_Block);
+ const Sord::URI edge_class (*world->rdf_world(), uris.ingen_Edge);
+ const Sord::URI internal_class(*world->rdf_world(), uris.ingen_Internal);
const Sord::URI in_port_class (*world->rdf_world(), LV2_CORE__InputPort);
const Sord::URI out_port_class(*world->rdf_world(), LV2_CORE__OutputPort);
const Sord::URI lv2_class (*world->rdf_world(), LV2_CORE__Plugin);
- const Sord::URI rdf_type (*world->rdf_world(), NS_RDF "type");
+ const Sord::URI rdf_type (*world->rdf_world(), uris.rdf_type);
const Sord::Node nil;
// Parse explicit subject patch
@@ -518,8 +521,8 @@ parse(Ingen::World* world,
relative_uri( model.base_uri().to_string(), s.to_string(), true));
if (types.find(patch_class) != types.end()) {
ret = parse_patch(world, target, model, s, parent, symbol, data);
- } else if (types.find(node_class) != types.end()) {
- ret = parse_node(world, target, model, s, path, data);
+ } else if (types.find(block_class) != types.end()) {
+ ret = parse_block(world, target, model, s, path, data);
} else if (types.find(in_port_class) != types.end() ||
types.find(out_port_class) != types.end()) {
parse_properties(
diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp
index b480d531..a9d49fe3 100644
--- a/src/serialisation/Serialiser.cpp
+++ b/src/serialisation/Serialiser.cpp
@@ -69,9 +69,9 @@ struct Serialiser::Impl {
void serialise_patch(SharedPtr<const GraphObject> p,
const Sord::Node& id);
- void serialise_node(SharedPtr<const GraphObject> n,
- const Sord::Node& class_id,
- const Sord::Node& id);
+ void serialise_block(SharedPtr<const GraphObject> n,
+ const Sord::Node& class_id,
+ const Sord::Node& id);
void serialise_port(const GraphObject* p,
Resource::Graph context,
@@ -133,21 +133,22 @@ Serialiser::Impl::write_manifest(const std::string& bundle_path,
start_to_filename(manifest_path);
Sord::World& world = _model->world();
+ const URIs& uris = _world.uris();
const string filename(patch_symbol + ".ttl");
const Sord::URI subject(world, filename, _base_uri);
_model->add_statement(subject,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "ingen:Patch"));
+ Sord::URI(world, uris.rdf_type),
+ Sord::URI(world, uris.ingen_Patch));
_model->add_statement(subject,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "lv2:Plugin"));
+ Sord::URI(world, uris.rdf_type),
+ Sord::URI(world, uris.lv2_Plugin));
_model->add_statement(subject,
- Sord::Curie(world, "rdfs:seeAlso"),
+ Sord::URI(world, uris.rdfs_seeAlso),
Sord::URI(world, filename, _base_uri));
_model->add_statement(subject,
- Sord::Curie(world, "lv2:binary"),
+ Sord::URI(world, uris.lv2_binary),
Sord::URI(world, binary_path, _base_uri));
symlink(Glib::Module::build_path(INGEN_BUNDLE_DIR, "ingen_lv2").c_str(),
@@ -285,9 +286,9 @@ Serialiser::serialise(SharedPtr<const GraphObject> object) throw (std::logic_err
if (object->graph_type() == GraphObject::PATCH) {
me->serialise_patch(object, me->path_rdf_node(object->path()));
- } else if (object->graph_type() == GraphObject::NODE) {
+ } else if (object->graph_type() == GraphObject::BLOCK) {
const Sord::URI plugin_id(me->_model->world(), object->plugin()->uri());
- me->serialise_node(object, plugin_id, me->path_rdf_node(object->path()));
+ me->serialise_block(object, plugin_id, me->path_rdf_node(object->path()));
} else if (object->graph_type() == GraphObject::PORT) {
me->serialise_port(object.get(),
Resource::DEFAULT,
@@ -302,27 +303,25 @@ void
Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch,
const Sord::Node& patch_id)
{
- assert(_model);
Sord::World& world = _model->world();
+ const URIs& uris = _world.uris();
_model->add_statement(patch_id,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "ingen:Patch"));
+ Sord::URI(world, uris.rdf_type),
+ Sord::URI(world, uris.ingen_Patch));
_model->add_statement(patch_id,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "lv2:Plugin"));
+ Sord::URI(world, uris.rdf_type),
+ Sord::URI(world, uris.lv2_Plugin));
_model->add_statement(patch_id,
- Sord::Curie(world, "lv2:extensionData"),
+ Sord::URI(world, uris.lv2_extensionData),
Sord::URI(world, LV2_STATE__interface));
_model->add_statement(patch_id,
Sord::URI(world, LV2_UI__ui),
Sord::URI(world, "http://drobilla.net/ns/ingen#PatchUIGtk2"));
- const URIs& uris = _world.uris();
-
// Always write a symbol (required by Ingen)
Raul::Symbol symbol("_");
GraphObject::Properties::const_iterator s = patch->properties().find(uris.lv2_symbol);
@@ -334,7 +333,7 @@ Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch,
symbol = Raul::Symbol::symbolify(base.substr(0, base.find('.')));
_model->add_statement(
patch_id,
- Sord::Curie(world, "lv2:symbol"),
+ Sord::URI(world, uris.lv2_symbol),
Sord::Literal(world, symbol.c_str()));
} else {
symbol = Raul::Symbol::symbolify(s->second.get_string());
@@ -381,21 +380,21 @@ Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch,
_base_uri = my_base_uri;
_model = my_model;
- // Serialise reference to patch node
- const Sord::Node node_id(path_rdf_node(subpatch->path()));
+ // Serialise reference to patch block
+ const Sord::Node block_id(path_rdf_node(subpatch->path()));
_model->add_statement(patch_id,
- Sord::Curie(world, "ingen:node"),
- node_id);
- serialise_node(subpatch, subpatch_id, node_id);
- } else if (n->second->graph_type() == GraphObject::NODE) {
- SharedPtr<const GraphObject> node = n->second;
-
- const Sord::URI class_id(world, node->plugin()->uri());
- const Sord::Node node_id(path_rdf_node(n->second->path()));
+ Sord::URI(world, uris.ingen_block),
+ block_id);
+ serialise_block(subpatch, subpatch_id, block_id);
+ } else if (n->second->graph_type() == GraphObject::BLOCK) {
+ SharedPtr<const GraphObject> block = n->second;
+
+ const Sord::URI class_id(world, block->plugin()->uri());
+ const Sord::Node block_id(path_rdf_node(n->second->path()));
_model->add_statement(patch_id,
- Sord::Curie(world, "ingen:node"),
- node_id);
- serialise_node(node, class_id, node_id);
+ Sord::URI(world, uris.ingen_block),
+ block_id);
+ serialise_block(block, class_id, block_id);
}
}
@@ -421,29 +420,31 @@ Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch,
}
void
-Serialiser::Impl::serialise_node(SharedPtr<const GraphObject> node,
- const Sord::Node& class_id,
- const Sord::Node& node_id)
+Serialiser::Impl::serialise_block(SharedPtr<const GraphObject> block,
+ const Sord::Node& class_id,
+ const Sord::Node& block_id)
{
- _model->add_statement(node_id,
- Sord::Curie(_model->world(), "rdf:type"),
- Sord::Curie(_model->world(), "ingen:Node"));
- _model->add_statement(node_id,
- Sord::Curie(_model->world(), "ingen:prototype"),
+ const URIs& uris = _world.uris();
+
+ _model->add_statement(block_id,
+ Sord::URI(_model->world(), uris.rdf_type),
+ Sord::URI(_model->world(), uris.ingen_Block));
+ _model->add_statement(block_id,
+ Sord::URI(_model->world(), uris.ingen_prototype),
class_id);
- _model->add_statement(node_id,
- Sord::Curie(_model->world(), "lv2:symbol"),
- Sord::Literal(_model->world(), node->path().symbol()));
+ _model->add_statement(block_id,
+ Sord::URI(_model->world(), uris.lv2_symbol),
+ Sord::Literal(_model->world(), block->path().symbol()));
- const GraphObject::Properties props = node->properties(Resource::EXTERNAL);
- serialise_properties(node_id, props);
+ const GraphObject::Properties props = block->properties(Resource::EXTERNAL);
+ serialise_properties(block_id, props);
- for (uint32_t i = 0; i < node->num_ports(); ++i) {
- GraphObject* const p = node->port(i);
+ for (uint32_t i = 0; i < block->num_ports(); ++i) {
+ GraphObject* const p = block->port(i);
const Sord::Node port_id = path_rdf_node(p->path());
serialise_port(p, Resource::EXTERNAL, port_id);
- _model->add_statement(node_id,
- Sord::Curie(_model->world(), "lv2:port"),
+ _model->add_statement(block_id,
+ Sord::URI(_model->world(), uris.lv2_port),
port_id);
}
}
@@ -457,7 +458,7 @@ Serialiser::Impl::serialise_port(const GraphObject* port,
Sord::World& world = _model->world();
_model->add_statement(port_id,
- Sord::Curie(world, "lv2:symbol"),
+ Sord::URI(world, uris.lv2_symbol),
Sord::Literal(world, port->path().symbol()));
GraphObject::Properties props = port->properties(context);
@@ -494,25 +495,26 @@ Serialiser::Impl::serialise_edge(const Sord::Node& parent,
"serialise_edge called without serialisation in progress");
Sord::World& world = _model->world();
+ const URIs& uris = _world.uris();
- const Sord::Node src = path_rdf_node(edge->tail_path());
- const Sord::Node dst = path_rdf_node(edge->head_path());
+ const Sord::Node src = path_rdf_node(edge->tail_path());
+ const Sord::Node dst = path_rdf_node(edge->head_path());
const Sord::Node edge_id = Sord::Node::blank_id(*_world.rdf_world());
_model->add_statement(edge_id,
- Sord::Curie(world, "ingen:tail"),
+ Sord::URI(world, uris.ingen_tail),
src);
_model->add_statement(edge_id,
- Sord::Curie(world, "ingen:head"),
+ Sord::URI(world, uris.ingen_head),
dst);
if (parent.is_valid()) {
_model->add_statement(parent,
- Sord::Curie(world, "ingen:edge"),
+ Sord::URI(world, uris.ingen_edge),
edge_id);
} else {
_model->add_statement(edge_id,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "ingen:Edge"));
+ Sord::URI(world, uris.rdf_type),
+ Sord::URI(world, uris.ingen_Edge));
}
}