102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
s.fname = s2.fname;
s.istart = s2.istart;
s.iend = s2.iend
}
return s
}
/* -- expand a multi-rest into single rests and measure bars -- */
function mrest_expand(s) {
var p_voice, s2, next,
nb = s.nmes,
dur = s.dur / nb
/* change the multi-rest (type bar) to a single rest */
var a_dd = s.a_dd;
s.a_dd = null
s.type = C.REST;
s.dur = s.dur_orig = dur;
/* add the bar(s) and rest(s) */
next = s.next;
p_voice = s.p_v;
p_voice.last_sym = s;
p_voice.time = s.time + dur;
p_voice.cst = s.st;
s2 = s
while (--nb > 0) {
s2 = sym_add(p_voice, C.BAR);
s2.bar_type = "|";
s2 = sym_add(p_voice, C.REST);
if (s.invis)
s2.invis = true;
s2.dur = s2.dur_orig = dur;
p_voice.time += dur
}
s2.next = next
if (next)
next.prev = s2;
/* copy the mrest decorations to the last rest */
s2.a_dd = a_dd
}
/* -- sort all symbols by time and vertical sequence -- */
// weight of the symbols !! depends on the symbol type !!
var w_tb = new Uint8Array([
4, // bar
1, // clef
8, // custos
0, // (free)
|
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
-
|
function sort_all() {
var s, s2, p_voice, v, time, w, wmin, ir, multi,
prev, nb, ir2, v2, fl, new_sy,
nv = voice_tb.length,
vtb = [],
vn = [], // voice indexed by range
mrest_time = -1,
sy = cur_sy
for (v = 0; v < nv; v++)
vtb.push(voice_tb[v].sym)
// set the first symbol
ir2 = nv
|
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
w = w_tb[s.type]
if (s.time < time) {
time = s.time;
wmin = w
} else if (w < wmin) {
wmin = w
}
if (s.type == C.MREST) {
if (s.nmes == 1)
mrest_expand(s)
else if (multi > 0)
mrest_time = time
}
}
}
if (wmin > 127)
break // done
/* if some multi-rest and many voices, expand */
if (time == mrest_time) {
nb = 0
for (ir = 0; ir < nv; ir++) {
v = vn[ir]
if (v == undefined)
break
s = vtb[v]
if (!s || s.time != time
|| w_tb[s.type] != wmin)
continue
if (s.type != C.MREST) {
mrest_time = -1 /* some note or rest */
break
}
if (nb == 0) {
nb = s.nmes
} else if (nb != s.nmes) {
mrest_time = -1 /* different duration */
break
}
}
if (mrest_time < 0) {
for (ir = 0; ir < nv; ir++) {
v = vn[ir]
if (v == undefined)
break
s = vtb[v]
if (s && s.type == C.MREST)
mrest_expand(s)
}
}
}
/* link the vertical sequence */
for (ir = 0; ir < nv; ir++) {
v = vn[ir]
if (v == undefined)
break
s = vtb[v]
if (!s || s.time != time
|