diff options
author | David Robillard <d@drobilla.net> | 2007-03-22 02:45:06 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-03-22 02:45:06 +0000 |
commit | 61c123747f791633bb9b61a1c528d7fbb7d7bdd7 (patch) | |
tree | 23516f30b18a0447de5e5188a30822ede389ce9e /src/engine | |
parent | b80654a5193536050c8f8e494ba5fd402b7a18aa (diff) | |
download | machina-61c123747f791633bb9b61a1c528d7fbb7d7bdd7.tar.gz machina-61c123747f791633bb9b61a1c528d7fbb7d7bdd7.tar.bz2 machina-61c123747f791633bb9b61a1c528d7fbb7d7bdd7.zip |
Serialization fixes for GUI.
Loading/Saving of MIDI actions to RDF.
git-svn-id: http://svn.drobilla.net/lad/machina@368 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/JackDriver.cpp | 2 | ||||
-rw-r--r-- | src/engine/Loader.cpp | 41 | ||||
-rw-r--r-- | src/engine/Makefile.am | 1 | ||||
-rw-r--r-- | src/engine/machina/Driver.hpp | 2 | ||||
-rw-r--r-- | src/engine/machina/JackDriver.hpp | 1 | ||||
-rw-r--r-- | src/engine/machina/Machine.hpp | 3 | ||||
-rw-r--r-- | src/engine/machina/Makefile.am | 1 |
7 files changed, 34 insertions, 17 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp index 4f08543..d389e2a 100644 --- a/src/engine/JackDriver.cpp +++ b/src/engine/JackDriver.cpp @@ -28,7 +28,6 @@ namespace Machina { JackDriver::JackDriver(SharedPtr<Machine> machine) : Driver(machine) , _machine_changed(0) - , _machine(machine) , _input_port(NULL) , _output_port(NULL) , _cycle_time(1/48000.0, 120.0) @@ -100,6 +99,7 @@ JackDriver::set_machine(SharedPtr<Machine> machine) _machine = machine; if (is_activated()) _machine_changed.wait(); + assert(_machine == machine); } diff --git a/src/engine/Loader.cpp b/src/engine/Loader.cpp index 5c5ccdb..b58d150 100644 --- a/src/engine/Loader.cpp +++ b/src/engine/Loader.cpp @@ -26,6 +26,7 @@ #include "machina/Node.hpp" #include "machina/Edge.hpp" #include "machina/Machine.hpp" +#include "machina/ActionFactory.hpp" using namespace Raul; using std::cerr; using std::cout; using std::endl; @@ -76,6 +77,8 @@ Loader::load(const Glib::ustring& uri) const Glib::ustring machine_uri = "<>"; + cout << "USER URI: " << uri << endl; + cout << "[Loader] Loading " << machine_uri << " from " << document_uri << endl; machine = SharedPtr<Machine>(new Machine()); @@ -134,24 +137,34 @@ Loader::load(const Glib::ustring& uri) } - /* Get actions */ + /* Get note actions */ query = Raul::RDFQuery(*_namespaces, Glib::ustring( - "SELECT DISTINCT ?node ?enter_action ?exit_action FROM <") + "SELECT DISTINCT ?node ?note FROM <") + document_uri + "> WHERE {\n" + - "?node :enterAction ?enter_action ;\n" - " :exitAction ?exit_action .\n" + "?node :enterAction [ a :MidiAction; :midiNote ?note ] ;\n" + " :exitAction [ a :MidiAction; :midiNote ?note ] .\n" "}\n"); results = query.run(document_uri); for (RDFQuery::Results::iterator i = results.begin(); i != results.end(); ++i) { - const Glib::ustring& node = (*i)["node"]; - const Glib::ustring& enter_action = (*i)["enter_action"]; - const Glib::ustring& exit_action = (*i)["exit_action"]; - - cout << "Node: " << node << ", Action: " << enter_action << " .. " << exit_action <<endl; - + const Glib::ustring& node_id = (*i)["node"]; + const Glib::ustring& note = (*i)["note"]; + + Created::iterator node_i = created.find(node_id); + if (node_i != created.end()) { + SharedPtr<Node> node = node_i->second; + const long note_num = strtol(note.c_str(), NULL, 10); + if (note_num >= 0 && note_num <= 127) { + node->add_enter_action(ActionFactory::note_on((unsigned char)note_num)); + node->add_exit_action(ActionFactory::note_off((unsigned char)note_num)); + } else { + cerr << "WARNING: MIDI note number out of range, ignoring." << endl; + } + } else { + cerr << "WARNING: Found note for unknown states. Ignoring." << endl; + } } @@ -190,10 +203,12 @@ Loader::load(const Glib::ustring& uri) } - if (machine) + if (machine && machine->nodes().size() > 0) { machine->reset(); - - return machine; + return machine; + } else { + return SharedPtr<Machine>(); + } } diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index 8d41dd6..c526633 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -12,6 +12,7 @@ libmachina_la_SOURCES = \ Machine.cpp \ Loader.cpp \ MidiAction.cpp \ + ActionFactory.cpp \ SMFDriver.cpp \ Engine.cpp \ LearnRequest.cpp diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp index b900da0..a1a38a2 100644 --- a/src/engine/machina/Driver.hpp +++ b/src/engine/machina/Driver.hpp @@ -39,7 +39,7 @@ public: virtual void activate() {} virtual void deactivate() {} -private: +protected: SharedPtr<Machine> _machine; }; diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp index e5d0abb..a048c0c 100644 --- a/src/engine/machina/JackDriver.hpp +++ b/src/engine/machina/JackDriver.hpp @@ -67,7 +67,6 @@ private: virtual void on_process(jack_nframes_t nframes); Raul::Semaphore _machine_changed; - SharedPtr<Machine> _machine; SharedPtr<Machine> _last_machine; jack_port_t* _input_port; diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index 12b601d..fb37f4e 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -18,6 +18,7 @@ #ifndef MACHINA_MACHINE_HPP #define MACHINA_MACHINE_HPP +#include <boost/utility.hpp> #include <raul/SharedPtr.h> #include <raul/List.h> #include <raul/RDFWriter.h> @@ -29,7 +30,7 @@ namespace Machina { -class Machine : public Raul::Stateful { +class Machine : public Raul::Stateful, public boost::noncopyable { public: Machine(); ~Machine(); diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am index ff8eab5..ce19080 100644 --- a/src/engine/machina/Makefile.am +++ b/src/engine/machina/Makefile.am @@ -8,6 +8,7 @@ libmachinainclude_HEADERS = \ Machine.hpp \ Loader.hpp \ MidiAction.hpp \ + ActionFactory.hpp \ Driver.hpp \ LearnRequest.hpp \ Engine.hpp |