summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-09-20 23:54:36 -0400
committerJules Laplace <jules@okfoc.us>2016-09-20 23:54:36 -0400
commit6b05011c19d274aad88d03ab28b3a3635a746105 (patch)
tree53071ccd7241b33f17a074769ef57e9d8e962c03
parentda8b6b0bd537b32e13c08d46ca787975ed2ef058 (diff)
clicking note sets scale
-rw-r--r--index.html35
1 files changed, 20 insertions, 15 deletions
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( "<span>" + s.range( 0, limit+1).map(function(i){ return i.toFixed(0) }).join("</span> <span>") + "</span>" )
+ s.div.dataset.scale_index = i
write("&nbsp;")
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 ] )
}
})