aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/Action.hpp9
-rw-r--r--src/engine/Controller.cpp67
-rw-r--r--src/engine/Edge.cpp6
-rw-r--r--src/engine/Engine.cpp23
-rw-r--r--src/engine/JackDriver.cpp25
-rw-r--r--src/engine/JackDriver.hpp5
-rw-r--r--src/engine/LearnRequest.cpp5
-rw-r--r--src/engine/LearnRequest.hpp3
-rw-r--r--src/engine/Loader.cpp8
-rw-r--r--src/engine/MIDISink.hpp52
-rw-r--r--src/engine/Machine.cpp40
-rw-r--r--src/engine/MachineBuilder.cpp31
-rw-r--r--src/engine/MidiAction.cpp18
-rw-r--r--src/engine/MidiAction.hpp8
-rw-r--r--src/engine/Node.cpp6
-rw-r--r--src/engine/Node.hpp11
-rw-r--r--src/engine/Problem.cpp2
-rw-r--r--src/engine/Problem.hpp4
-rw-r--r--src/engine/Quantizer.hpp4
-rw-r--r--src/engine/Recorder.cpp12
-rw-r--r--src/engine/Recorder.hpp15
-rw-r--r--src/engine/SMFDriver.cpp24
-rw-r--r--src/engine/SMFDriver.hpp12
-rw-r--r--src/engine/SMFReader.cpp57
-rw-r--r--src/engine/SMFReader.hpp4
-rw-r--r--src/engine/SMFWriter.cpp17
-rw-r--r--src/engine/SMFWriter.hpp19
-rw-r--r--src/engine/Updates.cpp109
-rw-r--r--src/engine/machina/Driver.hpp12
-rw-r--r--src/engine/machina/Engine.hpp10
-rw-r--r--src/engine/machina/Loader.hpp5
-rw-r--r--src/engine/machina/Machine.hpp15
-rw-r--r--src/engine/machina/URIs.hpp9
-rw-r--r--src/engine/quantize_test.cpp5
-rw-r--r--src/engine/smf_test.cpp2
-rw-r--r--src/engine/wscript4
36 files changed, 329 insertions, 329 deletions
diff --git a/src/engine/Action.hpp b/src/engine/Action.hpp
index 7469f7e..7e0cc4f 100644
--- a/src/engine/Action.hpp
+++ b/src/engine/Action.hpp
@@ -21,20 +21,21 @@
#include <string>
#include <iostream>
-#include "raul/MIDISink.hpp"
#include "raul/SharedPtr.hpp"
#include "raul/TimeSlice.hpp"
+#include "raul/Manageable.hpp"
#include "machina/types.hpp"
+#include "MIDISink.hpp"
#include "Stateful.hpp"
namespace Machina {
/** An Action, executed on entering or exiting of a state.
*/
-struct Action : public Raul::Deletable, public Stateful {
- virtual void execute(SharedPtr<Raul::MIDISink> sink, Raul::TimeStamp time) = 0;
+struct Action : public Raul::Manageable, public Stateful {
+ virtual void execute(SharedPtr<MIDISink> sink, Raul::TimeStamp time) = 0;
virtual void write_state(Sord::Model& model);
};
@@ -43,7 +44,7 @@ class PrintAction : public Action {
public:
PrintAction(const std::string& msg) : _msg(msg) {}
- void execute(SharedPtr<Raul::MIDISink>, Raul::TimeStamp time)
+ void execute(SharedPtr<MIDISink>, Raul::TimeStamp time)
{ std::cout << "t=" << time << ": " << _msg << std::endl; }
private:
diff --git a/src/engine/Controller.cpp b/src/engine/Controller.cpp
index 1b92e5f..7533a77 100644
--- a/src/engine/Controller.cpp
+++ b/src/engine/Controller.cpp
@@ -15,8 +15,6 @@
* along with Machina. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "raul/log.hpp"
-
#include "client/ClientModel.hpp"
#include "client/ClientObject.hpp"
#include "machina/Controller.hpp"
@@ -41,8 +39,8 @@ uint64_t
Controller::create(const Client::ClientObject& properties)
{
TimeDuration dur(_engine->machine()->time().unit(),
- properties.get(URIs::instance().machina_duration).get_float());
- SharedPtr<Machina::Node> node(new Machina::Node(dur));
+ properties.get(URIs::instance().machina_duration).get_float());
+ SharedPtr<Machina::Node> node(new Machina::Node(dur));
SharedPtr<Client::ClientObject> obj(new Client::ClientObject(properties, node->id()));
_objects.insert(node);
_client_model.new_object(obj);
@@ -53,17 +51,20 @@ Controller::create(const Client::ClientObject& properties)
void
Controller::announce(SharedPtr<Machine> machine)
{
+ Raul::Forge& forge = _engine->forge();
+
for (Machina::Machine::Nodes::const_iterator n = machine->nodes().begin();
n != machine->nodes().end(); ++n) {
-
- SharedPtr<Machina::Client::ClientObject> obj(new Machina::Client::ClientObject((*n)->id()));
- obj->set(URIs::instance().rdf_type, "machina:Node");
- obj->set(URIs::instance().machina_duration, Raul::Atom(float((*n)->duration().to_double())));
- obj->set(URIs::instance().machina_canvas_x, 0.0f);
- obj->set(URIs::instance().machina_canvas_y, 0.0f);
-
- _objects.insert(*n);
- _client_model.new_object(obj);
+ SharedPtr<Machina::Client::ClientObject> obj(new Machina::Client::ClientObject((*n)->id()));
+ obj->set(URIs::instance().rdf_type,
+ forge.make_urid(URIs::instance().machina_Node));
+ obj->set(URIs::instance().machina_duration,
+ forge.make(float((*n)->duration().to_double())));
+ obj->set(URIs::instance().machina_canvas_x, forge.make(0.0f));
+ obj->set(URIs::instance().machina_canvas_y, forge.make(0.0f));
+
+ _objects.insert(*n);
+ _client_model.new_object(obj);
}
for (Machina::Machine::Nodes::const_iterator n = machine->nodes().begin();
@@ -71,12 +72,15 @@ Controller::announce(SharedPtr<Machine> machine)
for (Machina::Node::Edges::const_iterator e = (*n)->edges().begin();
e != (*n)->edges().end(); ++e) {
_objects.insert(*e);
-
SharedPtr<Client::ClientObject> eobj(new Client::ClientObject((*e)->id()));
- eobj->set(URIs::instance().rdf_type, "machina:Edge");
- eobj->set(URIs::instance().machina_probability, (*e)->probability());
- eobj->set(URIs::instance().machina_tail_id, (int32_t)(*n)->id());
- eobj->set(URIs::instance().machina_head_id, (int32_t)(*e)->head()->id());
+ eobj->set(URIs::instance().rdf_type,
+ forge.make_urid(URIs::instance().rdf_type));
+ eobj->set(URIs::instance().machina_probability,
+ forge.make((*e)->probability()));
+ eobj->set(URIs::instance().machina_tail_id,
+ forge.make((int32_t)(*n)->id()));
+ eobj->set(URIs::instance().machina_head_id,
+ forge.make((int32_t)(*e)->head()->id()));
_client_model.new_object(eobj);
}
@@ -87,9 +91,10 @@ SharedPtr<Stateful>
Controller::find(uint64_t id)
{
SharedPtr<StatefulKey> key(new StatefulKey(id));
- Objects::iterator i = _objects.find(key);
- if (i != _objects.end())
+ Objects::iterator i = _objects.find(key);
+ if (i != _objects.end()) {
return *i;
+ }
return SharedPtr<Stateful>();
}
@@ -97,10 +102,11 @@ void
Controller::learn(SharedPtr<Raul::Maid> maid, uint64_t node_id)
{
SharedPtr<Machina::Node> node = PtrCast<Machina::Node>(find(node_id));
- if (node)
+ if (node) {
_engine->machine()->learn(maid, node);
- else
+ } else {
std::cerr << "Failed to find node " << node_id << " for learn" << std::endl;
+ }
}
void
@@ -123,11 +129,14 @@ Controller::connect(uint64_t tail_id, uint64_t head_id)
tail->add_edge(edge);
_objects.insert(edge);
+ Raul::Forge& forge = _engine->forge();
+
SharedPtr<Client::ClientObject> obj(new Client::ClientObject(/**this,*/ edge->id()));
- obj->set(URIs::instance().rdf_type, "machina:Edge");
- obj->set(URIs::instance().machina_probability, 1.0f);
- obj->set(URIs::instance().machina_tail_id, (int32_t)tail->id());
- obj->set(URIs::instance().machina_head_id, (int32_t)head->id());
+ obj->set(URIs::instance().rdf_type,
+ forge.make_urid(URIs::instance().machina_Edge));
+ obj->set(URIs::instance().machina_probability, forge.make(1.0f));
+ obj->set(URIs::instance().machina_tail_id, forge.make((int32_t)tail->id()));
+ obj->set(URIs::instance().machina_head_id, forge.make((int32_t)head->id()));
_client_model.new_object(obj);
@@ -144,7 +153,7 @@ Controller::disconnect(uint64_t tail_id, uint64_t head_id)
if (edge) {
_client_model.erase_object(edge->id());
} else {
- Raul::error << "Edge not found" << std::endl;
+ std::cerr << "Edge not found" << std::endl;
}
}
@@ -152,7 +161,7 @@ void
Controller::erase(uint64_t id)
{
SharedPtr<StatefulKey> key(new StatefulKey(id));
- Objects::iterator i = _objects.find(key);
+ Objects::iterator i = _objects.find(key);
if (i == _objects.end()) {
return;
}
@@ -174,7 +183,7 @@ Controller::process_updates()
uint64_t subject;
URIInt key;
Raul::Atom value;
- for (uint32_t i = 0; i < read_space;) {
+ for (uint32_t i = 0; i < read_space; ) {
i += read_set(_updates, &subject, &key, &value);
SharedPtr<Machina::Client::ClientObject> obj = _client_model.find(subject);
if (obj) {
diff --git a/src/engine/Edge.cpp b/src/engine/Edge.cpp
index 6b1aede..c79d1cc 100644
--- a/src/engine/Edge.cpp
+++ b/src/engine/Edge.cpp
@@ -16,7 +16,6 @@
*/
#include "raul/Atom.hpp"
-#include "raul/AtomRDF.hpp"
#include "sord/sordmm.hpp"
@@ -28,7 +27,7 @@ namespace Machina {
void
Edge::set(URIInt key, const Raul::Atom& value)
{
- std::cout << "EDGE SET " << key << " = " << value << std::endl;
+ std::cout << "EDGE SET " << key << std::endl;
}
void
@@ -60,10 +59,13 @@ Edge::write_state(Sord::Model& model)
Sord::Curie(model.world(), "machina:head"),
head->rdf_id(model.world()));
+ std::cerr << "FIXME: save atom" << std::endl;
+ /*
model.add_statement(
rdf_id,
Sord::Curie(model.world(), "machina:probability"),
AtomRDF::atom_to_node(model, Atom(_probability.get())));
+ */
}
} // namespace Machina
diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp
index a53bb81..80eead7 100644
--- a/src/engine/Engine.cpp
+++ b/src/engine/Engine.cpp
@@ -28,25 +28,30 @@
namespace Machina {
-Engine::Engine(SharedPtr<Driver> driver, Sord::World& rdf_world)
+Engine::Engine(Raul::Forge& forge,
+ SharedPtr<Driver> driver,
+ Sord::World& rdf_world)
: _driver(driver)
, _rdf_world(rdf_world)
- , _loader(_rdf_world)
+ , _loader(_forge, _rdf_world)
+ , _forge(forge)
{
}
SharedPtr<Driver>
-Engine::new_driver(const std::string& name, SharedPtr<Machine> machine)
+Engine::new_driver(Raul::Forge& forge,
+ const std::string& name,
+ SharedPtr<Machine> machine)
{
#ifdef HAVE_JACK
if (name == "jack") {
- JackDriver* driver = new JackDriver(machine);
+ JackDriver* driver = new JackDriver(forge, machine);
driver->attach("machina");
return SharedPtr<Driver>(driver);
}
#endif
if (name == "smf")
- return SharedPtr<Driver>(new SMFDriver(machine->time().unit()));
+ return SharedPtr<Driver>(new SMFDriver(forge, machine->time().unit()));
std::cerr << "Error: Unknown driver type `" << name << "'" << std::endl;
return SharedPtr<Driver>();
@@ -77,7 +82,7 @@ Engine::load_machine(const Glib::ustring& uri)
SharedPtr<Machine>
Engine::load_machine_midi(const Glib::ustring& uri, double q, Raul::TimeDuration dur)
{
- SharedPtr<SMFDriver> file_driver(new SMFDriver(dur.unit()));
+ SharedPtr<SMFDriver> file_driver(new SMFDriver(_forge, dur.unit()));
SharedPtr<Machine> machine = file_driver->learn(uri, q, dur);
SharedPtr<Machine> old_machine;
if (machine) {
@@ -95,7 +100,9 @@ void
Engine::import_machine(SharedPtr<Machine> machine)
{
machine->activate();
- _driver->machine()->nodes().append(machine->nodes());
+ _driver->machine()->nodes().insert(_driver->machine()->nodes().end(),
+ machine->nodes().begin(),
+ machine->nodes().end());
// FIXME: thread safe?
// FIXME: announce
}
@@ -104,7 +111,7 @@ void
Engine::export_midi(const Glib::ustring& filename, Raul::TimeDuration dur)
{
SharedPtr<Machine> machine = _driver->machine();
- SharedPtr<Machina::SMFDriver> file_driver(new Machina::SMFDriver(dur.unit()));
+ SharedPtr<Machina::SMFDriver> file_driver(new Machina::SMFDriver(_forge, dur.unit()));
const bool activated = _driver->is_activated();
if (activated)
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp
index 2775dcc..bcde9ef 100644
--- a/src/engine/JackDriver.cpp
+++ b/src/engine/JackDriver.cpp
@@ -27,13 +27,13 @@
#include "MidiAction.hpp"
#include "jack_compat.h"
-using namespace Raul;
+using namespace Machina;
using namespace std;
namespace Machina {
-JackDriver::JackDriver(SharedPtr<Machine> machine)
- : Driver(machine)
+JackDriver::JackDriver(Raul::Forge& forge, SharedPtr<Machine> machine)
+ : Driver(forge, machine)
, _client(NULL)
, _machine_changed(0)
, _input_port(NULL)
@@ -96,8 +96,9 @@ JackDriver::attach(const std::string& client_name)
std::cerr << "WARNING: Failed to create MIDI output port." << std::endl;
if (!_machine)
- _machine = SharedPtr<Machine>(new Machine(
- TimeUnit::frames(jack_get_sample_rate(jack_client()))));
+ _machine = SharedPtr<Machine>(
+ new Machine(_forge,
+ TimeUnit::frames(jack_get_sample_rate(jack_client()))));
_machine->activate();
}
@@ -162,7 +163,7 @@ JackDriver::set_machine(SharedPtr<Machine> machine)
}
void
-JackDriver::process_input(SharedPtr<Machine> machine, const TimeSlice& time)
+JackDriver::process_input(SharedPtr<Machine> machine, const Raul::TimeSlice& time)
{
// We only actually read Jack input at the beginning of a cycle
//assert(time.offset_ticks().is_zero());
@@ -222,13 +223,13 @@ JackDriver::process_input(SharedPtr<Machine> machine, const TimeSlice& time)
const uint64_t id = Stateful::next_id();
write_set(_updates, id,
URIs::instance().rdf_type,
- URIs::instance().machina_MidiAction_atom);
+ _forge.make_urid(URIs::instance().machina_MidiAction));
write_set(_updates, learn->node()->id(),
URIs::instance().machina_enter_action,
- Raul::Atom((int32_t)id));
+ _forge.make((int32_t)id));
write_set(_updates, id,
URIs::instance().machina_note_number,
- Raul::Atom((int32_t)ev.buffer[1]));
+ _forge.make((int32_t)ev.buffer[1]));
machine->clear_pending_learn();
}
@@ -386,7 +387,7 @@ void
JackDriver::start_record(bool step)
{
// FIXME: Choose an appropriate maximum ringbuffer size
- _recorder = SharedPtr<Recorder>(new Recorder(1024, _beats_unit, _quantization.get(), step));
+ _recorder = SharedPtr<Recorder>(new Recorder(_forge, 1024, _beats_unit, _quantization.get(), step));
_recorder->start();
_record_dur = 0;
_recording = true;
@@ -399,7 +400,9 @@ JackDriver::finish_record()
SharedPtr<Machine> machine = _recorder->finish();
_recorder.reset();
machine->activate();
- _machine->nodes().append(machine->nodes());
+ _machine->nodes().insert(_machine->nodes().end(),
+ machine->nodes().begin(),
+ machine->nodes().end());
}
int
diff --git a/src/engine/JackDriver.hpp b/src/engine/JackDriver.hpp
index f1eb80c..5e76f1a 100644
--- a/src/engine/JackDriver.hpp
+++ b/src/engine/JackDriver.hpp
@@ -47,7 +47,8 @@ class Node;
class JackDriver : public Machina::Driver,
public boost::enable_shared_from_this<JackDriver> {
public:
- JackDriver(SharedPtr<Machine> machine = SharedPtr<Machine>());
+ JackDriver(Raul::Forge& forge,
+ SharedPtr<Machine> machine = SharedPtr<Machine>());
~JackDriver();
void attach(const std::string& client_name);
@@ -67,7 +68,7 @@ public:
void stop();
- bool recording() { return _recording.get(); }
+ bool recording() { return _recording.load(); }
void start_record(bool step);
void finish_record();
diff --git a/src/engine/LearnRequest.cpp b/src/engine/LearnRequest.cpp
index 46d9399..1dd5767 100644
--- a/src/engine/LearnRequest.cpp
+++ b/src/engine/LearnRequest.cpp
@@ -15,8 +15,8 @@
* along with Machina. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "raul/Quantizer.hpp"
#include "LearnRequest.hpp"
+#include "Quantizer.hpp"
namespace Machina {
@@ -55,8 +55,7 @@ LearnRequest::finish(TimeStamp time)
_node->set_enter_action(_enter_action);
_node->set_exit_action(_exit_action);
- //TimeDuration duration = Raul::Quantizer::quantize(_quantization, time - _start_time);
-
+ //TimeDuration duration = Quantizer::quantize(_quantization, time - _start_time);
//_node->set_duration(duration);
}
diff --git a/src/engine/LearnRequest.hpp b/src/engine/LearnRequest.hpp
index 385c615..8a5f1e0 100644
--- a/src/engine/LearnRequest.hpp
+++ b/src/engine/LearnRequest.hpp
@@ -20,6 +20,7 @@
#include "raul/Maid.hpp"
#include "raul/SharedPtr.hpp"
+#include "raul/Manageable.hpp"
#include "machina/types.hpp"
@@ -33,7 +34,7 @@ class MidiAction;
/** A request to MIDI learn a certain node.
*/
-class LearnRequest : public Raul::Deletable {
+class LearnRequest : public Raul::Manageable {
public:
static SharedPtr<LearnRequest>
create(SharedPtr<Raul::Maid> maid, SharedPtr<Node> node);
diff --git a/src/engine/Loader.cpp b/src/engine/Loader.cpp
index 7cee16b..0ee4f11 100644
--- a/src/engine/Loader.cpp
+++ b/src/engine/Loader.cpp
@@ -37,8 +37,9 @@ using namespace std;
namespace Machina {
-Loader::Loader(Sord::World& rdf_world)
- : _rdf_world(rdf_world)
+Loader::Loader(Raul::Forge& forge, Sord::World& rdf_world)
+ : _forge(forge)
+ , _rdf_world(rdf_world)
{
_rdf_world.add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#");
_rdf_world.add_prefix("", "http://drobilla.net/ns/machina#");
@@ -67,7 +68,8 @@ Loader::load(const Glib::ustring& uri)
cout << "[Loader] Loading " << document_uri << endl;
- machine = SharedPtr<Machine>(new Machine(TimeUnit::beats(MACHINA_PPQN)));
+ machine = SharedPtr<Machine>(
+ new Machine(_forge, TimeUnit::beats(MACHINA_PPQN)));
typedef std::map<Sord::Node, SharedPtr<Node> > Created;
Created created;
diff --git a/src/engine/MIDISink.hpp b/src/engine/MIDISink.hpp
index 41a5114..ff4a1a7 100644
--- a/src/engine/MIDISink.hpp
+++ b/src/engine/MIDISink.hpp
@@ -1,39 +1,39 @@
-/*
- This file is part of Raul.
- Copyright 2007-2012 David Robillard <http://drobilla.net>
-
- Raul 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 3 of the License, or any later version.
-
- Raul 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 more details.
-
- You should have received a copy of the GNU General Public License
- along with Raul. If not, see <http://www.gnu.org/licenses/>.
-*/
+/* This file is part of Machina.
+ * Copyright 2007-2012 David Robillard <http://drobilla.net>
+ *
+ * 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 3 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 more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Machina. If not, see <http://www.gnu.org/licenses/>.
+ */
-#ifndef RAUL_MIDI_SINK_HPP
-#define RAUL_MIDI_SINK_HPP
+#ifndef MACHINA_MIDI_SINK_HPP
+#define MACHINA_MIDI_SINK_HPP
-#include <stdexcept>
-#include "raul/TimeStamp.hpp"
#include "raul/Deletable.hpp"
+#include "raul/TimeStamp.hpp"
-namespace Raul {
+namespace Machina {
/** Pure virtual base for anything you can write MIDI to.
* \ingroup raul
*/
-class MIDISink : public Deletable {
+class MIDISink : public Raul::Deletable {
public:
- virtual void write_event(TimeStamp time,
- size_t ev_size,
- const uint8_t* ev) = 0;
+ virtual void write_event(Raul::TimeStamp time,
+ size_t ev_size,
+ const uint8_t* ev) = 0;
};
-} // namespace Raul
+} // namespace Machina
-#endif // RAUL_MIDI_SINK_HPP
+#endif // MACHINA_MIDI_SINK_HPP
diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp
index bd3c87f..ce4d60f 100644
--- a/src/engine/Machine.cpp
+++ b/src/engine/Machine.cpp
@@ -16,6 +16,7 @@
*/
#include <cstdlib>
+#include <map>
#include "raul/Atom.hpp"
#include "raul/SharedPtr.hpp"
@@ -34,13 +35,11 @@
using namespace std;
using namespace Raul;
-static const Raul::Atom true_atom(true);
-static const Raul::Atom false_atom(false);
-
namespace Machina {
-Machine::Machine(TimeUnit unit)
+Machine::Machine(Raul::Forge& forge, TimeUnit unit)
: _active_nodes(MAX_ACTIVE_NODES, SharedPtr<Node>())
+ , _forge(forge)
, _is_activated(false)
, _is_finished(false)
, _time(unit, 0, 0)
@@ -55,12 +54,13 @@ Machine::Machine(TimeUnit unit)
Machine::Machine(const Machine& copy)
: Stateful() // don't copy RDF ID
, _active_nodes(MAX_ACTIVE_NODES, SharedPtr<Node>())
+ , _forge(copy._forge)
, _is_activated(false)
, _is_finished(false)
, _time(copy.time())
, _sink(copy._sink)
{
- map< SharedPtr<Node>, SharedPtr<Node> > replacements;
+ std::map< SharedPtr<Node>, SharedPtr<Node> > replacements;
for (Nodes::const_iterator n = copy._nodes.begin(); n != copy._nodes.end(); ++n) {
SharedPtr<Machina::Node> node(new Machina::Node(*n->get()));
@@ -110,10 +110,10 @@ Machine::operator=(const Machine& other)
/** Set the MIDI sink to be used for executing MIDI actions.
*
* MIDI actions will silently do nothing unless this call is passed an
- * existing Raul::MIDISink before running.
+ * existing MIDISink before running.
*/
void
-Machine::set_sink(SharedPtr<Raul::MIDISink> sink)
+Machine::set_sink(SharedPtr<MIDISink> sink)
{
_sink = sink;
}
@@ -150,14 +150,14 @@ Machine::random_edge()
void
Machine::add_node(SharedPtr<Node> node)
{
- assert(_nodes.find(node) == _nodes.end());
+ assert(std::find(_nodes.begin(), _nodes.end(), node) == _nodes.end());
_nodes.push_back(node);
}
void
Machine::remove_node(SharedPtr<Node> node)
{
- _nodes.erase(_nodes.find(node));
+ _nodes.erase(std::find(_nodes.begin(), _nodes.end(), node));
for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n)
(*n)->remove_edge_to(node);
@@ -212,7 +212,7 @@ Machine::earliest_node() const
* Returns true if node was entered, or false if the maximum active nodes has been reached.
*/
bool
-Machine::enter_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node, SharedPtr<UpdateBuffer> updates)
+Machine::enter_node(SharedPtr<MIDISink> sink, SharedPtr<Node> node, SharedPtr<UpdateBuffer> updates)
{
assert(!node->is_active());
@@ -225,7 +225,10 @@ Machine::enter_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node, Shared
assert(node->is_active());
_active_nodes.at(index) = node;
- write_set(updates, node->id(), URIs::instance().machina_active, true_atom);
+ write_set(updates,
+ node->id(),
+ URIs::instance().machina_active,
+ _forge.make(true));
return true;
}
index = (index + 1) % MAX_ACTIVE_NODES;
@@ -238,10 +241,13 @@ Machine::enter_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node, Shared
/** Exit an active node at the current _time.
*/
void
-Machine::exit_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node, SharedPtr<UpdateBuffer> updates)
+Machine::exit_node(SharedPtr<MIDISink> sink, SharedPtr<Node> node, SharedPtr<UpdateBuffer> updates)
{
node->exit(sink, _time);
- write_set(updates, node->id(), URIs::instance().machina_active, false_atom);
+ write_set(updates,
+ node->id(),
+ URIs::instance().machina_active,
+ _forge.make(false));
assert(!node->is_active());
@@ -305,7 +311,8 @@ Machine::run(const Raul::TimeSlice& time, SharedPtr<UpdateBuffer> updates)
if (_is_finished)
return 0;
- SharedPtr<Raul::MIDISink> sink = _sink.lock();
+
+ SharedPtr<MIDISink> sink = _sink.lock();
const TimeStamp cycle_end_frames = time.start_ticks() + time.length_ticks();
const TimeStamp cycle_end = time.ticks_to_beats(cycle_end_frames);
@@ -319,7 +326,10 @@ Machine::run(const Raul::TimeSlice& time, SharedPtr<UpdateBuffer> updates)
for (Nodes::const_iterator n = _nodes.begin(); n != _nodes.end(); ++n) {
if ((*n)->is_active()) {
(*n)->exit(sink, _time);
- write_set(updates, (*n)->id(), URIs::instance().machina_active, false_atom);
+ write_set(updates,
+ (*n)->id(),
+ URIs::instance().machina_active,
+ _forge.make(false));
}
if ((*n)->is_initial()) {
diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp
index 7157b8f..4f4d599 100644
--- a/src/engine/MachineBuilder.cpp
+++ b/src/engine/MachineBuilder.cpp
@@ -17,16 +17,17 @@
#include <algorithm>
-#include "raul/midi_events.h"
+#include "lv2/lv2plug.in/ns/ext/midi/midi.h"
+
#include "raul/SharedPtr.hpp"
-#include "raul/Quantizer.hpp"
#include "machina/Machine.hpp"
#include "Edge.hpp"
-#include "Node.hpp"
#include "MachineBuilder.hpp"
#include "MidiAction.hpp"
+#include "Node.hpp"
+#include "Quantizer.hpp"
using namespace std;
using namespace Raul;
@@ -121,7 +122,7 @@ MachineBuilder::event(Raul::TimeStamp time_offset,
if (ev_size == 0)
return;
- if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
+ if ((buf[0] & 0xF0) == LV2_MIDI_MSG_NOTE_ON) {
SharedPtr<Node> node(new Node(TimeStamp(unit)));
node->set_enter_action(SharedPtr<Action>(new MidiAction(ev_size, buf)));
@@ -156,10 +157,10 @@ MachineBuilder::event(Raul::TimeStamp time_offset,
_connect_node_end_time = t;
}
- node->enter(SharedPtr<Raul::MIDISink>(), t);
+ node->enter(SharedPtr<MIDISink>(), t);
_active_nodes.push_back(node);
- } else if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_OFF) {
+ } else if ((buf[0] & 0xF0) == LV2_MIDI_MSG_NOTE_OFF) {
for (ActiveList::iterator i = _active_nodes.begin(); i != _active_nodes.end(); ++i) {
SharedPtr<MidiAction> action = PtrCast<MidiAction>((*i)->enter_action());
@@ -169,7 +170,7 @@ MachineBuilder::event(Raul::TimeStamp time_offset,
const size_t ev_size = action->event_size();
const unsigned char* ev = action->event();
- if (ev_size == 3 && (ev[0] & 0xF0) == MIDI_CMD_NOTE_ON
+ if (ev_size == 3 && (ev[0] & 0xF0) == LV2_MIDI_MSG_NOTE_ON
&& (ev[0] & 0x0F) == (buf[0] & 0x0F) // same channel
&& ev[1] == buf[1]) // same note
{
@@ -217,7 +218,8 @@ MachineBuilder::event(Raul::TimeStamp time_offset,
resolved->set_exit_action(SharedPtr<Action>());
set_node_duration(_connect_node, resolved->duration());
resolved = _connect_node;
- if (_machine->nodes().find(_connect_node) == _machine->nodes().end())
+ if (std::find(_machine->nodes().begin(), _machine->nodes().end(), _connect_node)
+ == _machine->nodes().end())
_machine->add_node(_connect_node);
} else {
@@ -234,7 +236,7 @@ MachineBuilder::event(Raul::TimeStamp time_offset,
}
if (resolved->is_active())
- resolved->exit(SharedPtr<Raul::MIDISink>(), t);
+ resolved->exit(SharedPtr<MIDISink>(), t);
_active_nodes.erase(i);
@@ -254,18 +256,18 @@ MachineBuilder::resolve()
// Resolve stuck notes
if ( ! _active_nodes.empty()) {
for (list<SharedPtr<Node> >::iterator i = _active_nodes.begin(); i != _active_nodes.end(); ++i) {
- cerr << "WARNING: Resolving stuck note." << endl;
+ cerr << "WARNING: Resolving stuck note." << endl;
SharedPtr<MidiAction> action = PtrCast<MidiAction>((*i)->enter_action());
if (!action)
continue;
const size_t ev_size = action->event_size();
const unsigned char* ev = action->event();
- if (ev_size == 3 && (ev[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
- unsigned char note_off[3] = { ((MIDI_CMD_NOTE_OFF & 0xF0) | (ev[0] & 0x0F)), ev[1], 0x40 };
+ if (ev_size == 3 && (ev[0] & 0xF0) == LV2_MIDI_MSG_NOTE_ON) {
+ unsigned char note_off[3] = { ((LV2_MIDI_MSG_NOTE_OFF & 0xF0) | (ev[0] & 0x0F)), ev[1], 0x40 };
(*i)->set_exit_action(SharedPtr<Action>(new MidiAction(3, note_off)));
set_node_duration((*i), _time - (*i)->enter_time());
- (*i)->exit(SharedPtr<Raul::MIDISink>(), _time);
+ (*i)->exit(SharedPtr<MIDISink>(), _time);
_machine->add_node((*i));
}
}
@@ -274,7 +276,8 @@ MachineBuilder::resolve()
// Add initial note if necessary
if (_machine->nodes().size() > 0
- && _machine->nodes().find(_initial_node) == _machine->nodes().end())
+ && (std::find(_machine->nodes().begin(), _machine->nodes().end(), _initial_node)
+ == _machine->nodes().end()))
_machine->add_node(_initial_node);
}
diff --git a/src/engine/MidiAction.cpp b/src/engine/MidiAction.cpp
index cc0b123..d7433b3 100644
--- a/src/engine/MidiAction.cpp
+++ b/src/engine/MidiAction.cpp
@@ -18,12 +18,11 @@
#include <iostream>
#include "raul/SharedPtr.hpp"
-#include "raul/MIDISink.hpp"
#include "raul/Atom.hpp"
-#include "raul/AtomRDF.hpp"
#include "machina/types.hpp"
+#include "MIDISink.hpp"
#include "MidiAction.hpp"
namespace Machina {
@@ -47,7 +46,7 @@ MidiAction::MidiAction(size_t size,
MidiAction::~MidiAction()
{
- delete[] _event.get();
+ delete[] _event.load();
}
/** Set the MIDI event to be emitted when the action executes.
@@ -60,7 +59,7 @@ MidiAction::~MidiAction()
bool
MidiAction::set_event(size_t size, const byte* new_event)
{
- byte* const event = _event.get();
+ byte* const event = _event.load();
if (size <= _max_size) {
_event = NULL;
if (size > 0 && new_event)
@@ -78,9 +77,9 @@ MidiAction::set_event(size_t size, const byte* new_event)
* Safe to call concurrently with set_event.
*/
void
-MidiAction::execute(SharedPtr<Raul::MIDISink> sink, Raul::TimeStamp time)
+MidiAction::execute(SharedPtr<MIDISink> sink, Raul::TimeStamp time)
{
- const byte* const event = _event.get();
+ const byte* const event = _event.load();
if (event) {
if (sink)
@@ -98,13 +97,16 @@ MidiAction::write_state(Sord::Model& model)
Action::write_state(model);
model.add_statement(rdf_id(model.world()),
- Sord::Curie(model.world(), "rdf:type"),
- Sord::Curie(model.world(), "machina:MidiAction"));
+ Sord::Curie(model.world(), "rdf:type"),
+ Sord::Curie(model.world(), "machina:MidiAction"));
// FIXME: Assumes note on/note off
+ std::cerr << "FIXME: AtomRDF" << std::endl;
+ /*
model.add_statement(rdf_id(model.world()),
Sord::Curie(model.world(), "machina:midiNote"),
AtomRDF::atom_to_node(model, Atom((int)(_event.get()[1]))));
+ */
}
} // namespace Machina
diff --git a/src/engine/MidiAction.hpp b/src/engine/MidiAction.hpp
index 729ac59..7c43584 100644
--- a/src/engine/MidiAction.hpp
+++ b/src/engine/MidiAction.hpp
@@ -26,10 +26,10 @@
#include "Action.hpp"
-namespace Raul { class MIDISink; }
-
namespace Machina {
+class MIDISink;
+
class MidiAction : public Action {
public:
~MidiAction();
@@ -38,11 +38,11 @@ public:
const unsigned char* event);
size_t event_size() { return _size; }
- byte* event() { return _event.get(); }
+ byte* event() { return _event.load(); }
bool set_event(size_t size, const byte* event);
- void execute(SharedPtr<Raul::MIDISink> driver, Raul::TimeStamp time);
+ void execute(SharedPtr<MIDISink> driver, Raul::TimeStamp time);
virtual void write_state(Sord::Model& model);
diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp
index 11d941a..6860452 100644
--- a/src/engine/Node.cpp
+++ b/src/engine/Node.cpp
@@ -19,7 +19,6 @@
#include <iostream>
#include "raul/Atom.hpp"
-#include "raul/AtomRDF.hpp"
#include "sord/sordmm.hpp"
@@ -164,7 +163,7 @@ Node::add_edge(SharedPtr<Edge> edge)
void
Node::remove_edge(SharedPtr<Edge> edge)
{
- _edges.erase(_edges.find(edge));
+ _edges.erase(std::find(_edges.begin(), _edges.end(), edge));
edges_changed();
}
@@ -221,10 +220,13 @@ Node::write_state(Sord::Model& model)
Sord::Curie(model.world(), "rdf:type"),
Sord::Curie(model.world(), "machina:Node"));
+ std::cerr << "ATOMRDF" << std::endl;
+ /*
model.add_statement(
rdf_id,
Sord::Curie(model.world(), "machina:duration"),
AtomRDF::atom_to_node(model, Atom((float)_duration.to_double())));
+ */
if (_enter_action) {
_enter_action->write_state(model);
diff --git a/src/engine/Node.hpp b/src/engine/Node.hpp
index 8290a99..b0ede31 100644
--- a/src/engine/Node.hpp
+++ b/src/engine/Node.hpp
@@ -18,13 +18,14 @@
#ifndef MACHINA_NODE_HPP
#define MACHINA_NODE_HPP
-#include "raul/List.hpp"
-#include "raul/MIDISink.hpp"
+#include <list>
+
#include "raul/SharedPtr.hpp"
#include "Action.hpp"
#include "Schrodinbit.hpp"
#include "Stateful.hpp"
+#include "MIDISink.hpp"
namespace Machina {
@@ -52,8 +53,8 @@ public:
SharedPtr<Action> enter_action() { return _enter_action; }
SharedPtr<Action> exit_action() { return _exit_action; }
- void enter(SharedPtr<Raul::MIDISink> driver, TimeStamp time);
- void exit(SharedPtr<Raul::MIDISink> driver, TimeStamp time);
+ void enter(SharedPtr<MIDISink> driver, TimeStamp time);
+ void exit(SharedPtr<MIDISink> driver, TimeStamp time);
void edges_changed();
@@ -78,7 +79,7 @@ public:
inline bool changed() { return _changed; }
inline void set_changed() { _changed = true; }
- typedef Raul::List<SharedPtr<Edge> > Edges;
+ typedef std::list< SharedPtr<Edge> > Edges;
Edges& edges() { return _edges; }
SharedPtr<Edge> random_edge();
diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp
index 9e62016..7607829 100644
--- a/src/engine/Problem.cpp
+++ b/src/engine/Problem.cpp
@@ -43,7 +43,7 @@ Problem::Problem(TimeUnit unit, const std::string& target_midi, SharedPtr<Machin
, _target(*this)
, _seed(new Machine(*seed.get()))
{
- Raul::SMFReader smf;
+ SMFReader smf;
const bool opened = smf.open(target_midi);
assert(opened);
diff --git a/src/engine/Problem.hpp b/src/engine/Problem.hpp
index fc970af..a5fe853 100644
--- a/src/engine/Problem.hpp
+++ b/src/engine/Problem.hpp
@@ -19,10 +19,12 @@
#define MACHINA_PROBLEM_HPP
#include <map>
-#include "raul/MIDISink.hpp"
+
#include "machina/Machine.hpp"
#include "eugene/Problem.hpp"
+#include "MIDISink.hpp"
+
namespace Machina {
class Problem : public Eugene::Problem<Machine> {
diff --git a/src/engine/Quantizer.hpp b/src/engine/Quantizer.hpp
index 078f5e2..8970b06 100644
--- a/src/engine/Quantizer.hpp
+++ b/src/engine/Quantizer.hpp
@@ -20,7 +20,7 @@
#include <cmath>
#include "raul/TimeStamp.hpp"
-namespace Raul {
+namespace Machina {
/** Quantizer.
* \ingroup raul
@@ -42,6 +42,6 @@ public:
}
};
-} // namespace Raul
+} // namespace Machina
#endif // RAUL_QUANTIZER_HPP
diff --git a/src/engine/Recorder.cpp b/src/engine/Recorder.cpp
index 0a6b5a0..9d8c4fe 100644
--- a/src/engine/Recorder.cpp
+++ b/src/engine/Recorder.cpp
@@ -26,10 +26,16 @@ using namespace Raul;
namespace Machina {
-Recorder::Recorder(size_t buffer_size, TimeUnit unit, double q, bool step)
- : _unit(unit)
+Recorder::Recorder(Raul::Forge& forge,
+ size_t buffer_size,
+ TimeUnit unit,
+ double q,
+ bool step)
+ : _forge(forge)
+ , _unit(unit)
, _record_buffer(buffer_size)
- , _builder(new MachineBuilder(SharedPtr<Machine>(new Machine(unit)), q, step))
+ , _builder(new MachineBuilder(
+ SharedPtr<Machine>(new Machine(forge, unit)), q, step))
{
}
diff --git a/src/engine/Recorder.hpp b/src/engine/Recorder.hpp
index 714b2a9..9c669b9 100644
--- a/src/engine/Recorder.hpp
+++ b/src/engine/Recorder.hpp
@@ -18,24 +18,28 @@
#ifndef MACHINA_RECORDER_HPP
#define MACHINA_RECORDER_HPP
-#include "raul/log.hpp"
-#include "raul/Slave.hpp"
#include "raul/SharedPtr.hpp"
#include "raul/RingBuffer.hpp"
#include "machina/Machine.hpp"
+#include "Slave.hpp"
+
namespace Machina {
class MachineBuilder;
-class Recorder : public Raul::Slave {
+class Recorder : public Slave {
public:
- Recorder(size_t buffer_size, TimeUnit unit, double q, bool step);
+ Recorder(Raul::Forge& forge,
+ size_t buffer_size,
+ TimeUnit unit,
+ double q,
+ bool step);
inline void write(Raul::TimeStamp time, size_t size, const unsigned char* buf) {
if (_record_buffer.write_space() < (sizeof(TimeStamp) + sizeof(size_t) + size)) {
- Raul::warn << "Record buffer overflow" << std::endl;
+ std::cerr << "Record buffer overflow" << std::endl;
return;
} else {
_record_buffer.write(sizeof(TimeStamp), (uint8_t*)&time);
@@ -49,6 +53,7 @@ public:
private:
virtual void _whipped();
+ Raul::Forge& _forge;
TimeUnit _unit;
Raul::RingBuffer _record_buffer;
SharedPtr<MachineBuilder> _builder;
diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp
index cba814d..e3e95b8 100644
--- a/src/engine/SMFDriver.cpp
+++ b/src/engine/SMFDriver.cpp
@@ -20,24 +20,24 @@
#include <glibmm/convert.h>
-#include "raul/Quantizer.hpp"
#include "raul/SharedPtr.hpp"
-#include "raul/SMFWriter.hpp"
-#include "raul/SMFReader.hpp"
#include "machina/Machine.hpp"
#include "Edge.hpp"
+#include "Quantizer.hpp"
#include "SMFDriver.hpp"
+#include "SMFReader.hpp"
+#include "SMFWriter.hpp"
using namespace std;
namespace Machina {
-SMFDriver::SMFDriver(Raul::TimeUnit unit)
- : Driver(SharedPtr<Machine>())
+SMFDriver::SMFDriver(Raul::Forge& forge, Raul::TimeUnit unit)
+ : Driver(forge, SharedPtr<Machine>())
{
- _writer = SharedPtr<Raul::SMFWriter>(new Raul::SMFWriter(unit));
+ _writer = SharedPtr<SMFWriter>(new SMFWriter(unit));
}
/** Learn a single track from the MIDI file at @a uri
@@ -51,9 +51,9 @@ SharedPtr<Machine>
SMFDriver::learn(const string& filename, unsigned track, double q, Raul::TimeDuration max_duration)
{
//assert(q.unit() == max_duration.unit());
- SharedPtr<Machine> m(new Machine(max_duration.unit()));
+ SharedPtr<Machine> m(new Machine(_forge, max_duration.unit()));
SharedPtr<MachineBuilder> builder = SharedPtr<MachineBuilder>(new MachineBuilder(m, q, false));
- Raul::SMFReader reader;
+ SMFReader reader;
if (!reader.open(filename)) {
cerr << "Unable to open MIDI file " << filename << endl;
@@ -80,9 +80,9 @@ SMFDriver::learn(const string& filename, unsigned track, double q, Raul::TimeDur
SharedPtr<Machine>
SMFDriver::learn(const string& filename, double q, Raul::TimeStamp max_duration)
{
- SharedPtr<Machine> m(new Machine(max_duration.unit()));
+ SharedPtr<Machine> m(new Machine(_forge, max_duration.unit()));
SharedPtr<MachineBuilder> builder = SharedPtr<MachineBuilder>(new MachineBuilder(m, q, false));
- Raul::SMFReader reader;
+ SMFReader reader;
if (!reader.open(filename)) {
cerr << "Unable to open MIDI file " << filename << endl;
@@ -104,7 +104,7 @@ SMFDriver::learn(const string& filename, double q, Raul::TimeStamp max_duration)
void
SMFDriver::learn_track(SharedPtr<MachineBuilder> builder,
- Raul::SMFReader& reader,
+ SMFReader& reader,
unsigned track,
double q,
Raul::TimeDuration max_duration)
@@ -122,7 +122,7 @@ SMFDriver::learn_track(SharedPtr<MachineBuilder> builder,
while (reader.read_event(4, buf, &ev_size, &ev_delta_time) >= 0) {
unquantized_t += ev_delta_time;
- t = Raul::Quantizer::quantize(q, unquantized_t);
+ t = Quantizer::quantize(q, unquantized_t);
builder->set_time(TimeStamp(max_duration.unit(), (double)t));
diff --git a/src/engine/SMFDriver.hpp b/src/engine/SMFDriver.hpp
index 264b15a..5da6358 100644
--- a/src/engine/SMFDriver.hpp
+++ b/src/engine/SMFDriver.hpp
@@ -21,14 +21,14 @@
#include <boost/enable_shared_from_this.hpp>
#include <glibmm/ustring.h>
-#include "raul/SMFReader.hpp"
-#include "raul/SMFWriter.hpp"
#include "raul/SharedPtr.hpp"
#include "machina/Driver.hpp"
#include "machina/types.hpp"
#include "MachineBuilder.hpp"
+#include "SMFReader.hpp"
+#include "SMFWriter.hpp"
namespace Machina {
@@ -38,7 +38,7 @@ class Machine;
class SMFDriver : public Driver,
public boost::enable_shared_from_this<SMFDriver> {
public:
- SMFDriver(Raul::TimeUnit unit);
+ SMFDriver(Raul::Forge& forge, Raul::TimeUnit unit);
SharedPtr<Machine> learn(const std::string& filename,
double q,
@@ -59,13 +59,13 @@ public:
void set_bpm(double /*bpm*/) { }
void set_quantization(double /*quantization*/) { }
- SharedPtr<Raul::SMFWriter> writer() { return _writer; }
+ SharedPtr<SMFWriter> writer() { return _writer; }
private:
- SharedPtr<Raul::SMFWriter> _writer;
+ SharedPtr<SMFWriter> _writer;
void learn_track(SharedPtr<MachineBuilder> builder,
- Raul::SMFReader& reader,
+ SMFReader& reader,
unsigned track,
double q,
Raul::TimeDuration max_duration);
diff --git a/src/engine/SMFReader.cpp b/src/engine/SMFReader.cpp
index 0474f88..cba1fb0 100644
--- a/src/engine/SMFReader.cpp
+++ b/src/engine/SMFReader.cpp
@@ -14,20 +14,20 @@
along with Raul. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <glib.h>
-
#include <cassert>
#include <cstdio>
#include <cstring>
#include <string>
-#include "raul/log.hpp"
-#include "raul/SMFReader.hpp"
-#include "raul/midi_events.h"
+#include <glib.h>
+
+#include "lv2/lv2plug.in/ns/ext/midi/midi.h"
+
+#include "SMFReader.hpp"
using std::endl;
-namespace Raul {
+namespace Machina {
/** Return the size of the given event NOT including the status byte,
* or -1 if unknown (eg sysex)
@@ -40,31 +40,30 @@ midi_event_size(unsigned char status)
}
switch (status) {
- case MIDI_CMD_NOTE_OFF:
- case MIDI_CMD_NOTE_ON:
- case MIDI_CMD_NOTE_PRESSURE:
- case MIDI_CMD_CONTROL:
- case MIDI_CMD_BENDER:
- case MIDI_CMD_COMMON_SONG_POS:
+ case LV2_MIDI_MSG_NOTE_OFF:
+ case LV2_MIDI_MSG_NOTE_ON:
+ case LV2_MIDI_MSG_NOTE_PRESSURE:
+ case LV2_MIDI_MSG_CONTROLLER:
+ case LV2_MIDI_MSG_BENDER:
+ case LV2_MIDI_MSG_SONG_POS:
return 2;
- case MIDI_CMD_PGM_CHANGE:
- case MIDI_CMD_CHANNEL_PRESSURE:
- case MIDI_CMD_COMMON_MTC_QUARTER:
- case MIDI_CMD_COMMON_SONG_SELECT:
+ case LV2_MIDI_MSG_PGM_CHANGE:
+ case LV2_MIDI_MSG_CHANNEL_PRESSURE:
+ case LV2_MIDI_MSG_MTC_QUARTER:
+ case LV2_MIDI_MSG_SONG_SELECT:
return 1;
- case MIDI_CMD_COMMON_TUNE_REQUEST:
- case MIDI_CMD_COMMON_SYSEX_END:
- case MIDI_CMD_COMMON_CLOCK:
- case MIDI_CMD_COMMON_START:
- case MIDI_CMD_COMMON_CONTINUE:
- case MIDI_CMD_COMMON_STOP:
- case MIDI_CMD_COMMON_SENSING:
- case MIDI_CMD_COMMON_RESET:
+ case LV2_MIDI_MSG_TUNE_REQUEST:
+ case LV2_MIDI_MSG_CLOCK:
+ case LV2_MIDI_MSG_START:
+ case LV2_MIDI_MSG_CONTINUE:
+ case LV2_MIDI_MSG_STOP:
+ case LV2_MIDI_MSG_ACTIVE_SENSE:
+ case LV2_MIDI_MSG_RESET:
return 0;
- case MIDI_CMD_COMMON_SYSEX:
+ case LV2_MIDI_MSG_SYSTEM_EXCLUSIVE:
return -1;
}
@@ -93,7 +92,7 @@ SMFReader::open(const std::string& filename) throw (std::logic_error, Unsupporte
if (_fd)
throw std::logic_error("Attempt to start new read while write in progress.");
- info << "Opening SMF file " << filename << " for reading." << endl;
+ std::cout << "Opening SMF file " << filename << " for reading." << endl;
_fd = fopen(filename.c_str(), "r+");
@@ -104,7 +103,7 @@ SMFReader::open(const std::string& filename) throw (std::logic_error, Unsupporte
mthd[4] = '\0';
fread(mthd, 1, 4, _fd);
if (strcmp(mthd, "MThd")) {
- error << filename << " is not an SMF file, aborting." << endl;
+ std::cerr << filename << " is not an SMF file, aborting." << endl;
fclose(_fd);
_fd = NULL;
return false;
@@ -163,7 +162,7 @@ SMFReader::seek_to_track(unsigned track) throw (std::logic_error)
if (!strcmp(id, "MTrk")) {
++track_pos;
} else {
- error << "Unknown chunk ID " << id << endl;
+ std::cerr << "Unknown chunk ID " << id << endl;
}
uint32_t chunk_size_be;
@@ -307,5 +306,5 @@ SMFReader::read_var_len(FILE* fd) throw (PrematureEOF)
return value;
}
-} // namespace Raul
+} // namespace Machina
diff --git a/src/engine/SMFReader.hpp b/src/engine/SMFReader.hpp
index dbca289..053a62c 100644
--- a/src/engine/SMFReader.hpp
+++ b/src/engine/SMFReader.hpp
@@ -22,7 +22,7 @@
#include <inttypes.h>
#include "raul/TimeStamp.hpp"
-namespace Raul {
+namespace Machina {
/** Standard Midi File (Type 0) Reader
*
@@ -75,7 +75,7 @@ protected:
uint32_t _track_size;
};
-} // namespace Raul
+} // namespace Machina
#endif // RAUL_SMF_READER_HPP
diff --git a/src/engine/SMFWriter.cpp b/src/engine/SMFWriter.cpp
index f3a9043..ad993bc 100644
--- a/src/engine/SMFWriter.cpp
+++ b/src/engine/SMFWriter.cpp
@@ -24,12 +24,11 @@
#include <limits>
#include <string>
-#include "raul/log.hpp"
-#include "raul/SMFWriter.hpp"
+#include "SMFWriter.hpp"
using std::endl;
-namespace Raul {
+namespace Machina {
/** Create a new SMF writer.
*
@@ -38,7 +37,7 @@ namespace Raul {
*
* *** NOTE: Only beat time is implemented currently.
*/
-SMFWriter::SMFWriter(TimeUnit unit)
+SMFWriter::SMFWriter(Raul::TimeUnit unit)
: _fd(NULL)
, _unit(unit)
, _start_time(unit, 0, 0)
@@ -46,7 +45,7 @@ SMFWriter::SMFWriter(TimeUnit unit)
, _track_size(0)
, _header_size(0)
{
- if (unit.type() == TimeUnit::BEATS)
+ if (unit.type() == Raul::TimeUnit::BEATS)
assert(unit.ppt() < std::numeric_limits<uint16_t>::max());
}
@@ -69,7 +68,7 @@ SMFWriter::start(const std::string& filename,
if (_fd)
throw std::logic_error("Attempt to start new write while write in progress.");
- info << "Opening SMF file " << filename << " for writing." << endl;
+ std::cout << "Opening SMF file " << filename << " for writing." << endl;
_fd = fopen(filename.c_str(), "w+");
@@ -152,7 +151,7 @@ SMFWriter::finish() throw (std::logic_error)
void
SMFWriter::write_header()
{
- info << "SMF Flushing header\n";
+ std::cout << "SMF Flushing header\n";
assert(_fd);
@@ -177,7 +176,7 @@ SMFWriter::write_header()
void
SMFWriter::write_footer()
{
- info << "Writing EOT\n";
+ std::cout << "Writing EOT\n";
fseek(_fd, 0, SEEK_END);
write_var_len(1); // whatever...
@@ -231,5 +230,5 @@ SMFWriter::write_var_len(uint32_t value)
return ret;
}
-} // namespace Raul
+} // namespace Machina
diff --git a/src/engine/SMFWriter.hpp b/src/engine/SMFWriter.hpp
index 4c52b12..3e47e9f 100644
--- a/src/engine/SMFWriter.hpp
+++ b/src/engine/SMFWriter.hpp
@@ -20,25 +20,26 @@
#include <stdexcept>
#include <string>
-#include "raul/MIDISink.hpp"
#include "raul/TimeStamp.hpp"
-namespace Raul {
+#include "MIDISink.hpp"
+
+namespace Machina {
/** Standard Midi File (Type 0) Writer
* \ingroup raul
*/
-class SMFWriter : public Raul::MIDISink {
+class SMFWriter : public MIDISink {
public:
- explicit SMFWriter(TimeUnit unit);
+ explicit SMFWriter(Raul::TimeUnit unit);
~SMFWriter();
bool start(const std::string& filename,
- TimeStamp start_time) throw (std::logic_error);
+ Raul::TimeStamp start_time) throw (std::logic_error);
- TimeUnit unit() const { return _unit; }
+ Raul::TimeUnit unit() const { return _unit; }
- void write_event(TimeStamp time,
+ void write_event(Raul::TimeStamp time,
size_t ev_size,
const unsigned char* ev) throw (std::logic_error);
@@ -58,14 +59,14 @@ protected:
std::string _filename;
FILE* _fd;
- TimeUnit _unit;
+ Raul::TimeUnit _unit;
Raul::TimeStamp _start_time;
Raul::TimeStamp _last_ev_time; ///< Time last event was written relative to _start_time
uint32_t _track_size;
uint32_t _header_size; ///< size of SMF header, including MTrk chunk header
};
-} // namespace Raul
+} // namespace Machina
#endif // RAUL_SMF_WRITER_HPP
diff --git a/src/engine/Updates.cpp b/src/engine/Updates.cpp
index d093df4..aabd4fb 100644
--- a/src/engine/Updates.cpp
+++ b/src/engine/Updates.cpp
@@ -15,6 +15,8 @@
* along with Machina. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "lv2/lv2plug.in/ns/ext/atom/atom.h"
+
#include "raul/Atom.hpp"
#include "raul/SharedPtr.hpp"
@@ -23,94 +25,6 @@
namespace Machina {
-static inline void
-write_atom(SharedPtr<UpdateBuffer> buf,
- const Raul::Atom& value)
-{
- const Raul::Atom::Type type = value.type();
- buf->write(sizeof(type), &type);
- int32_t ival;
- float fval;
- size_t szval;
- switch (value.type()) {
- case Raul::Atom::INT:
- ival = value.get_int32();
- buf->write(sizeof(ival), &ival);
- break;
- case Raul::Atom::FLOAT:
- ival = value.get_float();
- buf->write(sizeof(fval), &fval);
- break;
- case Raul::Atom::BOOL:
- ival = value.get_bool() ? 1 : 0;
- buf->write(sizeof(ival), &ival);
- break;
- case Raul::Atom::STRING:
- szval = value.data_size();
- buf->write(sizeof(size_t), &szval);
- buf->write(value.data_size(), value.get_string());
- break;
- case Raul::Atom::URI:
- szval = value.data_size();
- buf->write(sizeof(size_t), &szval);
- buf->write(value.data_size(), value.get_uri());
- break;
- default:
- assert(false);
- }
-}
-
-uint32_t
-read_atom(SharedPtr<UpdateBuffer> buf,
- Raul::Atom* value)
-{
- Raul::Atom::Type type;
- buf->read(sizeof(type), &type);
-
- int32_t ival;
- float fval;
- char* sval;
- size_t val_size;
- switch (type) {
- case Raul::Atom::INT:
- val_size = sizeof(ival);
- buf->read(val_size, &ival);
- *value = Raul::Atom(ival);
- break;
- case Raul::Atom::FLOAT:
- val_size = sizeof(fval);
- buf->read(val_size, &fval);
- *value = Raul::Atom(fval);
- break;
- case Raul::Atom::BOOL:
- val_size = sizeof(ival);
- buf->read(val_size, &ival);
- assert(ival == 0 || ival == 1);
- *value = Raul::Atom(bool(ival));
- break;
- case Raul::Atom::STRING:
- buf->read(sizeof(val_size), &val_size);
- sval = (char*)malloc(val_size);
- buf->read(val_size, sval);
- val_size += sizeof(val_size);
- *value = Raul::Atom(sval);
- free(sval);
- break;
- case Raul::Atom::URI:
- buf->read(sizeof(val_size), &val_size);
- sval = (char*)malloc(val_size);
- buf->read(val_size, sval);
- val_size += sizeof(val_size);
- *value = Raul::Atom(Raul::Atom::URI, sval);
- free(sval);
- break;
- default:
- assert(false);
- }
-
- return sizeof(type) + val_size;
-}
-
void
write_set(SharedPtr<UpdateBuffer> buf,
uint64_t subject,
@@ -121,7 +35,10 @@ write_set(SharedPtr<UpdateBuffer> buf,
buf->write(sizeof(update_type), &update_type);
buf->write(sizeof(subject), &subject);
buf->write(sizeof(key), &key);
- write_atom(buf, value);
+
+ const LV2_Atom atom = { value.size(), value.type() };
+ buf->write(sizeof(LV2_Atom), &atom);
+ buf->write(value.size(), value.get_body());
}
uint32_t
@@ -132,12 +49,20 @@ read_set(SharedPtr<UpdateBuffer> buf,
{
uint32_t update_type;
buf->read(sizeof(update_type), &update_type);
- assert(update_type == UPDATE_SET);
+ if (update_type != UPDATE_SET) {
+ return 0;
+ }
+
buf->read(sizeof(*subject), subject);
buf->read(sizeof(*key), key);
- const uint32_t value_size = read_atom(buf, value);
- return sizeof(update_type) + sizeof(*subject) + sizeof(*key) + value_size;
+ LV2_Atom atom;
+ buf->read(sizeof(LV2_Atom), &atom);
+ *value = Raul::Atom(atom.size, atom.type, NULL);
+ buf->read(atom.size, value->get_body());
+
+ return sizeof(update_type) + sizeof(*subject) + sizeof(*key) +
+ sizeof(LV2_Atom) + atom.size;
}
}
diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp
index c80fc26..69bf951 100644
--- a/src/engine/machina/Driver.hpp
+++ b/src/engine/machina/Driver.hpp
@@ -18,18 +18,23 @@
#ifndef MACHINA_DRIVER_HPP
#define MACHINA_DRIVER_HPP
-#include "raul/MIDISink.hpp"
#include "raul/RingBuffer.hpp"
#include "machina/types.hpp"
+#include "MIDISink.hpp"
+
namespace Machina {
class Machine;
-class Driver : public Raul::MIDISink {
+class Driver : public MIDISink {
public:
- Driver(SharedPtr<Machine> machine) : _machine(machine) {}
+ Driver(Raul::Forge& forge, SharedPtr<Machine> machine)
+ : _forge(forge)
+ , _machine(machine)
+ {}
+
virtual ~Driver() {}
SharedPtr<Machine> machine() { return _machine; }
@@ -52,6 +57,7 @@ public:
virtual void finish_record() {}
protected:
+ Raul::Forge& _forge;
SharedPtr<Machine> _machine;
SharedPtr<UpdateBuffer> _updates;
};
diff --git a/src/engine/machina/Engine.hpp b/src/engine/machina/Engine.hpp
index 8c3a117..5f11d55 100644
--- a/src/engine/machina/Engine.hpp
+++ b/src/engine/machina/Engine.hpp
@@ -22,6 +22,7 @@
#include <glibmm/ustring.h>
+#include "raul/Atom.hpp"
#include "raul/SharedPtr.hpp"
#include "machina/Driver.hpp"
@@ -33,15 +34,19 @@ class Machine;
class Engine {
public:
- Engine(SharedPtr<Driver> driver, Sord::World& rdf_world);
+ Engine(Raul::Forge& forge,
+ SharedPtr<Driver> driver,
+ Sord::World& rdf_world);
Sord::World& rdf_world() { return _rdf_world; }
- static SharedPtr<Driver> new_driver(const std::string& name,
+ static SharedPtr<Driver> new_driver(Raul::Forge& forge,
+ const std::string& name,
SharedPtr<Machine> machine);
SharedPtr<Driver> driver() { return _driver; }
SharedPtr<Machine> machine() { return _driver->machine(); }
+ Raul::Forge& forge() { return _forge; }
SharedPtr<Machine> load_machine(const Glib::ustring& uri);
SharedPtr<Machine> load_machine_midi(const Glib::ustring& uri,
@@ -60,6 +65,7 @@ private:
SharedPtr<Driver> _driver;
Sord::World& _rdf_world;
Loader _loader;
+ Raul::Forge _forge;
};
} // namespace Machina
diff --git a/src/engine/machina/Loader.hpp b/src/engine/machina/Loader.hpp
index a393ccd..470b109 100644
--- a/src/engine/machina/Loader.hpp
+++ b/src/engine/machina/Loader.hpp
@@ -20,7 +20,7 @@
#include <glibmm/ustring.h>
-#include "raul/Path.hpp"
+#include "raul/Atom.hpp"
#include "raul/SharedPtr.hpp"
#include "sord/sordmm.hpp"
@@ -33,11 +33,12 @@ class Machine;
class Loader {
public:
- Loader(Sord::World& rdf_world);
+ Loader(Raul::Forge& forge, Sord::World& rdf_world);
SharedPtr<Machine> load(const Glib::ustring& filename);
private:
+ Raul::Forge& _forge;
Sord::World& _rdf_world;
};
diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp
index b9ad4c1..d65b670 100644
--- a/src/engine/machina/Machine.hpp
+++ b/src/engine/machina/Machine.hpp
@@ -21,7 +21,7 @@
#include <vector>
#include <boost/utility.hpp>
-#include "raul/List.hpp"
+#include "raul/Atom.hpp"
#include "raul/Maid.hpp"
#include "raul/RingBuffer.hpp"
#include "raul/SharedPtr.hpp"
@@ -42,7 +42,7 @@ class LearnRequest;
*/
class Machine : public Stateful {
public:
- Machine(TimeUnit unit);
+ Machine(Raul::Forge& forge, TimeUnit unit);
Machine(const Machine& copy);
Machine& operator=(const Machine& other);
@@ -74,30 +74,31 @@ public:
SharedPtr<LearnRequest> pending_learn() { return _pending_learn; }
void clear_pending_learn() { _pending_learn.reset(); }
- typedef Raul::List< SharedPtr<Node> > Nodes;
+ typedef std::list< SharedPtr<Node> > Nodes;
Nodes& nodes() { return _nodes; }
const Nodes& nodes() const { return _nodes; }
SharedPtr<Node> random_node();
SharedPtr<Edge> random_edge();
- void set_sink(SharedPtr<Raul::MIDISink> sink);
+ void set_sink(SharedPtr<MIDISink> sink);
private:
// Audio context
SharedPtr<Node> earliest_node() const;
- bool enter_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node, SharedPtr<UpdateBuffer> updates);
- void exit_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node>, SharedPtr<UpdateBuffer> updates);
+ bool enter_node(SharedPtr<MIDISink> sink, SharedPtr<Node> node, SharedPtr<UpdateBuffer> updates);
+ void exit_node(SharedPtr<MIDISink> sink, SharedPtr<Node>, SharedPtr<UpdateBuffer> updates);
static const size_t MAX_ACTIVE_NODES = 128;
std::vector< SharedPtr<Node> > _active_nodes;
+ Raul::Forge& _forge;
bool _is_activated;
bool _is_finished;
Raul::TimeStamp _time;
SharedPtr<LearnRequest> _pending_learn;
- WeakPtr<Raul::MIDISink> _sink;
+ WeakPtr<MIDISink> _sink;
Nodes _nodes;
};
diff --git a/src/engine/machina/URIs.hpp b/src/engine/machina/URIs.hpp
index 944ab63..ae6cd2f 100644
--- a/src/engine/machina/URIs.hpp
+++ b/src/engine/machina/URIs.hpp
@@ -32,8 +32,9 @@ public:
static inline const URIs& instance() { assert(_instance); return *_instance; }
- Raul::Atom machina_MidiAction_atom;
-
+ URIInt machina_Edge;
+ URIInt machina_MidiAction;
+ URIInt machina_Node;
URIInt machina_active;
URIInt machina_canvas_x;
URIInt machina_canvas_y;
@@ -50,7 +51,9 @@ public:
private:
URIs()
- : machina_MidiAction_atom(Raul::Atom::URI, "machina:MidiAction")
+ : machina_Edge(43)
+ , machina_MidiAction(43)
+ , machina_Node(42)
, machina_active(1)
, machina_canvas_x(2)
, machina_canvas_y(3)
diff --git a/src/engine/quantize_test.cpp b/src/engine/quantize_test.cpp
index 9cc165d..dfb3b4b 100644
--- a/src/engine/quantize_test.cpp
+++ b/src/engine/quantize_test.cpp
@@ -14,11 +14,12 @@
along with Raul. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "raul/Quantizer.hpp"
#include <iostream>
+#include "Quantizer.hpp"
+
using namespace std;
-using namespace Raul;
+using namespace Machina;
int
main()
diff --git a/src/engine/smf_test.cpp b/src/engine/smf_test.cpp
index 680f66b..4787b7d 100644
--- a/src/engine/smf_test.cpp
+++ b/src/engine/smf_test.cpp
@@ -21,7 +21,7 @@
#include "raul/SMFWriter.hpp"
using namespace std;
-using namespace Raul;
+using namespace Machina;
int
main(int argc, char** argv)
diff --git a/src/engine/wscript b/src/engine/wscript
index bacffbe..60bddd3 100644
--- a/src/engine/wscript
+++ b/src/engine/wscript
@@ -18,6 +18,8 @@ def build(bld):
Node.cpp
Recorder.cpp
SMFDriver.cpp
+ SMFReader.cpp
+ SMFWriter.cpp
Stateful.cpp
Updates.cpp
URIs.cpp
@@ -33,7 +35,7 @@ def build(bld):
obj.includes = ['.', '..', '../..']
obj.name = 'libmachina_engine'
obj.target = 'machina_engine'
- core_libs = 'GLIBMM GTHREAD RAUL SORD JACK'
+ core_libs = 'RAUL GLIBMM GTHREAD RAUL SERD SORD JACK'
if bld.is_defined('HAVE_EUGENE'):
core_libs += ' EUGENE '
autowaf.use_lib(bld, obj, core_libs)