Skip to content

Commit d445437

Browse files
author
Ben Michel
authored
syntax highlighting
1 parent 62981d3 commit d445437

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

MIDIAccess.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ In case of a rejection, you can utilize a great [polyfill](https://en.wikipedia.
3434

3535
If it does not, this script can be injected into your HTML source code to attain access:
3636

37-
`<script src='http://cwilso.github.com/WebMIDIAPIShim/build/WebMIDIAPI.min.js'></script>`
37+
```html
38+
<script src='http://cwilso.github.com/WebMIDIAPIShim/build/WebMIDIAPI.min.js'></script>
39+
```
3840

3941
## Example Use
4042

4143
### Simple Access
4244
Check to see if your browser supports the Web MIDI API, then ask the navigator for `MIDIAccess` and pass the result to your handlers (eg. `onMIDIAccess` & `onMIDIAccessFailure`).
43-
```
45+
```js
4446
if (navigator.requestMIDIAccess) {
4547
navigator.requestMIDIAccess({ sysex: false }).then(onMIDIAccess, onMIDIAccessFailure)
4648
} else {
@@ -49,7 +51,7 @@ if (navigator.requestMIDIAccess) {
4951
```
5052

5153
If access has been gained, you can begin to use a `MIDIAccess` object!
52-
```
54+
```js
5355
const onMIDIAccess = (midiAccessObject) => {
5456
console.log(‘The MIDI Access Object:’, midiAccessObject)
5557
}
@@ -59,7 +61,7 @@ const onMIDIAccess = (midiAccessObject) => {
5961
Errors typically occur in two cases: there are no MIDI devices currently available, or your browser doesn’t support the Web MIDI API.
6062

6163
In any case, handling an error allows you to alert the user of their best available options, and log standard errors:
62-
```
64+
```js
6365
const onMIDIAccessFailure = (err) {
6466
console.log(`No MIDI devices are available, or the Web MIDI API isn’t supported by this browser.`)
6567
console.log(`Utilize this Web MIDI API Polyfill in order to use the Web MIDI API: http://cwilso.github.io/WebMIDIAPIShim/`)
@@ -69,7 +71,7 @@ const onMIDIAccessFailure = (err) {
6971

7072
### Working with raw MIDI data
7173
By looping through the available input values from connected devices, you can pass every message to a handler and begin doing incredible things with MIDI in your browser! Have fun! 🙌
72-
```
74+
```js
7375
const onMIDIAccess = (midiAccessObject) => {
7476
let inputs = midiAccessObject.inputs.values()
7577
for (let input = inputs.next(); input && !input.done; input = inputs.next()) {

0 commit comments

Comments
 (0)