-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
290 lines (248 loc) · 9.08 KB
/
script.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
const A_chord = new Audio("sounds/A_chord.mp3");
const Am_chord = new Audio("sounds/Am_chord.mp3");
const Ab_chord = new Audio("sounds/Ab_chord.mp3");
const Abm_chord = new Audio("sounds/Abm_chord.mp3");
const B_chord = new Audio("sounds/B_chord.mp3");
const Bm_chord = new Audio("sounds/Bm_chord.mp3");
const Bb_chord = new Audio("sounds/Bb_chord.mp3");
const Bbm_chord = new Audio("sounds/Bbm_chord.mp3");
const C_chord = new Audio("sounds/C_chord.mp3");
const Cm_chord = new Audio("sounds/Cm_chord.mp3");
const Cb_chord = new Audio("sounds/Cb_chord.mp3");
const Cbm_chord = new Audio("sounds/Cbm_chord.mp3");
const D_chord = new Audio("sounds/D_chord.mp3");
const Dm_chord = new Audio("sounds/Dm_chord.mp3");
const Db_chord = new Audio("sounds/Db_chord.mp3");
const Dbm_chord = new Audio("sounds/Dbm_chord.mp3");
const E_chord = new Audio("sounds/E_chord.mp3");
const Em_chord = new Audio("sounds/Em_chord.mp3");
const Eb_chord = new Audio("sounds/Eb_chord.mp3");
const Ebm_chord = new Audio("sounds/Ebm_chord.mp3");
const F_chord = new Audio("sounds/F_chord.mp3");
const Fm_chord = new Audio("sounds/Fm_chord.mp3");
const Fb_chord = new Audio("sounds/Fb_chord.mp3");
const Fbm_chord = new Audio("sounds/Fbm_chord.mp3");
const G_chord = new Audio("sounds/G_chord.mp3");
const Gm_chord = new Audio("sounds/Gm_chord.mp3");
const Gb_chord = new Audio("sounds/Gb_chord.mp3");
const Gbm_chord = new Audio("sounds/Gbm_chord.mp3");
const playSound = audio => {
const clone = audio.cloneNode();
clone.play();
};
function change(id1, id2) {
document.getElementById(id1).style.display="none";
document.getElementById(id2).style.display="block";
}
// All the scales (If len(element) == 2, element % 10 -> concatenate 'm' to the element )
var scales_dict = {
"warmstop":[0, 95, 3, 93],
"tay-tay":[0, 95, 3, 4],
"satellite-foot":[0, 93, 95, 93],
"idk-my-name":[0, 3, 95, 4],
"iconic":[4, 92, 95, 1],
"basic":[0, 4, 95, 3],
"bittersweet":[0, 3, 93, 0],
"hopeful":[95, 3, 0, 4],
"happy":[0, 3, 4, 4]
};
// All of the chord progressions (Make the chord progressions easier for the computer to read)
var chords_dict = {
"key-of-c":["C", "D", "E", "F", "G", "A", "B"],
"key-of-c#/db":["Db", "Eb", "Fb", "Gb", "Ab", "Bb", "Cb"],
"key-of-d":["D", "E", "Gb", "G", "A", "B", "Db"],
"key-of-d#/eb":["Eb", "F", "G", "Ab", "Bb", "C", "D"],
"key-of-e":["E", "Gb", "Ab", "A", "B", "Db", "Eb"],
"key-of-f":["F", "G", "A", "Bb", "C", "D", "E"],
"key-of-f#/gb":["Gb", "Ab", "Bb", "Cb", "Db", "Eb", "F"],
"key-of-g":["G", "A", "B", "C", "D", "E", "Gb"],
"key-of-g#/ab":["Ab", "Bb", "C", "Db", "Eb", "F", "G"],
"key-of-a":["A", "B", "Db", "D", "E", "Gb", "Ab"],
"key-of-a#/bb":["Bb", "C", "D", "Eb", "F", "G", "A"],
"key-of-b":["B", "Db", "Eb", "E", "Gb", "Ab", "Bb"]
};
const A_chordKey = document.querySelector(".A_chord-key");
const playA = () => {
playSound(A_chord);
};
A_chordKey.addEventListener("submit", playA, true);
const Am_chordKey = document.querySelector(".Am_chord-key");
const playAm = () => {
playSound(Am_chord);
};
Am_chordKey.addEventListener("submit", playAm, true);
const Ab_chordKey = document.querySelector(".Ab_chord-key");
const playAb = () => {
playSound(Ab_chord);
};
Ab_chordKey.addEventListener("submit", playAb, true);
const Abm_chordKey = document.querySelector(".Abm_chord-key");
const playAbm = () => {
playSound(Abm_chord);
};
Abm_chordKey.addEventListener("submit", playAbm, true);
const B_chordKey = document.querySelector(".B_chord-key");
const playB = () => {
playSound(B_chord);
};
B_chordKey.addEventListener("submit", playB, true);
const Bm_chordKey = document.querySelector(".Bm_chord-key");
const playBm = () => {
playSound(Bm_chord);
};
Bm_chordKey.addEventListener("submit", playBm, true);
const Bb_chordKey = document.querySelector(".Bb_chord-key");
const playBb = () => {
playSound(Bb_chord);
};
Bb_chordKey.addEventListener("submit", playBb, true);
const Bbm_chordKey = document.querySelector(".Bbm_chord-key");
const playBbm = () => {
playSound(Bbm_chord);
};
Bbm_chordKey.addEventListener("submit", playBbm, true);
const C_chordKey = document.querySelector(".C_chord-key");
const playC = () => {
playSound(C_chord);
};
C_chordKey.addEventListener("submit", playC, true);
const Cm_chordKey = document.querySelector(".Cm_chord-key");
const playCm = () => {
playSound(Cm_chord);
};
Cm_chordKey.addEventListener("submit", playCm, true);
const Cb_chordKey = document.querySelector(".Cb_chord-key");
const playCb = () => {
playSound(Cb_chord);
};
Cb_chordKey.addEventListener("submit", playCb, true);
const Cbm_chordKey = document.querySelector(".Cbm_chord-key");
const playCbm = () => {
playSound(Cbm_chord);
};
Cbm_chordKey.addEventListener("submit", playCbm, true);
const D_chordKey = document.querySelector(".D_chord-key");
const playD = () => {
playSound(D_chord);
};
D_chordKey.addEventListener("submit", playD, true);
const Dm_chordKey = document.querySelector(".Dm_chord-key");
const playDm = () => {
playSound(Dm_chord);
};
Dm_chordKey.addEventListener("submit", playDm, true);
const Db_chordKey = document.querySelector(".Db_chord-key");
const playDb = () => {
playSound(Db_chord);
};
Db_chordKey.addEventListener("submit", playDb, true);
const Dbm_chordKey = document.querySelector(".Dbm_chord-key");
const playDbm = () => {
playSound(Dbm_chord);
};
Dbm_chordKey.addEventListener("submit", playDbm, true);
const E_chordKey = document.querySelector(".E_chord-key");
const playE = () => {
playSound(E_chord);
};
E_chordKey.addEventListener("submit", playE, true);
const Em_chordKey = document.querySelector(".Em_chord-key");
const playEm = () => {
playSound(Em_chord);
};
Em_chordKey.addEventListener("submit", playEm, true);
const Eb_chordKey = document.querySelector(".Eb_chord-key");
const playEb = () => {
playSound(Eb_chord);
};
Eb_chordKey.addEventListener("submit", playEb, true);
const Ebm_chordKey = document.querySelector(".Ebm_chord-key");
const playEbm = () => {
playSound(Ebm_chord);
};
Ebm_chordKey.addEventListener("submit", playEbm, true);
const F_chordKey = document.querySelector(".F_chord-key");
const playF = () => {
playSound(F_chord);
};
F_chordKey.addEventListener("submit", playF, true);
const Fm_chordKey = document.querySelector(".Fm_chord-key");
const playFm = () => {
playSound(Fm_chord);
};
Fm_chordKey.addEventListener("submit", playFm, true);
const Fb_chordKey = document.querySelector(".Fb_chord-key");
const playFb = () => {
playSound(Fb_chord);
};
Fb_chordKey.addEventListener("submit", playFb, true);
const Fbm_chordKey = document.querySelector(".Fbm_chord-key");
const playFbm = () => {
playSound(Fbm_chord);
};
Fbm_chordKey.addEventListener("submit", playFbm, true);
const G_chordKey = document.querySelector(".G_chord-key");
const playG = () => {
playSound(G_chord);
};
G_chordKey.addEventListener("submit", playG, true);
const Gm_chordKey = document.querySelector(".Gm_chord-key");
const playGm = () => {
playSound(Gm_chord);
};
Gm_chordKey.addEventListener("submit", playGm, true);
const Gb_chordKey = document.querySelector(".Gb_chord-key");
const playGb = () => {
playSound(Gb_chord);
};
Gb_chordKey.addEventListener("submit", playGb, true);
const Gbm_chordKey = document.querySelector(".Gbm_chord-key");
const playGbm = () => {
playSound(Gbm_chord);
};
Gbm_chordKey.addEventListener("submit", playGbm, true);
// Initializes the form variable, to be used later when pulling user input
var form = document.getElementById("the-form");
let chord_funcs = []
// Initializes the submit function with the event parameter; this'll be the function that will pull
// user-inputted elements from the form.
function submit(event) {
var key = document.getElementById('key');
var chords = document.getElementById('chords');
let progression = [];
for (let i = 0; i < 4; i++) {
if (scales_dict[chords.value.toString()][i].toString().length == 2){
progression.push(chords_dict[key.value.toString()][scales_dict[chords.value.toString()][i] % 10] + "m");
} else {
progression.push(chords_dict[key.value.toString()][scales_dict[chords.value.toString()][i]]);
}
}
document.getElementById("the-progression").innerHTML = progression.join(" ");
for (let i = 0; i < 4; i++) {
chord_funcs.push('play' + progression[i]);
}
change("home-page", "result");
event.preventDefault();
}
// 'Listens' for when the user submits the form, then calls the submit(event) function.
form.addEventListener("submit", submit, true)
function man_click() {
start_playing.addEventListener("click", play_chords, true);
start_playing.click()
}
var start_playing = document.getElementById("play-chords");
function play_chords(event) {
start_playing.removeEventListener("click", play_chords, true);
setTimeout(eval(chord_funcs[0]), 1);
setTimeout(eval(chord_funcs[1]), 2424);
setTimeout(eval(chord_funcs[2]), 4810);
setTimeout(eval(chord_funcs[3]), 7210);
setTimeout(man_click, 9588);
event.preventDefault();
}
start_playing.addEventListener("click", play_chords, true);
var stop_playing = document.getElementById("refresh");
function refresh() {
location.reload();
}
stop_playing.addEventListener("click", refresh, true);