From 6b05011c19d274aad88d03ab28b3a3635a746105 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 20 Sep 2016 23:54:36 -0400 Subject: clicking note sets scale --- index.html | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index f61b858..d3af9ce 100644 --- a/index.html +++ b/index.html @@ -152,33 +152,36 @@ var opts = [ var scale, scales = [] var scale_list = document.querySelector("#scale_list") -opts.forEach(function(opt){ +opts.forEach(function(opt, i){ var s = new Intonation(opt) scales.push(s) - var heading = write( s.name ) var limit = s.interval == 2 ? s.scale.length : s.scale.length*2 + s.heading = write( s.name ) s.div = write( "" + s.range( 0, limit+1).map(function(i){ return i.toFixed(0) }).join(" ") + "" ) + s.div.dataset.scale_index = i write(" ") if (! scale) { - scale = s - heading.classList.add("active") - console.log(s) - console.log("scale:", s.name) + set_scale(s) } - heading.classList.add("heading") - heading.addEventListener("click", function(){ - var active = document.querySelector(".active") - active && active.classList.remove("active") - scale = s - heading.classList.add("active") - console.log(s) - console.log("scale:", s.name) + s.heading.classList.add("heading") + s.heading.addEventListener("click", function(){ + set_scale(s) }) }) +function set_scale (s) { + if (scale == s) return + var active = document.querySelector(".active") + active && active.classList.remove("active") + scale = s + s.heading.classList.add("active") + console.log(s) + console.log("scale:", s.name) +} + var polysynth = new Tone.PolySynth(8, Tone.synth) polysynth.set({ oscillator: { type: "sine" }, @@ -192,11 +195,13 @@ polysynth.set({ var comp = new Tone.Compressor(-30, 3).toMaster() polysynth.connect(comp) document.addEventListener("click", function(e){ - var span = e.currentTarget + var span = e.target val = span.innerHTML if (val && ! val.match(/[^0-9]/)) { var freq = parseInt(val) play(freq) + var div = span.parentNode + set_scale( scales[ div.dataset.scale_index ] ) } }) -- cgit v1.2.3-70-g09d2