然后获得第一个按钮按下的音调,我收到此错误...
错误:setValueAtTime 的参数无效:{},2.2188208616780045
不确定这个错误来自哪里,我为每个鼠标事件设置了时间,所以这应该可以防止任何错误。
我的代码:
import React, { Component } from "react";
import ButtonGroup from "react-bootstrap/ButtonGroup";
import Button from "react-bootstrap/Button";
import * as Tone from "tone";
const synth = new Tone.Synth().toDestination();
//
//container component to hold the piano keys
//
class PianoBoard extends Component {
constructor(props) {
super(props);
this.handleMouseDown = this.handleMouseDown.bind(this);
this.handleMouseUp = this.handleMouseUp.bind(this);
}
handleMouseDown(e){
e.preventDefault(e);
Tone.start();
synth.triggerAttack(e.target.attributes.note,Tone.now());
}
handleMouseUp(e){
e.preventDefault(e);
synth.triggerRelease(Tone.now());
}
render() {
return (
<div class="pianoboard">
<Button onMouseDown={this.handleMouseDown} onMouseUp={this.handleMouseUp} note="C4">
C4
</Button>
</div>
);
}
}
export default PianoBoard;