| 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 |
s |
| 26 |
|
| 27 |
|
| 28 |
s |
| 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.gamelan = { |
| 48 |
|
| 49 |
cde2fcg: new Int8Array([0, 2, 4, -1, 1, 3, 5]), |
| 50 |
cgd2cde: new Int8Array([0, -4, -1, -5, -2, -6, -3, |
| 51 |
0, -4, -1, -5, -2, -6, -3, 0]), |
| 52 |
acc2: new Int8Array([-2, -1, 3, 1, 2]), |
| 53 |
|
| 54 |
|
| 55 |
do_pscom: function(of, p) { |
| 56 |
switch (p.match(/\w+/)[0]) { |
| 57 |
case 'staves': |
| 58 |
case 'score': |
| 59 |
p = p.replace(/\(|\)/g, '') |
| 60 |
break |
| 61 |
} |
| 62 |
of(p) |
| 63 |
}, |
| 64 |
|
| 65 |
|
| 66 |
output_music: function(of) { |
| 67 |
var v, |
| 68 |
C = abc2svg.C, |
| 69 |
abc = this, |
| 70 |
cur_sy = abc.get_cur_sy(), |
| 71 |
voice_tb = abc.get_voice_tb() |
| 72 |
|
| 73 |
if (!abc.cfmt().gamelan) { |
| 74 |
of() |
| 75 |
return |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
function slice(s) { |
| 80 |
var m, n, s2, s3, d, d_orig |
| 81 |
|
| 82 |
if (s.dur <= C.BLEN * 3 / 8) { |
| 83 |
if ((s.dur_orig / 9 | 0) * 9 != s.dur_orig) |
| 84 |
return |
| 85 |
d = s.dur / 3 |
| 86 |
d_orig = s.dur_orig / 3 |
| 87 |
s.dur -= d |
| 88 |
s.dur_orig -= d_orig |
| 89 |
n = 1 |
| 90 |
} else { |
| 91 |
if (s.dur >= C.BLEN) |
| 92 |
n = 3 |
| 93 |
else if (s.dur == C.BLEN / 2) |
| 94 |
n = 1 |
| 95 |
else |
| 96 |
n = 2 |
| 97 |
d = d_orig = C.BLEN / 4 |
| 98 |
s.dur = s.dur_orig = C.BLEN / 4 |
| 99 |
} |
| 100 |
for (m = 0; m <= s.nhd; m++) |
| 101 |
s.notes[m].dur = s.dur |
| 102 |
s.beam_on = true |
| 103 |
while (--n >= 0) { |
| 104 |
s2 = { |
| 105 |
type: C.REST, |
| 106 |
v: s.v, |
| 107 |
p_v: s.p_v, |
| 108 |
st: s.st, |
| 109 |
fmt: s.fmt, |
| 110 |
dur: d, |
| 111 |
dur_orig: d_orig, |
| 112 |
stem: 1, |
| 113 |
multi: 0, |
| 114 |
nhd: 0, |
| 115 |
notes: [{ |
| 116 |
pit: s.notes[0].pit, |
| 117 |
jn: 8 |
| 118 |
}], |
| 119 |
xmx: 0, |
| 120 |
beam_on: true, |
| 121 |
noplay: true, |
| 122 |
time: s.time + s.dur, |
| 123 |
prev: s, |
| 124 |
next: s.next |
| 125 |
} |
| 126 |
s.next = s2 |
| 127 |
if (s2.next) |
| 128 |
s2.next.prev = s2 |
| 129 |
|
| 130 |
if (!s.ts_next) { |
| 131 |
s.ts_next = s2 |
| 132 |
if (s.soln) |
| 133 |
s.soln = false |
| 134 |
s2.ts_prev = s |
| 135 |
s2.seqst = true |
| 136 |
} else { |
| 137 |
for (s3 = s.ts_next; s3; s3 = s3.ts_next) { |
| 138 |
if (s3.time < s2.time) |
| 139 |
continue |
| 140 |
if (s3.time > s2.time) { |
| 141 |
s2.seqst = true |
| 142 |
s3 = s3.ts_prev |
| 143 |
} |
| 144 |
s2.ts_next = s3.ts_next |
| 145 |
s2.ts_prev = s3 |
| 146 |
if (s2.ts_next) |
| 147 |
s2.ts_next.ts_prev = s2 |
| 148 |
s3.ts_next = s2 |
| 149 |
break |
| 150 |
} |
| 151 |
} |
| 152 |
s = s2 |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
function do_tie(s) { |
| 158 |
var end_time = s.time + s.dur |
| 159 |
while (1) { |
| 160 |
s = s.ts_next |
| 161 |
if (!s || s.time > end_time) |
| 162 |
return |
| 163 |
if (s.type == C.NOTE |
| 164 |
&& s.time == end_time) |
| 165 |
break |
| 166 |
} |
| 167 |
s.notes[0].jn = 8 |
| 168 |
s.notes[0].jo = 2 |
| 169 |
} |
| 170 |
|
| 171 |
function set_sym(p_v) { |
| 172 |
var s, s2, note, pit, nn, p, a, m, i, |
| 173 |
sf = p_v.key.k_sf, |
| 174 |
delta = abc2svg.gamelan.cgd2cde[sf + 7] - 2 |
| 175 |
|
| 176 |
delete p_v.key.k_a_acc |
| 177 |
|
| 178 |
|
| 179 |
p_v.clef.invis = true |
| 180 |
|
| 181 |
|
| 182 |
for (s = p_v.sym; s; s = s.next) { |
| 183 |
s.st = p_v.st |
| 184 |
switch (s.type) { |
| 185 |
case C.CLEF: |
| 186 |
s.invis = true |
| 187 |
|
| 188 |
default: |
| 189 |
continue |
| 190 |
case C.KEY: |
| 191 |
delta = abc2svg.gamelan.cgd2cde[s.k_sf + 7] - 2 |
| 192 |
continue |
| 193 |
case C.REST: |
| 194 |
if (s.notes[0].jn) |
| 195 |
continue |
| 196 |
s.notes[0].jn = 0 |
| 197 |
s.notes[0].pit = 21 |
| 198 |
slice(s) |
| 199 |
continue |
| 200 |
case C.NOTE: |
| 201 |
break |
| 202 |
} |
| 203 |
|
| 204 |
s.stem = 1 |
| 205 |
s.stemless = true |
| 206 |
|
| 207 |
|
| 208 |
if (s.sls) { |
| 209 |
for (i = 0; i < s.sls.length; i++) |
| 210 |
s.sls[i].ty = C.SL_BELOW |
| 211 |
} |
| 212 |
|
| 213 |
for (m = 0; m <= s.nhd; m++) { |
| 214 |
note = s.notes[m] |
| 215 |
|
| 216 |
|
| 217 |
p = note.pit |
| 218 |
pit = p + delta |
| 219 |
if (note.jn == undefined) { |
| 220 |
note.jn = ((pit + 77) % 7) + 1 |
| 221 |
note.jo = (pit / 7) | 0 |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
note.pit = 21 |
| 227 |
|
| 228 |
|
| 229 |
a = note.acc |
| 230 |
if (a) { |
| 231 |
nn = abc2svg.gamelan.cde2fcg[(p + 5 + 16 * 7) % 7] - sf |
| 232 |
if (a != 3) |
| 233 |
nn += a * 7 |
| 234 |
nn = ((((nn + 1 + 21) / 7) | 0) + 2 - 3 + 32 * 5) % 5 |
| 235 |
note.acc = abc2svg.gamelan.acc2[nn] |
| 236 |
} |
| 237 |
|
| 238 |
if (note.tie_ty) { |
| 239 |
do_tie(s) |
| 240 |
delete note.tie_ty |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
slice(s) |
| 246 |
|
| 247 |
|
| 248 |
if (s.a_dd) { |
| 249 |
for (i = 0; i < s.a_dd.length; i++) { |
| 250 |
if (s.a_dd[i].glyph == "stc") { |
| 251 |
abc.deco_put("gstc", s) |
| 252 |
s.a_dd[i] = s.a_dd.pop() |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
for (v = 0; v < voice_tb.length; v++) |
| 262 |
set_sym(voice_tb[v]) |
| 263 |
|
| 264 |
of() |
| 265 |
}, |
| 266 |
|
| 267 |
draw_symbols: function(of, p_voice) { |
| 268 |
var i, m, nl, note, s, s2, x, y, |
| 269 |
C = abc2svg.C, |
| 270 |
abc = this, |
| 271 |
dot = "\ue1e7", |
| 272 |
staff_tb = abc.get_staff_tb(), |
| 273 |
out_svg = abc.out_svg, |
| 274 |
out_sxsy = abc.out_sxsy, |
| 275 |
xypath = abc.xypath |
| 276 |
|
| 277 |
if (!abc.cfmt().gamelan) { |
| 278 |
of(p_voice) |
| 279 |
return |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
function draw_dur(s1, y, s2, n, nl) { |
| 284 |
var s, s3 |
| 285 |
|
| 286 |
xypath(s1.x - 3, y + 24) |
| 287 |
out_svg('h' + (s2.x - s1.x + 8).toFixed(1) + '"/>\n') |
| 288 |
y -= 2.5 |
| 289 |
while (++n <= nl) { |
| 290 |
s = s1 |
| 291 |
while (1) { |
| 292 |
if (s.nflags && s.nflags >= n) { |
| 293 |
s3 = s |
| 294 |
while (s != s2) { |
| 295 |
if (s.next.beam_br1 |
| 296 |
|| (s.next.beam_br2 && n > 2) |
| 297 |
|| (s.next.nflags |
| 298 |
&& s.next.nflags < n)) |
| 299 |
break |
| 300 |
s = s.next |
| 301 |
} |
| 302 |
draw_dur(s3, y, s, n, nl) |
| 303 |
} |
| 304 |
if (s == s2) |
| 305 |
break |
| 306 |
s = s.next |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
function out_mus(x, y, p) { |
| 312 |
out_svg('<text x="') |
| 313 |
out_sxsy(x, '" y="', y) |
| 314 |
out_svg('">' + p + '</text>\n') |
| 315 |
} |
| 316 |
|
| 317 |
function out_txt(x, y, p) { |
| 318 |
out_svg('<text class="bn" x="') |
| 319 |
out_sxsy(x, '" y="', y) |
| 320 |
out_svg('">' + p + '</text>\n') |
| 321 |
} |
| 322 |
|
| 323 |
function draw_hd(s, x, y) { |
| 324 |
var m, note, ym |
| 325 |
|
| 326 |
for (m = 0; m <= s.nhd; m++) { |
| 327 |
note = s.notes[m] |
| 328 |
out_txt(x - 3.5, y + 8, "01234567."[note.jn]) |
| 329 |
if (note.acc) { |
| 330 |
out_svg('<path class="stroke" stroke-width="1.1" d="M') |
| 331 |
if (note.acc > 0) { |
| 332 |
out_sxsy(x - 6, ' ', y + 10) |
| 333 |
out_svg("l12 -6") |
| 334 |
} else { |
| 335 |
out_sxsy(x - 6, ' ', y + 16) |
| 336 |
out_svg("l12 6") |
| 337 |
} |
| 338 |
out_svg('"/>\n') |
| 339 |
} |
| 340 |
if (note.jo > 2) { |
| 341 |
out_mus(x - 1, y + 23, dot) |
| 342 |
if (note.jo > 3) { |
| 343 |
y += 3 |
| 344 |
out_mus(x - 1, y + 23.4, dot) |
| 345 |
} |
| 346 |
} else if (note.jo < 2) { |
| 347 |
ym = y + 4 |
| 348 |
out_mus(x - 1, ym, dot) |
| 349 |
} |
| 350 |
y += 20 |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
for (s = p_voice.sym; s; s = s.next) { |
| 357 |
if (s.invis) |
| 358 |
continue |
| 359 |
switch (s.type) { |
| 360 |
case C.NOTE: |
| 361 |
case C.REST: |
| 362 |
x = s.x |
| 363 |
y = staff_tb[s.st].y |
| 364 |
draw_hd(s, x, y) |
| 365 |
break |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
for (s = p_voice.sym; s; s = s.next) { |
| 371 |
if (s.invis) |
| 372 |
continue |
| 373 |
switch (s.type) { |
| 374 |
case C.NOTE: |
| 375 |
case C.REST: |
| 376 |
nl = s.nflags |
| 377 |
if (nl <= 0) |
| 378 |
continue |
| 379 |
y = staff_tb[s.st].y |
| 380 |
s2 = s |
| 381 |
while (s.next && s.next.nflags > 0) { |
| 382 |
s = s.next |
| 383 |
if (s.nflags > nl) |
| 384 |
nl = s.nflags |
| 385 |
if (s.beam_end) |
| 386 |
break |
| 387 |
} |
| 388 |
draw_dur(s2, y + 7, s, 1, nl) |
| 389 |
break |
| 390 |
} |
| 391 |
} |
| 392 |
}, |
| 393 |
|
| 394 |
|
| 395 |
set_fmt: function(of, cmd, param) { |
| 396 |
if (cmd == "gamelan") { |
| 397 |
var cfmt = this.cfmt() |
| 398 |
|
| 399 |
if (!this.get_bool(param)) |
| 400 |
return |
| 401 |
cfmt.gamelan = true |
| 402 |
cfmt.staffsep = 20 |
| 403 |
cfmt.sysstaffsep = 14 |
| 404 |
this.set_v_param("stafflines", "...") |
| 405 |
cfmt.tuplets = [0, 1, 0, 1] |
| 406 |
return |
| 407 |
} |
| 408 |
of(cmd, param) |
| 409 |
}, |
| 410 |
|
| 411 |
|
| 412 |
set_pitch: function(of, last_s) { |
| 413 |
of(last_s) |
| 414 |
if (!last_s |
| 415 |
|| !this.cfmt().gamelan) |
| 416 |
return |
| 417 |
|
| 418 |
var C = abc2svg.C |
| 419 |
|
| 420 |
for (var s = this.get_tsfirst(); s; s = s.ts_next) { |
| 421 |
switch (s.type) { |
| 422 |
|
| 423 |
|
| 424 |
case C.NOTE: |
| 425 |
s.ymx = 20 * s.nhd + (s.nflags > 0 ? 30 : 24) |
| 426 |
if (s.notes[s.nhd].jo > 2) { |
| 427 |
s.ymx += 3 |
| 428 |
if (s.notes[s.nhd].jo > 3) |
| 429 |
s.ymx += 2 |
| 430 |
} |
| 431 |
s.ys = s.ymx |
| 432 |
break |
| 433 |
} |
| 434 |
} |
| 435 |
}, |
| 436 |
|
| 437 |
|
| 438 |
set_width: function(of, s) { |
| 439 |
of(s) |
| 440 |
if (!this.cfmt().gamelan) |
| 441 |
return |
| 442 |
|
| 443 |
var w, m, note, |
| 444 |
C = abc2svg.C |
| 445 |
|
| 446 |
switch (s.type) { |
| 447 |
case C.CLEF: |
| 448 |
case C.KEY: |
| 449 |
case C.METER: |
| 450 |
s.wl = s.wr = .1 |
| 451 |
break |
| 452 |
} |
| 453 |
}, |
| 454 |
|
| 455 |
set_hooks: function(abc) { |
| 456 |
abc.do_pscom = abc2svg.gamelan.do_pscom.bind(abc, abc.do_pscom) |
| 457 |
abc.draw_symbols = abc2svg.gamelan.draw_symbols.bind(abc, abc.draw_symbols) |
| 458 |
abc.output_music = abc2svg.gamelan.output_music.bind(abc, abc.output_music) |
| 459 |
abc.set_format = abc2svg.gamelan.set_fmt.bind(abc, abc.set_format) |
| 460 |
abc.set_pitch = abc2svg.gamelan.set_pitch.bind(abc, abc.set_pitch) |
| 461 |
abc.set_width = abc2svg.gamelan.set_width.bind(abc, abc.set_width) |
| 462 |
|
| 463 |
|
| 464 |
abc.get_glyphs().gstc = '<circle id="gstc" cx="0" cy="-3" r="2"/>' |
| 465 |
abc.get_decos().gstc = "0 gstc 5 1 1" |
| 466 |
|
| 467 |
abc.add_style("\n.bn {font-family:sans-serif; font-size:16px}") |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
if (!abc2svg.mhooks) |
| 472 |
abc2svg.mhooks = {} |
| 473 |
abc2svg.mhooks.gamelan = abc2svg.gamelan.set_hooks |