-
Notifications
You must be signed in to change notification settings - Fork 41
/
linvst.cpp
487 lines (398 loc) · 11.4 KB
/
linvst.cpp
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/* linvst is based on wacvst Copyright 2009 retroware. All rights reserved. and
dssi-vst Copyright 2004-2007 Chris Cannam
linvst Mark White 2017
This file is part of linvst.
linvst 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 3 of the License, or
(at your option) 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. *
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "remotevstclient.h"
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/wait.h>
extern "C" {
#define VST_EXPORT __attribute__((visibility("default")))
extern VST_EXPORT AEffect *VSTPluginMain(audioMasterCallback audioMaster);
AEffect *main_plugin(audioMasterCallback audioMaster) asm("main");
#define main main_plugin
VST_EXPORT AEffect *main(audioMasterCallback audioMaster) {
return VSTPluginMain(audioMaster);
}
}
VstIntPtr dispatcher(AEffect *effect, VstInt32 opcode, VstInt32 index,
VstIntPtr value, void *ptr, float opt) {
RemotePluginClient *plugin = (RemotePluginClient *)effect->object;
VstIntPtr v = 0;
#ifdef EMBED
#ifdef TRACKTIONWM
char dawbuf[512];
#endif
#endif
if (!effect)
return 0;
if (!plugin)
return 0;
if (plugin->m_inexcept == 1) {
return 0;
}
if (plugin->m_threadbreak == 1) {
return 0;
}
switch (opcode) {
case effEditGetRect:
if (plugin->editopen == 1)
{
*((struct ERect **)ptr) = plugin->rp;
v = 1;
}
else
v = 0;
break;
case effEditIdle:
sched_yield();
break;
case effStartProcess:
plugin->effVoidOp(effStartProcess);
break;
case effStopProcess:
plugin->effVoidOp(effStopProcess);
break;
case effMainsChanged:
v = plugin->getEffInt(effMainsChanged, value);
break;
case effGetVendorString:
// strncpy((char *) ptr, plugin->getMaker().c_str(),
// kVstMaxVendorStrLen);
strcpy((char *)ptr, plugin->getMaker().c_str());
v = 1;
break;
case effGetEffectName:
// strncpy((char *) ptr, plugin->getName().c_str(),
// kVstMaxEffectNameLen);
strcpy((char *)ptr, plugin->getName().c_str());
v = 1;
break;
case effGetParamName:
// strncpy((char *) ptr, plugin->getParameterName(index).c_str(),
// kVstMaxParamStrLen);
// strncpy((char *) ptr, plugin->getParameterName(index).c_str(),
// kVstMaxVendorStrLen);
strcpy((char *)ptr, plugin->getParameterName(index).c_str());
break;
case effGetParamLabel:
strcpy((char *)ptr, plugin->getParameterLabel(index).c_str());
// strcpy((char *) ptr, plugin->getEffString(effGetParamLabel,
// index).c_str());
break;
case effGetParamDisplay:
strcpy((char *)ptr, plugin->getParameterDisplay(index).c_str());
// strcpy((char *) ptr, plugin->getEffString(effGetParamDisplay,
// index).c_str());
break;
case effGetProgramNameIndexed:
v = plugin->getProgramNameIndexed(index, (char *)ptr);
break;
case effGetProgramName:
// strncpy((char *) ptr, plugin->getProgramName().c_str(),
// kVstMaxProgNameLen);
strcpy((char *)ptr, plugin->getProgramName().c_str());
break;
case effSetSampleRate:
plugin->setSampleRate(opt);
break;
case effSetBlockSize:
plugin->setBufferSize((VstInt32)value);
break;
#ifdef DOUBLEP
case effSetProcessPrecision:
v = plugin->getEffInt(effSetProcessPrecision, value);
break;
#endif
case effGetInputProperties:
v = plugin->getEffInProp(index, (char *)ptr);
break;
case effGetOutputProperties:
v = plugin->getEffOutProp(index, (char *)ptr);
break;
#ifdef MIDIEFF
case effGetMidiKeyName:
v = plugin->getEffMidiKey(index, (char *)ptr);
break;
case effGetMidiProgramName:
v = plugin->getEffMidiProgName(index, (char *)ptr);
break;
case effGetCurrentMidiProgram:
v = plugin->getEffMidiCurProg(index, (char *)ptr);
break;
case effGetMidiProgramCategory:
v = plugin->getEffMidiProgCat(index, (char *)ptr);
break;
case effHasMidiProgramsChanged:
v = plugin->getEffMidiProgCh(index);
break;
case effSetSpeakerArrangement:
v = plugin->setEffSpeaker(value, (char *)ptr);
break;
case effGetSpeakerArrangement:
v = plugin->getEffSpeaker(value, (char *)ptr);
break;
#endif
case effGetVstVersion:
v = kVstVersion;
break;
case effGetPlugCategory:
v = plugin->getEffInt(effGetPlugCategory, 0);
break;
#ifdef WAVES
case effShellGetNextPlugin:
v = plugin->getShellName((char *)ptr);
break;
#endif
case effSetProgram:
plugin->setCurrentProgram((VstInt32)value);
break;
case effEditOpen:
#ifdef EMBED
plugin->editopen = 0;
plugin->winm->handle = (intptr_t)ptr;
plugin->winm->winerror = 0;
plugin->winm->width = 0;
plugin->winm->height = 0;
plugin->showGUI();
if(plugin->winm->winerror == 0)
{
plugin->rp->bottom = plugin->winm->height;
plugin->rp->top = 0;
plugin->rp->right = plugin->winm->width;
plugin->rp->left = 0;
}
else
break;
#else
plugin->showGUI();
#endif
plugin->editopen = 1;
v = 1;
break;
case effEditClose:
if((plugin->editopen == 1) && (plugin->winm->winerror == 0))
{
plugin->hideGUI();
plugin->editopen = 0;
v = 1;
}
break;
case effCanDo:
if (ptr && !strcmp((char *)ptr, "hasCockosExtensions")) {
plugin->reaperid = 1;
plugin->effVoidOp(78345432);
}
#ifdef EMBED
#ifdef TRACKTIONWM
if(plugin->reaperid == 0)
{
if(plugin->theEffect && plugin->m_audioMaster)
{
plugin->m_audioMaster(plugin->theEffect, audioMasterGetProductString, 0, 0, dawbuf, 0);
if((strcmp(dawbuf, "Tracktion") == 0) || (strcmp(dawbuf, "Waveform") == 0))
{
plugin->hosttracktion = 1;
plugin->waveformid = plugin->effVoidOp2(67584930, index, value, opt);
}
}
}
#endif
#endif
#ifdef CANDOEFF
v = plugin->getEffCanDo((char *)ptr);
#else
v = 1;
#endif
break;
case effProcessEvents:
v = plugin->processVstEvents((VstEvents *)ptr);
break;
case effGetChunk:
v = plugin->getChunk((void **)ptr, index);
break;
case effSetChunk:
v = plugin->setChunk(ptr, value, index);
break;
case effGetProgram:
v = plugin->getProgram();
break;
case effCanBeAutomated:
v = plugin->canBeAutomated(index);
break;
case effOpen:
plugin->EffectOpen();
break;
case effClose:
if(plugin->winm->winerror == 1)
plugin->winm->winerror = 0;
else
{
if(plugin->editopen == 1)
{
plugin->hideGUI();
plugin->editopen = 0;
v = 1;
}
}
plugin->effVoidOp(effClose);
delete plugin;
break;
default:
break;
}
return v;
}
void processDouble(AEffect *effect, double **inputs, double **outputs,
VstInt32 sampleFrames) {
#ifdef DOUBLEP
RemotePluginClient *plugin = (RemotePluginClient *)effect->object;
if (!plugin)
return;
if ((plugin->m_bufferSize > 0) && (plugin->m_numInputs >= 0) &&
(plugin->m_numOutputs >= 0)) {
plugin->processdouble(inputs, outputs, sampleFrames);
}
#endif
return;
}
void process(AEffect *effect, float **inputs, float **outputs,
VstInt32 sampleFrames) {
RemotePluginClient *plugin = (RemotePluginClient *)effect->object;
if (!plugin)
return;
if ((plugin->m_bufferSize > 0) && (plugin->m_numInputs >= 0) &&
(plugin->m_numOutputs >= 0)) {
plugin->process(inputs, outputs, sampleFrames);
}
return;
}
void setParameter(AEffect *effect, VstInt32 index, float parameter) {
RemotePluginClient *plugin = (RemotePluginClient *)effect->object;
if (!plugin)
return;
if ((plugin->m_bufferSize > 0) && (plugin->m_numInputs >= 0) &&
(plugin->m_numOutputs >= 0)) {
plugin->setParameter(index, parameter);
}
return;
}
float getParameter(AEffect *effect, VstInt32 index) {
RemotePluginClient *plugin = (RemotePluginClient *)effect->object;
float retval = -1;
if (!plugin)
return retval;
if ((plugin->m_bufferSize > 0) && (plugin->m_numInputs >= 0) &&
(plugin->m_numOutputs >= 0)) {
retval = plugin->getParameter(index);
}
return retval;
}
void initEffect(AEffect *eff, RemotePluginClient *plugin) {
memset(eff, 0x0, sizeof(AEffect));
eff->magic = kEffectMagic;
eff->dispatcher = dispatcher;
eff->setParameter = setParameter;
eff->getParameter = getParameter;
eff->numInputs = plugin->getInputCount();
eff->numOutputs = plugin->getOutputCount();
eff->numPrograms = plugin->getProgramCount();
eff->numParams = plugin->getParameterCount();
eff->flags = plugin->getFlags();
#ifndef DOUBLEP
eff->flags &= ~effFlagsCanDoubleReplacing;
eff->flags |= effFlagsCanReplacing;
#endif
eff->resvd1 = 0;
eff->resvd2 = 0;
eff->initialDelay = plugin->getinitialDelay();
eff->object = (void *)plugin;
eff->user = 0;
eff->uniqueID = plugin->getUID();
eff->version = plugin->getVersion();
eff->processReplacing = process;
#ifdef DOUBLEP
eff->processDoubleReplacing = processDouble;
#endif
}
void errwin2() {
Window window = 0;
Window ignored = 0;
Display *display = 0;
int screen = 0;
Atom winstate;
Atom winmodal;
std::string filename2;
filename2 = "lin-vst-server/vst not found or LinVst version mismatch";
XInitThreads();
display = XOpenDisplay(NULL);
if (!display)
return;
screen = DefaultScreen(display);
window = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10,
480, 20, 0, BlackPixel(display, screen),
WhitePixel(display, screen));
if (!window)
return;
winstate = XInternAtom(display, "_NET_WM_STATE", True);
winmodal = XInternAtom(display, "_NET_WM_STATE_ABOVE", True);
XChangeProperty(display, window, winstate, XA_ATOM, 32, PropModeReplace,
(unsigned char *)&winmodal, 1);
XStoreName(display, window, filename2.c_str());
XMapWindow(display, window);
XSync(display, false);
sleep(10);
XSync(display, false);
XDestroyWindow(display, window);
XSync(display, false);
XCloseDisplay(display);
display = 0;
}
VST_EXPORT AEffect *VSTPluginMain(audioMasterCallback audioMaster) {
RemotePluginClient *plugin;
if (!audioMaster(0, audioMasterVersion, 0, 0, 0, 0))
return 0;
// try {
plugin = new RemoteVSTClient(audioMaster);
// } catch (std::string e) {
if(!plugin)
{
std::cerr << "Could not connect to Server" << std::endl;
errwin2();
return 0;
}
if (plugin->m_runok == 2) {
std::cerr << "LinVst Error: trying to load unnamed linvst.so" << std::endl;
if (plugin)
delete plugin;
return 0;
}
if (plugin->m_runok == 1) {
std::cerr << "LinVst Error: lin-vst-server not found or vst dll load timeout or LinVst version mismatch" << std::endl;
// errwin2();
if (plugin)
delete plugin;
return 0;
}
initEffect(plugin->theEffect, plugin);
#ifdef EMBED
XInitThreads();
#endif
return plugin->theEffect;
}