Audacity 3.2.0
LV2FeaturesList.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file LV2FeaturesList.h
6
7 Paul Licameli split from LV2Effect.h
8
9 Audacity(R) is copyright (c) 1999-2013 Audacity Team.
10 License: GPL v2 or later. See License.txt.
11
12*********************************************************************/
13
14#ifndef __AUDACITY_LV2_FEATURES_LIST__
15#define __AUDACITY_LV2_FEATURES_LIST__
16
17#if USE_LV2
18
19#include "lv2/log/log.h"
20#include "lv2/uri-map/uri-map.h"
21
23#include "LV2Symbols.h"
24#include "LV2Preferences.h" // for DEFAULT_BLOCKSIZE
25
26// Define a reasonable default sequence size in bytes
27#define DEFAULT_SEQSIZE 8192
28
30
33class LV2_API LV2FeaturesListBase {
34public:
35 explicit LV2FeaturesListBase(const LilvPlugin &plug);
37
40
42 using FeaturePointers = std::vector<const LV2_Feature *>;
44
49 bool ValidateFeatures(const LilvNode *subject);
50
56 bool CheckFeatures(const LilvNode *subject, bool required);
57
58 const LilvPlugin &mPlug;
59 bool mNoResize{ false };
60};
61
62// Dummy "keyword" argument prevents overload resolution to the copy ctor
63struct WithBase_t{};
65
68public:
70 const LV2FeaturesListBase &baseFeatures);
72 FeaturePointers GetFeaturePointers() const override;
73 void AddFeature(const char *uri, const void *data);
75protected:
76 std::vector<LV2_Feature> mFeatures;
77};
78
79class LV2_API LV2FeaturesList : public LV2FeaturesListBase {
80public:
81 static ComponentInterfaceSymbol GetPluginSymbol(const LilvPlugin &plug);
82
83 explicit LV2FeaturesList(const LilvPlugin &plug);
84 ~LV2FeaturesList() override;
85
87 bool InitializeFeatures();
88
89 FeaturePointers GetFeaturePointers() const override;
90
93 static bool SuppliesWorkerInterface(const LilvPlugin &plug);
94
97 bool SuppliesWorkerInterface() const { return mSuppliesWorkerInterface; }
98
99 void AddFeature(const char *uri, const void *data);
100
101 // lv2 functions require a pointer to non-const in places, but presumably
102 // have no need to mutate the members of this structure
103 LV2_URID_Map *URIDMapFeature() const
104 { return const_cast<LV2_URID_Map*>(&mURIDMapFeature); }
105
106 LV2_URID URID_Map(const char *uri) const;
107
108protected:
109 static uint32_t uri_to_id(LV2_URI_Map_Callback_Data callback_data,
110 const char *map, const char *uri);
111 static LV2_URID urid_map(LV2_URID_Map_Handle handle, const char *uri);
112 static const char *urid_unmap(LV2_URID_Unmap_Handle handle, LV2_URID urid);
113 const char *URID_Unmap(LV2_URID urid);
114
115 static int log_printf(LV2_Log_Handle handle,
116 LV2_URID type, const char *fmt, ...);
117 static int log_vprintf(LV2_Log_Handle handle,
118 LV2_URID type, const char *fmt, va_list ap);
119 int LogVPrintf(LV2_URID type, const char *fmt, va_list ap);
120
121 // These objects contain C-style virtual function tables that we fill in
122 const LV2_URI_Map_Feature mUriMapFeature{
123 this, LV2FeaturesList::uri_to_id }; // Features we support
124 const LV2_URID_Map mURIDMapFeature{ this, LV2FeaturesList::urid_map };
125 const LV2_URID_Unmap mURIDUnmapFeature{ this, LV2FeaturesList::urid_unmap };
126 const LV2_Log_Log mLogFeature{
128
130
136
137 std::vector<LV2_Feature> mFeatures;
138
140
141public:
142 const bool mOk;
143};
144
145#endif
146#endif
constexpr WithBase_t WithBase
Lilv_ptr< LilvNodes, lilv_nodes_free > LilvNodesPtr
Declare URI identifiers used in calls to the lv2 library and a mapping of them to integers.
std::unique_ptr< Type, Lilv_deleter< Type, f > > Lilv_ptr
Generate classes of smart pointers to lv2 resources.
Definition: LV2Utils.h:26
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Extends one (immutable) feature list (whose lifetime contains this one's)
virtual ~ExtendedLV2FeaturesList()
const LV2FeaturesListBase & mBaseFeatures
std::vector< LV2_Feature > mFeatures
const LilvPlugin & mPlug
std::vector< const LV2_Feature * > FeaturePointers
Get vector of pointers to features, whose .data() can be passed to lv2.
LV2FeaturesListBase & operator=(const LV2FeaturesListBase &)=delete
LV2FeaturesListBase(const LV2FeaturesListBase &)=delete
virtual ~LV2FeaturesListBase()
virtual FeaturePointers GetFeaturePointers() const =0
LV2_URID_Map * URIDMapFeature() const
~LV2FeaturesList() override
LV2Symbols::URIDMap mURIDMap
Per-effect URID map allocates an ID for each URI on first lookup.
static LV2_URID urid_map(LV2_URID_Map_Handle handle, const char *uri)
std::vector< LV2_Feature > mFeatures
static uint32_t uri_to_id(LV2_URI_Map_Callback_Data callback_data, const char *map, const char *uri)
const bool mSuppliesWorkerInterface
static int log_printf(LV2_Log_Handle handle, LV2_URID type, const char *fmt,...)
static const char * urid_unmap(LV2_URID_Unmap_Handle handle, LV2_URID urid)
static int log_vprintf(LV2_Log_Handle handle, LV2_URID type, const char *fmt, va_list ap)
bool SuppliesWorkerInterface() const
std::vector< MallocString<> > URIDMap
Definition: LV2Symbols.h:142