-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcplug_vst3.c
More file actions
2655 lines (2325 loc) · 112 KB
/
Copy pathcplug_vst3.c
File metadata and controls
2655 lines (2325 loc) · 112 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>
#define tuid_match(a, b) memcmp(a, b, sizeof(Steinberg_TUID)) == 0
#define CPLUG_ARRLEN(a) (sizeof(a) / sizeof(a[0]))
// Parameter automtion in some hosts can be too highly frequent. eg. Ableton sends a new automation points every 8
// samples. In order to effeciently process parameter & audio events in order, parameter events are coalesced and
// quantized using the value below.
#ifndef CPLUG_EVENT_FRAME_QUANTISE
#define CPLUG_EVENT_FRAME_QUANTISE 64
#endif
// VST3 Param IDs are 32bit unsigned integers, but some DAWs such as FL Studio are suspect of misinterpreting them as
// signed integers and reject any negative integer.
enum
{
CPLUG_MIDI_PARAMID_COUNT = (16 * Steinberg_Vst_ControllerNumbers_kCountCtrlNumber),
CPLUG_MIDI_PARAMID_END = 0x7fffffff,
CPLUG_MIDI_PARAMID_START = CPLUG_MIDI_PARAMID_END - CPLUG_MIDI_PARAMID_COUNT,
};
static inline bool cplug_is_midi_param(Steinberg_Vst_ParamID id)
{
return id >= CPLUG_MIDI_PARAMID_START && id < CPLUG_MIDI_PARAMID_END;
}
#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)
{
// https://github.com/justinfrankel/reaper-sdk
static const Steinberg_TUID IReaperUIEmbedInterface_iid =
SMTG_INLINE_UID(0x049BF9E7, 0xBC74EAD0, 0xC4101E86, 0x7F725981);
// https://github.com/fenderdigital/presonus-plugin-extensions
static const Steinberg_TUID IContextInfoProvider = SMTG_INLINE_UID(0x483e61ea, 0x17994494, 0x8199a35a, 0xebb35e3c);
static const Steinberg_TUID IContextInfoProvider2 = SMTG_INLINE_UID(0x61e45968, 0x3d364f39, 0xb15e1733, 0x4944172b);
static const Steinberg_TUID IContextInfoProvider3 = SMTG_INLINE_UID(0x4e31fdf8, 0x6f4448d4, 0xb4ec1461, 0x68a4150f);
static const Steinberg_TUID IContextInfoHandler_iid =
SMTG_INLINE_UID(0xc3b17bc0, 0x2c174494, 0x80293402, 0xfbc4bbf8);
static const Steinberg_TUID IContextInfoHandler2_iid =
SMTG_INLINE_UID(0x31e29a7a, 0xe55043ad, 0x8b95b9b8, 0xda1fbe1e);
static const Steinberg_TUID IEditControllerExtra = SMTG_INLINE_UID(0x50553fd9, 0x1d2c4c24, 0xb410f484, 0xc5fb9f3f);
static const Steinberg_TUID ISlaveControllerHandler =
SMTG_INLINE_UID(0xd93894bd, 0x67454c29, 0x977ae2f5, 0xdb380434);
static const Steinberg_TUID IGainReductionInfo = SMTG_INLINE_UID(0x8e3c292c, 0x95924f9d, 0xb2590b1e, 0x100e4198);
static const Steinberg_TUID IHostCommandHandler = SMTG_INLINE_UID(0xF92032CD, 0x7A84407C, 0xABE6F863, 0x058EA6C2);
static const Steinberg_TUID ICommandList = SMTG_INLINE_UID(0xC5A687DB, 0x82F344E9, 0xB378254A, 0x47C4D712);
static const Steinberg_TUID IInstrumentController = SMTG_INLINE_UID(0xd2ce9317, 0xf24942c9, 0x9742e82d, 0xb10ccc52);
static const Steinberg_TUID ISoundVariationInfo = SMTG_INLINE_UID(0xe59066c0, 0x41d940bc, 0x8f88cbb9, 0xa337e20a);
static const Steinberg_TUID ISoundVariationController =
SMTG_INLINE_UID(0x3abdfc3e, 0x4b964a66, 0xafcd86f10, 0x0d554023);
static const Steinberg_TUID ISpeakerSupportInfo = SMTG_INLINE_UID(0x7342e0eb, 0x8f5641de, 0xa5f7c503, 0x8e2ec3ef);
static const Steinberg_TUID ISpeakerSupportHostInfo =
SMTG_INLINE_UID(0x3327e14a, 0x055e4d27, 0x9a0f6b4a, 0x36316e7b);
static const Steinberg_TUID IPlugInViewEmbedding = SMTG_INLINE_UID(0xda57e6d1, 0x1f3242d1, 0xad9c1a82, 0xfdb95695);
static const Steinberg_TUID IBitmapAccessor = SMTG_INLINE_UID(0x1c4b3ab0, 0x76384cb2, 0x8adafd1b, 0xdd198055);
static const Steinberg_TUID IPlugViewCoordinateUnitSupport =
SMTG_INLINE_UID(0xeae3ebb, 0xb301468a, 0xa127bd34, 0x8fab0824);
static const Steinberg_TUID IPlugViewRendering = SMTG_INLINE_UID(0x215519ce, 0xb4de449f, 0x9572b7f2, 0x4a004a8f);
static const Steinberg_TUID IPlugRenderingFrame = SMTG_INLINE_UID(0x68956019, 0x4b964921, 0x9c249f6a, 0xbcff47c6);
static const Steinberg_TUID IPlugViewMouseInput = SMTG_INLINE_UID(0xc13c4ea4, 0x868e4af7, 0x9614d52c, 0x7cd07b47);
static const Steinberg_TUID IPlugInViewScaling = SMTG_INLINE_UID(0x65ed9690, 0x8ac44525, 0x8aadef7a, 0x72ea703f);
static const Steinberg_TUID IPlugInViewSystemScalingSupport =
SMTG_INLINE_UID(0xde9817bf, 0xe9684b03, 0x91b80816, 0xc2a1ca5);
static const Steinberg_TUID IWaylandHost = SMTG_INLINE_UID(0x5E9582EE, 0x86594652, 0xB213678E, 0x7F1A705E);
static const Steinberg_TUID IWaylandFrame = SMTG_INLINE_UID(0x809FAEC6, 0x231C4FFA, 0x98ED046C, 0x6E9E2003);
static const struct
{
const Steinberg_TUID* iid;
const char* name;
} _known_iids[] = {
// Supported
{&cplug_tuid_component, "{cplug_tuid_component}"},
{&cplug_tuid_controller, "{cplug_tuid_controller}"},
{&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}"},
{&Steinberg_Vst_IMidiMapping_iid, "{Steinberg_Vst_IMidiMapping_iid}"},
{&Steinberg_IPlugFrame_iid, "{Steinberg_IPlugFrame_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}"},
// misc
{&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}"},
{&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_IParamValueQueue_iid, "{Steinberg_Vst_IParamValueQueue_iid}"},
{&Steinberg_Vst_IParameterChanges_iid, "{Steinberg_Vst_IParameterChanges_iid}"},
{&Steinberg_Vst_IParameterFinder_iid, "{Steinberg_Vst_IParameterFinder_iid}"},
// 3rd party
{&IReaperUIEmbedInterface_iid, "{IReaperUIEmbedInterface_iid}"},
{&IContextInfoProvider, "{IContextInfoProvider}"},
{&IContextInfoProvider2, "{IContextInfoProvider2}"},
{&IContextInfoProvider3, "{IContextInfoProvider3}"},
{&IContextInfoHandler_iid, "{IContextInfoHandler_iid}"},
{&IContextInfoHandler2_iid, "{IContextInfoHandler2_iid}"},
{&IEditControllerExtra, "{IEditControllerExtra}"},
{&ISlaveControllerHandler, "{ISlaveControllerHandler}"},
{&IGainReductionInfo, "{IGainReductionInfo}"},
{&IHostCommandHandler, "{IHostCommandHandler}"},
{&ICommandList, "{ICommandList}"},
{&IInstrumentController, "{IInstrumentController}"},
{&ISoundVariationInfo, "{ISoundVariationInfo}"},
{&ISoundVariationController, "{ISoundVariationController}"},
{&ISpeakerSupportInfo, "{ISpeakerSupportInfo}"},
{&ISpeakerSupportHostInfo, "{ISpeakerSupportHostInfo}"},
{&IPlugInViewEmbedding, "{IPlugInViewEmbedding}"},
{&IBitmapAccessor, "{IBitmapAccessor}"},
{&IPlugViewCoordinateUnitSupport, "{IPlugViewCoordinateUnitSupport}"},
{&IPlugViewRendering, "{IPlugViewRendering}"},
{&IPlugRenderingFrame, "{IPlugRenderingFrame}"},
{&IPlugViewMouseInput, "{IPlugViewMouseInput}"},
{&IPlugInViewScaling, "{IPlugInViewScaling}"},
{&IPlugInViewSystemScalingSupport, "{IPlugInViewSystemScalingSupport}"},
{&IWaylandHost, "{IWaylandHost}"},
{&IWaylandFrame, "{IWaylandFrame}"}};
// More:
// https://github.com/justinfrankel/reaper-sdk
// https://github.com/fenderdigital/presonus-plugin-extensions
for (size_t i = 0; i < CPLUG_ARRLEN(_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];
#ifndef _WIN32
Steinberg_TUID unswizzled = SMTG_INLINE_UID(idu32[0], idu32[1], idu32[2], idu32[3]);
idu32 = (unsigned*)&unswizzled[0];
#endif
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;
}
// 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;
}
}
#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 */
struct VST3ProcessContextRequirements
{
Steinberg_Vst_IProcessContextRequirementsVtbl* lpVtbl;
Steinberg_Vst_IProcessContextRequirementsVtbl base;
} g_vst3ProcessContext;
typedef struct VST3Factory
{
Steinberg_IPluginFactory3Vtbl* lpVtbl;
Steinberg_IPluginFactory3Vtbl base;
cplug_atomic_i32 refcounter;
} VST3Factory;
typedef struct VST3Plugin
{
CplugHostContext hostContext;
void* userPlugin; // Pointer to your plugin lives here
#if CPLUG_WANT_GUI
struct VST3View* view;
#endif
struct
{
Steinberg_Vst_IComponentVtbl* lpVtbl;
Steinberg_Vst_IComponentVtbl base;
cplug_atomic_i32 refcounter;
} component;
struct
{
Steinberg_Vst_IEditControllerVtbl* lpVtbl;
Steinberg_Vst_IEditControllerVtbl base;
cplug_atomic_i32 refcounter;
Steinberg_Vst_IComponentHandler* componentHandler;
} controller;
// NOTE: You're not allowed to simply receive MIDI data
// https://steinbergmedia.github.io/vst3_doc/vstinterfaces/classSteinberg_1_1Vst_1_1IMidiMapping.html
struct
{
Steinberg_Vst_IMidiMappingVtbl* lpVtbl;
Steinberg_Vst_IMidiMappingVtbl base;
cplug_atomic_i32 refcounter;
} midiMapping;
// At the time of writing, the only DAWs that properly support INoteExpressionController are Cubase & Bitwig.
// Cubase are a little more othodox to their own plugin format. The noteId they send in their
// NoteExpressionValueEvent is a full 4-byte signed integer, and the plugin is meant to use this noteId to lookup
// the voice triggered by kNoteOnEvent, which was sent tagged with a kNoteOnEvent. Theoretically this can support
// simultaneous note down events of the same key, but ironically Cubases own MIDI interface does not support writing
// MIDI in this way, making the 4 byte ID redundant for plugins ie. all MIDI notes in Cubase are mapped to the key.
// Bitwig simply sets the noteId to the MIDI note number, meaning you only need 1 byte.
// As a quality of life feature for CPLUG, we convert noteIds to midi note numbers using 'id_to_pitch_map' below.
// If NoteExpressionValueEvent had been designed a pitch/midi note number field, we wouldn't have to do this...
struct
{
Steinberg_Vst_INoteExpressionControllerVtbl* lpVtbl;
Steinberg_Vst_INoteExpressionControllerVtbl base;
cplug_atomic_i32 refcounter;
} noteExpression;
struct
{
Steinberg_Vst_IAudioProcessorVtbl* lpVtbl;
Steinberg_Vst_IAudioProcessorVtbl base;
cplug_atomic_i32 refcounter;
} processor;
Steinberg_Vst_IHostApplication* host;
// Structure of arrays format. The index of the ID (key) matches the midi note (value)
struct
{
size_t size;
Steinberg_int32 ids[128];
uint8_t pitch[128];
} noteidmap;
// 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];
// Param updates sent through IAudioProcessor::process() are sent in a very inconvenient way
// They are ordered by paramID first, and sample position second
// Also Steinberg pseudo MIDI (IEventList) events come through a saperate queue
// Also some versions of Ableton send MIDI parameters hough ::setParamNormalized(),
// It's a giant mess to order correctly and maintain these 3 queues, so we stuff everything in this big buffer
// and sort them in the ::process() callback.
size_t num_events;
CplugEvent events[CPLUG_EVENT_QUEUE_SIZE];
} VST3Plugin;
void _cplug_vst3_push_event(VST3Plugin* vst3, CplugEvent event, uint32_t frameIdx)
{
if (vst3->num_events < CPLUG_ARRLEN(vst3->events))
{
event.type |= frameIdx << 4; // pack frame index in type. We will unpack later
vst3->events[vst3->num_events] = event;
vst3->num_events++;
}
}
// Naughty pointer shifting for VST3 classes
static inline VST3Plugin* _cplug_pointerShiftComponent(void* const ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, component));
}
static inline VST3Plugin* _cplug_pointerShiftController(void* const ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, controller));
}
static inline VST3Plugin* _cplug_pointerShiftMidiMapping(void* const ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, midiMapping));
}
static inline VST3Plugin* _cplug_pointerShiftNoteExpression(void* const ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, noteExpression));
}
static inline VST3Plugin* _cplug_pointerShiftProcessor(void* const ptr)
{
return (VST3Plugin*)((char*)(ptr)-offsetof(VST3Plugin, processor));
}
// General notes on syncing parameters with a host:
// If your plugin has hundreds of parameters, Ableton 10 likely won't show them in their interface.
// Instead they suggest you use their 'Configure' mode and start changing parameters within your plugins interface. The
// parameters you changed should be detected and new controls will be added to their interface. The catch here (which I
// haven't seen documented anywhere else) is that you must update your parameters using IComponentHandler which is UI
// thread only. Ableton doesn't share this problem with in their Audio Unit v2 implementation...?
// Sending parameter updates through the audio thread doesn't sync with FL Studio.
// In Reaper & Bitwig, only sending param updates over the audio thread won't produce syncing problems.
// This method is the most reliable way to send param changes and sync them with the DAW
static void _cplug_vst3_sendParamEvent(CplugHostContext* ctx, const CplugEvent* event)
{
CPLUG_LOG_ASSERT(
event->type == CPLUG_EVENT_PARAM_CHANGE_BEGIN || event->type == CPLUG_EVENT_PARAM_CHANGE_UPDATE ||
event->type == CPLUG_EVENT_PARAM_CHANGE_END);
static_assert(offsetof(VST3Plugin, hostContext) == 0, "Required offset for c-cast below");
VST3Plugin* vst3 = (VST3Plugin*)ctx;
Steinberg_Vst_IComponentHandler* handler = vst3->controller.componentHandler;
CPLUG_LOG_ASSERT(handler != NULL);
if (handler)
{
if (event->type == CPLUG_EVENT_PARAM_CHANGE_BEGIN)
handler->lpVtbl->beginEdit(handler, event->parameter.id);
else if (event->type == CPLUG_EVENT_PARAM_CHANGE_UPDATE)
{
double norm = cplug_normaliseParameterValue(vst3->userPlugin, event->parameter.id, event->parameter.value);
handler->lpVtbl->performEdit(handler, event->parameter.id, norm);
}
else if (event->type == CPLUG_EVENT_PARAM_CHANGE_END)
handler->lpVtbl->endEdit(handler, event->parameter.id);
}
}
static void _cplug_vst3_rescan(CplugHostContext* ctx, uint32_t flags)
{
cplug_log("_cplug_vst3_rescan => %p %u", ctx, flags);
VST3Plugin* vst3 = (VST3Plugin*)ctx;
Steinberg_int32 vst_flags = 0;
if (flags & CPLUG_FLAG_RESCAN_LATENCY)
vst_flags |= Steinberg_Vst_RestartFlags_kLatencyChanged;
if (flags & CPLUG_FLAG_RESCAN_BUS_COUNT)
vst_flags |= Steinberg_Vst_RestartFlags_kIoChanged;
if (flags & CPLUG_FLAG_RESCAN_BUS_NAMES)
vst_flags |= Steinberg_Vst_RestartFlags_kIoTitlesChanged;
// A dynamic parameter count isn't really supported in VST3 at the time of writing. In theory you could call
// kReloadComponent, however if you call this from the GUI, for example in the callback of a button click, hosts
// such as Reaper will delete your GUI in that button callback.
// Instead, it's recommended you allocate a maximum number of parameters at startup.
// https://forums.steinberg.net/t/can-i-dynamically-create-parameters/201672
// if (flags & CPLUG_FLAG_RESCAN_PARAM_COUNT)
// vst_flags |= Steinberg_Vst_RestartFlags_kReloadComponent;
if (flags & CPLUG_FLAG_RESCAN_PARAM_VALUES)
vst_flags |= Steinberg_Vst_RestartFlags_kParamValuesChanged;
if (flags & (CPLUG_FLAG_RESCAN_PARAM_NAMES | CPLUG_FLAG_RESCAN_PARAM_METADATA))
vst_flags |= Steinberg_Vst_RestartFlags_kParamTitlesChanged;
Steinberg_Vst_IComponentHandler* handler = vst3->controller.componentHandler;
CPLUG_LOG_ASSERT(handler != NULL);
if (handler)
{
handler->lpVtbl->restartComponent(handler, vst_flags);
}
}
static bool _cplug_vst3_getHostName(CplugHostContext* ctx, char* buf, size_t buflen)
{
VST3Plugin* vst3 = (VST3Plugin*)ctx;
bool ok = false;
if (vst3->host)
{
Steinberg_Vst_String128 name;
Steinberg_tresult result = vst3->host->lpVtbl->getName(vst3->host, name);
if (result == Steinberg_kResultOk)
{
_cplug_utf16To8(buf, name, buflen);
ok = true;
}
}
return ok;
}
static_assert(sizeof(CplugHostContext) == 40, "You may need to add support for new methods");
static void _cplug_tryDeleteVST3Plugin(VST3Plugin* vst3)
{
int ref_component = cplug_atomic_load_i32(&vst3->component.refcounter);
int ref_controller = cplug_atomic_load_i32(&vst3->controller.refcounter);
int ref_midimap = cplug_atomic_load_i32(&vst3->midiMapping.refcounter);
int ref_noteexp = cplug_atomic_load_i32(&vst3->noteExpression.refcounter);
int ref_processor = cplug_atomic_load_i32(&vst3->processor.refcounter);
cplug_log(
"_cplug_tryDeleteVST3Plugin %p | component: %d, controller: %d, midimapping: %d, noteExpression: %d, "
"processor: %d",
vst3,
ref_component,
ref_controller,
ref_midimap,
ref_noteexp,
ref_processor);
int total = ref_component + ref_controller + ref_midimap + ref_noteexp + ref_processor;
if (total == 0)
{
cplug_log("_cplug_tryDeleteVST3Plugin %p | all refcounts are zero, deleting everything!", vst3);
free(vst3);
}
}
#if CPLUG_WANT_GUI
typedef struct VST3View
{
Steinberg_IPlugViewVtbl* lpVtbl;
Steinberg_IPlugViewVtbl base;
cplug_atomic_i32 refcounter;
// Windows only. MacOS is able to detect scale changes using 'viewDidChangeBackingProperties' in NSView
struct
{
Steinberg_IPlugViewContentScaleSupportVtbl* lpVtbl;
Steinberg_IPlugViewContentScaleSupportVtbl base;
cplug_atomic_i32 refcounter;
} contentScaleSupport;
void* userGUI;
VST3Plugin* vst3;
Steinberg_IPlugFrame* frame;
} VST3View;
static void _cplug_tryDeleteVST3View(VST3View* view)
{
int ref_view = cplug_atomic_load_i32(&view->refcounter);
int ref_contentscake = cplug_atomic_load_i32(&view->contentScaleSupport.refcounter);
int total = ref_view + ref_contentscake;
if (total == 0)
{
cplug_log("_cplug_tryDeleteVST3View %p | all refcounts are zero, deleting everything!", view);
CPLUG_LOG_ASSERT(view->vst3 != NULL);
VST3Plugin* vst3 = view->vst3;
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);
view->userGUI = NULL;
vst3->view = NULL;
free(view);
// Help make sure "vst3" is deleted last. DAWs such as Cubase may delete the your GUI last, which is not
// desirable for many plugins
vst3->controller.lpVtbl->release(&vst3->controller);
}
}
/*----------------------------------------------------------------------------------------------------------------------
Source: "pluginterfaces/gui/iplugviewcontentscalesupport.h", line 57 */
// Steinberg_FUnknown
static inline VST3View* _cplug_pointerShiftContentScaleSupport(void* const ptr)
{
return (VST3View*)((char*)(ptr)-offsetof(VST3View, contentScaleSupport));
}
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3ViewContentScale_queryInterface(void* const self, const Steinberg_TUID iid, void** const iface)
{
VST3View* const view = _cplug_pointerShiftContentScaleSupport(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(&view->contentScaleSupport.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)
{
VST3View* const view = _cplug_pointerShiftContentScaleSupport(self);
return cplug_atomic_fetch_add_i32(&view->contentScaleSupport.refcounter, 1) + 1;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3ViewContentScale_release(void* const self)
{
VST3View* const view = _cplug_pointerShiftContentScaleSupport(self);
int refcount = cplug_atomic_fetch_add_i32(&view->contentScaleSupport.refcounter, -1) - 1;
cplug_log("VST3ViewContentScale_release => %p | refcount %d", self, refcount);
if (refcount == 0)
_cplug_tryDeleteVST3View(view);
return refcount;
}
// Steinberg_IPlugViewContentScaleSupport
static Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3ViewContentScale_setContentScaleFactor(void* const self, const float factor)
{
cplug_log("VST3ViewContentScale_setContentScaleFactor => %p %f", self, factor);
VST3View* const view = _cplug_pointerShiftContentScaleSupport(self);
cplug_setScaleFactor(view->userGUI, factor);
return Steinberg_kResultOk;
}
/*----------------------------------------------------------------------------------------------------------------------
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;
}
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->contentScaleSupport.refcounter, 1);
*iface = &view->contentScaleSupport;
return Steinberg_kResultOk;
}
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 refcount = cplug_atomic_fetch_add_i32(&view->refcounter, -1) - 1;
cplug_log("VST3View_release => %p | refcount %d", self, refcount);
if (refcount == 0)
view->contentScaleSupport.lpVtbl->release(&view->contentScaleSupport);
return refcount;
}
// ----------------------------------------------------------------------------------------------------------------
// 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 %p", rect);
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);
VST3View* const view = (VST3View*)self;
view->frame = 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
bool _cplug_vst3_requestResize(CplugHostContext* ctx, uint32_t width, uint32_t height)
{
#if CPLUG_WANT_GUI
VST3Plugin* vst3 = (VST3Plugin*)ctx;
if (vst3->view && vst3->view->frame)
{
struct Steinberg_ViewRect rect;
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
Steinberg_tresult res =
vst3->view->frame->lpVtbl->resizeView(vst3->view->frame, (Steinberg_IPlugView*)vst3->view, &rect);
return res == Steinberg_kResultOk;
}
#endif // CPLUG_WANT_GUI
return false;
}
/*----------------------------------------------------------------------------------------------------------------------
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;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3MidiMapping_addRef(void* const thisInterface)
{
VST3Plugin* const vst3 = _cplug_pointerShiftMidiMapping(thisInterface);
const int refcount = cplug_atomic_fetch_add_i32(&vst3->midiMapping.refcounter, 1) + 1;
cplug_log("VST3MidiMapping_addRef => %p | refcount %i", thisInterface, refcount);
return refcount;
}
static uint32_t SMTG_STDMETHODCALLTYPE VST3MidiMapping_release(void* const thisInterface)
{
VST3Plugin* vst3 = _cplug_pointerShiftMidiMapping(thisInterface);
const int refcount = cplug_atomic_fetch_add_i32(&vst3->midiMapping.refcounter, -1) - 1;
cplug_log("VST3MidiMapping_release => %p | refcount %d", thisInterface, refcount);
if (refcount == 0)
_cplug_tryDeleteVST3Plugin(vst3);
return refcount;
}
// Steinberg_Vst_IMidiMapping
Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3MidiMapping_getMidiControllerAssignment(
void* self,
Steinberg_int32 busIdx,
Steinberg_int16 channel,
Steinberg_Vst_CtrlNumber ctrlNum,
Steinberg_Vst_ParamID* id)
{
// This gets hammered at startup
// cplug_log("VST3MidiMapping_getMidiControllerAssignment => %p %d %hd %u %p", self, busIdx, channel, ctrlNum, id);
CPLUG_LOG_ASSERT_RETURN(busIdx == 0, Steinberg_kResultFalse);
CPLUG_LOG_ASSERT_RETURN(
ctrlNum >= 0 && ctrlNum < Steinberg_Vst_ControllerNumbers_kCountCtrlNumber,
Steinberg_kResultFalse);
*id = CPLUG_MIDI_PARAMID_START + (Steinberg_Vst_ParamID)channel * Steinberg_Vst_ControllerNumbers_kCountCtrlNumber +
(Steinberg_Vst_ParamID)ctrlNum;
return Steinberg_kResultTrue;
}
/*----------------------------------------------------------------------------------------------------------------------
Source: "pluginterfaces/vst/ivstnoteexpression.h", line 165 */
// Implementation largely copy pasted from here:
// https://steinbergmedia.github.io/vst3_dev_portal/pages/Technical+Documentation/Change+History/3.5.0/INoteExpressionController.html
// Steinberg_FUnknown
Steinberg_tresult SMTG_STDMETHODCALLTYPE
VST3NoteExpression_queryInterface(void* thisInterface, const Steinberg_TUID iid, void** obj)
{
if (tuid_match(iid, Steinberg_Vst_INoteExpressionController_iid))
{
cplug_log("VST3NoteExpression_queryInterface => %p %s %p | OK", thisInterface, _cplug_tuid2str(iid), obj);
*obj = thisInterface;
return Steinberg_kResultOk;
}
cplug_log(
"VST3NoteExpression_queryInterface => %p %s %p | WARNING UNSUPPORTED",
thisInterface,
_cplug_tuid2str(iid),
obj);
*obj = NULL;
return Steinberg_kNoInterface;
}
Steinberg_uint32 SMTG_STDMETHODCALLTYPE VST3NoteExpression_addRef(void* thisInterface)
{
VST3Plugin* const vst3 = _cplug_pointerShiftNoteExpression(thisInterface);
const int refcount = cplug_atomic_fetch_add_i32(&vst3->noteExpression.refcounter, 1) + 1;
cplug_log("VST3NoteExpression_addRef => %p | refcount %i", thisInterface, refcount);
return refcount;
}
Steinberg_uint32 SMTG_STDMETHODCALLTYPE VST3NoteExpression_release(void* thisInterface)
{
VST3Plugin* vst3 = _cplug_pointerShiftNoteExpression(thisInterface);
const int refcount = cplug_atomic_fetch_add_i32(&vst3->noteExpression.refcounter, -1) - 1;
cplug_log("VST3NoteExpression_release => %p | refcount %d", thisInterface, refcount);
if (refcount == 0)
_cplug_tryDeleteVST3Plugin(vst3);
return refcount;
}
// Steinberg_Vst_INoteExpressionController
Steinberg_int32 SMTG_STDMETHODCALLTYPE
VST3NoteExpression_getNoteExpressionCount(void* thisInterface, Steinberg_int32 busIndex, Steinberg_int16 channel)
{
cplug_log("VST3NoteExpression_getNoteExpressionCount => %p %d %hd", thisInterface, busIndex, channel);
// we accept only the first bus and 1 channel
if (busIndex == 0 && channel == 0)
return 1;
return 0;
}
Steinberg_tresult SMTG_STDMETHODCALLTYPE VST3NoteExpression_getNoteExpressionInfo(
void* thisInterface,
Steinberg_int32 busIndex,
Steinberg_int16 channel,
Steinberg_int32 noteExpressionIndex,
struct Steinberg_Vst_NoteExpressionTypeInfo* info)
{
cplug_log(
"VST3NoteExpression_getNoteExpressionInfo => %p %d %hd %d %p",
thisInterface,
busIndex,
channel,
noteExpressionIndex,
info);
// we accept only the first bus and 1 channel and only 1 Note Expression (tuning)
if (busIndex == 0 && channel == 0 && noteExpressionIndex == 0)
{
memset(info, 0, sizeof(*info));
// set the tuning type
info->typeId = Steinberg_Vst_NoteExpressionTypeIDs_kTuningTypeID;
// set some strings
swprintf((wchar_t*)info->title, 128, L"%ls", L"Tuning");