FridayNightFunkinBoyfriendBot/util/txt_song_parser.js

16 lines
643 B
JavaScript
Raw Permalink Normal View History

2023-12-17 14:55:27 -05:00
const { instrumentsArray } = require('minecraft-data') // chip hardcoding moment
function parseTXTSong (data) {
let length = 0
const notes = String(data).split(/\r\n|\r|\n/).map(line => {
const [tick, pitch, instrument] = line.split(':').map(Number)
if (tick === undefined || pitch === undefined || instrument === undefined) return undefined
const time = tick * 50
length = Math.max(length, time)
return { time, pitch, instrument: instrumentsArray[instrument].name, volume: 1 }
}).filter(note => note !== undefined)
return { name: '', notes, loop: false, loopPosition: 0, length }
}
module.exports = parseTXTSong