App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/res/abc/abc2svg/capo-1.js view on Meta::CPAN
var abc2svg = {}
abc2svg.capo = {
// b40 intervals of capo
icb40: [0, 5, 6,11,16,17,22,23,28,33,34,39],
// e f ^f g _a a _b b c _d d _e
gch_build: function(of, s) {
var t, i, gch, gch2, i2,
abc = this,
p_v = abc.get_curvoice(),
a_gch = s.a_gch
if (p_v.capo && a_gch) {
t = p_v.capo
i = 0
while (1) {
gch = a_gch[i++]
if (!gch) {
of(s)
return
}
if (gch.type == 'g')
break
}
gch2 = Object.create(gch)
gch2.capo = false // (would be erased when setting gch)
gch2.text = abc.gch_tr1(gch2.text, -abc2svg.capo.icb40[t % 12])
if (!p_v.capo_first) { // if new voice
p_v.capo_first = true
gch2.text += " (capo: " + t.toString() + ")"
}
gch2.font = abc.get_font(abc.cfmt().capofont ?
"capo" : "annotation")
a_gch.splice(i, 0, gch2)
// set a mark in the first chord symbol for %%diagram
gch.capo = true
}
of(s)
},
set_fmt: function(of, cmd, param) {
if (cmd == "capo") {
this.set_v_param("capo_", param)
return
}
of(cmd, param)
},
// get the parameters of the current voice
set_vp: function(of, a) {
var i, v,
p_v = this.get_curvoice()
for (i = 0; i < a.length; i++) {
if (a[i] == "capo_=") {
v = Number(a[++i])
if (isNaN(v) || v <= 0)
this.syntax(1, "Bad fret number in %%capo")
else
p_v.capo = v
break
}
}
of(a)
}, // set_vp()
set_hooks: function(abc) {
abc.gch_build = abc2svg.capo.gch_build.bind(abc, abc.gch_build);
abc.set_format = abc2svg.capo.set_fmt.bind(abc, abc.set_format)
abc.set_vp = abc2svg.capo.set_vp.bind(abc, abc.set_vp)
}
} // capo
if (!abc2svg.mhooks)
abc2svg.mhooks = {}
abc2svg.mhooks.capo = abc2svg.capo.set_hooks
( run in 1.345 second using v1.01-cache-2.11-cpan-140bd7fdf52 )