Audacity 3.2.0
LV2Symbols.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file LV2Symbols.cpp
6
7 Paul Licameli split from LoadLV2.cpp
8
9*********************************************************************/
10
11#include "LV2Symbols.h"
12#include <wx/crt.h>
13#include "lv2/atom/atom.h"
14#include "lv2/buf-size/buf-size.h"
15#include "lv2/log/log.h"
16#include "lv2/midi/midi.h"
17#include "lv2/options/options.h"
18#include "lv2/parameters/parameters.h"
19#include "lv2/port-groups/port-groups.h"
20#include "lv2/port-props/port-props.h"
21#include "lv2/presets/presets.h"
22#include "lv2/resize-port/resize-port.h"
23#include "lv2/time/time.h"
24#include "lv2/units/units.h"
25#include "lv2_external_ui.h"
26
27namespace LV2Symbols {
28
31LilvWorld *gWorld = nullptr;
32
33// Define the static URI map
35
36// Define the static LILV URI nodes
37#undef NODE
38#define NODE(n, u) \
39 LilvNode *node_##n = nullptr; \
40 LilvNodePtr unode_##n;
42
43// Define the static URIDs
44#undef URID
45#define URID(n, u) LV2_URID urid_##n = 0;
47
49{
50 // Try to initialise Lilv, or return.
51 uWorld.reset(lilv_world_new());
52 if (!uWorld)
53 return false;
54 gWorld = uWorld.get();
55
56 // Create LilvNodes for each of the URIs we need
57 #undef NODE
58 #define NODE(n, u) \
59 unode_##n.reset(lilv_new_uri(gWorld, u)); \
60 node_##n = unode_##n.get();
62
63 // Generate URIDs
64 #undef URID
65 #define URID(n, u) urid_##n = Lookup_URI(gURIDMap, u);
67
68 return true;
69}
70
72{
73 gWorld = nullptr;
74}
75
76LV2_URID Lookup_URI(URIDMap & map, const char *uri, bool add)
77{
78 size_t ndx = map.size();
79 for (size_t i = 0; i < ndx; ++i)
80 if (strcmp(map[i].get(), uri) == 0)
81 return i + 1;
82 if (add) {
83 // Almost all compilers have strdup(),
84 // but VC++ and MinGW call it _strdup().
85 map.push_back(MallocString<>(wxCRT_StrdupA(uri)));
86 return ndx + 1;
87 }
88 return 0;
89}
90
91}
Declare URI identifiers used in calls to the lv2 library and a mapping of them to integers.
#define NODELIST
Definition: LV2Symbols.h:48
#define URIDLIST
Definition: LV2Symbols.h:92
std::unique_ptr< Type, Lilv_deleter< Type, f > > Lilv_ptr
Generate classes of smart pointers to lv2 resources.
Definition: LV2Utils.h:26
std::unique_ptr< Character[], freer > MallocString
Definition: MemoryX.h:147
Lilv_ptr< LilvWorld, lilv_world_free > LilvWorldPtr
Definition: LV2Symbols.cpp:29
void FinalizeGWorld()
Call at end of session.
Definition: LV2Symbols.cpp:71
URIDLIST bool InitializeGWorld()
Call before any use of the constants defined in this file.
Definition: LV2Symbols.cpp:48
std::vector< MallocString<> > URIDMap
Definition: LV2Symbols.h:142
static LilvWorldPtr uWorld
Definition: LV2Symbols.cpp:30
LV2_URID Lookup_URI(URIDMap &map, const char *uri, bool add)
Definition: LV2Symbols.cpp:76
LilvWorld * gWorld
Definition: LV2Symbols.cpp:31
URIDMap gURIDMap
Declare the global map of positive integers to URIs.
Definition: LV2Symbols.cpp:34
void add(const T *src1, const T *src2, T *dst, int32_t n)
Definition: VectorOps.h:46