-
Notifications
You must be signed in to change notification settings - Fork 0
/
midi-inputs.js
48 lines (41 loc) · 973 Bytes
/
midi-inputs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
html,
Component
} from "https://unpkg.com/htm/preact/standalone.module.js";
import midi from "./midi.js";
class MidiInputs extends Component {
state = {
selected: "",
inputs: []
};
setInputs = inputs => {
this.setState({ inputs: Array.from(inputs) });
};
setSelected = ([id]) => {
this.setState({ selected: id });
};
onSelectIn = event => {
midi.selectIn(event.target.value);
};
componentDidMount() {
midi.on("inputs_changed", this.setInputs);
midi.on("audioin_changed", this.setSelected);
}
render() {
return html`
<label>
In:
<select onChange=${this.onSelectIn}>
${this.state.inputs.map(
([id, controller]) => html`
<option selected="${id === this.state.selected}" value="${id}"
>${controller.name}</option
>
`
)}
</select>
</label>
`;
}
}
export default MidiInputs;