From 2bbf30f19ee91c930f564fcb3b44308910bc20a7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 14 Feb 2010 05:48:21 +0000 Subject: Preserve patch port indices across saves. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2449 a436a847-0d15-0410-975c-d299462d15a1 --- src/serialisation/Parser.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/serialisation') diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp index d667723e..f59c7263 100644 --- a/src/serialisation/Parser.cpp +++ b/src/serialisation/Parser.cpp @@ -569,7 +569,42 @@ Parser::parse_patch( ports_i->second.insert(make_pair(key, AtomRDF::node_to_atom(model, (*i)["val"]))); } + std::vector ports_by_index(patch_ports.size(), patch_ports.end()); for (Objects::iterator i = patch_ports.begin(); i != patch_ports.end(); ++i) { + Properties::const_iterator index_i = i->second.lower_bound(uris.lv2_index); + if (index_i == i->second.end()) { + error << "Patch port has no index" << endl; + return boost::optional(); + } + + if (index_i->second.type() != Atom::INT) { + error << "Patch port index has non-integer type" << endl; + return boost::optional(); + } + + const int32_t index = index_i->second.get_int32(); + + ++index_i; + if (index_i != i->second.end() && index_i->first == uris.lv2_index) { + error << "Patch port has multiple indices" << endl; + return boost::optional(); + } + + if (index < 0 || static_cast(index) >= patch_ports.size()) { + error << "Patch port index out of range" << endl; + return boost::optional(); + } + + if (ports_by_index[index] != patch_ports.end()) { + error << "Patch has several ports with index " << index << endl; + return boost::optional(); + } + + ports_by_index[index] = i; + } + + for (uint32_t index = 0; index < patch_ports.size(); ++index) { + Objects::iterator i = ports_by_index[index]; Glib::Mutex::Lock lock(world->rdf_world->mutex()); const Path port_path(relative_uri(base_uri, i->first, true)); std::pair types_range -- cgit v1.2.1