Skip to content

Commit 947ac27

Browse files
committed
Added message if no audio support.
1 parent af331df commit 947ac27

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

css/index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ body {
2121
height: calc(100% - 80px);
2222
}
2323

24+
.text-center {
25+
text-align: center;
26+
}
27+
2428
header {
2529
height: 48px;
2630
width: 996px;

src/App.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ import EventEmitter from 'event-emitter'
1818

1919
import WaveTableData from './data/WaveTableData.json'
2020

21-
const audioContext = new AudioContext()
21+
let audioContext
2222
const eventEmitter = new EventEmitter()
2323

24+
if (window.AudioContext) {
25+
audioContext = new AudioContext()
26+
}
27+
2428
class App extends React.Component {
2529
constructor (props) {
2630
super(props)
@@ -31,9 +35,27 @@ class App extends React.Component {
3135
}
3236

3337
render () {
38+
// Shows a message if no audio support in the browser.
39+
if (!window.AudioContext) {
40+
return (
41+
<div>
42+
<h1 style={{textAlign: 'center'}}>Bummer, this browser doesn't support audio.</h1>
43+
<h1 style={{textAlign: 'center'}}>Try this synth in Chrome.</h1>
44+
</div>
45+
)
46+
}
47+
// Shows a message if not Chrome.
48+
const isChrome = !!window.chrome && !!window.chrome.webstore
3449
return (
3550
<div>
3651
<div className='scroll-container'>
52+
{!isChrome &&
53+
<div>
54+
<h1 className='text-center'>
55+
Try this synth in Chrome for better audio quality and MIDI support.
56+
</h1>
57+
</div>
58+
}
3759
<header>
3860
<div>
3961
<h1>Dog Synth</h1>
@@ -81,7 +103,7 @@ class App extends React.Component {
81103
})
82104
}
83105
</div>
84-
<div className='scroll-footer'>&nbsp;</div>
106+
<div className='scroll-footer' />
85107
</div>
86108

87109
<footer>

src/data/PresetData.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/views/Midi/MidiInput.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ import Actions from '../../data/Actions.js'
1010
class MidiInput extends React.Component {
1111
constructor (props) {
1212
super(props)
13-
this.state = {
14-
options: [{ label: 'Select MIDI device', value: -1, disabled: true }],
15-
selectedInput: -1
13+
if (navigator.requestMIDIAccess) {
14+
navigator.requestMIDIAccess().then(this.onMidiInit.bind(this), this.onMidiError)
15+
this.state = {
16+
options: [{ label: 'Select MIDI device', value: -1, disabled: true }],
17+
selectedInput: -1
18+
}
19+
} else {
20+
this.state = {
21+
options: [{ label: 'MIDI not supported, try Chrome', value: -1, disabled: true }],
22+
selectedInput: -1
23+
}
1624
}
17-
navigator.requestMIDIAccess().then(this.onMidiInit.bind(this), this.onMidiError)
1825
this.notesOn = []
1926
}
2027

0 commit comments

Comments
 (0)