From 0b1c17f08f8eab4ada52ee98ba7353ec0260d3eb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 11 Jun 2006 23:33:00 +0000 Subject: New nodes in gtk client working through Store signal interface git-svn-id: http://svn.drobilla.net/lad/grauph@26 a436a847-0d15-0410-975c-d299462d15a1 --- src/progs/gtk/Store.cpp | 156 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 107 insertions(+), 49 deletions(-) (limited to 'src/progs/gtk/Store.cpp') diff --git a/src/progs/gtk/Store.cpp b/src/progs/gtk/Store.cpp index c68bdc75..8f74e3c7 100644 --- a/src/progs/gtk/Store.cpp +++ b/src/progs/gtk/Store.cpp @@ -37,7 +37,7 @@ Store::Store(SigClientInterface& emitter) void -Store::add_object(ObjectModel* object) +Store::add_object(CountedPtr object) { assert(object->path() != ""); assert(m_objects.find(object->path()) == m_objects.end()); @@ -48,32 +48,41 @@ Store::add_object(ObjectModel* object) } -void -Store::remove_object(ObjectModel* object) +CountedPtr +Store::remove_object(const string& path) { - if (!object) - return; - - map::iterator i - = m_objects.find(object->path()); + map >::iterator i = m_objects.find(path); if (i != m_objects.end()) { - assert((*i).second == object); + assert((*i).second->path() == path); + CountedPtr result = (*i).second; m_objects.erase(i); + cout << "[Store] Removed " << path << endl; + return result; } else { - cerr << "[App] Unable to find object " << object->path() - << " to remove." << endl; + cerr << "[Store] Unable to find object " << path << " to remove." << endl; + return NULL; } - - cout << "[Store] Removed " << object->path() << endl; +} + + +CountedPtr +Store::plugin(const string& uri) +{ + assert(uri.length() > 0); + map >::iterator i = m_plugins.find(uri); + if (i == m_plugins.end()) + return NULL; + else + return (*i).second; } CountedPtr -Store::object(const string& path) const +Store::object(const string& path) { assert(path.length() > 0); - map::const_iterator i = m_objects.find(path); + map >::iterator i = m_objects.find(path); if (i == m_objects.end()) return NULL; else @@ -82,41 +91,43 @@ Store::object(const string& path) const CountedPtr -Store::patch(const string& path) const +Store::patch(const string& path) { assert(path.length() > 0); - map::const_iterator i = m_objects.find(path); + map >::iterator i = m_objects.find(path); if (i == m_objects.end()) return NULL; else - return dynamic_cast((*i).second); + //return dynamic_cast((*i).second.get()); + return (CountedPtr)(*i).second; // FIXME } CountedPtr -Store::node(const string& path) const +Store::node(const string& path) { assert(path.length() > 0); - map::const_iterator i = m_objects.find(path); + map >::iterator i = m_objects.find(path); if (i == m_objects.end()) return NULL; else - return dynamic_cast((*i).second); + return (*i).second; } CountedPtr -Store::port(const string& path) const +Store::port(const string& path) { assert(path.length() > 0); - map::const_iterator i = m_objects.find(path); + map >::iterator i = m_objects.find(path); if (i == m_objects.end()) { return NULL; } else { // Normal port - PortModel* const pc = dynamic_cast((*i).second); + /*PortModel* const pc = dynamic_cast((*i).second); if (pc) - return pc; + return pc;*/ + return (*i).second; // Patch port (corresponding Node is in store) // FIXME @@ -133,14 +144,13 @@ Store::port(const string& path) const void -Store::add_plugin(const PluginModel* pm) +Store::add_plugin(CountedPtr pm) { if (m_plugins.find(pm->uri()) != m_plugins.end()) { - cerr << "DUPE! " << pm->uri() << endl; - delete m_plugins[pm->uri()]; + cerr << "DUPE PLUGIN: " << pm->uri() << endl; + } else { + m_plugins[pm->uri()] = pm; } - - m_plugins[pm->uri()] = pm; } @@ -151,7 +161,8 @@ Store::add_plugin(const PluginModel* pm) void Store::destruction_event(const string& path) { - remove_object(object(path).get()); + remove_object(path); + // FIXME: emit signals } void @@ -166,19 +177,41 @@ Store::new_plugin_event(const string& type, const string& uri, const string& nam void Store::new_patch_event(const string& path, uint32_t poly) { - PatchModel* const p = new PatchModel(path, poly); - add_object(p); + // FIXME: What to do with a conflict? + + if (m_objects.find(path) == m_objects.end()) { + PatchModel* const p = new PatchModel(path, poly); + add_object(p); + } } + void Store::new_node_event(const string& plugin_type, const string& plugin_uri, const string& node_path, bool is_polyphonic, uint32_t num_ports) { + // FIXME: What to do with a conflict? // FIXME: resolve plugin here - NodeModel* const n = new NodeModel(node_path); - n->polyphonic(is_polyphonic); - // FIXME: num_ports unused - add_object(n); + + if (m_objects.find(node_path) == m_objects.end()) { + + CountedPtr plug = plugin(plugin_uri); + assert(plug); + + CountedPtr n(new NodeModel(plug, node_path)); + n->polyphonic(is_polyphonic); + // FIXME: num_ports unused + add_object(n); + + std::map >::iterator pi = m_objects.find(n->path().parent()); + if (pi != m_objects.end()) { + PatchModel* parent = dynamic_cast((*pi).second.get()); + if (parent) + parent->add_node(n); + else + cerr << "ERROR: new node with no parent" << endl; + } + } } @@ -186,18 +219,43 @@ void Store::new_port_event(const string& path, const string& type, bool is_output) { // FIXME: this sucks - - PortModel::Type ptype = PortModel::CONTROL; - if (type == "AUDIO") ptype = PortModel::AUDIO; - else if (type == "CONTROL") ptype = PortModel::CONTROL; - else if (type== "MIDI") ptype = PortModel::MIDI; - else cerr << "[OSCListener] WARNING: Unknown port type received (" << type << ")" << endl; - - PortModel::Direction pdir = is_output ? PortModel::OUTPUT : PortModel::INPUT; - - PortModel* const p = new PortModel(path, ptype, pdir); - add_object(p); - + /* + if (m_objects.find(path) == m_objects.end()) { + PortModel::Type ptype = PortModel::CONTROL; + if (type == "AUDIO") ptype = PortModel::AUDIO; + else if (type == "CONTROL") ptype = PortModel::CONTROL; + else if (type== "MIDI") ptype = PortModel::MIDI; + else cerr << "[OSCListener] WARNING: Unknown port type received (" << type << ")" << endl; + + PortModel::Direction pdir = is_output ? PortModel::OUTPUT : PortModel::INPUT; + + PortModel* const p = new PortModel(path, ptype, pdir); + + add_object(p); + } else + */ + if (m_objects.find(path) == m_objects.end()) { + + PortModel::Type ptype = PortModel::CONTROL; + if (type == "AUDIO") ptype = PortModel::AUDIO; + else if (type == "CONTROL") ptype = PortModel::CONTROL; + else if (type== "MIDI") ptype = PortModel::MIDI; + else cerr << "[OSCListener] WARNING: Unknown port type received (" << type << ")" << endl; + + PortModel::Direction pdir = is_output ? PortModel::OUTPUT : PortModel::INPUT; + + CountedPtr p(new PortModel(path, ptype, pdir)); + add_object(p); + + std::map >::iterator pi = m_objects.find(p->path().parent()); + if (pi != m_objects.end()) { + NodeModel* parent = dynamic_cast((*pi).second.get()); + if (parent) + parent->add_port(p); + else + cerr << "ERROR: new port with no parent" << endl; + } + } } -- cgit v1.2.1