jazz-soft/JZZ-midi-SMF

MTrk fails without 'new' keyword

pearcemerritt opened this issue · 1 comments

The JZZ.MIDI.SMF reference says an MTrk can be created without new:
Screen Shot 2019-05-19 at 1 38 26 PM

However, I get this error:

/path/to/app/node_modules/jzz-midi-smf/javascript/JZZ.midi.SMF.js:339
      this.push(new Event(0, '\xff\x2f', ''));
           ^

TypeError: this.push is not a function
    at Function.MTrk (/path/to/app/node_modules/jzz-midi-smf/javascript/JZZ.midi.SMF.js:339:12)
    at Object.<anonymous> (/path/to/app/dist/smf_workspace.js:7:24)
...

when I run this code in Node.js:

var JZZ = require('jzz');
require('jzz-midi-smf')(JZZ);

var smf = new JZZ.MIDI.SMF(0, 96); // type 0, 96 ticks per quarter note
var trk = JZZ.MIDI.SMF.MTrk();
smf.push(trk);
// add contents:
trk.smfSeqName('This is a sequence name').smfBPM(90).tick(96)
   .ch(0).note('C6', 127, 96).note('Eb6', 127, 96).note('G6', 127, 96)
   .tick(192).smfEndOfTrack();

var midiout = JZZ().openMidiOut();
var player = smf.player();
player.connect(midiout);
player.play();

JZZ.close();

This code (except for JZZ.close()) is all copied from examples in README.md.

If I change the 5th line from

var trk = JZZ.MIDI.SMF.MTrk();

to

var trk = new JZZ.MIDI.SMF.MTrk();

I hear the C minor chord as expected

Great catch! Thanks a lot!
I have uploaded a new version.