diff options
Diffstat (limited to 'src/engine/Node.hpp')
-rw-r--r-- | src/engine/Node.hpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/engine/Node.hpp b/src/engine/Node.hpp new file mode 100644 index 0000000..13f6bb3 --- /dev/null +++ b/src/engine/Node.hpp @@ -0,0 +1,104 @@ +/* This file is part of Machina. + * Copyright (C) 2007-2009 David Robillard <http://drobilla.net> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#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> action); + void set_exit_action(SharedPtr<Action> action); + + SharedPtr<Action> enter_action() { return _enter_action; } + SharedPtr<Action> exit_action() { return _exit_action; } + + void enter(SharedPtr<Raul::MIDISink> driver, TimeStamp time); + void exit(SharedPtr<Raul::MIDISink> driver, TimeStamp time); + + void edges_changed(); + + void add_edge(SharedPtr<Edge> edge); + void remove_edge(SharedPtr<Edge> edge); + SharedPtr<Edge> remove_edge_to(SharedPtr<Node> node); + bool connected_to(SharedPtr<Node> node); + + void set(URIInt key, const Raul::Atom& value); + void write_state(Redland::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<SharedPtr<Edge> > Edges; + Edges& edges() { return _edges; } + + SharedPtr<Edge> random_edge(); + +private: + Node& operator=(const Node& other); // undefined + + TimeStamp _enter_time; ///< valid iff _is_active + TimeDuration _duration; + SharedPtr<Action> _enter_action; + SharedPtr<Action> _exit_action; + Edges _edges; + Schrodinbit _changed; + bool _is_initial; + bool _is_selector; + bool _is_active; +}; + + +} // namespace Machina + +#endif // MACHINA_NODE_HPP |