forked from infusionvlc/learnTheBeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
178 lines (154 loc) · 7.77 KB
/
index.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
<head>
<meta charset="ISO-8859-1">
<!-- CSS -->
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap core CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.13/css/mdb.min.css" rel="stylesheet">
<!-- -->
<!-- Javascript -->
<!-- JQuery -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.4/umd/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.13/js/mdb.min.js"></script>
<!-- -->
<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
<!--script src="https://jeromeetienne.github.io/AR.js/aframe/build/aframe-ar.js"></script-->
<script src="./vendor/aframe-ar.js"></script>
<script src="./js/vendor/aframe-stl-model-component.min.js" type="text/javascript"></script>
<script src="./vendor/STLLoader.js"></script>
<!-- polyfill -->
<script src="./MIDI/inc/shim/Base64.js" type="text/javascript"></script>
<script src="./MIDI/inc/shim/Base64binary.js" type="text/javascript"></script>
<script src="./MIDI/inc/shim/WebAudioAPI.js" type="text/javascript"></script>
<!-- midi.js package -->
<script src="./MIDI/js/midi/audioDetect.js" type="text/javascript"></script>
<script src="./MIDI/js/midi/gm.js" type="text/javascript"></script>
<script src="./MIDI/js/midi/loader.js" type="text/javascript"></script>
<script src="./MIDI/js/midi/plugin.audiotag.js" type="text/javascript"></script>
<script src="./MIDI/js/midi/plugin.webaudio.js" type="text/javascript"></script>
<script src="./MIDI/js/midi/plugin.webmidi.js" type="text/javascript"></script>
<!-- utils -->
<script src="./MIDI/js/util/dom_request_xhr.js" type="text/javascript"></script>
<script src="./MIDI/js/util/dom_request_script.js" type="text/javascript"></script>
<script src="./js/sound_note_system.js" type="text/javascript"></script>
<script src="./js/sound_note_component.js" type="text/javascript"></script>
</head>
<body style='margin : 0px; overflow: hidden;'>
<script>
window.onload = function() {
MIDI.loadPlugin({
soundfontUrl: "https://gleitz.github.io/midi-js-soundfonts/FluidR3_GM/",
instruments: [0, 21],
onprogress: function(state, progress) {
console.log(state, progress);
},
onsuccess: function() {
}
});
};
</script>
<div id="hook" style="position: fixed; top: 20px; font-size: 4em; color: white;"></div>
<a-scene embedded arjs='sourceType: webcam;' sound_note>
<a-assets>
<a-asset-item response-type="arraybuffer" id="note" src="./models/1la_chang.stl"></a-asset-item>
</a-assets>
<!-- add a simple camera -->
<a-entity camera></a-entity>
</a-scene>
<div style="margin: 0em; left: 2em; top: 2em; position: fixed;">
<div class="container">
<div class="row">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary active">
<input type="radio" name="options" id="option1" autocomplete="off" checked> Distancias
</label>
<label class="btn btn-secondary">
<input type="radio" name="options" id="option2" autocomplete="off"> Perfect Pitch
</label>
<label class="btn btn-secondary">
<input type="radio" name="options" id="option3" autocomplete="off"> Acordes
</label>
</div>
</div>
<div class="row">
<button id=gamePlayButton class="btn btn-primary" style="margin-left: 0; width: 110" onclick="startGame()"> PLAY </button>
<button id=gameStopButton class="btn btn-primary" style="margin-left: 0" onclick="stopGame()" disabled> STOP </button>
</div>
<div class="row" style="background-color: #d9534f; width: 150; align-items: center!important">
<div class="col-md-8" style="font-size: 10; align-items: center!important">
<h6 style="color: white; text-transform: uppercase; align-items: center!important; margin-bottom: 0px">Fails</h6>
</div>
<div class="col-md-1" style="color: white">
<span id="failsScore" ></span>
</div>
</div>
<div class="row" style="margin-top: 5; background-color: #28a745; width: 150; align-items: center!important">
<div class="col-md-8" style="font-size: 10; align-items: center!important; width: 100">
<h6 style="color: white; text-transform: uppercase; align-items: center!important; margin-bottom: 0px">CORRECTS</h6>
</div>
<div class="col-md-1" style="color:white; width: 30">
<span id="corretsScore" ></span>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
var Ongame=false;
//var notes_list = ['dob3', 'do3', 'reb3', 'reb3', 're3', 'mib3', 'mib3', 'mi3', 'fa3', 'solb3', 'solb3','sol3', 'lab3', 'lab3', 'la3', 'sib3', 'sib3', 'si3'];
//var notes_marks = ['dob', 'do', 'do\#', 'reb', 're', 're\#', 'mib', 'mi', 'fa', 'fa\#', 'solb', 'sol', 'sol\#', 'lab', 'la', 'la\#', 'sib', 'si'];
var notes_list = ['dob3', 'do3', 'reb3', 're3', 'mib3', 'mi3', 'fa3', 'solb3','sol3', 'lab3', 'la3', 'sib3', 'si3'];
var notes_marks = ['dob', 'do', 'reb', 're', 'mib', 'mi', 'fa', 'solb', 'sol', 'lab', 'la', 'sib', 'si'];
var sceneEl = document.querySelector('a-scene');
for (let i = 0; i < notes_marks.length; i++){
console.log(i)
let entityEl = document.createElement('a-marker');
entityEl.setAttribute('type', 'pattern');
entityEl.setAttribute('url', './patterns/patt/' + notes_marks[i] + '.patt');
// entityEl.setAttribute('emitevents', 'true');
let subEntityEl = document.createElement('a-entity');
subEntityEl.setAttribute('position', '0 0.5 0');
subEntityEl.setAttribute('material', 'color: red');
console.log(notes_list[i]);
subEntityEl.setAttribute('sound_note', 'instrument: acoustic_grand_piano; note: ' + notes_list[i] + '');
subEntityEl.innerHTML = '<a-animation attribute="rotation" easing="linear" dur="10000" fill="forwards" to="0 360 0" repeat="indefinite"></a-animation>';
entityEl.appendChild(subEntityEl);
//entityEl.innerHTML = subEntityEl.outerHTML;
sceneEl.appendChild(entityEl);
}
function startGame(){
Ongame=true;
document.getElementById("gamePlayButton").disabled = true;
document.getElementById("gameStopButton").disabled = false;
var system = document.querySelector('a-scene').systems['sound_note'];
cambiarNota(system);
}
function cambiarNota( system){
var note_name = notes_list[Math.floor(Math.random()*notes_list.length)]
current_note = notes[note_name];
system.play_sound(current_note);
console.log(""+current_note);
fails = 0;
//corrects = 0;
}
function stopGame(){
Ongame=false;
document.getElementById("gameStopButton").disabled = true;
document.getElementById("gamePlayButton").disabled = false;
fails = 0;
corrects = 0;
document.getElementById('failsScore').innerHTML= fails;
document.getElementById('corretsScore').innerHTML= corrects;
current_note = -1;
}
document.getElementById('failsScore').innerHTML= fails;
document.getElementById('corretsScore').innerHTML= corrects;
</script>