diff options
Diffstat (limited to 'src/AtomReader.cpp')
-rw-r--r-- | src/AtomReader.cpp | 197 |
1 files changed, 110 insertions, 87 deletions
diff --git a/src/AtomReader.cpp b/src/AtomReader.cpp index fc74c5d5..21cb9e40 100644 --- a/src/AtomReader.cpp +++ b/src/AtomReader.cpp @@ -14,31 +14,31 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/Atom.hpp" -#include "ingen/AtomReader.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Log.hpp" -#include "ingen/Message.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/Status.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "ingen/paths.hpp" -#include "lv2/atom/atom.h" -#include "lv2/atom/util.h" -#include "lv2/urid/urid.h" -#include "raul/Path.hpp" - -#include <boost/optional/optional.hpp> +#include <ingen/AtomReader.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Log.hpp> +#include <ingen/Message.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/paths.hpp> +#include <lv2/atom/atom.h> +#include <lv2/atom/util.h> +#include <raul/Path.hpp> #include <cstdint> #include <cstring> +#include <optional> #include <string> namespace ingen { +enum class Status; + AtomReader::AtomReader(URIMap& map, URIs& uris, Log& log, Interface& iface) : _map(map) , _uris(uris) @@ -72,51 +72,57 @@ AtomReader::get_props(const LV2_Atom_Object* obj, const Atom type(sizeof(int32_t), _uris.atom_URID, &obj->body.otype); props.emplace(_uris.rdf_type, type); } - LV2_ATOM_OBJECT_FOREACH(obj, p) { + LV2_ATOM_OBJECT_FOREACH (obj, p) { Atom val; get_atom(&p->value, val); props.emplace(URI(_map.unmap_uri(p->key)), val); } } -boost::optional<URI> +std::optional<URI> AtomReader::atom_to_uri(const LV2_Atom* atom) { if (!atom) { - return boost::optional<URI>(); - } else if (atom->type == _uris.atom_URI) { - const char* str = (const char*)LV2_ATOM_BODY_CONST(atom); + return {}; + } + + if (atom->type == _uris.atom_URI) { + const char* str = static_cast<const char*>(LV2_ATOM_BODY_CONST(atom)); if (URI::is_valid(str)) { return URI(str); - } else { - _log.warn("Invalid URI <%1%>\n", str); } + + _log.warn("Invalid URI <%1%>\n", str); } else if (atom->type == _uris.atom_Path) { - const char* str = (const char*)LV2_ATOM_BODY_CONST(atom); + const char* str = static_cast<const char*>(LV2_ATOM_BODY_CONST(atom)); if (!strncmp(str, "file://", 5)) { return URI(str); - } else { - return URI(std::string("file://") + str); } - } else if (atom->type == _uris.atom_URID) { - const char* str = _map.unmap_uri(((const LV2_Atom_URID*)atom)->body); + + return URI(std::string("file://") + str); + } + + if (atom->type == _uris.atom_URID) { + const char* str = + _map.unmap_uri(reinterpret_cast<const LV2_Atom_URID*>(atom)->body); if (str) { return URI(str); - } else { - _log.warn("Unknown URID %1%\n", str); } + + _log.warn("Unknown URID %1%\n", str); } - return boost::optional<URI>(); + + return {}; } -boost::optional<Raul::Path> +std::optional<raul::Path> AtomReader::atom_to_path(const LV2_Atom* atom) { - boost::optional<URI> uri = atom_to_uri(atom); + std::optional<URI> uri = atom_to_uri(atom); if (uri && uri_is_path(*uri)) { return uri_to_path(*uri); } - return boost::optional<Raul::Path>(); + return {}; } Resource::Graph @@ -124,7 +130,7 @@ AtomReader::atom_to_context(const LV2_Atom* atom) { Resource::Graph ctx = Resource::Graph::DEFAULT; if (atom) { - boost::optional<URI> maybe_uri = atom_to_uri(atom); + std::optional<URI> maybe_uri = atom_to_uri(atom); if (maybe_uri) { ctx = Resource::uri_to_graph(*maybe_uri); } else { @@ -141,7 +147,7 @@ AtomReader::is_message(const URIs& uris, const LV2_Atom* msg) return false; } - const auto* obj = (const LV2_Atom_Object*)msg; + const auto* obj = reinterpret_cast<const LV2_Atom_Object*>(msg); return (obj->body.otype == uris.patch_Get || obj->body.otype == uris.patch_Delete || obj->body.otype == uris.patch_Put || @@ -159,19 +165,19 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) return false; } - const auto* obj = (const LV2_Atom_Object*)msg; - const LV2_Atom* subject = nullptr; - const LV2_Atom* number = nullptr; + const auto* const obj = reinterpret_cast<const LV2_Atom_Object*>(msg); + const LV2_Atom* subject = nullptr; + const LV2_Atom* number = nullptr; lv2_atom_object_get(obj, - (LV2_URID)_uris.patch_subject, &subject, - (LV2_URID)_uris.patch_sequenceNumber, &number, + _uris.patch_subject.urid(), &subject, + _uris.patch_sequenceNumber.urid(), &number, nullptr); - const boost::optional<URI> subject_uri = atom_to_uri(subject); + const std::optional<URI> subject_uri = atom_to_uri(subject); const int32_t seq = ((number && number->type == _uris.atom_Int) - ? ((const LV2_Atom_Int*)number)->body + ? reinterpret_cast<const LV2_Atom_Int*>(number)->body : default_id); if (obj->body.otype == _uris.patch_Get) { @@ -182,27 +188,35 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) _iface(BundleBegin{seq}); } else if (obj->body.otype == _uris.ingen_BundleEnd) { _iface(BundleEnd{seq}); + } else if (obj->body.otype == _uris.ingen_Undo) { + _iface(Undo{seq}); + } else if (obj->body.otype == _uris.ingen_Redo) { + _iface(Redo{seq}); } else if (obj->body.otype == _uris.patch_Delete) { const LV2_Atom_Object* body = nullptr; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_body, &body, 0); + lv2_atom_object_get(obj, + _uris.patch_body.urid(), &body, + 0); if (subject_uri && !body) { _iface(Del{seq, *subject_uri}); return true; - } else if (body && body->body.otype == _uris.ingen_Arc) { + } + + if (body && body->body.otype == _uris.ingen_Arc) { const LV2_Atom* tail = nullptr; const LV2_Atom* head = nullptr; const LV2_Atom* incidentTo = nullptr; lv2_atom_object_get(body, - (LV2_URID)_uris.ingen_tail, &tail, - (LV2_URID)_uris.ingen_head, &head, - (LV2_URID)_uris.ingen_incidentTo, &incidentTo, + _uris.ingen_tail.urid(), &tail, + _uris.ingen_head.urid(), &head, + _uris.ingen_incidentTo.urid(), &incidentTo, nullptr); - boost::optional<Raul::Path> subject_path(atom_to_path(subject)); - boost::optional<Raul::Path> tail_path(atom_to_path(tail)); - boost::optional<Raul::Path> head_path(atom_to_path(head)); - boost::optional<Raul::Path> other_path(atom_to_path(incidentTo)); + std::optional<raul::Path> subject_path(atom_to_path(subject)); + std::optional<raul::Path> tail_path(atom_to_path(tail)); + std::optional<raul::Path> head_path(atom_to_path(head)); + std::optional<raul::Path> other_path(atom_to_path(incidentTo)); if (tail_path && head_path) { _iface(Disconnect{seq, *tail_path, *head_path}); } else if (subject_path && other_path) { @@ -216,13 +230,15 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) const LV2_Atom_Object* body = nullptr; const LV2_Atom* context = nullptr; lv2_atom_object_get(obj, - (LV2_URID)_uris.patch_body, &body, - (LV2_URID)_uris.patch_context, &context, + _uris.patch_body.urid(), &body, + _uris.patch_context.urid(), &context, 0); if (!body) { _log.warn("Put message has no body\n"); return false; - } else if (!subject_uri) { + } + + if (!subject_uri) { _log.warn("Put message has no subject\n"); return false; } @@ -231,16 +247,16 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) LV2_Atom* tail = nullptr; LV2_Atom* head = nullptr; lv2_atom_object_get(body, - (LV2_URID)_uris.ingen_tail, &tail, - (LV2_URID)_uris.ingen_head, &head, + _uris.ingen_tail.urid(), &tail, + _uris.ingen_head.urid(), &head, nullptr); if (!tail || !head) { _log.warn("Arc has no tail or head\n"); return false; } - boost::optional<Raul::Path> tail_path(atom_to_path(tail)); - boost::optional<Raul::Path> head_path(atom_to_path(head)); + std::optional<raul::Path> tail_path(atom_to_path(tail)); + std::optional<raul::Path> head_path(atom_to_path(head)); if (tail_path && head_path) { _iface(Connect{seq, *tail_path, *head_path}); } else { @@ -261,14 +277,17 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) const LV2_Atom* value = nullptr; const LV2_Atom* context = nullptr; lv2_atom_object_get(obj, - (LV2_URID)_uris.patch_property, &prop, - (LV2_URID)_uris.patch_value, &value, - (LV2_URID)_uris.patch_context, &context, + _uris.patch_property.urid(), &prop, + _uris.patch_value.urid(), &value, + _uris.patch_context.urid(), &context, 0); - if (!prop || ((const LV2_Atom*)prop)->type != _uris.atom_URID) { + if (!prop || + reinterpret_cast<const LV2_Atom*>(prop)->type != _uris.atom_URID) { _log.warn("Set message missing property\n"); return false; - } else if (!value) { + } + + if (!value) { _log.warn("Set message missing value\n"); return false; } @@ -290,14 +309,16 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) const LV2_Atom_Object* add = nullptr; const LV2_Atom* context = nullptr; lv2_atom_object_get(obj, - (LV2_URID)_uris.patch_remove, &remove, - (LV2_URID)_uris.patch_add, &add, - (LV2_URID)_uris.patch_context, &context, + _uris.patch_remove.urid(), &remove, + _uris.patch_add.urid(), &add, + _uris.patch_context.urid(), &context, 0); if (!remove) { _log.warn("Patch message has no remove\n"); return false; - } else if (!add) { + } + + if (!add) { _log.warn("Patch message has no add\n"); return false; } @@ -316,20 +337,20 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) return false; } + if (!subject_uri) { + _log.warn("Copy message has non-path subject\n"); + return false; + } + const LV2_Atom* dest = nullptr; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_destination, &dest, 0); + lv2_atom_object_get(obj, _uris.patch_destination.urid(), &dest, 0); if (!dest) { _log.warn("Copy message has no destination\n"); return false; } - boost::optional<URI> subject_uri(atom_to_uri(subject)); - if (!subject_uri) { - _log.warn("Copy message has non-path subject\n"); - return false; - } - boost::optional<URI> dest_uri(atom_to_uri(dest)); + std::optional<URI> dest_uri(atom_to_uri(dest)); if (!dest_uri) { _log.warn("Copy message has non-URI destination\n"); return false; @@ -343,19 +364,19 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) } const LV2_Atom* dest = nullptr; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_destination, &dest, 0); + lv2_atom_object_get(obj, _uris.patch_destination.urid(), &dest, 0); if (!dest) { _log.warn("Move message has no destination\n"); return false; } - boost::optional<Raul::Path> subject_path(atom_to_path(subject)); + std::optional<raul::Path> subject_path(atom_to_path(subject)); if (!subject_path) { _log.warn("Move message has non-path subject\n"); return false; } - boost::optional<Raul::Path> dest_path(atom_to_path(dest)); + std::optional<raul::Path> dest_path(atom_to_path(dest)); if (!dest_path) { _log.warn("Move message has non-path destination\n"); return false; @@ -363,21 +384,23 @@ AtomReader::write(const LV2_Atom* msg, int32_t default_id) _iface(Move{seq, *subject_path, *dest_path}); } else if (obj->body.otype == _uris.patch_Response) { - const LV2_Atom* seq = nullptr; const LV2_Atom* body = nullptr; lv2_atom_object_get(obj, - (LV2_URID)_uris.patch_sequenceNumber, &seq, - (LV2_URID)_uris.patch_body, &body, + _uris.patch_body.urid(), &body, 0); - if (!seq || seq->type != _uris.atom_Int) { + if (!number || number->type != _uris.atom_Int) { _log.warn("Response message has no sequence number\n"); return false; - } else if (!body || body->type != _uris.atom_Int) { + } + + if (!body || body->type != _uris.atom_Int) { _log.warn("Response message body is not integer\n"); return false; } - _iface(Response{((const LV2_Atom_Int*)seq)->body, - (ingen::Status)((const LV2_Atom_Int*)body)->body, + + _iface(Response{reinterpret_cast<const LV2_Atom_Int*>(number)->body, + static_cast<ingen::Status>( + reinterpret_cast<const LV2_Atom_Int*>(body)->body), subject_uri ? subject_uri->c_str() : ""}); } else { _log.warn("Unknown object type <%1%>\n", |