2 Copyright (C) 2008-2011 Paul Davis
3 Author: David Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "pbd/error.h"
29 #include "ardour/uri_map.h"
34 c_uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data,
38 URIMap* const me = (URIMap*)callback_data;
39 const uint32_t id = me->uri_to_id(uri);
41 /* The event context with the uri-map extension guarantees a value in the
42 range of uint16_t. Ardour used to map to a separate range to achieve
43 this, but unfortunately some plugins are broken and use the incorrect
44 context. To compensate, we simply use the same context for everything
45 and hope that anything in the event context gets mapped before
46 UINT16_MAX is reached (which will be fine unless something seriously
47 weird is going on). If this fails there is nothing we can do, die.
49 assert(!map || strcmp(map, "http://lv2plug.in/ns/ext/event")
56 c_urid_map(LV2_URID_Map_Handle handle,
59 URIMap* const me = (URIMap*)handle;
60 return me->uri_to_id(uri);
64 c_urid_unmap(LV2_URID_Unmap_Handle handle,
67 URIMap* const me = (URIMap*)handle;
68 return me->id_to_uri(urid);
73 _uri_map_feature_data.uri_to_id = c_uri_map_uri_to_id;
74 _uri_map_feature_data.callback_data = this;
75 _uri_map_feature.URI = LV2_URI_MAP_URI;
76 _uri_map_feature.data = &_uri_map_feature_data;
78 _urid_map_feature_data.map = c_urid_map;
79 _urid_map_feature_data.handle = this;
80 _urid_map_feature.URI = LV2_URID_MAP_URI;
81 _urid_map_feature.data = &_urid_map_feature_data;
83 _urid_unmap_feature_data.unmap = c_urid_unmap;
84 _urid_unmap_feature_data.handle = this;
85 _urid_unmap_feature.URI = LV2_URID_UNMAP_URI;
86 _urid_unmap_feature.data = &_urid_unmap_feature_data;
90 URIMap::uri_to_id(const char* uri)
92 const std::string urimm(uri);
93 const Map::const_iterator i = _map.find(urimm);
94 if (i != _map.end()) {
97 const uint32_t id = _map.size() + 1;
98 _map.insert(std::make_pair(urimm, id));
99 _unmap.insert(std::make_pair(id, urimm));
104 URIMap::id_to_uri(const uint32_t id) const
106 const Unmap::const_iterator i = _unmap.find(id);
107 return (i != _unmap.end()) ? i->second.c_str() : NULL;
110 } // namespace ARDOUR