From a532829cb5d19aa06ad7f52693e3db24f234741e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 14 Feb 2007 03:28:12 +0000 Subject: Serialization work on Machina. git-svn-id: http://svn.drobilla.net/lad/machina@306 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/JackDriver.cpp | 14 +++++++++----- src/engine/Machine.cpp | 24 ++++++++++++++++++++++++ src/engine/Node.cpp | 17 +++++++++++++++++ src/engine/machina/Machine.hpp | 5 ++++- src/engine/machina/Node.hpp | 5 ++++- 5 files changed, 58 insertions(+), 7 deletions(-) (limited to 'src/engine') diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp index fefa4d2..6dc2153 100644 --- a/src/engine/JackDriver.cpp +++ b/src/engine/JackDriver.cpp @@ -60,11 +60,15 @@ JackDriver::attach(const std::string& client_name) void JackDriver::detach() { - jack_port_unregister(jack_client(), _input_port); - jack_port_unregister(jack_client(), _output_port); - _input_port = NULL; - _output_port = NULL; - + if (_input_port) { + jack_port_unregister(jack_client(), _input_port); + _input_port = NULL; + } + + if (_output_port) { + jack_port_unregister(jack_client(), _output_port); + _output_port = NULL; + } Raul::JackDriver::detach(); } diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp index dbb212c..142ea37 100644 --- a/src/engine/Machine.cpp +++ b/src/engine/Machine.cpp @@ -197,5 +197,29 @@ Machine::learn(SharedPtr learn) } +void +Machine::write_state(Raul::RDFWriter& writer) +{ + using Raul::RdfId; + + writer.add_prefix("machina", "http://drobilla.net/ns/machina"); + + writer.write(RdfId(RdfId::RESOURCE, ""), + RdfId(RdfId::RESOURCE, "rdf:type"), + RdfId(RdfId::RESOURCE, "machina:Machine")); + + for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) { + if ( ! (*n)->id() ) + (*n)->set_id(writer.blank_id()); + + (*n)->write_state(writer); + + writer.write(RdfId(RdfId::RESOURCE, ""), + RdfId(RdfId::RESOURCE, "machina:node"), + (*n)->id()); + } +} + + } // namespace Machina diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp index 59af04e..c0e0ce6 100644 --- a/src/engine/Node.cpp +++ b/src/engine/Node.cpp @@ -16,6 +16,7 @@ */ #include +#include #include "machina/Node.hpp" #include "machina/Edge.hpp" @@ -99,5 +100,21 @@ Node::remove_outgoing_edge(SharedPtr edge) } +void +Node::write_state(Raul::RDFWriter& writer) +{ + using Raul::RdfId; + + writer.write(_id, + RdfId(RdfId::RESOURCE, "rdf:type"), + RdfId(RdfId::RESOURCE, "machina:Node")); + + writer.write(_id, + RdfId(RdfId::RESOURCE, "machina:duration"), + Raul::Atom((int)_duration)); +} + + + } // namespace Machina diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index b53f55c..3e63530 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -20,6 +20,7 @@ #include #include +#include #include "types.hpp" #include "LearnRequest.hpp" #include "Node.hpp" @@ -27,7 +28,7 @@ namespace Machina { -class Machine { +class Machine : public Raul::Stateful { public: Machine(); ~Machine(); @@ -42,6 +43,8 @@ public: void add_node(SharedPtr node); void learn(SharedPtr learn); + void write_state(Raul::RDFWriter& writer); + // Audio context void reset(); FrameCount run(FrameCount nframes); diff --git a/src/engine/machina/Node.hpp b/src/engine/machina/Node.hpp index 243773f..10d4ed4 100644 --- a/src/engine/machina/Node.hpp +++ b/src/engine/machina/Node.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "types.hpp" #include "Action.hpp" @@ -37,7 +38,7 @@ class Edge; * Initial nodes do not have enter actions (since they are entered at * an undefined point in time <= 0). */ -class Node : public boost::noncopyable { +class Node : public Raul::Stateful, public boost::noncopyable { public: typedef std::string ID; @@ -55,6 +56,8 @@ public: void add_outgoing_edge(SharedPtr edge); void remove_outgoing_edge(SharedPtr edge); + void write_state(Raul::RDFWriter& writer); + bool is_initial() const { return _is_initial; } void set_initial(bool i) { _is_initial = i; } bool is_active() const { return _is_active; } -- cgit v1.2.1