From ea7bc6c83e7e9131f6bfb799f4b8e5f864bd1d4f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 11 Jan 2013 21:43:31 +0000 Subject: Move run context information to Context object and remove Machine::_forge. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4923 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Machine.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src/engine/Machine.cpp') diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index ce4d60f..24e6aaf 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -26,6 +26,7 @@ #include "machina/Machine.hpp" #include "machina/Updates.hpp" #include "machina/URIs.hpp" +#include "machina/Context.hpp" #include "Edge.hpp" #include "Node.hpp" @@ -37,9 +38,8 @@ using namespace Raul; namespace Machina { -Machine::Machine(Raul::Forge& forge, TimeUnit unit) +Machine::Machine(TimeUnit unit) : _active_nodes(MAX_ACTIVE_NODES, SharedPtr()) - , _forge(forge) , _is_activated(false) , _is_finished(false) , _time(unit, 0, 0) @@ -54,7 +54,6 @@ Machine::Machine(Raul::Forge& forge, TimeUnit unit) Machine::Machine(const Machine& copy) : Stateful() // don't copy RDF ID , _active_nodes(MAX_ACTIVE_NODES, SharedPtr()) - , _forge(copy._forge) , _is_activated(false) , _is_finished(false) , _time(copy.time()) @@ -212,7 +211,7 @@ Machine::earliest_node() const * Returns true if node was entered, or false if the maximum active nodes has been reached. */ bool -Machine::enter_node(SharedPtr sink, SharedPtr node, SharedPtr updates) +Machine::enter_node(Context& context, SharedPtr sink, SharedPtr node, SharedPtr updates) { assert(!node->is_active()); @@ -228,7 +227,7 @@ Machine::enter_node(SharedPtr sink, SharedPtr node, SharedPtrid(), URIs::instance().machina_active, - _forge.make(true)); + context.forge().make(true)); return true; } index = (index + 1) % MAX_ACTIVE_NODES; @@ -241,13 +240,13 @@ Machine::enter_node(SharedPtr sink, SharedPtr node, SharedPtr sink, SharedPtr node, SharedPtr updates) +Machine::exit_node(Context& context, SharedPtr sink, SharedPtr node, SharedPtr updates) { node->exit(sink, _time); write_set(updates, node->id(), URIs::instance().machina_active, - _forge.make(false)); + context.forge().make(false)); assert(!node->is_active()); @@ -270,7 +269,7 @@ Machine::exit_node(SharedPtr sink, SharedPtr node, SharedPtr range_min && rand_normal < range_min + (*s)->probability()) { - enter_node(sink, (*s)->head(), updates); + enter_node(context, sink, (*s)->head(), updates); break; } else { @@ -289,7 +288,7 @@ Machine::exit_node(SharedPtr sink, SharedPtr node, SharedPtr head = (*e)->head(); if ( ! head->is_active()) - enter_node(sink, head, updates); + enter_node(context, sink, head, updates); } } @@ -306,16 +305,15 @@ Machine::exit_node(SharedPtr sink, SharedPtr node, SharedPtr updates) +Machine::run(Context& context, SharedPtr updates) { if (_is_finished) return 0; - SharedPtr sink = _sink.lock(); - const TimeStamp cycle_end_frames = time.start_ticks() + time.length_ticks(); - const TimeStamp cycle_end = time.ticks_to_beats(cycle_end_frames); + const TimeStamp cycle_end_frames = context.time().start_ticks() + context.time().length_ticks(); + const TimeStamp cycle_end = context.time().ticks_to_beats(cycle_end_frames); assert(_is_activated); @@ -329,11 +327,11 @@ Machine::run(const Raul::TimeSlice& time, SharedPtr updates) write_set(updates, (*n)->id(), URIs::instance().machina_active, - _forge.make(false)); + context.forge().make(false)); } if ((*n)->is_initial()) { - if (enter_node(sink, (*n), updates)) + if (enter_node(context, sink, (*n), updates)) entered = true; } } @@ -357,10 +355,10 @@ Machine::run(const Raul::TimeSlice& time, SharedPtr updates) _is_finished = true; break; - } else if (time.beats_to_ticks(earliest->exit_time()) < cycle_end_frames) { + } else if (context.time().beats_to_ticks(earliest->exit_time()) < cycle_end_frames) { // Earliest active state ends this cycle _time = earliest->exit_time(); - exit_node(sink, earliest, updates); + exit_node(context, sink, earliest, updates); } else { // Earliest active state ends in the future, done this cycle @@ -370,7 +368,8 @@ Machine::run(const Raul::TimeSlice& time, SharedPtr updates) } - return time.beats_to_ticks(_time).ticks() - time.start_ticks().ticks(); + return context.time().beats_to_ticks(_time).ticks() + - context.time().start_ticks().ticks(); } /** Push a node onto the learn stack. -- cgit v1.2.1