| 1 |
|
| 2 |
|
| 3 |
e |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
"use strict" |
| 26 |
if (typeof abc2svg == "undefined") |
| 27 |
var abc2svg = {} |
| 28 |
|
| 29 |
abc2svg.equalbars = { |
| 30 |
|
| 31 |
|
| 32 |
output_music: function(of) { |
| 33 |
this.equalbars_d = 0; |
| 34 |
of() |
| 35 |
}, |
| 36 |
|
| 37 |
|
| 38 |
set_fmt: function(of, cmd, parm) { |
| 39 |
if (cmd != "equalbars") { |
| 40 |
of(cmd, parm) |
| 41 |
return |
| 42 |
} |
| 43 |
var fmt = this.cfmt() |
| 44 |
fmt.equalbars = this.get_bool(parm) |
| 45 |
fmt.stretchlast = 1 |
| 46 |
}, |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
set_sym_glue: function(of, width) { |
| 51 |
var C = abc2svg.C, |
| 52 |
s, s2, d, w, i, n, x, g, t, t0, f, |
| 53 |
bars = [], |
| 54 |
tsfirst = this.get_tsfirst(); |
| 55 |
|
| 56 |
of(width) |
| 57 |
if (!this.cfmt().equalbars) |
| 58 |
return |
| 59 |
|
| 60 |
|
| 61 |
for (s2 = tsfirst; s2; s2 = s2.next) { |
| 62 |
switch (s2.type) { |
| 63 |
default: |
| 64 |
continue |
| 65 |
case C.GRACE: |
| 66 |
case C.MREST: |
| 67 |
case C.NOTE: |
| 68 |
case C.REST: |
| 69 |
case C.SPACE: |
| 70 |
break |
| 71 |
} |
| 72 |
break |
| 73 |
} |
| 74 |
if (!s2) |
| 75 |
return |
| 76 |
|
| 77 |
|
| 78 |
t0 = t = s2.time |
| 79 |
for (s = s2; s.next; s = s.next) { |
| 80 |
if (s.type == C.BAR && s.seqst && s.time != t) { |
| 81 |
bars.push([s, s.time - t]); |
| 82 |
t = s.time |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
if (s.time != t) |
| 88 |
bars.push([s, s.time - t]) |
| 89 |
else |
| 90 |
bars[bars.length - 1][0] = s |
| 91 |
|
| 92 |
t = s.time |
| 93 |
if (s.dur) |
| 94 |
t += s.dur; |
| 95 |
|
| 96 |
n = bars.length |
| 97 |
if (n <= 1) |
| 98 |
return |
| 99 |
|
| 100 |
|
| 101 |
if (s.x < width) { |
| 102 |
w = 0 |
| 103 |
x = 0 |
| 104 |
for (i = 0; i < n; i++) { |
| 105 |
s = bars[i][0] |
| 106 |
if (s.x - x > w) |
| 107 |
w = s.x - x |
| 108 |
x = s.x |
| 109 |
} |
| 110 |
if (w * n < width) |
| 111 |
width = w * n |
| 112 |
this.set_realwidth(width) |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
x = s2.type == C.GRACE ? s2.extra.x : (s2.x - s2.wl) |
| 117 |
if (this.equalbars_d < x) |
| 118 |
this.equalbars_d = x |
| 119 |
|
| 120 |
d = this.equalbars_d |
| 121 |
w = (width - d) / (t - t0) |
| 122 |
|
| 123 |
|
| 124 |
for (i = 0; i < n; i++) { |
| 125 |
do { |
| 126 |
if (s2.type == C.GRACE) { |
| 127 |
for (g = s2.extra; g; g = g.next) |
| 128 |
g.x = d + g.x - x |
| 129 |
} else { |
| 130 |
s2.x = d + s2.x - x |
| 131 |
} |
| 132 |
s2 = s2.ts_next |
| 133 |
} while (!s2.seqst) |
| 134 |
|
| 135 |
s = bars[i][0]; |
| 136 |
f = w * bars[i][1] / (s.x - x) |
| 137 |
|
| 138 |
|
| 139 |
for ( ; s2 != s; s2 = s2.ts_next) { |
| 140 |
if (s2.type == C.GRACE) { |
| 141 |
for (g = s2.extra; g; g = g.next) |
| 142 |
g.x = d + (g.x - x) * f |
| 143 |
|
| 144 |
} else { |
| 145 |
s2.x = d + (s2.x - x) * f |
| 146 |
} |
| 147 |
} |
| 148 |
d += w * bars[i][1]; |
| 149 |
x = s2.x |
| 150 |
while (1) { |
| 151 |
s2.x = d; |
| 152 |
s2 = s2.ts_next |
| 153 |
if (!s2 || s2.seqst) |
| 154 |
break |
| 155 |
} |
| 156 |
if (!s2) |
| 157 |
break |
| 158 |
} |
| 159 |
}, |
| 160 |
|
| 161 |
set_hooks: function(abc) { |
| 162 |
abc.output_music = abc2svg.equalbars.output_music.bind(abc, abc.output_music); |
| 163 |
abc.set_format = abc2svg.equalbars.set_fmt.bind(abc, abc.set_format); |
| 164 |
abc.set_sym_glue = abc2svg.equalbars.set_sym_glue.bind(abc, abc.set_sym_glue) |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
if (!abc2svg.mhooks) |
| 169 |
abc2svg.mhooks = {} |
| 170 |
abc2svg.mhooks.equalbars = abc2svg.equalbars.set_hooks |