Implement the LV2 urid extension and remove implementation of (experimental) LV2 uri-unmap extension.

git-svn-id: svn://localhost/ardour2/branches/3.0@10723 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2011-11-21 03:22:08 +00:00
parent da9b82732e
commit d2b7f0d3d2
4 changed files with 50 additions and 114 deletions

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2009 Paul Davis Copyright (C) 2009-2011 Paul Davis
Author: David Robillard Author: David Robillard
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@ -15,46 +15,48 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifndef __ardour_uri_map_h__ #ifndef __ardour_uri_map_h__
#define __ardour_uri_map_h__ #define __ardour_uri_map_h__
#include <map> #include <map>
#include <string>
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include "lv2.h" #include "lv2.h"
#include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h" #include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h"
#include "lv2/lv2plug.in/ns/ext/uri-unmap/uri-unmap.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
namespace ARDOUR { namespace ARDOUR {
/** Implementation of the LV2 URI Map extension /** Implementation of the LV2 uri-map and urid extensions.
*/ */
class URIMap : public boost::noncopyable { class URIMap : public boost::noncopyable {
public: public:
URIMap(); URIMap();
LV2_Feature* feature() { return &uri_map_feature; } LV2_Feature* uri_map_feature() { return &_uri_map_feature; }
LV2_Feature* urid_map_feature() { return &_urid_map_feature; }
LV2_Feature* urid_unmap_feature() { return &_urid_unmap_feature; }
uint32_t uri_to_id(const char* map, uint32_t uri_to_id(const char* map,
const char* uri); const char* uri);
const char* id_to_uri(const char* map, const char* id_to_uri(const char* map,
uint32_t id); uint32_t id);
private: private:
static uint32_t uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data, static uint32_t uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data,
const char* map, const char* map,
const char* uri); const char* uri);
static const char* uri_unmap_id_to_uri(LV2_URI_Map_Callback_Data callback_data, static LV2_URID urid_map(LV2_URID_Map_Handle handle,
const char* map, const char* uri);
const uint32_t id);
static const char* urid_unmap(LV2_URID_Unmap_Handle handle,
LV2_URID urid);
typedef std::map<uint16_t, uint32_t> EventToGlobal; typedef std::map<uint16_t, uint32_t> EventToGlobal;
typedef std::map<uint32_t, uint16_t> GlobalToEvent; typedef std::map<uint32_t, uint16_t> GlobalToEvent;
@ -62,10 +64,12 @@ private:
EventToGlobal _event_to_global; EventToGlobal _event_to_global;
GlobalToEvent _global_to_event; GlobalToEvent _global_to_event;
LV2_Feature uri_map_feature; LV2_Feature _uri_map_feature;
LV2_URI_Map_Feature uri_map_feature_data; LV2_URI_Map_Feature _uri_map_feature_data;
LV2_Feature uri_unmap_feature; LV2_Feature _urid_map_feature;
LV2_URI_Unmap_Feature uri_unmap_feature_data; LV2_URID_Map _urid_map_feature_data;
LV2_Feature _urid_unmap_feature;
LV2_URID_Unmap _urid_unmap_feature_data;
}; };

View file

@ -1,81 +0,0 @@
/* lv2_uri_unmap.h - C header file for the LV2 URI Unmap extension.
*
* Copyright (C) 2010 David Robillard <http://drobilla.net>
*
* This header is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This header 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 Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this header; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
*/
/** @file
* C header for the LV2 URI Map extension <http://lv2plug.in/ns/ext/uri-unmap>.
*/
#ifndef LV2_URI_UNMAP_H
#define LV2_URI_UNMAP_H
#define LV2_URI_UNMAP_URI "http://lv2plug.in/ns/ext/uri-unmap"
#include <stdint.h>
/** Opaque pointer to host data. */
typedef void* LV2_URI_Unmap_Callback_Data;
/** The data field of the LV2_Feature for the URI Unmap extension.
*
* To support this extension the host must pass an LV2_Feature struct to the
* plugin's instantiate method with URI "http://lv2plug.in/ns/ext/uri-unmap"
* and data pointed to an instance of this struct.
*/
typedef struct {
/** Opaque pointer to host data.
*
* The plugin MUST pass this to any call to functions in this struct.
* Otherwise, it must not be interpreted in any way.
*/
LV2_URI_Unmap_Callback_Data callback_data;
/** Get the numeric ID of a URI from the host.
*
* @param callback_data Must be the callback_data member of this struct.
* @param map The 'context' used to map this URI.
* @param id The URI ID to unmap.
* @return The string form of @a id, or NULL on error.
*
* The @a id MUST be a value previously returned from
* LV2_Uri_Map_Feature.uri_to_id.
*
* The returned string is owned by the host and MUST NOT be freed by
* the plugin or stored for a long period of time (e.g. across run
* invocations) without copying.
*
* This function is referentially transparent - any number of calls with
* the same arguments is guaranteed to return the same value over the life
* of a plugin instance (though the same ID may return different values
* with a different map parameter).
*
* This function may be called from any non-realtime thread, possibly
* concurrently (hosts may simply use a mutex to meet these requirements).
*/
const char* (*id_to_uri)(LV2_URI_Unmap_Callback_Data callback_data,
const char* map,
uint32_t id);
} LV2_URI_Unmap_Feature;
#endif /* LV2_URI_UNMAP_H */

