I need to convert a note sequence using Magenta.js into a midi file and generate a url for users to download. The goal is to use this url in a midi-player/visualizer.
// Creating a Magenta note sequence
generateMelody(sendedNotes, 0.7, document.getElementById('bpm').value).then((magentaSequence) => {
// Converting the Magenta sequence into midi
const magentaMidi = core.sequenceProtoToMidi(magentaSequence);
// Converting byte array into a file
const magentaFile = new Blob([magentaMidi], { type: 'audio/midi' })
// Generating the URL of the file
const magentaURL = URL.createObjectURL(magentaFile);
// Building midi elements and filling out the template
const magentaContent = melodyTemplate({'id': 2, 'src': magentaURL});
// Adding a new item to the results
document.querySelector('#results').innerHTML += magentaContent;
However, I am encountering the following error:
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.