| 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 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
if (typeof abc2svg == "undefined") |
| 34 |
var abc2svg = {} |
| 35 |
|
| 36 |
abc2svg.chordnames = { |
| 37 |
|
| 38 |
gch_build: function(of, s) { |
| 39 |
var gch, ix, t, |
| 40 |
cfmt = this.cfmt() |
| 41 |
|
| 42 |
if (s.a_gch && cfmt.chordnames) { |
| 43 |
for (ix = 0; ix < s.a_gch.length; ix++) { |
| 44 |
gch = s.a_gch[ix] |
| 45 |
t = gch.text |
| 46 |
if (gch.type != 'g' || !t) |
| 47 |
continue |
| 48 |
if (t[0] == 'n' || t[0] == 'N') |
| 49 |
t = 'N' |
| 50 |
gch.text = t.replace(cfmt.chordnames.re, |
| 51 |
function(c){return cfmt.chordnames.o[c]}) |
| 52 |
} |
| 53 |
} |
| 54 |
of(s) |
| 55 |
}, |
| 56 |
|
| 57 |
gimpl: 'CDEFGABN', |
| 58 |
set_fmt: function(of, cmd, parm) { |
| 59 |
var i, v, |
| 60 |
re = [], |
| 61 |
o = {}, |
| 62 |
cfmt = this.cfmt() |
| 63 |
|
| 64 |
if (cmd == "chordnames") { |
| 65 |
parm = parm.split(',') |
| 66 |
if (parm[0].indexOf(':') > 0) { |
| 67 |
for (i = 0; i < parm.length; i++) { |
| 68 |
v = parm[i].split(':') |
| 69 |
if (!v[1]) |
| 70 |
continue |
| 71 |
o[v[0]] = v[1] |
| 72 |
re.push(v[0]) |
| 73 |
} |
| 74 |
} else { |
| 75 |
for (i = 0; i < parm.length; i++) { |
| 76 |
v = abc2svg.chordnames.gimpl[i] |
| 77 |
o[v] = parm[i] |
| 78 |
re.push(v) |
| 79 |
} |
| 80 |
} |
| 81 |
cfmt.chordnames = {re: new RegExp(re.join('|'), 'g'), o: o} |
| 82 |
return |
| 83 |
} |
| 84 |
of(cmd, parm) |
| 85 |
}, |
| 86 |
|
| 87 |
set_hooks: function(abc) { |
| 88 |
abc.gch_build = abc2svg.chordnames.gch_build.bind(abc, abc.gch_build) |
| 89 |
abc.set_format = abc2svg.chordnames.set_fmt.bind(abc, abc.set_format) |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
if (!abc2svg.mhooks) |
| 94 |
abc2svg.mhooks = {} |
| 95 |
abc2svg.mhooks.chordnames = abc2svg.chordnames.set_hooks |