-
Notifications
You must be signed in to change notification settings - Fork 0
/
kode_vst3_instance.h
2202 lines (1878 loc) · 73 KB
/
kode_vst3_instance.h
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
#ifndef vst3_instance_included
#define vst3_instance_included
//----------------------------------------------------------------------
// needs kode_vst3.h, which is gpl3
// so this file also needs to be gpl3
//----------------------------------------------------------------------
#ifndef KODE_NO_GUI
#include "plugin/kode_editor.h"
#endif
#include "plugin/base/kode_base_instance.h"
#include "plugin/vst3/kode_vst3.h"
#include "plugin/vst3/kode_vst3_utils.h"
//----------------------------------------------------------------------
#define KODE_VST3_MAX_INPUTS 8
#define KODE_VST3_MAX_OUTPUTS 8
#define KODE_VST3_PARAM_AFTERTOUCH 0x10000 // kode_vst3_AfterTouch (128)
#define KODE_VST3_PARAM_PITCHBEND 0x20000 // kode_vst3_PitchBend (129)
#define KODE_VST3_PARAM_BRIGHTNESS 0x30000 // kode_vst3_CtrlFilterResonance (74)
#define KODE_VST3_QUEUE_SIZE 1024
#define KODE_VST3_TIMER_MS 30
typedef KODE_Queue<uint32_t,KODE_VST3_QUEUE_SIZE> KODE_Vst3UpdateQueue;
//----------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------
class KODE_Vst3Instance
: public KODE_Vst3IComponent
, public KODE_Vst3IAudioProcessor
, public KODE_Vst3IUnitInfo
, public KODE_Vst3IConnectionPoint
, public KODE_Vst3IMidiMapping
, public KODE_Vst3IKeyswitchController
//, public KODE_Vst3INoteExpressionController
, public KODE_Vst3IEditController
, public KODE_Vst3IEditController2
, public KODE_Vst3IPlugView
, public KODE_Vst3ITimerHandler
, public KODE_Vst3IEventHandler
, public KODE_BaseInstance {
//------------------------------
private:
//------------------------------
uint32_t MRefCount = 1;
KODE_Vst3IComponentHandler* MComponentHandler = KODE_NULL;
KODE_Vst3IComponentHandler2* MComponentHandler2 = KODE_NULL;
KODE_Vst3IPlugFrame* MPlugFrame = KODE_NULL;
KODE_Vst3IHostApplication* MHostApp = KODE_NULL;
KODE_Vst3ParameterInfo* MParamInfos = KODE_NULL;
KODE_Vst3IRunLoop* MRunLoop = KODE_NULL;
uint32_t MIoMode = 0;
uint32_t MProcessMode = 0;
uint32_t MSampleSize = 0;
uint32_t MBlockSize = 0;
float MSampleRate = 0.0f;
bool MIsProcessing = false;
char MHostName[129] = {0};
KODE_ProcessContext MProcessContext = {0};
KODE_Descriptor* MDescriptor = KODE_NULL;
KODE_Vst3UpdateQueue MHostParameterQueue;
float* MHostParameterValues = KODE_NULL;
float* MParameterValues = KODE_NULL;
//float* MEditorParameterValues = KODE_NULL;
#ifndef KODE_NO_GUI
KODE_Editor* MEditor = KODE_NULL;
#endif
pid_t MHostPid = 0;
pid_t MHostTid = 0;
//------------------------------
public:
//------------------------------
KODE_Vst3Instance(KODE_Descriptor* ADescriptor)
: KODE_BaseInstance(ADescriptor) {
KODE_VST3PRINT;
MRefCount = 1;
MDescriptor = ADescriptor;
createParameterBuffers();
createParameterInfo();
}
//----------
virtual ~KODE_Vst3Instance() {
KODE_VST3PRINT;
deleteParameterInfo();
destroyParameterBuffers();
}
//------------------------------
public:
//------------------------------
KODE_Descriptor* getDescriptor() override {
KODE_VST3PRINT;
return MDescriptor;
}
pid_t getHostPid() { return MHostPid; }
pid_t getHostTid() { return MHostTid; }
const char* getHostName() override {
return MHostName;
}
//------------------------------
public:
//------------------------------
void setDefaultParameterValues() override {
KODE_VST3PRINT;
uint32_t num = MDescriptor->getNumParameters();
for (uint32_t i=0; i<num; i++) {
KODE_Parameter* parameter = MDescriptor->getParameter(i);
float value = parameter->getDefValue();
MParameterValues[i] = value;
}
}
//----------
void updateAllParameters() override {
KODE_VST3PRINT;
uint32_t num = MDescriptor->getNumParameters();
for (uint32_t i=0; i<num; i++) {
KODE_Parameter* parameter = MDescriptor->getParameter(i);
float value = MParameterValues[i];
float v = parameter->from01(value);
on_plugin_parameter(0,i,v);
// if editor is open ...
}
}
//----------
#ifndef KODE_NO_GUI
void updateAllEditorParameters(KODE_BaseEditor* AEditor, bool ARedraw=true) override {
KODE_Vst3Print("%s\n",ARedraw?"(redraw=true)":"");
uint32_t num = MDescriptor->getNumParameters();
for (uint32_t i=0; i<num; i++) {
float value = MParameterValues[i];
//KODE_Parameter* parameter = MDescriptor->getParameter(i);
//float v = parameter->from01(value);
float v = value;
//on_plugin_parameter(0,i,v);
AEditor->updateParameterFromHost(i,v,ARedraw);
}
}
#endif
//----------
/*
we run our gui in its own thread, but need to communicate with the
host on its gui thread.. so, when we tweak a parameter, we queue the
parameter (index), and send all updated ones to the host during onTimer
(see bottom)
the host should communicate the parameter change (audio thread) during
next process()
*/
#ifndef KODE_NO_GUI
void updateParameterFromEditor(uint32_t AIndex, float AValue) override {
KODE_Vst3Print("index: %i value: %.3f\n",AIndex,AValue);
//MEditorParameterValues[AIndex] = AValue;
MParameterValues[AIndex] = AValue;
queueParameterToHost(AIndex,AValue);
}
#endif
//------------------------------
private:
//------------------------------
void createParameterBuffers() {
KODE_VST3PRINT;
uint32_t size = MDescriptor->getNumParameters() * sizeof(float);
//MNumParameters = MDescriptor->getNumParameters();
MParameterValues = (float*)malloc(size);
//MEditorParameterValues = (float*)malloc(size);
MHostParameterValues = (float*)malloc(size);
memset(MParameterValues, 0,size);
//memset(MEditorParameterValues, 0,size);
memset(MHostParameterValues, 0,size);
}
//----------
void destroyParameterBuffers() {
KODE_VST3PRINT;
if (MParameterValues) free(MParameterValues);
//if (MEditorParameterValues) free(MEditorParameterValues);
if (MHostParameterValues) free(MHostParameterValues);
}
//----------
void queueParameterToHost(uint32_t AIndex, float AValue) {
//KODE_Print("index: %i value: %.3f\n",AIndex,AValue);
MHostParameterValues[AIndex] = AValue;
MHostParameterQueue.write(AIndex);
}
//----------
/*
must call the MComponentHandler from the same thread as we received it
(same thread as setComponentHandler)
IRunLoop
Sets the normalized value to the parameter associated to the paramID.
The controller must never pass this value-change back to the host via the
IComponentHandler. It should update the according GUI element(s) only!
https://github.com/soundradix/JUCE/commit/2e9e66cbc8c65e889be5232ffae83c0ca78f9c7e
performEdit ((Vst::ParamID) index, (double) newValue);
// call setParamNormalized too, as without it value will reset at endEdit in Cubase.
// setParamNormalized does not replace performEdit as it does not record automation.
setParamNormalized ((Vst::ParamID) index, (double) newValue);
https://sdk.steinberg.net/viewtopic.php?t=693
"Remember that everything in the edit controller domain must happen on the
main thread also calls to the IComponentHandler instance of the host. So
don't call beginEdit, endEdit or performEdit on a secondary thread."
NB: Cubase has problems if performEdit is called without setParamNormalized
EditController::setParamNormalized(AIndex,AValue);
MComponentHandler->performEdit(AIndex,AValue); // drag
*/
/*
todo:
beginEdit when mouseClick
performEdit while mouseDrag
endEdit when mouseRelease
*/
void flushParametersToHost() {
KODE_VST3PRINT;
uint32_t index = 0;
while (MHostParameterQueue.read(&index)) {
float value = MHostParameterValues[index];
KODE_Vst3DPrint(" index: %i value: %.3f\n",index,value);
if (MComponentHandler) {
//if (MComponentHandler2) MComponentHandler2->startGroupEdit();
MComponentHandler->beginEdit(index);
MComponentHandler->performEdit(index,value);
MComponentHandler->endEdit(index);
//if (MComponentHandler2) MComponentHandler2->finishGroupEdit();
}
}
}
//----------
/*
reaper asks for this all the time, so we create (and cache) it, and
return a ptr to the same buffer each time..
(re-check, as i think i remember i saw something about this in a
recent reaper update log)
numsteps
0 = continuous
1 = toggle
2.. = max value
so, steps-1, or 0 if cont..
*/
void createParameterInfo() {
KODE_VST3PRINT;
if (!MParamInfos) {
uint32_t num = MDescriptor->getNumParameters();
MParamInfos = (KODE_Vst3ParameterInfo*)malloc( num * sizeof(KODE_Vst3ParameterInfo) );
for (uint32_t i=0; i<num; i++) {
KODE_Parameter* param = MDescriptor->getParameter(i);
MParamInfos[i].id = i;
KODE_CharToUtf16(param->getName(),&MParamInfos[i].title);
KODE_CharToUtf16(param->getShortName(),&MParamInfos[i].shortTitle);
KODE_CharToUtf16(param->getLabel(),&MParamInfos[i].units);
uint32_t numsteps = param->getNumSteps();
if (numsteps > 1) numsteps -= 1;
MParamInfos[i].stepCount = numsteps;
MParamInfos[i].defaultNormalizedValue = param->getDefValue();
MParamInfos[i].unitId = kode_vst3_RootUnitId; //-1;
int32_t flags = 0;
if (param->canAutomate()) flags += KODE_Vst3ParameterInfo::kode_vst3_CanAutomate;
else flags += KODE_Vst3ParameterInfo::kode_vst3_IsReadOnly; // ??
MParamInfos[i].flags = flags;
}
}
}
//----------
void deleteParameterInfo() {
KODE_VST3PRINT;
if (MParamInfos) free(MParamInfos);
}
//----------
/*
no interpolation, or sample-accurate automation yet..
we 'cheat', and only use the last value for each block
(plugins can interpolate this)
a) fill a buffer (blocksize) with parameter values?
b) split process-buffer, and send parameter updates inbetween?
(not interpolated)
#define KODE_VST3_PARAMS_LAST, _STEPPED, _INTERPOLATED
*/
void handleParametersInProcess(KODE_Vst3ProcessData& data) {
//KODE_VST3PRINT;
KODE_Vst3IParameterChanges* paramChanges = data.inputParameterChanges;
if (paramChanges) {
int32_t num_param_changes = paramChanges->getParameterCount();
if (num_param_changes > 0) {
for (int32_t i=0; i<num_param_changes; i++) {
KODE_Vst3IParamValueQueue* paramQueue = paramChanges->getParameterData(i);
if (paramQueue) {
uint32_t id = paramQueue->getParameterId();
if (id < MDescriptor->getNumParameters()) {
//for (int32_t j=0; j<paramQueue->getPointCount(); j++) {
int32_t offset = 0;
double value = 0;
int32_t pointcount = paramQueue->getPointCount();
paramQueue->getPoint(pointcount-1,offset,value); // last point
MParameterValues[id] = value;
//KODE_Print("MParameterValues[%i] = %.3f\n",id,value);
KODE_Parameter* param = MDescriptor->getParameter(id);
if (param) value = param->from01(value);
on_plugin_parameter(0,id,value);
//}
} // id < param
else {
// if PLUGIN_RECEIVE_MIDI
// IMidiMapping
int32_t offset = 0;
double value = 0.5;
int32_t pointcount = paramQueue->getPointCount();
paramQueue->getPoint(pointcount-1,offset,value); // last point
uint32_t midi_ev = (id & 0xffff0000);
uint32_t midi_ch = (id & 0x0000ffff);
switch(midi_ev) {
case KODE_VST3_PARAM_AFTERTOUCH: {
//if (offset != 0)
on_plugin_midi(offset,KODE_MIDI_CHANNEL_AFTERTOUCH+midi_ch,value*127.0f,0);
break;
} // at
case KODE_VST3_PARAM_PITCHBEND: {
float v2 = value * 16383.0f;
uint32_t i2 = (uint32_t)v2;
//if (midi_ch != 0) {
uint32_t m2 = i2 & 0x7f;
uint32_t m3 = i2 >> 7;
//if (offset != 0)
on_plugin_midi(offset,KODE_MIDI_PITCHBEND+midi_ch,m2,m3);
//}
break;
} // pb
case KODE_VST3_PARAM_BRIGHTNESS: {
//if (offset != 0)
on_plugin_midi(offset,KODE_MIDI_CONTROL_CHANGE+midi_ch,74,value*127.0f);
break;
}
} // switch (midi_ev)
} // id < num params
} // paramqueue
} // for all params
} // numparams > 0
} // paramchanges
}
//----------
void handleEventsInProcess(KODE_Vst3ProcessData& data) {
//KODE_VST3PRINT;
//if PLUGIN_RECEIVE_MIDI
KODE_Vst3IEventList* inputEvents = data.inputEvents;
if (inputEvents) {
int32_t num = inputEvents->getEventCount();
for (int32_t i=0; i<num; i++) {
KODE_Vst3Event event;
inputEvents->getEvent(i,event);
uint32_t offset = 0;
uint8_t msg1 = 0;
uint8_t msg2 = 0;
uint8_t msg3 = 0;
//uint32_t type = 0;//kve_none;
//uint32_t noteid = 0;
//float value = 0.0f;
switch (event.type) {
case KODE_Vst3Event::kode_vst3_NoteOnEvent:
offset = event.sampleOffset;
msg1 = KODE_MIDI_NOTE_ON + event.noteOn.channel;
msg2 = event.noteOn.pitch;
msg3 = event.noteOn.velocity * 127;
//noteid = event.noteOn.noteId;
on_plugin_midi(offset,msg1,msg2,msg3);
//on_noteExpression(offset,type,noteid,value);
break;
case KODE_Vst3Event::kode_vst3_NoteOffEvent:
offset = event.sampleOffset;
msg1 = KODE_MIDI_NOTE_OFF + event.noteOff.channel;
msg2 = event.noteOff.pitch;
msg3 = event.noteOff.velocity * 127;
//noteid = event.noteOff.noteId;
on_plugin_midi(offset,msg1,msg2,msg3);
//on_noteExpression(offset,type,noteid,value);
break;
case KODE_Vst3Event::kode_vst3_DataEvent:
break;
case KODE_Vst3Event::kode_vst3_PolyPressureEvent:
offset = event.sampleOffset;
msg1 = KODE_MIDI_POLY_AFTERTOUCH + event.polyPressure.channel;
msg2 = event.polyPressure.pitch;
msg3 = event.polyPressure.pressure * 127;
//noteid = event.polyPressure.noteId;
on_plugin_midi(offset,msg1,msg2,msg3);
break;
case KODE_Vst3Event::kode_vst3_NoteExpressionValueEvent:
//offset = event.sampleOffset;
//noteid = event.noteExpressionValue.noteId;
//value = event.noteExpressionValue.value;
//switch(event.noteExpressionValue.typeId) {
// case kode_vst3_TuningTypeID: type = kve_bend; break;
// case kode_vst3_BrightnessTypeID: type = kve_slide; break;
// //case kode_vst3_VolumeTypeID: type = kve_none; break;
// //case kode_vst3_PanTypeID: type = kve_none; break;
// //case kode_vst3_VibratoTypeID: type = kve_none; break;
// //case kode_vst3_ExpressionTypeID: type = kve_none; break;
//}polyPressure
//on_noteExpression(offset,type,noteid,value);
break;
case KODE_Vst3Event::kode_vst3_NoteExpressionTextEvent:
break;
case KODE_Vst3Event::kode_vst3_ChordEvent:
break;
case KODE_Vst3Event::kode_vst3_ScaleEvent:
break;
default:
break;
} // switch
} // for all events
} // if input events
}
//----------------------------------------------------------------------
// vst3
//----------------------------------------------------------------------
//------------------------------
public: // FUnknown
//------------------------------
/*
Adds a reference and return the new reference count.
Remarks: The initial reference count after creating an object is 1.
*/
uint32_t KODE_VST3_PLUGIN_API addRef() final {
MRefCount++;
KODE_Vst3Print("-> %i\n",MRefCount);
return MRefCount;
}
//----------
/*
Releases a reference and return the new reference count.
If the reference count reaches zero, the object will be destroyed in
memory.
*/
uint32_t KODE_VST3_PLUGIN_API release() final {
const uint32_t r = --MRefCount;
KODE_Vst3Print("-> %i %s",r, (r==0) ? "(delete)\n" : "\n" );
if (r == 0) {
on_plugin_close();
delete this;
};
return r;
}
//----------
/*
Query for a pointer to the specified interface.
Returns kResultOk on success or kNoInterface if the object does not
implement the interface.
The object has to call addRef when returning an interface.
_iid: (in) 16 Byte interface identifier (-> FUID)
obj: (out) On return, *obj points to the requested interface
Although it is not recommended, it is possible to implement both, the
processing part and the controller part in one component class. The host
tries to query the IEditController interface after creating an
IAudioProcessor and on success uses it as controller.
reaper asks for:
C3B17BC0-2C174494-80293402-FBC4BBF8 (IContextInfoHandler, pslextensions)
31E29A7A-E55043AD-8B95B9B8-DA1FBE1E (IContextInfoHandler2, pslextensions)
bitwig asks for:
6C389611-D391455D-B870B833-94A0EFDD (IUnitData)
8683B01F-7B354F70-A2651DEC-353AF4FF (IProgramListData)
7F4EFE59-F3204967-AC27A3AE-AFB63038 (IEditController2)
65ED9690-8AC44525-8AADEF7A-72EA703F (IPlugViewContentScaleSupport)
( 65ed9690-8ac44525-8aadef7a-72ea703f (IPlugInViewScaling, pslextensions) !! )
633b9012-d19a4953-b477b436-9daaeedb
8e8bbb11-73384477-ac6b1eeb-383df4f0
ccc87233-accb4371-bc74a1f2-5ebba43c
7743fe5e-f3224d6d-a729ada9-aab2333b
cd291308-775e4492-b5db37be-62bb1a54
41c5087e-4bbb4e8b-8da21bd2-97dc6679
001a4b89-86924ed8-b7aacdee-cc12d6dd
98e97900-c220484c-82a3edcd-d06cdd45
6bec9099-83c14927-83a8ee72-79e97733
*/
int32_t KODE_VST3_PLUGIN_API queryInterface(const KODE_Vst3Id _iid, void** obj) final {
KODE_Vst3Print("iid: ");
KODE_Vst3PrintIID(_iid);
if (KODE_iidEqual(KODE_Vst3IAudioProcessor_iid,_iid) ) {
KODE_Vst3DPrint(" (IAudioProcessor) -> Ok\n");
*obj = (KODE_Vst3IAudioProcessor*)this;
addRef();
return kode_vst3_ResultOk;
}
if (KODE_iidEqual(KODE_Vst3IEditController_iid,_iid) ) {
KODE_Vst3DPrint(" (IEditController) -> Ok\n");
*obj = (KODE_Vst3IEditController*)this;
addRef();
return kode_vst3_ResultOk;
}
if (KODE_iidEqual(KODE_Vst3IMidiMapping_iid,_iid) ) {
KODE_Vst3DPrint(" (IMidiMapping) -> Ok\n");
*obj = (KODE_Vst3IMidiMapping*)this;
addRef();
return kode_vst3_ResultOk;
}
if (KODE_iidEqual(KODE_Vst3IUnitInfo_iid,_iid) ) {
KODE_Vst3DPrint(" (IUnitInfo) -> Ok\n");
*obj = (KODE_Vst3IUnitInfo*)this;
addRef();
return kode_vst3_ResultOk;
}
//if (KODE_iidEqual(KODE_Vst3INoteExpressionController_iid,_iid) ) {
// KODE_Vst3DPrint(" (INoteExpressionController) -> NoInterface\n");
// //*obj = (KODE_Vst3INoteExpressionController*)this;
// //addRef();
// //return kode_vst3_ResultOk;
// return kode_vst3_NoInterface;
//}
if (KODE_iidEqual(KODE_Vst3IKeyswitchController_iid,_iid) ) {
KODE_Vst3DPrint(" (IKeySwitchProcessor) -> Ok\n");
//*obj = (KODE_Vst3IKeyswitchController*)this;
//addRef();
//return kode_vst3_ResultOk;
return kode_vst3_NoInterface;
}
if (KODE_iidEqual(KODE_Vst3IConnectionPoint_iid,_iid) ) {
KODE_Vst3DPrint(" (IConnectionPoint) -> Ok\n");
*obj = (KODE_Vst3IConnectionPoint*)this;
addRef();
return kode_vst3_ResultOk;
}
if (KODE_iidEqual(KODE_Vst3ITimerHandler_iid,_iid) ) {
KODE_Vst3DPrint(" (ITimerHandler) -> NoInterface\n");
//*obj = (KODE_Vst3ITimerHandler*)this;
//addRef();
//return kode_vst3_ResultOk;
return kode_vst3_NoInterface;
}
KODE_Vst3DPrint(" (unknown) -> NoInterface\n");
*obj = KODE_NULL;
return kode_vst3_NoInterface;
}
//------------------------------
public: // IPluginBase
//------------------------------
/*
file:///WORK/code/_backup/vst3/VST3SDK/index.html
The context parameter passed to IPluginBase::initialize is
Vst::IHostApplication. Hosts should not call others functions before
initialize is called!, except IComponent::setIoMode which need to be
called before or IComponent::getControllerClassId which could be called
before.
note: Extensive memory allocations etc. should be performed in this
method rather than in the class' constructor!
If the method does NOT return kResultOk, the object is released
immediately. In this case terminate is not called!
---
3.6.12
Allow a Plug-in to ask the host if a given Plug-in interface is
supported/used by the host. It is implemented by the hostContext given
when the component is initialized.
tresult PLUGIN_API MyPluginController::initialize (FUnknown* context) {
// ...
FUnknownPtr<IPlugInterfaceSupport> plugInterfaceSupport (context);
if (plugInterfaceSupport) {
if (plugInterfaceSupport->isPlugInterfaceSupported (IMidiMapping::iid) == kResultTrue)
// IMidiMapping is used by the host
}
//...
}
---
IHostApplication: passed as 'context' in to IPluginBase::initialize()
*/
int32_t KODE_VST3_PLUGIN_API initialize(KODE_Vst3FUnknown* context) final {
KODE_Vst3Print("contect: %p",context);
MHostApp = (KODE_Vst3IHostApplication*)context;
//context->queryInterface(IHostApplication_iid, (void**)&MHostApp);
if (MHostApp) {
KODE_Vst3String u;
MHostApp->getName(u);
KODE_Utf16ToChar(&u,MHostName);
KODE_Vst3DPrint(" (hostname: '%s')",MHostName);
}
else {
}
KODE_Vst3DPrint(" -> Ok\n");
on_plugin_initialize();
return kode_vst3_ResultOk;
}
//----------
/*
This function is called before the Plug-in is unloaded and can be used
for cleanups. You have to release all references to any host application
interfaces.
*/
int32_t KODE_VST3_PLUGIN_API terminate() final {
KODE_Vst3Print(" -> Ok\n");
on_plugin_terminate();
return kode_vst3_ResultOk;
}
//------------------------------
public: // IComponent
//------------------------------
/*
Called before initializing the component to get information about the
controller class.
file:///WORK/code/_backup/vst3/VST3SDK/index.html
In order to enable the host to create a corresponding edit controller the
processing component has to provide the matching class-ID. The host uses
the module's class factory to create the controller component.
(IComponent::getControllerClassId)
*/
int32_t KODE_VST3_PLUGIN_API getControllerClassId(KODE_Vst3Id classId) final {
KODE_Vst3Print("classId: ");
KODE_Vst3PrintIID(classId);
if (MDescriptor->hasEditor()) {
memcpy(classId,MDescriptor->getLongEditorId(),16);
KODE_Vst3DPrint("-> ");
KODE_Vst3PrintIID(classId);
KODE_Vst3DPrint(" -> Ok\n");
return kode_vst3_ResultOk;
}
else {
KODE_Vst3DPrint(" -> False\n");
return kode_vst3_ResultFalse;
}
}
//----------
/*
Called before 'initialize' to set the component usage (optional).
See IoModes
*/
int32_t KODE_VST3_PLUGIN_API setIoMode(int32_t mode) final {
KODE_Vst3Print(" mode: %i",mode);
MIoMode = mode;
switch (mode) {
case kode_vst3_Simple: KODE_Vst3DPrint(" /simple"); break;
case kode_vst3_Advanced: KODE_Vst3DPrint(" /advanced"); break;
case kode_vst3_OfflineProcessing: KODE_Vst3DPrint(" /offline"); break;
}
KODE_Vst3DPrint(" -> Ok\n");
return kode_vst3_ResultOk;
}
//----------
/*
Called after the Plug-in is initialized.
See MediaTypes, BusDirections
*/
int32_t KODE_VST3_PLUGIN_API getBusCount(int32_t type, int32_t dir) final {
KODE_Vst3Print("type: %s dir: %s",type?"1/event":"0/audio",dir?"1/output":"0/input");
switch (type) {
case kode_vst3_Audio:
switch (dir) {
case kode_vst3_Input:
if (MDescriptor->getNumInputs() > 0) {
KODE_Vst3DPrint(" -> 1\n");
return 1;
}
else {
KODE_Vst3DPrint(" -> 0\n");
return 0;
}
case kode_vst3_Output:
if (MDescriptor->getNumOutputs() > 0) {
KODE_Vst3DPrint(" -> 1\n");
return 1;
}
else {
KODE_Vst3DPrint(" -> 0\n");
return 0;
}
}
case kode_vst3_Event:
switch (dir) {
case kode_vst3_Input:
if (MDescriptor->canReceiveMidi() || MDescriptor->isSynth()) {
KODE_Vst3DPrint(" -> 1\n");
return 1;
}
else {
KODE_Vst3DPrint(" -> 0\n");
return 0;
}
case kode_vst3_Output:
KODE_Vst3DPrint(" -> 0\n");
return 0;
}
}
KODE_Vst3DPrint("-> 0\n");
return 0;
}
//----------
/*
Called after the Plug-in is initialized.
See MediaTypes, BusDirections
*/
int32_t KODE_VST3_PLUGIN_API getBusInfo(int32_t type, int32_t dir, int32_t index, KODE_Vst3BusInfo& bus) final {
KODE_Vst3Print("type: %s dir: %s index: %i",type?"1/event":"0/audio",dir?"1/output":"0/input",index);
switch (type) {
case kode_vst3_Audio:
switch (dir) {
case kode_vst3_Input:
bus.mediaType = kode_vst3_Audio;
bus.direction = kode_vst3_Input;
bus.channelCount = MDescriptor->getNumInputs();
KODE_CharToUtf16("Audio In",&bus.name);
bus.busType = kode_vst3_Main; // Aux
bus.flags = KODE_Vst3BusInfo::kode_vst3_DefaultActive; // 0
KODE_Vst3DPrint(" -> Ok\n");
KODE_Vst3DPrint(". type: %i (Audio)\n",bus.mediaType);
KODE_Vst3DPrint(". dir: %i (Input)\n",bus.direction);
KODE_Vst3DPrint(". chn.count: %i\n",bus.channelCount);
KODE_Vst3DPrint(". name: '%s'\n","Audio In");
KODE_Vst3DPrint(". busType: %i (Main)\n",bus.busType);
KODE_Vst3DPrint(". flags: %i (DefaultActive)\n",bus.flags);
return kode_vst3_ResultOk;
case kode_vst3_Output:
bus.mediaType = kode_vst3_Audio;
bus.direction = kode_vst3_Output;
bus.channelCount = MDescriptor->getNumOutputs();
KODE_CharToUtf16("Audio Out",&bus.name);
bus.busType = kode_vst3_Main; // Aux
bus.flags = KODE_Vst3BusInfo::kode_vst3_DefaultActive; // 0
KODE_Vst3DPrint(" -> Ok\n");
KODE_Vst3DPrint(". type: %i (Audio)\n",bus.mediaType);
KODE_Vst3DPrint(". dir: %i (Output)\n",bus.direction);
KODE_Vst3DPrint(". chn.count: %i\n",bus.channelCount);
KODE_Vst3DPrint(". name: '%s'\n","Audio Out");
KODE_Vst3DPrint(". busType: %i (Main)\n",bus.busType);
KODE_Vst3DPrint(". flags: %i (DefaultActive)\n",bus.flags);
return kode_vst3_ResultOk;
} // switch (dir)
case kode_vst3_Event:
switch (dir) {
case kode_vst3_Input:
bus.mediaType = kode_vst3_Event;
bus.direction = kode_vst3_Input;
bus.channelCount = 16;
KODE_CharToUtf16("Midi In",&bus.name);
bus.busType = kode_vst3_Main; // Aux
bus.flags = KODE_Vst3BusInfo::kode_vst3_DefaultActive; // 0
KODE_Vst3DPrint(" -> Ok\n");
KODE_Vst3DPrint(". type: %i (Event)\n",bus.mediaType);
KODE_Vst3DPrint(". dir: %i (Input)\n",bus.direction);
KODE_Vst3DPrint(". chn.count: %i\n",bus.channelCount);
KODE_Vst3DPrint(". name: '%s'\n","Midi In");
KODE_Vst3DPrint(". busType: %i (Main)\n",bus.busType);
KODE_Vst3DPrint(". flags: %i (DefaultActive)\n",bus.flags);
return kode_vst3_ResultOk;
case kode_vst3_Output:
//bus.mediaType = kode_vst3_Event;
////bus.flags = 0;//kode_vst3_DefaultActive;
//bus.direction = kode_vst3_Input;
//bus.channelCount = 16;
//KODE_CharToUtf16("Midi In",&bus.name);
KODE_Vst3DPrint(" -> False\n");
return kode_vst3_ResultFalse; // kode_vst3_ResultOk;
//break;
} // switch (dir)
} // switch (type)
KODE_Vst3DPrint(" -> False\n");
return kode_vst3_ResultFalse;
}
//----------
/*
Retrieves routing information (to be implemented when more than one
regular input or output bus exists).
The inInfo always refers to an input bus while the returned outInfo must
refer to an output bus!
*/
int32_t KODE_VST3_PLUGIN_API getRoutingInfo(KODE_Vst3RoutingInfo& inInfo, KODE_Vst3RoutingInfo& outInfo) final {
KODE_Vst3Print("\n");
outInfo.mediaType = inInfo.mediaType; // MediaTypes::kode_vst3_Audio;
outInfo.busIndex = inInfo.busIndex; // 0;
outInfo.channel = -1;
KODE_Vst3DPrint(". inInfo.mediaType: \n",inInfo.mediaType);
KODE_Vst3DPrint(". inInfo.busIndex: \n",inInfo.busIndex);
KODE_Vst3DPrint(". inInfo.channel: \n",inInfo.channel);
KODE_Vst3DPrint(". outInfo.mediaType: \n",outInfo.mediaType);
KODE_Vst3DPrint(". outInfo.busIndex: \n",outInfo.busIndex);
KODE_Vst3DPrint(". outInfo.channel: \n",outInfo.channel);
KODE_Vst3Print("-> Ok\n");
return kode_vst3_ResultOk;
}
//----------
/*
Called upon (de-)activating a bus in the host application. The Plug-in
should only processed an activated bus, the host could provide less
AudioBusBuffers in the process call (see IAudioProcessor::process) if
last buses are not activated
*/
int32_t KODE_VST3_PLUGIN_API activateBus(int32_t type, int32_t dir, int32_t index, uint8_t state) final {
KODE_Vst3Print("type: %s dir: %s index: %i state: %i",type?"1/event":"0/audio",dir?"1/output":"0/input",index,state);
KODE_Vst3DPrint(" -> Ok\n");
return kode_vst3_ResultOk;
}
//----------
/*
Activates / deactivates the component.
*/
int32_t KODE_VST3_PLUGIN_API setActive(uint8_t state) final {
if (state) on_plugin_activate();
else on_plugin_deactivate();
KODE_Vst3Print("state: %i -> Ok\n",state);
return kode_vst3_ResultOk;
}
//----------
/*
How does persistence work?
An instantiated Plug-in often has state information that must be saved in
order to properly re-instantiate that Plug-in at a later time. A VST 3
Plug-in has two states which are saved and reloaded: its component state
and its controller state.
The sequence of actions for saving is:
component->getState (compState)
controller->getState (ctrlState)
The sequence of actions for loading is:
component->setState (compState)
controller->setComponentState (compState)
controller->setState (ctrlState)
In the latter sequence you can see that the controller part will receive
the component state. This allows the 2 parts to synchronize their states.
What's the difference between IEditController::setComponentState and
IEditController::setState?
After a preset is loaded, the host calls IEditController::setComponentState
and IComponent::setState. Both delivering the same information.
IEditController::setState is called by the host so that the Plug-in is able
to update its controller dependent parameters, eg. position of scroll bars.
Prior to this, there should have been a call by the host to
IEditController::getState, where the Plug-in writes these various
parameters into the stream.
Can IComponent::getState()/setState() could be called during processing?
Yes, setState and getState are called normally from the UI Thread when the
Plug-in is used in a realtime context, in an offline context set/getState
could be called in the same thread than the process call. Check the
workflow diagram Audio Processor Call Sequence for more info about in which
state which interfaces are called.
---
Restore: When the states are restored, the host passes the processor state
to both the processor and the controller (IEditController::setComponentState).
A host must always pass that state to the processor first. The controller
then has to synchronize its parameters to this state (but must not perform
any IComponentHandler callbacks).
After restoring a state, the host will rescan the parameters (asking the
controller) in order to update its intern representation.
*/
int32_t KODE_VST3_PLUGIN_API setState(KODE_Vst3IBStream* state) final {
KODE_VST3PRINT;
uint32_t version = 0;
uint32_t mode = 0;
int32_t size = 0;
int32_t num_read = 0;
state->read(&version, sizeof(uint32_t),&num_read);
state->read(&mode, sizeof(uint32_t),&num_read);
state->read(&size, sizeof(int32_t),&num_read);
switch (mode) {
case 0: {
// is it safe to malloc/free here?
// use static, pre malloc'd buffer?
void* ptr = malloc(size);
state->read(&ptr,size,&num_read);
on_plugin_restoreState(size,ptr,0);
free(ptr);
break;
}
case 1: {
uint32_t num_params = MDescriptor->getNumParameters();
for (uint32_t i=0; i<num_params; i++) {
float v = 0.f;
state->read(&v,sizeof(float),&num_read);
//setParameterValue(i,v);
MParameterValues[i] = v;
//on_plugin_parameter(i,v,0);
}
updateAllParameters();
break;
}
}
return kode_vst3_ResultOk;
}
//----------
/*
Retrieves complete state of component.
//state->write(MParamValues,MNumParameters*sizeof(float));
mode
0 = user
1 = simple (all params)
*/