问题描述
我正在尝试将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.
解决方法
我通过添加以下内容解决了该问题:
magentaSequence.notes.forEach(n => n.velocity = bpm);
似乎注释需要一定的速度才能使此代码起作用。我在此链接https://github.com/magenta/magenta-js/issues/462
中找到了详细信息