Skip to content

Commit

Permalink
Fixed gs/xgMasterScaleTuning()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Oct 21, 2023
1 parent 70d0896 commit 28e3397
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
11 changes: 6 additions & 5 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -1840,13 +1840,14 @@
};
function _splitMasterTuning(a, b, c, d) {
if (typeof b != 'undefined') return [_7b(a), _7b(b), _7b(c), _7b(d)];
if (a != parseInt(a) || a < 0 || n > 0xffff) _bad(a);
if (a != parseInt(a) || a < 0 || a > 0xffff) _bad(a);
a = parseInt(a);
return [(a >> 12) & 0xf, (a >> 8) & 0xf, (a >> 4) & 0xf, a & 0xf];
}
function _gsxg12b(x) { // -1 <= x <= 1
function _gsxg16b(x) { // -1 <= x <= 1
_float(x);
return Math.round(x * 1000 + 0x400);
x = Math.round(x * 0x10000 + 0x4000);
return x < 0 ? 0 : x > 0xffff ? 0xffff : x;
}
var _helperNC = { // no channel
mtc: function(t) { return [0xF1, _mtc(t)]; },
Expand Down Expand Up @@ -1915,7 +1916,7 @@
gsMasterVolume: function(n) { return _helperSX.sxGS.call(this, [0x40, 0, 4, _7b(n)]); },
gsMasterVolumeF: function(x) { return _helperSX.gsMasterVolume.call(this, MIDI.to7b(_01(x))); },
gsMasterFineTuning: function(a, b, c, d) { a = _splitMasterTuning(a, b, c, d); return _helperSX.sxGS.call(this, [0x40, 0, 0, a[0], a[1], a[2], a[3]]); },
gsMasterFineTuningF: function(x) { return _helperSX.gsMasterFineTuning.call(this, _gsxg12b(x % 1)); },
gsMasterFineTuningF: function(x) { return _helperSX.gsMasterFineTuning.call(this, _gsxg16b(x % 1)); },
gsMasterCoarseTuning: function(n) { return _helperSX.sxGS.call(this, [0x40, 0, 5, _7b(n)]); },
gsMasterCoarseTuningF: function(x) { return _helperSX.gsMasterCoarseTuning.call(this, 0x40 + (x - x % 1)); },
gsOctaveTuning: function(c, n, x) { return _helperSX.sxGS.call(this, [0x40, 0x10 + [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15][_ch(c)], 0x40 + MIDI.octaveValue(n), _7b(x)]); },
Expand All @@ -1924,7 +1925,7 @@
xgMasterVolume: function(n) { return _helperSX.sxXG.call(this, [0, 0, 4, _7b(n)]); },
xgMasterVolumeF: function(x) { return _helperSX.xgMasterVolume.call(this, MIDI.to7b(_01(x))); },
xgMasterFineTuning: function(a, b, c, d) { a = _splitMasterTuning(a, b, c, d); return _helperSX.sxXG.call(this, [0, 0, 0, a[0], a[1], a[2], a[3]]); },
xgMasterFineTuningF: function(x) { return _helperSX.xgMasterFineTuning.call(this, _gsxg12b(x % 1)); },
xgMasterFineTuningF: function(x) { return _helperSX.xgMasterFineTuning.call(this, _gsxg16b(x % 1)); },
xgMasterCoarseTuning: function(n) { return _helperSX.sxXG.call(this, [0, 0, 6, _7b(n)]); },
xgMasterCoarseTuningF: function(x) { return _helperSX.xgMasterCoarseTuning.call(this, 0x40 + (x - x % 1)); },
xgOctaveTuning: function(c, n, x) { return _helperSX.sxXG.call(this, [8, _ch(c), 0x41 + MIDI.octaveValue(n), _7b(x)]); },
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
],
"author": "jazz-soft (https://jazz-soft.net/)",
"dependencies": {
"@types/webmidi": "^2.0.8",
"@types/webmidi": "^2.0.9",
"jazz-midi": "^1.7.9"
},
"devDependencies": {
"eslint": "^8.51.0",
"eslint": "^8.52.0",
"grunt": "^1.6.1",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-uglify": "^5.2.2",
Expand Down
31 changes: 13 additions & 18 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,17 @@ describe('MIDI messages', function() {
assert.equal(JZZ.MIDI.gsMasterFineTuning(0, 1, 2, 3).toString(), 'f0 41 7f 42 12 40 00 00 00 01 02 03 3a f7');
assert.equal(JZZ.MIDI.gsMasterFineTuning(0x123).toString(), 'f0 41 7f 42 12 40 00 00 00 01 02 03 3a f7');
assert.throws(function() { JZZ.MIDI.gsMasterFineTuning(); });
assert.equal(JZZ.MIDI.gsMasterFineTuningF(0).toString(), 'f0 41 7f 42 12 40 00 00 00 04 00 00 3c f7');
assert.equal(JZZ.MIDI.gsMasterFineTuningF(0.9999).toString(), 'f0 41 7f 42 12 40 00 00 00 07 0e 08 23 f7');
assert.equal(JZZ.MIDI.gsMasterFineTuningF(-0.9999).toString(), 'f0 41 7f 42 12 40 00 00 00 00 01 08 37 f7');
assert.equal(JZZ.MIDI.gsMasterFineTuningF(0).toString(), 'f0 41 7f 42 12 40 00 00 04 00 00 00 3c f7');
assert.equal(JZZ.MIDI.gsMasterFineTuningF(0.9999).toString(), 'f0 41 7f 42 12 40 00 00 0f 0f 0f 0f 04 f7');
assert.equal(JZZ.MIDI.gsMasterFineTuningF(-0.9999).toString(), 'f0 41 7f 42 12 40 00 00 00 00 00 00 40 f7');
assert.equal(JZZ.MIDI.gsMasterCoarseTuning(0x41).toString(), 'f0 41 7f 42 12 40 00 05 41 7a f7');
assert.equal(JZZ.MIDI.gsMasterCoarseTuningF(1).toString(), 'f0 41 7f 42 12 40 00 05 41 7a f7');
assert.equal(JZZ.MIDI.gsMasterTranspose(0x41).toString(), 'f0 41 7f 42 12 40 00 05 41 7a f7');
assert.equal(JZZ.MIDI.gsMasterTransposeF(1).toString(), 'f0 41 7f 42 12 40 00 05 41 7a f7');
assert.equal(JZZ.MIDI.gsMasterTuningF(1.5)[0].toString(), 'f0 41 7f 42 12 40 00 05 41 7a f7');
assert.equal(JZZ.MIDI.gsMasterTuningF(1.5)[1].toString(), 'f0 41 7f 42 12 40 00 00 00 05 0f 04 28 f7');
assert.equal(JZZ.MIDI.gsMasterTuningF(1.5)[1].toString(), 'f0 41 7f 42 12 40 00 00 0c 00 00 00 34 f7');
assert.equal(JZZ.MIDI.gsMasterTuningA(880)[0].toString(), 'f0 41 7f 42 12 40 00 05 4c 6f f7');
assert.equal(JZZ.MIDI.gsMasterTuningA(880)[1].toString(), 'f0 41 7f 42 12 40 00 00 00 04 00 00 3c f7');
assert.equal(JZZ.MIDI.gsMasterTuningA(880)[1].toString(), 'f0 41 7f 42 12 40 00 00 04 00 00 00 3c f7');
});
it('gsOctaveTuning', function() {
assert.equal(JZZ.MIDI.gsOctaveTuning(1, 'C5', 114).toString(), 'f0 41 7f 42 12 40 12 40 72 7c f7');
Expand All @@ -688,17 +688,17 @@ describe('MIDI messages', function() {
assert.equal(JZZ.MIDI.xgMasterFineTuning(0, 1, 2, 3).toString(), 'f0 43 10 4c 00 00 00 00 01 02 03 f7');
assert.equal(JZZ.MIDI.xgMasterFineTuning(0x123).toString(), 'f0 43 10 4c 00 00 00 00 01 02 03 f7');
assert.throws(function() { JZZ.MIDI.xgMasterFineTuning(); });
assert.equal(JZZ.MIDI.xgMasterFineTuningF(0).toString(), 'f0 43 10 4c 00 00 00 00 04 00 00 f7');
assert.equal(JZZ.MIDI.xgMasterFineTuningF(0.9999).toString(), 'f0 43 10 4c 00 00 00 00 07 0e 08 f7');
assert.equal(JZZ.MIDI.xgMasterFineTuningF(-0.9999).toString(), 'f0 43 10 4c 00 00 00 00 00 01 08 f7');
assert.equal(JZZ.MIDI.xgMasterFineTuningF(0).toString(), 'f0 43 10 4c 00 00 00 04 00 00 00 f7');
assert.equal(JZZ.MIDI.xgMasterFineTuningF(0.9999).toString(), 'f0 43 10 4c 00 00 00 0f 0f 0f 0f f7');
assert.equal(JZZ.MIDI.xgMasterFineTuningF(-0.9999).toString(), 'f0 43 10 4c 00 00 00 00 00 00 00 f7');
assert.equal(JZZ.MIDI.xgMasterCoarseTuning(0x41).toString(), 'f0 43 10 4c 00 00 06 41 f7');
assert.equal(JZZ.MIDI.xgMasterCoarseTuningF(1).toString(), 'f0 43 10 4c 00 00 06 41 f7');
assert.equal(JZZ.MIDI.xgMasterTranspose(0x41).toString(), 'f0 43 10 4c 00 00 06 41 f7');
assert.equal(JZZ.MIDI.xgMasterTransposeF(1).toString(), 'f0 43 10 4c 00 00 06 41 f7');
assert.equal(JZZ.MIDI.xgMasterTuningF(1.5)[0].toString(), 'f0 43 10 4c 00 00 06 41 f7');
assert.equal(JZZ.MIDI.xgMasterTuningF(1.5)[1].toString(), 'f0 43 10 4c 00 00 00 00 05 0f 04 f7');
assert.equal(JZZ.MIDI.xgMasterTuningF(1.5)[1].toString(), 'f0 43 10 4c 00 00 00 0c 00 00 00 f7');
assert.equal(JZZ.MIDI.xgMasterTuningA(880)[0].toString(), 'f0 43 10 4c 00 00 06 4c f7');
assert.equal(JZZ.MIDI.xgMasterTuningA(880)[1].toString(), 'f0 43 10 4c 00 00 00 00 04 00 00 f7');
assert.equal(JZZ.MIDI.xgMasterTuningA(880)[1].toString(), 'f0 43 10 4c 00 00 00 04 00 00 00 f7');
});
it('xgOctaveTuning', function() {
assert.equal(JZZ.MIDI.xgOctaveTuning(1, 'C5', 114).toString(), 'f0 43 10 4c 08 01 41 72 f7');
Expand Down Expand Up @@ -867,7 +867,7 @@ describe('UMP messages', function() {
assert.equal(JZZ.UMP.sxMidiSoft(5, 4, 'karaoke...').toString(), '35160020 2400046b -- SysEx,35266172 616f6b65 -- SysEx,35332e2e 2e000000 -- SysEx');
});
it('xgMasterTuningA', function() {
var s = '30164310 4c000006 -- SysEx,30314000 00000000 -- SysEx,30164310 4c000000 -- SysEx,30340004 00000000 -- SysEx';
var s = '30164310 4c000006 -- SysEx,30314000 00000000 -- SysEx,30164310 4c000000 -- SysEx,30340400 00000000 -- SysEx';
assert.equal(JZZ.UMP.xgMasterTuningA(0, 440).toString(), s);
assert.equal(JZZ.UMP.gr(0).xgMasterTuningA(440).toString(), s);
});
Expand Down Expand Up @@ -1483,22 +1483,17 @@ describe('JZZ.Widget', function() {
[48, 22, 67, 16, 76, 0, 0, 6],
[48, 49, 64, 0, 0, 0, 0, 0],
[48, 22, 67, 16, 76, 0, 0, 0],
[48, 52, 0, 4, 0, 0, 0, 0],
[48, 52, 4, 0, 0, 0, 0, 0],
[48, 22, 67, 16, 76, 0, 0, 6],
[48, 49, 64, 0, 0, 0, 0, 0],
[48, 22, 67, 16, 76, 0, 0, 0],
[48, 52, 0, 4, 0, 0, 0, 0]
[48, 52, 4, 0, 0, 0, 0, 0]
]);
var port = JZZ.Widget().MIDI2();
port.connect(function(msg) { sample.compare(msg); });
assert.equal(port.connected(), 1);
port.xgMasterTuningA(0, 440).gr(0).xgMasterTuningA(440).disconnect();
});
it('xgMasterTuningA', function() {
var s = '30164310 4c000006 -- SysEx,30314000 00000000 -- SysEx,30164310 4c000000 -- SysEx,30340004 00000000 -- SysEx';
assert.equal(JZZ.UMP.xgMasterTuningA(0, 440).toString(), s);
assert.equal(JZZ.UMP.gr(0).xgMasterTuningA(440).toString(), s);
});
it('umpBPM', function(done) {
var sample = new test.Sample(done, [
[209, 16, 0, 0, 2, 250, 240, 128, 0, 0, 0, 0, 0, 0, 0, 0],
Expand Down

0 comments on commit 28e3397

Please sign in to comment.