| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
if (typeof abc2svg == "undefined") |
| 26 |
var abc2svg = {} |
| 27 |
|
| 28 |
abc2svg.capo = { |
| 29 |
|
| 30 |
icb40: [0, 5, 6,11,16,17,22,23,28,33,34,39], |
| 31 |
|
| 32 |
|
| 33 |
gch_build: function(of, s) { |
| 34 |
var t, i, gch, gch2, i2, |
| 35 |
abc = this, |
| 36 |
p_v = abc.get_curvoice(), |
| 37 |
a_gch = s.a_gch |
| 38 |
|
| 39 |
if (p_v.capo && a_gch) { |
| 40 |
t = p_v.capo |
| 41 |
i = 0 |
| 42 |
|
| 43 |
while (1) { |
| 44 |
gch = a_gch[i++] |
| 45 |
if (!gch) { |
| 46 |
of(s) |
| 47 |
return |
| 48 |
} |
| 49 |
if (gch.type == 'g') |
| 50 |
break |
| 51 |
} |
| 52 |
gch2 = Object.create(gch) |
| 53 |
gch2.capo = false |
| 54 |
gch2.text = abc.gch_tr1(gch2.text, -abc2svg.capo.icb40[t % 12]) |
| 55 |
if (!p_v.capo_first) { |
| 56 |
p_v.capo_first = true |
| 57 |
gch2.text += " (capo: " + t.toString() + ")" |
| 58 |
} |
| 59 |
|
| 60 |
gch2.font = abc.get_font(abc.cfmt().capofont ? |
| 61 |
"capo" : "annotation") |
| 62 |
a_gch.splice(i, 0, gch2) |
| 63 |
|
| 64 |
|
| 65 |
gch.capo = true |
| 66 |
} |
| 67 |
of(s) |
| 68 |
}, |
| 69 |
|
| 70 |
set_fmt: function(of, cmd, param) { |
| 71 |
if (cmd == "capo") { |
| 72 |
this.set_v_param("capo_", param) |
| 73 |
return |
| 74 |
} |
| 75 |
of(cmd, param) |
| 76 |
}, |
| 77 |
|
| 78 |
|
| 79 |
set_vp: function(of, a) { |
| 80 |
var i, v, |
| 81 |
p_v = this.get_curvoice() |
| 82 |
|
| 83 |
for (i = 0; i < a.length; i++) { |
| 84 |
if (a[i] == "capo_=") { |
| 85 |
v = Number(a[++i]) |
| 86 |
if (isNaN(v) || v <= 0) |
| 87 |
this.syntax(1, "Bad fret number in %%capo") |
| 88 |
else |
| 89 |
p_v.capo = v |
| 90 |
break |
| 91 |
} |
| 92 |
} |
| 93 |
of(a) |
| 94 |
}, |
| 95 |
|
| 96 |
set_hooks: function(abc) { |
| 97 |
abc.gch_build = abc2svg.capo.gch_build.bind(abc, abc.gch_build); |
| 98 |
abc.set_format = abc2svg.capo.set_fmt.bind(abc, abc.set_format) |
| 99 |
abc.set_vp = abc2svg.capo.set_vp.bind(abc, abc.set_vp) |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
if (!abc2svg.mhooks) |
| 104 |
abc2svg.mhooks = {} |
| 105 |
abc2svg.mhooks.capo = abc2svg.capo.set_hooks |