X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Furi_map.cc;h=a702ee3862d8b685694a1755edb157e791cdb1a0;hb=454f14d9c58de541a230c266ad59987b8ca7b1a4;hp=2c2861e3852c79a8fc0d190c5bc7b46c2adabb98;hpb=b85b4d9e54caef0585d308ef3bffee21d0e5ae56;p=ardour.git diff --git a/libs/ardour/uri_map.cc b/libs/ardour/uri_map.cc index 2c2861e385..a702ee3862 100644 --- a/libs/ardour/uri_map.cc +++ b/libs/ardour/uri_map.cc @@ -1,23 +1,33 @@ -/* This file is part of Ingen. - * Copyright (C) 2008 Dave Robillard - * - * Ingen is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) 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 General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ +/* + Copyright (C) 2008-2010 Paul Davis + Author: David Robillard + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ #include #include + #include +#include + +#include + +#include "pbd/error.h" + #include "ardour/uri_map.h" using namespace std; @@ -26,12 +36,16 @@ namespace ARDOUR { URIMap::URIMap() - : next_uri_id(1) { - uri_map_feature_data.uri_to_id = &URIMap::uri_map_uri_to_id; + uri_map_feature_data.uri_to_id = &URIMap::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; + uri_map_feature.URI = LV2_URI_MAP_URI; + uri_map_feature.data = &uri_map_feature_data; + + uri_unmap_feature_data.id_to_uri = &URIMap::uri_unmap_id_to_uri; + uri_unmap_feature_data.callback_data = this; + uri_unmap_feature.URI = LV2_URI_UNMAP_URI; + uri_unmap_feature.data = &uri_unmap_feature_data; } @@ -39,33 +53,64 @@ uint32_t URIMap::uri_to_id(const char* map, const char* uri) { - return uri_map_uri_to_id(this, map, uri); + const uint32_t id = static_cast(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 { + if (_global_to_event.size() + 1 > UINT16_MAX) { + PBD::error << "Event URI " << uri << " ID out of range." << endl; + return 0; + } + 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; + } +} + + +const char* +URIMap::id_to_uri(const char* map, + const uint32_t 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()) { + PBD::error << "Failed to unmap event URI " << id << endl; + return NULL; + } + return g_quark_to_string(i->second); + } else { + return g_quark_to_string(id); + } + } uint32_t URIMap::uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data, - const char* /*map*/, + const char* map, const char* uri) { - // TODO: map ignored, < UINT16_MAX assumed - URIMap* me = (URIMap*)callback_data; - uint32_t ret = 0; + return me->uri_to_id(map, uri); - Map::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 ? (void*)map : NULL) - << "): " << uri << " -> " << ret << endl;*/ - assert(ret <= UINT16_MAX); - return ret; +const char* +URIMap::uri_unmap_id_to_uri(LV2_URI_Map_Callback_Data callback_data, + const char* map, + uint32_t id) +{ + URIMap* me = (URIMap*)callback_data; + return me->id_to_uri(map, id); }