-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notenleer.html
151 lines (123 loc) · 5.27 KB
/
Notenleer.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
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vexflow@4.0.3/build/cjs/vexflow.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha2/dist/js/bootstrap.bundle.min.js" integrity="sha384-qKXV1j0HvMUeCBQ+QVp7JcfGl760yU08IQ+GpUo5hlbpg51QRiuqHAJz8+BrxE/N" crossorigin="anonymous"></script>
</head>
<body>
<div class="col-lg-8 mx-auto p-4 py-md-5">
<header class="d-flex align-items-center pb-3 mb-5 border-bottom">
<span class="fs-4">Notenleer</span>
</header>
<main>
<div class="container">
<div class="row justify-content-md-center" style="height:50px">
<center>
<h1 id="feedback"></h1>
</center>
</div>
<div class="row justify-content-md-center">
<center>
<div id="output"></div>
</center>
</div>
<div class="row justify-content-md-center">
<center>
<button id="0" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Lage La</button>
<button id="1" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Lage Si</button>
<button id="2" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Do</button>
<button id="3" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Re</button>
<button id="4" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Mi</button>
<button id="5" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Fa</button>
<button id="6" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Sol</button>
<button id="7" onclick="checkNote(this.id)" class="btn btn-primary" type="button">La</button>
<button id="8" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Si</button>
<button id="9" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Hoge Do</button>
<button id="10" onclick="checkNote(this.id)" class="btn btn-primary" type="button">Hoge Re</button>
</center>
</div>
</div>
</main>
<footer class="pt-5 my-5 text-body-secondary border-top">
</footer>
</div>
<script>
const { Renderer, Stave ,StaveNote, Voice, Formatter } = Vex.Flow;
// Create an SVG renderer and attach it to the DIV element named "boo".
const div = document.getElementById("output");
const renderer = new Renderer(div, Renderer.Backends.SVG);
// Configure the rendering context.
renderer.resize(500, 250);
const context = renderer.getContext();
// Create a stave of width 400 at position 10, 40 on the canvas.
const stave = new Stave(10, 40, 400);
// Add a clef and time signature.
stave.addClef("treble")//.addTimeSignature("4/4");
const allNotes = [
new StaveNote({ keys: ["a/3"], duration: "h" }),
new StaveNote({ keys: ["b/3"], duration: "h" }),
new StaveNote({ keys: ["c/4"], duration: "h" }),
new StaveNote({ keys: ["d/4"], duration: "h" }),
new StaveNote({ keys: ["e/4"], duration: "h" }),
new StaveNote({ keys: ["f/4"], duration: "h" }),
new StaveNote({ keys: ["g/4"], duration: "h" }),
new StaveNote({ keys: ["a/4"], duration: "h" }),
new StaveNote({ keys: ["b/4"], duration: "h" }),
new StaveNote({ keys: ["c/5"], duration: "h" }),
new StaveNote({ keys: ["d/5"], duration: "h" }),
];
var pick = 0;
function pickOne() {
var n = Math.floor(Math.random()*allNotes.length);
while(n == pick) {
n = Math.floor(Math.random()*allNotes.length)
}
pick = n;
var item = allNotes[pick];
showNotes([item]);
}
function checkNote(id) {
if(parseInt(id) == pick) {
document.getElementById("feedback").innerHTML = "Correct!";
setTimeout(function () {
document.getElementById("feedback").innerHTML = "";
pickOne();
}, 1000);
} else {
document.getElementById("feedback").innerHTML = "Probeer nog eens!";
setTimeout(function () {
document.getElementById("feedback").innerHTML = "";
}, 1000);
}
}
function showNotes(notes) {
renderer.ctx.clear()
stave.setContext(context).draw();
// Create a voice in 4/4 and add above notes
const voice = new Voice({ num_beats: 24, beat_value: 4 });
voice.addTickables(notes);
voice.mode = Voice.Mode.SOFT;
showVoice(voice,stave);
}
function showVoice(voice,stave) {
// Format and justify the notes to 400 pixels.
new Formatter().joinVoices([voice]).format([voice], 350);
voice.draw(context, stave);
}
showNotes( [
new StaveNote({ keys: ["a/3"], duration: "h" }),
new StaveNote({ keys: ["b/3"], duration: "h" }),
new StaveNote({ keys: ["c/4"], duration: "h" }),
new StaveNote({ keys: ["d/4"], duration: "h" }),
new StaveNote({ keys: ["e/4"], duration: "h" }),
new StaveNote({ keys: ["f/4"], duration: "h" }),
new StaveNote({ keys: ["g/4"], duration: "h" }),
new StaveNote({ keys: ["a/4"], duration: "h" }),
new StaveNote({ keys: ["b/4"], duration: "h" }),
new StaveNote({ keys: ["c/5"], duration: "h" }),
new StaveNote({ keys: ["d/5"], duration: "h" }),
]);
pickOne();
</script>
</body>
</html>