From 3f0c366cf9bab7c51d8dafec4528309ece0d1dc7 Mon Sep 17 00:00:00 2001 From: ChomeNS Date: Sun, 20 Nov 2022 09:09:36 +0700 Subject: [PATCH] um --- util/midi_converter/main.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/util/midi_converter/main.js b/util/midi_converter/main.js index c64eb02..d1d57ea 100644 --- a/util/midi_converter/main.js +++ b/util/midi_converter/main.js @@ -1,36 +1,38 @@ -const { Midi } = require('@tonejs/midi') -const { convertNote, convertPercussionNote } = require('./convert_note.js') +/* eslint-disable max-len */ +/* eslint-disable require-jsdoc */ +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};