@@ -7,7 +7,7 @@ The following are some examples of common MIDI usage in JavaScript.
77This example shows how to request access to the MIDI system.
88
99``` js
10- var midi = null ; // global MIDIAccess object
10+ let midi = null ; // global MIDIAccess object
1111
1212function onMIDISuccess ( midiAccess ) {
1313 console .log ( " MIDI ready!" );
@@ -26,7 +26,7 @@ This example shows how to request access to the MIDI system, including the
2626ability to send and receive System Exclusive messages.
2727
2828``` js
29- var midi = null ; // global MIDIAccess object
29+ let midi = null ; // global MIDIAccess object
3030
3131function onMIDISuccess ( midiAccess ) {
3232 console .log ( " MIDI ready!" );
@@ -46,15 +46,15 @@ information to the console log, using ES6 for...of notation.
4646
4747``` js
4848function listInputsAndOutputs ( midiAccess ) {
49- for (var entry of midiAccess .inputs ) {
50- var input = entry[1 ];
49+ for (let entry of midiAccess .inputs ) {
50+ let input = entry[1 ];
5151 console .log ( " Input port [type:'" + input .type + " '] id:'" + input .id +
5252 " ' manufacturer:'" + input .manufacturer + " ' name:'" + input .name +
5353 " ' version:'" + input .version + " '" );
5454 }
5555
56- for (var entry of midiAccess .outputs ) {
57- var output = entry[1 ];
56+ for (let entry of midiAccess .outputs ) {
57+ let output = entry[1 ];
5858 console .log ( " Output port [type:'" + output .type + " '] id:'" + output .id +
5959 " ' manufacturer:'" + output .manufacturer + " ' name:'" + output .name +
6060 " ' version:'" + output .version + " '" );
@@ -68,8 +68,8 @@ the console log.
6868
6969``` js
7070function onMIDIMessage ( event ) {
71- var str = " MIDI message received at timestamp " + event .timeStamp + " [" + event .data .length + " bytes]: " ;
72- for (var i= 0 ; i& lt;event .data .length ; i++ ) {
71+ let str = " MIDI message received at timestamp " + event .timeStamp + " [" + event .data .length + " bytes]: " ;
72+ for (let i= 0 ; i& lt;event .data .length ; i++ ) {
7373 str += " 0x" + event .data [i].toString (16 ) + " " ;
7474 }
7575 console .log ( str );
@@ -87,8 +87,8 @@ queues a corresponding note off message for 1 second later.
8787
8888``` js
8989function sendMiddleC ( midiAccess , portID ) {
90- var noteOnMessage = [0x90 , 60 , 0x7f ]; // note on, middle C, full velocity
91- var output = midiAccess .outputs .get (portID);
90+ let noteOnMessage = [0x90 , 60 , 0x7f ]; // note on, middle C, full velocity
91+ let output = midiAccess .outputs .get (portID);
9292 output .send ( noteOnMessage ); // omitting the timestamp means send immediately.
9393 output .send ( [0x80 , 60 , 0x40 ], window .performance .now () + 1000.0 ); // Inlined array creation- note off, middle C,
9494 // release velocity = 64, timestamp = now + 1000ms.
@@ -100,8 +100,8 @@ This example loops all input messages on the first input port to the first
100100output port - including System Exclusive messages.
101101
102102``` js
103- var midi = null ; // global MIDIAccess object
104- var output = null ;
103+ let midi = null ; // global MIDIAccess object
104+ let output = null ;
105105
106106function echoMIDIMessage ( event ) {
107107 if (output) {
@@ -111,7 +111,7 @@ function echoMIDIMessage( event ) {
111111
112112function onMIDISuccess ( midiAccess ) {
113113 console .log ( " MIDI ready!" );
114- var input = midiAccess .inputs .entries ().next ();
114+ let input = midiAccess .inputs .entries ().next ();
115115 if (input)
116116 input .onmidimessage = echoMIDIMessage;
117117 output = midiAccess .outputs .values ().next ().value ;
@@ -135,14 +135,14 @@ are not. This sample is also hosted on <a href=
135135"http://webaudiodemos.appspot.com/monosynth/index.html">webaudiodemos.appspot.com </a >.
136136
137137``` js
138- var context= null ; // the Web Audio "context" object
139- var midiAccess= null ; // the MIDIAccess object.
140- var oscillator= null ; // the single oscillator
141- var envelope= null ; // the envelope for the single oscillator
142- var attack= 0.05 ; // attack speed
143- var release= 0.05 ; // release speed
144- var portamento= 0.05 ; // portamento/glide speed
145- var activeNotes = []; // the stack of actively-pressed keys
138+ let context= null ; // the Web Audio "context" object
139+ let midiAccess= null ; // the MIDIAccess object.
140+ let oscillator= null ; // the single oscillator
141+ let envelope= null ; // the envelope for the single oscillator
142+ let attack= 0.05 ; // attack speed
143+ let release= 0.05 ; // release speed
144+ let portamento= 0.05 ; // portamento/glide speed
145+ let activeNotes = []; // the stack of actively-pressed keys
146146
147147window .addEventListener (' load' , function () {
148148 // patch up prefixes
@@ -167,9 +167,9 @@ window.addEventListener('load', function() {
167167function onMIDIInit (midi ) {
168168 midiAccess = midi;
169169
170- var haveAtLeastOneDevice= false ;
171- var inputs= midiAccess .inputs .values ();
172- for ( var input = inputs .next (); input & amp;& ! input .done ; input = inputs .next ()) {
170+ let haveAtLeastOneDevice= false ;
171+ let inputs= midiAccess .inputs .values ();
172+ for ( let input = inputs .next (); input & amp;& ! input .done ; input = inputs .next ()) {
173173 input .value .onmidimessage = MIDIMessageEventHandler;
174174 haveAtLeastOneDevice = true ;
175175 }
@@ -209,7 +209,7 @@ function noteOn(noteNumber) {
209209}
210210
211211function noteOff (noteNumber ) {
212- var position = activeNotes .indexOf (noteNumber);
212+ let position = activeNotes .indexOf (noteNumber);
213213 if (position!= - 1 ) {
214214 activeNotes .splice (position,1 );
215215 }
0 commit comments