Skip to content

Commit

Permalink
smfSequencer() and smfMidiPort()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Mar 30, 2019
1 parent 8503d44 commit 8c9b5cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ by running `npm remove midi-test --save-dev`.
##### CDN

<script src="https://cdn.jsdelivr.net/npm/jzz"></script> // the latest version, or
<script src="https://cdn.jsdelivr.net/npm/jzz@0.7.1"></script> // any particular version
<script src="https://cdn.jsdelivr.net/npm/jzz@0.7.2"></script> // any particular version
//...

##### CommonJS (Browserify and Node.js command line applications)
Expand Down
19 changes: 16 additions & 3 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
})(this, function() {

var _scope = typeof window === 'undefined' ? global : window;
var _version = '0.7.1';
var _version = '0.7.2';
var i, j, k, m, n;

var _time = Date.now || function () { return new Date().getTime(); };
Expand Down Expand Up @@ -1576,6 +1576,18 @@
}
return _smf(32, dd);
},
smfMidiPort: function(dd) {
if (dd == parseInt(dd)) {
if (dd < 0 || dd > 127) throw RangeError('Port number out of range: ' + dd);
dd = String.fromCharCode(dd);
}
else {
dd = '' + dd;
if (dd.length == 0) dd = '\x00';
else if (dd.length > 1 || dd.charCodeAt(0) > 127) throw RangeError('Port number out of range: ' + _smftxt(dd));
}
return _smf(33, dd);
},
smfEndOfTrack: function(dd) {
if (_2s(dd) != '') throw RangeError('Unexpected data: ' + _smftxt(_2s(dd)));
return _smf(47);
Expand Down Expand Up @@ -1644,7 +1656,7 @@
if (dd.length == 2 && dd.charCodeAt(1) <= 1 && (dd.charCodeAt(0) <= 7 || dd.charCodeAt(0) <= 255 && dd.charCodeAt(0) >= 249)) return _smf(89, dd);
throw RangeError('Incorrect key signature: ' + _smftxt(dd));
},
smfMetaEvent: function(dd) { return _smf(127, _2s(dd)); }
smfSequencer: function(dd) { return _smf(127, _2s(dd)); }
};

