【问题标题】:How to play a melody using Tone.js如何使用 Tone.js 演奏旋律
【发布时间】:2020-08-26 04:07:19
【问题描述】:

我有很多这样的笔记

const notes = [{note: 'C4', duration: '8n'}, {note: 'D4', duration: '4n'}, {note: 'C4', duration: '2n'}, {note: '', duration: '8n'}] //last element stands for a pause

如何根据这个数组演奏旋律? 有没有更好的方法来存储旋律?

或者我应该为此使用另一个库吗?

谢谢!

【问题讨论】:

    标签: tone.js


    【解决方案1】:

    所以我是这样做的:

    playTab = tab => {
        const now = Tone.Time()
        let currentTime = 0
        tab.forEach(item => {
            const {note, duration} = parseNote(item)
            if (note !== '') {
                this.synth.triggerAttackRelease(note, duration, now + currentTime)
            }
            currentTime += Tone.Time(duration).toSeconds()
        })
    }
    

    这是一个好的决定吗?还是应该换一种方式?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多