问题描述
我有一系列这样的笔记
const notes = [{note: 'C4',duration: '8n'},{note: 'D4',duration: '4n'},{note: 'C4',duration: '2n'},{note: '',duration: '8n'}] //last element stands for a pause
如何基于此阵列演奏旋律? 还有没有更好的方法来存储旋律?
或者我应该为此使用另一个库吗?
谢谢!
解决方法
所以我这样做了:
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()
})
}
这是一个好决定吗?还是应该以其他方式进行?