@@ -3,11 +3,9 @@ Dropdown, shows a list of files.
33On select, loads the file.
44*/
55import React from 'react'
6- import axios from 'axios'
76import Select from 'react-select'
87import { connect } from 'react-redux'
98import Actions from '../../data/Actions.js'
10- const baseUrl = 'http://davedave.us/wavetable-synth/wavs/'
119
1210class WaveFileLoader extends React . Component {
1311 constructor ( props ) {
@@ -18,16 +16,16 @@ class WaveFileLoader extends React.Component {
1816 }
1917
2018 componentWillUpdate ( nextProps , nextState ) {
21- if ( this . props . files . length !== nextProps . files . length ) {
22- let options = nextProps . files . map ( ( file ) => {
19+ if ( this . props . files !== nextProps . files ) {
20+ let options = Object . keys ( nextProps . files ) . map ( ( file ) => {
2321 let fileName = file . split ( '.' ) [ 0 ]
2422 return { value : fileName , label : file . split ( '.' ) [ 0 ] }
2523 } )
2624 this . setState ( { options} )
2725 }
2826
2927 // Wait until the file list is ready.
30- if ( this . props . files . length ) {
28+ if ( Object . keys ( this . props . files ) . length ) {
3129 this . loadWaveFile ( nextProps . selectedFile )
3230 }
3331 }
@@ -39,29 +37,25 @@ class WaveFileLoader extends React.Component {
3937 }
4038
4139 loadWaveFile ( fileName ) {
42- const { id, side, audioContext, dispatch} = this . props
43- const filePath = baseUrl + fileName + '.wav'
40+ const { id, side, dispatch} = this . props
4441
4542 if ( fileName . toLowerCase ( ) . indexOf ( 'noise' ) !== - 1 ) {
46- // Generate some noise, don't bother to load and parse a file.
47- // The "noise.wav" is actually not noise, it's just another wavetable
48- // file renamed to "noise.wav" so it shows up as an option in the dropdown.
43+ // 600 is too short for a white noise osc, so we generate 1 second
44+ // of noise here. All other waves are 600 samples long.
4945 let channelData = new Float32Array ( 44100 )
5046 for ( var i = 0 ; i < 44100 ; i ++ ) {
5147 channelData [ i ] = Math . random ( )
5248 }
5349 let action = Actions . waveFileLoadCompleted ( id , side , channelData )
5450 dispatch ( action )
5551 } else {
56- axios . get ( filePath , { responseType : 'arraybuffer' } )
57- . then ( function ( response ) {
58- // Extract the data to draw each waveform.
59- audioContext . decodeAudioData ( response . data ) . then ( function ( buffer ) {
60- let channelData = buffer . getChannelData ( 0 )
61- let action = Actions . waveFileLoadCompleted ( id , side , channelData )
62- dispatch ( action )
63- } )
64- } )
52+ // Convert regular array from JSON file to the format the osc needs:
53+ let channelData = new Float32Array ( 600 )
54+ this . props . files [ fileName ] . forEach ( ( data , index ) => {
55+ channelData [ index ] = data
56+ } )
57+ let action = Actions . waveFileLoadCompleted ( id , side , channelData )
58+ dispatch ( action )
6559 }
6660 }
6761
@@ -85,7 +79,7 @@ class WaveFileLoader extends React.Component {
8579 }
8680}
8781WaveFileLoader . propTypes = {
88- files : React . PropTypes . array ,
82+ files : React . PropTypes . object ,
8983 id : React . PropTypes . string
9084}
9185WaveFileLoader . defaultProps = {
0 commit comments