-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathstatic-instrument-example.js
63 lines (61 loc) · 1.95 KB
/
static-instrument-example.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react';
import { Instrument, Note } from '../../../src/';
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
class StaticInstrumentExample extends React.Component {
constructor(props) {
super(props);
this.state = {
playA: false,
playC: false,
};
this.playMelody = this.playMelody.bind(this);
this.onInstrumentLoaded = this.onInstrumentLoaded.bind(this);
}
async onInstrumentLoaded() {
await this.playMelody();
}
async playMelody() {
await delay(1000);
this.setState({ playA: true });
await delay(1000);
this.setState({ playC: true, playA: false });
await delay(1000);
this.setState({ playC: false });
}
render() {
return (
<div>
<Instrument name={'acoustic_grand_piano'} interactive={false} onInstrumentLoaded={this.onInstrumentLoaded}>
<Note name={'A3'} play={this.state.playA}>
{/*
You can put any react element here native or web.
*/}
<div className="control">
<a className={`button ${this.state.playA ? 'is-primary' : ''}`}>
This is what I want my note to look like ! I can put anything in here.
<img
alt="Some pic"
src="https://s-media-cache-ak0.pinimg.com/originals/36/43/e7/3643e7e8dab9b88b3972ee1c9f909dea.jpg"
width="30"
/>
</a>
</div>
</Note>
<Note name={'C3'} play={this.state.playC}>
<div className="control">
<div className={`button ${this.state.playC ? 'is-primary' : ''}`}>
Another note
</div>
</div>
</Note>
</Instrument>
<div className="control">
<button className="button" onClick={this.playMelody}>
Play Melody
</button>
</div>
</div>
);
}
}
export default StaticInstrumentExample;