From 4543288514e1b0a83c6ed003dfb22e175e07bfaa Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 8 Feb 2007 03:56:42 +0000 Subject: 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 --- src/gui/MachinaCanvas.cpp | 157 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/gui/MachinaCanvas.cpp (limited to 'src/gui/MachinaCanvas.cpp') 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 + * + * 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 +#include +#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, //item1, + boost::shared_ptr) //item2) +{ +#if 0 + boost::shared_ptr p1 = boost::dynamic_pointer_cast(port1); + boost::shared_ptr p2 = boost::dynamic_pointer_cast(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,// item1, + boost::shared_ptr)// item2) +{ +#if 0 + boost::shared_ptr input + = boost::dynamic_pointer_cast(port1); + boost::shared_ptr output + = boost::dynamic_pointer_cast(port2); + + if (!input || !output) + return; + + if (input->is_output() && output->is_input()) { + // Damn, guessed wrong + boost::shared_ptr 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 i) +{ + SharedPtr item = PtrCast(i); + if (!item) + return; + + cerr << "SELECTED: " << i->name() << endl; + + SharedPtr last = _last_selected.lock(); + + if (last) { + boost::shared_ptr 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 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 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); +} + -- cgit v1.2.1