首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tone.js用户集参数

Tone.js用户集参数
EN

Stack Overflow用户
提问于 2021-03-11 05:19:00
回答 1查看 91关注 0票数 0

我试图让用户最终选择他们想要使用的注释,但是首先为了测试这个特性,我列出了几个按钮,在单击时应该播放所需的注释。

下面的片段是Tone.js通常的工作方式。synth.triggerAttackRelease("C5", "8n")

下面的片段表达了我希望它工作的方式。synth.triggerAttackRelease(btnId, "8n")

我得到以下错误,即使btnId作为相应的注释返回,例如"A4“。Uncaught Error: Invalid argument(s) to setValueAtTime: "A", 0.1 A是本例中的一个注释.

下面是一个完整的代码块,例如一个工作函数

代码语言:javascript
复制
   import * as Tone from 'tone'
   import {Notes} from './Notes.js';
   const synth = new Tone.Synth().toDestination();
   
   export default Class SynthDisplay extends React.Component {
      constructor(props) {
         super(props);
         this.btnClick = this.BtnClick.bind(this);
      }
      btnClick () {
         synth.triggerAttackRelease("C5", "8n");
      }
      render(){
         return(
           <button onClick={btnClick} />
          )
      }
   }

这是我想要工作的代码

代码语言:javascript
复制
import React from 'react';


export default class SpinDial extends React.Component {
    constructor(props) {
        super(props);
        this.state = {Notes: props.Notes, Tone: props.Tone, array: []};
        this.renderNotes = this.renderNotes.bind(this);
        this.btnPress = this.btnPress.bind(this);
    }
    componentDidMount() {
        this.renderNotes();
    }
    renderNotes () {
        const notes = this.state.Notes;
        const array = this.state.array;
        for (let i = 0; i < notes.length; i ++) {
            array.push(<button className="noteBtn" key={notes[i] + i} id={notes[i]} onClick={this.btnPress}>{notes[i]}</button>);
        }
        const mapArray = array.map((object, index) => {
            return <div className={"mapDiv"} key={index} value={object.id}>{[object]}</div>
        });
        this.setState({
            array: mapArray
        });
    }
    btnPress (e) {
        const btnId = e.target.id;
        const noteBtnArray = document.getElementsByClassName("noteBtn");
        for (let i = 0; i < noteBtnArray.length; i++) {
            if (noteBtnArray[i].id === btnId) {
                console.log("Match" + noteBtnArray[i] + " " + btnId);
                const synth = new this.state.Tone.Synth().toDestination();
                synth.triggerAttackRelease(btnId, "8n");

            } else {
                console.log("Fail" + noteBtnArray[i] + " " + btnId);
            }
        }

    }
    render() {
        return(
            <div>{this.state.array}</div>
            
        )
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-03-14 01:32:06

因此,我意识到,我在E#文件中的一些注释(如E#和Notes.js文件)并不是如何在文档中列出的。只要注释与文档相匹配,上述代码就可以工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66576879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档