import "bootstrap" ; import 'bootstrap/dist/css/bootstrap.css' ; import '@fortawesome/fontawesome-free/css/all.css' ; import "material-design-icons" ; import "bootstrap-submenu/dist/css/bootstrap-submenu.css" ; import "bootstrap-submenu/dist/js/bootstrap-submenu" ; import "jquery" ; import { Part , Transport } from "tone" ; import $ from "jquery" ; import { Piano } from "./keyboard/Piano" ; import { PianoSound } from "./sound/PianoSound" ; import { Loader } from "./interface/Loader" ; import { ChordTypeBtn } from "./setting-toolbar/ChordTypeBtn" ; import { InversionBtn } from "./setting-toolbar/InversionBtn" ; import { Chord } from "./music-theory/Chord" ; import { ChordProgression } from "./progression/ChordProgression" ; import { MidiSaver } from "./progression/MidiSaver" ; new Loader ( ) ; const chordTypeBtn = new ChordTypeBtn ( ) ; const inversionBtn = new InversionBtn ( ) ; const pianoContainer = document . getElementById ( "pianoContainer" ) ! ; const piano = new Piano ( pianoContainer ) ; const sound = new PianoSound ( 0 , 100 ) ; sound . load ( ) ; const progression = new ChordProgression ( ) ; const midiSaver = new MidiSaver ( ) ; param chord piano . onKeyDown = function ( chord ) { progression . setChord ( chord ) ; const notes = chord . getNotes ( ) ; sound . keyDown ( notes ) ; } ; param chord piano . onKeyUp = function ( chord ) { sound . keyUp ( chord ) ; } ; param chord piano . onSetChord = function ( chord ) { const notes = chord . getNotes ( ) ; sound . keyDownUp ( notes , 1 ) ; } ; param type param family chordTypeBtn . onSetChordType = function ( type , family ) { console . log ( `Set the type to ${ type }` ) ; const chordLen = Chord . getLen ( family , type ) ; inversionBtn . reset ( chordLen ) ; piano . setChordType ( family , type ) ; progression . setChordType ( family , type ) ; } ; param inversionNum inversionBtn . onSetInversion = function ( inversionNum ) { piano . setInversion ( inversionNum ) ; progression . setInversion ( inversionNum ) ; console . log ( `Set the inversion to ${ inversionNum }` ) ; } ; param chord progression . onActivate = function ( chord ) { piano . setChord ( chord ) ; chordTypeBtn . setTypeText ( chord . type ) ; inversionBtn . setInversionText ( chord ) ; console . log ( `Set the chord to ${ chord }` ) ; } ; let part = new Part ( ( ) => { } , [ ] ) ; param chords progression . onPlay = function ( chords ) { part . removeAll ( ) ; let events = [ ] ; for ( let i = 0 ; i < chords . length ; i ++ ) { const event = { "time" : i , "chord" : chords [ i ] } ; events . push ( event ) ; } part = new Part ( function ( time , value ) { progression . switch ( ) ; console . log ( `Play the chord ${ value . chord }` ) ; } , events ) . start ( 0 ) ; part . loop = true ; part . loopStart = 0 ; part . loopEnd = chords . length ; chordTypeBtn . disable ( ) ; inversionBtn . disable ( ) ; piano . disable ( ) ; this . activate ( this . curChordNameBtn ! ) ; Transport . start ( '+1.1' ) ; } ; /**
 * Enable the chord, inversion buttons and the piano interface after the progression stops to play
 * Enable the chord type, and inversion button and piano
 */ progression . onStop = function ( ) { chordTypeBtn . enable ( ) ; inversionBtn . enable ( ) ; piano . enable ( ) ; } ; /**
 * Get the chord progression from the progression for writing to the midi file
 */ midiSaver . onGetChords = function ( ) { return progression . chordsList ; } ; $ ( '#helpBtn' ) . tooltip ( ) ; window . onbeforeunload = function ( ) { return "Data will be lost if you leave the page, are you sure?" ; } ;