import $ from "jquery" ; /**
 * Save the chord progression as a midi file
 */ export class MidiSaver { downloadBtn : HTMLElement ; onGetChords : Function ; constructor ( ) { this . onGetChords = function ( ) { } ; this . downloadBtn = document . getElementById ( "downloadBtn" ) ! ; this . downloadBtn . addEventListener ( "pointerup" , ( ) => { this . _write ( ) ; } ) ; $ ( "#downloadBtn" ) . tooltip ( ) ; } returns private _getChords ( ) { return this . onGetChords ( ) ; } /**
     * Write the chords to a MIDI file, and download it
     * Reference: https://github.com/grimmdude/MidiWriterJS
     */ private _write ( ) { const chords = this . _getChords ( ) ; const MidiWriter = require ( 'midi-writer-js' ) ; const track = new MidiWriter . Track ( ) ; track . addEvent ( new MidiWriter . ProgramChangeEvent ( { instrument : 1 } ) ) ; for ( let chord of chords ) { const pitch = chord . getNotes ( ) ; var note = new MidiWriter . NoteEvent ( { pitch : pitch , duration : '2' } ) ; track . addEvent ( note ) ; } var write = new MidiWriter . Writer ( track ) ; document . getElementById ( 'my_iframe' ) ! . src = write . dataUri ( ) ; } }