@@ -7,7 +7,7 @@ The following are some examples of common MIDI usage in JavaScript.
7
7
This example shows how to request access to the MIDI system.
8
8
9
9
``` js
10
- var midi = null ; // global MIDIAccess object
10
+ let midi = null ; // global MIDIAccess object
11
11
12
12
function onMIDISuccess ( midiAccess ) {
13
13
console .log ( " MIDI ready!" );
@@ -26,7 +26,7 @@ This example shows how to request access to the MIDI system, including the
26
26
ability to send and receive System Exclusive messages.
27
27
28
28
``` js
29
- var midi = null ; // global MIDIAccess object
29
+ let midi = null ; // global MIDIAccess object
30
30
31
31
function onMIDISuccess ( midiAccess ) {
32
32
console .log ( " MIDI ready!" );
@@ -46,15 +46,15 @@ information to the console log, using ES6 for...of notation.
46
46
47
47
``` js
48
48
function 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 ];
51
51
console .log ( " Input port [type:'" + input .type + " '] id:'" + input .id +
52
52
" ' manufacturer:'" + input .manufacturer + " ' name:'" + input .name +
53
53
" ' version:'" + input .version + " '" );
54
54
}
55
55
56
- for (var entry of midiAccess .outputs ) {
57
- var output = entry[1 ];
56
+ for (let entry of midiAccess .outputs ) {
57
+ let output = entry[1 ];
58
58
console .log ( " Output port [type:'" + output .type + " '] id:'" + output .id +
59
59
" ' manufacturer:'" + output .manufacturer + " ' name:'" + output .name +
60
60
" ' version:'" + output .version + " '" );
@@ -68,8 +68,8 @@ the console log.
68
68
69
69
``` js
70
70
function 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++ ) {
73
73
str += " 0x" + event .data [i].toString (16 ) + " " ;
74
74
}
75
75
console .log ( str );
@@ -87,8 +87,8 @@ queues a corresponding note off message for 1 second later.
87
87
88
88
``` js
89
89
function 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);
92
92
output .send ( noteOnMessage ); // omitting the timestamp means send immediately.
93
93
output .send ( [0x80 , 60 , 0x40 ], window .performance .now () + 1000.0 ); // Inlined array creation- note off, middle C,
94
94
// release velocity = 64, timestamp = now + 1000ms.
@@ -100,8 +100,8 @@ This example loops all input messages on the first input port to the first
100
100
output port - including System Exclusive messages.
101
101
102
102
``` js
103
- var midi = null ; // global MIDIAccess object
104
- var output = null ;
103
+ let midi = null ; // global MIDIAccess object
104
+ let output = null ;
105
105
106
106
function echoMIDIMessage ( event ) {
107
107
if (output) {
@@ -111,7 +111,7 @@ function echoMIDIMessage( event ) {
111
111
112
112
function onMIDISuccess ( midiAccess ) {
113
113
console .log ( " MIDI ready!" );
114
- var input = midiAccess .inputs .entries ().next ();
114
+ let input = midiAccess .inputs .entries ().next ();
115
115
if (input)
116
116
input .onmidimessage = echoMIDIMessage;
117
117
output = midiAccess .outputs .values ().next ().value ;
@@ -135,14 +135,14 @@ are not. This sample is also hosted on <a href=
135
135
"http://webaudiodemos.appspot.com/monosynth/index.html">webaudiodemos.appspot.com </a >.
136
136
137
137
``` 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
146
146
147
147
window .addEventListener (' load' , function () {
148
148
// patch up prefixes
@@ -167,9 +167,9 @@ window.addEventListener('load', function() {
167
167
function onMIDIInit (midi ) {
168
168
midiAccess = midi;
169
169
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 ()) {
173
173
input .value .onmidimessage = MIDIMessageEventHandler;
174
174
haveAtLeastOneDevice = true ;
175
175
}
@@ -209,7 +209,7 @@ function noteOn(noteNumber) {
209
209
}
210
210
211
211
function noteOff (noteNumber ) {
212
- var position = activeNotes .indexOf (noteNumber);
212
+ let position = activeNotes .indexOf (noteNumber);
213
213
if (position!= - 1 ) {
214
214
activeNotes .splice (position,1 );
215
215
}
0 commit comments