summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-08-18 19:02:13 +0000
committerDavid Robillard <d@drobilla.net>2008-08-18 19:02:13 +0000
commitf31f6e53c139e194d0d0b4f24b7988c5c3652727 (patch)
treea0f2dbf18bc727a050149548ff24af29d5f7c132 /src
parent76466bde179e9b0d58b1586fb3f4ed40dedbdc13 (diff)
downloadingen-f31f6e53c139e194d0d0b4f24b7988c5c3652727.tar.gz
ingen-f31f6e53c139e194d0d0b4f24b7988c5c3652727.tar.bz2
ingen-f31f6e53c139e194d0d0b4f24b7988c5c3652727.zip
Fix copy/paste between different patches.
Barf less serialisation stuff to the console. git-svn-id: http://svn.drobilla.net/lad/ingen@1431 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/libs/gui/PatchCanvas.cpp8
-rw-r--r--src/libs/gui/ThreadedLoader.cpp5
-rw-r--r--src/libs/serialisation/Parser.cpp6
-rw-r--r--src/libs/serialisation/Serialiser.cpp5
-rw-r--r--src/libs/shared/ClashAvoider.cpp71
-rw-r--r--src/libs/shared/ClashAvoider.hpp10
6 files changed, 63 insertions, 42 deletions
diff --git a/src/libs/gui/PatchCanvas.cpp b/src/libs/gui/PatchCanvas.cpp
index 2ea4496c..4fcafdc3 100644
--- a/src/libs/gui/PatchCanvas.cpp
+++ b/src/libs/gui/PatchCanvas.cpp
@@ -589,17 +589,17 @@ PatchCanvas::paste()
clipboard.set_plugins(App::instance().store()->plugins());
clipboard.new_patch("/", _patch->poly());
- ClashAvoider avoider(*App::instance().store().get(), _patch->path(), clipboard);
- //parser->parse_string(App::instance().world(), &avoider, str, _patch->path().base());
+ ClashAvoider avoider(*App::instance().store().get(), _patch->path(), clipboard, &clipboard);
parser->parse_string(App::instance().world(), &avoider, str, "/",
boost::optional<Glib::ustring>(), (Glib::ustring)_patch->path());
for (Store::iterator i = clipboard.begin(); i != clipboard.end(); ++i) {
+ cout << "************ OBJECT: " << i->first << endl;
if (_patch->path() == "/" && i->first == "/") {
- //cout << "SKIPPING ROOT " << _patch->path() << " :: " << i->first << endl;
+ cout << "SKIPPING ROOT " << _patch->path() << " :: " << i->first << endl;
continue;
} else if (i->first.parent() != "/") {
- //cout << "SKIPPING NON ROOTED OBJECT " << i->first << endl;
+ cout << "SKIPPING NON ROOTED OBJECT " << i->first << endl;
continue;
}
GraphObject::Variables::iterator x = i->second->variables().find("ingenuity:canvas-x");
diff --git a/src/libs/gui/ThreadedLoader.cpp b/src/libs/gui/ThreadedLoader.cpp
index 86c4ea1c..24edc69a 100644
--- a/src/libs/gui/ThreadedLoader.cpp
+++ b/src/libs/gui/ThreadedLoader.cpp
@@ -108,12 +108,9 @@ ThreadedLoader::load_patch(bool merge,
engine_base = engine_parent.get().base();
}
- cout << "ENGINE BASE 1: " << engine_base << endl;
- if (merge && engine_parent.get() == "/" || !engine_parent)
+ if (merge && (engine_parent.get() == "/" || !engine_parent))
engine_base = engine_base.substr(0, engine_base.find_last_of("/"));
- cout << "ENGINE BASE: " << engine_base << endl;
- cout << "PARENT: " << (engine_parent ? (string)engine_parent.get() : "NONE") << endl;
_events.push_back(sigc::hide_return(sigc::bind(
sigc::mem_fun(_parser.get(), &Ingen::Serialisation::Parser::parse_document),
App::instance().world(),
diff --git a/src/libs/serialisation/Parser.cpp b/src/libs/serialisation/Parser.cpp
index 0e83b858..c26921ea 100644
--- a/src/libs/serialisation/Parser.cpp
+++ b/src/libs/serialisation/Parser.cpp
@@ -228,12 +228,8 @@ Parser::parse_patch(
patch_poly = static_cast<uint32_t>(poly_node.to_int());
}
- cout << "XXXXXXXXXX " << engine_base << endl;
- cout << "YYYYYYYYYY " << uri_relative_to_base(base_uri, object_uri) << endl;
string symbol = uri_relative_to_base(base_uri, object_uri);
symbol = symbol.substr(0, symbol.find("."));
- cout << "SSSSSSSSSS " << symbol << endl;
- cout << "BBBBBBBBBBB " << engine_base << endl;
Path patch_path("/");
if (engine_base == "")
patch_path = "/";
@@ -242,8 +238,6 @@ Parser::parse_patch(
else
patch_path = (Path)engine_base;
- cout << "!!!!!!!!!!!!!!!!!!! PATCH PATH: " << patch_path << endl;
-
if (patch_path != engine_base && patch_path != "/")
target->new_patch(patch_path, patch_poly);
diff --git a/src/libs/serialisation/Serialiser.cpp b/src/libs/serialisation/Serialiser.cpp
index dd431f12..5f4c0cbf 100644
--- a/src/libs/serialisation/Serialiser.cpp
+++ b/src/libs/serialisation/Serialiser.cpp
@@ -77,7 +77,6 @@ Serialiser::to_string(SharedPtr<GraphObject> object,
const string& base_uri,
const GraphObject::Variables& extra_rdf)
{
- _root_path = object->path();
start_to_string(object->path(), base_uri);
serialise(object);
@@ -121,12 +120,16 @@ Serialiser::start_to_filename(const string& filename)
*
* The results of the serialization will be returned by the finish() method after
* the desired objects have been serialised.
+ *
+ * All serialized paths will have the root path chopped from their prefix
+ * (therefore all serialized paths must be descendants of the root)
*/
void
Serialiser::start_to_string(const Raul::Path& root, const string& base_uri)
{
setlocale(LC_NUMERIC, "C");
+ _root_path = root;
_base_uri = base_uri;
_model = new Redland::Model(_world);
_model->set_base_uri(base_uri);
diff --git a/src/libs/shared/ClashAvoider.cpp b/src/libs/shared/ClashAvoider.cpp
index c3078468..01a34878 100644
--- a/src/libs/shared/ClashAvoider.cpp
+++ b/src/libs/shared/ClashAvoider.cpp
@@ -28,8 +28,8 @@ namespace Shared {
const Raul::Path
ClashAvoider::map_path(const Raul::Path& in)
{
- cout << "MAP PATH: " << in << endl;
-
+ //cout << "MAP PATH: " << in << endl;
+
unsigned offset = 0;
bool has_offset = false;
size_t pos = in.find_last_of("_");
@@ -38,43 +38,47 @@ ClashAvoider::map_path(const Raul::Path& in)
has_offset = (sscanf(trailing.c_str(), "%u", &offset) > 0);
}
+ //cout << "HAS OFFSET: " << offset << endl;
+
+ // Path without _n suffix
+ Path base_path = in;
+ if (has_offset)
+ base_path = base_path.substr(0, base_path.find_last_of("_"));
+
+ //cout << "\tBASE: " << base_path << endl;
+
SymbolMap::iterator m = _symbol_map.find(in);
if (m != _symbol_map.end()) {
+ //cout << " (1) " << m->second << endl;
return m->second;
} else {
typedef std::pair<SymbolMap::iterator, bool> InsertRecord;
- Store::iterator s = _store.find(_prefix.base() + in.substr(1));
// No clash, use symbol unmodified
- if (s == _store.end()) {
+ if (!exists(in) && _symbol_map.find(in) == _symbol_map.end()) {
InsertRecord i = _symbol_map.insert(make_pair(in, in));
+ assert(i.second);
+ //cout << " (2) " << i.first->second << endl;;
return i.first->second;
} else {
// See if the parent is mapped
+ // FIXME: do this the other way around
Path parent = in.parent();
do {
SymbolMap::iterator p = _symbol_map.find(parent);
if (p != _symbol_map.end()) {
const Path mapped = p->second.base() + in.substr(parent.base().length());
InsertRecord i = _symbol_map.insert(make_pair(in, mapped));
- return _prefix.base() + i.first->second.substr(1);
+ //cout << " (3) " << _prefix.base() + i.first->second.substr(1) << endl;
+ return i.first->second;
}
parent = parent.parent();
} while (parent != "/");
- cout << "????????????????????????????????? " << in << endl;
-
- if (in.parent() != "/")
- cout << "!!!!!!!!!!!!!!!!!!!!!! NOT ROOT PARENT " << endl;
-
// Append _2 _3 etc until an unused symbol is found
- string base_name = in.name();
- if (has_offset)
- base_name = base_name.substr(0, base_name.find_last_of("_"));
-
while (true) {
- Offsets::iterator o = _offsets.find(base_name);
+ Offsets::iterator o = _offsets.find(base_path);
if (o != _offsets.end()) {
offset = ++o->second;
} else {
@@ -82,21 +86,25 @@ ClashAvoider::map_path(const Raul::Path& in)
parent_str = parent_str.substr(0, parent_str.find_last_of("/"));
if (parent_str == "")
parent_str = "/";
- cout << "***** PARENT: " << parent_str << endl;
- offset = _store.child_name_offset(parent_str, base_name, false);
- _offsets.insert(make_pair(base_name, offset));
+ //cout << "***** PARENT: " << parent_str << endl;
}
- assert(offset != 0); // shouldn't have been a clash, then...
std::stringstream ss;
- ss << in.parent().base() << base_name << "_" << offset;
- if (_store.find(ss.str()) == _store.end()) {
- string str = _prefix.base() + ss.str().substr(1);
+ ss << base_path << "_" << offset;
+ if (!exists(ss.str())) {
+ string str = ss.str();
InsertRecord i = _symbol_map.insert(make_pair(in, str));
- cout << "HIT: offset = " << offset << ", str = " << str << endl;
+ //cout << "HIT: offset = " << offset << ", str = " << str << endl;
+ offset = _store.child_name_offset(in.parent(), base_path.name(), false);
+ _offsets.insert(make_pair(base_path, offset));
+ //cout << " (4) " << i.first->second << endl;;
return i.first->second;
} else {
- cout << "MISSED OFFSET: " << in << " => " << ss.str() << endl;
+ //cout << "MISSED OFFSET: " << in << " => " << ss.str() << endl;
+ if (o != _offsets.end())
+ offset = ++o->second;
+ else
+ ++offset;
}
}
}
@@ -104,6 +112,20 @@ ClashAvoider::map_path(const Raul::Path& in)
}
+bool
+ClashAvoider::exists(const Raul::Path& path) const
+{
+ bool exists = (_store.find(_prefix.base() + path.substr(1)) != _store.end());
+ if (exists)
+ return true;
+
+ if (_also_avoid)
+ return (_also_avoid->find(path) != _also_avoid->end());
+ else
+ return false;
+}
+
+
void
ClashAvoider::new_patch(const std::string& path,
uint32_t poly)
@@ -116,6 +138,7 @@ void
ClashAvoider::new_node(const std::string& path,
const std::string& plugin_uri)
{
+ cout << "NEW NODE: " << path << " -> " << map_path(path) << endl;
_target.new_node(map_path(path), plugin_uri);
}
diff --git a/src/libs/shared/ClashAvoider.hpp b/src/libs/shared/ClashAvoider.hpp
index 3c8a1c9f..9f205ff5 100644
--- a/src/libs/shared/ClashAvoider.hpp
+++ b/src/libs/shared/ClashAvoider.hpp
@@ -37,8 +37,9 @@ class Store;
class ClashAvoider : public CommonInterface
{
public:
- ClashAvoider(Store& store, const Raul::Path& prefix, CommonInterface& target)
- : _prefix(prefix), _store(store), _target(target) {}
+ ClashAvoider(Store& store, const Raul::Path& prefix, CommonInterface& target,
+ Store* also_avoid=NULL)
+ : _prefix(prefix), _store(store), _target(target), _also_avoid(also_avoid) {}
void set_target(CommonInterface& target) { _target = target; }
@@ -87,7 +88,10 @@ private:
Store& _store;
CommonInterface& _target;
- typedef std::map<Raul::Symbol, unsigned> Offsets;
+ Store* _also_avoid;
+ bool exists(const Raul::Path& path) const;
+
+ typedef std::map<Raul::Path, unsigned> Offsets;
Offsets _offsets;
typedef std::map<Raul::Path, Raul::Path> SymbolMap;