Skip to content

Commit

Permalink
gs/xgMasterFineTuning()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Nov 14, 2021
1 parent c85332f commit 74432ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,12 @@
mono: function(c, n) { if (typeof n == 'undefined') n = 1; return [0xB0 + _ch(c), 0x7e, _7b(n)]; },
poly: function(c) { return [0xB0 + _ch(c), 0x7f, 0]; },
};
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);
a = parseInt(a);
return [(a >> 12) & 0xf, (a >> 8) & 0xf, (a >> 4) & 0xf, a & 0xf];
}
var _helperNC = { // no channel
mtc: function(t) { return [0xF1, _mtc(t)]; },
songPosition: function(n, l) { return typeof l == 'undefined' ? [0xF2, _lsb(n), _msb(n)] : [0xF2, _7b(l), _7b(n)]; },
Expand Down Expand Up @@ -1796,13 +1802,15 @@
a.push(0xf7); return a; },
gsMasterVolume: function(n) { return _helperNC.sxGS.call(this, [0x40, 0, 4, _7b(n)]); },
gsMasterVolumeF: function(x) { return _helperNC.gsMasterVolume.call(this, MIDI.to7b(_01(x))); },
gsMasterFineTuning: function(a, b, c, d) { a = _splitMasterTuning(a, b, c, d); return _helperNC.sxGS.call(this, [0x40, 0, 0, a[0], a[1], a[2], a[3]]); },
gsMasterCoarseTuning: function(n) { return _helperNC.sxGS.call(this, [0x40, 0, 5, _7b(n)]); },
gsMasterCoarseTuningF: function(x) { return _helperNC.gsMasterCoarseTuning.call(this, 0x40 + (x - x % 1)); },
gsOctaveTuning: function(c, n, x) { return _helperNC.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)]); },
gsOctaveTuningF: function(c, n, x) { if (x < -0.64 || x > 0.63) throw RangeError('Out of range: ' + x);
return _helperNC.gsOctaveTuning.call(this, c, n, Math.floor(x * 100 + 64)); },
xgMasterVolume: function(n) { return _helperNC.sxXG.call(this, [0, 0, 4, _7b(n)]); },
xgMasterVolumeF: function(x) { return _helperNC.xgMasterVolume.call(this, MIDI.to7b(_01(x))); },
xgMasterFineTuning: function(a, b, c, d) { a = _splitMasterTuning(a, b, c, d); return _helperNC.sxXG.call(this, [0, 0, 0, a[0], a[1], a[2], a[3]]); },
xgMasterCoarseTuning: function(n) { return _helperNC.sxXG.call(this, [0, 0, 6, _7b(n)]); },
xgMasterCoarseTuningF: function(x) { return _helperNC.xgMasterCoarseTuning.call(this, 0x40 + (x - x % 1)); },
xgOctaveTuning: function(c, n, x) { return _helperNC.sxXG.call(this, [8, _ch(c), 0x41 + MIDI.octaveValue(n), _7b(x)]); },
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,10 @@ describe('MIDI messages', function() {
assert.equal(JZZ.MIDI.gsMasterVolume(0x40).toString(), 'f0 41 7f 42 12 40 00 04 40 7c f7');
assert.equal(JZZ.MIDI.gsMasterVolumeF(0.5).toString(), 'f0 41 7f 42 12 40 00 04 40 7c f7');
});
it('gsMasterTranspose', function() {
it('gsMasterTuning', 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.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');
Expand All @@ -660,7 +663,10 @@ describe('MIDI messages', function() {
assert.equal(JZZ.MIDI.xgMasterVolume(0x40).toString(), 'f0 43 10 4c 00 00 04 40 f7');
assert.equal(JZZ.MIDI.xgMasterVolumeF(0.5).toString(), 'f0 43 10 4c 00 00 04 40 f7');
});
it('xgMasterTranspose', function() {
it('xgMasterTuning', 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.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');
Expand Down

0 comments on commit 74432ae

Please sign in to comment.