0

我正在尝试将 Magenta.js 中的音符序列转换为 midi 文件并获取 url,以便用户可以下载它并在我的 midi-player/visualizer 中使用该 url。

// Create a magenta note sequence
generateMelody(sendedNotes, 0.7, document.getElementById('bpm').value).then((magentaSequence) => {

    // Create midi out of magenteSequence
    const magentaMidi = core.sequenceProtoToMidi(magentaSequence);

    // Convert byte array to file
    const magentaFile = new Blob([magentaMidi], { type: 'audio/midi' })

    // Get url of the file
    const magentaURL = URL.createObjectURL(magentaFile);

    // Create midi elements and populate the template
    const magentaContent = melodyTemplate({'id': 2, 'src': magentaURL});

    // Add new item to results
    document.querySelector('#results').innerHTML += magentaContent;

但我得到这个错误:

Uncaught (in promise) Error: The sequence you are using with the visualizer does not have a totalTime field set, so the visualizer can't be horizontally sized correctly.
4

1 回答 1

1

我通过添加解决了它:

magentaSequence.notes.forEach(n => n.velocity = bpm);

似乎注释需要速度才能使此代码起作用。我在此链接中找到了详细信息https://github.com/magenta/magenta-js/issues/462

于 2020-10-05T16:12:05.420 回答