如何将magenta.js音符序列转换为midi文件?

问题描述

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)