summaryrefslogtreecommitdiffstats
path: root/src/progs/gtk/Store.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-06-11 23:33:00 +0000
committerDavid Robillard <d@drobilla.net>2006-06-11 23:33:00 +0000
commit0b1c17f08f8eab4ada52ee98ba7353ec0260d3eb (patch)
tree09af4447ba74f392d12f2153b432cb60be1c08ab /src/progs/gtk/Store.cpp
parent228279d6717e69ffd2d2a886244179635ac27c2b (diff)
downloadingen-0b1c17f08f8eab4ada52ee98ba7353ec0260d3eb.tar.gz
ingen-0b1c17f08f8eab4ada52ee98ba7353ec0260d3eb.tar.bz2
ingen-0b1c17f08f8eab4ada52ee98ba7353ec0260d3eb.zip
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
Diffstat (limited to 'src/progs/gtk/Store.cpp')
-rw-r--r--src/progs/gtk/Store.cpp156
1 files changed, 107 insertions, 49 deletions
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<ObjectModel> 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<ObjectModel>
+Store::remove_object(const string& path)
{
- if (!object)
- return;
-
- map<string, ObjectModel*>::iterator i
- = m_objects.find(object->path());
+ map<string, CountedPtr<ObjectModel> >::iterator i = m_objects.find(path);
if (i != m_objects.end()) {
- assert((*i).second == object);
+ assert((*i).second->path() == path);
+ CountedPtr<ObjectModel> 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<PluginModel>
+Store::plugin(const string& uri)
+{
+ assert(uri.length() > 0);
+ map<string, CountedPtr<PluginModel> >::iterator i = m_plugins.find(uri);
+ if (i == m_plugins.end())
+ return NULL;
+ else
+ return (*i).second;
}
CountedPtr<ObjectModel>
-Store::object(const string& path) const
+Store::object(const string& path)
{
assert(path.length() > 0);
- map<string, ObjectModel*>::const_iterator i = m_objects.find(path);
+ map<string, CountedPtr<ObjectModel> >::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<PatchModel>
-Store::patch(const string& path) const
+Store::patch(const string& path)
{
assert(path.length() > 0);
- map<string, ObjectModel*>::const_iterator i = m_objects.find(path);
+ map<string, CountedPtr<ObjectModel> >::iterator i = m_objects.find(path);
if (i == m_objects.end())
return NULL;
else
- return dynamic_cast<PatchModel*>((*i).second);
+ //return dynamic_cast<PatchModel*>((*i).second.get());
+ return (CountedPtr<PatchModel>)(*i).second; // FIXME
}
CountedPtr<NodeModel>
-Store::node(const string& path) const
+Store::node(const string& path)
{
assert(path.length() > 0);
- map<string, ObjectModel*>::const_iterator i = m_objects.find(path);
+ map<string, CountedPtr<ObjectModel> >::iterator i = m_objects.find(path);
if (i == m_objects.end())
return NULL;
else
- return dynamic_cast<NodeModel*>((*i).second);
+ return (*i).second;
}
CountedPtr<PortModel>
-Store::port(const string& path) const
+Store::port(const string& path)
{
assert(path.length() > 0);
- map<string, ObjectModel*>::const_iterator i = m_objects.find(path);
+ map<string, CountedPtr<ObjectModel> >::iterator i = m_objects.find(path);
if (i == m_objects.end()) {
return NULL;
} else {
// Normal port
- PortModel* const pc = dynamic_cast<PortModel*>((*i).second);
+ /*PortModel* const pc = dynamic_cast<PortModel*>((*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<PluginModel> 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<PluginModel> plug = plugin(plugin_uri);
+ assert(plug);
+
+ CountedPtr<NodeModel> n(new NodeModel(plug, node_path));
+ n->polyphonic(is_polyphonic);
+ // FIXME: num_ports unused
+ add_object(n);
+
+ std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(n->path().parent());
+ if (pi != m_objects.end()) {
+ PatchModel* parent = dynamic_cast<PatchModel*>((*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<PortModel> p(new PortModel(path, ptype, pdir));
+ add_object(p);
+
+ std::map<string, CountedPtr<ObjectModel> >::iterator pi = m_objects.find(p->path().parent());
+ if (pi != m_objects.end()) {
+ NodeModel* parent = dynamic_cast<NodeModel*>((*pi).second.get());
+ if (parent)
+ parent->add_port(p);
+ else
+ cerr << "ERROR: new port with no parent" << endl;
+ }
+ }
}