View file

@ -167,13 +167,15 @@ LV2Plugin::init(void* c_plugin, framecnt_t rate)
} }
#endif #endif
_features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * 6); _features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * 8);
_features[0] = &_instance_access_feature; _features[0] = &_instance_access_feature;
_features[1] = &_data_access_feature; _features[1] = &_data_access_feature;
_features[2] = &_path_support_feature; _features[2] = &_path_support_feature;
_features[3] = &_new_file_support_feature; _features[3] = &_new_file_support_feature;
_features[4] = _uri_map.feature(); _features[4] = _uri_map.uri_map_feature();
_features[5] = NULL; _features[5] = _uri_map.urid_map_feature();
_features[6] = _uri_map.urid_unmap_feature();
_features[7] = NULL;
LV2_Files_Path_Support* path_support = (LV2_Files_Path_Support*)malloc( LV2_Files_Path_Support* path_support = (LV2_Files_Path_Support*)malloc(
sizeof(LV2_Files_Path_Support)); sizeof(LV2_Files_Path_Support));

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2008-2010 Paul Davis Copyright (C) 2008-2011 Paul Davis
Author: David Robillard Author: David Robillard
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
@ -15,7 +15,6 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <cassert> #include <cassert>
@ -37,15 +36,20 @@ namespace ARDOUR {
URIMap::URIMap() URIMap::URIMap()
{ {
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_data.callback_data = this;
uri_map_feature.URI = LV2_URI_MAP_URI; _uri_map_feature.URI = LV2_URI_MAP_URI;
uri_map_feature.data = &uri_map_feature_data; _uri_map_feature.data = &_uri_map_feature_data;
uri_unmap_feature_data.id_to_uri = &URIMap::uri_unmap_id_to_uri; _urid_map_feature_data.map = &URIMap::urid_map;
uri_unmap_feature_data.callback_data = this; _urid_map_feature_data.handle = this;
uri_unmap_feature.URI = LV2_URI_UNMAP_URI; _urid_map_feature.URI = LV2_URID_MAP_URI;
uri_unmap_feature.data = &uri_unmap_feature_data; _urid_map_feature.data = &_urid_map_feature_data;
_urid_unmap_feature_data.unmap = &URIMap::urid_unmap;
_urid_unmap_feature_data.handle = this;
_urid_unmap_feature.URI = LV2_URID_UNMAP_URI;
_urid_unmap_feature.data = &_urid_unmap_feature_data;
} }
@ -98,19 +102,26 @@ URIMap::uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data,
const char* map, const char* map,
const char* uri) const char* uri)
{ {
URIMap* me = (URIMap*)callback_data; URIMap* const me = (URIMap*)callback_data;
return me->uri_to_id(map, uri); return me->uri_to_id(map, uri);
}
LV2_URID
URIMap::urid_map(LV2_URID_Map_Handle handle,
const char* uri)
{
URIMap* const me = (URIMap*)handle;
return me->uri_to_id(NULL, uri);
} }
const char* const char*
URIMap::uri_unmap_id_to_uri(LV2_URI_Map_Callback_Data callback_data, URIMap::urid_unmap(LV2_URID_Unmap_Handle handle,
const char* map, LV2_URID urid)
uint32_t id)
{ {
URIMap* me = (URIMap*)callback_data; URIMap* const me = (URIMap*)handle;
return me->id_to_uri(map, id); return me->id_to_uri(NULL, urid);
} }