summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sensfreq/main.js22
1 files changed, 13 insertions, 9 deletions
diff --git a/sensfreq/main.js b/sensfreq/main.js
index 6dc431e..a50ae95 100644
--- a/sensfreq/main.js
+++ b/sensfreq/main.js
@@ -1,6 +1,7 @@
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
e = s => document.getElementById(s);
+n2n = n => ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"][n];
let ans = false;
let nq = 0;
@@ -9,23 +10,24 @@ let nc = 0;
function init()
{
e("gench").disabled = false;
- e("response").style.display="none";
+ e("response").style.display = "none";
+ e("prompt").innerHTML = " ";
reset_stats();
loadTheme();
}
function play_notes(freq, t, arpt)
{
- const stop_notes=function(g, o)
+ const stop_notes = function(g, o)
{
o.stop();
g.disconnect(audioCtx.destination);
o.disconnect(g);
}
- const play_note=function(f)
+ const play_note = function(f)
{
const gn = audioCtx.createGain();
- gn.gain.setValueAtTime(.5/freq.length, audioCtx.currentTime);
+ gn.gain.setValueAtTime(.5 / freq.length, audioCtx.currentTime);
gn.gain.linearRampToValueAtTime(0, audioCtx.currentTime + t / 1000.);
gn.connect(audioCtx.destination);
const osc = audioCtx.createOscillator();
@@ -39,7 +41,7 @@ function play_notes(freq, t, arpt)
freq.forEach(function(f){setTimeout(play_note.bind(null, f), arpt * (i++));});
}
-get_freq = n => 440 * Math.pow(Math.pow(2, 1./12), n-69)
+get_freq = n => 440 * Math.pow(Math.pow(2, 1. / 12), n - 69)
function generate_challenge()
{
@@ -71,20 +73,22 @@ function generate_challenge()
while (f.length < nnotes)
{
let n = Math.floor(Math.random() * (maxrange - minrange + 1)) + minrange;
- if (l.indexOf(n)!=-1)
+ if (l.indexOf(n) != -1)
continue;
ans |= ((n % 12) == Number(e("note").value));
f.push(get_freq(n));
}
- f.sort((a,b)=>a-b);
+ f.sort((a,b)=>a - b);
play_notes(f, 1000, e("arp").checked ? 50 : 0);
e("gench").disabled = true;
- e("response").style.display="";
+ e("response").style.display = "";
+ e("prompt").innerHTML = nnotes == 1 ? `Was the note you just heard ${n2n(Number(e("note").value))}?`
+ : `Did the chord you just heard contain the note ${n2n(Number(e("note").value))}?`;
}
function update_stats()
{
- e("stats").innerHTML=`You got ${nc} of the ${nq} challenges correct.`
+ e("stats").innerHTML = `You got ${nc} of the ${nq} challenges correct.`;
}
function reset_stats()