diff options
author | David Robillard <d@drobilla.net> | 2010-02-14 05:48:21 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-02-14 05:48:21 +0000 |
commit | 2bbf30f19ee91c930f564fcb3b44308910bc20a7 (patch) | |
tree | 727aa45066f173ee84c3e0ea9d179d56ac42787d /src/serialisation | |
parent | 8e39e60112ff2a86587436edbde31dc1030bb681 (diff) | |
download | ingen-2bbf30f19ee91c930f564fcb3b44308910bc20a7.tar.gz ingen-2bbf30f19ee91c930f564fcb3b44308910bc20a7.tar.bz2 ingen-2bbf30f19ee91c930f564fcb3b44308910bc20a7.zip |
Preserve patch port indices across saves.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2449 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/serialisation')
-rw-r--r-- | src/serialisation/Parser.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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<Objects::iterator> 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<Raul::Path>(); + } + + if (index_i->second.type() != Atom::INT) { + error << "Patch port index has non-integer type" << endl; + return boost::optional<Raul::Path>(); + } + + 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<Raul::Path>(); + } + + if (index < 0 || static_cast<size_t>(index) >= patch_ports.size()) { + error << "Patch port index out of range" << endl; + return boost::optional<Raul::Path>(); + } + + if (ports_by_index[index] != patch_ports.end()) { + error << "Patch has several ports with index " << index << endl; + return boost::optional<Raul::Path>(); + } + + 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<Properties::iterator,Properties::iterator> types_range |