summaryrefslogtreecommitdiffstats
path: root/src/serialisation
diff options
context:
space:
mode:
Diffstat (limited to 'src/serialisation')
-rw-r--r--src/serialisation/Parser.cpp341
-rw-r--r--src/serialisation/Parser.hpp4
-rw-r--r--src/serialisation/Serialiser.cpp212
-rw-r--r--src/serialisation/Serialiser.hpp26
-rw-r--r--src/serialisation/serialisation.cpp2
5 files changed, 311 insertions, 274 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp
index 06922653..059a9bfd 100644
--- a/src/serialisation/Parser.cpp
+++ b/src/serialisation/Parser.cpp
@@ -86,17 +86,37 @@ relative_uri(Glib::ustring base, const Glib::ustring uri, bool leading_slash)
return ret;
}
+static std::string
+get_basename(const std::string& uri)
+{
+ std::string ret = Glib::path_get_basename(uri);
+ ret = ret.substr(0, ret.find_last_of('.'));
+ return ret;
+}
+
+static bool
+skip_property(const Sord::Node& predicate)
+{
+ return (predicate.to_string() == "http://drobilla.net/ns/ingen#node"
+ || predicate.to_string() == "http://drobilla.net/ns/ingen#connection"
+ || predicate.to_string() == "http://lv2plug.in/ns/lv2core#port");
+}
+
+Parser::Parser(Ingen::Shared::World& world)
+{
+}
+
Parser::PatchRecords
Parser::find_patches(Ingen::Shared::World* world,
const Glib::ustring& manifest_uri)
{
+ const Sord::URI ingen_Patch (*world->rdf_world(), NS_INGEN "Patch");
+ const Sord::URI rdf_type (*world->rdf_world(), NS_RDF "type");
+ const Sord::URI rdfs_seeAlso(*world->rdf_world(), NS_RDFS "seeAlso");
+
Sord::Model model(*world->rdf_world(), manifest_uri);
model.load_file(manifest_uri);
- Sord::URI rdf_type(*world->rdf_world(), NS_RDF "type");
- Sord::URI rdfs_seeAlso(*world->rdf_world(), NS_RDFS "seeAlso");
- Sord::URI ingen_Patch(*world->rdf_world(), NS_INGEN "Patch");
-
std::list<PatchRecord> records;
for (Sord::Iter i = model.find(nil, rdf_type, ingen_Patch); !i.end(); ++i) {
const Sord::Node patch = i.get_subject();
@@ -204,13 +224,14 @@ Parser::parse(Ingen::Shared::World* world,
boost::optional<Raul::Symbol> symbol,
boost::optional<GraphObject::Properties> data)
{
- const Sord::URI rdf_type (*world->rdf_world(), NS_RDF "type");
- const Sord::URI patch_class (*world->rdf_world(), NS_INGEN "Patch");
- const Sord::URI node_class (*world->rdf_world(), NS_INGEN "URI");
- const Sord::URI internal_class (*world->rdf_world(), NS_INGEN "Internal");
- const Sord::URI in_port_class (*world->rdf_world(), NS_LV2 "InputPort");
- const Sord::URI out_port_class (*world->rdf_world(), NS_LV2 "OutputPort");
- const Sord::URI lv2_class (*world->rdf_world(), NS_LV2 "Plugin");
+ 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 port_class (*world->rdf_world(), NS_INGEN "Port");
+ const Sord::URI internal_class(*world->rdf_world(), NS_INGEN "Internal");
+ const Sord::URI in_port_class (*world->rdf_world(), NS_LV2 "InputPort");
+ const Sord::URI out_port_class(*world->rdf_world(), NS_LV2 "OutputPort");
+ const Sord::URI lv2_class (*world->rdf_world(), NS_LV2 "Plugin");
+ const Sord::URI rdf_type (*world->rdf_world(), NS_RDF "type");
Sord::Node subject = nil;
if (data_path && data_path->is_root()) {
@@ -228,23 +249,40 @@ Parser::parse(Ingen::Shared::World* world,
path = parent->child(*symbol);
}
- boost::optional<Path> ret;
- boost::optional<Path> root_path;
+ // Get all subjects and their types (?subject a ?type)
+ typedef std::map< Sord::Node, std::set<Sord::Node> > Subjects;
+ Subjects subjects;
for (Sord::Iter i = model.find(subject, rdf_type, nil); !i.end(); ++i) {
const Sord::Node& subject = i.get_subject();
const Sord::Node& rdf_class = i.get_object();
- if (rdf_class == patch_class) {
+ Subjects::iterator s = subjects.find(subject);
+ if (s == subjects.end()) {
+ std::set<Sord::Node> types;
+ types.insert(rdf_class);
+ subjects.insert(make_pair(subject, types));
+ } else {
+ s->second.insert(rdf_class);
+ }
+ }
+
+ // Parse and create each subject
+ boost::optional<Path> ret;
+ boost::optional<Path> root_path;
+ for (Subjects::const_iterator i = subjects.begin(); i != subjects.end(); ++i) {
+ const Sord::Node& subject = i->first;
+ const std::set<Sord::Node>& types = i->second;
+ if (types.find(patch_class) != types.end()) {
ret = parse_patch(world, target, model, subject, parent, symbol, data);
- } else if (rdf_class == node_class) {
+ } else if (types.find(node_class) != types.end()) {
ret = parse_node(world, target, model, subject, path, data);
- } else if (rdf_class == in_port_class || rdf_class == out_port_class) {
+ } else if (types.find(port_class) != types.end()) {
parse_properties(world, target, model, subject, path, data);
ret = path;
}
-
+
if (!ret) {
- LOG(error) << "Failed to parse object " << path << endl;
+ LOG(error) << "Failed to parse " << path << endl;
return boost::optional<Path>();
}
@@ -256,6 +294,60 @@ Parser::parse(Ingen::Shared::World* world,
return path;
}
+static Resource::Properties
+get_properties(Sord::Model& model,
+ const Sord::Node& subject)
+{
+ Resource::Properties props;
+ for (Sord::Iter i = model.find(subject, nil, nil); !i.end(); ++i) {
+ const Sord::Node& predicate = i.get_predicate();
+ const Sord::Node& object = i.get_object();
+ if (!skip_property(predicate)) {
+ props.insert(
+ make_pair(predicate.to_string(),
+ AtomRDF::node_to_atom(model, object)));
+ }
+ }
+ return props;
+}
+
+typedef std::pair<Path, Resource::Properties> PortRecord;
+
+static int
+get_port(Ingen::Shared::World* world,
+ Sord::Model& model,
+ const Sord::Node& subject,
+ const Raul::Path& parent,
+ PortRecord& record)
+{
+ const LV2URIMap& uris = *world->uris().get();
+
+ // Get all properties
+ Resource::Properties props = get_properties(model, subject);
+
+ // Get index
+ Resource::Properties::const_iterator i = props.find(uris.lv2_index);
+ if (i == props.end()
+ || i->second.type() != Atom::INT
+ || i->second.get_int32() < 0) {
+ LOG(error) << "Port " << subject << " has no valid lv2:index" << endl;
+ return -1;
+ }
+ const uint32_t index = i->second.get_int32();
+
+ // Get symbol
+ Resource::Properties::const_iterator s = props.find(uris.lv2_symbol);
+ if (s == props.end()) {
+ LOG(error) << "Port " << subject << " has no symbol" << endl;
+ return -1;
+ }
+ const Symbol port_sym = s->second.get_string();
+ const Path port_path = parent.child(port_sym);
+
+ record = make_pair(port_path, props);
+ return index;
+}
+
boost::optional<Path>
Parser::parse_patch(Ingen::Shared::World* world,
Ingen::Shared::CommonInterface* target,
@@ -265,24 +357,23 @@ Parser::parse_patch(Ingen::Shared::World* world,
boost::optional<Raul::Symbol> a_symbol,
boost::optional<GraphObject::Properties> data)
{
- const LV2URIMap& uris = *world->uris().get();
-
- Sord::URI ingen_polyphony(*world->rdf_world(), NS_INGEN "polyphony");
- Sord::URI lv2_port(*world->rdf_world(), NS_LV2 "port");
- Sord::URI lv2_symbol(*world->rdf_world(), NS_LV2 "symbol");
+ const Sord::URI ingen_node(*world->rdf_world(), NS_INGEN "node");
+ const Sord::URI ingen_polyphony(*world->rdf_world(), NS_INGEN "polyphony");
+ const Sord::URI lv2_port(*world->rdf_world(), NS_LV2 "port");
+ const LV2URIMap& uris = *world->uris().get();
const Sord::Node& patch = subject_node;
uint32_t patch_poly = 0;
- /* Use parameter overridden polyphony, if given */
+ // Use parameter overridden polyphony, if given
if (data) {
GraphObject::Properties::iterator poly_param = data.get().find(uris.ingen_polyphony);
if (poly_param != data.get().end() && poly_param->second.type() == Atom::INT)
patch_poly = poly_param->second.get_int32();
}
- /* Load polyphony from file if necessary */
+ // Load polyphony from file if necessary
if (patch_poly == 0) {
Sord::Iter i = model.find(subject_node, ingen_polyphony, nil);
if (!i.end()) {
@@ -294,7 +385,7 @@ Parser::parse_patch(Ingen::Shared::World* world,
}
}
- /* No polyphony found anywhere, use 1 */
+ // No polyphony found anywhere, use 1
if (patch_poly == 0)
patch_poly = 1;
@@ -304,8 +395,7 @@ Parser::parse_patch(Ingen::Shared::World* world,
if (a_symbol) {
symbol = *a_symbol;
} else {
- const std::string basename = Glib::path_get_basename(base_uri);
- symbol = Raul::Symbol::symbolify(basename.substr(0, basename.find('.')));
+ const std::string basename = get_basename(base_uri);
}
string patch_path_str = relative_uri(base_uri, subject_node.to_string(), true);
@@ -317,132 +407,63 @@ Parser::parse_patch(Ingen::Shared::World* world,
return boost::optional<Raul::Path>();
}
- /* Create patch */
+ // Create patch
Path patch_path(patch_path_str);
- Resource::Properties props;
- props.insert(make_pair(uris.rdf_type, Raul::URI(uris.ingen_Patch)));
- props.insert(make_pair(uris.ingen_polyphony, Raul::Atom(int32_t(patch_poly))));
+ Resource::Properties props = get_properties(model, subject_node);
target->put(patch_path, props);
- Sord::URI rdf_type(*world->rdf_world(), NS_RDF "type");
- Sord::URI ingen_Patch(*world->rdf_world(), NS_INGEN "Patch");
- Sord::URI ingen_node(*world->rdf_world(), NS_INGEN "node");
-
- typedef multimap<Raul::URI, Raul::Atom> Properties;
- typedef map<string, Sord::Node> Resources;
- typedef map<string, Properties> Objects;
- typedef map<string, string> Types;
-
- Objects patch_nodes;
- Objects plugin_nodes;
- Resources resources;
- Types types;
-
- /* For each node in this patch */
- typedef map<Sord::Node, Properties> Nodes;
- Nodes nodes;
+ // 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();
-
- /* Get all node properties */
- Properties node_properties;
- for (Sord::Iter np = model.find(node, nil, nil); !np.end(); ++np) {
- const Sord::Node& predicate = np.get_predicate();
- const Sord::Node& object = np.get_object();
- if (!skip_property(predicate)) {
- node_properties.insert(
- make_pair(predicate.to_string(),
- AtomRDF::node_to_atom(model, object)));
- }
- }
+ Sord::Node node = n.get_object();
+ const Path node_path = patch_path.child(get_basename(node.to_string()));
- /* Create node */
- const Path node_path = patch_path.child(
- relative_uri(base_uri, node.to_string(), false));
- target->put(node_path, node_properties);
+ // Parse and create node
+ parse_node(world, target, model, node, node_path,
+ boost::optional<GraphObject::Properties>());
- /* For each port on this node */
+ // For each port on this node
for (Sord::Iter p = model.find(node, lv2_port, nil); !p.end(); ++p) {
Sord::Node port = p.get_object();
- /* Get all port properties */
- Properties port_properties;
- for (Sord::Iter pp = model.find(port, nil, nil); !pp.end(); ++pp) {
- const Sord::Node& predicate = pp.get_predicate();
- const Sord::Node& object = pp.get_object();
- if (!skip_property(predicate)) {
- port_properties.insert(
- make_pair(predicate.to_string(),
- AtomRDF::node_to_atom(model, object)));
- }
- }
-
- /* Set port properties */
- Properties::const_iterator s = port_properties.find(uris.lv2_symbol);
- if (s == port_properties.end()) {
- LOG(error) << "Port on " << node_path << " has no symbol" << endl;
+ // Get all properties
+ PortRecord port_record;
+ const int index = get_port(world, model, port, node_path, port_record);
+ if (index < 0) {
+ LOG(error) << "Invalid port " << port << endl;
return boost::optional<Path>();
}
- const Symbol port_sym = s->second.get_string();
- const Path port_path = node_path.child(port_sym);
- target->put(port_path, port_properties);
+ // Create port and/or set all port properties
+ target->put(port_record.first, port_record.second);
}
}
- /* For each port on this patch */
+ // For each port on this patch
+ typedef std::map<uint32_t, PortRecord> PortRecords;
+ PortRecords ports;
for (Sord::Iter p = model.find(patch, lv2_port, nil); !p.end(); ++p) {
Sord::Node port = p.get_object();
- /* Get all port properties */
- Properties port_properties;
- for (Sord::Iter pp = model.find(port, nil, nil); !pp.end(); ++pp) {
- const Sord::Node& predicate = pp.get_predicate();
- const Sord::Node& object = pp.get_object();
- if (!skip_property(predicate)) {
- port_properties.insert(
- make_pair(predicate.to_string(),
- AtomRDF::node_to_atom(model, object)));
- }
- }
-
- /* Set port properties */
- Properties::const_iterator s = port_properties.find(uris.lv2_symbol);
- if (s == port_properties.end()) {
- LOG(error) << "Port on " << patch_path << " has no symbol" << endl;
+ // Get all properties
+ PortRecord port_record;
+ const int index = get_port(world, model, port, patch_path, port_record);
+ if (index < 0) {
+ LOG(error) << "Invalid port " << port << endl;
return boost::optional<Path>();
}
- const Symbol port_sym = s->second.get_string();
- const Path port_path = patch_path.child(port_sym);
- target->put(port_path, port_properties);
+ // Store port information in ports map
+ ports[index] = port_record;
}
- parse_properties(world, target, model, subject_node, patch_path, data);
+ // Create ports in order by index
+ for (PortRecords::const_iterator i = ports.begin(); i != ports.end(); ++i) {
+ target->put(i->second.first, i->second.second);
+ }
+
+ //parse_properties(world, target, model, subject_node, patch_path, data);
parse_connections(world, target, model, subject_node, patch_path);
- cerr << "FIXME: enable patch" << endl;
- target->set_property(patch_path, uris.ingen_enabled, (bool)true);
-#if 0
- /* Enable */
- query = Sord::Query(*world->rdf_world(), Glib::ustring(
- "SELECT DISTINCT ?enabled WHERE {\n")
- + subject + " ingen:enabled ?enabled .\n"
- "}");
-
- results = query.run(*world->rdf_world(), model, base_uri);
- for (; !results->finished(); results->next()) {
- Glib::Mutex::Lock lock(world->rdf_world()->mutex());
- const Sord::Node& enabled_node = results->get("enabled");
- if (enabled_node.is_bool() && enabled_node) {
- target->set_property(patch_path, uris.ingen_enabled, (bool)true);
- break;
- } else {
- LOG(warn) << "Unknown type for ingen:enabled" << endl;
- }
- }
-#endif
-
return patch_path;
}
@@ -458,27 +479,52 @@ Parser::parse_node(Ingen::Shared::World* world,
Sord::URI rdf_instanceOf(*world->rdf_world(), NS_RDF "instanceOf");
- /* Get plugin */
Sord::Iter i = model.find(subject, rdf_instanceOf, nil);
- if (i.end()) {
- LOG(error) << "Node missing mandatory rdf:instanceOf property" << endl;
+ if (i.end() || i.get_object().type() != Sord::Node::URI) {
+ LOG(error) << "Node missing mandatory rdf:instanceOf" << endl;
return boost::optional<Path>();
}
- const Sord::Node& plugin_node = i.get_object();
- if (plugin_node.type() != Sord::Node::URI) {
- LOG(error) << "Node's rdf:instanceOf property is not a resource" << endl;
- return boost::optional<Path>();
- }
+ const std::string type_uri = relative_uri(
+ model.base_uri().to_string(),
+ i.get_object().to_string(),
+ false);
- Resource::Properties props;
- props.insert(make_pair(uris.rdf_type,
- Raul::URI(uris.ingen_Node)));
- props.insert(make_pair(uris.rdf_instanceOf,
- AtomRDF::node_to_atom(model, plugin_node)));
- target->put(path, props);
+ if (!serd_uri_string_has_scheme((const uint8_t*)type_uri.c_str())) {
+ SerdURI base_uri;
+ serd_uri_parse(model.base_uri().to_u_string(), &base_uri);
+
+ SerdURI ignored;
+ SerdNode sub_uri = serd_node_new_uri_from_string(
+ i.get_object().to_u_string(),
+ &base_uri,
+ &ignored);
+
+ const std::string sub_uri_str((const char*)sub_uri.buf);
+ std::string basename = get_basename(sub_uri_str);
+
+ const std::string sub_file =
+ string((const char*)sub_uri.buf) + "/" + basename + ".ttl";
+
+ Sord::Model sub_model(*world->rdf_world(), sub_file);
+ sub_model.load_file(sub_file);
+
+ Sord::URI sub_node(*world->rdf_world(), sub_file);
+ parse_patch(world, target, sub_model, sub_node,
+ path.parent(), Raul::Symbol(path.symbol()));
+
+ cout << "DONE PARSING SUB PATCH FILE" << endl;
- parse_properties(world, target, model, subject, path, data);
+ parse_patch(world, target, model, subject,
+ path.parent(), Raul::Symbol(path.symbol()));
+
+ cout << "} SUB PATCH" << endl;
+ } else {
+ Resource::Properties props = get_properties(model, subject);
+ props.insert(make_pair(uris.rdf_type,
+ Raul::URI(uris.ingen_Node)));
+ target->put(path, props);
+ }
return path;
}
@@ -558,13 +604,6 @@ Parser::parse_properties(Ingen::Shared::World* world,
return true;
}
-bool
-Parser::skip_property(const Sord::Node& predicate)
-{
- return (predicate.to_string() == "http://drobilla.net/ns/ingen#node"
- || predicate.to_string() == "http://lv2plug.in/ns/lv2core#port");
-}
-
} // namespace Serialisation
} // namespace Ingen
diff --git a/src/serialisation/Parser.hpp b/src/serialisation/Parser.hpp
index 5d4fc3fc..948a2e74 100644
--- a/src/serialisation/Parser.hpp
+++ b/src/serialisation/Parser.hpp
@@ -39,6 +39,8 @@ namespace Serialisation {
class Parser {
public:
+ Parser(Ingen::Shared::World& world);
+
virtual ~Parser() {}
typedef Shared::GraphObject::Properties Properties;
@@ -115,8 +117,6 @@ private:
Sord::Model& model,
const Sord::Node& subject,
const Raul::Path& patch);
-
- bool skip_property(const Sord::Node& predicate);
};
} // namespace Serialisation
diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp
index 39723177..0629a97c 100644
--- a/src/serialisation/Serialiser.cpp
+++ b/src/serialisation/Serialiser.cpp
@@ -95,11 +95,10 @@ uri_to_symbol(const std::string& uri)
}
void
-Serialiser::write_manifest(const std::string& bundle_uri,
+Serialiser::write_manifest(const std::string& bundle_path,
SharedPtr<Shared::Patch> patch,
const std::string& patch_symbol)
{
- const string bundle_path(Glib::filename_from_uri(bundle_uri));
const string manifest_path(Glib::build_filename(bundle_path, "manifest.ttl"));
const string binary_path(Glib::Module::build_path("", "ingen_lv2"));
@@ -129,24 +128,56 @@ Serialiser::write_manifest(const std::string& bundle_uri,
finish();
}
+std::string
+normal_bundle_uri(const std::string& uri)
+{
+ std::string ret = uri;
+ size_t i;
+ while ((i = ret.find("/./")) != std::string::npos) {
+ ret = ret.substr(0, i) + ret.substr(i + 2);
+ }
+ const size_t last_slash = ret.find_last_of("/");
+ if (last_slash != std::string::npos) {
+ return ret.substr(0, last_slash);
+ } else {
+ return ret + "/";
+ }
+ return ret;
+}
+
void
Serialiser::write_bundle(SharedPtr<Shared::Patch> patch,
const std::string& uri)
{
- string bundle_uri = uri;
- if (bundle_uri[bundle_uri.length()-1] != '/')
- bundle_uri.append("/");
+ Glib::ustring path = "";
+ try {
+ path = Glib::filename_from_uri(uri);
+ } catch (...) {
+ LOG(error) << "Illegal file URI `" << uri << "'" << endl;
+ return;
+ }
+
+ if (Glib::file_test(path, Glib::FILE_TEST_EXISTS)
+ && !Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) {
+ path = Glib::path_get_dirname(path);
+ }
- g_mkdir_with_parents(Glib::filename_from_uri(bundle_uri).c_str(), 0744);
+ if (path[path.length() - 1] != '/')
+ path.append("/");
+
+ g_mkdir_with_parents(path.c_str(), 0744);
const string symbol = uri_to_symbol(uri);
- const string root_file = bundle_uri + symbol + INGEN_PATCH_FILE_EXT;
+ const string root_file = path + symbol + INGEN_PATCH_FILE_EXT;
start_to_filename(root_file);
+ const Path old_root_path = _root_path;
+ _root_path = patch->path();
serialise_patch(patch, Sord::URI(_model->world(), ""));
+ _root_path = old_root_path;
finish();
- write_manifest(bundle_uri, patch, symbol);
+ write_manifest(path, patch, symbol);
}
string
@@ -160,13 +191,9 @@ Serialiser::to_string(SharedPtr<GraphObject> object,
Sord::URI base_rdf_node(_model->world(), base_uri);
for (GraphObject::Properties::const_iterator v = extra_rdf.begin();
v != extra_rdf.end(); ++v) {
- if (v->first.find(":") != string::npos) {
- _model->add_statement(base_rdf_node,
- AtomRDF::atom_to_node(*_model, v->first),
- AtomRDF::atom_to_node(*_model, v->second));
- } else {
- LOG(warn) << "Not serialising extra RDF with key '" << v->first << "'" << endl;
- }
+ _model->add_statement(base_rdf_node,
+ AtomRDF::atom_to_node(*_model, v->first),
+ AtomRDF::atom_to_node(*_model, v->second));
}
return finish();
@@ -244,7 +271,8 @@ Serialiser::path_rdf_node(const Path& path)
{
assert(_model);
assert(path.is_child_of(_root_path));
- return Sord::URI(_model->world(), path.chop_scheme().substr(1));
+ const Path rel_path(path.relative_to_base(_root_path));
+ return Sord::URI(_model->world(), rel_path.chop_scheme().substr(1));
}
void
@@ -269,7 +297,7 @@ Serialiser::serialise(SharedPtr<GraphObject> object) throw (std::logic_error)
SharedPtr<Shared::Port> port = PtrCast<Shared::Port>(object);
if (port) {
- serialise_port(port.get(), path_rdf_node(port->path()));
+ serialise_port(port.get(), Resource::DEFAULT, path_rdf_node(port->path()));
return;
}
@@ -299,7 +327,8 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa
if (s == patch->properties().end()
|| !s->second.type() == Atom::STRING
|| !Symbol::is_valid(s->second.get_string())) {
- symbol = Glib::path_get_basename(Glib::filename_from_uri(_model->base_uri().to_c_string()));
+ const string path = Glib::filename_from_uri(_model->base_uri().to_c_string());
+ symbol = Glib::path_get_basename(path);
symbol = Symbol::symbolify(symbol.substr(0, symbol.find('.')));
_model->add_statement(
patch_id,
@@ -310,12 +339,12 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa
}
// If the patch has no doap:name (required by LV2), use the symbol
- if (patch->meta().properties().find(uris.doap_name) == patch->meta().properties().end())
+ if (patch->properties().find(uris.doap_name) == patch->properties().end())
_model->add_statement(patch_id,
AtomRDF::atom_to_node(*_model, uris.doap_name),
Sord::Literal(world, symbol));
- serialise_properties(patch_id, NULL, patch->meta().properties());
+ serialise_properties(patch.get(), Resource::INTERNAL, patch_id);
for (Store::const_iterator n = _store->children_begin(patch);
n != _store->children_end(patch); ++n) {
@@ -367,10 +396,6 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa
}
}
- assert(_model);
-
- bool root = (patch->path() == _root_path);
-
for (uint32_t i = 0; i < patch->num_ports(); ++i) {
Port* p = patch->port(i);
const Sord::Node port_id = path_rdf_node(p->path());
@@ -382,14 +407,12 @@ Serialiser::serialise_patch(SharedPtr<Shared::Patch> patch, const Sord::Node& pa
_model->add_statement(patch_id,
Sord::URI(world, NS_LV2 "port"),
port_id);
- serialise_port_meta(p, port_id);
- if (root)
- serialise_properties(port_id, &p->meta(), p->properties());
+ serialise_port(p, Resource::INTERNAL, port_id);
}
for (Shared::Patch::Connections::const_iterator c = patch->connections().begin();
c != patch->connections().end(); ++c) {
- serialise_connection(patch, c->second);
+ serialise_connection(patch_id, c->second);
}
}
@@ -408,96 +431,72 @@ Serialiser::serialise_node(SharedPtr<Shared::Node> node,
Sord::Curie(_model->world(), "lv2:symbol"),
Sord::Literal(_model->world(), node->path().symbol()));
- serialise_properties(node_id, &node->meta(), node->properties());
+ serialise_properties(node.get(), Resource::EXTERNAL, node_id);
for (uint32_t i = 0; i < node->num_ports(); ++i) {
Port* const p = node->port(i);
const Sord::Node port_id = path_rdf_node(p->path());
- serialise_port(p, port_id);
+ serialise_port(p, Resource::EXTERNAL, port_id);
_model->add_statement(node_id,
Sord::Curie(_model->world(), "lv2:port"),
port_id);
}
}
-/** Serialise a port on a Node */
void
-Serialiser::serialise_port(const Port* port, const Sord::Node& port_id)
+Serialiser::serialise_port(const Port* port,
+ Shared::Resource::Graph context,
+ const Sord::Node& port_id)
{
Sord::World& world = _model->world();
- if (port->is_input())
+ if (port->is_input()) {
_model->add_statement(port_id,
Sord::Curie(world, "rdf:type"),
Sord::Curie(world, "lv2:InputPort"));
- else
+ } else {
_model->add_statement(port_id,
Sord::Curie(world, "rdf:type"),
Sord::Curie(world, "lv2:OutputPort"));
+ }
for (Port::PortTypes::const_iterator i = port->types().begin();
- i != port->types().end(); ++i)
+ i != port->types().end(); ++i) {
_model->add_statement(port_id,
Sord::Curie(world, "rdf:type"),
Sord::URI(world, i->uri().str()));
+ }
_model->add_statement(port_id,
Sord::Curie(world, "lv2:symbol"),
Sord::Literal(world, port->path().symbol()));
- serialise_properties(port_id, &port->meta(), port->properties());
-}
+ serialise_properties(port, context, port_id);
-/** Serialise a port on a Patch */
-void
-Serialiser::serialise_port_meta(const Port* port, const Sord::Node& port_id)
-{
- Sord::World& world = _model->world();
-
- if (port->is_input())
- _model->add_statement(port_id,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "lv2:InputPort"));
- else
- _model->add_statement(port_id,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "lv2:OutputPort"));
-
- for (Port::PortTypes::const_iterator i = port->types().begin();
- i != port->types().end(); ++i)
- _model->add_statement(port_id,
- Sord::Curie(world, "rdf:type"),
- Sord::URI(world, i->uri().str()));
-
- _model->add_statement(
- port_id,
- Sord::Curie(world, "lv2:index"),
- AtomRDF::atom_to_node(*_model, Atom((int)port->index())));
-
- _model->add_statement(
- port_id,
- Sord::Curie(world, "lv2:symbol"),
- Sord::Literal(world, port->path().symbol()));
-
- if (!port->get_property(NS_LV2 "default").is_valid()) {
- if (port->is_input()) {
- if (port->value().is_valid()) {
- _model->add_statement(
- port_id,
- Sord::Curie(world, "lv2:default"),
- AtomRDF::atom_to_node(*_model, port->value()));
- } else if (port->is_a(PortType::CONTROL)) {
- LOG(warn) << "Port " << port->path() << " has no lv2:default" << endl;
+ if (context == Resource::INTERNAL) {
+ _model->add_statement(
+ port_id,
+ Sord::Curie(world, "lv2:index"),
+ AtomRDF::atom_to_node(*_model, Atom((int)port->index())));
+
+ if (!port->get_property(NS_LV2 "default").is_valid()) {
+ if (port->is_input()) {
+ if (port->value().is_valid()) {
+ _model->add_statement(
+ port_id,
+ Sord::Curie(world, "lv2:default"),
+ AtomRDF::atom_to_node(*_model, port->value()));
+ } else if (port->is_a(PortType::CONTROL)) {
+ LOG(warn) << "Port " << port->path() << " has no lv2:default" << endl;
+ }
}
}
}
-
- serialise_properties(port_id, NULL, port->meta().properties());
}
void
-Serialiser::serialise_connection(SharedPtr<GraphObject> parent,
- SharedPtr<Connection> connection) throw (std::logic_error)
+Serialiser::serialise_connection(const Sord::Node& parent,
+ SharedPtr<Connection> connection) throw (std::logic_error)
{
Sord::World& world = _model->world();
@@ -515,38 +514,35 @@ Serialiser::serialise_connection(SharedPtr<GraphObject> parent,
Sord::Curie(world, "ingen:destination"),
dst);
- if (parent) {
- const Sord::Node parent_id = path_rdf_node(parent->path());
- _model->add_statement(parent_id,
- Sord::Curie(world, "ingen:connection"),
- connection_id);
- } else {
- _model->add_statement(connection_id,
- Sord::Curie(world, "rdf:type"),
- Sord::Curie(world, "ingen:Connection"));
- }
+ _model->add_statement(parent,
+ Sord::Curie(world, "ingen:connection"),
+ connection_id);
+}
+
+static bool
+skip_property(const Sord::Node& predicate)
+{
+ return (predicate.to_string() == "http://drobilla.net/ns/ingen#document");
}
void
-Serialiser::serialise_properties(Sord::Node subject,
- const Shared::Resource* meta,
- const GraphObject::Properties& properties)
+Serialiser::serialise_properties(const Shared::GraphObject* o,
+ Shared::Resource::Graph context,
+ Sord::Node id)
{
- for (GraphObject::Properties::const_iterator v = properties.begin();
- v != properties.end(); ++v) {
- if (v->second.is_valid()) {
- if (!meta || !meta->has_property(v->first.str(), v->second)) {
- const Sord::URI key(_model->world(), v->first.str());
- const Sord::Node value(AtomRDF::atom_to_node(*_model, v->second));
- if (value.is_valid()) {
- _model->add_statement(subject, key, value);
- } else {
- LOG(warn) << "Can not serialise variable '" << v->first << "' :: "
- << (int)v->second.type() << endl;
- }
+ const GraphObject::Properties props = o->properties(context);
+
+ typedef GraphObject::Properties::const_iterator iterator;
+ for (iterator v = props.begin(); v != props.end(); ++v) {
+ const Sord::URI key(_model->world(), v->first.str());
+ const Sord::Node value(AtomRDF::atom_to_node(*_model, v->second));
+ if (!skip_property(key)) {
+ if (value.is_valid()) {
+ _model->add_statement(id, key, value);
+ } else {
+ LOG(warn) << "Can not serialise variable '" << v->first << "' :: "
+ << (int)v->second.type() << endl;
}
- } else {
- LOG(warn) << "Property '" << v->first << "' has no value" << endl;
}
}
}
diff --git a/src/serialisation/Serialiser.hpp b/src/serialisation/Serialiser.hpp
index 55dbcea1..596cb1c5 100644
--- a/src/serialisation/Serialiser.hpp
+++ b/src/serialisation/Serialiser.hpp
@@ -69,8 +69,8 @@ public:
void start_to_string(const Raul::Path& root, const std::string& base_uri);
void serialise(SharedPtr<Shared::GraphObject> object) throw (std::logic_error);
- void serialise_connection(SharedPtr<Shared::GraphObject> parent,
- SharedPtr<Shared::Connection> c) throw (std::logic_error);
+ void serialise_connection(const Sord::Node& parent,
+ SharedPtr<Shared::Connection> c) throw (std::logic_error);
std::string finish();
@@ -79,22 +79,24 @@ private:
void start_to_filename(const std::string& filename);
- void serialise_patch(SharedPtr<Shared::Patch> p, const Sord::Node& id);
+ void serialise_patch(SharedPtr<Shared::Patch> p,
+ const Sord::Node& id);
+
void serialise_node(SharedPtr<Shared::Node> n,
- const Sord::Node& class_id, const Sord::Node& id);
- void serialise_port(const Shared::Port* p, const Sord::Node& id);
- void serialise_port_meta(const Shared::Port* p, const Sord::Node& id);
+ const Sord::Node& class_id,
+ const Sord::Node& id);
- void serialise_meta_properties(Sord::Node subject,
- const Properties& properties);
+ void serialise_port(const Shared::Port* p,
+ Shared::Resource::Graph context,
+ const Sord::Node& id);
- void serialise_properties(Sord::Node subject,
- const Shared::Resource* meta,
- const Properties& properties);
+ void serialise_properties(const Shared::GraphObject* o,
+ Shared::Resource::Graph context,
+ Sord::Node id);
Sord::Node path_rdf_node(const Raul::Path& path);
- void write_manifest(const std::string& bundle_uri,
+ void write_manifest(const std::string& bundle_path,
SharedPtr<Shared::Patch> patch,
const std::string& patch_symbol);
diff --git a/src/serialisation/serialisation.cpp b/src/serialisation/serialisation.cpp
index e6780ed6..c6141d7d 100644
--- a/src/serialisation/serialisation.cpp
+++ b/src/serialisation/serialisation.cpp
@@ -25,7 +25,7 @@ using namespace Ingen;
struct IngenSerialisationModule : public Shared::Module {
void load(Shared::World* world) {
world->set_parser(SharedPtr<Serialisation::Parser>(
- new Serialisation::Parser()));
+ new Serialisation::Parser(*world)));
world->set_serialiser(SharedPtr<Serialisation::Serialiser>(
new Serialisation::Serialiser(*world, world->store())));
}