| 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.clip = { |
| 29 |
|
| 30 |
get_clip: function(parm) { |
| 31 |
var C = abc2svg.C |
| 32 |
|
| 33 |
|
| 34 |
function get_symsel(a) { |
| 35 |
var j, d, sq, |
| 36 |
b = a.match(/(\d+)([a-z]?)(:\d+\/\d+)?/) |
| 37 |
|
| 38 |
if (!b) |
| 39 |
return |
| 40 |
if (b[2]) |
| 41 |
sq = b[2].charCodeAt(0) - 0x61 |
| 42 |
if (!b[3]) |
| 43 |
return {m: b[1], t: 0, sq: sq} |
| 44 |
a = b[3].match(/:(\d+)\/(\d+)/) |
| 45 |
if (!a || a[2] < 1) |
| 46 |
return |
| 47 |
return {m: b[1], t: a[1] * C.BLEN / a[2], sq: sq} |
| 48 |
} |
| 49 |
|
| 50 |
var b, c, |
| 51 |
a = parm.split(/[ -]/) |
| 52 |
|
| 53 |
if (a.length != 3) { |
| 54 |
this.syntax(1, this.errs.bad_val, "%%clip") |
| 55 |
return |
| 56 |
} |
| 57 |
if (!a[1]) |
| 58 |
b = {m: 0, t: 0} |
| 59 |
else |
| 60 |
b = get_symsel(a[1]); |
| 61 |
c = get_symsel(a[2]) |
| 62 |
if (!b || !c) { |
| 63 |
this.syntax(1, this.errs.bad_val, "%%clip") |
| 64 |
return |
| 65 |
} |
| 66 |
this.cfmt().clip = [b, c] |
| 67 |
}, |
| 68 |
|
| 69 |
|
| 70 |
do_clip: function() { |
| 71 |
var C = abc2svg.C, |
| 72 |
abc = this, |
| 73 |
voice_tb = this.get_voice_tb(), |
| 74 |
cfmt = this.cfmt() |
| 75 |
|
| 76 |
|
| 77 |
function chkptr(last) { |
| 78 |
var i, sl, s2, m, nt, |
| 79 |
tim = last.time, |
| 80 |
s = abc.get_tsfirst() |
| 81 |
|
| 82 |
do { |
| 83 |
if (s.sls) { |
| 84 |
for (i = 0; i < s.sls.length; i++) { |
| 85 |
sl = s.sls[i] |
| 86 |
s2 = sl.se |
| 87 |
if (s2.time >= tim) |
| 88 |
sl.loc = 'o' |
| 89 |
} |
| 90 |
} |
| 91 |
if (s.ti1 |
| 92 |
&& s.time + s.dur >= tim) { |
| 93 |
for (m = 0; m <= s.nhd; m++) { |
| 94 |
nt = s.notes[m] |
| 95 |
if (nt.tie_e && nt.tie_e.s.time >= tim) |
| 96 |
delete nt.tie_e |
| 97 |
} |
| 98 |
} |
| 99 |
s = s.ts_next |
| 100 |
} while (s) |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
function go_global_time(s, sel) { |
| 105 |
var s2, bar_time, seq |
| 106 |
|
| 107 |
if (sel.m <= 1) { |
| 108 |
if (sel.m == 1) { |
| 109 |
for (s2 = s; s2; s2 = s2.ts_next) { |
| 110 |
if (s2.type == C.BAR |
| 111 |
&& s2.time != 0) |
| 112 |
break |
| 113 |
} |
| 114 |
if (s2.time < voice_tb[abc.get_cur_sy().top_voice]. |
| 115 |
meter.wmeasure) |
| 116 |
s = s2 |
| 117 |
} |
| 118 |
} else { |
| 119 |
for ( ; s; s = s.ts_next) { |
| 120 |
if (s.type == C.BAR |
| 121 |
&& s.bar_num >= sel.m) |
| 122 |
break |
| 123 |
} |
| 124 |
if (!s) |
| 125 |
return |
| 126 |
|
| 127 |
if (sel.sq) { |
| 128 |
seq = sel.sq |
| 129 |
for (s = s.ts_next; s; s = s.ts_next) { |
| 130 |
if (s.type == C.BAR |
| 131 |
&& s.bar_num == sel.m) { |
| 132 |
if (--seq == 0) |
| 133 |
break |
| 134 |
} |
| 135 |
} |
| 136 |
if (!s) |
| 137 |
return |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
if (sel.t == 0) |
| 142 |
return s; |
| 143 |
bar_time = s.time + sel.t |
| 144 |
while (s.time < bar_time) { |
| 145 |
s = s.ts_next |
| 146 |
if (!s) |
| 147 |
return s |
| 148 |
} |
| 149 |
do { |
| 150 |
s = s.ts_prev |
| 151 |
} while (!s.seqst) |
| 152 |
return s |
| 153 |
} |
| 154 |
|
| 155 |
var s, s2, sy, p_voice, v |
| 156 |
|
| 157 |
|
| 158 |
s = this.get_tsfirst() |
| 159 |
if (cfmt.clip[0].m > 0 |
| 160 |
|| cfmt.clip[0].t > 0) { |
| 161 |
s = go_global_time(s, cfmt.clip[0]) |
| 162 |
if (!s) { |
| 163 |
this.set_tsfirst(null) |
| 164 |
return |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
sy = this.get_cur_sy() |
| 169 |
for (s2 = this.get_tsfirst(); s2 != s; s2 = s2.ts_next) { |
| 170 |
switch (s2.type) { |
| 171 |
case C.CLEF: |
| 172 |
s2.p_v.clef = s2 |
| 173 |
break |
| 174 |
case C.KEY: |
| 175 |
s2.p_v.key = this.clone(s2.as.u.key) |
| 176 |
s2.p_v.ckey = this.clone(s2.as.u.ckey) |
| 177 |
break |
| 178 |
case C.METER: |
| 179 |
s2.p_v.meter = this.clone(s2.as.u.meter) |
| 180 |
break |
| 181 |
case C.STAVES: |
| 182 |
sy = s2.sy; |
| 183 |
this.set_cur_sy(sy) |
| 184 |
break |
| 185 |
} |
| 186 |
} |
| 187 |
for (v = 0; v < voice_tb.length; v++) { |
| 188 |
p_voice = voice_tb[v] |
| 189 |
for (s2 = s; s2; s2 = s2.ts_next) { |
| 190 |
if (s2.v == v) { |
| 191 |
delete s2.prev |
| 192 |
break |
| 193 |
} |
| 194 |
} |
| 195 |
p_voice.sym = s2 |
| 196 |
} |
| 197 |
s2 = this.get_tsfirst() |
| 198 |
if (s != s2) { |
| 199 |
if (s2.type == C.STAVES) { |
| 200 |
s2.ts_next = s |
| 201 |
s.ts_prev = s2 |
| 202 |
s2.next = s2.p_v.sym |
| 203 |
s2.p_v.sym = s2 |
| 204 |
s2.next.prev = s2 |
| 205 |
} else { |
| 206 |
this.set_tsfirst(s) |
| 207 |
delete s.ts_prev |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
s = go_global_time(s, cfmt.clip[1]) |
| 214 |
if (!s) |
| 215 |
return |
| 216 |
|
| 217 |
|
| 218 |
do { |
| 219 |
s = s.ts_next |
| 220 |
if (!s) |
| 221 |
return |
| 222 |
} while (!s.seqst) |
| 223 |
|
| 224 |
|
| 225 |
for (v = 0; v < voice_tb.length; v++) { |
| 226 |
p_voice = voice_tb[v] |
| 227 |
for (s2 = s.ts_prev; s2; s2 = s2.ts_prev) { |
| 228 |
if (s2.v == v) { |
| 229 |
delete s2.next |
| 230 |
break |
| 231 |
} |
| 232 |
} |
| 233 |
if (!s2) |
| 234 |
p_voice.sym = null |
| 235 |
} |
| 236 |
delete s.ts_prev.ts_next |
| 237 |
|
| 238 |
chkptr(s.ts_prev) |
| 239 |
}, |
| 240 |
|
| 241 |
do_pscom: function (of, text) { |
| 242 |
if (text.slice(0, 5) == "clip ") |
| 243 |
abc2svg.clip.get_clip.call(this, text) |
| 244 |
else |
| 245 |
of(text) |
| 246 |
}, |
| 247 |
|
| 248 |
set_bar_num: function(of) { |
| 249 |
of() |
| 250 |
if (this.cfmt().clip) |
| 251 |
abc2svg.clip.do_clip.call(this) |
| 252 |
}, |
| 253 |
|
| 254 |
set_hooks: function(abc) { |
| 255 |
abc.do_pscom = abc2svg.clip.do_pscom.bind(abc, abc.do_pscom); |
| 256 |
abc.set_bar_num = abc2svg.clip.set_bar_num.bind(abc, abc.set_bar_num) |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
if (!abc2svg.mhooks) |
| 261 |
abc2svg.mhooks = {} |
| 262 |
abc2svg.mhooks.clip = abc2svg.clip.set_hooks |