From f673a148c7104b3aaee4b1332a3631ac15f5f769 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 5 Dec 2007 07:31:01 +0000 Subject: Add preliminary mutation to machina (only random edge probability mutation so far). git-svn-id: http://svn.drobilla.net/lad/machina@951 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/machina/Machine.hpp | 5 +++- src/engine/machina/MachineMutation.hpp | 37 ++++++++++++++++++++++++++++ src/engine/machina/Makefile.am | 1 + src/engine/machina/Node.hpp | 24 +++++++----------- src/engine/machina/Schrodinbit.hpp | 45 ++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 src/engine/machina/MachineMutation.hpp create mode 100644 src/engine/machina/Schrodinbit.hpp (limited to 'src/engine/machina') diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index 626ef10..889dc1a 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -61,9 +61,12 @@ public: SharedPtr pending_learn() { return _pending_learn; } void clear_pending_learn() { _pending_learn.reset(); } - typedef Raul::List > Nodes; + typedef Raul::List< SharedPtr > Nodes; Nodes& nodes() { return _nodes; } + SharedPtr random_node(); + SharedPtr random_edge(); + void set_sink(SharedPtr sink); private: diff --git a/src/engine/machina/MachineMutation.hpp b/src/engine/machina/MachineMutation.hpp new file mode 100644 index 0000000..34eda30 --- /dev/null +++ b/src/engine/machina/MachineMutation.hpp @@ -0,0 +1,37 @@ +/* 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., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef MACHINA_MACHINE_MUTATION_HPP +#define MACHINA_MACHINE_MUTATION_HPP + +namespace Machina { + +class Machine; + +namespace Mutation { + +struct Mutation { virtual void mutate(Machine& machine) = 0; }; + +struct AddEdge { static void mutate(Machine& machine); }; +struct RemoveEdge { static void mutate(Machine& machine); }; +struct AdjustEdge { static void mutate(Machine& machine); }; + +} // namespace Mutation + +} // namespace Machina + +#endif // MACHINA_MACHINE_MUTATION_HPP diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am index 65ea295..de99845 100644 --- a/src/engine/machina/Makefile.am +++ b/src/engine/machina/Makefile.am @@ -11,6 +11,7 @@ libmachinainclude_HEADERS = \ Loader.hpp \ Machine.hpp \ MachineBuilder.hpp \ + MachineMutation.hpp \ MidiAction.hpp \ Node.hpp \ Recorder.hpp \ diff --git a/src/engine/machina/Node.hpp b/src/engine/machina/Node.hpp index 041f443..a916eb6 100644 --- a/src/engine/machina/Node.hpp +++ b/src/engine/machina/Node.hpp @@ -24,6 +24,7 @@ #include #include #include "Action.hpp" +#include "Schrodinbit.hpp" namespace Machina { @@ -57,7 +58,7 @@ public: void add_outgoing_edge(SharedPtr edge); void remove_outgoing_edge(SharedPtr edge); - void remove_outgoing_edges_to(SharedPtr node); + void remove_edges_to(SharedPtr node); void write_state(Redland::Model& model); @@ -71,23 +72,16 @@ public: bool is_selector() const { return _is_selector; } void set_selector(bool i); - /// Schroedinger's flag - inline bool changed() { - if (_changed) { - _changed = false; - return true; - } else { - return false; - } - } - - void set_changed() { _changed = true; } + inline bool changed() { return _changed; } + inline void set_changed() { _changed = true; } typedef Raul::List > Edges; - Edges& outgoing_edges() { return _outgoing_edges; } + Edges& edges() { return _edges; } + + SharedPtr random_edge(); private: - bool _changed; + Schrodinbit _changed; bool _is_initial; bool _is_selector; bool _is_active; @@ -95,7 +89,7 @@ private: BeatCount _duration; SharedPtr _enter_action; SharedPtr _exit_action; - Edges _outgoing_edges; + Edges _edges; }; diff --git a/src/engine/machina/Schrodinbit.hpp b/src/engine/machina/Schrodinbit.hpp new file mode 100644 index 0000000..6065cfc --- /dev/null +++ b/src/engine/machina/Schrodinbit.hpp @@ -0,0 +1,45 @@ +/* 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., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef SCHRODINBIT_HPP +#define SCHRODINBIT_HPP + + +/** A flag which becomes false when it's value is observed + */ +class Schrodinbit { +public: + Schrodinbit() : _flag(false) {} + + inline operator bool() { + const bool ret = _flag; + _flag = false; + return ret; + } + + inline bool operator=(bool flag) { + _flag = flag; + return flag; + } + +private: + bool _flag; +}; + + +#endif // SCHRODINBIT_HPP + -- cgit v1.2.1