aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-02-20 06:13:44 +0000
committerDavid Robillard <d@drobilla.net>2007-02-20 06:13:44 +0000
commita865ddb5043c4dc094b8f64d2cae60e0df16b8ac (patch)
treedf65f1e1a1eff036e46f003bbcd9f8ffe26325db /src
parent1e0a7b90f35130892015a4ed6aef778a159b02ac (diff)
downloadmachina-a865ddb5043c4dc094b8f64d2cae60e0df16b8ac.tar.gz
machina-a865ddb5043c4dc094b8f64d2cae60e0df16b8ac.tar.bz2
machina-a865ddb5043c4dc094b8f64d2cae60e0df16b8ac.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/engine/machina/Edge.hpp12
-rw-r--r--src/gui/EdgeView.cpp67
-rw-r--r--src/gui/EdgeView.hpp45
-rw-r--r--src/gui/MachinaCanvas.cpp19
-rw-r--r--src/gui/Makefile.am4
-rw-r--r--src/gui/machina.glade2
6 files changed, 137 insertions, 12 deletions
diff --git a/src/engine/machina/Edge.hpp b/src/engine/machina/Edge.hpp
index f20e5db..8860abe 100644
--- a/src/engine/machina/Edge.hpp
+++ b/src/engine/machina/Edge.hpp
@@ -22,6 +22,7 @@
#include <boost/utility.hpp>
#include <raul/WeakPtr.h>
#include <raul/SharedPtr.h>
+#include <raul/DoubleBuffer.h>
#include "types.hpp"
#include "Action.hpp"
@@ -32,7 +33,11 @@ class Node;
class Edge : boost::noncopyable {
public:
- Edge(WeakPtr<Node> src, SharedPtr<Node> dst) : _src(src) , _dst(dst) {}
+ Edge(WeakPtr<Node> src, SharedPtr<Node> dst)
+ : _probability(1.0f)
+ , _src(src)
+ , _dst(dst)
+ {}
WeakPtr<Node> src() { return _src; }
SharedPtr<Node> dst() { return _dst; }
@@ -40,7 +45,12 @@ public:
void set_src(WeakPtr<Node> src) { _src = src; }
void set_dst(SharedPtr<Node> dst) { _dst = dst; }
+ inline float probability() { return _probability.get(); }
+ inline void set_probability(float p) { _probability.set(p); }
+
private:
+ Raul::DoubleBuffer<float> _probability;
+
WeakPtr<Node> _src;
SharedPtr<Node> _dst;
};
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