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 ++++- src/gui/MachinaGUI.cpp | 42 +++++++++++++++++++++++++++++++++++++++--- src/gui/MachinaGUI.hpp | 9 +++++++-- src/gui/machina.glade | 8 ++++---- 8 files changed, 108 insertions(+), 16 deletions(-) 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; } diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index dab150f..546bf7d 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "MachinaGUI.hpp" #include "MachinaCanvas.hpp" #include "NodeView.hpp" @@ -107,7 +109,10 @@ MachinaGUI::MachinaGUI(SharedPtr machine) xml->get_widget("machina_win", _main_window); xml->get_widget("about_win", _about_window); xml->get_widget("help_dialog", _help_dialog); - xml->get_widget("file_quit_menuitem", _menu_file_quit); + xml->get_widget("open_menuitem", _menu_file_open); + xml->get_widget("save_menuitem", _menu_file_save); + xml->get_widget("save_as_menuitem", _menu_file_save_as); + xml->get_widget("quit_menuitem", _menu_file_quit); xml->get_widget("view_refresh_menuitem", _menu_view_refresh); xml->get_widget("view_messages_menuitem", _menu_view_messages); xml->get_widget("help_about_menuitem", _menu_help_about); @@ -131,14 +136,17 @@ MachinaGUI::MachinaGUI(SharedPtr machine) _zoom_full_button->signal_clicked().connect(sigc::mem_fun(_canvas.get(), &MachinaCanvas::zoom_full)); + _menu_file_open->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_file_open)); + _menu_file_save->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_file_save)); + _menu_file_save_as->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_file_save_as)); _menu_file_quit->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_file_quit)); _menu_view_refresh->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_view_refresh)); _menu_view_messages->signal_toggled().connect( sigc::mem_fun(this, &MachinaGUI::show_messages_toggled)); _menu_help_about->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_help_about)); - _menu_help_help->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_help_help)); + _menu_help_help->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_help_help)); connect_widgets(); - + //update_state(); _canvas->show(); @@ -275,6 +283,8 @@ MachinaGUI::connect_widgets() } +using namespace std; + void MachinaGUI::menu_file_quit() @@ -283,6 +293,31 @@ MachinaGUI::menu_file_quit() } +void +MachinaGUI::menu_file_open() +{ + cerr << "open\n"; + +} + + +void +MachinaGUI::menu_file_save() +{ + cerr << "save\n"; + + Raul::RDFWriter writer; + writer.start_to_filename("test.machina.ttl"); + _machine->write_state(writer); + writer.finish();} + + +void +MachinaGUI::menu_file_save_as() +{ +} + + void MachinaGUI::on_pane_position_changed() { @@ -365,3 +400,4 @@ MachinaGUI::menu_help_help() _help_dialog->run(); _help_dialog->hide(); } + diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp index 147a506..a9ae5e5 100644 --- a/src/gui/MachinaGUI.hpp +++ b/src/gui/MachinaGUI.hpp @@ -18,7 +18,6 @@ #ifndef MACHINA_GUI_H #define MACHINA_GUI_H -//#include "config.h" #include #include #include @@ -56,6 +55,9 @@ protected: void connect_widgets(); void menu_file_quit(); + void menu_file_open(); + void menu_file_save(); + void menu_file_save_as(); void show_messages_toggled(); void menu_view_refresh(); void menu_help_about(); @@ -71,7 +73,7 @@ protected: bool _update_pane_position; int _user_pane_position; - bool _refresh; + bool _refresh; boost::shared_ptr _canvas; boost::shared_ptr _machine; @@ -83,6 +85,9 @@ protected: Gtk::Window* _main_window; Gtk::Dialog* _help_dialog; Gtk::AboutDialog* _about_window; + Gtk::MenuItem* _menu_file_open; + Gtk::MenuItem* _menu_file_save; + Gtk::MenuItem* _menu_file_save_as; Gtk::MenuItem* _menu_file_quit; Gtk::MenuItem* _menu_help_about; Gtk::CheckMenuItem* _menu_view_messages; diff --git a/src/gui/machina.glade b/src/gui/machina.glade index 3216b96..06241a6 100644 --- a/src/gui/machina.glade +++ b/src/gui/machina.glade @@ -44,7 +44,7 @@ - + True gtk-open True @@ -53,7 +53,7 @@ - + True gtk-save True @@ -62,7 +62,7 @@ - + True gtk-save-as True @@ -77,7 +77,7 @@ - + True gtk-quit True -- cgit v1.2.1