diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/EdgeView.cpp | 67 | ||||
-rw-r--r-- | src/gui/EdgeView.hpp | 45 | ||||
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 19 | ||||
-rw-r--r-- | src/gui/Makefile.am | 4 | ||||
-rw-r--r-- | src/gui/machina.glade | 2 |
5 files changed, 126 insertions, 11 deletions
diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp new file mode 100644 index 0000000..e681f26 --- /dev/null +++ b/src/gui/EdgeView.cpp @@ -0,0 +1,67 @@ +/* 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 <iomanip> +#include <sstream> +#include <flowcanvas/FlowCanvas.h> +#include <machina/Edge.hpp> +#include "EdgeView.hpp" +#include "NodeView.hpp" + +using namespace LibFlowCanvas; + +EdgeView::EdgeView(SharedPtr<FlowCanvas> canvas, + SharedPtr<NodeView> src, + SharedPtr<NodeView> dst, + SharedPtr<Machina::Edge> edge) + : LibFlowCanvas::Connection(canvas, src, dst, 0x9999AAff, true) + , _edge(edge) +{ + update_label(); +} + + +void +EdgeView::update_label() +{ + std::ostringstream label; + label << std::setw(4); + label << _edge->probability(); + set_label(label.str()); +} + + +bool +EdgeView::on_event(GdkEvent* ev) +{ + using namespace std; + + if (ev->type == GDK_BUTTON_PRESS) { + if (ev->button.button == 1) { + _edge->set_probability(_edge->probability() - 0.1); + update_label(); + return true; + } else if (ev->button.button == 3) { + _edge->set_probability(_edge->probability() + 0.1); + update_label(); + return true; + } + } + + cerr << "NO BUTTON\n"; + return false; +} diff --git a/src/gui/EdgeView.hpp b/src/gui/EdgeView.hpp new file mode 100644 index 0000000..c61d0cf --- /dev/null +++ b/src/gui/EdgeView.hpp @@ -0,0 +1,45 @@ +/* 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 + */ + +#ifndef MACHINA_EDGEVIEW_H +#define MACHINA_EDGEVIEW_H + +#include <flowcanvas/Connection.h> + +namespace Machina { class Edge; } +class NodeView; + + +class EdgeView : public LibFlowCanvas::Connection { +public: + EdgeView(SharedPtr<LibFlowCanvas::FlowCanvas> canvas, + SharedPtr<NodeView> src, + SharedPtr<NodeView> dst, + SharedPtr<Machina::Edge> edge); + + SharedPtr<Machina::Edge> edge() { return _edge; } + + void update_label(); + +private: + bool on_event(GdkEvent* ev); + + SharedPtr<Machina::Edge> _edge; +}; + + +#endif // MACHINA_EDGEVIEW_H diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index b105426..5029682 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -22,9 +22,10 @@ #include "machina/Action.hpp" #include "machina/Edge.hpp" #include "machina/LearnRequest.hpp" -#include "NodeView.hpp" -#include "MachinaCanvas.hpp" #include "MachinaGUI.hpp" +#include "MachinaCanvas.hpp" +#include "NodeView.hpp" +#include "EdgeView.hpp" using namespace LibFlowCanvas; @@ -83,7 +84,8 @@ MachinaCanvas::canvas_event(GdkEvent* event) assert(event); - if (event->type == GDK_BUTTON_RELEASE) { + if (event->type == GDK_BUTTON_RELEASE + && event->button.state & GDK_CONTROL_MASK) { const double x = event->button.x; const double y = event->button.y; @@ -116,15 +118,14 @@ void MachinaCanvas::connect_node(boost::shared_ptr<NodeView> src, boost::shared_ptr<NodeView> dst) { - boost::shared_ptr<Connection> c(new Connection(shared_from_this(), - src, dst, 0x9999AAFF, true)); + SharedPtr<Machina::Edge> edge(new Machina::Edge(src->node(), dst->node())); + src->node()->add_outgoing_edge(edge); + + boost::shared_ptr<Connection> c(new EdgeView(shared_from_this(), + src, dst, edge)); src->add_connection(c); dst->add_connection(c); - c->set_label("1.0"); add_connection(c); - - src->node()->add_outgoing_edge(SharedPtr<Machina::Edge>( - new Machina::Edge(src->node(), dst->node()))); } diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 6a9ff3b..570cc8a 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -19,6 +19,8 @@ machina_gui_SOURCES = \ MachinaCanvas.hpp \ MachinaCanvas.cpp \ NodeView.hpp \ - NodeView.cpp + NodeView.cpp \ + EdgeView.hpp \ + EdgeView.cpp endif diff --git a/src/gui/machina.glade b/src/gui/machina.glade index 06241a6..b319dab 100644 --- a/src/gui/machina.glade +++ b/src/gui/machina.glade @@ -400,7 +400,7 @@ along with Machina; if not, write to the Free Software Foundation, Inc., <property name="visible">True</property> <property name="label" translatable="yes">Interface is a bit sketchy still: -- Left click the canvas to create a new node +- Ctrl+Left click the canvas to create a new node - Middle click nodes to learn a MIDI note for that node - Right click two nodes in succession to connect nodes - Double click a node to make it an initial node |