OCTAVE = “A Bb B C Db D Eb E F Gb G Ab”.split(“ ”) window.capo = (chord, fret) ->
idx = OCTAVE.indexOf(chord[0..1]) start = 2 if idx < 0 idx = OCTAVE.indexOf(chord[0]) start = 1 throw new Exception("Unknown chord #{chord}") if idx < 0 return "#{OCTAVE[(idx + fret) % OCTAVE.length]}#{chord[start..-1]}"
window.transpose = (steps) ->
d3.selectAll(".chords").each (c) -> $(this).text $(this).text().replace(/[^\s]+/g, (t) -> capo(t, steps))
window.currentTranspose = 0 window.transposeUp = ->
window.currentTranspose += 1 window.transpose 1
window.transposeDown = ->
window.currentTranspose -= 1 window.transpose -1