diff --git a/util/midi_converter/main.js b/util/midi_converter/main.js index d1d57ea..b939e77 100644 --- a/util/midi_converter/main.js +++ b/util/midi_converter/main.js @@ -1,38 +1,38 @@ /* eslint-disable max-len */ /* eslint-disable require-jsdoc */ -const {Midi} = require('@tonejs/midi'); -const {convertNote, convertPercussionNote} = require('./convert_note.js'); +const { Midi } = require('@tonejs/midi') +const { convertNote, convertPercussionNote } = require('./convert_note.js') -function convertMidi(midi) { - if (!(midi instanceof Midi)) throw new TypeError('midi must be an instance of require(\'@tonejs/midi\').Midi'); +function convertMidi (midi) { + if (!(midi instanceof Midi)) throw new TypeError('midi must be an instance of require(\'@tonejs/midi\').Midi') - let noteList = []; + let noteList = [] for (const track of midi.tracks) { for (const note of track.notes) { - const mcNote = (track.instrument.percussion ? convertPercussionNote : convertNote)(track, note); + const mcNote = (track.instrument.percussion ? convertPercussionNote : convertNote)(track, note) if (mcNote != null) { - noteList.push(mcNote); + noteList.push(mcNote) } } } - noteList = noteList.sort((a, b) => a.time - b.time); + noteList = noteList.sort((a, b) => a.time - b.time) // It might be better to move some of this code to the converting loop (for performance reasons) - let maxVolume = 0.001; + let maxVolume = 0.001 for (const note of noteList) { - if (note.volume > maxVolume) maxVolume = note.volume; + if (note.volume > maxVolume) maxVolume = note.volume } for (const note of noteList) { - note.volume /= maxVolume; + note.volume /= maxVolume } - let songLength = 0; + let songLength = 0 for (const note of noteList) { - if (note.time > songLength) songLength = note.time; + if (note.time > songLength) songLength = note.time } - return {name: midi.header.name, notes: noteList, loop: false, loopPosition: 0, length: songLength}; + return { name: midi.header.name, notes: noteList, loop: false, loopPosition: 0, length: songLength } } -module.exports = {convertMidi, convertNote, convertPercussionNote}; +module.exports = { convertMidi, convertNote, convertPercussionNote }