From a865ddb5043c4dc094b8f64d2cae60e0df16b8ac Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 20 Feb 2007 06:13:44 +0000 Subject: New double buffer class in Raul (used for realtime-safe thread-safe writes to variables used in the realtime audio thead). Manipulation of edge labels in Machina (left click and right click). git-svn-id: http://svn.drobilla.net/lad/machina@323 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/EdgeView.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++ src/gui/EdgeView.hpp | 45 +++++++++++++++++++++++++++++++ src/gui/MachinaCanvas.cpp | 19 +++++++------- src/gui/Makefile.am | 4 ++- src/gui/machina.glade | 2 +- 5 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 src/gui/EdgeView.cpp create mode 100644 src/gui/EdgeView.hpp (limited to 'src/gui') 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 + * + * 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 +#include +#include +#include +#include "EdgeView.hpp" +#include "NodeView.hpp" + +using namespace LibFlowCanvas; + +EdgeView::EdgeView(SharedPtr canvas, + SharedPtr src, + SharedPtr dst, + SharedPtr 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 + * + * 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 + +namespace Machina { class Edge; } +class NodeView; + + +class EdgeView : public LibFlowCanvas::Connection { +public: + EdgeView(SharedPtr canvas, + SharedPtr src, + SharedPtr dst, + SharedPtr edge); + + SharedPtr edge() { return _edge; } + + void update_label(); + +private: + bool on_event(GdkEvent* ev); + + SharedPtr _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 src, boost::shared_ptr dst) { - boost::shared_ptr c(new Connection(shared_from_this(), - src, dst, 0x9999AAFF, true)); + SharedPtr edge(new Machina::Edge(src->node(), dst->node())); + src->node()->add_outgoing_edge(edge); + + boost::shared_ptr 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( - 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., True 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 -- cgit v1.2.1