Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.41k stars 976 forks source link

no sound with tone array #903

Closed hp8wvvvgnj6asjm7 closed 3 years ago

hp8wvvvgnj6asjm7 commented 3 years ago

Example does nothing...


            const toneArray = []

            for(let i=0; i < _data.length-1; i++){

                _data[i].y[_data[i].y.length-1] > 0.002 && toneArray.push("A3");
                _data[i].y[_data[i].y.length-1] > 0.003 && toneArray.push("C4");
                _data[i].y[_data[i].y.length-1] > 0.004 && toneArray.push("A4");
                _data[i].y[_data[i].y.length-1] > 0.005 && toneArray.push("C5");
                _data[i].y[_data[i].y.length-1] > 0.006 && toneArray.push("A5");
                _data[i].y[_data[i].y.length-1] > 0.008 && toneArray.push("C6");
                _data[i].y[_data[i].y.length-1] > 0.009 && toneArray.push("A6");
                //_data[0][1] < -0.002 && synth.triggerAttackRelease("A-3", "8n")
                //_data[0][1] < -0.003 && synth.triggerAttackRelease("C-4", "8n")
                //_data[0][1] < -0.004 && synth.triggerAttackRelease("A-4", "8n")
                //_data[0][1] < -0.005 && synth.triggerAttackRelease("C-5", "8n")
                //_data[0][1] < -0.006 && synth.triggerAttackRelease("A-5", "8n")
                //_data[0][1] < -0.008 && synth.triggerAttackRelease("C-6", "8n")
                //_data[0][1] < -0.009 && synth.triggerAttackRelease("A-6", "8n")

            }

            const synth = new Tone.Synth().toDestination()

            new Tone.Part(((time:any, value:any) => synth.triggerAttackRelease(value.note, "8n", time, value.velocity)), toneArray.map((x:any, i:any) => ({time: i, note: x, velocity: 0.9}))).start(0)

            Tone.Transport.start()            
tambien commented 3 years ago

Seems like the issue might be with trying to start the transport before there is a user click event:

Here's a very similar example but which starts the sound only after a user clicks the start button: https://codesandbox.io/s/xenodochial-cdn-n6222?file=/src/index.ts