Preliminary MIDI plugin support.
[ardour.git] / libs / ardour / uri_map.cc
1 /* This file is part of Ingen.
2  * Copyright (C) 2008 Dave Robillard <http://drobilla.net>
3  * 
4  * Ingen is free software; you can redistribute it and/or modify it under the
5  * terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  * 
9  * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
12  * 
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17
18 #define __STDC_LIMIT_MACROS 1
19 #include <cassert>
20 #include <iostream>
21 #include <stdint.h>
22 #include "ardour/uri_map.h"
23
24 using namespace std;
25
26 namespace ARDOUR {
27         
28
29 URIMap::URIMap()
30         : next_uri_id(1)
31 {
32         uri_map_feature_data.uri_to_id = &URIMap::uri_map_uri_to_id;
33         uri_map_feature_data.callback_data = this;
34         uri_map_feature.URI = LV2_URI_MAP_URI;
35         uri_map_feature.data = &uri_map_feature_data;
36 }
37
38         
39 uint32_t
40 URIMap::uri_to_id(const char* map,
41                   const char* uri)
42 {
43         return uri_map_uri_to_id(this, map, uri);
44 }
45
46
47 uint32_t
48 URIMap::uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data,
49                           const char*               map,
50                           const char*               uri)
51 {
52         // TODO: map ignored, < UINT16_MAX assumed
53         
54         URIMap* me = (URIMap*)callback_data;
55         uint32_t ret = 0;
56
57         Map::iterator i = me->uri_map.find(uri);
58         if (i != me->uri_map.end()) {
59                 ret = i->second;
60         } else {
61                 ret = me->next_uri_id++;
62                 me->uri_map.insert(make_pair(string(uri), ret));
63         }
64         
65         /*cout << "URI MAP (" << (map ? (void*)map : NULL)
66                 << "): " << uri << " -> " << ret << endl;*/
67
68         assert(ret <= UINT16_MAX);
69         return ret;
70 }
71
72
73 } // namespace ARDOUR
74