aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/Machine.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-04-05 05:50:53 +0000
committerDavid Robillard <d@drobilla.net>2007-04-05 05:50:53 +0000
commit0123cdeacc9acc7ca16fa8b0a9dee7a5d916b7df (patch)
tree582897e91977bcb42cfbd88e66af0dad1dd3bb3d /src/engine/Machine.cpp
parent74688702fa060fb6aaa413b06deceec6c78d74a6 (diff)
downloadmachina-0123cdeacc9acc7ca16fa8b0a9dee7a5d916b7df.tar.gz
machina-0123cdeacc9acc7ca16fa8b0a9dee7a5d916b7df.tar.bz2
machina-0123cdeacc9acc7ca16fa8b0a9dee7a5d916b7df.zip
Selector states.
Togglable edge and state labels. Builder fixes. GUI/input/etc fixes. git-svn-id: http://svn.drobilla.net/lad/machina@398 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/Machine.cpp')
-rw-r--r--src/engine/Machine.cpp46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp
index c61bd4f..38e6e11 100644
--- a/src/engine/Machine.cpp
+++ b/src/engine/Machine.cpp
@@ -65,6 +65,9 @@ void
Machine::remove_node(SharedPtr<Node> node)
{
_nodes.erase(_nodes.find(node));
+
+ for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
+ (*n)->remove_outgoing_edges_to(node);
}
@@ -164,21 +167,44 @@ Machine::exit_node(SharedPtr<Raul::MIDISink> sink, const SharedPtr<Node> node)
}
}
- // Activate all successors to this node
+ // Activate successors to this node
// (that aren't aready active right now)
- for (Node::Edges::const_iterator s = node->outgoing_edges().begin();
- s != node->outgoing_edges().end(); ++s) {
-
- assert((*s)->head() != node); // no loops
+
+ if (node->is_selector()) {
const double rand_normal = rand() / (double)RAND_MAX; // [0, 1]
-
- if (rand_normal <= (*s)->probability()) {
- SharedPtr<Node> head = (*s)->head();
+ double range_min = 0;
+
+ for (Node::Edges::const_iterator s = node->outgoing_edges().begin();
+ s != node->outgoing_edges().end(); ++s) {
+
+ if (!(*s)->head()->is_active()
+ && rand_normal > range_min
+ && rand_normal < range_min + (*s)->probability()) {
+
+ enter_node(sink, (*s)->head());
+ break;
+
+ } else {
+ range_min += (*s)->probability();
+ }
+ }
+
+ } else {
+
+ for (Node::Edges::const_iterator s = node->outgoing_edges().begin();
+ s != node->outgoing_edges().end(); ++s) {
- if (!head->is_active())
- enter_node(sink, head);
+ const double rand_normal = rand() / (double)RAND_MAX; // [0, 1]
+
+ if (rand_normal <= (*s)->probability()) {
+ SharedPtr<Node> head = (*s)->head();
+
+ if ( ! head->is_active())
+ enter_node(sink, head);
+ }
}
+
}
}