第二次调用 Tone.JS 函数不起作用

Calling Tone.JS function doesn't work second time

当我第一次按下按钮时,它会按预期播放笔记列表,但第二次不会。我的控制台日志记录表明第二次以相同的方式调用该函数,但也许我遗漏了什么?为什么这不会第二次播放音符序列?

我尝试了 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();


}

我不得不在完成回放后调用 Transport 和 Tone 序列对象的 .stop() 来解决问题:

if (count === last_note) {
      pattern.stop();
      Tone.Transport.stop();
    }