I'm creating a midi file based on frequencies. I'm using ToneJS (in Node.js) to create the midi file with this code:
exports.createMidiFile = (req,res,next) => {
// create a new midi file
var midi = new Midi()
// add a track
const track = midi.addTrack()
track.addNote({
midi : Tone.Frequency(400).toMidi(),
time : 0,
duration: 10
})
// write the output
fs.writeFileSync("output.mid", new Buffer(midi.toArray()))
}
What im trying to do is a for loop to add notes to the same track. I tried:
for (var i = 0; i < length; i++){
track.addNote({
midi : Tone.Frequency(i).toMidi(),
time : 0,
duration: 10
})
}
But when i try to open the file it says the file is damaged..
Thanks in advance friends.