【问题标题】:How to convert a magenta.js note sequence to a midi file?如何将 magenta.js 音符序列转换为 midi 文件?
【发布时间】:2020-10-02 23:59:14
【问题描述】:

我正在尝试将 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.

【问题讨论】:

    标签: javascript midi magenta


    【解决方案1】:

    我通过添加解决了它:

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

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

    【讨论】:

      猜你喜欢
      • 2022-07-06
      • 1970-01-01
      • 2022-10-30
      • 2017-06-04
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      • 2010-10-17
      • 2014-04-12
      相关资源
      最近更新 更多