-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
272 lines (235 loc) · 6.76 KB
/
index.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
// tum hi ho
// let notes ="e ab bf fe dc df ee dd cd d c bgg aa eea bbf fe dc dfee cdd d c d dcbg gaa cd e c d cd e c d bdc ba b g a e cd cd e cd bb dc ba b g a";
//jodi tr dak sune keo
// var notes =
// "bb b c cd d g fe dc de ed c bb b c cd d g fe dc de ed c fg gg fg ga# a#g fe de de ed c bb b c cd d g fe dc de ed c ff f ga a# g cc dg a a# agagf ga a# g ff fg g#a# a# g#gf fg aa# g ff fg g#a# a# g#gf fg aa# g ff fg aa# a# a a a#a# a aa# ag ga ag f";
//sare jaha se achha
// var notes ="g gf# ef# d# ee ed#c#b bc#e f#g# ag# ag#f#e g gf# ef# d# ee ed#c#b";
//Happy Birthday
// var notes ="aa bad c#"
// sare ga ma pa
// var notes ="c d e f g a b s s b a g f e d c";
// sare ga ma pa sharp
// var notes ="c# d# e# f# g# a# b# s# s# b# a# g# f# e# d# c#";
const inputBox = document.querySelector(".inputField input");
const addBtn = document.querySelector(".inputField button");
var notes;
var r = false;
$("#start").click(function () {
var mybutton = $(this);
mybutton.prop("disabled", true);
setTimeout(function () {
notes = inputBox.value;
r = false;
auto_Read_play(notes);
}, 1000);
setTimeout(function () {
mybutton.prop("disabled", false);
}, 4000);
});
inputBox.onclick = () => {
r = true;
};
function setCharAt(str, index, chr) {
if (index > str.length - 1) return str;
return str.substring(0, index) + chr + str.substring(index + 1);
}
function auto_Read_play(notes) {
var copy_notes = " ";
for (let i = 0; i < notes.length; i++) {
if (notes[i + 1] == "#") {
var x = notes[i].toUpperCase();
notes = setCharAt(notes, i, x);
copy_notes = copy_notes + notes[i];
} else if (notes[i] != "#") copy_notes = copy_notes + notes[i];
}
for (let i = 0; i < copy_notes.length; i++) {
document.getElementById("stop").onclick = () => {
window.location.reload();
};
task(i);
}
function task(i) {
setTimeout(function () {
var btnclick = document.getElementById(copy_notes[i]);
btnclick.classList.add("active");
setTimeout(function () {
btnclick.classList.remove("active");
}, 100);
makeSound(copy_notes[i]);
}, 320 * i);
}
}
//black
var numberOfDrumButtons = document.querySelectorAll(".black").length;
for (var i = 0; i < numberOfDrumButtons; i++) {
document.querySelectorAll(".black")[i].addEventListener("click", function () {
var buttonInnerHTML = this.innerHTML;
makeSound(buttonInnerHTML);
});
}
//white
var numberOfDrumButtons = document.querySelectorAll(".white").length;
for (var i = 0; i < numberOfDrumButtons; i++) {
document.querySelectorAll(".white")[i].addEventListener("click", function () {
var buttonInnerHTML = this.innerHTML;
makeSound(buttonInnerHTML);
});
}
var allowed = true;
$(document).keypress(function (event) {
if (event.repeat != undefined) {
allowed = !event.repeat;
}
if (!allowed) return;
allowed = false;
if (event.keyCode == 32) return;
$("h2").css("visibility", "visible");
$("h2").text(event.key);
});
$(document).keyup(function (e) {
allowed = true;
});
$(document).focus(function (e) {
allowed = true;
});
$(document).keyup(function (event) {
$("h2").css("visibility", "hidden");
});
document.addEventListener("keydown", (e) => {
if (r == false) {
if (e.repeat) return;
var btnclick = document.getElementById(e.key);
btnclick.classList.add("active");
makeSound(e.key);
}
});
document.addEventListener("keyup", (e) => {
var btnclick = document.getElementById(e.key);
btnclick.classList.remove("active");
});
document.addEventListener("keyup", (e) => {
var btnclick = document.getElementById(e.key);
btnclick.classList.remove("active");
});
function makeSound(key) {
switch (key) {
case "c":
var piano1 = new Audio("Steinway_Grand/c3.mp3");
piano1.play();
break;
case "d":
var piano2 = new Audio("Steinway_Grand/d3.mp3");
piano2.play();
break;
case "e":
var piano3 = new Audio("Steinway_Grand/e3.mp3");
piano3.play();
break;
case "f":
var piano4 = new Audio("Steinway_Grand/f3.mp3");
piano4.play();
break;
case "g":
var piano5 = new Audio("Steinway_Grand/g3.mp3");
piano5.play();
break;
case "a":
var piano6 = new Audio("Steinway_Grand/a3.mp3");
piano6.play();
break;
case "b":
var piano7 = new Audio("Steinway_Grand/b3.mp3");
piano7.play();
break;
case "s":
var piano15 = new Audio("Steinway_Grand/c4.mp3");
piano15.play();
break;
//Steinway_Grand
case "C":
var piano8 = new Audio("Steinway_Grand/cs3.mp3");
piano8.play();
break;
case "D":
var piano9 = new Audio("Steinway_Grand/ds3.mp3");
piano9.play();
break;
case "E":
var piano10 = new Audio("Steinway_Grand/f3.mp3");
piano10.play();
break;
case "F":
var piano11 = new Audio("Steinway_Grand/fs3.mp3");
piano11.play();
break;
case "G":
var piano12 = new Audio("Steinway_Grand/gs3.mp3");
piano12.play();
break;
case "A":
var piano13 = new Audio("Steinway_Grand/as3.mp3");
piano13.play();
break;
case "B":
var piano14 = new Audio("Steinway_Grand/c4.mp3");
piano14.play();
break;
case "S":
var piano15 = new Audio("Steinway_Grand/cs4.mp3");
piano15.play();
break;
case ".":
alert("This is just a dummy key");
break;
default:
console.log(key);
}
}
function preloaderFadeOutInit() {
$(".loader").fadeOut("slow");
$("body").attr("id", "");
}
// Window load function
jQuery(window).on("load", function () {
(function ($) {
preloaderFadeOutInit();
})(jQuery);
});
// var notes ="g gf# ef# d# ee ed#c#b bc#e f#g# ag# ag#f#e g gf# ef# d# ee ed#c#b";
// var notes ="c# d# e# f# g# a# b# s# s# b# a# g# f# e# d# c#";
// var notes = "c#d# e# f# g# a# b# s# s# b# a# g# f# e# d# c#";
// alert(notes);
// var copy_notes = [];
// for (let i = 0; i < notes.length; i++) {
// if (notes[i+1] == '#') {
// var x = notes[i].toUpperCase();
// notes = setCharAt(notes, i, x);
// if(notes[i]=='c')
// {
// alert("space");
// copy_notes=copy_notes+" a";
// }
// else
// copy_notes=copy_notes+notes[i]+" ";
// }
// else if(notes[i]!='#')
// copy_notes=copy_notes+notes[i];
// }
// // alert(copy_notes);
// function auto_Read_play() {
// for (let i = 0; i < copy_notes.length; i++) {
// task(i);
// }
// function task(i) {
// setTimeout(function () {
// var btnclick = document.getElementById(copy_notes[i]);
// btnclick.classList.add("active");
// setTimeout(function () {
// btnclick.classList.remove("active");
// }, 100);
// makeSound(copy_notes[i]);
// }, 450 * i);
// }
// }
// auto_Read_play();