Skip to content

Commit

Permalink
_f_32()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Dec 25, 2023
1 parent 409cacd commit 32eec49
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
11 changes: 11 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,10 @@
a = _32b(a);
return [(a >> 24) & 255, (a >> 16) & 255, (a >> 8) & 255, a & 255];
}
function _f_32(x) {
x = Math.floor(x * 0x100000000);
return x > 0xffffffff ? 0xffffffff : x < 0 ? 0 : x;
}
var _helperNN = {
noop: function() { return [0, 0, 0, 0]; },
umpClock: function(n) { n = _16b(n); return [0, 0x10, n >> 8, n & 0xff]; },
Expand Down Expand Up @@ -3070,13 +3074,19 @@
umpAftertouch: function(g, c, n, x, y, z, w) {
return [0x40 + _4b(g), 0xa0 + _ch(c), _7bn(n), 0].concat(_32a(x, y, z, w));
},
umpAftertouchF: function(g, c, n, x) {
return _helperGC.umpAftertouch(g, c, n, _f_32(x));
},
umpControl: function(g, c, n, x, y, z, w) {
if (_noctrl.includes(n)) _throw(n);
return [0x40 + _4b(g), 0xb0 + _ch(c), _7b(n), 0].concat(_32a(x, y, z, w));
},
umpPressure: function(g, c, x, y, z, w) {
return [0x40 + _4b(g), 0xd0 + _ch(c), 0, 0].concat(_32a(x, y, z, w));
},
umpPressureF: function(g, c, x) {
return _helperGC.umpPressure(g, c, _f_32(x));
},
umpProgram: function(g, c, n, msb, lsb) {
return typeof msb == 'undefined' && typeof lsb == 'undefined' ?
[0x40 + _4b(g), 0xc0 + _ch(c), 0, 0, _7bn(n), 0, 0, 0] :
Expand Down Expand Up @@ -3112,6 +3122,7 @@
}
};
_helperGC.umpPnPressure = _helperGC.umpAftertouch;
_helperGC.umpPnPressureF = _helperGC.umpAftertouchF;
var _helperGCX = {
umpCustomText: function(g, c, d, b, s, t) {
var i;
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,10 +1042,16 @@ describe('UMP messages', function() {
it('umpAftertouch', function() {
assert.equal(JZZ.UMP.umpAftertouch(1, 2, 3, 0xf0f0f0f0).toString(), '41a20300 f0f0f0f0 -- Poly Pressure');
assert.equal(JZZ.UMP.umpPnPressure(1, 2, 3, 0xf0f0f0f0).toString(), '41a20300 f0f0f0f0 -- Poly Pressure');
assert.equal(JZZ.UMP.umpAftertouchF(1, 2, 3, 0).toString(), '41a20300 00000000 -- Poly Pressure');
assert.equal(JZZ.UMP.umpAftertouchF(1, 2, 3, 0.5).toString(), '41a20300 80000000 -- Poly Pressure');
assert.equal(JZZ.UMP.umpAftertouchF(1, 2, 3, 1).toString(), '41a20300 ffffffff -- Poly Pressure');
assert.throws(function() { JZZ.UMP.umpAftertouch(1, 2, 3, -1); });
});
it('umpPressure', function() {
assert.equal(JZZ.UMP.umpPressure(1, 2, 0xf0f0f0f0).toString(), '41d20000 f0f0f0f0 -- Channel Pressure');
assert.equal(JZZ.UMP.umpPressureF(1, 2, 10).toString(), '41d20000 ffffffff -- Channel Pressure');
assert.equal(JZZ.UMP.umpPressureF(1, 2, 0.75).toString(), '41d20000 c0000000 -- Channel Pressure');
assert.equal(JZZ.UMP.umpPressureF(1, 2, -1).toString(), '41d20000 00000000 -- Channel Pressure');
});
it('umpControl', function() {
var s = '41b20300 f0f0f0f0 -- Control Change';
Expand Down

0 comments on commit 32eec49

Please sign in to comment.