summaryrefslogtreecommitdiffstats
path: root/src/serialisation
diff options
context:
space:
mode:
Diffstat (limited to 'src/serialisation')
-rw-r--r--src/serialisation/Parser.cpp19
-rw-r--r--src/serialisation/Serialiser.cpp37
-rw-r--r--src/serialisation/Serialiser.hpp1
3 files changed, 43 insertions, 14 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp
index 3eae4814..3dda415c 100644
--- a/src/serialisation/Parser.cpp
+++ b/src/serialisation/Parser.cpp
@@ -36,7 +36,8 @@ namespace Ingen {
namespace Serialisation {
#define NS_INGEN "http://drobilla.net/ns/ingen#"
-
+#define NS_LV2 "http://lv2plug.in/ns/lv2core#"
+#define NS_LV2EV "http://lv2plug.in/ns/ext/event#"
Glib::ustring
Parser::uri_relative_to_base(Glib::ustring base, const Glib::ustring uri)
@@ -130,8 +131,8 @@ Parser::parse(
const Redland::Node patch_class(*world->rdf_world, res, NS_INGEN "Patch");
const Redland::Node node_class(*world->rdf_world, res, NS_INGEN "Node");
- const Redland::Node in_port_class(*world->rdf_world, res, NS_INGEN "InputPort");
- const Redland::Node out_port_class(*world->rdf_world, res, NS_INGEN "OutputPort");
+ const Redland::Node in_port_class(*world->rdf_world, res, NS_LV2 "InputPort");
+ const Redland::Node out_port_class(*world->rdf_world, res, NS_LV2 "OutputPort");
string subject_str = ((object_uri && object_uri.get() != "") ? object_uri.get() : base_uri);
if (subject_str[0] == '/')
@@ -333,7 +334,7 @@ Parser::parse_patch(
"SELECT DISTINCT ?nodename ?portname ?portval WHERE {\n") +
subject + " ingen:node ?node .\n"
"?node lv2:symbol ?nodename ;\n"
- " ingen:port ?port .\n"
+ " lv2:port ?port .\n"
"?port lv2:symbol ?portname ;\n"
" ingen:value ?portval .\n"
"FILTER ( datatype(?portval) = xsd:decimal )\n"
@@ -355,11 +356,11 @@ Parser::parse_patch(
/* Load this patch's ports */
query = Redland::Query(*world->rdf_world, Glib::ustring(
"SELECT DISTINCT ?port ?type ?name ?datatype ?varkey ?varval ?portval WHERE {\n") +
- subject + " ingen:port ?port .\n"
+ subject + " lv2:port ?port .\n"
"?port a ?type ;\n"
" a ?datatype ;\n"
" lv2:symbol ?name .\n"
- " FILTER (?type != ?datatype && ((?type = ingen:InputPort) || (?type = ingen:OutputPort)))\n"
+ " FILTER (?type != ?datatype && ((?type = lv2:InputPort) || (?type = lv2:OutputPort)))\n"
"OPTIONAL { ?port ingen:value ?portval . \n"
" FILTER ( datatype(?portval) = xsd:decimal ) }\n"
"OPTIONAL { ?port lv2var:variable ?variable .\n"
@@ -379,7 +380,7 @@ Parser::parse_patch(
const Path port_path = patch_path.base() + name;
if (created.find(port_path) == created.end()) {
- bool is_output = (type == "ingen:OutputPort"); // FIXME: check validity
+ bool is_output = (type == "lv2:OutputPort"); // FIXME: check validity
// FIXME: read index
target->new_port(port_path, 0, datatype, is_output);
created.insert(port_path);
@@ -468,7 +469,7 @@ Parser::parse_port(
"SELECT DISTINCT ?type ?datatype ?value WHERE {\n") +
subject + " a ?type ;\n"
" a ?datatype .\n"
- " FILTER (?type != ?datatype && ((?type = ingen:InputPort) || (?type = ingen:OutputPort)))\n"
+ " FILTER (?type != ?datatype && ((?type = lv2:InputPort) || (?type = lv2:OutputPort)))\n"
"OPTIONAL { " + subject + " ingen:value ?value . }\n"
"}");
@@ -479,7 +480,7 @@ Parser::parse_port(
const string type = world->rdf_world->qualify((*i)["type"].to_string());
const string datatype = world->rdf_world->qualify((*i)["datatype"].to_string());
- bool is_output = (type == "ingen:OutputPort");
+ bool is_output = (type == "lv2:OutputPort");
// FIXME: read index
target->new_port(path, 0, datatype, is_output);
diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp
index 2f0d9877..7dccbe2c 100644
--- a/src/serialisation/Serialiser.cpp
+++ b/src/serialisation/Serialiser.cpp
@@ -301,6 +301,11 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch)
patch_id,
"rdf:type",
Redland::Node(_model->world(), Redland::Node::RESOURCE, "http://drobilla.net/ns/ingen#Patch"));
+
+ _model->add_statement(
+ patch_id,
+ "rdf:type",
+ Redland::Node(_model->world(), Redland::Node::RESOURCE, "http://lv2plug.in/ns/lv2core#Plugin"));
GraphObject::Variables::const_iterator s = patch->variables().find("lv2:symbol");
// If symbol is stored as a variable, write that
@@ -324,6 +329,7 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch)
"ingen:enabled",
AtomRDF::atom_to_node(_model->world(), Atom((bool)patch->enabled())));
+ serialise_properties(patch_id, patch->properties());
serialise_variables(patch_id, patch->variables());
for (GraphObject::const_iterator n = _store->children_begin(patch);
@@ -347,7 +353,12 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch)
for (uint32_t i=0; i < patch->num_ports(); ++i) {
Port* p = patch->port(i);
const Redland::Node port_id = path_to_rdf_node(p->path());
- _model->add_statement(patch_id, "ingen:port", port_id);
+
+ // Ensure lv2:name always exists so Patch is a valid LV2 plugin
+ if (p->properties().find("lv2:name") == p->properties().end())
+ p->properties()["lv2:name"] = p->symbol(); // FIXME: use human name
+
+ _model->add_statement(patch_id, "lv2:port", port_id);
serialise_port(p, port_id);
}
@@ -405,9 +416,10 @@ Serialiser::serialise_node(SharedPtr<Shared::Node> node, const Redland::Node& no
assert(p);
const Redland::Node port_id = path_to_rdf_node(p->path());
serialise_port(p, port_id);
- _model->add_statement(node_id, "ingen:port", port_id);
+ _model->add_statement(node_id, "lv2:port", port_id);
}
+ serialise_properties(node_id, node->properties());
serialise_variables(node_id, node->variables());
}
@@ -421,10 +433,10 @@ Serialiser::serialise_port(const Port* port, const Redland::Node& port_id)
{
if (port->is_input())
_model->add_statement(port_id, "rdf:type",
- Redland::Node(_model->world(), Redland::Node::RESOURCE, "ingen:InputPort"));
+ Redland::Node(_model->world(), Redland::Node::RESOURCE, "lv2:InputPort"));
else
_model->add_statement(port_id, "rdf:type",
- Redland::Node(_model->world(), Redland::Node::RESOURCE, "ingen:OutputPort"));
+ Redland::Node(_model->world(), Redland::Node::RESOURCE, "lv2:OutputPort"));
_model->add_statement(port_id, "lv2:index",
AtomRDF::atom_to_node(_model->world(), Atom((int)port->index())));
@@ -439,6 +451,7 @@ Serialiser::serialise_port(const Port* port, const Redland::Node& port_id)
_model->add_statement(port_id, "ingen:value",
AtomRDF::atom_to_node(_model->world(), Atom(port->value())));
+ serialise_properties(port_id, port->properties());
serialise_variables(port_id, port->variables());
}
@@ -468,13 +481,27 @@ Serialiser::serialise_connection(SharedPtr<GraphObject> parent,
/* ... but this is cleaner */
//_model->add_statement(dst_node, "ingen:connectedTo", src_node);
}
+
+
+void
+Serialiser::serialise_properties(Redland::Node subject, const GraphObject::Variables& properties)
+{
+ for (GraphObject::Variables::const_iterator v = properties.begin(); v != properties.end(); ++v) {
+ if (v->first.find(":") && v->second.is_valid()) {
+ const Redland::Node value = AtomRDF::atom_to_node(_model->world(), v->second);
+ _model->add_statement(subject, v->first, value);
+ } else {
+ cerr << "Warning: unable to serialize property \'" << v->first << "\'" << endl;
+ }
+ }
+}
void
Serialiser::serialise_variables(Redland::Node subject, const GraphObject::Variables& variables)
{
for (GraphObject::Variables::const_iterator v = variables.begin(); v != variables.end(); ++v) {
- if (v->first.find(":") != string::npos && v->first != "ingen:document") {
+ if (v->first.find(":") && v->first != "ingen:document") {
if (v->second.is_valid()) {
const Redland::Node var_id = _world.blank_id();
const Redland::Node key(_model->world(), Redland::Node::RESOURCE, v->first);
diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp
index f27cad83..a739980c 100644
--- a/src/serialisation/Serialiser.hpp
+++ b/src/serialisation/Serialiser.hpp
@@ -84,6 +84,7 @@ private:
void serialise_node(SharedPtr<Shared::Node> n, const Redland::Node& id);
void serialise_port(const Shared::Port* p, const Redland::Node& id);
+ void serialise_properties(Redland::Node subject, const GraphObject::Variables& properties);
void serialise_variables(Redland::Node subject, const GraphObject::Variables& variables);
Redland::Node path_to_rdf_node(const Path& path);