Skip to content

Commit

Permalink
MidiSoft text
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jun 21, 2021
1 parent 94027b9 commit 2deab67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,11 @@
};
MIDI.prototype.getText = function() {
if (typeof this.dd != 'undefined') return JZZ.lib.fromUTF8(this.dd);
if (this.isMidiSoft()) {
var s = [];
for (var i = 6; i < this.length - 1; i++) s.push(String.fromCharCode(this[i]));
return s.join('');
}
};
MIDI.prototype.setText = function(dd) {
this.dd = JZZ.lib.toUTF8(dd);
Expand Down Expand Up @@ -2180,6 +2185,9 @@
MIDI.prototype.isFullSysEx = function() {
return this[0] == 0xf0 && this[this.length - 1] == 0xf7;
};
MIDI.prototype.isMidiSoft = function() {
return this.isFullSysEx() && this[1] == 0 && this[2] == 0x20 && this[3] == 0x24 && this[4] == 0;
};
MIDI.prototype.isSMF = function() {
return this.ff >= 0 && this.ff <= 0x7f;
};
Expand Down Expand Up @@ -2299,6 +2307,7 @@
255: 'Reset'
}[this[0]];
if (ss) return s + ' -- ' + ss;
if (this.isMidiSoft()) return s + ' -- [' + __hex(this[5]) + '] ' + _toLine(this.getText());
var c = this[0] >> 4;
ss = {8: 'Note Off', 10: 'Aftertouch', 12: 'Program Change', 13: 'Channel Aftertouch', 14: 'Pitch Wheel'}[c];
if (ss) return s + ' -- ' + ss;
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ describe('MIDI messages', function() {
assert.equal(JZZ.MIDI.sxGM(true).toString(), 'f0 7e 7f 09 01 f7');
assert.equal(JZZ.MIDI.sxGM(2).toString(), 'f0 7e 7f 09 03 f7');
});
it('sxMidiSoft', function() {
var msg = JZZ.MIDI([0xf0, 0x00, 0x20, 0x24, 0x00, 0x04, 0x22, 0x41, 0x4c, 0x42, 0x41, 0x43, 0x48, 0x49, 0x41, 0x52, 0x41, 0x22, 0x0a, 0xf7]);
assert.equal(msg.toString(), 'f0 00 20 24 00 04 22 41 4c 42 41 43 48 49 41 52 41 22 0a f7 -- [04] "ALBACHIARA"\\n');
});
it('reset', function() {
assert.equal(JZZ.MIDI.reset().toString(), 'ff -- Reset');
});
Expand Down

0 comments on commit 2deab67

Please sign in to comment.