aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/Mutation.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-01-12 23:38:03 +0000
committerDavid Robillard <d@drobilla.net>2013-01-12 23:38:03 +0000
commit1dad5b5aaa139993fe19e266d08dfc55844e6804 (patch)
treefd2bed5971853b429f1b74369a778a4d608e6925 /src/engine/Mutation.cpp
parent8f048287d06afd7d3c2e90f4a503d7666a9cb6fa (diff)
downloadmachina-1dad5b5aaa139993fe19e266d08dfc55844e6804.tar.gz
machina-1dad5b5aaa139993fe19e266d08dfc55844e6804.tar.bz2
machina-1dad5b5aaa139993fe19e266d08dfc55844e6804.zip
Remove Raul::SharedPtr and switch to std::shared_ptr.
Use project local short type aliases for shared_ptr and friends. Move Raul::Disposable and Raul::Manageable into Raul::Maid. Use sets to store machina nodes and edges to avoid O(n) searches. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4939 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/Mutation.cpp')
-rw-r--r--src/engine/Mutation.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/engine/Mutation.cpp b/src/engine/Mutation.cpp
index e25cdbb..fde1ba6 100644
--- a/src/engine/Mutation.cpp
+++ b/src/engine/Mutation.cpp
@@ -55,17 +55,17 @@ AddNode::mutate(Machine& machine)
//cout << "ADD NODE" << endl;
// Create random node
- SharedPtr<Node> node(new Node(machine.time().unit()));
+ SPtr<Node> node(new Node(machine.time().unit()));
node->set_selector(true);
- SharedPtr<Node> note_node = machine.random_node();
+ SPtr<Node> note_node = machine.random_node();
if (!note_node) {
return;
}
uint8_t note = rand() % 128;
- SharedPtr<MidiAction> enter_action = PtrCast<MidiAction>(
+ SPtr<MidiAction> enter_action = dynamic_ptr_cast<MidiAction>(
note_node->enter_action());
if (enter_action) {
note = enter_action->event()[1];
@@ -76,15 +76,15 @@ AddNode::mutate(Machine& machine)
machine.add_node(node);
// Insert after some node
- SharedPtr<Node> tail = machine.random_node();
+ SPtr<Node> tail = machine.random_node();
if (tail && (tail != node) /* && !node->connected_to(tail)*/) {
- tail->add_edge(boost::shared_ptr<Edge>(new Edge(tail, node)));
+ tail->add_edge(SPtr<Edge>(new Edge(tail, node)));
}
// Insert before some other node
- SharedPtr<Node> head = machine.random_node();
+ SPtr<Node> head = machine.random_node();
if (head && (head != node) /* && !head->connected_to(node)*/) {
- node->add_edge(boost::shared_ptr<Edge>(new Edge(node, head)));
+ node->add_edge(SPtr<Edge>(new Edge(node, head)));
}
}
@@ -93,7 +93,7 @@ RemoveNode::mutate(Machine& machine)
{
//cout << "REMOVE NODE" << endl;
- SharedPtr<Node> node = machine.random_node();
+ SPtr<Node> node = machine.random_node();
if (node && !node->is_initial()) {
machine.remove_node(node);
}
@@ -104,11 +104,11 @@ AdjustNode::mutate(Machine& machine)
{
//cout << "ADJUST NODE" << endl;
- SharedPtr<Node> node = machine.random_node();
+ SPtr<Node> node = machine.random_node();
if (node) {
- SharedPtr<MidiAction> enter_action = PtrCast<MidiAction>(
+ SPtr<MidiAction> enter_action = dynamic_ptr_cast<MidiAction>(
node->enter_action());
- SharedPtr<MidiAction> exit_action = PtrCast<MidiAction>(
+ SPtr<MidiAction> exit_action = dynamic_ptr_cast<MidiAction>(
node->exit_action());
if (enter_action && exit_action) {
const uint8_t note = rand() % 128;
@@ -128,16 +128,16 @@ SwapNodes::mutate(Machine& machine)
return;
}
- SharedPtr<Node> a = machine.random_node();
- SharedPtr<Node> b = machine.random_node();
+ SPtr<Node> a = machine.random_node();
+ SPtr<Node> b = machine.random_node();
while (b == a) {
b = machine.random_node();
}
- SharedPtr<MidiAction> a_enter = PtrCast<MidiAction>(a->enter_action());
- SharedPtr<MidiAction> a_exit = PtrCast<MidiAction>(a->exit_action());
- SharedPtr<MidiAction> b_enter = PtrCast<MidiAction>(b->enter_action());
- SharedPtr<MidiAction> b_exit = PtrCast<MidiAction>(b->exit_action());
+ SPtr<MidiAction> a_enter = dynamic_ptr_cast<MidiAction>(a->enter_action());
+ SPtr<MidiAction> a_exit = dynamic_ptr_cast<MidiAction>(a->exit_action());
+ SPtr<MidiAction> b_enter = dynamic_ptr_cast<MidiAction>(b->enter_action());
+ SPtr<MidiAction> b_exit = dynamic_ptr_cast<MidiAction>(b->exit_action());
uint8_t note_a = a_enter->event()[1];
uint8_t note_b = b_enter->event()[1];
@@ -153,14 +153,14 @@ AddEdge::mutate(Machine& machine)
{
//cout << "ADJUST EDGE" << endl;
- SharedPtr<Node> tail = machine.random_node();
- SharedPtr<Node> head = machine.random_node();
+ SPtr<Node> tail = machine.random_node();
+ SPtr<Node> head = machine.random_node();
if (tail && head && tail != head) {
// && !tail->connected_to(head) && !head->connected_to(tail)
- SharedPtr<Edge> edge(new Edge(tail, head));
+ SPtr<Edge> edge(new Edge(tail, head));
edge->set_probability(rand() / (float)RAND_MAX);
- tail->add_edge(boost::shared_ptr<Edge>(new Edge(tail, head)));
+ tail->add_edge(SPtr<Edge>(new Edge(tail, head)));
}
}
@@ -169,7 +169,7 @@ RemoveEdge::mutate(Machine& machine)
{
//cout << "REMOVE EDGE" << endl;
- SharedPtr<Node> tail = machine.random_node();
+ SPtr<Node> tail = machine.random_node();
if (tail && !(tail->is_initial() && tail->edges().size() == 1)) {
tail->remove_edge(tail->random_edge());
}
@@ -180,7 +180,7 @@ AdjustEdge::mutate(Machine& machine)
{
//cout << "ADJUST EDGE" << endl;
- SharedPtr<Edge> edge = machine.random_edge();
+ SPtr<Edge> edge = machine.random_edge();
if (edge) {
edge->set_probability(rand() / (float)RAND_MAX);
edge->tail().lock()->edges_changed();