diff options
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/Controller.cpp | 150 | ||||
-rw-r--r-- | src/engine/Engine.cpp | 8 | ||||
-rw-r--r-- | src/engine/Updates.cpp | 6 | ||||
-rw-r--r-- | src/engine/machina/Controller.hpp | 19 | ||||
-rw-r--r-- | src/engine/machina/Model.hpp | 44 | ||||
-rw-r--r-- | src/engine/machina/types.hpp | 6 | ||||
-rw-r--r-- | src/engine/wscript | 4 |
7 files changed, 142 insertions, 95 deletions
diff --git a/src/engine/Controller.cpp b/src/engine/Controller.cpp index 8c27503..8f9e1a2 100644 --- a/src/engine/Controller.cpp +++ b/src/engine/Controller.cpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard <http://drobilla.net> + Copyright 2007-2014 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 @@ -14,12 +14,9 @@ along with Machina. If not, see <http://www.gnu.org/licenses/>. */ -#include "client/ClientModel.hpp" -#include "client/ClientObject.hpp" #include "machina/Controller.hpp" #include "machina/Engine.hpp" #include "machina/Machine.hpp" -#include "machina/Machine.hpp" #include "machina/Updates.hpp" #include "Edge.hpp" @@ -27,26 +24,32 @@ namespace machina { -Controller::Controller(SPtr<Engine> engine, - client::ClientModel& client_model) +Controller::Controller(SPtr<Engine> engine, + Model& model) : _engine(engine) - , _client_model(client_model) + , _model(model) , _updates(new Raul::RingBuffer(4096)) { _engine->driver()->set_update_sink(_updates); } uint64_t -Controller::create(const client::ClientObject& properties) +Controller::create(const Properties& properties) { - TimeDuration dur( - _engine->machine()->time().unit(), - properties.get(URIs::instance().machina_duration).get<float>()); + std::map<URIInt, Atom>::const_iterator d = properties.find( + URIs::instance().machina_duration); + + double duration = 0.0; + if (d != properties.end()) { + duration = d->second.get<float>(); + } else { + std::cerr << "warning: new object has no duration" << std::endl; + } + + TimeDuration dur(_engine->machine()->time().unit(), duration); SPtr<Node> node(new Node(dur)); - SPtr<client::ClientObject> obj( - new client::ClientObject(properties, node->id())); _objects.insert(node); - _client_model.new_object(obj); + _model.new_object(node->id(), properties); _engine->machine()->add_node(node); return node->id(); } @@ -54,59 +57,55 @@ Controller::create(const client::ClientObject& properties) void Controller::announce(SPtr<Machine> machine) { + if (!machine) { + return; + } + Forge& forge = _engine->forge(); + // Announce nodes for (const auto& n : machine->nodes()) { - // Find or create a new client object if necessary - SPtr<client::ClientObject> obj = _client_model.find(n->id()); - if (!obj) { - obj = SPtr<client::ClientObject>(new 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()))); - if (n->is_initial()) { - obj->set(URIs::instance().machina_initial, forge.make(true)); - } - - SPtr<MidiAction> midi_action = dynamic_ptr_cast<MidiAction>( - n->enter_action()); - if (midi_action) { - SPtr<client::ClientObject> action = _client_model.find( - midi_action->id()); - if (!action) { - action = SPtr<client::ClientObject>( - new client::ClientObject(midi_action->id())); - action->set(URIs::instance().machina_note_number, - forge.make((int32_t)midi_action->event()[1])); - _client_model.new_object(action); - } - obj->set(URIs::instance().machina_enter_action, - forge.make(int32_t(n->enter_action()->id()))); - } + Properties properties { + { URIs::instance().rdf_type, + forge.make_urid(URIs::instance().machina_Node) }, + { URIs::instance().machina_duration, + forge.make(float(n->duration().to_double())) } }; + if (n->is_initial()) { + properties.insert({ URIs::instance().machina_initial, + forge.make(true) }); } + + SPtr<MidiAction> midi_action = dynamic_ptr_cast<MidiAction>( + n->enter_action()); + if (midi_action) { + Properties action_properties { + { URIs::instance().machina_note_number, + forge.make((int32_t)midi_action->event()[1]) } }; + + _model.new_object(midi_action->id(), action_properties); + properties.insert({ URIs::instance().machina_enter_action, + forge.make(int32_t(n->enter_action()->id())) }); + } + _objects.insert(n); - _client_model.new_object(obj); + _model.new_object(n->id(), properties); } + // Announce edges for (const auto& n : machine->nodes()) { for (const auto& e : n->edges()) { - SPtr<client::ClientObject> eobj = _client_model.find(e->id()); - if (!eobj) { - eobj = SPtr<client::ClientObject>( - new client::ClientObject(e->id())); - eobj->set(URIs::instance().rdf_type, - forge.make_urid(URIs::instance().machina_Edge)); - 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())); - } + const Properties properties { + { URIs::instance().rdf_type, + forge.make_urid(URIs::instance().machina_Edge) }, + { URIs::instance().machina_probability, + forge.make(e->probability()) }, + { URIs::instance().machina_tail_id, + forge.make((int32_t)n->id()) }, + { URIs::instance().machina_head_id, + forge.make((int32_t)e->head()->id()) } }; _objects.insert(e); - _client_model.new_object(eobj); + _model.new_object(e->id(), properties); } } } @@ -142,7 +141,7 @@ Controller::set_property(uint64_t object_id, SPtr<Stateful> object = find(object_id); if (object) { object->set(key, value); - _client_model.property(object_id, key, value); + _model.set(object_id, key, value); } } @@ -152,20 +151,30 @@ Controller::connect(uint64_t tail_id, uint64_t head_id) SPtr<Node> tail = dynamic_ptr_cast<Node>(find(tail_id)); SPtr<Node> head = dynamic_ptr_cast<Node>(find(head_id)); + if (!tail) { + std::cerr << "error: tail node " << tail_id << " not found" << std::endl; + return 0; + } else if (!head) { + std::cerr << "error: head node " << head_id << " not found" << std::endl; + return 0; + } + SPtr<Edge> edge(new Edge(tail, head)); tail->add_edge(edge); _objects.insert(edge); Forge& forge = _engine->forge(); - SPtr<client::ClientObject> obj(new client::ClientObject(edge->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())); + const Properties properties = { + { URIs::instance().rdf_type, + forge.make_urid(URIs::instance().machina_Edge) }, + { URIs::instance().machina_probability, forge.make(1.0f) }, + { URIs::instance().machina_tail_id, + forge.make((int32_t)tail->id()) }, + { URIs::instance().machina_head_id, + forge.make((int32_t)head->id()) } }; - _client_model.new_object(obj); + _model.new_object(edge->id(), properties); return edge->id(); } @@ -178,7 +187,7 @@ Controller::disconnect(uint64_t tail_id, uint64_t head_id) SPtr<Edge> edge = tail->remove_edge_to(head); if (edge) { - _client_model.erase_object(edge->id()); + _model.erase_object(edge->id()); } else { std::cerr << "Edge not found" << std::endl; } @@ -198,7 +207,7 @@ Controller::erase(uint64_t id) _engine->machine()->remove_node(node); } - _client_model.erase_object((*i)->id()); + _model.erase_object((*i)->id()); _objects.erase(i); } @@ -212,14 +221,7 @@ Controller::process_updates() Atom value; for (uint32_t i = 0; i < read_space; ) { i += read_set(_updates, &subject, &key, &value); - SPtr<client::ClientObject> obj = _client_model.find(subject); - if (obj) { - obj->set(key, value); - } else { - SPtr<client::ClientObject> obj(new client::ClientObject(subject)); - obj->set(key, value); - _client_model.new_object(obj); - } + _model.set(subject, key, value); } } diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 7eeafa4..969b7cc 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard <http://drobilla.net> + Copyright 2007-2014 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 @@ -41,13 +41,15 @@ Engine::new_driver(Forge& forge, const std::string& name, SPtr<Machine> machine) { -#ifdef HAVE_JACK if (name == "jack") { +#ifdef HAVE_JACK JackDriver* driver = new JackDriver(forge, machine); driver->attach("machina"); return SPtr<Driver>(driver); - } +#else + return SPtr<Driver>(); #endif + } if (name == "smf") { return SPtr<Driver>(new SMFDriver(forge, machine->time().unit())); } diff --git a/src/engine/Updates.cpp b/src/engine/Updates.cpp index 3193d41..846bf8d 100644 --- a/src/engine/Updates.cpp +++ b/src/engine/Updates.cpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard <http://drobilla.net> + Copyright 2007-2014 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 @@ -44,7 +44,7 @@ read_set(SPtr<Raul::RingBuffer> buf, URIInt* key, Atom* value) { - uint32_t update_type; + uint32_t update_type = 0; buf->read(sizeof(update_type), &update_type); if (update_type != UPDATE_SET) { return 0; @@ -53,7 +53,7 @@ read_set(SPtr<Raul::RingBuffer> buf, buf->read(sizeof(*subject), subject); buf->read(sizeof(*key), key); - LV2_Atom atom; + LV2_Atom atom = { 0, 0 }; buf->read(sizeof(LV2_Atom), &atom); *value = Atom(atom.size, atom.type, NULL); buf->read(atom.size, value->get_body()); diff --git a/src/engine/machina/Controller.hpp b/src/engine/machina/Controller.hpp index e745c9c..833b5b2 100644 --- a/src/engine/machina/Controller.hpp +++ b/src/engine/machina/Controller.hpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard <http://drobilla.net> + Copyright 2007-2014 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 @@ -24,8 +24,9 @@ #include "raul/RingBuffer.hpp" #include "raul/Maid.hpp" -#include "machina/types.hpp" +#include "machina/Model.hpp" #include "machina/URIs.hpp" +#include "machina/types.hpp" #include "Stateful.hpp" @@ -37,19 +38,13 @@ namespace machina { class Engine; class Machine; -class Stateful; - -namespace client { -class ClientModel; -class ClientObject; -} class Controller { public: - Controller(SPtr<Engine> engine, client::ClientModel& client_model); + Controller(SPtr<Engine> engine, Model& model); - uint64_t create(const client::ClientObject& obj); + uint64_t create(const Properties& properties); uint64_t connect(uint64_t tail_id, uint64_t head_id); void set_property(uint64_t object_id, URIInt key, const Atom& value); @@ -74,8 +69,8 @@ private: typedef std::set<SPtr<Stateful>, StatefulComparator> Objects; Objects _objects; - SPtr<Engine> _engine; - client::ClientModel& _client_model; + SPtr<Engine> _engine; + Model& _model; SPtr<Raul::RingBuffer> _updates; }; diff --git a/src/engine/machina/Model.hpp b/src/engine/machina/Model.hpp new file mode 100644 index 0000000..32a332e --- /dev/null +++ b/src/engine/machina/Model.hpp @@ -0,0 +1,44 @@ +/* + This file is part of Machina. + Copyright 2014 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 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 MACHINA_MODEL_HPP +#define MACHINA_MODEL_HPP + +#include <stdint.h> + +#include <map> + +#include "machina/Atom.hpp" +#include "machina/types.hpp" + +namespace machina { + +class Model +{ +public: + virtual ~Model() {} + + virtual void new_object(uint64_t id, const Properties& properties) = 0; + + virtual void erase_object(uint64_t id) = 0; + + virtual void set(uint64_t id, URIInt key, const Atom& value) = 0; + virtual const Atom& get(uint64_t id, URIInt key) const = 0; +}; + +} // namespace machina + +#endif // MACHINA_MODEL_HPP diff --git a/src/engine/machina/types.hpp b/src/engine/machina/types.hpp index fff2601..e9ac7d0 100644 --- a/src/engine/machina/types.hpp +++ b/src/engine/machina/types.hpp @@ -1,6 +1,6 @@ /* This file is part of Machina. - Copyright 2007-2013 David Robillard <http://drobilla.net> + Copyright 2007-2014 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 @@ -17,6 +17,7 @@ #ifndef MACHINA_TYPES_HPP #define MACHINA_TYPES_HPP +#include <map> #include <memory> #include "raul/RingBuffer.hpp" @@ -27,6 +28,9 @@ typedef unsigned char byte; typedef uint32_t URIInt; +class Atom; +typedef std::map<URIInt, Atom> Properties; + #if __cplusplus >= 201103L template <class T> using SPtr = std::shared_ptr<T>; diff --git a/src/engine/wscript b/src/engine/wscript index 80f03a4..e1fc1ab 100644 --- a/src/engine/wscript +++ b/src/engine/wscript @@ -23,7 +23,7 @@ def build(bld): Updates.cpp URIs.cpp ''' - if bld.is_defined('HAVE_EUGENE'): + if bld.env.HAVE_EUGENE: core_source += ''' Evolver.cpp Problem.cpp @@ -35,7 +35,7 @@ def build(bld): obj.name = 'libmachina_engine' obj.target = 'machina_engine' core_libs = 'RAUL GLIBMM GTHREAD RAUL SERD SORD JACK LV2' - if bld.is_defined('HAVE_EUGENE'): + if bld.env.HAVE_EUGENE: core_libs += ' EUGENE ' autowaf.use_lib(bld, obj, core_libs) |