close method

dynamic close()

Close the MIDIFile for further writing. To close the File for events, we must close the _tracks, adjust the time to be zero-origined, and have the _tracks write to their MIDI Stream data structure.

Implementation

/// To close the File for events, we must close the _tracks, adjust the time
/// to be zero-origined, and have the _tracks write to their MIDI Stream
/// data structure.

close() {
  if (this._closed) return;

  List.generate(this.numTracks, (i) {
    this._tracks[i].closeTrack();
    //  We want things like program changes to come before notes when
    //  they are at the same time, so we sort the MIDI events by both
    //  their start time and a secondary ordinality defined for each kind
    //  of event.
    this._tracks[i].MIDIEventList = sortEvents(this._tracks[i].MIDIEventList);
  });

  var origin = this.findOrigin();

  List.generate(this.numTracks, (i) {
    this._tracks[i].adjustTimeAndOrigin(origin, this._adjust_origin);
    this._tracks[i].writeMIDIStream();
  });

  this._closed = true;
}