@@ -62,21 +62,48 @@ function listInputsAndOutputs( midiAccess ) {
62
62
}
63
63
```
64
64
65
+ ### Adding inputs and outputs to select boxes
66
+
67
+ ``` js
68
+ // to tell how many entries there are:
69
+ let numberOfMIDIInputs = inputs .size ;
70
+
71
+ // add each of the ports to a <select> box
72
+ for (let input of inputs .values ()) {
73
+ let opt = document .createElement (" option" );
74
+ opt .text = input .name ;
75
+ document .getElementById (" inputportselector" ).add (opt);
76
+ }
77
+
78
+ // to tell how many entries there are:
79
+ let numberOfMIDIOutputs = outputs .size ;
80
+
81
+ // add each of the ports to a <select> box
82
+ for (let output of outputs .values ()) {
83
+ let opt = document .createElement (" option" );
84
+ opt .text = output .name ;
85
+ document .getElementById (" outputportselector" ).add (opt);
86
+ }
87
+ ```
88
+
65
89
### Handling MIDI Input
66
90
This example prints incoming MIDI messages on a single arbitrary input port to
67
91
the console log.
68
92
69
93
``` js
70
94
function onMIDIMessage ( event ) {
71
95
let str = " MIDI message received at timestamp " + event .timeStamp + " [" + event .data .length + " bytes]: " ;
72
- for (let i= 0 ; i& lt; event .data .length ; i++ ) {
96
+ for (let i= 0 ; i< event .data .length ; i++ ) {
73
97
str += " 0x" + event .data [i].toString (16 ) + " " ;
74
98
}
75
99
console .log ( str );
76
100
}
77
101
78
- function startLoggingMIDIInput ( midiAccess , indexOfPort ) {
79
- midiAccess .inputs .forEach ( function (entry ) {entry .onmidimessage = onMIDIMessage;});
102
+ function startLoggingMIDIInput ( midiAccess ) {
103
+ for (let entry of midiAccess .inputs ) {
104
+ let input = entry[1 ];
105
+ input .onmidimessage = onMIDIMessage;
106
+ }
80
107
}
81
108
```
82
109
@@ -169,7 +196,7 @@ function onMIDIInit(midi) {
169
196
170
197
let haveAtLeastOneDevice= false ;
171
198
let inputs= midiAccess .inputs .values ();
172
- for ( let input = inputs .next (); input & amp; & ! input .done ; input = inputs .next ()) {
199
+ for ( let input = inputs .next (); input && ! input .done ; input = inputs .next ()) {
173
200
input .value .onmidimessage = MIDIMessageEventHandler;
174
201
haveAtLeastOneDevice = true ;
175
202
}
0 commit comments