-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginEditor.cpp
More file actions
2297 lines (1959 loc) · 84 KB
/
Copy pathPluginEditor.cpp
File metadata and controls
2297 lines (1959 loc) · 84 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
#include "PluginEditor.h"
#include "PluginProcessor.h"
#include <thread>
namespace {
constexpr int sliderTextBoxWidth = 52;
constexpr int sliderTextBoxHeight = 20;
constexpr int unitLabelGap = 6;
constexpr int unitLabelWidth = 34;
constexpr int titleAreaHeight = 54;
constexpr float titleAreaHorizontalPadding = 4.0f;
const juce::StringArray &getAvailableTypefaceNames() {
static const juce::StringArray names = juce::Font::findAllTypefaceNames();
return names;
}
bool hasTypeface(const juce::String &name) {
for (const auto &availableName : getAvailableTypefaceNames())
if (availableName.equalsIgnoreCase(name))
return true;
return false;
}
juce::String chooseTypeface(std::initializer_list<const char *> candidates) {
for (const auto *candidate : candidates)
if (hasTypeface(candidate))
return candidate;
return {};
}
juce::Font makePlatformFont(const juce::String &primaryName,
std::initializer_list<const char *> fallbacks,
float height, int styleFlags = juce::Font::plain) {
juce::Font font(primaryName.isNotEmpty()
? juce::FontOptions(primaryName, height, styleFlags)
: juce::FontOptions(height, styleFlags));
juce::StringArray fallbackNames;
for (const auto *fallback : fallbacks)
if (hasTypeface(fallback) && !fallbackNames.contains(fallback))
fallbackNames.add(fallback);
if (fallbackNames.size() > 0)
font.setPreferredFallbackFamilies(fallbackNames);
return font;
}
juce::Font makeEnglishUIFont(float height, int styleFlags = juce::Font::plain) {
return makePlatformFont("Helvetica Neue",
{"Arial", "Segoe UI", "Liberation Sans"}, height,
styleFlags);
}
juce::String chooseJapaneseUIFontFamily() {
#if JUCE_MAC
return chooseTypeface(
{"Hiragino Sans", "Hiragino Kaku Gothic ProN", "Helvetica Neue"});
#elif JUCE_WINDOWS
return chooseTypeface(
{"Meiryo UI", "Meiryo", "Yu Gothic UI", "Yu Gothic", "Segoe UI"});
#else
return chooseTypeface({"Noto Sans CJK JP", "Noto Sans JP", "Noto Sans",
"DejaVu Sans", "Liberation Sans"});
#endif
}
juce::Font makeMultilingualSansFont(float height,
int styleFlags = juce::Font::plain) {
const bool bold = (styleFlags & juce::Font::bold) != 0;
#if JUCE_MAC
const auto primary =
chooseTypeface({bold ? "Hiragino Sans W7" : "Hiragino Sans W5",
"Hiragino Sans", "Helvetica Neue"});
return makePlatformFont(primary, {"Hiragino Sans", "Helvetica Neue", "Arial"},
height, styleFlags);
#elif JUCE_WINDOWS
const auto primary = chooseTypeface(
{"Meiryo UI", "Meiryo", bold ? "Yu Gothic UI Semibold" : "Yu Gothic UI",
"Yu Gothic", "Segoe UI"});
return makePlatformFont(primary,
{"Meiryo UI", "Meiryo", "Yu Gothic UI", "Yu Gothic",
"Segoe UI", "Arial Unicode MS", "Arial"},
height, styleFlags);
#else
const auto primary = chooseTypeface(
{bold ? "Noto Sans CJK JP Bold" : "Noto Sans CJK JP Medium",
"Noto Sans CJK JP", "Noto Sans JP", "Noto Sans", "DejaVu Sans"});
return makePlatformFont(primary,
{"Noto Sans CJK JP", "Noto Sans JP", "Noto Sans",
"DejaVu Sans", "Liberation Sans"},
height, styleFlags);
#endif
}
juce::Font makeJapaneseTitleFont(float height) {
#if JUCE_MAC
return makeMultilingualSansFont(height, juce::Font::bold);
#elif JUCE_WINDOWS
const auto primary =
chooseTypeface({"Yu Gothic UI Semibold", "Yu Gothic UI Bold", "Meiryo UI",
"Meiryo", "Segoe UI"});
return makePlatformFont(primary,
{"Yu Gothic UI Semibold", "Yu Gothic UI", "Meiryo UI",
"Meiryo", "Segoe UI", "Arial Unicode MS"},
height, juce::Font::plain);
#else
const auto primary =
chooseTypeface({"Noto Sans CJK JP Bold", "Noto Sans JP Bold",
"Noto Sans CJK JP", "Noto Sans JP", "Noto Sans"});
return makePlatformFont(primary,
{"Noto Sans CJK JP Bold", "Noto Sans JP Bold",
"Noto Sans CJK JP", "Noto Sans JP", "Noto Sans",
"DejaVu Sans", "Liberation Sans"},
height, juce::Font::plain);
#endif
}
juce::Font makeHelveticaFont(float height, int styleFlags = juce::Font::plain) {
return makeEnglishUIFont(height, styleFlags);
}
bool isJapaneseLanguageCode(const juce::String &languageCode) {
return VocalWidenerProcessor::normaliseLanguageCode(languageCode) == "ja";
}
float measureTextWidth(const juce::Font &font, const juce::String &text) {
return juce::GlyphArrangement::getStringWidth(font, text);
}
double clampDisplayedZero(double value, double threshold) {
return std::abs(value) < threshold ? 0.0 : value;
}
double parseNumericValue(const juce::String &text) {
return text.retainCharacters("+-0123456789.").getDoubleValue();
}
juce::String formatOffsetMs(double value) {
return juce::String(clampDisplayedZero(value, 0.005), 2);
}
juce::String formatPitchCents(double value) {
return juce::String(clampDisplayedZero(value, 0.005), 2);
}
juce::String formatPanAmount(double value) {
return juce::String(juce::roundToInt(clampDisplayedZero(value, 0.5)));
}
juce::String formatHaasPercent(double value) {
return juce::String(juce::roundToInt(clampDisplayedZero(value, 0.5)));
}
juce::String formatOutputDb(double value) {
return juce::String(clampDisplayedZero(value, 0.05), 1);
}
float readoutFontHeightForLanguage(const juce::String &languageCode) {
return isJapaneseLanguageCode(languageCode) ? 12.8f : 12.2f;
}
double smoothStep(double t) {
t = juce::jlimit(0.0, 1.0, t);
return t * t * (3.0 - 2.0 * t);
}
double mapSegment(double value, double start, double end, double outStart,
double outEnd, double (*easing)(double)) {
if (end <= start)
return outEnd;
const double t = juce::jlimit(0.0, 1.0, (value - start) / (end - start));
return juce::jmap(easing(t), outStart, outEnd);
}
juce::String normaliseVersionTag(juce::String version) {
auto normalised = version.trim().toLowerCase();
if (normalised.isEmpty())
return {};
if (!normalised.startsWithChar('v'))
normalised = "v" + normalised;
return normalised;
}
struct SemVer {
int major = 0, minor = 0, patch = 0;
juce::String prerelease;
bool valid = false;
};
SemVer parseSemVer(const juce::String &tag) {
auto stripped = tag.trimCharactersAtStart("vV");
auto plusIndex = stripped.indexOfChar('+');
if (plusIndex >= 0)
stripped = stripped.substring(0, plusIndex);
auto dashIndex = stripped.indexOfChar('-');
juce::String prerelease;
if (dashIndex >= 0) {
prerelease = stripped.substring(dashIndex + 1).trim();
stripped = stripped.substring(0, dashIndex);
}
auto parts = juce::StringArray::fromTokens(stripped, ".", "");
if (parts.size() < 2)
return {};
SemVer v;
v.major = parts[0].getIntValue();
v.minor = parts[1].getIntValue();
v.patch = parts.size() >= 3 ? parts[2].getIntValue() : 0;
v.prerelease = prerelease;
v.valid = true;
return v;
}
bool isNumericIdentifier(const juce::String &identifier) {
if (identifier.isEmpty())
return false;
for (auto c : identifier)
if (!juce::CharacterFunctions::isDigit(c))
return false;
return true;
}
int comparePrereleaseIdentifiers(const juce::String &lhs,
const juce::String &rhs) {
const bool lhsNumeric = isNumericIdentifier(lhs);
const bool rhsNumeric = isNumericIdentifier(rhs);
if (lhsNumeric && rhsNumeric) {
const auto lhsValue = lhs.getLargeIntValue();
const auto rhsValue = rhs.getLargeIntValue();
if (lhsValue < rhsValue)
return -1;
if (lhsValue > rhsValue)
return 1;
return 0;
}
if (lhsNumeric != rhsNumeric)
return lhsNumeric ? -1 : 1;
const auto comparison = lhs.compareNatural(rhs);
if (comparison < 0)
return -1;
if (comparison > 0)
return 1;
return 0;
}
int comparePrerelease(const juce::String &lhs, const juce::String &rhs) {
if (lhs.isEmpty() && rhs.isEmpty())
return 0;
if (lhs.isEmpty())
return 1;
if (rhs.isEmpty())
return -1;
auto lhsParts = juce::StringArray::fromTokens(lhs, ".", "");
auto rhsParts = juce::StringArray::fromTokens(rhs, ".", "");
const int count = juce::jmax(lhsParts.size(), rhsParts.size());
for (int i = 0; i < count; ++i) {
if (i >= lhsParts.size())
return -1;
if (i >= rhsParts.size())
return 1;
const int comparison =
comparePrereleaseIdentifiers(lhsParts[i], rhsParts[i]);
if (comparison != 0)
return comparison;
}
return 0;
}
int compareSemVer(const SemVer &lhs, const SemVer &rhs) {
if (lhs.major != rhs.major)
return lhs.major < rhs.major ? -1 : 1;
if (lhs.minor != rhs.minor)
return lhs.minor < rhs.minor ? -1 : 1;
if (lhs.patch != rhs.patch)
return lhs.patch < rhs.patch ? -1 : 1;
return comparePrerelease(lhs.prerelease, rhs.prerelease);
}
bool isUpdateAvailable(const juce::String ¤tVersion,
const juce::String &latestVersion) {
const auto currentTag = normaliseVersionTag(currentVersion);
const auto latestTag = normaliseVersionTag(latestVersion);
if (latestTag.isEmpty())
return false;
auto current = parseSemVer(currentTag);
auto latest = parseSemVer(latestTag);
if (!current.valid || !latest.valid)
return latestTag != currentTag;
return compareSemVer(current, latest) < 0;
}
enum class UILanguage { english, japanese };
struct LocalizedStrings {
juce::String titleLeadingWord;
juce::String titleTrailingWord;
juce::String titleBypassTrailingWord;
juce::String settingsTitle;
bool allowTitleAllCaps = true;
juce::String offsetTime;
juce::String leftPan;
juce::String rightPan;
juce::String pitchShift;
juce::String haasComp;
juce::String outputGain;
juce::String equalDelay;
juce::String linkPan;
juce::String flipPan;
juce::String bypass;
juce::String advanced;
juce::String tooltipOffset;
juce::String tooltipLeftPan;
juce::String tooltipRightPan;
juce::String tooltipPitchShift;
juce::String tooltipHaasAmount;
juce::String tooltipOutputGain;
juce::String tooltipEqualDelay;
juce::String tooltipLinkPan;
juce::String tooltipFlipPan;
juce::String tooltipHaasToggle;
juce::String tooltipBypass;
juce::String tooltipSettings;
juce::String tooltipCloseSettings;
juce::String resetDefaults;
juce::String tooltipResetDefaults;
juce::String language;
juce::String checkForUpdates;
juce::String currentVersionPrefix;
juce::String checking;
juce::String updateAvailablePrefix;
juce::String upToDate;
juce::String updateCheckFailed;
juce::String disclaimerLine1;
juce::String disclaimerLine2;
juce::String releasesLink;
juce::String leftChannel;
juce::String rightChannel;
juce::String delay;
juce::String pitch;
juce::String reportedLatencyPrefix;
juce::String haasPrecedencePrefix;
juce::String statusOff;
juce::String statusNone;
juce::String statusLeft;
juce::String statusRight;
juce::String statusAmbiguous;
juce::String leftGain;
juce::String rightGain;
juce::String stereoWarning;
};
UILanguage languageFromCode(const juce::String &languageCode) {
return VocalWidenerProcessor::normaliseLanguageCode(languageCode) == "ja"
? UILanguage::japanese
: UILanguage::english;
}
juce::String languageCodeFor(UILanguage language) {
return language == UILanguage::japanese ? "ja" : "en";
}
int comboIdForLanguage(UILanguage language) {
return language == UILanguage::japanese ? 2 : 1;
}
UILanguage languageForComboId(int comboId) {
return comboId == 2 ? UILanguage::japanese : UILanguage::english;
}
const LocalizedStrings &getStrings(UILanguage language) {
static const LocalizedStrings english{
"topaz",
"pan",
"unpan",
"settings",
true,
"offset time",
"left pan",
"right pan",
"adt drift",
"haas comp",
"output gain",
"equal delay",
"link pan",
"flip pan",
"bypass",
"advanced",
"sets the delay between the left and right channels",
"sets how far left the left voice sits",
"sets how far right the right voice sits",
"adds ADT-style drift and decorrelation between channels. Experimental "
"feature. Adds slight compensated latency.",
"controls how strongly the plugin compensates for the perceived level "
"imbalance caused by channel delay. Experimental feature.",
"controls the final output volume",
"may or may not improve the perceived timing of vocals. Experimental "
"feature. Adds slight compensated latency.",
"locks both pan amounts together",
"swaps the left and right pan destinations",
"turns Haas compensation on or off. Experimental feature.",
"bypasses the entire plugin",
"settings",
"close settings",
"reset defaults",
"resets all parameters to their original values",
"language",
"check for updates",
"current: ",
"checking...",
"update available: ",
"up to date",
"update check failed",
"update checks may be incomplete or inaccurate",
"verify the latest version on the link below:",
"github releases",
"left voice",
"right voice",
"delay",
"drift",
"latency: ",
"haas precedence: ",
"off",
"none",
"left voice",
"right voice",
"ambiguous",
"left voice gain",
"right voice gain",
"Warning: Plugin requires mono or stereo input with stereo output."};
static const LocalizedStrings japanese{
juce::String::fromUTF8("とぱず"),
juce::String::fromUTF8("パン"),
juce::String::fromUTF8("パン"),
juce::String::fromUTF8("設定"),
false,
juce::String::fromUTF8("オフセット"),
juce::String::fromUTF8("左パン"),
juce::String::fromUTF8("右パン"),
juce::String::fromUTF8("ADTドリフト"),
juce::String::fromUTF8("ハース補正"),
juce::String::fromUTF8("出力ゲイン"),
juce::String::fromUTF8("ディレイ補正"),
juce::String::fromUTF8("パンリンク"),
juce::String::fromUTF8("パン反転"),
juce::String::fromUTF8("バイパス"),
juce::String::fromUTF8("エキスパート"),
juce::String::fromUTF8("左右のチャンネルに付ける時間差を調整します"),
juce::String::fromUTF8("左側の音をどれだけ左に配置するかを調整します"),
juce::String::fromUTF8("右側の音をどれだけ右に配置するかを調整します"),
juce::String::fromUTF8("左右チャンネルに微小なピッチの揺れとタイミングの"
"ズレを加えます。実験的機能です。レイテンシーが発"
"生しますが、ホスト側で自動補正されます。"),
juce::String::fromUTF8("時間差で片側が大きく聞こえる印象を、どれだけ補正"
"するかを調整します。実験的機能です。"),
juce::String::fromUTF8("最終的な出力レベルを調整します"),
juce::String::fromUTF8(
"ボーカルのタイミング感が改善して聞こえる場合があります。実験的機能で"
"す。レイテンシーが発生しますが、ホスト側で自動補正されます。"),
juce::String::fromUTF8("左右のパン量を連動させます"),
juce::String::fromUTF8("左右の配置を入れ替えます"),
juce::String::fromUTF8(
"ハース補正のオン / オフを切り替えます。実験的機能です。"),
juce::String::fromUTF8("プラグイン全体をバイパスします"),
juce::String::fromUTF8("設定"),
juce::String::fromUTF8("設定を閉じる"),
juce::String::fromUTF8("デフォルトに戻す"),
juce::String::fromUTF8("すべてのパラメータを初期値に戻します"),
juce::String::fromUTF8("言語"),
juce::String::fromUTF8("アップデートを確認"),
juce::String::fromUTF8("現在のバージョン: "),
juce::String::fromUTF8("確認中..."),
juce::String::fromUTF8("更新があります: "),
juce::String::fromUTF8("最新版です"),
juce::String::fromUTF8("アップデートを確認できませんでした"),
juce::String::fromUTF8(
"更新確認の結果が不完全または不正確な場合があります"),
juce::String::fromUTF8("必ず下のリンクから最新版も確認してください"),
"GitHub Releases",
juce::String::fromUTF8("左ボイス"),
juce::String::fromUTF8("右ボイス"),
juce::String::fromUTF8("ディレイ"),
juce::String::fromUTF8("ドリフト"),
juce::String::fromUTF8("レイテンシ: "),
juce::String::fromUTF8("ハース先行: "),
juce::String::fromUTF8("オフ"),
juce::String::fromUTF8("なし"),
juce::String::fromUTF8("左ボイス"),
juce::String::fromUTF8("右ボイス"),
juce::String::fromUTF8("不明"),
juce::String::fromUTF8("左ボイスゲイン"),
juce::String::fromUTF8("右ボイスゲイン"),
juce::String::fromUTF8("警告: "
"このプラグインはモノラルまたはステレオ入力、ステ"
"レオ出力で使用してください。")};
return language == UILanguage::japanese ? japanese : english;
}
const LocalizedStrings &getStringsForCode(const juce::String &languageCode) {
return getStrings(languageFromCode(languageCode));
}
juce::Path createSettingsGearPath() {
juce::Path path;
path.setUsingNonZeroWinding(false);
const auto centre = juce::Point<float>(50.0f, 50.0f);
const auto spoke = juce::Rectangle<float>(46.0f, 6.0f, 8.0f, 18.0f);
for (int i = 0; i < 8; ++i) {
path.addRoundedRectangle(
spoke.transformedBy(juce::AffineTransform::rotation(
juce::MathConstants<float>::twoPi * (static_cast<float>(i) / 8.0f),
centre.x, centre.y)),
2.0f);
}
path.addEllipse(20.0f, 20.0f, 60.0f, 60.0f);
path.addEllipse(37.0f, 37.0f, 26.0f, 26.0f);
return path;
}
struct UpdateCheckResult {
enum class Status { upToDate, updateAvailable, failed };
Status status = Status::failed;
juce::String latestTag;
};
UpdateCheckResult fetchLatestRelease() {
UpdateCheckResult result;
int statusCode = 0;
const auto currentVersion =
parseSemVer(normaliseVersionTag(VocalWidenerProcessor::getVersionTag()));
const bool includePrereleases =
currentVersion.valid && currentVersion.prerelease.isNotEmpty();
auto options =
juce::URL::InputStreamOptions(juce::URL::ParameterHandling::inAddress)
.withHttpRequestCmd("GET")
.withExtraHeaders("User-Agent: topaz-pan\r\n"
"Accept: application/vnd.github+json\r\n")
.withConnectionTimeoutMs(5000)
.withNumRedirectsToFollow(4)
.withStatusCode(&statusCode);
auto stream =
VocalWidenerProcessor::getReleasesApiUrl().createInputStream(options);
if (stream == nullptr)
return result;
if (statusCode >= 400)
return result;
const auto responseText = stream->readEntireStreamAsString();
const auto parsed = juce::JSON::parse(responseText);
auto *releases = parsed.getArray();
if (releases == nullptr)
return result;
juce::String latestTag;
SemVer latestVersion;
for (const auto &entry : *releases) {
auto *object = entry.getDynamicObject();
if (object == nullptr)
continue;
if (static_cast<bool>(object->getProperty("draft")))
continue;
const bool prerelease =
static_cast<bool>(object->getProperty("prerelease"));
if (prerelease && !includePrereleases)
continue;
const auto candidateTag =
normaliseVersionTag(object->getProperty("tag_name").toString());
if (candidateTag.isEmpty())
continue;
const auto candidateVersion = parseSemVer(candidateTag);
if (!candidateVersion.valid)
continue;
if (latestTag.isEmpty() || compareSemVer(latestVersion, candidateVersion) < 0) {
latestTag = candidateTag;
latestVersion = candidateVersion;
}
}
if (latestTag.isEmpty())
return result;
result.latestTag = latestTag;
result.status =
isUpdateAvailable(VocalWidenerProcessor::getVersionTag(), latestTag)
? UpdateCheckResult::Status::updateAvailable
: UpdateCheckResult::Status::upToDate;
return result;
}
class SettingsTitleComponent : public juce::Component {
public:
void setLanguageCode(const juce::String &newLanguageCode) {
languageCode =
VocalWidenerProcessor::normaliseLanguageCode(newLanguageCode);
repaint();
}
void setText(const juce::String &newText) {
if (titleText == newText)
return;
titleText = newText;
repaint();
}
void paint(juce::Graphics &g) override {
const auto bounds = getLocalBounds().toFloat();
auto font = isJapaneseLanguageCode(languageCode)
? makeJapaneseTitleFont(32.0f)
: makeHelveticaFont(32.0f, juce::Font::bold);
const float baselineY =
bounds.getCentreY() - (font.getHeight() * 0.5f) + font.getAscent();
g.setColour(juce::Colours::white);
g.setFont(font);
float cursorX = bounds.getX() + titleAreaHorizontalPadding;
for (int i = 0; i < titleText.length(); ++i) {
const juce::String glyph = juce::String::charToString(titleText[i]);
const float glyphWidth = measureTextWidth(font, glyph);
g.drawText(glyph,
juce::Rectangle<float>(cursorX, baselineY - font.getAscent(),
glyphWidth + 4.0f, font.getHeight()),
juce::Justification::centredLeft, false);
cursorX += glyphWidth;
}
}
private:
juce::String languageCode{"en"};
juce::String titleText{"settings"};
};
class SettingsOverlay : public juce::Component {
public:
SettingsOverlay(CustomLookAndFeel &lookAndFeelRef,
const juce::String &initialLanguageCode,
std::function<void(const juce::String &)> onLanguageChangedIn,
std::function<void()> onCloseIn)
: lookAndFeel(lookAndFeelRef),
onLanguageChanged(std::move(onLanguageChangedIn)),
onClose(std::move(onCloseIn)) {
setLookAndFeel(&lookAndFeel);
setInterceptsMouseClicks(true, true);
setOpaque(true);
addAndMakeVisible(titleGraphic);
addAndMakeVisible(closeButton);
closeButton.setButtonText("X");
closeButton.onClick = [this] {
if (onClose)
onClose();
};
closeButton.getProperties().set("settingsClose", true);
closeButton.setColour(juce::TextButton::buttonColourId,
juce::Colours::transparentBlack);
closeButton.setColour(juce::TextButton::buttonOnColourId,
juce::Colours::transparentBlack);
closeButton.setColour(juce::TextButton::textColourOffId,
juce::Colours::white);
closeButton.setTooltip(
getStringsForCode(initialLanguageCode).tooltipCloseSettings);
addAndMakeVisible(languageLabel);
languageLabel.setColour(juce::Label::textColourId, juce::Colours::white);
languageLabel.setJustificationType(juce::Justification::centredLeft);
addAndMakeVisible(languageButton);
languageButton.getProperties().set("settingsCombo", true);
languageButton.onClick = [this] { showLanguageMenu(); };
languageButton.setColour(juce::TextButton::buttonColourId,
juce::Colours::transparentBlack);
languageButton.setColour(juce::TextButton::buttonOnColourId,
juce::Colours::transparentBlack);
languageButton.setColour(juce::TextButton::textColourOffId,
juce::Colours::white);
addAndMakeVisible(checkForUpdatesButton);
checkForUpdatesButton.onClick = [this] { beginUpdateCheck(); };
checkForUpdatesButton.getProperties().set("settingsAction", true);
checkForUpdatesButton.setColour(juce::TextButton::buttonColourId,
juce::Colours::white.withAlpha(0.035f));
checkForUpdatesButton.setColour(juce::TextButton::buttonOnColourId,
juce::Colours::white.withAlpha(0.08f));
checkForUpdatesButton.setColour(juce::TextButton::textColourOffId,
juce::Colours::white);
addAndMakeVisible(updateStatusLabel);
updateStatusLabel.setJustificationType(juce::Justification::centredLeft);
updateStatusLabel.setColour(juce::Label::textColourId,
juce::Colours::white.withAlpha(0.62f));
addAndMakeVisible(disclaimerLabel);
disclaimerLabel.setColour(juce::Label::textColourId,
juce::Colours::white.withAlpha(0.55f));
disclaimerLabel.setJustificationType(juce::Justification::centredLeft);
disclaimerLabel.setFont(makeHelveticaFont(11.0f));
addAndMakeVisible(disclaimerDetailLabel);
disclaimerDetailLabel.setColour(juce::Label::textColourId,
juce::Colours::white.withAlpha(0.55f));
disclaimerDetailLabel.setJustificationType(
juce::Justification::centredLeft);
disclaimerDetailLabel.setFont(makeHelveticaFont(11.0f));
addAndMakeVisible(releasesLinkButton);
releasesLinkButton.getProperties().set("settingsLink", true);
releasesLinkButton.onClick = [] {
VocalWidenerProcessor::getReleasesPageUrl().launchInDefaultBrowser();
};
releasesLinkButton.setColour(juce::TextButton::textColourOffId,
juce::Colours::white.withAlpha(0.78f));
releasesLinkButton.setMouseCursor(juce::MouseCursor::PointingHandCursor);
// Social footer text links
auto setupSocialLink = [this](juce::TextButton &btn,
const juce::String &url) {
btn.getProperties().set("settingsLink", true);
btn.onClick = [url] { juce::URL(url).launchInDefaultBrowser(); };
btn.setMouseCursor(juce::MouseCursor::PointingHandCursor);
btn.setColour(juce::TextButton::textColourOffId,
juce::Colours::white.withAlpha(0.55f));
btn.setColour(juce::TextButton::buttonColourId,
juce::Colours::transparentBlack);
btn.setColour(juce::TextButton::buttonOnColourId,
juce::Colours::transparentBlack);
addAndMakeVisible(btn);
};
setupSocialLink(homepageLinkButton, "https://toopazu.net");
setupSocialLink(xLinkButton, "https://x.com/toopazu");
setupSocialLink(youtubeLinkButton, "https://www.youtube.com/@toopazu");
for (auto *dot : {&socialDot1, &socialDot2}) {
dot->setText(juce::CharPointer_UTF8("\xc2\xb7"),
juce::dontSendNotification);
dot->setColour(juce::Label::textColourId,
juce::Colours::white.withAlpha(0.35f));
dot->setJustificationType(juce::Justification::centred);
dot->setInterceptsMouseClicks(false, false);
dot->setFont(makeHelveticaFont(12.0f));
addAndMakeVisible(*dot);
}
setLanguageCode(initialLanguageCode);
}
~SettingsOverlay() override { setLookAndFeel(nullptr); }
void paint(juce::Graphics &g) override {
g.fillAll(juce::Colour::fromString("#FF7BBED4"));
g.setColour(juce::Colours::white.withAlpha(0.10f));
const float footerRuleY = static_cast<float>(getHeight() - 146);
g.drawLine(30.0f, footerRuleY, static_cast<float>(getWidth() - 30),
footerRuleY, 1.0f);
}
void resized() override {
const int leftMargin = 30;
const int labelW = 100;
const int sliderW = 210;
const int rowH = 34;
const int rightEdge = getWidth() - 30;
titleGraphic.setBounds(leftMargin, 20, getWidth() - 60, titleAreaHeight);
closeButton.setBounds(getWidth() - 58, 27, 32, 32);
int yStart = 108;
languageLabel.setBounds(leftMargin, yStart, labelW, rowH);
languageButton.setBounds(leftMargin + labelW, yStart, sliderW + 52, rowH);
yStart += rowH + 24;
checkForUpdatesButton.setBounds(leftMargin + labelW, yStart, sliderW + 52,
rowH);
yStart += rowH + 16;
updateStatusLabel.setBounds(leftMargin + labelW, yStart, sliderW + 52, 18);
const int footerY = getHeight() - 118;
disclaimerLabel.setBounds(leftMargin, footerY, rightEdge - leftMargin, 16);
disclaimerDetailLabel.setBounds(leftMargin, footerY + 18,
rightEdge - leftMargin, 16);
releasesLinkButton.setBounds(leftMargin, footerY + 38, 140, 20);
// Social links row at bottom — center aligned
const int linksY = getHeight() - 38;
const int linkH = 18;
const int dotW = 10;
auto linkFont = isJapaneseLanguageCode(languageCode)
? makeMultilingualSansFont(10.8f)
: makeHelveticaFont(11.5f);
// First pass: measure total width
auto measureLink = [&](juce::TextButton &btn) -> int {
return static_cast<int>(
std::ceil(measureTextWidth(linkFont, btn.getButtonText()))) +
4;
};
int totalW = measureLink(homepageLinkButton) + dotW +
measureLink(xLinkButton) + dotW +
measureLink(youtubeLinkButton);
int linkX = (getWidth() - totalW) / 2;
// Second pass: place
auto layoutLink = [&](juce::TextButton &btn) {
int w = measureLink(btn);
btn.setBounds(linkX, linksY, w, linkH);
linkX += w;
};
auto layoutDot = [&](juce::Label &dot) {
dot.setBounds(linkX, linksY, dotW, linkH);
linkX += dotW;
};
layoutLink(homepageLinkButton);
layoutDot(socialDot1);
layoutLink(xLinkButton);
layoutDot(socialDot2);
layoutLink(youtubeLinkButton);
}
void mouseUp(const juce::MouseEvent &event) override {
if (!getPanelBounds().contains(event.getPosition())) {
if (onClose)
onClose();
}
}
void setLanguageCode(const juce::String &newLanguageCode) {
languageCode =
VocalWidenerProcessor::normaliseLanguageCode(newLanguageCode);
applyLocalisation();
}
private:
juce::Rectangle<int> getPanelBounds() const { return getLocalBounds(); }
void refreshUpdateStatusText() {
const auto &strings = getStringsForCode(languageCode);
switch (updateStatus) {
case UpdateStatus::currentVersion:
updateStatusLabel.setText(strings.currentVersionPrefix +
VocalWidenerProcessor::getVersionTag(),
juce::dontSendNotification);
break;
case UpdateStatus::checking:
updateStatusLabel.setText(strings.checking, juce::dontSendNotification);
break;
case UpdateStatus::updateAvailable:
updateStatusLabel.setText(strings.updateAvailablePrefix + latestTag,
juce::dontSendNotification);
break;
case UpdateStatus::upToDate:
updateStatusLabel.setText(strings.upToDate, juce::dontSendNotification);
break;
case UpdateStatus::failed:
updateStatusLabel.setText(strings.updateCheckFailed,
juce::dontSendNotification);
break;
}
}
void showLanguageMenu() {
juce::PopupMenu menu;
const auto currentLanguage = languageFromCode(languageCode);
menu.setLookAndFeel(&lookAndFeel);
menu.addItem(comboIdForLanguage(UILanguage::english), "English", true,
currentLanguage == UILanguage::english);
menu.addItem(comboIdForLanguage(UILanguage::japanese),
juce::String::fromUTF8("日本語"), true,
currentLanguage == UILanguage::japanese);
auto options =
juce::PopupMenu::Options()
.withTargetComponent(languageButton)
.withMinimumWidth(languageButton.getWidth())
.withMaximumNumColumns(1)
.withInitiallySelectedItem(comboIdForLanguage(currentLanguage))
.withItemThatMustBeVisible(comboIdForLanguage(currentLanguage))
.withStandardItemHeight(languageButton.getHeight());
juce::Component::SafePointer<SettingsOverlay> safeThis(this);
menu.showMenuAsync(options, [safeThis](int result) {
if (safeThis == nullptr || result == 0)
return;
const auto selectedLanguage = languageForComboId(result);
safeThis->languageCode = languageCodeFor(selectedLanguage);
safeThis->applyLocalisation();
if (safeThis->onLanguageChanged)
safeThis->onLanguageChanged(safeThis->languageCode);
});
}
void applyLocalisation() {
const auto &strings = getStringsForCode(languageCode);
titleGraphic.setText(strings.settingsTitle);
titleGraphic.setLanguageCode(languageCode);
closeButton.setTooltip(strings.tooltipCloseSettings);
languageLabel.setText(strings.language, juce::dontSendNotification);
languageButton.setButtonText(languageFromCode(languageCode) ==
UILanguage::japanese
? juce::String::fromUTF8("日本語")
: "English");
checkForUpdatesButton.setButtonText(strings.checkForUpdates);
disclaimerLabel.setText(strings.disclaimerLine1,
juce::dontSendNotification);
disclaimerDetailLabel.setText(strings.disclaimerLine2,
juce::dontSendNotification);
disclaimerLabel.setFont(isJapaneseLanguageCode(languageCode)
? makeMultilingualSansFont(10.8f)
: makeHelveticaFont(11.0f));
disclaimerDetailLabel.setFont(isJapaneseLanguageCode(languageCode)
? makeMultilingualSansFont(10.8f)
: makeHelveticaFont(11.0f));
releasesLinkButton.setButtonText(strings.releasesLink);
homepageLinkButton.setButtonText(
isJapaneseLanguageCode(languageCode)
? juce::String::fromUTF8("\u30db\u30fc\u30e0\u30da\u30fc\u30b8")
: "Homepage");
xLinkButton.setButtonText(isJapaneseLanguageCode(languageCode)
? juce::String::fromUTF8("X (旧Twitter)")
: "Twitter / X");
youtubeLinkButton.setButtonText("YouTube");
refreshUpdateStatusText();
resized();
repaint();
}
void beginUpdateCheck() {
if (isCheckingForUpdates)
return;
isCheckingForUpdates = true;
checkForUpdatesButton.setEnabled(false);
updateStatus = UpdateStatus::checking;
refreshUpdateStatusText();
juce::Component::SafePointer<SettingsOverlay> safeThis(this);
std::thread([safeThis] {
const auto result = fetchLatestRelease();
juce::MessageManager::callAsync([safeThis, result] {
if (safeThis == nullptr)
return;
safeThis->isCheckingForUpdates = false;
safeThis->checkForUpdatesButton.setEnabled(true);
switch (result.status) {
case UpdateCheckResult::Status::updateAvailable:
safeThis->updateStatus = UpdateStatus::updateAvailable;