diff options
author | David Robillard <d@drobilla.net> | 2006-06-17 23:47:42 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2006-06-17 23:47:42 +0000 |
commit | c6d42dbbf9f6872d4fed67aecde8f7a65effab08 (patch) | |
tree | 424f7ec643cf81b8282e6404ac56d81e4ef34021 /src/progs/gtk | |
parent | 471c9e43493ab1d3a83ed6a8ca53bd818a2ed275 (diff) | |
download | ingen-c6d42dbbf9f6872d4fed67aecde8f7a65effab08.tar.gz ingen-c6d42dbbf9f6872d4fed67aecde8f7a65effab08.tar.bz2 ingen-c6d42dbbf9f6872d4fed67aecde8f7a65effab08.zip |
New patch ports interface
git-svn-id: http://svn.drobilla.net/lad/grauph@48 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/progs/gtk')
-rw-r--r-- | src/progs/gtk/Makefile.am | 4 | ||||
-rw-r--r-- | src/progs/gtk/PatchController.cpp | 132 | ||||
-rw-r--r-- | src/progs/gtk/PatchController.h | 2 | ||||
-rw-r--r-- | src/progs/gtk/PortController.cpp | 19 | ||||
-rw-r--r-- | src/progs/gtk/PortController.h | 12 |
5 files changed, 124 insertions, 45 deletions
diff --git a/src/progs/gtk/Makefile.am b/src/progs/gtk/Makefile.am index 3bf779a8..bb42d575 100644 --- a/src/progs/gtk/Makefile.am +++ b/src/progs/gtk/Makefile.am @@ -62,12 +62,16 @@ om_gtk_SOURCES = \ ../../common/Path.h \ OmModule.h \ OmModule.cpp \ + OmPortModule.h \ + OmPortModule.cpp \ DSSIModule.h \ DSSIModule.cpp \ SubpatchModule.h \ SubpatchModule.cpp \ OmPort.h \ OmPort.cpp \ + OmPatchPort.h \ + OmPatchPort.cpp \ NewSubpatchWindow.h \ NewSubpatchWindow.cpp \ ConfigWindow.h \ diff --git a/src/progs/gtk/PatchController.cpp b/src/progs/gtk/PatchController.cpp index 1caf1e8c..d9b22e35 100644 --- a/src/progs/gtk/PatchController.cpp +++ b/src/progs/gtk/PatchController.cpp @@ -33,6 +33,7 @@ #include "PatchWindow.h" #include "NodeModel.h" #include "OmModule.h" +#include "OmPortModule.h" #include "OmPort.h" #include "ControlModel.h" #include "NodeControlWindow.h" @@ -73,6 +74,7 @@ PatchController::PatchController(CountedPtr<PatchModel> model) cerr << "[PatchController] " << path() << " ERROR: Parent not found." << endl; }*/ + //model->new_port_sig.connect(sigc::mem_fun(this, &PatchController::add_port)); model->new_node_sig.connect(sigc::mem_fun(this, &PatchController::add_node)); model->removed_node_sig.connect(sigc::mem_fun(this, &PatchController::remove_node)); model->new_connection_sig.connect(sigc::mem_fun(this, &PatchController::connection)); @@ -278,6 +280,7 @@ PatchController::create_module(OmFlowCanvas* canvas) assert(canvas != NULL); assert(m_module == NULL); + assert(!m_patch_view || canvas != m_patch_view->canvas()); m_module = new SubpatchModule(canvas, this); @@ -333,7 +336,10 @@ PatchController::create_view() NodeController* nc = ((NodeController*)nm->controller()); if (!nc) - nc = new NodeController(nm); // this should set nm->controller() + nc = create_controller_for_node(nm); + + assert(nc); + assert(nm->controller() == nc); if (nc->module() == NULL); nc->create_module(m_patch_view->canvas()); @@ -341,6 +347,19 @@ PatchController::create_view() m_patch_view->canvas()->add_module(nc->module()); } + // Create pseudo modules for ports (ports on this canvas, not on our module) + for (PortModelList::const_iterator i = patch_model()->ports().begin(); + i != patch_model()->ports().end(); ++i) { + PortController* const pc = dynamic_cast<PortController*>((*i)->controller()); + assert(pc); + if (pc->module() == NULL) + pc->create_module(m_patch_view->canvas(), 1600, 1200); + assert(pc->module() != NULL); + m_patch_view->canvas()->add_module(pc->module()); + pc->module()->resize(); + } + + // Create connections for (list<CountedPtr<ConnectionModel> >::const_iterator i = patch_model()->connections().begin(); i != patch_model()->connections().end(); ++i) { @@ -404,6 +423,30 @@ PatchController::create_connection(CountedPtr<ConnectionModel> cm) } +NodeController* +PatchController::create_controller_for_node(CountedPtr<NodeModel> node) +{ + assert(!node->controller()); + NodeController* nc = NULL; + + CountedPtr<PatchModel> patch(node); + if (patch) { + assert(patch == node); + assert(patch->parent() == m_patch_model); + nc = new PatchController(patch); + } else { + assert(node->plugin()); + if (node->plugin()->type() == PluginModel::DSSI) + nc = new DSSIController(node); + else + nc = new NodeController(node); + } + + assert(node->controller() == nc); + return nc; +} + + /** Add a child node to this patch. * * This is for plugin nodes and patches, and is responsible for creating the @@ -413,8 +456,8 @@ void PatchController::add_node(CountedPtr<NodeModel> object) { assert(object); - assert(object->path().parent() == m_patch_model->path()); assert(object->parent() == m_patch_model); + assert(patch_model()->get_node(object->name())); /*if (patch_model()->get_node(nm->name()) != NULL) { cerr << "Ignoring existing\n"; @@ -428,36 +471,10 @@ PatchController::add_node(CountedPtr<NodeModel> object) if (node) { assert(node->parent() == m_patch_model); - NodeController* nc = NULL; - - CountedPtr<PatchModel> patch(node); - if (patch) { - assert(patch == node == object); - assert(patch->parent() == m_patch_model); - nc = new PatchController(patch); - } else { - assert(node->plugin()); - if (node->plugin()->type() == PluginModel::DSSI) - nc = new DSSIController(node); - else - nc = new NodeController(node); - } - - assert(nc != NULL); + NodeController* nc = create_controller_for_node(node); + assert(nc); assert(node->controller() == nc); - // Check if this is a bridge node - FIXME: remove this - CountedPtr<PortModel> pm = patch_model()->get_port(node->path().name()); - if (pm) { - cerr << "Bridge node." << endl; - PortController* pc = ((PortController*)pm->controller()); - assert(pc != NULL); - nc->bridge_port(pc); - } - - //nc->add_to_store(); - //patch_model()->add_node(node); - if (m_patch_view != NULL) { int x, y; get_new_module_location(x, y); @@ -514,29 +531,58 @@ void PatchController::add_port(CountedPtr<PortModel> pm) { assert(pm); - assert(!pm->parent()); + assert(pm->parent() == m_patch_model); + assert(patch_model()->get_port(pm->name())); + + cerr << "ADDING PORT " << pm->name() << "TO PATCH: " << patch_model()->path() << endl; //cerr << "[PatchController] Adding port " << pm->path() << endl; - if (patch_model()->get_port(pm->name())) { - cerr << "[PatchController] Ignoring duplicate port " - << pm->path() << endl; - return; - } - - node_model()->add_port(pm); + /*if (patch_model()->get_port(pm->name())) { + cerr << "[PatchController] Ignoring duplicate port " + << pm->path() << endl; + return; + }*/ + + //node_model()->add_port(pm); + // FIXME: leak PortController* pc = new PortController(pm); // Handle bridge ports/nodes (this is uglier than it should be) - NodeController* nc = (NodeController*)Store::instance().node(pm->path())->controller(); - if (nc != NULL) - nc->bridge_port(pc); - + /*NodeController* nc = (NodeController*)Store::instance().node(pm->path())->controller(); + if (nc != NULL) + nc->bridge_port(pc); + */ + + // Create port on this patch's module (if there is one) if (m_module != NULL) { pc->create_port(m_module); m_module->resize(); + } + + // Create port's (pseudo) module on this patch's canvas (if there is one) + if (m_patch_view != NULL) { + int x, y; + get_new_module_location(x, y); + + // Set zoom to 1.0 so module isn't messed up (Death to GnomeCanvas) + float old_zoom = m_patch_view->canvas()->zoom(); + if (old_zoom != 1.0) + m_patch_view->canvas()->zoom(1.0); + + if (pc->module() == NULL) + pc->create_module(m_patch_view->canvas(), x, y); + assert(pc->module() != NULL); + m_patch_view->canvas()->add_module(pc->module()); + pc->module()->resize(); + + // Reset zoom + if (old_zoom != 1.0) { + m_patch_view->canvas()->zoom(old_zoom); + pc->module()->zoom(old_zoom); + } } - + if (m_control_window != NULL) { assert(m_control_window->control_panel() != NULL); m_control_window->control_panel()->add_port(pc); diff --git a/src/progs/gtk/PatchController.h b/src/progs/gtk/PatchController.h index eff525c8..04bc82a8 100644 --- a/src/progs/gtk/PatchController.h +++ b/src/progs/gtk/PatchController.h @@ -113,6 +113,8 @@ private: void create_connection(CountedPtr<ConnectionModel> cm); + NodeController* create_controller_for_node(CountedPtr<NodeModel> node); + PatchPropertiesWindow* m_properties_window; PatchWindow* m_window; ///< Patch Window currently showing m_patch_view diff --git a/src/progs/gtk/PortController.cpp b/src/progs/gtk/PortController.cpp index fcb93b30..cdae49f7 100644 --- a/src/progs/gtk/PortController.cpp +++ b/src/progs/gtk/PortController.cpp @@ -19,6 +19,7 @@ #include "PortModel.h" #include "ControlPanel.h" #include "OmPort.h" +#include "OmPatchPort.h" #include "Store.h" namespace OmGtk { @@ -26,6 +27,7 @@ namespace OmGtk { PortController::PortController(CountedPtr<PortModel> model) : GtkObjectController(model), + m_module(NULL), m_port(NULL), m_control_panel(NULL) { @@ -66,6 +68,23 @@ PortController::destroy() void +PortController::create_module(OmFlowCanvas* canvas, double x, double y) +{ + cerr << "Creating port module " << m_model->path() << endl; + + assert(canvas); + assert(port_model()); + m_module = new OmPortModule(canvas, this, x, y); + + // FIXME: leak + m_patch_port = new OmPatchPort(m_module, port_model()); + m_module->add_port(m_patch_port, false); + + m_module->move_to(x, y); +} + + +void PortController::metadata_update(const string& key, const string& value) { // FIXME: double lookups diff --git a/src/progs/gtk/PortController.h b/src/progs/gtk/PortController.h index ee4dc41f..34919129 100644 --- a/src/progs/gtk/PortController.h +++ b/src/progs/gtk/PortController.h @@ -20,6 +20,7 @@ #include <string> #include <gtkmm.h> #include "GtkObjectController.h" +#include "OmPortModule.h" using std::string; using namespace LibOmClient; @@ -33,8 +34,11 @@ namespace OmGtk { class Controller; class OmPort; +class OmPatchPort; class ControlPanel; class OmModule; +class OmPortModule; +class OmFlowCanvas; /** Controller for a port on a (non-patch) node. @@ -49,6 +53,8 @@ public: virtual void destroy(); + virtual void create_module(OmFlowCanvas* canvas, double x, double y); + OmPortModule* module() { return m_module; } /* virtual void add_to_store(); virtual void remove_from_store(); @@ -63,10 +69,12 @@ public: ControlPanel* control_panel() const { return m_control_panel; } void set_control_panel(ControlPanel* cp); - CountedPtr<PortModel> port_model() const { return CountedPtr<PortModel>((PortModel*)m_model.get()); } + CountedPtr<PortModel> port_model() const { return m_model; } private: - OmPort* m_port; ///< Canvas module port + OmPatchPort* m_patch_port; ///< Port on m_module + OmPortModule* m_module; ///< Port pseudo-module (for patch ports only) + OmPort* m_port; ///< Port on some other canvas module ControlPanel* m_control_panel; ///< Control panel that contains this port }; |