Skip to content

Commit

Permalink
UMP.toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Sep 13, 2023
1 parent 5a7a5e2 commit ce2aa8d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 19 deletions.
80 changes: 67 additions & 13 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -3149,29 +3149,83 @@
var n, s;
var t = this[0] >> 4;
if (t == 1 || t == 2) return new MIDI(this.slice(1))._string();
if (t == 0) {
else if (t == 0) {
n = this[1] >> 4;
s = ['NOOP', 'JR Clock', 'JR Timestamp', 'Ticks Per Quarter Note', 'Delta Ticks'][n];
return s;
}
if (t == 4) {
else if (t == 3) {
s = 'SysEx';
}
else if (t == 4) {
n = this[1] >> 4;
s = {
0: 'Registered Per-Note Controller',
1: 'Assignable Per-Note Controller',
2: 'Registered Controller',
3: 'Assignable Controller',
4: 'Relative Registered Controller',
5: 'Relative Assignable Controller',
6: 'Per-Note Pitch Bend',
8: 'Note Off',
9: 'Note On'
9: 'Note On',
10: 'Poly Pressure',
11: 'Control Change',
12: 'Program Change',
13: 'Channel Pressure',
14: 'Pitch Bend',
15: 'Per-Note Management'
}[n];
return s;
}
if (this[0] == 0xd0) {
if (this[2] == 0) {
if (this[3] == 0) return 'Tempo ' + this.getBPM() + ' BPM';
if (this[3] == 1) return 'Time Signature ' + this.getTimeSignature().join('/');
}
}
if (this[0] == 0xf0) {
else if (t == 5) {
s = 'Data';
}
else if (t == 13) {
n = this[2];
if (n == 0) {
n = this[3];
s = {
0: 'Tempo ',
1: 'Time Signature ',
2: 'Metronome',
5: 'Key Signature',
6: 'Chord Name'
}[n];
if (n == 0) s += this.getBPM() + ' BPM';
else if (n == 1) s += this.getTimeSignature().join('/');
}
else if (n == 1) {
n = this[3];
s = {
0: 'Metadata Text',
1: 'Project Name',
2: 'Composition Name',
3: 'Clip Name',
4: 'Copyright',
5: 'Composer Name',
6: 'Lyricist Name',
7: 'Arranger Name',
8: 'Publisher Name',
9: 'Primary Performer Name',
10: 'Accompanying Performer Name',
11: 'Recording Date',
12: 'Recording Location'
}[n];
}
else if (n == 2) {
n = this[3];
s = {
0: 'Performance Text',
1: 'Lyrics',
2: 'Lyrics Language',
3: 'Ruby',
4: 'Ruby Language',
}[n];
}
}
if (t == 15) {
s = { 0x20: 'Start of Clip', 0x21: 'End of Clip' }[this[1]];
return s;
}
return s;
};

UMP.prototype._stamp = MIDI.prototype._stamp;
Expand Down
16 changes: 10 additions & 6 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ describe('UMP messages', function() {
assert.equal(msg.toString(), s);
});
it('sxIdRequest', function() {
var s = '37047e7f 06010000';
var s = '37047e7f 06010000 -- SysEx';
var msg = JZZ.UMP.sxId(1).sxId(1).sxId().sxId().sxIdRequest(7)[0];
assert.equal(msg.getGroup(), 7);
assert.equal(msg.toString(), s);
Expand All @@ -850,13 +850,13 @@ describe('UMP messages', function() {
assert.equal(msg.toString(), s);
});
it('sxMasterVolume', function() {
assert.equal(JZZ.UMP.sxMasterVolumeF(5, 0.5).toString(), '35067f7f 04010040');
assert.equal(JZZ.UMP.sxMasterVolumeF(5, 0.5).toString(), '35067f7f 04010040 -- SysEx');
});
it('sxGS', function() {
assert.equal(JZZ.UMP.sxGS(5).toString(), '3516417f 42124000,35337f00 41000000');
assert.equal(JZZ.UMP.sxGS(5).toString(), '3516417f 42124000 -- SysEx,35337f00 41000000 -- SysEx');
});
it('sxMidiSoft', function() {
assert.equal(JZZ.UMP.sxMidiSoft(5, 4, 'karaoke...').toString(), '35160020 2400046b,35266172 616f6b65,35332e2e 2e000000');
assert.equal(JZZ.UMP.sxMidiSoft(5, 4, 'karaoke...').toString(), '35160020 2400046b -- SysEx,35266172 616f6b65 -- SysEx,35332e2e 2e000000 -- SysEx');
});
it('umpClock', function() {
assert.equal(JZZ.UMP.umpClock(96).toString(), '00100060 -- JR Clock');
Expand Down Expand Up @@ -910,6 +910,10 @@ describe('UMP messages', function() {
assert.throws(function() { JZZ.UMP.gr(0).umpTimeSignature(100, 4); });
assert.throws(function() { JZZ.UMP.gr(0).umpTimeSignature(); });
});
it('umpKeySignature', function() {
var s = 'd0100005 00000000 00000000 00000000 -- Key Signature';
assert.equal(JZZ.UMP([0xd0, 0x10, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), s);
});
it('umpNoteOn', function() {
var s = '41923d00 ffff0000 -- Note On';
var msg = JZZ.UMP.umpNoteOn(1, 2, 'C#5');
Expand Down Expand Up @@ -937,8 +941,8 @@ describe('UMP messages', function() {
});

it('unknown', function() {
assert.equal(JZZ.UMP([0xd0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), 'd0000500 00000000 00000000 00000000');
assert.equal(JZZ.UMP([0xd0, 0x10, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), 'd0100005 00000000 00000000 00000000');
assert.equal(JZZ.UMP([0xd0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), 'd0000700 00000000 00000000 00000000');
assert.equal(JZZ.UMP([0xd0, 0x10, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), 'd0100007 00000000 00000000 00000000');
});
});

Expand Down

0 comments on commit ce2aa8d

Please sign in to comment.