1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 window.onload = function() {
8 // Create objects, makes sure that all the audio gets loaded.
9 gSounds.c1 = new Audio("sound/piano_c1.opus");
10 gSounds.d1 = new Audio("sound/piano_d1.opus");
11 gSounds.e1 = new Audio("sound/piano_e1.opus");
12 gSounds.f1 = new Audio("sound/piano_f1.opus");
13 gSounds.g1 = new Audio("sound/piano_g1.opus");
14 gSounds.a1 = new Audio("sound/piano_a1.opus");
15 gSounds.b1 = new Audio("sound/piano_b1.opus");
16 gSounds.c2 = new Audio("sound/piano_c2.opus");
18 document.getElementById("body").addEventListener("keydown", eventHandler, false);
22 handleEvent: function(aEvent) {
23 switch (aEvent.type) {
25 // Should use aEvent.key instead of aEvent.which but needs bug 680830.
26 // See https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/keydown
27 switch (aEvent.which) {
52 default: // not supported
53 console.log("key not supported: " + aEvent.which);
61 play: function(aPitchName) {
62 gPitches.flash(aPitchName);
63 var pitchSound = new Audio(gSounds[aPitchName].src);
67 flash: function(aPitchName) {
68 document.getElementById(aPitchName + "-upper").classList.add("active");
69 document.getElementById(aPitchName + "-lower").classList.add("active");
70 setTimeout(gPitches.unflash, 200, aPitchName);
73 unflash: function(aPitchName) {
74 document.getElementById(aPitchName + "-upper").classList.remove("active");
75 document.getElementById(aPitchName + "-lower").classList.remove("active");
79 function toggleHelp() {
80 document.getElementById("helpdesc").classList.toggle("hidden");