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