summaryrefslogtreecommitdiffstats
path: root/ingen
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-12-17 20:33:47 +0100
committerDavid Robillard <d@drobilla.net>2019-01-12 18:19:58 +0100
commit79fe75853ed8205674335f88e4e9c0e9dec137f9 (patch)
tree7e139dd4cff621b719ab751974883ed62cf68b6d /ingen
parentcc3d7ef610e5f93086eb46406cc600ee81a23e98 (diff)
downloadingen-79fe75853ed8205674335f88e4e9c0e9dec137f9.tar.gz
ingen-79fe75853ed8205674335f88e4e9c0e9dec137f9.tar.bz2
ingen-79fe75853ed8205674335f88e4e9c0e9dec137f9.zip
Use LV2 atom forge C++ bindings
Diffstat (limited to 'ingen')
-rw-r--r--ingen/AtomForgeSink.hpp21
-rw-r--r--ingen/AtomWriter.hpp47
-rw-r--r--ingen/Forge.hpp6
3 files changed, 46 insertions, 28 deletions
diff --git a/ingen/AtomForgeSink.hpp b/ingen/AtomForgeSink.hpp
index ed8b0b8b..872f66d8 100644
--- a/ingen/AtomForgeSink.hpp
+++ b/ingen/AtomForgeSink.hpp
@@ -32,24 +32,17 @@ namespace ingen {
class AtomForgeSink
{
public:
- explicit 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;
@@ -81,16 +74,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 bb6ab921..5d03c5e0 100644
--- a/ingen/AtomWriter.hpp
+++ b/ingen/AtomWriter.hpp
@@ -25,6 +25,7 @@
#include "ingen/Properties.hpp"
#include "ingen/Resource.hpp"
#include "ingen/ingen.h"
+#include "lv2/atom/Forge.hpp"
#include "lv2/atom/forge.h"
#include "lv2/urid/urid.h"
@@ -66,19 +67,51 @@ 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 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 139211e4..81b64998 100644
--- a/ingen/Forge.hpp
+++ b/ingen/Forge.hpp
@@ -22,8 +22,9 @@
#include <string>
#include "ingen/Atom.hpp"
+#include "ingen/URI.hpp"
#include "ingen/ingen.h"
-#include "lv2/atom/forge.h"
+#include "lv2/atom/Forge.hpp"
namespace ingen {
@@ -31,9 +32,10 @@ class URIMap;
class URI;
/** 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);