function _copyPortHelper(M, name, func) {
Expand Down Expand Up @@ -1851,6 +1863,7 @@
if (this.ff == 0) s += 'Sequence Number: ' + _s2n(this.dd);
else if (this.ff > 0 && this.ff < 10) s += ['', 'Text', 'Copyright', 'Sequence Name', 'Instrument Name', 'Lyric', 'Marker', 'Cue Point', 'Program Name', 'Device Name'][this.ff] + _smftxt(this.dd);
else if (this.ff == 32) s += 'Channel Prefix' + _smfhex(this.dd);
else if (this.ff == 33) s += 'MIDI Port' + _smfhex(this.dd);
else if (this.ff == 47) s += 'End of Track' + _smfhex(this.dd);
else if (this.ff == 81) {
var ms = this.dd.charCodeAt(0) * 65536 + this.dd.charCodeAt(1) * 256 + this.dd.charCodeAt(2);
Expand All @@ -1875,7 +1888,7 @@
if (mi) s += ' min';
}
}
else if (this.ff == 127) s += 'Meta Event' + _smfhex(this.dd);
else if (this.ff == 127) s += 'Sequencer Specific' + _smfhex(this.dd);
else s += 'SMF' + _smfhex(this.dd);
return s;
}
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jzz",
"version": "0.7.1",
"version": "0.7.2",
"description": "MIDI library for Node.js and web-browsers",
"main": "javascript/JZZ.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
},
"devDependencies": {
"coveralls": "^3.0.3",
"grunt": "^1.0.3",
"grunt": "^1.0.4",
"grunt-contrib-jshint": "^2.0.0",
"grunt-contrib-uglify": "^4.0.0",
"istanbul": "^0.4.5",
Expand Down
25 changes: 15 additions & 10 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ describe('SMF events', function() {
assert.equal(JZZ.MIDI.smf(0x70).toString(), 'ff70 -- SMF');
});
it('smf', function() {
assert.equal(JZZ.MIDI.smf(JZZ.MIDI.smf(0x7f)).toString(), 'ff7f -- Meta Event');
assert.equal(JZZ.MIDI.smf([0x7f]).toString(), 'ff7f -- Meta Event');
assert.equal(JZZ.MIDI.smf(0x7f, [0, 1]).toString(), 'ff7f -- Meta Event: 00 01');
assert.equal(JZZ.MIDI.smf(0x7f, 0, 1).toString(), 'ff7f -- Meta Event: 00 01');
assert.equal(JZZ.MIDI.smf([0x7f, 0, 1]).toString(), 'ff7f -- Meta Event: 00 01');
assert.equal(JZZ.MIDI.smf(JZZ.MIDI.smf(0x7f)).toString(), 'ff7f -- Sequencer Specific');
assert.equal(JZZ.MIDI.smf([0x7f]).toString(), 'ff7f -- Sequencer Specific');
assert.equal(JZZ.MIDI.smf(0x7f, [0, 1]).toString(), 'ff7f -- Sequencer Specific: 00 01');
assert.equal(JZZ.MIDI.smf(0x7f, 0, 1).toString(), 'ff7f -- Sequencer Specific: 00 01');
assert.equal(JZZ.MIDI.smf([0x7f, 0, 1]).toString(), 'ff7f -- Sequencer Specific: 00 01');
assert.equal(JZZ.MIDI.smf(0x70, 'abc').toString(), 'ff70 -- SMF: 61 62 63');
});
it('smf/SeqNumber', function() {
Expand Down Expand Up @@ -235,6 +235,11 @@ describe('SMF events', function() {
assert.equal(JZZ.MIDI.smfChannelPrefix(10).toString(), 'ff20 -- Channel Prefix: 0a');
assert.equal(JZZ.MIDI.smfChannelPrefix('\n').toString(), 'ff20 -- Channel Prefix: 0a');
});
it('smf/MidiPort', function() {
assert.equal(JZZ.MIDI.smf(0x21, '\x0a').toString(), 'ff21 -- MIDI Port: 0a');
assert.equal(JZZ.MIDI.smfMidiPort(10).toString(), 'ff21 -- MIDI Port: 0a');
assert.equal(JZZ.MIDI.smfMidiPort('\n').toString(), 'ff21 -- MIDI Port: 0a');
});
it('smf/EndOfTrack', function() {
assert.equal(JZZ.MIDI.smf(0x2f).toString(), 'ff2f -- End of Track');
assert.equal(JZZ.MIDI.smfEndOfTrack().toString(), 'ff2f -- End of Track');
Expand Down Expand Up @@ -263,11 +268,11 @@ describe('SMF events', function() {
assert.equal(JZZ.MIDI.smfKeySignature('Eb major').toString(), 'ff59 -- Key Signature: Eb');
assert.equal(JZZ.MIDI.smfKeySignature('C').toString(), 'ff59 -- Key Signature: C');
});
it('smf/MetaEvent', function() {
assert.equal(JZZ.MIDI.smf(0x7f).toString(), 'ff7f -- Meta Event');
assert.equal(JZZ.MIDI.smf(0x7f, '\x0a\x0b\x0c').toString(), 'ff7f -- Meta Event: 0a 0b 0c');
assert.equal(JZZ.MIDI.smfMetaEvent('\x0a\x0b\x0c').toString(), 'ff7f -- Meta Event: 0a 0b 0c');
assert.equal(JZZ.MIDI.smfMetaEvent([0xa, 0xb, 0xc]).toString(), 'ff7f -- Meta Event: 0a 0b 0c');
it('smf/Sequencer', function() {
assert.equal(JZZ.MIDI.smf(0x7f).toString(), 'ff7f -- Sequencer Specific');
assert.equal(JZZ.MIDI.smf(0x7f, '\x0a\x0b\x0c').toString(), 'ff7f -- Sequencer Specific: 0a 0b 0c');
assert.equal(JZZ.MIDI.smfSequencer('\x0a\x0b\x0c').toString(), 'ff7f -- Sequencer Specific: 0a 0b 0c');
assert.equal(JZZ.MIDI.smfSequencer([0xa, 0xb, 0xc]).toString(), 'ff7f -- Sequencer Specific: 0a 0b 0c');
});
});

Expand Down

0 comments on commit 8c9b5cd

Please sign in to comment.