@@ -5,26 +5,23 @@ import Synth from './Synth'
55
66import NOTES from './notes'
77
8- const getNotesForOctave = octave => {
9- return Object . keys ( NOTES ) . reduce ( ( state , note ) => {
10- if ( note . split ( '' ) . pop ( ) === Number ( octave ) ) state [ note ] = NOTES [ note ]
8+ const getNotesForOctave = octave =>
9+ Object . keys ( NOTES ) . reduce ( ( state , note ) => {
10+ if ( note . split ( '' ) . pop ( ) === String ( octave ) ) state [ note ] = NOTES [ note ]
1111 return state
1212 } , { } )
13- }
1413
1514const defaultPads = [
16- [ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
17- [ 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
18- [ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
19- [ 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 ] ,
20- [ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
21- [ 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
15+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
16+ [ 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ,
17+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
2218 [ 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 ] ,
23- [ 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 ]
19+ [ 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 ] ,
20+ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
21+ [ 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ] ,
22+ [ 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ]
2423]
2524
26- const synth = new Synth ( )
27-
2825class Sequencer extends Component {
2926 state = {
3027 type : 'sine' ,
@@ -95,12 +92,14 @@ class Sequencer extends Component {
9592 }
9693
9794 play ( ) {
95+ this . synth = new Synth ( )
96+
9897 const { bpm, notes, type, release, delay } = this . state
9998 const notesArray = Object . keys ( notes ) . map ( key => notes [ key ] )
10099
101- this . setState ( {
100+ this . setState ( ( ) => ( {
102101 playing : true
103- } )
102+ } ) )
104103
105104 this . interval = setInterval ( ( ) => {
106105 this . setState (
@@ -112,7 +111,7 @@ class Sequencer extends Component {
112111 . map ( ( pad , i ) => ( pad === 1 ? notesArray [ i ] : null ) )
113112 . filter ( x => x )
114113
115- synth . playNotes ( next , {
114+ this . synth . playNotes ( next , {
116115 release,
117116 bpm,
118117 type,
@@ -124,10 +123,10 @@ class Sequencer extends Component {
124123 }
125124
126125 pause ( ) {
127- this . setState ( {
126+ this . setState ( ( ) => ( {
128127 playing : false ,
129128 step : 0
130- } )
129+ } ) )
131130
132131 clearInterval ( this . interval )
133132 }
0 commit comments