【问题标题】:What is the proper way to set BPM in Tone.js在 Tone.js 中设置 BPM 的正确方法是什么
【发布时间】:2022-11-08 18:15:36
【问题描述】:

我试过简单地设置Tone.Transport.bpm,但它被忽略了。我的内容仅以默认的 120 BPM 播放。然后我查看了some of the docsand it implies,您可以将参数传递给构造函数以使用自定义参数制作传输。然而,当我尝试这告诉我Transport is not a constructor,我猜它不在 v14 中:/

我在最新的 React 中使用 v14 / Ubuntu / 版本 104.0.5112.79 (Official Build) (64-bit)。

这是我的代码,它非常接近他们的官方示例代码。有趣(而且令人困惑!)的事情是取消注释 rampTo 行确实改变了节奏,但在 200 毫秒的过程中。将此值设置得太低会导致错误,并且我不希望播放开始后速度发生变化。我希望它以从样本 0 开始的设定速度开始......

import React, {useState} from 'react'
import * as Tone from 'tone'

function App() {

    const [toneStarted, setToneStarted] = useState(false)
    const [playing, setPlaying] = useState(false)
    const [setup, setSetup] = useState(false)

    async function goHandler(event) {
        if(!toneStarted) await Tone.start()
        setToneStarted(true)
        setPlaying(!playing)
        if(playing) return Tone.Transport.stop()
        
        if(!setup){
            var kick = new Tone.Player("/samples/Kicks/003.WAV").toDestination()
            var snare = new Tone.Player("/samples/Snares/003.WAV").toDestination()
            await Tone.loaded()

            // play a note every quarter-note
            new Tone.Loop(time => {
                kick.start(time)
            }, "4n").start(0)

            // play another note every off quarter-note, by starting it "8n"
            new Tone.Loop(time => {
                snare.start(time)
            }, "4n").start("8n")

            // Tone.Transport.bpm.rampTo(50, 0.2);
            setSetup(true)
        }
    
        Tone.Transport.bmp = 50;
        Tone.Transport.start()
    }

    return (
            <div className="App">
                <header className="App-header">
                    <button onClick={goHandler}>{playing ? "STOP" : "PLAY"}</button>
                </header>
            </div>
    );
}

export default App;

【问题讨论】:

    标签: tonejs


    【解决方案1】:

    您必须在末尾使用 .value 符号:

    Tone.Transport.bpm.value = 50
    

    注意:默认 bpm 值为 120


    你打错了 = bpm 而不是 bmp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-17
      • 2010-11-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 2013-12-26
      • 2014-03-16
      相关资源
      最近更新 更多