aboutsummaryrefslogtreecommitdiffstats
path: root/src/gui/MachinaCanvas.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-02-08 03:56:42 +0000
committerDavid Robillard <d@drobilla.net>2007-02-08 03:56:42 +0000
commit4543288514e1b0a83c6ed003dfb22e175e07bfaa (patch)
treeef076ca889b88c0635d4e29df6b96148b6594336 /src/gui/MachinaCanvas.cpp
parentc803c07346142f93dd2d7929cd100764d9e43273 (diff)
downloadmachina-4543288514e1b0a83c6ed003dfb22e175e07bfaa.tar.gz
machina-4543288514e1b0a83c6ed003dfb22e175e07bfaa.tar.bz2
machina-4543288514e1b0a83c6ed003dfb22e175e07bfaa.zip
Circular nodes in FlowCanvas, related necessary redesign work and changes for API update.
Beginnings of a Machina GUI. git-svn-id: http://svn.drobilla.net/lad/machina@290 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/gui/MachinaCanvas.cpp')
-rw-r--r--src/gui/MachinaCanvas.cpp157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp
new file mode 100644
index 0000000..2309a5c
--- /dev/null
+++ b/src/gui/MachinaCanvas.cpp
@@ -0,0 +1,157 @@
+/* This file is part of Machina.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Machina is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Machina is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+//#include "config.h"
+#include <raul/SharedPtr.h>
+#include <flowcanvas/Ellipse.h>
+#include "MachinaCanvas.hpp"
+#include "MachinaGUI.hpp"
+
+MachinaCanvas::MachinaCanvas(MachinaGUI* app, int width, int height)
+: FlowCanvas(width, height),
+ _app(app)
+{
+}
+
+
+void
+MachinaCanvas::connect(boost::shared_ptr<Connectable>, //item1,
+ boost::shared_ptr<Connectable>) //item2)
+{
+#if 0
+ boost::shared_ptr<MachinaPort> p1 = boost::dynamic_pointer_cast<MachinaPort>(port1);
+ boost::shared_ptr<MachinaPort> p2 = boost::dynamic_pointer_cast<MachinaPort>(port2);
+ if (!p1 || !p2)
+ return;
+
+ if (p1->type() == JACK_AUDIO && p2->type() == JACK_AUDIO
+ || (p1->type() == JACK_MIDI && p2->type() == JACK_MIDI))
+ _app->jack_driver()->connect(p1, p2);
+#ifdef HAVE_ALSA
+ else if (p1->type() == ALSA_MIDI && p2->type() == ALSA_MIDI)
+ _app->alsa_driver()->connect(p1, p2);
+#endif
+ else
+ status_message("WARNING: Cannot make connection, incompatible port types.");
+#endif
+}
+
+
+void
+MachinaCanvas::disconnect(boost::shared_ptr<Connectable>,// item1,
+ boost::shared_ptr<Connectable>)// item2)
+{
+#if 0
+ boost::shared_ptr<MachinaPort> input
+ = boost::dynamic_pointer_cast<MachinaPort>(port1);
+ boost::shared_ptr<MachinaPort> output
+ = boost::dynamic_pointer_cast<MachinaPort>(port2);
+
+ if (!input || !output)
+ return;
+
+ if (input->is_output() && output->is_input()) {
+ // Damn, guessed wrong
+ boost::shared_ptr<MachinaPort> swap = input;
+ input = output;
+ output = swap;
+ }
+
+ if (!input || !output || input->is_output() || output->is_input()) {
+ status_message("ERROR: Attempt to disconnect mismatched/unknown ports");
+ return;
+ }
+
+ if (input->type() == JACK_AUDIO && output->type() == JACK_AUDIO
+ || input->type() == JACK_MIDI && output->type() == JACK_MIDI)
+ _app->jack_driver()->disconnect(output, input);
+#ifdef HAVE_ALSA
+ else if (input->type() == ALSA_MIDI && output->type() == ALSA_MIDI)
+ _app->alsa_driver()->disconnect(output, input);
+#endif
+ else
+ status_message("ERROR: Attempt to disconnect ports with mismatched types");
+#endif
+}
+
+
+void
+MachinaCanvas::status_message(const string& msg)
+{
+ _app->status_message(string("[Canvas] ").append(msg));
+}
+
+
+void
+MachinaCanvas::item_selected(SharedPtr<Item> i)
+{
+ SharedPtr<Connectable> item = PtrCast<Connectable>(i);
+ if (!item)
+ return;
+
+ cerr << "SELECTED: " << i->name() << endl;
+
+ SharedPtr<Connectable> last = _last_selected.lock();
+
+ if (last) {
+ boost::shared_ptr<Connection> c(new Connection(shared_from_this(),
+ last, item, 0x9999AAFF, true));
+ last->add_connection(c);
+ item->add_connection(c);
+ add_connection(c);
+ i->raise_to_top();
+ _last_selected.reset();
+ } else {
+ _last_selected = item;
+ }
+}
+
+
+bool
+MachinaCanvas::canvas_event(GdkEvent* event)
+{
+ static int last = 0;
+
+ assert(event);
+
+ if (event->type == GDK_BUTTON_PRESS) {
+
+ const double x = event->button.x;
+ const double y = event->button.y;
+
+ if (event->button.button == 1) {
+ SharedPtr<Ellipse> item(new Ellipse(shared_from_this(),
+ string("Note")+(char)(last++ +'0'), x, y, 30, 30, true));
+ item->signal_selected.connect(sigc::bind(sigc::mem_fun(this,
+ &MachinaCanvas::item_selected), item));
+ add_item(item);
+ item->raise_to_top();
+ } else if (event->button.button == 2) {
+ SharedPtr<Module> item(new Module(shared_from_this(),
+ string("Note")+(char)(last++ +'0'), x, y, true));
+ item->resize();
+ add_item(item);
+ } else if (event->button.button == 3) {
+ //_last_click_x = (int)event->button.x;
+ //_last_click_y = (int)event->button.y;
+ //show_menu(event);
+ }
+ }
+
+ return FlowCanvas::canvas_event(event);
+}
+