| 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 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
if (typeof abc2svg == "undefined") |
| 45 |
var abc2svg = {} |
| 46 |
|
| 47 |
abc2svg.diag = { |
| 48 |
|
| 49 |
cd4: {}, |
| 50 |
|
| 51 |
cd6: { |
| 52 |
C: "x32010 ,0 x32010", |
| 53 |
Cm: "x03320 fr3 x03420 barre=5-1", |
| 54 |
C7: "x32310 ,0 x32410", |
| 55 |
Cm7: "003020 fr3 x03020 barre=5-1", |
| 56 |
CM7: "032000 ,0 x21000", |
| 57 |
Csus4: "x03340 fr3 x02340 barre=5-1", |
| 58 |
D: "000232 ,0 x00132", |
| 59 |
Dm: "000231 ,0 x00231", |
| 60 |
D7: "000212 ,0 x00312", |
| 61 |
Dm7: "000211 ,0 xx0211", |
| 62 |
DM7: "000222 ,0 xx0111", |
| 63 |
Dsus4: "000233 ,0 xx0134", |
| 64 |
E: "022100 ,0 023100", |
| 65 |
Em: "022000 ,0 023000", |
| 66 |
E7: "020100 ,0 020100", |
| 67 |
Em7: "022030 ,0 023040", |
| 68 |
EM7: "021100 ,0 031200", |
| 69 |
Esus4: "022200 ,0 023400", |
| 70 |
F: "033200 fr1 034200 barre=6-1", |
| 71 |
Fm: "033000 fr1 034000 barre=6-1", |
| 72 |
F7: "030200 fr1 030200 barre=6-1", |
| 73 |
Fm7: "030000 fr1 030000 barre=6-1", |
| 74 |
FM7: "xx3210 ,0 xx3210", |
| 75 |
Fsus4: "033300 fr1 023400 barre=6-1", |
| 76 |
G: "320003 ,0 230004", |
| 77 |
Gm: "033000 fr3 034000 barre=6-1", |
| 78 |
G7: "320001 ,0 320001", |
| 79 |
Gm7: "030000 fr3 030000 barre=6-1", |
| 80 |
GM7: "320002 ,0 310002", |
| 81 |
Gsus4: "033300 fr3 023400 barre=6-1", |
| 82 |
A: "002220 ,0 002340", |
| 83 |
Am: "002210 ,0 002310", |
| 84 |
A7: "002020 ,0 002030", |
| 85 |
Am7: "002010 ,0 002010", |
| 86 |
AM7: "002120 ,0 x02130", |
| 87 |
Asus4: "x02230 ,0 x02340", |
| 88 |
B: "x03330 fr2 002340 barre=5-1", |
| 89 |
Bm: "x03320 fr2 003410 barre=5-1", |
| 90 |
B7: "021202 ,0 x21304", |
| 91 |
Bm7: "003020 fr2 x03020 barre=5-1", |
| 92 |
BM7: "003230 fr2 x03240 barre=5-1", |
| 93 |
Bsus4: "x03340 fr2 x02340 barre=5-1", |
| 94 |
}, |
| 95 |
|
| 96 |
|
| 97 |
draw_gchord: function(of, i, s, x, y) { |
| 98 |
var gch, nm, |
| 99 |
cfmt = this.cfmt(), |
| 100 |
n = cfmt.diag, |
| 101 |
glyphs = this.get_glyphs() |
| 102 |
|
| 103 |
|
| 104 |
if (!glyphs.ddot) { |
| 105 |
this.add_style("\ |
| 106 |
\n.fng {font:6px sans-serif}\ |
| 107 |
\n.frn {font:italic 7px sans-serif}") |
| 108 |
glyphs.ddot = '<circle id="ddot" class="fill" r="1.5"/>' |
| 109 |
} |
| 110 |
|
| 111 |
if (!glyphs["fb" + n]) { |
| 112 |
if (n == 4) { |
| 113 |
glyphs.fb4 = '<g id="fb4">\n\ |
| 114 |
<path class="stroke" stroke-width="0.4" d="\ |
| 115 |
M-6 -24h12m0 6h-12\ |
| 116 |
m0 6h12m0 6h-12\ |
| 117 |
m0 6h12"/>\n\ |
| 118 |
<path class="stroke" stroke-width="0.5" d="\ |
| 119 |
M-6 -24v24m4 0v-24\ |
| 120 |
m4 0v24m4 0v-24"/>\n\ |
| 121 |
</g>' |
| 122 |
glyphs.nut4 = |
| 123 |
'<path id="nut4" class="stroke" stroke-width="1.6" d="\ |
| 124 |
M-6.2 -24.5h12.4"/>' |
| 125 |
} else { |
| 126 |
glyphs.fb6 = '<g id="fb6">\n\ |
| 127 |
<path class="stroke" stroke-width="0.4" d="\ |
| 128 |
M-10 -24h20m0 6h-20\ |
| 129 |
m0 6h20m0 6h-20\ |
| 130 |
m0 6h20"/>\n\ |
| 131 |
<path class="stroke" stroke-width="0.5" d="\ |
| 132 |
M-10 -24v24m4 0v-24\ |
| 133 |
m4 0v24m4 0v-24\ |
| 134 |
m4 0v24m4 0v-24"/>\n\ |
| 135 |
</g>' |
| 136 |
glyphs.nut6 = |
| 137 |
'<path id="nut6" class="stroke" stroke-width="1.6" d="\ |
| 138 |
M-10.2 -24.5h20.4"/>' |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
function ch_cnv(t) { |
| 144 |
var a = t.match(/[A-G][#♯b♭]?([^/]*)\/type |
| 145 |
if (a && a[1]) { |
| 146 |
a[2] = abc2svg.ch_alias[a[1]] |
| 147 |
if (a[2] != undefined) |
| 148 |
t = t.replace(a[1], a[2]) |
| 149 |
} |
| 150 |
return t.replace('/', '.') |
| 151 |
.replace(/\u266f/g,'#') |
| 152 |
.replace(/\u266d/g,'b') |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
function diag_add(nm) { |
| 157 |
var dc, i, l, x, y, |
| 158 |
d = abc2svg.diag["cd" + n][nm.slice(1)] |
| 159 |
|
| 160 |
|
| 161 |
if (!d) |
| 162 |
return |
| 163 |
d = d.split(' ') |
| 164 |
x = 2 - 2 * n |
| 165 |
dc = '<g id="' + nm + '">\n\ |
| 166 |
<use xlink:href="#fb' + n + '"/>\n' |
| 167 |
l = d[1].split(',') |
| 168 |
if (!l[0] || l[0].slice(-1) == l[1]) |
| 169 |
dc += '<use xlink:href="#nut' + n + '"/>\n' |
| 170 |
if (l[0]) |
| 171 |
dc += '<text x="' + (x - 10).toString() |
| 172 |
+ '" y="' + ((l[1] || 1) * 6 - 25) |
| 173 |
+ '" class="frn">' + l[0] + '</text>\n' |
| 174 |
|
| 175 |
dc += '<text x="' + (n == 6 ? '-12,-8,-4,0,4,8' |
| 176 |
: '-8,-4,0,4') |
| 177 |
+ '" y="-26" class="fng">' |
| 178 |
+ d[2].replace(/[y0]/g, ' ') |
| 179 |
+ '</text>\n' |
| 180 |
|
| 181 |
for (i = 0; i < n; i++) { |
| 182 |
l = d[0][i] |
| 183 |
if (l && l != 'x' && l != '0') |
| 184 |
dc += '<use x="' + (i * 4 + x) |
| 185 |
+ '" y="' + (l * 6 - 27) |
| 186 |
+ '" xlink:href="#ddot"/>\n' |
| 187 |
} |
| 188 |
|
| 189 |
if (d[3]) { |
| 190 |
l = d[3].match(/barre=(\d)-(\d)/) |
| 191 |
if (l) |
| 192 |
dc += '<path id="barre" class="stroke"\ |
| 193 |
stroke-width="1.4" d="M' + ((n - l[1]) * 4 + x - 2) |
| 194 |
+ ' -21h' + ((l[1] - l[2]) * 4 + 4) + '"/>' |
| 195 |
} |
| 196 |
dc += '</g>' |
| 197 |
glyphs[nm] = dc |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
of(i, s, x, y) |
| 202 |
|
| 203 |
if ((s.invis && s.play) |
| 204 |
|| !n) |
| 205 |
return |
| 206 |
gch = s.a_gch[i] |
| 207 |
if (!gch || gch.type != 'g' || gch.capo) |
| 208 |
return |
| 209 |
nm = n + ch_cnv(gch.text) |
| 210 |
|
| 211 |
|
| 212 |
if (!glyphs[nm]) |
| 213 |
diag_add(nm) |
| 214 |
|
| 215 |
|
| 216 |
if (glyphs[nm]) { |
| 217 |
x = s.x |
| 218 |
y = this.y_get(s.st, 1, x - 10, 20) |
| 219 |
this.xygl(x, y + 2, nm) |
| 220 |
this.y_set(s.st, 1, x - 10, 20, y + 34) |
| 221 |
} |
| 222 |
}, |
| 223 |
|
| 224 |
set_fmt: function(of, cmd, param) { |
| 225 |
var a, d, n, |
| 226 |
cfmt = this.cfmt() |
| 227 |
|
| 228 |
switch (cmd) { |
| 229 |
case "diagram": |
| 230 |
n = param |
| 231 |
if (n == '0') |
| 232 |
n = '' |
| 233 |
else if (n != '4') |
| 234 |
n = '6' |
| 235 |
cfmt.diag = n |
| 236 |
return |
| 237 |
case "setdiag": |
| 238 |
n = cfmt.diag |
| 239 |
if (!n) |
| 240 |
n = "6" |
| 241 |
a = param.match(/(\S*)\s+(.*)/) |
| 242 |
if (a && a.length == 3) { |
| 243 |
d = a[2].split(' ') |
| 244 |
if (d && d.length >= 3) { |
| 245 |
abc2svg.diag["cd" + n][a[1].replace('/', '.')] |
| 246 |
= a[2] |
| 247 |
return |
| 248 |
} |
| 249 |
} |
| 250 |
this.syntax(1, this.errs.bad_val, "%%setdiag") |
| 251 |
return |
| 252 |
} |
| 253 |
of(cmd, param) |
| 254 |
}, |
| 255 |
|
| 256 |
set_hooks: function(abc) { |
| 257 |
abc.draw_gchord = abc2svg.diag.draw_gchord.bind(abc,abc.draw_gchord) |
| 258 |
abc.set_format = abc2svg.diag.set_fmt.bind(abc, abc.set_format) |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
if (!abc2svg.mhooks) |
| 263 |
abc2svg.mhooks = {} |
| 264 |
abc2svg.mhooks.diag = abc2svg.diag.set_hooks |