From f6aea091cd1263fc5ac93333d60799fcb5791b19 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 5 Dec 2007 01:41:54 +0000 Subject: Preliminary evolutionary stuff in machina. Fix compilation against redlandmm (instead of old Raul RDF stuff). git-svn-id: http://svn.drobilla.net/lad/machina@949 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/Action.cpp | 4 ++-- src/engine/Edge.cpp | 5 +++-- src/engine/Machine.cpp | 39 +++++++++++++++++++++++++++++++++++---- src/engine/Node.cpp | 5 +++-- src/engine/machina/Loader.hpp | 4 ++-- src/engine/machina/Machine.hpp | 17 +++++++++++++---- src/engine/machina/Makefile.am | 23 ++++++++++------------- 7 files changed, 68 insertions(+), 29 deletions(-) (limited to 'src/engine') diff --git a/src/engine/Action.cpp b/src/engine/Action.cpp index 7be3687..bb7adaf 100644 --- a/src/engine/Action.cpp +++ b/src/engine/Action.cpp @@ -15,8 +15,8 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include +#include +#include #include "machina/Action.hpp" namespace Machina { diff --git a/src/engine/Edge.cpp b/src/engine/Edge.cpp index 08e45c0..511d38e 100644 --- a/src/engine/Edge.cpp +++ b/src/engine/Edge.cpp @@ -15,8 +15,9 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include +#include +#include +#include #include "machina/Node.hpp" #include "machina/Edge.hpp" diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index 7f668ef..9bb88a5 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -16,13 +16,14 @@ */ #include -#include -#include #include -#include "machina/Machine.hpp" -#include "machina/Node.hpp" +#include +#include #include "machina/Edge.hpp" +#include "machina/Gene.hpp" +#include "machina/Machine.hpp" #include "machina/MidiAction.hpp" +#include "machina/Node.hpp" using namespace std; using namespace Raul; @@ -37,10 +38,40 @@ Machine::Machine() { } + +Machine::Machine(SharedPtr genotype) + : _is_activated(false) + , _is_finished(false) + , _time(0) + , _genotype(genotype) +{ +} + Machine::~Machine() { } + + +SharedPtr +Machine::genotype() +{ + if (_genotype) + return _genotype; + + _genotype = SharedPtr(new Gene(_nodes.size())); + + size_t node_id = 0; + for (Nodes::iterator n = _nodes.begin(); n != _nodes.end(); ++n, ++node_id) { + size_t edge_id = 0; + for (Node::Edges::iterator e = (*n)->outgoing_edges().begin(); + e != (*n)->outgoing_edges().end(); ++e, ++edge_id) { + (*_genotype.get())[node_id].push_back(edge_id); + } + } + + return _genotype; +} /** Set the MIDI sink to be used for executing MIDI actions. diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp index 77c6d00..5a1ca85 100644 --- a/src/engine/Node.cpp +++ b/src/engine/Node.cpp @@ -16,8 +16,9 @@ */ #include -#include -#include +#include +#include +#include #include #include diff --git a/src/engine/machina/Loader.hpp b/src/engine/machina/Loader.hpp index 914df24..4a3c123 100644 --- a/src/engine/machina/Loader.hpp +++ b/src/engine/machina/Loader.hpp @@ -21,9 +21,9 @@ #include #include #include -#include +#include -using Raul::Namespaces; +using Redland::Namespaces; namespace Machina { diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index c63537d..76ccef1 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -21,19 +21,28 @@ #include #include #include -#include #include +#include #include "types.hpp" #include "LearnRequest.hpp" #include "Node.hpp" namespace Machina { +class Gene; + +/** A (Finite State) Machine. + * + * In evolutionary terms, this is the phenotype of Gene. + */ class Machine : public Raul::Stateful, public boost::noncopyable { public: Machine(); + Machine(SharedPtr genotype); ~Machine(); + + SharedPtr genotype(); // Main context void activate() { _is_activated = true; } @@ -74,13 +83,13 @@ private: static const size_t MAX_ACTIVE_NODES = 128; SharedPtr _active_nodes[MAX_ACTIVE_NODES]; - WeakPtr _sink; bool _is_activated; bool _is_finished; Raul::BeatTime _time; - Nodes _nodes; - + SharedPtr _genotype; SharedPtr _pending_learn; + WeakPtr _sink; + Nodes _nodes; }; diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am index 4a97f3e..e7c5a56 100644 --- a/src/engine/machina/Makefile.am +++ b/src/engine/machina/Makefile.am @@ -1,22 +1,19 @@ libmachinaincludedir = $(includedir)/machina libmachinainclude_HEADERS = \ - types.hpp \ Action.hpp \ - Node.hpp \ - Edge.hpp \ - Machine.hpp \ - Loader.hpp \ - MidiAction.hpp \ ActionFactory.hpp \ Driver.hpp \ - LearnRequest.hpp \ + Edge.hpp \ Engine.hpp \ - Recorder.hpp \ + Gene.hpp \ + JackDriver.hpp \ + LearnRequest.hpp \ + Loader.hpp \ + Machine.hpp \ MachineBuilder.hpp \ + MidiAction.hpp \ + Node.hpp \ + Recorder.hpp \ SMFDriver.hpp \ - JackDriver.hpp - -if WITH_JACK - JackDriver.hpp -endif + types.hpp -- cgit v1.2.1