我有一组类似的钞票
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()
})
}
这是个好决定吗?还是应该采取不同的做法?