-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamMaster.cpp
1421 lines (1257 loc) · 49.5 KB
/
StreamMaster.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
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
#include "StreamMaster.h"
#include "IPlug_include_in_plug_src.h"
#include "DLPG_FeedbackSender.h"
#include <cmath>
// Number of presets
const int kNumPrograms = 1;
/*
@brief All GUI relates data is updated in this thread
@note Actual redrawing happens in IPlug's craphics core automatically at a given FPS, not here.
*/
void StreamMaster::UpdateGui()
{
char sLoudnessString[PLUG_METER_TEXT_LABEL_STRING_SIZE];
char sGrString[PLUG_METER_TEXT_LABEL_STRING_SIZE];
double fMaxGainReductionPerFrameDb = 0.;
double fLufs = tLoudnessMeter->GetLufs();
double fLufsShortTerm = tLoudnessMeter->GetShortTermLufs();
double fTruePeakingDb, fTruePeakingShortTermDb, fTruePeakingOfWindowDb;
char sLufsInt[PLUG_DB_VALUE_STRING_SIZE];
char sLufsShortTerm[PLUG_DB_VALUE_STRING_SIZE];
// Text below LUFS meter bar
// If values are to low, they would be displayed as "-oo"
if((fLufs < PLUG_DB_VALUE_TOO_LOW) || std::isnan(fLufs))
memcpy(sLufsInt, sDbValueMinusInf, PLUG_DB_VALUE_MINUS_INF_LEN);
else
sprintf(sLufsInt, "%4.1f", fLufs);
if((fLufsShortTerm < PLUG_DB_VALUE_TOO_LOW) || std::isnan(fLufsShortTerm))
memcpy(sLufsShortTerm, sDbValueMinusInf, PLUG_DB_VALUE_MINUS_INF_LEN);
else
sprintf(sLufsShortTerm, "%4.1f", fLufsShortTerm);
sprintf(sLoudnessString, "Int.: %sLUFS\nShort: %sLUFS", sLufsInt, sLufsShortTerm);
tLoudnessTextControl->SetTextFromPlug(sLoudnessString);
// Updating LUFS bar values
tILevelMeteringBar->SetValue(fLufs);
double fGrMeterGainLinear, fGrMeterCurrentPeakDb;
static double fGrMeterPreviousPeakDb = 0.;
// Updating gain reduction bar values
if (tPlugCurrentMode == PLUG_MASTER_MODE){
fMaxGainReductionPerFrameDb = LINEAR_TO_LOG(fMaxGainReductionPerFrame);
// ("<" because gain reduction is negative in log domain)
if (fMaxGainReductionPerFrameDb < fMaxGainReductionPerSessionDb){
fMaxGainReductionPerSessionDb = fMaxGainReductionPerFrameDb;
tIGrMeteringBar->SetNotchValue(fMaxGainReductionPerSessionDb);
}
// Filter GR meter values so it won't flash too fast
fGrMeterGainLinear = \
(fMaxGainReductionPerFrameDb > fGrMeterPreviousPeakDb ? PLUG_GR_METER_DECAY : PLUG_GR_METER_ATTACK);
fGrMeterCurrentPeakDb = \
fMaxGainReductionPerFrameDb * fGrMeterGainLinear + \
fGrMeterPreviousPeakDb * (1.0 - fGrMeterGainLinear);
fGrMeterPreviousPeakDb = fGrMeterCurrentPeakDb;
tIGrMeteringBar->SetValue(fGrMeterCurrentPeakDb);
}
// Text below Gain reduction bar
sprintf(sGrString, "GR: %4.2fdB\nMax: %4.2fdB",
fMaxGainReductionPerFrameDb,
fMaxGainReductionPerSessionDb);
tGrTextControl->SetTextFromPlug(sGrString);
// True peaking text label
if(tPlugCurrentMode == PLUG_MASTER_MODE){
// TP
fTruePeakingDb = LINEAR_TO_LOG(tLoudnessMeter->GetTruePeaking());
fTruePeakingShortTermDb = LINEAR_TO_LOG(tLoudnessMeter->GetTruePeakingShortTerm());
UpdateTruePeak(fTruePeakingDb);
/*
Dynamic range (PSR)
PSR = TP_short_term - LUFS_short_term
Both parameters have to have the same window (3s). LUFS short term has a
correct window as it is, but we have to do extra stuff with TP.
*/
tPeakingBuffer->Add(fTruePeakingShortTermDb);
fTruePeakingOfWindowDb = tPeakingBuffer->GetMax();
double fCurrentPsrDb = fTruePeakingOfWindowDb - fLufsShortTerm;
UpdateDynamicRange(fCurrentPsrDb);
}
}
void StreamMaster::UpdateDynamicRange(double fDynamicRangeDb){
static double fPreviousDynamicRangeDb = PLUG_DR_WARNING_VALUE_DB + 0.1;
char sDrValue[PLUG_DB_VALUE_STRING_SIZE];
char sDrString[PLUG_DR_LABEL_STRING_SIZE];
IText tDrLabel;
/*
The higher the PSR value is (in log domain), the more dynamics the track has.
If PSR falls below a certain level (e.g. +8dB), it's considered not healthy,
so it should not be a full-on alert, just a friendly warning.
*/
// If we crossed PSR threshold down, do the warning stuff
if(
(fDynamicRangeDb <= PLUG_DR_WARNING_VALUE_DB) &&
((fPreviousDynamicRangeDb > PLUG_DR_WARNING_VALUE_DB) ||
tDrTextControl == tDrResetTextControl)
){
tDrWarningTextControl->Hide(false);
tDrOkTextControl->Hide(true);
tDrResetTextControl->Hide(true);
tDrTextControl = tDrWarningTextControl;
}
// If we crossed PSR threshold up, undo the warning stuff
if(
(fDynamicRangeDb > PLUG_DR_WARNING_VALUE_DB) &&
((fPreviousDynamicRangeDb < PLUG_DR_WARNING_VALUE_DB) ||
tDrTextControl == tDrResetTextControl)
){
tDrWarningTextControl->Hide(true);
tDrOkTextControl->Hide(false);
tDrResetTextControl->Hide(true);
tDrTextControl = tDrOkTextControl;
}
/* If the value is too high, it would be displayed as "+oo".
It may be also "nan" during start up, in that case it's "+oo" as well. */
if(
(fDynamicRangeDb > PLUG_DB_VALUE_TOO_HIGH) ||
(fDynamicRangeDb < PLUG_DB_VALUE_TOO_LOW) ||
std::isnan(fDynamicRangeDb)
){
if(tDrTextControl != tDrResetTextControl){
tDrWarningTextControl->Hide(true);
tDrOkTextControl->Hide(true);
tDrResetTextControl->Hide(false);
tDrTextControl = tDrResetTextControl;
}
memcpy(sDrValue, sDbValuePlusInf, PLUG_DB_VALUE_PLUS_INF_LEN);
}
else
sprintf(sDrValue, "%3.1f", fDynamicRangeDb);
fPreviousDynamicRangeDb = fDynamicRangeDb;
sprintf(sDrString, "PSR: %sdB", sDrValue);
tDrTextControl->SetTextFromPlug(sDrString);
}
void StreamMaster::UpdateTruePeak(double fTruePeakingDb){
static double fPreviousTruePeakingDb=LINEAR_TO_LOG(0.);
char sTpValue[PLUG_DB_VALUE_STRING_SIZE];
char sTpString[PLUG_TP_LABEL_STRING_SIZE];
IText tTpLabel;
// If we crossed TP threshold up, do some alert stuff
if(
(fTruePeakingDb >= PLUG_TP_ALERT_VALUE_DB) &&
((fPreviousTruePeakingDb < PLUG_TP_ALERT_VALUE_DB) ||
tTpTextControl == tTpResetTextControl)
){
tTpOkTextControl->Hide(true);
tTpAlertTextControl->Hide(false);
tTpResetTextControl->Hide(true);
tTpTextControl = tTpAlertTextControl;
}
// If we crossed TP threshold down, undo the alert stuff
if(
(fTruePeakingDb < PLUG_TP_ALERT_VALUE_DB) &&
((fPreviousTruePeakingDb > PLUG_TP_ALERT_VALUE_DB) ||
tTpTextControl == tTpResetTextControl)
){
tTpAlertTextControl->Hide(true);
tTpOkTextControl->Hide(false);
tTpResetTextControl->Hide(true);
tTpTextControl = tTpOkTextControl;
}
/* If the value is too low, it would be displayed as "-oo".
It may be also "nan" during start up, in that case it's "-oo" as well. */
if((fTruePeakingDb < PLUG_DB_VALUE_TOO_LOW) || std::isnan(fTruePeakingDb)){
if(tTpTextControl != tTpResetTextControl){
tTpAlertTextControl->Hide(true);
tTpOkTextControl->Hide(true);
tTpResetTextControl->Hide(false);
tTpTextControl = tTpResetTextControl;
}
memcpy(sTpValue, sDbValueMinusInf, PLUG_DB_VALUE_MINUS_INF_LEN);
}
else
sprintf(sTpValue, "%+4.1f", fTruePeakingDb);
fPreviousTruePeakingDb = fTruePeakingDb;
sprintf(sTpString, "TP: %sdB", sTpValue);
tTpTextControl->SetTextFromPlug(sTpString);
}
/*
\brief Locks and unlocks controls depending on current mode. Called every time the mode is changed.
*/
void StreamMaster::UpdateAvailableControls(){
bool
bIsModeSwitchDisabled,
bIsGrMeteringDisabled,
bIsLoudnessMeteringDisabled,
bIsMasteringKnobsDisabled,
bIsPlatformSwitchesDisabled,
bIsTpMeteringDisabled;
#ifdef PLUG_DO_NOT_BLOCK_CONTROLS
// Unlock all controls in debug mode
bIsModeSwitchDisabled = false;
bIsGrMeteringDisabled = false;
bIsLoudnessMeteringDisabled = false;
bIsMasteringKnobsDisabled = false;
bIsPlatformSwitchesDisabled = false;
bIsTpMeteringDisabled = false;
#else
if(bIsBypassed){
// Everything is locked if the plug is bypassed
bIsModeSwitchDisabled = true;
bIsGrMeteringDisabled = true;
bIsLoudnessMeteringDisabled = true;
bIsMasteringKnobsDisabled = true;
bIsPlatformSwitchesDisabled = true;
bIsTpMeteringDisabled = true;
}
else{
// Not bypassed
switch (tPlugCurrentMode){
case PLUG_LEARN_MODE:
// Learn mode
// Only mode switch and LUFS meter
bIsModeSwitchDisabled = false;
bIsGrMeteringDisabled = true;
bIsLoudnessMeteringDisabled = false;
bIsMasteringKnobsDisabled = true;
bIsPlatformSwitchesDisabled = true;
bIsTpMeteringDisabled = true;
break;
case PLUG_MASTER_MODE:
// Master mode
if(bLufsTooLow)
{
// If LUFS was too low in learning mode...
// Only mode switch
// TODO: Do we need to show LUFS meter?
bIsModeSwitchDisabled = false;
bIsGrMeteringDisabled = true;
bIsLoudnessMeteringDisabled = false;
bIsMasteringKnobsDisabled = true;
bIsPlatformSwitchesDisabled = true;
bIsTpMeteringDisabled = true;
}
else{
// Everything unlocked
bIsModeSwitchDisabled = false;
bIsGrMeteringDisabled = false;
bIsLoudnessMeteringDisabled = false;
bIsMasteringKnobsDisabled = false;
bIsPlatformSwitchesDisabled = false;
bIsTpMeteringDisabled = false;
}
break;
case PLUG_OFF_MODE:
// Learn mode
// Only mode switch
bIsModeSwitchDisabled = false;
bIsGrMeteringDisabled = true;
bIsLoudnessMeteringDisabled = true;
bIsMasteringKnobsDisabled = true;
bIsPlatformSwitchesDisabled = true;
bIsTpMeteringDisabled = true;
break;
} //switch
} // bIsBypassed
#endif
tModeSwitch->GrayOut(bIsModeSwitchDisabled);
tIGrMeteringBar->GrayOut(bIsGrMeteringDisabled);
tPeakingKnob->GrayOut(bIsMasteringKnobsDisabled);
tAdjustKnob->GrayOut(bIsMasteringKnobsDisabled);
tPeakingTextControl->Hide(bIsMasteringKnobsDisabled);
tAdjustTextControl->Hide(bIsMasteringKnobsDisabled);
tPlatformSelector->GrayOut(bIsPlatformSwitchesDisabled);
tPlatformSelectorClickable->Hide(bIsPlatformSwitchesDisabled);
tPlatformSelectorClickableGreyOut->Hide(!bIsPlatformSwitchesDisabled);
tILevelMeteringBar->GrayOut(bIsLoudnessMeteringDisabled);
TIGrContactControl->GrayOut(bIsGrMeteringDisabled);
TILufsContactControl->GrayOut(bIsLoudnessMeteringDisabled);
tLoudnessTextControl->Hide(bIsLoudnessMeteringDisabled);
tGrTextControl->Hide(bIsGrMeteringDisabled);
tTpTextControl->Hide(bIsTpMeteringDisabled);
tDrTextControl->Hide(bIsTpMeteringDisabled);
}
/*
@brief Makes sure all DSP stuff works at the correct sample rate
*/
void StreamMaster::UpdateSampleRate(){
const double fCurrentSampleRate = GetSampleRate();
// Limiter's envelope has sample rate in Hz, double
tLimiter->setSampleRate(fCurrentSampleRate);
// Loudness meter has sample rate in Hz, unsigned long
tLoudnessMeter->SetSampleRate((unsigned long)fCurrentSampleRate);
// TP buffer
tPeakingBuffer->Resize(
PLUG_DR_METER_WINDOW_SECONDS,
fCurrentSampleRate,
GetBlockSize()
);
// Update sample rate in feedback link
MakeFeedbackUrl(sFeedbackUrl);
tFeedbackLink = new IURLControl(this, tFeedbackLinkIRect, sFeedbackUrl);
pGraphics->AttachControl(tFeedbackLink);
}
/*
\brief We set up GUI and related processing classes here.
*/
StreamMaster::StreamMaster(IPlugInstanceInfo instanceInfo):
IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo),
fLowestDynamicRangeDb(PLUG_DB_VALUE_TOO_HIGH)
{
TRACE;
//bJustRecalledSourceLufs = false;
int i; /* For enum inits */
IBitmap tBmp;
/*
Hide some parameters from DAW's automation menu; this also affects
whether or not the parameters are displayed in generic UI view.
Note: this does not affect all plugins formats. For instance, it works
in VST3, it should work in AAX, AU and RTAS, but is ignored in VST2.
*/
// Bar values are not for automation obviously
GetParam(kILevelMeteringBar)->SetCanAutomate(false);
GetParam(kIGrMeteringBar)->SetCanAutomate(false);
// There are two linked controls for platform selection, so we disable one of them
GetParam(kPlatformSwitchClickable)->SetCanAutomate(false);
// Meter reset buttons are not necessary for automation as well
GetParam(kIGrContactControl)->SetCanAutomate(false);
GetParam(kILufsContactControl)->SetCanAutomate(false);
// Setting up values for all the controls
// arguments are: name, defaultVal, minVal, maxVal, step, label
// Bypass switch
GetParam(kBypassSwitch)->InitBool("OnOff", 0, "");
// Ceiling knob
/*
We want to only have values with 0.1 step for ceiling knob,
plus make it feel "clicky" opposed to a usual smooth knob,
so we have to use integer values and convert them into double later.
For example, "9" represents -0.1dB, "0" is for -1.0dB etc.
if the actual range is -1.0..0.0dB
*/
GetParam(kCeiling)->InitInt(
"Ceiling",
PLUG_KNOB_PEAK_DEFAULT,
PLUG_KNOB_PEAK_MIN,
PLUG_KNOB_PEAK_MAX,
"tenths of dB"
);
GetParam(kCeiling)->SetShape(1.);
// Adjust knob
GetParam(kAdjust)->InitDouble(
"Target LUFS Adjust",
PLUG_KNOB_ADJUST_DEFAULT,
PLUG_KNOB_ADJUST_MIN,
PLUG_KNOB_ADJUST_MAX,
PLUG_KNOB_ADJUST_STEP,
"LUFS"
);
GetParam(kAdjust)->SetShape(1.);
/* LUFS and GR bars */
// Loudness meter
GetParam(kILevelMeteringBar)->InitDouble(
"[Loudness]",
PLUG_LUFS_RANGE_MIN,
PLUG_LUFS_RANGE_MIN,
PLUG_LUFS_RANGE_MAX,
0.1,
"LUFS"
);
/* GR meter
Min and max values are the other way around here
because -6dB of gain reduction is more than -3dB,
but -6 is less than -3 obviously. */
GetParam(kIGrMeteringBar)->InitDouble(
"[Gain reduction]",
PLUG_GR_RANGE_MIN,
PLUG_GR_RANGE_MAX,
PLUG_GR_RANGE_MIN,
0.1,
"dB");
// Mode and platform switches
GetParam(kModeSwitch)->InitEnum(
"Mode",
PLUG_CONVERT_PLUG_MODE_TO_SWITCH_VALUE(PLUG_INITIAL_MODE),
3
);
for (i=0; i<3; i++)
GetParam(kModeSwitch)->SetDisplayText(i, asModeNames[i]);
GetParam(kPlatformSwitchClickable)->InitEnum(
"[Target platform]",
PLUG_REVERSE_PLATFORM_SWITCH_VALUE(PLUG_DEFAULT_TARGET_PLATFORM),
PLUG_PLATFORM_OPTIONS
);
for (i=0; i<PLUG_PLATFORM_OPTIONS; i++)
GetParam(kPlatformSwitchClickable)->SetDisplayText(PLUG_REVERSE_PLATFORM_SWITCH_VALUE(i), asTargetNames[i]);
GetParam(kPlatformSwitch)->InitEnum(
"Target platform",
PLUG_DEFAULT_TARGET_PLATFORM,
PLUG_PLATFORM_OPTIONS
);
for (i=0; i<PLUG_PLATFORM_OPTIONS; i++)
GetParam(kPlatformSwitch)->SetDisplayText(i, asTargetNames[i]);
GetParam(kPlatformSwitch)->SetShape(1.);
GetParam(kPlatformSwitchClickable)->SetShape(1.);
// GR and LUFS overlay switches for resetting
GetParam(kIGrContactControl)->InitBool("[GR meter reset]", 0, "");
GetParam(kILufsContactControl)->InitBool("[Loudness meter reset]", 0, "");
// *** Initing actual GUI controls
// Plug window, background
pGraphics = MakeGraphics(this, kWidth, kHeight);
pGraphics->AttachBackground(BG_ID, BG_FN);
/* Meters - start */
// True peaking label
// One for "okay" state, one for "alert" state (different color),
// and one that stores the current text label pointer
// for okay state
IText tTpOkLabel = IText(PLUG_TP_LABEL_STRING_SIZE);
tTpOkLabel.mColor = PLUG_TP_LABEL_OK_COLOR;
tTpOkLabel.mSize = PLUG_TP_LABEL_FONT_SIZE;
tTpOkLabel.mAlign = tTpOkLabel.PLUG_TP_TEXT_ALIGNMENT;
tTpOkTextControl = new ITextControl(
this,
PLUG_TP_LABEL_IRECT,
&tTpOkLabel,
PLUG_TP_LABEL_DEFAULT_TEXT);
// for alert state
IText tTpAlertLabel = IText(tTpOkLabel);
tTpAlertLabel.mColor = PLUG_TP_LABEL_ALERT_COLOR;
tTpAlertTextControl = new ITextControl(
this,
PLUG_TP_LABEL_IRECT,
&tTpAlertLabel,
PLUG_TP_LABEL_DEFAULT_TEXT);
// for reset (default) state
IText tTpResetLabel = IText(tTpOkLabel);
tTpResetLabel.mColor = PLUG_TP_LABEL_RESET_COLOR;
tTpResetTextControl = new ITextControl(
this,
PLUG_TP_LABEL_IRECT,
&tTpResetLabel,
PLUG_TP_LABEL_DEFAULT_TEXT);
// for current state
tTpTextControl = tTpResetTextControl;
// TP labels should be attached later, so they are sandwitched
// between meter bars and meter reset buttons. Otherwise they
// may get in the way of clicking.
// Dynamic range label - similar to true peaking label
IText tDrOkLabel = IText(PLUG_DR_LABEL_STRING_SIZE);
tDrOkLabel.mColor = PLUG_DR_LABEL_OK_COLOR;
tDrOkLabel.mSize = PLUG_DR_LABEL_FONT_SIZE;
tDrOkLabel.mAlign = tDrOkLabel.PLUG_DR_TEXT_ALIGNMENT;
tDrOkTextControl = new ITextControl(
this,
PLUG_DR_LABEL_IRECT,
&tDrOkLabel,
PLUG_DR_LABEL_DEFAULT_TEXT);
// for warning state
IText tDrWarningLabel = IText(tDrOkLabel);
tDrWarningLabel.mColor = PLUG_DR_LABEL_WARNING_COLOR;
tDrWarningTextControl = new ITextControl(
this,
PLUG_DR_LABEL_IRECT,
&tDrWarningLabel,
PLUG_DR_LABEL_DEFAULT_TEXT);
// for reset state
IText tDrResetLabel = IText(tDrOkLabel);
tDrResetLabel.mColor = PLUG_DR_LABEL_RESET_COLOR;
tDrResetTextControl = new ITextControl(
this,
PLUG_DR_LABEL_IRECT,
&tDrResetLabel,
PLUG_DR_LABEL_DEFAULT_TEXT);
// for current state
tDrTextControl = tDrResetTextControl;
// Bars
// LUFS meter
tILevelMeteringBar = new Plug::ILevelMeteringBar(
this,
kLufsMeter_X,
kLufsMeter_Y,
PLUG_LUFS_METERING_BAR_IRECT,
kILevelMeteringBar,
false,
&LOUDNESS_BAR_FG_ICOLOR
);
tILevelMeteringBar->SetNotchValue(PLUG_LUFS_RANGE_MAX);
pGraphics->AttachControl(tILevelMeteringBar);
// Gain Reduction meter
tIGrMeteringBar = new Plug::ILevelMeteringBar(
this,
kGrMeter_X,
kGrMeter_Y,
PLUG_GR_METERING_BAR_IRECT,
kIGrMeteringBar,
true,
&GR_BAR_DEFAULT_FG_ICOLOR,
&GR_BAR_DEFAULT_NOTCH_ICOLOR,
&METERING_BAR_ABOVE_NOTCH_ICOLOR);
pGraphics->AttachControl(tIGrMeteringBar);
// Overlay labels
// "Loudness"
tBmp = pGraphics->LoadIBitmap(
LOUDNESSLABELOVERLAY_ID,
LOUDNESSLABELOVERLAY_FN,
1
);
tLoudnessLabelOverlay = new IBitmapControl(this, kLoudnessLabelOverlay_X, kLoudnessLabelOverlay_Y, &tBmp);
pGraphics->AttachControl(tLoudnessLabelOverlay);
// "Gain reduction"
tBmp = pGraphics->LoadIBitmap(
GRLABELOVERLAY_ID,
GRLABELOVERLAY_FN,
1
);
tGrLabelOverlay = new IBitmapControl(this, kGrLabelOverlay_X, kGrLabelOverlay_Y, &tBmp);
pGraphics->AttachControl(tGrLabelOverlay);
// Attaching TP and Dynamic range labels so they are below reset buttons
pGraphics->AttachControl(tTpOkTextControl);
pGraphics->AttachControl(tTpAlertTextControl);
pGraphics->AttachControl(tTpResetTextControl);
tTpOkTextControl->Hide(true);
tTpAlertTextControl->Hide(true);
tTpResetTextControl->Hide(false);
pGraphics->AttachControl(tDrOkTextControl);
pGraphics->AttachControl(tDrWarningTextControl);
pGraphics->AttachControl(tDrResetTextControl);
tDrOkTextControl->Hide(true);
tDrWarningTextControl->Hide(true);
tDrResetTextControl->Hide(false);
// Reset buttons - same coordinates as the actual meter bar
tBmp = pGraphics->LoadIBitmap(
METEROVERLAYSWITCH_ID,
METEROVERLAYSWITCH_FN,
kIContactControl_N
);
TIGrContactControl = new IContactControl(
this, kGrMeter_X, kGrMeter_Y, kIGrContactControl, &tBmp);
pGraphics->AttachControl(TIGrContactControl);
TILufsContactControl = new IContactControl(
this, kLufsMeter_X, kLufsMeter_Y, kILufsContactControl, &tBmp);
pGraphics->AttachControl(TILufsContactControl);
/* Meters - end */
// Bypass switch
tBmp = pGraphics->LoadIBitmap(BYPASSSWITCH_ID, BYPASSSWITCH_FN, kBypassSwitchFrames);
tBypassSwitch = new ISwitchControl(this, kBypassSwitchX, kBypassSwitchY, kBypassSwitch, &tBmp);
pGraphics->AttachControl(tBypassSwitch);
// Limiter knob
tBmp = pGraphics->LoadIBitmap(KNOB_ID, KNOB_FN, kKnobFrames);
tPeakingKnob = new IKnobMultiControl(this, kCeilingX, kCeilingY, kCeiling, &tBmp);
pGraphics->AttachControl(tPeakingKnob);
// Adjust knob
tBmp = pGraphics->LoadIBitmap(ADJUST_ID, ADJUST_FN, kAdjustFrames);
tAdjustKnob = new IKnobMultiControl(this, kAdjustX, kAdjustY, kAdjust, &tBmp);
pGraphics->AttachControl(tAdjustKnob);
// Mode selector (learn-master-off)
tBmp = pGraphics->LoadIBitmap(MODESWITCH_ID, MODESWITCH_FN, kModeSwitch_N);
tModeSwitch = new ISwitchControl(this, kModeSwitch_X, kModeSwitch_Y, kModeSwitch, &tBmp);
pGraphics->AttachControl(tModeSwitch);
// Platform selector (YT, spotify etc.)
// Rotatable control
tBmp = pGraphics->LoadIBitmap(PLATFORMSWITCH_ID, PLATFORMSWITCH_FN, kPlatformSwitch_N);
tPlatformSelector = new IKnobMultiControl(
this,
kPlatformSwitch_X,
kPlatformSwitch_Y,
kPlatformSwitch,
&tBmp
);
pGraphics->AttachControl(tPlatformSelector);
// Same control, but lest user click on platform names too
tBmp = pGraphics->LoadIBitmap(MODESWITCHCLICKABLE_ID, MODESWITCHCLICKABLE_FN, kPlatformSwitchClickable_N);
tPlatformSelectorClickable = new IRadioButtonsControl(
this,
tPlatformSwitchClickableIRect,
kPlatformSwitchClickable,
kPlatformSwitchClickable_TOTAL,
&tBmp
);
//IRadioButtonsControl(this, IRECT(kIRadioButtonsControl_V_X, kIRadioButtonsControl_V_Y, kIRadioButtonsControl_V_X + (kIRBC_W*kIRBC_VN), kIRadioButtonsControl_V_Y + (kIRBC_H*kIRBC_VN)), kIRadioButtonsControl_V, kIRBC_VN, &bitmap));
pGraphics->AttachControl(tPlatformSelectorClickable);
// Grey out overlay over platform names
tBmp = pGraphics->LoadIBitmap(MODERADIOSWITCHGREYOUT_ID, MODERADIOSWITCHGREYOUT_FN, 1);
tPlatformSelectorClickableGreyOut = new IBitmapControl(
this,
kModeRadioSwitchGreyOut_X,
kModeRadioSwitchGreyOut_Y,
&tBmp
);
pGraphics->AttachControl(tPlatformSelectorClickableGreyOut);
tPlatformSelectorClickableGreyOut->Hide(true);
// Text LUFS meter
static IText tDefaultLoudnessLabel = IText(PLUG_METER_TEXT_LABEL_STRING_SIZE);
tDefaultLoudnessLabel.mColor = PLUG_METER_TEXT_LABEL_COLOR;
tDefaultLoudnessLabel.mSize = PLUG_METER_TEXT_LABEL_FONT_SIZE;
tDefaultLoudnessLabel.mAlign = tDefaultLoudnessLabel.PLUG_METER_TEXT_ALIGNMENT;
tLoudnessTextControl = new ITextControl(
this,
IRECT(
kILoudnessTextControl_X,
kILoudnessTextControl_Y,
(kILoudnessTextControl_X + kILoudnessTextControl_W),
(kILoudnessTextControl_Y + kILoudnessTextControl_H)
),
&tDefaultLoudnessLabel,
"-");
pGraphics->AttachControl(tLoudnessTextControl);
// Text GR meter
static IText tGrLabel = IText(PLUG_METER_TEXT_LABEL_STRING_SIZE);
tGrLabel.mColor = PLUG_METER_TEXT_LABEL_COLOR;
tGrLabel.mSize = PLUG_METER_TEXT_LABEL_FONT_SIZE;
tGrLabel.mAlign = tGrLabel.PLUG_METER_TEXT_ALIGNMENT;
tGrTextControl = new ITextControl(
this,
IRECT(
kIGrTextControl_X,
kIGrTextControl_Y,
(kIGrTextControl_X + kIGrTextControl_W),
(kIGrTextControl_Y + kIGrTextControl_H)
),
&tGrLabel,
"-");
pGraphics->AttachControl(tGrTextControl);
// Text Peaking knob guide
static IText tPeakingLabel = IText(PLUG_KNOB_TEXT_LABEL_STRING_SIZE);
tPeakingLabel.mColor = PLUG_KNOB_TEXT_LABEL_COLOR;
tPeakingLabel.mSize = PLUG_KNOB_TEXT_LABEL_FONT_SIZE;
tPeakingLabel.mAlign = tPeakingLabel.kAlignCenter;
tPeakingTextControl = new ITextControl(
this,
IRECT(
kIPeakingTextControl_X,
kIPeakingTextControl_Y,
(kIPeakingTextControl_X + kIPeakingTextControl_W),
(kIPeakingTextControl_Y + kIPeakingTextControl_H)
),
&tPeakingLabel,
"-");
pGraphics->AttachControl(tPeakingTextControl);
tPeakingTextControl->Hide(true);
// Text Adjust knob guide
static IText tAdjustLabel = IText(PLUG_KNOB_TEXT_LABEL_STRING_SIZE);
tAdjustLabel.mColor = PLUG_KNOB_TEXT_LABEL_COLOR;
tAdjustLabel.mSize = PLUG_KNOB_TEXT_LABEL_FONT_SIZE;
tAdjustLabel.mAlign = tPeakingLabel.kAlignCenter;
tAdjustTextControl = new ITextControl(
this,
IRECT(
kAdjustTextControlX,
kAdjustTextControlY,
(kAdjustTextControlX + kAdjustTextControlW),
(kAdjustTextControlY + kAdjustTextControlH)
),
&tAdjustLabel,
"-");
pGraphics->AttachControl(tAdjustTextControl);
tAdjustTextControl->Hide(true);
// Text for the mastering mode
static IText tModeLabel = IText(PLUG_MODE_TEXT_LABEL_STRING_SIZE);
tModeLabel.mColor = PLUG_GUIDE_TEXT_LABEL_COLOR;
tModeLabel.mSize = PLUG_GUIDE_TEXT_LABEL_FONT_SIZE;
tModeLabel.mAlign = tModeLabel.PLUG_GUIDE_TEXT_ALIGNMENT;
tModeTextControl = new ITextControl(
this,
IRECT(
kIModeTextControl_X,
kIModeTextControl_Y,
(kIModeTextControl_X + kIModeTextControl_W),
(kIModeTextControl_Y + kIModeTextControl_H)
),
&tModeLabel,
"-");
pGraphics->AttachControl(tModeTextControl);
// Text label with current version of the plug
// TODO: Make it clickable so it leads to a website or something
static IText tTextVersion = IText(PLUG_VERSION_TEXT_LABEL_STRING_SIZE);
char sDisplayedVersion[PLUG_VERSION_TEXT_LABEL_STRING_SIZE];
const IColor tTextVersionColor(
255,
kTextVersion_ColorMono,
kTextVersion_ColorMono,
kTextVersion_ColorMono
);
const IRECT tTextVersionRect(
kTextVersion_X,
kTextVersion_Y,
(kTextVersion_X + kTextVersion_W),
(kTextVersion_Y + kTextVersion_H)
);
#ifdef _PLUG_VERSION_H
sprintf(
sDisplayedVersion,
PLUG_VERSTION_TEXT,
VST3_VER_STR,
(char*)sPlugVersionGitHead,
(char*)sPlugVersionDate
);
#else
sprintf(
sDisplayedVersion,
PLUG_VERSTION_TEXT,
VST3_VER_STR
);
#endif
tTextVersion.mColor = tTextVersionColor;
tTextVersion.mSize = PLUG_VERSION_TEXT_LABEL_FONT_SIZE;
tTextVersion.mAlign = tTextVersion.kAlignNear;
pGraphics->AttachControl(
new ITextControl(
this,
tTextVersionRect,
&tTextVersion,
(const char*)&sDisplayedVersion
)
);
// Clickable area leading to a website
tWebsiteLink = new IURLControl(this, tWebsiteLinkIRect, PLUG_WEBSITE_LINK);
pGraphics->AttachControl(tWebsiteLink);
// Guide message
sModeString = new char[PLUG_MODE_TEXT_LABEL_STRING_SIZE];
sprintf(sModeString, PLUG_OFF_STARTUP_MESSAGE);
tModeTextControl->SetTextFromPlug(sModeString);
// Bugreport link
static IText tBugreportLabel = IText(DLPG_BUGREPORT_LABEL_STRING_SIZE);
tBugreportLabel.mColor = tBugreportLabelColor;
tBugreportLabel.mSize = DLPG_BUGREPORT_LABEL_FONT_SIZE;
tBugreportLabel.mAlign = tBugreportLabel.kAlignNear;
pGraphics->AttachControl(
new ITextControl(
this,
tBugreportLabelIrect,
&tBugreportLabel,
DLPG_BUGREPORT_LABEL_TEXT
)
);
// Clickable area for bugreports
MakeFeedbackUrl(sFeedbackUrl);
tFeedbackLink = new IURLControl(this, tFeedbackLinkIRect, sFeedbackUrl);
pGraphics->AttachControl(tFeedbackLink);
// Finally - feed all the controls to IPlug's graphics gizmo
AttachGraphics(pGraphics);
// *** Initing actual GUI controls - end
// *** Stuff for signal processing
//Limiter
tLimiter = new chunkware_simple::SimpleLimit();
/* Limiter's threshold is always PLUG_LIMITER_DEFAULT_THRESHOLD_DB,
which is 0dB by default. The actual threshold is controlled by pre-
and post-limiter gain. */
tLimiter->setThresh(PLUG_LIMITER_DEFAULT_THRESHOLD_DB);
tLimiter->setAttack(PLUG_LIMITER_ATTACK_MILLISECONDS);
tLimiter->initRuntime();
// LUFS loudness meter
tLoudnessMeter = new Plug::LoudnessMeter();
tLoudnessMeter->SetNumberOfChannels(PLUG_DEFAULT_CHANNEL_NUMBER);
/*
Value inits
Since we have to consider not only the case when user adds the plugin
for the first time, but also the case when user recalls previously saved
session, we have to be careful with which walues we should reset excplicitly,
and which ones we should leave to host (DAW) to initiate.
Recallable parameters:
fTargetLoudness - updated in UpdatePlatform()
nCurrentTargetIndex - dealt with below
fMasteringGainDb - updated in UpdatePreMastering() called from UpdatePlatform()
fTargetLufsIntegratedDb - updated in UpdatePreMastering() called from UpdatePlatform()
fSourceLufsIntegratedDb - dealt with in OnParamChange()
fLimiterCeilingDb - updated in UpdatePreMastering() called from UpdatePlatform()
fLimiterCeilingLinear - updated in UpdatePreMastering() called from UpdatePlatform()
fMasteringGainLinear - updated in UpdatePreMastering() called from UpdatePlatform()
tPlugCurrentMode - dealt with below
bLufsTooLow - dealt with below
bIsBypassed - dealt with below
*/
// Bypass switch state
bIsBypassed = (bool)GetParam(kBypassSwitch)->Bool();
// GR meter values - non-recallable
fMaxGainReductionPerFrame = PLUG_MAX_GAIN_REDUCTION_PER_FRAME_DB_RESET;
fMaxGainReductionPerSessionDb = PLUG_MAX_GAIN_REDUCTION_PER_SESSION_DB_RESET;
// Off, Learn or Master
tPlugCurrentMode = PLUG_CONVERT_SWITCH_VALUE_TO_PLUG_MODE(kModeSwitch);
/* Source LUFS
If the mode on startup is "master", i.e. not the default one, that means that
the plugin is being recalled from a previously saved project. In that case we
get the value from UnserializeState() where it should be stored with regular
control values. Otherwise we initialize with some default value.
*/
bNeedToRecallSourceLufs = (tPlugCurrentMode == PLUG_MASTER_MODE);
if (tPlugCurrentMode == PLUG_INITIAL_MODE)
fSourceLufsIntegratedDb = PLUG_SOURCE_LUFS_INTEGRATED_DB_RESET;
// Target platform
nCurrentTargetIndex = (unsigned short)GetParam(kPlatformSwitch)->Int();
// Target loudness user adjustement
fAdjustLufsDb = PLUG_KNOB_ADJUST_ROUND(GetParam(kAdjust)->Value());
// ###
/* Low (-inf) LUFS flag. Doesn't allow user to go into mastering mode
unless plugin successfully got source LUFS reading first. */
bLufsTooLow = !((fSourceLufsIntegratedDb > PLUG_LUFS_TOO_LOW) || PLUG_ALWAYS_ALLOW_MASTERING);
/* Calling UpdatePlatform() updates:
fTargetLoudness
fTargetLufsIntegratedDb
fLimiterCeilingDb
fLimiterCeilingLinear
fMasteringGainDb
fMasteringGainLinear
*/
/*
if(tPlugCurrentMode == PLUG_MASTER_MODE)
UpdatePlatform((PLUG_Target)nCurrentTargetIndex);
*/
// Set up TP buffer for PSR calculation
tPeakingBuffer = new DLPG::PeakingBuffer(0, PLUG_DB_VALUE_TOO_LOW);
tPeakingBuffer->Resize(
PLUG_DR_METER_WINDOW_SECONDS,
GetSampleRate(),
GetBlockSize()
);
// Knob gearing
tPeakingKnob->SetGearing(PLUG_PEAKING_KNOB_GEARING);
tPlatformSelector->SetGearing(PLUG_PLATFORM_SELECTOR_GEARING);
tAdjustKnob->SetGearing(PLUG_ADJUST_KNOB_GEARING);
// *** General plugin shenanigans
// Presets displayed in the plugin's hosts
// We have only one preset
MakeDefaultPreset((char *)PLUG_DEFAULT_PRESET_NAME, kNumPrograms);
// *** Interface stuff
// Set initial values to controls that can't be handled
// in the "GetParam()->Init...() section of this constructor"
UpdateAvailableControls();
// Tell DSP related objects what the current sample rate is
UpdateSampleRate();
}
StreamMaster::~StreamMaster() {}
/*
\brief DSP thread. All signall processing happens here. Also the GUI values are updated fron this thread.
*/
void StreamMaster::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
// Mutex is already locked for us.
// Assuming we're working with a stereo signal
double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];
double *afInterleavedSamples;
if(bIsBypassed){
// True bypass
std::memcpy(out1, in1, sizeof(double) * nFrames);
std::memcpy(out2, in2, sizeof(double) * nFrames);
}
else{
// If plugin is active
switch(tPlugCurrentMode){
case PLUG_LEARN_MODE:
// Learn mode
// Feed in the audio into the LUFS meter, but not changing it
afInterleavedSamples = new double[nFrames * 2];
for (int frame = 0, sample = 0; frame < nFrames; ++frame, ++in1, ++in2, ++out1, ++out2, sample += 2)
{
*out1 = *in1;
*out2 = *in2;
afInterleavedSamples[sample] = *in1;
afInterleavedSamples[sample+1] = *in2;
}
tLoudnessMeter->AddSamples(afInterleavedSamples, nFrames);
delete[] afInterleavedSamples;
break;
case PLUG_MASTER_MODE:
// Master mode
// Process the audio, then feed it to the meter
// Make sure unprocessed audio's loudness is stored in fSourceLufsIntegratedDb once
// after switching the mode and not changed until the mode in changed to "off"!
afInterleavedSamples = new double[nFrames * 2];
for (int frame = 0, sample = 0; frame < nFrames; ++frame, ++in1, ++in2, ++out1, ++out2, sample += 2)
{
// Apply gain to the samples
*out1 = fMasteringGainLinear * *in1;
*out2 = fMasteringGainLinear * *in2;
// Feed them to the limiter and read GR value
tLimiter->process(*out1, *out2);
tLimiter->getGr(&fMaxGainReductionPerFrame);
// Applying ceiling value (post-limiter gain)
*out1 *= fLimiterCeilingLinear;
*out2 *= fLimiterCeilingLinear;
// Collect samples for loudness measurement, post-limiter
afInterleavedSamples[sample] = *out1;
afInterleavedSamples[sample+1] = *out2;
}
tLoudnessMeter->AddSamples(afInterleavedSamples, nFrames);
delete[] afInterleavedSamples;
break;
case PLUG_OFF_MODE:
// Off mode
// Do nothing to the audio
std::memcpy(out1, in1, sizeof(double) * nFrames);
std::memcpy(out2, in2, sizeof(double) * nFrames);
break;
} //switch
} // if(bIsBypassed)
// GUI also updates in this thread. So make sure it's simple.
UpdateGui();
}
void StreamMaster::Reset()
{
TRACE;
IMutexLock lock(this);
UpdateSampleRate();
}
/*
Quick maths:
MasteringGainDb = (TargetLufsIntegratedDb + AdjustLufsDb) - SourceLufsIntegratedDb - LimiterCeilingDb,
Where LimiterCeilingDb is a negative value. Loudness (in dB) is usually negative too, although it can be above zero.
MasteringGainLinear = LOG_TO_LINEAR(MasteringGainDb)
SignalOutLinear = MasteringGainLinear * SignalInLinear, pre-limiter!
then feed it into the limiter.
Done!
*/
/*