From 239825b92b1d4c79ebd67cb3766355bf8e699bc7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 19 May 2008 23:52:44 +0000 Subject: Better global (engine/client) LV2 feature sharing. Provide URI map extension to plugin UIs. git-svn-id: http://svn.drobilla.net/lad/ingen@1217 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/LV2Info.cpp | 74 +++++++++++------------------------------ src/libs/engine/LV2Info.hpp | 25 +++++--------- src/libs/engine/LV2Node.cpp | 3 +- src/libs/engine/Makefile.am | 1 + src/libs/engine/NodeFactory.cpp | 2 +- 5 files changed, 32 insertions(+), 73 deletions(-) (limited to 'src/libs/engine') diff --git a/src/libs/engine/LV2Info.cpp b/src/libs/engine/LV2Info.cpp index df8dd1f9..e5e9dde2 100644 --- a/src/libs/engine/LV2Info.cpp +++ b/src/libs/engine/LV2Info.cpp @@ -20,40 +20,32 @@ #include #include #include "LV2Info.hpp" +#include using namespace std; namespace Ingen { -LV2Info::LV2Info(SLV2World world) - : input_class(slv2_value_new_uri(world, SLV2_PORT_CLASS_INPUT)) - , output_class(slv2_value_new_uri(world, SLV2_PORT_CLASS_OUTPUT)) - , control_class(slv2_value_new_uri(world, SLV2_PORT_CLASS_CONTROL)) - , audio_class(slv2_value_new_uri(world, SLV2_PORT_CLASS_AUDIO)) - , event_class(slv2_value_new_uri(world, SLV2_PORT_CLASS_EVENT)) - , next_uri_id(1) - , lv2_features(new LV2_Feature*[3]) +LV2Info::LV2Info(Ingen::Shared::World* world) + : input_class(slv2_value_new_uri(world->slv2_world, SLV2_PORT_CLASS_INPUT)) + , output_class(slv2_value_new_uri(world->slv2_world, SLV2_PORT_CLASS_OUTPUT)) + , control_class(slv2_value_new_uri(world->slv2_world, SLV2_PORT_CLASS_CONTROL)) + , audio_class(slv2_value_new_uri(world->slv2_world, SLV2_PORT_CLASS_AUDIO)) + , event_class(slv2_value_new_uri(world->slv2_world, SLV2_PORT_CLASS_EVENT)) + , _world(world) { - uri_map_feature_data.uri_to_id = &LV2Info::uri_map_uri_to_id; - uri_map_feature_data.callback_data = this; - uri_map_feature.URI = LV2_URI_MAP_URI; - uri_map_feature.data = &uri_map_feature_data; - - event_feature_data.lv2_event_ref= &LV2Info::event_ref; - event_feature_data.lv2_event_unref= &LV2Info::event_ref; - event_feature_data.callback_data = this; - event_feature.URI = LV2_EVENT_URI; - event_feature.data = &event_feature_data; - - lv2_features[0] = &uri_map_feature; - lv2_features[1] = &event_feature; - lv2_features[2] = NULL; - - /* this is needed so we get a fixed type ID for MIDI, it would - probably be better to make the type map accessible from any - JackMidiPort. */ - next_uri_id++; - uri_map.insert(make_pair(string("http://lv2plug.in/ns/ext/midi#MidiEvent"), 1)); + // Client would never add the event referencing feature + assert( ! world->lv2_features->feature(LV2_EVENT_URI)); + + LV2_Event_Feature* ev_data = (LV2_Event_Feature*)malloc(sizeof(LV2_Event_Feature)); + ev_data->lv2_event_ref = &LV2Info::event_ref; + ev_data->lv2_event_unref = &LV2Info::event_ref; + ev_data->callback_data = this; + LV2_Feature* ev_feature = (LV2_Feature*)malloc(sizeof(LV2_Event_Feature)); + ev_feature->URI = LV2_EVENT_URI; + ev_feature->data = ev_data; + + world->lv2_features->add_feature(LV2_EVENT_URI, ev_feature, ev_data); } @@ -67,32 +59,6 @@ LV2Info::~LV2Info() } - -uint32_t -LV2Info::uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data, - const char* map, - const char* uri) -{ - // TODO: map ignored, < UINT16_MAX assumed - - LV2Info* me = (LV2Info*)callback_data; - uint32_t ret = 0; - - URIMap::iterator i = me->uri_map.find(uri); - if (i != me->uri_map.end()) { - ret = i->second; - } else { - ret = me->next_uri_id++; - me->uri_map.insert(make_pair(string(uri), ret)); - } - - cout << "URI MAP (" << map << "): " << uri << " -> " << ret << endl; - - assert(ret <= UINT16_MAX); - return ret; -} - - uint32_t LV2Info::event_ref(LV2_Event_Callback_Data callback_data, LV2_Event* event) diff --git a/src/libs/engine/LV2Info.hpp b/src/libs/engine/LV2Info.hpp index 09865784..1fff0b92 100644 --- a/src/libs/engine/LV2Info.hpp +++ b/src/libs/engine/LV2Info.hpp @@ -27,18 +27,19 @@ #include #include #include "module/global.hpp" +#include "module/World.hpp" +#include "shared/LV2URIMap.hpp" #include "lv2/uri_map/lv2_uri_map.h" #include "lv2/event/lv2_event.h" - namespace Ingen { /** Stuff that may need to be passed to an LV2 plugin (i.e. LV2 features). */ -class LV2Info { +class LV2Info : public Shared::LV2URIMap { public: - LV2Info(SLV2World world); + LV2Info(Ingen::Shared::World* world); ~LV2Info(); SLV2Value input_class; @@ -47,23 +48,13 @@ public: SLV2Value audio_class; SLV2Value event_class; - LV2_Feature uri_map_feature; - LV2_URI_Map_Feature uri_map_feature_data; - LV2_Feature event_feature; - LV2_Event_Feature event_feature_data; - - typedef std::map URIMap; - URIMap uri_map; - uint32_t next_uri_id; - - static uint32_t uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data, - const char* map, - const char* uri); - static uint32_t event_ref(LV2_Event_Callback_Data callback_data, LV2_Event* event); - LV2_Feature** lv2_features; + LV2_Feature** lv2_features() const { return _world->lv2_features->lv2_features(); } + +private: + Ingen::Shared::World* _world; }; diff --git a/src/libs/engine/LV2Node.cpp b/src/libs/engine/LV2Node.cpp index bdeca701..9bb05f98 100644 --- a/src/libs/engine/LV2Node.cpp +++ b/src/libs/engine/LV2Node.cpp @@ -75,6 +75,7 @@ LV2Node::prepare_poly(uint32_t poly) _prepared_instances = new Raul::Array(poly, *_instances); for (uint32_t i = _polyphony; i < _prepared_instances->size(); ++i) { + // FIXME: features array (in NodeFactory) must be passed! _prepared_instances->at(i) = slv2_plugin_instantiate( _lv2_plugin->slv2_plugin(), _srate, NULL); @@ -137,7 +138,7 @@ LV2Node::instantiate() uint32_t port_buffer_size = 0; for (uint32_t i=0; i < _polyphony; ++i) { - (*_instances)[i] = slv2_plugin_instantiate(plug, _srate, info->lv2_features); + (*_instances)[i] = slv2_plugin_instantiate(plug, _srate, info->lv2_features()); if ((*_instances)[i] == NULL) { cerr << "Failed to instantiate plugin!" << endl; return false; diff --git a/src/libs/engine/Makefile.am b/src/libs/engine/Makefile.am index 8fa561ac..b53b28e1 100644 --- a/src/libs/engine/Makefile.am +++ b/src/libs/engine/Makefile.am @@ -18,6 +18,7 @@ libingen_engine_la_CXXFLAGS = \ libingen_engine_la_LDFLAGS = -no-undefined -module -avoid-version libingen_engine_la_LIBADD = \ + ../shared/libingen_shared.la \ @GLIBMM_LIBS@ \ @JACK_LIBS@ \ @LASH_LIBS@ \ diff --git a/src/libs/engine/NodeFactory.cpp b/src/libs/engine/NodeFactory.cpp index e86f9a2d..733dc6b1 100644 --- a/src/libs/engine/NodeFactory.cpp +++ b/src/libs/engine/NodeFactory.cpp @@ -49,7 +49,7 @@ NodeFactory::NodeFactory(Ingen::Shared::World* world) : _world(world) , _has_loaded(false) #ifdef HAVE_SLV2 - , _lv2_info(new LV2Info(world->slv2_world)) + , _lv2_info(new LV2Info(world)) #endif { } -- cgit v1.2.1