prototype online self-automating LV2 plugin interface
[ardour.git] / libs / ardour / ardour / uri_map.h
index 3fb8560022f71d6479063a9cbcfe69e7ba7012fa..523eb18e917e1dd6bdf5b2fcb7bf3d969ffe81f6 100644 (file)
 
 #include <boost/utility.hpp>
 
+#include <glibmm/threads.h>
+
 #include "lv2.h"
 #include "lv2/lv2plug.in/ns/ext/uri-map/uri-map.h"
 #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
 
-namespace ARDOUR {
+#include "ardour/libardour_visibility.h"
 
+namespace ARDOUR {
 
 /** Implementation of the LV2 uri-map and urid extensions.
+ *
+ * This just uses a pair of std::map and is not so great in the space overhead
+ * department, but it's fast enough and not really performance critical anyway.
  */
-class URIMap : public boost::noncopyable {
+class LIBARDOUR_API URIMap : public boost::noncopyable {
 public:
+       static URIMap& instance();
+
        URIMap();
 
        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,
-                          const char* uri);
-
-       const char* id_to_uri(const char* map,
-                             uint32_t    id);
+       LV2_URID_Map*   urid_map()   { return &_urid_map_feature_data; }
+       LV2_URID_Unmap* urid_unmap() { return &_urid_unmap_feature_data; }
+
+       uint32_t    uri_to_id(const char* uri);
+       const char* id_to_uri(uint32_t id) const;
+
+       // Cached URIDs for use in real-time code
+       struct URIDs {
+               void init(URIMap& uri_map);
+
+               uint32_t atom_Chunk;
+               uint32_t atom_Path;
+               uint32_t atom_Sequence;
+               uint32_t atom_eventTransfer;
+               uint32_t atom_URID;
+               uint32_t atom_Blank;
+               uint32_t atom_Object;
+               uint32_t atom_Float;
+               uint32_t log_Error;
+               uint32_t log_Note;
+               uint32_t log_Warning;
+               uint32_t midi_MidiEvent;
+               uint32_t time_Position;
+               uint32_t time_bar;
+               uint32_t time_barBeat;
+               uint32_t time_beatUnit;
+               uint32_t time_beatsPerBar;
+               uint32_t time_beatsPerMinute;
+               uint32_t time_frame;
+               uint32_t time_speed;
+               uint32_t patch_Get;
+               uint32_t patch_Set;
+               uint32_t patch_property;
+               uint32_t patch_value;
+#ifdef LV2_EXTENDED
+               uint32_t auto_event;
+               uint32_t auto_setup;
+               uint32_t auto_finalize;
+               uint32_t auto_start;
+               uint32_t auto_end;
+               uint32_t auto_parameter;
+               uint32_t auto_value;
+#endif
+       };
+
+       URIDs urids;
 
 private:
-       static uint32_t uri_map_uri_to_id(LV2_URI_Map_Callback_Data callback_data,
-                                         const char*               map,
-                                         const char*               uri);
-
-       static LV2_URID urid_map(LV2_URID_Map_Handle handle,
-                                const char*         uri);
+       typedef std::map<const std::string, uint32_t> Map;
+       typedef std::map<uint32_t, const std::string> Unmap;
 
-       static const char* urid_unmap(LV2_URID_Unmap_Handle handle,
-                                     LV2_URID              urid);
+       Map   _map;
+       Unmap _unmap;
 
-       typedef std::map<uint16_t, uint32_t> EventToGlobal;
-       typedef std::map<uint32_t, uint16_t> GlobalToEvent;
+       LV2_Feature         _uri_map_feature;
+       LV2_URI_Map_Feature _uri_map_feature_data;
+       LV2_Feature         _urid_map_feature;
+       LV2_URID_Map        _urid_map_feature_data;
+       LV2_Feature         _urid_unmap_feature;
+       LV2_URID_Unmap      _urid_unmap_feature_data;
 
-       EventToGlobal _event_to_global;
-       GlobalToEvent _global_to_event;
+       mutable Glib::Threads::Mutex _lock;
 
-       LV2_Feature           _uri_map_feature;
-       LV2_URI_Map_Feature   _uri_map_feature_data;
-       LV2_Feature           _urid_map_feature;
-       LV2_URID_Map          _urid_map_feature_data;
-       LV2_Feature           _urid_unmap_feature;
-       LV2_URID_Unmap        _urid_unmap_feature_data;
+       static URIMap* uri_map;
 };
 
-
 } // namespace ARDOUR
 
 #endif // __ardour_uri_map_h__