From 6c61c79d43d1d4715ce04b46e459279d0fa6c854 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 11 Jan 2013 22:15:55 +0000 Subject: Move MIDISink from Machine state to Context parameter. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4925 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Machine.cpp | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) (limited to 'src/engine/Machine.cpp') diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index 9538be2..8a7f0b4 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -54,10 +54,9 @@ Machine::Machine(TimeUnit unit) Machine::Machine(const Machine& copy) : Stateful() // don't copy RDF ID , _active_nodes(MAX_ACTIVE_NODES, SharedPtr()) + , _time(copy.time()) , _is_activated(false) , _is_finished(false) - , _time(copy.time()) - , _sink(copy._sink) { std::map< SharedPtr, SharedPtr > replacements; @@ -84,7 +83,6 @@ Machine::operator=(const Machine& other) _is_finished = false; _time = other._time; _pending_learn = SharedPtr(); - _sink = other._sink; _nodes.clear(); map< SharedPtr, SharedPtr > replacements; @@ -106,17 +104,6 @@ Machine::operator=(const Machine& other) return *this; } -/** Set the MIDI sink to be used for executing MIDI actions. - * - * MIDI actions will silently do nothing unless this call is passed an - * existing MIDISink before running. - */ -void -Machine::set_sink(SharedPtr sink) -{ - _sink = sink; -} - /** Always returns a node, unless there are none */ SharedPtr Machine::random_node() @@ -165,16 +152,16 @@ Machine::remove_node(SharedPtr node) /** Exit all active states and reset time to 0. */ void -Machine::reset(Raul::TimeStamp time) +Machine::reset(MIDISink* sink, Raul::TimeStamp time) { if (!_is_finished) { for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) { SharedPtr node = (*n); - if (node->is_active()) - node->exit(_sink.lock(), time); + if (sink && node->is_active()) + node->exit(sink, time); - assert(! node->is_active()); + assert(!node->is_active()); } for (size_t i=0; i < MAX_ACTIVE_NODES; ++i) @@ -211,7 +198,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(Context& context, SharedPtr sink, SharedPtr node, SharedPtr updates) +Machine::enter_node(Context& context, SharedPtr node, SharedPtr updates) { assert(!node->is_active()); @@ -220,7 +207,7 @@ Machine::enter_node(Context& context, SharedPtr sink, SharedPtr size_t index = (rand() % MAX_ACTIVE_NODES); for (size_t i=0; i < MAX_ACTIVE_NODES; ++i) { if (_active_nodes.at(index) == NULL) { - node->enter(sink, _time); + node->enter(context.sink(), _time); assert(node->is_active()); _active_nodes.at(index) = node; @@ -240,9 +227,9 @@ Machine::enter_node(Context& context, SharedPtr sink, SharedPtr /** Exit an active node at the current _time. */ void -Machine::exit_node(Context& context, SharedPtr sink, SharedPtr node, SharedPtr updates) +Machine::exit_node(Context& context, SharedPtr node, SharedPtr updates) { - node->exit(sink, _time); + node->exit(context.sink(), _time); write_set(updates, node->id(), URIs::instance().machina_active, @@ -269,7 +256,7 @@ Machine::exit_node(Context& context, SharedPtr sink, SharedPtr n && rand_normal > range_min && rand_normal < range_min + (*s)->probability()) { - enter_node(context, sink, (*s)->head(), updates); + enter_node(context, (*s)->head(), updates); break; } else { @@ -288,7 +275,7 @@ Machine::exit_node(Context& context, SharedPtr sink, SharedPtr n SharedPtr head = (*e)->head(); if ( ! head->is_active()) - enter_node(context, sink, head, updates); + enter_node(context, head, updates); } } @@ -310,8 +297,6 @@ Machine::run(Context& context, SharedPtr updates) if (_is_finished) return 0; - SharedPtr sink = _sink.lock(); - 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); @@ -323,7 +308,7 @@ Machine::run(Context& context, SharedPtr updates) if ( ! _nodes.empty()) { for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) { if ((*n)->is_active()) { - (*n)->exit(sink, _time); + (*n)->exit(context.sink(), _time); write_set(updates, (*n)->id(), URIs::instance().machina_active, @@ -331,7 +316,7 @@ Machine::run(Context& context, SharedPtr updates) } if ((*n)->is_initial()) { - if (enter_node(context, sink, (*n), updates)) + if (enter_node(context, (*n), updates)) entered = true; } } @@ -358,7 +343,7 @@ Machine::run(Context& context, SharedPtr updates) } 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(context, sink, earliest, updates); + exit_node(context, earliest, updates); } else { // Earliest active state ends in the future, done this cycle -- cgit v1.2.1