-
Notifications
You must be signed in to change notification settings - Fork 873
/
musicutils.js
5973 lines (5558 loc) · 178 KB
/
musicutils.js
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
// Copyright (c) 2016-23 Walter Bender
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
/*
global
_, last, DRUMNAMES, NOISENAMES, VOICENAMES, INVALIDPITCH, CUSTOMSAMPLES
*/
/*
Global Locations
js/utils/utils.js
_, last
js/utils/synthutils.js
VOICENAMES, DRUMNAMES, NOISENAMES
js/logo.js
INVALIDPITCH
*/
/*
exported
SYNTHSVG, RSYMBOLS, NOTENAMES, ALLNOTENAMES, NOTENAMES1,
WESTERN2EISOLFEGENAMES, PITCHES1, PITCHES3, SCALENOTES,
EASTINDIANSOLFNOTES, DRUMS, GRAPHICS, SOLFATTRS, DEGREES,
RHYTHMRULERHEIGHT, SLIDERHEIGHT, SLIDERWIDTH, MATRIXLABELCOLOR,
MATRIXNOTECELLCOLOR, MATRIXTUPLETCELLCOLOR, MATRIXRHYTHMCELLCOLOR,
MATRIXBUTTONCOLORHOVER, MATRIXNOTECELLCOLORHOVER, MATRIXSOLFEWIDTH,
EIGHTHNOTEWIDTH, MATRIXBUTTONHEIGHT, MATRIXBUTTONHEIGHT2,
MATRIXSOLFEHEIGHT, NOTESYMBOLS, SELECTORSTRINGS, ACCIDENTALLABELS,
ACCIDENTALNAMES, ACCIDENTALVALUES, INTERVALS, MODE_PIE_MENUS,
updateTemperaments, DEFAULTINVERT, DEFAULTINTERVAL, DEFAULTEFFECT,
DEFAULTMODE, DEFAULTOSCILLATORTYPE, DEFAULTACCIDENTAL,
getInvertMode, getIntervalNumber, getIntervalDirection,
getModeNumbers, getDrumIndex, getDrumName, getDrumSymbol,
getFilterTypes, getOscillatorTypes, getDrumIcon, getDrumSynthName,
getNoiseName, getNoiseIcon, getNoiseSynthName, getVoiceName,
getVoiceIcon, getVoiceSynthName, getTemperamentKeys,
getTemperamentName, getStepSizeUp, getStepSizeDown, getModeLength,
nthDegreeToPitch, getInterval, calcNoteValueToDisplay,
durationToNoteValue, noteToFrequency, getSolfege, splitScaleDegree,
getNumNote, calcOctave, calcOctaveInterval, isInt,
convertFromSolfege, getPitchInfo, MATRIXBUTTONCOLOR, i18nSolfege,
convertFactor, getOctaveRatio, setOctaveRatio, getTemperamentsList,
addTemperamentToList, getTemperament, deleteTemperamentFromList,
addTemperamentToDictionary, buildScale, CHORDNAMES, CHORDVALUES,
DEFAULTCHORD, DEFAULTVOICE, setCustomChord, EQUIVALENTACCIDENTALS,
INTERVALVALUES, getIntervalRatio, frequencyToPitch, NOTESTEP,
GetNotesForInterval,ALLNOTESTEP,NOTENAMES,SEMITONETOINTERVALMAP
*/
/**
* Scalable sinewave graphic.
* @const
* @type {string}
*/
const SYNTHSVG =
'<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" y="0px" xml:space="preserve" x="0px" width="SVGWIDTHpx" viewBox="0 0 SVGWIDTH 55" version="1.1" height="55px" enable-background="new 0 0 SVGWIDTH 55"><g transform="scale(XSCALE,1)"><path d="m 1.5,27.5 c 0,0 2.2,-17.5 6.875,-17.5 4.7,0.0 6.25,11.75 6.875,17.5 0.75,6.67 2.3,17.5 6.875,17.5 4.1,0.0 6.25,-13.6 6.875,-17.5 C 29.875,22.65 31.1,10 35.875,10 c 4.1,0.0 5.97,13.0 6.875,17.5 1.15,5.7 1.75,17.5 6.875,17.5 4.65,0.0 6.875,-17.5 6.875,-17.5" style="stroke:#90c100;fill-opacity:1;fill:none;stroke-width:STROKEWIDTHpx;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /></g></svg>';
/**
* Notes graphics.
* @const
* @type {string}
*/
const WHOLENOTE =
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" id="svg6468" viewBox="0 0 5.1680003 12.432" height="12.432" width="5.1680002"> <g transform="translate(-375.23523,-454.37592)"> <g transform="translate(7.9606,5.6125499)" style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"> <path d="m 369.80263,457.99537 q 1.104,0 1.872,0.432 0.768,0.416 0.768,1.2 0,0.752 -0.752,1.168 -0.752,0.4 -1.808,0.4 -1.104,0 -1.856,-0.416 -0.752,-0.416 -0.752,-1.232 0,-0.576 0.464,-0.944 0.48,-0.368 1.008,-0.48 0.528,-0.128 1.056,-0.128 z m -0.864,1.136 q 0,0.672 0.304,1.184 0.304,0.512 0.784,0.512 0.736,0 0.736,-0.8 0,-0.64 -0.304,-1.136 -0.288,-0.512 -0.8,-0.512 -0.72,0 -0.72,0.752 z" /> </g> </g> </svg>';
const HALFNOTE =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3.84 12.432" height="3.5085866mm" width="1.0837333mm"> <g transform="translate(-375.23523,-454.37592)"> <g style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"> <path d="m 375.23523,465.70392 q 0,-0.832 0.816,-1.472 0.816,-0.656 1.728,-0.656 0.528,0 0.944,0.272 l 0,-9.472 0.352,0 0,10.352 q 0,0.896 -0.784,1.488 -0.784,0.592 -1.728,0.592 -0.528,0 -0.928,-0.304 -0.4,-0.32 -0.4,-0.8 z m 0.736,0.48 q 0.848,0 1.712,-0.72 0.88,-0.72 0.88,-1.072 0,-0.224 -0.192,-0.224 -0.592,0 -1.632,0.688 -1.024,0.672 -1.024,1.12 0,0.208 0.256,0.208 z" /> </g> </g> </svg>';
const QUARTERNOTE =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4.0859801 11.74224" height="3.313921mm" width="1.1531544mm"> <g transform="translate(-226.1339,-457.841)"> <g style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"> <path d="m 229.60268,457.841 0.5625,0 0.0547,0.0625 0,10.02344 q 0,1.27344 -1.53125,1.625 l -0.375,0.0313 -0.27343,0 q -1.65625,0 -1.875,-1.03906 l -0.0313,-0.24219 q 0,-1.01562 1.64843,-1.20312 l 0.25782,-0.0391 q 0.77343,0 1.47656,0.5 l 0.0313,0 0,-9.65625 0.0547,-0.0625 z" /> </g> </g> </svg>';
const EIGHTHNOTE =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7.5234898 11.7422" height="3.3139098mm" width="2.123296mm"> <g transform="translate(-244.80575,-403.5553)"> <g style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"> <path d="m 248.14955,403.5553 0.67969,0 0.0625,0.0547 0,0.30468 q 0.21094,0.42188 1.5625,0.91407 1.875,0.54687 1.875,1.625 0,1.14062 -0.95313,1.89062 l -0.0313,0 -0.23437,-0.25 q 0.47656,-0.38281 0.47656,-1.03906 0,-0.54688 -1.78125,-1.10156 -0.71875,-0.32813 -0.91406,-0.53125 l 0,8.32812 q 0,1.19531 -1.75,1.54688 l -0.44531,0 q -1.89063,0 -1.89063,-1.3125 0,-1.02344 1.65625,-1.20313 l 0.17969,0 q 0.75,0 1.44531,0.5 l 0,-9.67187 0.0625,-0.0547 z" /> </g> </g> </svg>';
const SIXTEENTHNOTE =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7.0080001 12.432" height="3.5085866mm" width="1.9778134mm"> <g transform="translate(-182.21292,-431.51877)"> <g style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"> <path d="m 182.21292,442.84677 q 0,-0.832 0.816,-1.472 0.816,-0.656 1.728,-0.656 0.528,0 0.944,0.272 l 0,-9.472 0.336,0 q 0.064,0.56 0.4,1.088 0.352,0.512 0.8,0.944 0.448,0.416 0.88,0.864 0.448,0.432 0.752,1.024 0.304,0.576 0.304,1.232 0,0.544 -0.256,1.104 0.304,0.448 0.304,1.184 0,1.232 -0.608,2.24 l -0.384,0 q 0.56,-1.12 0.56,-2.032 0,-0.512 -0.256,-0.96 -0.24,-0.448 -0.752,-0.816 -0.496,-0.368 -0.832,-0.56 -0.32,-0.192 -0.896,-0.48 l 0,5.52 q 0,0.896 -0.784,1.488 -0.784,0.592 -1.728,0.592 -0.528,0 -0.928,-0.304 -0.4,-0.32 -0.4,-0.8 z m 6.464,-5.904 q 0,-1.648 -2.624,-3.072 0,0.464 0.192,0.88 0.192,0.416 0.512,0.752 0.32,0.32 0.656,0.592 0.336,0.272 0.688,0.608 0.352,0.32 0.544,0.608 0.032,-0.256 0.032,-0.368 z" /> </g> </g> </svg>';
const THIRTYSECONDNOTE =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7.0080001 14.496001" height="4.0910935mm" width="1.9778134mm"> <g transform="translate(-630.78433,-240.88335)"> <g style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"> <path d="m 630.78433,254.27535 q 0,-0.832 0.816,-1.472 0.816,-0.656 1.728,-0.656 0.528,0 0.944,0.272 l 0,-11.536 0.352,0 q 0.048,0.56 0.384,1.072 0.336,0.496 0.768,0.912 0.432,0.4 0.864,0.848 0.432,0.448 0.72,1.104 0.304,0.656 0.304,1.456 0,0.48 -0.16,1.056 0.224,0.416 0.224,0.912 0,0.512 -0.24,0.976 0.304,0.448 0.304,1.168 0,1.232 -0.608,2.24 l -0.384,0 q 0.56,-1.12 0.56,-2.032 0,-0.512 -0.256,-0.96 -0.24,-0.448 -0.752,-0.816 -0.496,-0.368 -0.832,-0.56 -0.32,-0.192 -0.896,-0.48 l 0,5.52 q 0,0.896 -0.784,1.488 -0.784,0.592 -1.728,0.592 -0.528,0 -0.928,-0.304 -0.4,-0.32 -0.4,-0.8 z m 6.448,-7.872 q 0,-0.496 -0.208,-0.928 -0.192,-0.432 -0.64,-0.832 -0.432,-0.416 -0.784,-0.672 -0.352,-0.256 -0.976,-0.656 0.032,0.448 0.352,0.896 0.32,0.432 0.704,0.752 0.4,0.32 0.848,0.8 0.464,0.464 0.704,0.912 l 0,-0.272 z m 0,2.096 q 0,-0.4 -0.16,-0.768 -0.144,-0.368 -0.32,-0.608 -0.16,-0.256 -0.592,-0.608 -0.416,-0.352 -0.672,-0.528 -0.256,-0.176 -0.848,-0.576 0.064,0.48 0.4,0.976 0.336,0.48 0.72,0.816 0.4,0.336 0.832,0.784 0.448,0.432 0.64,0.784 l 0,-0.272 z" /> </g> </g> </svg>';
const SIXTYFOURTHNOTE =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 7.0080001 14.528" height="4.1001244mm" width="1.9778134mm"> <g transform="translate(-345.3223,-325.39492)"> <g transform="translate(3.1093785,1.6864426)" style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"> <path d="m 342.21292,337.13248 q 0,-0.832 0.816,-1.472 0.816,-0.656 1.728,-0.656 0.528,0 0.944,0.272 l 0,-11.568 0.336,0 q 0.064,0.64 0.384,1.104 0.336,0.464 0.752,0.768 0.416,0.304 0.832,0.656 0.416,0.336 0.688,0.928 0.288,0.592 0.288,1.44 0,0.24 -0.144,0.768 0.256,0.608 0.256,1.376 0,0.32 -0.16,0.896 0.224,0.416 0.224,0.912 0,0.496 -0.24,0.96 0.304,0.448 0.304,1.024 0,0.384 -0.08,0.688 -0.08,0.304 -0.16,0.448 -0.08,0.144 -0.368,0.608 l -0.384,0 q 0.08,-0.16 0.192,-0.368 0.112,-0.224 0.16,-0.32 0.064,-0.096 0.112,-0.24 0.064,-0.144 0.08,-0.288 0.016,-0.144 0.016,-0.32 0,-0.272 -0.096,-0.512 -0.08,-0.256 -0.176,-0.432 -0.096,-0.192 -0.32,-0.4 -0.224,-0.208 -0.368,-0.32 -0.144,-0.128 -0.464,-0.304 -0.304,-0.192 -0.432,-0.256 -0.128,-0.064 -0.48,-0.224 -0.336,-0.176 -0.4,-0.208 l 0,4.064 q 0,0.896 -0.784,1.488 -0.784,0.592 -1.728,0.592 -0.528,0 -0.928,-0.304 -0.4,-0.32 -0.4,-0.8 z m 6.352,-8.384 q 0,-0.352 -0.144,-0.688 -0.128,-0.352 -0.288,-0.576 -0.16,-0.224 -0.48,-0.496 -0.32,-0.272 -0.512,-0.4 -0.192,-0.144 -0.592,-0.384 -0.384,-0.24 -0.496,-0.32 0.032,0.432 0.352,0.832 0.32,0.384 0.704,0.656 0.4,0.272 0.816,0.72 0.432,0.432 0.624,0.912 0.016,-0.176 0.016,-0.256 z m 0.016,2.128 q 0,-0.208 -0.048,-0.4 -0.032,-0.192 -0.08,-0.336 -0.048,-0.16 -0.176,-0.336 -0.128,-0.176 -0.208,-0.288 -0.08,-0.112 -0.272,-0.272 -0.192,-0.176 -0.288,-0.256 -0.096,-0.08 -0.352,-0.256 -0.24,-0.176 -0.336,-0.224 -0.096,-0.064 -0.384,-0.24 -0.288,-0.192 -0.384,-0.256 0.032,0.464 0.368,0.88 0.336,0.416 0.736,0.704 0.4,0.272 0.816,0.688 0.416,0.416 0.576,0.864 0.032,-0.192 0.032,-0.272 z m -0.016,1.936 q 0,-0.848 -0.624,-1.504 -0.608,-0.672 -1.872,-1.392 0.064,0.464 0.384,0.896 0.336,0.416 0.72,0.688 0.4,0.272 0.8,0.704 0.4,0.416 0.576,0.88 0.016,-0.064 0.016,-0.272 z" /> </g> </g> </svg>';
// Is there a "proper" double-sharp symbol as well? I see this from wikipedia: U+1D12A 𝄪 MUSICAL SYMBOL DOUBLE SHARP (HTML 𝄪) (https://en.wikipedia.org/wiki/Double_sharp)
/**
* Symbol for a sharp note.
* @constant {string}
* @default
*/
const SHARP = "♯";
/**
* Symbol for a flat note.
* @constant {string}
* @default
*/
const FLAT = "♭";
/**
* Symbol for a natural note.
* @constant {string}
* @default
*/
const NATURAL = "♮";
/**
* Symbol for a double sharp note.
* @constant {string}
* @default
*/
const DOUBLESHARP = "𝄪";
/**
* Symbol for a double flat note.
* @constant {string}
* @default
*/
const DOUBLEFLAT = "𝄫";
/**
* Symbols representing different note durations.
* @constant {Object.<number, string>}
* @default
*/
const NSYMBOLS = { 1: "𝅝", 2: "𝅗𝅥", 4: "♩", 8: "♪", 16: "𝅘𝅥𝅯" };
/**
* Symbols representing different rest durations.
* @constant {Object.<number, string>}
* @default
*/
const RSYMBOLS = { 1: "𝄻", 2: "𝄼", 4: "𝄽", 8: "𝄾", 16: "𝄿" };
/**
* Maps from notes with flats to their corresponding notes with '♭' (flat) symbol.
* @constant {Object.<string, string>}
*/
const BTOFLAT = {
Eb: "E" + FLAT,
Gb: "G" + FLAT,
Ab: "A" + FLAT,
Bb: "B" + FLAT,
Db: "D" + FLAT,
Cb: "C" + FLAT,
Fb: "F" + FLAT,
eb: "E" + FLAT,
gb: "G" + FLAT,
ab: "A" + FLAT,
bb: "B" + FLAT,
db: "D" + FLAT,
cb: "C" + FLAT,
fb: "F" + FLAT
};
/**
* Maps from notes with flats to their corresponding notes with '♯' (sharp) symbol.
* @constant {Object.<string, string>}
*/
const STOSHARP = {
"E#": "E" + SHARP,
"G#": "G" + SHARP,
"A#": "A" + SHARP,
"B#": "B" + SHARP,
"D#": "D" + SHARP,
"C#": "C" + SHARP,
"F#": "F" + SHARP,
"e#": "E" + SHARP,
"g#": "G" + SHARP,
"a#": "A" + SHARP,
"b#": "B" + SHARP,
"d#": "D" + SHARP,
"c#": "C" + SHARP,
"f#": "F" + SHARP
};
/**
* Array of notes with sharps.
* @constant {string[]}
*/
const NOTESSHARP = [
"C",
"C" + SHARP,
"D",
"D" + SHARP,
"E",
"F",
"F" + SHARP,
"G",
"G" + SHARP,
"A",
"A" + SHARP,
"B"
];
/**
* Array of notes with flats.
* @constant {string[]}
*/
const NOTESFLAT = [
"C",
"D" + FLAT,
"D",
"E" + FLAT,
"E",
"F",
"G" + FLAT,
"G",
"A" + FLAT,
"A",
"B" + FLAT,
"B"
];
/**
* Array of lowercase notes with flats.
* @constant {string[]}
*/
const NOTESFLAT2 = [
"c",
"d" + FLAT,
"d",
"e" + FLAT,
"e",
"f",
"g" + FLAT,
"g",
"a" + FLAT,
"a",
"b" + FLAT,
"b"
];
/**
* Equivalent flats for various notes.
* @const
* @type {Object.<string, string>}
*/
const EQUIVALENTFLATS = {
"C♯": "D" + FLAT,
"D♯": "E" + FLAT,
"F♯": "G" + FLAT,
"G♯": "A" + FLAT,
"A♯": "B" + FLAT
};
/**
* Equivalent sharps for various notes.
* @const
* @type {Object.<string, string>}
*/
const EQUIVALENTSHARPS = {
"D♭": "C" + SHARP,
"E♭": "D" + SHARP,
"G♭": "F" + SHARP,
"A♭": "G" + SHARP,
"B♭": "A" + SHARP
};
/**
* Maps from notes with specific accidentals to their equivalent natural notes.
* @constant {Object.<string, string>}
*/
const EQUIVALENTNATURALS = { "E♯": "F", "B♯": "C", "C♭": "B", "F♭": "E" };
/**
* Maps from natural notes to their equivalent notes with specific accidentals.
* @constant {Object.<string, string>}
*/
const EQUIVALENTACCIDENTALS = { F: "E♯", C: "B♯", B: "C♭", E: "F♭", G: "F𝄪", D: "C𝄪", A: "G𝄪" };
/**
* Converts a note down to a flat note.
* @const
* @type {Object.<string, string>}
*/
const CONVERT_DOWN = {
"C": "B" + SHARP,
"C♭": "B",
"D♭": "C" + SHARP,
"E♭": "D" + SHARP,
"F": "E" + SHARP,
"F♭": "E",
"G♭": "F" + SHARP,
"A♭": "G" + SHARP,
"B♭": "A" + SHARP
};
/**
* Maps from notes with specific accidentals to their equivalent notes after a double-down transposition.
* @constant {Object.<string, string>}
*/
const CONVERT_DOUBLE_DOWN = {
"C♯": "B" + DOUBLESHARP,
"D": "C" + DOUBLESHARP,
"E": "D" + DOUBLESHARP,
"F♯": "E" + DOUBLESHARP,
"G": "F" + DOUBLESHARP,
"A": "G" + DOUBLESHARP,
"B": "A" + DOUBLESHARP
};
/**
* Maps from notes with specific accidentals to their equivalent notes after an up transposition.
* @constant {Object.<string, string>}
*/
const CONVERT_UP = {
"C♯": "D" + FLAT,
"D♯": "E" + FLAT,
"E♯": "F",
"E": "F" + FLAT,
"F♯": "G" + FLAT,
"G♯": "A" + FLAT,
"A♯": "B" + FLAT,
"B♯": "C",
"B": "C" + FLAT
};
/**
* Maps from notes with specific accidentals to their equivalent notes after a double-up transposition.
* @constant {Object.<string, string>}
*/
const CONVERT_DOUBLE_UP = {
"C": "D" + DOUBLEFLAT,
"D": "E" + DOUBLEFLAT,
"E♭": "F" + DOUBLEFLAT,
"F": "G" + DOUBLEFLAT,
"G": "A" + DOUBLEFLAT,
"A": "B" + DOUBLEFLAT,
"B♭": "C" + DOUBLEFLAT
};
/**
* Extra transpositions for specific notes with accidentals.
* @constant {Object.<string, [string, number]>}
*/
const EXTRATRANSPOSITIONS = {
"E♯": ["F", 0],
"B♯": ["C", 1],
"C♭": ["B", -1],
"F♭": ["E", 0],
"e♯": ["F", 0],
"b♯": ["C", 1],
"c♭": ["B", -1],
"f♭": ["E", 0]
};
/**
* Array containing the solfege names for the diatonic scale.
* @constant {string[]}
*/
const SOLFEGENAMES = ["do", "re", "mi", "fa", "sol", "la", "ti"];
/**
* Array containing the solfege names for the chromatic scale.
* @constant {string[]}
*/
const SOLFEGENAMES1 = [
"do",
"do" + SHARP,
"do" + DOUBLESHARP,
"re" + DOUBLEFLAT,
"re" + FLAT,
"re",
"re" + SHARP,
"re" + DOUBLESHARP,
"mi" + DOUBLEFLAT,
"mi" + FLAT,
"mi",
"fa",
"fa" + SHARP,
"fa" + DOUBLESHARP,
"sol" + DOUBLEFLAT,
"sol" + FLAT,
"sol",
"sol" + SHARP,
"sol" + DOUBLESHARP,
"la",
"la" + DOUBLEFLAT,
"la" + FLAT,
"la" + SHARP,
"la" + DOUBLESHARP,
"ti" + DOUBLEFLAT,
"ti" + FLAT,
"ti"
];
/**
* Array containing the basic note names (without accidentals).
* @constant {string[]}
*/
const NOTENAMES = ["C", "D", "E", "F", "G", "A", "B"];
/**
* Array containing all possible note names, including double sharps/flats and triple sharps/flats.
* @constant {string[]}
*/
const ALLNOTENAMES = [
"C",
"C#",
"Cx",
"Dbb",
"Db",
"D",
"D#",
"Dx",
"Ebb",
"Eb",
"E",
"E#",
"Ex",
"Fbb",
"Fb",
"F",
"F#",
"Fx",
"Gbb",
"Gb",
"G",
"G#",
"Gx",
"Abb",
"Ab",
"A",
"A#",
"Ax",
"Bbb",
"Bb",
"B",
"B#",
"Bx",
"Cbb",
"Cb"
];
/**
* Array containing note names with various accidentals (sharps and flats).
* @constant {string[]}
*/
const NOTENAMES1 = [
"C",
"C" + SHARP,
"C" + DOUBLESHARP,
"D" + DOUBLEFLAT,
"D" + FLAT,
"D",
"D" + SHARP,
"D" + DOUBLESHARP,
"E" + DOUBLEFLAT,
"E" + FLAT,
"E",
"F",
"F" + SHARP,
"F" + DOUBLESHARP,
"G" + DOUBLEFLAT,
"G" + FLAT,
"G",
"G" + SHARP,
"G" + DOUBLESHARP,
"A",
"A" + DOUBLEFLAT,
"A" + FLAT,
"A" + SHARP,
"A" + DOUBLESHARP,
"B" + DOUBLEFLAT,
"B" + FLAT,
"B"
];
/**
* Maps from Western note names to their corresponding solfege names.
* @constant {Object.<string, string>}
*/
const SOLFEGECONVERSIONTABLE = {
"C♭": "do" + FLAT,
"C": "do",
"C♯": "do" + SHARP,
"D♭": "re" + FLAT,
"D": "re",
"D♯": "re" + SHARP,
"E♭": "mi" + FLAT,
"E": "mi",
"F": "fa",
"F♯": "fa" + SHARP,
"G♭": "sol" + FLAT,
"G": "sol",
"G♯": "sol" + SHARP,
"A♭": "la" + FLAT,
"A": "la",
"A♯": "la" + SHARP,
"B♭": "ti" + FLAT,
"B": "ti",
"B♯": "ti" + SHARP,
"R": _("rest")
};
/**
* Maps from Western solfege names to their corresponding Carnatic solfege names.
* @constant {Object.<string, string>}
*/
const WESTERN2EISOLFEGENAMES = {
do: "sa",
re: "re",
mi: "ga",
fa: "ma",
sol: "pa",
la: "dha",
ti: "ni"
};
/**
* Array containing pitches with flats.
* @constant {string[]}
*/
const PITCHES = [
"C",
"D" + FLAT,
"D",
"E" + FLAT,
"E",
"F",
"G" + FLAT,
"G",
"A" + FLAT,
"A",
"B" + FLAT,
"B"
];
/**
* Array containing pitches with flats and sharps.
* @constant {string[]}
*/
const PITCHES1 = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"];
/**
* Array containing pitches with sharps.
* @constant {string[]}
*/
const PITCHES2 = [
"C",
"C" + SHARP,
"D",
"D" + SHARP,
"E",
"F",
"F" + SHARP,
"G",
"G" + SHARP,
"A",
"A" + SHARP,
"B"
];
/**
* Array containing pitches with sharps.
* @constant {string[]}
*/
const PITCHES3 = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];
/**
* Maps from numerical values to solfege names.
* @constant {Object.<number, string>}
*/
const NOTESTABLE = {
1: "do",
2: "do" + SHARP,
3: "re",
4: "re" + SHARP,
5: "mi",
6: "fa",
7: "fa" + SHARP,
8: "sol",
9: "sol" + SHARP,
10: "la",
11: "la" + SHARP,
0: "ti"
};
/**
* Maps from fixed solfege names to their corresponding Western note names.
* @constant {Object.<string, string>}
*/
const FIXEDSOLFEGE = {
do: "C",
re: "D",
mi: "E",
fa: "F",
sol: "G",
la: "A",
ti: "B"
};
/**
* Maps from fixed solfege names with accidentals to their corresponding Western note names.
* @constant {Object.<string, string>}
*/
const FIXEDSOLFEGE1 = {
"do𝄫": "B",
"do♭": "C" + FLAT,
"do": "C",
"do♯": "C" + SHARP,
"do𝄪": "D",
"re𝄫": "C",
"re♭": "D" + FLAT,
"re": "D",
"re♯": "D" + SHARP,
"re𝄪": "E",
"mi𝄫": "D",
"mi♭": "E" + FLAT,
"mi": "E",
"mi♯": "E" + SHARP,
"mi𝄪": "G",
"fa𝄫": "E" + FLAT,
"fa♭": "F" + FLAT,
"fa": "F",
"fa♯": "F" + SHARP,
"fa𝄪": "G" + SHARP,
"sol𝄫": "E",
"sol♭": "G" + FLAT,
"sol": "G",
"sol♯": "G" + SHARP,
"sol𝄪": "A",
"la𝄫": "G",
"la♭": "A" + FLAT,
"la": "A",
"la♯": "A" + SHARP,
"la𝄪": "B",
"ti𝄫": "A",
"ti♭": "B" + FLAT,
"ti": "B",
"ti♯": "B" + SHARP,
"ti𝄪": "C",
"R": _("rest")
};
/**
* Maps from note names to their corresponding step numbers.
* @constant {Object.<string, number>}
*/
const NOTESTEP = { C: 1, D: 3, E: 5, F: 6, G: 8, A: 10, B: 12 };
/**
* Maps note names to their corresponding step numbers, including enharmonic equivalents.
* @constant {Object.<number, string>}
*/
const ALLNOTESTEP = {
"Cb": 0,
"C": 1,
"C#": 2,
"Db": 2,
"D": 3,
"D#": 4,
"Eb": 4,
"E": 5,
"E#": 6,
"Fb": 5,
"F": 6,
"F#": 7,
"Gb": 7,
"G": 8,
"G#": 9,
"Ab": 9,
"A": 10,
"A#": 11,
"Bb": 11,
"B": 12,
"B#": 0
};
/**
* semitone/intervalnumber --> lettergap/notenamesgap -->intervalnames
* @constant {Object.<number, Object.<number,string>}
*/
const SEMITONETOINTERVALMAP = {
0: { 0: _("Perfect unison"), 1: _("Diminished second") },
1: { 1: _("Minor second"), 0: _("Augmented unison") },
2: { 1: _("Major second"), 2: _("Diminished third") },
3: { 2: _("Minor third"), 1: _("Augmented second") },
4: { 2: _("Major third"), 3: _("Diminished fourth") },
5: { 3: _("Perfect fourth"), 2: _("Augmented third") },
6: { 4: _("Diminished fifth"), 3: _("Augmented fourth") },
7: { 4: _("Perfect fifth"), 5: _("Diminished sixth") },
8: { 5: _("Minor sixth"), 4: _("Augmented fifth") },
9: { 5: _("Major sixth"), 6: _("Diminished seventh") },
10: { 6: _("Minor seventh"), 5: _("Augmented sixth") },
11: { 6: _("Major seventh"), 0: _("Diminished octave") },
12: { 0: _("Perfect octave"), 6: _("Augmented seventh") },
13: { 1: _("Minor ninth"), 0: _("Augmented octave") },
14: { 1: _("Major ninth"), 2: _("Diminished tenth") },
15: { 2: _("Minor tenth"), 1: _("Augmented ninth") },
16: { 2: _("Major tenth"), 3: _("Diminished eleventh") },
17: { 3: _("Perfect eleventh"), 2: _("Augmented tenth") },
18: { 4: _("Diminished twelfth"), 3: _("Augmented eleventh") },
19: { 4: _("Perfect twelfth"), 5: _("Diminished thirteenth") },
20: { 5: _("Minor thirteenth"), 4: _("Augmented fifth, plus an octave") },
21: { 5: _("Major thirteenth"), 6: _("Diminished seventh, plus an octave") }
};
/**
* Array containing preferences for keys with sharps.
* @constant {string[]}
*/
const SHARPPREFERENCE = [
"g major",
"d major",
"a major",
"e major",
"b major",
"f# major",
"c# major",
"e minor",
"b minor",
"f# minor",
"c# minor",
"g# minor",
"d# minor"
];
/**
* Array containing preferences for keys with flats.
* @constant {string[]}
*/
const FLATPREFERENCE = [
"f major",
"bb major",
"eb major",
"ab major",
"db major",
"gb major",
"cb major",
"d minor",
"g minor",
"c minor",
"f minor",
"bb minor",
"eb minor",
"d harmonic minor",
"g harmonic minor",
"c harmonic minor",
"f harmonic minor",
"bb harmonic minor",
"eb harmonic minor"
];
/**
* Internal representation of solfege notes used in selectors.
* @constant {string[]}
*/
const SOLFNOTES = ["ti", "la", "sol", "fa", "mi", "re", "do"];
/**
* Scale notes used in selectors.
* @constant {string[]}
*/
const SCALENOTES = ["7", "6", "5", "4", "3", "2", "1"];
/**
* Carnatic solfege notes.
* @constant {string[]}
*/
const EASTINDIANSOLFNOTES = ["ni", "dha", "pa", "ma", "ga", "re", "sa"];
/**
* Drum names used in selectors.
* @constant {string[]}
*/
const DRUMS = [
"snare drum",
"kick drum",
"tom tom",
"floor tom",
"bass drum",
"cup drum",
"darbuka drum",
"japanese drum",
"hi hat",
"ride bell",
"cow bell",
"triangle bell",
"finger cymbals",
"chime",
"gong",
"clang",
"crash",
"clap",
"slap"
];
/**
* Graphics names used in selectors.
* @constant {string[]}
*/
const GRAPHICS = [
"forward",
"back",
"right",
"left",
"set heading",
"set color",
"set shade",
"set hue",
"set grey",
"set translucency",
"set pen size"
];
//The "original solfege" https://en.wikipedia.org/wiki/Solf%C3%A8ge#Origin
// const ARETINIANSOLFNOTES = ['si', 'la', 'sol', 'fa', 'mi', 're', 'ut'];
// https://en.wikipedia.org/wiki/Iroha
// const IROHASOLFNOTES = ['ro', 'i', 'to', 'he', 'ho', 'ni', 'ha'];
// const IROHASOLFNOTESJA = ['ロ','イ','ト','へ','ホ','二','ハ'];
/**
* Solfège attributes including double sharp, sharp, natural, flat, and double flat.
* @constant {string[]}
*/
const SOLFATTRS = [DOUBLESHARP, SHARP, NATURAL, FLAT, DOUBLEFLAT];
//.TRANS: ordinal number. Please keep exactly one space between each number.
/**
* Ordinal numbers for degrees.
* @constant {string}
*/
const DEGREES = _("1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th");
/**
* Number of semitones in an octave.
* @constant {number}
*/
const SEMITONES = 12;
/**
* Array representing powers of 2.
* @constant {number[]}
*/
const POWER2 = [1, 2, 4, 8, 16, 32, 64, 128];
// eslint-disable-next-line no-loss-of-precision
const TWELTHROOT2 = 1.0594630943592953;
// eslint-disable-next-line no-loss-of-precision
const TWELVEHUNDRETHROOT2 = 1.0005777895065549;
const A0 = 27.5;
const C8 = 4186.01;
/**
* Octave ratio.
* @type {number}
*/
let octaveRatio = 2;
/**
* Height of the rhythm ruler.
* @constant {number}
*/
const RHYTHMRULERHEIGHT = 100;
/**
* Height of a staff note.
* @constant {number}
*/
const YSTAFFNOTEHEIGHT = 12.5;
/**
* Height of a staff octave.
* @constant {number}
*/
const YSTAFFOCTAVEHEIGHT = 87.5;
/**
* Height of a slider.
* @constant {number}
*/
const SLIDERHEIGHT = 200;
/**
* Width of a slider.
* @constant {number}
*/
const SLIDERWIDTH = 50;
/**
* Color of matrix buttons.
* @constant {string}
*/
const MATRIXBUTTONCOLOR = "#c374e9";
/**
* Color of matrix labels.
* @constant {string}
*/
const MATRIXLABELCOLOR = "#90c100";
/**
* Color of matrix note cells.
* @constant {string}
*/
const MATRIXNOTECELLCOLOR = "#b1db00";
/**
* Color of matrix tuplet cells.
* @constant {string}
*/
const MATRIXTUPLETCELLCOLOR = "#57e751";
/**
* Color of matrix rhythm cells.
* @constant {string}
*/
const MATRIXRHYTHMCELLCOLOR = "#c8c8c8";
/**
* Hover color of matrix buttons.
* @constant {string}
*/
const MATRIXBUTTONCOLORHOVER = "#c894e0";
/**
* Hover color of matrix note cells.
* @constant {string}
*/
const MATRIXNOTECELLCOLORHOVER = "#c2e820";
/**
* Width of matrix solfege.
* @constant {number}
*/
const MATRIXSOLFEWIDTH = 52;
/**
* Width of an eighth note.
* @constant {number}
*/
const EIGHTHNOTEWIDTH = 24;
/**
* Height of matrix buttons.
* @constant {number}
*/
const MATRIXBUTTONHEIGHT = 40;
/**
* Height of matrix buttons.
* @constant {number}
*/
const MATRIXBUTTONHEIGHT2 = 66;
/**
* Height of matrix solfege.
* @constant {number}
*/
const MATRIXSOLFEHEIGHT = 30;
/**
* Image URL for a whole note.
* @constant {string}
*/
const wholeNoteImg = "data:image/svg+xml;base64," + window.btoa(base64Encode(WHOLENOTE));
const halfNoteImg = "data:image/svg+xml;base64," + window.btoa(base64Encode(HALFNOTE));
const quarterNoteImg = "data:image/svg+xml;base64," + window.btoa(base64Encode(QUARTERNOTE));
const eighthNoteImg = "data:image/svg+xml;base64," + window.btoa(base64Encode(EIGHTHNOTE));
const sixteenthNoteImg = "data:image/svg+xml;base64," + window.btoa(base64Encode(SIXTEENTHNOTE));
const thirtysecondNoteImg =
"data:image/svg+xml;base64," + window.btoa(base64Encode(THIRTYSECONDNOTE));
const sixtyfourthNoteImg =
"data:image/svg+xml;base64," + window.btoa(base64Encode(SIXTYFOURTHNOTE));
/**
* Map from note duration to corresponding note symbols.
* @constant {Object.<number, string>}
*/
const NOTESYMBOLS = {
1: wholeNoteImg,
2: halfNoteImg,
4: quarterNoteImg,
8: eighthNoteImg,
16: sixteenthNoteImg,
32: thirtysecondNoteImg,
64: sixtyfourthNoteImg
};
/**
* Musical terms used in selectors that may require translation.
* @constant {Array<string>}
*/
const SELECTORSTRINGS = [
//.TRANS: unison is a music term related to intervals
_("unison"),