From 254b434f0a79fea54bd963e8ff2e845a5b0cd3a6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 19 Mar 2012 20:16:46 +0000 Subject: Partially functioning communication between Ingen LV2 plugin and UI. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4078 a436a847-0d15-0410-975c-d299462d15a1 --- src/shared/AtomReader.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/shared/AtomReader.cpp (limited to 'src/shared/AtomReader.cpp') diff --git a/src/shared/AtomReader.cpp b/src/shared/AtomReader.cpp new file mode 100644 index 00000000..009aace6 --- /dev/null +++ b/src/shared/AtomReader.cpp @@ -0,0 +1,83 @@ +/* This file is part of Ingen. + * Copyright 2012 David Robillard + * + * Ingen 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 2 of the License, or (at your option) any later + * version. + * + * Ingen 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 details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "ingen/shared/AtomReader.hpp" +#include "lv2/lv2plug.in/ns/ext/atom/util.h" +#include "raul/log.hpp" + +namespace Ingen { +namespace Shared { + +AtomReader::AtomReader(LV2URIMap& map, URIs& uris, Forge& forge, Interface& iface) + : _map(map) + , _uris(uris) + , _forge(forge) + , _iface(iface) +{ +} + +void +AtomReader::write(const LV2_Atom* msg) +{ + if (msg->type != _uris.atom_Blank) { + Raul::warn << "Unknown message type " << msg->type << std::endl; + return; + } + + const LV2_Atom_Object* obj = (const LV2_Atom_Object*)msg; + const LV2_Atom* subject = NULL; + + lv2_object_get(obj, (LV2_URID)_uris.patch_subject, &subject, NULL); + const char* subject_uri = subject ? (const char*)LV2_ATOM_BODY(subject) : NULL; + if (obj->body.otype == _uris.patch_Get) { + Raul::warn << "ATOM GET " << subject_uri << std::endl; + _iface.set_response_id(1); + _iface.get(subject_uri); + } else if (obj->body.otype == _uris.patch_Put) { + Raul::warn << "PUT" << std::endl; + const LV2_Atom_Object* body = NULL; + lv2_object_get(obj, (LV2_URID)_uris.patch_body, &body, 0); + if (!body) { + Raul::warn << "NO BODY" << std::endl; + return; + } + + Ingen::Resource::Properties props; + LV2_OBJECT_FOREACH(body, i) { + LV2_Atom_Property_Body* p = lv2_object_iter_get(i); + props.insert(std::make_pair(_map.unmap_uri(p->key), + _forge.alloc(p->value.size, + p->value.type, + LV2_ATOM_BODY(&p->value)))); + } + + if (subject_uri) { + _iface.put(subject_uri, props); + } else { + Raul::warn << "Put message has no subject, ignored" << std::endl; + } + + } else { + Raul::warn << "HANDLE MESSAGE TYPE " << obj->body.otype << std::endl; + } +} + +} // namespace Shared +} // namespace Ingen -- cgit v1.2.1