forked from euwbah/musescore-microtonal-edo-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pitch up no dt.qml
3198 lines (2856 loc) · 148 KB
/
pitch up no dt.qml
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
import QtQuick 2.1
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
import QtQuick.Dialogs 1.1
import MuseScore 3.0
MuseScore {
MessageDialog {
id: invalidTuningSystemError
title: 'n-TET tuning plugin error:'
text: 'Tuning system not supported, it requires an accidental that cannot be represented.\nOnly EDOs ranked up to sharp-8 are supported. See the README for more info.'
onAccepted: {
Qt.quit();
}
}
version: "2.1.2"
description: "Raises selection (Shift-click) or individually selected notes (Ctrl-click) by 1 step of n EDO." +
"This version prioritises up/down arrows over semisharp/flat accidentals whereever possible."
menuPath: "Plugins.n-EDO.Raise Pitch By 1 Step (Arrows)"
// WARNING! This doesn't validate the accidental code!
property variant customKeySigRegex: /\.(.*)\.(.*)\.(.*)\.(.*)\.(.*)\.(.*)\.(.*)/g
// MuseScore's annotations contain formatting code in angle brackets if the
// annotation text formatting is not default. This function removes
// all text within angle brackets including the brackets themselves
function removeFormattingCode(str) {
if (typeof(str) == 'string')
return str.replace(/<[^>]*>/g, '');
else
return null;
}
// <TUNING SYSTEM VARIANT CHECKPOINT>
function getCentOffset(noteName, stepOffset, edo, a4Freq) {
var stepSize = 1200.0 / edo;
var fifthStep = Math.round(edo * Math.log(3/2) / Math.log(2));
var sharpValue = 7 * fifthStep - 4 * edo;
var regularAccCentOffset = 0;
for (var x = -2; x <= 2; x++) {
if (stepOffset == x*sharpValue)
regularAccCentOffset += 100*x;
}
var centOffset = -regularAccCentOffset;
centOffset += 1200.0 * Math.log(a4Freq / 440.0) / Math.log(2);
switch (noteName) {
case 'f':
return stepSize*(-4*fifthStep + stepOffset) + 2800 + centOffset;
case 'c':
return stepSize*(-3*fifthStep + stepOffset) + 2100 + centOffset;
case 'g':
return stepSize*(-2*fifthStep + stepOffset) + 1400 + centOffset;
case 'd':
return stepSize*(-fifthStep + stepOffset) + 700 + centOffset;
case 'a':
return stepSize*stepOffset + centOffset;
case 'e':
return stepSize*(fifthStep + stepOffset) - 700 + centOffset;
case 'b':
return stepSize*(2*fifthStep + stepOffset) - 1400 + centOffset;
}
}
function convertAccidentalToSteps(acc, edo) {
return convertAccidentalTypeToSteps(convertAccidentalTextToAccidentalType(acc), edo);
}
function convertAccidentalTextToAccidentalType(accStr) {
switch(accStr.trim()) {
case 'bbv3':
return Accidental.DOUBLE_FLAT_THREE_ARROWS_DOWN;
case 'bbv2':
return Accidental.DOUBLE_FLAT_TWO_ARROWS_DOWN;
case 'bbv':
case 'bbv1':
return Accidental.DOUBLE_FLAT_ONE_ARROW_DOWN;
case 'bb':
return Accidental.FLAT2;
case 'bb^3':
return Accidental.DOUBLE_FLAT_THREE_ARROWS_UP;
case 'bb^2':
return Accidental.DOUBLE_FLAT_TWO_ARROWS_UP;
case 'bb^':
case 'bb^1':
return Accidental.DOUBLE_FLAT_ONE_ARROW_UP;
case 'db':
case 'bd':
return Accidental.MIRRORED_FLAT2;
case 'bv3':
return Accidental.FLAT_THREE_ARROWS_DOWN;
case 'bv2':
return Accidental.FLAT_TWO_ARROWS_DOWN;
case 'bv':
case 'bv1':
return Accidental.FLAT_ONE_ARROW_DOWN;
case 'b':
return Accidental.FLAT;
case 'b^3':
return Accidental.FLAT_THREE_ARROWS_UP;
case 'b^2':
return Accidental.FLAT_TWO_ARROWS_UP;
case 'b^':
case 'b^1':
return Accidental.FLAT_ONE_ARROW_UP;
case 'v3':
return Accidental.NATURAL_THREE_ARROWS_DOWN;
case 'v2':
return Accidental.NATURAL_TWO_ARROWS_DOWN;
case 'v':
case 'v1':
return Accidental.NATURAL_ONE_ARROW_DOWN;
case 'd':
return Accidental.MIRRORED_FLAT;
case '+':
return Accidental.SHARP_SLASH;
case '^3':
return Accidental.NATURAL_THREE_ARROWS_UP;
case '^2':
return Accidental.NATURAL_TWO_ARROWS_UP;
case '^':
case '^1':
return Accidental.NATURAL_ONE_ARROW_UP;
case '#v3':
return Accidental.SHARP_THREE_ARROWS_DOWN;
case '#v2':
return Accidental.SHARP_TWO_ARROWS_DOWN;
case '#v':
case '#v1':
return Accidental.SHARP_ONE_ARROW_DOWN;
case '#':
return Accidental.SHARP;
case '#^3':
return Accidental.SHARP_THREE_ARROWS_UP;
case '#^2':
return Accidental.SHARP_TWO_ARROWS_UP;
case '#^':
case '#^1':
return Accidental.SHARP_ONE_ARROW_UP;
case '#+':
case '+#':
return Accidental.SHARP_SLASH4;
case 'xv3':
return Accidental.DOUBLE_SHARP_THREE_ARROWS_DOWN;
case 'xv2':
return Accidental.DOUBLE_SHARP_TWO_ARROWS_DOWN;
case 'xv':
case 'xv1':
return Accidental.DOUBLE_SHARP_ONE_ARROW_DOWN;
case 'x':
return Accidental.SHARP2;
case 'x^3':
return Accidental.DOUBLE_SHARP_THREE_ARROWS_UP;
case 'x^2':
return Accidental.DOUBLE_SHARP_TWO_ARROWS_UP;
case 'x^':
case 'x^1':
return Accidental.DOUBLE_SHARP_ONE_ARROW_UP;
default:
return Accidental.NATURAL;
}
}
// <TUNING SYSTEM VARIANT CHECKPOINT>
function convertAccidentalTypeToSteps(accType, edo) {
var accOffset = null;
var fifthStep = Math.round(edo * Math.log(3/2) / Math.log(2));
var sharpValue = 7 * fifthStep - 4 * edo;
switch(accType) {
case Accidental.SHARP_SLASH4:
accOffset = 3*sharpValue/2;
break;
case Accidental.SHARP_SLASH:
accOffset = sharpValue/2;
break;
case Accidental.MIRRORED_FLAT:
accOffset = -sharpValue/2;
break;
case Accidental.MIRRORED_FLAT2:
accOffset = -3*sharpValue/2;
break;
case Accidental.DOUBLE_SHARP_THREE_ARROWS_UP:
accOffset = 2*sharpValue + 3;
break;
case Accidental.DOUBLE_SHARP_TWO_ARROWS_UP:
accOffset = 2*sharpValue + 2;
break;
case Accidental.SHARP2_ARROW_UP:
case Accidental.DOUBLE_SHARP_ONE_ARROW_UP:
accOffset = 2*sharpValue + 1;
break;
case Accidental.SHARP2:
accOffset = 2 * sharpValue;
break;
case Accidental.SHARP2_ARROW_DOWN:
case Accidental.DOUBLE_SHARP_ONE_ARROW_DOWN:
accOffset = 2*sharpValue - 1;
break;
case Accidental.DOUBLE_SHARP_TWO_ARROWS_DOWN:
accOffset = 2*sharpValue - 2;
break;
case Accidental.DOUBLE_SHARP_THREE_ARROWS_DOWN:
accOffset = 2*sharpValue - 3;
break;
case Accidental.SHARP_THREE_ARROWS_UP:
accOffset = sharpValue + 3;
break;
case Accidental.SHARP_TWO_ARROWS_UP:
accOffset = sharpValue + 2;
break;
case Accidental.SHARP_ARROW_UP:
case Accidental.SHARP_ONE_ARROW_UP:
accOffset = sharpValue + 1;
break;
case Accidental.SHARP:
accOffset = sharpValue;
break;
case Accidental.SHARP_ARROW_DOWN:
case Accidental.SHARP_ONE_ARROW_DOWN:
accOffset = sharpValue - 1;
break;
case Accidental.SHARP_TWO_ARROWS_DOWN:
accOffset = sharpValue - 2;
break;
case Accidental.SHARP_THREE_ARROWS_DOWN:
accOffset = sharpValue - 3;
break;
case Accidental.NATURAL_THREE_ARROWS_UP:
accOffset = 3;
break;
case Accidental.NATURAL_TWO_ARROWS_UP:
accOffset = 2;
break;
case Accidental.NATURAL_ARROW_UP:
case Accidental.NATURAL_ONE_ARROW_UP:
accOffset = 1;
break;
case Accidental.NATURAL:
accOffset = 0;
break;
case Accidental.NATURAL_ARROW_DOWN:
case Accidental.NATURAL_ONE_ARROW_DOWN:
accOffset = -1;
break;
case Accidental.NATURAL_TWO_ARROWS_DOWN:
accOffset = -2;
break;
case Accidental.NATURAL_THREE_ARROWS_DOWN:
accOffset = -3;
break;
case Accidental.FLAT_THREE_ARROWS_UP:
accOffset = -sharpValue + 3;
break;
case Accidental.FLAT_TWO_ARROWS_UP:
accOffset = -sharpValue + 2;
break;
case Accidental.FLAT_ARROW_UP:
case Accidental.FLAT_ONE_ARROW_UP:
accOffset = -sharpValue + 1;
break;
case Accidental.FLAT:
accOffset = -sharpValue;
break;
case Accidental.FLAT_ARROW_DOWN:
case Accidental.FLAT_ONE_ARROW_DOWN:
accOffset = -sharpValue - 1;
break;
case Accidental.FLAT_TWO_ARROWS_DOWN:
accOffset = -sharpValue - 2;
break;
case Accidental.FLAT_THREE_ARROWS_DOWN:
accOffset = -sharpValue - 3;
break;
case Accidental.DOUBLE_FLAT_THREE_ARROWS_UP:
accOffset = -2*sharpValue + 3;
break;
case Accidental.DOUBLE_FLAT_TWO_ARROWS_UP:
accOffset = -2*sharpValue + 2;
break;
case Accidental.FLAT2_ARROW_UP:
case Accidental.DOUBLE_FLAT_ONE_ARROW_UP:
accOffset = -2*sharpValue + 1;
break;
case Accidental.FLAT2:
accOffset = -2 * sharpValue;
break;
case Accidental.FLAT2_ARROW_DOWN:
case Accidental.DOUBLE_FLAT_ONE_ARROW_DOWN:
accOffset = -2*sharpValue - 1;
break;
case Accidental.DOUBLE_FLAT_TWO_ARROWS_DOWN:
accOffset = -2*sharpValue - 2;
break;
case Accidental.DOUBLE_FLAT_THREE_ARROWS_DOWN:
accOffset = -2*sharpValue - 3;
break;
}
return accOffset;
}
// Construct an up/down arrow accidental based on the number of sharps and number of up arrows
// of the accidental. Negative values represents flats/down arrows instead.
//
// If numSharps is 1.5, 0.5, -0.5, or -1.5, it represents a quarter tone accidental.
// the numArrows param will be ignored.
//
// Returns null if no such accidental exists, and logs a warning in the console.
function constructAccidental(numSharps, numArrows) {
console.log('called construct acc with sharps: ' + numSharps + ', arrows: ' + numArrows);
if (numSharps == -1.5)
return Accidental.MIRRORED_FLAT2;
else if (numSharps == -0.5)
return Accidental.MIRRORED_FLAT;
else if (numSharps == 0.5)
return Accidental.SHARP_SLASH;
else if (numSharps == 1.5)
return Accidental.SHARP_SLASH4;
else if (numSharps == -2) {
switch(numArrows) {
case -3:
return Accidental.DOUBLE_FLAT_THREE_ARROWS_DOWN;
case -2:
return Accidental.DOUBLE_FLAT_TWO_ARROWS_DOWN;
case -1:
return Accidental.DOUBLE_FLAT_ONE_ARROW_DOWN;
case 0:
return Accidental.FLAT2;
case 1:
return Accidental.DOUBLE_FLAT_ONE_ARROW_UP;
case 2:
return Accidental.DOUBLE_FLAT_TWO_ARROWS_UP;
case 3:
return Accidental.DOUBLE_FLAT_THREE_ARROWS_UP;
}
} else if (numSharps == -1) {
switch(numArrows) {
case -3:
return Accidental.FLAT_THREE_ARROWS_DOWN;
case -2:
return Accidental.FLAT_TWO_ARROWS_DOWN;
case -1:
return Accidental.FLAT_ONE_ARROW_DOWN;
case 0:
return Accidental.FLAT;
case 1:
return Accidental.FLAT_ONE_ARROW_UP;
case 2:
return Accidental.FLAT_TWO_ARROWS_UP;
case 3:
return Accidental.FLAT_THREE_ARROWS_UP;
}
} else if (numSharps == 0) {
switch(numArrows) {
case -3:
return Accidental.NATURAL_THREE_ARROWS_DOWN;
case -2:
return Accidental.NATURAL_TWO_ARROWS_DOWN;
case -1:
return Accidental.NATURAL_ONE_ARROW_DOWN;
case 0:
return Accidental.NATURAL;
case 1:
return Accidental.NATURAL_ONE_ARROW_UP;
case 2:
return Accidental.NATURAL_TWO_ARROWS_UP;
case 3:
return Accidental.NATURAL_THREE_ARROWS_UP;
}
} else if (numSharps == 1) {
switch(numArrows) {
case -3:
return Accidental.SHARP_THREE_ARROWS_DOWN;
case -2:
return Accidental.SHARP_TWO_ARROWS_DOWN;
case -1:
return Accidental.SHARP_ONE_ARROW_DOWN;
case 0:
return Accidental.SHARP;
case 1:
return Accidental.SHARP_ONE_ARROW_UP;
case 2:
return Accidental.SHARP_TWO_ARROWS_UP;
case 3:
return Accidental.SHARP_THREE_ARROWS_UP;
}
} else if (numSharps == 2) {
switch(numArrows) {
case -3:
return Accidental.DOUBLE_SHARP_THREE_ARROWS_DOWN;
case -2:
return Accidental.DOUBLE_SHARP_TWO_ARROWS_DOWN;
case -1:
return Accidental.DOUBLE_SHARP_ONE_ARROW_DOWN;
case 0:
return Accidental.SHARP2;
case 1:
return Accidental.DOUBLE_SHARP_ONE_ARROW_UP;
case 2:
return Accidental.DOUBLE_SHARP_TWO_ARROWS_UP;
case 3:
return Accidental.DOUBLE_SHARP_THREE_ARROWS_UP;
}
}
console.log('WARNING: unexpected to have no such accidental exist: sharps: ' + numSharps + ', arrows: ' + numArrows);
return null; // if no such accidental exists.
}
// deconstructs and accidental enum into {numSharps, numArrows}
// does the opposite of constructAccidental
function deconstructAccidental(acc) {
// helper fn for creating objects
function a(x, y) {
return {
numSharps: x,
numArrows: y
};
}
switch(acc) {
case Accidental.SHARP_SLASH4:
return a(1.5, 0);
case Accidental.SHARP_SLASH:
return a(0.5, 0);
case Accidental.MIRRORED_FLAT:
return a(-0.5, 0);
case Accidental.MIRRORED_FLAT2:
return a(-1.5, 0);
case Accidental.DOUBLE_SHARP_THREE_ARROWS_UP:
return a(2, 3);
case Accidental.DOUBLE_SHARP_TWO_ARROWS_UP:
return a(2, 2);
case Accidental.SHARP2_ARROW_UP:
case Accidental.DOUBLE_SHARP_ONE_ARROW_UP:
return a(2, 1);
case Accidental.SHARP2:
return a(2, 0);
case Accidental.SHARP2_ARROW_DOWN:
case Accidental.DOUBLE_SHARP_ONE_ARROW_DOWN:
return a(2, -1);
case Accidental.DOUBLE_SHARP_TWO_ARROWS_DOWN:
return a(2, -2);
case Accidental.DOUBLE_SHARP_THREE_ARROWS_DOWN:
return a(2, -3);
case Accidental.SHARP_THREE_ARROWS_UP:
return a(1, 3);
case Accidental.SHARP_TWO_ARROWS_UP:
return a(1, 2);
case Accidental.SHARP_ARROW_UP:
case Accidental.SHARP_ONE_ARROW_UP:
return a(1, 1);
case Accidental.SHARP:
return a(1, 0);
case Accidental.SHARP_ARROW_DOWN:
case Accidental.SHARP_ONE_ARROW_DOWN:
return a(1, -1);
case Accidental.SHARP_TWO_ARROWS_DOWN:
return a(1, -2);
case Accidental.SHARP_THREE_ARROWS_DOWN:
return a(1, -3);
case Accidental.NATURAL_THREE_ARROWS_UP:
return a(0, 3);
case Accidental.NATURAL_TWO_ARROWS_UP:
return a(0, 2);
case Accidental.NATURAL_ARROW_UP:
case Accidental.NATURAL_ONE_ARROW_UP:
return a(0, 1);
case Accidental.NATURAL:
return a(0, 0);
case Accidental.NATURAL_ARROW_DOWN:
case Accidental.NATURAL_ONE_ARROW_DOWN:
return a(0, -1);
case Accidental.NATURAL_TWO_ARROWS_DOWN:
return a(0, -2);
case Accidental.NATURAL_THREE_ARROWS_DOWN:
return a(0, -3);
case Accidental.FLAT_THREE_ARROWS_UP:
return a(-1, 3);
case Accidental.FLAT_TWO_ARROWS_UP:
return a(-1, 2);
case Accidental.FLAT_ARROW_UP:
case Accidental.FLAT_ONE_ARROW_UP:
return a(-1, 1);
case Accidental.FLAT:
return a(-1, 0);
case Accidental.FLAT_ARROW_DOWN:
case Accidental.FLAT_ONE_ARROW_DOWN:
return a(-1, -1);
case Accidental.FLAT_TWO_ARROWS_DOWN:
return a(-1, -2);
case Accidental.FLAT_THREE_ARROWS_DOWN:
return a(-1, -3);
case Accidental.DOUBLE_FLAT_THREE_ARROWS_UP:
return a(-2, 3);
case Accidental.DOUBLE_FLAT_TWO_ARROWS_UP:
return a(-2, 2);
case Accidental.FLAT2_ARROW_UP:
case Accidental.DOUBLE_FLAT_ONE_ARROW_UP:
return a(-2, 1);
case Accidental.FLAT2:
return a(-2, 0);
case Accidental.FLAT2_ARROW_DOWN:
case Accidental.DOUBLE_FLAT_ONE_ARROW_DOWN:
return a(-2, -1);
case Accidental.DOUBLE_FLAT_TWO_ARROWS_DOWN:
return a(-2, -2);
case Accidental.DOUBLE_FLAT_THREE_ARROWS_DOWN:
return a(-2, -3);
}
}
// NOTE: This function may differ between upwards and downwards variants of
// the plugin as some tuning systems (e.g. 31 ups and downs) will have
// enharmonic equivalents between two different types of accidentals
//
// e.g.: C#v and C^.
//
// Whenever possible, use the LEAST number of arrows
// If steps splits sharpValue exactly into half, use a quarter-tone accidental.
// If plugin moves upwards, prefer spelling using up arrows (default to the flatter enharmonic side, or sharper if super-flat)
// If plugin moves downwards, prefer spelling using down arrows (default to the sharper enharmonic side, or flatter if super-flat)
//
// <TUNING SYSTEM VARIANT CHECKPOINT>
function convertStepsToAccidentalType(steps, edo) {
var fifthStep = Math.round(edo * Math.log(3/2) / Math.log(2));
var sharpValue = 7 * fifthStep - 4 * edo;
var numSharpsFlatter = Math.floor(steps / sharpValue);
var numSharpsSharper = Math.ceil(steps / sharpValue);
var arrowsOnFlatSide = steps - numSharpsFlatter * sharpValue;
var arrowsOnSharpSide = steps - numSharpsSharper * sharpValue;
var useFlatSide = Math.abs(arrowsOnFlatSide) < Math.abs(arrowsOnSharpSide);
if (Math.abs(arrowsOnFlatSide) == Math.abs(arrowsOnSharpSide)) {
// <UP DOWN VARIANT CHECKPOINT>
useFlatSide = sharpValue >= 0; // invert equality if the plugin moves downwards
}
// check if the num of sharps the algorithm decides to use is illegal.
// maximum of 2 sharps/flats allowed.
if (numSharpsFlatter > 2 || numSharpsFlatter < -2)
useFlatSide = false;
if (numSharpsSharper > 2 || numSharpsSharper < -2)
useFlatSide = true;
// check if quartertone accidentals may be used.
if (steps == -sharpValue * 3/2)
return Accidental.MIRRORED_FLAT2;
else if (steps == -sharpValue * 1/2)
return Accidental.MIRRORED_FLAT;
else if (steps == sharpValue * 1/2)
return Accidental.SHARP_SLASH;
else if (steps == sharpValue * 3/2)
return Accidental.SHARP_SLASH4;
var numSharps = useFlatSide ? numSharpsFlatter : numSharpsSharper;
var numArrows = useFlatSide ? arrowsOnFlatSide : arrowsOnSharpSide;
while (numSharps > 2) {
if (numArrows + sharpValue > 3 || numArrows + sharpValue < -3) {
invalidTuningSystemError.open();
return null;
} else {
numSharps--;
numArrows += sharpValue;
}
}
while (numSharps < -2) {
if (numArrows - sharpValue > 3 || numArrows - sharpValue < -3) {
invalidTuningSystemError.open();
return null;
} else {
numSharps++;
numArrows -= sharpValue;
}
}
return constructAccidental(numSharps, numArrows);
}
function convertAccidentalTypeToName(accType) {
switch(accType) {
case Accidental.DOUBLE_FLAT_THREE_ARROWS_DOWN:
return 'bbv3';
case Accidental.DOUBLE_FLAT_TWO_ARROWS_DOWN:
return 'bbv2';
case Accidental.FLAT2_ARROW_DOWN:
case Accidental.DOUBLE_FLAT_ONE_ARROW_DOWN:
return 'bbv';
case Accidental.FLAT2:
return 'bb';
case Accidental.FLAT2_ARROW_UP:
case Accidental.DOUBLE_FLAT_ONE_ARROW_UP:
return 'bb^';
case Accidental.DOUBLE_FLAT_TWO_ARROWS_UP:
return 'bb^2';
case Accidental.DOUBLE_FLAT_THREE_ARROWS_UP:
return 'bb^3';
case Accidental.MIRRORED_FLAT2:
return 'db';
case Accidental.FLAT_THREE_ARROWS_DOWN:
return 'bv3';
case Accidental.FLAT_TWO_ARROWS_DOWN:
return 'bv2';
case Accidental.FLAT_ARROW_DOWN:
case Accidental.FLAT_ONE_ARROW_DOWN:
return 'bv';
case Accidental.FLAT:
return 'b';
case Accidental.MIRRORED_FLAT:
return 'd';
case Accidental.FLAT_ARROW_UP:
case Accidental.FLAT_ONE_ARROW_UP:
return 'b^';
case Accidental.FLAT_TWO_ARROWS_UP:
return 'b^2';
case Accidental.FLAT_THREE_ARROWS_UP:
return 'b^3';
case Accidental.NATURAL_THREE_ARROWS_DOWN:
return 'v3';
case Accidental.NATURAL_TWO_ARROWS_DOWN:
return 'v2';
case Accidental.NATURAL_ARROW_DOWN:
case Accidental.NATURAL_ONE_ARROW_DOWN:
return 'v';
case Accidental.NATURAL:
return 'nat';
case Accidental.NATURAL_THREE_ARROWS_UP:
return '^3';
case Accidental.NATURAL_TWO_ARROWS_UP:
return '^2';
case Accidental.NATURAL_ARROW_UP:
case Accidental.NATURAL_ONE_ARROW_UP:
return '^';
case Accidental.SHARP_THREE_ARROWS_DOWN:
return '#v3';
case Accidental.SHARP_TWO_ARROWS_DOWN:
return '#v2';
case Accidental.SHARP_ARROW_DOWN:
case Accidental.SHARP_ONE_ARROW_DOWN:
return '#v';
case Accidental.SHARP_SLASH:
return '+';
case Accidental.SHARP:
return '#';
case Accidental.SHARP_THREE_ARROWS_UP:
return '#^3';
case Accidental.SHARP_TWO_ARROWS_UP:
return '#^2';
case Accidental.SHARP_ARROW_UP:
case Accidental.SHARP_ONE_ARROW_UP:
return '#^';
case Accidental.SHARP_SLASH4:
return '#+';
case Accidental.DOUBLE_SHARP_THREE_ARROWS_DOWN:
return 'xv3';
case Accidental.DOUBLE_SHARP_TWO_ARROWS_DOWN:
return 'xv2';
case Accidental.SHARP2_ARROW_DOWN:
case Accidental.DOUBLE_SHARP_ONE_ARROW_DOWN:
return 'xv';
case Accidental.SHARP2:
return 'x';
case Accidental.DOUBLE_SHARP_THREE_ARROWS_UP:
return 'x^3';
case Accidental.DOUBLE_SHARP_TWO_ARROWS_UP:
return 'x^2';
case Accidental.SHARP2_ARROW_UP:
case Accidental.DOUBLE_SHARP_ONE_ARROW_UP:
return 'x^';
case Accidental.NONE:
return 'none';
default:
return 'unrecognized';
}
}
// Returns the accidental after it has been transposed up (or down if the plugin is for transposing down)
// will return null if there are no more accidentals that are higher (or lower) than acc.
//
// acc: a value from the Accidental enum
// edo: the tuning system
//
// <TUNING SYSTEM VARIANT CHECKPOINT>
function getNextAccidental(acc, edo) {
/*
1. keep the main accidental as much as possible, if it is natural, leave it as natural
2. increase the number of up arrows by one
3. if the next accidental (determined by + sharp value) matches the transposed note
perfectly without any arrows, use that instead
4. if the new transposed note matches exactly half or one and a half steps that a sharp/flat
would transpose it by, use a quarter tone accidental.
5. once 3 arrows are exceeded, a different accidental has to be used
6. if 3 arrows are exceeded and no accidentals are found that allows the note to be spelt with
less than or eq. to 3 arrows, there is no such note and the tuning system cannot be supported
as there are more notes than the number of accidentals available in musescore
*/
var fifthStep = Math.round(edo * Math.log(3/2) / Math.log(2));
var sharpValue = 7 * fifthStep - 4 * edo;
var acc = deconstructAccidental(acc);
console.log('get next called: sharps: ' + acc.numSharps + ', arrows: ' + acc.numArrows);
// handle quarter tone accidentals
if (acc.numSharps % 1 !== 0) {
if (acc.numSharps > 0) {
acc.numSharps = Math.floor(Math.abs(acc.numSharps));
acc.numArrows = Math.round(sharpValue / 2);
} else {
acc.numSharps = -Math.floor(Math.abs(acc.numSharps));
acc.numArrows = -Math.round(sharpValue / 2);
}
}
// <UP DOWN VARIANT CHECKPOINT>
acc.numArrows ++; // NOTE: set to -- for downwards plugin
// Sharp-flat manipulation section.
// disregard this section if perfect EDO (sharp-0), as sharps and flats do nothing to the scale.
if (sharpValue != 0) {
// check if the number of arrows coincide with a standard accidental
// <UP DOWN VARIANT CHECKPOINT>: negate sharp value for downwards plugins
if (sharpValue > 0 && acc.numArrows == sharpValue && acc.numSharps < 2)
return constructAccidental(acc.numSharps + 1, 0);
// in a flat-n edo, pythagorically flatenning the note raises the pitch.
else if (sharpValue < 0 && acc.numArrows == -sharpValue && acc.numSharps > -2)
return constructAccidental(acc.numSharps - 1, 0);
// check if the number of arrows coincide with quarter tone accidentals
// in the 'arrow priority' version, this is only enabled if absolutely necessary
// (when apotome size is 8 steps and above)
else if (acc.numArrows == 1/2 * sharpValue && acc.numSharps < 2 && sharpValue >= 8)
return constructAccidental(acc.numSharps + 0.5, 0);
else if (acc.numArrows == -1/2 * sharpValue && acc.numSharps > -2 && sharpValue >= 8)
return constructAccidental(acc.numSharps - 0.5, 0);
else if (acc.numArrows == 3/2 * sharpValue && acc.numSharps < 1 && sharpValue >= 8)
return constructAccidental(acc.numSharps + 1.5, 0);
else if (acc.numArrows == -3/2 * sharpValue && acc.numSharps > -1 && sharpValue >= 8)
return constructAccidental(acc.numSharps - 1.5, 0);
// check if number of arrows exceeds sharpValue in the direction of transposition,
// and thus can be better represented with a different base accidental.
// <UP DOWN VARIANT CHECKPOINT>
else if (sharpValue > 0 && acc.numArrows > 3 * sharpValue && acc.numSharps < 0)
return constructAccidental(acc.numSharps + 3, acc.numArrows - sharpValue * 3);
else if (sharpValue > 0 && acc.numArrows > 2 * sharpValue && acc.numSharps < 1)
return constructAccidental(acc.numSharps + 2, acc.numArrows - sharpValue * 2);
else if (sharpValue > 0 && acc.numArrows > sharpValue && acc.numSharps < 2)
return constructAccidental(acc.numSharps + 1, acc.numArrows - sharpValue);
// for flat-n edos, flats raise the pitch instead.
else if (sharpValue < 0 && acc.numArrows > -3 * sharpValue && acc.numSharps > 0)
return constructAccidental(acc.numSharps - 3, acc.numArrows + sharpValue * 3);
else if (sharpValue < 0 && acc.numArrows > -2 * sharpValue && acc.numSharps > -1)
return constructAccidental(acc.numSharps - 2, acc.numArrows + sharpValue * 2);
else if (sharpValue < 0 && acc.numArrows > -sharpValue && acc.numSharps > -2)
return constructAccidental(acc.numSharps - 1, acc.numArrows + sharpValue);
}
// otherwise, make sure its a valid accidental
if ((sharpValue > 0 && acc.numSharps == 2 && acc.numArrows > 3) ||
(sharpValue < 0 && acc.numSharps == -2 && acc.numArrows > 3))
return null;
// make sure the number of arrows are valid. (from -3 to +3)
// NOTE: will possibly return null from here if edo is perfect (sharp-0)
if (sharpValue > 0) {
if (acc.numArrows > 3 && acc.numArrows - sharpValue >= -3 && acc.numArrows - sharpValue <= 3 && acc.numSharps < 2)
return constructAccidental(acc.numSharps + 1, acc.numArrows - sharpValue);
else if (acc.numArrows < -3 && acc.numArrows + sharpValue >= -3 && acc.numArrows + sharpValue <= 3 && acc.numSharps > -2)
return constructAccidental(acc.numSharps - 1, acc.numArrows + sharpValue);
} else if (sharpValue < 0) {
if (acc.numArrows > 3 && acc.numArrows + sharpValue >= -3 && acc.numArrows + sharpValue <= 3 && acc.numSharps > -2)
return constructAccidental(acc.numSharps - 1, acc.numArrows + sharpValue);
else if (acc.numArrows < -3 && acc.numArrows - sharpValue >= -3 && acc.numArrows - sharpValue <= 3 && acc.numSharps < 2)
return constructAccidental(acc.numSharps + 1, acc.numArrows - sharpValue);
}
// console.log('constructing default: ' + acc.numSharps + ', ' + acc.numArrows);
// if no such accidental exists, it will return null.
var a = constructAccidental(acc.numSharps, acc.numArrows);
// console.log('constructed: ' + convertAccidentalTypeToName(0 + a));
return a;
}
// returns the note.line property after it has been enharmonically transposed
// in the direction of the plugin.
// NOTE: Set the coefficient to -1 for upwards plugins, and +1 for downwards plugins.
// <UP DOWN VARIANT CHECKPOINT>
function getNextLine(line) {
return line - 1;
}
// returns the accidental equivalent of the next baseNote after the current baseNote
// at maximum accidental offset is exceeded.
//
// The maximum accidental offset is x^3 (bb^3 for super-flat edos) for the upwards plugin
// and bv3 (xv3 for super-flat) for the downwards plugin
//
// example: if the note is Bx^3, and there is no more accidental sharper than x^3,
// call this function with the arguments 'b' and 31 edo, and it will
// return Accidental.DOUBLE_SHARP_ONE_ARROW_UP representing the note
// that is one step higher than Bx^3 in 31 edo is Cx^.
// (distance between nominals B and C in 31 edo is 3 steps)
//
// <TUNING SYSTEM VARIANT CHECKPOINT>
function getOverLimitEnharmonicEquivalent(baseNote, edo) {
var fifthStep = Math.round(edo * Math.log(3/2) / Math.log(2));
var sharpValue = 7 * fifthStep - 4 * edo;
switch(baseNote) {
// <UP DOWN VARIANT CHECKPOINT> change to D E G A B for downwards variant
case 'c':
case 'd':
case 'f':
case 'g':
case 'a':
// a whole tone up enharmonic nominal. Steps = 2 fifthStep - octave.
var wholeToneSteps = 2 * fifthStep - edo;
// <UP DOWN VARIANT CHECKPOINT> flip steps direction
// limits are: x^3 or bb^3 (super-flat) if upwards, bbv3 or xv3 (super-flat) if downwards
var overLimitSteps = (sharpValue >= 0) ? (2 * sharpValue + 3 + 1) : (-2 * sharpValue + 3 + 1);
// <UP DOWN VARIANT CHECKPOINT> flip sign
// Simulate going up an enharmonic whole tone, reducing the offset.
var newSteps = overLimitSteps - wholeToneSteps;
return convertStepsToAccidentalType(newSteps, edo);
default:
// a diatonic semitone up enharmonic nominal. Steps = -5 fifthStep + 3 octaves
var semitoneSteps = -5 * fifthStep + 3 * edo;
var overLimitSteps = (sharpValue >= 0) ? (2 * sharpValue + 3 + 1) : (-2 * sharpValue + 3 + 1);
var newSteps = overLimitSteps - wholeToneSteps;
return convertStepsToAccidentalType(newSteps, edo);
}
}
// returns enharmonics above and below
// {
// above: {baseNote: 'a' through 'g', offset: diesis offset}
// below: {baseNote: 'a' through 'g', offset: diesis offset}
// }
// <TUNING SYSTEM VARIANT CHECKPOINT>
function getEnharmonics(baseNote, offset, edo) {
var above, below;
var fifthStep = Math.round(edo * Math.log(3/2) / Math.log(2));
var sharpValue = 7 * fifthStep - 4 * edo;
var wholeToneSteps = 2 * fifthStep - edo;
var semitoneSteps = -5 * fifthStep + 3 * edo;
switch (baseNote) {
case 'a': case 'd': case 'g':
above = offset - wholeToneSteps;
below = offset + wholeToneSteps;
break;
case 'b': case 'e':
above = offset - semitoneSteps;
below = offset + wholeToneSteps;
break;
case 'c': case 'f':
above = offset - wholeToneSteps;
below = offset + semitoneSteps;
}
var lowerOffsetBound = -2 * Math.abs(sharpValue) - 3;
var upperOffsetBound = 2 * Math.abs(sharpValue) + 3;
above = above < lowerOffsetBound ? null : {
baseNote: getNextNote(baseNote),
offset: above
};
below = below > upperOffsetBound ? null : {
baseNote: getPrevNote(baseNote),
offset: below
};
return {
above: above,
below: below
};
}
// gets the base note alphabet above the current notestr
function getNextNote(noteStr) {
switch(noteStr) {
case 'a':
return 'b';
case 'b':
return 'c';
case 'c':
return 'd';
case 'd':
return 'e';
case 'e':
return 'f';
case 'f':
return 'g';
case 'g':
return 'a';
}
}
function getPrevNote(noteStr) {
switch(noteStr) {
case 'a':
return 'g';
case 'b':
return 'a';
case 'c':
return 'b';
case 'd':
return 'c';
case 'e':
return 'd';
case 'f':
return 'e';
case 'g':
return 'f';
}
}
// Takes in annotations[].text and returns either
// a key signature object if str is a valid custom key sig code or null.
//
// Key signature object structure:
// {
// c: {steps: <number of diesis offset>, type: Accidental enum value}
// d: ...
// e: ...
// etc...
// }
//
//
// Valid key sig code is denoted as such:
// .c.d.e.f.g.a.b
// where identifiers c thru b denote a valid accidental code of which
// will apply to the respective notes.
//
// For example, this is F-down major: .v.v.v.v.v.v.bv
//
// whitespace can be placed between dots and accidentals for readability.
//
// For the natural accidental, blank or whitespace will both work.
//
// Assign the key signature object to the parms.currKeySig field!
function scanCustomKeySig(str, edo) {
if (typeof(str) !== 'string')
return null;
str = str.trim();
var keySig = {};
var res = str.match(customKeySigRegex);
// For code golfing
var notes = [null, 'c', 'd', 'e', 'f', 'g', 'a', 'b'];
if (res === null)
return null;
console.log('scanCust', str, 'res:', res[0]);
for (var i = 1; i <= 7; i++) {
console.log(res[i]);
var accSteps = convertAccidentalToSteps(res[i].trim(), edo);
var accType = convertAccidentalTextToAccidentalType(res[i].trim());
keySig[notes[i]] = {offset: accSteps, type: accType};
}
return keySig;
}
// get the tick of a note object, whether it is a grace note or normal note.
function getTick(note) {
if (note.parent.parent.tick !== undefined)
return note.parent.parent.tick;
else
return note.parent.parent.parent.tick;
}
// Apply the given function to all notes in selection
// or, if nothing is selected, in the entire score