From 4ba23866bc60df1d63f9a18cb61808825e7d3303 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 23 Jan 2007 02:34:45 +0000 Subject: Renamed "MetaState" to "Machine". git-svn-id: http://svn.drobilla.net/lad/machina@268 a436a847-0d15-0410-975c-d299462d15a1 --- src/Machine.cpp | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Machine.hpp | 48 +++++++++++++++++++++ src/MetaState.cpp | 127 ------------------------------------------------------ src/MetaState.hpp | 48 --------------------- src/main.cpp | 10 ++--- 5 files changed, 180 insertions(+), 180 deletions(-) create mode 100644 src/Machine.cpp create mode 100644 src/Machine.hpp delete mode 100644 src/MetaState.cpp delete mode 100644 src/MetaState.hpp diff --git a/src/Machine.cpp b/src/Machine.cpp new file mode 100644 index 0000000..91335c7 --- /dev/null +++ b/src/Machine.cpp @@ -0,0 +1,127 @@ +/* This file is part of Machina. Copyright (C) 2007 Dave Robillard. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include "Machine.hpp" +#include "Node.hpp" +#include "Edge.hpp" + +namespace Machina { + + +Machine::Machine(size_t poly) + : _initial_node(new Node()) + , _voices(poly, NULL)//_initial_node) + , _time(0) +{ + /* reserve poly spaces in _voices, so accessing it + * with operator[] should be realtime safe. + */ +} + + +Machine::~Machine() +{ + delete _initial_node; +} + + +void +Machine::reset() +{ + for (std::vector::iterator i = _voices.begin(); + i != _voices.end(); ++i) { + *i = NULL; + } +} + + +void +Machine::process(FrameCount nframes) +{ + const FrameCount cycle_end = _time + nframes; + bool done = false; + + FrameCount latest_event = _time; + + std::cerr << "--------- " << _time << " - " << _time + nframes << std::endl; + + // FIXME: way too much iteration + + while (!done) { + + done = true; + + for (std::vector::iterator i = _voices.begin(); + i != _voices.end(); ++i) { + + Node* const n = *i; + + // Active voice which ends within this cycle, transition + if (n && n->is_active() && n->end_time() < cycle_end) { + // Guaranteed to be within this cycle + const FrameCount end_time = std::max(_time, n->end_time()); + n->exit(std::max(_time, n->end_time())); + done = false; + + // Greedily grab one of the successors with the voice already + // on this node so voices follow paths nicely + for (Node::EdgeList::const_iterator s = n->outgoing_edges().begin(); + s != n->outgoing_edges().end(); ++s) { + Node* dst = (*s)->dst(); + if (!dst->is_active()) { + dst->enter(end_time); + *i = dst; + break; + } + } + + latest_event = end_time; + } + + } + + // FIXME: use free voices to claim any 'free successors' + // (when nodes have multiple successors and one gets chosen in the + // greedy bit above) + + // If every voice is on the initial node... + bool is_reset = true; + for (std::vector::iterator i = _voices.begin(); + i != _voices.end(); ++i) + if ((*i) != NULL && (*i)->is_active()) + is_reset = false; + + // ... then start + if (is_reset) { + + std::vector::iterator n = _voices.begin(); + for (Node::EdgeList::const_iterator s = _initial_node->outgoing_edges().begin(); + s != _initial_node->outgoing_edges().end() && n != _voices.end(); + ++s, ++n) { + (*s)->dst()->enter(latest_event); + done = false; + *n = (*s)->dst(); + } + } + } + + _time += nframes; +} + + +} // namespace Machina + diff --git a/src/Machine.hpp b/src/Machine.hpp new file mode 100644 index 0000000..aefd041 --- /dev/null +++ b/src/Machine.hpp @@ -0,0 +1,48 @@ +/* This file is part of Machina. Copyright (C) 2007 Dave Robillard. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef MACHINA_MACHINE_HPP +#define MACHINA_MACHINE_HPP + +#include +#include "types.hpp" + +namespace Machina { + +class Node; + + +class Machine { +public: + Machine(size_t poly); + ~Machine(); + + Node* initial_node() { return _initial_node; } + + void reset(); + void process(FrameCount nframes); + +private: + Node* _initial_node; + std::vector _voices; + + FrameCount _time; +}; + + +} // namespace Machina + +#endif // MACHINA_MACHINE_HPP diff --git a/src/MetaState.cpp b/src/MetaState.cpp deleted file mode 100644 index 43ff4b1..0000000 --- a/src/MetaState.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* This file is part of Machina. Copyright (C) 2007 Dave Robillard. - * - * 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., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include "MetaState.hpp" -#include "Node.hpp" -#include "Edge.hpp" - -namespace Machina { - - -MetaState::MetaState(size_t poly) - : _initial_node(new Node()) - , _voices(poly, NULL)//_initial_node) - , _time(0) -{ - /* reserve poly spaces in _voices, so accessing it - * with operator[] should be realtime safe. - */ -} - - -MetaState::~MetaState() -{ - delete _initial_node; -} - - -void -MetaState::reset() -{ - for (std::vector::iterator i = _voices.begin(); - i != _voices.end(); ++i) { - *i = NULL; - } -} - - -void -MetaState::process(FrameCount nframes) -{ - const FrameCount cycle_end = _time + nframes; - bool done = false; - - FrameCount latest_event = _time; - - std::cerr << "--------- " << _time << " - " << _time + nframes << std::endl; - - // FIXME: way too much iteration - - while (!done) { - - done = true; - - for (std::vector::iterator i = _voices.begin(); - i != _voices.end(); ++i) { - - Node* const n = *i; - - // Active voice which ends within this cycle, transition - if (n && n->is_active() && n->end_time() < cycle_end) { - // Guaranteed to be within this cycle - const FrameCount end_time = std::max(_time, n->end_time()); - n->exit(std::max(_time, n->end_time())); - done = false; - - // Greedily grab one of the successors with the voice already - // on this node so voices follow paths nicely - for (Node::EdgeList::const_iterator s = n->outgoing_edges().begin(); - s != n->outgoing_edges().end(); ++s) { - Node* dst = (*s)->dst(); - if (!dst->is_active()) { - dst->enter(end_time); - *i = dst; - break; - } - } - - latest_event = end_time; - } - - } - - // FIXME: use free voices to claim any 'free successors' - // (when nodes have multiple successors and one gets chosen in the - // greedy bit above) - - // If every voice is on the initial node... - bool is_reset = true; - for (std::vector::iterator i = _voices.begin(); - i != _voices.end(); ++i) - if ((*i) != NULL && (*i)->is_active()) - is_reset = false; - - // ... then start - if (is_reset) { - - std::vector::iterator n = _voices.begin(); - for (Node::EdgeList::const_iterator s = _initial_node->outgoing_edges().begin(); - s != _initial_node->outgoing_edges().end() && n != _voices.end(); - ++s, ++n) { - (*s)->dst()->enter(latest_event); - done = false; - *n = (*s)->dst(); - } - } - } - - _time += nframes; -} - - -} // namespace Machina - diff --git a/src/MetaState.hpp b/src/MetaState.hpp deleted file mode 100644 index 08e15a7..0000000 --- a/src/MetaState.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of Machina. Copyright (C) 2007 Dave Robillard. - * - * 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., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef MACHINA_METASTATE_HPP -#define MACHINA_METASTATE_HPP - -#include -#include "types.hpp" - -namespace Machina { - -class Node; - - -class MetaState { -public: - MetaState(size_t poly); - ~MetaState(); - - Node* initial_node() { return _initial_node; } - - void reset(); - void process(FrameCount nframes); - -private: - Node* _initial_node; - std::vector _voices; - - FrameCount _time; -}; - - -} // namespace Machina - -#endif // MACHINA_METASTATE_HPP diff --git a/src/main.cpp b/src/main.cpp index bf3148e..9b4511b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ */ #include -#include "MetaState.hpp" +#include "Machine.hpp" #include "Node.hpp" #include "Action.hpp" #include "Edge.hpp" @@ -42,19 +42,19 @@ Node* create_debug_node(const string& name, FrameCount duration) int main()//int argc, char** argv) { - MetaState ms(1); + Machine m(1); Node* n1 = create_debug_node("1", 1); Node* n2 = create_debug_node("2", 10); - ms.initial_node()->add_outgoing_edge(new Edge(n1)); + m.initial_node()->add_outgoing_edge(new Edge(n1)); n1->add_outgoing_edge(new Edge(n2)); - n2->add_outgoing_edge(new Edge(ms.initial_node())); + n2->add_outgoing_edge(new Edge(m.initial_node())); Timestamp t = 0; while (t < 80) { - ms.process(10); + m.process(10); t += 10; } -- cgit v1.2.1