-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
CarlaPluginInternal.hpp
385 lines (292 loc) · 10.8 KB
/
CarlaPluginInternal.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*
* Carla Plugin
* Copyright (C) 2011-2014 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program 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 General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/
#ifndef CARLA_PLUGIN_INTERNAL_HPP_INCLUDED
#define CARLA_PLUGIN_INTERNAL_HPP_INCLUDED
#include "CarlaPlugin.hpp"
#include "CarlaLibUtils.hpp"
#include "CarlaStateUtils.hpp"
#include "CarlaMIDI.h"
#include "CarlaMutex.hpp"
#include "CarlaString.hpp"
#include "RtLinkedList.hpp"
CARLA_BACKEND_START_NAMESPACE
// -----------------------------------------------------------------------
// Engine helper macro, sets lastError and returns false/NULL
#define CARLA_SAFE_ASSERT_RETURN_ERR(cond, err) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); pData->engine->setLastError(err); return false; }
#define CARLA_SAFE_ASSERT_RETURN_ERRN(cond, err) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); pData->engine->setLastError(err); return nullptr; }
#define CARLA_SAFE_EXCEPTION_RETURN_ERR(excptMsg, errMsg) catch(...) { carla_safe_exception(excptMsg, __FILE__, __LINE__); pData->engine->setLastError(errMsg); return false; }
#define CARLA_SAFE_EXCEPTION_RETURN_ERRN(excptMsg, errMsg) catch(...) { carla_safe_exception(excptMsg, __FILE__, __LINE__); pData->engine->setLastError(errMsg); return nullptr; }
// -----------------------------------------------------------------------
// Maximum pre-allocated events for some plugin types
const ushort kPluginMaxMidiEvents = 512;
// -----------------------------------------------------------------------
// Extra plugin hints, hidden from backend
const uint PLUGIN_EXTRA_HINT_HAS_MIDI_IN = 0x01;
const uint PLUGIN_EXTRA_HINT_HAS_MIDI_OUT = 0x02;
const uint PLUGIN_EXTRA_HINT_CAN_RUN_RACK = 0x04;
// -----------------------------------------------------------------------
// Special parameters
enum SpecialParameterType {
PARAMETER_SPECIAL_NULL = 0,
PARAMETER_SPECIAL_FREEWHEEL = 1,
PARAMETER_SPECIAL_LATENCY = 2,
PARAMETER_SPECIAL_SAMPLE_RATE = 3,
PARAMETER_SPECIAL_TIME = 4
};
// -----------------------------------------------------------------------
/*!
* Post-RT event type.
* These are events postponned from within the process function,
*
* During process, we cannot lock, allocate memory or do UI stuff,
* so events have to be postponned to be executed later, on a separate thread.
* @see PluginPostRtEvent
*/
enum PluginPostRtEventType {
kPluginPostRtEventNull = 0,
kPluginPostRtEventDebug,
kPluginPostRtEventParameterChange, // param, SP (*), value (SP: if 1 only report change to UI, don't report to Callback and OSC)
kPluginPostRtEventProgramChange, // index
kPluginPostRtEventMidiProgramChange, // index
kPluginPostRtEventNoteOn, // channel, note, velo
kPluginPostRtEventNoteOff // channel, note
};
/*!
* A Post-RT event.
* @see PluginPostRtEventType
*/
struct PluginPostRtEvent {
PluginPostRtEventType type;
int32_t value1;
int32_t value2;
float value3;
};
// -----------------------------------------------------------------------
struct ExternalMidiNote {
int8_t channel; // invalid if -1
uint8_t note; // 0 to 127
uint8_t velo; // 1 to 127, 0 for note-off
};
// -----------------------------------------------------------------------
struct PluginAudioPort {
uint32_t rindex;
CarlaEngineAudioPort* port;
};
struct PluginAudioData {
uint32_t count;
PluginAudioPort* ports;
PluginAudioData() noexcept;
~PluginAudioData() noexcept;
void createNew(const uint32_t newCount);
void clear() noexcept;
void initBuffers() const noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PluginAudioData)
};
// -----------------------------------------------------------------------
struct PluginCVPort {
uint32_t rindex;
//uint32_t param; // FIXME is this needed?
CarlaEngineCVPort* port;
};
struct PluginCVData {
uint32_t count;
PluginCVPort* ports;
PluginCVData() noexcept;
~PluginCVData() noexcept;
void createNew(const uint32_t newCount);
void clear() noexcept;
void initBuffers() const noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PluginCVData)
};
// -----------------------------------------------------------------------
struct PluginEventData {
CarlaEngineEventPort* portIn;
CarlaEngineEventPort* portOut;
PluginEventData() noexcept;
~PluginEventData() noexcept;
void clear() noexcept;
void initBuffers() const noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PluginEventData)
};
// -----------------------------------------------------------------------
struct PluginParameterData {
uint32_t count;
ParameterData* data;
ParameterRanges* ranges;
SpecialParameterType* special;
PluginParameterData() noexcept;
~PluginParameterData() noexcept;
void createNew(const uint32_t newCount, const bool withSpecial);
void clear() noexcept;
float getFixedValue(const uint32_t parameterId, const float& value) const noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PluginParameterData)
};
// -----------------------------------------------------------------------
typedef const char* ProgramName;
struct PluginProgramData {
uint32_t count;
int32_t current;
ProgramName* names;
PluginProgramData() noexcept;
~PluginProgramData() noexcept;
void createNew(const uint32_t newCount);
void clear() noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PluginProgramData)
};
// -----------------------------------------------------------------------
struct PluginMidiProgramData {
uint32_t count;
int32_t current;
MidiProgramData* data;
PluginMidiProgramData() noexcept;
~PluginMidiProgramData() noexcept;
void createNew(const uint32_t newCount);
void clear() noexcept;
const MidiProgramData& getCurrent() const noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PluginMidiProgramData)
};
// -----------------------------------------------------------------------
struct CarlaPlugin::ProtectedData {
CarlaEngine* const engine;
CarlaEngineClient* client;
uint id;
uint hints;
uint options;
uint32_t nodeId;
bool active;
bool enabled;
bool needsReset;
lib_t lib;
lib_t uiLib;
// misc
int8_t ctrlChannel;
uint extraHints;
uint transientTryCounter;
// data 1
const char* name;
const char* filename;
const char* iconName;
// data 2
PluginAudioData audioIn;
PluginAudioData audioOut;
PluginCVData cvIn;
PluginCVData cvOut;
PluginEventData event;
PluginParameterData param;
PluginProgramData prog;
PluginMidiProgramData midiprog;
LinkedList<CustomData> custom;
CarlaMutex masterMutex; // global master lock
CarlaMutex singleMutex; // small lock used only in processSingle()
CarlaStateSave stateSave;
struct ExternalNotes {
CarlaMutex mutex;
RtLinkedList<ExternalMidiNote>::Pool dataPool;
RtLinkedList<ExternalMidiNote> data;
ExternalNotes() noexcept;
~ExternalNotes() noexcept;
void appendNonRT(const ExternalMidiNote& note) noexcept;
void clear() noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(ExternalNotes)
} extNotes;
struct Latency {
uint32_t frames;
#ifndef BUILD_BRIDGE
uint32_t channels;
float** buffers;
#endif
Latency() noexcept;
#ifndef BUILD_BRIDGE
~Latency() noexcept;
void clearBuffers() noexcept;
void recreateBuffers(const uint32_t newChannels, const uint32_t newFrames);
#endif
CARLA_DECLARE_NON_COPY_STRUCT(Latency)
} latency;
struct PostRtEvents {
CarlaMutex mutex;
RtLinkedList<PluginPostRtEvent>::Pool dataPool;
RtLinkedList<PluginPostRtEvent> data;
RtLinkedList<PluginPostRtEvent> dataPendingRT;
PostRtEvents() noexcept;
~PostRtEvents() noexcept;
void appendRT(const PluginPostRtEvent& event) noexcept;
void trySplice() noexcept;
void clear() noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PostRtEvents)
} postRtEvents;
struct PostUiEvents {
CarlaMutex mutex;
LinkedList<PluginPostRtEvent> data;
PostUiEvents() noexcept;
~PostUiEvents() noexcept;
void append(const PluginPostRtEvent& event) noexcept;
void clear() noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PostUiEvents)
} postUiEvents;
#ifndef BUILD_BRIDGE
struct PostProc {
float dryWet;
float volume;
float balanceLeft;
float balanceRight;
float panning;
PostProc() noexcept;
CARLA_DECLARE_NON_COPY_STRUCT(PostProc)
} postProc;
#endif
ProtectedData(CarlaEngine* const engine, const uint idx) noexcept;
~ProtectedData() noexcept;
// -------------------------------------------------------------------
// Buffer functions
void clearBuffers() noexcept;
// -------------------------------------------------------------------
// Post-poned events
void postponeRtEvent(const PluginPostRtEvent& rtEvent) noexcept;
void postponeRtEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const float value3) noexcept;
// -------------------------------------------------------------------
// Library functions
static const char* libError(const char* const filename) noexcept;
bool libOpen(const char* const filename) noexcept;
bool libClose() noexcept;
bool uiLibOpen(const char* const filename, const bool canDelete) noexcept;
bool uiLibClose() noexcept;
template<typename Func>
Func libSymbol(const char* const symbol) const noexcept
{
return lib_symbol<Func>(lib, symbol);
}
template<typename Func>
Func uiLibSymbol(const char* const symbol) const noexcept
{
return lib_symbol<Func>(uiLib, symbol);
}
// -------------------------------------------------------------------
// Misc
#ifndef BUILD_BRIDGE
void tryTransient() noexcept;
#endif
void updateParameterValues(CarlaPlugin* const plugin, const bool sendOsc, const bool sendCallback, const bool useDefault) noexcept;
// -------------------------------------------------------------------
#ifdef CARLA_PROPER_CPP11_SUPPORT
ProtectedData() = delete;
CARLA_DECLARE_NON_COPY_STRUCT(ProtectedData);
#endif
CARLA_LEAK_DETECTOR(ProtectedData);
};
CARLA_BACKEND_END_NAMESPACE
#endif // CARLA_PLUGIN_INTERNAL_HPP_INCLUDED