diff options
Diffstat (limited to 'src/libs')
28 files changed, 257 insertions, 179 deletions
diff --git a/src/libs/client/DeprecatedLoader.cpp b/src/libs/client/DeprecatedLoader.cpp index c5354c5a..a98b7794 100644 --- a/src/libs/client/DeprecatedLoader.cpp +++ b/src/libs/client/DeprecatedLoader.cpp @@ -149,7 +149,7 @@ DeprecatedLoader::add_metadata(MetadataMap& data, string old_key, string value) if (endptr != c_val && *endptr == '\0') data[key] = Atom(fval); else - data[key]= Atom(value); + data[key] = Atom(value); free(c_val); } diff --git a/src/libs/client/NodeModel.cpp b/src/libs/client/NodeModel.cpp index 39c31c82..58ddb56b 100644 --- a/src/libs/client/NodeModel.cpp +++ b/src/libs/client/NodeModel.cpp @@ -93,6 +93,8 @@ void NodeModel::add_child(SharedPtr<ObjectModel> c) { assert(c->parent().get() == this); + + ObjectModel::add_child(c); SharedPtr<PortModel> pm = PtrCast<PortModel>(c); assert(pm); @@ -100,15 +102,19 @@ NodeModel::add_child(SharedPtr<ObjectModel> c) } -void +bool NodeModel::remove_child(SharedPtr<ObjectModel> c) { assert(c->path().is_child_of(_path)); assert(c->parent().get() == this); + + bool ret = ObjectModel::remove_child(c); SharedPtr<PortModel> pm = PtrCast<PortModel>(c); assert(pm); remove_port(pm); + + return ret; } diff --git a/src/libs/client/NodeModel.hpp b/src/libs/client/NodeModel.hpp index 68027526..ccf2f1fb 100644 --- a/src/libs/client/NodeModel.hpp +++ b/src/libs/client/NodeModel.hpp @@ -19,18 +19,18 @@ #define NODEMODEL_H #include <cstdlib> -#include <map> #include <iostream> #include <string> #include <sigc++/sigc++.h> +#include <raul/Table.hpp> #include "ObjectModel.hpp" #include "PortModel.hpp" #include <raul/Path.hpp> #include <raul/SharedPtr.hpp> #include "PluginModel.hpp" -using std::string; using std::map; using std::find; -using std::cout; using std::cerr; using std::endl; +using std::string; +using Raul::Table; namespace Ingen { namespace Client { @@ -50,7 +50,8 @@ public: SharedPtr<PortModel> get_port(const string& port_name) const; - const map<int, map<int, string> >& get_programs() const { return _banks; } + const Table<int,Table<int,string> >& get_programs() const { return _banks; } + const string& plugin_uri() const { return _plugin_uri; } SharedPtr<PluginModel> plugin() const { return _plugin; } int num_ports() const { return _ports.size(); } @@ -69,7 +70,7 @@ protected: NodeModel(const Path& path); void add_child(SharedPtr<ObjectModel> c); - void remove_child(SharedPtr<ObjectModel> c); + bool remove_child(SharedPtr<ObjectModel> c); void add_port(SharedPtr<PortModel> pm); void remove_port(SharedPtr<PortModel> pm); void remove_port(const Path& port_path); @@ -81,15 +82,15 @@ protected: friend class PatchModel; void set_path(const Path& p); - bool _polyphonic; - PortModelList _ports; ///< List of ports (not a map to preserve order) - string _plugin_uri; ///< Plugin URI (if PluginModel is unknown) - SharedPtr<PluginModel> _plugin; ///< The plugin this node is an instance of - map<int, map<int, string> > _banks; ///< DSSI banks + bool _polyphonic; + PortModelList _ports; ///< List of ports (not a Table to preserve order) + string _plugin_uri; ///< Plugin URI (if PluginModel is unknown) + SharedPtr<PluginModel> _plugin; ///< The plugin this node is an instance of + Table<int, Table<int, string> > _banks; ///< DSSI banks }; -typedef map<string, SharedPtr<NodeModel> > NodeModelMap; +typedef Table<string, SharedPtr<NodeModel> > NodeModelMap; } // namespace Client diff --git a/src/libs/client/ObjectModel.cpp b/src/libs/client/ObjectModel.cpp index 699d1ce7..f1393232 100644 --- a/src/libs/client/ObjectModel.cpp +++ b/src/libs/client/ObjectModel.cpp @@ -16,6 +16,10 @@ */ #include "ObjectModel.hpp" +#include <raul/TableImpl.hpp> +#include <iostream> + +using namespace std; namespace Ingen { namespace Client { @@ -31,6 +35,50 @@ ObjectModel::~ObjectModel() { } +SharedPtr<ObjectModel> +ObjectModel::get_child(const string& name) const +{ + assert(name.find("/") == string::npos); + Children::const_iterator i = _children.find(name); + return ((i != _children.end()) ? (*i).second : SharedPtr<ObjectModel>()); +} + +void +ObjectModel::add_child(SharedPtr<ObjectModel> o) +{ + assert(o); + assert(o->path().is_child_of(_path)); + assert(o->parent().get() == this); + +#ifndef NDEBUG + // Be sure there's no duplicates + Children::iterator existing = _children.find(o->path().name()); + assert(existing == _children.end()); +#endif + + _children.insert(make_pair(o->path().name(), o)); + new_child_sig.emit(o); +} + +bool +ObjectModel::remove_child(SharedPtr<ObjectModel> o) +{ + assert(o->path().is_child_of(_path)); + assert(o->parent().get() == this); + + Children::iterator i = _children.find(o->path().name()); + if (i != _children.end()) { + assert(i->second == o); + _children.erase(i); + removed_child_sig.emit(o); + return true; + } else { + cerr << "[ObjectModel::remove_child] " << _path + << ": failed to find child " << o->path().name() << endl; + return false; + } +} + /** Get a piece of metadata for this object. * * @return Metadata value with key @a key, empty string otherwise. diff --git a/src/libs/client/ObjectModel.hpp b/src/libs/client/ObjectModel.hpp index 03abafba..fe0f223c 100644 --- a/src/libs/client/ObjectModel.hpp +++ b/src/libs/client/ObjectModel.hpp @@ -19,7 +19,6 @@ #define OBJECTMODEL_H #include <cstdlib> -#include <map> #include <iostream> #include <string> #include <algorithm> @@ -29,16 +28,16 @@ #include <raul/Atom.hpp> #include <raul/Path.hpp> #include <raul/SharedPtr.hpp> +#include <raul/Table.hpp> -using std::string; using std::map; using std::find; -using std::cout; using std::cerr; using std::endl; +using std::string; using std::find; using Raul::Atom; using Raul::Path; namespace Ingen { namespace Client { -typedef map<string, Atom> MetadataMap; +typedef Raul::Table<string, Atom> MetadataMap; /** Base class for all GraphObject models (NodeModel, PatchModel, PortModel). @@ -59,34 +58,43 @@ public: const Atom& get_metadata(const string& key) const; void set_metadata(const string& key, const Atom& value) - { _metadata[key] = value; metadata_update_sig.emit(key, value); } + { _metadata.insert(make_pair(key, value)); metadata_update_sig.emit(key, value); } + + typedef Raul::Table<string, SharedPtr<ObjectModel> > Children; const MetadataMap& metadata() const { return _metadata; } + const Children& children() const { return _children; } inline const Path& path() const { return _path; } SharedPtr<ObjectModel> parent() const { return _parent; } + SharedPtr<ObjectModel> get_child(const string& name) const; + // Signals sigc::signal<void, const string&, const Atom&> metadata_update_sig; + sigc::signal<void, SharedPtr<ObjectModel> > new_child_sig; + sigc::signal<void, SharedPtr<ObjectModel> > removed_child_sig; sigc::signal<void> destroyed_sig; + sigc::signal<void> renamed_sig; protected: friend class Store; ObjectModel(const Path& path); - virtual void set_path(const Path& p) { _path = p; } + virtual void set_path(const Path& p) { _path = p; } virtual void set_parent(SharedPtr<ObjectModel> p) { assert(p); _parent = p; } - virtual void add_child(SharedPtr<ObjectModel> c) = 0; - virtual void remove_child(SharedPtr<ObjectModel> c) = 0; + virtual void add_child(SharedPtr<ObjectModel> c); + virtual bool remove_child(SharedPtr<ObjectModel> c); void add_metadata(const MetadataMap& data); void set(SharedPtr<ObjectModel> model); - Path _path; + Path _path; SharedPtr<ObjectModel> _parent; MetadataMap _metadata; + Children _children; }; diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 85cf3dc7..615ae562 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -30,6 +30,8 @@ namespace Client { void PatchModel::set_path(const Path& new_path) { + throw; +#if 0 // FIXME: haack if (new_path == "") { _path = ""; @@ -37,7 +39,7 @@ PatchModel::set_path(const Path& new_path) } NodeModel::set_path(new_path); - for (NodeModelMap::iterator i = _nodes.begin(); i != _nodes.end(); ++i) + for (Children::iterator i = _children.begin(); i != _children.end(); ++i) (*i).second->set_path(_path +"/"+ (*i).second->path().name()); #ifdef DEBUG @@ -48,6 +50,7 @@ PatchModel::set_path(const Path& new_path) assert((*j)->src_port_path().parent().parent() == new_path); } #endif +#endif } @@ -55,100 +58,65 @@ void PatchModel::add_child(SharedPtr<ObjectModel> c) { assert(c->parent().get() == this); - - SharedPtr<PortModel> pm = PtrCast<PortModel>(c); - if (pm) { - add_port(pm); - return; - } - SharedPtr<NodeModel> nm = PtrCast<NodeModel>(c); - if (nm) { - add_node(nm); - return; - } -} - - -void -PatchModel::remove_child(SharedPtr<ObjectModel> c) -{ - assert(c->path().is_child_of(_path)); - assert(c->parent().get() == this); + ObjectModel::add_child(c); SharedPtr<PortModel> pm = PtrCast<PortModel>(c); if (pm) { - remove_port(pm); + add_port(pm); return; } SharedPtr<NodeModel> nm = PtrCast<NodeModel>(c); - if (nm) { - remove_node(nm); - return; - } + if (nm) + new_node_sig.emit(nm); } - SharedPtr<NodeModel> PatchModel::get_node(const string& name) const { - assert(name.find("/") == string::npos); - NodeModelMap::const_iterator i = _nodes.find(name); - return ((i != _nodes.end()) ? (*i).second : SharedPtr<NodeModel>()); + return PtrCast<NodeModel>(get_child(name)); } -void -PatchModel::add_node(SharedPtr<NodeModel> nm) +bool +PatchModel::remove_child(SharedPtr<ObjectModel> o) { - assert(nm); - assert(nm->path().is_child_of(_path)); - assert(nm->parent().get() == this); - - NodeModelMap::iterator existing = _nodes.find(nm->path().name()); + assert(o->path().is_child_of(_path)); + assert(o->parent().get() == this); - // Store should have handled this by merging the two - assert(existing == _nodes.end()); + SharedPtr<PortModel> pm = PtrCast<PortModel>(o); + if (pm) + remove_port(pm); + + // Remove any connections which referred to this object, + // since they can't possibly exist anymore + for (ConnectionList::iterator j = _connections.begin(); j != _connections.end() ; ) { - _nodes[nm->path().name()] = nm; - new_node_sig.emit(nm); -} + list<SharedPtr<ConnectionModel> >::iterator next = j; + ++next; + SharedPtr<ConnectionModel> cm = (*j); -void -PatchModel::remove_node(SharedPtr<NodeModel> nm) -{ - assert(nm->path().is_child_of(_path)); - assert(nm->parent().get() == this); - - NodeModelMap::iterator i = _nodes.find(nm->path().name()); - if (i != _nodes.end()) { - assert(i->second == nm); - - // Remove any connections which referred to this node, - // since they can't possibly exist anymore - for (list<SharedPtr<ConnectionModel> >::iterator j = _connections.begin(); - j != _connections.end() ; ) { - list<SharedPtr<ConnectionModel> >::iterator next = j; - ++next; - SharedPtr<ConnectionModel> cm = (*j); - if (cm->src_port_path().parent() == nm->path() - || cm->dst_port_path().parent() == nm->path()) { - removed_connection_sig.emit(cm); - _connections.erase(j); // cuts our reference - assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates - } - j = next; + if (cm->src_port_path().parent() == o->path() + || cm->src_port_path() == o->path() + || cm->dst_port_path().parent() == o->path() + || cm->dst_port_path() == o->path()) { + removed_connection_sig.emit(cm); + _connections.erase(j); // cuts our reference + assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates } - - // Remove the Node itself - _nodes.erase(i); - removed_node_sig.emit(nm); + j = next; + } + if (ObjectModel::remove_child(o)) { + SharedPtr<NodeModel> nm = PtrCast<NodeModel>(o); + if (nm) { + removed_node_sig.emit(nm); + } + return true; } else { - cerr << "[PatchModel::remove_node] " << _path - << ": failed to find node " << nm->path().name() << endl; + return false; } } @@ -157,10 +125,10 @@ void PatchModel::remove_node(const string& name) { assert(name.find("/") == string::npos); - NodeModelMap::iterator i = _nodes.find(name); - if (i != _nodes.end()) { + NodeModelMap::iterator i = _children.find(name); + if (i != _children.end()) { //delete i->second; - _nodes.erase(i); + _children.erase(i); removed_node_sig.emit(name); i->second->parent().reset(); return; @@ -176,17 +144,17 @@ PatchModel::clear() //for (list<SharedPtr<ConnectionModel> >::iterator j = _connections.begin(); j != _connections.end(); ++j) // delete (*j); - for (NodeModelMap::iterator i = _nodes.begin(); i != _nodes.end(); ++i) { + /*for (Children::iterator i = _children.begin(); i != _children.end(); ++i) { (*i).second->clear(); //delete (*i).second; - } + }*/ - _nodes.clear(); + _children.clear(); _connections.clear(); NodeModel::clear(); - assert(_nodes.empty()); + assert(_children.empty()); assert(_connections.empty()); assert(_ports.empty()); } @@ -205,9 +173,9 @@ PatchModel::rename_node(const Path& old_path, const Path& new_path) assert(old_path.parent() == path()); assert(new_path.parent() == path()); - NodeModelMap::iterator i = _nodes.find(old_path.name()); + NodeModelMap::iterator i = _children.find(old_path.name()); - if (i != _nodes.end()) { + if (i != _children.end()) { SharedPtr<NodeModel> nm = (*i).second; for (list<SharedPtr<ConnectionModel> >::iterator j = _connections.begin(); j != _connections.end(); ++j) { if ((*j)->src_port_path().parent() == old_path) @@ -215,9 +183,9 @@ PatchModel::rename_node(const Path& old_path, const Path& new_path) if ((*j)->dst_port_path().parent() == old_path) (*j)->dst_port_path(new_path.base() + (*j)->dst_port_path().name()); } - _nodes.erase(i); + _children.erase(i); assert(nm->path() == new_path); - _nodes[new_path.name()] = nm; + _children[new_path.name()] = nm; return; } diff --git a/src/libs/client/PatchModel.hpp b/src/libs/client/PatchModel.hpp index 55040858..af1ef101 100644 --- a/src/libs/client/PatchModel.hpp +++ b/src/libs/client/PatchModel.hpp @@ -21,13 +21,12 @@ #include <cassert> #include <list> #include <string> -#include <map> #include <sigc++/sigc++.h> #include "NodeModel.hpp" #include <raul/SharedPtr.hpp> #include "ConnectionModel.hpp" -using std::list; using std::string; using std::map; +using std::list; using std::string; namespace Ingen { namespace Client { @@ -42,7 +41,6 @@ class Store; class PatchModel : public NodeModel { public: - const NodeModelMap& nodes() const { return _nodes; } const ConnectionList& connections() const { return _connections; } SharedPtr<ConnectionModel> get_connection(const string& src_port_path, const string& dst_port_path) const; @@ -79,10 +77,10 @@ private: void disable(); void clear(); void set_path(const Path& path); - void add_node(SharedPtr<NodeModel> nm); - void remove_node(SharedPtr<NodeModel> nm); + //void add_node(SharedPtr<NodeModel> nm); + //void remove_node(SharedPtr<NodeModel> nm); void add_child(SharedPtr<ObjectModel> c); - void remove_child(SharedPtr<ObjectModel> c); + bool remove_child(SharedPtr<ObjectModel> c); void add_connection(SharedPtr<ConnectionModel> cm); void remove_connection(const string& src_port_path, const string& dst_port_path); @@ -90,14 +88,13 @@ private: void rename_node(const Path& old_path, const Path& new_path); void rename_node_port(const Path& old_path, const Path& new_path); - NodeModelMap _nodes; ConnectionList _connections; string _filename; bool _enabled; size_t _poly; }; -typedef map<string, SharedPtr<PatchModel> > PatchModelMap; +typedef Table<string, SharedPtr<PatchModel> > PatchModelMap; } // namespace Client diff --git a/src/libs/client/PortModel.hpp b/src/libs/client/PortModel.hpp index 25573226..cf8b94f0 100644 --- a/src/libs/client/PortModel.hpp +++ b/src/libs/client/PortModel.hpp @@ -85,7 +85,7 @@ private: } void add_child(SharedPtr<ObjectModel> c) { throw; } - void remove_child(SharedPtr<ObjectModel> c) { throw; } + bool remove_child(SharedPtr<ObjectModel> c) { throw; } void connected_to(SharedPtr<PortModel> p) { ++_connections; connection_sig.emit(p); } void disconnected_from(SharedPtr<PortModel> p) { --_connections; disconnection_sig.emit(p); } diff --git a/src/libs/client/Serializer.cpp b/src/libs/client/Serializer.cpp index f0920be5..bf7a745e 100644 --- a/src/libs/client/Serializer.cpp +++ b/src/libs/client/Serializer.cpp @@ -250,17 +250,18 @@ Serializer::serialize_patch(SharedPtr<PatchModel> patch, const Node& patch_id) } } - for (NodeModelMap::const_iterator n = patch->nodes().begin(); n != patch->nodes().end(); ++n) { + for (ObjectModel::Children::const_iterator n = patch->children().begin(); n != patch->children().end(); ++n) { SharedPtr<PatchModel> patch = PtrCast<PatchModel>(n->second); + SharedPtr<NodeModel> node = PtrCast<NodeModel>(n->second); if (patch) { const Node subpatch_id = Node(_model->world(), Node::RESOURCE, patch_id.to_string() + "#" + patch->path().substr(1)); _model->add_statement(patch_id, "ingen:node", subpatch_id); serialize_patch(patch, subpatch_id); - } else { + } else if (node) { const Node node_id = path_to_node_id(n->second->path()); _model->add_statement(patch_id, "ingen:node", node_id); - serialize_node(n->second, node_id); + serialize_node(node, node_id); } } diff --git a/src/libs/client/Serializer.hpp b/src/libs/client/Serializer.hpp index a42d99fa..837d7333 100644 --- a/src/libs/client/Serializer.hpp +++ b/src/libs/client/Serializer.hpp @@ -28,6 +28,7 @@ #include <raul/Atom.hpp> #include <raul/RDFWorld.hpp> #include <raul/RDFModel.hpp> +#include <raul/Table.hpp> #include "ObjectModel.hpp" namespace Ingen { @@ -71,7 +72,8 @@ private: Raul::RDF::Node path_to_node_id(const Path& path); - typedef std::map<Path, Raul::RDF::Node> NodeMap; + typedef Raul::Table<Path, Raul::RDF::Node> NodeMap; + Mode _mode; NodeMap _node_map; string _base_uri; diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index 61c02698..a2c9bf6f 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -34,6 +34,7 @@ Store::Store(SharedPtr<EngineInterface> engine, SharedPtr<SigClientInterface> em , _emitter(emitter) { emitter->object_destroyed_sig.connect(sigc::mem_fun(this, &Store::destruction_event)); + emitter->object_renamed_sig.connect(sigc::mem_fun(this, &Store::rename_event)); emitter->new_plugin_sig.connect(sigc::mem_fun(this, &Store::new_plugin_event)); emitter->new_patch_sig.connect(sigc::mem_fun(this, &Store::new_patch_event)); emitter->new_node_sig.connect(sigc::mem_fun(this, &Store::new_node_event)); @@ -63,7 +64,7 @@ Store::add_plugin_orphan(SharedPtr<NodeModel> node) cerr << "WARNING: Node " << node->path() << " received, but plugin " << node->plugin_uri() << " unknown." << endl; - map<string, list<SharedPtr<NodeModel> > >::iterator spawn + Raul::Table<string, list<SharedPtr<NodeModel> > >::iterator spawn = _plugin_orphans.find(node->plugin_uri()); _engine->request_plugin(node->plugin_uri()); @@ -81,7 +82,7 @@ Store::add_plugin_orphan(SharedPtr<NodeModel> node) void Store::resolve_plugin_orphans(SharedPtr<PluginModel> plugin) { - map<string, list<SharedPtr<NodeModel> > >::iterator n + Raul::Table<string, list<SharedPtr<NodeModel> > >::iterator n = _plugin_orphans.find(plugin->uri()); if (n != _plugin_orphans.end()) { @@ -145,7 +146,7 @@ Store::add_orphan(SharedPtr<ObjectModel> child) { cerr << "WARNING: Orphan object " << child->path() << " received." << endl; - map<Path, list<SharedPtr<ObjectModel> > >::iterator children + Raul::Table<Path, list<SharedPtr<ObjectModel> > >::iterator children = _orphans.find(child->path().parent()); _engine->request_object(child->path().parent()); @@ -155,7 +156,7 @@ Store::add_orphan(SharedPtr<ObjectModel> child) } else { list<SharedPtr<ObjectModel> > l; l.push_back(child); - _orphans[child->path().parent()] = l; + _orphans.insert(make_pair(child->path().parent(), l)); } } @@ -163,7 +164,7 @@ Store::add_orphan(SharedPtr<ObjectModel> child) void Store::add_metadata_orphan(const Path& subject_path, const string& predicate, const Atom& value) { - map<Path, list<std::pair<string, Atom> > >::iterator orphans + Raul::Table<Path, list<std::pair<string, Atom> > >::iterator orphans = _metadata_orphans.find(subject_path); _engine->request_object(subject_path); @@ -181,7 +182,7 @@ Store::add_metadata_orphan(const Path& subject_path, const string& predicate, co void Store::resolve_metadata_orphans(SharedPtr<ObjectModel> subject) { - map<Path, list<std::pair<string, Atom> > >::iterator v + Raul::Table<Path, list<std::pair<string, Atom> > >::iterator v = _metadata_orphans.find(subject->path()); if (v != _metadata_orphans.end()) { @@ -201,7 +202,7 @@ Store::resolve_metadata_orphans(SharedPtr<ObjectModel> subject) void Store::resolve_orphans(SharedPtr<ObjectModel> parent) { - map<Path, list<SharedPtr<ObjectModel> > >::iterator c + Raul::Table<Path, list<SharedPtr<ObjectModel> > >::iterator c = _orphans.find(parent->path()); if (c != _orphans.end()) { @@ -263,7 +264,7 @@ Store::add_object(SharedPtr<ObjectModel> object) SharedPtr<ObjectModel> Store::remove_object(const Path& path) { - map<Path, SharedPtr<ObjectModel> >::iterator i = _objects.find(path); + Objects::iterator i = _objects.find(path); if (i != _objects.end()) { assert((*i).second->path() == path); @@ -298,7 +299,7 @@ SharedPtr<PluginModel> Store::plugin(const string& uri) { assert(uri.length() > 0); - map<string, SharedPtr<PluginModel> >::iterator i = _plugins.find(uri); + Plugins::iterator i = _plugins.find(uri); if (i == _plugins.end()) return SharedPtr<PluginModel>(); else @@ -310,7 +311,7 @@ SharedPtr<ObjectModel> Store::object(const Path& path) { assert(path.length() > 0); - map<Path, SharedPtr<ObjectModel> >::iterator i = _objects.find(path); + Objects::iterator i = _objects.find(path); if (i == _objects.end()) { return SharedPtr<ObjectModel>(); } else { @@ -345,6 +346,20 @@ Store::destruction_event(const Path& path) } void +Store::rename_event(const Path& old_path, const Path& new_path) +{ + SharedPtr<ObjectModel> object = remove_object(old_path); + if (object) { + object->set_path(new_path); + add_object(object); + object->renamed_sig.emit(); + cerr << "[Store] Renamed " << old_path << " -> " << new_path << endl; + } else { + cerr << "[Store] Failed to find object " << old_path << " to rename." << endl; + } +} + +void Store::new_plugin_event(const string& uri, const string& type_uri, const string& name) { SharedPtr<PluginModel> p(new PluginModel(uri, type_uri, name)); @@ -412,8 +427,8 @@ Store::patch_cleared_event(const Path& path) { SharedPtr<PatchModel> patch = PtrCast<PatchModel>(object(path)); if (patch) { - NodeModelMap children = patch->nodes(); // take a copy - for (NodeModelMap::iterator i = children.begin(); i != children.end(); ++i) { + ObjectModel::Children children = patch->children(); // take a copy + for (ObjectModel::Children::iterator i = children.begin(); i != children.end(); ++i) { destruction_event(i->second->path()); } } diff --git a/src/libs/client/Store.hpp b/src/libs/client/Store.hpp index 38814200..627d6f8a 100644 --- a/src/libs/client/Store.hpp +++ b/src/libs/client/Store.hpp @@ -20,14 +20,15 @@ #include <cassert> #include <string> -#include <map> #include <list> #include <raul/SharedPtr.hpp> #include <sigc++/sigc++.h> #include <raul/Path.hpp> #include <raul/Atom.hpp> +#include <raul/Table.hpp> +#include <raul/TableImpl.hpp> #include "interface/EngineInterface.hpp" -using std::string; using std::map; using std::list; +using std::string; using std::list; using Ingen::Shared::EngineInterface; using Raul::Path; using Raul::Atom; @@ -59,10 +60,10 @@ public: size_t num_object() { return _objects.size(); } - typedef map<string, SharedPtr<PluginModel> > Plugins; + typedef Raul::Table<string, SharedPtr<PluginModel> > Plugins; const Plugins& plugins() const { return _plugins; } - typedef map<Path, SharedPtr<ObjectModel> > Objects; + typedef Raul::Table<Path, SharedPtr<ObjectModel> > Objects; const Objects& objects() const { return _objects; } sigc::signal<void, SharedPtr<ObjectModel> > new_object_sig; @@ -91,6 +92,7 @@ private: // Slots for SigClientInterface signals void destruction_event(const Path& path); + void rename_event(const Path& old_path, const Path& new_path); void new_plugin_event(const string& uri, const string& type_uri, const string& name); void new_patch_event(const Path& path, uint32_t poly); void new_node_event(const string& plugin_uri, const Path& node_path, bool is_polyphonic, uint32_t num_ports); @@ -106,20 +108,19 @@ private: SharedPtr<EngineInterface> _engine; SharedPtr<SigClientInterface> _emitter; - Objects _objects; ///< Map, keyed by Ingen path Plugins _plugins; ///< Map, keyed by plugin URI /** Objects we've received, but depend on the existance of another unknown object. * Keyed by the path of the depended-on object (for tolerance of orderless comms) */ - map<Path, list<SharedPtr<ObjectModel> > > _orphans; + Raul::Table<Path, list<SharedPtr<ObjectModel> > > _orphans; /** Same idea, except with plugins instead of parents. * It's unfortunate everything doesn't just have a URI and this was the same.. ahem.. */ - map<string, list<SharedPtr<NodeModel> > > _plugin_orphans; + Raul::Table<string, list<SharedPtr<NodeModel> > > _plugin_orphans; /** Not orphans OF metadata like the above, but orphans which are metadata */ - map<Path, list<std::pair<string, Atom> > > _metadata_orphans; + Raul::Table<Path, list<std::pair<string, Atom> > > _metadata_orphans; /** Ditto */ list<SharedPtr<ConnectionModel> > _connection_orphans; diff --git a/src/libs/engine/NodeBase.cpp b/src/libs/engine/NodeBase.cpp index 04afe3b6..203dc823 100644 --- a/src/libs/engine/NodeBase.cpp +++ b/src/libs/engine/NodeBase.cpp @@ -156,6 +156,7 @@ NodeBase::post_process(SampleCount nframes, FrameTime start, FrameTime end) void NodeBase::set_path(const Path& new_path) { +#if 0 const Path old_path = path(); //cerr << "Renaming " << old_path << " -> " << new_path << endl; @@ -180,6 +181,15 @@ NodeBase::set_path(const Path& new_path) assert(_store->find(new_path) == this); +#endif + GraphObject::set_path(new_path); + + // Rename children (ports) + for (size_t i=0; i < num_ports(); ++i) { + Port* const port = _ports->at(i); + const string name = port->path().name(); + port->set_path(new_path.base() + name); + } } diff --git a/src/libs/engine/ObjectStore.hpp b/src/libs/engine/ObjectStore.hpp index 8a5b61c6..9d56cb77 100644 --- a/src/libs/engine/ObjectStore.hpp +++ b/src/libs/engine/ObjectStore.hpp @@ -47,8 +47,8 @@ public: Port* find_port(const Path& path); GraphObject* find(const Path& path); - void add(GraphObject* o); - void add(TreeNode<GraphObject*>* o); + void add(GraphObject* o); + void add(TreeNode<GraphObject*>* o); TreeNode<GraphObject*>* remove(const string& key); const Tree<GraphObject*>& objects() { return _objects; } diff --git a/src/libs/engine/events/RenameEvent.cpp b/src/libs/engine/events/RenameEvent.cpp index 035bd005..0a2b0239 100644 --- a/src/libs/engine/events/RenameEvent.cpp +++ b/src/libs/engine/events/RenameEvent.cpp @@ -65,7 +65,7 @@ RenameEvent::pre_process() return; } - GraphObject* obj = _engine.object_store()->find(_old_path); + TreeNode<GraphObject*>* obj = _engine.object_store()->remove(_old_path); if (obj == NULL) { _error = OBJECT_NOT_FOUND; @@ -81,8 +81,10 @@ RenameEvent::pre_process() }*/ if (obj != NULL) { - obj->set_path(_new_path); - assert(obj->path() == _new_path); + obj->node()->set_path(_new_path); + obj->key(_new_path); + _engine.object_store()->add(obj); + assert(obj->node()->path() == _new_path); } QueuedEvent::pre_process(); diff --git a/src/libs/engine/tests/Makefile.am b/src/libs/engine/tests/Makefile.am index 9363f51f..64fdd419 100644 --- a/src/libs/engine/tests/Makefile.am +++ b/src/libs/engine/tests/Makefile.am @@ -1,6 +1,6 @@ if BUILD_UNIT_TESTS -AM_CXXFLAGS = @JACK_CFLAGS@ @RAUL_CFLAGS@ @LIBLO_CFLAGS@ @ALSA_CFLAGS@ -I../../common +AM_CXXFLAGS = @JACK_CFLAGS@ @LIBLO_CFLAGS@ @ALSA_CFLAGS@ -I$(top_srcdir)/raul -I../../common common_ldadd = @JACK_LIBS@ @RAUL_LIBS@ @LIBLO_LIBS@ @ALSA_LIBS@ -lrt node_tree_test_LDADD = $(common_ldadd) diff --git a/src/libs/engine/tests/node_tree_test.cpp b/src/libs/engine/tests/node_tree_test.cpp index 2bce9b97..923cb0ba 100644 --- a/src/libs/engine/tests/node_tree_test.cpp +++ b/src/libs/engine/tests/node_tree_test.cpp @@ -1,8 +1,8 @@ #include <cstdlib> #include <iostream> #include <vector> -#include "../Tree.h" -#include "../TreeImplementation.h" +#include "../Tree.hpp" +#include "../TreeImplementation.hpp" using std::vector; using std::cout; using std::cerr; using std::endl; diff --git a/src/libs/gui/LoadPluginWindow.cpp b/src/libs/gui/LoadPluginWindow.cpp index 194b6636..f079bb18 100644 --- a/src/libs/gui/LoadPluginWindow.cpp +++ b/src/libs/gui/LoadPluginWindow.cpp @@ -168,7 +168,7 @@ void LoadPluginWindow::on_show() { if (!_has_shown) { - set_plugin_list(App::instance().store()->plugins()); + set_plugins(App::instance().store()->plugins()); // Center on patch window /*int _w, _h; @@ -209,11 +209,11 @@ LoadPluginWindow::plugin_compare(const Gtk::TreeModel::iterator& a_i, void -LoadPluginWindow::set_plugin_list(const std::map<string, SharedPtr<PluginModel> >& m) +LoadPluginWindow::set_plugins(const Raul::Table<string, SharedPtr<PluginModel> >& m) { _plugins_liststore->clear(); - for (std::map<string, SharedPtr<PluginModel> >::const_iterator i = m.begin(); i != m.end(); ++i) { + for (Raul::Table<string, SharedPtr<PluginModel> >::const_iterator i = m.begin(); i != m.end(); ++i) { SharedPtr<PluginModel> plugin = (*i).second; Gtk::TreeModel::iterator iter = _plugins_liststore->append(); @@ -393,7 +393,7 @@ LoadPluginWindow::filter_changed() size_t num_visible = 0; - for (std::map<string, SharedPtr<PluginModel> >::const_iterator i = App::instance().store()->plugins().begin(); + for (Raul::Table<string, SharedPtr<PluginModel> >::const_iterator i = App::instance().store()->plugins().begin(); i != App::instance().store()->plugins().end(); ++i) { const SharedPtr<PluginModel> plugin = (*i).second; @@ -440,7 +440,7 @@ void LoadPluginWindow::clear_clicked() { _search_entry->set_text(""); - set_plugin_list(App::instance().store()->plugins()); + set_plugins(App::instance().store()->plugins()); } bool diff --git a/src/libs/gui/LoadPluginWindow.hpp b/src/libs/gui/LoadPluginWindow.hpp index ce8a331b..f1ba6383 100644 --- a/src/libs/gui/LoadPluginWindow.hpp +++ b/src/libs/gui/LoadPluginWindow.hpp @@ -19,11 +19,11 @@ #ifndef LOADPLUGINWINDOW_H #define LOADPLUGINWINDOW_H -#include <map> #include <libglademm/xml.h> #include <libglademm.h> #include <gtkmm.h> #include <raul/SharedPtr.hpp> +#include <raul/Table.hpp> #include "client/PatchModel.hpp" #include "client/PluginModel.hpp" using Ingen::Client::PluginModel; @@ -91,7 +91,7 @@ public: LoadPluginWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& xml); void set_patch(SharedPtr<PatchModel> patch); - void set_plugin_list(const std::map<string, SharedPtr<PluginModel> >& m); + void set_plugins(const Raul::Table<string, SharedPtr<PluginModel> >& m); void add_plugin(SharedPtr<PluginModel> plugin); bool has_shown() const { return _has_shown; } diff --git a/src/libs/gui/NodeMenu.cpp b/src/libs/gui/NodeMenu.cpp index f65eb512..3a09e34f 100644 --- a/src/libs/gui/NodeMenu.cpp +++ b/src/libs/gui/NodeMenu.cpp @@ -44,15 +44,15 @@ NodeMenu::NodeMenu(SharedPtr<NodeModel> node) items().push_back(Gtk::Menu_Helpers::SeparatorElem()); - /*items().push_back(Gtk::Menu_Helpers::MenuElem("Rename...", + items().push_back(Gtk::Menu_Helpers::MenuElem("Rename...", sigc::bind( sigc::mem_fun(app.window_factory(), &WindowFactory::present_rename), - node)));*/ + node))); + /*items().push_back(Gtk::Menu_Helpers::MenuElem("Clone", sigc::bind( sigc::mem_fun(app.engine(), &EngineInterface::clone), - node))); - sigc::mem_fun(this, &NodeMenu::on_menu_clone)));*/ + node)));*/ items().push_back(Gtk::Menu_Helpers::MenuElem("Disconnect All", sigc::mem_fun(this, &NodeMenu::on_menu_disconnect_all))); diff --git a/src/libs/gui/PatchCanvas.cpp b/src/libs/gui/PatchCanvas.cpp index 44ee72e6..e209a43f 100644 --- a/src/libs/gui/PatchCanvas.cpp +++ b/src/libs/gui/PatchCanvas.cpp @@ -70,12 +70,6 @@ PatchCanvas::PatchCanvas(SharedPtr<PatchModel> patch, int width, int height) xml->get_widget("canvas_menu_load_plugin", _menu_load_plugin); xml->get_widget("canvas_menu_load_patch", _menu_load_patch); xml->get_widget("canvas_menu_new_patch", _menu_new_patch); - - // Add control menu items - _menu_add_number_control->signal_activate().connect( - sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_control), NUMBER)); - _menu_add_button_control->signal_activate().connect( - sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_control), BUTTON)); // Add port menu items _menu_add_audio_input->signal_activate().connect( @@ -102,6 +96,12 @@ PatchCanvas::PatchCanvas(SharedPtr<PatchModel> patch, int width, int height) _menu_add_osc_output->signal_activate().connect( sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_port), "osc_output", "ingen:osc", true)); + + // Add control menu items + _menu_add_number_control->signal_activate().connect( + sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_control), NUMBER)); + _menu_add_button_control->signal_activate().connect( + sigc::bind(sigc::mem_fun(this, &PatchCanvas::menu_add_control), BUTTON)); #ifdef HAVE_SLV2 build_plugin_menu(); @@ -176,7 +176,7 @@ PatchCanvas::build_plugin_menu() Gtk::MenuItem* plugin_menu_item = &(_menu->items().back()); Gtk::Menu* plugin_menu = Gtk::manage(new Gtk::Menu()); plugin_menu_item->set_submenu(*plugin_menu); - _menu->reorder_child(*plugin_menu_item, 2); + _menu->reorder_child(*plugin_menu_item, 3); SLV2PluginClass lv2_plugin = slv2_world_get_plugin_class(PluginModel::slv2_world()); SLV2PluginClasses classes = slv2_world_get_plugin_classes(PluginModel::slv2_world()); @@ -193,9 +193,11 @@ PatchCanvas::build() boost::dynamic_pointer_cast<PatchCanvas>(shared_from_this()); // Create modules for nodes - for (NodeModelMap::const_iterator i = _patch->nodes().begin(); - i != _patch->nodes().end(); ++i) { - add_node((*i).second); + for (ObjectModel::Children::const_iterator i = _patch->children().begin(); + i != _patch->children().end(); ++i) { + SharedPtr<NodeModel> node = PtrCast<NodeModel>(i->second); + if (node) + add_node(node); } // Create pseudo modules for ports (ports on this canvas, not on our module) diff --git a/src/libs/gui/PatchPortModule.cpp b/src/libs/gui/PatchPortModule.cpp index 1d566741..bf63e9b6 100644 --- a/src/libs/gui/PatchPortModule.cpp +++ b/src/libs/gui/PatchPortModule.cpp @@ -26,6 +26,7 @@ #include "GladeFactory.hpp" #include "RenameWindow.hpp" #include "PatchWindow.hpp" +#include "WindowFactory.hpp" namespace Ingen { namespace GUI { @@ -71,6 +72,10 @@ PatchPortModule::create(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortMod assert(ret); ret->_patch_port = boost::shared_ptr<Port>(new Port(ret, port, true, true)); + ret->_patch_port->menu().items().push_back(Gtk::Menu_Helpers::MenuElem("Rename...", + sigc::bind( + sigc::mem_fun(App::instance().window_factory(), &WindowFactory::present_rename), + port))); ret->add_port(ret->_patch_port); for (MetadataMap::const_iterator m = port->metadata().begin(); m != port->metadata().end(); ++m) diff --git a/src/libs/gui/Port.cpp b/src/libs/gui/Port.cpp index 4b824f15..cd13d89d 100644 --- a/src/libs/gui/Port.cpp +++ b/src/libs/gui/Port.cpp @@ -47,6 +47,8 @@ Port::Port(boost::shared_ptr<FlowCanvas::Module> module, SharedPtr<PortModel> pm if (destroyable) _menu.items().push_back(Gtk::Menu_Helpers::MenuElem("Destroy", sigc::mem_fun(this, &Port::on_menu_destroy))); + + _port_model->renamed_sig.connect(sigc::mem_fun(this, &Port::renamed)); } @@ -57,5 +59,12 @@ Port::on_menu_destroy() } +void +Port::renamed() +{ + set_name(_port_model->path().name()); +} + + } // namespace GUI } // namespace Ingen diff --git a/src/libs/gui/Port.hpp b/src/libs/gui/Port.hpp index 84a1643c..b381c44b 100644 --- a/src/libs/gui/Port.hpp +++ b/src/libs/gui/Port.hpp @@ -46,6 +46,7 @@ public: private: void on_menu_destroy(); + void renamed(); SharedPtr<PortModel> _port_model; }; diff --git a/src/libs/gui/WindowFactory.cpp b/src/libs/gui/WindowFactory.cpp index 9f128e8e..b1ebe5ae 100644 --- a/src/libs/gui/WindowFactory.cpp +++ b/src/libs/gui/WindowFactory.cpp @@ -35,14 +35,14 @@ namespace GUI { WindowFactory::WindowFactory() -: _load_plugin_win(NULL) -, _load_patch_win(NULL) -, _load_remote_patch_win(NULL) -, _upload_patch_win(NULL) -, _new_subpatch_win(NULL) -, _load_subpatch_win(NULL) -, _node_properties_win(NULL) -, _patch_properties_win(NULL) + : _load_plugin_win(NULL) + , _load_patch_win(NULL) + , _load_remote_patch_win(NULL) + , _upload_patch_win(NULL) + , _new_subpatch_win(NULL) + , _load_subpatch_win(NULL) + , _node_properties_win(NULL) + , _patch_properties_win(NULL) { Glib::RefPtr<Gnome::Glade::Xml> xml = GladeFactory::new_glade_reference(); @@ -54,6 +54,7 @@ WindowFactory::WindowFactory() xml->get_widget_derived("load_subpatch_win", _load_subpatch_win); xml->get_widget_derived("node_properties_win", _node_properties_win); xml->get_widget_derived("patch_properties_win", _patch_properties_win); + xml->get_widget_derived("rename_win", _rename_win); } diff --git a/src/libs/gui/ingen_gui.glade b/src/libs/gui/ingen_gui.glade index 6294791c..a4609be7 100644 --- a/src/libs/gui/ingen_gui.glade +++ b/src/libs/gui/ingen_gui.glade @@ -2555,7 +2555,7 @@ Contributors: <widget class="GtkImage" id="menu-item-image20"> <property name="visible">True</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> - <property name="stock">gtk-edit</property> + <property name="stock">gtk-add</property> </widget> </child> </widget> diff --git a/src/libs/serialisation/Loader.cpp b/src/libs/serialisation/Loader.cpp index c14c8a1f..806dbfc3 100644 --- a/src/libs/serialisation/Loader.cpp +++ b/src/libs/serialisation/Loader.cpp @@ -20,6 +20,7 @@ #include <glibmm/ustring.h> #include <raul/RDFModel.hpp> #include <raul/RDFQuery.hpp> +#include <raul/TableImpl.hpp> #include "interface/EngineInterface.hpp" #include "Loader.hpp" @@ -44,13 +45,13 @@ Loader::load(SharedPtr<EngineInterface> engine, boost::optional<Path> parent, string patch_name, Glib::ustring patch_uri, - map<string,Atom> data) + Raul::Table<string, Atom> data) { setlocale(LC_NUMERIC, "C"); // FIXME: this whole thing is a mess - std::map<Path, bool> created; + Raul::Table<Path, bool> created; RDF::Model model(*rdf_world, document_uri); diff --git a/src/libs/serialisation/Loader.hpp b/src/libs/serialisation/Loader.hpp index b729e71d..87465880 100644 --- a/src/libs/serialisation/Loader.hpp +++ b/src/libs/serialisation/Loader.hpp @@ -19,12 +19,12 @@ #define LOADER_H #include <string> -#include <map> #include <glibmm/ustring.h> #include <boost/optional.hpp> #include <raul/SharedPtr.hpp> #include <raul/Path.hpp> #include <raul/Atom.hpp> +#include <raul/Table.hpp> namespace Raul { class Atom; namespace RDF { class World; } } namespace Ingen { namespace Shared { class EngineInterface; } } @@ -37,7 +37,7 @@ class Loader { public: virtual ~Loader() {} - typedef std::map<std::string, Raul::Atom> Metadata; + typedef Raul::Table<std::string, Raul::Atom> Metadata; virtual bool load(SharedPtr<Ingen::Shared::EngineInterface> engine, |