-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsample_piano.html
75 lines (60 loc) · 2.75 KB
/
sample_piano.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="piano_style.css">
<title>Piano Keyboard</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="http://www.verovio.org/javascript/latest/verovio-toolkit-light.js" type="text/javascript" ></script>
<script src="piano.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
//create piano with 3 octaves, starting at C4 (lowest key)
//shows labels and octave shift buttons
var keyboardHTML = htmlForKeyboardWithOctaves(3, octaves.C4, true, true)
//render the keyboard in the div
$("#keyboardContainer").html(keyboardHTML)
//when keys are pressed updatePreview() is called
bindKeysToFunction(updatePreviewWithNote)
//when the clef is changed updatePreviewWithClef() is called
bindClefSelectionToFunction(updatePreviewWithClef)
//set the default clef to G4
setSelectedClef(clefs.G4)
$("#backspaceButton").click(deleteLast)
})
//this stores all keyboard input
var plaineEasieCodes = []
var selectedClef = clefs.G4
//this is called whenever a piano key is pressed
function updatePreviewWithNote(sender, paeNote) {
console.log("key pressed is " + paeNote)
plaineEasieCodes.push(paeNote)
updateNotesSVG()
}
//this is called when the user changes the clef for display
function updatePreviewWithClef(sender, clef) {
console.log("clef changed to " + clef)
selectedClef = clef
updateNotesSVG()
}
//delete last input
function deleteLast() {
plaineEasieCodes.pop()
updateNotesSVG()
}
function updateNotesSVG() {
//render the notes to an SVG using the Verovio tookit
//width of the svg is 800px and note scaling 50%
var notesSVG = svgNotesForPlaineEasieCode(plaineEasieCodes.join(""), selectedClef, 800, 50)
//insert thes SVG code in our div
var svgContainerDiv = $('#svgNotesContainer')
svgContainerDiv.html(notesSVG)
}
</script>
</head>
<body>
<div id="keyboardContainer"></div><!-- this will hold the keyboard -->
<div id="svgNotesContainer"></div><!-- this will hold the SVG with rendered notes -->
<button id="backspaceButton">Delete</button>
</body>
</html>