diff options
author | David Robillard <d@drobilla.net> | 2012-07-31 00:14:50 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-07-31 00:14:50 +0000 |
commit | 629fb50716083c71146340de97eb8651679ca9fb (patch) | |
tree | 9c5f25fdfd24f3cdb89924062f291a6647580878 /src/shared | |
parent | 6297b8805c95dd1831ee9a0b9639ae41d00a1473 (diff) | |
download | ingen-629fb50716083c71146340de97eb8651679ca9fb.tar.gz ingen-629fb50716083c71146340de97eb8651679ca9fb.tar.bz2 ingen-629fb50716083c71146340de97eb8651679ca9fb.zip |
Merge Ingen::Shared namespace into Ingen namespace and core libingen library.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4579 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/AtomReader.cpp | 276 | ||||
-rw-r--r-- | src/shared/AtomWriter.cpp | 301 | ||||
-rw-r--r-- | src/shared/Builder.cpp | 55 | ||||
-rw-r--r-- | src/shared/ClashAvoider.cpp | 206 | ||||
-rw-r--r-- | src/shared/Configuration.cpp | 56 | ||||
-rw-r--r-- | src/shared/Forge.cpp | 56 | ||||
-rw-r--r-- | src/shared/LV2Features.cpp | 65 | ||||
-rw-r--r-- | src/shared/Store.cpp | 101 | ||||
-rw-r--r-- | src/shared/URIMap.cpp | 97 | ||||
-rw-r--r-- | src/shared/URIs.cpp | 128 | ||||
-rw-r--r-- | src/shared/World.cpp | 323 | ||||
-rw-r--r-- | src/shared/runtime_paths.cpp | 116 | ||||
-rw-r--r-- | src/shared/wscript | 44 |
13 files changed, 0 insertions, 1824 deletions
diff --git a/src/shared/AtomReader.cpp b/src/shared/AtomReader.cpp deleted file mode 100644 index 862c61b1..00000000 --- a/src/shared/AtomReader.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <utility> - -#include "ingen/shared/AtomReader.hpp" -#include "ingen/shared/URIMap.hpp" -#include "lv2/lv2plug.in/ns/ext/atom/util.h" -#include "raul/Path.hpp" -#include "raul/log.hpp" - -namespace Ingen { -namespace Shared { - -AtomReader::AtomReader(URIMap& map, URIs& uris, Forge& forge, Interface& iface) - : _map(map) - , _uris(uris) - , _forge(forge) - , _iface(iface) -{ -} - -void -AtomReader::get_atom(const LV2_Atom* in, Raul::Atom& out) -{ - if (in) { - if (in->type == _uris.atom_URID) { - const LV2_Atom_URID* urid = (const LV2_Atom_URID*)in; - const char* uri = _map.unmap_uri(urid->body); - if (uri) { - out = _forge.alloc_uri(_map.unmap_uri(urid->body)); - } else { - Raul::error(Raul::fmt("Unable to unmap URID %1%\n") - % urid->body); - } - } else { - out = _forge.alloc(in->size, in->type, LV2_ATOM_BODY(in)); - } - } -} - -void -AtomReader::get_props(const LV2_Atom_Object* obj, - Ingen::Resource::Properties& props) -{ - if (obj->body.otype) { - props.insert( - std::make_pair(_uris.rdf_type, - _forge.alloc_uri(_map.unmap_uri(obj->body.otype)))); - } - LV2_ATOM_OBJECT_FOREACH(obj, p) { - Raul::Atom val; - get_atom(&p->value, val); - props.insert(std::make_pair(_map.unmap_uri(p->key), val)); - } -} - -const char* -AtomReader::atom_to_uri(const LV2_Atom* atom) -{ - if (atom && atom->type == _uris.atom_URI) { - return (const char*)LV2_ATOM_BODY(atom); - } else if (atom && atom->type == _uris.atom_URID) { - return _map.unmap_uri(((LV2_Atom_URID*)atom)->body); - } else { - return NULL; - } -} - -bool -AtomReader::is_message(URIs& uris, const LV2_Atom* msg) -{ - if (msg->type != uris.atom_Blank && msg->type != uris.atom_Resource) { - return false; - } - - const LV2_Atom_Object* obj = (const LV2_Atom_Object*)msg; - return (obj->body.otype == uris.patch_Get || - obj->body.otype == uris.patch_Delete || - obj->body.otype == uris.patch_Put || - obj->body.otype == uris.patch_Patch || - obj->body.otype == uris.patch_Move || - obj->body.otype == uris.patch_Response); -} - -bool -AtomReader::write(const LV2_Atom* msg) -{ - if (msg->type != _uris.atom_Blank && msg->type != _uris.atom_Resource) { - Raul::warn << (Raul::fmt("Unknown message type <%1%>\n") - % _map.unmap_uri(msg->type)).str(); - return false; - } - - const LV2_Atom_Object* obj = (const LV2_Atom_Object*)msg; - const LV2_Atom* subject = NULL; - - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_subject, &subject, NULL); - const char* subject_uri = atom_to_uri(subject); - - if (obj->body.otype == _uris.patch_Get) { - _iface.set_response_id(obj->body.id); - _iface.get(subject_uri); - } else if (obj->body.otype == _uris.patch_Delete) { - const LV2_Atom_Object* body = NULL; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_body, &body, 0); - - if (subject_uri && !body) { - _iface.del(subject_uri); - return true; - } else if (body && body->body.otype == _uris.ingen_Edge) { - const LV2_Atom* tail = NULL; - const LV2_Atom* head = NULL; - const LV2_Atom* incidentTo = NULL; - lv2_atom_object_get(body, - (LV2_URID)_uris.ingen_tail, &tail, - (LV2_URID)_uris.ingen_head, &head, - (LV2_URID)_uris.ingen_incidentTo, &incidentTo, - NULL); - - Raul::Atom tail_atom; - Raul::Atom head_atom; - Raul::Atom incidentTo_atom; - get_atom(tail, tail_atom); - get_atom(head, head_atom); - get_atom(incidentTo, incidentTo_atom); - if (tail_atom.is_valid() && head_atom.is_valid()) { - _iface.disconnect(Raul::Path(tail_atom.get_uri()), - Raul::Path(head_atom.get_uri())); - } else if (incidentTo_atom.is_valid()) { - _iface.disconnect_all(subject_uri, - Raul::Path(incidentTo_atom.get_uri())); - } else { - Raul::warn << "Delete of unknown object." << std::endl; - return false; - } - } - } else if (obj->body.otype == _uris.patch_Put) { - const LV2_Atom_Object* body = NULL; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_body, &body, 0); - if (!body) { - Raul::warn << "Put message has no body" << std::endl; - return false; - } else if (!subject_uri) { - Raul::warn << "Put message has no subject" << std::endl; - return false; - } - - if (body->body.otype == _uris.ingen_Edge) { - LV2_Atom* tail = NULL; - LV2_Atom* head = NULL; - lv2_atom_object_get(body, - (LV2_URID)_uris.ingen_tail, &tail, - (LV2_URID)_uris.ingen_head, &head, - NULL); - if (!tail || !head) { - Raul::warn << "Edge has no tail or head" << std::endl; - return false; - } - - Raul::Atom tail_atom; - Raul::Atom head_atom; - get_atom(tail, tail_atom); - get_atom(head, head_atom); - _iface.connect(Raul::Path(tail_atom.get_uri()), - Raul::Path(head_atom.get_uri())); - } else { - Ingen::Resource::Properties props; - get_props(body, props); - _iface.set_response_id(obj->body.id); - _iface.put(subject_uri, props); - } - } else if (obj->body.otype == _uris.patch_Set) { - const LV2_Atom_Object* body = NULL; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_body, &body, 0); - if (!body) { - Raul::warn << "Set message has no body" << std::endl; - return false; - } else if (!subject_uri) { - Raul::warn << "Set message has no subject" << std::endl; - return false; - } - - LV2_ATOM_OBJECT_FOREACH(body, p) { - Raul::Atom val; - get_atom(&p->value, val); - _iface.set_property(subject_uri, _map.unmap_uri(p->key), val); - } - } else if (obj->body.otype == _uris.patch_Patch) { - if (!subject_uri) { - Raul::warn << "Put message has no subject" << std::endl; - return false; - } - - const LV2_Atom_Object* remove = NULL; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_remove, &remove, 0); - if (!remove) { - Raul::warn << "Patch message has no remove" << std::endl; - return false; - } - - const LV2_Atom_Object* add = NULL; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_add, &add, 0); - if (!add) { - Raul::warn << "Patch message has no add" << std::endl; - return false; - } - - Ingen::Resource::Properties add_props; - get_props(remove, add_props); - - Ingen::Resource::Properties remove_props; - get_props(remove, remove_props); - - _iface.delta(subject_uri, remove_props, add_props); - } else if (obj->body.otype == _uris.patch_Move) { - if (!subject_uri) { - Raul::warn << "Move message has no subject" << std::endl; - return false; - } - - const LV2_Atom* dest = NULL; - lv2_atom_object_get(obj, (LV2_URID)_uris.patch_destination, &dest, 0); - if (!dest) { - Raul::warn << "Move message has no destination" << std::endl; - return false; - } - - const char* dest_uri = atom_to_uri(dest); - if (!dest_uri) { - Raul::warn << "Move message destination is not a URI" << std::endl; - return false; - } - - _iface.move(subject_uri, dest_uri); - } else if (obj->body.otype == _uris.patch_Response) { - const LV2_Atom* request = NULL; - const LV2_Atom* body = NULL; - lv2_atom_object_get(obj, - (LV2_URID)_uris.patch_request, &request, - (LV2_URID)_uris.patch_body, &body, - 0); - if (!request || request->type != _uris.atom_Int) { - Raul::warn << "Response message has no request" << std::endl; - return false; - } else if (!body || body->type != _uris.atom_Int) { - Raul::warn << "Response message body is not integer" << std::endl; - return false; - } - _iface.response(((LV2_Atom_Int*)request)->body, - (Ingen::Status)((LV2_Atom_Int*)body)->body, - subject_uri); - } else { - Raul::warn << "Unknown object type <" - << _map.unmap_uri(obj->body.otype) - << ">" << std::endl; - } - - return true; -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/AtomWriter.cpp b/src/shared/AtomWriter.cpp deleted file mode 100644 index 80bd0156..00000000 --- a/src/shared/AtomWriter.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <string> - -#include "ingen/shared/AtomSink.hpp" -#include "ingen/shared/AtomWriter.hpp" -#include "ingen/shared/URIMap.hpp" -#include "raul/Path.hpp" -#include "serd/serd.h" - -namespace Ingen { -namespace Shared { - -static LV2_Atom_Forge_Ref -forge_sink(LV2_Atom_Forge_Sink_Handle handle, - const void* buf, - uint32_t size) -{ - SerdChunk* chunk = (SerdChunk*)handle; - const LV2_Atom_Forge_Ref ref = chunk->len + 1; - serd_chunk_sink(buf, size, chunk); - return ref; -} - -static LV2_Atom* -forge_deref(LV2_Atom_Forge_Sink_Handle handle, LV2_Atom_Forge_Ref ref) -{ - SerdChunk* chunk = (SerdChunk*)handle; - return (LV2_Atom*)(chunk->buf + ref - 1); -} - -AtomWriter::AtomWriter(URIMap& map, URIs& uris, AtomSink& sink) - : _map(map) - , _uris(uris) - , _sink(sink) - , _id(1) -{ - _out.buf = NULL; - _out.len = 0; - lv2_atom_forge_init(&_forge, &map.urid_map_feature()->urid_map); - lv2_atom_forge_set_sink(&_forge, forge_sink, forge_deref, &_out); -} - -void -AtomWriter::finish_msg() -{ - _sink.write((LV2_Atom*)_out.buf); - _out.len = 0; -} - -int32_t -AtomWriter::next_id() -{ - if (_id == -1) { - return 0; - } else { - return ++_id; - } -} - -void -AtomWriter::bundle_begin() -{ -} - -void -AtomWriter::bundle_end() -{ -} - -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())); - } else { - lv2_atom_forge_uri(&_forge, uri.c_str(), uri.length()); - } -} - -void -AtomWriter::forge_properties(const Resource::Properties& properties) -{ - for (Resource::Properties::const_iterator i = properties.begin(); - i != properties.end(); ++i) { - lv2_atom_forge_property_head(&_forge, _map.map_uri(i->first.c_str()), 0); - if (i->second.type() == _forge.URI) { - forge_uri(i->second.get_uri()); - } else { - lv2_atom_forge_atom(&_forge, i->second.size(), i->second.type()); - lv2_atom_forge_write(&_forge, i->second.get_body(), i->second.size()); - } - } -} - -void -AtomWriter::forge_edge(const Raul::URI& tail, const Raul::URI& head) -{ - LV2_Atom_Forge_Frame edge; - lv2_atom_forge_blank(&_forge, &edge, 0, _uris.ingen_Edge); - lv2_atom_forge_property_head(&_forge, _uris.ingen_tail, 0); - forge_uri(tail); - lv2_atom_forge_property_head(&_forge, _uris.ingen_head, 0); - forge_uri(head); - lv2_atom_forge_pop(&_forge, &edge); -} - -void -AtomWriter::put(const Raul::URI& uri, - const Resource::Properties& properties, - Resource::Graph ctx) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Put); - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(uri); - lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0); - - LV2_Atom_Forge_Frame body; - lv2_atom_forge_blank(&_forge, &body, 0, 0); - forge_properties(properties); - lv2_atom_forge_pop(&_forge, &body); - - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::delta(const Raul::URI& uri, - const Resource::Properties& remove, - const Resource::Properties& add) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Patch); - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(uri); - - lv2_atom_forge_property_head(&_forge, _uris.patch_remove, 0); - LV2_Atom_Forge_Frame remove_obj; - lv2_atom_forge_blank(&_forge, &remove_obj, 0, 0); - forge_properties(remove); - lv2_atom_forge_pop(&_forge, &remove_obj); - - lv2_atom_forge_property_head(&_forge, _uris.patch_add, 0); - LV2_Atom_Forge_Frame add_obj; - lv2_atom_forge_blank(&_forge, &add_obj, 0, 0); - forge_properties(add); - lv2_atom_forge_pop(&_forge, &add_obj); - - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::move(const Raul::Path& old_path, - const Raul::Path& new_path) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Move); - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(old_path); - lv2_atom_forge_property_head(&_forge, _uris.patch_destination, 0); - forge_uri(new_path); -} - -void -AtomWriter::del(const Raul::URI& uri) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Delete); - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(uri); -} - -void -AtomWriter::connect(const Raul::Path& tail, - const Raul::Path& head) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Put); - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(Raul::Path::lca(tail, head)); - lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0); - forge_edge(tail, head); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::disconnect(const Raul::Path& tail, - const Raul::Path& head) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Delete); - lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0); - forge_edge(tail, head); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::disconnect_all(const Raul::Path& parent_patch_path, - const Raul::Path& path) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Delete); - - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(parent_patch_path); - - lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0); - LV2_Atom_Forge_Frame edge; - lv2_atom_forge_blank(&_forge, &edge, 0, _uris.ingen_Edge); - lv2_atom_forge_property_head(&_forge, _uris.ingen_incidentTo, 0); - forge_uri(path); - lv2_atom_forge_pop(&_forge, &edge); - - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::set_property(const Raul::URI& subject, - const Raul::URI& predicate, - const Raul::Atom& value) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Set); - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(subject); - lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0); - - LV2_Atom_Forge_Frame body; - lv2_atom_forge_blank(&_forge, &body, 0, 0); - lv2_atom_forge_property_head(&_forge, _map.map_uri(predicate.c_str()), 0); - lv2_atom_forge_atom(&_forge, value.size(), value.type()); - lv2_atom_forge_write(&_forge, value.get_body(), value.size()); - lv2_atom_forge_pop(&_forge, &body); - - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::set_response_id(int32_t id) -{ -} - -void -AtomWriter::get(const Raul::URI& uri) -{ - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Get); - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - forge_uri(uri); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::response(int32_t id, Status status, const std::string& subject) -{ - if (id == -1) { - return; - } - - LV2_Atom_Forge_Frame msg; - lv2_atom_forge_blank(&_forge, &msg, next_id(), _uris.patch_Response); - lv2_atom_forge_property_head(&_forge, _uris.patch_request, 0); - lv2_atom_forge_int(&_forge, id); - if (!subject.empty() && Raul::URI::is_valid(subject)) { - lv2_atom_forge_property_head(&_forge, _uris.patch_subject, 0); - lv2_atom_forge_uri(&_forge, subject.c_str(), subject.length()); - } - lv2_atom_forge_property_head(&_forge, _uris.patch_body, 0); - lv2_atom_forge_int(&_forge, status); - lv2_atom_forge_pop(&_forge, &msg); - finish_msg(); -} - -void -AtomWriter::error(const std::string& msg) -{ -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/Builder.cpp b/src/shared/Builder.cpp deleted file mode 100644 index dadd2989..00000000 --- a/src/shared/Builder.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "ingen/Edge.hpp" -#include "ingen/GraphObject.hpp" -#include "ingen/Interface.hpp" -#include "ingen/shared/Builder.hpp" -#include "ingen/shared/URIs.hpp" -#include "raul/Atom.hpp" -#include "raul/Path.hpp" - -using namespace std; - -namespace Ingen { -namespace Shared { - -Builder::Builder(Shared::URIs& uris, Interface& interface) - : _uris(uris) - , _interface(interface) -{ -} - -void -Builder::build(SharedPtr<const GraphObject> object) -{ - _interface.put(object->path(), object->properties()); -} - -void -Builder::connect(SharedPtr<const GraphObject> object) -{ - if (object->graph_type() == GraphObject::PATCH) { - for (GraphObject::Edges::const_iterator i = object->edges().begin(); - i != object->edges().end(); ++i) { - _interface.connect(i->second->tail_path(), i->second->head_path()); - } - return; - } -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/ClashAvoider.cpp b/src/shared/ClashAvoider.cpp deleted file mode 100644 index 8e6683e8..00000000 --- a/src/shared/ClashAvoider.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <cstdio> -#include <sstream> -#include <string> -#include <utility> - -#include "raul/log.hpp" - -#include "ingen/shared/ClashAvoider.hpp" -#include "ingen/shared/Store.hpp" - -using namespace std; - -namespace Ingen { -namespace Shared { - -const Raul::URI -ClashAvoider::map_uri(const Raul::URI& in) -{ - if (Raul::Path::is_path(in)) - return map_path(in.str()); - else - return in; -} - -const Raul::Path -ClashAvoider::map_path(const Raul::Path& in) -{ - Raul::debug << "MAP PATH: " << in; - - unsigned offset = 0; - bool has_offset = false; - const size_t pos = in.find_last_of('_'); - if (pos != string::npos && pos != (in.length()-1)) { - const std::string trailing = in.substr(pos + 1); - has_offset = (sscanf(trailing.c_str(), "%u", &offset) > 0); - } - - Raul::debug << "OFFSET: " << offset << endl; - - // Path without _n suffix - Raul::Path base_path = in; - if (has_offset) - base_path = base_path.substr(0, base_path.find_last_of('_')); - - Raul::debug << "BASE: " << base_path << endl; - - SymbolMap::iterator m = _symbol_map.find(in); - if (m != _symbol_map.end()) { - Raul::debug << " (1) " << m->second << endl; - return m->second; - } else { - typedef std::pair<SymbolMap::iterator, bool> InsertRecord; - - // See if parent is mapped - Raul::Path parent = in.parent(); - do { - Raul::debug << "CHECK: " << parent << endl; - SymbolMap::iterator p = _symbol_map.find(parent); - if (p != _symbol_map.end()) { - const Raul::Path mapped = p->second.base() + in.substr(parent.base().length()); - InsertRecord i = _symbol_map.insert(make_pair(in, mapped)); - Raul::debug << " (2) " << i.first->second << endl; - return i.first->second; - } - parent = parent.parent(); - } while (!parent.is_root()); - - // No clash, use symbol unmodified - if (!exists(in) && _symbol_map.find(in) == _symbol_map.end()) { - InsertRecord i = _symbol_map.insert(make_pair(in, in)); - assert(i.second); - Raul::debug << " (3) " << i.first->second << endl; - return i.first->second; - - // Append _2 _3 etc until an unused symbol is found - } else { - while (true) { - Offsets::iterator o = _offsets.find(base_path); - if (o != _offsets.end()) { - offset = ++o->second; - } else { - string parent_str = in.parent().base(); - parent_str = parent_str.substr(0, parent_str.find_last_of("/")); - if (parent_str.empty()) - parent_str = "/"; - Raul::debug << "PARENT: " << parent_str << endl; - } - - if (offset == 0) - offset = 2; - - std::stringstream ss; - ss << base_path << "_" << offset; - if (!exists(ss.str())) { - string name = base_path.symbol(); - if (name == "") - name = "_"; - string str = ss.str(); - InsertRecord i = _symbol_map.insert(make_pair(in, str)); - Raul::debug << "HIT: offset = " << offset << ", str = " << str << endl; - offset = _store.child_name_offset(in.parent(), name, false); - _offsets.insert(make_pair(base_path, offset)); - Raul::debug << " (4) " << i.first->second << endl; - return i.first->second; - } else { - Raul::debug << "MISSED OFFSET: " << in << " => " << ss.str() << endl; - if (o != _offsets.end()) - offset = ++o->second; - else - ++offset; - } - } - } - } -} - -bool -ClashAvoider::exists(const Raul::Path& path) const -{ - bool exists = (_store.find(path) != _store.end()); - if (exists) - return true; - - if (_also_avoid) - return (_also_avoid->find(path) != _also_avoid->end()); - else - return false; -} - -void -ClashAvoider::put(const Raul::URI& path, - const Resource::Properties& properties, - Resource::Graph ctx) -{ - _target.put(map_uri(path), properties, ctx); -} - -void -ClashAvoider::delta(const Raul::URI& path, - const Resource::Properties& remove, - const Resource::Properties& add) -{ - _target.delta(map_uri(path), remove, add); -} - -void -ClashAvoider::move(const Raul::Path& old_path, - const Raul::Path& new_path) -{ - _target.move(map_path(old_path), map_path(new_path)); -} - -void -ClashAvoider::connect(const Raul::Path& tail, - const Raul::Path& head) -{ - _target.connect(map_path(tail), map_path(head)); -} - -void -ClashAvoider::disconnect(const Raul::Path& tail, - const Raul::Path& head) -{ - _target.disconnect(map_path(tail), map_path(head)); -} - -void -ClashAvoider::disconnect_all(const Raul::Path& parent_patch, - const Raul::Path& path) -{ - _target.disconnect_all(map_path(parent_patch), map_path(path)); -} - -void -ClashAvoider::set_property(const Raul::URI& subject, - const Raul::URI& predicate, - const Raul::Atom& value) -{ - _target.set_property(map_uri(subject), predicate, value); -} - -void -ClashAvoider::del(const Raul::URI& uri) -{ - if (Raul::Path::is_path(uri)) - _target.del(map_path(Raul::Path(uri.str()))); -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/Configuration.cpp b/src/shared/Configuration.cpp deleted file mode 100644 index 28038466..00000000 --- a/src/shared/Configuration.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "ingen/shared/Configuration.hpp" - -namespace Ingen { -namespace Shared { - -Configuration::Configuration() - : Raul::Configuration( - "A realtime modular audio processor.", - "Ingen is a flexible modular system that be used in various ways.\n" - "The engine can run as a stand-alone server controlled via network protocol,\n" - "or internal to another process (e.g. the GUI). The GUI, or other\n" - "clients, can communicate with the engine via any supported protocol, or host the\n" - "engine in the same process. Many clients can connect to an engine at once.\n\n" - "Examples:\n" - " ingen -e # Run an engine, listen for connections\n" - " ingen -g # Run a GUI, connect to running engine\n" - " ingen -eg # Run an engine and a GUI in one process\n" - " ingen -egl patch.ttl # Run an engine and a GUI and load a patch file\n" - " ingen -egl patch.ingen # Run an engine and a GUI and load a patch bundle") -{ - add("client-port", 'C', "Client port", INT, Value()); - add("connect", 'c', "Connect to engine URI", STRING, Value("unix:///tmp/ingen.sock")); - add("engine", 'e', "Run (JACK) engine", BOOL, Value(false)); - add("engine-port", 'E', "Engine listen port", INT, Value(16180)); - add("socket", 'S', "Engine socket path", STRING, Value("/tmp/ingen.sock")); - add("gui", 'g', "Launch the GTK graphical interface", BOOL, Value(false)); - add("help", 'h', "Print this help message", BOOL, Value(false)); - add("jack-client", 'n', "JACK client name", STRING, Value("ingen")); - add("jack-server", 's', "JACK server name", STRING, Value("")); - add("uuid", 'u', "JACK session UUID", STRING, Value()); - add("load", 'l', "Load patch", STRING, Value()); - add("packet-size", 'k', "Maximum UDP packet size", INT, Value(4096)); - add("parallelism", 'p', "Number of concurrent process threads", INT, Value(1)); - add("path", 'L', "Target path for loaded patch", STRING, Value()); - add("queue-size", 'q', "Event queue size", INT, Value(4096)); - add("run", 'r', "Run script", STRING, Value()); -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/Forge.cpp b/src/shared/Forge.cpp deleted file mode 100644 index b667cf1c..00000000 --- a/src/shared/Forge.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <sstream> -#include <string> - -#include "ingen/shared/Forge.hpp" -#include "ingen/shared/URIMap.hpp" -#include "lv2/lv2plug.in/ns/ext/atom/atom.h" - -namespace Ingen { -namespace Shared { - -Forge::Forge(Shared::URIMap& map) -{ - Int = map.map_uri(LV2_ATOM__Int); - Float = map.map_uri(LV2_ATOM__Float); - Bool = map.map_uri(LV2_ATOM__Bool); - URI = map.map_uri(LV2_ATOM__URI); - URID = map.map_uri(LV2_ATOM__URID); - String = map.map_uri(LV2_ATOM__String); -} - -std::string -Forge::str(const Raul::Atom& atom) -{ - std::ostringstream ss; - if (atom.type() == Int) { - ss << atom.get_int32(); - } else if (atom.type() == Float) { - ss << atom.get_float(); - } else if (atom.type() == Bool) { - ss << (atom.get_bool() ? "true" : "false"); - } else if (atom.type() == URI) { - ss << "<" << atom.get_uri() << ">"; - } else if (atom.type() == String) { - ss << "\"" << atom.get_string() << "\""; - } - return ss.str(); -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/LV2Features.cpp b/src/shared/LV2Features.cpp deleted file mode 100644 index 7061ff76..00000000 --- a/src/shared/LV2Features.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <cstdlib> - -#include "ingen/shared/LV2Features.hpp" - -using namespace std; - -namespace Ingen { -namespace Shared { - -LV2Features::LV2Features() -{ -} - -void -LV2Features::add_feature(SharedPtr<Feature> feature) -{ - _features.push_back(feature); -} - -LV2Features::FeatureArray::FeatureArray(FeatureVector& features) - : _features(features) -{ - _array = (LV2_Feature**)malloc(sizeof(LV2_Feature) * (features.size() + 1)); - _array[features.size()] = NULL; - for (size_t i = 0; i < features.size(); ++i) { - _array[i] = features[i].get(); - } -} - -LV2Features::FeatureArray::~FeatureArray() -{ - free(_array); -} - -SharedPtr<LV2Features::FeatureArray> -LV2Features::lv2_features(Shared::World* world, GraphObject* node) const -{ - FeatureArray::FeatureVector vec; - for (Features::const_iterator f = _features.begin(); f != _features.end(); ++f) { - SharedPtr<LV2_Feature> fptr = (*f)->feature(world, node); - if (fptr) { - vec.push_back(fptr); - } - } - return SharedPtr<FeatureArray>(new FeatureArray(vec)); -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/Store.cpp b/src/shared/Store.cpp deleted file mode 100644 index ad950fd7..00000000 --- a/src/shared/Store.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <sstream> -#include <string> - -#include "ingen/GraphObject.hpp" -#include "ingen/shared/Store.hpp" -#include "raul/PathTable.hpp" -#include "raul/TableImpl.hpp" -#include "raul/log.hpp" - -using namespace std; - -namespace Ingen { -namespace Shared { - -void -Store::add(GraphObject* o) -{ - if (find(o->path()) != end()) { - Raul::error << "[Store] Attempt to add duplicate object " << o->path() << endl; - return; - } - - insert(make_pair(o->path(), o)); - - for (uint32_t i = 0; i < o->num_ports(); ++i) { - add(o->port(i)); - } -} - -Store::const_iterator -Store::children_begin(SharedPtr<const GraphObject> o) const -{ - const_iterator parent = find(o->path()); - assert(parent != end()); - ++parent; - return parent; -} - -Store::const_iterator -Store::children_end(SharedPtr<const GraphObject> o) const -{ - const_iterator parent = find(o->path()); - assert(parent != end()); - return find_descendants_end(parent); -} - -SharedPtr<GraphObject> -Store::find_child(SharedPtr<const GraphObject> parent, - const string& child_name) const -{ - const_iterator pi = find(parent->path()); - assert(pi != end()); - const_iterator children_end = find_descendants_end(pi); - const_iterator child = find(pi, children_end, parent->path().base() + child_name); - if (child != end()) - return child->second; - else - return SharedPtr<GraphObject>(); -} - -unsigned -Store::child_name_offset(const Raul::Path& parent, - const Raul::Symbol& symbol, - bool allow_zero) -{ - unsigned offset = 0; - - while (true) { - std::stringstream ss; - ss << symbol; - if (offset > 0) - ss << "_" << offset; - if (find(parent.base() + ss.str()) == end() && (allow_zero || offset > 0)) - break; - else if (offset == 0) - offset = 2; - else - ++offset; - } - - return offset; -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/URIMap.cpp b/src/shared/URIMap.cpp deleted file mode 100644 index b8981fd3..00000000 --- a/src/shared/URIMap.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <stdint.h> - -#include <glib.h> - -#include "ingen/shared/URIMap.hpp" - -using namespace std; - -namespace Ingen { -namespace Shared { - -URIMap::URIMap(LV2_URID_Map* map, LV2_URID_Unmap* unmap) - : _urid_map_feature(new URIDMapFeature(this, map)) - , _urid_unmap_feature(new URIDUnmapFeature(this, unmap)) -{ -} - -URIMap::URIDMapFeature::URIDMapFeature(URIMap* map, - LV2_URID_Map* impl) - : Feature(LV2_URID__map, &urid_map) -{ - if (impl) { - urid_map = *impl; - } else { - urid_map.map = default_map; - urid_map.handle = NULL; - } -} - -LV2_URID -URIMap::URIDMapFeature::default_map(LV2_URID_Map_Handle handle, - const char* uri) -{ - return static_cast<LV2_URID>(g_quark_from_string(uri)); -} - -LV2_URID -URIMap::URIDMapFeature::map(const char* uri) -{ - return urid_map.map(urid_map.handle, uri); -} - -URIMap::URIDUnmapFeature::URIDUnmapFeature(URIMap* map, - LV2_URID_Unmap* impl) - : Feature(LV2_URID__unmap, &urid_unmap) -{ - if (impl) { - urid_unmap = *impl; - } else { - urid_unmap.unmap = default_unmap; - urid_unmap.handle = NULL; - } -} - -const char* -URIMap::URIDUnmapFeature::default_unmap(LV2_URID_Unmap_Handle handle, - LV2_URID urid) -{ - return g_quark_to_string(urid); -} - -const char* -URIMap::URIDUnmapFeature::unmap(LV2_URID urid) -{ - return urid_unmap.unmap(urid_unmap.handle, urid); -} - -uint32_t -URIMap::map_uri(const char* uri) -{ - return _urid_map_feature->map(uri); -} - -const char* -URIMap::unmap_uri(uint32_t urid) const -{ - return _urid_unmap_feature->unmap(urid); -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/URIs.cpp b/src/shared/URIs.cpp deleted file mode 100644 index 102c7b8b..00000000 --- a/src/shared/URIs.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "ingen/shared/URIMap.hpp" -#include "ingen/shared/URIs.hpp" -#include "lv2/lv2plug.in/ns/ext/atom/atom.h" -#include "lv2/lv2plug.in/ns/ext/midi/midi.h" -#include "lv2/lv2plug.in/ns/ext/patch/patch.h" -#include "lv2/lv2plug.in/ns/ext/port-props/port-props.h" -#include "lv2/lv2plug.in/ns/lv2core/lv2.h" - -namespace Ingen { -namespace Shared { - -URIs::Quark::Quark(Shared::Forge& forge, URIMap* map, const char* c_str) - : Raul::URI(c_str) - , id(map->map_uri(c_str)) - , atom(forge.alloc_uri(c_str)) -{ -} - -#define NS_INGEN "http://drobilla.net/ns/ingen#" -#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" -#define NS_RDFS "http://www.w3.org/2000/01/rdf-schema#" - -URIs::URIs(Shared::Forge& f, URIMap* map) - : forge(f) - , atom_AtomPort (forge, map, LV2_ATOM__AtomPort) - , atom_Blank (forge, map, LV2_ATOM__Blank) - , atom_Bool (forge, map, LV2_ATOM__Bool) - , atom_Chunk (forge, map, LV2_ATOM__Chunk) - , atom_Float (forge, map, LV2_ATOM__Float) - , atom_Int (forge, map, LV2_ATOM__Int) - , atom_Resource (forge, map, LV2_ATOM__Resource) - , atom_Sequence (forge, map, LV2_ATOM__Sequence) - , atom_Sound (forge, map, LV2_ATOM__Sound) - , atom_String (forge, map, LV2_ATOM__String) - , atom_URI (forge, map, LV2_ATOM__URI) - , atom_URID (forge, map, LV2_ATOM__URID) - , atom_Vector (forge, map, LV2_ATOM__Vector) - , atom_bufferType (forge, map, LV2_ATOM__bufferType) - , atom_eventTransfer (forge, map, LV2_ATOM__eventTransfer) - , atom_supports (forge, map, LV2_ATOM__supports) - , doap_name (forge, map, "http://usefulinc.com/ns/doap#name") - , ingen_Edge (forge, map, NS_INGEN "Edge") - , ingen_Internal (forge, map, NS_INGEN "Internal") - , ingen_Node (forge, map, NS_INGEN "Node") - , ingen_Patch (forge, map, NS_INGEN "Patch") - , ingen_activity (forge, map, NS_INGEN "activity") - , ingen_broadcast (forge, map, NS_INGEN "broadcast") - , ingen_canvasX (forge, map, NS_INGEN "canvasX") - , ingen_canvasY (forge, map, NS_INGEN "canvasY") - , ingen_controlBinding (forge, map, NS_INGEN "controlBinding") - , ingen_document (forge, map, NS_INGEN "document") - , ingen_enabled (forge, map, NS_INGEN "enabled") - , ingen_engine (forge, map, NS_INGEN "engine") - , ingen_head (forge, map, NS_INGEN "head") - , ingen_incidentTo (forge, map, NS_INGEN "incidentTo") - , ingen_nil (forge, map, NS_INGEN "nil") - , ingen_node (forge, map, NS_INGEN "node") - , ingen_polyphonic (forge, map, NS_INGEN "polyphonic") - , ingen_polyphony (forge, map, NS_INGEN "polyphony") - , ingen_prototype (forge, map, NS_INGEN "prototype") - , ingen_sampleRate (forge, map, NS_INGEN "sampleRate") - , ingen_status (forge, map, NS_INGEN "status") - , ingen_tail (forge, map, NS_INGEN "tail") - , ingen_uiEmbedded (forge, map, NS_INGEN "uiEmbedded") - , ingen_value (forge, map, NS_INGEN "value") - , lv2_AudioPort (forge, map, LV2_CORE__AudioPort) - , lv2_CVPort (forge, map, LV2_CORE__CVPort) - , lv2_ControlPort (forge, map, LV2_CORE__ControlPort) - , lv2_InputPort (forge, map, LV2_CORE__InputPort) - , lv2_OutputPort (forge, map, LV2_CORE__OutputPort) - , lv2_Plugin (forge, map, LV2_CORE__Plugin) - , lv2_connectionOptional(forge, map, LV2_CORE__connectionOptional) - , lv2_default (forge, map, LV2_CORE__default) - , lv2_index (forge, map, LV2_CORE__index) - , lv2_integer (forge, map, LV2_CORE__integer) - , lv2_maximum (forge, map, LV2_CORE__maximum) - , lv2_minimum (forge, map, LV2_CORE__minimum) - , lv2_name (forge, map, LV2_CORE__name) - , lv2_portProperty (forge, map, LV2_CORE__portProperty) - , lv2_sampleRate (forge, map, LV2_CORE__sampleRate) - , lv2_scalePoint (forge, map, LV2_CORE__scalePoint) - , lv2_symbol (forge, map, LV2_CORE__symbol) - , lv2_toggled (forge, map, LV2_CORE__toggled) - , midi_Bender (forge, map, LV2_MIDI__Bender) - , midi_ChannelPressure (forge, map, LV2_MIDI__ChannelPressure) - , midi_Controller (forge, map, LV2_MIDI__Controller) - , midi_MidiEvent (forge, map, LV2_MIDI__MidiEvent) - , midi_NoteOn (forge, map, LV2_MIDI__NoteOn) - , midi_controllerNumber (forge, map, LV2_MIDI__controllerNumber) - , midi_noteNumber (forge, map, LV2_MIDI__noteNumber) - , patch_Delete (forge, map, LV2_PATCH__Delete) - , patch_Get (forge, map, LV2_PATCH__Get) - , patch_Move (forge, map, LV2_PATCH__Move) - , patch_Patch (forge, map, LV2_PATCH__Patch) - , patch_Put (forge, map, LV2_PATCH__Put) - , patch_Response (forge, map, LV2_PATCH__Response) - , patch_Set (forge, map, LV2_PATCH__Set) - , patch_add (forge, map, LV2_PATCH__add) - , patch_body (forge, map, LV2_PATCH__body) - , patch_destination (forge, map, LV2_PATCH__destination) - , patch_remove (forge, map, LV2_PATCH__remove) - , patch_request (forge, map, LV2_PATCH__request) - , patch_subject (forge, map, LV2_PATCH__subject) - , pprops_logarithmic (forge, map, LV2_PORT_PROPS__logarithmic) - , rdf_type (forge, map, NS_RDF "type") - , rdfs_seeAlso (forge, map, NS_RDFS "seeAlso") - , wildcard (forge, map, NS_INGEN "wildcard") -{ -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/World.cpp b/src/shared/World.cpp deleted file mode 100644 index 05a941e9..00000000 --- a/src/shared/World.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <map> -#include <string> - -#include <glibmm/fileutils.h> -#include <glibmm/miscutils.h> -#include <glibmm/module.h> - -#include "ingen/shared/Configuration.hpp" -#include "ingen/shared/LV2Features.hpp" -#include "ingen/shared/Module.hpp" -#include "ingen/shared/URIMap.hpp" -#include "ingen/shared/URIs.hpp" -#include "ingen/shared/World.hpp" -#include "ingen/shared/runtime_paths.hpp" -#include "lilv/lilv.h" -#include "raul/log.hpp" -#include "sord/sordmm.hpp" - -#define LOG(s) (s("[World] ")) - -using namespace std; - -namespace Ingen { - -class EngineBase; -class Interface; - -namespace Serialisation { class Parser; class Serialiser; } - -namespace Shared { - -class Store; - -/** Load a dynamic module from the default path. - * - * This will check in the directories specified in the environment variable - * INGEN_MODULE_PATH (typical colon delimited format), then the default module - * installation directory (ie /usr/local/lib/ingen), in that order. - * - * \param name The base name of the module, e.g. "ingen_serialisation" - */ -Glib::Module* -ingen_load_module(const string& name) -{ - Glib::Module* module = NULL; - - // Search INGEN_MODULE_PATH first - bool module_path_found; - string module_path = Glib::getenv("INGEN_MODULE_PATH", module_path_found); - if (module_path_found) { - string dir; - istringstream iss(module_path); - while (getline(iss, dir, G_SEARCHPATH_SEPARATOR)) { - string filename = Shared::module_path(name, dir); - if (Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) { - module = new Glib::Module(filename); - if (*module) { - LOG(Raul::info)(Raul::fmt("Loading %1%\n") % filename); - return module; - } else { - Raul::error << Glib::Module::get_last_error() << endl; - } - } - } - } - - // Try default directory if not found - module = new Glib::Module(Shared::module_path(name)); - - if (module) { - LOG(Raul::info)(Raul::fmt("Loading %1%\n") % Shared::module_path(name)); - return module; - } else if (!module_path_found) { - LOG(Raul::error)(Raul::fmt("Unable to find %1% (%2%)\n") - % name % Glib::Module::get_last_error()); - return NULL; - } else { - LOG(Raul::error)(Raul::fmt("Unable to load %1% from %2% (%3%)\n") - % name % module_path % Glib::Module::get_last_error()); - LOG(Raul::error)("Is Ingen installed?\n"); - return NULL; - } -} - -class World::Impl { -public: - Impl(int& a_argc, - char**& a_argv, - LV2_URID_Map* map, - LV2_URID_Unmap* unmap) - : argc(a_argc) - , argv(a_argv) - , lv2_features(NULL) - , rdf_world(new Sord::World()) - , uri_map(new Ingen::Shared::URIMap(map, unmap)) - , forge(new Ingen::Shared::Forge(*uri_map)) - , uris(new Shared::URIs(*forge, uri_map)) - , lilv_world(lilv_world_new()) - { - conf.parse(argc, argv); - lv2_features = new Ingen::Shared::LV2Features(); - lv2_features->add_feature(uri_map->urid_map_feature()); - lv2_features->add_feature(uri_map->urid_unmap_feature()); - lilv_world_load_all(lilv_world); - - // Set up RDF namespaces - rdf_world->add_prefix("atom", "http://lv2plug.in/ns/ext/atom#"); - rdf_world->add_prefix("patch", "http://lv2plug.in/ns/ext/patch#"); - rdf_world->add_prefix("doap", "http://usefulinc.com/ns/doap#"); - rdf_world->add_prefix("ingen", "http://drobilla.net/ns/ingen#"); - rdf_world->add_prefix("lv2", "http://lv2plug.in/ns/lv2core#"); - rdf_world->add_prefix("lv2ev", "http://lv2plug.in/ns/ext/event#"); - rdf_world->add_prefix("midi", "http://lv2plug.in/ns/ext/midi#"); - rdf_world->add_prefix("owl", "http://www.w3.org/2002/07/owl#"); - rdf_world->add_prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); - rdf_world->add_prefix("xsd", "http://www.w3.org/2001/XMLSchema#"); - } - - ~Impl() - { - serialiser.reset(); - parser.reset(); - interface.reset(); - engine.reset(); - store.reset(); - - interface_factories.clear(); - script_runners.clear(); - - delete rdf_world; - delete lv2_features; - delete uris; - delete forge; - delete uri_map; - - lilv_world_free(lilv_world); - - - for (Modules::iterator i = modules.begin(); i != modules.end(); ++i) { - // Keep a reference to the library - Glib::Module* lib = i->second->library; - - // Destroy the Ingen module - delete i->second; - - // Now all references to library code should be done, close it - delete lib; - } - } - - typedef std::map<const std::string, Module*> Modules; - Modules modules; - - typedef std::map<const std::string, World::InterfaceFactory> InterfaceFactories; - InterfaceFactories interface_factories; - - typedef bool (*ScriptRunner)(World* world, const char* filename); - typedef std::map<const std::string, ScriptRunner> ScriptRunners; - ScriptRunners script_runners; - - int& argc; - char**& argv; - Shared::Configuration conf; - LV2Features* lv2_features; - Sord::World* rdf_world; - URIMap* uri_map; - Shared::Forge* forge; - URIs* uris; - SharedPtr<Interface> interface; - SharedPtr<EngineBase> engine; - SharedPtr<Serialisation::Serialiser> serialiser; - SharedPtr<Serialisation::Parser> parser; - SharedPtr<Store> store; - LilvWorld* lilv_world; - std::string jack_uuid; -}; - -World::World(int& argc, - char**& argv, - LV2_URID_Map* map, - LV2_URID_Unmap* unmap) - : _impl(new Impl(argc, argv, map, unmap)) -{ -} - -World::~World() -{ - delete _impl; -} - -void World::set_engine(SharedPtr<EngineBase> e) { _impl->engine = e; } -void World::set_interface(SharedPtr<Interface> i) { _impl->interface = i; } -void World::set_parser(SharedPtr<Serialisation::Parser> p) { _impl->parser = p; } -void World::set_serialiser(SharedPtr<Serialisation::Serialiser> s) { _impl->serialiser = s; } -void World::set_store(SharedPtr<Store> s) { _impl->store = s; } - -SharedPtr<EngineBase> World::engine() { return _impl->engine; } -SharedPtr<Interface> World::interface() { return _impl->interface; } -SharedPtr<Serialisation::Parser> World::parser() { return _impl->parser; } -SharedPtr<Serialisation::Serialiser> World::serialiser() { return _impl->serialiser; } -SharedPtr<Store> World::store() { return _impl->store; } - -int& World::argc() { return _impl->argc; } -char**& World::argv() { return _impl->argv; } -Shared::Configuration& World::conf() { return _impl->conf; } - -Sord::World* World::rdf_world() { return _impl->rdf_world; } -LilvWorld* World::lilv_world() { return _impl->lilv_world; } - -LV2Features& World::lv2_features() { return *_impl->lv2_features; } -Shared::Forge& World::forge() { return *_impl->forge; } -URIs& World::uris() { return *_impl->uris; } -URIMap& World::uri_map() { return *_impl->uri_map; } - -bool -World::load_module(const char* name) -{ - Impl::Modules::iterator i = _impl->modules.find(name); - if (i != _impl->modules.end()) { - LOG(Raul::info)(Raul::fmt("Module `%1%' already loaded\n") % name); - return true; - } - Glib::Module* lib = ingen_load_module(name); - Ingen::Shared::Module* (*module_load)() = NULL; - if (lib && lib->get_symbol("ingen_module_load", (void*&)module_load)) { - Module* module = module_load(); - if (module) { - module->library = lib; - module->load(this); - _impl->modules.insert(make_pair(string(name), module)); - return true; - } - } - - LOG(Raul::error)(Raul::fmt("Failed to load module `%1%'\n") % name); - delete lib; - return false; -} - -bool -World::run_module(const char* name) -{ - Impl::Modules::iterator i = _impl->modules.find(name); - if (i == _impl->modules.end()) { - LOG(Raul::error) << "Attempt to run unloaded module `" << name << "'" << endl; - return false; - } - - i->second->run(this); - return true; -} - -void -World::unload_modules() -{ - _impl->modules.clear(); -} - -/** Get an interface for a remote engine at @a url - */ -SharedPtr<Interface> -World::new_interface(const std::string& engine_url, - SharedPtr<Interface> respondee) -{ - const string scheme = engine_url.substr(0, engine_url.find(":")); - const Impl::InterfaceFactories::const_iterator i = _impl->interface_factories.find(scheme); - if (i == _impl->interface_factories.end()) { - Raul::warn << "Unknown URI scheme `" << scheme << "'" << endl; - return SharedPtr<Interface>(); - } - - return i->second(this, engine_url, respondee); -} - -/** Run a script of type @a mime_type at filename @a filename */ -bool -World::run(const std::string& mime_type, const std::string& filename) -{ - const Impl::ScriptRunners::const_iterator i = _impl->script_runners.find(mime_type); - if (i == _impl->script_runners.end()) { - Raul::warn << "Unknown script MIME type `" << mime_type << "'" << endl; - return false; - } - - return i->second(this, filename.c_str()); -} - -void -World::add_interface_factory(const std::string& scheme, InterfaceFactory factory) -{ - _impl->interface_factories.insert(make_pair(scheme, factory)); -} - -void -World::set_jack_uuid(const std::string& uuid) -{ - _impl->jack_uuid = uuid; -} - -std::string -World::jack_uuid() -{ - return _impl->jack_uuid; -} - -} // namespace Shared -} // namespace Ingen diff --git a/src/shared/runtime_paths.cpp b/src/shared/runtime_paths.cpp deleted file mode 100644 index 8439b248..00000000 --- a/src/shared/runtime_paths.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard <http://drobilla.net/> - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include <string> - -#include <limits.h> -#include <stdlib.h> - -#include <dlfcn.h> - -#include <glibmm/module.h> -#include <glibmm/miscutils.h> - -#include "raul/log.hpp" - -#include "ingen/shared/runtime_paths.hpp" - -#include "ingen_config.h" - -using namespace std; - -namespace Ingen { -namespace Shared { - -static std::string bundle_path; - -/** Must be called once at startup, and passed a pointer to a function - * that lives in the 'top level' of the bundle (e.g. the executable). - * Passing a function defined in a module etc. will not work! - */ -void -set_bundle_path_from_code(void* function) -{ - Dl_info dli; - dladdr(function, &dli); - -#ifdef BUNDLE - char bin_loc[PATH_MAX]; - realpath(dli.dli_fname, bin_loc); -#else - const char* bin_loc = dli.dli_fname; -#endif - - Raul::info(Raul::fmt("Binary location: %1%\n") % bin_loc); - - string bundle = bin_loc; - bundle = bundle.substr(0, bundle.find_last_of(G_DIR_SEPARATOR)); - bundle_path = bundle; -} - -void -set_bundle_path(const char* path) -{ - bundle_path = path; -} - -/** Return the absolute path of a file in an Ingen LV2 bundle - */ -std::string -bundle_file_path(const std::string& name) -{ - return Glib::build_filename(bundle_path, name); -} - -/** Return the absolute path of a 'resource' file. - */ -std::string -data_file_path(const std::string& name) -{ -#ifdef BUNDLE - return Glib::build_filename(bundle_path, Glib::build_path(INGEN_DATA_DIR, name)); -#else - return Glib::build_filename(INGEN_DATA_DIR, name); -#endif -} - -/** Return the absolute path of a module (dynamically loaded shared library). - */ -std::string -module_path(const std::string& name, std::string dir) -{ - std::string ret; - if (dir == "") { -#ifdef BUNDLE - dir = Glib::build_path(bundle_path, INGEN_MODULE_DIR); -#else - dir = INGEN_MODULE_DIR; -#endif - } - - ret = Glib::Module::build_path(dir, string("ingen_") + name); - -#ifdef __APPLE__ - // MacPorts glib doesnt seem to do portable path building correctly... - if (ret.substr(ret.length() - 3) == ".so") - ret = ret.substr(0, ret.length() - 2).append("dylib"); -#endif - return ret; -} - -} // namespace Ingen -} // namespace Shared - diff --git a/src/shared/wscript b/src/shared/wscript deleted file mode 100644 index 8a873653..00000000 --- a/src/shared/wscript +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -from waflib.extras import autowaf as autowaf - -sources = [ - 'AtomReader.cpp', - 'AtomWriter.cpp', - 'Builder.cpp', - 'ClashAvoider.cpp', - 'Configuration.cpp', - 'Forge.cpp', - 'LV2Features.cpp', - 'Store.cpp', - 'URIMap.cpp', - 'URIs.cpp', - 'World.cpp', - 'runtime_paths.cpp', -] - -def build(bld): - obj = bld(features = 'cxx cxxshlib', - source = sources, - export_includes = ['../..'], - includes = ['../..'], - name = 'libingen_shared', - target = 'ingen_shared', - use = 'libingen', - vnum = '0.0.0', - install_path = '${LIBDIR}', - lib = ['dl']) - autowaf.use_lib(bld, obj, 'GLIBMM LV2 LILV RAUL SORD LV2_MIDI') - - if bld.env['BUILD_TESTS']: - obj = bld(features = 'cxx cxxshlib', - source = sources, - export_includes = ['../..'], - includes = ['../..'], - name = 'libingen_shared_profiled', - target = 'ingen_shared_profiled', - use = 'libingen', - install_path = '', - lib = ['dl'] + bld.env['INGEN_TEST_LIBS'], - cxxflags = bld.env['INGEN_TEST_CXXFLAGS']) - autowaf.use_lib(bld, obj, 'GLIBMM LV2 LILV RAUL SORD LV2_MIDI') - |