Skip to content

Commit a44b55f

Browse files
committed
Add intro screen to fix user-interaction error
Since this was originally built a new restriction is now in place in Chrome that requires a user interaction to happen before audioContext initilization can occur. Figured adding a short intro screen was the easiest way to fix this.
1 parent 8ad858c commit a44b55f

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

css/index.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ h2 {
2626
padding-bottom: 0;
2727
}
2828

29+
.get-started {
30+
padding: 80px;
31+
text-align: center;
32+
max-width: 600px;
33+
margin:0 auto;
34+
}
35+
.get-started button{
36+
background-color: $blue;
37+
padding: 24px 36px;
38+
color: white;
39+
}
40+
2941
.scroll-container {
3042
padding: 0;
3143
margin: 0;

src/App.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ import EventEmitter from 'event-emitter'
2121

2222
import WaveTableData from './data/WaveTableData.json'
2323

24-
let audioContext
25-
const eventEmitter = new EventEmitter()
2624

27-
if (window.AudioContext) {
28-
audioContext = new AudioContext()
29-
}
25+
const eventEmitter = new EventEmitter()
3026

3127
class App extends React.Component {
3228
constructor (props) {
@@ -68,18 +64,13 @@ class App extends React.Component {
6864
</div>
6965
)
7066
}
71-
// Shows a message if not Chrome.
72-
const isChrome = !!window.chrome && !!window.chrome.webstore
67+
const { audioContext } = this.props;
68+
69+
70+
7371
return (
7472
<div>
7573
<div className='scroll-container'>
76-
{!isChrome &&
77-
<div>
78-
<h1 className='text-center'>
79-
Try this synth in Chrome for better audio quality and MIDI support.
80-
</h1>
81-
</div>
82-
}
8374
<header>
8475
<div>
8576
<h1>Wavetable</h1>

src/index.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,37 @@ import App from './App.js'
1111
import Reducers from './data/Reducers.js'
1212

1313
let store = createStore(Reducers)
14+
let audioContext
15+
const createAudioContext = () => {
16+
audioContext = new AudioContext()
17+
renderApp();
18+
}
1419

15-
render(
16-
<Provider store={store}>
17-
<App store={store} />
18-
</Provider>,
19-
document.getElementById('root')
20-
)
20+
const renderApp = () => {
21+
if(!audioContext){
22+
return render(
23+
<div className="get-started">
24+
<h1>Welcome to Wavetable synth!</h1>
25+
<p>Click on the piano keys, type keys on your keyboard, or even hook up a MIDI keyboard to hear it in action!</p>
26+
<button
27+
onClick={createAudioContext}>
28+
Click Here to Start
29+
</button>
30+
</div>,
31+
document.getElementById('root')
32+
);
33+
}
34+
35+
return render(
36+
<Provider store={store}>
37+
<App
38+
store={store}
39+
audioContext={audioContext}
40+
createAudioContext={createAudioContext}
41+
/>
42+
</Provider>,
43+
document.getElementById('root')
44+
)
45+
}
46+
47+
renderApp();

src/views/Presets/Presets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Presets extends React.Component {
2929
}
3030

3131
render () {
32+
console.log("options --->", this.props.presetId, this.state.options);
3233
return (
3334
<div className='preset-list-container'>
3435
<Select

0 commit comments

Comments
 (0)