Skip to content

Commit

Permalink
RawClip warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Feb 17, 2024
1 parent d1a9c6d commit 4004e59
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
47 changes: 39 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,46 @@ function RawClip(x) {
if (typeof x != 'undefined') self.load(x);
return self;
}
function Warn(off, msg, data) {
this.off = off;
this.msg = msg;
this.data = data;
}
Warn.prototype.toString = function() {
var a = [];
if (typeof this.off != 'undefined') a.push('offset ' + this.off);
a.push('--');
a.push(this.msg);
if (typeof this.data != 'undefined') a.push('(' + this.data + ')');
return a.join(' ');
};
function _tohex(x) { return (x < 16 ? '0' : '') + x.toString(16); }

RawClip.prototype = [];
RawClip.prototype.send = function(msg) { this.push(JZZ.UMP(msg)); return this; };
RawClip.prototype.annotate = function() {};
RawClip.prototype.validate = function() {
var clip, w;
var i;
var off = this._off || 0;
var ww = [];
if (this._warn) for (i = 0; i < this._warn.length; i++) ww.push(this._warn[i]);
try {
clip = new JZZ.MIDI.Clip(this.dump());
w = clip.validate();
var clip = new JZZ.MIDI.Clip(this.dump());
var w = clip.validate();
if (w) for (i = 0; i < w.length; i++) {
w[i].off += off;
ww.push(w[i]);
}
}
catch (e) {/**/}
return w;
ww.sort(function(a, b) {
return (a.off || 0) - (b.off || 0) || (a.tick || 0) - (b.tick || 0);
});
return ww;
};
RawClip.prototype._complain = function(off, msg) {
console.log(off, msg);
RawClip.prototype._complain = function(off, msg, data) {
if (!this._warn) this._warn = [];
this._warn.push(new Warn(off, msg, data));
};
RawClip.prototype.dump = function() {
var a = [SMF2CLIP];
Expand All @@ -37,9 +63,8 @@ RawClip.prototype.load = function(s) {
if (s.substr(0, 8) != SMF2CLIP) {
var z = s.indexOf(SMF2CLIP);
if (z != -1) {
s = s.substr(z);
this._complain(off, 'Extra leading characters', z);
off += z;
this._complain(off, 'Extra leading characters', off);
}
else _error('Not a Clip');
}
Expand All @@ -51,6 +76,12 @@ RawClip.prototype.load = function(s) {
t = s.charCodeAt(off) >> 4;
len = [4, 4, 4, 8, 8, 16, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16][t];
a = [];
if (s.length < off + len) {
for (i = off; i < s.length; i++) a.push(_tohex(s.charCodeAt(i)));
this._complain(off, 'Incomplete message', a.join(' '));
off += len;
break;
}
for (i = 0; i < len; i++) a.push(s.charCodeAt(off + i));
m = JZZ.UMP(a);
if (m.isDelta()) tt += m.getDelta();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-midi-files",
"version": "1.0.3",
"version": "1.0.4",
"description": "A framework for producing test MIDI files",
"main": "index.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
"jzz-gui-player": "^1.7.0",
"jzz-midi-gear": "^1.3.2",
"jzz-midi-gm": "^1.3.5",
"jzz-midi-smf": "^1.8.5",
"jzz-midi-smf": "^1.8.6",
"jzz-synth-tiny": "^1.3.8"
},
"devDependencies": {
Expand Down

0 comments on commit 4004e59

Please sign in to comment.