-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex-old.html
1932 lines (1684 loc) · 72 KB
/
index-old.html
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
<html>
<!-- Full disclosure: JavaScript is not my forte and neither is CSS. -B -->
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=640, initial-scale=1">
<head>
<title>Warframe Shawzin Tab Generator</title>
</head>
<!-- embedded favicon because why not -->
<link href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAANH5AADR+QGceVN3AAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrB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LJJPr9PoQQ03K5fBvATwA4AQAhxLkQQoWarFarFAgEMBqNkEgkYLfb0el00G630el0zlTzoYd0L5fLTY1G465uIQSFEATAeDxOkvevNFFVpVLpXjfKYrH4QevRafokDYdD+bpPMRgM7ABuqrEWgCM/ltjqKuDIpZaD3RTUA5/Pd6koyi2DwbA+5FwsFid+v/9SC/gzAD0ZXxYwq1doAAAAAElFTkSuQmCC" rel="icon" type="image/png" />
<style type="text/css">
/* general formatting */
* {
font-family: sans-serif;
color: #B0B0B0;
}
body {
background-color: #202020;
}
input, textarea {
color: #000000;
}
input:invalid {
background: #FF8888;
}
.title {
font-weight: bold;
font-size: 100%;
color: #80A0D0;
display: inline;
}
.titleBar {
background-color: #404040;
margin: 1ex;
padding: 1ex;
border-radius: 1ex;
text-align: middle;
}
.titleBar .businessDiv {
margin: 2ex 1ex 1ex 1ex;
}
.mainTitle {
font-weight: bold;
text-align: center;
font-size: 200%;
color: #FFFFFF;
}
.subTitle {
font-weight: bold;
text-align: center;
font-size: 150%;
color: #FFFFFF;
}
.label {
color: #FFFFFF;
}
a {
color: #8080FF
}
a:visited {
color: #D080FF
}
ul {
list-style-type: disc;
}
li {
margin: 0ex 0ex 1ex 0ex;
}
/* help section formatting */
#lotsOfWordsContainer, .footerContainer {
background-color: #202020;
margin: 1ex;
padding: 1ex;
border-radius: 1ex;
text-align: center;
}
.lotsOfWords, .footer {
max-width: 100ex;
display: inline-block;
text-align: left;
}
.footer {
font-weight: bold;
font-size: 100%;
}
.about {
text-align: center;
}
h1, h2, h3, h4 {
color: A0C0F0;
}
strong {
color: 6080B0;
}
.warn, .warn * {
color: D06040;
}
#TOC li {
margin: 0;
}
/* notes formatting */
.notes tr td {
padding: 0.1ex 0.25ex 1ex 0.25ex;
vertical-align: text-top;
}
.notes tr td:first-child {
width: 33%;
text-align: right;
}
/*
For some unknown reason, the font size on moble devices is much smaller, but only on the first column on the
notes tables. Work around using a media query for a coarse pointer (usually denotes a phone or tablet).
*/
@media only screen and (pointer: coarse) {
.notes tr td:first-child {
font-size: 150%;
}
}
/* error bar formatting */
#errorBar {
text-align: center;
}
#error {
background-color: #B00000;
font-weight: bold;
text-align: left;
color: #FFFFFF;
margin: 1ex;
padding: 1ex;
border-radius: 1ex;
display: inline-block;
}
.errorLine {
font-weight: bold;
color: #FFFFFF;
}
/* Buttons */
.button {
margin: 1ex 1ex 1ex 1ex;
cursor: pointer;
}
.utilGroup {
text-align: center;
}
.util, .utilHidden {
margin: 1ex 0ex 1ex 0ex;
}
.util {
display: inline;
}
.utilHidden {
display: none;
}
.button, #platformDiv, #meteredDiv, #darkModeDiv, #hidpiDiv, #meterDiv, #tempoDiv, #measuresPerLineDiv, #leadInBeatsDiv, #secondsPerLineDiv, .start, .urlButton {
background-color: #808080;
border: none;
color: #FFFFFF;
padding: 1ex;
text-align: center;
text-decoration: none;
font-size: 100%;
border-radius: 1ex;
display: block-inline;
}
.songContainer {
text-align: center;
}
.songDiv {
display: inline-block;
text-align: left;
}
#songTitleDiv, #authorDiv, #songCodeDiv {
background-color: #404080;
border: none;
color: #FFFFFF;
padding: 1ex;
text-align: left;
text-decoration: none;
font-size: 100%;
border-radius: 1ex;
display: block;
}
.start {
background-color: #60A060;
}
.stop {
background-color: #A06060;
}
.urlButton, {
background-color: #406080;
}
.density, .cumulative, .query {
background-color: #404040;
color: #D0D0D0;
}
.densitySelected, .cumulativeSelected, .querySelected {
background-color: #80A0D0;
color: #FFFFFF;
}
/* Fields */
.inputName, .inputTime, .inputRequired, .inputCount, .inputRate, .inputRange, .inputStopAfter, .inputResult, .inputPercentile {
background-color: #101010;
border: none;
color: #B0B0B0;
font-size: 75%;
padding: 1ex;
border-radius: 1ex;
}
.inputBailEarly, #copyUrlAutoStart {
background-color: #101010;
border: none;
color: #B0B0B0;
}
#samplesSelect, .rivenTypeSelect {
background-color: #101010;
border: none;
color: #B0B0B0;
font-size: 100%;
padding: 1ex;
border-radius: 1ex;
}
/* graying everthing out when disabled */
.rivenTypeSelect:disabled {
background-color: #202020;
}
.button:disabled {
background-color: #404040;
color: #B0B0B0;
cursor: not-allowed;
}
.inputName:disabled, .inputTime:disabled, .inputRequired:disabled, .inputCount:disabled, .inputRate:disabled, .inputRange:disabled, .inputStopAfter:disabled, .inputResult:disabled, .inputPercentile:disabled {
background-color: #202020;
color: #B0B0B0;
cursor: not-allowed;
}
.inputStopAfter:disabled {
background-color: #404040;
}
.inputBailEarly:disabled, #copyUrlAutoStart:disabled {
background-color: #202020;
color: #B0B0B0;
cursor: not-allowed;
}
#samplesSelect:disabled {
background-color: #202020;
color: #B0B0B0;
cursor: not-allowed;
}
#tabArea {
background-color: #FFFFFF;
border: none;
color: #000000;
font-size: 75%;
padding: 1ex;
border-radius: 1ex;
text-align: center;
}
/* tooltips, adapted from https://www.w3schools.com/css/css_tooltip.asp */
.tooltip {
position: relative;
display: inline-block;
}
.tooltip:hover .tooltiptext, .tooltip:hover .tooltiptextbottom {
visibility: visible;
opacity: 1;
}
/* fix the link colors inside tooltips */
.tooltip a {
color: #0000FF
}
.tooltip a:visited {
color: #B000FF
}
/* right side tooltip */
.tooltip .tooltiptext {
visibility: hidden;
width: 50ex;
background-color: #C0C0C0;
color: #4040A0;
text-align: center;
border-radius: 0.5ex;
padding: 1ex;
position: absolute;
z-index: 1;
top: 1ex;
left: calc(100% + 2ex);
opacity: 0;
transition: opacity 500ms;
transition-delay: 1s;
}
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 2.25ex;
right: 100%;
margin-top: -1ex;
border-width: 1ex;
border-style: solid;
border-color: transparent #C0C0C0 transparent transparent;
}
/* bottom side tooltip */
.tooltip .tooltiptextbottom {
visibility: hidden;
width: 30ex;
background-color: #C0C0C0;
color: #4040A0;
text-align: center;
border-radius: 0.5ex;
padding: 1ex;
position: absolute;
z-index: 1;
top: 120%;
left: calc(50% - 15ex);
margin-left: -2ex;
pointer-events: none;
opacity: 0;
transition: opacity 500ms;
transition-delay: 1s;
}
.tooltip .tooltiptextbottom::after {
content: "";
position: absolute;
bottom: 100%; /* At the top of the tooltip */
left: 50%;
margin-left: -1ex;
border-width: 1ex;
border-style: solid;
border-color: transparent transparent #C0C0C0 transparent;
}
/* popup, adapted from https://www.w3schools.com/howto/howto_js_popup.asp */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
}
.popup .popuptext {
visibility: hidden;
width: 50ex;
background-color: #C0C0C0;
color: #000080;
text-align: center;
border-radius: 0.5ex;
padding: 1ex;
position: absolute;
z-index: 1;
top: 120%;
left: -40ex;
margin-left: -2ex;
}
.popup .popuptext::after {
content: "";
position: absolute;
bottom: 100%; /* At the top of the tooltip */
right: 2ex;
margin-left: -1ex;
border-width: 1ex;
border-style: solid;
border-color: transparent transparent #C0C0C0 transparent;
}
.popup .show {
visibility: visible;
animation: fadeIn 1s
}
#urlHolder {
color: #000000;
}
</style>
<body onload="initModel()">
<script type="text/javascript" language="javascript">
// todo: make this configurable?
var stringThreeOnTop = true;
var darkMode = false;
var hiDPI = false;
function isHiDPI() {
return hiDPI;
}
// thanks to https://www.reddit.com/r/Warframe/comments/cxbxoc/shawzin_song_recording_syntax/
var scale_map = new Map();
scale_map.set('1', 'Pentatonic Minor');
scale_map.set('2', 'Pentatonic Major');
scale_map.set('3', 'Chromatic');
scale_map.set('4', 'Hexatonic');
scale_map.set('5', 'Major');
scale_map.set('6', 'Minor');
scale_map.set('7', 'Hirajoshi');
scale_map.set('8', 'Phrygian');
scale_map.set('9', 'Yo');
var base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function base64ToInt(char) {
// todo: better?
var index = base64Chars.indexOf(char);
if (index < 0) {
throw "Invalid character: \"" + char + "\"";
}
return index;
}
class Note {
constructor() {
this.string = "";
this.fret = "";
this.time = 0;
}
fromString(code) {
// sanity check
if (code.length != 3) {
throw "Invalid note code: \"" + code + "\""
}
// split three base64 chars and convert to ints
var noteInt = base64ToInt(code.charAt(0));
var measure = base64ToInt(code.charAt(1));
var tick = base64ToInt(code.charAt(2));
// bits 1-3 of the note int are the strings
this.string = "";
if (noteInt & 0x01) this.string = this.string + "1";
if (noteInt & 0x02) this.string = this.string + "2";
if (noteInt & 0x04) this.string = this.string + "3";
// bits 4-6 of the note int are the frets
this.fret = "";
if (noteInt & 0x08) this.fret = this.fret + "1";
if (noteInt & 0x10) this.fret = this.fret + "2";
if (noteInt & 0x20) this.fret = this.fret + "3";
// combine measure int and tick into into a single time, number of ticks from the beginning of the song
this.time = (measure * 64) + tick
return this;
}
desc() {
return "[" + this.time + " - " + this.string + ":" + this.fret + "]";
}
offsetTime(offset) {
// construct a new note with the same note value but an offset time
var n = new Note();
n.string = this.string;
n.fret = this.fret;
n.time = this.time + offset;
return n;
}
}
function noteTimeComparator(note1, note2) {
return note1.time - note2.time;
}
class Song {
constructor() {
this.scale = "";
this.notes = Array();
}
setScale(scale) {
this.scale = scale;
return this;
}
fromString(code) {
// should be 3n+1 chars long
if (code.length % 3 != 1) {
throw "Code is an invalid length"
}
// pull out the scale code and map it
var scaleCode = code.charAt(0);
this.scale = scale_map.get(scaleCode);
if (!this.scale) {
throw "Invalid scale code: \"" + scaleCode + "\""
}
// note array
this.notes = Array();
// pull out each three-char substring and parse it into a note string, fret, and time
for (var i = 1; i < code.length; i+= 3) {
this.notes.push(new Note().fromString(code.substring(i, i+3)));
}
// sort by time, should be unnecessary but there's nothing preventing anyone from
// building note lists out of order.
this.notes.sort(noteTimeComparator);
return this;
}
isEmpty() {
return this.notes.length == 0;
}
applyLeadIn(leadInLength, measureLength) {
var leadInOffset = measureLength - leadInLength;
if (leadInOffset < 0) {
throw "Lead in size cannot be more than one measure"
}
// iterate over all the notes
for (var i = 0; i < this.notes.length; i++) {
this.notes[i] = this.notes[i].offsetTime(leadInOffset);
}
return this;
}
split(intervalLength) {
// This is the meat of the whole thing
// we will build an array of sub-songs
var array = new Array();
// initial state, start before beginning
var intervalStart = -intervalLength;
// the start of the next interval
var intervalEnd = 0;
// loop over notes
// current sub-song, there isn't one yet
var subSong;
// iterate over all the notes
for (var i = 0; i < this.notes.length; i++) {
var note = this.notes[i];
// if the note's time is after our current interval, add sub-songs and increment the interval
// until we reach the right range
while (note.time >= intervalEnd) {
// create a new subSong and put it at the end of the array
// might as well copy the scale, too
subSong = new Song().setScale(this.scale);
array.push(subSong);
// increment the interval
intervalStart = intervalEnd;
intervalEnd = intervalStart + intervalLength;
}
// offset the note so that the interval start is time zero
subSong.notes.push(note.offsetTime(-intervalStart));
}
return array;
}
}
//==============================================================
// UI Builders
//==============================================================
function buildTabWithoutMeasures(song, platform, title, author, secondsPerLine) {
var secondsPerLineFloat = parseFloat(secondsPerLine);
if (secondsPerLineFloat <= 0) {
throw "Invalid seconds per line: \"" + secondsPerLine + "\"";
}
// 16 ticks in a second
// round to the nearest tick
buildTab(song, platform, title, author, Math.round(secondsPerLineFloat * 16));
}
function buildTabWithMeasures(song, platform, title, author, meter, tempo, measuresPerLine, leadInBeats) {
// parse the tempo
var tempoInt = parseInt(tempo);
if (tempoInt <= 0) {
throw "Invalid tempo: \"" + secondsPerLine + "\"";
}
// 16 ticks in a second => ticks/minute * minutes/beat = ticks per beat
var ticksPerBeat = (16*60) / tempoInt;
// parse the meter
var regex = /(\d+)\/(\d+)/g;
var match = regex.exec(meter);
if (!match) {
throw "Invalid time signature: \"" + meter + "\"";
}
// pull out the numerator and denominator of the meter
// numerator = beats per measure
var beatsPerMeasure = parseInt(match[1]);
// denominator = the beat value
var beatValue = parseInt(match[2]);
if (beatsPerMeasure <= 0 || beatValue <= 0) {
throw "Invalid time signature: \"" + meter + "\"";
}
// beatValue doesn't actually matter for our purposes. We don't have to worry about drawing eighth notes
// versus quarter notes. We have a tempo in beats per second, and all we care about is how many beats are
// in each measure
// measure length is a multiple of the beat length
var ticksPerMeasure = ticksPerBeat * beatsPerMeasure;
var measuresPerLineInt = parseInt(measuresPerLine);
if (measuresPerLineInt <= 0) {
throw "Invalid measures per line: \"" + measuresPerLineInt + "\"";
}
// line length is a multiple of the measure length
var ticksPerLine = ticksPerMeasure * measuresPerLineInt;
var leadInBeatsFloat = parseFloat(leadInBeats);
if (leadInBeatsFloat < 0) {
throw "Invalid lead in beats: \"" + leadInBeats + "\"";
}
var leadInTicks = Math.round(leadInBeatsFloat * ticksPerBeat);
// glad that's all out of the way
buildTab(song, platform, title, author, ticksPerLine, ticksPerMeasure, ticksPerBeat, leadInTicks);
}
function parseInt(s) {
var i = Number.parseInt(s);
if (Number.isNaN(i)) {
throw "Invalid number: \"" + s + "\"";
}
return i;
}
function parseFloat(s) {
// read a decimal from a string
var i = Number.parseFloat(s);
if (Number.isNaN(i) || i < 0) {
throw "Invalid number: \"" + s + "\"";
}
return i;
}
// convenience function to draw an image centered on a point
function drawCenteredImage(context, img, x, y) {
context.drawImage(img, x - (img.width / 2), y - (img.height / 2));
}
function buildTab(song, platform, title, author, lineBreaks, measureBreaks=0, beatBreaks=0, leadIn=0) {
// get the tab container
var tabArea = document.getElementById("tabArea")
// offset the song if lead-in was specified
// The Shawzin recorder always starts on the first note, even if that note isn't at the beginning of a measure
if (leadIn > 0) {
song = song.applyLeadIn(leadIn, measureBreaks);
}
// split the song up into sub-songs by lines
var lineSongs = song.split(lineBreaks);
var scale = isHiDPI() ? 2 : 1;
// set a few constants for the image
// todo: pull these from CSS like I do with rngsim
if (darkMode) {
var sideMargin = 15 * scale;
var topBottomMargin = 15 * scale;
var headerHeight = 80 * scale;
var footerHeight = 50 * scale;
var pageWidth = 1000 * scale;
var lineHeight = 60 * scale;
var fontSize = 18 * scale;
var lineSeparation = 60 * scale;
} else {
var sideMargin = 15 * scale;
var topBottomMargin = 15 * scale;
var headerHeight = 80 * scale;
var footerHeight = 50 * scale;
var pageWidth = 1000 * scale;
var lineHeight = 60 * scale;
var fontSize = 15 * scale;
var lineSeparation = 60 * scale;
}
if (platform == "none") {
var fretSep = 0;
// enable old rendering method
var string1 = null;
var string2 = null;
var string3 = null;
var fret0 = null;
var fret1 = null;
var fret2 = null;
var fret3 = null;
} else if (darkMode) {
var fretSep = 14 * scale;
// image objects
var string1 = document.getElementById("plat_s_1_d")
var string2 = document.getElementById("plat_s_2_d")
var string3 = document.getElementById("plat_s_3_d")
var fret0 = document.getElementById("all_f_0_d")
var fret1 = document.getElementById("plat_f_1_d")
var fret2 = document.getElementById("plat_f_2_d")
var fret3 = document.getElementById("plat_f_3_d")
} else {
var fretSep = 12 * scale;
// image objects
var string1 = document.getElementById("plat_s_1_l")
var string2 = document.getElementById("plat_s_2_l")
var string3 = document.getElementById("plat_s_3_l")
var fret0 = document.getElementById("all_f_0_l")
var fret1 = document.getElementById("plat_f_1_l")
var fret2 = document.getElementById("plat_f_2_l")
var fret3 = document.getElementById("plat_f_3_l")
}
// these are calculated
var pageHeight = headerHeight + footerHeight + (lineHeight * lineSongs.length) + (lineSeparation * (lineSongs.length - 1)) + (topBottomMargin * 2);
var lineWidth = pageWidth - (sideMargin * 2);
// create a canvas element under the tab container with the dimensions we calculated
// if you configure something stupid like a thousand-line tab you're probably going to crash something.
tabArea.innerHTML = `<canvas class="tabCanvas" height=` + pageHeight + ` width=` + pageWidth + ` onclick="convertToPng(this);"/>`;
// find the canvas element we just added
var canvas = getFirstChild(tabArea, "tabCanvas");
if (scale != 1) {
canvas.style.height = (pageHeight/scale) + 'px';
canvas.style.width = (pageWidth/scale) + 'px';
}
// save the title to the canvas element for convertToPng() to pick up for a file name
canvas.saveName = title;
// get the graphics context, this is what we'll do all our work in
var context = canvas.getContext("2d");
// fill the whole canvas with a background color, otherwise it will be transparent
context.fillStyle = darkMode ? "#000000" : "#FFFFFF";
context.fillRect(0, 0, canvas.width, canvas.height);
// set the line color and width
context.strokeStyle = darkMode ? "#FFFFFF" : "#000000";
context.lineWidth = darkMode ? fontSize / 6 : fontSize / 10;
// set up the title text
context.font = (fontSize * 2) + "px Arial";
context.textAlign = "center";
context.fillStyle = darkMode ? "#FFFFFF" : "#000000";
// title
context.fillText(title, pageWidth/2, topBottomMargin + headerHeight * 0.3);
// set up the scale line
context.font = (fontSize * 1) + "px Arial";
context.textAlign = "left";
// scale line
context.fillText("Scale: " + song.scale, sideMargin*5, topBottomMargin + headerHeight * 0.6);
// set up the author line
context.font = (fontSize * 1) + "px Arial";
context.textAlign = "right";
// authorline
context.fillText(author, pageWidth - sideMargin*5, topBottomMargin + headerHeight * 0.6);
// set up the footer line
context.font = (fontSize * 1) + "px Arial";
context.textAlign = "right";
// footer line
context.fillText("https://buff0000n.github.io/shawzintab/", pageWidth - sideMargin, pageHeight - (topBottomMargin + footerHeight * 0.25));
// set up the rest of the text
context.font = fontSize + "px Arial";
context.textAlign = "center";
// iterate over the sub-songs
for (var line = 0; line < lineSongs.length; line++) {
// calculate the box coordinates containing the line
var x1 = sideMargin;
var x2 = x1 + lineWidth;
var y1 = topBottomMargin + headerHeight + ((lineHeight + lineSeparation) * line);
var y2 = y1 + lineHeight;
// draw the song line
buildSongLine(context, x1, y1, x2, y2, fontSize, lineSongs[line], lineBreaks, measureBreaks, beatBreaks,
string1, string2, string3, fret0, fret1, fret2, fret3, fretSep)
}
}
function buildSongLine(context, x1, y1, x2, y3, fontSize, lineSong, lineBreaks, measureBreaks, beatBreaks,
string1, string2, string3, fret0, fret1, fret2, fret3, fretSep) {
// margin around the start/end bars and measure bars if present
var barMargin = fontSize;
// calculate the middle string y-position
var y2 = (y1 + y3) / 2;
// we'll use this line width for pretty much everything
context.lineWidth = darkMode ? fontSize / 6 : fontSize / 10;
// width for the string labels on the left
var labelWidth = fontSize * 1.5
// easier this way
x1 += labelWidth;
// draw 3 string lines
drawLine(context, x1, y1, x2, y1);
drawLine(context, x1, y2, x2, y2);
drawLine(context, x1, y3, x2, y3);
// string line labels
if (!fret0) {
placeText(context, fontSize, stringThreeOnTop ? "3" : "1", x1-(fontSize*1), y1);
placeText(context, fontSize, "2", x1-(fontSize*1), y2);
placeText(context, fontSize, stringThreeOnTop ? "1" : "3", x1-(fontSize*1), y3);
} else {
drawCenteredImage(context, stringThreeOnTop ? string3 : string1, x1-(fontSize*1), y1);
drawCenteredImage(context, string2, x1-(fontSize*1), y2);
drawCenteredImage(context, stringThreeOnTop ? string1 : string3, x1-(fontSize*1), y3);
}
if (measureBreaks != 0) {
// draw measure lines
for (var i = 0; i <= lineBreaks; i+= measureBreaks) {
var x3 = x1 + (((x2 - x1) * i) / lineBreaks);
drawLine(context, x3, y1, x3, y3);
}
// split up the line by measures
var measureSongs = lineSong.split(measureBreaks);
function drawMeasure(clear) {
for (var m = 0; m < measureSongs.length; m++) {
var measureSong = measureSongs[m];
var x1b = x1 + (((x2 - x1) * (m * measureBreaks)) / lineBreaks);
var x2b = x1 + (((x2 - x1) * ((m + 1) * measureBreaks)) / lineBreaks);
drawNotes(context, x1b+barMargin, y1, x2b-barMargin, y3, y2, fontSize, measureSong, measureBreaks,
clear, fret0, fret1, fret2, fret3, fretSep);
}
}
if (!fret0) {
drawMeasure(true);
drawMeasure(false);
} else {
drawMeasure(true);
}
} else {
// just put lines at the beginning and ending of each line
drawLine(context, x1, y1, x1, y3);
drawLine(context, x2, y1, x2, y3);
if (!fret0) {
// clear space for all the notes first
drawNotes(context, x1+barMargin, y1, x2-barMargin, y3, y2, fontSize, lineSong, lineBreaks,
true, fret0, fret1, fret2, fret3, fretSep);
// now draw the notes
drawNotes(context, x1+barMargin, y1, x2-barMargin, y3, y2, fontSize, lineSong, lineBreaks,
false, fret0, fret1, fret2, fret3, fretSep);
} else {
drawNotes(context, x1+barMargin, y1, x2-barMargin, y3, y2, fontSize, lineSong, lineBreaks,
true, fret0, fret1, fret2, fret3, fretSep);
}
}
// beat lines are too much clutter
/*
if (beatBreaks != 0) {
context.lineWidth = fontSize / 20;
var y1b = ((y1*2) + (y3*1)) / 3;
var y3b = ((y3*2) + (y1*1)) / 3;
for (var i = 0; i <= lineBreaks; i+= beatBreaks) {
var x3 = x1 + (((x2 - x1) * i) / lineBreaks);
drawLine(context, x3, y1b, x3, y3b);
}
}
*/
}
function drawNotes(context, x1, y1, x2, y3, y2, fontSize, drawSong, intervalLength, clear, fret0, fret1, fret2, fret3, fretSep) {
if (!fret0) {
context.textAlign = "center";
// fill color depends on whether we're clearing or drawing
if (clear) {
context.fillStyle = darkMode ? "#000000" : "#FFFFFF";
} else {
context.fillStyle = darkMode ? "#FFFFFF" : "#000000";
}
}
// iterate over the notes
for (var n = 0; n < drawSong.notes.length; n++) {
var note = drawSong.notes[n];
// use the notes time to calculate its x position in the line. The time is assumed to
// start at zero at the beginning of the line
// substract 1 from interval length to let barMargin take care of separating lines/measures
var x3 = x1 + (((x2 - x1) * note.time) / (intervalLength - 1));
// iterate over the note's strings
// do multi-string notes actually happen?
for (var j = 0; j < note.string.length; j++) {
var string = note.string.charAt(j);
// pick the y position for the correct string
var ty;
switch (string) {
case "1": ty = stringThreeOnTop ? y3 : y1; break;
case "2": ty = y2; break;
case "3": ty = stringThreeOnTop ? y1 : y3; break;
}
if (!fret0) {
// if there's no frets then use "0"
var fret = (note.fret != "" ? note.fret : "0");
// clear space or draw the note
placeText(context, fontSize, fret, x3, ty, clear);
} else {
// draw the three frets, either open or closed
drawCenteredImage(context, note.fret.includes("1") ? fret1 : fret0, x3, ty + fretSep);
drawCenteredImage(context, note.fret.includes("2") ? fret2 : fret0, x3, ty);
drawCenteredImage(context, note.fret.includes("3") ? fret3 : fret0, x3, ty - fretSep);
}
}
}
}
function placeText(context, fontSize, text, x3, ty, clear=false) {
// kludge to make it appear in the middle of the string line
// todo: how many browsers support context.measureText()?
ty += (fontSize*0.35);
var w = text.length * (fontSize * 0.8);
var h = fontSize;
if (clear) {
// clear a rectangle around the text
context.fillRect(x3-(w/2), ty-h, w, h*1.3);
} else {
// draw the text
context.fillText(text, x3, ty);
// if it's a multi-fret chord then underline it
if (text.length > 1) {
context.lineWidth = darkMode ? fontSize / 6 : fontSize / 10;
drawLine(context, x3-(w/2), ty+(h*0.3), x3+(w/2), ty+(h*0.3))
}
}
}
function drawLine(context, x1, y1, x2, y2) {
// why is this so annoying
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.stroke();
}
function convertToPng(canvas) {
// quick and easy replace a canvas element with an equivalent image element for easy download
// builds a huuuuge URL with the base-64 encoded PNG data embedded inside it
var src = canvas.toDataURL();
// get the song name that was saved to the canvas element
var name = canvas.saveName;
// use a default if no name was specified
if (!name || name == "") {
name = "song";
}
var fileName = name + ".png";
if (canvas.style.height) {
var imgStyle = `style = "height: ` + canvas.style.height + `; width: ` + canvas.style.width + `"`;
} else {
var imgStyle = ``;
}
// replace the canvas with an image
// Ugh, the only way to give it a file name is to wrap it in a link element, and duplicate the entire src contents.
canvas.parentElement.innerHTML = `
<a download="${fileName}" href="${src}">
<image src="${src}" ` + imgStyle + `></image>
</a>
`;