| 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.break = { |
| 29 |
|
| 30 |
|
| 31 |
get_break: function(parm) { |
| 32 |
var C = abc2svg.C, |
| 33 |
b, c, d, n, sq, |
| 34 |
a = parm.split(/[ ,]/), |
| 35 |
cfmt = this.cfmt() |
| 36 |
|
| 37 |
if (!cfmt.break) |
| 38 |
cfmt.break = [] |
| 39 |
for (n = 1; n < a.length; n++) { |
| 40 |
b = a[n]; |
| 41 |
c = b.match(/(\d+)([a-z]?)(:\d+\/\d+)?/) |
| 42 |
if (!c) { |
| 43 |
this.syntax(1, this.errs.bad_val, "%%break") |
| 44 |
continue |
| 45 |
} |
| 46 |
if (c[2]) |
| 47 |
sq = c[2].charCodeAt(0) - 0x61 |
| 48 |
if (!c[3]) { |
| 49 |
cfmt.break.push({ |
| 50 |
m: c[1], |
| 51 |
t: 0, |
| 52 |
sq: sq}) |
| 53 |
continue |
| 54 |
} |
| 55 |
d = c[3].match(/:(\d+)\/(\d+)/) |
| 56 |
if (!d || d[2] < 1) { |
| 57 |
this.syntax(1, "Bad denominator in %%break") |
| 58 |
continue |
| 59 |
} |
| 60 |
cfmt.break.push({ |
| 61 |
m: c[1], |
| 62 |
t: d[1] * C.BLEN / d[2], |
| 63 |
sq: sq}) |
| 64 |
} |
| 65 |
}, |
| 66 |
|
| 67 |
|
| 68 |
do_break: function() { |
| 69 |
var i, m, t, brk, s, seq, |
| 70 |
voice_tb = this.get_voice_tb(), |
| 71 |
v = this.get_cur_sy().top_voice, |
| 72 |
s1 = voice_tb[v].sym, |
| 73 |
cfmt = this.cfmt() |
| 74 |
|
| 75 |
for (i = 0; i < cfmt.break.length; i++) { |
| 76 |
brk = cfmt.break[i]; |
| 77 |
m = brk.m |
| 78 |
for (s = s1; s; s = s.next) { |
| 79 |
if (s.bar_num == m) |
| 80 |
break |
| 81 |
} |
| 82 |
if (!s) |
| 83 |
continue |
| 84 |
|
| 85 |
if (brk.sq) { |
| 86 |
seq = brk.sq |
| 87 |
for (s = s.ts_next; s; s = s.ts_next) { |
| 88 |
if (s.bar_num == m) { |
| 89 |
if (--seq == 0) |
| 90 |
break |
| 91 |
} |
| 92 |
} |
| 93 |
if (!s) |
| 94 |
continue |
| 95 |
} |
| 96 |
|
| 97 |
t = brk.t |
| 98 |
if (t) { |
| 99 |
t = s.time + t |
| 100 |
for ( ; s; s = s.next) { |
| 101 |
if (s.time >= t) |
| 102 |
break |
| 103 |
} |
| 104 |
} else { |
| 105 |
s = s.next |
| 106 |
} |
| 107 |
if (s) |
| 108 |
s.soln = true |
| 109 |
} |
| 110 |
}, |
| 111 |
|
| 112 |
do_pscom: function (of, text) { |
| 113 |
if (text.slice(0, 6) == "break ") |
| 114 |
abc2svg.break.get_break.call(this, text) |
| 115 |
else |
| 116 |
of(text) |
| 117 |
}, |
| 118 |
|
| 119 |
set_bar_num: function(of) { |
| 120 |
of() |
| 121 |
if (this.cfmt().break) |
| 122 |
abc2svg.break.do_break.call(this) |
| 123 |
}, |
| 124 |
|
| 125 |
set_hooks: function(abc) { |
| 126 |
abc.do_pscom = abc2svg.break.do_pscom.bind(abc, abc.do_pscom); |
| 127 |
abc.set_bar_num = abc2svg.break.set_bar_num.bind(abc, abc.set_bar_num) |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
if (!abc2svg.mhooks) |
| 132 |
abc2svg.mhooks = {} |
| 133 |
abc2svg.mhooks.break = abc2svg.break.set_hooks |