summaryrefslogtreecommitdiffstats
path: root/src/progs/ingenuity/OmModule.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2006-09-13 06:11:25 +0000
committerDavid Robillard <d@drobilla.net>2006-09-13 06:11:25 +0000
commite5675ebfeb93175e16762d0a078bd51d15d05f63 (patch)
tree189249ed9014e4c482cfaed0d6af28ced68570ca /src/progs/ingenuity/OmModule.cpp
parent23b7568ab7a87a79c186b8ddf3d3db4f1f934b06 (diff)
downloadingen-e5675ebfeb93175e16762d0a078bd51d15d05f63.tar.gz
ingen-e5675ebfeb93175e16762d0a078bd51d15d05f63.tar.bz2
ingen-e5675ebfeb93175e16762d0a078bd51d15d05f63.zip
Heavy-duty redesign of client library and GUI (now fully signal driven with clean Model/View separation).
Smarter, centralized window creation/management (should make window unification easy (panes?)). Typed metadata system, no more fugly string conversion of floats. Supports OSC fundamental types string, int, float, blob for now (though blob isn't working over the wire yet). git-svn-id: http://svn.drobilla.net/lad/ingen@131 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/progs/ingenuity/OmModule.cpp')
-rw-r--r--src/progs/ingenuity/OmModule.cpp109
1 files changed, 84 insertions, 25 deletions
diff --git a/src/progs/ingenuity/OmModule.cpp b/src/progs/ingenuity/OmModule.cpp
index dd6f3da5..9e06d910 100644
--- a/src/progs/ingenuity/OmModule.cpp
+++ b/src/progs/ingenuity/OmModule.cpp
@@ -16,6 +16,7 @@
#include "OmModule.h"
#include <cassert>
+#include "util/Atom.h"
#include "App.h"
#include "ModelEngineInterface.h"
#include "OmFlowCanvas.h"
@@ -24,53 +25,95 @@
#include "OmPort.h"
#include "GladeFactory.h"
#include "RenameWindow.h"
-#include "PatchController.h"
#include "PatchWindow.h"
+#include "WindowFactory.h"
namespace Ingenuity {
-OmModule::OmModule(OmFlowCanvas* canvas, NodeController* node)
-: LibFlowCanvas::Module(canvas, node->node_model()->path().name(),
- node->node_model()->x(), node->node_model()->y()),
- m_node(node)
+OmModule::OmModule(OmFlowCanvas* canvas, CountedPtr<NodeModel> node)
+: LibFlowCanvas::Module(canvas, node->path().name()),
+ m_node(node),
+ m_menu(node)
{
assert(m_node);
- /*if (node_model()->polyphonic() && node_model()->parent() != NULL
- && node_model()->parent_patch()->poly() > 1) {
- border_width(2.0);
- }*/
- if (node->node_model()->polyphonic()) {
+ if (node->polyphonic()) {
border_width(2.0);
}
+
+ create_all_ports();
+
+ const Atom& x = node->get_metadata("module-x");
+ const Atom& y = node->get_metadata("module-y");
+
+ if (x.type() == Atom::FLOAT && y.type() == Atom::FLOAT) {
+ move_to(x.get_float(), y.get_float());
+ } else {
+ double x, y;
+ ((OmFlowCanvas*)m_canvas)->get_new_module_location(x, y);
+ }
+
+ node->new_port_sig.connect(sigc::mem_fun(this, &OmModule::add_port));
+ node->removed_port_sig.connect(sigc::mem_fun(this, &OmModule::remove_port));
+ node->metadata_update_sig.connect(sigc::mem_fun(this, &OmModule::metadata_update));
+}
+
+
+void
+OmModule::create_all_ports()
+{
+ for (PortModelList::const_iterator i = m_node->ports().begin();
+ i != m_node->ports().end(); ++i) {
+ add_port(*i);
+ }
+
+ resize();
+
+ // FIXME
+ //if (has_control_inputs())
+ // enable_controls_menuitem();
+}
+
+
+void
+OmModule::add_port(CountedPtr<PortModel> port)
+{
+ new OmPort(this, port);
+ resize();
+}
+
+
+void
+OmModule::remove_port(CountedPtr<PortModel> port)
+{
+ LibFlowCanvas::Port* canvas_port = get_port(port->path().name());
+ delete canvas_port;
}
void
OmModule::show_control_window()
{
- node()->show_control_window();
+ App::instance().window_factory()->present_controls(m_node);
}
void
OmModule::store_location()
{
- if (m_node->node_model()->x() == 0 || m_node->node_model()->y() == 0)
- return;
-
- char temp_buf[16];
+ const float x = static_cast<float>(property_x());
+ const float y = static_cast<float>(property_y());
- m_node->node_model()->x(property_x());
- snprintf(temp_buf, 16, "%f", m_node->node_model()->x());
- m_node->node_model()->set_metadata("module-x", temp_buf); // just in case?
- App::instance().engine()->set_metadata(m_node->node_model()->path(), "module-x", temp_buf);
+ const Atom& existing_x = m_node->get_metadata("module-x");
+ const Atom& existing_y = m_node->get_metadata("module-y");
- m_node->node_model()->y(property_y());
- snprintf(temp_buf, 16, "%f", m_node->node_model()->y());
- m_node->node_model()->set_metadata("module-y", temp_buf); // just in case?
- App::instance().engine()->set_metadata(m_node->node_model()->path(), "module-y", temp_buf);
+ if (existing_x.type() != Atom::FLOAT || existing_y.type() != Atom::FLOAT
+ || existing_x.get_float() != x || existing_y.get_float() != y) {
+ App::instance().engine()->set_metadata(m_node->path(), "module-x", Atom(x));
+ App::instance().engine()->set_metadata(m_node->path(), "module-y", Atom(y));
+ }
+
}
@@ -78,9 +121,25 @@ void
OmModule::move_to(double x, double y)
{
Module::move_to(x, y);
- m_node->node_model()->x(x);
- m_node->node_model()->y(y);
//store_location();
}
+
+void
+OmModule::on_right_click(GdkEventButton* event)
+{
+ m_menu.popup(event->button, event->time);
+}
+
+
+void
+OmModule::metadata_update(const string& key, const Atom& value)
+{
+ if (key == "module-x" && value.type() == Atom::FLOAT)
+ move_to(value.get_float(), property_y());
+ else if (key == "module-y" && value.type() == Atom::FLOAT)
+ move_to(property_x(), value.get_float());
+}
+
+
} // namespace Ingenuity