/* 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 "raul/Atom.hpp" #include "raul/Maid.hpp" #include "raul/RingBuffer.hpp" #include "raul/SharedPtr.hpp" #include "raul/TimeSlice.hpp" #include "raul/WeakPtr.hpp" #include "sord/sordmm.hpp" #include "types.hpp" #include "Node.hpp" namespace Machina { class Controller; class LearnRequest; /** A (Finite State) Machine. */ class Machine : public Stateful { public: Machine(Raul::Forge& forge, 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(SharedPtr node); void remove_node(SharedPtr node); void learn(SharedPtr maid, SharedPtr node); void write_state(Sord::Model& model); // Audio context void reset(Raul::TimeStamp time); uint32_t run(const Raul::TimeSlice& time, SharedPtr updates); // Any context inline Raul::TimeStamp time() const { return _time; } SharedPtr pending_learn() { return _pending_learn; } void clear_pending_learn() { _pending_learn.reset(); } typedef std::list< SharedPtr > Nodes; Nodes& nodes() { return _nodes; } const Nodes& nodes() const { return _nodes; } SharedPtr random_node(); SharedPtr random_edge(); void set_sink(SharedPtr sink); private: // Audio context SharedPtr earliest_node() const; bool enter_node(SharedPtr sink, SharedPtr node, SharedPtr updates); void exit_node(SharedPtr sink, SharedPtr, SharedPtr updates); static const size_t MAX_ACTIVE_NODES = 128; std::vector< SharedPtr > _active_nodes; Raul::Forge& _forge; bool _is_activated; bool _is_finished; Raul::TimeStamp _time; SharedPtr _pending_learn; WeakPtr _sink; Nodes _nodes; }; } // namespace Machina #endif // MACHINA_MACHINE_HPP