Skip to content

Commit

Permalink
Export MIDI-1.0 SysEx
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jun 25, 2023
1 parent 12c54d8 commit 48367b7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
28 changes: 28 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -2874,12 +2874,24 @@

function _UMP() {}
_UMP.prototype = UMP;
UMP._sxid = 0x7f;
UMP.sxId = function(id) {
if (typeof id == 'undefined') id = UMP._sxid;
if (id == this._sxid) return this;
id = _7b(id);
var ret = new _UMP();
ret._ch = this._ch;
ret._gr = this._gr;
ret._sxid = id;
return ret;
};
UMP.ch = function(c) {
if (c == this._ch || typeof c == 'undefined' && typeof this._ch == 'undefined') return this;
var ret = new _UMP();
if (typeof c != 'undefined') c = _ch(c);
ret._ch = c;
ret._gr = this._gr;
ret._sxid = this._sxid;
return ret;
};
UMP.gr = function(g) {
Expand All @@ -2888,6 +2900,7 @@
if (typeof g != 'undefined') g = _ch(g);
ret._ch = this._ch;
ret._gr = g;
ret._sxid = this._sxid;
return ret;
};
UMP.prototype.getGroup = function() {
Expand Down Expand Up @@ -2926,6 +2939,20 @@
return new UMP([0x10 + args[0]].concat(func.apply(this, args.slice(1)), [0, 0]).slice(0, 4));
};
}
function _umpseqstat(n, i) { return n == 1 ? 0 : i == 0 ? 0x10 : i == n - 1 ? 0x30 : 0x20; }
function _sliceSX(gr, m) {
var a = [];
for (var x = m.slice(1, m.length - 1); x.length; x = x.slice(6)) a.push(x.slice(0, 6));
for (var i = 0; i < a.length; i++) a[i] = new UMP([0x30 + gr, _umpseqstat(a.length, i) + a[i].length].concat(a[i], [0, 0, 0, 0, 0]).slice(0, 8));
return a;
}
function _copyHelperSX(name, func) {
UMP[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
return _sliceSX(args[0], func.apply(this, args.slice(1)));
};
}
function _copyHelperM1(name, func) {
UMP[name] = function() {
var args = Array.prototype.slice.call(arguments);
Expand All @@ -2939,6 +2966,7 @@
_for(_helperMPE, function(n) { _copyHelperM1(n, _helperMPE[n]); });
_for(_helperCH, function(n) { _copyHelperM1(n, _helperCH[n]); });
_for(_helperNC, function(n) { _copyHelperGN(n, _helperNC[n]); });
_for(_helperSX, function(n) { _copyHelperSX(n, _helperSX[n]); });

UMP.prototype._stamp = MIDI.prototype._stamp;
UMP.prototype._unstamp = MIDI.prototype._unstamp;
Expand Down
28 changes: 26 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,10 @@ describe('UMP messages', function() {
assert.equal(JZZ.UMP.noteOff(1, 2, 'C#5', 64).toString(), '21823d40');
});
it('program', function() {
assert.equal(JZZ.UMP.program(1, 2, 15).toString(), '21c20f00');
var s = '21c20f00';
var msg = JZZ.UMP.program(1, 2, 15);
assert.equal(msg.getGroup(), 1);
assert.equal(JZZ.UMP.gr(1).program(2, 15).toString(), s);
});
it('damper', function() {
assert.equal(JZZ.UMP.damper(1, 2, true).toString(), '21b2407f');
Expand All @@ -807,7 +810,28 @@ describe('UMP messages', function() {
assert.equal(JZZ.UMP.songSelect(5, 15).toString(), '15f30f00');
});
it('reset', function() {
assert.equal(JZZ.UMP.reset(5).toString(), '15ff0000');
var s = '15ff0000';
var msg = JZZ.UMP.reset(5);
assert.equal(msg.getGroup(), 5);
assert.equal(msg.toString(), s);
msg = JZZ.UMP.gr(5).reset();
assert.equal(msg.getGroup(), 5);
assert.equal(msg.toString(), s);
});
it('sxIdRequest', function() {
var s = '37047e7f 06010000';
var msg = JZZ.UMP.sxId(1).sxId(1).sxId().sxId().sxIdRequest(7)[0];
assert.equal(msg.getGroup(), 7);
assert.equal(msg.toString(), s);
msg = JZZ.UMP.gr(7).sxIdRequest()[0];
assert.equal(msg.getGroup(), 7);
assert.equal(msg.toString(), s);
});
it('sxMasterVolume', function() {
assert.equal(JZZ.UMP.sxMasterVolumeF(5, 0.5).toString(), '35067f7f 04010040');
});
it('sxGS', function() {
assert.equal(JZZ.UMP.sxGS(5).toString(), '3516417f 42124000,35337f00 41000000');
});
});

Expand Down

0 comments on commit 48367b7

Please sign in to comment.