Skip to content

Commit

Permalink
Coverage and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Nov 18, 2023
1 parent 86974e4 commit 5f909bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function chop(s, n) {
function populate(x, m) {
var i, j, k, h;
if (m instanceof JZZ.MIDI.Clip) {
h = { type: 'clip', ppqn: m.length };
h = { type: 'clip', ppqn: m.ppqn };
x.header = h;
}
else {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "runkit-midi",
"version": "1.1.0",
"version": "1.1.1",
"description": "MIDI player/viewer for RunKit",
"main": "index.js",
"scripts": {
Expand All @@ -24,6 +24,7 @@
"jzz-synth-tiny": "^1.3.7"
},
"devDependencies": {
"@runkit/value-viewer": "^1.0.0",
"eslint": "^8.53.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0"
Expand Down
44 changes: 32 additions & 12 deletions test/mocha.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
const assert = require('assert');
const { ValueViewerSymbol } = require("@runkit/value-viewer");
const rkmidi = require('..');
const JZZ = require('jzz');
require('jzz-midi-smf')(JZZ);

describe('smoke test', function() {
it('it works!', function() {
var smf = new JZZ.MIDI.SMF(0, 96);
var trk = new JZZ.MIDI.SMF.MTrk();
smf.push(trk);
trk.smfBPM(90).ch(0).program(16)
.tick(96).noteOn('C6', 127).tick(96).noteOn('Eb6', 127)
.tick(96).noteOn('G6', 127).tick(96).noteOn('C7', 127)
.tick(192).noteOff('C6').noteOff('Eb6').noteOff('G6')
.noteOff('C7').tick(96).smfEndOfTrack();
var data = rkmidi(smf);
assert.equal(data.ValueViewerSymbol.title, 'MIDI Player');
var clip = new JZZ.MIDI.Clip();
var smf1 = new JZZ.MIDI.SMF(0, 96);
var smf2 = new JZZ.MIDI.SMF(1, 24, 16);
var trk1 = new JZZ.MIDI.SMF.MTrk();
var trk2 = new JZZ.MIDI.SMF.Chunk('JUNK', 'JUNK');
smf1.push(trk1);
smf2.push(trk1);
smf2.push(trk2);
trk1.noteOn(0, 'C6', 127).tick(96).noteOff(0, 'C6');
clip.noteOn(0, 0, 'C6', 127).tick(96).noteOff(0, 0, 'C6');

describe('MIDI files', function() {
it('empty', function() {
var data = rkmidi();
assert.equal(data[ValueViewerSymbol].title, 'MIDI Player');
});
it('smf1', function() {
var data = rkmidi(smf1);
assert.equal(data[ValueViewerSymbol].title, 'MIDI Player');
});
it('smf2', function() {
var data = rkmidi(smf2);
assert.equal(data[ValueViewerSymbol].title, 'MIDI Player');
});
it('clip', function() {
var data = rkmidi(clip);
assert.equal(data[ValueViewerSymbol].title, 'MIDI Player');
});
it('error', function() {
var data = rkmidi('error');
assert.equal(data[ValueViewerSymbol].title, 'MIDI Player');
});
});

0 comments on commit 5f909bf

Please sign in to comment.