diff options
author | David Robillard <d@drobilla.net> | 2014-01-24 04:47:33 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2014-01-24 04:47:33 +0000 |
commit | 2c03f2abd3d3d98a81020438ca805acded39dbab (patch) | |
tree | 92abb5ae29cbc25a0655e7aa5b6a8c07bbff6756 /src/serialisation | |
parent | d970641441746aacfc645176b71d7ba71af0463a (diff) | |
download | ingen-2c03f2abd3d3d98a81020438ca805acded39dbab.tar.gz ingen-2c03f2abd3d3d98a81020438ca805acded39dbab.tar.bz2 ingen-2c03f2abd3d3d98a81020438ca805acded39dbab.zip |
Remove redundant and unnecessary properties from saved graphs and protocol.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5321 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/serialisation')
-rw-r--r-- | src/serialisation/Parser.cpp | 47 | ||||
-rw-r--r-- | src/serialisation/Serialiser.cpp | 21 |
2 files changed, 43 insertions, 25 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index 3d8ba96d..d49ac9a6 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -140,31 +140,47 @@ get_port(Ingen::World* world, Sord::Model& model, const Sord::Node& subject, const Raul::Path& parent, - uint32_t& index) + uint32_t* index) { const URIs& uris = world->uris(); // Get all properties Resource::Properties props = get_properties(world, model, subject); - // Get index - Resource::Properties::const_iterator i = props.find(uris.lv2_index); - if (i == props.end() - || i->second.type() != world->forge().Int - || i->second.get<int32_t>() < 0) { - world->log().warn(fmt("Port %1% has no valid index\n") % subject); - return boost::optional<PortRecord>(); + // Get index if requested (for Graphs) + if (index) { + Resource::Properties::const_iterator i = props.find(uris.lv2_index); + if (i == props.end() + || i->second.type() != world->forge().Int + || i->second.get<int32_t>() < 0) { + world->log().error(fmt("Port %1% has no valid index\n") % subject); + return boost::optional<PortRecord>(); + } + *index = i->second.get<int32_t>(); } - index = i->second.get<int32_t>(); // Get symbol Resource::Properties::const_iterator s = props.find(uris.lv2_symbol); - if (s == props.end()) { - world->log().warn(fmt("Port %1% has no symbol\n") % subject); + std::string sym; + if (s != props.end()) { + sym = s->second.ptr<char>(); + } else { + const std::string subject_str = subject.to_string(); + const size_t last_slash = subject_str.find_last_of("/"); + + sym = ((last_slash == string::npos) + ? subject_str + : subject_str.substr(last_slash + 1)); + } + + if (!Raul::Symbol::is_valid(sym)) { + world->log().error(fmt("Port %1% has invalid symbol `%2%'\n") + % subject % sym); return boost::optional<PortRecord>(); } - const Raul::Symbol port_sym(s->second.ptr<char>()); - const Raul::Path port_path = parent.child(port_sym); + + const Raul::Symbol port_sym(sym); + const Raul::Path port_path(parent.child(port_sym)); return make_pair(port_path, props); } @@ -341,9 +357,8 @@ parse_graph(Ingen::World* world, Sord::Node port = p.get_object(); // Get all properties - uint32_t index = 0; boost::optional<PortRecord> port_record = get_port( - world, model, port, block_path, index); + world, model, port, block_path, NULL); if (!port_record) { world->log().error(fmt("Invalid port %1%\n") % port); return boost::optional<Raul::Path>(); @@ -364,7 +379,7 @@ parse_graph(Ingen::World* world, // Get all properties uint32_t index = 0; boost::optional<PortRecord> port_record = get_port( - world, model, port, graph_path, index); + world, model, port, graph_path, &index); if (!port_record) { world->log().error(fmt("Invalid port %1%\n") % port); return boost::optional<Raul::Path>(); diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp index 425ac00f..dd1be2b4 100644 --- a/src/serialisation/Serialiser.cpp +++ b/src/serialisation/Serialiser.cpp @@ -433,9 +433,6 @@ Serialiser::Impl::serialise_block(SPtr<const Node> block, _model->add_statement(block_id, Sord::URI(_model->world(), uris.ingen_prototype), class_id); - _model->add_statement(block_id, - Sord::URI(_model->world(), uris.lv2_symbol), - Sord::Literal(_model->world(), block->path().symbol())); const Node::Properties props = block->properties(Resource::Graph::EXTERNAL); serialise_properties(block_id, props); @@ -455,14 +452,20 @@ Serialiser::Impl::serialise_port(const Node* port, Resource::Graph context, const Sord::Node& port_id) { - URIs& uris = _world.uris(); - Sord::World& world = _model->world(); + URIs& uris = _world.uris(); + Sord::World& world = _model->world(); + Node::Properties props = port->properties(context); - _model->add_statement(port_id, - Sord::URI(world, uris.lv2_symbol), - Sord::Literal(world, port->path().symbol())); + if (context == Resource::Graph::INTERNAL) { + // Always write lv2:symbol for Graph ports (required for lv2:Plugin) + _model->add_statement(port_id, + Sord::URI(world, uris.lv2_symbol), + Sord::Literal(world, port->path().symbol())); + } else { + // Never write lv2:index for plugin instances (not persistent/stable) + props.erase(uris.lv2_index); + } - Node::Properties props = port->properties(context); if (context == Resource::Graph::INTERNAL && port->has_property(uris.rdf_type, uris.lv2_ControlPort) && port->has_property(uris.rdf_type, uris.lv2_InputPort)) |