From 602e31074b30167baace71ccfff1f58a6b3f0626 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 17 Aug 2008 18:58:24 +0000 Subject: More serialization work. Preliminary copy/paste (nodes only) git-svn-id: http://svn.drobilla.net/lad/ingen@1418 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/ClientStore.cpp | 97 ++++++++++++++++++++++++++++------------- src/libs/client/ClientStore.hpp | 45 +++++++++++-------- src/libs/client/ObjectModel.cpp | 34 +++++++++++++++ src/libs/client/ObjectModel.hpp | 4 ++ src/libs/client/PortModel.hpp | 9 +++- 5 files changed, 139 insertions(+), 50 deletions(-) (limited to 'src/libs/client') diff --git a/src/libs/client/ClientStore.cpp b/src/libs/client/ClientStore.cpp index 969f3a8f..6c2c81ff 100644 --- a/src/libs/client/ClientStore.cpp +++ b/src/libs/client/ClientStore.cpp @@ -35,20 +35,27 @@ namespace Client { ClientStore::ClientStore(SharedPtr engine, SharedPtr emitter) : _engine(engine) , _emitter(emitter) + , _plugins(new Plugins()) { - emitter->signal_object_destroyed.connect(sigc::mem_fun(this, &ClientStore::destruction_event)); - emitter->signal_object_renamed.connect(sigc::mem_fun(this, &ClientStore::rename_event)); - emitter->signal_new_plugin.connect(sigc::mem_fun(this, &ClientStore::new_plugin_event)); - emitter->signal_new_patch.connect(sigc::mem_fun(this, &ClientStore::new_patch_event)); - emitter->signal_new_node.connect(sigc::mem_fun(this, &ClientStore::new_node_event)); - emitter->signal_new_port.connect(sigc::mem_fun(this, &ClientStore::new_port_event)); - emitter->signal_patch_cleared.connect(sigc::mem_fun(this, &ClientStore::patch_cleared_event)); - emitter->signal_connection.connect(sigc::mem_fun(this, &ClientStore::connection_event)); - emitter->signal_disconnection.connect(sigc::mem_fun(this, &ClientStore::disconnection_event)); - emitter->signal_variable_change.connect(sigc::mem_fun(this, &ClientStore::variable_change_event)); - emitter->signal_property_change.connect(sigc::mem_fun(this, &ClientStore::property_change_event)); - emitter->signal_port_value.connect(sigc::mem_fun(this, &ClientStore::port_value_event)); - emitter->signal_port_activity.connect(sigc::mem_fun(this, &ClientStore::port_activity_event)); + _handle_orphans = (engine && emitter); + + if (!emitter) + return; + + emitter->signal_object_destroyed.connect(sigc::mem_fun(this, &ClientStore::destruction)); + emitter->signal_object_renamed.connect(sigc::mem_fun(this, &ClientStore::rename)); + emitter->signal_new_plugin.connect(sigc::mem_fun(this, &ClientStore::new_plugin)); + emitter->signal_new_patch.connect(sigc::mem_fun(this, &ClientStore::new_patch)); + emitter->signal_new_node.connect(sigc::mem_fun(this, &ClientStore::new_node)); + emitter->signal_new_port.connect(sigc::mem_fun(this, &ClientStore::new_port)); + emitter->signal_patch_cleared.connect(sigc::mem_fun(this, &ClientStore::patch_cleared)); + emitter->signal_connection.connect(sigc::mem_fun(this, &ClientStore::connect)); + emitter->signal_disconnection.connect(sigc::mem_fun(this, &ClientStore::disconnect)); + emitter->signal_variable_change.connect(sigc::mem_fun(this, &ClientStore::set_variable)); + emitter->signal_property_change.connect(sigc::mem_fun(this, &ClientStore::set_property)); + emitter->signal_port_value.connect(sigc::mem_fun(this, &ClientStore::set_port_value)); + emitter->signal_voice_value.connect(sigc::mem_fun(this, &ClientStore::set_voice_value)); + emitter->signal_port_activity.connect(sigc::mem_fun(this, &ClientStore::port_activity)); } @@ -56,13 +63,15 @@ void ClientStore::clear() { Store::clear(); - _plugins.clear(); + _plugins->clear(); } void ClientStore::add_plugin_orphan(SharedPtr node) { + if (!_handle_orphans) + return; cerr << "WARNING: Node " << node->path() << " received, but plugin " << node->plugin_uri() << " unknown." << endl; @@ -84,6 +93,8 @@ ClientStore::add_plugin_orphan(SharedPtr node) void ClientStore::resolve_plugin_orphans(SharedPtr plugin) { + if (!_handle_orphans) + return; Raul::Table > >::iterator n = _plugin_orphans.find(plugin->uri()); @@ -106,6 +117,8 @@ ClientStore::resolve_plugin_orphans(SharedPtr plugin) void ClientStore::add_connection_orphan(std::pair orphan) { + if (!_handle_orphans) + return; cerr << "WARNING: Orphan connection " << orphan.first << " -> " << orphan.second << " received." << endl; @@ -116,6 +129,8 @@ ClientStore::add_connection_orphan(std::pair orphan) void ClientStore::resolve_connection_orphans(SharedPtr port) { + if (!_handle_orphans) + return; assert(port->parent()); for (list< pair >::iterator c = _connection_orphans.begin(); @@ -139,6 +154,8 @@ ClientStore::resolve_connection_orphans(SharedPtr port) void ClientStore::add_orphan(SharedPtr child) { + if (!_handle_orphans) + return; cerr << "WARNING: Orphan object " << child->path() << " received." << endl; Raul::PathTable > >::iterator children @@ -159,6 +176,8 @@ ClientStore::add_orphan(SharedPtr child) void ClientStore::add_variable_orphan(const Path& subject_path, const string& predicate, const Atom& value) { + if (!_handle_orphans) + return; Raul::PathTable > >::iterator orphans = _variable_orphans.find(subject_path); @@ -177,6 +196,8 @@ ClientStore::add_variable_orphan(const Path& subject_path, const string& predica void ClientStore::resolve_variable_orphans(SharedPtr subject) { + if (!_handle_orphans) + return; Raul::PathTable > >::iterator v = _variable_orphans.find(subject->path()); @@ -198,6 +219,8 @@ ClientStore::resolve_variable_orphans(SharedPtr subject) void ClientStore::resolve_orphans(SharedPtr parent) { + if (!_handle_orphans) + return; Raul::PathTable > >::iterator c = _orphans.find(parent->path()); @@ -222,6 +245,7 @@ ClientStore::add_object(SharedPtr object) // one (with precedence to the new values). iterator existing = find(object->path()); if (existing != end()) { + cout << "WARNING: Object " << object->path() << " already exists in store" << endl; PtrCast(existing->second)->set(object); } else { @@ -307,8 +331,8 @@ SharedPtr ClientStore::plugin(const string& uri) { assert(uri.length() > 0); - Plugins::iterator i = _plugins.find(uri); - if (i == _plugins.end()) + Plugins::iterator i = _plugins->find(uri); + if (i == _plugins->end()) return SharedPtr(); else return (*i).second; @@ -335,9 +359,9 @@ ClientStore::add_plugin(SharedPtr pm) { // FIXME: dupes? merge, like with objects? - _plugins[pm->uri()] = pm; + (*_plugins)[pm->uri()] = pm; signal_new_plugin(pm); - //cerr << "Plugin: " << pm->uri() << ", # plugins: " << _plugins.size() << endl; + //cerr << "Plugin: " << pm->uri() << ", # plugins: " << _plugins->size() << endl; } @@ -345,7 +369,7 @@ ClientStore::add_plugin(SharedPtr pm) void -ClientStore::destruction_event(const Path& path) +ClientStore::destruction(const Path& path) { SharedPtr removed = remove_object(path); @@ -356,7 +380,7 @@ ClientStore::destruction_event(const Path& path) } void -ClientStore::rename_event(const Path& old_path, const Path& new_path) +ClientStore::rename(const Path& old_path, const Path& new_path) { iterator parent = find(old_path); if (parent == end()) { @@ -398,7 +422,7 @@ ClientStore::rename_event(const Path& old_path, const Path& new_path) } void -ClientStore::new_plugin_event(const string& uri, const string& type_uri, const string& symbol, const string& name) +ClientStore::new_plugin(const string& uri, const string& type_uri, const string& symbol, const string& name) { SharedPtr p(new PluginModel(uri, type_uri, symbol, name)); add_plugin(p); @@ -407,7 +431,7 @@ ClientStore::new_plugin_event(const string& uri, const string& type_uri, const s void -ClientStore::new_patch_event(const Path& path, uint32_t poly) +ClientStore::new_patch(const string& path, uint32_t poly) { SharedPtr p(new PatchModel(path, poly)); add_object(p); @@ -415,7 +439,7 @@ ClientStore::new_patch_event(const Path& path, uint32_t poly) void -ClientStore::new_node_event(const Path& path, const string& plugin_uri) +ClientStore::new_node(const string& path, const string& plugin_uri) { SharedPtr plug = plugin(plugin_uri); if (!plug) { @@ -429,7 +453,7 @@ ClientStore::new_node_event(const Path& path, const string& plugin_uri) void -ClientStore::new_port_event(const Path& path, uint32_t index, const string& type, bool is_output) +ClientStore::new_port(const string& path, uint32_t index, const string& type, bool is_output) { PortModel::Direction pdir = is_output ? PortModel::OUTPUT : PortModel::INPUT; @@ -441,7 +465,7 @@ ClientStore::new_port_event(const Path& path, uint32_t index, const string& type void -ClientStore::patch_cleared_event(const Path& path) +ClientStore::patch_cleared(const Path& path) { iterator i = find(path); if (i != end()) { @@ -469,7 +493,7 @@ ClientStore::patch_cleared_event(const Path& path) void -ClientStore::variable_change_event(const Path& subject_path, const string& predicate, const Atom& value) +ClientStore::set_variable(const string& subject_path, const string& predicate, const Atom& value) { SharedPtr subject = object(subject_path); @@ -485,7 +509,7 @@ ClientStore::variable_change_event(const Path& subject_path, const string& predi void -ClientStore::property_change_event(const Path& subject_path, const string& predicate, const Atom& value) +ClientStore::set_property(const string& subject_path, const string& predicate, const Atom& value) { SharedPtr subject = object(subject_path); @@ -501,7 +525,7 @@ ClientStore::property_change_event(const Path& subject_path, const string& predi void -ClientStore::port_value_event(const Path& port_path, const Raul::Atom& value) +ClientStore::set_port_value(const string& port_path, const Raul::Atom& value) { SharedPtr port = PtrCast(object(port_path)); if (port) @@ -510,9 +534,20 @@ ClientStore::port_value_event(const Path& port_path, const Raul::Atom& value) cerr << "ERROR: control change for nonexistant port " << port_path << endl; } + +void +ClientStore::set_voice_value(const string& port_path, uint32_t voice, const Raul::Atom& value) +{ + SharedPtr port = PtrCast(object(port_path)); + if (port) + port->value(voice, value); + else + cerr << "ERROR: poly control change for nonexistant port " << port_path << endl; +} + void -ClientStore::port_activity_event(const Path& port_path) +ClientStore::port_activity(const Path& port_path) { SharedPtr port = PtrCast(object(port_path)); if (port) @@ -581,14 +616,14 @@ ClientStore::attempt_connection(const Path& src_port_path, const Path& dst_port_ void -ClientStore::connection_event(const Path& src_port_path, const Path& dst_port_path) +ClientStore::connect(const string& src_port_path, const string& dst_port_path) { attempt_connection(src_port_path, dst_port_path, true); } void -ClientStore::disconnection_event(const Path& src_port_path, const Path& dst_port_path) +ClientStore::disconnect(const string& src_port_path, const string& dst_port_path) { // Find the ports and create a ConnectionModel just to get at the parent path // finding logic in ConnectionModel. So I'm lazy. diff --git a/src/libs/client/ClientStore.hpp b/src/libs/client/ClientStore.hpp index a750f875..4b4d9742 100644 --- a/src/libs/client/ClientStore.hpp +++ b/src/libs/client/ClientStore.hpp @@ -53,9 +53,10 @@ class ConnectionModel; * * \ingroup IngenClient */ -class ClientStore : public Shared::Store, public sigc::trackable { // FIXME: is trackable necessary? +class ClientStore : public Shared::Store, public Shared::CommonInterface, public sigc::trackable { public: - ClientStore(SharedPtr engine, SharedPtr emitter); + ClientStore(SharedPtr engine=SharedPtr(), + SharedPtr emitter=SharedPtr()); SharedPtr plugin(const string& uri); SharedPtr object(const Path& path); @@ -63,7 +64,21 @@ public: void clear(); typedef Raul::Table > Plugins; - const Plugins& plugins() const { return _plugins; } + SharedPtr plugins() const { return _plugins; } + SharedPtr plugins() { return _plugins; } + void set_plugins(SharedPtr p) { _plugins = p; } + + // CommonInterface + void new_plugin(const string& uri, const string& type_uri, const string& symbol, const string& name); + void new_patch(const string& path, uint32_t poly); + void new_node(const string& path, const string& plugin_uri); + void new_port(const string& path, uint32_t index, const string& data_type, bool is_output); + void set_variable(const string& subject_path, const string& predicate, const Atom& value); + void set_property(const string& subject_path, const string& predicate, const Atom& value); + void set_port_value(const string& port_path, const Raul::Atom& value); + void set_voice_value(const string& port_path, uint32_t voice, const Raul::Atom& value); + void connect(const string& src_port_path, const string& dst_port_path); + void disconnect(const string& src_port_path, const string& dst_port_path); sigc::signal > signal_new_object; sigc::signal > signal_new_plugin; @@ -92,28 +107,24 @@ private: void add_variable_orphan(const Path& subject, const string& predicate, const Atom& value); void resolve_variable_orphans(SharedPtr subject); + + void bundle_begin() {} + void bundle_end() {} // 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& symbol, const string& name); - void new_patch_event(const Path& path, uint32_t poly); - void new_node_event(const Path& path, const string& plugin_uri); - void new_port_event(const Path& path, uint32_t index, const string& data_type, bool is_output); - void patch_cleared_event(const Path& path); - void variable_change_event(const Path& subject_path, const string& predicate, const Atom& value); - void property_change_event(const Path& subject_path, const string& predicate, const Atom& value); - void port_value_event(const Path& port_path, const Raul::Atom& value); - void port_activity_event(const Path& port_path); - void connection_event(const Path& src_port_path, const Path& dst_port_path); - void disconnection_event(const Path& src_port_path, const Path& dst_port_path); + void destruction(const Path& path); + void rename(const Path& old_path, const Path& new_path); + void patch_cleared(const Path& path); + void port_activity(const Path& port_path); bool attempt_connection(const Path& src_port_path, const Path& dst_port_path, bool add_orphan=false); + bool _handle_orphans; + SharedPtr _engine; SharedPtr _emitter; - Plugins _plugins; ///< Map, keyed by plugin URI + SharedPtr _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) */ diff --git a/src/libs/client/ObjectModel.cpp b/src/libs/client/ObjectModel.cpp index 0afb9ad8..e9a491a6 100644 --- a/src/libs/client/ObjectModel.cpp +++ b/src/libs/client/ObjectModel.cpp @@ -54,6 +54,23 @@ ObjectModel::get_variable(const string& key) const } +/** Get a variable for this object. + * + * @return Metadata value with key @a key, empty string otherwise. + */ +Atom& +ObjectModel::get_variable( string& key) +{ + static Atom null_atom; + + Variables::iterator i = _variables.find(key); + if (i != _variables.end()) + return i->second; + else + return null_atom; +} + + /** Get a property of this object. * * @return Metadata value with key @a key, empty string otherwise. @@ -71,6 +88,23 @@ ObjectModel::get_property(const string& key) const } +/** Get a property of this object. + * + * @return Metadata value with key @a key, empty string otherwise. + */ +Atom& +ObjectModel::get_property(const string& key) +{ + static Atom null_atom; + + Properties::iterator i = _properties.find(key); + if (i != _properties.end()) + return i->second; + else + return null_atom; +} + + bool ObjectModel::polyphonic() const { diff --git a/src/libs/client/ObjectModel.hpp b/src/libs/client/ObjectModel.hpp index 2b4642da..11cc87a4 100644 --- a/src/libs/client/ObjectModel.hpp +++ b/src/libs/client/ObjectModel.hpp @@ -60,7 +60,9 @@ public: virtual ~ObjectModel(); const Atom& get_variable(const string& key) const; + Atom& get_variable( string& key); const Atom& get_property(const string& key) const; + Atom& get_property(const string& key); virtual void set_variable(const string& key, const Atom& value) { _variables[key] = value; signal_variable.emit(key, value); } @@ -70,6 +72,8 @@ public: const Variables& variables() const { return _variables; } const Properties& properties() const { return _properties; } + Variables& variables() { return _variables; } + Properties& properties() { return _properties; } const Path path() const { return _path; } const Symbol symbol() const { return _path.name(); } SharedPtr parent() const { return _parent; } diff --git a/src/libs/client/PortModel.hpp b/src/libs/client/PortModel.hpp index 8fa18f1c..a86c9188 100644 --- a/src/libs/client/PortModel.hpp +++ b/src/libs/client/PortModel.hpp @@ -56,16 +56,21 @@ public: inline bool operator==(const PortModel& pm) const { return (_path == pm._path); } - inline void value(const Atom& val) - { + inline void value(const Atom& val) { if (val != _current_val) { _current_val = val; signal_value_changed.emit(val); } } + inline void value(uint32_t voice, const Atom& val) { + // FIXME: implement properly + signal_voice_changed.emit(voice, val); + } + // Signals sigc::signal signal_value_changed; ///< Value ports + sigc::signal signal_voice_changed; ///< Polyphonic value ports sigc::signal signal_activity; ///< Message ports sigc::signal > signal_connection; sigc::signal > signal_disconnection; -- cgit v1.2.1