Skip to content

Commit

Permalink
ClipHeader fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Oct 28, 2023
1 parent 17ada20 commit da9ffd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions javascript/JZZ.midi.SMF.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@
self.playing = false;
self._loop = 0;
self._data = [];
self._hdr = [];
self._pos = 0;
self._tick = (function(x) { return function(){ x.tick(); }; })(self);
for (var k in Player.prototype) if (Player.prototype.hasOwnProperty(k)) self[k] = Player.prototype[k];
Expand Down Expand Up @@ -983,6 +984,10 @@
if (this.ppqn) {
this._mul = this.ppqn / 500.0; // 120 bpm
m = this._mul;
for (i = 0; i < this._hdr.length; i++) {
e = this._data[i];
if (e.isTempo()) m = this.ppqn * 100000.00 / (e.getTempo() || 1);
}
t = 0;
this._durationMS = 0;
this._ttt.push({ t: 0, m: m, ms: 0 });
Expand Down Expand Up @@ -1356,6 +1361,9 @@
ClipHdr.prototype._image = Clip.prototype._image;
ClipHdr.prototype.send = Clip.prototype.send;
ClipHdr.prototype.tick = Clip.prototype.tick;
ClipHdr.prototype.gr = Clip.prototype.gr;
ClipHdr.prototype.ch = Clip.prototype.ch;
ClipHdr.prototype.sxId = Clip.prototype.sxId;
ClipHdr.prototype.add = function(t, msg) {
t = parseInt(t);
if(isNaN(t) || t < 0) _error('Invalid parameter');
Expand Down Expand Up @@ -1515,9 +1523,13 @@
Clip.prototype.player = function() {
var pl = new Player();
pl.ppqn = this.ppqn;
var i;
var i, e;
for (i = 0; i < this.header.length; i++) {
e = JZZ.MIDI2(this.header[i]);
pl._hdr.push(e);
}
for (i = 0; i < this.length; i++) {
var e = JZZ.MIDI2(this[i]);
e = JZZ.MIDI2(this[i]);
pl._data.push(e);
}
pl._type = 0;
Expand Down
4 changes: 3 additions & 1 deletion test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ describe('SMF2', function() {
});
it('player', function() {
var clip = new JZZ.MIDI.Clip();
clip.header.gr(0).umpBPM(120).ch(0).program(8);
clip.gr(0).gr(0).ch(1).ch(1).sxId(2).sxId(2).noteOn('C5').tick(96).noteOff('C5').gr().gr().ch().ch().sxId().sxId();
clip.player();
var player = clip.player();
//console.log(player.durationMS());
});
});

0 comments on commit da9ffd0

Please sign in to comment.