Skip to content

Commit

Permalink
Fixed Clip.validate()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Mar 3, 2024
1 parent f2d58b3 commit 2b9e208
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions javascript/JZZ.midi.SMF.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@
}
else {
m.tt = tt;
m.off = off;
if (prev && !prev.isDelta()) {
clip._complain(off, "Missing Delta Ticks message", m.toString(), tt);
}
Expand Down Expand Up @@ -1520,14 +1521,19 @@
}
if (k) {
if (p[k]) {
if (d == 0 || d == 1) clip._complain(p[k].off, 'Missing series end', p[k].toString(), p[k].tick);
if (d == 0 || d == 1) clip._complain(p[k].off, 'Missing series end', p[k].toString(), p[k].tt);
}
else {
if (d == 2 || d == 3) clip._complain(m.off, 'Missing series start', m.toString(), m.tick);
if (d == 2 || d == 3) clip._complain(m.off, 'Missing series start', m.toString(), m.tt);
}
p[k] = (d == 0 || d == 3) ? undefined : m;
}
}
d = Object.keys(p);
for (i = 0; i < d.length; i++) {
m = p[d[i]];
if (m) clip._complain(m.off, 'Missing series end', m.toString(), m.tt);
}
}
Clip.prototype.validate = function() {
var i;
Expand Down
11 changes: 11 additions & 0 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,17 @@ describe('SMF2', function() {
clip = new JZZ.MIDI.Clip();
val = clip.validate();
assert.equal(typeof val, 'undefined');
var a = JZZ.UMP.umpText(0, 'text text text text text text');
clip.send(a[0]).send(a[1]).send(a[2]);
clip = new JZZ.MIDI.Clip(clip.dump());
val = clip.validate();
assert.equal(typeof val, 'undefined');
clip = new JZZ.MIDI.Clip();
clip.send(a[0]).send(a[1]).send(a[2]).tick(96).send(a[2]).send(a[1]).send(a[0]);
clip = new JZZ.MIDI.Clip(clip.dump());
val = clip.validate();
assert.equal(val[0].toString(), 'offset 100 tick 96 -- Missing series start (d0d00200 20746578 74000000 00000000 -- Text)');
assert.equal(val[3].toString(), 'offset 140 tick 96 -- Missing series end (d0500200 74657874 20746578 74207465 -- Text)');
});
it('tick', function() {
var clip = new JZZ.MIDI.Clip();
Expand Down

0 comments on commit 2b9e208

Please sign in to comment.