-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableItems.js
108 lines (97 loc) · 3.18 KB
/
tableItems.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
function chordAction(){
var array = this.id.split("-");
var chord = parseInt(array[0]);
var inversion = parseInt(array[1]);
if(parseInt(array[2])){
playChord(chord, inversion);
}
else{
storeChord(chord, inversion);
}
}
function oneChordInfo(chordNumber, inversionIndex, table){
var scaleOffset = Math.floor(scaleNumber / 2);
var scaleInfo = allChordInfo[chordNumber];
var baseNumber = (Math.floor(chordNumber/2) - scaleOffset + 12) % 12;
var label, left, middle, right, leftNum, midNum, rightNum, modifier;
if(chordNumber % 2 == 0){
modifier = 4;
}else{
modifier = 3;
}
var labelStuff = ["Root:", "First Inversion:", "Second Inversion:"];
var scaleInfoStuff = [scaleInfo.root, scaleInfo.middle, scaleInfo.dominant];
var scaleNumberStuff = [baseNumber % 12, (baseNumber + modifier) % 12, (baseNumber + 7) % 12];
label = labelStuff[inversionIndex];
left = scaleInfoStuff[(0 + inversionIndex) % 3];
middle = scaleInfoStuff[(1 + inversionIndex) % 3];
right = scaleInfoStuff[(2 + inversionIndex) % 3];
leftNum = scaleNumberStuff[(0 + inversionIndex) % 3];
midNum = scaleNumberStuff[(1 + inversionIndex) % 3];
rightNum = scaleNumberStuff[(2 + inversionIndex) % 3];
row = document.createElement("tr");
var cell1 = document.createElement("td");
cell1.className = "left";
cell1.innerHTML = label;
var cell2 = document.createElement("td");
cell2.className = "center";
cell2.innerHTML = left;
var cell3 = document.createElement("td");
cell3.className = "center";
cell3.innerHTML = middle;
var cell4 = document.createElement("td");
cell4.className = "center";
cell4.innerHTML = right;
var cell5 = document.createElement("td");
cell5.className = "center";
cell5.id = chordNumber + "-" + inversionIndex + "-0";
cell5.onclick = chordAction;
cell5.innerHTML = "Add";
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
row.appendChild(cell5);
table.appendChild(row);
row = document.createElement("tr");
cell1 = document.createElement("td");
cell1.className = "left";
cell2 = document.createElement("td");
cell2.className = "center";
cell3 = document.createElement("td");
cell3.className = "center";
cell4 = document.createElement("td");
cell4.className = "center";
cell5 = document.createElement("td");
cell5.className = "center";
cell5.id = chordNumber + "-" + inversionIndex + "-1";
cell5.onclick = chordAction;
cell5.innerHTML = "Play";
cell1.innerHTML = "";
cell2.innerHTML = leftNum;
cell3.innerHTML = midNum;
cell4.innerHTML = rightNum;
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);
row.appendChild(cell5);
table.appendChild(row);
}
function getTableOfChordInfo(scaleNum)
{
var scaleInfo = allChordInfo[scaleNum];
var middleNumber = scaleNum % 2 == 0 ? 4 : 3;
var table = document.createElement("table");
table.className = "small";
var row = document.createElement("tr");
var headerCell = document.createElement("th");
headerCell.innerHTML = scaleInfo.name;
headerCell.className = "left";
row.appendChild(headerCell);
table.appendChild(row);
oneChordInfo(scaleNum, 0, table);
oneChordInfo(scaleNum, 1, table);
oneChordInfo(scaleNum, 2, table);
return table;
}