/* 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_NODE_HPP #define MACHINA_NODE_HPP #include "raul/List.hpp" #include "raul/MIDISink.hpp" #include "raul/SharedPtr.hpp" #include "Action.hpp" #include "Schrodinbit.hpp" #include "Stateful.hpp" namespace Machina { class Edge; using Raul::TimeDuration; using Raul::TimeStamp; using Raul::TimeUnit; /** A node is a state (as in a FSM diagram), or "note". * * It contains a action, as well as a duration and pointers to it's * successors (states/nodes that (may) follow it). * * Initial nodes do not have enter actions (since they are entered at * an undefined point in time <= 0). */ class Node : public Stateful { public: Node(TimeDuration duration, bool initial=false); Node(const Node& copy); void set_enter_action(SharedPtr action); void set_exit_action(SharedPtr action); SharedPtr enter_action() { return _enter_action; } SharedPtr exit_action() { return _exit_action; } void enter(SharedPtr driver, TimeStamp time); void exit(SharedPtr driver, TimeStamp time); void edges_changed(); void add_edge(SharedPtr edge); void remove_edge(SharedPtr edge); SharedPtr remove_edge_to(SharedPtr node); bool connected_to(SharedPtr node); void set(URIInt key, const Raul::Atom& value); void write_state(Sord::Model& model); bool is_initial() const { return _is_initial; } void set_initial(bool i) { _is_initial = i; } bool is_active() const { return _is_active; } TimeStamp enter_time() const { assert(_is_active); return _enter_time; } TimeStamp exit_time() const { assert(_is_active); return _enter_time + _duration; } TimeDuration duration() const { return _duration; } void set_duration(TimeDuration d) { _duration = d; } bool is_selector() const { return _is_selector; } void set_selector(bool i); inline bool changed() { return _changed; } inline void set_changed() { _changed = true; } typedef Raul::List > Edges; Edges& edges() { return _edges; } SharedPtr random_edge(); private: Node& operator=(const Node& other); // undefined TimeStamp _enter_time; ///< valid iff _is_active TimeDuration _duration; SharedPtr _enter_action; SharedPtr _exit_action; Edges _edges; Schrodinbit _changed; bool _is_initial; bool _is_selector; bool _is_active; }; } // namespace Machina #endif // MACHINA_NODE_HPP