/* This file is part of Machina. * Copyright 2007-2011 David 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 3 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 more details. * * You should have received a copy of the GNU General Public License * along with Machina. If not, see . */ #ifndef MACHINA_MACHINE_HPP #define MACHINA_MACHINE_HPP #include #include #include #include "machina/types.hpp" #include "raul/Atom.hpp" #include "raul/RingBuffer.hpp" #include "raul/TimeSlice.hpp" #include "sord/sordmm.hpp" #include "types.hpp" #include "Node.hpp" namespace machina { class Context; class Controller; class LearnRequest; /** A (Finite State) Machine. */ class Machine : public Stateful { public: Machine(TimeUnit unit); Machine(const Machine& copy); Machine& operator=(const Machine& other); // Kluge to appease Eugene bool operator==(const Machine& other) { return false; } // Main context void activate() { _is_activated = true; } void deactivate() { _is_activated = false; } bool is_empty() { return _nodes.empty(); } bool is_finished() { return _is_finished; } bool is_activated() { return _is_activated; } void add_node(SPtr node); void remove_node(SPtr node); void learn(SPtr maid, SPtr node); void write_state(Sord::Model& model); // Audio context void reset(MIDISink* sink, Raul::TimeStamp time); uint32_t run(Context& context, SPtr updates); // Any context inline Raul::TimeStamp time() const { return _time; } SPtr pending_learn() { return _pending_learn; } void clear_pending_learn() { _pending_learn.reset(); } typedef std::set< SPtr > Nodes; Nodes& nodes() { return _nodes; } const Nodes& nodes() const { return _nodes; } SPtr random_node(); SPtr random_edge(); private: // Audio context SPtr earliest_node() const; bool enter_node(Context& context, SPtr node, SPtr updates); void exit_node(Context& context, SPtr node, SPtr updates); static const size_t MAX_ACTIVE_NODES = 128; std::vector< SPtr > _active_nodes; SPtr _pending_learn; Nodes _nodes; Raul::TimeStamp _time; bool _is_activated; bool _is_finished; }; } // namespace machina #endif // MACHINA_MACHINE_HPP