UNPKG

nbs-reader

Version:

This package is a library that processes Note Block Studio nbs files in Note.js.

1 lines 2.47 kB
var fs=require("fs");module.exports=(e=>{var r=0,n=(e,n,t,o=null)=>{var a=e.substring(r,r+2*n);return t&&(a=a.match(/.{2}/g).reverse().join("")),r+=2*n,null==o?a:o(a)},t=e=>parseInt(e,16),o=e=>0==e.length?"":(new TextDecoder).decode(new Uint8Array(e.match(/.{2}/g).map(e=>parseInt(e,16)))),a=e=>{var r=n(e,4,!0,t);return n(e,r,!1,o)},s=e=>n(e,1,!0,t),i=fs.readFileSync(e).toString("hex").toUpperCase(),l=n(i,2,!0,t);if(0==l)return function(){for(var e={OpenNbs:!0,Version:s(i),VanillaInstruments:s(i),Length:n(i,2,!0,t),Layers:n(i,2,!0,t),SongName:a(i),SongAuthor:a(i),OriginalAuthor:a(i),Description:a(i),Tempo:n(i,2,!0,t)/100,AutoSave:{Enable:new Boolean(s(i)),Duration:s(i)},TimeSignature:s(i),MinutesSpent:n(i,4,!0,t),LeftClicks:n(i,4,!0,t),RightClicks:n(i,4,!0,t),BlocksAdded:n(i,4,!0,t),BlocksRemoved:n(i,4,!0,t),FileName:a(i),Loop:{Enable:new Boolean(s(i)),Count:s(i),StartTick:n(i,2,!0,t)},Notes:[],CustomInstruments:[]},r=[],o=-1,l={};;){var u=n(i,2,!0,t);if(0==u)break;if(u>1)for(let e=0;e<u-1;e++)r[o+e+1]=[];o+=u;for(var m=-1;0!=(u=n(i,2,!0,t));){var c={Tick:o,Layer:m+=u,Inst:s(i),Key:s(i),Velocity:s(i),Panning:s(i),Pitch:n(i,2,!0,t)};r[o]?r[o].push(c):r[o]=[c],m<e.Layers&&(l[m]?l[m][o]=c:(l[m]={},l[m][o]=c))}}var h=e.Layers;e.Layers=[];for(let r=0;r<h;r++)m={Name:a(i),Locked:new Boolean(s(i)),Volume:s(i),Panning:s(i),Notes:l[r]},e.Layers.push(m);e.Notes=r;var p=s(i);for(let r=0;r<p;r++)e.CustomInstruments.push({Name:a(i),FileName:a(i),Pitch:s(i),PressKey:new Boolean(s(i))});return e}();for(var u={OpenNbs:!1,Version:0,VanillaInstruments:10,Length:l+1,Layers:n(i,2,!0,t),SongName:a(i),SongAuthor:a(i),OriginalAuthor:a(i),Description:a(i),Tempo:n(i,2,!0,t)/100,AutoSave:{Enable:new Boolean(s(i)),Duration:s(i)},TimeSignature:s(i),MinutesSpent:n(i,4,!0,t),LeftClicks:n(i,4,!0,t),RightClicks:n(i,4,!0,t),BlocksAdded:n(i,4,!0,t),BlocksRemoved:n(i,4,!0,t),FileName:a(i),Loop:{Enable:!1,Count:0,StartTick:0},Notes:[],CustomInstruments:[]},m=[],c=-1,h=0,p={};0!=(h=n(i,2,!0,t));){if(h>1)for(let e=0;e<h-1;e++)m[c+e+1]=[];c+=h;for(var f=-1;0!=(h=n(i,2,!0,t));){var g={Tick:c,Layer:f+=h,Inst:s(i),Key:s(i),Velocity:100,Panning:100,Pitch:0};m[c]?m[c].push(g):m[c]=[g],f<u.Layers&&(p[f]?p[f][c]=g:(p[f]={},p[f][c]=g))}}var v=u.Layers;u.Layers=[];for(let e=0;e<v;e++){f={Name:a(i),Volume:s(i),Notes:p[e]};u.Layers.push(f)}u.Notes=m;var y=s(i);for(let e=0;e<y;e++)u.CustomInstruments.push({Name:a(i),FileName:a(i),Pitch:s(i),PressKey:new Boolean(s(i))});return u});