-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpluginconstants.h
More file actions
1761 lines (1464 loc) · 45.6 KB
/
Copy pathpluginconstants.h
File metadata and controls
1761 lines (1464 loc) · 45.6 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
#pragma once
// turn off non-critical warnings
#pragma warning(disable : 4244)//double to float
#pragma warning(disable : 4996)//strncpy
#pragma warning(disable : 4305)//double float truncation
#pragma warning(disable : 4018)//signed/unsigned mismatch
#pragma warning(disable : 4800)//signed/unsigned mismatch
#pragma warning(disable : 4267)//'initializing' : conversion from 'xxxxxx' to 'int, float, etc...'
// includes for the project
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// --- for RAFX2 support, internal to RackAFX
#ifdef _RAFX2
#include"PluginKernel/pluginstructures.h"
#else
#include <stdint.h>
class IMidiEventQueue
{
public:
// --- Get the event count (extra, does not really need to be used)
virtual uint32_t getEventCount() = 0;
// --- Fire off the next
virtual bool fireMidiEvents(uint32_t uSampleOffset) = 0;
};
#endif
// this #define enables the following constants form math.h
#define _MATH_DEFINES_DEFINED
/*
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.707106781186547524401
*/
#include <math.h>
// For WIN vs MacOS
// XCode requires these be defined for compatibility
#if defined _WINDOWS || defined _WINDLL
#include <windows.h>
#else // MacOS
typedef unsigned int UINT;
typedef unsigned long DWORD;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
#endif
// --- v6.6 RAFX GUI Stuff
// --- messages
enum {GUI_DID_OPEN, /* RAFX GUI called after GUI_RAFX_OPEN, NOT called with GUI_USER_CUSTOM_OPEN */
GUI_WILL_CLOSE, /* RAFX GUI called after GUI_RAFX_CLOSE, but before window is destroyed, NOT called with GUI_USER_CUSTOM_CLOSE */
GUI_TIMER_PING, /* timer ping for custom views */
GUI_CUSTOMVIEW, /* query for a custom view */
GUI_SUBCONTROLLER, /* query for a subcontroller (not supported) */
GUI_HAS_USER_CUSTOM, /* CUSTOM GUI - reply in bHasUserCustomView */
GUI_USER_CUSTOM_OPEN, /* CUSTOM GUI - create your custom GUI, you must supply the code */
GUI_USER_CUSTOM_CLOSE, /* CUSTOM GUI - destroy your custom GUI, you must supply the code */
GUI_USER_CUSTOM_SIZE, /* CUSTOM GUI Size - currently not used, return in the info struct instead */
GUI_RAFX_OPEN,
GUI_RAFX_CLOSE,
GUI_RAFX_INIT,
GUI_RAFX_SYNC,
GUI_EXTERNAL_SET_NORM_VALUE,
GUI_EXTERNAL_SET_ACTUAL_VALUE,
GUI_EXTERNAL_GET_NORM_VALUE, /* currently not used */
GUI_EXTERNAL_GET_ACTUAL_VALUE}; /* currently not used */
// --- simple stucts
typedef struct
{
int x;
int y;
}VSTGUIPOINT;
typedef struct
{
int width;
int height;
}VSTGUISIZE;
typedef struct
{
int left;
int top;
int bottom;
int right;
}VSTGUIRECT;
// --- info/messaging struct for RAFX<-->GUI Communication
typedef struct
{
unsigned int message; // type of info message
// --- custom view stuff
char* customViewName;
int customViewTag;
VSTGUIRECT customViewRect;
VSTGUIPOINT customViewOffset;
char* customViewBitmapName;
char* customViewHandleBitmapName; // sliders
char* customViewOffBitmapName; // LED Meters
char* customViewOrientation; // sliders, switches, meters
void* customViewBackColor; // CColor cloaked
void* customViewFrameColor; // CColor cloaked
void* customViewFontColor; // CColor cloaked
int customViewFrameWidth;
int customViewRoundRectRadius;
bool customViewStyleNoFrame;
bool customViewStyleRoundRect;
int customViewHtOneImage; // CAnimKnob
int customViewSubPixmaps; // CAnimKnob
// --- 9-part tiled offsets
bool isNinePartTiledBitmap;
double nptoLeft;
double nptoTop;
double nptoRight;
double nptoBottom;
// --- subcontroller stuff
char* subControllerName;
// --- pointer to VST3Editor
void* editor; // editor
void* window; // HWND for WinOS or NSView* for MacOS
void* listener; // HWND for WinOS or NSView* for MacOS
int vstPlatformType; // for VST2 vs. VST3 on MacOS support
// --- handles updates/inits from various APIs (pure custom GUIs only)
double normalizedParameterValue;
double actualParameterValue;
int parameterTag;
// --- instance stuff
void* hRAFXInstance;
void* hPlugInInstance;
// --- for RAFX View
void* XMLResource;
unsigned long xmlSize;
int nControlCount;
UINT* pControlMap;
void* pGUISynchronizer; // ptr to host GUI_PARAM_SYNCH_STRUCT (pure custom GUIs only)
void* pAAXParameters; // ptr to host AAX Parameters (pure custom GUIs only)
// --- for User Custom View
bool bHasUserCustomView;
VSTGUISIZE size; // return variable with GUI width/height, or (-1, -1) if GUI not supported
}VSTGUI_VIEW_INFO;
typedef struct
{
// --- bus
UINT uInputBus; // sidechain input = 1; others may follow
// --- pointers for the three process types
float* pFrameInputBuffer;
float* pRAFXInputBuffer;
float** ppVSTInputBuffer;
UINT uNumInputChannels;
UINT uBufferSize; // RAFX buffer only, generally you won't need this
bool bInputEnabled;
}audioProcessData;
// --- for thread safe GUI updates v6.7.2.x and above
// --- Messages
enum { preProcessData, postProcessData, updateHostInfo, idleProcessData, midiMessageEx, midiEventList, queryPluginInfo };
enum {vectorJoystickX_Offset, vectorJoystickY_Offset, numAddtlParams}; // numAddtlParams ALWAYS LAST
enum {paramCount, paramInfo, paramValueDisplay, paramValueIn, paramValueOut};
// --- struct for future MIDI expansion, implemented in Make VST for RAFX v6.8.0.5+
typedef struct
{
unsigned int uMessage;
unsigned int uChannel;
unsigned int uData1;
unsigned int uData2;
unsigned int uSampleOffset;
int nPitchBendValue;
float fNormalizedPitchBendValue;
bool bDirty;
}MIDI_EVENT;
// --- struct for VST2 Queries
typedef struct
{
unsigned int uInfoType;
int nNumParams;
int nParamIndex;
char cParamName[8];
char cParamUnits[8];
char cParamValue[8];
float fParamValueIn;
float fParamValueOut;
}VST2_INFO;
// --- struct for GUI parameter synchronization
typedef struct
{
int nControlIndex; /* index of CUICtrl Object in plugin list */
UINT uControlId; /* RackAFX ControlId */
float fNormalizedValue; /* normalized version of parameter */
float fActualValue; /* actual value of parameter */
bool bDirty; /* flag that parameter needs update */
bool bKorgVectorJoystickOrientation; /* Korg = Sequential Circuits = diamond shaped VJStick path */
// --- these are for future implementation
unsigned int uSampleOffset; /* future implementation, currently not used */
unsigned int uNumSAParameters; /* future implementation, currently not used */
unsigned int* pSASampleOffsets; /* future implementation, currently not used */
float* pSANormalizedValues; /* future implementation, currently not used */
float* pSAActualValue; /* future implementation, currently not used */
}GUI_PARAMETER;
// --- GUI Thread Synchronization struct for RackAFX ONLY
typedef struct
{
#if defined _WINDOWS || defined _WINDLL
CRITICAL_SECTION cs; /* thread protection mechanism */
#endif
GUI_PARAMETER* pGUIParameters; /* ptr to (copy of) GUI_PARAMETER array */
int nNumParams; /* num of params in struct; should be m_UIControlList.count( ) + numAddtlParams */
} GUI_PARAM_SYNCH_STRUCT;
typedef struct
{
// --- common to all APIs
unsigned long long uAbsoluteFrameBufferIndex; // --- the sample index at top of buffer; this is incremented for processAudioFrame() so you always know the current sample index; for processRackAFXBuffer() and processVSTBuffer() it is up to you to keep track
double dAbsoluteFrameBufferTime; // --- the time in seconds of the sample index at top of buffer; this is incremented for processAudioFrame() so you always know the current sample index; for processRackAFXBuffer() and processVSTBuffer() it is up to you to keep track
double dBPM; // --- beats per minute, aka "tempo"
float fTimeSigNumerator; // --- time signature numerator
UINT uTimeSigDenomintor; // --- time signature denominator
// --- VST3 Specific: note these use same variable names as VST3::struct ProcessContext
// see ..\VST3 SDK\pluginterfaces\vst\ivstprocesscontext.h for information on decoding these
//
unsigned int state; // --- a combination of the values from \ref StatesAndFlags; use to decode validity of other VST3 items in this struct
long long systemTime; // --- system time in nanoseconds (optional)
double continousTimeSamples; // --- project time, without loop (optional)
double projectTimeMusic; // --- musical position in quarter notes (1.0 equals 1 quarter note)
double barPositionMusic; // --- last bar start position, in quarter notes
double cycleStartMusic; // --- cycle start in quarter notes
double cycleEndMusic; // --- cycle end in quarter notes
unsigned int samplesToNextClock;// --- MIDI Clock Resolution (24 Per Quarter Note), can be negative (nearest)
/*
IF you need SMPTE information, you need to get the information yourself at the start of the process( ) function
where the above values are filled out. See the variables here in VST3 SDK\pluginterfaces\vst\ivstprocesscontext.h:
int32 smpteOffsetSubframes; // --- SMPTE (sync) offset in subframes (1/80 of frame)
FrameRate frameRate; // --- frame rate
*/
// --- AU Specific
// see AUBase.h for definitions and information on decoding these
//
double dCurrentBeat; // --- current DAW beat value
bool bIsPlayingAU; // --- notorously incorrect in Logic - once set to true, stays stuck there
bool bTransportStateChanged; // --- only notifies a change, but not what was changed to...
unsigned int nDeltaSampleOffsetToNextBeat; // --- samples to next beat
double dCurrentMeasureDownBeat; // --- current downbeat
bool bIsCycling; // --- looping
double dCycleStartBeat; // --- loop start
double dCycleEndBeat; // --- loop end
// --- AAX Specific
// see AAX_ITransport.h for definitions and information on decoding these
bool bIsPlayingAAX; // --- flag if playing
long long nTickPosition; // --- "Tick" is represented here as 1/960000 of a quarter note
bool bLooping; // --- looping flag
long long nLoopStartTick; // --- start tick for loop
long long nLoopEndTick ; // --- end tick for loop
/*
NOTE: there are two optional functions that cause a performance hit in AAX; these are commented out of the
RAFX ported projects; if you decide to use them, you should re-locate them to a non-realtime thread. Use
at your own risk!
int32_t nBars = 0;
int32_t nBeats = 0;
int64_t nDisplayTicks = 0;
int64_t nCustomTickPosition = 0;
// --- There is a minor performance cost associated with using this API in Pro Tools. It should NOT be used excessively without need
midiTransport->GetBarBeatPosition(&nBars, &nBeats, &nDisplayTicks, nAbsoluteSampleLocation);
// --- There is a minor performance cost associated with using this API in Pro Tools. It should NOT be used excessively without need
midiTransport->GetCustomTickPosition(&nCustomTickPosition, nAbsoluteSampleLocation);
NOTE: if you need SMPTE or metronome information, you need to get the information yourself at the start of the ProcessAudio( ) function
see AAX_ITransport.h for definitions and information on decoding these
virtual AAX_Result GetTimeCodeInfo(AAX_EFrameRate* oFrameRate, int32_t* oOffset) const = 0;
virtual AAX_Result GetFeetFramesInfo(AAX_EFeetFramesRate* oFeetFramesRate, int64_t* oOffset) const = 0;
virtual AAX_Result IsMetronomeEnabled(int32_t* isEnabled) const = 0;
*/
}HOST_INFO;
// --- thanks to Alexirae on my Forum for this LPF smoother; see:
// http://www.willpirkle.com/forum/synth-algorithms/frequency-change-in-wtoscillator/
//
// --- 6.8.0.5: added double-version
//
class CFloatParamSmoother
{
public:
CFloatParamSmoother(){a = 0.0; b = 0.0; z = 0.0; z2 = 0; da = 0.0; db = 0.0; dz = 0.0; dz2 = 0.0;}
void initParamSmoother(float smoothingTimeInMs, float samplingRate, float initValue)
{
const float c_twoPi = 6.283185307179586476925286766559f;
a = exp(-c_twoPi / (smoothingTimeInMs * 0.001f * samplingRate));
b = 1.f - a;
z = initValue;
z2 = initValue;
da = a;
db = b;
dz = z;
dz2 = z2;
}
inline bool smoothParameter(float in, float& out)
{
z = (in * b) + (z * a);
if(z == z2)
{
out = in;
return false;
}
z2 = z;
out = z2;
return true;
}
inline bool smoothDoubleParameter(double in, double& out)
{
dz = (in * db) + (dz * da);
if(dz == dz2)
{
out = in;
return false;
}
dz2 = dz;
out = dz2;
return true;
}
private:
float a;
float b;
float z;
float z2;
double da;
double db;
double dz;
double dz2;
};
// --- Interface for VST3 parameter value update queue (sample accurate automation)
class IParamUpdateQueue
{
public:
// --- Get the index number associated with the parameter
virtual UINT getParameterIndex() = 0;
// --- Get the sample-accurate value of the parameter at the given sample offset. Pass in the last known normalized value.
// Returns true if dPreviousValue != dNextValue
virtual bool getValueAtOffset(long int lSampleOffset, double dPreviousValue, double &dNextValue) = 0;
// --- Get the sample-accurate value of the parameter at the next sample offset, determined by an internal counter
// Returns true if dNextValue is different than the previous value
virtual bool getNextValue(double &dNextValue) = 0;
};
// --- only for plugins that use processVSTBuffers() and inside of VST3 host
class IMidiEventList
{
public:
// --- Get the event count (extra, does not really need to be used)
virtual UINT getEventCount() = 0;
// --- Fire off the next
virtual bool fireMidiEvent(unsigned int uSampleOffset) = 0;
};
typedef struct
{
char* rafx2Name;
IMidiEventQueue* midiEventQueue;
}RAFX2_INFO;
typedef struct
{
const GUI_PARAMETER* pInGUIParameters;
const GUI_PARAMETER* pOutGUIParameters;
const HOST_INFO* pHostInfo;
const MIDI_EVENT* pMIDIEvent; // for sample accurate MIDI in AU versions
IMidiEventList* pIMidiEventList;
VST2_INFO* pVSTInfo; // for VST2 queries
RAFX2_INFO* pRAFX2Info;
int nNumParams; // = number of ordinary RAFX variables + 2 for Vector Joystick
bool bIgnoreSmoothing; // for impulse response analyzer measurements only, not for normal audio processing
}PROCESS_INFO;
#if defined _WINDOWS || defined _WINDLL
#if (_MSC_VER <= 1700) // vs2012 and earlier
#ifndef fmax
#define fmax(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef fmin
#define fmin(a,b) (((a) < (b)) ? (a) : (b))
#endif
#endif
#endif
#ifndef itoa
#define itoa(value,string,radix) sprintf(string, "%d", value)
#endif
#ifndef ltoa
#define ltoa(value,string,radix) sprintf(string, "%u", value)
#endif
// a few more constants from student suggestions
#define pi 3.1415926535897932384626433832795
#define sqrt2over2 0.707106781186547524401 // same as M_SQRT1_2
// constants for dealing with overflow or underflow
#define FLT_EPSILON_PLUS 1.192092896e-07 /* smallest such that 1.0+FLT_EPSILON != 1.0 */
#define FLT_EPSILON_MINUS -1.192092896e-07 /* smallest such that 1.0-FLT_EPSILON != 1.0 */
#define FLT_MIN_PLUS 1.175494351e-38 /* min positive value */
#define FLT_MIN_MINUS -1.175494351e-38 /* min negative value */
const UINT CONTROL_THEME_SIZE = 32;
const UINT PLUGIN_CONTROL_THEME_SIZE = 64;
const UINT CONTROL_THEME = 0;
const UINT PRESET_COUNT = 16; // more than 16 in VST gets sluggish depending on the client
const UINT CURRENT_PLUGIN_API = 64;
const UINT MAX_USER_METERS = 1034; // v6.8+ allows 20 + 1014 = 1034 user meters
// --- m_uPlugInEX[ ] index values
//
// Other index values are used in RackAFX Client only
//
const UINT RESERVED_3 = 3; // future use
const UINT ENABLE_SIDECHAIN_VSTAU = 4; // VSTAU sidechain enable
const UINT ENABLE_SAA_VST3 = 5; // sample accurate automation/param support
const UINT SAA_VST3_GRANULARITY = 6; // sample accurate automation/param support
const UINT VST_INFINITE_TAIL = 7; // infinite tail time for VST, forces transport always-on
// -------------------------------------------------------------------------
// --- CControl::uFluxCapControl
const UINT RESERVED_FLUX_CAP_CTRL_0 = 0; // --- reserved
const UINT RESERVED_FLUX_CAP_CTRL_1 = 1; // --- reserved
const UINT RESERVED_FLUX_CAP_CTRL_2 = 2; // --- reserved
// -------------------------------------------------------------------------
// --- CControl::fFluxCapData
const UINT RESERVED_FLUX_CAP_VALUE_0 = 0; // --- reserved
const UINT RESERVED_FLUX_CAP_VALUE_1 = 1; // --- reserved
const UINT RESERVED_FLUX_CAP_VALUE_2 = 2; // --- reserved
// -------------------------------------------------------------------------
// custom messages
#define SEND_STATUS_WND_MESSAGE WM_USER + 3000
#define SEND_JSPROG_BUTTON_CLICK WM_USER + 3008
const UINT MAX_JS_PROGRAM_STEPS = 16;
const UINT MAX_JS_PROGRAM_STEP_VARS = 7;
const UINT JS_PROGRAM_CHANGE = 0xFFFFFFFF;
// helper for the 2-Dimensional Joystick Program array
#define JS_PROG_INDEX(x,y) ((x)+(MAX_JS_PROGRAM_STEPS*(y)))
// basic enums
enum {intData, floatData, doubleData, UINTData, nonData};
enum {JS_ONESHOT, JS_LOOP, JS_SUSTAIN, JS_LOOP_BACKANDFORTH};
// SHARED with Client App - do not remove!
#ifndef CLIENT_APP
const UINT FILTER_CONTROL_CONTINUOUSLY_VARIABLE = 100;
const UINT FILTER_CONTROL_DIRECT_DATA_ENTRY = 101;
const UINT FILTER_CONTROL_RADIO_SWITCH_VARIABLE = 102;
const UINT FILTER_CONTROL_LED_METER = 103; // RackAFX custom LED meters 5/23/11
const UINT FILTER_CONTROL_COMBO_VARIABLE = 104; // my own Joystick 7/30/11
const UINT DETECT_MODE_PEAK = 0;
const UINT DETECT_MODE_MS = 1;
const UINT DETECT_MODE_RMS = 2;
const UINT DETECT_MODE_NONE = 3;
/*
Function: lagrpol() implements n-order Lagrange Interpolation
Inputs: double* x Pointer to an array containing the x-coordinates of the input values
double* y Pointer to an array containing the y-coordinates of the input values
int n The order of the interpolator, this is also the length of the x,y input arrays
double xbar The x-coorinates whose y-value we want to interpolate
Returns The interpolated value y at xbar. xbar ideally is between the middle two values in the input array,
but can be anywhere within the limits, which is needed for interpolating the first few or last few samples
in a table with a fixed size.
*/
inline double lagrpol(double* x, double* y, int n, double xbar)
{
int i,j;
double fx=0.0;
double l=1.0;
for (i=0; i<n; i++)
{
l=1.0;
for (j=0; j<n; j++)
{
if (j != i)
l *= (xbar-x[j])/(x[i]-x[j]);
}
fx += l*y[i];
}
return (fx);
}
inline float dLinTerp(float x1, float x2, float y1, float y2, float x)
{
float denom = x2 - x1;
if(denom == 0)
return y1; // should not ever happen
// calculate decimal position of x
float dx = (x - x1)/(x2 - x1);
// use weighted sum method of interpolating
float result = dx*y2 + (1-dx)*y1;
return result;
}
inline bool normalizeBuffer(double* pInputBuffer, UINT uBufferSize)
{
double fMax = 0;
for(UINT j=0; j<uBufferSize; j++)
{
if((fabs(pInputBuffer[j])) > fMax)
fMax = fabs(pInputBuffer[j]);
}
if(fMax > 0)
{
for(UINT j=0; j<uBufferSize; j++)
pInputBuffer[j] = pInputBuffer[j]/fMax;
}
return true;
}
#endif
// Helper Functions ------------------------------------------------------------- //
// calcLogControl: accepts a float variable from 0.0 to 1.0
// returns a log version from 0.0 to 1.0
/* y = 0.5*log10(x) + 1.0
|
1.0 | *
| *
| *
| *
|*
|*
0.0 ------------------------
0.0 1.0
*/
inline float calcLogControl(float fVar)
{
return fVar == 0.0 ? 0.0 : 0.5*log10(fVar) + 1.0;
}
// ----------------------------------------------------------------------------- //
// calcAntiLogControl: accepts a float variable from 0.0 to 1.0
// returns an anti-log version from 0.0 to 1.0
/* y = e^(2x-2)
|
1.0 | *
| *
| *
| *
| *
|*
0.0 ------------------------
0.0 1.0
*/
inline float calcAntiLogControl(float fVar)
{
return pow(10.0, 2.0*fVar - 2);
}
// ----------------------------------------------------------------------------- //
// calcInverseLogControl:accepts a float variable from 0.0 t0 1.0
// returns an anti-log version from 1.0 to 0.0
/* y = 0.5(1-x) + 1
|
1.0 |*
| *
| *
| *
| *
| *
0.0 ------------------------
0.0 1.0
*/
inline float calcInverseLogControl(float fVar)
{
return fVar == 1.0 ? 0.0 : 0.5*log10(1.0 - fVar) + 1.0;
}
// ----------------------------------------------------------------------------- //
// calcInverseAntiLogControl: accepts a float variable from 0.0 t0 1.0
// returns an anti-log version from 1.0 to 0.0
/* y = 10^(-2x) -- this is similar to e^(-5x) but clamps value to 0 at 1
|
1.0 |*
|*
| *
| *
| *
| *
0.0 ------------------------
0.0 1.0
*/
inline float calcInverseAntiLogControl(float fVar)
{
return pow((float)10.0, (float)-2.0*fVar);
}
// ----------------------------------------------------------------------------- //
// Helpers for advanced users who make their own GUI
inline float calcDisplayVariable(float fMin, float fMax, float fVar)
{
return (fMax - fMin)*fVar + fMin;
}
// 0->1
inline float calcSliderVariable(float fMin, float fMax, float fVar)
{
float fDiff = fMax - fMin;
float fCookedData = (fVar - fMin)/fDiff;
return fCookedData;
}
inline void RotateVJSPoint45CW(double& x1, double& y1)
{
double x = x1;
double y = y1;
x1 = (x + y)/1.41421356;
y1 = (y - x)/1.41421356;
}
inline void RotateVJSPoint45CCW(double& x1, double& y1)
{
double x = x1;
double y = y1;
x1 = (x - y)/1.41421356;
y1 = (x + y)/1.41421356;
}
// --- for RAFX only
inline void calculateRAFXVectorMixValues(double dPointX, double dPointY,
double& dAmag, double& dBmag, double& dCmag, double& dDmag,
double& dACMix, double& dBDMix, bool bJoystickCoords = true)
{
double x = dPointX;
double y = dPointY;
double dUnitScalar = 1.41421356; // sqrt(2)
if(!bJoystickCoords)
{
RotateVJSPoint45CCW(x, y);
x /= dUnitScalar;
y /= dUnitScalar;
}
// these are 0->1 unipolar
dACMix = (x + 1.0)/2.0;
dBDMix = (y + 1.0)/2.0;
if(bJoystickCoords)
{
dPointX *= dUnitScalar;
dPointY *= dUnitScalar;
}
// actual surface is -45 degrees from joystick axes
if(bJoystickCoords)
RotateVJSPoint45CW(dPointX, dPointY);
dPointX *= 127;
dPointY *= 127;
if (dPointX > 127) /* Limit range to -128 - 127 */
dPointX = 127;
else if (dPointX < -128)
dPointX = -128;
if (dPointY > 127) /* Limit range to -128 - 127 */
dPointY = 127;
else if (dPointY < -128)
dPointY = -128;
dPointX += 127;
dPointY += 127;
if(dPointX == 127 && dPointY == 127)
{
dAmag = 0.25;
dBmag = 0.25;
dCmag = 0.25;
dDmag = 0.25;
return;
}
// the Korg/Sequential Circuits VS Equations
dBmag = dPointX*dPointY/645; /* Calculate individual wave % */
dCmag = dPointX*(255 - dPointY)/645; /* 645=(255^2/100)*127/128 */
dDmag = (255-dPointX)*(255-dPointY)/645;
dAmag = 100.0 - dBmag - dCmag - dDmag;
// convert from percent
dAmag /= 100.0;
dBmag /= 100.0;
dCmag /= 100.0;
dDmag /= 100.0;
// limit to 1.0 from rounding/truncation
dAmag = fmin(1.0, dAmag);
dBmag = fmin(1.0, dBmag);
dCmag = fmin(1.0, dCmag);
dDmag = fmin(1.0, dDmag);
dAmag = fmax(0.0, dAmag);
dBmag = fmax(0.0, dBmag);
dCmag = fmax(0.0, dCmag);
dDmag = fmax(0.0, dDmag);
}
//
// String Helpers: these convert to and from strings
//
// user must delete char array when done!
inline char* uintToString(long value)
{
char* text = new char[33];
ltoa (value, text, 10);
return text;
}
inline UINT stringToUINT(char* p)
{
return atol (p);
}
// user must delete char array when done!
inline char* intToString(long value)
{
char* text = new char[33];
itoa (value, text, 10);
return text;
}
inline double stringToDouble(char* p)
{
return atof (p);
}
inline double stringToFloat(char* p)
{
return atof (p);
}
inline int stringToInt(char* p)
{
return atol (p);
}
// user must delete char array when done!
inline char* floatToString(float value, int nSigDigits)
{
char* text = new char[64];
if(nSigDigits > 32)
nSigDigits = 32;
// gcvt (value, nSigDigits, text);
sprintf(text,"%.*f", nSigDigits, value);
return text;
}
// user must delete char array when done!
inline char* doubleToString(double value, int nSigDigits)
{
char* text = new char[64];
if(nSigDigits > 32)
nSigDigits = 32;
// gcvt (value, nSigDigits, text);
sprintf(text,"%.*f", nSigDigits, value);
return text;
}
// user must delete the return char* after use
//
// This function returns the contatenation of String1 and String2 as a newly created
// correctly sized string.
//
// example:
// char* p = addStrings("this", " and that"):
//
// results in p = "this and that"
//
// example, when called from your DLL you can use your getMyDLLDirectory() method:
// char* p = addStrings(getMyDLLDirectory(),"\\test\\this.wav"); <-- note the double \\
//
// this returns a char* that is the Path to the file: this.wav
// located in the folder: test
// which is located: inside the Directory containing your PlugIn
inline char* addStrings(char* pString1, char* pString2)
{
int n = strlen(pString1);
int m = strlen(pString2);
char* p = new char[n+m+1];
strcpy(p, pString1);
return strncat(p, pString2, m);
}
// Helpers for separating control and data information
// advanced use only, see website for details
inline int extractControlID(char* p)
{
// find :
char * pColon;
pColon = strchr(p,':');
if(!pColon) return -1; // no more
DWORD dEndIndex = strlen(p) - strlen(pColon);
char* pID = new char[dEndIndex+1];
memset(pID,0,dEndIndex);
strncpy(pID, p, dEndIndex);
pID[dEndIndex] = '\0';
int n = stringToInt(pID);
delete [] pID;
return n;
}
inline double extractControlValue(char* p)
{
// find :
char * pColon;
pColon = strchr(p,':');
if(!pColon) return -1; // no more
DWORD dEndIndex = strlen(pColon);
char* pVal = new char[dEndIndex+1];
memset(pVal,0,dEndIndex);
strncpy(pVal, pColon+1, dEndIndex);
pVal[dEndIndex] = '\0';
//delete [] pVal;
//return 0;
double d = stringToDouble(pVal);
delete [] pVal;
return d;
}
// END Helper Functions --------------------------------------------------------- //
// RackAFX Built-In Objects for use in Plug-Ins; see book for details
//
//
// Note about Helper Objects: DO NOT MODIFY THESE OBJECTS. If you need to do so,
// create a derived class and modify it. These objects may be updated from time to
// time so they need to be left alone.
//
// The Object Implementations are found in PluginObjects.cpp
//
// --- CEnvelopeDetector ---
//
// http://www.musicdsp.org/archive.php?classid=0#205
//
const float DIGITAL_TC = -4.60517019; // ln(1%)
const float ANALOG_TC = -1.00239343; // ln(36.7%)
const float METER_UPDATE_INTERVAL_MSEC = 50.0;
const float RAFX_METER_UPDATE_INTERVAL_MSEC = 50.0; //125.0;
const float METER_MIN_DB = -60.0;
class CEnvelopeDetector
{
public:
CEnvelopeDetector(void);
~CEnvelopeDetector(void);
public:
// Call the Init Function to initialize and setup all at once; this can be called as many times
// as you want
void init(float samplerate, float attack_in_ms, float release_in_ms, bool bAnalogTC, UINT uDetect, bool bLogDetector);
// these functions allow you to change modes and attack/release one at a time during
// realtime operation
void setTCModeAnalog(bool bAnalogTC); // {m_bAnalogTC = bAnalogTC;}
// THEN do these after init
void setAttackTime(float attack_in_ms);
void setReleaseTime(float release_in_ms);
// Use these "codes"
// DETECT PEAK = 0
// DETECT MS = 1
// DETECT RMS = 2
//
void setDetectMode(UINT uDetect) {m_uDetectMode = uDetect;}
void setSampleRate(float f) {m_fSampleRate = f;}
void setLogDetect(bool b) {m_bLogDetector = b;}
// call this to detect; it returns the peak ms or rms value at that instant
float detect(float fInput);
// call this from your prepareForPlay() function each time to reset the detector
void prepareForPlay();
protected:
int m_nSample;
float m_fAttackTime;
float m_fReleaseTime;
float m_fAttackTime_mSec;
float m_fReleaseTime_mSec;
float m_fSampleRate;
float m_fEnvelope;
UINT m_uDetectMode;
bool m_bAnalogTC;
bool m_bLogDetector;
};
// --- BiQuad ---
// This class can be used alone or as the base class for a derived object
// Note the virtual destructor, required for proper clean-up of derived
// classes
//
// Implements a single Bi-Quad Structure
class CBiQuad
{
public:
CBiQuad(void);
virtual ~CBiQuad(void);
protected:
float m_f_Xz_1; // x z-1 delay element
float m_f_Xz_2; // x z-2 delay element
float m_f_Yz_1; // y z-1 delay element
float m_f_Yz_2; // y z-2 delay element