forked from Tremus/CPLUG
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcplug_vst3.c
More file actions
2157 lines (1859 loc) · 86.9 KB
/
Copy pathcplug_vst3.c
File metadata and controls
2157 lines (1859 loc) · 86.9 KB
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This file is subject to the terms of the VST3 SDK License. See here https://www.steinberg.net/sdklicenses
* Originally authored by Filipe Coelho as a part of DPF https://github.com/DISTRHO/DPF
* A special thanks goes to him for allowing the use of his code here.
* Edited and ported to CPLUG by Tré Dudman */
#include <cplug.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <vst3_c_api.h>
#include <wchar.h>
#ifdef __cplusplus
extern "C" {
#endif
#define tuid_match(a, b) memcmp(a, b, sizeof(Steinberg_TUID)) == 0
#ifndef ARRSIZE
#define ARRSIZE(a) (sizeof(a) / sizeof(a[0]))
#endif
static const uint32_t cplug_midiControllerOffset = 0xffffffff - (16 * Steinberg_Vst_ControllerNumbers_kCountCtrlNumber);
#define CALL_SMTG_INLINE_UID(args) SMTG_INLINE_UID args
static const Steinberg_TUID cplug_tuid_component = CALL_SMTG_INLINE_UID((CPLUG_VST3_TUID_COMPONENT));
static const Steinberg_TUID cplug_tuid_controller = CALL_SMTG_INLINE_UID((CPLUG_VST3_TUID_CONTROLLER));
const char* _cplug_tuid2str(const Steinberg_TUID iid)
{
static const struct
{
const Steinberg_TUID* iid;
const char* name;
} _known_iids[] = {
// Supported
{&Steinberg_Vst_IAudioProcessor_iid, "{Steinberg_Vst_IAudioProcessor_iid}"},
{&Steinberg_Vst_IAttributeList_iid, "{Steinberg_Vst_IComponent_iid}"},
{&Steinberg_IBStream_iid, "{Steinberg_IBStream_iid}"},
{&Steinberg_Vst_IComponent_iid, "{Steinberg_Vst_IComponent_iid}"},
{&Steinberg_Vst_IComponentHandler_iid, "{Steinberg_Vst_IComponentHandler_iid}"},
{&Steinberg_Vst_IConnectionPoint_iid, "{Steinberg_Vst_IConnectionPoint_iid}"},
{&Steinberg_Vst_IEditController_iid, "{Steinberg_Vst_IEditController_iid}"},
{&Steinberg_Vst_IEventList_iid, "{Steinberg_Vst_IEventList_iid}"},
{&Steinberg_FUnknown_iid, "{Steinberg_FUnknown_iid}"},
{&Steinberg_Vst_IHostApplication_iid, "{Steinberg_Vst_IHostApplication_iid}"},
{&Steinberg_IPluginBase_iid, "{Steinberg_IPluginBase_iid}"},
{&Steinberg_IPluginFactory_iid, "{Steinberg_IPluginFactory_iid}"},
{&Steinberg_IPluginFactory2_iid, "{Steinberg_IPluginFactory2_iid}"},
{&Steinberg_IPluginFactory3_iid, "{Steinberg_IPluginFactory3_iid}"},
{&Steinberg_IPlugView_iid, "{Steinberg_IPlugView_iid}"},
{&Steinberg_IPlugViewContentScaleSupport_iid, "{Steinberg_IPlugViewContentScaleSupport_iid}"},
{&Steinberg_Vst_IProcessContextRequirements_iid, "{Steinberg_Vst_IProcessContextRequirements_iid}"},
// edit-controller
{&Steinberg_Vst_IComponentHandler2_iid, "{Steinberg_Vst_IComponentHandler2_iid}"},
{&Steinberg_Vst_IEditController2_iid, "{Steinberg_Vst_IEditController2_iid}"},
{&Steinberg_Vst_IComponentHandlerBusActivation_iid, "{Steinberg_Vst_IComponentHandlerBusActivation_iid}"},
{&Steinberg_Vst_IEditControllerHostEditing_iid, "{Steinberg_Vst_IEditControllerHostEditing_iid}"},
{&Steinberg_Vst_INoteExpressionController_iid, "{Steinberg_Vst_INoteExpressionController_iid}"},
{&Steinberg_Vst_IKeyswitchController_iid, "{Steinberg_Vst_IKeyswitchController_iid}"},
{&Steinberg_Vst_IMidiLearn_iid, "{Steinberg_Vst_IMidiLearn_iid}"},
// units
{&Steinberg_Vst_IProgramListData_iid, "{Steinberg_Vst_IProgramListData_iid}"},
{&Steinberg_Vst_IUnitData_iid, "{Steinberg_Vst_IUnitData_iid}"},
{&Steinberg_Vst_IUnitHandler_iid, "{Steinberg_Vst_IUnitHandler_iid}"},
{&Steinberg_Vst_IUnitHandler2_iid, "{Steinberg_Vst_IUnitHandler2_iid}"},
{&Steinberg_Vst_IUnitInfo_iid, "{Steinberg_Vst_IUnitInfo_iid}"},
// misc
{&Steinberg_Vst_IAudioPresentationLatency_iid, "{Steinberg_Vst_IAudioPresentationLatency_iid}"},
{&Steinberg_Vst_IAutomationState_iid, "{Steinberg_Vst_IAutomationState_iid}"},
{&Steinberg_Vst_ChannelContext_IInfoListener_iid, "{Steinberg_Vst_ChannelContext_IInfoListener_iid}"},
{&Steinberg_Vst_IParameterFunctionName_iid, "{Steinberg_Vst_IParameterFunctionName_iid}"},
{&Steinberg_Vst_IPrefetchableSupport_iid, "{Steinberg_Vst_IPrefetchableSupport_iid}"},
{&Steinberg_Vst_IXmlRepresentationController_iid, "{Steinberg_Vst_IXmlRepresentationController_iid}"},
{&Steinberg_Vst_IMessage_iid, "{Steinberg_Vst_IMessage_iid}"},
{&Steinberg_Vst_IMidiMapping_iid, "{Steinberg_Vst_IMidiMapping_iid}"},
{&Steinberg_Vst_IParamValueQueue_iid, "{Steinberg_Vst_IParamValueQueue_iid}"},
{&Steinberg_Vst_IParameterChanges_iid, "{Steinberg_Vst_IParameterChanges_iid}"},
{&Steinberg_IPlugFrame_iid, "{Steinberg_IPlugFrame_iid}"},
{&Steinberg_Vst_IParameterFinder_iid, "{Steinberg_Vst_IParameterFinder_iid}"},
};
if (tuid_match(iid, cplug_tuid_component))
return "{cplug_tuid_component}";
if (tuid_match(iid, cplug_tuid_controller))
return "{cplug_tuid_controller}";
for (size_t i = 0; i < ARRSIZE(_known_iids); ++i)
{
if (tuid_match(iid, _known_iids[i].iid))
return _known_iids[i].name;
}
// Steinberg swizzle their UIDs outside of Windows. Here we unswizzle it so we can read the same IDs
unsigned* idu32 = (unsigned*)&iid[0];
Steinberg_TUID unswizzled = SMTG_INLINE_UID(idu32[0], idu32[1], idu32[2], idu32[3]);
idu32 = (unsigned*)&unswizzled[0];
static char buf[46];
snprintf(buf, sizeof(buf), "{0x%08X,0x%08X,0x%08X,0x%08X}", idu32[0], idu32[1], idu32[2], idu32[3]);
return buf;
}
#if CPLUG_NUM_INPUT_BUSSES + CPLUG_NUM_OUTPUT_BUSSES > 0
// someone please tell me what is up with these..
static inline Steinberg_Vst_Speaker _cplug_channelCountToVST3Speaker(const uint32_t channelCount)
{
switch (channelCount)
{
// regular mono
case 1:
return Steinberg_Vst_kSpeakerM;
// regular stereo
case 2:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR;
// stereo with center channel
case 3:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerC;
// stereo with surround (quadro)
case 4:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs;
// regular 5.0
case 5:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs |
Steinberg_Vst_kSpeakerC;
// regular 6.0
case 6:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs |
Steinberg_Vst_kSpeakerSl | Steinberg_Vst_kSpeakerSr;
// regular 7.0
case 7:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs |
Steinberg_Vst_kSpeakerSl | Steinberg_Vst_kSpeakerSr | Steinberg_Vst_kSpeakerC;
// regular 8.0
case 8:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs |
Steinberg_Vst_kSpeakerSl | Steinberg_Vst_kSpeakerSr | Steinberg_Vst_kSpeakerC | Steinberg_Vst_kSpeakerCs;
// regular 8.1
case 9:
return Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs |
Steinberg_Vst_kSpeakerSl | Steinberg_Vst_kSpeakerSr | Steinberg_Vst_kSpeakerC |
Steinberg_Vst_kSpeakerCs | Steinberg_Vst_kSpeakerLfe;
// cinema 10.0
case 10:
return (
Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs |
Steinberg_Vst_kSpeakerSl | Steinberg_Vst_kSpeakerSr | Steinberg_Vst_kSpeakerLc | Steinberg_Vst_kSpeakerRc |
Steinberg_Vst_kSpeakerC | Steinberg_Vst_kSpeakerCs);
// cinema 10.1
case 11:
return (
Steinberg_Vst_kSpeakerL | Steinberg_Vst_kSpeakerR | Steinberg_Vst_kSpeakerLs | Steinberg_Vst_kSpeakerRs |
Steinberg_Vst_kSpeakerSl | Steinberg_Vst_kSpeakerSr | Steinberg_Vst_kSpeakerLc | Steinberg_Vst_kSpeakerRc |
Steinberg_Vst_kSpeakerC | Steinberg_Vst_kSpeakerCs | Steinberg_Vst_kSpeakerLfe);
default:
cplug_log("[WARNING]: _cplug_channelCountToVST3Speaker: Unsupported number of channels %u", channelCount);
return 0;
}
}
#endif
#ifndef NDEBUG
static inline const char* _cplug_getMediaTypeStr(int32_t type)
{
if (type == Steinberg_Vst_MediaTypes_kAudio)
return "MediaTypes_kAudio";
if (type == Steinberg_Vst_MediaTypes_kEvent)
return "MediaTypes_kEvent";
return "[unknown]";
}
static inline const char* _cplug_getBusDirectionStr(int32_t type)
{
if (type == Steinberg_Vst_BusDirections_kInput)
return "BusDirections_kInput";
if (type == Steinberg_Vst_BusDirections_kOutput)
return "BusDirections_kOutput";
return "[unknown]";
}
#endif
// clang-format off
// Taken from Richard Mitton & Randy Gaul (public domain)
// https://github.com/RandyGaul/cute_headers_deprecated/blob/master/cute_utf.h
const char* _cplug_decode8(const char* text, int* cp)
{
unsigned char c = *text++;
int extra = 0, min = 0;
*cp = 0;
if (c >= 0xF0) { *cp = c & 0x07; extra = 3; min = 0x10000; }
else if (c >= 0xE0) { *cp = c & 0x0F; extra = 2; min = 0x800; }
else if (c >= 0xC0) { *cp = c & 0x1F; extra = 1; min = 0x80; }
else if (c >= 0x80) { *cp = 0xFFFD; }
else { *cp = c; }
while (extra--)
{
c = *text++;
if ((c & 0xC0) != 0x80) { *cp = 0xFFFD; break; }
(*cp) = ((*cp) << 6) | (c & 0x3F);
}
if (*cp < min) *cp = 0xFFFD;
return text;
}
char* _cplug_encode8(char *text, int cp)
{
if (cp < 0 || cp > 0x10FFFF) cp = 0xFFFD;
#define CU_EMIT(X, Y, Z) *text++ = X | ((cp >> Y) & Z)
if (cp < 0x80) { CU_EMIT(0x00,0,0x7F); }
else if (cp < 0x800) { CU_EMIT(0xC0,6,0x1F); CU_EMIT(0x80, 0, 0x3F); }
else if (cp < 0x10000) { CU_EMIT(0xE0,12,0xF); CU_EMIT(0x80, 6, 0x3F); CU_EMIT(0x80, 0, 0x3F); }
else { CU_EMIT(0xF0,18,0x7); CU_EMIT(0x80, 12, 0x3F); CU_EMIT(0x80, 6, 0x3F); CU_EMIT(0x80, 0, 0x3F); }
#undef CU_EMIT
return text;
}
char16_t* _cplug_encode16(char16_t* text, int cp)
{
if (cp < 0x10000) *text++ = cp;
else
{
cp -= 0x10000;
*text++ = 0xD800 | ((cp >> 10) & 0x03FF);
*text++ = 0xDC00 | (cp & 0x03FF);
}
return text;
}
const char16_t* _cplug_decode16(const char16_t* text, int* cp)
{
int in = *text++;
if (in < 0xD800 || in > 0xDFFF) *cp = in;
else if (in > 0xD800 && in < 0xDBFF) *cp = ((in & 0x03FF) << 10) | (*text++ & 0x03FF);
else *cp = 0xFFFD;
return text;
}
void _cplug_utf8To16(char16_t* dst, const char* src, int len)
{
char16_t* it = dst;
int cp;
while (*src && (it < dst + len - 1))
{
src = _cplug_decode8(src, &cp);
it = _cplug_encode16(it, cp);
}
*it = 0;
}
void _cplug_utf16To8(char* dst, const char16_t* src, int len)
{
char* it = dst;
int cp;
while (*src && (it < dst + len - 1))
{
src = _cplug_decode16(src, &cp);
it = _cplug_encode8(it, cp);
}
*it = 0;
}
// clang-format on
/*----------------------------------------------------------------------------------------------------------------------
Structs */
// NOTE: You're not allowed to simply receive MIDI data
// https://steinbergmedia.github.io/vst3_doc/vstinterfaces/classSteinberg_1_1Vst_1_1IMidiMapping.html
struct VST3MidiMapping
{
Steinberg_Vst_IMidiMappingVtbl* lpVtbl;
Steinberg_Vst_IMidiMappingVtbl base;
} g_vst3MidiMapping;
typedef struct VST3Controller
{
Steinberg_Vst_IEditControllerVtbl* lpVtbl;
Steinberg_Vst_IEditControllerVtbl base;
cplug_atomic_i32 refcounter;
// TODO: support changing param count & other cool things
Steinberg_Vst_IComponentHandler* componentHandler;
} VST3Controller;
struct VST3ProcessContextRequirements
{
Steinberg_Vst_IProcessContextRequirementsVtbl* lpVtbl;
Steinberg_Vst_IProcessContextRequirementsVtbl base;
} g_vst3ProcessContext;
typedef struct VST3Processor
{
Steinberg_Vst_IAudioProcessorVtbl* lpVtbl;
Steinberg_Vst_IAudioProcessorVtbl base;
cplug_atomic_i32 refcounter;
} VST3Processor;
typedef struct VST3Component
{
Steinberg_Vst_IComponentVtbl* lpVtbl;
Steinberg_Vst_IComponentVtbl base;
cplug_atomic_i32 refcounter;
} VST3Component;
typedef struct VST3Factory
{
Steinberg_IPluginFactory3Vtbl* lpVtbl;
Steinberg_IPluginFactory3Vtbl base;
cplug_atomic_i32 refcounter;
// We don't use this, but it's here in case you need it...
Steinberg_FUnknown* hostContext;
} VST3Factory;
typedef struct VST3Plugin
{
void* userPlugin; // Pointer to your plugin lives here
VST3Component component;
VST3Controller controller;
VST3Processor processor;
// We don't use this, but it's here in case you need it...
Steinberg_Vst_IHostApplication* host;
// Not all hosts (Ableton) pass MIDI controller events through the process callback. In Steinberg logic, MIDI
// controller messages are parameters, and hosts will call 'setParamNormalized' to send these messages
// NOTE: We only assume that hosts aren't doubly stupid and only send these messages on the audio thread.
size_t midiContollerQueueSize;
uint32_t midiContollerQueue[CPLUG_EVENT_QUEUE_SIZE];
} VST3Plugin;
// Naughty pointer shifting for VST3 classes
static VST3Plugin* _cplug_pointerShiftController(VST3Controller* ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, controller));
}
static VST3Plugin* _cplug_pointerShiftProcessor(VST3Processor* ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, processor));
}
static VST3Plugin* _cplug_pointerShiftComponent(VST3Component* ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, component));
}
// Guard against plugin hosts that lose track of their own refs to your plugin
static VST3Plugin** _cplug_leakedVST3Arr = NULL;
static int _cplug_leakedVST3Count = 0;
static int _cplug_leakedVST3Cap = 0;
static void _cplug_pushLeakedVST3(VST3Plugin* ptr)
{
if (_cplug_leakedVST3Cap >= _cplug_leakedVST3Count)
{
_cplug_leakedVST3Cap += 32;
size_t nextCapBytes = sizeof(void*) * (_cplug_leakedVST3Cap);
_cplug_leakedVST3Arr = (VST3Plugin**)realloc(_cplug_leakedVST3Arr, nextCapBytes);
}
_cplug_leakedVST3Arr[_cplug_leakedVST3Count] = ptr;
_cplug_leakedVST3Count++;
}
static int _cplug_tryDeleteVST3(VST3Plugin* vst3)
{
int total = 0;
total += cplug_atomic_load_i32(&vst3->component.refcounter);
total += cplug_atomic_load_i32(&vst3->controller.refcounter);
total += cplug_atomic_load_i32(&vst3->processor.refcounter);
if (total != 0)
return 0;
cplug_log("_cplug_tryDeleteVST3 %p | all refcounts are zero, deleting everything!", vst3);
free(vst3);
// If we previously stored a ptr that looked like a leak, we remove it
for (int i = 0; i < _cplug_leakedVST3Count; i++)
{
if (_cplug_leakedVST3Arr[i] == vst3)
{
cplug_log("_cplug_tryDeleteVST3 %p | Removing VST3 from leak array", vst3);
_cplug_leakedVST3Count--;
if (i != _cplug_leakedVST3Count)
{
size_t bytes = sizeof(void*) * (_cplug_leakedVST3Count - i);
memmove(_cplug_leakedVST3Arr + i, _cplug_leakedVST3Arr + i + 1, bytes);
}
break;
}
}
return 1;
}
#if CPLUG_WANT_GUI
typedef struct VST3ViewContentScale
{
Steinberg_IPlugViewContentScaleSupportVtbl* lpVtbl;
Steinberg_IPlugViewContentScaleSupportVtbl base;
cplug_atomic_i32 refcounter;
} VST3ViewContentScale;
typedef struct VST3View
{
Steinberg_IPlugViewVtbl* lpVtbl;
Steinberg_IPlugViewVtbl base;
cplug_atomic_i32 refcounter;
#ifdef _WIN32
// Windows only. MacOS is able to detect scale changes using 'viewDidChangeBackingProperties' in NSView
VST3ViewContentScale scale;
#endif
void* userGUI;
} VST3View;
#ifdef _WIN32
/*----------------------------------------------------------------------------------------------------------------------
Source: "pluginterfaces/gui/iplugviewcontentscalesupport.h", line 57 */
// Steinberg_FUnknown
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3ViewContentScale_queryInterface(void* const self, const Steinberg_TUID iid, void** const iface)
{
VST3ViewContentScale* const scale = (VST3ViewContentScale*)self;
if (tuid_match(iid, Steinberg_FUnknown_iid) || tuid_match(iid, Steinberg_IPlugViewContentScaleSupport_iid))
{
cplug_log("VST3ViewContentScale_queryInterface => %p %s %p | OK", self, _cplug_tuid2str(iid), iface);
cplug_atomic_fetch_add_i32(&scale->refcounter, 1);
*iface = self;
return Steinberg_kResultOk;
}
cplug_log(
"VST3ViewContentScale_queryInterface => %p %s %p | WARNING UNSUPPORTED",
self,
_cplug_tuid2str(iid),
iface);
*iface = NULL;
return Steinberg_kNoInterface;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3ViewContentScale_addRef(void* const self)
{
VST3ViewContentScale* const scale = (VST3ViewContentScale*)self;
return cplug_atomic_fetch_add_i32(&scale->refcounter, 1) + 1;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3ViewContentScale_release(void* const self)
{
VST3ViewContentScale* const scale = (VST3ViewContentScale*)self;
int refcount = cplug_atomic_fetch_add_i32(&scale->refcounter, -1) - 1;
if (refcount == 0 && cplug_atomic_load_i32(&scale->refcounter) == 0)
{
cplug_log("VST3ViewContentScale_setContentScaleFactor | Freeing VST3View");
VST3View* view = (VST3View*)((char*)scale - offsetof(VST3View, scale));
free(view);
}
return refcount;
}
// Steinberg_IPlugViewContentScaleSupport
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3ViewContentScale_setContentScaleFactor(void* const self, const float factor)
{
VST3ViewContentScale* const scale = (VST3ViewContentScale*)self;
cplug_log("VST3ViewContentScale_setContentScaleFactor => %p %f", self, factor);
VST3View* view = (VST3View*)((char*)scale - offsetof(VST3View, scale));
cplug_setScaleFactor(view->userGUI, factor);
return Steinberg_kResultOk;
}
#endif // _WIN32
/*----------------------------------------------------------------------------------------------------------------------
Source: "pluginterfaces/gui/iplugview.h", line 122 */
// Steinberg_FUnknown
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3View_queryInterface(void* self, const Steinberg_TUID iid, void** iface)
{
VST3View* const view = (VST3View*)self;
if (tuid_match(iid, Steinberg_FUnknown_iid) || tuid_match(iid, Steinberg_IPlugView_iid))
{
cplug_log("VST3View_queryInterface => %p %s %p | OK", self, _cplug_tuid2str(iid), iface);
cplug_atomic_fetch_add_i32(&view->refcounter, 1);
*iface = self;
return Steinberg_kResultOk;
}
#ifdef _WIN32
if (tuid_match(Steinberg_IPlugViewContentScaleSupport_iid, iid))
{
cplug_log("VST3View_queryInterface => %p %s %p | OK convert", self, _cplug_tuid2str(iid), iface);
cplug_atomic_fetch_add_i32(&view->scale.refcounter, 1);
*iface = &view->scale;
return Steinberg_kResultOk;
}
#endif
cplug_log("VST3View_queryInterface => %p %s %p | WARNING UNSUPPORTED", self, _cplug_tuid2str(iid), iface);
*iface = NULL;
return Steinberg_kNoInterface;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3View_addRef(void* self)
{
VST3View* const view = (VST3View*)self;
int refcount = cplug_atomic_fetch_add_i32(&view->refcounter, 1) + 1;
cplug_log("VST3View_addRef => %p | refcount %i", self, refcount);
return refcount;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3View_release(void* self)
{
VST3View* const view = (VST3View*)self;
const int view_refcount = cplug_atomic_fetch_add_i32(&view->refcounter, -1) - 1;
cplug_log("VST3View_release => %p | refcount %i", self, view_refcount);
if (view_refcount)
return view_refcount;
cplug_setVisible(view->userGUI, false);
// Some hosts (Ableton) don't call removed() before destroying your GUI, others (Bitwig) do.
cplug_setParent(view->userGUI, NULL);
cplug_destroyGUI(view->userGUI);
#ifndef _WIN32
free(view);
#else
cplug_log("VST3View_release | should call free from IPlugViewContentScaleSupport extension");
view->scale.lpVtbl->release(&view->scale);
#endif
return 0;
}
// ----------------------------------------------------------------------------------------------------------------
// Steinberg_IPlugView
#if defined(_WIN32)
#define CPLUG_VST3_GUI_API Steinberg_kPlatformTypeHWND
#elif defined(__APPLE__)
#define CPLUG_VST3_GUI_API Steinberg_kPlatformTypeNSView
#else
#define CPLUG_VST3_GUI_API Steinberg_kPlatformTypeX11EmbedWindowID
#endif
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3View_isPlatformTypeSupported(void* const self, const char* const platform_type)
{
cplug_log("VST3View_isPlatformTypeSupported => %p %s", self, platform_type);
if (strcmp(platform_type, CPLUG_VST3_GUI_API) == 0)
return Steinberg_kResultOk;
return Steinberg_kResultFalse;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3View_attached(void* const self, void* const parent, const char* const platform_type)
{
cplug_log("VST3View_attached => %p %p %s", self, parent, platform_type);
VST3View* const view = (VST3View*)self;
cplug_setParent(view->userGUI, parent);
cplug_setVisible(view->userGUI, parent != NULL);
return Steinberg_kResultOk;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3View_removed(void* const self)
{
cplug_log("VST3View_removed => %p", self);
VST3View* const view = (VST3View*)self;
cplug_setVisible(view->userGUI, false);
cplug_setParent(view->userGUI, NULL);
return Steinberg_kResultOk;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3View_onWheel(void* const self, const float distance)
{
return Steinberg_kResultFalse;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3View_onKeyDown(void* const self, const char16_t key_char, const int16_t key_code, const int16_t modifiers)
{
cplug_log("VST3View_onKeyDown => %p %hu %hu %hu", self, key_char, key_code, modifiers);
return Steinberg_kResultFalse;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3View_onKeyUp(void* const self, const char16_t key_char, const int16_t key_code, const int16_t modifiers)
{
cplug_log("VST3View_onKeyUp => %p %hu %hu %hu", self, key_char, key_code, modifiers);
return Steinberg_kResultFalse;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3View_getSize(void* const self, struct Steinberg_ViewRect* const rect)
{
cplug_log("VST3View_getSize");
uint32_t width, height;
cplug_getSize(((VST3View*)self)->userGUI, &width, &height);
rect->right = rect->left + width;
rect->bottom = rect->top + height;
return Steinberg_kResultOk;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3View_onSize(void* const self, struct Steinberg_ViewRect* const rect)
{
cplug_log("VST3View_onSize => %p {%d,%d,%d,%d}", self, rect->top, rect->left, rect->right, rect->bottom);
int width = rect->right - rect->left;
int height = rect->bottom - rect->top;
CPLUG_LOG_ASSERT_RETURN(width >= 0, Steinberg_kInvalidArgument);
CPLUG_LOG_ASSERT_RETURN(height >= 0, Steinberg_kInvalidArgument);
return ! cplug_setSize(((VST3View*)self)->userGUI, width, height);
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3View_onFocus(void* const self, const Steinberg_TBool state)
{
cplug_log("VST3View_onFocus => %p %hhu", state);
// TODO: Ableton seems to lose track of who has focus. Not sure if this is an Ableton bug or our fault.
return Steinberg_kResultFalse;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3View_setFrame(void* const self, Steinberg_IPlugFrame* const frame)
{
cplug_log("VST3View_setFrame => %p %p", self, frame);
return Steinberg_kResultTrue;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3View_canResize(void* const self) { return ! CPLUG_GUI_RESIZABLE; }
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3View_checkSizeConstraint(void* const self, struct Steinberg_ViewRect* const rect)
{
cplug_log("VST3View_checkSizeConstraint => %p %d %d %d %d", self, rect->left, rect->top, rect->right, rect->bottom);
uint32_t width = rect->right - rect->left;
uint32_t height = rect->bottom - rect->top;
cplug_checkSize(((VST3View*)self)->userGUI, &width, &height);
rect->right = rect->left + width;
rect->bottom = rect->top + height;
// We always return Ok here because Ableton 10 won't change their behaviour if we return anything else
return Steinberg_kResultOk;
}
#endif // CPLUG_WANT_GUI
/*----------------------------------------------------------------------------------------------------------------------
Source: "pluginterfaces/vst/ivsteditcontroller.h", line 557 */
// Steinberg_FUnknown
Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3MidiMapping_queryInterface(void* thisInterface, const Steinberg_TUID iid, void** obj)
{
if (tuid_match(iid, Steinberg_Vst_IMidiMapping_iid))
{
cplug_log("VST3MidiMapping_queryInterface => %p %s %p | OK", thisInterface, _cplug_tuid2str(iid), obj);
*obj = thisInterface;
return Steinberg_kResultOk;
}
cplug_log(
"VST3MidiMapping_queryInterface => %p %s %p | WARNING UNSUPPORTED",
thisInterface,
_cplug_tuid2str(iid),
obj);
*obj = NULL;
return Steinberg_kNoInterface;
}
Steinberg_uint32 SMTG_STDMETHODCALLTYPE VST3MidiMapping_addRef(void* thisInterface) { return 1; }
Steinberg_uint32 SMTG_STDMETHODCALLTYPE VST3MidiMapping_release(void* thisInterface) { return 0; }
// Steinberg_Vst_IMidiMapping
Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3MidiMapping_getMidiControllerAssignment(
void* thisInterface,
Steinberg_int32 busIndex,
Steinberg_int16 channel,
Steinberg_Vst_CtrlNumber midiControllerNumber,
Steinberg_Vst_ParamID* id)
{
// This gets hammered at startup
// cplug_log("VST3MidiMapping_getMidiControllerAssignment => %p %d %hd %u %p", thisInterface, busIndex, channel,
// midiControllerNumber, id);
CPLUG_LOG_ASSERT_RETURN(busIndex == 0, Steinberg_kResultFalse);
CPLUG_LOG_ASSERT_RETURN(
midiControllerNumber < Steinberg_Vst_ControllerNumbers_kCountCtrlNumber,
Steinberg_kResultFalse);
*id = cplug_midiControllerOffset + channel * 16 + midiControllerNumber;
return Steinberg_kResultTrue;
}
/*----------------------------------------------------------------------------------------------------------------------
Source: "pluginterfaces/vst/ivsteditcontroller.h", line 398 */
// Steinberg_FUnknown
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_queryInterface(void* const self, const Steinberg_TUID iid, void** const iface)
{
VST3Controller* const controller = (VST3Controller*)self;
if (tuid_match(iid, Steinberg_FUnknown_iid) || tuid_match(iid, Steinberg_IPluginBase_iid) ||
tuid_match(iid, Steinberg_Vst_IEditController_iid))
{
cplug_log("VST3Controller_queryInterface => %p %s %p | OK", self, _cplug_tuid2str(iid), iface);
cplug_atomic_fetch_add_i32(&controller->refcounter, 1);
*iface = self;
return Steinberg_kResultOk;
}
if (tuid_match(iid, Steinberg_Vst_IMidiMapping_iid))
{
*iface = &g_vst3MidiMapping;
return Steinberg_kResultOk;
}
cplug_log("VST3Controller_queryInterface => %p %s %p | WARNING UNSUPPORTED", self, _cplug_tuid2str(iid), iface);
*iface = NULL;
return Steinberg_kNoInterface;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3Controller_addRef(void* const self)
{
VST3Controller* const controller = (VST3Controller*)self;
const int refcount = cplug_atomic_fetch_add_i32(&controller->refcounter, 1) + 1;
cplug_log("VST3Controller_addRef => %p | refcount %i", self, refcount);
return refcount;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3Controller_release(void* const self)
{
VST3Plugin* vst3 = _cplug_pointerShiftController((VST3Controller*)self);
const int refcount = cplug_atomic_fetch_add_i32(&vst3->controller.refcounter, -1) - 1;
if (refcount)
{
cplug_log("VST3Controller_release => %p | refcount %i", self, refcount);
return refcount;
}
if (vst3->controller.componentHandler)
vst3->controller.componentHandler->lpVtbl->release(vst3->controller.componentHandler);
_cplug_tryDeleteVST3(vst3);
return 0;
}
// Steinberg_IPluginBase
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_initialize(void* const self, Steinberg_FUnknown* const context)
{
cplug_log("VST3Controller_initialize => %p %p", self, context);
return Steinberg_kResultOk;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3Controller_terminate(void* self)
{
cplug_log("VST3Controller_terminate => %p", self);
return Steinberg_kResultOk;
}
// Steinberg_Vst_IEditController
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_setComponentState(void* const self, Steinberg_IBStream* const stream)
{
cplug_log("VST3Controller_setComponentState => %p %p", self, stream);
return Steinberg_kNotImplemented;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_setState(void* const self, Steinberg_IBStream* const stream)
{
cplug_log("VST3Controller_setState => %p %p", self, stream);
return Steinberg_kNotImplemented;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_getState(void* const self, Steinberg_IBStream* const stream)
{
cplug_log("VST3Controller_getState => %p %p", self, stream);
return Steinberg_kNotImplemented;
}
static int32_t SMTG_STDMETHODCALLTYPE VST3Controller_getParameterCount(void* self)
{
// cplug_log("VST3Controller_getParameterCount => %p", self);
return CPLUG_NUM_PARAMS;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_getParameterInfo(void* self, int32_t index, struct Steinberg_Vst_ParameterInfo* info)
{
// cplug_log("VST3Controller_getParameterInfo => %p %i", self, index);
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
memset(info, 0, sizeof(*info));
CPLUG_LOG_ASSERT_RETURN(index >= 0 && index < CPLUG_NUM_PARAMS, Steinberg_kInvalidArgument);
info->id = index;
// set up flags
double min, max;
cplug_getParameterRange(vst3->userPlugin, index, &min, &max);
const uint32_t hints = cplug_getParameterFlags(vst3->userPlugin, index);
if (hints & CPLUG_FLAG_PARAMETER_IS_AUTOMATABLE)
info->flags |= Steinberg_Vst_ParameterInfo_ParameterFlags_kCanAutomate;
if (hints & CPLUG_FLAG_PARAMETER_IS_READ_ONLY)
info->flags |= Steinberg_Vst_ParameterInfo_ParameterFlags_kIsReadOnly;
if (hints & CPLUG_FLAG_PARAMETER_IS_HIDDEN)
info->flags |= Steinberg_Vst_ParameterInfo_ParameterFlags_kIsHidden;
if (hints & CPLUG_FLAG_PARAMETER_IS_BYPASS)
info->flags |= Steinberg_Vst_ParameterInfo_ParameterFlags_kIsBypass;
if (hints & CPLUG_FLAG_PARAMETER_IS_BOOL)
info->stepCount = 1;
else if (hints & CPLUG_FLAG_PARAMETER_IS_INTEGER)
info->stepCount = (int)(max - min);
double defaultValue = cplug_getDefaultParameterValue(vst3->userPlugin, index);
info->defaultNormalizedValue = cplug_normaliseParameterValue(vst3->userPlugin, index, defaultValue);
_cplug_utf8To16(info->title, cplug_getParameterName(vst3->userPlugin, index), 128);
// Who cares?
_cplug_utf8To16(info->shortTitle, cplug_getParameterName(vst3->userPlugin, index), 128);
return Steinberg_kResultOk;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_getParamStringByValue(void* self, uint32_t index, double normalised, Steinberg_Vst_String128 output)
{
// NOTE very noisy, called many times
// cplug_log("VST3Controller_getParamStringByValue => %p %u %f %p", self, index, normalised, output);
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
// Bitwig 5 has been spotted failing this assertion
CPLUG_LOG_ASSERT_RETURN(normalised >= 0.0 && normalised <= 1.0, Steinberg_kInvalidArgument);
CPLUG_LOG_ASSERT_RETURN(index < CPLUG_NUM_PARAMS, Steinberg_kInvalidArgument);
char buf[128];
double denormalised = cplug_denormaliseParameterValue(vst3->userPlugin, index, normalised);
cplug_parameterValueToString(vst3->userPlugin, index, buf, 128, denormalised);
_cplug_utf8To16(output, buf, sizeof(buf));
return Steinberg_kResultOk;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_getParamValueByString(void* self, uint32_t index, char16_t* input, double* output)
{
// cplug_log("VST3Controller_getParamValueByString => %p %u %p %p", self, rindex, input, output);
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
CPLUG_LOG_ASSERT_RETURN(index < CPLUG_NUM_PARAMS, Steinberg_kInvalidArgument);
char as_utf8[128];
_cplug_utf16To8(as_utf8, input, 128);
double denormalised = cplug_parameterStringToValue(vst3->userPlugin, index, as_utf8);
*output = cplug_normaliseParameterValue(vst3->userPlugin, index, denormalised);
return Steinberg_kResultOk;
}
static double SMTG_STDMETHODCALLTYPE
VST3Controller_normalizedParamToPlain(void* self, uint32_t index, double normalised)
{
// Gets called a lot in ableton, even when you aren't touching parameters
// cplug_log("VST3Controller_normalizedParamToPlain => %p %u %f", self, rindex, normalised);
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
CPLUG_LOG_ASSERT_RETURN(normalised >= 0.0 && normalised <= 1.0, 0.0);
CPLUG_LOG_ASSERT_RETURN(index < CPLUG_NUM_PARAMS, 0.0);
return cplug_denormaliseParameterValue(vst3->userPlugin, index, normalised);
}
static double SMTG_STDMETHODCALLTYPE VST3Controller_plainParamToNormalised(void* self, uint32_t index, double plain)
{
// Gets called a lot in ableton, even when you aren't touching parameters
// cplug_log("VST3Controller_plainParamToNormalised => %p %u %f", self, index, plain);
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
CPLUG_LOG_ASSERT_RETURN(index < CPLUG_NUM_PARAMS, 0.0);
return cplug_normaliseParameterValue(vst3->userPlugin, index, plain);
}
static double SMTG_STDMETHODCALLTYPE VST3Controller_getParamNormalized(void* self, uint32_t index)
{
// cplug_log("VST3Controller_getParamNormalized => %p %u", self, index);
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
// Ableton will ask you for MIDI control values. So far, returning 0 here hasn't caused any problems...
if (index >= cplug_midiControllerOffset)
return 0.0;
CPLUG_LOG_ASSERT_RETURN(index < CPLUG_NUM_PARAMS, 0.0);
double val = cplug_getParameterValue(vst3->userPlugin, index);
return cplug_normaliseParameterValue(vst3->userPlugin, index, val);
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_setParamNormalized(void* const self, const uint32_t index, const double normalised)
{
// Gets called a lot in ableton, even when you aren't touching parameters
// cplug_log("VST3Controller_setParamNormalized => %p %u %f", self, index, normalised);
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
CPLUG_LOG_ASSERT_RETURN(normalised >= 0.0 && normalised <= 1.0, Steinberg_kInvalidArgument);
if (index >= cplug_midiControllerOffset)
{
uint8_t channel = (index - cplug_midiControllerOffset) / 16;
uint8_t control = (index - cplug_midiControllerOffset) % Steinberg_Vst_ControllerNumbers_kCountCtrlNumber;
if (vst3->midiContollerQueueSize < ARRSIZE(vst3->midiContollerQueue))
{
uint8_t* midi = (uint8_t*)&vst3->midiContollerQueue[vst3->midiContollerQueueSize];
switch (control)
{
case Steinberg_Vst_ControllerNumbers_kAfterTouch:
midi[0] = 0xd0 | channel;
midi[1] = (uint8_t)(normalised * 127.0);
break;
case Steinberg_Vst_ControllerNumbers_kPitchBend:
{
uint16_t pb = (uint16_t)(normalised * 16383);
midi[0] = 0xe0 | channel;
midi[1] = pb & 127;
midi[2] = (pb >> 7) & 127;
break;
}
default:
midi[0] = 0xb0;
midi[1] = control;
midi[2] = (uint8_t)(normalised * 127.0);
break;
}
vst3->midiContollerQueueSize++;
}
return Steinberg_kResultOk;
}
CPLUG_LOG_ASSERT_RETURN(index < CPLUG_NUM_PARAMS, 0.0);
double denormalisedVal = cplug_denormaliseParameterValue(vst3->userPlugin, index, normalised);
cplug_setParameterValue(vst3->userPlugin, index, denormalisedVal);
return Steinberg_kResultOk;
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3Controller_setComponentHandler(void* self, Steinberg_Vst_IComponentHandler* handler)
{
cplug_log("VST3Controller_setComponentHandler => %p %p", self, handler);
/* NOTE: Ableton 10 & FL Studio has been spotted trying to pass NULL here.
Good thing we don't use it... */
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
if (vst3->controller.componentHandler)
vst3->controller.componentHandler->lpVtbl->release(vst3->controller.componentHandler);
if (handler != NULL)
handler->lpVtbl->addRef(handler);
vst3->controller.componentHandler = handler;
return Steinberg_kResultOk;
}
static Steinberg_IPlugView* SMTG_STDMETHODCALLTYPE VST3Controller_createView(void* self, const char* name)
{
cplug_log("VST3Controller_createView => %p %s", self, name);
// NOTE: VST3 does not appear to have any kind of hide feature.
// This means windows need to constantly be created & destroyed.
// Create must be followed by show, destroy must be preceded by hide
#if CPLUG_WANT_GUI
VST3Plugin* const vst3 = _cplug_pointerShiftController((VST3Controller*)self);
// plugin must be initialized
CPLUG_LOG_ASSERT_RETURN(vst3->userPlugin != NULL, NULL);
VST3View* const view = (VST3View*)malloc(sizeof(VST3View));
view->lpVtbl = &view->base;
// Steinberg_FUnknown
view->base.queryInterface = VST3View_queryInterface;
view->base.addRef = VST3View_addRef;
view->base.release = VST3View_release;
// Steinberg_IPlugView
view->base.isPlatformTypeSupported = VST3View_isPlatformTypeSupported;
view->base.attached = VST3View_attached;
view->base.removed = VST3View_removed;
view->base.onWheel = VST3View_onWheel;
view->base.onKeyDown = VST3View_onKeyDown;
view->base.onKeyUp = VST3View_onKeyUp;
view->base.getSize = VST3View_getSize;
view->base.onSize = VST3View_onSize;
view->base.onFocus = VST3View_onFocus;
view->base.setFrame = VST3View_setFrame;
view->base.canResize = VST3View_canResize;
view->base.checkSizeConstraint = VST3View_checkSizeConstraint;
view->refcounter = 1;
#ifdef _WIN32
view->scale.lpVtbl = &view->scale.base;
// Steinberg_FUnknown
view->scale.base.queryInterface = VST3ViewContentScale_queryInterface;
view->scale.base.addRef = VST3ViewContentScale_addRef;
view->scale.base.release = VST3ViewContentScale_release;