Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed May 17, 2024
1 parent 41b8a74 commit 05a4f16
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- run: npm install
- run: npm test
- run: npm run coverage
- uses: coverallsapp/github-action@master
- uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
42 changes: 21 additions & 21 deletions javascript/JZZ.midi.SMF.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/* istanbul ignore next */
if (JZZ.MIDI.SMF) return;

var _ver = '1.9.1';
var _ver = '1.9.2';

var _now = JZZ.lib.now;
function _error(s) { throw new Error(s); }
Expand Down Expand Up @@ -150,20 +150,20 @@
};
SMF.prototype.load = function(s) {
var off = 0;
if (s.substr(0, 4) == 'RIFF' && s.substr(8, 8) == 'RMIDdata') {
if (s.substring(0, 4) == 'RIFF' && s.substring(8, 16) == 'RMIDdata') {
this.rmi = true;
off = 20;
s = s.substr(20, s.charCodeAt(16) + s.charCodeAt(17) * 0x100 + s.charCodeAt(18) * 0x10000 + s.charCodeAt(19) * 0x1000000);
s = s.substring(20, 20 + s.charCodeAt(16) + s.charCodeAt(17) * 0x100 + s.charCodeAt(18) * 0x10000 + s.charCodeAt(19) * 0x1000000);
}
_loadSMF(this, s, off);
};

var MThd0006 = 'MThd' + String.fromCharCode(0) + String.fromCharCode(0) + String.fromCharCode(0) + String.fromCharCode(6);
function _loadSMF(self, s, off) {
if (s.substr(0, 8) != MThd0006) {
if (s.substring(0, 8) != MThd0006) {
var z = s.indexOf(MThd0006);
if (z != -1) {
s = s.substr(z);
s = s.substring(z);
self._complain(off, 'Extra leading characters', z);
off += z;
}
Expand Down Expand Up @@ -191,15 +191,15 @@
var p = 14;
while (p < s.length - 8) {
var offset = p + off;
var type = s.substr(p, 4);
var type = s.substring(p, p + 4);
if (type == 'MTrk') n++;
var len = (s.charCodeAt(p + 4) << 24) + (s.charCodeAt(p + 5) << 16) + (s.charCodeAt(p + 6) << 8) + s.charCodeAt(p + 7);
if (len <= 0) { // broken file
len = s.length - p - 8;
self._complain(p + off + 4, 'Invalid track length', s.charCodeAt(p + 4) + '/' + s.charCodeAt(p + 5) + '/' + s.charCodeAt(p + 6) + '/' + s.charCodeAt(p + 7));
}
p += 8;
var data = s.substr(p, len);
var data = s.substring(p, p + len);
self.push(new Chunk(type, data, offset));
if (type == 'MThd') self._complain(offset, 'Unexpected chunk type', 'MThd');
p += len;
Expand Down Expand Up @@ -572,14 +572,14 @@
};

function _validate_msg_data(trk, s, p, m, t, off) {
var x = s.substr(p, m);
var x = s.substring(p, p + m);
if (x.length < m) {
trk._complain(off, 'Incomplete track data', m - x.length, t);
x = (x + '\x00\x00').substr(0, m);
x = (x + '\x00\x00').substring(0, m);
}
for (var i = 0; i < m; i++) if (x.charCodeAt(i) > 127) {
trk._complain(off + i, 'Bad MIDI value set to 0', x.charCodeAt(i), t);
x = x.substr(0, i) + '\x00' + x.substr(i + 1);
x = x.substring(0, i) + '\x00' + x.substring(i + 1);
}
return x;
}
Expand Down Expand Up @@ -619,32 +619,32 @@
off += 8;
var offset = p + off;
while (p < s.length) {
m = _validate_number(this, s.substr(p, 4), offset, t, true);
m = _validate_number(this, s.substring(p, p + 4), offset, t, true);
p += m[0];
t += m[1];
offset = p + off;
if (s.charCodeAt(p) == 0xff) {
st = s.substr(p, 2);
st = s.substring(p, p + 2);
if (st.length < 2) {
this._complain(offset, 'Incomplete track data', 3 - st.length, t);
st = '\xff\x2f';
}
p += 2;
m = _validate_number(this, s.substr(p, 4), offset + 2, t);
m = _validate_number(this, s.substring(p, p + 4), offset + 2, t);
p += m[0];
this.push (new Event(t, st, s.substr(p, m[1]), offset));
this.push (new Event(t, st, s.substring(p, p + m[1]), offset));
p += m[1];
}
else if (s.charCodeAt(p) == 0xf0 || s.charCodeAt(p) == 0xf7) {
st = s.substr(p, 1);
st = s.substring(p, p + 1);
p += 1;
m = _validate_number(this, s.substr(p, 4), offset + 1, t);
m = _validate_number(this, s.substring(p, p + 4), offset + 1, t);
p += m[0];
this.push(new Event(t, st, s.substr(p, m[1]), offset));
this.push(new Event(t, st, s.substring(p, p + m[1]), offset));
p += m[1];
}
else if (s.charCodeAt(p) & 0x80) {
w = s.substr(p, 1);
w = s.substring(p, p + 1);
p += 1;
m = _msglen(w.charCodeAt(0));
if (w.charCodeAt(0) > 0xf0) this._complain(offset, 'Unexpected MIDI message', w.charCodeAt(0).toString(16), t);
Expand Down Expand Up @@ -673,8 +673,8 @@
function _shortmsg(msg) {
var s = msg.toString();
if (s.length > 80) {
s = s.substr(0, 78);
s = s.substr(0, s.lastIndexOf(' ')) + ' ...';
s = s.substring(0, 78);
s = s.substring(0, s.lastIndexOf(' ')) + ' ...';
}
return s;
}
Expand Down Expand Up @@ -1444,7 +1444,7 @@
}
function _loadClip(clip, s, off) {
if (!s.length) _error('Empty clip');
if (s.substr(0, 8) != SMF2CLIP) {
if (s.substring(0, 8) != SMF2CLIP) {
var z = s.indexOf(SMF2CLIP);
if (z != -1) {
off += z;
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.midi.SMF.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jzz-midi-smf",
"version": "1.9.1",
"version": "1.9.2",
"description": "Standard MIDI Files: read / write / play (MIDI 1.0 and MIDI 2.0)",
"main": "javascript/JZZ.midi.SMF.js",
"scripts": {
Expand All @@ -18,19 +18,19 @@
],
"author": "jazz-soft (https://jazz-soft.net/)",
"dependencies": {
"jzz": "^1.8.1"
"jzz": "^1.8.4"
},
"devDependencies": {
"eslint": "^8.57.0",
"eslint": "^9.2.0",
"grunt": "^1.6.1",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-uglify": "^5.2.2",
"jzz-gui-player": "^1.7.2",
"jzz-gui-player": "^1.7.3",
"jzz-midi-gm": "^1.3.6",
"jzz-synth-tiny": "^1.3.8",
"jzz-synth-tiny": "^1.4.0",
"mocha": "^10.4.0",
"nyc": "^15.1.0",
"test-midi-files": "^1.0.5"
"test-midi-files": "^1.0.7"
},
"runkitExampleFilename": "runkit.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('functions', function() {
});
assert.throws(function() { // Invalid MIDI header
var dump = JZZ.MIDI.SMF(0, 24, 16).dump();
JZZ.MIDI.SMF(dump.substr(0, 13) + '\0' + dump.substr(14));
JZZ.MIDI.SMF(dump.substring(0, 13) + '\0' + dump.substring(14));
});
assert.throws(function() {
JZZ.MIDI.SMF.Chunk();
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('functions', function() {
.dataIncr(3).rpn(4, 0x7f, 0x7f).dataDecr(4)
;
var dump = smf.dump();
dump = dump.substr(0, 9) + '\3' + dump.substr(10);
dump = dump.substring(0, 9) + '\3' + dump.substring(10);
dump = dump.replace('MTrk', 'MThd')
dump = dump.replace('\xf0\7\xf7\xf7\xf7\xf7\xf7\xf7\xf7', '\xf1\0\0\xf3\0\0\xf2\0\0');
smf = JZZ.MIDI.SMF(dump);
Expand Down

0 comments on commit 05a4f16

Please sign in to comment.