summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-11-30 23:28:59 +0000
committerDavid Robillard <d@drobilla.net>2010-11-30 23:28:59 +0000
commit6e4322bc87a3af604b656e410d48d8bd8673d3b2 (patch)
tree3fc4f370e9d04e1e9418a89d6254f5f332dab212 /src/shared
parent27c3aec25ca4eefa88df64b63d50ed4451bec190 (diff)
downloadingen-6e4322bc87a3af604b656e410d48d8bd8673d3b2.tar.gz
ingen-6e4322bc87a3af604b656e410d48d8bd8673d3b2.tar.bz2
ingen-6e4322bc87a3af604b656e410d48d8bd8673d3b2.zip
Actually implement event context URI mapping (translate to/from global URI IDs, all other contexts are global).
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2679 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/LV2URIMap.cpp155
-rw-r--r--src/shared/LV2URIMap.hpp6
2 files changed, 90 insertions, 71 deletions
diff --git a/src/shared/LV2URIMap.cpp b/src/shared/LV2URIMap.cpp
index 5a8dbff0..24bc1611 100644
--- a/src/shared/LV2URIMap.cpp
+++ b/src/shared/LV2URIMap.cpp
@@ -53,63 +53,63 @@ LV2URIMap::Quark::c_str() const
#define NS_RDFS "http://www.w3.org/2000/01/rdf-schema#"
LV2URIMap::LV2URIMap()
- : atom_MessagePort (LV2_ATOM_URI "#MessagePort")
- , atom_AtomTransfer (LV2_ATOM_URI "#AtomTransfer")
- , atom_Bool (LV2_ATOM_URI "#Bool")
- , atom_Float32 (LV2_ATOM_URI "#Float32")
- , atom_Int32 (LV2_ATOM_URI "#Int32")
- , atom_String (LV2_ATOM_URI "#String")
- , atom_ValuePort (LV2_ATOM_URI "#ValuePort")
- , atom_Vector (LV2_ATOM_URI "#Vector")
- , atom_supports (LV2_ATOM_URI "#supports")
- , ctx_AudioContext (NS_CTX "AudioContext")
- , ctx_MessageContext (NS_CTX "MessageContext")
- , ctx_context (NS_CTX "context")
- , doap_name ("http://usefulinc.com/ns/doap#name")
- , ev_EventPort ("http://lv2plug.in/ns/ext/event#EventPort")
- , ingen_Internal (NS_INGEN "Internal")
- , ingen_LADSPAPlugin (NS_INGEN "LADSPAPlugin")
- , ingen_Node (NS_INGEN "Node")
- , ingen_Patch (NS_INGEN "Patch")
- , ingen_Port (NS_INGEN "Port")
- , ingen_broadcast (NS_INGEN "broadcast")
- , ingen_controlBinding (NS_INGEN "controlBinding")
- , ingen_document (NS_INGEN "document")
- , ingen_enabled (NS_INGEN "enabled")
- , ingen_nil (NS_INGEN "nil")
- , ingen_node (NS_INGEN "node")
- , ingen_polyphonic (NS_INGEN "polyphonic")
- , ingen_polyphony (NS_INGEN "polyphony")
- , ingen_selected (NS_INGEN "selected")
- , ingen_value (NS_INGEN "value")
- , ingenui_canvas_x (NS_INGENUI "canvas-x")
- , ingenui_canvas_y (NS_INGENUI "canvas-y")
- , lv2_AudioPort (NS_LV2 "AudioPort")
- , lv2_ControlPort (NS_LV2 "ControlPort")
- , lv2_InputPort (NS_LV2 "InputPort")
- , lv2_OutputPort (NS_LV2 "OutputPort")
- , lv2_Plugin (NS_LV2 "Plugin")
- , lv2_default (NS_LV2 "default")
- , lv2_index (NS_LV2 "index")
- , lv2_integer (NS_LV2 "integer")
- , lv2_maximum (NS_LV2 "maximum")
- , lv2_minimum (NS_LV2 "minimum")
- , lv2_name (NS_LV2 "name")
- , lv2_portProperty (NS_LV2 "portProperty")
- , lv2_symbol (NS_LV2 "symbol")
- , lv2_toggled (NS_LV2 "toggled")
- , midi_Bender (NS_MIDI "Bender")
- , midi_ChannelPressure (NS_MIDI "ChannelPressure")
- , midi_Controller (NS_MIDI "Controller")
- , midi_MidiEvent ("http://lv2plug.in/ns/ext/midi#MidiEvent")
- , midi_Note (NS_MIDI "Note")
- , midi_controllerNumber (NS_MIDI "controllerNumber")
- , midi_noteNumber (NS_MIDI "noteNumber")
- , rdf_instanceOf (NS_RDF "instanceOf")
- , rdf_type (NS_RDF "type")
- , rdfs_seeAlso (NS_RDFS "seeAlso")
- , ui_Events ("http://lv2plug.in/ns/extensions/ui#Events")
- , wildcard (NS_INGEN "wildcard")
+ : atom_AtomTransfer (LV2_ATOM_URI "#AtomTransfer")
+ , atom_Bool (LV2_ATOM_URI "#Bool")
+ , atom_Float32 (LV2_ATOM_URI "#Float32")
+ , atom_Int32 (LV2_ATOM_URI "#Int32")
+ , atom_MessagePort (LV2_ATOM_URI "#MessagePort")
+ , atom_String (LV2_ATOM_URI "#String")
+ , atom_ValuePort (LV2_ATOM_URI "#ValuePort")
+ , atom_Vector (LV2_ATOM_URI "#Vector")
+ , atom_supports (LV2_ATOM_URI "#supports")
+ , ctx_AudioContext (NS_CTX "AudioContext")
+ , ctx_MessageContext (NS_CTX "MessageContext")
+ , ctx_context (NS_CTX "context")
+ , doap_name ("http://usefulinc.com/ns/doap#name")
+ , ev_EventPort ("http://lv2plug.in/ns/ext/event#EventPort")
+ , ingen_Internal (NS_INGEN "Internal")
+ , ingen_LADSPAPlugin (NS_INGEN "LADSPAPlugin")
+ , ingen_Node (NS_INGEN "Node")
+ , ingen_Patch (NS_INGEN "Patch")
+ , ingen_Port (NS_INGEN "Port")
+ , ingen_broadcast (NS_INGEN "broadcast")
+ , ingen_controlBinding (NS_INGEN "controlBinding")
+ , ingen_document (NS_INGEN "document")
+ , ingen_enabled (NS_INGEN "enabled")
+ , ingen_nil (NS_INGEN "nil")
+ , ingen_node (NS_INGEN "node")
+ , ingen_polyphonic (NS_INGEN "polyphonic")
+ , ingen_polyphony (NS_INGEN "polyphony")
+ , ingen_selected (NS_INGEN "selected")
+ , ingen_value (NS_INGEN "value")
+ , ingenui_canvas_x (NS_INGENUI "canvas-x")
+ , ingenui_canvas_y (NS_INGENUI "canvas-y")
+ , lv2_AudioPort (NS_LV2 "AudioPort")
+ , lv2_ControlPort (NS_LV2 "ControlPort")
+ , lv2_InputPort (NS_LV2 "InputPort")
+ , lv2_OutputPort (NS_LV2 "OutputPort")
+ , lv2_Plugin (NS_LV2 "Plugin")
+ , lv2_default (NS_LV2 "default")
+ , lv2_index (NS_LV2 "index")
+ , lv2_integer (NS_LV2 "integer")
+ , lv2_maximum (NS_LV2 "maximum")
+ , lv2_minimum (NS_LV2 "minimum")
+ , lv2_name (NS_LV2 "name")
+ , lv2_portProperty (NS_LV2 "portProperty")
+ , lv2_symbol (NS_LV2 "symbol")
+ , lv2_toggled (NS_LV2 "toggled")
+ , midi_Bender (NS_MIDI "Bender")
+ , midi_ChannelPressure (NS_MIDI "ChannelPressure")
+ , midi_Controller (NS_MIDI "Controller")
+ , midi_MidiEvent ("http://lv2plug.in/ns/ext/midi#MidiEvent")
+ , midi_Note (NS_MIDI "Note")
+ , midi_controllerNumber (NS_MIDI "controllerNumber")
+ , midi_noteNumber (NS_MIDI "noteNumber")
+ , rdf_instanceOf (NS_RDF "instanceOf")
+ , rdf_type (NS_RDF "type")
+ , rdfs_seeAlso (NS_RDFS "seeAlso")
+ , ui_Events ("http://lv2plug.in/ns/extensions/ui#Events")
+ , wildcard (NS_INGEN "wildcard")
{
uri_map_feature_data.uri_to_id = &LV2URIMap::uri_map_uri_to_id;
uri_map_feature_data.callback_data = this;
@@ -132,7 +132,21 @@ uint32_t
LV2URIMap::uri_to_id(const char* map,
const char* uri)
{
- return static_cast<uint32_t>(g_quark_from_string(uri));
+ const uint32_t id = static_cast<uint32_t>(g_quark_from_string(uri));
+ if (map && !strcmp(map, "http://lv2plug.in/ns/ext/event")) {
+ GlobalToEvent::iterator i = _global_to_event.find(id);
+ if (i != _global_to_event.end()) {
+ return i->second;
+ } else {
+ const uint16_t ev_id = _global_to_event.size() + 1;
+ assert(_event_to_global.find(ev_id) == _event_to_global.end());
+ _global_to_event.insert(make_pair(id, ev_id));
+ _event_to_global.insert(make_pair(ev_id, id));
+ return ev_id;
+ }
+ } else {
+ return id;
+ }
}
@@ -140,8 +154,16 @@ const char*
LV2URIMap::id_to_uri(const char* map,
const uint32_t id)
{
- // FIXME: Handle event map properly
- return g_quark_to_string(id);
+ if (map && !strcmp(map, "http://lv2plug.in/ns/ext/event")) {
+ EventToGlobal::iterator i = _event_to_global.find(id);
+ if (i == _event_to_global.end()) {
+ error << "Failed to unmap event URI " << id << endl;
+ return NULL;
+ }
+ return g_quark_to_string(i->second);
+ } else {
+ return g_quark_to_string(id);
+ }
}
@@ -150,13 +172,8 @@ LV2URIMap::uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data,
const char* map,
const char* uri)
{
- LV2URIMap* me = (LV2URIMap*)callback_data;
- const uint32_t id = me->uri_to_id(map, uri);
-
- // FIXME: Handle event type map properly
- assert(!map || strcmp(map, "http://lv2plug.in/ns/ext/event") || id <= UINT16_MAX);
-
- return id;
+ LV2URIMap* me = (LV2URIMap*)callback_data;
+ return me->uri_to_id(map, uri);
}
@@ -166,10 +183,6 @@ LV2URIMap::uri_unmap_id_to_uri(LV2_URI_Map_Callback_Data callback_data,
uint32_t id)
{
LV2URIMap* me = (LV2URIMap*)callback_data;
-
- // FIXME: Handle event type map properly
- assert(!map || strcmp(map, "http://lv2plug.in/ns/ext/event") || id <= UINT16_MAX);
-
return me->id_to_uri(map, id);
}
diff --git a/src/shared/LV2URIMap.hpp b/src/shared/LV2URIMap.hpp
index c63214ea..894df25f 100644
--- a/src/shared/LV2URIMap.hpp
+++ b/src/shared/LV2URIMap.hpp
@@ -70,6 +70,12 @@ private:
LV2_URI_Unmap_Feature uri_unmap_feature_data;
SharedPtr<UnmapFeature> _unmap_feature;
+
+ typedef std::map<uint16_t, uint32_t> EventToGlobal;
+ typedef std::map<uint32_t, uint16_t> GlobalToEvent;
+
+ EventToGlobal _event_to_global;
+ GlobalToEvent _global_to_event;
public:
struct Quark : public Raul::URI {