diff options
author | David Robillard <d@drobilla.net> | 2017-12-17 20:33:47 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-12-17 20:33:47 +0100 |
commit | 7f37e2306f79d3f77934aa97e5f784fb0b39b838 (patch) | |
tree | 32a8b3b87795ba494ff5f0fcaf7ea893a8fb5594 | |
parent | 86bf9cbd7af99c8964745d414494c26af11af0f4 (diff) | |
download | ingen-7f37e2.tar.gz ingen-7f37e2.tar.bz2 ingen-7f37e2.zip |
Use LV2 atom forge C++ bindings
-rw-r--r-- | ingen/AtomForgeSink.hpp | 24 | ||||
-rw-r--r-- | ingen/AtomWriter.hpp | 49 | ||||
-rw-r--r-- | ingen/Forge.hpp | 5 | ||||
-rw-r--r-- | src/AtomWriter.cpp | 222 | ||||
-rw-r--r-- | src/Forge.cpp | 6 | ||||
-rw-r--r-- | src/Parser.cpp | 7 | ||||
-rw-r--r-- | src/SocketReader.cpp | 9 | ||||
-rw-r--r-- | src/server/JackDriver.cpp | 43 | ||||
-rw-r--r-- | src/server/JackDriver.hpp | 4 | ||||
-rw-r--r-- | tests/ingen_test.cpp | 8 | ||||
-rw-r--r-- | wscript | 2 |
11 files changed, 162 insertions, 217 deletions
diff --git a/ingen/AtomForgeSink.hpp b/ingen/AtomForgeSink.hpp index 5520906c..b32d9679 100644 --- a/ingen/AtomForgeSink.hpp +++ b/ingen/AtomForgeSink.hpp @@ -17,9 +17,10 @@ #ifndef INGEN_ATOMFORGESINK_HPP #define INGEN_ATOMFORGESINK_HPP +#include <cassert> #include <cstdlib> -#include "lv2/lv2plug.in/ns/ext/atom/forge.h" +#include "lv2/lv2plug.in/ns/ext/atom/util.h" namespace Ingen { @@ -27,24 +28,17 @@ namespace Ingen { class AtomForgeSink { public: - AtomForgeSink(LV2_Atom_Forge* forge = nullptr) + AtomForgeSink() : _capacity(8 * sizeof(LV2_Atom)) , _size(0) , _buf((LV2_Atom*)calloc(8, sizeof(LV2_Atom))) { - if (forge) { - set_forge_sink(forge); - } } ~AtomForgeSink() { free(_buf); } - void set_forge_sink(LV2_Atom_Forge* forge) { - lv2_atom_forge_set_sink(forge, c_append, c_deref, this); - } - /** Append some data and return a reference to its start. */ - intptr_t append(const void* buf, uint32_t len) { + intptr_t write(const void* buf, uint32_t len) { // Record offset of the start of this write (+1 to avoid NULL) const intptr_t ref = _size + 1; @@ -76,16 +70,6 @@ public: void clear() { _buf->type = 0; _buf->size = 0; _size = 0; } - static LV2_Atom_Forge_Ref - c_append(void* handle, const void* buf, uint32_t len) { - return ((AtomForgeSink*)handle)->append(buf, len); - } - - static LV2_Atom* - c_deref(void* handle, LV2_Atom_Forge_Ref ref) { - return ((AtomForgeSink*)handle)->deref(ref); - } - private: size_t _capacity; size_t _size; diff --git a/ingen/AtomWriter.hpp b/ingen/AtomWriter.hpp index 20d152e6..aca1f5bb 100644 --- a/ingen/AtomWriter.hpp +++ b/ingen/AtomWriter.hpp @@ -23,7 +23,7 @@ #include "ingen/Interface.hpp" #include "ingen/URIs.hpp" #include "ingen/ingen.h" -#include "lv2/lv2plug.in/ns/ext/atom/forge.h" +#include "lv2/lv2plug.in/ns/ext/atom/Forge.hpp" namespace Ingen { @@ -36,8 +36,6 @@ class INGEN_API AtomWriter : public Interface public: AtomWriter(URIMap& map, URIs& uris, AtomSink& sink); - ~AtomWriter(); - Raul::URI uri() const { return Raul::URI("ingen:/clients/atom_writer"); } @@ -62,19 +60,50 @@ public: void operator()(const Undo&); private: + using ScopedObject = lv2::atom::Forge::ScopedObject; + + struct ScopedEmitter + { + ScopedEmitter(AtomWriter& writer) : writer(writer) {} + ~ScopedEmitter() { writer.finish_msg(); } + + ScopedEmitter(const ScopedEmitter&) = delete; + ScopedEmitter& operator=(const ScopedEmitter&) = delete; + + AtomWriter& writer; + }; + + struct ScopedMessage + { + ScopedMessage(AtomWriter& writer, + const LV2_URID type, + const int32_t seq = 0) + : emitter(writer) + , object(writer._forge, 0, type) + { + if (seq) { + object.key(writer._uris.patch_sequenceNumber); + writer._forge.write(seq); + } + } + + ScopedEmitter emitter; + ScopedObject object; + }; + void forge_uri(const Raul::URI& uri); - void forge_properties(const Properties& properties); + void forge_properties(ScopedObject& object, const Properties& properties); void forge_arc(const Raul::Path& tail, const Raul::Path& head); void forge_request(LV2_Atom_Forge_Frame* frame, LV2_URID type, int32_t id); - void forge_context(Resource::Graph ctx); + void forge_context(ScopedMessage& message, Resource::Graph ctx); void finish_msg(); - URIMap& _map; - URIs& _uris; - AtomSink& _sink; - AtomForgeSink _out; - LV2_Atom_Forge _forge; + URIMap& _map; + URIs& _uris; + AtomSink& _sink; + AtomForgeSink _out; + lv2::atom::Forge _forge; }; } // namespace Ingen diff --git a/ingen/Forge.hpp b/ingen/Forge.hpp index 9b45bde1..a2395636 100644 --- a/ingen/Forge.hpp +++ b/ingen/Forge.hpp @@ -21,7 +21,7 @@ #include "ingen/Atom.hpp" #include "ingen/ingen.h" -#include "lv2/lv2plug.in/ns/ext/atom/forge.h" +#include "lv2/lv2plug.in/ns/ext/atom/Forge.hpp" #include "raul/URI.hpp" namespace Ingen { @@ -29,9 +29,10 @@ namespace Ingen { class URIMap; /** Forge for Atoms. + * * @ingroup IngenShared */ -class INGEN_API Forge : public LV2_Atom_Forge { +class INGEN_API Forge : public lv2::atom::Forge { public: explicit Forge(URIMap& map); diff --git a/src/AtomWriter.cpp b/src/AtomWriter.cpp index cf5f40ac..d4e7f863 100644 --- a/src/AtomWriter.cpp +++ b/src/AtomWriter.cpp @@ -60,18 +60,15 @@ #include "raul/Path.hpp" #include "serd/serd.h" +using namespace lv2; + namespace Ingen { AtomWriter::AtomWriter(URIMap& map, URIs& uris, AtomSink& sink) : _map(map) , _uris(uris) , _sink(sink) -{ - lv2_atom_forge_init(&_forge, &map.urid_map_feature()->urid_map); - _out.set_forge_sink(&_forge); -} - -AtomWriter::~AtomWriter() + , _forge(&map.urid_map_feature()->urid_map, _out) { } @@ -110,41 +107,34 @@ AtomWriter::message(const Message& message) void AtomWriter::operator()(const BundleBegin& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.ingen_BundleStart, message.seq); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + ScopedMessage msg(*this, _uris.ingen_BundleStart, message.seq); } void AtomWriter::operator()(const BundleEnd& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.ingen_BundleEnd, message.seq); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + ScopedMessage msg(*this, _uris.ingen_BundleEnd, message.seq); } void AtomWriter::forge_uri(const Raul::URI& uri) { if (serd_uri_string_has_scheme((const uint8_t*)uri.c_str())) { - lv2_atom_forge_urid(&_forge, _map.map_uri(uri.c_str())); + _forge.urid(_map.map_uri(uri.c_str())); } else { - lv2_atom_forge_uri(&_forge, uri.c_str(), uri.length()); + _forge.uri(uri); } } void -AtomWriter::forge_properties(const Properties& properties) +AtomWriter::forge_properties(ScopedObject& object, const Properties& properties) { for (auto p : properties) { - lv2_atom_forge_key(&_forge, _map.map_uri(p.first.c_str())); + object.key(_map.map_uri(p.first.c_str())); if (p.second.type() == _forge.URI) { forge_uri(Raul::URI(p.second.ptr<char>())); } else { - lv2_atom_forge_atom(&_forge, p.second.size(), p.second.type()); - lv2_atom_forge_write(&_forge, p.second.get_body(), p.second.size()); + _forge.atom(p.second.size(), p.second.type(), p.second.get_body()); } } } @@ -152,36 +142,23 @@ AtomWriter::forge_properties(const Properties& properties) void AtomWriter::forge_arc(const Raul::Path& tail, const Raul::Path& head) { - LV2_Atom_Forge_Frame arc; - lv2_atom_forge_object(&_forge, &arc, 0, _uris.ingen_Arc); - lv2_atom_forge_key(&_forge, _uris.ingen_tail); + ScopedObject arc(_forge, 0, _uris.ingen_Arc); + arc.key(_uris.ingen_tail); forge_uri(path_to_uri(tail)); - lv2_atom_forge_key(&_forge, _uris.ingen_head); + arc.key(_uris.ingen_head); forge_uri(path_to_uri(head)); - lv2_atom_forge_pop(&_forge, &arc); -} - -void -AtomWriter::forge_request(LV2_Atom_Forge_Frame* frame, LV2_URID type, int32_t id) -{ - lv2_atom_forge_object(&_forge, frame, 0, type); - - if (id) { - lv2_atom_forge_key(&_forge, _uris.patch_sequenceNumber); - lv2_atom_forge_int(&_forge, id); - } } void -AtomWriter::forge_context(Resource::Graph ctx) +AtomWriter::forge_context(ScopedMessage& msg, Resource::Graph ctx) { switch (ctx) { case Resource::Graph::EXTERNAL: - lv2_atom_forge_key(&_forge, _uris.patch_context); + msg.object.key(_uris.patch_context); forge_uri(_uris.ingen_externalContext); break; case Resource::Graph::INTERNAL: - lv2_atom_forge_key(&_forge, _uris.patch_context); + msg.object.key(_uris.patch_context); forge_uri(_uris.ingen_internalContext); break; default: break; @@ -215,20 +192,15 @@ AtomWriter::forge_context(Resource::Graph ctx) void AtomWriter::operator()(const Put& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Put, message.seq); - forge_context(message.ctx); - lv2_atom_forge_key(&_forge, _uris.patch_subject); - forge_uri(message.uri); - lv2_atom_forge_key(&_forge, _uris.patch_body); + ScopedMessage msg(*this, _uris.patch_Put, message.seq); + forge_context(msg, message.ctx); - LV2_Atom_Forge_Frame body; - lv2_atom_forge_object(&_forge, &body, 0, 0); - forge_properties(message.properties); - lv2_atom_forge_pop(&_forge, &body); + msg.object.key(_uris.patch_subject); + forge_uri(message.uri); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + msg.object.key(_uris.patch_body); + ScopedObject body(_forge, 0, 0); + forge_properties(body, message.properties); } /** @page protocol @@ -260,26 +232,22 @@ AtomWriter::operator()(const Put& message) void AtomWriter::operator()(const Delta& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Patch, message.seq); - forge_context(message.ctx); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + ScopedMessage msg(*this, _uris.patch_Patch, message.seq); + forge_context(msg, message.ctx); + msg.object.key(_uris.patch_subject); forge_uri(message.uri); - lv2_atom_forge_key(&_forge, _uris.patch_remove); - LV2_Atom_Forge_Frame remove_obj; - lv2_atom_forge_object(&_forge, &remove_obj, 0, 0); - forge_properties(message.remove); - lv2_atom_forge_pop(&_forge, &remove_obj); - - lv2_atom_forge_key(&_forge, _uris.patch_add); - LV2_Atom_Forge_Frame add_obj; - lv2_atom_forge_object(&_forge, &add_obj, 0, 0); - forge_properties(message.add); - lv2_atom_forge_pop(&_forge, &add_obj); + msg.object.key(_uris.patch_remove); + { + ScopedObject remove_obj(_forge, 0, 0); + forge_properties(remove_obj, message.remove); + } - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + msg.object.key(_uris.patch_add); + { + ScopedObject add_obj(_forge, 0, 0); + forge_properties(add_obj, message.add); + } } /** @page protocol @@ -308,14 +276,11 @@ AtomWriter::operator()(const Delta& message) void AtomWriter::operator()(const Copy& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Copy, message.seq); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + ScopedMessage msg(*this, _uris.patch_Copy, message.seq); + msg.object.key(_uris.patch_subject); forge_uri(message.old_uri); - lv2_atom_forge_key(&_forge, _uris.patch_destination); + msg.object.key(_uris.patch_destination); forge_uri(message.new_uri); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); } /** @page protocol @@ -337,14 +302,11 @@ AtomWriter::operator()(const Copy& message) void AtomWriter::operator()(const Move& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Move, message.seq); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + ScopedMessage msg(*this, _uris.patch_Move, message.seq); + msg.object.key(_uris.patch_subject); forge_uri(path_to_uri(message.old_path)); - lv2_atom_forge_key(&_forge, _uris.patch_destination); + msg.object.key(_uris.patch_destination); forge_uri(path_to_uri(message.new_path)); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); } /** @page protocol @@ -365,12 +327,9 @@ AtomWriter::operator()(const Move& message) void AtomWriter::operator()(const Del& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Delete, message.seq); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + ScopedMessage msg(*this, _uris.patch_Delete, message.seq); + msg.object.key(_uris.patch_subject); forge_uri(message.uri); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); } /** @page protocol @@ -390,19 +349,18 @@ AtomWriter::operator()(const Del& message) void AtomWriter::operator()(const SetProperty& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Set, message.seq); - forge_context(message.ctx); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + ScopedMessage msg(*this, _uris.patch_Set, message.seq); + forge_context(msg, message.ctx); + + msg.object.key(_uris.patch_subject); forge_uri(message.subject); - lv2_atom_forge_key(&_forge, _uris.patch_property); - lv2_atom_forge_urid(&_forge, _map.map_uri(message.predicate.c_str())); - lv2_atom_forge_key(&_forge, _uris.patch_value); - lv2_atom_forge_atom(&_forge, message.value.size(), message.value.type()); - lv2_atom_forge_write(&_forge, message.value.get_body(), message.value.size()); - - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + + msg.object.key(_uris.patch_property); + _forge.urid(_map.map_uri(message.predicate.c_str())); + + const auto& value = message.value; + msg.object.key(_uris.patch_value); + _forge.atom(value.size(), value.type(), value.get_body()); } /** @page protocol @@ -420,10 +378,7 @@ AtomWriter::operator()(const SetProperty& message) void AtomWriter::operator()(const Undo& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.ingen_Undo, message.seq); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + ScopedMessage msg(*this, _uris.ingen_Undo, message.seq); } /** @page protocol @@ -438,10 +393,7 @@ AtomWriter::operator()(const Undo& message) void AtomWriter::operator()(const Redo& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.ingen_Redo, message.seq); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + ScopedMessage msg(*this, _uris.ingen_Redo, message.seq); } /** @page protocol @@ -459,12 +411,9 @@ AtomWriter::operator()(const Redo& message) void AtomWriter::operator()(const Get& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Get, message.seq); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + ScopedMessage msg(*this, _uris.patch_Get, message.seq); + msg.object.key(_uris.patch_subject); forge_uri(message.subject); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); } /** @page protocol @@ -493,14 +442,11 @@ AtomWriter::operator()(const Get& message) void AtomWriter::operator()(const Connect& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Put, message.seq); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + ScopedMessage msg(*this, _uris.patch_Put, message.seq); + msg.object.key(_uris.patch_subject); forge_uri(path_to_uri(Raul::Path::lca(message.tail, message.head))); - lv2_atom_forge_key(&_forge, _uris.patch_body); + msg.object.key(_uris.patch_body); forge_arc(message.tail, message.head); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); } /** @page protocol @@ -522,12 +468,9 @@ AtomWriter::operator()(const Connect& message) void AtomWriter::operator()(const Disconnect& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Delete, message.seq); - lv2_atom_forge_key(&_forge, _uris.patch_body); + ScopedMessage msg(*this, _uris.patch_Delete, message.seq); + msg.object.key(_uris.patch_body); forge_arc(message.tail, message.head); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); } /** @page protocol @@ -551,21 +494,17 @@ AtomWriter::operator()(const Disconnect& message) void AtomWriter::operator()(const DisconnectAll& message) { - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Delete, message.seq); + ScopedMessage msg(*this, _uris.patch_Delete, message.seq); - lv2_atom_forge_key(&_forge, _uris.patch_subject); + msg.object.key(_uris.patch_subject); forge_uri(path_to_uri(message.graph)); - lv2_atom_forge_key(&_forge, _uris.patch_body); - LV2_Atom_Forge_Frame arc; - lv2_atom_forge_object(&_forge, &arc, 0, _uris.ingen_Arc); - lv2_atom_forge_key(&_forge, _uris.ingen_incidentTo); - forge_uri(path_to_uri(message.path)); - lv2_atom_forge_pop(&_forge, &arc); - - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + msg.object.key(_uris.patch_body); + { + ScopedObject arc(_forge, 0, _uris.ingen_Arc); + arc.key(_uris.ingen_incidentTo); + forge_uri(path_to_uri(message.path)); + } } /** @page protocol @@ -606,18 +545,15 @@ AtomWriter::operator()(const Response& response) return; } - LV2_Atom_Forge_Frame msg; - forge_request(&msg, _uris.patch_Response, 0); - lv2_atom_forge_key(&_forge, _uris.patch_sequenceNumber); - lv2_atom_forge_int(&_forge, response.id); + ScopedMessage msg(*this, _uris.patch_Response, 0); + msg.object.key(_uris.patch_sequenceNumber); + _forge.write(response.id); if (!subject.empty() && Raul::URI::is_valid(subject)) { - lv2_atom_forge_key(&_forge, _uris.patch_subject); - lv2_atom_forge_uri(&_forge, subject.c_str(), subject.length()); + msg.object.key(_uris.patch_subject); + _forge.uri(subject); } - lv2_atom_forge_key(&_forge, _uris.patch_body); - lv2_atom_forge_int(&_forge, static_cast<int>(response.status)); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); + msg.object.key(_uris.patch_body); + _forge.write(static_cast<int32_t>(response.status)); } void diff --git a/src/Forge.cpp b/src/Forge.cpp index 52a01f40..e3891de0 100644 --- a/src/Forge.cpp +++ b/src/Forge.cpp @@ -23,16 +23,16 @@ namespace Ingen { Forge::Forge(URIMap& map) - : _map(map) + : lv2::atom::Forge(&map.urid_map_feature()->urid_map) + , _map(map) { - lv2_atom_forge_init(this, &map.urid_map_feature()->urid_map); } Atom Forge::make_urid(const Raul::URI& u) { const LV2_URID urid = _map.map_uri(u); - return Atom(sizeof(int32_t), URID, &urid); + return Atom(sizeof(urid), URID, &urid); } std::string diff --git a/src/Parser.cpp b/src/Parser.cpp index c3d6eaaf..c6650ecb 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -32,6 +32,7 @@ #include "ingen/URIs.hpp" #include "ingen/World.hpp" #include "lv2/lv2plug.in/ns/ext/atom/atom.h" +#include "lv2/lv2plug.in/ns/ext/atom/Forge.hpp" #include "serd/serd.h" #include "sord/sordmm.hpp" #include "sratom/sratom.h" @@ -131,10 +132,8 @@ get_properties(Ingen::World* world, LV2_URID_Map* map = &world->uri_map().urid_map_feature()->urid_map; Sratom* sratom = sratom_new(map); - LV2_Atom_Forge forge; - lv2_atom_forge_init(&forge, map); - - AtomForgeSink out(&forge); + AtomForgeSink out; + lv2::atom::Forge forge(map, out); const Sord::Node nil; Properties props; diff --git a/src/SocketReader.cpp b/src/SocketReader.cpp index 381a5305..3fb846a8 100644 --- a/src/SocketReader.cpp +++ b/src/SocketReader.cpp @@ -24,6 +24,7 @@ #include "ingen/SocketReader.hpp" #include "ingen/URIMap.hpp" #include "ingen/World.hpp" +#include "lv2/lv2plug.in/ns/ext/atom/Forge.hpp" #include "sord/sordmm.hpp" #include "sratom/sratom.h" @@ -101,11 +102,9 @@ SocketReader::run() } // Set up sratom and a forge to build LV2 atoms from model - Sratom* sratom = sratom_new(map); - LV2_Atom_Forge forge; - lv2_atom_forge_init(&forge, map); - - AtomForgeSink buffer(&forge); + Sratom* sratom(sratom_new(map)); + AtomForgeSink buffer; + lv2::atom::Forge forge(map, buffer); SordNode* base_uri = NULL; SordModel* model = NULL; diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp index 44f92dd8..ad2c5c5b 100644 --- a/src/server/JackDriver.cpp +++ b/src/server/JackDriver.cpp @@ -55,6 +55,7 @@ namespace Server { JackDriver::JackDriver(Engine& engine) : _engine(engine) + , _forge(&engine.world()->uri_map().urid_map_feature()->urid_map) , _sem(0) , _flag(false) , _client(NULL) @@ -67,8 +68,6 @@ JackDriver::JackDriver(Engine& engine) , _old_rolling(false) { _midi_event_type = _engine.world()->uris().midi_MidiEvent; - lv2_atom_forge_init( - &_forge, &engine.world()->uri_map().urid_map_feature()->urid_map); } JackDriver::~JackDriver() @@ -427,26 +426,26 @@ JackDriver::append_time_events(RunContext& context, _old_bpm = pos->beats_per_minute; // Build an LV2 position object to append to the buffer - LV2_Atom pos_buf[16]; - LV2_Atom_Forge_Frame frame; - lv2_atom_forge_set_buffer(&_forge, (uint8_t*)pos_buf, sizeof(pos_buf)); - lv2_atom_forge_object(&_forge, &frame, 0, uris.time_Position); - lv2_atom_forge_key(&_forge, uris.time_frame); - lv2_atom_forge_long(&_forge, pos->frame); - lv2_atom_forge_key(&_forge, uris.time_speed); - lv2_atom_forge_float(&_forge, rolling ? 1.0 : 0.0); - if (pos->valid & JackPositionBBT) { - lv2_atom_forge_key(&_forge, uris.time_barBeat); - lv2_atom_forge_float( - &_forge, pos->beat - 1 + (pos->tick / pos->ticks_per_beat)); - lv2_atom_forge_key(&_forge, uris.time_bar); - lv2_atom_forge_long(&_forge, pos->bar - 1); - lv2_atom_forge_key(&_forge, uris.time_beatUnit); - lv2_atom_forge_int(&_forge, pos->beat_type); - lv2_atom_forge_key(&_forge, uris.time_beatsPerBar); - lv2_atom_forge_float(&_forge, pos->beats_per_bar); - lv2_atom_forge_key(&_forge, uris.time_beatsPerMinute); - lv2_atom_forge_float(&_forge, pos->beats_per_minute); + LV2_Atom pos_buf[16]; + _forge.set_buffer((uint8_t*)pos_buf, sizeof(pos_buf)); + { + lv2::atom::Forge::ScopedObject position(_forge, 0, uris.time_Position); + position.key(uris.time_frame); + _forge.write(int64_t(pos->frame)); + position.key(uris.time_speed); + _forge.write(rolling ? 1.0f : 0.0f); + if (pos->valid & JackPositionBBT) { + position.key(uris.time_barBeat); + _forge.write(pos->beat - 1 + (pos->tick / pos->ticks_per_beat)); + position.key(uris.time_bar); + _forge.write(int64_t(pos->bar - 1)); + position.key(uris.time_beatUnit); + _forge.write(int32_t(pos->beat_type)); + position.key(uris.time_beatsPerBar); + _forge.write(float(pos->beats_per_bar)); + position.key(uris.time_beatsPerMinute); + _forge.write(float(pos->beats_per_minute)); + } } // Append position to buffer at offset 0 (start of this cycle) diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp index ce9af82e..9d69be7b 100644 --- a/src/server/JackDriver.hpp +++ b/src/server/JackDriver.hpp @@ -31,7 +31,7 @@ #include "raul/Semaphore.hpp" -#include "lv2/lv2plug.in/ns/ext/atom/forge.h" +#include "lv2/lv2plug.in/ns/ext/atom/Forge.hpp" #include "Driver.hpp" #include "EnginePort.hpp" @@ -144,7 +144,7 @@ protected: Engine& _engine; Ports _ports; - LV2_Atom_Forge _forge; + lv2::atom::Forge _forge; Raul::Semaphore _sem; std::atomic<bool> _flag; jack_client_t* _client; diff --git a/tests/ingen_test.cpp b/tests/ingen_test.cpp index 6ba91f33..4ff165f8 100644 --- a/tests/ingen_test.cpp +++ b/tests/ingen_test.cpp @@ -27,8 +27,8 @@ #include <glibmm/thread.h> #include <glibmm/timer.h> +#include "lv2/lv2plug.in/ns/ext/atom/Forge.hpp" #include "raul/Path.hpp" - #include "serd/serd.h" #include "sord/sordmm.hpp" #include "sratom/sratom.h" @@ -127,10 +127,8 @@ main(int argc, char** argv) sratom_set_object_mode(sratom, SRATOM_OBJECT_MODE_BLANK_SUBJECT); - LV2_Atom_Forge forge; - lv2_atom_forge_init(&forge, map); - - AtomForgeSink out(&forge); + AtomForgeSink out; + lv2::atom::Forge forge(map, out); // AtomReader to read commands from a file and send them to engine AtomReader atom_reader(world->uri_map(), @@ -75,7 +75,7 @@ def configure(conf): define_name='INGEN_HAVE_THREAD_BUILTIN') autowaf.check_pkg(conf, 'lv2', uselib_store='LV2', - atleast_version='1.15.3', mandatory=True) + atleast_version='1.15.4', mandatory=True) autowaf.check_pkg(conf, 'glibmm-2.4', uselib_store='GLIBMM', atleast_version='2.14.0', mandatory=True) autowaf.check_pkg(conf, 'gthread-2.0', uselib_store='GTHREAD', |