-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
406 lines (344 loc) · 17 KB
/
index.html
File metadata and controls
406 lines (344 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>fretboard project</title>
<style>
body {
margin: 10px 0;
padding: 0;
text-align: center;
}
.note {
text-align: center;
width: 30px;
height: 30px;
}
.float-left {
float: left;
}
div#body {
display: inline-block;
text-align: center;
}
div#controls {
display: inline-block;
margin-top: 5px;
}
table {
border: 0;
border-spacing: 5px;
border-collapse: separate;
margin: 0;
padding: 0;
}
table td {
border: 2px solid #555555;
text-align: center;
}
table td.tuning {
border: 0px;
}
table th {
}
</style>
</head>
<body onload="setup()">
<div id="body">
<div id="content">
<table id="fretboard">
<thead>
<tr></tr>
</thead>
<tbody>
</tbody>
</table>
<div id="controls">
<a href="#" onclick="tableRowsStringCreate()">add a string</a>
<label for="tuning">tuning</label>
<select name="tuning" id="tuning" onchange="tuningSet()">
<option value="0">eadgbe - standard</option>
<option value="1">dadgbe - drop d</option>
<option value="2">dadgbd - double drop d</option>
<option value="3">dadgad - celtic</option>
</select>
<label for="scale">scale</label>
<select name="scale" id="scale" onchange="scaleSet()">
<option value="0">aeolian (natural minor)</option>
<option value="1">locrian</option>
<option value="2">ionian (major)</option>
<option value="3">dorian</option>
<option value="4">phrygian</option>
<option value="5">lydian</option>
<option value="6">mixolydian</option>
</select>
<label for="rootNote">root note</label>
<select name="rootNote" id="rootNote" onchange="rootNoteSet()">
<option value="0">A</option>
<option value="1">A#/Bb</option>
<option value="2">B/Cb</option>
<option value="3">C</option>
<option value="4">C#/Db</option>
<option value="5">D</option>
<option value="6">D#/Eb</option>
<option value="7">E/Fb</option>
<option value="8">F</option>
<option value="9">F#/Gb</option>
<option value="10">G</option>
<option value="11">G#/Ab</option>
</select>
<label for "fretsNumber">number of frets</label>
<select name="fretsNumber" id="fretsNumber" onchange="fretsSet()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24" selected="selected">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
</select>
<a href="#" onclick="refresh()">refresh</a>
</div>
</div>
</div>
<script type="text/javascript">
// html elements
var table = document.getElementById("fretboard");
var scales = [
[1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0], // aeolian (natural minor)
[1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0], // locrian
[1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1], // ionian (major)
[1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0], // dorian
[1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0], // phrygian
[1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1], // lydian
[1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0], // mixolydian
]
var tunings = [
[7, 2, 10, 5, 0, 7], // standard (eadgbe)
[7, 2, 10, 5, 0, 5], // drop d (dadgbe)
[5, 2, 10, 5, 0, 5], // double drop d (dadgbd)
[5, 0, 10, 5, 0, 5], // celtic (dadgad)
]
var frets = 24;
/*
tuning
0 1 2 3 4 5 6 7 8 9 10 11
A A# B C C# D D# E F F# G G#
*/
var notes = ["A", "A#/Bb", "B/Cb", "C", "C#/Db", "D", "D#/Eb", "E/Fb", "F", "F#/Gb", "G", "G#/Ab"];
var scale = scales[0];
var tuning = [0, 0, 0, 0, 0, 0];
var rootNote = 0;
function arrayShift(array, shift) {
array = array.slice() // slice a copy of array element
if (shift < 0) {
for (var i = 0; i > shift; i--) {
array.push(array.shift()); // remove first element and replace it at end of array
}
} else {
for (var i = 0; i < shift; i++) {
array.unshift(array.pop()); // remove last element and replace it at beginning of array
}
}
return array
}
function scaleSet() {
elementScale = document.getElementById("scale");
scale = scales[elementScale.value].slice(); // slice copy of array element
populate();
}
function tuningSet() {
elementTuning = document.getElementById("tuning");
for (var i = 0; i < tableRowsStringsCount(); i++) {
var tuningCurrent = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[i].getElementsByTagName('select')[0];
tuningCurrent.selectedIndex = tunings[elementTuning.value][i]
}
populate();
}
function tuningStringUpdate(element) {
tuning[element.id] = element.value;
populate();
}
function rootNoteSet() {
elementRootNote = document.getElementById("rootNote");
rootNote = elementRootNote.value;
populate();
}
function depopulate() {
for (var i = 0; i < tableRowsStringsCount(); i++) {
for (var n = 0; n <= frets; n++) {
table.rows[i + 1].cells[n + 1].innerHTML = "";
}
}
}
function populate() {
depopulate();
/*
scaleCurrent is assigned by shifting the selected scale interval pattern array (major, minor, etc.)
until the start of the scale interval pattern is aligned to the position of the selected root note
in the set of static root notes:
0 1 2 3 4 5 6 7 8 9 10 11
a a# b c c# d d# e f f# g g#
if root note is a, then scale interval pattern will not shift. assuming major, the pattern is:
a a# b c c# d d# e f f# g g#
1 0 1 0 1 1 0 1 0 1 0 1
w w h w w w h (whole whole half whole whole whole half)
^ interval pattern starts
if root note is b, then scale interval pattern shifts 2 positions to the right:
a a# b c c# d d# e f f# g g#
0 1 1 0 1 0 1 1 0 1 0 1
h w w h w w w
^ interval pattern starts
if the root note is d, then the scale interval pattern will shift 5 to the right, and so on.
*/
scaleCurrent = arrayShift(scale, rootNote);
// loop through tuning array elements to determine the note layout for each string
for (var i = 0; i < tableRowsStringsCount(); i++) {
/*
scaleCurrentShifted is assigned by shifting scaleCurrent to the left x positions, where x is
equivalent to place value of string tuning. to demonstrate, assuming current root note of 'a',
and current scale of 'major', and current tuning of 'e a d g b e':
scaleCurrent:
a a# b c c# d d# e f f# g g#
1 0 1 0 1 1 0 1 0 1 0 1
^ interval pattern starts
shifting scale interval pattern left by value of 'e' (7), gives:
e f f# g g# a a# b c c# d d#
1 0 1 0 1 1 0 1 0 1 1 0
^ interval pattern starts
thus, scale patern is maintained relative to root note.
*/
var tuningCurrent = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[i].getElementsByTagName('select')[0].options[table.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[i].getElementsByTagName('select')[0].selectedIndex].value;
var scaleCurrentShifted = arrayShift(scaleCurrent, -tuningCurrent);
// place an x for each fret position belonging to the scale
for (var n = 0; n <= frets; n++) {
if (scaleCurrentShifted[0] == 1) {
table.rows[i + 1].cells[n + 1].innerHTML = "X";
}
/*
shift scaleCurrentShifted one to the left with each fret position processed
*/
scaleCurrentShifted = arrayShift(scaleCurrentShifted, -1);
}
}
}
function setup() {
for (var i = 0; i < 6; i++) {
tableRowsStringCreate();
}
fretsSet();
scaleSet();
tuningSet();
rootNoteSet();
}
function refresh() {
scaleSet();
tuningSet();
rootNoteSet();
}
/* html element creation */
function tableRowsStringsCount() {
return table.getElementsByTagName('tbody')[0].rows.length;
}
function tableCellsFretsCount() {
return table.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[0].cells.length;
}
function tableRowsStringCreate() {
var fretboard = document.getElementById('fretboard');
var rowsCount = tableRowsStringsCount('fretboard');
var tr = document.createElement('tr');
// tuning cell
var tdTuning = document.createElement('td');
var stringButtonRemove = document.createElement('input');
stringButtonRemove.type = 'button';
stringButtonRemove.value = 'x';
stringButtonRemove.onclick = function(){tableRowsStringRemove(tr)};
tdTuning.appendChild(stringButtonRemove);
tdTuning.appendChild(elementSelectTuningCreate(rowsCount));
tdTuning.className = 'tuning';
tr.appendChild(tdTuning);
// fret cells
for (var i = 0; i <= frets; i++) {
var trTd = document.createElement('td');
trTd.className = 'note';
tr.appendChild(trTd);
}
fretboard.getElementsByTagName('tbody')[0].appendChild(tr);
populate();
}
function tableRowsStringRemove(tr) {
tr.parentNode.removeChild(tr);
}
function elementSelectTuningCreate() {
var select = document.createElement('select');
var options = tuningOptionsPopulate();
for (var i = 0; i < options.length; i++) {
select.options[i] = options[i];
}
select.onchange = function(){tuningStringUpdate(select);};
return select;
}
function tuningOptionsPopulate() {
var tuningOptions = new Array();
for (var i = 0; i < notes.length; i++) {
tuningOptions[i] = new Option(notes[i], i);
}
return tuningOptions;
}
function fretsSet() {
frets = document.getElementById('fretsNumber').selectedIndex + 1;
var thead = fretboard.getElementsByTagName('thead')[0];
thead.innerHTML = "<tr></tr>";
var trTh = document.createElement('th');
thead.appendChild(trTh);
// fret header numbers
for (var i = 0; i <= frets; i++) {
var trTh = document.createElement('th');
trTh.innerHTML = i;
thead.appendChild(trTh);
}
tableCellsUpdate();
}
function tableCellsUpdate() {
var rowsCount = tableRowsStringsCount('fretboard');
var cellsCount = tableCellsFretsCount();
for (var i = 0; i < tableRowsStringsCount(); i++) {
var rowCurrent = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[i]
if (frets > cellsCount - 2) {
for (var n = cellsCount - 1; n <= frets; n++) {
var tdCurrent = document.createElement('td');
tdCurrent.className = 'note';
rowCurrent.appendChild(tdCurrent);
}
} else if (frets < cellsCount - 2) {
for (var n = cellsCount - 2; n > frets; n--) {
rowCurrent.removeChild(rowCurrent.getElementsByTagName('td')[n + 1]);
}
}
}
refresh();
}
</script>
</body>
</html>