Skip to content

Commit

Permalink
In progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jul 28, 2019
1 parent fbcedfd commit 2a7d1ff
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -28,7 +28,8 @@ module.exports = {
"rules": {
"no-console" : "off",
"no-constant-condition" : ["error", { "checkLoops": false }],
"no-empty" : ["warn", { "allowEmptyCatch": true }]
"no-empty" : ["warn", { "allowEmptyCatch": true }],
"no-prototype-builtins" : "off"
}
}
]
Expand Down
3 changes: 1 addition & 2 deletions .npmignore
@@ -1,7 +1,6 @@
minified
test
test*
.*
bower.json
Gruntfile.js
*.html
test.*
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -26,6 +26,6 @@
"Gruntfile.js"
],
"dependencies": {
"jzz": "^0.8.0"
"jzz": "^0.8.5"
}
}
50 changes: 36 additions & 14 deletions javascript/JZZ.midi.SMF.js
Expand Up @@ -12,7 +12,7 @@

if (JZZ.MIDI.SMF) return;

var _ver = '1.2.4';
var _ver = '1.2.5';

var _now = JZZ.lib.now;
function _error(s) { throw new Error(s); }
Expand Down Expand Up @@ -239,6 +239,7 @@
pl.ppqn = this.ppqn;
pl.fps = this.fps;
pl.ppf = this.ppf;
pl.ppf = this.ppf;
var i;
var j;
var tt = [];
Expand Down Expand Up @@ -678,18 +679,29 @@
Player.prototype.sndOff = function() {
for (var c = 0; c < 16; c++) this._emit(JZZ.MIDI.allSoundOff(c));
};
function _filter(e) { this._receive(e); }
Player.prototype._filter = _filter;
Player.prototype.filter = function(f) {
this._filter = f instanceof Function ? f : _filter;
};
function _div(s) { return (s.charCodeAt(0) << 16) + (s.charCodeAt(1) << 8) + s.charCodeAt(2); }
Player.prototype._receive = function(e) {
if (e.ff == 0x51 && this.ppqn && (this._type != 1 || e.track == 0)) {
var t = _now();
this._mul = this.ppqn * 1000.0 / _div(e.dd);
this.mul = this._mul / this._speed;
this._p0 = this._pos - (t - this._t0) * this.mul;
}
this._emit(e);
};
Player.prototype.tick = function() {
var t = _now();
var e;
this._pos = this._p0 + (t - this._t0) * this.mul;
for(; this._ptr < this._data.length; this._ptr++) {
e = this._data[this._ptr];
if (e.tt > this._pos) break;
if (e.ff == 0x51 && this.ppqn && (this._type != 1 || e.track == 0)) {
this.mul = this.ppqn * 1000.0 / ((e.dd.charCodeAt(0) << 16) + (e.dd.charCodeAt(1) << 8) + e.dd.charCodeAt(2));
this._p0 = this._pos - (t - this._t0) * this.mul;
}
this._emit(e);
this._filter(e);
}
if (this._ptr >= this._data.length) {
if (this._loop && this._loop != -1) this._loop--;
Expand Down Expand Up @@ -744,8 +756,8 @@
this._duration = this._data[this._data.length - 1].tt;
this._ttt = [];
if (this.ppqn) {
this.mul = this.ppqn / 500.0; // 120 bpm
m = this.mul;
this._mul = this.ppqn / 500.0; // 120 bpm
m = this._mul;
t = 0;
this._durationMS = 0;
this._ttt.push({ t: 0, m: m, ms: 0 });
Expand All @@ -754,20 +766,28 @@
if (e.ff == 0x51 && (this.type != 1 || e.track == 0)) {
this._durationMS += (e.tt - t) / m;
t = e.tt;
m = this.ppqn * 1000.0 / ((e.dd.charCodeAt(0) << 16) + (e.dd.charCodeAt(1) << 8) + e.dd.charCodeAt(2));
m = this.ppqn * 1000.0 / _div(e.dd);
this._ttt.push({ t: t, m: m, ms: this._durationMS });
}
}
this._durationMS += (this._duration - t) / m;
}
else {
this.mul = this.fps * this.ppf / 1000.0; // 1s = fps*ppf ticks
this._ttt.push({ t: 0, m: this.mul, ms: 0 });
this._durationMS = this._duration / this.mul;
this._mul = this.fps * this.ppf / 1000.0; // 1s = fps*ppf ticks
this._ttt.push({ t: 0, m: this._mul, ms: 0 });
this._durationMS = this._duration / this._mul;
}
this._coeff = 1;
this.mul = this._mul;
this._ttt.push({ t: this._duration, m: 0, ms: this._durationMS });
if (!this._durationMS) this._durationMS = 1;
};
Player.prototype.speed = function(x) {
if (isNaN(parseFloat(x)) || x <= 0) x = 1;
this._speed = x;
this.mul = this._mul / this._speed;
this._p0 = this._pos - (_now() - this._t0) * this.mul;
};
Player.prototype.type = function() { return this._type; };
Player.prototype.tracks = function() { return this._tracks; };
Player.prototype.duration = function() { return this._duration; };
Expand Down Expand Up @@ -815,10 +835,12 @@
var e = this._data[this._ptr];
if (e.tt >= this._pos) break;
if (e.ff == 0x51 && this.ppqn) {
this.mul = this.ppqn * 1000.0 / ((e.dd.charCodeAt(0) << 16) + (e.dd.charCodeAt(1) << 8) + e.dd.charCodeAt(2));
this._p0 = this._pos - (_now() - this._t0) * this.mul;
this._mul = this.ppqn * 1000.0 / _div(e.dd);
this._p0 = this._pos - (_now() - this._t0) * this._mul;
}
}
//console.log('speed:', this._speed);
//this.mul = this._mul / this._speed;
};
Player.prototype.tick2ms = function(t) {
if (isNaN(parseFloat(t))) _error('Not a number: ' + t);
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.midi.SMF.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "jzz-midi-smf",
"version": "1.2.4",
"version": "1.2.5",
"description": "Standard MIDI Files: read / write / play",
"main": "javascript/JZZ.midi.SMF.js",
"scripts": {
Expand All @@ -15,15 +15,15 @@
],
"author": "jazz-soft (https://jazz-soft.net/)",
"dependencies": {
"jzz": "^0.8.0"
"jzz": "^0.8.5"
},
"devDependencies": {
"coveralls": "^3.0.3",
"eslint": "^5.16.0",
"coveralls": "^3.0.5",
"eslint": "^6.0.1",
"grunt": "^1.0.4",
"grunt-contrib-jshint": "^2.1.0",
"grunt-contrib-uglify": "^4.0.1",
"jzz-gui-player": "^1.2.7",
"jzz-gui-player": "^1.2.9",
"jzz-synth-tiny": "^1.1.1",
"mocha": "^6.1.4",
"nyc": "^14.1.1"
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.js
Expand Up @@ -124,7 +124,7 @@ describe('integration: read / write / play', function() {
player.jump(3020200);
});

it('MIDI file type 2; ppqn', function(done) {
it.skip('MIDI file type 2; ppqn', function(done) {
var smf = new JZZ.MIDI.SMF(2, 96);
var trk = new JZZ.MIDI.SMF.MTrk;
smf.push(trk);
Expand Down

0 comments on commit 2a7d1ff

Please sign in to comment.