From cb42d2cc4daa09c7d1db5515e39e94b9a5a43447 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 2 Dec 2008 05:49:41 +0000 Subject: Rewrite pretty much everything to do with paths in Serialiser to actually make an ounce of sense. Fix various things with nested patches (fix tickets #286 #289). Cascade successive pastes nicely. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1840 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/PatchCanvas.cpp | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'src/gui/PatchCanvas.cpp') diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp index 852aca5e..8a580b88 100644 --- a/src/gui/PatchCanvas.cpp +++ b/src/gui/PatchCanvas.cpp @@ -58,6 +58,7 @@ PatchCanvas::PatchCanvas(SharedPtr patch, int width, int height) , _patch(patch) , _last_click_x(0) , _last_click_y(0) + , _paste_count(0) , _refresh_menu(false) , _human_names(true) , _show_port_names(true) @@ -632,6 +633,7 @@ PatchCanvas::copy_selection() } string result = serialiser.finish(); + _paste_count = 0; Glib::RefPtr clipboard = Gtk::Clipboard::get(); clipboard->set_text(result); @@ -649,30 +651,51 @@ PatchCanvas::paste() } clear_selection(); + ++_paste_count; Builder builder(*App::instance().engine()); ClientStore clipboard; clipboard.set_plugins(App::instance().store()->plugins()); + + // mkdir -p + string to_create = _patch->path().substr(1); + string created = "/"; clipboard.new_patch("/", _patch->poly()); + size_t first_slash; + while (to_create != "/" && to_create != "" + && (first_slash = to_create.find("/")) != string::npos) { + created += to_create.substr(0, first_slash); + assert(Path::is_valid(created)); + clipboard.new_patch(created, _patch->poly()); + to_create = to_create.substr(first_slash + 1); + } + + if (_patch->path() != "/") + clipboard.new_patch(_patch->path(), _patch->poly()); - ClashAvoider avoider(*App::instance().store().get(), _patch->path(), clipboard, &clipboard); - parser->parse_string(App::instance().world(), &avoider, str, "/", _patch->path()); + boost::optional data_path; + boost::optional parent; + boost::optional symbol; + + if (_patch->path() != "/") { + parent = _patch->path(); + } + + ClashAvoider avoider(*App::instance().store().get(), clipboard, &clipboard); + parser->parse_string(App::instance().world(), &avoider, str, "", data_path, + parent, symbol); 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; - continue; - } else if (i->first.parent() != "/") { - //cout << "SKIPPING NON ROOTED OBJECT " << i->first << endl; + //cout << "Skipping root" << endl; continue; } GraphObject::Variables::iterator x = i->second->variables().find("ingenuity:canvas-x"); if (x != i->second->variables().end()) - x->second = x->second.get_float() + 20.0f; + x->second = x->second.get_float() + (20.0f * _paste_count); GraphObject::Variables::iterator y = i->second->variables().find("ingenuity:canvas-y"); if (y != i->second->variables().end()) - y->second = y->second.get_float() + 20.0f; + y->second = y->second.get_float() + (20.0f * _paste_count); if (i->first.parent() == "/") { GraphObject::Properties::iterator s = i->second->properties().find("ingen:selected"); if (s != i->second->properties().end()) @@ -680,11 +703,11 @@ PatchCanvas::paste() else i->second->properties().insert(make_pair("ingen:selected", true)); } - builder.build(_patch->path(), i->second); + builder.build(i->second); } // Successful connections - SharedPtr root = PtrCast(clipboard.object("/")); + SharedPtr root = PtrCast(clipboard.object(_patch->path())); assert(root); for (Patch::Connections::const_iterator i = root->connections().begin(); i != root->connections().end(); ++i) { @@ -694,6 +717,7 @@ PatchCanvas::paste() // Orphan connections (just in case...) for (ClientStore::ConnectionRecords::const_iterator i = clipboard.connection_records().begin(); i != clipboard.connection_records().end(); ++i) { + cout << "WARNING: Orphan connection paste: " << i->first << " -> " << i->second << endl; App::instance().engine()->connect(i->first, i->second); } } -- cgit v1.2.1