From 042445d4f178043cb97aa0388f5bc9a65fcac2df Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 21 Oct 2011 17:40:47 +0000 Subject: Simplify LV2Features. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3561 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/LV2Info.cpp | 6 +++--- src/server/LV2Node.cpp | 2 +- src/shared/LV2Features.cpp | 32 +++++++++++++++++++------------- src/shared/LV2Features.hpp | 22 +++++----------------- src/shared/World.cpp | 4 ++-- 5 files changed, 30 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/server/LV2Info.cpp b/src/server/LV2Info.cpp index 1ff351b6..6d13644e 100644 --- a/src/server/LV2Info.cpp +++ b/src/server/LV2Info.cpp @@ -51,11 +51,11 @@ LV2Info::LV2Info(Ingen::Shared::World* world) { assert(world); - world->lv2_features()->add_feature(LV2_EVENT_URI, + world->lv2_features()->add_feature( SharedPtr(new EventFeature())); - world->lv2_features()->add_feature(LV2_RESIZE_PORT_URI, + world->lv2_features()->add_feature( SharedPtr(new ResizeFeature())); - world->lv2_features()->add_feature(LV2_CONTEXTS_URI "#RequestRunFeature", + world->lv2_features()->add_feature( SharedPtr(new RequestRunFeature())); } diff --git a/src/server/LV2Node.cpp b/src/server/LV2Node.cpp index 125beaee..76837c88 100644 --- a/src/server/LV2Node.cpp +++ b/src/server/LV2Node.cpp @@ -152,7 +152,7 @@ LV2Node::instantiate(BufferFactory& bufs) uint32_t port_buffer_size = 0; LilvNode* ctx_ext_uri = lilv_new_uri(info->lv2_world(), - LV2_CONTEXTS_URI "#MessageContext"); + LV2_CONTEXTS_URI "#MessageContext"); for (uint32_t i = 0; i < _polyphony; ++i) { (*_instances)[i] = SharedPtr( diff --git a/src/shared/LV2Features.cpp b/src/shared/LV2Features.cpp index 83c817eb..ea5cdd8a 100644 --- a/src/shared/LV2Features.cpp +++ b/src/shared/LV2Features.cpp @@ -16,7 +16,7 @@ */ #include -#include + #include "LV2Features.hpp" #include "LV2URIMap.hpp" @@ -29,20 +29,25 @@ LV2Features::LV2Features() { } -SharedPtr -LV2Features::feature(const std::string& uri) +void +LV2Features::add_feature(SharedPtr feature) { - Features::const_iterator i = _features.find(uri); - if (i != _features.end()) - return i->second; - else - return SharedPtr(); + _features.push_back(feature); } -void -LV2Features::add_feature(const std::string& uri, SharedPtr 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() { - _features.insert(make_pair(uri, feature)); + free(_array); } SharedPtr @@ -50,9 +55,10 @@ LV2Features::lv2_features(Shared::World* world, Node* node) const { FeatureArray::FeatureVector vec; for (Features::const_iterator f = _features.begin(); f != _features.end(); ++f) { - SharedPtr fptr = f->second->feature(world, node); - if (fptr) + SharedPtr fptr = (*f)->feature(world, node); + if (fptr) { vec.push_back(fptr); + } } return SharedPtr(new FeatureArray(vec)); } diff --git a/src/shared/LV2Features.hpp b/src/shared/LV2Features.hpp index 75bbcda3..f33cc605 100644 --- a/src/shared/LV2Features.hpp +++ b/src/shared/LV2Features.hpp @@ -18,8 +18,6 @@ #ifndef INGEN_SHARED_LV2FEATURES_HPP #define INGEN_SHARED_LV2FEATURES_HPP -#include -#include #include #include "lv2/lv2plug.in/ns/lv2core/lv2.h" @@ -43,6 +41,7 @@ public: class Feature { public: virtual ~Feature() {} + virtual SharedPtr feature(Shared::World* world, Node* node) = 0; }; @@ -51,18 +50,9 @@ public: public: typedef std::vector< SharedPtr > FeatureVector; - explicit 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(); - } + explicit FeatureArray(FeatureVector& features); - ~FeatureArray() { - free(_array); - } + ~FeatureArray(); LV2_Feature** array() { return _array; } @@ -71,15 +61,13 @@ public: LV2_Feature** _array; }; - SharedPtr feature(const std::string& uri); - - void add_feature(const std::string& uri, SharedPtr feature); + void add_feature(SharedPtr feature); SharedPtr lv2_features(Shared::World* world, Node* node) const; private: - typedef std::map< std::string, SharedPtr > Features; + typedef std::vector< SharedPtr > Features; Features _features; }; diff --git a/src/shared/World.cpp b/src/shared/World.cpp index 92d7a03f..c70b9196 100644 --- a/src/shared/World.cpp +++ b/src/shared/World.cpp @@ -107,8 +107,8 @@ public: , lilv_world(lilv_world_new()) { lv2_features = new Ingen::Shared::LV2Features(); - lv2_features->add_feature(LV2_URI_MAP_URI, uris); - lv2_features->add_feature(LV2_URI_UNMAP_URI, uris->unmap_feature()); + lv2_features->add_feature(uris); + lv2_features->add_feature(uris->unmap_feature()); lilv_world_load_all(lilv_world); // Set up RDF namespaces -- cgit v1.2.1