【发布时间】:2020-06-11 15:48:19
【问题描述】:
当我第一次按下按钮时,它会按预期播放音符列表,但不是第二次。我的控制台日志记录表明第二次以相同的方式调用该函数,但也许我遗漏了什么?为什么这不会播放第二次音符序列?
我尝试了 Tone.Transport.start(0) 等其他潜在解决方案,但这并没有解决问题。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src= "www/js/Tone.js"></script>
<script src= "main.js"></script>
</head>
<body>
<button onclick="playSeq([60, 61, 62], false, this.id, 'tone');">Play</button>
</body>
</html>
Javascript
function playSeq (note_list, hidePlay, id, sound) {
midi_list = note_list.map(x => Tone.Frequency(x, "midi").toNote());
last_note = midi_list.length;
count = 0;
var pattern = new Tone.Sequence(function(time, note){
triggerNote(sound, note, 0.25);
count = count + 1;
if (count === last_note) {
console.log("finished!");
}
}, midi_list);
pattern.start(0).loop = false;
console.log(Tone.Transport);
// begin at the beginning
Tone.Transport.start();
}
【问题讨论】:
标签: javascript tone.js